summaryrefslogtreecommitdiffstats
path: root/tests/auto/sql
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-04-19 15:20:08 +0000
commit1932953334e3b37441e0a12804813cc529dcbc04 (patch)
tree118287293afae339621fbc09b3bec8b0761787bf /tests/auto/sql
parent1051db0b018b1ef686b9d04cdd37e70f39399289 (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/auto/sql')
-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 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())