2

I use Qt 5.7, C++, SQLite database. I have QSqlTableModel descendant class. I update rows via setRecord(), submitAll() calls (QSqlTableModel::OnManualSubmit mode). Let's set value_1 to field_1 in a single row. It is saved correctly in database, also corresponding QTableView is automatically refreshed. When I set value_2 to field_1 in any row once again, modification is shown in a view, but it's not saved in database. See qsqltablemodel.cpp source for Qt 5.7.0

bool QSqlTableModelPrivate::exec(const QString &stmt, bool prepStatement, const QSqlRecord &rec, const QSqlRecord &whereValues)

It contains the following fragment:

if (editQuery.lastQuery() != stmt) {
        if (!editQuery.prepare(stmt)) {
            error = editQuery.lastError();
            return false;
        }
}    

In my case, for the 2nd and further update calls the following condition is true: editQuery.lastQuery() == stmt.

stmt can contain value like

UPDATE documents SET "mark"=? WHERE "documents"."id" = ? AND "documents"."checked" = ? AND "documents"."state" = ?

So, bool QSQLiteResult::prepare(const QString &query) is not called. That is why after assignment

int paramCount = sqlite3_bind_parameter_count(d->stmt);

this condition is true: paramCount == 0 (see qsql_sqlite.cpp:429, d->stmt is a pointer to sqlite3_stmt and it's NULL).

It leads to the final error "Parameter count mismatch". Is it a bug, what is a workaround? Please, don't advise raw SQL, I don't want to reset model very often.

ilya
  • 1,103
  • 14
  • 36

0 Answers0