-
Bug
-
Resolution: Fixed
-
P1: Critical
-
6.1, 6.8.0, 6.8.4, 6.9.1
-
-
7f24d8952 (dev), 20b5d3d0e (6.10), 6084f1d45 (6.9), c083f18bd (tqtc/lts-6.8)
When using QSqlDatabase / QSqlQuery to retrieve data from an MS SQL database through the ODBC driver, the data type real with the value 0.015625 is not preserved exactly and is instead retrieved as 0.01562 or 0.015619.
To reproduce the issue, run the following commands in Microsoft SQL Server:
int main(int argc, char *argv[]) { qDebug() << "Qt version: " << QT_VERSION_STR; QApplication a(argc, argv); QSqlDatabase database = QSqlDatabase::addDatabase("QODBC"); database.setDatabaseName("qt_test"); database.setUserName("sa"); database.setPassword("testuser"); database.open(); QSqlQuery q(database); q.exec("DROP TABLE IF EXISTS test_table"); q.exec(R"( CREATE TABLE test_table ( Id INT IDENTITY(1,1) PRIMARY KEY, Column1 REAL, Column2 FLOAT ); )"); q.exec("INSERT INTO test_table(Column1, Column2) Values (0.015625, 0.015625), (0.09375, 0.09375);"); q.exec("SELECT Column1, Column2 FROM test_table"); while (q.next()) { auto val1 = q.value(0).toDouble(); auto val2 = q.value(1).toDouble(); qDebug() << val1 << val2; } return 0; }
- Edit the username and password in the attached example project to connect to your database, then run the project.
Expected behavior:
The value in Column1 (of type real) in the first row should return exactly 0.015625, as it is stored in the database.
Actual behavior:
The value in Column1 of the first row does not return the exact stored value; instead, it returns an approximation such as 0.01562 or 0.015619.
- resulted from
-
QTBUG-8963 Driver for ODBC - qsql_odbc.cpp should use the QMetaType:float when sql type is SQL_FLOAT instead of QVariant::Double
-
- Closed
-