Revision 2087
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
589 | 589 |
if not create: raise |
590 | 590 |
return put(db, table, row, pkey, row_ct_ref) # insert new row |
591 | 591 |
|
592 |
def put_table(db, out_table, out_cols, in_table, in_cols, pkey, row_ct_ref=None,
|
|
593 |
table_is_esc=False): |
|
592 |
def put_table(db, out_table, out_cols, in_tables, in_cols, pkey,
|
|
593 |
row_ct_ref=None, table_is_esc=False):
|
|
594 | 594 |
'''Recovers from errors. |
595 | 595 |
Only works under PostgreSQL (uses INSERT RETURNING). |
596 | 596 |
@return Name of the table where the pkeys (from INSERT RETURNING) are made |
... | ... | |
599 | 599 |
pkeys_table = clean_name(out_table)+'_pkeys' |
600 | 600 |
def insert_(): |
601 | 601 |
return insert_select(db, out_table, out_cols, |
602 |
*mk_select(db, in_table, in_cols, table_is_esc=table_is_esc), |
|
602 |
*mk_select(db, in_tables[0], in_cols, table_is_esc=table_is_esc),
|
|
603 | 603 |
returning=pkey, into=pkeys_table, recover=True, |
604 | 604 |
table_is_esc=table_is_esc) |
605 | 605 |
try: |
lib/db_xml.py | ||
---|---|---|
142 | 142 |
pkey_ = pkey(out_table) |
143 | 143 |
row = {} |
144 | 144 |
children = [] |
145 |
in_tables = [] |
|
145 | 146 |
|
146 | 147 |
# Divide children into fields and children with fkeys to parent |
147 | 148 |
for child in xml_dom.NodeElemIter(node): |
... | ... | |
161 | 162 |
else: row[out_col] = (value, out_col) # value is literal value |
162 | 163 |
|
163 | 164 |
# Insert node |
165 |
in_tables.append(qual_name(in_table)) |
|
164 | 166 |
pkeys_table = sql.put_table(db, esc_name(out_table), row.keys(), |
165 |
qual_name(in_table), row.values(), pkey_, row_ct_ref, table_is_esc=True)
|
|
167 |
in_tables, row.values(), pkey_, row_ct_ref, table_is_esc=True)
|
|
166 | 168 |
|
167 | 169 |
if commit: db.db.commit() |
168 | 170 |
return (pkeys_table, pkey_) |
Also available in: Unified diff
sql.py: put_table(): Take multiple in_tables. Initial implementation just used the first in_table.