Close a connection if PQexec returned NULL

This happens for Socket connections, not for TCP ones, where a result
containing an error is returned and correctly handled by pq_raise()

Closes ticket #196 but not #192: poll() still doesn't change the
connection closed.

Conflicts:

	NEWS
	psycopg/pqpath.c
This commit is contained in:
Daniele Varrazzo 2014-03-06 18:11:17 +00:00
parent ae67f353d2
commit c8ee04a9fa
2 changed files with 14 additions and 4 deletions

2
NEWS
View File

@ -22,6 +22,8 @@ What's new in psycopg 2.4.7
failing to connect (from :ticket:`#192` discussion).
- Don't segfault using poorly defined cursor subclasses which forgot to call
the superclass init (:ticket:`#195`).
- Mark the connection closed when a Socket connection is broken, as it
happens for TCP connections instead (:ticket:`#196`).
- Fixed overflow opening a lobject with an oid not fitting in a signed int
(:ticket:`#203`).
- Fixed possible segfault in named cursors creation.

View File

@ -388,12 +388,20 @@ pq_complete_error(connectionObject *conn, PGresult **pgres, char **error)
{
Dprintf("pq_complete_error: pgconn = %p, pgres = %p, error = %s",
conn->pgconn, *pgres, *error ? *error : "(null)");
if (*pgres != NULL)
if (*pgres != NULL) {
pq_raise(conn, NULL, *pgres);
else if (*error != NULL) {
PyErr_SetString(OperationalError, *error);
} else {
PyErr_SetString(OperationalError, "unknown error");
if (*error != NULL) {
PyErr_SetString(OperationalError, *error);
} else {
PyErr_SetString(OperationalError, "unknown error");
}
/* Trivia: with a broken socket connection PQexec returns NULL, so we
* end up here. With a TCP connection we get a pgres with an error
* instead, and the connection gets closed in the pq_raise call above
* (see ticket #196)
*/
conn->closed = 2;
}
IFCLEARPGRES(*pgres);
if (*error) {