summaryrefslogtreecommitdiff
path: root/psycopg/pqpath.c
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2017-02-04 02:25:48 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2017-02-04 02:38:56 +0000
commitc1e016e597e1ee2b52e5277a09793caa9401f39d (patch)
tree3719e64a5efcdbe66652e19a4e38d531ef2ba479 /psycopg/pqpath.c
parent9863637f309e1e89523007c40e9dcdde69f60bc0 (diff)
downloadpsycopg2-c1e016e597e1ee2b52e5277a09793caa9401f39d.tar.gz
Don't use default_transaction_* for session characteristics
Store the state in the connection object and set the params on BEGIN Some tests fail: a few can be fixed reading transaction_* instead of default_transaction_*; but the behaviour of tx characteristics with autocommit is effectively changed. It may be addressed by setting default_transaction_* if autocommit is set.
Diffstat (limited to 'psycopg/pqpath.c')
-rw-r--r--psycopg/pqpath.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c
index 328a2b2..8a4d78f 100644
--- a/psycopg/pqpath.c
+++ b/psycopg/pqpath.c
@@ -53,7 +53,9 @@
#endif
extern HIDDEN PyObject *psyco_DescriptionType;
-
+extern HIDDEN const char *srv_isolevels[];
+extern HIDDEN const char *srv_readonly[];
+extern HIDDEN const char *srv_deferrable[];
/* Strip off the severity from a Postgres error message. */
static const char *
@@ -479,6 +481,8 @@ int
pq_begin_locked(connectionObject *conn, PGresult **pgres, char **error,
PyThreadState **tstate)
{
+ const size_t bufsize = 256;
+ char buf[bufsize];
int result;
Dprintf("pq_begin_locked: pgconn = %p, autocommit = %d, status = %d",
@@ -489,7 +493,14 @@ pq_begin_locked(connectionObject *conn, PGresult **pgres, char **error,
return 0;
}
- result = pq_execute_command_locked(conn, "BEGIN", pgres, error, tstate);
+ snprintf(buf, bufsize, "BEGIN%s%s%s%s%s",
+ conn->server_version < 80000 ? ";SET TRANSACTION" : "",
+ (conn->isolevel >= 1 && conn->isolevel <= 4) ? " ISOLATION LEVEL " : "",
+ srv_isolevels[conn->isolevel],
+ srv_readonly[conn->readonly],
+ srv_deferrable[conn->deferrable]);
+
+ result = pq_execute_command_locked(conn, buf, pgres, error, tstate);
if (result == 0)
conn->status = CONN_STATUS_BEGIN;