Update of /usr/cvs/Public/pygresql/module
In directory druid.net:/tmp/cvs-serv14329/module

Modified Files:
        TEST_PyGreSQL_dbapi20.py pgdb.py 
Log Message:
Let execute() and executemany() methods return the cursor object. Removed an 
unnecessary call in executemany().
To see the diffs for this commit:
   
http://www.druid.net/pygresql/viewcvs.cgi/cvs/pygresql/module/TEST_PyGreSQL_dbapi20.py.diff?r1=1.15&r2=1.16

Index: TEST_PyGreSQL_dbapi20.py
===================================================================
RCS file: /usr/cvs/Public/pygresql/module/TEST_PyGreSQL_dbapi20.py,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- TEST_PyGreSQL_dbapi20.py    23 Nov 2008 13:14:05 -0000      1.15
+++ TEST_PyGreSQL_dbapi20.py    2 Apr 2009 22:18:59 -0000       1.16
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-# $Id: TEST_PyGreSQL_dbapi20.py,v 1.15 2008/11/23 13:14:05 cito Exp $
+# $Id: TEST_PyGreSQL_dbapi20.py,v 1.16 2009/04/02 22:18:59 cito Exp $
 
 import dbapi20
 import unittest
@@ -51,7 +51,8 @@
 
         con = self._connect()
         curs = myCursor(con)
-        curs.execute("select 1 as a, 2 as b")
+        ret = curs.execute("select 1 as a, 2 as b")
+        self.assert_(ret is curs, 'execute() should return cursor')
         self.assertEqual(curs.fetchone(), {'a': 1, 'b': 2})
 
     def test_cursor_iteration(self):

   
http://www.druid.net/pygresql/viewcvs.cgi/cvs/pygresql/module/pgdb.py.diff?r1=1.54&r2=1.55

Index: pgdb.py
===================================================================
RCS file: /usr/cvs/Public/pygresql/module/pgdb.py,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -r1.54 -r1.55
--- pgdb.py     23 Nov 2008 14:32:18 -0000      1.54
+++ pgdb.py     2 Apr 2009 22:18:59 -0000       1.55
@@ -4,7 +4,7 @@
 #
 # Written by D'Arcy J.M. Cain
 #
-# $Id: pgdb.py,v 1.54 2008/11/23 14:32:18 cito Exp $
+# $Id: pgdb.py,v 1.55 2009/04/02 22:18:59 cito Exp $
 #
 
 """pgdb - DB-API 2.0 compliant module for PygreSQL.
@@ -248,15 +248,16 @@
 
     def execute(self, operation, params=None):
         """Prepare and execute a database operation (query or command)."""
+
         # The parameters may also be specified as list of
         # tuples to e.g. insert multiple rows in a single
         # operation, but this kind of usage is deprecated:
         if (params and isinstance(params, list)
                 and isinstance(params[0], tuple)):
-            self.executemany(operation, params)
+            return self.executemany(operation, params)
         else:
             # not a list of tuples
-            self.executemany(operation, (params,))
+            return self.executemany(operation, [params])
 
     def executemany(self, operation, param_seq):
         """Prepare operation and execute it against a parameter sequence."""
@@ -295,11 +296,14 @@
             getdescr = self._type_cache.getdescr
             coltypes = self._src.listinfo()
             self.description = [typ[1:2] + getdescr(typ[2]) for typ in 
coltypes]
-            self.lastrowid = self._src.oidstatus()
+            self.lastrowid = None
         else:
             self.rowcount = totrows
             self.description = None
             self.lastrowid = self._src.oidstatus()
+        # return the cursor object, so you can write statements such as
+        # "cursor.execute(...).fetchall()" or "for row in cursor.execute(...)"
+        return self
 
     def fetchone(self):
         """Fetch the next row of a query result set."""

_______________________________________________
PyGreSQL mailing list
[email protected]
http://mailman.vex.net/mailman/listinfo/pygresql

Reply via email to