mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-22 17:06:33 +03:00
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.
This commit is contained in:
parent
a31c1a1722
commit
696d123550
2
NEWS
2
NEWS
|
@ -27,6 +27,8 @@ What's new in psycopg 2.5.3
|
|||
(:ticket:`#203`).
|
||||
- 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 possible segfault in named cursors creation.
|
||||
- It is now possible to call `get_transaction_status()` on closed connections.
|
||||
- Fixed debug build on Windows, thanks to James Emerton.
|
||||
|
|
|
@ -417,11 +417,19 @@ pq_complete_error(connectionObject *conn, PGresult **pgres, char **error)
|
|||
pq_raise(conn, NULL, pgres);
|
||||
/* now *pgres is null */
|
||||
}
|
||||
else if (*error != NULL) {
|
||||
else {
|
||||
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;
|
||||
}
|
||||
|
||||
if (*error) {
|
||||
free(*error);
|
||||
|
|
Loading…
Reference in New Issue
Block a user