Project

General

Profile

« Previous | Next » 

Revision 3351

sql.py: Added map_expr()

View differences:

lib/sql.py
1012 1012
    if match: str_ = match.group(1)
1013 1013
    return sql_gen.unesc_name(str_)
1014 1014

  
1015
def map_expr(db, expr, mapping, in_cols_found=None):
1016
    '''Replaces output columns with input columns in an expression.
1017
    @param in_cols_found If set, will be filled in with the expr's (input) cols
1018
    '''
1019
    for out, in_ in mapping.iteritems():
1020
        orig_expr = expr
1021
        out = sql_gen.to_name_only_col(out)
1022
        in_str = sql_gen.to_name_only_col(sql_gen.remove_col_rename(in_)
1023
            ).to_str(db)
1024
        
1025
        # Replace out both with and without quotes
1026
        expr = expr.replace(out.to_str(db), in_str)
1027
        expr = re.sub(r'\b'+out.name+r'\b', in_str, expr)
1028
        
1029
        if in_cols_found != None and expr != orig_expr: # replaced something
1030
            in_cols_found.append(in_)
1031
    return expr
1032

  
1015 1033
#### Tables
1016 1034

  
1017 1035
def tables(db, schema_like='public', table_like='%', exact=False):

Also available in: Unified diff