ネイティブ インターフェイス postgresql は、次のコマンドを提供します: 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