From 8301651428be5396b76f7d20c8f61b5558d5a971 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 23 Oct 2011 16:57:48 -0400 Subject: - [feature] Added new support for remote "schemas": - MetaData() accepts "schema" and "quote_schema" arguments, which will be applied to the same-named arguments of a Table or Sequence which leaves these at their default of ``None``. - Sequence accepts "quote_schema" argument - tometadata() for Table will use the "schema" of the incoming MetaData for the new Table if the schema argument is explicitly "None" - Added CreateSchema and DropSchema DDL constructs - these accept just the string name of a schema and a "quote" flag. - When using default "schema" with MetaData, ForeignKey will also assume the "default" schema when locating remote table. This allows the "schema" argument on MetaData to be applied to any set of Table objects that otherwise don't have a "schema". - a "has_schema" method has been implemented on dialect, but only works on Postgresql so far. Courtesy Manlio Perillo, [ticket:1679] --- lib/sqlalchemy/sql/compiler.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 2741a853f..8d7f2aab9 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -965,7 +965,7 @@ class SQLCompiler(engine.Compiled): if colparams or not supports_default_values: text += " (%s)" % ', '.join([preparer.format_column(c[0]) for c in colparams]) - + if self.returning or insert_stmt._returning: self.returning = self.returning or insert_stmt._returning returning_clause = self.returning_clause( @@ -1247,6 +1247,15 @@ class DDLCompiler(engine.Compiled): return self.sql_compiler.post_process_text(ddl.statement % context) + def visit_create_schema(self, create): + return "CREATE SCHEMA " + self.preparer.format_schema(create.element, create.quote) + + def visit_drop_schema(self, drop): + text = "DROP SCHEMA " + self.preparer.format_schema(drop.element, drop.quote) + if drop.cascade: + text += " CASCADE" + return text + def visit_create_table(self, create): table = create.element preparer = self.dialect.identifier_preparer @@ -1732,6 +1741,11 @@ class IdentifierPreparer(object): "." + result return result + def format_schema(self, name, quote): + """Prepare a quoted schema name.""" + + return self.quote(name, quote) + def format_column(self, column, use_table=False, name=None, table_name=None): """Prepare a quoted column name.""" -- cgit v1.2.1