Reputation: 495
Native interface postgresql provides the following command:NOTIFY channel [ , payload ]
, where payload is variable string. I use library pqxx
for interaction with database. It provides notify_listener
interface. The callback which executed as notification have just one parameter - id
.
This is my code:
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;
};
How I can get the payload
content using pqxx
interface provided?
Upvotes: 1
Views: 465
Reputation: 495
Found the following in libpqxx 4.0.1 version:
// Obsolete notification receiver.
/** @deprecated Use notification_receiver instead.
*/
class PQXX_LIBEXPORT PQXX_NOVTABLE notify_listener
You should use notification receiver
class instead of notify_listener
Upvotes: 2