diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-06-17 00:53:33 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-06-17 00:53:33 +0000 |
commit | 1ffed8432e282aa57ecde9f3e4ca778a1756ddc0 (patch) | |
tree | 0849938da765ee182bc23284337b214e3202e5d1 /lib/sqlalchemy/sql.py | |
parent | 3736b3ddff65f6d4b7e273b040b48b19dbac9b66 (diff) | |
download | sqlalchemy-1ffed8432e282aa57ecde9f3e4ca778a1756ddc0.tar.gz |
cast converted into its own ClauseElement so that it can have an explicit compilationrel_0_2_3
function in ANSICompiler
MySQLCompiler then skips most CAST calls since it only seems to support the standard syntax for Date
types; other types now a TODO for MySQL
then, polymorphic_union() function now CASTs null()s to the type corresponding to the columns in the UNION,
since postgres doesnt like mixing NULL with integer types
(long road for that .....)
Diffstat (limited to 'lib/sqlalchemy/sql.py')
-rw-r--r-- | lib/sqlalchemy/sql.py | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/lib/sqlalchemy/sql.py b/lib/sqlalchemy/sql.py index 0cacea12d..d978ee208 100644 --- a/lib/sqlalchemy/sql.py +++ b/lib/sqlalchemy/sql.py @@ -153,12 +153,9 @@ def cast(clause, totype, **kwargs): or cast(table.c.timestamp, DATE) """ - # handle non-column clauses (e.g. cast(1234, TEXT) - if not hasattr(clause, 'label'): - clause = literal(clause) - totype = sqltypes.to_instance(totype) - return Function('CAST', CompoundClause("AS", clause, TypeClause(totype)), type=totype, **kwargs) - + return Cast(clause, totype, **kwargs) + + def exists(*args, **params): params['correlate'] = True s = select(*args, **params) @@ -320,6 +317,7 @@ class ClauseVisitor(object): def visit_clauselist(self, list):pass def visit_calculatedclause(self, calcclause):pass def visit_function(self, func):pass + def visit_cast(self, cast):pass def visit_label(self, label):pass def visit_typeclause(self, typeclause):pass @@ -974,7 +972,20 @@ class Function(CalculatedClause): c.accept_visitor(visitor) visitor.visit_function(self) - +class Cast(ColumnElement): + def __init__(self, clause, totype, **kwargs): + if not hasattr(clause, 'label'): + clause = literal(clause) + self.type = sqltypes.to_instance(totype) + self.clause = clause + self.typeclause = TypeClause(self.type) + def accept_visitor(self, visitor): + self.clause.accept_visitor(visitor) + self.typeclause.accept_visitor(visitor) + visitor.visit_cast(self) + def _get_from_objects(self): + return self.clause._get_from_objects() + class FunctionGenerator(object): """generates Function objects based on getattr calls""" def __init__(self, engine=None): |