Commits

Mike Bayer committed 26aff0d

- MSSQL anonymous labels for selection of functions made deterministic
- propagate correct **kwargs through mssql methods

  • Participants
  • Parent commits 9677f0b

Comments (0)

Files changed (4)

   - 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]

lib/sqlalchemy/databases/mssql.py

                 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

test/dialect/firebird.py

         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()

test/dialect/mssql.py

         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()