Revision 2240
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
39 | 39 |
DbException.__init__(self, 'for name: '+str(name), cause) |
40 | 40 |
self.name = name |
41 | 41 |
|
42 |
class ExceptionWithNameValue(DbException): |
|
43 |
def __init__(self, name, value, cause=None): |
|
44 |
DbException.__init__(self, |
|
45 |
'for name: '+str(name)+'; value: '+str(value), cause) |
|
46 |
self.name = name |
|
47 |
self.value = value |
|
48 |
|
|
42 | 49 |
class ExceptionWithColumns(DbException): |
43 | 50 |
def __init__(self, cols, cause=None): |
44 | 51 |
DbException.__init__(self, 'for columns: '+(', '.join(cols)), cause) |
... | ... | |
50 | 57 |
|
51 | 58 |
class NullValueException(ExceptionWithColumns): pass |
52 | 59 |
|
53 |
class FunctionValueException(ExceptionWithName): pass |
|
60 |
class FunctionValueException(ExceptionWithNameValue): pass
|
|
54 | 61 |
|
55 | 62 |
class DuplicateTableException(ExceptionWithName): pass |
56 | 63 |
|
... | ... | |
346 | 353 |
except Exception, e: |
347 | 354 |
if not recover: raise # need savepoint to run index_cols() |
348 | 355 |
msg = str(e) |
356 |
|
|
349 | 357 |
match = re.search(r'duplicate key value violates unique constraint ' |
350 | 358 |
r'"((_?[^\W_]+)_[^"]+)"', msg) |
351 | 359 |
if match: |
... | ... | |
353 | 361 |
try: cols = index_cols(db, table, constraint) |
354 | 362 |
except NotImplementedError: raise e |
355 | 363 |
else: raise DuplicateKeyException(cols, e) |
364 |
|
|
356 | 365 |
match = re.search(r'null value in column "(\w+)" violates not-null ' |
357 | 366 |
r'constraint', msg) |
358 | 367 |
if match: raise NullValueException([match.group(1)], e) |
359 |
match = re.search(r'invalid input value\b.*\n' |
|
368 |
|
|
369 |
match = re.search(r'invalid input value\b.*: "(\w+)"\n' |
|
360 | 370 |
r'CONTEXT:.*\bfunction "(\w+)".*\bat assignment', msg) |
361 |
if match: raise FunctionValueException(match.group(1), e) |
|
371 |
if match: |
|
372 |
raise FunctionValueException(match.group(2), match.group(1), e) |
|
373 |
|
|
362 | 374 |
match = re.search(r'relation "(\w+)" already exists', msg) |
363 | 375 |
if match: raise DuplicateTableException(match.group(1), e) |
376 |
|
|
364 | 377 |
match = re.search(r'function "(\w+)" already exists', msg) |
365 | 378 |
if match: raise DuplicateFunctionException(match.group(1), e) |
379 |
|
|
366 | 380 |
raise # no specific exception raised |
367 | 381 |
|
368 | 382 |
##### Basic queries |
Also available in: Unified diff
sql.py: run_query(): Parse "invalid input value at assignment" errors' values as well