1

ネイティブ インターフェイス pos​​tgresql は、次のコマンドを提供します: NOTIFY channel [ , payload ]、ここで、ペイロードは可変文字列です。pqxxデータベースとのやり取りにはライブラリを使用します。インターフェイスを提供し notify_listenerます。通知として実行されるコールバックには、パラメーターが 1 つだけあります - 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;
};

提供されたインターフェイスpayloadを使用してコンテンツを取得するにはどうすればよいですか?pqxx

4

1 に答える 1

2

libpqxx 4.0.1 バージョンで以下を見つけました:

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

notification receiver代わりにクラスを使用する必要があります notify_listener

于 2015-12-24T13:50:26.633 に答える