0

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

1 Answer 1

1

The signature for the function is:

def updateDB(databaseLoc, post_id, new_class):

But you appear to be calling it with:

updateDB(databaseLoc, new_class, post_id)

Resulting in trying to update the post where POSTID = 1 every time, which is probably not what you wanted.

Sign up to request clarification or add additional context in comments.

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.