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/mysql/qsql_mysql.cpp | |
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/mysql/qsql_mysql.cpp')
-rw-r--r-- | src/sql/drivers/mysql/qsql_mysql.cpp | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/sql/drivers/mysql/qsql_mysql.cpp b/src/sql/drivers/mysql/qsql_mysql.cpp index 82ed124..0ea2f96 100644 --- a/src/sql/drivers/mysql/qsql_mysql.cpp +++ b/src/sql/drivers/mysql/qsql_mysql.cpp @@ -167,12 +167,11 @@ class QMYSQLResultPrivate : public QObject { Q_OBJECT public: - QMYSQLResultPrivate(const QMYSQLDriver* dp) : driver(dp), result(0), + QMYSQLResultPrivate(const QMYSQLDriver* dp, const QMYSQLResult* d) : driver(dp), result(0), q(d), rowsAffected(0), hasBlobs(false) #if MYSQL_VERSION_ID >= 40108 , stmt(0), meta(0), inBinds(0), outBinds(0) #endif - , precisionPolicy(QSql::HighPrecision) { connect(dp, SIGNAL(destroyed()), this, SLOT(driverDestroyed())); } @@ -180,6 +179,7 @@ public: const QMYSQLDriver* driver; MYSQL_RES *result; MYSQL_ROW row; + const QMYSQLResult* q; int rowsAffected; @@ -209,7 +209,6 @@ public: MYSQL_BIND *inBinds; MYSQL_BIND *outBinds; #endif - QSql::NumericalPrecisionPolicy precisionPolicy; private Q_SLOTS: void driverDestroyed() { driver = NULL; } }; @@ -254,6 +253,7 @@ static QVariant::Type qDecodeMYSQLType(int mysqltype, uint flags) break; case FIELD_TYPE_FLOAT : case FIELD_TYPE_DOUBLE : + case FIELD_TYPE_DECIMAL : type = QVariant::Double; break; case FIELD_TYPE_DATE : @@ -277,7 +277,6 @@ static QVariant::Type qDecodeMYSQLType(int mysqltype, uint flags) default: case FIELD_TYPE_ENUM : case FIELD_TYPE_SET : - case FIELD_TYPE_DECIMAL : type = QVariant::String; break; } @@ -354,6 +353,7 @@ bool QMYSQLResultPrivate::bindInValues() while((fieldInfo = mysql_fetch_field(meta))) { QMyField &f = fields[i]; f.myField = fieldInfo; + f.type = qDecodeMYSQLType(fieldInfo->type, fieldInfo->flags); if (qIsBlob(fieldInfo->type)) { // the size of a blob-field is available as soon as we call @@ -384,7 +384,7 @@ bool QMYSQLResultPrivate::bindInValues() QMYSQLResult::QMYSQLResult(const QMYSQLDriver* db) : QSqlResult(db) { - d = new QMYSQLResultPrivate(db); + d = new QMYSQLResultPrivate(db, this); } QMYSQLResult::~QMYSQLResult() @@ -599,15 +599,16 @@ QVariant QMYSQLResult::data(int field) case QVariant::Double: { QVariant v; bool ok=false; - switch(d->precisionPolicy) { + double dbl = val.toDouble(&ok); + switch(numericalPrecisionPolicy()) { case QSql::LowPrecisionInt32: - v=val.toInt(&ok); + v=QVariant(dbl).toInt(); break; case QSql::LowPrecisionInt64: - v = val.toLongLong(&ok); + v = QVariant(dbl).toLongLong(); break; case QSql::LowPrecisionDouble: - v = val.toDouble(&ok); + v = QVariant(dbl); break; case QSql::HighPrecision: default: @@ -620,6 +621,7 @@ QVariant QMYSQLResult::data(int field) else return QVariant(); } + return QVariant(val.toDouble()); case QVariant::Date: return qDateFromString(val); case QVariant::Time: @@ -679,6 +681,7 @@ bool QMYSQLResult::reset (const QString& query) setSelect(numFields != 0); d->fields.resize(numFields); d->rowsAffected = mysql_affected_rows(d->driver->d->mysql); + if (isSelect()) { for(int i = 0; i < numFields; i++) { MYSQL_FIELD* field = mysql_fetch_field_direct(d->result, i); @@ -813,10 +816,6 @@ void QMYSQLResult::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); } @@ -1148,7 +1147,6 @@ bool QMYSQLDriver::hasFeature(DriverFeature f) const case NamedPlaceholders: case BatchOperations: case SimpleLocking: - case LowPrecisionNumbers: case EventNotifications: case FinishQuery: return false; @@ -1156,6 +1154,7 @@ bool QMYSQLDriver::hasFeature(DriverFeature f) const case BLOB: case LastInsertId: case Unicode: + case LowPrecisionNumbers: return true; case PreparedQueries: case PositionalPlaceholders: @@ -1369,6 +1368,7 @@ QSqlRecord QMYSQLDriver::record(const QString& tablename) const return info; } MYSQL_FIELD* field; + while ((field = mysql_fetch_field(r))) info.append(qToField(field, d->tc)); mysql_free_result(r); @@ -1485,4 +1485,4 @@ bool QMYSQLDriver::isIdentifierEscapedImplementation(const QString &identifier, QT_END_NAMESPACE -#include "qsql_mysql.moc"
\ No newline at end of file +#include "qsql_mysql.moc" |