[python-sybase] Connection unusable after an exception has been raised

Skip Montanaro skip at pobox.com
Fri, 3 Sep 2004 13:45:07 -0500


If a cursor's execute() method results in an error (say, from a trigger
failing for some reason) it appears there is no recourse to continue other
than closing the connection and starting over.  Here's the simple test case:

    c = Sybase.Connection(...)
    c1 = c.cursor()
    c1.execute("select * from blah")
    c2 = c.cursor()
    c2.execute("select 1")

The first execute() call results in a DatabaseError exception because there
is no column "blah".  The second execute() call also fails with a
DatabaseError, this time in ct_send.  The message is:

    ct_send(): user api layer: external error: This routine cannot be called
    because another command structure has results pending.

How do I toss those pending results?  I've tried wrapping the c1 calls in
c.begin()/c.rollback() calls.  I've tried closing and/or deleting c1.  I've
tried fetching the nonexistent results of the failed execute() call.
Nothing seems to make Sybase happy again until a new connection is created.

Is there a better (less sledgehammer-like) way to recover from errors?

Thanks,

-- 
Skip Montanaro
Got spam? http://www.spambayes.org/
skip@pobox.com