Reputation: 45
I'm doing my first project in sqlite3 using python . But I keep getting an error saying:
MCurs.execute("""UPDATE Artist SET sqlite3.ProgrammingError: You did not supply a value for binding 5.
MCurs.execute("""UPDATE Artist SET
first_name=:first,
last_name=:last,
genre=:genre,
album=:album
Where oid =:oid""",
{
'first':first_name_box_edit.get(),
'last':last_name_box_edit.get(),
'genre':genre_box_edit.get(),
'album':album_box_edit.get()
})
Upvotes: 1
Views: 62
Reputation: 15088
Basically your error was that you said :oid
but gave no assignment for :oid
in the dictionary. So you will have to specify what the :oid
is in the dictionary, like:
{
'first':first_name_box_edit.get(),
'last':last_name_box_edit.get(),
'genre':genre_box_edit.get(),
'album':album_box_edit.get(),
'oid':whatever_variable #here you have to specify your oid
}
Or there is this better way of using placeholders with SQLite, ie, ?
. Here is how:
sql_command = """UPDATE Artist SET
first_name=?,
last_name=?,
genre=?,
album=?
Where oid=?"""
values = first_name_box_edit.get(),last_name_box_edit.get(),genre_box_edit.get(),album_box_edit.get(),oid_variable)
MCurs.execute(sql_command,values)
Basically your just changing :first
with ?
and then later giving a value for that from the passed tuple. Here values
is the tuple. Though you can combine all these into just a single execute()
. Also keep in mind whatever value your passing HAS to be a tuple.
But either way keep in mind, your not passing in the value for oid
and that is the error.
Upvotes: 1
Reputation: 1308
oid is miss, look this way, that is more correct and simple, I've "supply a value for binding 5" that is oid = 1
sql = "UPDATE Artist SET first_name =?, last_name =?, genre =?, album =? WHERE oid =?"
args = (first_name_box_edit.get(),
last_name_box_edit.get(),
genre_box_edit.get(),
album_box_edit.get(),
1)
cur.execute(sql, args)
Upvotes: 0