Project

General

Profile

« Previous | Next » 

Revision 3465

sql_io.py: data_exception_handler(): Refactored to use sql_gen.RowExcIgnore

View differences:

lib/sql_io.py
48 48
    if save_errors:
49 49
        errors_table_cols = map(sql_gen.Col,
50 50
            ['column', 'value', 'error_code', 'error'])
51
        col_names_query = sql.mk_select(db, sql_gen.NamedValues('c', None,
52
            [[c.name] for c in srcs]), order_by=None)
53
        insert_query = sql.mk_insert_select(db, errors_table, errors_table_cols,
54
            sql_gen.Values(errors_table_cols).to_str(db))+';\n'
51 55
        handler += '''\
52 56
-- Save error in errors table.
53 57
DECLARE
54 58
    error_code text := SQLSTATE;
55 59
    error text := SQLERRM;
56
    "column" text;
57 60
BEGIN
58 61
    -- Insert the value and error for *each* source column.
59
    FOR "column" IN
60
'''+sql.mk_select(db, sql_gen.NamedValues('c', None, [[c.name] for c in srcs]),
61
    order_by=None)+'''
62
    LOOP
63
        BEGIN
64
'''+sql.mk_insert_select(db, errors_table, errors_table_cols,
65
    sql_gen.Values(errors_table_cols).to_str(db))+''';
66
        EXCEPTION
67
            WHEN unique_violation THEN NULL; -- continue to next row
68
        END;
69
    END LOOP;
62
'''+sql_gen.RowExcIgnore('text', col_names_query, insert_query,
63
    row_var=errors_table_cols[0]).to_str(db)+'''
70 64
END;
71 65
'''
72 66
    else:

Also available in: Unified diff