DB API question - where is a stored procedure's return value?

Skip Montanaro skip at pobox.com
Wed Mar 12 22:44:07 CET 2014

I've stumbled on a problem with the python-sybase module. If I have a
stored procedure like this:

create stored procedure test_proc
    return 1

and call it from Python like this:

curs.callproc("test_proc", {})

it's not clear to me where the return status is stored. Currently, the
python-sybase module provides (I believe) the ability to set output
parameters (those specified as such in the argument dictionary), and
you can iterate over all the result sets the stored procedure

Looking at the Python database API (PEP 249), I saw no mention of the
return status:

.callproc( procname [, parameters ] )

(This method is optional since not all databases provide stored procedures. [3])

Call a stored database procedure with the given name. The sequence of
parameters must contain one entry for each argument that the procedure
expects. The result of the call is returned as modified copy of the
input sequence. Input parameters are left untouched, output and
input/output parameters replaced with possibly new values.

The procedure may also provide a result set as output. This must then
be made available through the standard.fetch*() methods.

I see no mention of how to handle the return value. The "modified copy
of the input sequence" is just that. In the case of the python-sybase
module, any parameter values in the input dictionary  of type
DataBufType are rewritten with values from the first row of the first
result set. The Cursor class also defines a _status_result() method,
which sounds promising. I haven't had a chance to try it out yet. My
concern is more that the Python database API doesn't mention stored
procedure return values at all.

What do other database adaptors do about stored procedure return
values? Does PEP 249 need revision?


More information about the Python-list mailing list