I want to write a 'select' command of mysql through python and I want to use date-time object of python:
cnxn = pyodbc.connect('DSN=aaa;')
cursor = cnxn.cursor()
cursor.execute("select * from tableA where time>" + str(CurrentTime)+ " order by time asc")
where type of CurrentTime is datetime.datetime.
When I print the above string, it looks fine, but when I run this, it gives me an error:
pyodbc.ProgrammingError: ('42000', "[42000] [MySQL][ODBC 5.3(w) Driver][mysqld-5.5.16-log]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 '11:17:07 order by time asc' at line 1 (1064) (SQLExecDirectW)")
Solved: cursor.execute("""select * from tablea where time> ? order by time asc""" , str(CurrentTime))