I need to delete DB entries where the value could be None. I get my values from a ListBox. The function looks like this:
def OnDelete(self, e):
num = self.list.GetItemCount()
for i in range(num):
if self.list.IsChecked(i):
itemValueList = []
for i2 in range(6):
item = self.list.GetItem(i, i2)
if item.GetText() == "None":
itemValueList.append("")
else:
itemValueList.append(item.GetText())
DBManager.DeleteEntry(itemValueList)
And the function in my DBManager looks like this:
def DeleteEntry(itemValueList):
# Open Database
conn = sqlite3.connect('Database.db')
c = conn.cursor()
# Delete a row of data
c.execute('delete from Database where Value1=? and Value2=? and Value3=? and Value4=? and Value5=? and Value6=?',
(itemValueList[0], itemValueList[1], itemValueList[2], itemValueList[3], itemValueList[4], itemValueList[5]))
# Save (commit) the changes
conn.commit()
So in my case at the moment Value5 and Value6 are "None" or NULL in the SQLite DB. Therefore i set the string added to the itemValueList to "". But that doesnt work. The DB Entriy doesnt get deleted.
What do i have to change that also Entries where some columns can have no value are getting deleted?
Thank you.
[EDIT]:
c.execute('delete from Database where isnull(Value1,"")=? and isnull(Value2,"")=? and isnull(Value3,"")=? and isnull(Value4,"")=? and isnull(Value5,"")=? and isnull(Value6,"")=?',
(itemValueList[0], itemValueList[1], itemValueList[2], itemValueList[3], itemValueList[4], itemValueList[5]))
NULL. To match a null value in SQL you have to usecolumnName IS NULL, you can't use=.