Revision 3134
Added by Aaron Marcuse-Kubitza over 12 years ago
bin/csv2db | ||
---|---|---|
46 | 46 |
if level <= verbosity: sys.stderr.write(msg.rstrip('\n')+'\n') |
47 | 47 |
db = sql.connect(db_config, log_debug=log) |
48 | 48 |
|
49 |
def mk_errors_table(): |
|
50 |
log('Creating errors table') |
|
51 |
errors_table = sql_io.errors_table(db, table, if_exists=False) |
|
52 |
sql.drop_table(db, errors_table) |
|
53 |
typed_cols = [ |
|
54 |
sql_gen.TypedCol('column', 'text', nullable=False), |
|
55 |
sql_gen.TypedCol('value', 'text'), |
|
56 |
sql_gen.TypedCol('error_code', 'character varying(5)', |
|
57 |
nullable=False), |
|
58 |
sql_gen.TypedCol('error', 'text', nullable=False), |
|
59 |
] |
|
60 |
sql.create_table(db, errors_table, typed_cols, has_pkey=False) |
|
61 |
index_cols = ['column', 'value', 'error_code', 'error'] |
|
62 |
sql.add_index(db, index_cols, errors_table, unique=True) |
|
49 |
log('Creating errors table') |
|
50 |
errors_table = sql_io.errors_table(db, table, if_exists=False) |
|
51 |
sql.drop_table(db, errors_table) |
|
52 |
typed_cols = [ |
|
53 |
sql_gen.TypedCol('column', 'text', nullable=False), |
|
54 |
sql_gen.TypedCol('value', 'text'), |
|
55 |
sql_gen.TypedCol('error_code', 'character varying(5)', |
|
56 |
nullable=False), |
|
57 |
sql_gen.TypedCol('error', 'text', nullable=False), |
|
58 |
] |
|
59 |
sql.create_table(db, errors_table, typed_cols, has_pkey=False) |
|
60 |
index_cols = ['column', 'value', 'error_code', 'error'] |
|
61 |
sql.add_index(db, index_cols, errors_table, unique=True) |
|
63 | 62 |
|
64 | 63 |
use_copy_from = [True] |
65 | 64 |
|
... | ... | |
133 | 132 |
|
134 | 133 |
log('Reanalyzing table') |
135 | 134 |
sql.analyze(db, table) |
136 |
|
|
137 |
mk_errors_table() |
|
138 | 135 |
|
139 |
if errors_table_only: mk_errors_table() |
|
140 |
else: |
|
136 |
if not errors_table_only: |
|
141 | 137 |
try: load() |
142 | 138 |
except sql.DatabaseErrors, e: |
143 | 139 |
if use_copy_from[0]: # first try |
Also available in: Unified diff
csv2db: Create errors table first, so that imports can start using it right away