diff options
Diffstat (limited to 'tests/auto/qsqlquery/tst_qsqlquery.cpp')
-rw-r--r-- | tests/auto/qsqlquery/tst_qsqlquery.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/tests/auto/qsqlquery/tst_qsqlquery.cpp b/tests/auto/qsqlquery/tst_qsqlquery.cpp index 5ebbc3b..27c28b1 100644 --- a/tests/auto/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/qsqlquery/tst_qsqlquery.cpp @@ -3294,14 +3294,19 @@ void tst_QSqlQuery::QTBUG_2192() QSqlQuery q(db); QVERIFY_SQL(q, exec("CREATE TABLE " + tableName + " (dt DATETIME)")); + QDateTime dt = QDateTime(QDate(2012, 7, 4), QTime(23, 59, 59, 999)); QVERIFY_SQL(q, prepare("INSERT INTO " + tableName + " (dt) VALUES (?)")); - q.bindValue(0, QVariant(QDateTime(QDate(2012, 7, 4), QTime(23, 59, 59, 999)))); + q.bindValue(0, dt); QVERIFY_SQL(q, exec()); - // Check if value was stored with at least second precision. QVERIFY_SQL(q, exec("SELECT dt FROM " + tableName)); QVERIFY_SQL(q, next()); - QVERIFY(q.value(0).toDateTime().msecsTo(QDateTime(QDate(2012, 7, 4), QTime(23, 59, 59, 999))) < 1000 ); + + // Check if retrieved value preserves reported precision + int precision = qMax(0, q.record().field("dt").precision()); + int diff = qAbs(q.value(0).toDateTime().msecsTo(dt)); + int keep = qMin(1000, (int)qPow(10.0, precision)); + QVERIFY(diff <= 1000 - keep); } } |