conn_commit/conn_rollback error handling (closes: #187).

This commit is contained in:
Federico Di Gregorio 2007-05-29 08:43:34 +00:00
parent a07987cd90
commit 46668d214b
3 changed files with 36 additions and 7 deletions

View File

@ -1,5 +1,8 @@
2007-05-29 Federico Di Gregorio <fog@initd.org>
* Applied patch from mkz (ticket #187) to add error handling when calling
conn_commit() and conn_rollback(). Fixes #187.
* cursor.copy_expert() implementation by David Rushby (copy_expert set 5/5.)
* SQL validation refactor patch from David Rushby (copy_expert set 4/5.)

View File

@ -117,8 +117,11 @@ psyco_conn_commit(connectionObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "")) return NULL;
/* FIXME: check return status? */
conn_commit(self);
if (conn_commit(self) < 0) {
PyErr_SetString(OperationalError,
PQerrorMessage(self->pgconn));
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
@ -137,8 +140,11 @@ psyco_conn_rollback(connectionObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "")) return NULL;
/* FIXME: check return status? */
conn_rollback(self);
if (conn_rollback(self) < 0) {
PyErr_SetString(OperationalError,
PQerrorMessage(self->pgconn));
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
@ -167,8 +173,12 @@ psyco_conn_set_isolation_level(connectionObject *self, PyObject *args)
return NULL;
}
/* FIXME: check return status? */
conn_switch_isolation_level(self, level);
if (conn_switch_isolation_level(self, level) < 0) {
PyErr_SetString(OperationalError,
PQerrorMessage(self->pgconn));
return NULL;
}
Py_INCREF(Py_None);
return Py_None;

View File

@ -397,13 +397,29 @@ pq_execute(cursorObject *curs, const char *query, int async)
Py_BEGIN_ALLOW_THREADS;
pthread_mutex_lock(&(curs->conn->lock));
pq_begin(curs->conn);
if (pq_begin(curs->conn) < 0) {
pthread_mutex_unlock(&(curs->conn->lock));
Py_BLOCK_THREADS;
PyErr_SetString(OperationalError,
PQerrorMessage(curs->conn->pgconn));
return -1;
}
if (async == 0) {
IFCLEARPGRES(curs->pgres);
Dprintf("pq_execute: executing SYNC query:");
Dprintf(" %-.200s", query);
curs->pgres = PQexec(curs->conn->pgconn, query);
/* dont let pgres = NULL go to pq_fetch() */
/* if (curs->pgres == NULL) {
pthread_mutex_unlock(&(curs->conn->lock));
Py_BLOCK_THREADS;
PyErr_SetString(OperationalError,
PQerrorMessage(curs->conn->pgconn));
return -1;
}
*/
}
else if (async == 1) {