Revision 2155
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
688 | 688 |
return mk_select(db, in_joins, cols, limit=limit, start=start, |
689 | 689 |
table_is_esc=table_is_esc) |
690 | 690 |
|
691 |
out_pkeys = temp_prefix+'_out_pkeys'
|
|
691 |
out_pkeys_ref = [temp_prefix+'_out_pkeys']
|
|
692 | 692 |
def insert_(): |
693 | 693 |
'''Inserts and capture output pkeys.''' |
694 | 694 |
cur = insert_select(db, out_table, mapping.keys(), |
695 | 695 |
*mk_select_(mapping.values()), returning=out_pkey, |
696 |
into_ref=[out_pkeys], recover=True, table_is_esc=table_is_esc)
|
|
696 |
into_ref=out_pkeys_ref, recover=True, table_is_esc=table_is_esc)
|
|
697 | 697 |
if row_ct_ref != None and cur.rowcount >= 0: |
698 | 698 |
row_ct_ref[0] += cur.rowcount |
699 |
add_row_num(db, out_pkeys) # for joining it with in_pkeys
|
|
699 |
add_row_num(db, out_pkeys_ref[0]) # for joining it with input pkeys
|
|
700 | 700 |
|
701 | 701 |
# Get input pkeys corresponding to rows in insert |
702 |
in_pkeys = temp_prefix+'_in_pkeys'
|
|
703 |
run_query_into(db, *mk_select_([in_pkey]), into_ref=[in_pkeys])
|
|
704 |
add_row_num(db, in_pkeys) # for joining it with out_pkeys
|
|
702 |
in_pkeys_ref = [temp_prefix+'_in_pkeys']
|
|
703 |
run_query_into(db, *mk_select_([in_pkey]), into_ref=in_pkeys_ref)
|
|
704 |
add_row_num(db, in_pkeys_ref[0]) # for joining it with output pkeys
|
|
705 | 705 |
|
706 |
# Join together out_pkeys and in_pkeys
|
|
706 |
# Join together output and input pkeys
|
|
707 | 707 |
run_query_into(db, *mk_select(db, |
708 |
[in_pkeys, (out_pkeys, {row_num_col: join_using})],
|
|
708 |
[in_pkeys_ref[0], (out_pkeys_ref[0], {row_num_col: join_using})],
|
|
709 | 709 |
pkeys_cols, start=0), into_ref=pkeys_ref) |
710 | 710 |
|
711 | 711 |
# Do inserts and selects |
Also available in: Unified diff
sql.py: put_table(): Pass in_pkeys and out_pkeys to run_query_into() by ref so they will be updated if the table names are changed