Make asynchronous connections always use autocommit

Clients using async connections are expected to do their own
transaction management by sending (asynchronously) BEGIN and COMMIT
statements.
As a bonus, it allows to drop one step from the async connection
building, namely getting the default isolation level from the server.
This commit is contained in:
Jan Urbański 2010-03-31 01:38:46 +02:00 committed by Federico Di Gregorio
parent 062a9602ae
commit d8ab5ac8a1
3 changed files with 6 additions and 19 deletions

View File

@ -48,9 +48,6 @@ extern "C" {
#define CONN_STATUS_SEND_CLIENT_ENCODING 8
#define CONN_STATUS_SENT_CLIENT_ENCODING 9
#define CONN_STATUS_GET_CLIENT_ENCODING 10
#define CONN_STATUS_SEND_TRANSACTION_ISOLATION 11
#define CONN_STATUS_SENT_TRANSACTION_ISOLATION 12
#define CONN_STATUS_GET_TRANSACTION_ISOLATION 13
/* async query execution status */
#define ASYNC_READ 1

View File

@ -404,11 +404,6 @@ conn_poll_send(connectionObject *self)
query = psyco_client_encoding;
next_status = CONN_STATUS_SENT_CLIENT_ENCODING;
break;
case CONN_STATUS_SEND_TRANSACTION_ISOLATION:
/* get the default isolevel */
query = psyco_transaction_isolation;
next_status = CONN_STATUS_SENT_TRANSACTION_ISOLATION;
break;
default:
/* unexpected state, error out */
PyErr_Format(OperationalError,
@ -444,9 +439,6 @@ conn_poll_send(connectionObject *self)
case CONN_STATUS_SENT_CLIENT_ENCODING:
next_status = CONN_STATUS_GET_CLIENT_ENCODING;
break;
case CONN_STATUS_SENT_TRANSACTION_ISOLATION:
next_status = CONN_STATUS_GET_TRANSACTION_ISOLATION;
break;
}
}
else {
@ -526,17 +518,17 @@ conn_poll_fetch(connectionObject *self)
return NULL;
}
Dprintf("conn_poll_fetch: got client_encoding %s", self->encoding);
next_status = CONN_STATUS_SEND_TRANSACTION_ISOLATION;
}
else if (self->status == CONN_STATUS_GET_TRANSACTION_ISOLATION) {
/* got the default isolevel */
self->isolation_level = conn_get_isolation_level(pgres);
Dprintf("conn_poll_fetch: got isolevel %ld", self->isolation_level);
/* since this is the last step, set the other instance variables now */
self->equote = conn_get_standard_conforming_strings(self->pgconn);
self->protocol = conn_get_protocol_version(self->pgconn);
self->server_version = (int) PQserverVersion(self->pgconn);
/*
* asynchronous connections always use isolation level 0, the user is
* expected to manage the transactions himself, by sending
* (asynchronously) BEGIN and COMMIT statements.
*/
self->isolation_level = 0;
Py_BEGIN_ALLOW_THREADS;
pthread_mutex_lock(&(self->lock));

View File

@ -421,14 +421,12 @@ psyco_conn_poll(connectionObject *self)
case CONN_STATUS_SEND_DATESTYLE:
case CONN_STATUS_SEND_CLIENT_ENCODING:
case CONN_STATUS_SEND_TRANSACTION_ISOLATION:
/* these mean that we need to wait for the socket to become writable
to send the rest of our query */
return conn_poll_send(self);
case CONN_STATUS_GET_DATESTYLE:
case CONN_STATUS_GET_CLIENT_ENCODING:
case CONN_STATUS_GET_TRANSACTION_ISOLATION:
/* these mean that we are waiting for the results of the queries */
return conn_poll_fetch(self);