#Delete suspense window
class dWindow(QtGui.QMainWindow, Ui_dWindow):
def __init__(self, parent = None):
QtGui.QMainWindow.__init__(self, parent)
self.setupUi(self)
for row in cursor.execute("SELECT FIRSTNAME FROM Staff"):
self.comboUser.addItems(row)
con.close()
self.btnDeleteSuspense.clicked.connect(self.btnDeleteSuspense_Clicked)
def btnDeleteSuspense_Clicked(self):
user = self.comboUser.currentText() #finds selected user
date = self.dateEdit.date().toString("M/d/yyyy")
numrecord = cursor.execute() ??
Here is a sample DB and program file to further help me explain
I have created variables to hold the selection of the combobox and the dateEdit box.
The next step (the one I'm struggling with) is to then use those variables in an SQL query that will first find the count of rows with the selected user name and having a date <= than the selected date. That will populate the numrecord variable so that I can display a "This will delete 'x' rows, are you sure?"
If the user selects yes then I will then use the variable in a delete query to delete the selected rows.
I believe if I can figure out how to use the variables I have in a SQL query then the DELETE query should be rather simple.
An example of a possible DELETE query to show what I'm trying to do
cursor.execute("DELETE TO, count(*) FROM Suspense where TO = [user] and DATE = [date]")
I know that is wrong but maybe it will help clarify.
I hope I have explained my question fully and I appreciate any help provided.
Edit: Thanks so much!!
Just before I saw that you had posted this I figured it out.
What I came up with was the following:
qdate = self.dateTimeEdit.dateTime().toPyDateTime() #grabs the raw datetime from the QDateTimeEdit object and converts to python datetime
query = "SELECT DATE FROM Suspense WHERE DATE >= ?" #creates the query using ? as a placeholder for variable
cursor.execute(query, (qdate,)) #executes the query and passes qdate as a tuple to the placeholder
With this knowledge I can recreate my queries to include both variables.