diff options
author | Bill King <bill.king@nokia.com> | 2009-06-12 00:29:44 (GMT) |
---|---|---|
committer | Bill King <bill.king@nokia.com> | 2009-06-15 00:31:07 (GMT) |
commit | c9f77564df14f91276e9ca693a9b3f339dab9334 (patch) | |
tree | 5c87e861a3973433c2b01ece730164d63a5dab95 /src/sql/drivers/odbc | |
parent | ba097c23159c1ec026b8b8772d1a9c5e72f2a681 (diff) | |
download | Qt-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/odbc')
-rw-r--r-- | src/sql/drivers/odbc/qsql_odbc.cpp | 63 |
1 files changed, 35 insertions, 28 deletions
diff --git a/src/sql/drivers/odbc/qsql_odbc.cpp b/src/sql/drivers/odbc/qsql_odbc.cpp index 8eaa8bf..f60c33c 100644 --- a/src/sql/drivers/odbc/qsql_odbc.cpp +++ b/src/sql/drivers/odbc/qsql_odbc.cpp @@ -127,7 +127,7 @@ class QODBCPrivate { public: QODBCPrivate() - : hEnv(0), hDbc(0), hStmt(0), useSchema(false), hasSQLFetchScroll(true), precisionPolicy(QSql::HighPrecision) + : hEnv(0), hDbc(0), hStmt(0), useSchema(false), hasSQLFetchScroll(true) { sql_char_type = sql_varchar_type = sql_longvarchar_type = QVariant::ByteArray; unicode = false; @@ -151,7 +151,6 @@ public: int fieldCacheIdx; int disconnectCount; bool hasSQLFetchScroll; - QSql::NumericalPrecisionPolicy precisionPolicy; bool isStmtHandleValid(const QSqlDriver *driver); void updateStmtHandleState(const QSqlDriver *driver); @@ -444,6 +443,26 @@ static QVariant qGetIntData(SQLHANDLE hStmt, int column, bool isSigned = true) return uint(intbuf); } +static QVariant qGetDoubleData(SQLHANDLE hStmt, int column) +{ + SQLDOUBLE dblbuf; + SQLINTEGER lengthIndicator = 0; + SQLRETURN r = SQLGetData(hStmt, + column+1, + SQL_C_DOUBLE, + (SQLPOINTER) &dblbuf, + 0, + &lengthIndicator); + if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) { + return QVariant(QVariant::Invalid); + } + if(lengthIndicator == SQL_NULL_DATA) + return QVariant(QVariant::Double); + + return (double) dblbuf; +} + + static QVariant qGetBigIntData(SQLHANDLE hStmt, int column, bool isSigned = true) { SQLBIGINT lngbuf = 0; @@ -1109,29 +1128,21 @@ QVariant QODBCResult::data(int field) d->fieldCache[i] = qGetStringData(d->hStmt, i, info.length(), true); break; case QVariant::Double: - { - QString value=qGetStringData(d->hStmt, i, info.length(), false); - bool ok=false; - switch(d->precisionPolicy) { - case QSql::LowPrecisionInt32: - d->fieldCache[i] = value.toInt(&ok); - break; - case QSql::LowPrecisionInt64: - d->fieldCache[i] = value.toLongLong(&ok); - break; - case QSql::LowPrecisionDouble: - d->fieldCache[i] = value.toDouble(&ok); - break; - case QSql::HighPrecision: - default: - d->fieldCache[i] = value; - ok=true; - break; - } - if(ok==false) - d->fieldCache[i] = QVariant(); - break; + switch(numericalPrecisionPolicy()) { + case QSql::LowPrecisionInt32: + d->fieldCache[i] = qGetIntData(d->hStmt, i); + break; + case QSql::LowPrecisionInt64: + d->fieldCache[i] = qGetBigIntData(d->hStmt, i); + break; + case QSql::LowPrecisionDouble: + d->fieldCache[i] = qGetDoubleData(d->hStmt, i); + break; + case QSql::HighPrecision: + d->fieldCache[i] = qGetStringData(d->hStmt, i, info.length(), false); + break; } + break; default: d->fieldCache[i] = QVariant(qGetStringData(d->hStmt, i, info.length(), false)); break; @@ -1628,10 +1639,6 @@ void QODBCResult::virtual_hook(int id, void *data) Q_ASSERT(data); *static_cast<bool*>(data) = nextResult(); break; - case QSqlResult::SetNumericalPrecision: - Q_ASSERT(data); - d->precisionPolicy = *reinterpret_cast<QSql::NumericalPrecisionPolicy *>(data); - break; default: QSqlResult::virtual_hook(id, data); } |