随机消失的结构

发布于 2024-08-13 00:45:17 字数 405 浏览 11 评论 0原文

我创建了一个 Objective-C 类来使用 libpq 与 PostgreSQL 交互。它基本上可以工作,但我有一个小问题 - 连接似乎随机消失。

此类设置为在打开窗口时打开连接,并在窗口关闭之前关闭该连接。在窗口的初始化代码中,我打开连接并监听通知,以便可以使用 PQfinnish() 关闭连接。

现在,如果我打开该窗口,我可以运行任意数量的查询。但如果我关闭它并再次打开它,我会收到 EXC_BAD_ACCESS 错误。该错误似乎在 libpq 内部,但我不知道我做错了什么 - 没有可遵循的示例,这使得遵循模式变得有点困难。

我相信连接对象似乎有问题,但我无法准确找出问题所在,因为所有诊断函数似乎都返回正确的值。

Postgresql 8.0,运行在最新的 OS X、最新的 Xcode 和目标为 10.5 的项目上

I've created a Objective-C class to interface with PostgreSQL using libpq. It mostly works but I have one small problem - the connection seems to disappear randomly.

This class is set to open a connection when a window is opened and close that connection before the window closes. On the init code of the window I open the connection and I listen to notifications so I can close the connection with PQfinnish().

Now if I open that window, I can run as many queries as I want. But if I close it and open it again I get an EXC_BAD_ACCESS error. The error seems to be inside libpq but I've no idea what I'm doing wrong - there's no examples to follow which makes it a bit harder to follow patterns.

I believe there seems to be a problem with the connection object but I can't find out exactly what as all diagnostic functions seem to be returning the right values.

Postgresql 8.0, running on latest OS X, latest Xcode and project targeted at 10.5

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

能否归途做我良人 2024-08-20 00:45:17

找到答案:

崩溃的代码是从通知触发的事件中调用的。崩溃是因为我在关闭窗口时没有从通知中心取消注册该类。

我现在从中心取消注册该课程,一切正常。

但不知道为什么问题会反映在连接对象上。

Found the answer:

The code that crashed was called from an event that was fired from a notification. The crash came because I wasn't unregistering that class from the notification centre when closing the window.

I now unregister that class from the centre and all works well.

No idea why the problem reflected itself on the connection object, though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文