diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-02-01 23:26:18 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-02-01 23:26:18 +0000 |
commit | b3a610dbc0eaaced4c529dc7c7dbf1cd2b503abc (patch) | |
tree | 656e863d59bd41c92e1626c8caab8b2c90dfd08d /lib/sqlalchemy/sql.py | |
parent | fd9c860700186de4b9aae97c7a3f67fe6ef18f84 (diff) | |
download | sqlalchemy-b3a610dbc0eaaced4c529dc7c7dbf1cd2b503abc.tar.gz |
might add scalar() to select which does limit=1
Diffstat (limited to 'lib/sqlalchemy/sql.py')
-rw-r--r-- | lib/sqlalchemy/sql.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql.py b/lib/sqlalchemy/sql.py index dcf153866..4ab1f1871 100644 --- a/lib/sqlalchemy/sql.py +++ b/lib/sqlalchemy/sql.py @@ -293,6 +293,10 @@ class Compiled(ClauseVisitor): """executes this compiled object via the execute() method, then returns the first column of the first row. Useful for executing functions, sequences, rowcounts, etc.""" + # we are still going off the assumption that fetching only the first row + # in a result set is not performance-wise any different than specifying limit=1 + # else we'd have to construct a copy of the select() object with the limit + # installed (else if we change the existing select, not threadsafe) row = self.execute(*multiparams, **params).fetchone() if row is not None: return row[0] @@ -399,6 +403,10 @@ class ClauseElement(object): """executes this SQL expression via the execute() method, then returns the first column of the first row. Useful for executing functions, sequences, rowcounts, etc.""" + # we are still going off the assumption that fetching only the first row + # in a result set is not performance-wise any different than specifying limit=1 + # else we'd have to construct a copy of the select() object with the limit + # installed (else if we change the existing select, not threadsafe) row = self.execute(*multiparams, **params).fetchone() if row is not None: return row[0] @@ -1324,6 +1332,13 @@ class Select(SelectBaseMixin, FromClause): def union_all(self, other, **kwargs): return union_all(self, other, **kwargs) +# def scalar(self, *multiparams, **params): + # need to set limit=1, but only in this thread. + # we probably need to make a copy of the select(). this + # is expensive. I think cursor.fetchone(), then discard remaining results + # should be fine with most DBs + # for now use base scalar() method + def _find_engine(self): """tries to return a SQLEngine, either explicitly set in this object, or searched within the from clauses for one""" |