0

I have somewhat strange issue with my QMessageBox answers. This function is used to remove a row from an SQLite database. Before deletion, a message box pops and asks for confirmation. Query executes fine, except it ALWAYS deletes, whether I answer with YES or NO.

here is the code:

def deleteFromDB(self):
  name = (str(self.ui.searchName.text()).upper())
    if name:
      with con:
        cur = con.cursor()
        cur.execute('SELECT name FROM cases WHERE name =?',[name])
        tempname = str(cur.fetchone())
        if len(tempname) != 4 :
            reply = QtGui.QMessageBox.question(self, 'Removal',
                    "Are you sure ", QtGui.QMessageBox.Yes |
                     QtGui.QMessageBox.No, QtGui.QMessageBox.No)
                 if reply == QtGui.QMessageBox.Yes:
                     cur.execute('DELETE FROM cases where name =?',[name])
ivica
  • 1,388
  • 1
  • 22
  • 38
  • The important bit seems to work fine for me (QMessageBox.question returns the correct values) – Luke Jul 09 '12 at 17:27
  • Well that puzzled me also. If I put print(reply) somwhere in there, it prints corresponding values for YES and NO (16384 for YES and 65536 for NO). Thank you for your reply. – ivica Jul 09 '12 at 17:39
  • The indentation in the example above is a little odd - the second to last line should be at the same indent level as line 9. Is this just a pasting issue or could this be your problem? The code (slightly stripped) works as expected for me with the indentation fixed. – Gary Hughes Jul 10 '12 at 08:14
  • It a pasting issue, my editor uses tabs, not spaces for indentation, so I tried to fix it "on the spot", badly I guess. Thank you both for replies, this piece of code is OK, issue must be somewhere else. – ivica Jul 10 '12 at 12:48

0 Answers0