From: Mike Bayer Date: Fri, 27 Jan 2006 23:56:13 +0000 (+0000) Subject: scalar() returns None if no rows X-Git-Tag: rel_0_1_0~99 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d917119235e7b43413e9b191492e0f5f48425cb0;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git scalar() returns None if no rows --- diff --git a/lib/sqlalchemy/sql.py b/lib/sqlalchemy/sql.py index c3048de294..4ec7cbb7bf 100644 --- a/lib/sqlalchemy/sql.py +++ b/lib/sqlalchemy/sql.py @@ -293,7 +293,11 @@ 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.""" - return self.execute(*multiparams, **params).fetchone()[0] + row = self.execute(*multiparams, **params).fetchone() + if row is not None: + return row[0] + else: + return None class ClauseElement(object): """base class for elements of a programmatically constructed SQL expression."""