summaryrefslogtreecommitdiff
path: root/psycopg/connection_int.c
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2018-01-11 01:59:49 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2018-01-11 02:23:27 +0000
commit74d2c4bef934b855726961472ba662141d2e88c9 (patch)
tree8a7c5c02f6465b9939ad34fd690cb7dcb5ca6a6d /psycopg/connection_int.c
parent6da3e7ee69971cd6cb692765a4d66a5ce405f104 (diff)
downloadpsycopg2-74d2c4bef934b855726961472ba662141d2e88c9.tar.gz
Fixed idempotence check changing connection characteristics
Diffstat (limited to 'psycopg/connection_int.c')
-rw-r--r--psycopg/connection_int.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c
index e8081b9..3ea5ca3 100644
--- a/psycopg/connection_int.c
+++ b/psycopg/connection_int.c
@@ -67,6 +67,9 @@ const char *srv_state_guc[] = {
};
+const int SRV_STATE_UNCHANGED = -1;
+
+
/* Return a new "string" from a char* from the database.
*
* On Py2 just get a string, on Py3 decode it in the connection codec.
@@ -1188,6 +1191,8 @@ conn_set_session(connectionObject *self, int autocommit,
int rv = -1;
PGresult *pgres = NULL;
char *error = NULL;
+ int want_autocommit = autocommit == SRV_STATE_UNCHANGED ?
+ self->autocommit : autocommit;
if (deferrable != self->deferrable && self->server_version < 90100) {
PyErr_SetString(ProgrammingError,
@@ -1209,24 +1214,24 @@ conn_set_session(connectionObject *self, int autocommit,
Py_BEGIN_ALLOW_THREADS;
pthread_mutex_lock(&self->lock);
- if (autocommit) {
- /* we are in autocommit state, so no BEGIN will be issued:
+ if (want_autocommit) {
+ /* we are or are going in autocommit state, so no BEGIN will be issued:
* configure the session with the characteristics requested */
- if (isolevel != self->isolevel) {
+ if (isolevel != SRV_STATE_UNCHANGED) {
if (0 > pq_set_guc_locked(self,
"default_transaction_isolation", srv_isolevels[isolevel],
&pgres, &error, &_save)) {
goto endlock;
}
}
- if (readonly != self->readonly) {
+ if (readonly != SRV_STATE_UNCHANGED) {
if (0 > pq_set_guc_locked(self,
"default_transaction_read_only", srv_state_guc[readonly],
&pgres, &error, &_save)) {
goto endlock;
}
}
- if (deferrable != self->deferrable) {
+ if (deferrable != SRV_STATE_UNCHANGED) {
if (0 > pq_set_guc_locked(self,
"default_transaction_deferrable", srv_state_guc[deferrable],
&pgres, &error, &_save)) {
@@ -1260,10 +1265,18 @@ conn_set_session(connectionObject *self, int autocommit,
}
}
- self->autocommit = autocommit;
- self->isolevel = isolevel;
- self->readonly = readonly;
- self->deferrable = deferrable;
+ if (autocommit != SRV_STATE_UNCHANGED) {
+ self->autocommit = autocommit;
+ }
+ if (isolevel != SRV_STATE_UNCHANGED) {
+ self->isolevel = isolevel;
+ }
+ if (readonly != SRV_STATE_UNCHANGED) {
+ self->readonly = readonly;
+ }
+ if (deferrable != SRV_STATE_UNCHANGED) {
+ self->deferrable = deferrable;
+ }
rv = 0;
endlock: