Revision 2180
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
365 | 365 |
|
366 | 366 |
join_using = object() # tells mk_select() to join the column with USING |
367 | 367 |
|
368 |
join_not_equal = object() # tells mk_select() to join the column with != |
|
369 |
|
|
368 | 370 |
def mk_select(db, tables, fields=None, conds=None, limit=None, start=None, |
369 | 371 |
order_by=order_by_pkey, table_is_esc=False): |
370 | 372 |
''' |
... | ... | |
431 | 433 |
right_col = table+'.'+esc_name_(right_col) |
432 | 434 |
sql_ = right_col+' ' |
433 | 435 |
|
436 |
negative = False |
|
437 |
|
|
434 | 438 |
# Parse special values |
435 | 439 |
if left_col == None: left_col = (left_col,) |
436 | 440 |
# for None values, tuple is optional |
437 | 441 |
elif left_col == join_using: left_col = right_col |
442 |
elif left_col == join_not_equal: |
|
443 |
left_col = right_col |
|
444 |
negative = True |
|
438 | 445 |
|
439 | 446 |
# Create SQL |
440 | 447 |
if isinstance(left_col, tuple) and len(left_col) == 1: |
... | ... | |
449 | 456 |
sql_ += ('= '+left_col+' OR ('+right_col+' IS NULL AND ' |
450 | 457 |
+left_col+' IS NULL)') |
451 | 458 |
|
459 |
if negative: sql_ = 'NOT ('+sql_+')' |
|
460 |
|
|
452 | 461 |
return sql_ |
453 | 462 |
|
454 | 463 |
if reduce(operator.and_, (v == join_using for v in joins.itervalues())): |
Also available in: Unified diff
sql.py: mk_select(): Support joins with !=