From bbd7c660560212844de3a92ba077bcec77740b16 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 3 Oct 2006 23:00:04 +0000 Subject: - 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). --- lib/sqlalchemy/sql.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/sql.py') 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): -- cgit v1.2.1