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 Pick-to: 6.0 5.15 5.12 Change-Id: I905c947b4d0266a3245d5735300300ca00f77480 Reviewed-by: Andy Shaw <andy.shaw@qt.io> Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
This commit is contained in:
parent
1bcfada9f0
commit
c2657f9762
@ -1289,7 +1289,8 @@ QVariant QODBCResult::data(int field)
|
|||||||
d->fieldCache[i] = qGetDoubleData(d->hStmt, i);
|
d->fieldCache[i] = qGetDoubleData(d->hStmt, i);
|
||||||
break;
|
break;
|
||||||
case QSql::HighPrecision:
|
case QSql::HighPrecision:
|
||||||
d->fieldCache[i] = qGetStringData(d->hStmt, i, info.length(), false);
|
const int extra = info.precision() > 0 ? 1 : 0;
|
||||||
|
d->fieldCache[i] = qGetStringData(d->hStmt, i, info.length() + extra, false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -258,6 +258,9 @@ private slots:
|
|||||||
void QTBUG_57138_data() { generic_data("QSQLITE"); }
|
void QTBUG_57138_data() { generic_data("QSQLITE"); }
|
||||||
void QTBUG_57138();
|
void QTBUG_57138();
|
||||||
|
|
||||||
|
void QTBUG_73286_data() { generic_data("QODBC"); }
|
||||||
|
void QTBUG_73286();
|
||||||
|
|
||||||
void dateTime_data();
|
void dateTime_data();
|
||||||
void dateTime();
|
void dateTime();
|
||||||
|
|
||||||
@ -4548,6 +4551,7 @@ void tst_QSqlQuery::QTBUG_57138()
|
|||||||
|
|
||||||
QSqlQuery create(db);
|
QSqlQuery create(db);
|
||||||
QString tableName = qTableName("qtbug57138", __FILE__, 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, 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 (?, ?, ?, ?)"));
|
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);
|
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()
|
void tst_QSqlQuery::dateTime_data()
|
||||||
{
|
{
|
||||||
if (dbs.dbNames.isEmpty())
|
if (dbs.dbNames.isEmpty())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user