0
votes

I am trying to insert data into my SQL database however, I am receiving the following error:

sqlite3.OperationalError: unrecognized token: "7nbtkq".

Note, the value 7nbtkq is a public key of one of the data that I am trying to update.

I have looked at several other solutions but they are either different scenarios that don't apply to mine or their solutions haven't worked for me.

sql = """UPDATE parent_reply SET parent_id = '{}', comment_id = '{}', parent = '{}', comment = '{}', subreddit = {}, unix = {}, score = {} WHERE parent_id ={};""".format(parentid, commentid, parent, comment, subreddit, int(time), score, parentid)
c.execute(sql)

I am expecting my SQL database to be updated with these new values on the according record.

1
SET parent_id = '{}' ... WHERE parent_id ={} looks like one of placeholders is wrong. Shouldn't both be surrounded by quotes? - Serg
BTW, why update parent_id with the value it currently has? - Serg
@Serg I am really just trying to update those data like comment id and etc. Do you think I should remove the parent_id = '{}' in ` SET parent_id = '{}' . . . WHERE parent_id = '{}' because it has to be anyway due to the WHEN? - BlueCanary
I see no reason to have parent_id = '{}' in SET clause. - Serg
@Serg Okay, thanks for the help! - BlueCanary

1 Answers

1
votes

I think you should give '' to each value except int:

sql = """UPDATE parent_reply SET parent_id = '{}', comment_id = '{}', parent = '{}', comment = '{}', subreddit = '{}', unix = {}, score = '{}' WHERE parent_id ='{}'""".format(parentid, commentid, parent, comment, subreddit, int(time), score, parentid)