O
O
old_stalin2020-10-08 15:12:55
Python
old_stalin, 2020-10-08 15:12:55

Why am I getting "sqlite3.OperationalError: no such column: test" error?

There is a table

cursor_voice.execute("""CREATE TABLE IF NOT EXISTS voice_data(
            c_name TEXT,
            c_id INT,
            v_name TEXT,
            v_id INT
        )""")

I want to update the values ​​​​in it (name_category contains the value test):
cursor_voice.execute("UPDATE voice_data SET c_name =  {}".format(name_category))
cursor_voice.execute("UPDATE voice_data SET c_id = {}".format(category_private.id))
cursor_voice.execute("UPDATE voice_data SET v_name = {}".format(voice_private))
cursor_voice.execute("UPDATE voice_data SET v_id = {}".format(voice_private.id))
voice.commit()

An error is thrown:
cursor_voice.execute("UPDATE voice_data SET c_name = {}".format(name_category))
sqlite3.OperationalError: no such column: test

How to solve it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Karbivnichy, 2020-10-08
@old_stalin

Queries with parameters in SQLite
Try this:

cursor_voice.execute("UPDATE voice_data SET c_name=?",(name_category,))
Only I do not understand the meaning of this request.

S
Sergey Gornostaev, 2020-10-08
@sergey-gornostaev

Because it is not necessary to substitute values ​​in the sql query using string formatting.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question