Revision 2223
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql_gen.py | ||
---|---|---|
107 | 107 |
if len(parts) == 1: parts, = parts |
108 | 108 |
return parts |
109 | 109 |
|
110 |
def col2sql_gen(col, default_table=None, table_is_esc=False): |
|
111 |
'''Converts old-style (tuple-based) columns to sql_gen-compatible columns. |
|
112 |
@param table_is_esc If False, assumes any table name is not escaped or that |
|
113 |
re-escaping it will produce the same value. |
|
114 |
''' |
|
115 |
if isinstance(col, Col): return col # already in sql_gen form |
|
116 |
|
|
117 |
table = default_table |
|
118 |
if isinstance(col, tuple): table, col = col |
|
119 |
if table_is_esc: table = unescape_table(table) |
|
120 |
return Col(col, as_Table(table)) |
|
121 |
|
|
110 | 122 |
def value2sql_gen(value, default_table=None, table_is_esc=False): |
111 | 123 |
'''Converts old-style (tuple-based) values to sql_gen-compatible values. |
112 | 124 |
@param table_is_esc If False, assumes any table name is not escaped or that |
... | ... | |
114 | 126 |
''' |
115 | 127 |
if isinstance(value, Code): return value # already in sql_gen form |
116 | 128 |
|
117 |
if table_is_esc: default_table = unescape_table(default_table) |
|
118 |
is_tuple = isinstance(value, tuple) |
|
119 |
if is_tuple and len(value) == 1: return Literal(value[0]) # value is literal |
|
120 |
elif is_tuple and len(value) == 2: # value is col with table |
|
121 |
table, col = value |
|
122 |
if table_is_esc: table = unescape_table(table) |
|
123 |
return Col(col, as_Table(table)) |
|
124 |
else: return Col(value, as_Table(default_table)) # value is col name |
|
129 |
if isinstance(value, tuple) and len(value) == 1: return Literal(value[0]) |
|
130 |
else: return col2sql_gen(value, default_table, table_is_esc) |
Also available in: Unified diff
sql_gen.py: Added col2sql_gen() and use it in value2sql_gen()