-class WhereNode(BaseWhereNode):
- def as_sql(self):
- bits = []
- for item in self.children:
- if isinstance(item, WhereNode):
- bits.append(item.as_sql())
- continue
- if len(item) == 4:
- # django 1.1
- (table, column, type), x, y, values = item
- else:
- # django 1.0
- table, column, type, x, y, values = item
- equal_bits = [ "(%s=%s)" % (column, value) for value in values ]
- if len(equal_bits) == 1:
- clause = equal_bits[0]
- else:
- clause = '(|%s)' % ''.join(equal_bits)
- if self.negated:
- bits.append('(!%s)' % clause)
- else:
- bits.append(clause)
- if len(bits) == 1:
- return bits[0]
- elif self.connector == AND:
- return '(&%s)' % ''.join(bits)
- elif self.connector == OR:
- return '(|%s)' % ''.join(bits)
- else:
- raise Exception("Unhandled WHERE connector: %s" % self.connector)
+class Constraint(BaseConstraint):
+ """
+ An object that can be passed to WhereNode.add() and knows how to
+ pre-process itself prior to including in the WhereNode.