【问题标题】:using notify_listener - libpqxx使用 notify_listener - libpqxx
【发布时间】:2012-10-10 21:13:03
【问题描述】:

我正在尝试使用libpqxx 监听通知事件。我从一个扩展pqxx::notify_listener 的示例开始。

#include <iostream>
#include <string>
#include <pqxx/pqxx>

class Foo : public pqxx::notify_listener {

public:
  Foo(pqxx::connection_base &c): pqxx::notify_listener(c, "listen") {}
  virtual void operator()(int id) { std::cout << "HERE!" << std::endl; }
};

int main(void) {
  // set up the listener
  pqxx::connection con("...secret...");
  Foo listener(con);

  // loop forever ...
}

但我无法让它工作。

我尝试将名称参数切换为
pqxx::notify_listener(c, "my_schema")
pqxx::notify_listener(c, "listen my_schema") 和其他一些参数。

我正在通过 pgAdmin 手动创建 NOTIFY 事件。无论我做什么,仿函数都不会被执行。

【问题讨论】:

    标签: c++ postgresql libpqxx


    【解决方案1】:

    您在主循环中调用pqxx::connection_base::get_notifs() 还是pqxx::connection_base::await_notification()

    如果没有,你需要。

    【讨论】:

    • 不错的收获。这在 doxygen 文档中并不明显。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多