Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.8
-
None
Description
This bug report originally comes from SO:
void printRecord(const QSqlRecord& record, const QString& msg) { qDebug() << "Name:" << record.value("Name").toString() << "isGenerated :" << (record.field("Name").isGenerated() ? "true " : "false") << "|" << msg; qDebug(); } void printModel(const QSqlTableModel& model, const QString& msg) { printRecord(model.record(0), msg); } void main() { QCoreApplication app(argc, argv); QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName(":memory:"); db.open(); QSqlQuery query; query.exec("CREATE TABLE Person(Name TEXT);"); query.exec("INSERT INTO Person (Name) VALUES ('John Green');"); QSqlTableModel model(nullptr, db); model.setTable("Person"); model.setEditStrategy(QSqlTableModel::OnManualSubmit); model.select(); printModel(model, "Model after select"); qDebug() << "-------------------"; qDebug(); auto record = model.record(0); printRecord(record, "Record retrieved first time"); model.setRecord(0, record); printModel(model, "Model after setRecord first time"); qDebug() << "-------------------"; qDebug(); #if 0 record = model.record(0); printRecord(record, "Record retrieved second time"); model.setRecord(0, record); printModel(model, "Model after setRecord second time"); qDebug() << "-------------------"; qDebug(); #endif record.setValue("Name", "Andy Brown"); printRecord(record, "Record modified"); model.setRecord(0, record); printModel(model, "Model after setRecord after modifying record"); qDebug() << "-------------------"; qDebug(); if (!model.submitAll()) qDebug() << model.lastError(); printModel(model, "Model after submitAll"); query.exec("SELECT * FROM Person;"); query.next(); qDebug() << "Content of DB Table \"Name\":" << query.value("Name").toString(); qDebug(); return 0; }
When a row is updated once and not submitted to the database, a second update will screw up the internal cache and a submit() will not update the row in the database.
Attachments
Gerrit Reviews
For Gerrit Dashboard: QTBUG-132708 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
616142,1 | QSqlTableModel: don't fail on a second setRecord() | dev | qt/qtbase | Status: NEW | -1 | 0 |