diff options
Diffstat (limited to 'src/sql/kernel')
-rw-r--r-- | src/sql/kernel/kernel.pri | 1 | ||||
-rw-r--r-- | src/sql/kernel/qsql.h | 4 | ||||
-rw-r--r-- | src/sql/kernel/qsqldatabase.cpp | 18 | ||||
-rw-r--r-- | src/sql/kernel/qsqldatabase.h | 4 | ||||
-rw-r--r-- | src/sql/kernel/qsqldriver.cpp | 32 | ||||
-rw-r--r-- | src/sql/kernel/qsqldriver.h | 5 | ||||
-rw-r--r-- | src/sql/kernel/qsqldriver_p.h | 86 | ||||
-rw-r--r-- | src/sql/kernel/qsqldriverplugin.h | 4 | ||||
-rw-r--r-- | src/sql/kernel/qsqlerror.cpp | 44 | ||||
-rw-r--r-- | src/sql/kernel/qsqlerror.h | 15 | ||||
-rw-r--r-- | src/sql/kernel/qsqlfield.h | 4 | ||||
-rw-r--r-- | src/sql/kernel/qsqlindex.h | 4 | ||||
-rw-r--r-- | src/sql/kernel/qsqlquery.cpp | 14 | ||||
-rw-r--r-- | src/sql/kernel/qsqlquery.h | 4 | ||||
-rw-r--r-- | src/sql/kernel/qsqlrecord.cpp | 15 | ||||
-rw-r--r-- | src/sql/kernel/qsqlrecord.h | 5 | ||||
-rw-r--r-- | src/sql/kernel/qsqlresult.cpp | 69 | ||||
-rw-r--r-- | src/sql/kernel/qsqlresult.h | 10 | ||||
-rw-r--r-- | src/sql/kernel/qsqlresult_p.h | 17 |
19 files changed, 239 insertions, 116 deletions
diff --git a/src/sql/kernel/kernel.pri b/src/sql/kernel/kernel.pri index fe7f1270f9..dad3b46781 100644 --- a/src/sql/kernel/kernel.pri +++ b/src/sql/kernel/kernel.pri @@ -4,6 +4,7 @@ HEADERS += kernel/qsql.h \ kernel/qsqlfield.h \ kernel/qsqlrecord.h \ kernel/qsqldriver.h \ + kernel/qsqldriver_p.h \ kernel/qsqlnulldriver_p.h \ kernel/qsqldriverplugin.h \ kernel/qsqlerror.h \ diff --git a/src/sql/kernel/qsql.h b/src/sql/kernel/qsql.h index 54c5fc13b6..9b9381f797 100644 --- a/src/sql/kernel/qsql.h +++ b/src/sql/kernel/qsql.h @@ -44,8 +44,6 @@ #include <QtCore/qglobal.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE #ifndef QT_STATIC @@ -97,6 +95,4 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QSql::ParamType) QT_END_NAMESPACE -QT_END_HEADER - #endif // QSQL_H diff --git a/src/sql/kernel/qsqldatabase.cpp b/src/sql/kernel/qsqldatabase.cpp index 36422f5f62..0ca79fd39f 100644 --- a/src/sql/kernel/qsqldatabase.cpp +++ b/src/sql/kernel/qsqldatabase.cpp @@ -48,31 +48,31 @@ #endif #ifdef QT_SQL_PSQL -#include "../drivers/psql/qsql_psql.h" +#include "../drivers/psql/qsql_psql_p.h" #endif #ifdef QT_SQL_MYSQL -#include "../drivers/mysql/qsql_mysql.h" +#include "../drivers/mysql/qsql_mysql_p.h" #endif #ifdef QT_SQL_ODBC -#include "../drivers/odbc/qsql_odbc.h" +#include "../drivers/odbc/qsql_odbc_p.h" #endif #ifdef QT_SQL_OCI -#include "../drivers/oci/qsql_oci.h" +#include "../drivers/oci/qsql_oci_p.h" #endif #ifdef QT_SQL_TDS // conflicting RETCODE typedef between odbc and freetds #define RETCODE DBRETCODE -#include "../drivers/tds/qsql_tds.h" +#include "../drivers/tds/qsql_tds_p.h" #undef RETCODE #endif #ifdef QT_SQL_DB2 -#include "../drivers/db2/qsql_db2.h" +#include "../drivers/db2/qsql_db2_p.h" #endif #ifdef QT_SQL_SQLITE -#include "../drivers/sqlite/qsql_sqlite.h" +#include "../drivers/sqlite/qsql_sqlite_p.h" #endif #ifdef QT_SQL_SQLITE2 -#include "../drivers/sqlite2/qsql_sqlite2.h" +#include "../drivers/sqlite2/qsql_sqlite2_p.h" #endif #ifdef QT_SQL_IBASE #undef SQL_FLOAT // avoid clash with ODBC @@ -82,7 +82,7 @@ #undef SQL_TYPE_DATE #undef SQL_DATE #define SCHAR IBASE_SCHAR // avoid clash with ODBC (older versions of ibase.h with Firebird) -#include "../drivers/ibase/qsql_ibase.h" +#include "../drivers/ibase/qsql_ibase_p.h" #undef SCHAR #endif diff --git a/src/sql/kernel/qsqldatabase.h b/src/sql/kernel/qsqldatabase.h index f0e920ade1..7249e223a5 100644 --- a/src/sql/kernel/qsqldatabase.h +++ b/src/sql/kernel/qsqldatabase.h @@ -45,8 +45,6 @@ #include <QtCore/qstring.h> #include <QtSql/qsql.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -146,6 +144,4 @@ Q_SQL_EXPORT QDebug operator<<(QDebug, const QSqlDatabase &); QT_END_NAMESPACE -QT_END_HEADER - #endif // QSQLDATABASE_H diff --git a/src/sql/kernel/qsqldriver.cpp b/src/sql/kernel/qsqldriver.cpp index 690525f8ca..63b90f27c6 100644 --- a/src/sql/kernel/qsqldriver.cpp +++ b/src/sql/kernel/qsqldriver.cpp @@ -46,6 +46,7 @@ #include "qsqlfield.h" #include "qsqlindex.h" #include "private/qobject_p.h" +#include "private/qsqldriver_p.h" QT_BEGIN_NAMESPACE @@ -60,30 +61,6 @@ static QString prepareIdentifier(const QString &identifier, return ret; } -class QSqlDriverPrivate : public QObjectPrivate -{ -public: - QSqlDriverPrivate(); - virtual ~QSqlDriverPrivate(); - -public: - // @CHECK: this member is never used. It was named q, which expanded to q_func(). - QSqlDriver *q_func(); - uint isOpen : 1; - uint isOpenError : 1; - QSqlError error; - QSql::NumericalPrecisionPolicy precisionPolicy; -}; - -inline QSqlDriverPrivate::QSqlDriverPrivate() - : QObjectPrivate(), isOpen(false), isOpenError(false), precisionPolicy(QSql::LowPrecisionDouble) -{ -} - -QSqlDriverPrivate::~QSqlDriverPrivate() -{ -} - /*! \class QSqlDriver \brief The QSqlDriver class is an abstract base class for accessing @@ -111,6 +88,13 @@ QSqlDriver::QSqlDriver(QObject *parent) { } +/*! \internal +*/ +QSqlDriver::QSqlDriver(QSqlDriverPrivate &dd, QObject *parent) + : QObject(dd, parent) +{ +} + /*! Destroys the object and frees any allocated resources. */ diff --git a/src/sql/kernel/qsqldriver.h b/src/sql/kernel/qsqldriver.h index aaa879e957..017ffd4e4a 100644 --- a/src/sql/kernel/qsqldriver.h +++ b/src/sql/kernel/qsqldriver.h @@ -47,8 +47,6 @@ #include <QtCore/qstringlist.h> #include <QtSql/qsql.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -128,6 +126,7 @@ Q_SIGNALS: void notification(const QString &name, QSqlDriver::NotificationSource source, const QVariant &payload); protected: + QSqlDriver(QSqlDriverPrivate &dd, QObject *parent = 0); virtual void setOpen(bool o); virtual void setOpenError(bool e); virtual void setLastError(const QSqlError& e); @@ -139,6 +138,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QSQLDRIVER_H diff --git a/src/sql/kernel/qsqldriver_p.h b/src/sql/kernel/qsqldriver_p.h new file mode 100644 index 0000000000..05570e584c --- /dev/null +++ b/src/sql/kernel/qsqldriver_p.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSql module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSQLDRIVER_P_H +#define QSQLDRIVER_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of the QtSQL module. This header file may change from version to version +// without notice, or even be removed. +// +// We mean it. +// + +#include "private/qobject_p.h" +#include "qsqldriver.h" +#include "qsqlerror.h" + +QT_BEGIN_NAMESPACE + +class QSqlDriverPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QSqlDriver) + +public: + enum DBMSType {UnknownDB, MSSqlServer, MySqlServer, PostgreSQL, Oracle, Sybase, SQLite, Interbase, DB2}; + + QSqlDriverPrivate() + : QObjectPrivate(), + isOpen(false), + isOpenError(false), + precisionPolicy(QSql::LowPrecisionDouble), + dbmsType(UnknownDB) + { } + + uint isOpen; + uint isOpenError; + QSqlError error; + QSql::NumericalPrecisionPolicy precisionPolicy; + DBMSType dbmsType; +}; + +QT_END_NAMESPACE + +#endif // QSQLDRIVER_P_H diff --git a/src/sql/kernel/qsqldriverplugin.h b/src/sql/kernel/qsqldriverplugin.h index a111c1257a..ca2e0f2474 100644 --- a/src/sql/kernel/qsqldriverplugin.h +++ b/src/sql/kernel/qsqldriverplugin.h @@ -46,8 +46,6 @@ #include <QtCore/qfactoryinterface.h> #include <QtSql/qsql.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -68,6 +66,4 @@ public: QT_END_NAMESPACE -QT_END_HEADER - #endif // QSQLDRIVERPLUGIN_H diff --git a/src/sql/kernel/qsqlerror.cpp b/src/sql/kernel/qsqlerror.cpp index adcb8de4d4..9beaf10a32 100644 --- a/src/sql/kernel/qsqlerror.cpp +++ b/src/sql/kernel/qsqlerror.cpp @@ -63,9 +63,7 @@ QDebug operator<<(QDebug dbg, const QSqlError &s) A QSqlError object can provide database-specific error data, including the driverText() and databaseText() messages (or both concatenated together as text()), and the error number() and - type(). The functions all have setters so that you can create and - return QSqlError objects from your own classes, for example from - your own SQL drivers. + type(). \sa QSqlDatabase::lastError(), QSqlQuery::lastError() */ @@ -149,7 +147,7 @@ QSqlError::~QSqlError() Returns the text of the error as reported by the driver. This may contain database-specific descriptions. It may also be empty. - \sa setDriverText(), databaseText(), text() + \sa databaseText(), text() */ QString QSqlError::driverText() const { @@ -157,21 +155,29 @@ QString QSqlError::driverText() const } /*! + \fn void QSqlError::setDriverText(const QString &driverText) + \obsolete + Sets the driver error text to the value of \a driverText. + Use QSqlError(const QString &driverText, const QString &databaseText, + ErrorType type, int number) instead + \sa driverText(), setDatabaseText(), text() */ +#if QT_DEPRECATED_SINCE(5, 1) void QSqlError::setDriverText(const QString& driverText) { driverError = driverText; } +#endif /*! Returns the text of the error as reported by the database. This may contain database-specific descriptions; it may be empty. - \sa setDatabaseText(), driverText(), text() + \sa driverText(), text() */ QString QSqlError::databaseText() const @@ -180,20 +186,26 @@ QString QSqlError::databaseText() const } /*! + \fn void QSqlError::setDatabaseText(const QString &databaseText) + \obsolete + Sets the database error text to the value of \a databaseText. + Use QSqlError(const QString &driverText, const QString &databaseText, + ErrorType type, int number) instead + \sa databaseText(), setDriverText(), text() */ +#if QT_DEPRECATED_SINCE(5, 1) void QSqlError::setDatabaseText(const QString& databaseText) { databaseError = databaseText; } +#endif /*! Returns the error type, or -1 if the type cannot be determined. - - \sa setType() */ QSqlError::ErrorType QSqlError::type() const @@ -202,21 +214,27 @@ QSqlError::ErrorType QSqlError::type() const } /*! + \fn void QSqlError::setType(ErrorType type) + \obsolete + Sets the error type to the value of \a type. + Use QSqlError(const QString &driverText, const QString &databaseText, + ErrorType type, int number) instead + \sa type() */ +#if QT_DEPRECATED_SINCE(5, 1) void QSqlError::setType(ErrorType type) { errorType = type; } +#endif /*! Returns the database-specific error number, or -1 if it cannot be determined. - - \sa setNumber() */ int QSqlError::number() const @@ -225,15 +243,23 @@ int QSqlError::number() const } /*! + \fn void QSqlError::setNumber(int number) + \obsolete + Sets the database-specific error number to \a number. + Use QSqlError(const QString &driverText, const QString &databaseText, + ErrorType type, int number) instead + \sa number() */ +#if QT_DEPRECATED_SINCE(5, 1) void QSqlError::setNumber(int number) { errorNumber = number; } +#endif /*! This is a convenience function that returns databaseText() and diff --git a/src/sql/kernel/qsqlerror.h b/src/sql/kernel/qsqlerror.h index beab5f27ba..39c4cda958 100644 --- a/src/sql/kernel/qsqlerror.h +++ b/src/sql/kernel/qsqlerror.h @@ -45,8 +45,6 @@ #include <QtCore/qstring.h> #include <QtSql/qsql.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -71,16 +69,19 @@ public: ~QSqlError(); QString driverText() const; - void setDriverText(const QString& driverText); QString databaseText() const; - void setDatabaseText(const QString& databaseText); ErrorType type() const; - void setType(ErrorType type); int number() const; - void setNumber(int number); QString text() const; bool isValid() const; +#if QT_DEPRECATED_SINCE(5, 1) + QT_DEPRECATED void setDriverText(const QString &driverText); + QT_DEPRECATED void setDatabaseText(const QString &databaseText); + QT_DEPRECATED void setType(ErrorType type); + QT_DEPRECATED void setNumber(int number); +#endif + private: QString driverError; QString databaseError; @@ -94,6 +95,4 @@ Q_SQL_EXPORT QDebug operator<<(QDebug, const QSqlError &); QT_END_NAMESPACE -QT_END_HEADER - #endif // QSQLERROR_H diff --git a/src/sql/kernel/qsqlfield.h b/src/sql/kernel/qsqlfield.h index 626cce16ca..a642721039 100644 --- a/src/sql/kernel/qsqlfield.h +++ b/src/sql/kernel/qsqlfield.h @@ -46,8 +46,6 @@ #include <QtCore/qstring.h> #include <QtSql/qsql.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -110,6 +108,4 @@ Q_SQL_EXPORT QDebug operator<<(QDebug, const QSqlField &); QT_END_NAMESPACE -QT_END_HEADER - #endif // QSQLFIELD_H diff --git a/src/sql/kernel/qsqlindex.h b/src/sql/kernel/qsqlindex.h index 83e1f21e9d..96c2f614f1 100644 --- a/src/sql/kernel/qsqlindex.h +++ b/src/sql/kernel/qsqlindex.h @@ -46,8 +46,6 @@ #include <QtCore/qstring.h> #include <QtCore/qlist.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -78,6 +76,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QSQLINDEX_H diff --git a/src/sql/kernel/qsqlquery.cpp b/src/sql/kernel/qsqlquery.cpp index cac2f1dad4..5b103f1bff 100644 --- a/src/sql/kernel/qsqlquery.cpp +++ b/src/sql/kernel/qsqlquery.cpp @@ -325,7 +325,7 @@ bool QSqlQuery::isNull(int field) const } /*! - + Executes the SQL in \a query. Returns true and sets the query state to \l{isActive()}{active} if the query was successful; otherwise returns false. The \a query string must use syntax appropriate for @@ -579,7 +579,7 @@ bool QSqlQuery::seek(int index, bool relative) } /*! - + Retrieves the next record in the result, if available, and positions the query on the retrieved record. Note that the result must be in the \l{isActive()}{active} state and isSelect() must return true @@ -783,7 +783,7 @@ bool QSqlQuery::isValid() const } /*! - + Returns true if the query is \e{active}. An active QSqlQuery is one that has been \l{QSqlQuery::exec()} {exec()'d} successfully but not yet finished with. When you are finished with an active query, you @@ -1143,7 +1143,7 @@ QString QSqlQuery::executedQuery() const behavior is undefined. For MySQL databases the row's auto-increment field will be returned. - + \note For this function to work in PSQL, the table table must contain OIDs, which may not have been created by default. Check the \c default_with_oids configuration variable to be sure. @@ -1199,7 +1199,7 @@ QSql::NumericalPrecisionPolicy QSqlQuery::numericalPrecisionPolicy() const call this function, but it may be helpful in order to free resources such as locks or cursors if you intend to re-use the query at a later time. - + Sets the query to inactive. Bound values retain their values. \sa prepare(), exec(), isActive() @@ -1216,7 +1216,7 @@ void QSqlQuery::finish() /*! \since 4.4 - + Discards the current result set and navigates to the next if available. Some databases are capable of returning multiple result sets for @@ -1224,7 +1224,7 @@ void QSqlQuery::finish() multiple statements). If multiple result sets are available after executing a query this function can be used to navigate to the next result set(s). - + If a new result set is available this function will return true. The query will be repositioned on an \e invalid record in the new result set and must be navigated to a valid record before data diff --git a/src/sql/kernel/qsqlquery.h b/src/sql/kernel/qsqlquery.h index 5c14f3808b..3719643174 100644 --- a/src/sql/kernel/qsqlquery.h +++ b/src/sql/kernel/qsqlquery.h @@ -46,8 +46,6 @@ #include <QtSql/qsqldatabase.h> #include <QtCore/qstring.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -122,6 +120,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QSQLQUERY_H diff --git a/src/sql/kernel/qsqlrecord.cpp b/src/sql/kernel/qsqlrecord.cpp index ad6505c096..4cac5028c3 100644 --- a/src/sql/kernel/qsqlrecord.cpp +++ b/src/sql/kernel/qsqlrecord.cpp @@ -524,4 +524,19 @@ QDebug operator<<(QDebug dbg, const QSqlRecord &r) } #endif +/*! + \since 5.1 + Returns a record containing the fields represented in \a keyFields set to values + that match by field name. +*/ +QSqlRecord QSqlRecord::keyValues(const QSqlRecord &keyFields) const +{ + QSqlRecord retValues(keyFields); + + for (int i = retValues.count() - 1; i >= 0; --i) + retValues.setValue(i, value(retValues.fieldName(i))); + + return retValues; +} + QT_END_NAMESPACE diff --git a/src/sql/kernel/qsqlrecord.h b/src/sql/kernel/qsqlrecord.h index 0d0fae1460..7799b96588 100644 --- a/src/sql/kernel/qsqlrecord.h +++ b/src/sql/kernel/qsqlrecord.h @@ -45,8 +45,6 @@ #include <QtCore/qstring.h> #include <QtSql/qsql.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -97,6 +95,7 @@ public: void clear(); void clearValues(); int count() const; + QSqlRecord keyValues(const QSqlRecord &keyFields) const; private: void detach(); @@ -109,6 +108,4 @@ Q_SQL_EXPORT QDebug operator<<(QDebug, const QSqlRecord &); QT_END_NAMESPACE -QT_END_HEADER - #endif // QSQLRECORD_H diff --git a/src/sql/kernel/qsqlresult.cpp b/src/sql/kernel/qsqlresult.cpp index ea972abf50..e3203f983c 100644 --- a/src/sql/kernel/qsqlresult.cpp +++ b/src/sql/kernel/qsqlresult.cpp @@ -61,7 +61,7 @@ QString QSqlResultPrivate::holderAt(int index) const } // return a unique id for bound names -QString QSqlResultPrivate::fieldSerial(int i) +QString QSqlResultPrivate::fieldSerial(int i) const { ushort arr[] = { ':', 'f', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; ushort *ptr = &arr[1]; @@ -81,7 +81,7 @@ static bool qIsAlnum(QChar ch) return u - 'a' < 26 || u - 'A' < 26 || u - '0' < 10 || u == '_'; } -QString QSqlResultPrivate::positionalToNamedBinding(const QString &query, QString (fieldSerialFunc)(int idx)) +QString QSqlResultPrivate::positionalToNamedBinding(const QString &query) const { int n = query.size(); @@ -106,7 +106,7 @@ QString QSqlResultPrivate::positionalToNamedBinding(const QString &query, QStrin result += ch; } else { if (ch == QLatin1Char('?')) { - result += fieldSerialFunc(count++); + result += fieldSerial(count++); } else { if (ch == QLatin1Char('\'') || ch == QLatin1Char('"') || ch == QLatin1Char('`')) closingQuote = ch; @@ -218,11 +218,24 @@ QString QSqlResultPrivate::namedToPositionalBinding(const QString &query) QSqlResult::QSqlResult(const QSqlDriver *db) { - d = new QSqlResultPrivate(this); + d_ptr = new QSqlResultPrivate; + Q_D(QSqlResult); + d->q_ptr = this; d->sqldriver = const_cast<QSqlDriver *>(db); - if(db) { - setNumericalPrecisionPolicy(db->numericalPrecisionPolicy()); - } + if (d->sqldriver) + setNumericalPrecisionPolicy(d->sqldriver->numericalPrecisionPolicy()); +} + +/*! \internal +*/ +QSqlResult::QSqlResult(QSqlResultPrivate &dd, const QSqlDriver *db) +{ + d_ptr = ⅆ + Q_D(QSqlResult); + d->q_ptr = this; + d->sqldriver = const_cast<QSqlDriver *>(db); + if (d->sqldriver) + setNumericalPrecisionPolicy(d->sqldriver->numericalPrecisionPolicy()); } /*! @@ -231,6 +244,7 @@ QSqlResult::QSqlResult(const QSqlDriver *db) QSqlResult::~QSqlResult() { + Q_D(QSqlResult); delete d; } @@ -243,6 +257,7 @@ QSqlResult::~QSqlResult() void QSqlResult::setQuery(const QString& query) { + Q_D(QSqlResult); d->sql = query; } @@ -255,6 +270,7 @@ void QSqlResult::setQuery(const QString& query) QString QSqlResult::lastQuery() const { + Q_D(const QSqlResult); return d->sql; } @@ -267,6 +283,7 @@ QString QSqlResult::lastQuery() const */ int QSqlResult::at() const { + Q_D(const QSqlResult); return d->idx; } @@ -281,6 +298,7 @@ int QSqlResult::at() const bool QSqlResult::isValid() const { + Q_D(const QSqlResult); return d->idx != QSql::BeforeFirstRow && d->idx != QSql::AfterLastRow; } @@ -298,6 +316,7 @@ bool QSqlResult::isValid() const bool QSqlResult::isActive() const { + Q_D(const QSqlResult); return d->active; } @@ -310,6 +329,7 @@ bool QSqlResult::isActive() const void QSqlResult::setAt(int index) { + Q_D(QSqlResult); d->idx = index; } @@ -325,6 +345,7 @@ void QSqlResult::setAt(int index) void QSqlResult::setSelect(bool select) { + Q_D(QSqlResult); d->isSel = select; } @@ -337,6 +358,7 @@ void QSqlResult::setSelect(bool select) bool QSqlResult::isSelect() const { + Q_D(const QSqlResult); return d->isSel; } @@ -347,6 +369,7 @@ bool QSqlResult::isSelect() const const QSqlDriver *QSqlResult::driver() const { + Q_D(const QSqlResult); return d->sqldriver; } @@ -360,6 +383,7 @@ const QSqlDriver *QSqlResult::driver() const void QSqlResult::setActive(bool active) { + Q_D(QSqlResult); if (active && d->executedQuery.isEmpty()) d->executedQuery = d->sql; @@ -375,6 +399,7 @@ void QSqlResult::setActive(bool active) void QSqlResult::setLastError(const QSqlError &error) { + Q_D(QSqlResult); d->error = error; } @@ -385,6 +410,7 @@ void QSqlResult::setLastError(const QSqlError &error) QSqlError QSqlResult::lastError() const { + Q_D(const QSqlResult); return d->error; } @@ -519,6 +545,7 @@ bool QSqlResult::fetchPrevious() */ bool QSqlResult::isForwardOnly() const { + Q_D(const QSqlResult); return d->forwardOnly; } @@ -540,6 +567,7 @@ bool QSqlResult::isForwardOnly() const */ void QSqlResult::setForwardOnly(bool forward) { + Q_D(QSqlResult); d->forwardOnly = forward; } @@ -554,6 +582,7 @@ void QSqlResult::setForwardOnly(bool forward) */ bool QSqlResult::savePrepare(const QString& query) { + Q_D(QSqlResult); if (!driver()) return false; d->clear(); @@ -565,7 +594,7 @@ bool QSqlResult::savePrepare(const QString& query) d->executedQuery = d->namedToPositionalBinding(query); if (driver()->hasFeature(QSqlDriver::NamedPlaceholders)) - d->executedQuery = QSqlResultPrivate::positionalToNamedBinding(query); + d->executedQuery = d->positionalToNamedBinding(query); return prepare(d->executedQuery); } @@ -579,6 +608,7 @@ bool QSqlResult::savePrepare(const QString& query) */ bool QSqlResult::prepare(const QString& query) { + Q_D(QSqlResult); d->sql = query; if (d->holders.isEmpty()) { // parse the query to memorize parameter location @@ -595,6 +625,7 @@ bool QSqlResult::prepare(const QString& query) */ bool QSqlResult::exec() { + Q_D(QSqlResult); bool ret; // fake preparation - just replace the placeholders.. QString query = lastQuery(); @@ -647,8 +678,9 @@ bool QSqlResult::exec() */ void QSqlResult::bindValue(int index, const QVariant& val, QSql::ParamType paramType) { + Q_D(QSqlResult); d->binds = PositionalBinding; - d->indexes[QSqlResultPrivate::fieldSerial(index)].append(index); + d->indexes[d->fieldSerial(index)].append(index); if (d->values.count() <= index) d->values.resize(index + 1); d->values[index] = val; @@ -675,6 +707,7 @@ void QSqlResult::bindValue(int index, const QVariant& val, QSql::ParamType param void QSqlResult::bindValue(const QString& placeholder, const QVariant& val, QSql::ParamType paramType) { + Q_D(QSqlResult); d->binds = NamedBinding; // if the index has already been set when doing emulated named // bindings - don't reset it @@ -696,6 +729,7 @@ void QSqlResult::bindValue(const QString& placeholder, const QVariant& val, */ void QSqlResult::addBindValue(const QVariant& val, QSql::ParamType paramType) { + Q_D(QSqlResult); d->binds = PositionalBinding; bindValue(d->bindCount, val, paramType); ++d->bindCount; @@ -709,6 +743,7 @@ void QSqlResult::addBindValue(const QVariant& val, QSql::ParamType paramType) */ QVariant QSqlResult::boundValue(int index) const { + Q_D(const QSqlResult); return d->values.value(index); } @@ -722,6 +757,7 @@ QVariant QSqlResult::boundValue(int index) const */ QVariant QSqlResult::boundValue(const QString& placeholder) const { + Q_D(const QSqlResult); QList<int> indexes = d->indexes.value(placeholder); return d->values.value(indexes.value(0,-1)); } @@ -733,6 +769,7 @@ QVariant QSqlResult::boundValue(const QString& placeholder) const */ QSql::ParamType QSqlResult::bindValueType(int index) const { + Q_D(const QSqlResult); return d->types.value(index, QSql::In); } @@ -744,6 +781,7 @@ QSql::ParamType QSqlResult::bindValueType(int index) const */ QSql::ParamType QSqlResult::bindValueType(const QString& placeholder) const { + Q_D(const QSqlResult); return d->types.value(d->indexes.value(placeholder).value(0,-1), QSql::In); } @@ -754,6 +792,7 @@ QSql::ParamType QSqlResult::bindValueType(const QString& placeholder) const */ int QSqlResult::boundValueCount() const { + Q_D(const QSqlResult); return d->values.count(); } @@ -765,7 +804,8 @@ int QSqlResult::boundValueCount() const */ QVector<QVariant>& QSqlResult::boundValues() const { - return d->values; + Q_D(const QSqlResult); + return const_cast<QSqlResultPrivate *>(d)->values; } /*! @@ -773,6 +813,7 @@ QVector<QVariant>& QSqlResult::boundValues() const */ QSqlResult::BindingSyntax QSqlResult::bindingSyntax() const { + Q_D(const QSqlResult); return d->binds; } @@ -782,6 +823,7 @@ QSqlResult::BindingSyntax QSqlResult::bindingSyntax() const */ void QSqlResult::clear() { + Q_D(QSqlResult); d->clear(); } @@ -795,11 +837,13 @@ void QSqlResult::clear() */ QString QSqlResult::executedQuery() const { + Q_D(const QSqlResult); return d->executedQuery; } void QSqlResult::resetBindCount() { + Q_D(QSqlResult); d->resetBindCount(); } @@ -811,6 +855,7 @@ void QSqlResult::resetBindCount() */ QString QSqlResult::boundValueName(int index) const { + Q_D(const QSqlResult); return d->holderAt(index); } @@ -822,6 +867,7 @@ QString QSqlResult::boundValueName(int index) const */ bool QSqlResult::hasOutValues() const { + Q_D(const QSqlResult); if (d->types.isEmpty()) return false; QHash<int, QSql::ParamType>::ConstIterator it; @@ -901,6 +947,7 @@ void QSqlResult::virtual_hook(int, void *) bool QSqlResult::execBatch(bool arrayBind) { Q_UNUSED(arrayBind); + Q_D(QSqlResult); QVector<QVariant> values = d->values; if (values.count() == 0) @@ -924,6 +971,7 @@ void QSqlResult::detachFromResultSet() */ void QSqlResult::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy policy) { + Q_D(QSqlResult); d->precisionPolicy = policy; } @@ -931,6 +979,7 @@ void QSqlResult::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy poli */ QSql::NumericalPrecisionPolicy QSqlResult::numericalPrecisionPolicy() const { + Q_D(const QSqlResult); return d->precisionPolicy; } diff --git a/src/sql/kernel/qsqlresult.h b/src/sql/kernel/qsqlresult.h index 134b96e81d..05f3d7ffec 100644 --- a/src/sql/kernel/qsqlresult.h +++ b/src/sql/kernel/qsqlresult.h @@ -46,8 +46,6 @@ #include <QtCore/qvector.h> #include <QtSql/qsql.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -61,9 +59,9 @@ class QSqlResultPrivate; class Q_SQL_EXPORT QSqlResult { + Q_DECLARE_PRIVATE(QSqlResult) friend class QSqlQuery; friend class QSqlTableModelPrivate; - friend class QSqlResultPrivate; public: virtual ~QSqlResult(); @@ -76,6 +74,7 @@ protected: }; explicit QSqlResult(const QSqlDriver * db); + QSqlResult(QSqlResultPrivate &dd, const QSqlDriver *db); int at() const; QString lastQuery() const; QSqlError lastError() const; @@ -134,8 +133,7 @@ protected: virtual bool nextResult(); void resetBindCount(); // HACK -private: - QSqlResultPrivate* d; + QSqlResultPrivate *d_ptr; private: Q_DISABLE_COPY(QSqlResult) @@ -143,6 +141,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QSQLRESULT_H diff --git a/src/sql/kernel/qsqlresult_p.h b/src/sql/kernel/qsqlresult_p.h index 246b914ec7..7f0459f3a8 100644 --- a/src/sql/kernel/qsqlresult_p.h +++ b/src/sql/kernel/qsqlresult_p.h @@ -70,9 +70,10 @@ struct QHolder { class Q_SQL_EXPORT QSqlResultPrivate { + public: - QSqlResultPrivate(QSqlResult *d) - : q(d), + QSqlResultPrivate() + : q_ptr(0), idx(QSql::BeforeFirstRow), active(false), isSel(false), @@ -81,6 +82,7 @@ public: bindCount(0), binds(QSqlResult::PositionalBinding) { } + virtual ~QSqlResultPrivate() { } void clearValues() { @@ -106,17 +108,12 @@ public: clearIndex();; } - // positionalToNamedBinding uses fieldSerial() by default, which converts to Oracle-style names, - // because this style is used in the API. A driver can reuse positionalToNamedBinding() - // internally for its own naming style by supplying its own fieldSerialFunc. We cannot make - // fieldSerial() virtual because it would allow a driver to impose its naming style on - // executedQuery when set by QSqlResult::savePrepare(). - static QString fieldSerial(int); - static QString positionalToNamedBinding(const QString &query, QString (fieldSerialFunc)(int idx) = fieldSerial); + virtual QString fieldSerial(int) const; + QString positionalToNamedBinding(const QString &query) const; QString namedToPositionalBinding(const QString &query); QString holderAt(int index) const; - QSqlResult *q; + QSqlResult *q_ptr; QPointer<QSqlDriver> sqldriver; int idx; QString sql; |