Project

General

Profile

« Previous | Next » 

Revision 2191

sql.py: DbConn: Use internal autocommit handling instead of DB connection autocommit attr to avoid autocommits inside a savepoint

View differences:

lib/sql.py
183 183
            self.__db = module.connect(**db_config)
184 184
            
185 185
            # Configure connection
186
            self.db.autocommit = self.autocommit
187 186
            if self.serializable and not self.autocommit:
188 187
                self.db.set_session(isolation_level='SERIALIZABLE')
189 188
            if schemas != None:
......
197 196
    class DbCursor(Proxy):
198 197
        def __init__(self, outer):
199 198
            Proxy.__init__(self, outer.db.cursor())
199
            self.outer = outer
200 200
            self.query_results = outer.query_results
201 201
            self.query_lookup = None
202 202
            self.result = []
......
205 205
            self._is_insert = query.upper().find('INSERT') >= 0
206 206
            self.query_lookup = _query_lookup(query, params)
207 207
            try:
208
                try: return_value = self.inner.execute(query, params)
208
                try:
209
                    return_value = self.inner.execute(query, params)
210
                    self.outer.do_autocommit()
209 211
                finally: self.query = get_cur_query(self.inner)
210 212
            except Exception, e:
211 213
                _add_cursor_info(e, self, query, params)
......
292 294
            raise
293 295
        else:
294 296
            self.run_query('RELEASE SAVEPOINT '+savepoint)
297
            self.do_autocommit()
295 298
            return return_val
299
    
300
    def do_autocommit(self):
301
        '''Autocommits if outside savepoint'''
302
        assert self._savepoint >= 0
303
        if self.autocommit and self._savepoint == 0:
304
            self.log_debug('Autocommiting')
305
            self.db.commit()
296 306

  
297 307
connect = DbConn
298 308

  

Also available in: Unified diff