Execute paramaters bug?

"May, Chuck (IMS)" <[email protected]>
Newsgroups gmane.comp.python.sybase
Message-ID <[email protected]>
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__=='__main__':
    import Sybase

    db = Sybase.connect('peach5025d', 'may', 'maymay', 'bsiweb_dev')
    c = db.cursor()

    status_id = 0
    output_text = "OUTPUT"
    error_text = "ABC"
    job_id = 30

    # this works (all numeric fields)
    c.execute('UPDATE jobs SET status_id = @status_id WHERE job_id =
@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 = 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 = @error_text WHERE job_id =
@job_id", \
              { '@error_text' : error_text, '@job_id' : job_id })
    
    # this works (all varchar fields)
    c.execute("UPDATE jobs SET output = @output, error_text =
@error_text WHERE job_id = 30", \
               { '@output' : output_text, '@error_text' : error_text })

    db.commit()
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.