[python-win32] How to specify parameters in a query using odbc [SEC=PERSONAL]
Andrew MacIntyre
Andrew.MacIntyre at acma.gov.au
Tue Feb 1 23:28:40 CET 2011
The odbc module in Pythonwin uses qmark parameter style I believe, so
use ? instead of %s for parameter substitution.
-------------------------> "These thoughts are mine alone!" <---------
Andrew MacIntyre Operations Branch
tel: +61 2 6219 5356 Communications Infrastructure Division
fax: +61 2 6253 3277 Australian Communications & Media Authority
email: andrew.macintyre at acma.gov.au
<mailto:andrew.macintyre at acma.gov.au>
http://www.acma.gov.au/ <http://www.acma.gov.au/>
Tom Hawkins wrote
I'm trying to get data out of a MS SQL Server 2005 database from a
Python 2.5 script, using the odbc module - I can't easily get anything
more up-to-date installed on this system.
{...}
...it works OK, but if I try to parameterise the query:
myQuery = """SELECT EnteredValue FROM SampleTests INNER JOIN
SampleResults
ON (SampleTests.SampleCode = SampleResults.SampleCode AND
SampleTests.AuditFlag = SampleResults.AuditFlag AND
SampleTests.TestPosition = SampleResults.TestPosition)
WHERE (SampleTests.SampleCode=%s AND SampleTests.AuditFlag=0 AND
SampleTests.TestCode=%s AND
SampleTests.TestStatus<900 AND SampleResults.ComponentName='IntMethod')
"""
...
cursor.execute(myQuery, ('foo', 'bar'))
...I get:
dbi.program-error: [Microsoft][ODBC SQL Server Driver][SQL
Server]Incorrect syntax near 's'. in EXEC
Any idea what I'm doing wrong please? Apologies if I've missed something
stupid. I get the same error if I only specify one of the parameters
with %s and leave the other one literal, by the way.
NOTICE: This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any unauthorized
review, use, disclosure or distribution is prohibited. If you are not the
intended recipient, please contact the sender by reply email and destroy all
copies of the original message.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20110202/1706c6ab/attachment.html>
More information about the python-win32
mailing list