Project

General

Profile

« Previous | Next » 

Revision 2078

sql.py: Added put_table()

View differences:

sql.py
576 576
    except StopIteration:
577 577
        if not create: raise
578 578
        return put(db, table, row, pkey, row_ct_ref) # insert new row
579

  
580
def put_table(db, out_table, out_cols, in_table, in_cols, pkey, row_ct_ref=None,
581
    table_is_esc=False):
582
    '''Recovers from errors.
583
    Only works under PostgreSQL (uses INSERT RETURNING).
584
    @return tuple(table, col) Where the pkeys (from INSERT RETURNING) are made
585
        available
586
    '''
587
    pkeys_table = clean_name(out_table)+'_pkeys'
588
    def insert_():
589
        return insert_select(db, out_table, out_cols,
590
            *mk_select(db, in_table, in_cols, table_is_esc=table_is_esc),
591
            returning=pkey, into=pkeys_table, recover=True,
592
            table_is_esc=table_is_esc)
593
    try:
594
        cur = with_parsed_errors(db, insert_)
595
        if row_ct_ref != None and cur.rowcount >= 0:
596
            row_ct_ref[0] += cur.rowcount
597
        return (pkeys_table, None)
598
    except DuplicateKeyException, e: raise

Also available in: Unified diff