PostgreSQL通知处理
我正在开发一个 C 应用程序,该应用程序应该与 PostgreSQL 对话。现在我需要处理服务器发送的通知和警告,但我不知道如何使其工作。
(非常不清楚)文档说我们应该使用PQsetNoticeReceiver 将方法设置为通知接收者,因为默认接收者只是将通知转发到 PQnoticeProcessor 并将其打印到 stderr。
因此,我定义了一个方法
static void noticeReceiver(void *arg, const PGresult *res)
,并将其设置为启动时的默认通知接收器,因此
PQsetNoticeReceiver(conn, noticeReceiver, NULL);
在我的方法实现中,我只是将一些随机字符打印到屏幕上,但它不会被调用。逐步调试表明它被设置为默认通知接收器但从未被调用。
有什么想法吗?
I'm working on a C application that is suppose to talk to PostgreSQL. Right now I need to handle notices and warnings sent by the server but I'm at a loss on how to make it work.
The (very unclear) documentation says we should use PQsetNoticeReceiver to set a method as the receiver of notifications, as the default receiver just forwards the notification to PQnoticeProcessor and this prints to stderr.
I've defined a method thus
static void noticeReceiver(void *arg, const PGresult *res)
and I'm setting it as the default notice receiver on startup thus
PQsetNoticeReceiver(conn, noticeReceiver, NULL);
In my method implementation I'm simply printing some random characters to screen but it doesn't get called. Step by step debugging shows that its being set as the default notice receiver but its never called.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我看到它不起作用的唯一方法是如果您在设置接收器后更改连接。请记住,接收器是连接的一个参数,因此如果您断开连接并重新连接,它就会消失。
这有效:
The only way I could see it not working is if you change the connection after setting the receiver. Keep in mind that the receiver is a parameter of the connection, so if you disconnect and reconnect it would go away.
This works: