Project

General

Profile

« Previous | Next » 

Revision 2801

sql.py: with_autocommit(): Use isolation_level attr and set_isolation_level() method of connection instead of autocommit attr to support older versions of psycopg2

View differences:

sql.py
333 333
    def is_cached(self, query): return query in self.query_results
334 334
    
335 335
    def with_autocommit(self, func, autocommit=True):
336
        prev_autocommit = self.db.autocommit
337
        self.db.autocommit = autocommit
336
        import psycopg2.extensions
337
        if autocommit:
338
            isolation_level = psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT
339
        else: isolation_level = psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE
340
        
341
        prev_isolation_level = self.db.isolation_level
342
        self.db.set_isolation_level(isolation_level)
338 343
        try: return func()
339
        finally: self.db.autocommit = prev_autocommit
344
        finally: self.db.set_isolation_level(prev_isolation_level)
340 345
    
341 346
    def with_savepoint(self, func):
342 347
        savepoint = 'level_'+str(self._savepoint)

Also available in: Unified diff