Revision 3454
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql_gen.py | ||
---|---|---|
469 | 469 |
''' |
470 | 470 |
return str_ |
471 | 471 |
|
472 |
### PL/pgSQL |
|
473 |
|
|
474 |
class ExcHandler(BasicObject): |
|
475 |
def __init__(self, exc, handler=None): |
|
476 |
if handler != None: handler = as_Code(handler) |
|
477 |
|
|
478 |
self.exc = exc |
|
479 |
self.handler = handler |
|
480 |
|
|
481 |
def to_str(self, db, body): |
|
482 |
body = as_Code(body) |
|
483 |
|
|
484 |
if self.handler != None: handler_str = '\n'+self.handler.to_str(db) |
|
485 |
else: handler_str = ' NULL;' |
|
486 |
|
|
487 |
str_ = '''\ |
|
488 |
BEGIN |
|
489 |
'''+body.to_str(db)+''' |
|
490 |
EXCEPTION |
|
491 |
WHEN '''+self.exc+''' THEN'''+handler_str+''' |
|
492 |
END;\ |
|
493 |
''' |
|
494 |
return str_ |
|
495 |
|
|
496 |
unique_violation_handler = ExcHandler('unique_violation') |
|
497 |
|
|
472 | 498 |
class RowExcIgnore(Code): |
473 | 499 |
def __init__(self, row_type, select_query, with_row, cols=None, |
474 | 500 |
exc='unique_violation', row_var='row'): |
Also available in: Unified diff
sql_gen.py: Added ExcHandler, unique_violation_handler