Пример #1
0
 def test_placeholderColumnInterface(self):
     """
     Test that a column from a placeholder provides L{IColumn}.
     """
     value = 0
     p = Placeholder(PlaceholderTestItem)
     a = p.attr
     self.failUnless(IColumn.providedBy(a))
Пример #2
0
    def __init__(self, attribute, container, negate):
        self.attribute = attribute
        self.container = container
        self.negate = negate

        if IColumn.providedBy(container):
            self.containerClause = self._columnContainer
            self.getArgs = self._columnArgs
        elif IQuery.providedBy(container):
            self.containerClause = self._queryContainer
            self.getArgs = self._queryArgs
        else:
            self.containerClause = self._sequenceContainer
            self.getArgs = self._sequenceArgs
Пример #3
0
    def __init__(self, attribute, container, negate):
        self.attribute = attribute
        self.container = container
        self.negate = negate

        if IColumn.providedBy(container):
            self.containerClause = self._columnContainer
            self.getArgs = self._columnArgs
        elif IQuery.providedBy(container):
            self.containerClause = self._queryContainer
            self.getArgs = self._queryArgs
        else:
            self.containerClause = self._sequenceContainer
            self.getArgs = self._sequenceArgs
Пример #4
0
def compare(left, right, op):
    # interim: maybe we want objects later?  right now strings should be fine
    if IColumn.providedBy(right):
        return TwoAttributeComparison(left, op, right)
    elif right is None:
        if op == '=':
            negate = False
        elif op == '!=':
            negate = True
        else:
            raise TypeError(
                "None/NULL does not work with %s comparison" % (op,))
        return NullComparison(left, negate)
    else:
        # convert to constant usable in the database
        return AttributeValueComparison(left, op, right)
Пример #5
0
def compare(left, right, op):
    # interim: maybe we want objects later?  right now strings should be fine
    if IColumn.providedBy(right):
        return TwoAttributeComparison(left, op, right)
    elif right is None:
        if op == '=':
            negate = False
        elif op == '!=':
            negate = True
        else:
            raise TypeError(
                "None/NULL does not work with %s comparison" % (op,))
        return NullComparison(left, negate)
    else:
        # convert to constant usable in the database
        return AttributeValueComparison(left, op, right)
Пример #6
0
    def _like(self, negate, firstOther, *others):
        others = (firstOther,) + others
        likeParts = []

        allValues = True
        for other in others:
            if IColumn.providedBy(other):
                likeParts.append(LikeColumn(other))
                allValues = False
            elif other is None:
                # LIKE NULL is a silly condition, but it's allowed.
                likeParts.append(LikeNull())
                allValues = False
            else:
                likeParts.append(LikeValue(other))

        if allValues:
            likeParts = [LikeValue(''.join(others))]

        return LikeComparison(self, negate, likeParts)
Пример #7
0
    def _like(self, negate, firstOther, *others):
        others = (firstOther, ) + others
        likeParts = []

        allValues = True
        for other in others:
            if IColumn.providedBy(other):
                likeParts.append(LikeColumn(other))
                allValues = False
            elif other is None:
                # LIKE NULL is a silly condition, but it's allowed.
                likeParts.append(LikeNull())
                allValues = False
            else:
                likeParts.append(LikeValue(other))

        if allValues:
            likeParts = [LikeValue(''.join(others))]

        return LikeComparison(self, negate, likeParts)