diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-03-16 20:58:46 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-03-16 20:58:46 -0400 |
commit | 55367ac4a26dbc3c0e57783c3964cd5c42647a35 (patch) | |
tree | 9816d2cfc0159a6abd2a472572af3fd0e31f2a29 /test | |
parent | 811ece13974504685e1e2add7c91b2b88d213322 (diff) | |
download | sqlalchemy-55367ac4a26dbc3c0e57783c3964cd5c42647a35.tar.gz |
- mxodbc can use default execute() call
- modified SQLCompiler to support rendering of bind parameters as literal
inline strings for specific sections, if specified by the compiler
subclass, using either literal_binds=True passed to process() or any visit
method, or by setting to False the "binds_in_columns_clause" flag for SQL-92
compatible columns clauses.. The compiler subclass is responsible for
implementing the literal quoting function which should make use of the DBAPI's native
capabilities.
- SQLCompiler now passes **kw to most process() methods (should be all,
ideally) so that literal_binds is propagated.
- added some rudimentary tests for mxodbc.
Diffstat (limited to 'test')
-rw-r--r-- | test/dialect/test_mssql.py | 55 |
1 files changed, 46 insertions, 9 deletions
diff --git a/test/dialect/test_mssql.py b/test/dialect/test_mssql.py index 89a3af5fb..8092d8cdc 100644 --- a/test/dialect/test_mssql.py +++ b/test/dialect/test_mssql.py @@ -6,7 +6,7 @@ from sqlalchemy import types, exc, schema from sqlalchemy.orm import * from sqlalchemy.sql import table, column from sqlalchemy.databases import mssql -from sqlalchemy.dialects.mssql import pyodbc +from sqlalchemy.dialects.mssql import pyodbc, mxodbc from sqlalchemy.engine import url from sqlalchemy.test import * from sqlalchemy.test.testing import eq_, emits_warning_on @@ -22,7 +22,35 @@ class CompileTest(TestBase, AssertsCompiledSQL): def test_update(self): t = table('sometable', column('somecolumn')) self.assert_compile(t.update(t.c.somecolumn==7), "UPDATE sometable SET somecolumn=:somecolumn WHERE sometable.somecolumn = :somecolumn_1", dict(somecolumn=10)) - + + # TODO: should this be for *all* MS-SQL dialects ? + def test_mxodbc_binds(self): + """mxodbc uses MS-SQL native binds, which aren't allowed in various places.""" + + mxodbc_dialect = mxodbc.dialect() + t = table('sometable', column('foo')) + + for expr, compile in [ + ( + select([literal("x"), literal("y")]), + "SELECT 'x', 'y'", + ), + ( + select([t]).where(t.c.foo.in_(['x', 'y', 'z'])), + "SELECT sometable.foo FROM sometable WHERE sometable.foo IN ('x', 'y', 'z')", + ), + ( + func.foobar("x", "y", 4, 5), + "foobar('x', 'y', 4, 5)", + ), + ( + select([t]).where(func.len('xyz') > func.len(t.c.foo)), + "SELECT sometable.foo FROM sometable WHERE len('xyz') > len(sometable.foo)", + ) + ]: + self.assert_compile(expr, compile, dialect=mxodbc_dialect) + + def test_in_with_subqueries(self): """Test that when using subqueries in a binary expression the == and != are changed to IN and NOT IN respectively. @@ -127,15 +155,24 @@ class CompileTest(TestBase, AssertsCompiledSQL): column('col4')) (s1, s2) = ( - select([t1.c.col3.label('col3'), t1.c.col4.label('col4')], t1.c.col2.in_(["t1col2r1", "t1col2r2"])), - select([t2.c.col3.label('col3'), t2.c.col4.label('col4')], t2.c.col2.in_(["t2col2r2", "t2col2r3"])) + select([t1.c.col3.label('col3'), t1.c.col4.label('col4')], + t1.c.col2.in_(["t1col2r1", "t1col2r2"])), + select([t2.c.col3.label('col3'), t2.c.col4.label('col4')], + t2.c.col2.in_(["t2col2r2", "t2col2r3"])) ) u = union(s1, s2, order_by=['col3', 'col4']) - self.assert_compile(u, "SELECT t1.col3 AS col3, t1.col4 AS col4 FROM t1 WHERE t1.col2 IN (:col2_1, :col2_2) "\ - "UNION SELECT t2.col3 AS col3, t2.col4 AS col4 FROM t2 WHERE t2.col2 IN (:col2_3, :col2_4) ORDER BY col3, col4") - - self.assert_compile(u.alias('bar').select(), "SELECT bar.col3, bar.col4 FROM (SELECT t1.col3 AS col3, t1.col4 AS col4 FROM t1 WHERE "\ - "t1.col2 IN (:col2_1, :col2_2) UNION SELECT t2.col3 AS col3, t2.col4 AS col4 FROM t2 WHERE t2.col2 IN (:col2_3, :col2_4)) AS bar") + self.assert_compile(u, + "SELECT t1.col3 AS col3, t1.col4 AS col4 FROM t1 WHERE t1.col2 IN " + "(:col2_1, :col2_2) "\ + "UNION SELECT t2.col3 AS col3, t2.col4 AS col4 FROM t2 WHERE t2.col2 " + "IN (:col2_3, :col2_4) ORDER BY col3, col4") + + self.assert_compile(u.alias('bar').select(), + "SELECT bar.col3, bar.col4 FROM (SELECT t1.col3 AS col3, " + "t1.col4 AS col4 FROM t1 WHERE "\ + "t1.col2 IN (:col2_1, :col2_2) UNION SELECT t2.col3 AS col3, " + "t2.col4 AS col4 FROM t2 WHERE t2.col2 IN (:col2_3, :col2_4)) " + "AS bar") def test_function(self): self.assert_compile(func.foo(1, 2), "foo(:foo_1, :foo_2)") |