[python-sybase] Small patch: factor out Cursor._checkready()

Greg Ward gward-pysybase at python.net
Fri Jul 28 01:25:12 EST 2006


Here's a small patch that I posted a few weeks ago.  I think it got lost
in the shuffle, since I never saw a response to my post.  It's a pure
refactoring: should have absolutely no effect on behaviour.  I've been
using it on my test server for several weeks now and it seems fine.

Andrew or Dave, can you give thumbs up or thumbs down on this one?

        Greg
-------------- next part --------------
--- Sybase.py.1.close-fetcher	2006-07-05 12:49:12.000000000 -0400
+++ Sybase.py	2006-07-07 09:10:29.000000000 -0400
@@ -788,19 +788,13 @@
     def fetchone(self):
         '''DB-API Cursor.fetchone()
         '''
-        if self._closed:
-            raise ProgrammingError('cursor is closed')
-        if not self._fetcher:
-            raise ProgrammingError('query has not been executed')
+        self._checkready()
         return self._fetcher.fetchone()
 
     def fetchmany(self, num = -1):
         '''DB-API Cursor.fetchmany()
         '''
-        if self._closed:
-            raise ProgrammingError('cursor is closed')
-        if not self._fetcher:
-            raise ProgrammingError('query has not been executed')
+        self._checkready()
         if num < 0:
             num = self.arraysize
         return self._fetcher.fetchmany(num)
@@ -808,25 +802,25 @@
     def fetchall(self):
         '''DB-API Cursor.fetchall()
         '''
-        if self._closed:
-            raise ProgrammingError('cursor is closed')
-        if not self._fetcher:
-            raise ProgrammingError('query has not been executed')
+        self._checkready()
         return self._fetcher.fetchall()
 
     def nextset(self):
         '''DB-API Cursor.nextset()
         '''
-        if self._closed:
-            raise ProgrammingError('cursor is closed')
-        if not self._fetcher:
-            raise ProgrammingError('query has not been executed')
+        self._checkready()
         desc = self._fetcher.nextset()
         if desc:
             self.description = desc
             return 1
         return 0
 
+    def _checkready(self):
+        if self._closed:
+            raise ProgrammingError('cursor is closed')
+        if not self._fetcher:
+            raise ProgrammingError('query has not been executed')
+
     def setinputsizes(self, *sizes):
         '''DB-API Cursor.setinputsizes()
         '''


More information about the Python-sybase mailing list