Project

General

Profile

« Previous | Next » 

Revision 2143

sql.py: with_parsed_errors(): Also parse "table name specified more than once" errors as DuplicateTableExceptions

View differences:

lib/sql.py
28 28
        exc.ExceptionWithCause.__init__(self, msg, cause)
29 29
        if cur != None: _add_cursor_info(self, cur)
30 30

  
31
class NameException(DbException): pass
31
class ExceptionWithName(DbException):
32
    def __init__(self, name, cause=None):
33
        DbException.__init__(self, 'name: '+str(name), cause)
34
        self.name = name
32 35

  
33 36
class ExceptionWithColumns(DbException):
34 37
    def __init__(self, cols, cause=None):
35
        DbException.__init__(self, 'columns: ' + ', '.join(cols), cause)
38
        DbException.__init__(self, 'columns: '+(', '.join(cols)), cause)
36 39
        self.cols = cols
37 40

  
41
class NameException(DbException): pass
42

  
38 43
class DuplicateKeyException(ExceptionWithColumns): pass
39 44

  
40 45
class NullValueException(ExceptionWithColumns): pass
41 46

  
47
class DuplicateTableException(ExceptionWithName): pass
48

  
42 49
class EmptyRowException(DbException): pass
43 50

  
44 51
##### Warnings
......
615 622
        match = re.search(r'null value in column "(\w+)" violates not-null '
616 623
            'constraint', msg)
617 624
        if match: raise NullValueException([match.group(1)], e)
625
        match = re.search(r'table name "(\w+)" specified more than once', msg)
626
        if match: raise DuplicateTableException(match.group(1), e)
618 627
        raise # no specific exception raised
619 628

  
620 629
def try_insert(db, table, row, returning=None):

Also available in: Unified diff