QPSQL: Use qstrtod() function for string to double conversion
A change to qstrtod() will give us a small performance improvement. Because the qstrtod() function does not correctly parse the NaN values, an appropriate check condition for NaN has been added. Also changed code structure so now the double conversion function is called only in one place. Task-number: QTBUG-65748 Change-Id: I49d40e5157e79cc5fce35db4c4272d1ccd270c6b Reviewed-by: Andy Shaw <andy.shaw@qt.io>
This commit is contained in:
parent
0a02de62d1
commit
52c0bb5994
@ -53,6 +53,7 @@
|
||||
#include <qlocale.h>
|
||||
#include <QtSql/private/qsqlresult_p.h>
|
||||
#include <QtSql/private/qsqldriver_p.h>
|
||||
#include <QtCore/private/qlocale_tools_p.h>
|
||||
|
||||
#include <queue>
|
||||
|
||||
@ -663,27 +664,30 @@ QVariant QPSQLResult::data(int i)
|
||||
return atoi(val);
|
||||
case QVariant::Double: {
|
||||
if (ptype == QNUMERICOID) {
|
||||
if (numericalPrecisionPolicy() != QSql::HighPrecision) {
|
||||
QVariant retval;
|
||||
bool convert;
|
||||
double dbl=QString::fromLatin1(val).toDouble(&convert);
|
||||
if (numericalPrecisionPolicy() == QSql::LowPrecisionInt64)
|
||||
retval = (qlonglong)dbl;
|
||||
else if (numericalPrecisionPolicy() == QSql::LowPrecisionInt32)
|
||||
retval = (int)dbl;
|
||||
else if (numericalPrecisionPolicy() == QSql::LowPrecisionDouble)
|
||||
retval = dbl;
|
||||
if (!convert)
|
||||
return QVariant();
|
||||
return retval;
|
||||
}
|
||||
return QString::fromLatin1(val);
|
||||
if (numericalPrecisionPolicy() == QSql::HighPrecision)
|
||||
return QString::fromLatin1(val);
|
||||
}
|
||||
if (qstricmp(val, "Infinity") == 0)
|
||||
return qInf();
|
||||
if (qstricmp(val, "-Infinity") == 0)
|
||||
return -qInf();
|
||||
return QString::fromLatin1(val).toDouble();
|
||||
bool ok;
|
||||
double dbl = qstrtod(val, nullptr, &ok);
|
||||
if (!ok) {
|
||||
if (qstricmp(val, "NaN") == 0)
|
||||
dbl = qQNaN();
|
||||
else if (qstricmp(val, "Infinity") == 0)
|
||||
dbl = qInf();
|
||||
else if (qstricmp(val, "-Infinity") == 0)
|
||||
dbl = -qInf();
|
||||
else
|
||||
return QVariant();
|
||||
}
|
||||
if (ptype == QNUMERICOID) {
|
||||
if (numericalPrecisionPolicy() == QSql::LowPrecisionInt64)
|
||||
return QVariant((qlonglong)dbl);
|
||||
else if (numericalPrecisionPolicy() == QSql::LowPrecisionInt32)
|
||||
return QVariant((int)dbl);
|
||||
else if (numericalPrecisionPolicy() == QSql::LowPrecisionDouble)
|
||||
return QVariant(dbl);
|
||||
}
|
||||
return dbl;
|
||||
}
|
||||
case QVariant::Date:
|
||||
if (val[0] == '\0') {
|
||||
|
Loading…
Reference in New Issue
Block a user