From 729117af8ba7d60bb80b636db1866e521f2fd399 Mon Sep 17 00:00:00 2001 From: James Henstridge Date: Thu, 10 Jan 2008 18:14:44 +0000 Subject: * 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. --- psycopg/pqpath.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'psycopg/pqpath.c') 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; } -- cgit v1.2.1