我的QMessageBox答案有点奇怪。此函数用于从SQLite数据库中删除行。在删除之前,会弹出一个消息框并要求确认。查询执行正常,但它总是删除,无论我是否回答。
这是代码:
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])