summaryrefslogtreecommitdiff
path: root/psycopg/pqpath.c
diff options
context:
space:
mode:
authorJames Henstridge <james@jamesh.id.au>2008-01-10 18:14:44 +0000
committerJames Henstridge <james@jamesh.id.au>2008-01-10 18:14:44 +0000
commit729117af8ba7d60bb80b636db1866e521f2fd399 (patch)
treec63aa95fc1aa8087375c30830a69778c7f1d29a2 /psycopg/pqpath.c
parentd190d5918aed4757a79b0799679fecdaa92a234d (diff)
downloadpsycopg2-729117af8ba7d60bb80b636db1866e521f2fd399.tar.gz
* psycopg/connection_int.c (conn_close): fix for new
pq_abort_locked() prototype. (conn_switch_isolation_level): fix for new pq_abort_locked() prototype, and use pq_complete_error() to show error message. (conn_set_client_encoding): same here. * psycopg/pqpath.c (pq_execute_command_locked): remove static modifier. (pq_complete_error): same here. (pq_abort_locked): add pgres and error arguments. (pq_abort): call pq_abort_locked() to reduce code duplication.
Diffstat (limited to 'psycopg/pqpath.c')
-rw-r--r--psycopg/pqpath.c23
1 files changed, 7 insertions, 16 deletions
diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c
index b7daba7..49aac27 100644
--- a/psycopg/pqpath.c
+++ b/psycopg/pqpath.c
@@ -238,7 +238,7 @@ pq_clear_async(connectionObject *conn)
On error, -1 is returned, and the pgres argument will hold the
relevant result structure.
*/
-static int
+int
pq_execute_command_locked(connectionObject *conn, const char *query,
PGresult **pgres, char **error)
{
@@ -280,7 +280,7 @@ pq_execute_command_locked(connectionObject *conn, const char *query,
This function should be called while holding the global interpreter
lock.
*/
-static void
+void
pq_complete_error(connectionObject *conn, PGresult **pgres, char **error)
{
Dprintf("pq_complete_error: pgconn = %p, pgres = %p, error = %s",
@@ -375,11 +375,9 @@ pq_commit(connectionObject *conn)
}
int
-pq_abort_locked(connectionObject *conn)
+pq_abort_locked(connectionObject *conn, PGresult **pgres, char **error)
{
int retvalue = -1;
- PGresult *pgres = NULL;
- char *error = NULL;
Dprintf("pq_abort_locked: pgconn = %p, isolevel = %ld, status = %d",
conn->pgconn, conn->isolation_level, conn->status);
@@ -390,14 +388,10 @@ pq_abort_locked(connectionObject *conn)
}
pq_clear_async(conn);
- retvalue = pq_execute_command_locked(conn, "ROLLBACK", &pgres, &error);
-
- if (retvalue < 0)
- pq_set_critical(conn, NULL);
+ retvalue = pq_execute_command_locked(conn, "ROLLBACK", pgres, error);
+ if (retvalue == 0)
+ conn->status = CONN_STATUS_READY;
- IFCLEARPGRES(pgres);
- if (error)
- free(error);
return retvalue;
}
@@ -424,16 +418,13 @@ pq_abort(connectionObject *conn)
Py_BEGIN_ALLOW_THREADS;
pthread_mutex_lock(&conn->lock);
- pq_clear_async(conn);
- retvalue = pq_execute_command_locked(conn, "ROLLBACK", &pgres, &error);
+ retvalue = pq_abort_locked(conn, &pgres, &error);
pthread_mutex_unlock(&conn->lock);
Py_END_ALLOW_THREADS;
if (retvalue < 0)
pq_complete_error(conn, &pgres, &error);
- else
- conn->status = CONN_STATUS_READY;
return retvalue;
}