MCPcopy Create free account
hub / github.com/webpy/webpy / sqlors

Function sqlors

web/db.py:399–428  ·  view source on GitHub ↗

`left is a SQL clause like `tablename.arg = ` and `lst` is a list of values. Returns a reparam-style pair featuring the SQL that ORs together the clause for each item in the lst. >>> sqlors('foo = ', []) >>> sqlors('foo = ', [1]) <sql: '

(left, lst)

Source from the content-addressed store, hash-verified

397
398
399def sqlors(left, lst):
400 """
401 `left is a SQL clause like `tablename.arg = `
402 and `lst` is a list of values. Returns a reparam-style
403 pair featuring the SQL that ORs together the clause
404 for each item in the lst.
405
406 >>> sqlors('foo = ', [])
407 <sql: '1=2'>
408 >>> sqlors('foo = ', [1])
409 <sql: 'foo = 1'>
410 >>> sqlors('foo = ', 1)
411 <sql: 'foo = 1'>
412 >>> sqlors('foo = ', [1,2,3])
413 <sql: '(foo = 1 OR foo = 2 OR foo = 3 OR 1=2)'>
414 """
415 if isinstance(lst, iters):
416 lst = list(lst)
417 ln = len(lst)
418 if ln == 0:
419 return SQLQuery("1=2")
420 if ln == 1:
421 lst = lst[0]
422
423 if isinstance(lst, iters):
424 return SQLQuery(
425 ["("] + sum(([left, sqlparam(x), " OR "] for x in lst), []) + ["1=2)"]
426 )
427 else:
428 return left + sqlparam(lst)
429
430
431def sqlwhere(data, grouping=" AND "):

Callers

nothing calls this directly

Calls 1

SQLQueryClass · 0.85

Tested by

no test coverage detected