def test_where(self): sql, values = sqlgen.select_distinct(Foo, Foo.q.s1, Foo.q.foo_id == 1, None, sqlgen.DIALECT_SQLITE, "?") self.assertEquals("SELECT DISTINCT s1 FROM foo WHERE foo_id=?", sql) self.assertEquals([1], values) # sql, values = sqlgen.select_distinct( Foo, Foo.q.d1, AND(Foo.q.i1 == 12, Foo.q.d1 == None, Foo.q.s1 == "y"), None, sqlgen.DIALECT_MYSQL, "%s" ) self.assertEquals("SELECT DISTINCT d1 FROM foo WHERE i1=%s AND d1 is NULL AND s1=%s", sql) self.assertEquals([12, "y"], values) # sql, values = sqlgen.select_distinct( Foo, Foo.q.d1, OR(Foo.q.i1 == 12, Foo.q.d1 == None, Foo.q.s1 == "y"), None, sqlgen.DIALECT_SQLITE, "?" ) self.assertEquals("SELECT DISTINCT d1 FROM foo WHERE i1=? OR d1 is NULL OR s1=?", sql) self.assertEquals([12, "y"], values)
def xselect_distinct(self, table, qcol, where=None, order_by=None): # gen sql sql, values = sqlgen.select_distinct( table, qcol, where, order_by, self.dialect, self.paramstr ) # execute sql cursor = self._execute(sql, values) # result iterator i = SelectDistinctResultIterator(cursor, self.DbError) self._last_ri = i return i
def test_order_by_different_col(self): try: sqlgen.select_distinct(Foo, Foo.q.i1, None, Foo.q.s1.ASC, sqlgen.DIALECT_SQLITE, "?") except AssertionError, e: self.assertEquals("SELECT DISTINCT column must match 'order_by' column", str(e))
def test_order_by(self): sql, values = sqlgen.select_distinct(Foo, Foo.q.foo_id, None, Foo.q.foo_id.ASC, sqlgen.DIALECT_SQLITE, "?") self.assertEquals("SELECT DISTINCT foo_id FROM foo ORDER BY foo_id ASC", sql)
def test(self): sql, values = sqlgen.select_distinct(Foo, Foo.q.i1, None, None, sqlgen.DIALECT_SQLITE, "?") self.assertEquals("SELECT DISTINCT i1 FROM foo", sql) self.assertEquals([], values)