From e5049ecc4590896a75dedcb098da9e991e1764ee Mon Sep 17 00:00:00 2001 From: Derick Hawcroft Date: Wed, 8 Jul 2009 09:20:31 +1000 Subject: Handle special number cases (nan,{+-}infinity) in PostgreSQL When contructing the EXECUTE statement, there is a special case that we need to handle whereby we explicitly put quotes around the special float values before submutting the statement for execution Task-number:233829 Reviewed-by: Bill King --- src/sql/drivers/psql/qsql_psql.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/sql/drivers/psql/qsql_psql.cpp b/src/sql/drivers/psql/qsql_psql.cpp index 69697da..64b2a23 100644 --- a/src/sql/drivers/psql/qsql_psql.cpp +++ b/src/sql/drivers/psql/qsql_psql.cpp @@ -54,6 +54,8 @@ #include #include +#include + #include #include @@ -1144,6 +1146,21 @@ QString QPSQLDriver::formatValue(const QSqlField &field, bool trimStrings) const qPQfreemem(data); break; } + case QVariant::Double: { + double val = field.value().toDouble(); + if (isnan(val)) + r = QLatin1String("'NaN'"); + else { + int res = isinf(val); + if (res == 1) + r = QLatin1String("'Infinity'"); + else if (res == -1) + r = QLatin1String("'-Infinity'"); + else + r = QSqlDriver::formatValue(field, trimStrings); + } + break; + } default: r = QSqlDriver::formatValue(field, trimStrings); break; -- cgit v0.12