diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-07-14 21:11:16 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-07-14 21:11:51 -0400 |
commit | dbc8bbfba3591d2ea704673d90e95014765d0f10 (patch) | |
tree | 274df91b7f0217d8bff7b8d9f3e6e4d6bd6365a0 /lib/sqlalchemy/sql/compiler.py | |
parent | d2193f53c10d29a7a9b1846ebf322fbced55041f (diff) | |
download | sqlalchemy-dbc8bbfba3591d2ea704673d90e95014765d0f10.tar.gz |
- allow the compilation rule that gets the formatted name
to again have the chance to veto rendering, as the naming convention
can make the decision that the name is "none" or not now.
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 99b74b3c8..da810e9fe 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -2537,8 +2537,9 @@ class DDLCompiler(Compiled): def visit_check_constraint(self, constraint): text = "" if constraint.name is not None: - text += "CONSTRAINT %s " % \ - self.preparer.format_constraint(constraint) + formatted_name = self.preparer.format_constraint(constraint) + if formatted_name is not None: + text += "CONSTRAINT %s " % formatted_name text += "CHECK (%s)" % self.sql_compiler.process(constraint.sqltext, include_table=False, literal_binds=True) @@ -2548,8 +2549,9 @@ class DDLCompiler(Compiled): def visit_column_check_constraint(self, constraint): text = "" if constraint.name is not None: - text += "CONSTRAINT %s " % \ - self.preparer.format_constraint(constraint) + formatted_name = self.preparer.format_constraint(constraint) + if formatted_name is not None: + text += "CONSTRAINT %s " % formatted_name text += "CHECK (%s)" % constraint.sqltext text += self.define_constraint_deferrability(constraint) return text @@ -2559,8 +2561,9 @@ class DDLCompiler(Compiled): return '' text = "" if constraint.name is not None: - text += "CONSTRAINT %s " % \ - self.preparer.format_constraint(constraint) + formatted_name = self.preparer.format_constraint(constraint) + if formatted_name is not None: + text += "CONSTRAINT %s " % formatted_name text += "PRIMARY KEY " text += "(%s)" % ', '.join(self.preparer.quote(c.name) for c in constraint) @@ -2571,14 +2574,15 @@ class DDLCompiler(Compiled): preparer = self.dialect.identifier_preparer text = "" if constraint.name is not None: - text += "CONSTRAINT %s " % \ - preparer.format_constraint(constraint) + formatted_name = self.preparer.format_constraint(constraint) + if formatted_name is not None: + text += "CONSTRAINT %s " % formatted_name remote_table = list(constraint._elements.values())[0].column.table text += "FOREIGN KEY(%s) REFERENCES %s (%s)" % ( ', '.join(preparer.quote(f.parent.name) for f in constraint._elements.values()), self.define_constraint_remote_table( - constraint, remote_table, preparer), + constraint, remote_table, preparer), ', '.join(preparer.quote(f.column.name) for f in constraint._elements.values()) ) @@ -2597,11 +2601,11 @@ class DDLCompiler(Compiled): return '' text = "" if constraint.name is not None: - text += "CONSTRAINT %s " % \ - self.preparer.format_constraint(constraint) + formatted_name = self.preparer.format_constraint(constraint) + text += "CONSTRAINT %s " % formatted_name text += "UNIQUE (%s)" % ( - ', '.join(self.preparer.quote(c.name) - for c in constraint)) + ', '.join(self.preparer.quote(c.name) + for c in constraint)) text += self.define_constraint_deferrability(constraint) return text @@ -2909,6 +2913,8 @@ class IdentifierPreparer(object): constraint, constraint.table) if name: return self.quote(name) + elif isinstance(constraint.name, elements._defer_none_name): + return None return self.quote(constraint.name) def format_table(self, table, use_schema=True, name=None): |