DELETE FROM doesn't work in Python for SQL

Viewed 40

I want to delete all rows in my tables that are empty. But the same command I use in SQL doesnt work in Python. Its on my raspberry and im using SQLite3.

I dont get any error message doing:

import sqlite3

currency_pairs = ['AUDUSD', 'EURCHF', 'EURUSD', 'EURCAD']

conn = sqlite3.connect("/home/ken/database/database.db")
cursor = conn.cursor()

for c in currency_pairs:
        cursor.execute("DELETE FROM {c} WHERE Close IS NULL;".format(c=c))

conn.close()

Again, using DELETE FROM AUDUSD WHERE Close IS NULL; for example works in my sqlite3 programm.

1 Answers

I think you need to use conn.commit() when executing one or multiple delete statement(s). Committing is not necessary if you select.

Related