MCPcopy
hub / github.com/ponyorm/pony / getsql

Method getsql

pony/orm/sqltranslation.py:2583–2614  ·  view source on GitHub ↗
(monad, sqlquery=None)

Source from the content-addressed store, hash-verified

2581 def negate(monad):
2582 return CmpMonad(cmp_negate[monad.op], monad.left, monad.right)
2583 def getsql(monad, sqlquery=None):
2584 op = monad.op
2585 if monad.left.type is NoneType and monad.right.type is NoneType: # in hybrid methods
2586 return [['EQ' if op == 'is' else 'NE', ['VALUE', 1], ['VALUE', 1]]]
2587 left_sql = monad.left.getsql()
2588 if op == 'is':
2589 return [ sqland([ [ 'IS_NULL', item ] for item in left_sql ]) ]
2590 if op == 'is not':
2591 return [ sqland([ [ 'IS_NOT_NULL', item ] for item in left_sql ]) ]
2592 right_sql = monad.right.getsql()
2593 if len(left_sql) == 1 and left_sql[0][0] == 'ROW':
2594 left_sql = left_sql[0][1:]
2595 if len(right_sql) == 1 and right_sql[0][0] == 'ROW':
2596 right_sql = right_sql[0][1:]
2597 assert len(left_sql) == len(right_sql)
2598 size = len(left_sql)
2599 if op in ('<', '<=', '>', '>='):
2600 if size == 1:
2601 return [ [ cmp_ops[op], left_sql[0], right_sql[0] ] ]
2602 if monad.translator.row_value_syntax:
2603 return [ [ cmp_ops[op], [ 'ROW' ] + left_sql, [ 'ROW' ] + right_sql ] ]
2604 clauses = []
2605 for i in range(size):
2606 clause = [ [ monad.EQ, left_sql[j], right_sql[j] ] for j in range(i) ]
2607 clause.append([ cmp_ops[op], left_sql[i], right_sql[i] ])
2608 clauses.append(sqland(clause))
2609 return [ sqlor(clauses) ]
2610 if op == '==':
2611 return [ sqland([ [ monad.EQ, a, b ] for a, b in zip(left_sql, right_sql) ]) ]
2612 if op == '!=':
2613 return [ sqlor([ [ monad.NE, a, b ] for a, b in zip(left_sql, right_sql) ]) ]
2614 assert False, op # pragma: no cover
2615
2616class LogicalBinOpMonad(BoolMonad):
2617 def __init__(monad, operands):

Callers 15

initMethod · 0.45
construct_sql_astMethod · 0.45
apply_kwfiltersMethod · 0.45
apply_lambdaMethod · 0.45
postIfExpMethod · 0.45
postJoinedStrMethod · 0.45
coerce_monadsFunction · 0.45
countMethod · 0.45
aggregateMethod · 0.45
to_intMethod · 0.45
to_strMethod · 0.45

Calls 3

sqlandFunction · 0.85
sqlorFunction · 0.85
appendMethod · 0.80

Tested by

no test coverage detected