Project

General

Profile

« Previous | Next » 

Revision 468

sql.py: ExceptionWithColumn now stores multiple columns so that they can all be used in DuplicateKeyExceptions

View differences:

sql.py
21 21

  
22 22
class NameException(DbException): pass
23 23

  
24
class ExceptionWithColumn(DbException):
25
    def __init__(self, col, cause=None):
26
        DbException.__init__(self, 'column: '+col, cause)
27
        self.col = col
24
class ExceptionWithColumns(DbException):
25
    def __init__(self, cols, cause=None):
26
        DbException.__init__(self, 'columns: ' + ', '.join(cols), cause)
27
        self.cols = cols
28 28

  
29
class DuplicateKeyException(ExceptionWithColumn): pass
29
class DuplicateKeyException(ExceptionWithColumns): pass
30 30

  
31
class NullValueException(ExceptionWithColumn): pass
31
class NullValueException(ExceptionWithColumns): pass
32 32

  
33 33
class EmptyRowException(DbException): pass
34 34

  
......
154 154
            if row_ct_ref != None and row_ct >= 0: row_ct_ref[0] += row_ct
155 155
            return last_insert_id(db)
156 156
        except DuplicateKeyException, e:
157
            return value(select(db, table, [pkey], {e.col: row[e.col]}))
157
            return value(select(db, table, [pkey],
158
                util.dict_subset(row, e.cols)))
158 159

  
159 160
def truncate(db, table):
160 161
    check_name(table)

Also available in: Unified diff