[python-sybase] RE: Sybase Module 0.36 Output Parameter Handling

Bradley Feldman bradley at relevantevidence.com
Thu, 17 Mar 2005 22:10:51 -0800


What version of FreeTDS are you using?

I'm not seeing any errors like that at all.  I'm using FreeTDS 0.62.4.  =
See
below:

Cursor.callproc
ct_cmd_alloc(conn0, &cmd) -> CS_SUCCEED, cmd3
ct_command(cmd3, CS_RPC_CMD, "sp_test_output", CS_NULLTERM, CS_UNUSED) =
->
CS_SUCCEED
ct_param(cmd3, &databuf0->fmt=3D[name:"@result" type:CS_INT_TYPE
status:CS_RETURN format:CS_FMT_UNUSED count:1 maxlength:4 scale:0
precision:0], databuf0->buff, 4, 0) -> CS_SUCCEED
ct_param(cmd3, &databuf1->fmt=3D[name:"@num" type:CS_INT_TYPE
status:CS_INPUTVALUE format:CS_FMT_UNUSED count:1 maxlength:4 scale:0
precision:0], databuf1->buff, 4, 0) -> CS_SUCCEED
ct_send(cmd3) -> CS_SUCCEED
ct_results(cmd3, &result) -> CS_SUCCEED, CS_STATUS_RESULT
ct_res_info(cmd3, CS_NUMDATA, &value, CS_UNUSED, NULL) -> CS_SUCCEED, 1
ct_describe(cmd3, 1, &fmt) -> CS_SUCCEED, datafmt0=3D[name:"" =
type:CS_INT_TYPE
status:CS_FALSE format:CS_FMT_UNUSED count:1 maxlength:4 scale:0
precision:0]
ct_bind(cmd3, 1, &datafmt0->fmt=3D[name:"" type:CS_INT_TYPE =
status:CS_FALSE
format:CS_FMT_UNUSED count:1 maxlength:4 scale:0 precision:0],
databuf2->buff, databuf2->copied, databuf2->indicator) -> CS_SUCCEED,
databuf2
_fetch_rows
ct_fetch(cmd3, CS_UNUSED, CS_UNUSED, CS_UNUSED, &rows_read) -> =
CS_SUCCEED, 1
_fetch_rows
ct_fetch(cmd3, CS_UNUSED, CS_UNUSED, CS_UNUSED, &rows_read) -> =
CS_END_DATA,
0
ct_results(cmd3, &result) -> CS_SUCCEED, CS_PARAM_RESULT
ct_res_info(cmd3, CS_NUMDATA, &value, CS_UNUSED, NULL) -> CS_SUCCEED, 1
ct_describe(cmd3, 1, &fmt) -> CS_SUCCEED, datafmt1=3D[name:"@result"
type:CS_INT_TYPE status:CS_FALSE format:CS_FMT_UNUSED count:1 =
maxlength:4
scale:0 precision:0]
ct_bind(cmd3, 1, &datafmt1->fmt=3D[name:"@result" type:CS_INT_TYPE
status:CS_FALSE format:CS_FMT_UNUSED count:1 maxlength:4 scale:0
precision:0], databuf3->buff, databuf3->copied, databuf3->indicator) ->
CS_SUCCEED, databuf3
ct_fetch(cmd3, CS_UNUSED, CS_UNUSED, CS_UNUSED, &rows_read) -> =
CS_SUCCEED, 1
ct_fetch(cmd3, CS_UNUSED, CS_UNUSED, CS_UNUSED, &rows_read) -> =
CS_END_DATA,
0
ct_results(cmd3, &result) -> CS_SUCCEED, CS_CMD_SUCCEED
ct_results(cmd3, &result) -> CS_SUCCEED, CS_CMD_DONE
ct_results(cmd3, &result) -> CS_END_RESULTS, CS_FALSE
{'@num': 12345, '@result': <DataBufType object at 0x2a95596770>}
Cursor.callproc
ct_cmd_drop(cmd3) -> CS_SUCCEED
ct_cmd_alloc(conn0, &cmd) -> CS_SUCCEED, cmd4
ct_command(cmd4, CS_RPC_CMD, "sp_test_output", CS_NULLTERM, CS_UNUSED) =
->
CS_SUCCEED
ct_param(cmd4, &databuf5->fmt=3D[name:"" type:CS_INT_TYPE =
status:CS_INPUTVALUE
format:CS_FMT_UNUSED count:1 maxlength:4 scale:0 precision:0],
databuf5->buff, 4, 0) -> CS_SUCCEED
ct_param(cmd4, &databuf4->fmt=3D[name:"" type:CS_INT_TYPE =
status:CS_RETURN
format:CS_FMT_UNUSED count:1 maxlength:4 scale:0 precision:0],
databuf4->buff, 4, 0) -> CS_SUCCEED
ct_send(cmd4) -> CS_SUCCEED
ct_results(cmd4, &result) -> CS_SUCCEED, CS_STATUS_RESULT
ct_res_info(cmd4, CS_NUMDATA, &value, CS_UNUSED, NULL) -> CS_SUCCEED, 1
ct_describe(cmd4, 1, &fmt) -> CS_SUCCEED, datafmt2=3D[name:"" =
type:CS_INT_TYPE
status:CS_FALSE format:CS_FMT_UNUSED count:1 maxlength:4 scale:0
precision:0]
ct_bind(cmd4, 1, &datafmt2->fmt=3D[name:"" type:CS_INT_TYPE =
status:CS_FALSE
format:CS_FMT_UNUSED count:1 maxlength:4 scale:0 precision:0],
databuf6->buff, databuf6->copied, databuf6->indicator) -> CS_SUCCEED,
databuf6
_fetch_rows
ct_fetch(cmd4, CS_UNUSED, CS_UNUSED, CS_UNUSED, &rows_read) -> =
CS_SUCCEED, 1
_fetch_rows
ct_fetch(cmd4, CS_UNUSED, CS_UNUSED, CS_UNUSED, &rows_read) -> =
CS_END_DATA,
0
ct_results(cmd4, &result) -> CS_SUCCEED, CS_PARAM_RESULT
ct_res_info(cmd4, CS_NUMDATA, &value, CS_UNUSED, NULL) -> CS_SUCCEED, 1
ct_describe(cmd4, 1, &fmt) -> CS_SUCCEED, datafmt3=3D[name:"" =
type:CS_INT_TYPE
status:CS_FALSE format:CS_FMT_UNUSED count:1 maxlength:4 scale:0
precision:0]
ct_bind(cmd4, 1, &datafmt3->fmt=3D[name:"" type:CS_INT_TYPE =
status:CS_FALSE
format:CS_FMT_UNUSED count:1 maxlength:4 scale:0 precision:0],
databuf7->buff, databuf7->copied, databuf7->indicator) -> CS_SUCCEED,
databuf7
ct_fetch(cmd4, CS_UNUSED, CS_UNUSED, CS_UNUSED, &rows_read) -> =
CS_SUCCEED, 1
ct_fetch(cmd4, CS_UNUSED, CS_UNUSED, CS_UNUSED, &rows_read) -> =
CS_END_DATA,
0
ct_results(cmd4, &result) -> CS_SUCCEED, CS_CMD_SUCCEED
ct_results(cmd4, &result) -> CS_SUCCEED, CS_CMD_DONE
ct_results(cmd4, &result) -> CS_END_RESULTS, CS_FALSE
[54321, <DataBufType object at 0x2a95596940>]
ct_cmd_drop(cmd4) -> CS_SUCCEED
ct_con_props(conn0, CS_GET, CS_CON_STATUS, &value, CS_UNUSED, NULL) ->
CS_SUCCEED, CS_CONSTAT_CONNECTED
ct_close(conn0, CS_OPT_STATS_IO) -> CS_SUCCEED
ct_con_drop(conn0) -> CS_SUCCEED

-----Original Message-----
From: python-sybase-admin@www.object-craft.com.au
[mailto:python-sybase-admin@www.object-craft.com.au] On Behalf Of Dave =
Cole
Sent: Thursday, March 17, 2005 10:00 PM
To: python-sybase@www.object-craft.com.au
Subject: Re: [python-sybase] RE: Sybase Module 0.36 Output Parameter
Handling


Dave Cole wrote:
> Dave Cole <djc@object-craft.com.au>Dave Cole
> <djc@object-craft.com.au>Dave Cole wrote:
>=20
>> I just installed ASE 12.5.2 on my machine so I could do some testing.
>> It appears there is a problem with the Cursor.callproc() method, but=20
>> only when you use a sequence to pass parameters.  Dictionary=20
>> parameters are fine.
>>
>> The attached sp_test.py program shows my testing.
>>
>> This program produces the following output (after applying the
>> attached callproc.patch to fix sequence argument passing).
>>
>> {'@num': 12345, '@result': 12345}
>> [54321, 54321]
>>
>> If I remove the comment character from the code that enables the
>> debugging I get the output contained in the attached sp_test.log.
>>
>> So if it is not working with FreeTDS then they are doing something
>> slightly differently that is either confusing my code or is =
incorrect.
>=20
>=20
> I just installed FreeTDS 0.61 (Debian sarge) and the test program=20
> fails
> to run.  The ct_param() functions fail.  What I did discover was that=20
> you can fudge it like this:
>=20
> print db.execute('''
> declare @result int
> exec sp_test_output 12345, @result output
> select @result
> ''')
>=20
> It prints the following:
> [[], [(12345,)]]
>=20
> I am now downloading the current cvs snapshot for FreeTDS to see if=20
> they
> have fixed parameter passing.

I just downloaded and installed the CVS snapshot.  With the original=20
test program it appears to send the parameters to the server but fails=20
with a server message.

Looking at the debug log:

Cursor.callproc
ct_cmd_alloc(conn0, &cmd) -> CS_SUCCEED, cmd3
ct_command(cmd3, CS_RPC_CMD, "sp_test_output", CS_NULLTERM, CS_UNUSED)=20
-> CS_SUCCEED
ct_param(cmd3, &databuf0->fmt=3D[name:"@result" type:CS_INT_TYPE=20
status:CS_RETURN format:CS_FMT_UNUSED count:1 maxlength:4 scale:0=20
precision:0], databuf0->buff, 4, 0) -> CS_SUCCEED ct_param(cmd3,
&databuf1->fmt=3D[name:"@num" type:CS_INT_TYPE=20
status:CS_INPUTVALUE format:CS_FMT_UNUSED count:1 maxlength:4 scale:0=20
precision:0], databuf1->buff, 4, 0) -> CS_SUCCEED


So it appears that parameters are being accepted by FreeTDS but from the =

next debug lines, they are not being sent correctly.


ct_send(cmd3) -> CS_SUCCEED
servermsg_cb
Msg 245, Level 16, State 1, Procedure sp_test_output
Domain error during implicit conversion of DECIMAL value '' to a INT =
field.
servermsg_cb Msg 245, Level 16, State 1, Procedure sp_test_output Domain
error during implicit conversion of DECIMAL value '' to a INT field.
ct_results(cmd3, &result) -> CS_SUCCEED, CS_STATUS_RESULT =
ct_cancel(conn0,
NULL, CS_CANCEL_ALL) -> CS_SUCCEED Traceback (most recent call last):
   File "a.py", line 21, in ?
     r =3D c.callproc('sp_test_output', {'@num': 12345, '@result':=20
Sybase.OUTPUT(1)})
   File "/usr/lib/python2.3/site-packages/Sybase.py", line 718, in =
callproc
     self.description =3D fetcher.start(self.arraysize, out_params)
   File "/usr/lib/python2.3/site-packages/Sybase.py", line 391, in start
     return _FetchNow.start(self, arraysize)
   File "/usr/lib/python2.3/site-packages/Sybase.py", line 315, in start
     raise e
Sybase.DatabaseError: Msg 245, Level 16, State 1, Procedure =
sp_test_output
Domain error during implicit conversion of DECIMAL value '' to a INT =
field.
Msg 245, Level 16, State 1, Procedure sp_test_output Domain error during
implicit conversion of DECIMAL value '' to a INT field.

Even more worrying is that the fudge in the previous message no longer=20
works.  I get crap back.

Oh well, looks like I can wait for another couple of FreeTDS releases=20
before trying again...

- Dave

--=20
http://www.object-craft.com.au
_______________________________________________
Python-sybase mailing list Python-sybase@www.object-craft.com.au
https://www.object-craft.com.au/cgi-bin/mailman/listinfo/python-sybase