[python-sybase] RE: Sybase Module 0.36 Output Parameter Handling
Dave Cole
djc at object-craft.com.au
Fri, 18 Mar 2005 17:00:27 +1100
Dave Cole wrote:
> Dave Cole <djc@object-craft.com.au>Dave Cole
> <djc@object-craft.com.au>Dave Cole wrote:
>
>> 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
>> only when you use a sequence to pass parameters. Dictionary
>> 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.
>
>
> I just installed FreeTDS 0.61 (Debian sarge) and the test program fails
> to run. The ct_param() functions fail. What I did discover was that
> you can fudge it like this:
>
> print db.execute('''
> declare @result int
> exec sp_test_output 12345, @result output
> select @result
> ''')
>
> It prints the following:
> [[], [(12345,)]]
>
> I am now downloading the current cvs snapshot for FreeTDS to see if they
> have fixed parameter passing.
I just downloaded and installed the CVS snapshot. With the original
test program it appears to send the parameters to the server but fails
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)
-> CS_SUCCEED
ct_param(cmd3, &databuf0->fmt=[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=[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
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 = c.callproc('sp_test_output', {'@num': 12345, '@result':
Sybase.OUTPUT(1)})
File "/usr/lib/python2.3/site-packages/Sybase.py", line 718, in callproc
self.description = 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
works. I get crap back.
Oh well, looks like I can wait for another couple of FreeTDS releases
before trying again...
- Dave
--
http://www.object-craft.com.au