Mar-16-2022, 11:59 AM
OK So the solution was to use a list. All I had to do was add the SQLite wildcards and append to the list. I did nothave to make it a tuple.
Full code in how it works is in my tkinter checkbox treeview thread in GUI but the query code is
Partial code to build the query
Full code in how it works is in my tkinter checkbox treeview thread in GUI but the query code is
Partial code to build the query
def search_contact(self): checkboxvalues = self.get_checkbox_values() # Set up to build the database query by first getting the start and then adding in clauses as required depending # on whether the checkbox is selected or not and on what is entered in the search criteria cmd = AnimalTrakker_Query_Code.display_start_select cmdjoinclause = "" cmdwhereclause = "" if checkboxvalues[0] : cmd = cmd + AnimalTrakker_Query_Code.display_member_first_name_true_select if checkboxvalues[1]: cmd = cmd + AnimalTrakker_Query_Code.display_member_last_name_true_select if checkboxvalues[2]: cmd = cmd +AnimalTrakker_Query_Code.display_farm_name_true_select if checkboxvalues[3]: cmd = cmd + AnimalTrakker_Query_Code.display_flock_prefix_true_select cmdjoinclause = AnimalTrakker_Query_Code.join_flock_prefix_table
# Remove the initial comma so that no matter what is selected to display the query works cmd = cmd[:cmd.index(",")]+ cmd[cmd.index(",")+1:] cmd = cmd + "FROM contacts_table " cmd = cmd + cmdjoinclause cmdvariables = [] search_name_data_entry = self.contact_name.get() if search_name_data_entry: cmdwhereclause = 'WHERE contacts_table.contact_last_name LIKE (?)' cmdvariables.append('%'+search_name_data_entry+'%') search_prefix_data_entry = self.farm_prefix.get() if search_prefix_data_entry: if search_name_data_entry: cmdwhereclause = cmdwhereclause + 'AND flock_prefix_table.flock_prefix LIKE (?)' cmdvariables.append('%' + search_prefix_data_entry + '%') else: cmdwhereclause = cmdwhereclause + 'WHERE flock_prefix_table.flock_prefix LIKE (?)' cmdvariables.append('%' + search_prefix_data_entry + '%') search_state_premise_data_entry = self.state_premise_id.get() if search_state_premise_data_entry: if search_name_data_entry or search_prefix_data_entry: cmdwhereclause = cmdwhereclause + 'AND contacts_premise_table.state_premise_id LIKE (?)' else: cmdwhereclause = cmdwhereclause + 'WHERE contacts_premise_table.state_premise_id LIKE (?)' cmdvariables.append('%' + search_state_premise_data_entry + '%') cmd = cmd + cmdwhereclause connection = sqlite3.connect(config.currentdatabase) resultcursor = connection.cursor() if cmdvariables: resultcursor.execute(cmd, cmdvariables) else: resultcursor.execute(cmd) results = resultcursor.fetchall()and the query code segments from another class
display_start_select =""" SELECT """ display_member_first_name_true_select =""" , contacts_table.contact_first_name """ display_member_last_name_true_select =""" , contacts_table.contact_last_name """ display_farm_name_true_select = """ , contacts_table.contact_company """ display_state_premise_true_select = """ , contacts_premise_table.state_premise_id """