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.

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))
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)

Comments

Your Answer

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.