Project

General

Profile

« Previous | Next » 

Revision 3529

sql_gen.py: RowExcIgnore: If a custom row_var is used, require it to already be defined. This also allows sql_io.ExcToErrorsTable to place the column var definition in the outer DECLARE, eliminating the extra DECLARE block.

View differences:

lib/sql_gen.py
668 668
class RowExcIgnore(Code):
669 669
    def __init__(self, row_type, select_query, with_row, cols=None,
670 670
        exc_handler=unique_violation_handler, row_var=row_var):
671
        '''
672
        @param row_type Ignored if a custom row_var is used.
673
        @pre If a custom row_var is used, it must already be defined.
674
        '''
671 675
        Code.__init__(self, lang='plpgsql')
672 676
        
673 677
        row_type = as_Code(row_type)
......
695 699
        # (http://www.postgresql.org/docs/8.3/static/\
696 700
        # plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING)
697 701
        str_ = '''\
702
FOR '''+(', '.join((v.to_str(db) for v in row_vars)))+''' IN
703
'''+strings.indent(self.select_query.to_str(db))+'''\
704
LOOP
705
'''+strings.indent(self.exc_handler.to_str(db, self.with_row))+'''\
706
END LOOP;
707
'''
708
        if self.row_var is row_var:
709
            str_ = '''\
698 710
DECLARE
699 711
    '''+self.row_var.to_str(db)+''' '''+self.row_type.to_str(db)+''';
700 712
BEGIN
701
    FOR '''+(', '.join((v.to_str(db) for v in row_vars)))+''' IN
702
'''+strings.indent(self.select_query.to_str(db), 2)+'''\
703
    LOOP
704
'''+strings.indent(self.exc_handler.to_str(db, self.with_row), 2)+'''\
705
    END LOOP;
706
END;\
713
'''+strings.indent(str_)+'''\
714
END;
707 715
'''
708 716
        return str_
709 717

  
lib/sql_io.py
72 72
    error_code text := SQLSTATE;
73 73
    error text := SQLERRM;
74 74
    value text := '''+self.value.to_str(db)+''';
75
    "column" text;
75 76
BEGIN
76 77
    -- Insert the value and error for *each* source column.
77
'''+strings.indent(sql_gen.RowExcIgnore('text', col_names_query, insert_query,
78
'''+strings.indent(sql_gen.RowExcIgnore(None, col_names_query, insert_query,
78 79
    row_var=errors_table_cols[0]).to_str(db))+'''
79 80
END;
80 81

  

Also available in: Unified diff