Project

General

Profile

« Previous | Next » 

Revision 5444

sql_io.py: put_table(): insert_into_pkeys(): Take a query as the param instead of sql.mk_select()'s params, to allow the caller to pass in any query without needing insert_into_pkeys() to manually pass through those args

View differences:

lib/sql_io.py
434 434
            into=full_in_table, add_pkey_=True)
435 435
    
436 436
    pkeys_table_exists_ref = [False]
437
    def insert_into_pkeys(joins, cols=None, limit=None, **kw_args):
438
        query = sql.mk_select(db, joins, cols, order_by=None, limit=limit)
437
    def insert_into_pkeys(query, **kw_args):
439 438
        if pkeys_table_exists_ref[0]:
440 439
            sql.insert_select(db, into, [in_pkey, into_out_pkey], query,
441 440
                **kw_args)
......
541 540
        func_call = sql_gen.NamedCol(into_out_pkey, func_call)
542 541
        
543 542
        # Create empty pkeys table so its row type can be used
544
        insert_into_pkeys(input_joins, [in_pkey_col, func_call], limit=0,
545
            recover=True)
543
        insert_into_pkeys(sql.mk_select(db, input_joins,
544
            [in_pkey_col, func_call], order_by=None, limit=0), recover=True)
546 545
        result_type = db.col_info(sql_gen.Col(into_out_pkey, into)).type
547 546
        
548 547
        ## Create error handling wrapper function
......
602 601
                if is_literals:
603 602
                    cur = sql.select(db, fields=[func_call], recover=True,
604 603
                        cacheable=True)
605
                else: insert_into_pkeys(wrapper_table, recover=True)
604
                else:
605
                    insert_into_pkeys(sql.mk_select(db, wrapper_table,
606
                        order_by=None), recover=True)
606 607
            else:
607 608
                cur = sql.insert_select(db, out_table, mapping.keys(),
608 609
                    main_select, **insert_args)
......
707 708
    elif has_joins:
708 709
        select_joins = input_joins+[sql_gen.Join(out_table, join_cols)]
709 710
        log_debug('Getting output table pkeys of existing/inserted rows')
710
        insert_into_pkeys(select_joins, [in_pkey_col,
711
            sql_gen.NamedCol(into_out_pkey, out_pkey_col)])
711
        insert_into_pkeys(sql.mk_select(db, select_joins, [in_pkey_col,
712
            sql_gen.NamedCol(into_out_pkey, out_pkey_col)], order_by=None))
712 713
    else:
713 714
        sql.add_row_num(db, insert_out_pkeys) # for joining with input pkeys
714 715
        
......
729 730
        in_col = sql_gen.Col(in_pkey, insert_in_pkeys)
730 731
        out_col = sql_gen.NamedCol(into_out_pkey,
731 732
            sql_gen.Col(out_pkey, insert_out_pkeys))
732
        insert_into_pkeys(pkey_joins, [in_col, out_col])
733
        insert_into_pkeys(sql.mk_select(db, pkey_joins, [in_col, out_col],
734
            order_by=None))
733 735
        
734 736
        sql.empty_temp(db, [insert_out_pkeys, insert_in_pkeys])
735 737
    
......
741 743
        missing_rows_joins = [full_in_table, sql_gen.Join(into,
742 744
            {in_pkey: sql_gen.join_same_not_null}, sql_gen.filter_out)]
743 745
            # must use join_same_not_null or query will take forever
744
        insert_into_pkeys(missing_rows_joins,
746
        insert_into_pkeys(sql.mk_select(db, missing_rows_joins,
745 747
            [sql_gen.Col(in_pkey, full_in_table),
746
            sql_gen.NamedCol(into_out_pkey, default)])
748
            sql_gen.NamedCol(into_out_pkey, default)], order_by=None))
747 749
    # otherwise, there is already an entry for every row
748 750
    
749 751
    assert (sql.table_row_count(db, into)

Also available in: Unified diff