В самом себе. c .execute ("УДАЛИТЬ из книг, ГДЕ book_name =" + str (delBooks)) Я хочу вызвать переменную delBooks из метода deleteBooks, но он не работает? Это PyQt5, и я использую базу данных sqlite3.
class DeleteDialog(QDialog):
def __init__(self, *args, **kwargs):
super(DeleteDialog, self).__init__(*args, **kwargs)
self.QBtn = QPushButton()
self.QBtn.setText("Delete Book")
self.setWindowTitle("Delete Book")
self.setFixedWidth(300)
self.setFixedHeight(100)
self.QBtn.clicked.connect(self.deleteBooks)
layout = QVBoxLayout()
self.deleteinput = QLineEdit()
self.deleteinput.setPlaceholderText("Book Name")
layout.addWidget(self.deleteinput)
layout.addWidget(self.QBtn)
self.setLayout(layout)
def deleteBooks(self):
delBooks = ""
delBooks = self.deleteinput.text()
try:
self.conn = sqlite3.connect("database.db")
self.c = self.conn.cursor()
self.c.execute("DELETE from books WHERE book_name="+str(delBooks))
self.conn.commit()
self.c.close()
self.conn.close()
QMessageBox.information(QMessageBox(),'Successful','Deleted From Table Successful')
self.close()
except Exception:
QMessageBox.warning(QMessageBox(), 'Error', 'Could not Delete that book from database.')