Project

General

Profile

« Previous | Next » 

Revision 2157

sql.py: mk_select(): fields: Support columns with tables. Changed syntax for literal values so that it wouldn't conflict with new syntax for columns with tables.

View differences:

lib/sql.py
382 382
    
383 383
    def parse_col(field):
384 384
        '''Parses fields'''
385
        if isinstance(field, tuple): # field is literal value
386
            value, col = field
385
        is_tuple = isinstance(field, tuple)
386
        if is_tuple and len(field) == 1: # field is literal value
387
            value, = field
387 388
            sql_ = '%s'
388 389
            params.append(value)
389
            if col != None: sql_ += ' AS '+esc_name_(col)
390
        elif is_tuple and len(field) == 2: # field is col with table
391
            table, col = field
392
            if not table_is_esc: table = esc_name_(table)
393
            sql_ = table+'.'+esc_name_(col)
390 394
        else: sql_ = esc_name_(field) # field is col name
391 395
        return sql_
392 396
    def cond(entry):
......
672 676
        available
673 677
    '''
674 678
    temp_prefix = '_'.join(map(clean_name,
675
        [out_table] + list(iters.flatten(mapping.items()))))
679
        [out_table] + list(iters.flatten_n(mapping.items(), depth=3))))
676 680
    pkeys_ref = [temp_prefix+'_pkeys']
677 681
    
678 682
    # Join together input tables
lib/db_xml.py
156 156
        else:
157 157
            child_value = xml_dom.value_node(child)
158 158
            if is_ptr(child_name) or xml_func.is_func(child_value):
159
                table, col = put_table_(child_value)
160
                row[child_name] = '$'+col
161
                in_tables.append(table)
159
                row[child_name] = put_table_(child_value)
162 160
            else: children.append(child)
163 161
    try: del row[pkey(out_table)]
164 162
    except KeyError: pass
165 163
    
166 164
    # Divide fields into input columns and literal values
167 165
    for out_col, value in row.iteritems():
168
        in_col = strings.remove_prefix('$', value)
169
        if in_col != value: row[out_col] = in_col # value is input column
170
        else: row[out_col] = (value, out_col) # value is literal value
166
        if isinstance(value, tuple): in_tables.append(value[0])
167
        else:
168
            in_col = strings.remove_prefix('$', value)
169
            if in_col != value: row[out_col] = in_col # value is input column
170
            else: row[out_col] = (value,) # value is literal value
171 171
    
172 172
    # Insert node
173 173
    pkeys_loc = sql.put_table(db, esc_name(out_table), in_tables, row,

Also available in: Unified diff