-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
- if self.negated:
- bits.append('(!(%s=%s))' % (column,values[0]))
- else:
- bits.append('(%s=%s)' % (column,values[0]))
- 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.