From 4bb0c3bdf6c32bf01d8ae0aa51da9b69ef36b794 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Mon, 5 Apr 2010 02:16:58 +0100 Subject: [PATCH] Use the wait callback in the connection setup queries. --- psycopg/connection_int.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c index 24a86c1b..1d68c98a 100644 --- a/psycopg/connection_int.c +++ b/psycopg/connection_int.c @@ -256,9 +256,13 @@ conn_setup(connectionObject *self, PGconn *pgconn) self->equote = conn_get_standard_conforming_strings(pgconn); - Py_UNBLOCK_THREADS; - pgres = PQexec(pgconn, psyco_datestyle); - Py_BLOCK_THREADS; + if (!psyco_green()) { + Py_UNBLOCK_THREADS; + pgres = PQexec(pgconn, psyco_datestyle); + Py_BLOCK_THREADS; + } else { + pgres = psyco_exec_green(self, psyco_datestyle); + } if (pgres == NULL || PQresultStatus(pgres) != PGRES_COMMAND_OK ) { PyErr_SetString(OperationalError, "can't set datestyle to ISO"); @@ -270,9 +274,13 @@ conn_setup(connectionObject *self, PGconn *pgconn) } CLEARPGRES(pgres); - Py_UNBLOCK_THREADS; - pgres = PQexec(pgconn, psyco_client_encoding); - Py_BLOCK_THREADS; + if (!psyco_green()) { + Py_UNBLOCK_THREADS; + pgres = PQexec(pgconn, psyco_client_encoding); + Py_BLOCK_THREADS; + } else { + pgres = psyco_exec_green(self, psyco_client_encoding); + } if (pgres == NULL || PQresultStatus(pgres) != PGRES_TUPLES_OK) { PyErr_SetString(OperationalError, "can't fetch client_encoding"); @@ -292,9 +300,13 @@ conn_setup(connectionObject *self, PGconn *pgconn) return -1; } - Py_UNBLOCK_THREADS; - pgres = PQexec(pgconn, psyco_transaction_isolation); - Py_BLOCK_THREADS; + if (!psyco_green()) { + Py_UNBLOCK_THREADS; + pgres = PQexec(pgconn, psyco_transaction_isolation); + Py_BLOCK_THREADS; + } else { + pgres = psyco_exec_green(self, psyco_transaction_isolation); + } if (pgres == NULL || PQresultStatus(pgres) != PGRES_TUPLES_OK) { PyErr_SetString(OperationalError, @@ -379,11 +391,11 @@ conn_sync_connect(connectionObject *self) */ self->status = CONN_STATUS_READY; - if (conn_setup(self, self->pgconn) == -1) { + if (pq_set_non_blocking(self, 1, 1) != 0) { return -1; } - if (pq_set_non_blocking(self, 1, 1) != 0) { + if (conn_setup(self, self->pgconn) == -1) { return -1; }