Reputation: 13
I've written this code for an SQLite3 database in python:
i = datetime.datetime.now()
v_day = i.day
v_month = i.month
v_year = i.year
v_hour = i.hour
v_minute = i.minute
cur.execute("""INSERT INTO weather(
day,month,year,hour,minut,temperature,humidity) VALUES (
?,?,?,?,?,?,?),
(v_day,v_month,v_year,v_hour,v_minute,temp,hum)""")
After trying it, it displayed this Error: File "store_data.py", line 68, in main (v_day,v_month,v_year,v_hour,v_minute,temp,hum)""") sqlite3.OperationalError: no such column: v_day I've already tried to put the variables names in the VALUES' list, but I occured in the same Error.
Thank you for the answer.
Upvotes: 1
Views: 69
Reputation: 9494
Try this one:
sql = f"""INSERT INTO weather(day,month,year,hour,minut,temperature,humidity) VALUES ({v_day},{v_month},{v_year},{v_hour},{v_minute},{temp},{hum})"""
cur.execute(sql)
Upvotes: 0
Reputation: 819
Your tuple is inside your string. Also you shouldn't denote the table columns in the query. Try
cur.execute("INSERT INTO weather VALUES (?,?,?,?,?,?,?)",
(v_day,v_month,v_year,v_hour,v_minute,temp,hum))
Upvotes: 1