diff --git a/ChangeLog b/ChangeLog index e9881c9c..7f5ddbb2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2007-05-29 Federico Di Gregorio + * 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.) diff --git a/psycopg/connection_type.c b/psycopg/connection_type.c index ae737b57..4eb16805 100644 --- a/psycopg/connection_type.c +++ b/psycopg/connection_type.c @@ -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; diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c index 28cdde80..c568c694 100644 --- a/psycopg/pqpath.c +++ b/psycopg/pqpath.c @@ -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) {