Project

General

Profile

« Previous | Next » 

Revision 2236

sql.py: put_table(): Use table-qualified pkey col names whenever possible, to avoid ambiguous column references

View differences:

lib/sql.py
759 759
    in_tables = in_tables[:] # don't modify input!
760 760
    in_tables0 = in_tables.pop(0) # first table is separate
761 761
    in_pkey = pkey(db, in_tables0, recover=True, table_is_esc=table_is_esc)
762
    in_pkey_col = sql_gen.col2sql_gen(in_pkey, in_tables0, table_is_esc)
762 763
    insert_joins = [in_tables0]+[(t, {in_pkey: join_using}) for t in in_tables]
763 764
    
764 765
    out_pkey = pkey(db, out_table, recover=True, table_is_esc=table_is_esc)
765
    pkeys_cols = [in_pkey, out_pkey]
766
    out_pkey_col = sql_gen.col2sql_gen(out_pkey, out_table, table_is_esc)
766 767
    
768
    pkeys = [in_pkey, out_pkey]
769
    pkeys_cols = [in_pkey_col, out_pkey_col]
770
    
767 771
    pkeys_table_exists_ref = [False]
768 772
    def run_query_into_pkeys(query, params):
769 773
        if pkeys_table_exists_ref[0]:
770
            insert_select(db, pkeys_ref[0], pkeys_cols, query, params)
774
            insert_select(db, pkeys_ref[0], pkeys, query, params)
771 775
        else:
772 776
            run_query_into(db, query, params, into_ref=pkeys_ref)
773 777
            pkeys_table_exists_ref[0] = True
......
798 802
            
799 803
            # Join together output and input pkeys
800 804
            run_query_into_pkeys(*mk_select(db, [in_pkeys_ref[0],
801
                (out_pkeys_ref[0], {row_num_col: join_using})], pkeys_cols,
802
                start=0))
805
                (out_pkeys_ref[0], {row_num_col: join_using})], pkeys, start=0))
803 806
            
804 807
            break # insert successful
805 808
        except DuplicateKeyException, e:
......
824 827
            try: in_col = mapping[out_col]
825 828
            except KeyError: # no mapping for missing col, so every row invalid
826 829
                run_query_into_pkeys(*mk_select(db, insert_joins,
827
                    [in_pkey, sql_gen.NamedCode(out_pkey, None)],
830
                    [in_pkey_col, sql_gen.NamedCode(out_pkey, None)],
828 831
                    order_by=None, start=0, table_is_esc=table_is_esc))
829 832
                break
830 833
            else:

Also available in: Unified diff