Project

General

Profile

« Previous | Next » 

Revision 2486

sql.py: put_table(): Made debug messages more self-documenting

View differences:

lib/sql.py
876 876
    
877 877
    def log_debug(msg): db.log_debug(msg, level=1.5)
878 878
    
879
    log_debug('Putting columns:\n'+strings.as_table(mapping))
879
    log_debug('********** New iteration **********')
880
    log_debug('Inserting these input columns into '
881
        +strings.as_tt(out_table.to_str(db))+':\n'+strings.as_table(mapping))
880 882
    
881 883
    temp_prefix = out_table.name
882 884
    pkeys = sql_gen.Table(temp_prefix+'_pkeys')
......
889 891
    input_joins = [in_tables0]+[sql_gen.Join(v,
890 892
        {in_pkey: sql_gen.join_same_not_null}) for v in in_tables_]
891 893
    
892
    log_debug('Joining together input tables')
894
    log_debug('Joining together input tables into temp table')
893 895
    # Place in new table for speed and so don't modify input if values edited
894 896
    in_table = sql_gen.Table(temp_prefix+'_in')
895 897
    flatten_cols = filter(sql_gen.is_table_col, mapping.values())
896 898
    mapping = dicts.join(mapping, flatten(db, in_table, input_joins,
897 899
        flatten_cols, preserve=[in_pkey_col], start=0))
898 900
    input_joins = [in_table]
901
    db.log_debug('Temp table: '+strings.as_tt(in_table.to_str(db)), level=2)
899 902
    
900 903
    out_pkey = pkey(db, out_table, recover=True)
901 904
    out_pkey_col = sql_gen.as_Col(out_pkey, out_table)
......
956 959
        else:
957 960
            insert_args.update(dict(returning=out_pkey, into=insert_out_pkeys))
958 961
        
959
        log_debug('Inserting new rows')
962
        log_debug('Trying to insert new rows')
960 963
        try:
961 964
            cur = insert_select(db, out_table, mapping.keys(),
962 965
                *mk_main_select(insert_joins, mapping.values()), **insert_args)
......
966 969
            
967 970
            old_join_cols = join_cols.copy()
968 971
            join_cols.update(util.dict_subset(mapping, e.cols))
969
            log_debug('Ignoring existing rows, comparing on:\n'
972
            log_debug('Ignoring existing rows, comparing on these columns:\n'
970 973
                +strings.as_inline_table(join_cols))
971 974
            assert join_cols != old_join_cols # avoid infinite loops
972 975
        except NullValueException, e:
......
975 978
            out_col, = e.cols
976 979
            try: in_col = mapping[out_col]
977 980
            except KeyError:
978
                log_debug('Missing mapping for NOT NULL '+out_col)
981
                log_debug('Missing mapping for NOT NULL column '+out_col)
979 982
                remove_all_rows()
980 983
            else: remove_rows(in_col, None)
981 984
        except FunctionValueException, e:
......
998 1001
    
999 1002
    if has_joins:
1000 1003
        select_joins = input_joins+[sql_gen.Join(out_table, join_cols)]
1001
        log_debug('Getting output pkeys of existing/inserted rows')
1004
        log_debug('Getting output table pkeys of existing/inserted rows')
1002 1005
        insert_into_pkeys(select_joins, pkeys_cols)
1003 1006
    else:
1004 1007
        add_row_num(db, insert_out_pkeys) # for joining with input pkeys
1005 1008
        
1006
        log_debug('Getting input pkeys for rows in insert')
1009
        log_debug('Getting input table pkeys of inserted rows')
1007 1010
        run_query_into(db, *mk_main_select(input_joins, [in_pkey]),
1008 1011
            into=insert_in_pkeys)
1009 1012
        add_row_num(db, insert_in_pkeys) # for joining with output pkeys
......
1011 1014
        assert table_row_count(db, insert_out_pkeys) == table_row_count(db,
1012 1015
            insert_in_pkeys)
1013 1016
        
1014
        log_debug('Joining together output and input pkeys')
1017
        log_debug('Combining output and input pkeys in inserted order')
1015 1018
        pkey_joins = [insert_in_pkeys, sql_gen.Join(insert_out_pkeys,
1016 1019
            {row_num_col: sql_gen.join_same_not_null})]
1017 1020
        insert_into_pkeys(pkey_joins, pkeys_names)
1018 1021
    
1019
    log_debug('Adding pkey on returned pkeys table to enable fast joins')
1022
    db.log_debug('Adding pkey on pkeys table to enable fast joins', level=2.5)
1020 1023
    index_pkey(db, pkeys)
1021 1024
    
1022 1025
    log_debug("Setting pkeys of missing rows to NULL")

Also available in: Unified diff