summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-10-23 16:57:48 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2011-10-23 16:57:48 -0400
commit8301651428be5396b76f7d20c8f61b5558d5a971 (patch)
tree29216f336a8c3e196da7011a971fe6a4cd947ba0 /lib/sqlalchemy/sql/compiler.py
parent2f2505893b9290c6147ec439a275b98c70c11bc5 (diff)
downloadsqlalchemy-8301651428be5396b76f7d20c8f61b5558d5a971.tar.gz
- [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]
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r--lib/sqlalchemy/sql/compiler.py16
1 files changed, 15 insertions, 1 deletions
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."""