From b855615b228bdb3ff9583a8342684d79acb46128 Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Tue, 29 Mar 2011 10:27:17 -0500 Subject: let generated flag control SQL generation Previously, if QSqlField's QVariant value had type "invalid", this caused the field to be omitted in data-changing SQL statements generated from QSqlRecord edit buffers. Complaints against this mechanism: - It precludes initializing value type to field type, which would otherwise seem sensible and useful, such as when using model.data() in contexts where the field type is not readily available. - QSqlField::clear() does initialize value type to match field type and so is incompatible with this mechanism. - Problems such as described in QTBUG-13211. - Unwanted distinction between "invalid" and "null" when mapping field values to SQL values. - QSqlField's generated flag already provides a mechanism for controlling SQL generation. These complaints are redressed here by replacing this mechanism with reliance on QSqlField's generated flag. The flag is initialized to false in new edit records and set to true when a value is set. Applications can still manipulate generated flags directly to control SQL generation. Generation of SELECT statements already used the generated flag and is unaffected by this change. Merge-request: 1114 Reviewed-by: Marius Storm-Olsen Reviewed-by: Michael Goddard --- tests/auto/qsqlquery/tst_qsqlquery.cpp | 7 +++---- tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp | 6 +++--- tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp | 6 +++--- 3 files changed, 9 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/auto/qsqlquery/tst_qsqlquery.cpp b/tests/auto/qsqlquery/tst_qsqlquery.cpp index 3928678375..592b49ad1b 100644 --- a/tests/auto/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/qsqlquery/tst_qsqlquery.cpp @@ -928,13 +928,12 @@ void tst_QSqlQuery::record() QSqlQuery q( db ); QVERIFY( q.record().isEmpty() ); QVERIFY_SQL( q, exec( "select id, t_varchar, t_char from " + qtest + " order by id" ) ); - QSqlRecord rec = q.record(); QCOMPARE( q.record().fieldName( 0 ).toLower(), QString( "id" ) ); QCOMPARE( q.record().fieldName( 1 ).toLower(), QString( "t_varchar" ) ); QCOMPARE( q.record().fieldName( 2 ).toLower(), QString( "t_char" ) ); - QVERIFY( !q.record().value( 0 ).isValid() ); - QVERIFY( !q.record().value( 1 ).isValid() ); - QVERIFY( !q.record().value( 2 ).isValid() ); + QCOMPARE(q.record().value(0), QVariant(q.record().field(0).type())); + QCOMPARE(q.record().value(1), QVariant(q.record().field(1).type())); + QCOMPARE(q.record().value(2), QVariant(q.record().field(2).type())); QVERIFY( q.next() ); QVERIFY( q.next() ); diff --git a/tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp b/tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp index 1bd640f98f..073f3da137 100644 --- a/tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp +++ b/tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp @@ -428,9 +428,9 @@ void tst_QSqlQueryModel::record() QCOMPARE(rec.fieldName(0), isToUpper ? QString("ID") : QString("id")); QCOMPARE(rec.fieldName(1), isToUpper ? QString("NAME") : QString("name")); QCOMPARE(rec.fieldName(2), isToUpper ? QString("TITLE") : QString("title")); - QCOMPARE(rec.value(0), QVariant()); - QCOMPARE(rec.value(1), QVariant()); - QCOMPARE(rec.value(2), QVariant()); + QCOMPARE(rec.value(0), QVariant(rec.field(0).type())); + QCOMPARE(rec.value(1), QVariant(rec.field(1).type())); + QCOMPARE(rec.value(2), QVariant(rec.field(2).type())); rec = model.record(0); QCOMPARE(rec.fieldName(0), isToUpper ? QString("ID") : QString("id")); diff --git a/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp b/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp index 60bc96fcb5..0700e9d978 100644 --- a/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp +++ b/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp @@ -569,9 +569,9 @@ void tst_QSqlTableModel::insertMultiRecords() QVERIFY(model.insertRow(2)); - QCOMPARE(model.data(model.index(2, 0)), QVariant()); - QCOMPARE(model.data(model.index(2, 1)), QVariant()); - QCOMPARE(model.data(model.index(2, 2)), QVariant()); + QCOMPARE(model.data(model.index(2, 0)), QVariant(model.record().field(0).type())); + QCOMPARE(model.data(model.index(2, 1)), QVariant(model.record().field(1).type())); + QCOMPARE(model.data(model.index(2, 2)), QVariant(model.record().field(2).type())); QVERIFY(model.insertRow(3)); QVERIFY(model.insertRow(0)); -- cgit v1.2.3