mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-12 07:10: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
f597c36f42
commit
d1e1243ba8
2
NEWS
2
NEWS
|
@ -10,6 +10,8 @@ What's new in psycopg 2.5.3
|
||||||
Adam Petrovich for the bug report and diagnosis.
|
Adam Petrovich for the bug report and diagnosis.
|
||||||
- Don't segfault using poorly defined cursor subclasses which forgot to call
|
- Don't segfault using poorly defined cursor subclasses which forgot to call
|
||||||
the superclass init (:ticket:`#195`).
|
the superclass init (:ticket:`#195`).
|
||||||
|
- Mark the connection closed when a Socket connection is broken, as it
|
||||||
|
happens for TCP connections instead (:ticket:`#196`).
|
||||||
- It is now possible to call `get_transaction_status()` on closed connections.
|
- It is now possible to call `get_transaction_status()` on closed connections.
|
||||||
- Fixed debug build on Windows, thanks to James Emerton.
|
- 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);
|
pq_raise(conn, NULL, pgres);
|
||||||
/* now *pgres is null */
|
/* now *pgres is null */
|
||||||
}
|
}
|
||||||
else if (*error != NULL) {
|
else {
|
||||||
|
if (*error != NULL) {
|
||||||
PyErr_SetString(OperationalError, *error);
|
PyErr_SetString(OperationalError, *error);
|
||||||
} else {
|
} else {
|
||||||
PyErr_SetString(OperationalError, "unknown error");
|
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) {
|
if (*error) {
|
||||||
free(*error);
|
free(*error);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user