Project

General

Profile

« Previous | Next » 

Revision 2403

sql.py: put_table(): FunctionValueException: Change invalid values to NULL using UPDATE instead of filtering them out using WHERE, to avoid adding lots of conditions to the SELECT statement

View differences:

lib/sql.py
859 859
    
860 860
    def log_exc(e):
861 861
        db.log_debug('Caught exception: '+exc.str_(e, first_line_only=True))
862
    def ignore(in_col, value):
862
    def log_ignore(in_col, value):
863 863
        db.log_debug('Ignoring rows with '+str(in_col)+' = '+repr(value))
864
    def remove_rows(in_col, value):
865
        log_ignore(in_col, value)
864 866
        cond = (in_col, sql_gen.CompareCond(value, '!='))
865 867
        assert cond not in conds # avoid infinite loops
866 868
        conds.add(cond)
869
    def invalid2null(in_col, value):
870
        log_ignore(in_col, value)
871
        update(db, in_table, [(in_col, None)],
872
            sql_gen.ColValueCond(in_col, value))
867 873
    
868 874
    # Do inserts and selects
869 875
    join_cols = {}
......
874 880
        
875 881
        # Prepare to insert new rows
876 882
        insert_joins = input_joins[:] # don't modify original!
877
        insert_args = dict(recover=True)
883
        insert_args = dict(recover=True, cacheable=False)
878 884
        if has_joins:
879 885
            distinct_on = [v.to_Col() for v in join_cols.values()]
880 886
            insert_joins.append(sql_gen.Join(out_table, join_cols,
......
902 908
            except KeyError:
903 909
                db.log_debug('Missing mapping for NOT NULL '+out_col)
904 910
                limit = 0 # just create an empty pkeys table
905
            else: ignore(in_col, None)
911
            else: remove_rows(in_col, None)
906 912
        except FunctionValueException, e:
907 913
            log_exc(e)
908 914
            
909 915
            assert e.name == out_table.name
910 916
            out_col = 'value' # assume function param was named "value"
911
            ignore(mapping[out_col], e.value)
917
            invalid2null(mapping[out_col], e.value)
912 918
        # after exception handled, rerun loop with additional constraints
913 919
    
914 920
    if row_ct_ref != None and cur.rowcount >= 0:

Also available in: Unified diff