[python-sybase] How to handle stored procedure errors?

Harri Pasanen harri.pasanen at trema.com
Mon, 13 May 2002 15:37:21 +0200


Me again,

I'm wondering how should I handle stored procedures returning error codes?  
Looks like the Sybase module 0.35pre1 raises an exception on those, and drops 
the connection.

The documentation on cursor.execute() and cursor.callproc() did not mention 
anything.

For example, calling sp_helpindex with a table having no indexes will throw an 
exception, after which a reconnect is required:

So my code looks something like:

import Sybase
db = Sybase.connect('SYBASE12', 'user', 'pwd', 'dbname',  auto_commit=1)

def IndexInfo(table):
   global db
    cmd = "sp_helpindex %s" % table
    try:
        print db.execute(cmd)
    except Sybase.DatabaseError:
        db = Sybase.connect('SYBASE12', 'user', 'pwd', 'dbname', 
auto_commit=1)
        pass

Which is not very clean.  



-Harri