Revision 2315
Added by Aaron Marcuse-Kubitza over 12 years ago
sql.py | ||
---|---|---|
430 | 430 |
use all columns |
431 | 431 |
@return tuple(query, params) |
432 | 432 |
''' |
433 |
# Parse tables param |
|
433 | 434 |
if not lists.is_seq(tables): tables = [tables] |
434 | 435 |
tables = list(tables) # don't modify input! (list() copies input) |
435 |
table0 = tables.pop(0) # first table is separate
|
|
436 |
table0 = sql_gen.as_Table(tables.pop(0)) # first table is separate
|
|
436 | 437 |
|
438 |
# Parse other params |
|
437 | 439 |
if conds == None: conds = {} |
438 | 440 |
assert limit == None or type(limit) == int |
439 | 441 |
assert start == None or type(start) == int |
440 |
table0 = sql_gen.as_Table(table0) |
|
441 |
if order_by is order_by_pkey: order_by = pkey(db, table0, recover=True) |
|
442 |
if order_by is order_by_pkey: |
|
443 |
if distinct_on != []: order_by = None |
|
444 |
else: order_by = pkey(db, table0, recover=True) |
|
442 | 445 |
|
443 |
params = []
|
|
446 |
query = 'SELECT'
|
|
444 | 447 |
|
445 |
def parse_col(field): |
|
446 |
'''Parses fields''' |
|
447 |
return sql_gen.as_Col(field, default_table).to_str(db) |
|
448 |
def parse_col(col): return sql_gen.as_Col(col, default_table).to_str(db) |
|
448 | 449 |
|
449 |
query = 'SELECT' |
|
450 |
|
|
451 | 450 |
# DISTINCT ON columns |
452 | 451 |
if distinct_on != []: |
453 | 452 |
query += ' DISTINCT' |
... | ... | |
478 | 477 |
if conds != {}: |
479 | 478 |
query += ' WHERE '+(' AND '.join((sql_gen.as_ValueCond(r).to_str(db, l) |
480 | 479 |
for l, r in conds.iteritems()))) |
481 |
params += conds.values() |
|
482 | 480 |
missing = False |
483 | 481 |
if order_by != None: |
484 | 482 |
query += ' ORDER BY '+sql_gen.as_Col(order_by, table0).to_str(db) |
... | ... | |
489 | 487 |
if missing: warnings.warn(DbWarning( |
490 | 488 |
'SELECT statement missing a WHERE, LIMIT, or OFFSET clause: '+query)) |
491 | 489 |
|
492 |
return (query, params)
|
|
490 |
return (query, [])
|
|
493 | 491 |
|
494 | 492 |
def select(db, *args, **kw_args): |
495 | 493 |
'''For params, see mk_select() and run_query()''' |
Also available in: Unified diff
sql.py: mk_select(): Fixed bug where order_by needed to default to None if distinct_on was used. Fixed bug where cond values were being treated as %s params in addition to being parsed by sql_gen.as_ValueCond().to_str().