示例#1
0
 def test_in_cond(self):
     cond_in = In('name', ['one', 2, 'three'])
     c, p = cond_in.glue()
     self.assertEqual(c, '"name" IN (%s,%s,%s)')
     self.assertEqual(p, ['one', 2, 'three'])
     cond_in = In('name', [])
     c, p = cond_in.glue()
     self.assertEqual(c, 'False')
     self.assertEqual(p, [])
示例#2
0
    def test_nested_select(self):
        nested = Select('service_set_descr', columns=['name'], cond=Eq('name', 'registration ru'))
        c, p = nested.glue()
        self.assertEqual(c, 'SELECT "name" FROM "service_set_descr" WHERE "name" = %s')
        self.assertEqual(p, ['registration ru'])

        scoped_cond = Scoped(nested)
        c, p = scoped_cond.glue()
        self.assertEqual(c, '(SELECT "name" FROM "service_set_descr" WHERE "name" = %s)')
        self.assertEqual(p, ['registration ru'])

        cond_eq = Eq('service_set_descr_id', Scoped(nested))
        c, p = cond_eq.glue()
        self.assertEqual(c, '"service_set_descr_id" = (SELECT "name" FROM "service_set_descr" WHERE "name" = %s)')
        self.assertEqual(p, ['registration ru'])

        nested = Select('service_set', columns=['service_type_id'], cond=cond_eq)
        c, p = nested.glue()
        self.assertEqual(c, 'SELECT "service_type_id" FROM "service_set" WHERE "service_set_descr_id" = (SELECT "name" FROM "service_set_descr" WHERE "name" = %s)')
        self.assertEqual(p, ['registration ru'])

        in_cond = In('id', nested)
        c, p = in_cond.glue()
        self.assertEqual(c, '''"id" IN (SELECT "service_type_id" FROM "service_set" WHERE "service_set_descr_id" = (SELECT "name" FROM "service_set_descr" WHERE "name" = %s))''')
        self.assertEqual(p, ['registration ru'])

        any_cond = Any('id', nested)
        c, p = any_cond.glue()
        self.assertEqual(c, '''%s = ANY (SELECT "service_type_id" FROM "service_set" WHERE "service_set_descr_id" = (SELECT "name" FROM "service_set_descr" WHERE "name" = %s))''')
        self.assertEqual(p, ['id', 'registration ru'])