summaryrefslogtreecommitdiff
path: root/psycopg/connection_int.c
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2017-02-04 13:24:41 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2017-02-04 13:26:43 +0000
commitc60682c230f8e9ef6a395be55409d549fa5d7239 (patch)
treea92f4569369c2a9c1cb2b7690c7f7ef1ab7109df /psycopg/connection_int.c
parent8527144173f9679b2779c71d4dbdfa0571e4bd40 (diff)
downloadpsycopg2-c60682c230f8e9ef6a395be55409d549fa5d7239.tar.gz
Reuse set_session to implement autocommit, set_isolation_level
Diffstat (limited to 'psycopg/connection_int.c')
-rw-r--r--psycopg/connection_int.c66
1 files changed, 17 insertions, 49 deletions
diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c
index da80b3a..0cb4cf3 100644
--- a/psycopg/connection_int.c
+++ b/psycopg/connection_int.c
@@ -1180,68 +1180,36 @@ conn_rollback(connectionObject *self)
return res;
}
-int
-conn_set_autocommit(connectionObject *self, int value)
-{
- Py_BEGIN_ALLOW_THREADS;
- pthread_mutex_lock(&self->lock);
-
- self->autocommit = value;
-
- pthread_mutex_unlock(&self->lock);
- Py_END_ALLOW_THREADS;
-
- return 0;
-}
-
-
-/* Promote an isolation level to one of the levels supported by the server */
-
-static int
-_adjust_isolevel(connectionObject *self, int level) {
- if (self->server_version < 80000) {
- if (level == ISOLATION_LEVEL_READ_UNCOMMITTED) {
- level = ISOLATION_LEVEL_READ_COMMITTED;
- }
- else if (level == ISOLATION_LEVEL_REPEATABLE_READ) {
- level = ISOLATION_LEVEL_SERIALIZABLE;
- }
- }
- return level;
-}
-
/* Change the state of the session */
RAISES_NEG int
conn_set_session(connectionObject *self, int autocommit,
int isolevel, int readonly, int deferrable)
{
- isolevel = _adjust_isolevel(self, isolevel);
+ /* Promote an isolation level to one of the levels supported by the server */
+ if (self->server_version < 80000) {
+ if (isolevel == ISOLATION_LEVEL_READ_UNCOMMITTED) {
+ isolevel = ISOLATION_LEVEL_READ_COMMITTED;
+ }
+ else if (isolevel == ISOLATION_LEVEL_REPEATABLE_READ) {
+ isolevel = ISOLATION_LEVEL_SERIALIZABLE;
+ }
+ }
+
+ Py_BEGIN_ALLOW_THREADS;
+ pthread_mutex_lock(&self->lock);
self->isolevel = isolevel;
self->readonly = readonly;
self->deferrable = deferrable;
self->autocommit = autocommit;
- return 0;
-}
-
-
-/* conn_switch_isolation_level - switch isolation level on the connection */
-
-RAISES_NEG int
-conn_switch_isolation_level(connectionObject *self, int level)
-{
- if (level == 0) {
- self->autocommit = 1;
- }
- else {
- level = _adjust_isolevel(self, level);
- self->isolevel = level;
- self->autocommit = 0;
- }
+ pthread_mutex_unlock(&self->lock);
+ Py_END_ALLOW_THREADS;
- Dprintf("conn_switch_isolation_level: switched to level %d", level);
+ Dprintf(
+ "conn_set_session: autocommit %d, isolevel %d, readonly %d, deferrable %d",
+ autocommit, isolevel, readonly, deferrable);
return 0;
}