From b3ec17153bd75107e7e6f8164c9fbea537685b5b Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 18 Nov 2007 21:32:13 +0000 Subject: [PATCH] - MSSQL anonymous labels for selection of functions made deterministic - propagate correct **kwargs through mssql methods --- CHANGES | 2 ++ lib/sqlalchemy/databases/mssql.py | 12 ++++++------ test/dialect/firebird.py | 5 ++++- test/dialect/mssql.py | 9 +++++++++ 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index 665e75218e..fef0c24176 100644 --- a/CHANGES +++ b/CHANGES @@ -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 92b454f820..672f8d77cf 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 daf2abba67..9d043153c2 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 b750e8ecdc..05d9efd786 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() -- 2.47.3