Revision 2677
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
1185 | 1185 |
##### Data cleanup |
1186 | 1186 |
|
1187 | 1187 |
def cleanup_table(db, table, cols): |
1188 |
def esc_name_(name): return esc_name(db, name) |
|
1188 |
table = sql_gen.as_Table(table) |
|
1189 |
cols = map(sql_gen.as_Col, cols) |
|
1189 | 1190 |
|
1190 |
table = sql_gen.as_Table(table).to_str(db) |
|
1191 |
cols = map(esc_name_, cols) |
|
1191 |
expr = ('nullif(nullif(trim(both from %s), '+db.esc_value('')+'), ' |
|
1192 |
+db.esc_value(r'\N')+')') |
|
1193 |
changes = [(v, sql_gen.CustomCode(expr % v.to_str(db))) |
|
1194 |
for v in cols] |
|
1192 | 1195 |
|
1193 |
run_query(db, 'UPDATE '+table+' SET\n'+(',\n'.join(('\n'+col |
|
1194 |
+' = nullif(nullif(trim(both from '+col+"), %(null0)s), %(null1)s)" |
|
1195 |
for col in cols))), |
|
1196 |
dict(null0='', null1=r'\N')) |
|
1196 |
update(db, table, changes) |
Also available in: Unified diff
sql.py: cleanup_table(): Use update(), which also fixes some formatting bugs