]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Corrected mssql schema named subqueries from not properly aliasing the columns. Fixes...
authorMichael Trier <mtrier@gmail.com>
Wed, 12 Nov 2008 05:36:45 +0000 (05:36 +0000)
committerMichael Trier <mtrier@gmail.com>
Wed, 12 Nov 2008 05:36:45 +0000 (05:36 +0000)
lib/sqlalchemy/databases/mssql.py
test/dialect/mssql.py

index a313b98bce1de24f7512d5cc202ed2aa6bedf4fa..d806492c620424174a53051954533b3495eb53de 100644 (file)
@@ -1001,7 +1001,8 @@ class MSSQLCompiler(compiler.DefaultCompiler):
         return super(MSSQLCompiler, self).visit_alias(alias, **kwargs)
 
     def visit_column(self, column, result_map=None, **kwargs):
-        if column.table is not None and not self.isupdate and not self.isdelete:
+        if column.table is not None and \
+            (not self.isupdate and not self.isdelete) or self.is_subquery():
             # translate for schema-qualified table aliases
             t = self._schema_aliased_table(column.table)
             if t is not None:
@@ -1009,9 +1010,9 @@ class MSSQLCompiler(compiler.DefaultCompiler):
 
                 if result_map is not None:
                     result_map[column.name.lower()] = (column.name, (column, ), column.type)
-                    
+
                 return super(MSSQLCompiler, self).visit_column(converted, result_map=None, **kwargs)
-                
+
         return super(MSSQLCompiler, self).visit_column(column, result_map=result_map, **kwargs)
 
     def visit_binary(self, binary, **kwargs):
index 1927de3f3ef767294cfeb7384619f8991303bbc3..5a4b38f6e9137e8a80229b7fb59677fd9dba028c 100755 (executable)
@@ -83,6 +83,9 @@ class CompileTest(TestBase, AssertsCompiledSQL):
         tbl = Table('test', metadata, Column('id', Integer, primary_key=True), schema='paj')
         self.assert_compile(tbl.delete(tbl.c.id == 1), "DELETE FROM paj.test WHERE paj.test.id = :id_1")
 
+        s = select([tbl.c.id]).where(tbl.c.id==1)
+        self.assert_compile(tbl.delete().where(tbl.c.id==(s)), "DELETE FROM paj.test WHERE paj.test.id IN (SELECT test_1.id FROM paj.test AS test_1 WHERE test_1.id = :id_1)")
+
     def test_union(self):
         t1 = table('t1',
             column('col1'),