Project

General

Profile

« Previous | Next » 

Revision 3455

sql_gen.py: RowExcIgnore: Changed exc param to exc_handler to allow user to specify handler code for the exception

View differences:

lib/sql_gen.py
497 497

  
498 498
class RowExcIgnore(Code):
499 499
    def __init__(self, row_type, select_query, with_row, cols=None,
500
        exc='unique_violation', row_var='row'):
500
        exc_handler=unique_violation_handler, row_var='row'):
501 501
        Code.__init__(self, lang='plpgsql')
502 502
        
503 503
        select_query = as_Code(select_query)
......
508 508
        self.select_query = select_query
509 509
        self.with_row = with_row
510 510
        self.cols = cols
511
        self.exc = exc
511
        self.exc_handler = exc_handler
512 512
        self.row_var = row_var
513 513
    
514 514
    def to_str(self, db):
......
530 530
    FOR '''+(', '.join((v.to_str(db) for v in row_vars)))+''' IN
531 531
'''+self.select_query.to_str(db)+'''
532 532
    LOOP
533
        BEGIN
534
'''+self.with_row.to_str(db)+'''
535
        EXCEPTION
536
            WHEN '''+self.exc+''' THEN NULL; -- continue to next row
537
        END;
533
'''+self.exc_handler.to_str(db, self.with_row)+'''
538 534
    END LOOP;
539 535
END;\
540 536
'''

Also available in: Unified diff