I am trying to use the parameters feature of the execute for the first
time, and there seems to be a bug. I all the parameters I set are of
the same type (all numeric, all varchar, etc...), then the call works
fine. However, if I mix and match, I get some strange errors. The code
is below.
Also, is there a function, like in Perl::DBI, which will escape a string
so that you can build an SQL string. It handles strings with quotes,
etc... I assume if I can get the parameters working, it won't matter.
Thanks,
Chuck
#!/usr/bin/env python -O
if __name__=3D=3D'__main__':
import Sybase
db =3D Sybase.connect('peach5025d', 'may', 'maymay', 'bsiweb_dev')
c =3D db.cursor()
status_id =3D 0
output_text =3D "OUTPUT"
error_text =3D "ABC"
job_id =3D 30
# this works (all numeric fields)
c.execute('UPDATE jobs SET status_id =3D @status_id WHERE job_id =3D
@job_id', \
{ '@job_id' : job_id, '@status_id' : 1 })
# this doesn't work (one numeric, one varchar), and give the
following error:
# Traceback (most recent call last):
# File "./testd.py", line 19, in ?
# { '@error_text' : error_text, '@job_id' : job_id })
# File "/opt/net/utils/lib/python2.2/site-packages/Sybase.py",
line 376, in execute
# self._start_results()
# File "/opt/net/utils/lib/python2.2/site-packages/Sybase.py",
line 548, in _start_results
# status, result =3D self._cmd.ct_results()
# File "/opt/net/utils/lib/python2.2/site-packages/Sybase.py",
line 145, in _servermsg_cb
# raise DatabaseError(_fmt_server(msg))
# Sybase.DatabaseError: Msg 1622, Level 18, State 2, Line 1
# Type 'C' not implemented.
c.execute("UPDATE jobs SET error_text =3D @error_text WHERE job_id =
=3D
@job_id", \
{ '@error_text' : error_text, '@job_id' : job_id })
=20
# this works (all varchar fields)
c.execute("UPDATE jobs SET output =3D @output, error_text =3D
@error_text WHERE job_id =3D 30", \
{ '@output' : output_text, '@error_text' : error_text })
db.commit()
|