diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-12-06 19:51:10 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-12-06 19:51:10 +0000 |
commit | f9cb6f5834fb1acf4460fd9bb6b72f8c76f8c36c (patch) | |
tree | d2ec1ec2f53858f927db3059cc0cf9ba6a8034d5 /lib/sqlalchemy/sql/compiler.py | |
parent | 4ca12d76bd8580d56c4ec1f7ed95c0e37a4c281a (diff) | |
download | sqlalchemy-f9cb6f5834fb1acf4460fd9bb6b72f8c76f8c36c.tar.gz |
- reworked the DDL generation of ENUM and similar to be more platform agnostic.
Uses a straight CheckConstraint with a generic expression. Preparing for boolean
constraint in [ticket:1589]
- CheckConstraint now accepts SQL expressions, though support for quoting of values
will be very limited. we don't want to get into formatting dates and such.
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 6802bfbef..a41a149d1 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -922,6 +922,11 @@ class SQLCompiler(engine.Compiled): class DDLCompiler(engine.Compiled): + + @util.memoized_property + def sql_compiler(self): + return self.dialect.statement_compiler(self.dialect, self.statement) + @property def preparer(self): return self.dialect.identifier_preparer @@ -982,7 +987,9 @@ class DDLCompiler(engine.Compiled): const = ", \n\t".join(p for p in (self.process(constraint) for constraint in table.constraints if constraint is not table.primary_key - and constraint.inline_ddl + and ( + constraint._create_rule is None or + constraint._create_rule(self)) and ( not self.dialect.supports_alter or not getattr(constraint, 'use_alter', False) @@ -1058,13 +1065,6 @@ class DDLCompiler(engine.Compiled): def post_create_table(self, table): return '' - def _compile(self, tocompile, parameters): - """compile the given string/parameters using this SchemaGenerator's dialect.""" - - compiler = self.dialect.statement_compiler(self.dialect, tocompile, parameters) - compiler.compile() - return compiler - def _validate_identifier(self, ident, truncate): if truncate: if len(ident) > self.dialect.max_identifier_length: @@ -1082,7 +1082,7 @@ class DDLCompiler(engine.Compiled): if isinstance(column.server_default.arg, basestring): return "'%s'" % column.server_default.arg else: - return unicode(self._compile(column.server_default.arg, None)) + return self.sql_compiler.process(column.server_default.arg) else: return None @@ -1091,7 +1091,8 @@ class DDLCompiler(engine.Compiled): if constraint.name is not None: text += "CONSTRAINT %s " % \ self.preparer.format_constraint(constraint) - text += " CHECK (%s)" % constraint.sqltext + sqltext = sql_util.expression_as_ddl(constraint.sqltext) + text += "CHECK (%s)" % self.sql_compiler.process(sqltext) text += self.define_constraint_deferrability(constraint) return text @@ -1138,17 +1139,6 @@ class DDLCompiler(engine.Compiled): text += self.define_constraint_deferrability(constraint) return text - def visit_enum_constraint(self, constraint): - text = "" - if constraint.name is not None: - text += "CONSTRAINT %s " % \ - self.preparer.format_constraint(constraint) - text += " CHECK (%s IN (%s))" % ( - self.preparer.format_column(constraint.column), - ",".join("'%s'" % x for x in constraint.type.enums) - ) - return text - def define_constraint_cascades(self, constraint): text = "" if constraint.ondelete is not None: |