From 2a962802de28615f5c961b423e1a995b7bd691bc Mon Sep 17 00:00:00 2001 From: Michael Trier Date: Sat, 11 Apr 2009 21:36:45 +0000 Subject: Added multi part schema name support. Closes #594 and #1341. --- lib/sqlalchemy/sql/compiler.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 5042959b2..84b0ff628 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -292,7 +292,7 @@ class DefaultCompiler(engine.Compiled): return name else: if column.table.schema: - schema_prefix = self.preparer.quote(column.table.schema, column.table.quote_schema) + '.' + schema_prefix = self.preparer.quote_schema(column.table.schema, column.table.quote_schema) + '.' else: schema_prefix = '' tablename = column.table.name @@ -613,7 +613,7 @@ class DefaultCompiler(engine.Compiled): def visit_table(self, table, asfrom=False, **kwargs): if asfrom: if getattr(table, "schema", None): - return self.preparer.quote(table.schema, table.quote_schema) + "." + self.preparer.quote(table.name, table.quote) + return self.preparer.quote_schema(table.schema, table.quote_schema) + "." + self.preparer.quote(table.name, table.quote) else: return self.preparer.quote(table.name, table.quote) else: @@ -1094,7 +1094,15 @@ class IdentifierPreparer(object): or self.illegal_initial_characters.match(value[0]) or not self.legal_characters.match(unicode(value)) or (lc_value != value)) - + + def quote_schema(self, schema, force): + """Quote a schema. + + Subclasses should override this to provide database-dependent + quoting behavior. + """ + return self.quote(schema, force) + def quote(self, ident, force): if force is None: if ident in self._strings: @@ -1113,7 +1121,7 @@ class IdentifierPreparer(object): def format_sequence(self, sequence, use_schema=True): name = self.quote(sequence.name, sequence.quote) if not self.omit_schema and use_schema and sequence.schema is not None: - name = self.quote(sequence.schema, sequence.quote) + "." + name + name = self.quote_schema(sequence.schema, sequence.quote) + "." + name return name def format_label(self, label, name=None): @@ -1135,7 +1143,7 @@ class IdentifierPreparer(object): name = table.name result = self.quote(name, table.quote) if not self.omit_schema and use_schema and getattr(table, "schema", None): - result = self.quote(table.schema, table.quote_schema) + "." + result + result = self.quote_schema(table.schema, table.quote_schema) + "." + result return result def format_column(self, column, use_table=False, name=None, table_name=None): @@ -1163,7 +1171,7 @@ class IdentifierPreparer(object): # a longer sequence. if not self.omit_schema and use_schema and getattr(table, 'schema', None): - return (self.quote(table.schema, table.quote_schema), + return (self.quote_schema(table.schema, table.quote_schema), self.format_table(table, use_schema=False)) else: return (self.format_table(table, use_schema=False), ) -- cgit v1.2.1