Project

General

Profile

« Previous | Next » 

Revision 2125

sql.py: put_table(): Take a dict mapping out to in cols instead of separate in and out cols lists

View differences:

lib/sql.py
629 629
        if not create: raise
630 630
        return put(db, table, row, pkey, row_ct_ref) # insert new row
631 631

  
632
def put_table(db, out_table, out_cols, in_tables, in_cols, pkey,
633
    row_ct_ref=None, table_is_esc=False):
632
def put_table(db, out_table, in_tables, mapping, pkey, row_ct_ref=None,
633
    table_is_esc=False):
634 634
    '''Recovers from errors.
635 635
    Only works under PostgreSQL (uses INSERT RETURNING).
636 636
    @return Name of the table where the pkeys (from INSERT RETURNING) are made
......
638 638
    '''
639 639
    pkeys_table = clean_name(out_table)+'_pkeys'
640 640
    def insert_():
641
        return insert_select(db, out_table, out_cols,
642
            *mk_select(db, in_tables[0], in_cols, table_is_esc=table_is_esc),
641
        return insert_select(db, out_table, mapping.keys(), *mk_select(db,
642
            in_tables[0], mapping.values(), table_is_esc=table_is_esc),
643 643
            returning=pkey, into=pkeys_table, recover=True,
644 644
            table_is_esc=table_is_esc)
645 645
    try:
lib/db_xml.py
171 171
    
172 172
    # Insert node
173 173
    in_tables.append(qual_name(in_table))
174
    pkeys_table = sql.put_table(db, esc_name(out_table), row.keys(),
175
        in_tables, row.values(), pkey_, row_ct_ref, table_is_esc=True)
174
    pkeys_table = sql.put_table(db, esc_name(out_table), in_tables, row, pkey_,
175
        row_ct_ref, table_is_esc=True)
176 176
    
177 177
    if commit: db.db.commit()
178 178
    return (pkeys_table, pkey_)

Also available in: Unified diff