]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
scalar() returns None if no rows
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 27 Jan 2006 23:56:13 +0000 (23:56 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 27 Jan 2006 23:56:13 +0000 (23:56 +0000)
lib/sqlalchemy/sql.py

index c3048de29422fd928da31405b49f3a3d5d401fb1..4ec7cbb7bfaa3c0ca9cd844a722119b7d167df96 100644 (file)
@@ -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."""