comparison roundup/backends/back_postgresql.py @ 4887:05c857e5dbed

New rdbms configuration option 'isolation_level' See discussion in http://issues.roundup-tracker.org/issue2550806
author Ralf Schlatterbeck <rsc@runtux.com>
date Sun, 06 Apr 2014 11:11:04 +0200
parents 4a017661e414
children e74c3611b138
comparison
equal deleted inserted replaced
4886:a116de39e38c 4887:05c857e5dbed
6 # 6 #
7 '''Postgresql backend via psycopg for Roundup.''' 7 '''Postgresql backend via psycopg for Roundup.'''
8 __docformat__ = 'restructuredtext' 8 __docformat__ = 'restructuredtext'
9 9
10 import os, shutil, time 10 import os, shutil, time
11 ISOLATION_LEVEL_READ_UNCOMMITTED = None
12 ISOLATION_LEVEL_READ_COMMITTED = None
13 ISOLATION_LEVEL_REPEATABLE_READ = None
14 ISOLATION_LEVEL_SERIALIZABLE = None
11 try: 15 try:
12 import psycopg 16 import psycopg
13 from psycopg import QuotedString 17 from psycopg import QuotedString
14 from psycopg import ProgrammingError 18 from psycopg import ProgrammingError
19 TransactionRollbackError = ProgrammingError
20 try:
21 from psycopg.extensions import ISOLATION_LEVEL_READ_UNCOMMITTED
22 from psycopg.extensions import ISOLATION_LEVEL_READ_COMMITTED
23 from psycopg.extensions import ISOLATION_LEVEL_REPEATABLE_READ
24 from psycopg.extensions import ISOLATION_LEVEL_SERIALIZABLE
25 except ImportError:
26 pass
15 except: 27 except:
16 from psycopg2 import psycopg1 as psycopg 28 from psycopg2 import psycopg1 as psycopg
17 from psycopg2.extensions import QuotedString 29 from psycopg2.extensions import QuotedString
30 from psycopg2.extensions import ISOLATION_LEVEL_READ_UNCOMMITTED
31 from psycopg2.extensions import ISOLATION_LEVEL_READ_COMMITTED
32 from psycopg2.extensions import ISOLATION_LEVEL_REPEATABLE_READ
33 from psycopg2.extensions import ISOLATION_LEVEL_SERIALIZABLE
18 from psycopg2.psycopg1 import ProgrammingError 34 from psycopg2.psycopg1 import ProgrammingError
35 from psycopg2.extensions import TransactionRollbackError
19 import logging 36 import logging
20 37
21 from roundup import hyperdb, date 38 from roundup import hyperdb, date
22 from roundup.backends import rdbms_common 39 from roundup.backends import rdbms_common
23 from roundup.backends import sessions_rdbms 40 from roundup.backends import sessions_rdbms
41
42 isolation_levels = \
43 { 'read uncommitted': ISOLATION_LEVEL_READ_COMMITTED
44 , 'read committed': ISOLATION_LEVEL_READ_COMMITTED
45 , 'repeatable read': ISOLATION_LEVEL_REPEATABLE_READ
46 , 'serializable': ISOLATION_LEVEL_SERIALIZABLE
47 }
24 48
25 def connection_dict(config, dbnamestr=None): 49 def connection_dict(config, dbnamestr=None):
26 ''' read_default_group is MySQL-specific, ignore it ''' 50 ''' read_default_group is MySQL-specific, ignore it '''
27 d = rdbms_common.connection_dict(config, dbnamestr) 51 d = rdbms_common.connection_dict(config, dbnamestr)
28 if 'read_default_group' in d: 52 if 'read_default_group' in d:
143 conn = psycopg.connect(**db) 167 conn = psycopg.connect(**db)
144 except psycopg.OperationalError, message: 168 except psycopg.OperationalError, message:
145 raise hyperdb.DatabaseError(message) 169 raise hyperdb.DatabaseError(message)
146 170
147 cursor = conn.cursor() 171 cursor = conn.cursor()
172 if ISOLATION_LEVEL_REPEATABLE_READ is not None:
173 lvl = isolation_levels [self.config.RDBMS_ISOLATION_LEVEL]
174 conn.set_isolation_level(lvl)
148 175
149 return (conn, cursor) 176 return (conn, cursor)
150 177
151 def open_connection(self): 178 def open_connection(self):
152 if not db_exists(self.config): 179 if not db_exists(self.config):

Roundup Issue Tracker: http://roundup-tracker.org/