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

Skip Montanaro skip at pobox.com
Wed, 5 Jan 2005 10:17:10 -0600


Sorry to take so long to get back to this problem.  Squeaky wheels and all,
you know...

    >> 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")

    ...

    Dave> I think I know what is causing this.  If someone could do an
    Dave> experiment for me I will make the change and cut a new release
    Dave> (with the output hook patch as well).

    ...

    Dave> There are two possible ways to attempt a fix.

    Dave> 1) Construct the Fetcher in the FETCHING state.  This will mean
    Dave>    that any exception raised in the ct_command() or the ct_send()
    Dave>    function will result in ct_cancel(CS_CANCEL_ALL) when the
    Dave>    Fetcher is deleted.

    Dave>      In _FetchLazy.__init__() change:
    Dave>          self._state = _LAZY_IDLE
    Dave>      to
    Dave>          self._state = _LAZY_FETCHING

This didn't work.

    Dave> 2) Set the Fetcher state to FETCHING immediately before calling
    Dave>    ct_send() in _FetchLazy.start().

    Dave>      In _FetchLazy.start() change:
    Dave>          status = self._cmd.ct_send()
    Dave>      to
    Dave>          self._set_state(_LAZY_FETCHING)
    Dave>          status = self._cmd.ct_send()

This did...

Thanks,

Skip