From 1932953334e3b37441e0a12804813cc529dcbc04 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Thu, 31 Jan 2019 11:50:15 +0100 Subject: QODBC: Preserve the whole value when using HighPrecision Some ODBC drivers do not properly handle SQL_NO_DATA and therefore decimal values returned with HighPrecision are cut off because the decimal point is not taken into account. Fixes: QTBUG-73286 Change-Id: I905c947b4d0266a3245d5735300300ca00f77480 Reviewed-by: Andy Shaw Reviewed-by: Christian Ehrlicher (cherry picked from commit c2657f9762e01abd65ac991ba31e3ca085d9540c) Reviewed-by: Qt Cherry-pick Bot --- tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'tests/auto/sql') diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp index 352687a369..d32277a250 100644 --- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp @@ -258,6 +258,9 @@ private slots: void QTBUG_57138_data() { generic_data("QSQLITE"); } void QTBUG_57138(); + void QTBUG_73286_data() { generic_data("QODBC"); } + void QTBUG_73286(); + void dateTime_data(); void dateTime(); @@ -4548,6 +4551,7 @@ void tst_QSqlQuery::QTBUG_57138() QSqlQuery create(db); QString tableName = qTableName("qtbug57138", __FILE__, db); + tst_Databases::safeDropTable(db, tableName); 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 (?, ?, ?, ?)")); @@ -4571,6 +4575,37 @@ void tst_QSqlQuery::QTBUG_57138() QCOMPARE(q.value(2).toDateTime(), tzoffset); } +void tst_QSqlQuery::QTBUG_73286() +{ + QFETCH(QString, dbName); + QSqlDatabase db = QSqlDatabase::database(dbName); + CHECK_DATABASE(db); + + QSqlQuery create(db); + QString tableName = qTableName("qtbug73286", __FILE__, db); + tst_Databases::safeDropTable(db, tableName); + + QVERIFY_SQL(create, exec("create table " + tableName + " (dec2 decimal(4,2), dec0 decimal(20,0), dec3 decimal(20,3))")); + QVERIFY_SQL(create, prepare("insert into " + tableName + " (dec2, dec0, dec3) values (?, ?, ?)")); + + create.addBindValue("99.99"); + create.addBindValue("12345678901234567890"); + create.addBindValue("12345678901234567.890"); + + QVERIFY_SQL(create, exec()); + + QSqlQuery q(db); + q.prepare("SELECT dec2, dec0, dec3 FROM " + tableName); + q.setNumericalPrecisionPolicy(QSql::HighPrecision); + + QVERIFY_SQL(q, exec()); + QVERIFY(q.next()); + + QCOMPARE(q.value(0).toString(), "99.99"); + QCOMPARE(q.value(1).toString(), "12345678901234567890"); + QCOMPARE(q.value(2).toString(), "12345678901234567.890"); +} + void tst_QSqlQuery::dateTime_data() { if (dbs.dbNames.isEmpty()) -- cgit v1.2.3