From 68cee5258b3db95aaf98c456a257863a2ef7ba14 Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Wed, 8 Feb 2012 00:45:47 +0100 Subject: [PATCH] QSqlTableModel::insertRecord(): clean up after failed setRecord() Change-Id: Ic9f314144bd3ccf4b59b9cb3f0d79f8d6f97a824 Reviewed-by: Yunqiao Yin --- dist/changes-5.0.0 | 2 ++ src/sql/models/qsqltablemodel.cpp | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/dist/changes-5.0.0 b/dist/changes-5.0.0 index 996bdf4b0b1..7726843ccb4 100644 --- a/dist/changes-5.0.0 +++ b/dist/changes-5.0.0 @@ -355,6 +355,8 @@ ignore the rest of the range. is consistent with the meaning of the flag. -Require all fields to map correctly. Previously fields that didn't map were simply ignored. + -For OnManualSubmit, insertRecord() no longer leaves behind an empty + row if setRecord() fails. **************************************************************************** * Database Drivers * diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp index 9e1cfe3051e..35346c0f835 100644 --- a/src/sql/models/qsqltablemodel.cpp +++ b/src/sql/models/qsqltablemodel.cpp @@ -1079,8 +1079,11 @@ bool QSqlTableModel::insertRecord(int row, const QSqlRecord &record) row = rowCount(); if (!insertRow(row, QModelIndex())) return false; - if (!setRecord(row, record)) + if (!setRecord(row, record)) { + if (d->strategy == OnManualSubmit) + revertRow(row); return false; + } if (d->strategy == OnFieldChange || d->strategy == OnRowChange) return submit(); return true;