[DB-SIG] Mysqldb python variable in request
wnvcole at peppermillcas.com
Thu Jan 22 11:47:39 EST 2004
There is some confusion here between supplying parameters to the SQL server,
which is done differently between different servers, and a python string
The python method always works, but is less efficient for repetative
This snippet from one of my programs does something like you want:
Sel = "select AuditDate from BB_PeriodEnd where (Casino_Code =
'%s' and Period_ID = 5 and AuditDate = '%s')" % (Casino_Code, AuditDate)
Note that all substitution is done in python, so I can check the syntax
using a python print statement. Also note that there are single quotes
around the %s constructs. These single quotes are passed to the SQL server,
which needs to see a string literal at that point. Python is filling in the
value for the literal. In your case, try something like:
cursor.execute(""" select %s from Xml2Mysql where %s='%s' """ % (target,
From: samira M'Bata [mailto:bouataa at hotmail.com]
Sent: Thursday, January 22, 2004 2:38 AM
To: db-sig at python.org
Subject: [DB-SIG] Mysqldb python variable in request
i hope someone could help me.
I d like to make an sql statement with python, in which the column names
will be parameter of a python function.
Bevore I tried to define my definition, i tried this code:
#DataType and Location are two columns of my Table
cursor.execute(""" select %s from Xml2Mysql where %s=%s """,(target,
I think the problem comes from the fact that my columns names are not as a
string type defined.
Should I change something in my table definition?
Add photos to your messages with MSN 8. Get 2 months FREE*.
DB-SIG maillist - DB-SIG at python.org
More information about the DB-SIG