diff options
author | Joni Poikelin <joni.poikelin@qt.io> | 2017-07-14 09:25:54 +0300 |
---|---|---|
committer | Joni Poikelin <joni.poikelin@qt.io> | 2017-07-31 17:59:49 +0000 |
commit | 0a5f71c6062d575602ff041fb1b88ec2d8ad92bc (patch) | |
tree | 6cc62ff650c6cad58e2f492ee4c721722062a75c /tests/auto/sql | |
parent | b7a898b8fee7552fb319f3fbdd44a23a3dc26919 (diff) |
Fix storing of QDateTime timespec for Sqlite
Commit 9e64fc9e1cebf1e11694c4f536881128f5aee288 caused a regression
which stored all QDateTime entries as if they were in localtime,
which causes them to be offset by the amount of local timezone
offset. This is fixed by adding "Z" if the time should be in UTC or
using "+/-hh:mm" if it should use fixed UTC offset or specific
timezone.
Task-number: QTBUG-57138
Change-Id: Ie60905dfb3a517db442b636ca41daf8348753d84
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
Diffstat (limited to 'tests/auto/sql')
-rw-r--r-- | tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp index 8deb5ddf8f..35f86772e2 100644 --- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp @@ -243,6 +243,9 @@ private slots: void integralTypesMysql_data() { generic_data("QMYSQL"); } void integralTypesMysql(); + void QTBUG_57138_data() { generic_data("QSQLITE"); } + void QTBUG_57138(); + private: // returns all database connections void generic_data(const QString &engine=QString()); @@ -4083,5 +4086,40 @@ void tst_QSqlQuery::integralTypesMysql() } } +void tst_QSqlQuery::QTBUG_57138() +{ + QDateTime utc = QDateTime(QDate(2150, 1, 5), QTime(14, 0, 0, 123), Qt::UTC); + QDateTime localtime = QDateTime(QDate(2150, 1, 5), QTime(14, 0, 0, 123), Qt::LocalTime); + QDateTime tzoffset = QDateTime(QDate(2150, 1, 5), QTime(14, 0, 0, 123), Qt::OffsetFromUTC, 3600); + + QFETCH(QString, dbName); + QSqlDatabase db = QSqlDatabase::database(dbName); + CHECK_DATABASE(db); + + QSqlQuery create(db); + QString tableName = qTableName("qtbug57138", __FILE__, db); + + QVERIFY_SQL(create, exec("create table " + tableName + " (id int, dt_utc datetime, dt_lt datetime, dt_tzoffset datetime)")); + QVERIFY_SQL(create, prepare("insert into " + tableName + " (id, dt_utc, dt_lt, dt_tzoffset) values (?, ?, ?, ?)")); + + create.addBindValue(0); + create.addBindValue(utc); + create.addBindValue(localtime); + create.addBindValue(tzoffset); + + QVERIFY_SQL(create, exec()); + + QSqlQuery q(db); + q.prepare("SELECT dt_utc, dt_lt, dt_tzoffset FROM " + tableName + " WHERE id = ?"); + q.addBindValue(0); + + QVERIFY_SQL(q, exec()); + QVERIFY(q.next()); + + QCOMPARE(q.value(0).toDateTime(), utc); + QCOMPARE(q.value(1).toDateTime(), localtime); + QCOMPARE(q.value(2).toDateTime(), tzoffset); +} + QTEST_MAIN( tst_QSqlQuery ) #include "tst_qsqlquery.moc" |