コード例 #1
0
 def testOneCondition(self):
     self.assertQuery(AND(A.type == u'Narf!'),
                      '((%s = ?))' % (A.type.getColumnName(self.store), ),
                      ['Narf!'])
     self.assertQuery(OR(A.type == u'Narf!'),
                      '((%s = ?))' % (A.type.getColumnName(self.store), ),
                      ['Narf!'])
     self.assertEquals(self.query(D, AND(D.one == 'd1.one')), [self.d1])
     self.assertEquals(self.query(D, OR(D.one == 'd1.one')), [self.d1])
コード例 #2
0
 def testMultipleOrConditions(self):
     condition = OR(A.type == u'Narf!', A.type == u'Poiuyt!',
                    A.type == u'Try to take over the world')
     expectedSQL = '((%s = ?) OR (%s = ?) OR (%s = ?))'
     expectedSQL %= (A.type.getColumnName(self.store), ) * 3
     self.assertQuery(condition, expectedSQL,
                      ['Narf!', 'Poiuyt!', 'Try to take over the world'])
     q = self.query(
         D, OR(D.one == 'd1.one', D.one == 'd2.one', D.one == 'd3.one'))
     e = [self.d1, self.d2, self.d3]
     self.assertEquals(sorted(q), sorted(e))
コード例 #3
0
ファイル: library.py プロジェクト: DalavanCloud/axiom-1
def main(s):
    for ll in s.query(LendingLibrary):
        print 'found existing library'
        break
    else:
        print 'creating new library'
        ll = LendingLibrary(store=s)
        ll.initialize()
    ll.displayBooks()
    print '***'
    ll.shuffleLending()
    print '---'
    ll.displayBooks()
    print '***'
    ll.shuffleLending()
    print '---'

    print s.count(
        Book,
        AND(Book.author == u'Stephen King',
            Book.title == u'The Lions of al-Rassan'))
    print s.count(
        Book,
        OR(Book.author == u'Stephen King',
           Book.title == u'The Lions of al-Rassan'))
コード例 #4
0
 def __ne__(self, other):
     if not isinstance(other, (AttributeTuple, tuple, list)):
         return NotImplemented
     return OR(*[
             myAttr != otherAttr
             for (myAttr, otherAttr)
             in zip(self, other)])
コード例 #5
0
ファイル: userbase.py プロジェクト: DalavanCloud/axiom-1
def getLoginMethods(store, protocol=None):
    """
    Retrieve L{LoginMethod} items from store C{store}, optionally constraining
    them by protocol
    """
    if protocol is not None:
        comp = OR(LoginMethod.protocol == u'*',
                  LoginMethod.protocol == protocol)
    else:
        comp = None
    return store.query(LoginMethod, comp)
コード例 #6
0
ファイル: queryutil.py プロジェクト: perkinslr/axiom-py3
def overlapping(
        startAttribute,  # X
        endAttribute,  # Y
        startValue,  # A
        endValue,  # B
):
    """
    Return an L{axiom.iaxiom.IComparison} (an object that can be passed as the
    'comparison' argument to Store.query/.sum/.count) which will constrain a
    query against 2 attributes for ranges which overlap with the given
    arguments.

    For a database with Items of class O which represent values in this
    configuration::

              X                   Y
             (a)                 (b)
              |-------------------|
        (c)      (d)
         |--------|          (e)      (f)
                              |--------|

     (g) (h)
      |---|                            (i)    (j)
                                        |------|

     (k)                                   (l)
      |-------------------------------------|

             (a)                           (l)
              |-----------------------------|
        (c)                      (b)
         |------------------------|

        (c)  (a)
         |----|
                                 (b)       (l)
                                  |---------|

    The query::

        myStore.query(
            O,
            findOverlapping(O.X, O.Y,
                            a, b))

    Will return a generator of Items of class O which represent segments a-b,
    c-d, e-f, k-l, a-l, c-b, c-a and b-l, but NOT segments g-h or i-j.

    (NOTE: If you want to pass attributes of different classes for
    startAttribute and endAttribute, read the implementation of this method to
    discover the additional join clauses required.  This may be eliminated some
    day so for now, consider this method undefined over multiple classes.)

    In the database where this query is run, for an item N, all values of
    N.startAttribute must be less than N.endAttribute.

    startValue must be less than endValue.
    """
    assert startValue <= endValue

    return OR(AND(startAttribute >= startValue, startAttribute <= endValue),
              AND(endAttribute >= startValue, endAttribute <= endValue),
              AND(startAttribute <= startValue, endAttribute >= endValue))
コード例 #7
0
ファイル: queryutil.py プロジェクト: perkinslr/axiom-py3
 def __le__(self, other):
     if not isinstance(other, (AttributeTuple, tuple, list)):
         return NotImplemented
     return OR(self < other, self == other)
コード例 #8
0
ファイル: test_count.py プロジェクト: perkinslr/axiom-py3
 def testORConditionCount(self):
     self.assertCountEqualsQuery(
         ThingsWithIntegers,
         OR(ThingsWithIntegers.a > self.MIDDLE,
            ThingsWithIntegers.b < self.MIDDLE))