1

I'm having an issue getting my python script to update my sqlite db.

The first part seems to work fine:

conn = sqlite3.connect('/Users/test/Desktop/my-accounts.db')
currentAccount = None

for row in conn.execute('SELECT email FROM accounts WHERE active=0'):
    currentAccount = row[0]
    print "Checking out: ",currentAccount
    break

if currentAccount is None:
    print "No available accounts"

Then this next part I want to take the variable currentAccount and update the row in the db where that value is.

else:
    conn.execute('UPDATE accounts SET active=1 WHERE email=?', [currentAccount,])

conn.close()

I don't get any errors in the console but the db does not update. The email column is a VARCHAR and the active column is an INT.

Thanks.

SOLUTION was to add conn.commit() after execute()

4
  • I've tried both as a tuple and a list. Neither one successfully updates the db. Commented Mar 30, 2013 at 8:00
  • 1
    try to add conn.commit() after conn.execute("XXX"). Sometimes sqlite3 doesn't auto commit the execution. Commented Mar 30, 2013 at 8:01
  • I will put the comment as a answer. Commented Mar 30, 2013 at 8:15
  • All DB-API 2.0 compatible driver disable auto commit by default. Commented Mar 30, 2013 at 8:19

1 Answer 1

1

try to add conn.commit() after conn.execute("XXX"). Sometimes sqlite3 doesn't auto commit the execution.

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

1 Comment

It's not sometime, auto commit is disabled by default

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.