From: Mike Bayer Date: Wed, 2 Apr 2008 16:35:06 +0000 (+0000) Subject: some fixes to the MS-SQL aliasing so that result_map is properly populated X-Git-Tag: rel_0_4_5~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=38b2869bb8a940949a44e6d51617d31e53570aae;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git some fixes to the MS-SQL aliasing so that result_map is properly populated --- diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py index 1c4a2c286e..849d585071 100644 --- a/lib/sqlalchemy/databases/mssql.py +++ b/lib/sqlalchemy/databases/mssql.py @@ -938,13 +938,19 @@ class MSSQLCompiler(compiler.DefaultCompiler): kwargs['mssql_aliased'] = True return super(MSSQLCompiler, self).visit_alias(alias, **kwargs) - def visit_column(self, column, **kwargs): + def visit_column(self, column, result_map=None, **kwargs): if column.table is not None and not self.isupdate and not self.isdelete: # translate for schema-qualified table aliases t = self._schema_aliased_table(column.table) if t is not None: - return self.process(expression._corresponding_column_or_error(t, column)) - return super(MSSQLCompiler, self).visit_column(column, **kwargs) + converted = expression._corresponding_column_or_error(t, column) + + 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): """Move bind parameters to the right-hand side of an operator, where possible.""" diff --git a/test/dialect/mssql.py b/test/dialect/mssql.py index 2adbca6b8f..857aa2b5b8 100755 --- a/test/dialect/mssql.py +++ b/test/dialect/mssql.py @@ -52,7 +52,18 @@ class CompileTest(TestBase, AssertsCompiledSQL): schema = 'remote_owner' ) + s = table4.select() + c = s.compile(dialect=self.__dialect__) + assert table4.c.rem_id in set(c.result_map['rem_id'][1]) + + s = table4.select(use_labels=True) + c = s.compile(dialect=self.__dialect__) + print c.result_map + assert table4.c.rem_id in set(c.result_map['remote_owner_remotetable_rem_id'][1]) + self.assert_compile(table4.select(), "SELECT remotetable_1.rem_id, remotetable_1.datatype_id, remotetable_1.value FROM remote_owner.remotetable AS remotetable_1") + + self.assert_compile(table4.select(use_labels=True), "SELECT remotetable_1.rem_id AS remote_owner_remotetable_rem_id, remotetable_1.datatype_id AS remote_owner_remotetable_datatype_id, remotetable_1.value AS remote_owner_remotetable_value FROM remote_owner.remotetable AS remotetable_1") self.assert_compile(table1.join(table4, table1.c.myid==table4.c.rem_id).select(), "SELECT mytable.myid, mytable.name, mytable.description, remotetable_1.rem_id, remotetable_1.datatype_id, remotetable_1.value FROM mytable JOIN remote_owner.remotetable AS remotetable_1 ON remotetable_1.rem_id = mytable.myid")