1

It's a similar problem to others out there but no body has clearly explained how to correct this:

process.py

import sqlite3  # version 2.6.0

connection = sqlite3.connect('./db.sqlite')
cursor = connection.cursor()
count_before = cursor.execute('SELECT COUNT(*) FROM r_data;').fetchall()[0][0]
print('{} rows in {}'.format(count_before, table_name))

query = 'DELETE FROM r_data WHERE pk IN (501, 668);'
print('Deleted ', cursor.execute(query).rowcount, 'rows')

count_after = cursor.execute('SELECT COUNT(*) FROM r_data;').fetchall()[0][0]
print('{} rows in {}'.format(count_after, table_name))
cursor.close()
connection.close()

output:

$ python process.py 
824 rows
822 rows
$ python process.py 
824 rows
822 rows

I know that the SQL queries are fine because I can run them successfully through other sqlite "clients" such as the firefox sqlite manager plugin.

1 Answer 1

1

Right, need to commit on connection:

cursor.close()
connection.commit()   # <<<<< !!
connection.close()
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.