Revision 2747
Added by Aaron Marcuse-Kubitza over 12 years ago
sql_gen.py | ||
---|---|---|
198 | 198 |
if isinstance(col, Code): return col |
199 | 199 |
else: return Col(col, table) |
200 | 200 |
|
201 |
def set_default_table(col, table): |
|
202 |
col = as_Col(col) |
|
203 |
if not isinstance(col, NamedCol) and col.table == None: col.table = table |
|
204 |
return col |
|
205 |
|
|
201 | 206 |
def set_cols_table(table, cols): |
202 | 207 |
table = as_Table(table) |
203 | 208 |
|
... | ... | |
386 | 391 |
def as_ValueCond(value, default_table=assume_literal): |
387 | 392 |
if not isinstance(value, ValueCond): |
388 | 393 |
if default_table is not assume_literal: |
389 |
value = as_Col(value, default_table)
|
|
394 |
value = set_default_table(value, default_table)
|
|
390 | 395 |
return CompareCond(value) |
391 | 396 |
else: return value |
392 | 397 |
|
... | ... | |
432 | 437 |
left = right_table_col |
433 | 438 |
right = left_table_col |
434 | 439 |
|
440 |
# Parse left side |
|
441 |
left = set_default_table(left, left_table) |
|
442 |
|
|
435 | 443 |
# Parse special values |
436 |
if right is join_same: right = left |
|
444 |
left_on_right = Col(left.name, right_table) |
|
445 |
if right is join_same: right = left_on_right |
|
437 | 446 |
elif right is join_same_not_null: |
438 |
right = CompareCond(as_Col(left, right_table), '~=')
|
|
447 |
right = CompareCond(left_on_right, '~=')
|
|
439 | 448 |
|
449 |
# Parse right side |
|
440 | 450 |
right = as_ValueCond(right, right_table) |
441 |
return right.to_str(db, as_Col(left, left_table)) |
|
451 |
|
|
452 |
return right.to_str(db, left) |
|
442 | 453 |
|
443 | 454 |
# Create join condition |
444 | 455 |
type_ = self.type_ |
... | ... | |
447 | 458 |
elif type_ is not filter_out and reduce(operator.and_, |
448 | 459 |
(v is join_same_not_null for v in joins.itervalues())): |
449 | 460 |
# all cols w/ USING, so can use simpler USING syntax |
450 |
cols = (as_Col(v).to_str(db) for v in joins.iterkeys())
|
|
451 |
join_cond = 'USING ('+(', '.join(cols))+')'
|
|
461 |
cols = map(to_name_only_col, joins.iterkeys())
|
|
462 |
join_cond = 'USING ('+(', '.join((c.to_str(db) for c in cols)))+')'
|
|
452 | 463 |
else: |
453 | 464 |
if len(joins) == 1: whitespace = ' ' |
454 | 465 |
else: whitespace = '\n' |
Also available in: Unified diff
sql_gen.py: Added set_default_table(). as_ValueCond(): Use set_default_table() instead of as_Col() so that any name-only column also gets its table set. Join.to_str(): Parse left side using set_default_table() instead of as_Col() so that any name-only column also gets its table set.