postgresql pqxx notify_listener - 获取通知负载

标签 postgresql libpqxx

原生接口(interface)postgresql提供了如下命令:NOTIFY channel [ , payload ],其中payload为可变字符串。我使用库 pqxx 与数据库进行交互。它提供了notify_listener接口(interface)。作为通知执行的回调只有一个参数 - id。 这是我的代码:

class notif : public pqxx::notify_listener {

public:
        notif(pqxx::connection_base &conn, const std::string &table, std::shared_ptr<notify_processor_t> pr) : 
            pqxx::notify_listener(conn, table), _table(table), _pr(pr) {}

        notif(pqxx::connection_base &conn, const std::string &table) :
            pqxx::notify_listener(conn, table), _table(table) {}

        virtual void operator()(int id) 
        { 
            std::cout << "notification " << _table << std::endl; 
            if (_pr.get())
                _pr->operator()();
        }
private:
        std::shared_ptr<notify_processor_t> _pr;
        std::string _table;
};

如何使用提供的pqxx接口(interface)获取payload内容?

最佳答案

在libpqxx 4.0.1版本中发现如下:

// Obsolete notification receiver.
/** @deprecated Use notification_receiver instead.
*/
class PQXX_LIBEXPORT PQXX_NOVTABLE notify_listener

您应该使用notification receiver 类而不是notify_listener

关于postgresql pqxx notify_listener - 获取通知负载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34453302/

相关文章:

sql - 从单列中分离名字和姓氏

c++ - 无法在 MinGW 中链接 libpqxx

c++ - 如何猜测libpqxx C++库函数抛出的异常类型?

c++ - 列号 1 超出范围 0..-1

c++ - 如何使用 libpqxx API 同时插入数据? (PostgreSQL,线程)

sql - 比多个 SELECT 语句更好的方法?

database - 在 Django 中,如果使用原始 SQL 添加行,是否会使用列的默认值?

c++ - 如何返回 pqxx 连接并保存到其他变量中?

ruby-on-rails - rails : An efficient method to match subdomains in the database?

json - 使用动态键和 json 值构建 JSON 对象