]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- MSSQL anonymous labels for selection of functions made deterministic
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 18 Nov 2007 21:32:13 +0000 (21:32 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 18 Nov 2007 21:32:13 +0000 (21:32 +0000)
- propagate correct **kwargs through mssql methods

CHANGES
lib/sqlalchemy/databases/mssql.py
test/dialect/firebird.py
test/dialect/mssql.py

diff --git a/CHANGES b/CHANGES
index 665e75218ef279ae93e3fe0f51200d4565005beb..fef0c241766e7c6a9f135512e918850203155bf7 100644 (file)
--- 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]
index 92b454f820121fe90326171e88489874536d11e8..672f8d77cf69b1576ce0c53e3e1e3b2229619714 100644 (file)
@@ -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
index daf2abba670d6d4da863336473f0609bdd51ba2c..9d043153c2146017a14ae6db098bde13b5db88cb 100644 (file)
@@ -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()
index b750e8ecdc7a1d1b29167fdcb5a9951c36a99e11..05d9efd7865bb4404139705f38a4210617c4f7c0 100755 (executable)
@@ -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()