[unixODBC-dev] RE: Bug in Postgres7.1 driver? - patch

Constantine Filin cfilin at intermedia.net
Wed Nov 23 04:05:22 GMT 2005

Hello -

The bug was confirmed by testing. 

If CC_connect exits because of empty query to the postgres backed fails
then it sets connection in state STATE_C2 so that even a call to
SQLDisconnect on such a handle does not close the socket.

Here's my patch for connection.c:

	if ( res == NULL || QR_get_status(res) != PGRES_EMPTY_QUERY) {
		mylog("got no result from the empty query.  (probably
database does not exist)\n");
		self->errornumber = CONNECTION_NO_SUCH_DATABASE;
		self->errormsg = "The database does not exist on the
server\nor user authentication failed.";
		if (res != NULL)
+                if( self->sock ) {
+                        SOCK_Destructor(self->sock);
+                        self->sock = NULL;
+                }
		return 0;
	if (res)


> -----Original Message-----
> From: Constantine Filin
> Sent: Tuesday, November 22, 2005 7:03 PM
> To: 'unixodbc-dev at easysoft.com'
> Subject: Bug in Postgres7.1 driver?
> Greetings -
> I have unixODBC version 2.2.9 with Postgres7.1 driver. Postgres
version is
> 8.0.1 running on Linux Fedora 2.
> When UnixODBC calls SQLDriverConnect() and from there CC_connect()
> function, unix odbc after a successful socket connection sends an
> query to the backend. That query sometimes fails despite the fact that
> postgres process has successfully started on the backend (this is also
> issue but not the bug I am reporting)
> When the empty query fails Postgres7.1 ODBC driver reports "The
> does not exist on the server or user authentication failed." and
> an error to the caller.
> The problem is that in such case ODBC driver does not close the SOCKET
> going to the postgres backend and that socket remains STALE in the
> without any reference to it and no way to close it. It can be seen in
> command output. The postgres server - meanwhile - keep the postgres
> process running for the connection until I send it a SIGTERM signal.
> How do I go about fixing it?
> Thanks
> -c

More information about the unixODBC-dev mailing list