Revision 2720
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
801 | 801 |
BEGIN |
802 | 802 |
-- Insert the value and error for *each* source column. |
803 | 803 |
INSERT INTO '''+errors_table.to_str(db)+''' |
804 |
("column", value, error) |
|
804 |
("column", value, error_code, error)
|
|
805 | 805 |
SELECT * |
806 | 806 |
FROM (VALUES '''+(', '.join(('('+c.to_str(db)+')' for c in cols)) |
807 | 807 |
)+''') AS c |
808 |
CROSS JOIN (VALUES (value, SQLERRM)) AS v |
|
808 |
CROSS JOIN (VALUES (value, SQLSTATE, SQLERRM)) AS v
|
|
809 | 809 |
; |
810 | 810 |
EXCEPTION |
811 | 811 |
WHEN unique_violation THEN NULL; -- ignore duplicate key |
bin/csv2db | ||
---|---|---|
122 | 122 |
|
123 | 123 |
log('Creating errors table') |
124 | 124 |
errors_table = table+'.errors' |
125 |
typed_cols = [sql_gen.TypedCol('column', 'text NOT NULL'), |
|
125 |
typed_cols = [ |
|
126 |
sql_gen.TypedCol('column', 'text NOT NULL'), |
|
126 | 127 |
sql_gen.TypedCol('value', 'text'), |
127 |
sql_gen.TypedCol('error', 'text NOT NULL')] |
|
128 |
sql_gen.TypedCol('error_code', 'character varying(5) NOT NULL'), |
|
129 |
sql_gen.TypedCol('error', 'text NOT NULL'), |
|
130 |
] |
|
128 | 131 |
sql.create_table(db, errors_table, typed_cols, has_pkey=False) |
129 |
index_cols = ['column', sql_gen.EnsureNotNull('value'), 'error'] |
|
132 |
index_cols = ['column', sql_gen.EnsureNotNull('value'), 'error_code', |
|
133 |
'error'] |
|
130 | 134 |
sql.add_index(db, index_cols, errors_table, unique=True) |
131 | 135 |
db.db.commit() |
132 | 136 |
|
Also available in: Unified diff
sql.py: cast(): Made errors table also store SQLSTATE in error_code column