Project

General

Profile

« Previous | Next » 

Revision 3477

sql_io.py: put_table(): is_function: Create empty pkeys table before calling function on all rows so its row type can later be used in an error handling wrapper function

View differences:

sql_io.py
322 322
        pkeys_cols = [in_pkey_col, out_pkey_col]
323 323
    
324 324
    pkeys_table_exists_ref = [False]
325
    def insert_into_pkeys(joins, cols, **kw_args):
326
        query = sql.mk_select(db, joins, cols, order_by=None)
325
    def insert_into_pkeys(joins, cols, limit=None, **kw_args):
326
        query = sql.mk_select(db, joins, cols, order_by=None, limit=limit)
327 327
        if pkeys_table_exists_ref[0]:
328 328
            sql.insert_select(db, into, pkeys_names, query, **kw_args)
329 329
        else:
......
414 414
            args = dict(((k.name, v) for k, v in mapping.iteritems()))
415 415
            func_call = sql_gen.NamedCol(out_pkey,
416 416
                sql_gen.FunctionCall(out_table, **args))
417
            def insert_func_call(limit=None):
418
                insert_into_pkeys(input_joins, [in_pkey_col, func_call],
419
                    limit=limit, recover=True)
420
            
421
            # Create empty pkeys table so its row type can be used
422
            insert_func_call(limit=0)
417 423
        else:
418 424
            insert_args = dict(recover=True, cacheable=False)
419 425
            if has_joins:
......
429 435
            cur = None
430 436
            if is_function:
431 437
                if is_literals: cur = sql.select(db, fields=[func_call])
432
                else:
433
                    insert_into_pkeys(input_joins, [in_pkey_col, func_call],
434
                        recover=True)
438
                else: insert_func_call()
435 439
            else:
436 440
                cur = sql.insert_select(db, out_table, mapping.keys(),
437 441
                    main_select, **insert_args)

Also available in: Unified diff