diff options
| author | Jan UrbaĆski <wulczer@wulczer.org> | 2010-03-31 01:53:59 +0200 |
|---|---|---|
| committer | Federico Di Gregorio <fog@initd.org> | 2010-04-05 16:25:17 +0200 |
| commit | 25a609c9a7379b758cd30f365e01d9601a67c37f (patch) | |
| tree | b6a09b289c7b6191858392f74486e3ae8242457e /psycopg/connection_int.c | |
| parent | b99eac18f8ff799f8ba109c7f440ec495806c8ad (diff) | |
| download | psycopg2-25a609c9a7379b758cd30f365e01d9601a67c37f.tar.gz | |
Handle initial connection queries being sent partly
The CONN_STATUS_SENT_* statuses were not being handled at all, and
they indicate that a query has been sent, but not fully, so the client
should wait for the socket to become writable again and flush the output.
Diffstat (limited to 'psycopg/connection_int.c')
| -rw-r--r-- | psycopg/connection_int.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c index 0fce84d..baca47f 100644 --- a/psycopg/connection_int.c +++ b/psycopg/connection_int.c @@ -387,7 +387,7 @@ conn_connect(connectionObject *self, long int async) PyObject * conn_poll_send(connectionObject *self) { - const char *query; + const char *query = NULL; int next_status; int ret; @@ -404,6 +404,12 @@ conn_poll_send(connectionObject *self) query = psyco_client_encoding; next_status = CONN_STATUS_SENT_CLIENT_ENCODING; break; + case CONN_STATUS_SENT_DATESTYLE: + case CONN_STATUS_SENT_CLIENT_ENCODING: + /* the query has only been partially sent */ + query = NULL; + next_status = self->status; + break; default: /* unexpected state, error out */ PyErr_Format(OperationalError, @@ -416,12 +422,14 @@ conn_poll_send(connectionObject *self) Py_BEGIN_ALLOW_THREADS; pthread_mutex_lock(&(self->lock)); - if (PQsendQuery(self->pgconn, query) != 1) { - pthread_mutex_unlock(&(self->lock)); - Py_BLOCK_THREADS; - PyErr_SetString(OperationalError, - PQerrorMessage(self->pgconn)); - return NULL; + if (query != NULL) { + if (PQsendQuery(self->pgconn, query) != 1) { + pthread_mutex_unlock(&(self->lock)); + Py_BLOCK_THREADS; + PyErr_SetString(OperationalError, + PQerrorMessage(self->pgconn)); + return NULL; + } } if (PQflush(self->pgconn) == 0) { |
