[python-sybase] ProgramingError on empty result set

Hrvoje Niksic hniksic at iskon.hr
Wed, 13 Aug 2003 17:55:05 +0200


Hrvoje Niksic wrote:
> I'm using python-sybase with MS SQL 6.5 and FreeTDS 0.61.  I keep
> stumbling upon this:
[...]

In case someone else has problems with this, here is a possible (and 
extremely kludgy) workaround.  Of course, that's not a long-term 
solution, but it helps me write compliant application until the problem 
is fixed.

import Sybase

def replacefun(oldfun, exception_class, exception_arg, altresult):
     def newfun(*argl, **argk):
         try:
             res = oldfun(*argl, **argk)
         except exception_class, e:
             if e.args[0] == exception_arg:
                 return altresult
             else:
                 raise
         return res
     return newfun
Sybase.Cursor.fetchone = replacefun(Sybase.Cursor.fetchone,
                                     Sybase.ProgrammingError,
                                     'no result set pending',
                                     None)
Sybase.Cursor.fetchall = replacefun(Sybase.Cursor.fetchall,
                                     Sybase.ProgrammingError,
                                     'no result set pending',
                                     [])