Re: ProgramingError on empty result set

Hrvoje Niksic <[email protected]>
Newsgroups gmane.comp.python.sybase
Message-ID <[email protected]>
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',
                                     [])
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.