summaryrefslogtreecommitdiff
path: root/psycopg/connection_int.c
diff options
context:
space:
mode:
authorJames Henstridge <james@jamesh.id.au>2008-01-10 06:14:20 +0000
committerJames Henstridge <james@jamesh.id.au>2008-01-10 06:14:20 +0000
commitd190d5918aed4757a79b0799679fecdaa92a234d (patch)
treeaed99b834328b553b912486da5a1553cf28dd490 /psycopg/connection_int.c
parent5fe08ae83e07aef2c7f9a56962d1ef28acf58b4d (diff)
downloadpsycopg2-d190d5918aed4757a79b0799679fecdaa92a234d.tar.gz
2007-12-23 James Henstridge <james@jamesh.id.au>
* psycopg/pqpath.c (pq_execute_command_locked): add an error argument to hold an error when no PGresult is returned by PQexec, rather than using pq_set_critical(). (pq_complete_error): new function that converts the error returned by pq_execute_command_locked() to a Python exception. (pq_begin_locked): add error argument. (pq_commit): use pq_complete_error(). (pq_abort): use pq_complete_error(). (pq_abort_locked): always call pq_set_critical() on error, and clear the error message from pq_execute_command_locked(). (pq_execute): use pq_complete_error() to handle the error from pq_begin_locked(). * psycopg/pqpath.c (pq_begin): remove unused function. * psycopg/connection_type.c (psyco_conn_commit): if conn_commit() raises an error, just return NULL, since it is now setting an exception itself. (psyco_conn_rollback): same here. * psycopg/connection_int.c (conn_commit): don't drop GIL and lock connection before calling pq_commit(). (conn_rollback): same here. (conn_close): use pq_abort_locked(). (conn_switch_isolation_level): same here. (conn_set_client_encoding): same here. * psycopg/pqpath.h: add prototype for pq_abort_locked(). * psycopg/pqpath.c (pq_commit): convert function to run with GIL held, and handle errors appropriately. (pq_abort): same here. (pq_abort_locked): new function to abort a locked connection. 2007-12-22 James Henstridge <james@jamesh.id.au> * psycopg/pqpath.c (pq_raise): add a "pgres" argument so we can generate nice errors not related to a particular cursor. (pq_execute): use pq_begin_locked() rather than pq_begin(). Use pq_raise() to handle any errors from it. * psycopg/pqpath.c (pq_execute_command_locked): helper function used to execute a command-style query on a locked connection. (pq_begin_locked): a variant of pq_begin() that uses pq_execute_command_locked(). (pq_begin): rewrite to use pq_begin_locked().
Diffstat (limited to 'psycopg/connection_int.c')
-rw-r--r--psycopg/connection_int.c24
1 files changed, 3 insertions, 21 deletions
diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c
index 1906e82..94b762b 100644
--- a/psycopg/connection_int.c
+++ b/psycopg/connection_int.c
@@ -217,7 +217,7 @@ conn_close(connectionObject *self)
/* execute a forced rollback on the connection (but don't check the
result, we're going to close the pq connection anyway */
if (self->pgconn) {
- pq_abort(self);
+ pq_abort_locked(self);
PQfinish(self->pgconn);
Dprintf("conn_close: PQfinish called");
self->pgconn = NULL;
@@ -235,17 +235,8 @@ conn_commit(connectionObject *self)
{
int res;
- Py_BEGIN_ALLOW_THREADS;
- pthread_mutex_lock(&self->lock);
-
res = pq_commit(self);
self->mark++;
-
- pthread_mutex_unlock(&self->lock);
- Py_END_ALLOW_THREADS;
-
- if (res == -1)
- pq_resolve_critical(self, 0);
return res;
}
@@ -256,17 +247,8 @@ conn_rollback(connectionObject *self)
{
int res;
- Py_BEGIN_ALLOW_THREADS;
- pthread_mutex_lock(&self->lock);
-
res = pq_abort(self);
self->mark++;
-
- pthread_mutex_unlock(&self->lock);
- Py_END_ALLOW_THREADS;
-
- if (res == -1)
- pq_resolve_critical(self, 0);
return res;
}
@@ -286,7 +268,7 @@ conn_switch_isolation_level(connectionObject *self, int level)
/* if the current isolation level is > 0 we need to abort the current
transaction before changing; that all folks! */
if (self->isolation_level != level && self->isolation_level > 0) {
- res = pq_abort(self);
+ res = pq_abort_locked(self);
}
self->isolation_level = level;
self->mark++;
@@ -322,7 +304,7 @@ conn_set_client_encoding(connectionObject *self, char *enc)
/* abort the current transaction, to set the encoding ouside of
transactions */
- res = pq_abort(self);
+ res = pq_abort_locked(self);
if (res == 0) {
pgres = PQexec(self->pgconn, query);