Revision 2357
Added by Aaron Marcuse-Kubitza over 12 years ago
sql.py | ||
---|---|---|
804 | 804 |
try: |
805 | 805 |
cur = insert_select(db, out_table, mapping.keys(), |
806 | 806 |
*mk_main_select(insert_joins, mapping.values()), **insert_args) |
807 |
break # insert successful |
|
807 | 808 |
except DuplicateKeyException, e: |
808 | 809 |
log_exc(e) |
809 | 810 |
|
... | ... | |
824 | 825 |
else: |
825 | 826 |
log_ignore(in_col, 'NULL') |
826 | 827 |
conds[in_col] = sql_gen.CompareCond(None, '!=') |
827 |
# rerun loop with additional constraints |
|
828 |
|
|
829 |
# rerun loop with additional constraints |
|
828 | 830 |
except FunctionValueException, e: |
829 | 831 |
log_exc(e) |
830 | 832 |
|
... | ... | |
834 | 836 |
value = e.value |
835 | 837 |
log_ignore(in_col, value) |
836 | 838 |
conds[in_col] = sql_gen.CompareCond(value, '!=') |
839 |
|
|
837 | 840 |
# rerun loop with additional constraints |
838 |
else: |
|
839 |
if row_ct_ref != None and cur.rowcount >= 0: |
|
840 |
row_ct_ref[0] += cur.rowcount |
|
841 |
|
|
842 |
if has_joins: |
|
843 |
select_joins = input_joins+[sql_gen.Join(out_table, join_cols)] |
|
844 |
db.log_debug('Getting output pkeys of existing/inserted rows') |
|
845 |
run_query_into_pkeys(*mk_select(db, select_joins, pkeys_cols, |
|
846 |
start=0)) |
|
847 |
else: |
|
848 |
add_row_num(db, out_pkeys_ref[0]) # for joining with input pkeys |
|
849 |
|
|
850 |
db.log_debug('Getting input pkeys for rows in insert') |
|
851 |
run_query_into(db, *mk_main_select(input_joins, [in_pkey]), |
|
852 |
into_ref=in_pkeys_ref) |
|
853 |
add_row_num(db, in_pkeys_ref[0]) # for joining with output pkeys |
|
854 |
|
|
855 |
db.log_debug('Joining together output and input pkeys') |
|
856 |
pkey_joins = [in_pkeys_ref[0], sql_gen.Join(out_pkeys_ref[0], |
|
857 |
{row_num_col: sql_gen.join_same_not_null})] |
|
858 |
run_query_into_pkeys(*mk_select(db, pkey_joins, pkeys, start=0)) |
|
859 |
|
|
860 |
db.log_debug("Setting missing rows' pkeys to NULL") |
|
861 |
missing_rows_joins = input_joins+[sql_gen.Join(pkeys_ref[0], |
|
862 |
{in_pkey: sql_gen.join_same_not_null}, sql_gen.filter_out)] |
|
863 |
# must use join_same_not_null or query will take forever |
|
864 |
run_query_into_pkeys(*mk_select(db, missing_rows_joins, |
|
865 |
[in_pkey_col, sql_gen.NamedCol(out_pkey, None)], start=0)) |
|
866 |
|
|
867 |
break # insert successful |
|
868 | 841 |
|
842 |
if row_ct_ref != None and cur.rowcount >= 0: |
|
843 |
row_ct_ref[0] += cur.rowcount |
|
844 |
|
|
845 |
if has_joins: |
|
846 |
select_joins = input_joins+[sql_gen.Join(out_table, join_cols)] |
|
847 |
db.log_debug('Getting output pkeys of existing/inserted rows') |
|
848 |
run_query_into_pkeys(*mk_select(db, select_joins, pkeys_cols, |
|
849 |
start=0)) |
|
850 |
else: |
|
851 |
add_row_num(db, out_pkeys_ref[0]) # for joining with input pkeys |
|
852 |
|
|
853 |
db.log_debug('Getting input pkeys for rows in insert') |
|
854 |
run_query_into(db, *mk_main_select(input_joins, [in_pkey]), |
|
855 |
into_ref=in_pkeys_ref) |
|
856 |
add_row_num(db, in_pkeys_ref[0]) # for joining with output pkeys |
|
857 |
|
|
858 |
db.log_debug('Joining together output and input pkeys') |
|
859 |
pkey_joins = [in_pkeys_ref[0], sql_gen.Join(out_pkeys_ref[0], |
|
860 |
{row_num_col: sql_gen.join_same_not_null})] |
|
861 |
run_query_into_pkeys(*mk_select(db, pkey_joins, pkeys, start=0)) |
|
862 |
|
|
863 |
db.log_debug("Setting missing rows' pkeys to NULL") |
|
864 |
missing_rows_joins = input_joins+[sql_gen.Join(pkeys_ref[0], |
|
865 |
{in_pkey: sql_gen.join_same_not_null}, sql_gen.filter_out)] |
|
866 |
# must use join_same_not_null or query will take forever |
|
867 |
run_query_into_pkeys(*mk_select(db, missing_rows_joins, |
|
868 |
[in_pkey_col, sql_gen.NamedCol(out_pkey, None)], start=0)) |
|
869 |
|
|
869 | 870 |
return sql_gen.Col(out_pkey, pkeys_ref[0]) |
870 | 871 |
|
871 | 872 |
##### Data cleanup |
Also available in: Unified diff
sql.py: put_table(): Moved post-insert code outside while loop because it will now always be run (there are no longer special cases where the postprocessing doesn't happen)