diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-11-18 21:32:13 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-11-18 21:32:13 +0000 |
| commit | b3ec17153bd75107e7e6f8164c9fbea537685b5b (patch) | |
| tree | f4cd3ba7ee973314213af2ee61dba2fcdbec88d0 | |
| parent | 4e12db829599e95a8e015e5254b0d8e0c28fffdd (diff) | |
| download | sqlalchemy-b3ec17153bd75107e7e6f8164c9fbea537685b5b.tar.gz | |
- MSSQL anonymous labels for selection of functions made deterministic
- propagate correct **kwargs through mssql methods
| -rw-r--r-- | CHANGES | 2 | ||||
| -rw-r--r-- | lib/sqlalchemy/databases/mssql.py | 12 | ||||
| -rw-r--r-- | test/dialect/firebird.py | 5 | ||||
| -rwxr-xr-x | test/dialect/mssql.py | 9 |
4 files changed, 21 insertions, 7 deletions
@@ -178,6 +178,8 @@ CHANGES - added awareness of schema name in oracle table_names() function, fixes metadata.reflect(schema='someschema') [ticket:847] + - MSSQL anonymous labels for selection of functions made deterministic + - sqlite will reflect "DECIMAL" as a numeric column. - Made access dao detection more reliable [ticket:828] diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py index 92b454f82..672f8d77c 100644 --- a/lib/sqlalchemy/databases/mssql.py +++ b/lib/sqlalchemy/databases/mssql.py @@ -903,25 +903,25 @@ class MSSQLCompiler(compiler.DefaultCompiler): return self.process(t.corresponding_column(column)) return super(MSSQLCompiler, self).visit_column(column, **kwargs) - def visit_binary(self, binary): + def visit_binary(self, binary, **kwargs): """Move bind parameters to the right-hand side of an operator, where possible.""" if isinstance(binary.left, expression._BindParamClause) and binary.operator == operator.eq: - return self.process(expression._BinaryExpression(binary.right, binary.left, binary.operator)) + return self.process(expression._BinaryExpression(binary.right, binary.left, binary.operator), **kwargs) else: - return super(MSSQLCompiler, self).visit_binary(binary) + return super(MSSQLCompiler, self).visit_binary(binary, **kwargs) def label_select_column(self, select, column): if isinstance(column, expression._Function): - return column.label(column.name + "_" + hex(random.randint(0, 65535))[2:]) + return column.label(None) else: return super(MSSQLCompiler, self).label_select_column(select, column) function_rewrites = {'current_date': 'getdate', 'length': 'len', } - def visit_function(self, func): + def visit_function(self, func, **kwargs): func.name = self.function_rewrites.get(func.name, func.name) - return super(MSSQLCompiler, self).visit_function(func) + return super(MSSQLCompiler, self).visit_function(func, **kwargs) def for_update_clause(self, select): # "FOR UPDATE" is only allowed on "DECLARE CURSOR" which SQLAlchemy doesn't use diff --git a/test/dialect/firebird.py b/test/dialect/firebird.py index daf2abba6..9d043153c 100644 --- a/test/dialect/firebird.py +++ b/test/dialect/firebird.py @@ -24,8 +24,11 @@ class CompileTest(SQLCompileTest): self.assert_compile(func.foo(1, 2), "foo(:foo, :foo_1)") self.assert_compile(func.current_time(), "current_time") self.assert_compile(func.foo(), "foo") - t = table('sometable', column('col1'), column('col2')) + + m = MetaData() + t = Table('sometable', m, Column('col1', Integer), Column('col2', Integer)) self.assert_compile(select([func.max(t.c.col1)]), "SELECT max(sometable.col1) FROM sometable") + if __name__ == '__main__': testbase.main() diff --git a/test/dialect/mssql.py b/test/dialect/mssql.py index b750e8ecd..05d9efd78 100755 --- a/test/dialect/mssql.py +++ b/test/dialect/mssql.py @@ -43,6 +43,15 @@ class CompileTest(SQLCompileTest): self.assert_compile(u, "SELECT t1.col3 AS col3, t1.col4 AS col4 FROM t1 WHERE t1.col2 IN (:t1_col2, :t1_col2_1) UNION SELECT t2.col3 AS col3, t2.col4 AS col4 FROM t2 WHERE t2.col2 IN (:t2_col2, :t2_col2_1) 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 (:t1_col2, :t1_col2_1) UNION SELECT t2.col3 AS col3, t2.col4 AS col4 FROM t2 WHERE t2.col2 IN (:t2_col2, :t2_col2_1)) AS bar") + + def test_function(self): + self.assert_compile(func.foo(1, 2), "foo(:foo, :foo_1)") + self.assert_compile(func.current_time(), "current_time") + self.assert_compile(func.foo(), "foo()") + + m = MetaData() + t = Table('sometable', m, Column('col1', Integer), Column('col2', Integer)) + self.assert_compile(select([func.max(t.c.col1)]), "SELECT max(sometable.col1) AS max_1 FROM sometable") if __name__ == "__main__": testbase.main() |
