Skip to content Skip to sidebar Skip to footer

Date Time Pass Value From Python To Mysql

I kept having sql syntax error.. what am I missing in here in order to pull data by day. Here's my python error : pyodbc.ProgrammingError: ('42000', '[42000] [MySQL][ODBC 5.1 Driv

Solution 1:

You execute a query with formatting parameters but never pass these in; the % (start, next) part goes outside of the SQL query:

cur_ca.execute("""
         select id,
     date_created,
     data
     from bureau_inquiry where date_created >= %s and date_created < %s
     """ % (start, next)
   )

You would be better off using SQL parameters however, so the database can prepare the query and reuse the query plan:

cur_ca.execute("""
         select id,
     date_created,
     data
     from bureau_inquiry where date_created >= ? and date_created < ?
     """, (start, next)
   )

PyODBC uses ? for SQL parameters.

Post a Comment for "Date Time Pass Value From Python To Mysql"