1

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.

emremrah
1,77515 silver badges24 bronze badges
asked Apr 4, 2020 at 10:40

2 Answers 2

1

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))
answered Apr 4, 2020 at 10:43
Sign up to request clarification or add additional context in comments.

Comments

0

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)
answered Apr 4, 2020 at 10:54

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.