summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMark Brand <mabrand@mabrand.nl>2012-07-10 22:11:11 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-07-13 09:54:45 (GMT)
commitf8edd0bad1f41267a1805297a5bc8717685cad2a (patch)
tree84935e3d5fc85f0997a1644393ae4fe46839d31d /tests/auto
parentea718a55f119381df25fc9d62126bb76a677ba95 (diff)
downloadQt-f8edd0bad1f41267a1805297a5bc8717685cad2a.zip
Qt-f8edd0bad1f41267a1805297a5bc8717685cad2a.tar.gz
Qt-f8edd0bad1f41267a1805297a5bc8717685cad2a.tar.bz2
QSqlTM: respect generated flag in insertRecord() and setRecord()
These methods failed to respect the setting of the generated flag on the fields of source record. INSERT and UPDATE statements should only include fields where generated is TRUE. Test included. Follow-up to 0f15ab4e750690bdb2b649332d5c3276bf24c440. Change-Id: I2f10dbcd7e5e5123489b38a123effe43a673a427 Task-number: QTBUG-23592 Reviewed-by: Bill King <bill.king@nokia.com> Reviewed-by: Jason Dolan <jason.t.dolan@gmail.com> Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp b/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp
index ced3a29..d0795bc 100644
--- a/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp
+++ b/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp
@@ -52,6 +52,7 @@ const QString test(qTableName("test", __FILE__)),
//TESTED_FILES=
Q_DECLARE_METATYPE(QModelIndex)
+Q_DECLARE_METATYPE(QSqlRecord)
class tst_QSqlTableModel : public QObject
{
@@ -522,6 +523,7 @@ void tst_QSqlTableModel::insertRow()
void tst_QSqlTableModel::insertRecord()
{
+ qRegisterMetaType<QSqlRecord>("QSqlRecord&");
QFETCH(QString, dbName);
QSqlDatabase db = QSqlDatabase::database(dbName);
CHECK_DATABASE(db);
@@ -534,6 +536,7 @@ void tst_QSqlTableModel::insertRecord()
QSqlRecord rec = model.record();
rec.setValue(0, 42);
+ rec.setGenerated(0, false);
rec.setValue(1, QString("vohi"));
rec.setValue(2, 1);
QVERIFY(model.insertRecord(1, rec));
@@ -543,7 +546,29 @@ void tst_QSqlTableModel::insertRecord()
QCOMPARE(model.data(model.index(1, 1)).toString(), QString("vohi"));
QCOMPARE(model.data(model.index(1, 2)).toInt(), 1);
+ QSignalSpy spy(&model, SIGNAL(beforeInsert(QSqlRecord&)));
+
+ // Don't care if the database accepts the change.
+ // Just check the generated flags.
+ model.submitAll();
+
+ QCOMPARE(spy.count(), 1);
+ QSqlRecord r = spy.at(0).at(0).value<QSqlRecord>();
+ QCOMPARE(r.count(), rec.count());
+ QCOMPARE(r.isGenerated(0), false);
+ QCOMPARE(r.value(0).toInt(), 42);
+ QCOMPARE(r.isGenerated(1), true);
+ QCOMPARE(r.value(1).toString(), QString("vohi"));
+
model.revertAll();
+ // Clean up
+ if (model.rowCount() == 4) {
+ QVERIFY_SQL(model, removeRow(1));
+ QVERIFY_SQL(model, submitAll());
+ }
+ QCOMPARE(model.rowCount(), 3);
+
+ rec.setGenerated(0, true);
model.setEditStrategy(QSqlTableModel::OnRowChange);
QVERIFY(model.insertRecord(-1, rec));