summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2006-10-03 23:00:04 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2006-10-03 23:00:04 +0000
commitbbd7c660560212844de3a92ba077bcec77740b16 (patch)
treeea4636813813fb80b8f18d24ec931c8fa522b05e /lib/sqlalchemy/sql.py
parentec6d7b39003f244b4acc7352f5973c910053e17f (diff)
downloadsqlalchemy-bbd7c660560212844de3a92ba077bcec77740b16.tar.gz
- Function objects know what to do in a FROM clause now. their
behavior should be the same, except now you can also do things like select(['*'], from_obj=[func.my_function()]) to get multiple columns from the result, or even use sql.column() constructs to name the return columns [ticket:172]. generally only postgres understands the syntax (and possibly oracle).
Diffstat (limited to 'lib/sqlalchemy/sql.py')
-rw-r--r--lib/sqlalchemy/sql.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/sqlalchemy/sql.py b/lib/sqlalchemy/sql.py
index 89688cbfe..a07536bc9 100644
--- a/lib/sqlalchemy/sql.py
+++ b/lib/sqlalchemy/sql.py
@@ -928,7 +928,8 @@ class CalculatedClause(ClauseList, ColumnElement):
def _process_from_dict(self, data, asfrom):
super(CalculatedClause, self)._process_from_dict(data, asfrom)
# this helps a Select object get the engine from us
- data.setdefault(self, self)
+ if asfrom:
+ data.setdefault(self, self)
def copy_container(self):
clauses = [clause.copy_container() for clause in self.clauses]
return CalculatedClause(type=self.type, engine=self._engine, *clauses)
@@ -948,7 +949,7 @@ class CalculatedClause(ClauseList, ColumnElement):
return self.type
-class Function(CalculatedClause):
+class Function(CalculatedClause, FromClause):
"""describes a SQL function. extends CalculatedClause turn the "clauselist" into function
arguments, also adds a "packagenames" argument"""
def __init__(self, name, *clauses, **kwargs):
@@ -1567,6 +1568,16 @@ class Select(SelectBaseMixin, FromClause):
if e is not None:
self._engine = e
return e
+ # look through the columns (largely synomous with looking
+ # through the FROMs except in the case of CalculatedClause/Function)
+ for cc in self._raw_columns:
+ for c in cc.columns:
+ if getattr(c, 'table', None) is self:
+ continue
+ e = c.engine
+ if e is not None:
+ self._engine = e
+ return e
return None
class UpdateBase(ClauseElement):