Python: automate input to MySQL query
Threader Slash
threaderslash at gmail.com
Mon Sep 21 05:18:06 EDT 2009
Hi Everybody...
I have a query that works as follows:
Code:
db.query("""SELECT traveler.travelerFirstName,vaccine.vaccineName from
(traveler INNER JOIN takenvaccine ON traveler.travelerID =
takenvaccine.travelerID)
INNER JOIN vaccine ON takenvaccine.vaccineID=vaccine.vaccineID
INNER JOIN requiredvaccine ON
vaccine.vaccineID=requiredvaccine.requiredvaccineID
INNER JOIN city ON requiredvaccine.cityID = city.cityID
WHERE traveler.travelerFirstName = 'John'""")
The output gives me all vaccines taken by a given employee. To allow the
user to choose different names when running the system, I am trying to use a
variable, named *person*:
Code:
person = "John"
db.query("""SELECT traveler.travelerFirstName,vaccine.vaccineName from
(traveler INNER JOIN takenvaccine ON traveler.travelerID =
takenvaccine.travelerID)
INNER JOIN vaccine ON takenvaccine.vaccineID=vaccine.vaccineID
INNER JOIN requiredvaccine ON
vaccine.vaccineID=requiredvaccine.requiredvaccineID
INNER JOIN city ON requiredvaccine.cityID = city.cityID
WHERE traveler.travelerFirstName = 'person'""")
Then I run the query inside my python program. The first version without
variable works fine. But the second, using variable, doesn't give me any
output. What I am missing here about the python variable sintaxe to make the
MySQL work with variable ... Any suggestion?
All comments or suggestions are highly appreciated!
Threader
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090921/e2b49932/attachment.html>
More information about the Python-list
mailing list