Please help me to fix a "Parameter count mismatch" exception in python.
I'm using QSqlTableModel connected to a sqlite3 database. My connection works fine and also my data are properly set: when I insert a record, after starting the program, everything work fine, but when I try to insert a new record, I receive the error "Parameter count mismatch". The following code throws the exception:
if not self.table_model.submitAll():
error_message = f"Error Customer Model: {self.table_model.lastError().text()}"
raise CustomModelError(error_message)
self.table_model.submitAll() fails. The more full python code is:
def update_customer(self, customer_id, data):
try:
self.db_model.open_connection()
row = self.find_row_by_customer_id(customer_id)
record = self.set_db_record(data, row)
self.table_model.setRecord(row, record)
self.confirm_database_changes()
return customer_id
finally:
self.db_model.close_connection()
def find_row_by_customer_id(self, customer_id):
row = -1
for i in range(self.table_model.rowCount()):
if str(self.table_model.data(self.table_model.index(i, 0))) == str(customer_id):
row = i
break
return row
def confirm_database_changes(self):
if not self.table_model.submitAll():
error_message = f"Error Customer Model: {self.table_model.lastError().text()}"
raise CustomModelError(error_message)
self.table_model.database().commit()
self.table_model.select()
self.select()
As you can see in the confirm_database_changes method, I refresh the model after inserting the new record, but the error still exists.
Any help is highly appreciated. Thanks.