summaryrefslogtreecommitdiffstats
path: root/src/sql/drivers/psql
diff options
context:
space:
mode:
authorBill King <bill.king@nokia.com>2009-06-12 00:29:44 (GMT)
committerBill King <bill.king@nokia.com>2009-06-15 00:31:07 (GMT)
commitc9f77564df14f91276e9ca693a9b3f339dab9334 (patch)
tree5c87e861a3973433c2b01ece730164d63a5dab95 /src/sql/drivers/psql
parentba097c23159c1ec026b8b8772d1a9c5e72f2a681 (diff)
downloadQt-c9f77564df14f91276e9ca693a9b3f339dab9334.zip
Qt-c9f77564df14f91276e9ca693a9b3f339dab9334.tar.gz
Qt-c9f77564df14f91276e9ca693a9b3f339dab9334.tar.bz2
Stage 1 of incorporating database level precision policy.
Queries now ask the database object what precision they should be, allows for setting precision policies on sql models, where previously this was not available. Also fixes some failing precisionpolicy implementations, as well as working around the fact qstring can't convert from "123.00" to an int based type.
Diffstat (limited to 'src/sql/drivers/psql')
-rw-r--r--src/sql/drivers/psql/qsql_psql.cpp21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/sql/drivers/psql/qsql_psql.cpp b/src/sql/drivers/psql/qsql_psql.cpp
index ce0b8c5..169a371 100644
--- a/src/sql/drivers/psql/qsql_psql.cpp
+++ b/src/sql/drivers/psql/qsql_psql.cpp
@@ -136,13 +136,12 @@ void QPSQLDriverPrivate::appendTables(QStringList &tl, QSqlQuery &t, QChar type)
class QPSQLResultPrivate
{
public:
- QPSQLResultPrivate(QPSQLResult *qq): q(qq), driver(0), result(0), currentSize(-1), precisionPolicy(QSql::HighPrecision) {}
+ QPSQLResultPrivate(QPSQLResult *qq): q(qq), driver(0), result(0), currentSize(-1) {}
QPSQLResult *q;
const QPSQLDriverPrivate *driver;
PGresult *result;
int currentSize;
- QSql::NumericalPrecisionPolicy precisionPolicy;
bool preparedQueriesEnabled;
QString preparedStmtId;
@@ -320,15 +319,16 @@ QVariant QPSQLResult::data(int i)
return atoi(val);
case QVariant::Double:
if (ptype == QNUMERICOID) {
- if (d->precisionPolicy != QSql::HighPrecision) {
+ if (numericalPrecisionPolicy() != QSql::HighPrecision) {
QVariant retval;
bool convert;
- if (d->precisionPolicy == QSql::LowPrecisionInt64)
- retval = QString::fromAscii(val).toLongLong(&convert);
- else if (d->precisionPolicy == QSql::LowPrecisionInt32)
- retval = QString::fromAscii(val).toInt(&convert);
- else if (d->precisionPolicy == QSql::LowPrecisionDouble)
- retval = QString::fromAscii(val).toDouble(&convert);
+ double dbl=QString::fromAscii(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;
@@ -467,9 +467,6 @@ void QPSQLResult::virtual_hook(int id, void *data)
Q_ASSERT(data);
switch (id) {
- case QSqlResult::SetNumericalPrecision:
- d->precisionPolicy = *reinterpret_cast<QSql::NumericalPrecisionPolicy *>(data);
- break;
default:
QSqlResult::virtual_hook(id, data);
}