Revision 5449
Added by Aaron Marcuse-Kubitza about 12 years ago
lib/sql_io.py | ||
---|---|---|
466 | 466 |
log_debug('Ignoring all rows') |
467 | 467 |
ignore_all_ref[0] = True # just return the default value column |
468 | 468 |
|
469 |
def ignore_cond(cond, e): |
|
470 |
if is_literals: remove_all_rows() |
|
469 |
def ignore_cond(cond, e, passed=False, failed=False): |
|
470 |
if is_literals: # we know the constraint was applied exactly once |
|
471 |
if passed: pass |
|
472 |
elif failed: remove_all_rows() |
|
473 |
else: raise NotImplementedError() |
|
471 | 474 |
else: |
472 | 475 |
out_table_cols = sql_gen.ColDict(db, out_table) |
473 | 476 |
out_table_cols.update(util.dict_subset_right_join({}, |
... | ... | |
477 | 480 |
cond = sql_gen.map_expr(db, cond, mapping, in_cols) |
478 | 481 |
cond = sql_gen.map_expr(db, cond, out_table_cols) |
479 | 482 |
|
480 |
track_data_error(db, errors_table_, sql_gen.cols_srcs(in_cols), |
|
481 |
None, e.cause.pgcode, |
|
482 |
strings.ensure_newl(e.cause.pgerror)+'condition: '+cond) |
|
483 |
|
|
484 | 483 |
not_cond = sql_gen.NotCond(sql_gen.CustomCode(cond)) |
485 | 484 |
log_debug('Ignoring rows that do not satisfy '+strings.as_tt(cond)) |
486 |
assert cond != sql_gen.true_expr # we know the constraint failed |
|
487 |
if cond == sql_gen.false_expr: remove_all_rows() |
|
488 |
else: sql.delete(db, insert_in_table, not_cond) |
|
485 |
cur = None |
|
486 |
if cond == sql_gen.false_expr: |
|
487 |
assert failed |
|
488 |
remove_all_rows() |
|
489 |
elif cond == sql_gen.true_expr: assert passed |
|
490 |
else: cur = sql.delete(db, insert_in_table, not_cond) |
|
491 |
|
|
492 |
if failed or cur.rowcount > 0: # only if any rows failed cond |
|
493 |
track_data_error(db, errors_table_, sql_gen.cols_srcs(in_cols), |
|
494 |
None, e.cause.pgcode, |
|
495 |
strings.ensure_newl(e.cause.pgerror)+'condition: '+cond) |
|
489 | 496 |
|
490 | 497 |
not_null_cols = set() |
491 | 498 |
def ignore(in_col, value, e): |
... | ... | |
662 | 669 |
except sql.CheckException, e: |
663 | 670 |
log_exc(e) |
664 | 671 |
|
665 |
ignore_cond(e.cond, e) |
|
672 |
ignore_cond(e.cond, e, failed=True)
|
|
666 | 673 |
except sql.InvalidValueException, e: |
667 | 674 |
log_exc(e) |
668 | 675 |
|
Also available in: Unified diff
sql_io.py: put_table(): ignore_cond(): Added support for constraints that did not fail at least once, and therefore should not be required to simplify to a non-false value. As part of this, only track the failed constraint in the errors table if it actually failed at least once based on the deleted row count or the `failed` param.