I've got a simple SQL query that works fine from a mysql command line:
select dateandtime from times where their_id=0053 and dateandtime>= 2022-08-24 and dateandtime<=DATE_ADD("2022-08-24", INTERVAL 7 DAY);
If I try to do this programatically by doing either:
params = (their_id,date,date," INTERVAL 7 DAY")
query = "select dateandtime from times where their_id=%s and dateandtime>= %s and dateandtime<=DATE_ADD(%s,%s) ";
cursor.execute(query,(params))
or
params = (their_id,date,"\""+date+"\""," INTERVAL 7 DAY")
query = "select dateandtime from times where their_id=%s and dateandtime>= %s and dateandtime<=DATE_ADD(%s,%s) ";
cursor.execute(query,(params))
I get: mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' INTERVAL 7 DAY')' at line 1
The obvious question is, is there any way to parameterise this query? Secondly, though, to help with similar problems in future, is there any way with a parameterised query to see the query as interpreted by MYSQL once the paramaters have been parsed?
Any help would be very gratefully received!