Use set_session instead of set_isolation_level where available

Avoid spurious queries as reported in psycopg2 ticket #125.
This commit is contained in:
Daniele Varrazzo 2012-12-02 23:51:26 +00:00
parent f9bcbc213e
commit fb24777200

View File

@ -52,6 +52,11 @@ class DB(TM, dbi_db.DB):
# connection, so we avoid to (re)initialize it risking errors.
conn = pool.getconn(self.dsn)
if init:
# use set_session where available as in these versions
# set_isolation_level generates an extra query.
if psycopg2.__version__ >= '2.4.2':
conn.set_session(isolation_level=int(self.tilevel))
else:
conn.set_isolation_level(int(self.tilevel))
conn.set_client_encoding(self.encoding)
for tc in self.typecasts: