コード例 #1
0
ファイル: test_operators.py プロジェクト: jobrooker/CompIndel
    def test_and(self):
        and_ = And((self.table.c1, self.table.c2))
        self.assertEqual(str(and_), '("c1" AND "c2")')
        self.assertEqual(and_.params, ())

        and_ = And((Literal(True), self.table.c2))
        self.assertEqual(str(and_), '(%s AND "c2")')
        self.assertEqual(and_.params, (True, ))
コード例 #2
0
    def test_operator_operators(self):
        and_ = And((Literal(True), self.table.c1))
        and2 = and_ & And((Literal(True), self.table.c2))
        self.assertEqual(str(and2), '((%s AND "c1") AND %s AND "c2")')
        self.assertEqual(and2.params, (True, True))

        and3 = and_ & Literal(True)
        self.assertEqual(str(and3), '((%s AND "c1") AND %s)')
        self.assertEqual(and3.params, (True, True))

        or_ = Or((Literal(True), self.table.c1))
        or2 = or_ | Or((Literal(True), self.table.c2))
        self.assertEqual(str(or2), '((%s OR "c1") OR %s OR "c2")')
        self.assertEqual(or2.params, (True, True))

        or3 = or_ | Literal(True)
        self.assertEqual(str(or3), '((%s OR "c1") OR %s)')
        self.assertEqual(or3.params, (True, True))
コード例 #3
0
 def __and__(self, other):
     from sql.operators import And
     return And((self, other))
コード例 #4
0
ファイル: ooquery_spec.py プロジェクト: gisce/ooquery
with description('The OOQuery object'):
    with description('when creating an ooquery object'):
        with it('should get the table to query'):
            q = OOQuery('table')
            expect(q.table).to(be_a(Table))
        with it('should have a select method which returns table.attr'):
            q = OOQuery('table')
            sel = q.select(['field1', 'field2'])
            sel2 = q.table.select(q.table.field1.as_('field1'), q.table.field2.as_('field2'))
            expect(str(sel._select)).to(equal(str(sel2)))
        with it('should have a where method to pass the domain'):
            q = OOQuery('table')
            sql = q.select(['field1', 'field2']).where([('field3', '=', 4)])
            t = Table('table')
            sel = t.select(t.field1.as_('field1'), t.field2.as_('field2'))
            sel.where = And((t.field3 == 4,))
            expect(tuple(sql)).to(equal(tuple(sel)))

        with it('should have where method and compare two fields of the table'):
            q = OOQuery('table')
            sql = q.select(['field1', 'field2']).where([('field3', '>', Field('field4'))])
            t = Table('table')
            sel = t.select(t.field1.as_('field1'), t.field2.as_('field2'))
            sel.where = And((t.field3 > t.field4,))
            expect(tuple(sql)).to(equal(tuple(sel)))

        with it('should have where and compare two fields of joined tables'):
            def dummy_fk(table, field):
                fks = {
                    'table_2': {
                        'constraint_name': 'fk_contraint_name',
コード例 #5
0
 def test_operator_compat_column(self):
     and_ = And((self.table.c1, self.table.c2))
     self.assertEqual(and_.table, '')
     self.assertEqual(and_.name, '')