Python/MySQL Connector: Some queries hang based on the input -


so using python mysql connector, , trying write code select rows depending on whether or not row fits criteria give it. table has column chemicals , column counties in california (among others)

all of following lines of code run through mysql console:

select wellname, approximatelatitude, approximatelongitude, chemical, result, units, date, county chemicaldata (county='yolo') , (chemical='cr6')  select wellname, approximatelatitude, approximatelongitude, chemical, result, units, date, county chemicaldata (chemical='cr6')  select wellname, approximatelatitude, approximatelongitude, chemical, result, units, date, county chemicaldata (chemical='cr')  select wellname, approximatelatitude, approximatelongitude, chemical, result, units, date, county chemicaldata (county='yolo') , (chemical='cr')  select wellname, approximatelatitude, approximatelongitude, chemical, result, units, date, county chemicaldata (county='yolo') , (chemical='no3') 

for each statement above, put statement in quotes , executed through python. tried run simple script. example

query = "select wellname, approximatelatitude, approximatelongitude, chemical, result, units, date, county chemicaldata (county='yolo') , (chemical='cr')" cursor.execute(query) = 0 (wellname,approximatelatitude,approximatelongitude,chemical,result,units,date,county) in cursor:      print      = i+1 

can guys guess of above 5 statements python script worked on? third , fifth...it makes no sense me because pretty same thing accept changed chemical, , work on mysql command line. more specific, when command doesn't work on python, counter have in loop freezes in middle , stops doing anything. third , fifth statements, loop exits , starts printing things out after loop. can me determine might possibly wrong or different ways me debug code? appreciate help!

try use slash in query.

query = "select wellname, approximatelatitude, approximatelongitude, chemical, result, units, date, county chemicaldata (county=\'yolo\') , (chemical=\'cr\')" cursor.execute(query) = 0 (wellname,approximatelatitude,approximatelongitude,chemical,result,units,date,county) in cursor:      print      = i+1 

tell me if works.


Comments