]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
added scalar() to ResultProxy
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 23 Sep 2006 21:13:10 +0000 (21:13 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 23 Sep 2006 21:13:10 +0000 (21:13 +0000)
CHANGES
lib/sqlalchemy/engine/base.py

diff --git a/CHANGES b/CHANGES
index e7954d9830642aadbbcd70d875f8431ec7179c70..e3dc2f2741a0315ee0f654d70f93e69378cbbfb8 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -18,7 +18,7 @@ after commit/rollback
 - added extract() function to sql dialect
 - added an implicit close() on the cursor in ResultProxy
 when the result closes
-- added scalar() method to ComposedSQLEngine
+- added scalar() method to ComposedSQLEngine, ResultProxy
 - post_update behavior improved; does a better job at not 
 updating too many rows, updates only required columns
 [ticket:208]
index 28d5ea94e658d2238163e560479e4d78ffface43..1285e8490de98b856ad45bb929b5fda11376d788 100644 (file)
@@ -593,6 +593,7 @@ class ResultProxy:
                 rec = self.props[key]
             self.__key_cache[key] = rec
             return rec
+            
     def _has_key(self, row, key):
         try:
             self._convert_key(key)
@@ -624,7 +625,7 @@ class ResultProxy:
         return self.executioncontext.supports_sane_rowcount()
         
     def fetchall(self):
-        """fetches all rows, just like DBAPI cursor.fetchall()."""
+        """fetch all rows, just like DBAPI cursor.fetchall()."""
         l = []
         while True:
             v = self.fetchone()
@@ -633,7 +634,7 @@ class ResultProxy:
             l.append(v)
             
     def fetchone(self):
-        """fetches one row, just like DBAPI cursor.fetchone()."""
+        """fetch one row, just like DBAPI cursor.fetchone()."""
         row = self.cursor.fetchone()
         if row is not None:
             if self.echo: self.engine.log(repr(row))
@@ -644,6 +645,18 @@ class ResultProxy:
             # and not just plain tuples ?
             self.close()
             return None
+
+    def scalar(self):
+        """fetch the first column of the first row, and close the result set."""
+        row = self.cursor.fetchone()
+        try:
+            if row is not None:
+                if self.echo: self.engine.log(repr(row))
+                return row[0]
+            else:
+                return None
+        finally:
+            self.close()
     
 class RowProxy:
     """proxies a single cursor row for a parent ResultProxy."""