如何在多线程C应用程序中连接到postgresql

时间:2021-10-14 21:02:45

I have a few threads in my application. Each has its own PGconn* connection that is individually opened with the same connection string. When a thread makes a query, it almost never returns PGRES_TUPLES_OK.

我的应用程序中有几个线程。每个都有自己的PGconn *连接,使用相同的连接字符串单独打开。当一个线程进行查询时,它几乎永远不会返回PGRES_TUPLES_OK。

I can provide some code examples if necessary, but does anything stand out here? I have tried using global mutexes as well, to no avail. I am using postgresql 9.3

如有必要,我可以提供一些代码示例,但这里有什么突出的东西吗?我也试过使用全局互斥锁,但无济于事。我正在使用postgresql 9.3

PQerrorMessage(db) returns: connection pointer is NULL

PQerrorMessage(db)返回:连接指针为NULL

From the postgresql documentation: If a null pointer is returned, it should be treated like a PGRES_FATAL_ERROR result. Use PQerrorMessage to get more information about the error.

从postgresql文档:如果返回空指针,则应将其视为PGRES_FATAL_ERROR结果。使用PQerrorMessage获取有关错误的更多信息。

1 个解决方案

#1


0  

Ok, I figured it out.

好的,我明白了。

I was using a function to open each connection, and was passing a pointer to a PGconn struct to it.

我正在使用一个函数来打开每个连接,并将指向PGconn结构的指针传递给它。

I needed to pass a double pointer.

我需要传递一个双指针。

#1


0  

Ok, I figured it out.

好的,我明白了。

I was using a function to open each connection, and was passing a pointer to a PGconn struct to it.

我正在使用一个函数来打开每个连接,并将指向PGconn结构的指针传递给它。

I needed to pass a double pointer.

我需要传递一个双指针。