diff options
author | Bill King <bill.king@nokia.com> | 2009-06-18 03:57:51 (GMT) |
---|---|---|
committer | Bill King <bill.king@nokia.com> | 2009-06-21 23:04:53 (GMT) |
commit | a290f3b64a4a77018845612eef15baa98fc0833a (patch) | |
tree | 9ab806dd7e0c3cf2a2264759a633aa68e1370d30 /src/sql | |
parent | cb8cfe965d9e5716e4ffc14b90c1fefaab53d126 (diff) | |
download | Qt-a290f3b64a4a77018845612eef15baa98fc0833a.zip Qt-a290f3b64a4a77018845612eef15baa98fc0833a.tar.gz Qt-a290f3b64a4a77018845612eef15baa98fc0833a.tar.bz2 |
Stage 2 of incorporating database level precision policy.
All autotests pass now for all databases except DB2 (untested).
Diffstat (limited to 'src/sql')
-rw-r--r-- | src/sql/drivers/ibase/qsql_ibase.cpp | 36 | ||||
-rw-r--r-- | src/sql/drivers/mysql/qsql_mysql.cpp | 3 | ||||
-rw-r--r-- | src/sql/drivers/oci/qsql_oci.cpp | 2 | ||||
-rw-r--r-- | src/sql/drivers/sqlite/qsql_sqlite.cpp | 2 | ||||
-rw-r--r-- | src/sql/drivers/sqlite2/qsql_sqlite2.cpp | 2 | ||||
-rw-r--r-- | src/sql/kernel/qsqlcachedresult.cpp | 13 | ||||
-rw-r--r-- | src/sql/kernel/qsqlcachedresult_p.h | 1 | ||||
-rw-r--r-- | src/sql/kernel/qsqlresult.cpp | 2 |
8 files changed, 56 insertions, 5 deletions
diff --git a/src/sql/drivers/ibase/qsql_ibase.cpp b/src/sql/drivers/ibase/qsql_ibase.cpp index 0698f26..259a247 100644 --- a/src/sql/drivers/ibase/qsql_ibase.cpp +++ b/src/sql/drivers/ibase/qsql_ibase.cpp @@ -1103,6 +1103,19 @@ bool QIBaseResult::gotoNext(QSqlCachedResult::ValueCache& row, int rowIdx) // null value QVariant v; v.convert(qIBaseTypeName2(d->sqlda->sqlvar[i].sqltype, d->sqlda->sqlvar[i].sqlscale < 0)); + if(v.type() == QVariant::Double) { + switch(numericalPrecisionPolicy()) { + case QSql::LowPrecisionInt32: + v.convert(QVariant::Int); + break; + case QSql::LowPrecisionInt64: + v.convert(QVariant::LongLong); + break; + case QSql::HighPrecision: + v.convert(QVariant::String); + break; + } + } row[idx] = v; continue; } @@ -1168,6 +1181,27 @@ bool QIBaseResult::gotoNext(QSqlCachedResult::ValueCache& row, int rowIdx) row[idx] = QVariant(); break; } + if (d->sqlda->sqlvar[i].sqlscale < 0) { + QVariant v = row[idx]; + switch(numericalPrecisionPolicy()) { + case QSql::LowPrecisionInt32: + if(v.convert(QVariant::Int)) + row[idx]=v; + break; + case QSql::LowPrecisionInt64: + if(v.convert(QVariant::LongLong)) + row[idx]=v; + break; + case QSql::LowPrecisionDouble: + if(v.convert(QVariant::Double)) + row[idx]=v; + break; + case QSql::HighPrecision: + if(v.convert(QVariant::String)) + row[idx]=v; + break; + } + } } return true; @@ -1339,7 +1373,6 @@ bool QIBaseDriver::hasFeature(DriverFeature f) const case LastInsertId: case BatchOperations: case SimpleLocking: - case LowPrecisionNumbers: case FinishQuery: case MultipleResultSets: return false; @@ -1349,6 +1382,7 @@ bool QIBaseDriver::hasFeature(DriverFeature f) const case Unicode: case BLOB: case EventNotifications: + case LowPrecisionNumbers: return true; } return false; diff --git a/src/sql/drivers/mysql/qsql_mysql.cpp b/src/sql/drivers/mysql/qsql_mysql.cpp index 46726a5..bfd65fc 100644 --- a/src/sql/drivers/mysql/qsql_mysql.cpp +++ b/src/sql/drivers/mysql/qsql_mysql.cpp @@ -254,6 +254,9 @@ static QVariant::Type qDecodeMYSQLType(int mysqltype, uint flags) case FIELD_TYPE_FLOAT : case FIELD_TYPE_DOUBLE : case FIELD_TYPE_DECIMAL : +#if defined(FIELD_TYPE_NEWDECIMAL) + case FIELD_TYPE_NEWDECIMAL: +#endif type = QVariant::Double; break; case FIELD_TYPE_DATE : diff --git a/src/sql/drivers/oci/qsql_oci.cpp b/src/sql/drivers/oci/qsql_oci.cpp index ca4b286..d5fb10f 100644 --- a/src/sql/drivers/oci/qsql_oci.cpp +++ b/src/sql/drivers/oci/qsql_oci.cpp @@ -1899,7 +1899,7 @@ void QOCIResult::virtual_hook(int id, void *data) QOCICols::execBatch(d, boundValues(), *reinterpret_cast<bool *>(data)); break; default: - QSqlResult::virtual_hook(id, data); + QSqlCachedResult::virtual_hook(id, data); } } diff --git a/src/sql/drivers/sqlite/qsql_sqlite.cpp b/src/sql/drivers/sqlite/qsql_sqlite.cpp index 1a05873..05f5ab3 100644 --- a/src/sql/drivers/sqlite/qsql_sqlite.cpp +++ b/src/sql/drivers/sqlite/qsql_sqlite.cpp @@ -289,7 +289,7 @@ void QSQLiteResult::virtual_hook(int id, void *data) sqlite3_reset(d->stmt); break; default: - QSqlResult::virtual_hook(id, data); + QSqlCachedResult::virtual_hook(id, data); } } diff --git a/src/sql/drivers/sqlite2/qsql_sqlite2.cpp b/src/sql/drivers/sqlite2/qsql_sqlite2.cpp index 790c1ef..1989c45 100644 --- a/src/sql/drivers/sqlite2/qsql_sqlite2.cpp +++ b/src/sql/drivers/sqlite2/qsql_sqlite2.cpp @@ -260,7 +260,7 @@ void QSQLite2Result::virtual_hook(int id, void *data) d->finalize(); break; default: - QSqlResult::virtual_hook(id, data); + QSqlCachedResult::virtual_hook(id, data); } } diff --git a/src/sql/kernel/qsqlcachedresult.cpp b/src/sql/kernel/qsqlcachedresult.cpp index 3cace06..ca51dc0 100644 --- a/src/sql/kernel/qsqlcachedresult.cpp +++ b/src/sql/kernel/qsqlcachedresult.cpp @@ -294,4 +294,17 @@ QSqlCachedResult::ValueCache &QSqlCachedResult::cache() return d->cache; } +void QSqlCachedResult::virtual_hook(int id, void *data) +{ + switch (id) { + case QSqlResult::DetachFromResultSet: + case QSqlResult::SetNumericalPrecision: + cleanup(); + break; + default: + QSqlResult::virtual_hook(id, data); + } +} + + QT_END_NAMESPACE diff --git a/src/sql/kernel/qsqlcachedresult_p.h b/src/sql/kernel/qsqlcachedresult_p.h index d19435c..a384b2e 100644 --- a/src/sql/kernel/qsqlcachedresult_p.h +++ b/src/sql/kernel/qsqlcachedresult_p.h @@ -89,6 +89,7 @@ protected: int colCount() const; ValueCache &cache(); + void virtual_hook(int id, void *data); private: bool cacheNext(); QSqlCachedResultPrivate *d; diff --git a/src/sql/kernel/qsqlresult.cpp b/src/sql/kernel/qsqlresult.cpp index 1c1595d..93c9d9f 100644 --- a/src/sql/kernel/qsqlresult.cpp +++ b/src/sql/kernel/qsqlresult.cpp @@ -905,7 +905,6 @@ QVariant QSqlResult::lastInsertId() const */ void QSqlResult::virtual_hook(int, void *) { - Q_ASSERT(false); } /*! \internal @@ -971,6 +970,7 @@ void QSqlResult::detachFromResultSet() void QSqlResult::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy policy) { d->precisionPolicy = policy; + virtual_hook(SetNumericalPrecision, &policy); } /*! \internal |