Revision 465
Added by Aaron Marcuse-Kubitza almost 13 years ago
lib/sql.py | ||
---|---|---|
126 | 126 |
try: return with_savepoint(db, lambda: insert(db, table, row)) |
127 | 127 |
except Exception, e: |
128 | 128 |
msg = str(e) |
129 |
match = re.search(r'duplicate key value violates unique constraint "' |
|
130 |
+table+'_(\w+)_index"', msg) |
|
131 |
if match: raise DuplicateKeyException(match.group(1), e) |
|
129 |
match = re.search(r'duplicate key value violates unique constraint ' |
|
130 |
r'"(([^\W_]+)_[^"]+)"', msg) |
|
131 |
if match: |
|
132 |
constraint, table = match.groups() |
|
133 |
try: cols = constraint_cols(db, table, constraint) |
|
134 |
except NotImplementedError: raise e |
|
135 |
else: raise DuplicateKeyException(cols[0], e) |
|
132 | 136 |
match = re.search(r'null value in column "(\w+)" violates not-null ' |
133 | 137 |
'constraint', msg) |
134 | 138 |
if match: raise NullValueException(match.group(1), e) |
Also available in: Unified diff
sql.py: Use constraint_cols() to determine DuplicateKeyException column in try_insert()