Project

General

Profile

« Previous | Next » 

Revision 2313

db_xml.py: put_table(): Accept sql_gen.Table objects or strings instead of separate table and schema names

View differences:

lib/db_xml.py
128 128

  
129 129
input_col_prefix = '$'
130 130

  
131
def put_table(db, node, in_table, in_schema=None, limit=None, start=0,
131
def put_table(db, node, in_table, limit=None, start=0,
132 132
    commit=False, row_ct_ref=None, parent_ids_loc=None):
133 133
    '''
134 134
    @param node The XML tree that transforms the input to the output. Similar to
......
138 138
    @return (table, col) Where the pkeys (from INSERT RETURNING) are made
139 139
        available
140 140
    '''
141
    def esc_name(name): return sql.esc_name(db, name)
142 141
    def pkey(table): return sql.pkey(db, table, True)
143 142
    
143
    in_table = sql_gen.as_Table(in_table)
144
    
144 145
    def put_table_(node, parent_ids_loc=None):
145
        return put_table(db, node, in_table, in_schema, limit, start, commit,
146
            row_ct_ref, parent_ids_loc)
146
        return put_table(db, node, in_table, limit, start, commit, row_ct_ref,
147
            parent_ids_loc)
147 148
    
148 149
    out_table = name_of(node)
149 150
    row = {}
......
170 171
        row[parent_ptr] = parent_ids_loc
171 172
    
172 173
    # Divide fields into input columns and literal values
173
    in_tables = [sql_gen.Table(in_table, in_schema)]
174
    in_tables = [in_table]
174 175
    for out_col, value in row.iteritems():
175 176
        if isinstance(value, sql_gen.Col): # value is temp table column
176 177
            in_tables.append(value.table)
177 178
        elif util.is_str(value) and value.startswith(input_col_prefix):
178 179
            # value is input column
179 180
            row[out_col] = sql_gen.Col(strings.remove_prefix(input_col_prefix,
180
                value))
181
                value), in_table)
181 182
        else: # value is literal value; should only be string or None
182 183
            assert util.is_str(value) or value == None
183 184
            row[out_col] = sql_gen.NamedCode(out_col, value)
bin/map
294 294
                if sep == '': # only the table name was specified
295 295
                    table = schema
296 296
                    schema = None
297
            table = sql_gen.Table(table, schema)
297 298
            
298 299
            # Fetch rows
299 300
            if by_col: limit = 0 # only fetch column names
300 301
            else: limit = n
301
            cur = sql.select(in_db, sql_gen.Table(table, schema), limit=limit,
302
                start=start, cacheable=False)
302
            cur = sql.select(in_db, table, limit=limit, start=start,
303
                cacheable=False)
303 304
            col_names = list(sql.col_names(cur))
304 305
            
305 306
            if by_col:
......
307 308
                xml_func.strip(root)
308 309
                if debug: log_debug('Putting stripped:\n'+str(root))
309 310
                    # only calc if debug
310
                db_xml.put_table(in_db, root.firstChild, table, schema, n,
311
                    start, commit, row_ins_ct_ref)
311
                db_xml.put_table(in_db, root.firstChild, table, n, start,
312
                    commit, row_ins_ct_ref)
312 313
                row_ct = 0 # unknown for now
313 314
            else:
314 315
                # Use normal by-row method

Also available in: Unified diff