[python-sybase] Parameter passing with freetds/MSSQL2000
Dave Cole
djc at object-craft.com.au
20 Feb 2003 09:53:22 +1100
> What is the current status regarding parameter passing with
> freetds/MSSQL2000? I get an error if I try simple queries.
>
> import Sybase as dbapi
>
> con=dbapi.connect('cazalla','gotta','password','personal')
> cur=con.cursor()
> cur.execute('select * from usuarios where cd_usuario=@u',
> {'@u':'marcos'})
> pprint.pprint(cur.fetchall())
>
> This is what I get (line numbers are incorrect)
>
> Traceback (most recent call last):
> File "etcPythonSybase.py", line 191, in ?
> cur.execute('select * from usuarios where
> cd_usuario=@u',{'@u':'marcos'})
> File "/usr/lib/python2.2/site-packages/Sybase.py", line 379, in
> execute
> self._raise_error(Error, 'ct_param')
> File "/usr/lib/python2.2/site-packages/Sybase.py", line 309, in
> _raise_error
> raise exc(text)
> Sybase.Error: ct_param
I think it still has issues. :-)
Looking at the FreeTDS 0.61 source for ct_param():
CS_RETCODE
ct_param(CS_COMMAND * cmd, CS_DATAFMT * datafmt, CS_VOID * data, CS_INT datalen, CS_SMALLINT indicator)
{
TDSSOCKET *tds;
TDSDYNAMIC *dyn;
/* TDSINPUTPARAM param; */
tdsdump_log(TDS_DBG_FUNC, "%L inside ct_param()\n");
tdsdump_log(TDS_DBG_INFO1, "%L ct_param() data addr = %d data length = %d\n", data, datalen);
tds = cmd->con->tds_socket;
dyn = tds_lookup_dynamic(tds, cmd->dyn_id);
/* TODO */
return CS_FAIL;
/*
dyn = tds->dyns[elem];
param = tds_add_input_param(dyn);
param->column_type = _ct_get_server_type(datafmt->datatype);
param->varaddr = data;
if (datalen==CS_NULLTERM) {
param->column_bindlen = 0;
} else {
param->column_bindlen = datalen;
}
param->is_null = indicator;
return CS_SUCCEED;
*/
}
Note that the code which would actually do something is commented out
and the function unconditionally returns CS_FAIL.
So for the being, you cannot pass parameters to Cursor.execute() or
Cursor.callproc(), you must build a query string which does not use
parameters.
If I was really clever I would make Sybase.py adapt to the presense of
FreeTDS and turn have it shield you from that limitation in FreeTDS.
- Dave
--
http://www.object-craft.com.au