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

Function sqlwhere

web/db.py:431–444  ·  view source on GitHub ↗

Converts a two-tuple (key, value) iterable `data` to an SQL WHERE clause `SQLQuery`. >>> sqlwhere((('cust_id', 2), ('order_id',3))) >>> sqlwhere((('order_id', 3), ('cust_id', 2)), grouping=', ') <sql: 'order_id = 3, cust

(data, grouping=" AND ")

Source from the content-addressed store, hash-verified

429
430
431def sqlwhere(data, grouping=" AND "):
432 """
433 Converts a two-tuple (key, value) iterable `data` to an SQL WHERE clause
434 `SQLQuery`.
435
436 >>> sqlwhere((('cust_id', 2), ('order_id',3)))
437 <sql: 'cust_id = 2 AND order_id = 3'>
438 >>> sqlwhere((('order_id', 3), ('cust_id', 2)), grouping=', ')
439 <sql: 'order_id = 3, cust_id = 2'>
440 >>> sqlwhere((('a', 'a'), ('b', 'b'))).query()
441 'a = %s AND b = %s'
442 """
443
444 return SQLQuery.join([k + " = " + sqlparam(v) for k, v in data], grouping)
445
446
447def sqlquote(a):

Callers 1

updateMethod · 0.85

Calls 1

joinMethod · 0.80

Tested by

no test coverage detected