Revision 468
Added by Aaron Marcuse-Kubitza almost 13 years ago
lib/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) |
lib/db_xml.py | ||
---|---|---|
101 | 101 |
if store_ids: xml_dom.set_id(node, id_) |
102 | 102 |
break |
103 | 103 |
except sql.NullValueException, e: |
104 |
col = e.cols[0] |
|
104 | 105 |
if try_num > 0: raise # exception still raised after retry |
105 |
if store_ids and is_ptr(e.col):
|
|
106 |
if store_ids and is_ptr(col): |
|
106 | 107 |
# Search for required column in ancestors and their children |
107 |
target = find_by_name(node, ptr_type_guess(e.col))
|
|
108 |
target = find_by_name(node, ptr_type_guess(col)) |
|
108 | 109 |
if target == None: raise |
109 |
row[e.col] = xml_dom.get_id(target)
|
|
110 |
row[col] = xml_dom.get_id(target) |
|
110 | 111 |
else: raise |
111 | 112 |
except sql.DatabaseErrors, e: on_error_(e); return None |
112 | 113 |
|
Also available in: Unified diff
sql.py: ExceptionWithColumn now stores multiple columns so that they can all be used in DuplicateKeyExceptions