QSqlTableModel::insertRecord(): clean up after failed setRecord()
authorMark Brand <mabrand@mabrand.nl>
Tue, 7 Feb 2012 23:45:47 +0000 (00:45 +0100)
committerQt by Nokia <qt-info@nokia.com>
Thu, 9 Feb 2012 09:45:38 +0000 (10:45 +0100)
Change-Id: Ic9f314144bd3ccf4b59b9cb3f0d79f8d6f97a824
Reviewed-by: Yunqiao Yin <charles.yin@nokia.com>
dist/changes-5.0.0
src/sql/models/qsqltablemodel.cpp

index 996bdf4..7726843 100644 (file)
@@ -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                                *
index 9e1cfe3..35346c0 100644 (file)
@@ -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;