Revision 2577
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql_gen.py | ||
---|---|---|
220 | 220 |
|
221 | 221 |
def to_str(self, db): return self.value.to_str(db, self.col) |
222 | 222 |
|
223 |
def combine_conds(conds, keyword=None): |
|
224 |
''' |
|
225 |
@param keyword The keyword to add before the conditions, if any |
|
226 |
''' |
|
227 |
str_ = '' |
|
228 |
if keyword != None: |
|
229 |
if conds == []: whitespace = '' |
|
230 |
elif len(conds) == 1: whitespace = ' ' |
|
231 |
else: whitespace = '\n' |
|
232 |
str_ += keyword+whitespace |
|
233 |
|
|
234 |
str_ += '\nAND '.join(conds) |
|
235 |
return str_ |
|
236 |
|
|
223 | 237 |
##### Condition column comparisons |
224 | 238 |
|
225 | 239 |
class ValueCond(BasicObject): |
... | ... | |
341 | 355 |
else: |
342 | 356 |
if len(joins) == 1: whitespace = ' ' |
343 | 357 |
else: whitespace = '\n' |
344 |
join_cond = 'ON'+whitespace+('\nAND '.join( |
|
345 |
map(join, joins.iteritems()))) |
|
358 |
join_cond = combine_conds(map(join, joins.iteritems()), 'ON') |
|
346 | 359 |
|
347 | 360 |
# Create join |
348 | 361 |
if type_ is filter_out: type_ = 'LEFT' |
lib/sql.py | ||
---|---|---|
511 | 511 |
if conds != []: |
512 | 512 |
if len(conds) == 1: whitespace = ' ' |
513 | 513 |
else: whitespace = '\n' |
514 |
query += '\nWHERE'+whitespace+('\nAND '.join((
|
|
515 |
'('+sql_gen.ColValueCond(l, r) .to_str(db)+')' for l, r in conds)))
|
|
514 |
query += '\n'+sql_gen.combine_conds(['('+sql_gen.ColValueCond(l, r)
|
|
515 |
.to_str(db)+')' for l, r in conds], 'WHERE')
|
|
516 | 516 |
missing = False |
517 | 517 |
if order_by != None: |
518 | 518 |
query += '\nORDER BY '+sql_gen.as_Col(order_by, table0).to_str(db) |
Also available in: Unified diff
sql_gen.py: Added combine_conds() and use it in Join.to_str() and sql.py mk_select()