Project

General

Profile

« Previous | Next » 

Revision 3025

sql.py: run_query(): Always parse exceptions, whether recover is set or not, to avoid making the caller set recover just to parse exceptions. If recover is not set, just don't run any queries when generating the parsed exception and return an empty value for the needed information. (A partial parsed exception is better than an unparsed one.)

View differences:

lib/sql.py
436 436
                return with_savepoint(db, run)
437 437
            else: return run() # don't need savepoint if cached
438 438
        except Exception, e:
439
            if not recover: raise # need savepoint to run index_cols()
440 439
            msg = exc.str_(e)
441 440
            
442 441
            match = re.search(r'duplicate key value violates unique constraint '
443 442
                r'"((_?[^\W_]+)_.+?)"', msg)
444 443
            if match:
445 444
                constraint, table = match.groups()
446
                try: cols = index_cols(db, table, constraint)
447
                except NotImplementedError: raise e
448
                else: raise DuplicateKeyException(constraint, cols, e)
445
                cols = []
446
                if recover: # need auto-rollback to run index_cols()
447
                    try: cols = index_cols(db, table, constraint)
448
                    except NotImplementedError: pass
449
                raise DuplicateKeyException(constraint, cols, e)
449 450
            
450 451
            match = re.search(r'null value in column "(.+?)" violates not-null'
451 452
                r' constraint', msg)

Also available in: Unified diff