I have the following Python3 code:
def updateDB(databaseLoc, post_id, new_class):
conn = sqlite3.connect(databaseLoc)
curs = conn.cursor()
vals = [new_class, post_id, ]
curs.execute('UPDATE POST SET CLASSIFICATION=? WHERE POSTID=?', vals)
conn.commit()
conn.close()
which is called occasionally with
if js[0]['data']['children'][0]['data']['ups'] > 2000:
print(post_id, "made it")
updateDB('retrieved_data.db',1,post_id)
However, even after the update and the commit, when I go into the database, nothing has changed (classification is still set to the initial value 0). I have tested the SQL string manually and it works fine.
I have comparable code for insertion that works fine:
def pushToDB(databaseLoc, posts):
conn = sqlite3.connect(databaseLoc)
curs = conn.cursor()
for p in posts:
vals = [p.id, p.title, p.s, p.time, p.day, "", p.first, p.second, p.image, 0, ]
try:
curs.execute('INSERT INTO POST VALUES(?,?,?,?,?,?,?,?,?,?)',vals)
except:
pass
conn.commit()
conn.close()
Is there an additional step that needs to be taken for a Python3 update? I have looked through the documentation and it doesn't specify anything additional, but then it only mentions update once and just glosses over it. I have also found very little on update examples in python