Revision 2122
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
353 | 353 |
else: query += ', '.join(map(parse_col, fields)) |
354 | 354 |
query += ' FROM '+table0 |
355 | 355 |
|
356 |
# Add joins |
|
357 |
left_table = table0 |
|
358 |
for table, joins in tables: |
|
359 |
if not table_is_esc: table = esc_name_(table) |
|
360 |
|
|
361 |
def join(entry): |
|
362 |
'''Parses joins''' |
|
363 |
left_col, right_col = entry |
|
364 |
left_col = left_table+'.'+esc_name_(left_col) |
|
365 |
right_col = table+'.'+esc_name_(right_col) |
|
366 |
return (left_col+' = '+right_col |
|
367 |
+' OR ('+left_col+' IS NULL AND '+right_col+' IS NULL)') |
|
368 |
|
|
369 |
query += ' JOIN '+table+' ON '+( |
|
370 |
' AND '.join(map(join, joins.iteritems()))) |
|
371 |
left_table = table |
|
372 |
|
|
356 | 373 |
missing = True |
357 | 374 |
if conds != {}: |
358 |
query += ' WHERE '+' AND '.join(map(cond, conds.iteritems()))
|
|
375 |
query += ' WHERE '+(' AND '.join(map(cond, conds.iteritems())))
|
|
359 | 376 |
params += conds.values() |
360 | 377 |
missing = False |
361 | 378 |
if order_by != None: query += ' ORDER BY '+esc_name_(order_by) |
Also available in: Unified diff
sql.py: mk_select(): Support joins