summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/databases/mssql.py2
-rw-r--r--lib/sqlalchemy/sql/compiler.py13
-rw-r--r--lib/sqlalchemy/sql/expression.py5
3 files changed, 8 insertions, 12 deletions
diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py
index 0ebb84a16..da42ea105 100644
--- a/lib/sqlalchemy/databases/mssql.py
+++ b/lib/sqlalchemy/databases/mssql.py
@@ -987,8 +987,6 @@ class MSSQLCompiler(compiler.DefaultCompiler):
t = self._schema_aliased_table(column.table)
if t is not None:
return self.process(expression._corresponding_column_or_error(t, column))
- else:
- kwargs['use_schema'] = True
return super(MSSQLCompiler, self).visit_column(column, **kwargs)
def visit_binary(self, binary, **kwargs):
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index ee3ecc1f1..76e2ca260 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -249,14 +249,9 @@ class DefaultCompiler(engine.Compiled):
return " ".join([self.process(label.obj), self.operator_string(operators.as_), self.preparer.format_label(label, labelname)])
- def visit_column(self, column, result_map=None, use_schema=False, **kwargs):
- # there is actually somewhat of a ruleset when you would *not* necessarily
- # want to truncate a column identifier, if its mapped to the name of a
- # physical column. but thats very hard to identify at this point, and
- # the identifier length should be greater than the id lengths of any physical
- # columns so should not matter.
-
- if use_schema and getattr(column, 'table', None) and getattr(column.table, 'schema', None):
+ def visit_column(self, column, result_map=None, **kwargs):
+
+ if getattr(column, 'table', None) and getattr(column.table, 'schema', None):
schema_prefix = self.preparer.quote(column.table, column.table.schema) + '.'
else:
schema_prefix = ''
@@ -278,7 +273,7 @@ class DefaultCompiler(engine.Compiled):
return schema_prefix + self.preparer.quote(column.table, ANONYMOUS_LABEL.sub(self._process_anon, column.table.name)) + "." + n
elif len(column.table.primary_key) != 0:
pk = list(column.table.primary_key)[0]
- return self.visit_column(pk, result_map=result_map, use_schema=use_schema, **kwargs)
+ return self.visit_column(pk, result_map=result_map, **kwargs)
else:
return None
elif column.table is None or not column.table.named_with_column:
diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py
index 3d95948cb..2cd10720a 100644
--- a/lib/sqlalchemy/sql/expression.py
+++ b/lib/sqlalchemy/sql/expression.py
@@ -2632,7 +2632,10 @@ class _ColumnClause(ColumnElement):
return None
if self.__label is None:
if self.table is not None and self.table.named_with_column:
- self.__label = self.table.name + "_" + self.name
+ if getattr(self.table, 'schema', None):
+ self.__label = "_".join([self.table.schema, self.table.name, self.name])
+ else:
+ self.__label = "_".join([self.table.name, self.name])
counter = 1
while self.__label in self.table.c:
self.__label = self.__label + "_%d" % counter