summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@digia.com>2012-01-19 20:39:30 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-01-26 06:02:13 (GMT)
commitb23631015c23a49e3b4d296ea0a6266bfce3d4f1 (patch)
treeebdbdf4c0102cfcc7d5461f8bfe23d413d03cb87 /tests
parent1f1874293eff08db6d831f864cfbe21ddb6f753c (diff)
downloadQt-b23631015c23a49e3b4d296ea0a6266bfce3d4f1.zip
Qt-b23631015c23a49e3b4d296ea0a6266bfce3d4f1.tar.gz
Qt-b23631015c23a49e3b4d296ea0a6266bfce3d4f1.tar.bz2
Handle the 'real' datatype correctly in the SQLite driver
The 'real' datatype should be seen as a QVariant::Double type and not as a QVariant::String type otherwise it does not get presented correctly when using a non Qt application to access it. Test is included for QSqlQuery. Task-number: QTBUG-16373 Change-Id: Ie323ce49eb95e4d6bb4c3814ba9a957a63f4b259 Reviewed-by: Yunqiao Yin <charles.yin@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qsqldatabase/tst_qsqldatabase.cpp2
-rw-r--r--tests/auto/qsqlquery/tst_qsqlquery.cpp30
2 files changed, 31 insertions, 1 deletions
diff --git a/tests/auto/qsqldatabase/tst_qsqldatabase.cpp b/tests/auto/qsqldatabase/tst_qsqldatabase.cpp
index bde6aa4..94cc10b 100644
--- a/tests/auto/qsqldatabase/tst_qsqldatabase.cpp
+++ b/tests/auto/qsqldatabase/tst_qsqldatabase.cpp
@@ -1232,7 +1232,7 @@ void tst_QSqlDatabase::recordSQLite()
FieldDef("integer", QVariant::Int, QVariant(13)),
FieldDef("int", QVariant::Int, QVariant(12)),
- FieldDef("real", QVariant::String, QVariant(1.234567890123456)),
+ FieldDef("real", QVariant::Double, QVariant(1.234567890123456)),
FieldDef()
};
diff --git a/tests/auto/qsqlquery/tst_qsqlquery.cpp b/tests/auto/qsqlquery/tst_qsqlquery.cpp
index 00facff..482b70f 100644
--- a/tests/auto/qsqlquery/tst_qsqlquery.cpp
+++ b/tests/auto/qsqlquery/tst_qsqlquery.cpp
@@ -224,6 +224,9 @@ private slots:
void benchmark();
#endif
+ void sqlite_real_data() { generic_data("QSQLITE"); }
+ void sqlite_real();
+
private:
// returns all database connections
void generic_data(const QString &engine=QString());
@@ -3310,5 +3313,32 @@ void tst_QSqlQuery::benchmark()
}
#endif
+void tst_QSqlQuery::sqlite_real()
+{
+ QFETCH(QString, dbName);
+ QSqlDatabase db = QSqlDatabase::database(dbName);
+ CHECK_DATABASE(db);
+ const QString tableName(qTableName("sqliterealtype", __FILE__));
+ tst_Databases::safeDropTable( db, tableName );
+
+ QSqlQuery q(db);
+ QVERIFY_SQL(q, exec("CREATE TABLE " + tableName + " (id INTEGER, realVal REAL)"));
+ QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id, realVal) VALUES (1, 2.3)"));
+ QVERIFY_SQL(q, exec("SELECT realVal FROM " + tableName));
+ QVERIFY(q.next());
+ QCOMPARE(q.value(0).toDouble(), 2.3);
+ QCOMPARE(q.record().field(0).type(), QVariant::Double);
+
+ q.prepare("INSERT INTO " + tableName + " (id, realVal) VALUES (?, ?)");
+ QVariant var((double)5.6);
+ q.addBindValue(4);
+ q.addBindValue(var);
+ QVERIFY_SQL(q, exec());
+
+ QVERIFY_SQL(q, exec("SELECT realVal FROM " + tableName + " WHERE ID=4"));
+ QVERIFY(q.next());
+ QCOMPARE(q.value(0).toDouble(), 5.6);
+}
+
QTEST_MAIN( tst_QSqlQuery )
#include "tst_qsqlquery.moc"