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/util.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/util.py')
-rw-r--r-- | lib/sqlalchemy/sql/util.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index a84a3eb74..78160ad1e 100644 --- a/lib/sqlalchemy/sql/util.py +++ b/lib/sqlalchemy/sql/util.py @@ -79,6 +79,26 @@ def find_columns(clause): visitors.traverse(clause, {}, {'column':cols.add}) return cols +def expression_as_ddl(clause): + """Given a SQL expression, convert for usage in DDL, such as + CREATE INDEX and CHECK CONSTRAINT. + + Converts bind params into quoted literals, column identifiers + into detached column constructs so that the parent table + identifier is not included. + + """ + def repl(element): + if isinstance(element, expression._BindParamClause): + return expression.literal_column(repr(element.value)) + elif isinstance(element, expression.ColumnClause) and \ + element.table is not None: + return expression.column(element.name) + else: + return None + + return visitors.replacement_traverse(clause, {}, repl) + def adapt_criterion_to_null(crit, nulls): """given criterion containing bind params, convert selected elements to IS NULL.""" |