summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2016-06-16 15:00:49 -0400
committerGerrit Code Review <gerrit2@ln3.zzzcomputing.com>2016-06-16 15:00:49 -0400
commit21f47e6f7ac0f1bb268cbf70b7c8bafda5d9f6b4 (patch)
tree15c781428a503c17514117dde65be731181a61b6
parentd8da8e4e7dd6b74165b78e6123ecdb3b18ca9bb3 (diff)
parentd7b8b475f8a5c0ddf955157f89db3d44d0dc0d9a (diff)
downloadsqlalchemy-21f47e6f7ac0f1bb268cbf70b7c8bafda5d9f6b4.tar.gz
Merge "Add DDLCompiler.create_table_suffix()"
-rw-r--r--doc/build/changelog/changelog_11.rst9
-rw-r--r--lib/sqlalchemy/sql/compiler.py11
-rw-r--r--test/sql/test_compiler.py16
3 files changed, 35 insertions, 1 deletions
diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst
index 534c3993c..2b71c799d 100644
--- a/doc/build/changelog/changelog_11.rst
+++ b/doc/build/changelog/changelog_11.rst
@@ -266,6 +266,15 @@
.. change::
:tags: feature, sql
+ :pullreq: github:275
+
+ Added a hook in :meth:`.DDLCompiler.visit_create_table` called
+ :meth:`.DDLCompiler.create_table_suffix`, allowing custom dialects
+ to add keywords after the "CREATE TABLE" clause. Pull request
+ courtesy Mark Sandan.
+
+ .. change::
+ :tags: feature, sql
:pullreq: github:231
Negative integer indexes are now accommodated by rows
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 5e537dfdc..fc5073596 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -2260,7 +2260,13 @@ class DDLCompiler(Compiled):
text = "\nCREATE "
if table._prefixes:
text += " ".join(table._prefixes) + " "
- text += "TABLE " + preparer.format_table(table) + " ("
+ text += "TABLE " + preparer.format_table(table) + " "
+
+ create_table_suffix = self.create_table_suffix(table)
+ if create_table_suffix:
+ text += create_table_suffix + " "
+
+ text += "("
separator = "\n"
@@ -2465,6 +2471,9 @@ class DDLCompiler(Compiled):
colspec += " NOT NULL"
return colspec
+ def create_table_suffix(self, table):
+ return ''
+
def post_create_table(self, table):
return ''
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py
index ca3468710..8b4e5053b 100644
--- a/test/sql/test_compiler.py
+++ b/test/sql/test_compiler.py
@@ -3081,6 +3081,22 @@ class DDLTest(fixtures.TestBase, AssertsCompiledSQL):
"PRIMARY KEY (b, a))"
)
+ def test_create_table_suffix(self):
+ class MyDialect(default.DefaultDialect):
+ class MyCompiler(compiler.DDLCompiler):
+ def create_table_suffix(self, table):
+ return 'SOME SUFFIX'
+
+ ddl_compiler = MyCompiler
+
+ m = MetaData()
+ t1 = Table('t1', m, Column('q', Integer))
+ self.assert_compile(
+ schema.CreateTable(t1),
+ "CREATE TABLE t1 SOME SUFFIX (q INTEGER)",
+ dialect=MyDialect()
+ )
+
def test_table_no_cols(self):
m = MetaData()
t1 = Table('t1', m)