summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2019-01-31 11:50:15 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-01-28 06:53:53 +0000
commit1c38e5a7b53813ae624770066cc7f7c7f5acfb9c (patch)
treeab71ebd5da512b6f177a96afacb46da3a38164fc /tests
parent5a9bcf5d06d8a3790000875ec9c347ccae587b8f (diff)
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 <andy.shaw@qt.io> Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de> (cherry picked from commit c2657f9762e01abd65ac991ba31e3ca085d9540c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
index e29d015031..76df61c892 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();
@@ -4529,6 +4532,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 (?, ?, ?, ?)"));
@@ -4552,6 +4556,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()
{
QTest::addColumn<QString>("dbName");