| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/sql/kernel/qsqlresult.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||||||||
| 6 | ** This file is part of the QtSql module of the Qt Toolkit. | - | ||||||||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||||||||
| 29 | ** | - | ||||||||||||||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
| 31 | ** | - | ||||||||||||||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||||||||||||||
| 33 | - | |||||||||||||||||||||||||
| 34 | #include "qsqlresult.h" | - | ||||||||||||||||||||||||
| 35 | - | |||||||||||||||||||||||||
| 36 | #include "qvariant.h" | - | ||||||||||||||||||||||||
| 37 | #include "qhash.h" | - | ||||||||||||||||||||||||
| 38 | #include "qregexp.h" | - | ||||||||||||||||||||||||
| 39 | #include "qsqlerror.h" | - | ||||||||||||||||||||||||
| 40 | #include "qsqlfield.h" | - | ||||||||||||||||||||||||
| 41 | #include "qsqlrecord.h" | - | ||||||||||||||||||||||||
| 42 | #include "qvector.h" | - | ||||||||||||||||||||||||
| 43 | #include "qsqldriver.h" | - | ||||||||||||||||||||||||
| 44 | #include "qpointer.h" | - | ||||||||||||||||||||||||
| 45 | #include "qsqlresult_p.h" | - | ||||||||||||||||||||||||
| 46 | #include "private/qsqldriver_p.h" | - | ||||||||||||||||||||||||
| 47 | #include <QDebug> | - | ||||||||||||||||||||||||
| 48 | - | |||||||||||||||||||||||||
| 49 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 50 | - | |||||||||||||||||||||||||
| 51 | QString QSqlResultPrivate::holderAt(int index) const | - | ||||||||||||||||||||||||
| 52 | { | - | ||||||||||||||||||||||||
| 53 | return holders.size() > index ? holders.at(index).holderName : fieldSerial(index); executed 154 times by 1 test: return holders.size() > index ? holders.at(index).holderName : fieldSerial(index);Executed by:
| 12-154 | ||||||||||||||||||||||||
| 54 | } | - | ||||||||||||||||||||||||
| 55 | - | |||||||||||||||||||||||||
| 56 | // return a unique id for bound names | - | ||||||||||||||||||||||||
| 57 | QString QSqlResultPrivate::fieldSerial(int i) const | - | ||||||||||||||||||||||||
| 58 | { | - | ||||||||||||||||||||||||
| 59 | ushort arr[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | - | ||||||||||||||||||||||||
| 60 | ushort *end = &arr[(sizeof(arr)/sizeof(*arr))]; | - | ||||||||||||||||||||||||
| 61 | ushort *ptr = end; | - | ||||||||||||||||||||||||
| 62 | - | |||||||||||||||||||||||||
| 63 | while (i > 0) {
| 116858-233612 | ||||||||||||||||||||||||
| 64 | *(--ptr) = 'a' + i % 16; | - | ||||||||||||||||||||||||
| 65 | i >>= 4; | - | ||||||||||||||||||||||||
| 66 | } executed 116858 times by 7 tests: end of blockExecuted by:
| 116858 | ||||||||||||||||||||||||
| 67 | - | |||||||||||||||||||||||||
| 68 | const int nb = end - ptr; | - | ||||||||||||||||||||||||
| 69 | *(--ptr) = 'a' + nb; | - | ||||||||||||||||||||||||
| 70 | *(--ptr) = ':'; | - | ||||||||||||||||||||||||
| 71 | - | |||||||||||||||||||||||||
| 72 | return QString::fromUtf16(ptr, int(end - ptr)); executed 233612 times by 8 tests: return QString::fromUtf16(ptr, int(end - ptr));Executed by:
| 233612 | ||||||||||||||||||||||||
| 73 | } | - | ||||||||||||||||||||||||
| 74 | - | |||||||||||||||||||||||||
| 75 | static bool qIsAlnum(QChar ch) | - | ||||||||||||||||||||||||
| 76 | { | - | ||||||||||||||||||||||||
| 77 | uint u = uint(ch.unicode()); | - | ||||||||||||||||||||||||
| 78 | // matches [a-zA-Z0-9_] | - | ||||||||||||||||||||||||
| 79 | return u - 'a' < 26 || u - 'A' < 26 || u - '0' < 10 || u == '_'; executed 97 times by 3 tests: return u - 'a' < 26 || u - 'A' < 26 || u - '0' < 10 || u == '_';Executed by:
| 0-97 | ||||||||||||||||||||||||
| 80 | } | - | ||||||||||||||||||||||||
| 81 | - | |||||||||||||||||||||||||
| 82 | QString QSqlResultPrivate::positionalToNamedBinding(const QString &query) const | - | ||||||||||||||||||||||||
| 83 | { | - | ||||||||||||||||||||||||
| 84 | int n = query.size(); | - | ||||||||||||||||||||||||
| 85 | - | |||||||||||||||||||||||||
| 86 | QString result; | - | ||||||||||||||||||||||||
| 87 | result.reserve(n * 5 / 4); | - | ||||||||||||||||||||||||
| 88 | QChar closingQuote; | - | ||||||||||||||||||||||||
| 89 | int count = 0; | - | ||||||||||||||||||||||||
| 90 | bool ignoreBraces = (sqldriver->d_func()->dbmsType == QSqlDriver::PostgreSQL); | - | ||||||||||||||||||||||||
| 91 | - | |||||||||||||||||||||||||
| 92 | for (int i = 0; i < n; ++i) {
| 13-253 | ||||||||||||||||||||||||
| 93 | QChar ch = query.at(i); | - | ||||||||||||||||||||||||
| 94 | if (!closingQuote.isNull()) {
| 38-215 | ||||||||||||||||||||||||
| 95 | if (ch == closingQuote) {
| 16-22 | ||||||||||||||||||||||||
| 96 | if (closingQuote == QLatin1Char(']')
| 8 | ||||||||||||||||||||||||
| 97 | && i + 1 < n && query.at(i + 1) == closingQuote) {
| 0-5 | ||||||||||||||||||||||||
| 98 | // consume the extra character. don't close. | - | ||||||||||||||||||||||||
| 99 | ++i; | - | ||||||||||||||||||||||||
| 100 | result += ch; | - | ||||||||||||||||||||||||
| 101 | } else { executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||||||||
| 102 | closingQuote = QChar(); | - | ||||||||||||||||||||||||
| 103 | } executed 13 times by 1 test: end of blockExecuted by:
| 13 | ||||||||||||||||||||||||
| 104 | } | - | ||||||||||||||||||||||||
| 105 | result += ch; | - | ||||||||||||||||||||||||
| 106 | } else { executed 38 times by 1 test: end of blockExecuted by:
| 38 | ||||||||||||||||||||||||
| 107 | if (ch == QLatin1Char('?')) {
| 10-205 | ||||||||||||||||||||||||
| 108 | result += fieldSerial(count++); | - | ||||||||||||||||||||||||
| 109 | } else { executed 10 times by 1 test: end of blockExecuted by:
| 10 | ||||||||||||||||||||||||
| 110 | if (ch == QLatin1Char('\'') || ch == QLatin1Char('"') || ch == QLatin1Char('`'))
| 0-200 | ||||||||||||||||||||||||
| 111 | closingQuote = ch; executed 8 times by 1 test: closingQuote = ch;Executed by:
| 8 | ||||||||||||||||||||||||
| 112 | else if (!ignoreBraces && ch == QLatin1Char('['))
| 0-197 | ||||||||||||||||||||||||
| 113 | closingQuote = QLatin1Char(']'); executed 5 times by 1 test: closingQuote = QLatin1Char(']');Executed by:
| 5 | ||||||||||||||||||||||||
| 114 | result += ch; | - | ||||||||||||||||||||||||
| 115 | } executed 205 times by 1 test: end of blockExecuted by:
| 205 | ||||||||||||||||||||||||
| 116 | } | - | ||||||||||||||||||||||||
| 117 | } | - | ||||||||||||||||||||||||
| 118 | result.squeeze(); | - | ||||||||||||||||||||||||
| 119 | return result; executed 13 times by 1 test: return result;Executed by:
| 13 | ||||||||||||||||||||||||
| 120 | } | - | ||||||||||||||||||||||||
| 121 | - | |||||||||||||||||||||||||
| 122 | QString QSqlResultPrivate::namedToPositionalBinding(const QString &query) | - | ||||||||||||||||||||||||
| 123 | { | - | ||||||||||||||||||||||||
| 124 | int n = query.size(); | - | ||||||||||||||||||||||||
| 125 | - | |||||||||||||||||||||||||
| 126 | QString result; | - | ||||||||||||||||||||||||
| 127 | result.reserve(n); | - | ||||||||||||||||||||||||
| 128 | QChar closingQuote; | - | ||||||||||||||||||||||||
| 129 | int count = 0; | - | ||||||||||||||||||||||||
| 130 | int i = 0; | - | ||||||||||||||||||||||||
| 131 | bool ignoreBraces = (sqldriver->d_func()->dbmsType == QSqlDriver::PostgreSQL); | - | ||||||||||||||||||||||||
| 132 | - | |||||||||||||||||||||||||
| 133 | while (i < n) {
| 255-16078 | ||||||||||||||||||||||||
| 134 | QChar ch = query.at(i); | - | ||||||||||||||||||||||||
| 135 | if (!closingQuote.isNull()) {
| 3386-12692 | ||||||||||||||||||||||||
| 136 | if (ch == closingQuote) {
| 342-3044 | ||||||||||||||||||||||||
| 137 | if (closingQuote == QLatin1Char(']')
| 10-332 | ||||||||||||||||||||||||
| 138 | && i + 1 < n && query.at(i + 1) == closingQuote) {
| 0-7 | ||||||||||||||||||||||||
| 139 | // consume the extra character. don't close. | - | ||||||||||||||||||||||||
| 140 | ++i; | - | ||||||||||||||||||||||||
| 141 | result += ch; | - | ||||||||||||||||||||||||
| 142 | } else { executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||||||||
| 143 | closingQuote = QChar(); | - | ||||||||||||||||||||||||
| 144 | } executed 339 times by 4 tests: end of blockExecuted by:
| 339 | ||||||||||||||||||||||||
| 145 | } | - | ||||||||||||||||||||||||
| 146 | result += ch; | - | ||||||||||||||||||||||||
| 147 | ++i; | - | ||||||||||||||||||||||||
| 148 | } else { executed 3386 times by 4 tests: end of blockExecuted by:
| 3386 | ||||||||||||||||||||||||
| 149 | if (ch == QLatin1Char(':')
| 32-12660 | ||||||||||||||||||||||||
| 150 | && (i == 0 || query.at(i - 1) != QLatin1Char(':'))
| 0-32 | ||||||||||||||||||||||||
| 151 | && (i + 1 < n && qIsAlnum(query.at(i + 1)))) {
| 0-32 | ||||||||||||||||||||||||
| 152 | int pos = i + 2; | - | ||||||||||||||||||||||||
| 153 | while (pos < n && qIsAlnum(query.at(pos)))
| 4-65 | ||||||||||||||||||||||||
| 154 | ++pos; executed 37 times by 3 tests: ++pos;Executed by:
| 37 | ||||||||||||||||||||||||
| 155 | QString holder(query.mid(i, pos - i)); | - | ||||||||||||||||||||||||
| 156 | indexes[holder].append(count++); | - | ||||||||||||||||||||||||
| 157 | holders.append(QHolder(holder, i)); | - | ||||||||||||||||||||||||
| 158 | result += QLatin1Char('?'); | - | ||||||||||||||||||||||||
| 159 | i = pos; | - | ||||||||||||||||||||||||
| 160 | } else { executed 32 times by 3 tests: end of blockExecuted by:
| 32 | ||||||||||||||||||||||||
| 161 | if (ch == QLatin1Char('\'') || ch == QLatin1Char('"') || ch == QLatin1Char('`'))
| 0-12648 | ||||||||||||||||||||||||
| 162 | closingQuote = ch; executed 333 times by 4 tests: closingQuote = ch;Executed by:
| 333 | ||||||||||||||||||||||||
| 163 | else if (!ignoreBraces && ch == QLatin1Char('['))
| 0-12327 | ||||||||||||||||||||||||
| 164 | closingQuote = QLatin1Char(']'); executed 7 times by 1 test: closingQuote = QLatin1Char(']');Executed by:
| 7 | ||||||||||||||||||||||||
| 165 | result += ch; | - | ||||||||||||||||||||||||
| 166 | ++i; | - | ||||||||||||||||||||||||
| 167 | } executed 12660 times by 8 tests: end of blockExecuted by:
| 12660 | ||||||||||||||||||||||||
| 168 | } | - | ||||||||||||||||||||||||
| 169 | } | - | ||||||||||||||||||||||||
| 170 | result.squeeze(); | - | ||||||||||||||||||||||||
| 171 | values.resize(holders.size()); | - | ||||||||||||||||||||||||
| 172 | return result; executed 255 times by 8 tests: return result;Executed by:
| 255 | ||||||||||||||||||||||||
| 173 | } | - | ||||||||||||||||||||||||
| 174 | - | |||||||||||||||||||||||||
| 175 | /*! | - | ||||||||||||||||||||||||
| 176 | \class QSqlResult | - | ||||||||||||||||||||||||
| 177 | \brief The QSqlResult class provides an abstract interface for | - | ||||||||||||||||||||||||
| 178 | accessing data from specific SQL databases. | - | ||||||||||||||||||||||||
| 179 | - | |||||||||||||||||||||||||
| 180 | \ingroup database | - | ||||||||||||||||||||||||
| 181 | \inmodule QtSql | - | ||||||||||||||||||||||||
| 182 | - | |||||||||||||||||||||||||
| 183 | Normally, you would use QSqlQuery instead of QSqlResult, since | - | ||||||||||||||||||||||||
| 184 | QSqlQuery provides a generic wrapper for database-specific | - | ||||||||||||||||||||||||
| 185 | implementations of QSqlResult. | - | ||||||||||||||||||||||||
| 186 | - | |||||||||||||||||||||||||
| 187 | If you are implementing your own SQL driver (by subclassing | - | ||||||||||||||||||||||||
| 188 | QSqlDriver), you will need to provide your own QSqlResult | - | ||||||||||||||||||||||||
| 189 | subclass that implements all the pure virtual functions and other | - | ||||||||||||||||||||||||
| 190 | virtual functions that you need. | - | ||||||||||||||||||||||||
| 191 | - | |||||||||||||||||||||||||
| 192 | \sa QSqlDriver | - | ||||||||||||||||||||||||
| 193 | */ | - | ||||||||||||||||||||||||
| 194 | - | |||||||||||||||||||||||||
| 195 | /*! | - | ||||||||||||||||||||||||
| 196 | \enum QSqlResult::BindingSyntax | - | ||||||||||||||||||||||||
| 197 | - | |||||||||||||||||||||||||
| 198 | This enum type specifies the different syntaxes for specifying | - | ||||||||||||||||||||||||
| 199 | placeholders in prepared queries. | - | ||||||||||||||||||||||||
| 200 | - | |||||||||||||||||||||||||
| 201 | \value PositionalBinding Use the ODBC-style positional syntax, with "?" as placeholders. | - | ||||||||||||||||||||||||
| 202 | \value NamedBinding Use the Oracle-style syntax with named placeholders (e.g., ":id") | - | ||||||||||||||||||||||||
| 203 | - | |||||||||||||||||||||||||
| 204 | \sa bindingSyntax() | - | ||||||||||||||||||||||||
| 205 | */ | - | ||||||||||||||||||||||||
| 206 | - | |||||||||||||||||||||||||
| 207 | /*! | - | ||||||||||||||||||||||||
| 208 | \enum QSqlResult::VirtualHookOperation | - | ||||||||||||||||||||||||
| 209 | \internal | - | ||||||||||||||||||||||||
| 210 | */ | - | ||||||||||||||||||||||||
| 211 | - | |||||||||||||||||||||||||
| 212 | /*! | - | ||||||||||||||||||||||||
| 213 | Creates a QSqlResult using database driver \a db. The object is | - | ||||||||||||||||||||||||
| 214 | initialized to an inactive state. | - | ||||||||||||||||||||||||
| 215 | - | |||||||||||||||||||||||||
| 216 | \sa isActive(), driver() | - | ||||||||||||||||||||||||
| 217 | */ | - | ||||||||||||||||||||||||
| 218 | - | |||||||||||||||||||||||||
| 219 | QSqlResult::QSqlResult(const QSqlDriver *db) | - | ||||||||||||||||||||||||
| 220 | { | - | ||||||||||||||||||||||||
| 221 | d_ptr = new QSqlResultPrivate; | - | ||||||||||||||||||||||||
| 222 | Q_D(QSqlResult); | - | ||||||||||||||||||||||||
| 223 | d->q_ptr = this; | - | ||||||||||||||||||||||||
| 224 | d->sqldriver = const_cast<QSqlDriver *>(db); | - | ||||||||||||||||||||||||
| 225 | if (d->sqldriver)
| 0-2195 | ||||||||||||||||||||||||
| 226 | setNumericalPrecisionPolicy(d->sqldriver->numericalPrecisionPolicy()); executed 2195 times by 10 tests: setNumericalPrecisionPolicy(d->sqldriver->numericalPrecisionPolicy());Executed by:
| 2195 | ||||||||||||||||||||||||
| 227 | } executed 2195 times by 10 tests: end of blockExecuted by:
| 2195 | ||||||||||||||||||||||||
| 228 | - | |||||||||||||||||||||||||
| 229 | /*! \internal | - | ||||||||||||||||||||||||
| 230 | */ | - | ||||||||||||||||||||||||
| 231 | QSqlResult::QSqlResult(QSqlResultPrivate &dd, const QSqlDriver *db) | - | ||||||||||||||||||||||||
| 232 | { | - | ||||||||||||||||||||||||
| 233 | d_ptr = ⅆ | - | ||||||||||||||||||||||||
| 234 | Q_D(QSqlResult); | - | ||||||||||||||||||||||||
| 235 | d->q_ptr = this; | - | ||||||||||||||||||||||||
| 236 | d->sqldriver = const_cast<QSqlDriver *>(db); | - | ||||||||||||||||||||||||
| 237 | if (d->sqldriver)
| 0 | ||||||||||||||||||||||||
| 238 | setNumericalPrecisionPolicy(d->sqldriver->numericalPrecisionPolicy()); never executed: setNumericalPrecisionPolicy(d->sqldriver->numericalPrecisionPolicy()); | 0 | ||||||||||||||||||||||||
| 239 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 240 | - | |||||||||||||||||||||||||
| 241 | /*! | - | ||||||||||||||||||||||||
| 242 | Destroys the object and frees any allocated resources. | - | ||||||||||||||||||||||||
| 243 | */ | - | ||||||||||||||||||||||||
| 244 | - | |||||||||||||||||||||||||
| 245 | QSqlResult::~QSqlResult() | - | ||||||||||||||||||||||||
| 246 | { | - | ||||||||||||||||||||||||
| 247 | Q_D(QSqlResult); | - | ||||||||||||||||||||||||
| 248 | delete d; | - | ||||||||||||||||||||||||
| 249 | } executed 2195 times by 19 tests: end of blockExecuted by:
| 2195 | ||||||||||||||||||||||||
| 250 | - | |||||||||||||||||||||||||
| 251 | /*! | - | ||||||||||||||||||||||||
| 252 | Sets the current query for the result to \a query. You must call | - | ||||||||||||||||||||||||
| 253 | reset() to execute the query on the database. | - | ||||||||||||||||||||||||
| 254 | - | |||||||||||||||||||||||||
| 255 | \sa reset(), lastQuery() | - | ||||||||||||||||||||||||
| 256 | */ | - | ||||||||||||||||||||||||
| 257 | - | |||||||||||||||||||||||||
| 258 | void QSqlResult::setQuery(const QString& query) | - | ||||||||||||||||||||||||
| 259 | { | - | ||||||||||||||||||||||||
| 260 | Q_D(QSqlResult); | - | ||||||||||||||||||||||||
| 261 | d->sql = query; | - | ||||||||||||||||||||||||
| 262 | } executed 2557 times by 9 tests: end of blockExecuted by:
| 2557 | ||||||||||||||||||||||||
| 263 | - | |||||||||||||||||||||||||
| 264 | /*! | - | ||||||||||||||||||||||||
| 265 | Returns the current SQL query text, or an empty string if there | - | ||||||||||||||||||||||||
| 266 | isn't one. | - | ||||||||||||||||||||||||
| 267 | - | |||||||||||||||||||||||||
| 268 | \sa setQuery() | - | ||||||||||||||||||||||||
| 269 | */ | - | ||||||||||||||||||||||||
| 270 | - | |||||||||||||||||||||||||
| 271 | QString QSqlResult::lastQuery() const | - | ||||||||||||||||||||||||
| 272 | { | - | ||||||||||||||||||||||||
| 273 | Q_D(const QSqlResult); | - | ||||||||||||||||||||||||
| 274 | return d->sql; executed 124 times by 3 tests: return d->sql;Executed by:
| 124 | ||||||||||||||||||||||||
| 275 | } | - | ||||||||||||||||||||||||
| 276 | - | |||||||||||||||||||||||||
| 277 | /*! | - | ||||||||||||||||||||||||
| 278 | Returns the current (zero-based) row position of the result. May | - | ||||||||||||||||||||||||
| 279 | return the special values QSql::BeforeFirstRow or | - | ||||||||||||||||||||||||
| 280 | QSql::AfterLastRow. | - | ||||||||||||||||||||||||
| 281 | - | |||||||||||||||||||||||||
| 282 | \sa setAt(), isValid() | - | ||||||||||||||||||||||||
| 283 | */ | - | ||||||||||||||||||||||||
| 284 | int QSqlResult::at() const | - | ||||||||||||||||||||||||
| 285 | { | - | ||||||||||||||||||||||||
| 286 | Q_D(const QSqlResult); | - | ||||||||||||||||||||||||
| 287 | return d->idx; executed 102997 times by 9 tests: return d->idx;Executed by:
| 102997 | ||||||||||||||||||||||||
| 288 | } | - | ||||||||||||||||||||||||
| 289 | - | |||||||||||||||||||||||||
| 290 | - | |||||||||||||||||||||||||
| 291 | /*! | - | ||||||||||||||||||||||||
| 292 | Returns \c true if the result is positioned on a valid record (that | - | ||||||||||||||||||||||||
| 293 | is, the result is not positioned before the first or after the | - | ||||||||||||||||||||||||
| 294 | last record); otherwise returns \c false. | - | ||||||||||||||||||||||||
| 295 | - | |||||||||||||||||||||||||
| 296 | \sa at() | - | ||||||||||||||||||||||||
| 297 | */ | - | ||||||||||||||||||||||||
| 298 | - | |||||||||||||||||||||||||
| 299 | bool QSqlResult::isValid() const | - | ||||||||||||||||||||||||
| 300 | { | - | ||||||||||||||||||||||||
| 301 | Q_D(const QSqlResult); | - | ||||||||||||||||||||||||
| 302 | return d->idx != QSql::BeforeFirstRow && d->idx != QSql::AfterLastRow; executed 9659 times by 8 tests: return d->idx != QSql::BeforeFirstRow && d->idx != QSql::AfterLastRow;Executed by:
| 21-9659 | ||||||||||||||||||||||||
| 303 | } | - | ||||||||||||||||||||||||
| 304 | - | |||||||||||||||||||||||||
| 305 | /*! | - | ||||||||||||||||||||||||
| 306 | \fn bool QSqlResult::isNull(int index) | - | ||||||||||||||||||||||||
| 307 | - | |||||||||||||||||||||||||
| 308 | Returns \c true if the field at position \a index in the current row | - | ||||||||||||||||||||||||
| 309 | is null; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 310 | */ | - | ||||||||||||||||||||||||
| 311 | - | |||||||||||||||||||||||||
| 312 | /*! | - | ||||||||||||||||||||||||
| 313 | Returns \c true if the result has records to be retrieved; otherwise | - | ||||||||||||||||||||||||
| 314 | returns \c false. | - | ||||||||||||||||||||||||
| 315 | */ | - | ||||||||||||||||||||||||
| 316 | - | |||||||||||||||||||||||||
| 317 | bool QSqlResult::isActive() const | - | ||||||||||||||||||||||||
| 318 | { | - | ||||||||||||||||||||||||
| 319 | Q_D(const QSqlResult); | - | ||||||||||||||||||||||||
| 320 | return d->active; executed 20171 times by 9 tests: return d->active;Executed by:
| 20171 | ||||||||||||||||||||||||
| 321 | } | - | ||||||||||||||||||||||||
| 322 | - | |||||||||||||||||||||||||
| 323 | /*! | - | ||||||||||||||||||||||||
| 324 | This function is provided for derived classes to set the | - | ||||||||||||||||||||||||
| 325 | internal (zero-based) row position to \a index. | - | ||||||||||||||||||||||||
| 326 | - | |||||||||||||||||||||||||
| 327 | \sa at() | - | ||||||||||||||||||||||||
| 328 | */ | - | ||||||||||||||||||||||||
| 329 | - | |||||||||||||||||||||||||
| 330 | void QSqlResult::setAt(int index) | - | ||||||||||||||||||||||||
| 331 | { | - | ||||||||||||||||||||||||
| 332 | Q_D(QSqlResult); | - | ||||||||||||||||||||||||
| 333 | d->idx = index; | - | ||||||||||||||||||||||||
| 334 | } executed 292539 times by 9 tests: end of blockExecuted by:
| 292539 | ||||||||||||||||||||||||
| 335 | - | |||||||||||||||||||||||||
| 336 | - | |||||||||||||||||||||||||
| 337 | /*! | - | ||||||||||||||||||||||||
| 338 | This function is provided for derived classes to indicate whether | - | ||||||||||||||||||||||||
| 339 | or not the current statement is a SQL \c SELECT statement. The \a | - | ||||||||||||||||||||||||
| 340 | select parameter should be true if the statement is a \c SELECT | - | ||||||||||||||||||||||||
| 341 | statement; otherwise it should be false. | - | ||||||||||||||||||||||||
| 342 | - | |||||||||||||||||||||||||
| 343 | \sa isSelect() | - | ||||||||||||||||||||||||
| 344 | */ | - | ||||||||||||||||||||||||
| 345 | - | |||||||||||||||||||||||||
| 346 | void QSqlResult::setSelect(bool select) | - | ||||||||||||||||||||||||
| 347 | { | - | ||||||||||||||||||||||||
| 348 | Q_D(QSqlResult); | - | ||||||||||||||||||||||||
| 349 | d->isSel = select; | - | ||||||||||||||||||||||||
| 350 | } executed 121905 times by 9 tests: end of blockExecuted by:
| 121905 | ||||||||||||||||||||||||
| 351 | - | |||||||||||||||||||||||||
| 352 | /*! | - | ||||||||||||||||||||||||
| 353 | Returns \c true if the current result is from a \c SELECT statement; | - | ||||||||||||||||||||||||
| 354 | otherwise returns \c false. | - | ||||||||||||||||||||||||
| 355 | - | |||||||||||||||||||||||||
| 356 | \sa setSelect() | - | ||||||||||||||||||||||||
| 357 | */ | - | ||||||||||||||||||||||||
| 358 | - | |||||||||||||||||||||||||
| 359 | bool QSqlResult::isSelect() const | - | ||||||||||||||||||||||||
| 360 | { | - | ||||||||||||||||||||||||
| 361 | Q_D(const QSqlResult); | - | ||||||||||||||||||||||||
| 362 | return d->isSel; executed 7591 times by 9 tests: return d->isSel;Executed by:
| 7591 | ||||||||||||||||||||||||
| 363 | } | - | ||||||||||||||||||||||||
| 364 | - | |||||||||||||||||||||||||
| 365 | /*! | - | ||||||||||||||||||||||||
| 366 | Returns the driver associated with the result. This is the object | - | ||||||||||||||||||||||||
| 367 | that was passed to the constructor. | - | ||||||||||||||||||||||||
| 368 | */ | - | ||||||||||||||||||||||||
| 369 | - | |||||||||||||||||||||||||
| 370 | const QSqlDriver *QSqlResult::driver() const | - | ||||||||||||||||||||||||
| 371 | { | - | ||||||||||||||||||||||||
| 372 | Q_D(const QSqlResult); | - | ||||||||||||||||||||||||
| 373 | return d->sqldriver; executed 17773 times by 10 tests: return d->sqldriver;Executed by:
| 17773 | ||||||||||||||||||||||||
| 374 | } | - | ||||||||||||||||||||||||
| 375 | - | |||||||||||||||||||||||||
| 376 | - | |||||||||||||||||||||||||
| 377 | /*! | - | ||||||||||||||||||||||||
| 378 | This function is provided for derived classes to set the internal | - | ||||||||||||||||||||||||
| 379 | active state to \a active. | - | ||||||||||||||||||||||||
| 380 | - | |||||||||||||||||||||||||
| 381 | \sa isActive() | - | ||||||||||||||||||||||||
| 382 | */ | - | ||||||||||||||||||||||||
| 383 | - | |||||||||||||||||||||||||
| 384 | void QSqlResult::setActive(bool active) | - | ||||||||||||||||||||||||
| 385 | { | - | ||||||||||||||||||||||||
| 386 | Q_D(QSqlResult); | - | ||||||||||||||||||||||||
| 387 | if (active && d->executedQuery.isEmpty())
| 1238-107307 | ||||||||||||||||||||||||
| 388 | d->executedQuery = d->sql; executed 1238 times by 9 tests: d->executedQuery = d->sql;Executed by:
| 1238 | ||||||||||||||||||||||||
| 389 | - | |||||||||||||||||||||||||
| 390 | d->active = active; | - | ||||||||||||||||||||||||
| 391 | } executed 134146 times by 9 tests: end of blockExecuted by:
| 134146 | ||||||||||||||||||||||||
| 392 | - | |||||||||||||||||||||||||
| 393 | /*! | - | ||||||||||||||||||||||||
| 394 | This function is provided for derived classes to set the last | - | ||||||||||||||||||||||||
| 395 | error to \a error. | - | ||||||||||||||||||||||||
| 396 | - | |||||||||||||||||||||||||
| 397 | \sa lastError() | - | ||||||||||||||||||||||||
| 398 | */ | - | ||||||||||||||||||||||||
| 399 | - | |||||||||||||||||||||||||
| 400 | void QSqlResult::setLastError(const QSqlError &error) | - | ||||||||||||||||||||||||
| 401 | { | - | ||||||||||||||||||||||||
| 402 | Q_D(QSqlResult); | - | ||||||||||||||||||||||||
| 403 | d->error = error; | - | ||||||||||||||||||||||||
| 404 | } executed 306692 times by 9 tests: end of blockExecuted by:
| 306692 | ||||||||||||||||||||||||
| 405 | - | |||||||||||||||||||||||||
| 406 | - | |||||||||||||||||||||||||
| 407 | /*! | - | ||||||||||||||||||||||||
| 408 | Returns the last error associated with the result. | - | ||||||||||||||||||||||||
| 409 | */ | - | ||||||||||||||||||||||||
| 410 | - | |||||||||||||||||||||||||
| 411 | QSqlError QSqlResult::lastError() const | - | ||||||||||||||||||||||||
| 412 | { | - | ||||||||||||||||||||||||
| 413 | Q_D(const QSqlResult); | - | ||||||||||||||||||||||||
| 414 | return d->error; executed 246941 times by 9 tests: return d->error;Executed by:
| 246941 | ||||||||||||||||||||||||
| 415 | } | - | ||||||||||||||||||||||||
| 416 | - | |||||||||||||||||||||||||
| 417 | /*! | - | ||||||||||||||||||||||||
| 418 | \fn int QSqlResult::size() | - | ||||||||||||||||||||||||
| 419 | - | |||||||||||||||||||||||||
| 420 | Returns the size of the \c SELECT result, or -1 if it cannot be | - | ||||||||||||||||||||||||
| 421 | determined or if the query is not a \c SELECT statement. | - | ||||||||||||||||||||||||
| 422 | - | |||||||||||||||||||||||||
| 423 | \sa numRowsAffected() | - | ||||||||||||||||||||||||
| 424 | */ | - | ||||||||||||||||||||||||
| 425 | - | |||||||||||||||||||||||||
| 426 | /*! | - | ||||||||||||||||||||||||
| 427 | \fn int QSqlResult::numRowsAffected() | - | ||||||||||||||||||||||||
| 428 | - | |||||||||||||||||||||||||
| 429 | Returns the number of rows affected by the last query executed, or | - | ||||||||||||||||||||||||
| 430 | -1 if it cannot be determined or if the query is a \c SELECT | - | ||||||||||||||||||||||||
| 431 | statement. | - | ||||||||||||||||||||||||
| 432 | - | |||||||||||||||||||||||||
| 433 | \sa size() | - | ||||||||||||||||||||||||
| 434 | */ | - | ||||||||||||||||||||||||
| 435 | - | |||||||||||||||||||||||||
| 436 | /*! | - | ||||||||||||||||||||||||
| 437 | \fn QVariant QSqlResult::data(int index) | - | ||||||||||||||||||||||||
| 438 | - | |||||||||||||||||||||||||
| 439 | Returns the data for field \a index in the current row as | - | ||||||||||||||||||||||||
| 440 | a QVariant. This function is only called if the result is in | - | ||||||||||||||||||||||||
| 441 | an active state and is positioned on a valid record and \a index is | - | ||||||||||||||||||||||||
| 442 | non-negative. Derived classes must reimplement this function and | - | ||||||||||||||||||||||||
| 443 | return the value of field \a index, or QVariant() if it cannot be | - | ||||||||||||||||||||||||
| 444 | determined. | - | ||||||||||||||||||||||||
| 445 | */ | - | ||||||||||||||||||||||||
| 446 | - | |||||||||||||||||||||||||
| 447 | /*! | - | ||||||||||||||||||||||||
| 448 | \fn bool QSqlResult::reset(const QString &query) | - | ||||||||||||||||||||||||
| 449 | - | |||||||||||||||||||||||||
| 450 | Sets the result to use the SQL statement \a query for subsequent | - | ||||||||||||||||||||||||
| 451 | data retrieval. | - | ||||||||||||||||||||||||
| 452 | - | |||||||||||||||||||||||||
| 453 | Derived classes must reimplement this function and apply the \a | - | ||||||||||||||||||||||||
| 454 | query to the database. This function is only called after the | - | ||||||||||||||||||||||||
| 455 | result is set to an inactive state and is positioned before the | - | ||||||||||||||||||||||||
| 456 | first record of the new result. Derived classes should return | - | ||||||||||||||||||||||||
| 457 | true if the query was successful and ready to be used, or false | - | ||||||||||||||||||||||||
| 458 | otherwise. | - | ||||||||||||||||||||||||
| 459 | - | |||||||||||||||||||||||||
| 460 | \sa setQuery() | - | ||||||||||||||||||||||||
| 461 | */ | - | ||||||||||||||||||||||||
| 462 | - | |||||||||||||||||||||||||
| 463 | /*! | - | ||||||||||||||||||||||||
| 464 | \fn bool QSqlResult::fetch(int index) | - | ||||||||||||||||||||||||
| 465 | - | |||||||||||||||||||||||||
| 466 | Positions the result to an arbitrary (zero-based) row \a index. | - | ||||||||||||||||||||||||
| 467 | - | |||||||||||||||||||||||||
| 468 | This function is only called if the result is in an active state. | - | ||||||||||||||||||||||||
| 469 | Derived classes must reimplement this function and position the | - | ||||||||||||||||||||||||
| 470 | result to the row \a index, and call setAt() with an appropriate | - | ||||||||||||||||||||||||
| 471 | value. Return true to indicate success, or false to signify | - | ||||||||||||||||||||||||
| 472 | failure. | - | ||||||||||||||||||||||||
| 473 | - | |||||||||||||||||||||||||
| 474 | \sa isActive(), fetchFirst(), fetchLast(), fetchNext(), fetchPrevious() | - | ||||||||||||||||||||||||
| 475 | */ | - | ||||||||||||||||||||||||
| 476 | - | |||||||||||||||||||||||||
| 477 | /*! | - | ||||||||||||||||||||||||
| 478 | \fn bool QSqlResult::fetchFirst() | - | ||||||||||||||||||||||||
| 479 | - | |||||||||||||||||||||||||
| 480 | Positions the result to the first record (row 0) in the result. | - | ||||||||||||||||||||||||
| 481 | - | |||||||||||||||||||||||||
| 482 | This function is only called if the result is in an active state. | - | ||||||||||||||||||||||||
| 483 | Derived classes must reimplement this function and position the | - | ||||||||||||||||||||||||
| 484 | result to the first record, and call setAt() with an appropriate | - | ||||||||||||||||||||||||
| 485 | value. Return true to indicate success, or false to signify | - | ||||||||||||||||||||||||
| 486 | failure. | - | ||||||||||||||||||||||||
| 487 | - | |||||||||||||||||||||||||
| 488 | \sa fetch(), fetchLast() | - | ||||||||||||||||||||||||
| 489 | */ | - | ||||||||||||||||||||||||
| 490 | - | |||||||||||||||||||||||||
| 491 | /*! | - | ||||||||||||||||||||||||
| 492 | \fn bool QSqlResult::fetchLast() | - | ||||||||||||||||||||||||
| 493 | - | |||||||||||||||||||||||||
| 494 | Positions the result to the last record (last row) in the result. | - | ||||||||||||||||||||||||
| 495 | - | |||||||||||||||||||||||||
| 496 | This function is only called if the result is in an active state. | - | ||||||||||||||||||||||||
| 497 | Derived classes must reimplement this function and position the | - | ||||||||||||||||||||||||
| 498 | result to the last record, and call setAt() with an appropriate | - | ||||||||||||||||||||||||
| 499 | value. Return true to indicate success, or false to signify | - | ||||||||||||||||||||||||
| 500 | failure. | - | ||||||||||||||||||||||||
| 501 | - | |||||||||||||||||||||||||
| 502 | \sa fetch(), fetchFirst() | - | ||||||||||||||||||||||||
| 503 | */ | - | ||||||||||||||||||||||||
| 504 | - | |||||||||||||||||||||||||
| 505 | /*! | - | ||||||||||||||||||||||||
| 506 | Positions the result to the next available record (row) in the | - | ||||||||||||||||||||||||
| 507 | result. | - | ||||||||||||||||||||||||
| 508 | - | |||||||||||||||||||||||||
| 509 | This function is only called if the result is in an active | - | ||||||||||||||||||||||||
| 510 | state. The default implementation calls fetch() with the next | - | ||||||||||||||||||||||||
| 511 | index. Derived classes can reimplement this function and position | - | ||||||||||||||||||||||||
| 512 | the result to the next record in some other way, and call setAt() | - | ||||||||||||||||||||||||
| 513 | with an appropriate value. Return true to indicate success, or | - | ||||||||||||||||||||||||
| 514 | false to signify failure. | - | ||||||||||||||||||||||||
| 515 | - | |||||||||||||||||||||||||
| 516 | \sa fetch(), fetchPrevious() | - | ||||||||||||||||||||||||
| 517 | */ | - | ||||||||||||||||||||||||
| 518 | - | |||||||||||||||||||||||||
| 519 | bool QSqlResult::fetchNext() | - | ||||||||||||||||||||||||
| 520 | { | - | ||||||||||||||||||||||||
| 521 | return fetch(at() + 1); never executed: return fetch(at() + 1); | 0 | ||||||||||||||||||||||||
| 522 | } | - | ||||||||||||||||||||||||
| 523 | - | |||||||||||||||||||||||||
| 524 | /*! | - | ||||||||||||||||||||||||
| 525 | Positions the result to the previous record (row) in the result. | - | ||||||||||||||||||||||||
| 526 | - | |||||||||||||||||||||||||
| 527 | This function is only called if the result is in an active state. | - | ||||||||||||||||||||||||
| 528 | The default implementation calls fetch() with the previous index. | - | ||||||||||||||||||||||||
| 529 | Derived classes can reimplement this function and position the | - | ||||||||||||||||||||||||
| 530 | result to the next record in some other way, and call setAt() | - | ||||||||||||||||||||||||
| 531 | with an appropriate value. Return true to indicate success, or | - | ||||||||||||||||||||||||
| 532 | false to signify failure. | - | ||||||||||||||||||||||||
| 533 | */ | - | ||||||||||||||||||||||||
| 534 | - | |||||||||||||||||||||||||
| 535 | bool QSqlResult::fetchPrevious() | - | ||||||||||||||||||||||||
| 536 | { | - | ||||||||||||||||||||||||
| 537 | return fetch(at() - 1); never executed: return fetch(at() - 1); | 0 | ||||||||||||||||||||||||
| 538 | } | - | ||||||||||||||||||||||||
| 539 | - | |||||||||||||||||||||||||
| 540 | /*! | - | ||||||||||||||||||||||||
| 541 | Returns \c true if you can only scroll forward through the result | - | ||||||||||||||||||||||||
| 542 | set; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 543 | - | |||||||||||||||||||||||||
| 544 | \sa setForwardOnly() | - | ||||||||||||||||||||||||
| 545 | */ | - | ||||||||||||||||||||||||
| 546 | bool QSqlResult::isForwardOnly() const | - | ||||||||||||||||||||||||
| 547 | { | - | ||||||||||||||||||||||||
| 548 | Q_D(const QSqlResult); | - | ||||||||||||||||||||||||
| 549 | return d->forwardOnly; executed 42254 times by 9 tests: return d->forwardOnly;Executed by:
| 42254 | ||||||||||||||||||||||||
| 550 | } | - | ||||||||||||||||||||||||
| 551 | - | |||||||||||||||||||||||||
| 552 | /*! | - | ||||||||||||||||||||||||
| 553 | Sets forward only mode to \a forward. If \a forward is true, only | - | ||||||||||||||||||||||||
| 554 | fetchNext() is allowed for navigating the results. Forward only | - | ||||||||||||||||||||||||
| 555 | mode needs much less memory since results do not have to be | - | ||||||||||||||||||||||||
| 556 | cached. By default, this feature is disabled. | - | ||||||||||||||||||||||||
| 557 | - | |||||||||||||||||||||||||
| 558 | Setting forward only to false is a suggestion to the database engine, | - | ||||||||||||||||||||||||
| 559 | which has the final say on whether a result set is forward only or | - | ||||||||||||||||||||||||
| 560 | scrollable. isForwardOnly() will always return the correct status of | - | ||||||||||||||||||||||||
| 561 | the result set. | - | ||||||||||||||||||||||||
| 562 | - | |||||||||||||||||||||||||
| 563 | \note Calling setForwardOnly after execution of the query will result | - | ||||||||||||||||||||||||
| 564 | in unexpected results at best, and crashes at worst. | - | ||||||||||||||||||||||||
| 565 | - | |||||||||||||||||||||||||
| 566 | \sa isForwardOnly(), fetchNext(), QSqlQuery::setForwardOnly() | - | ||||||||||||||||||||||||
| 567 | */ | - | ||||||||||||||||||||||||
| 568 | void QSqlResult::setForwardOnly(bool forward) | - | ||||||||||||||||||||||||
| 569 | { | - | ||||||||||||||||||||||||
| 570 | Q_D(QSqlResult); | - | ||||||||||||||||||||||||
| 571 | d->forwardOnly = forward; | - | ||||||||||||||||||||||||
| 572 | } executed 645 times by 9 tests: end of blockExecuted by:
| 645 | ||||||||||||||||||||||||
| 573 | - | |||||||||||||||||||||||||
| 574 | /*! | - | ||||||||||||||||||||||||
| 575 | Prepares the given \a query, using the underlying database | - | ||||||||||||||||||||||||
| 576 | functionality where possible. Returns \c true if the query is | - | ||||||||||||||||||||||||
| 577 | prepared successfully; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 578 | - | |||||||||||||||||||||||||
| 579 | Note: This method should have been called "safePrepare()". | - | ||||||||||||||||||||||||
| 580 | - | |||||||||||||||||||||||||
| 581 | \sa prepare() | - | ||||||||||||||||||||||||
| 582 | */ | - | ||||||||||||||||||||||||
| 583 | bool QSqlResult::savePrepare(const QString& query) | - | ||||||||||||||||||||||||
| 584 | { | - | ||||||||||||||||||||||||
| 585 | Q_D(QSqlResult); | - | ||||||||||||||||||||||||
| 586 | if (!driver())
| 0-247 | ||||||||||||||||||||||||
| 587 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 588 | d->clear(); | - | ||||||||||||||||||||||||
| 589 | d->sql = query; | - | ||||||||||||||||||||||||
| 590 | if (!driver()->hasFeature(QSqlDriver::PreparedQueries))
| 0-247 | ||||||||||||||||||||||||
| 591 | return prepare(query); never executed: return prepare(query); | 0 | ||||||||||||||||||||||||
| 592 | - | |||||||||||||||||||||||||
| 593 | // parse the query to memorize parameter location | - | ||||||||||||||||||||||||
| 594 | d->executedQuery = d->namedToPositionalBinding(query); | - | ||||||||||||||||||||||||
| 595 | - | |||||||||||||||||||||||||
| 596 | if (driver()->hasFeature(QSqlDriver::NamedPlaceholders))
| 13-234 | ||||||||||||||||||||||||
| 597 | d->executedQuery = d->positionalToNamedBinding(query); executed 13 times by 1 test: d->executedQuery = d->positionalToNamedBinding(query);Executed by:
| 13 | ||||||||||||||||||||||||
| 598 | - | |||||||||||||||||||||||||
| 599 | return prepare(d->executedQuery); executed 247 times by 8 tests: return prepare(d->executedQuery);Executed by:
| 247 | ||||||||||||||||||||||||
| 600 | } | - | ||||||||||||||||||||||||
| 601 | - | |||||||||||||||||||||||||
| 602 | /*! | - | ||||||||||||||||||||||||
| 603 | Prepares the given \a query for execution; the query will normally | - | ||||||||||||||||||||||||
| 604 | use placeholders so that it can be executed repeatedly. Returns | - | ||||||||||||||||||||||||
| 605 | true if the query is prepared successfully; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 606 | - | |||||||||||||||||||||||||
| 607 | \sa exec() | - | ||||||||||||||||||||||||
| 608 | */ | - | ||||||||||||||||||||||||
| 609 | bool QSqlResult::prepare(const QString& query) | - | ||||||||||||||||||||||||
| 610 | { | - | ||||||||||||||||||||||||
| 611 | Q_D(QSqlResult); | - | ||||||||||||||||||||||||
| 612 | d->sql = query; | - | ||||||||||||||||||||||||
| 613 | if (d->holders.isEmpty()) {
| 5-8 | ||||||||||||||||||||||||
| 614 | // parse the query to memorize parameter location | - | ||||||||||||||||||||||||
| 615 | d->namedToPositionalBinding(query); | - | ||||||||||||||||||||||||
| 616 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||||||||
| 617 | return true; // fake prepares should always succeed executed 13 times by 1 test: return true;Executed by:
| 13 | ||||||||||||||||||||||||
| 618 | } | - | ||||||||||||||||||||||||
| 619 | - | |||||||||||||||||||||||||
| 620 | /*! | - | ||||||||||||||||||||||||
| 621 | Executes the query, returning true if successful; otherwise returns | - | ||||||||||||||||||||||||
| 622 | false. | - | ||||||||||||||||||||||||
| 623 | - | |||||||||||||||||||||||||
| 624 | \sa prepare() | - | ||||||||||||||||||||||||
| 625 | */ | - | ||||||||||||||||||||||||
| 626 | bool QSqlResult::exec() | - | ||||||||||||||||||||||||
| 627 | { | - | ||||||||||||||||||||||||
| 628 | Q_D(QSqlResult); | - | ||||||||||||||||||||||||
| 629 | bool ret; | - | ||||||||||||||||||||||||
| 630 | // fake preparation - just replace the placeholders.. | - | ||||||||||||||||||||||||
| 631 | QString query = lastQuery(); | - | ||||||||||||||||||||||||
| 632 | if (d->binds == NamedBinding) {
| 0 | ||||||||||||||||||||||||
| 633 | int i; | - | ||||||||||||||||||||||||
| 634 | QVariant val; | - | ||||||||||||||||||||||||
| 635 | QString holder; | - | ||||||||||||||||||||||||
| 636 | for (i = d->holders.count() - 1; i >= 0; --i) {
| 0 | ||||||||||||||||||||||||
| 637 | holder = d->holders.at(i).holderName; | - | ||||||||||||||||||||||||
| 638 | val = d->values.value(d->indexes.value(holder).value(0,-1)); | - | ||||||||||||||||||||||||
| 639 | QSqlField f(QLatin1String(""), val.type()); | - | ||||||||||||||||||||||||
| 640 | f.setValue(val); | - | ||||||||||||||||||||||||
| 641 | query = query.replace(d->holders.at(i).holderPos, | - | ||||||||||||||||||||||||
| 642 | holder.length(), driver()->formatValue(f)); | - | ||||||||||||||||||||||||
| 643 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 644 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 645 | QString val; | - | ||||||||||||||||||||||||
| 646 | int i = 0; | - | ||||||||||||||||||||||||
| 647 | int idx = 0; | - | ||||||||||||||||||||||||
| 648 | for (idx = 0; idx < d->values.count(); ++idx) {
| 0 | ||||||||||||||||||||||||
| 649 | i = query.indexOf(QLatin1Char('?'), i); | - | ||||||||||||||||||||||||
| 650 | if (i == -1)
| 0 | ||||||||||||||||||||||||
| 651 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 652 | QVariant var = d->values.value(idx); | - | ||||||||||||||||||||||||
| 653 | QSqlField f(QLatin1String(""), var.type()); | - | ||||||||||||||||||||||||
| 654 | if (var.isNull())
| 0 | ||||||||||||||||||||||||
| 655 | f.clear(); never executed: f.clear(); | 0 | ||||||||||||||||||||||||
| 656 | else | - | ||||||||||||||||||||||||
| 657 | f.setValue(var); never executed: f.setValue(var); | 0 | ||||||||||||||||||||||||
| 658 | val = driver()->formatValue(f); | - | ||||||||||||||||||||||||
| 659 | query = query.replace(i, 1, driver()->formatValue(f)); | - | ||||||||||||||||||||||||
| 660 | i += val.length(); | - | ||||||||||||||||||||||||
| 661 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 662 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 663 | - | |||||||||||||||||||||||||
| 664 | // have to retain the original query with placeholders | - | ||||||||||||||||||||||||
| 665 | QString orig = lastQuery(); | - | ||||||||||||||||||||||||
| 666 | ret = reset(query); | - | ||||||||||||||||||||||||
| 667 | d->executedQuery = query; | - | ||||||||||||||||||||||||
| 668 | setQuery(orig); | - | ||||||||||||||||||||||||
| 669 | d->resetBindCount(); | - | ||||||||||||||||||||||||
| 670 | return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||
| 671 | } | - | ||||||||||||||||||||||||
| 672 | - | |||||||||||||||||||||||||
| 673 | /*! | - | ||||||||||||||||||||||||
| 674 | Binds the value \a val of parameter type \a paramType to position \a index | - | ||||||||||||||||||||||||
| 675 | in the current record (row). | - | ||||||||||||||||||||||||
| 676 | - | |||||||||||||||||||||||||
| 677 | \sa addBindValue() | - | ||||||||||||||||||||||||
| 678 | */ | - | ||||||||||||||||||||||||
| 679 | void QSqlResult::bindValue(int index, const QVariant& val, QSql::ParamType paramType) | - | ||||||||||||||||||||||||
| 680 | { | - | ||||||||||||||||||||||||
| 681 | Q_D(QSqlResult); | - | ||||||||||||||||||||||||
| 682 | d->binds = PositionalBinding; | - | ||||||||||||||||||||||||
| 683 | QList<int>& indexes = d->indexes[d->fieldSerial(index)]; | - | ||||||||||||||||||||||||
| 684 | if (!indexes.contains(index))
| 472-232988 | ||||||||||||||||||||||||
| 685 | indexes.append(index); executed 472 times by 7 tests: indexes.append(index);Executed by:
| 472 | ||||||||||||||||||||||||
| 686 | if (d->values.count() <= index)
| 472-232988 | ||||||||||||||||||||||||
| 687 | d->values.resize(index + 1); executed 472 times by 7 tests: d->values.resize(index + 1);Executed by:
| 472 | ||||||||||||||||||||||||
| 688 | d->values[index] = val; | - | ||||||||||||||||||||||||
| 689 | if (paramType != QSql::In || !d->types.isEmpty())
| 0-233460 | ||||||||||||||||||||||||
| 690 | d->types[index] = paramType; never executed: d->types[index] = paramType; | 0 | ||||||||||||||||||||||||
| 691 | } executed 233460 times by 7 tests: end of blockExecuted by:
| 233460 | ||||||||||||||||||||||||
| 692 | - | |||||||||||||||||||||||||
| 693 | /*! | - | ||||||||||||||||||||||||
| 694 | \overload | - | ||||||||||||||||||||||||
| 695 | - | |||||||||||||||||||||||||
| 696 | Binds the value \a val of parameter type \a paramType to the \a | - | ||||||||||||||||||||||||
| 697 | placeholder name in the current record (row). | - | ||||||||||||||||||||||||
| 698 | - | |||||||||||||||||||||||||
| 699 | \note Binding an undefined placeholder will result in undefined behavior. | - | ||||||||||||||||||||||||
| 700 | - | |||||||||||||||||||||||||
| 701 | \sa QSqlQuery::bindValue() | - | ||||||||||||||||||||||||
| 702 | */ | - | ||||||||||||||||||||||||
| 703 | void QSqlResult::bindValue(const QString& placeholder, const QVariant& val, | - | ||||||||||||||||||||||||
| 704 | QSql::ParamType paramType) | - | ||||||||||||||||||||||||
| 705 | { | - | ||||||||||||||||||||||||
| 706 | Q_D(QSqlResult); | - | ||||||||||||||||||||||||
| 707 | d->binds = NamedBinding; | - | ||||||||||||||||||||||||
| 708 | // if the index has already been set when doing emulated named | - | ||||||||||||||||||||||||
| 709 | // bindings - don't reset it | - | ||||||||||||||||||||||||
| 710 | QList<int> indexes = d->indexes.value(placeholder); | - | ||||||||||||||||||||||||
| 711 | foreach (int idx, indexes) { | - | ||||||||||||||||||||||||
| 712 | if (d->values.count() <= idx)
| 0-40 | ||||||||||||||||||||||||
| 713 | d->values.resize(idx + 1); never executed: d->values.resize(idx + 1); | 0 | ||||||||||||||||||||||||
| 714 | d->values[idx] = val; | - | ||||||||||||||||||||||||
| 715 | if (paramType != QSql::In || !d->types.isEmpty())
| 0-40 | ||||||||||||||||||||||||
| 716 | d->types[idx] = paramType; never executed: d->types[idx] = paramType; | 0 | ||||||||||||||||||||||||
| 717 | } executed 40 times by 1 test: end of blockExecuted by:
| 40 | ||||||||||||||||||||||||
| 718 | } executed 48 times by 2 tests: end of blockExecuted by:
| 48 | ||||||||||||||||||||||||
| 719 | - | |||||||||||||||||||||||||
| 720 | /*! | - | ||||||||||||||||||||||||
| 721 | Binds the value \a val of parameter type \a paramType to the next | - | ||||||||||||||||||||||||
| 722 | available position in the current record (row). | - | ||||||||||||||||||||||||
| 723 | - | |||||||||||||||||||||||||
| 724 | \sa bindValue() | - | ||||||||||||||||||||||||
| 725 | */ | - | ||||||||||||||||||||||||
| 726 | void QSqlResult::addBindValue(const QVariant& val, QSql::ParamType paramType) | - | ||||||||||||||||||||||||
| 727 | { | - | ||||||||||||||||||||||||
| 728 | Q_D(QSqlResult); | - | ||||||||||||||||||||||||
| 729 | d->binds = PositionalBinding; | - | ||||||||||||||||||||||||
| 730 | bindValue(d->bindCount, val, paramType); | - | ||||||||||||||||||||||||
| 731 | ++d->bindCount; | - | ||||||||||||||||||||||||
| 732 | } executed 233369 times by 5 tests: end of blockExecuted by:
| 233369 | ||||||||||||||||||||||||
| 733 | - | |||||||||||||||||||||||||
| 734 | /*! | - | ||||||||||||||||||||||||
| 735 | Returns the value bound at position \a index in the current record | - | ||||||||||||||||||||||||
| 736 | (row). | - | ||||||||||||||||||||||||
| 737 | - | |||||||||||||||||||||||||
| 738 | \sa bindValue(), boundValues() | - | ||||||||||||||||||||||||
| 739 | */ | - | ||||||||||||||||||||||||
| 740 | QVariant QSqlResult::boundValue(int index) const | - | ||||||||||||||||||||||||
| 741 | { | - | ||||||||||||||||||||||||
| 742 | Q_D(const QSqlResult); | - | ||||||||||||||||||||||||
| 743 | return d->values.value(index); executed 1 time by 1 test: return d->values.value(index);Executed by:
| 1 | ||||||||||||||||||||||||
| 744 | } | - | ||||||||||||||||||||||||
| 745 | - | |||||||||||||||||||||||||
| 746 | /*! | - | ||||||||||||||||||||||||
| 747 | \overload | - | ||||||||||||||||||||||||
| 748 | - | |||||||||||||||||||||||||
| 749 | Returns the value bound by the given \a placeholder name in the | - | ||||||||||||||||||||||||
| 750 | current record (row). | - | ||||||||||||||||||||||||
| 751 | - | |||||||||||||||||||||||||
| 752 | \sa bindValueType() | - | ||||||||||||||||||||||||
| 753 | */ | - | ||||||||||||||||||||||||
| 754 | QVariant QSqlResult::boundValue(const QString& placeholder) const | - | ||||||||||||||||||||||||
| 755 | { | - | ||||||||||||||||||||||||
| 756 | Q_D(const QSqlResult); | - | ||||||||||||||||||||||||
| 757 | QList<int> indexes = d->indexes.value(placeholder); | - | ||||||||||||||||||||||||
| 758 | return d->values.value(indexes.value(0,-1)); never executed: return d->values.value(indexes.value(0,-1)); | 0 | ||||||||||||||||||||||||
| 759 | } | - | ||||||||||||||||||||||||
| 760 | - | |||||||||||||||||||||||||
| 761 | /*! | - | ||||||||||||||||||||||||
| 762 | Returns the parameter type for the value bound at position \a index. | - | ||||||||||||||||||||||||
| 763 | - | |||||||||||||||||||||||||
| 764 | \sa boundValue() | - | ||||||||||||||||||||||||
| 765 | */ | - | ||||||||||||||||||||||||
| 766 | QSql::ParamType QSqlResult::bindValueType(int index) const | - | ||||||||||||||||||||||||
| 767 | { | - | ||||||||||||||||||||||||
| 768 | Q_D(const QSqlResult); | - | ||||||||||||||||||||||||
| 769 | return d->types.value(index, QSql::In); never executed: return d->types.value(index, QSql::In); | 0 | ||||||||||||||||||||||||
| 770 | } | - | ||||||||||||||||||||||||
| 771 | - | |||||||||||||||||||||||||
| 772 | /*! | - | ||||||||||||||||||||||||
| 773 | \overload | - | ||||||||||||||||||||||||
| 774 | - | |||||||||||||||||||||||||
| 775 | Returns the parameter type for the value bound with the given \a | - | ||||||||||||||||||||||||
| 776 | placeholder name. | - | ||||||||||||||||||||||||
| 777 | */ | - | ||||||||||||||||||||||||
| 778 | QSql::ParamType QSqlResult::bindValueType(const QString& placeholder) const | - | ||||||||||||||||||||||||
| 779 | { | - | ||||||||||||||||||||||||
| 780 | Q_D(const QSqlResult); | - | ||||||||||||||||||||||||
| 781 | return d->types.value(d->indexes.value(placeholder).value(0,-1), QSql::In); never executed: return d->types.value(d->indexes.value(placeholder).value(0,-1), QSql::In); | 0 | ||||||||||||||||||||||||
| 782 | } | - | ||||||||||||||||||||||||
| 783 | - | |||||||||||||||||||||||||
| 784 | /*! | - | ||||||||||||||||||||||||
| 785 | Returns the number of bound values in the result. | - | ||||||||||||||||||||||||
| 786 | - | |||||||||||||||||||||||||
| 787 | \sa boundValues() | - | ||||||||||||||||||||||||
| 788 | */ | - | ||||||||||||||||||||||||
| 789 | int QSqlResult::boundValueCount() const | - | ||||||||||||||||||||||||
| 790 | { | - | ||||||||||||||||||||||||
| 791 | Q_D(const QSqlResult); | - | ||||||||||||||||||||||||
| 792 | return d->values.count(); never executed: return d->values.count(); | 0 | ||||||||||||||||||||||||
| 793 | } | - | ||||||||||||||||||||||||
| 794 | - | |||||||||||||||||||||||||
| 795 | /*! | - | ||||||||||||||||||||||||
| 796 | Returns a vector of the result's bound values for the current | - | ||||||||||||||||||||||||
| 797 | record (row). | - | ||||||||||||||||||||||||
| 798 | - | |||||||||||||||||||||||||
| 799 | \sa boundValueCount() | - | ||||||||||||||||||||||||
| 800 | */ | - | ||||||||||||||||||||||||
| 801 | QVector<QVariant>& QSqlResult::boundValues() const | - | ||||||||||||||||||||||||
| 802 | { | - | ||||||||||||||||||||||||
| 803 | Q_D(const QSqlResult); | - | ||||||||||||||||||||||||
| 804 | return const_cast<QSqlResultPrivate *>(d)->values; executed 119180 times by 10 tests: return const_cast<QSqlResultPrivate *>(d)->values;Executed by:
| 119180 | ||||||||||||||||||||||||
| 805 | } | - | ||||||||||||||||||||||||
| 806 | - | |||||||||||||||||||||||||
| 807 | /*! | - | ||||||||||||||||||||||||
| 808 | Returns the binding syntax used by prepared queries. | - | ||||||||||||||||||||||||
| 809 | */ | - | ||||||||||||||||||||||||
| 810 | QSqlResult::BindingSyntax QSqlResult::bindingSyntax() const | - | ||||||||||||||||||||||||
| 811 | { | - | ||||||||||||||||||||||||
| 812 | Q_D(const QSqlResult); | - | ||||||||||||||||||||||||
| 813 | return d->binds; never executed: return d->binds; | 0 | ||||||||||||||||||||||||
| 814 | } | - | ||||||||||||||||||||||||
| 815 | - | |||||||||||||||||||||||||
| 816 | /*! | - | ||||||||||||||||||||||||
| 817 | Clears the entire result set and releases any associated | - | ||||||||||||||||||||||||
| 818 | resources. | - | ||||||||||||||||||||||||
| 819 | */ | - | ||||||||||||||||||||||||
| 820 | void QSqlResult::clear() | - | ||||||||||||||||||||||||
| 821 | { | - | ||||||||||||||||||||||||
| 822 | Q_D(QSqlResult); | - | ||||||||||||||||||||||||
| 823 | d->clear(); | - | ||||||||||||||||||||||||
| 824 | } executed 2554 times by 9 tests: end of blockExecuted by:
| 2554 | ||||||||||||||||||||||||
| 825 | - | |||||||||||||||||||||||||
| 826 | /*! | - | ||||||||||||||||||||||||
| 827 | Returns the query that was actually executed. This may differ from | - | ||||||||||||||||||||||||
| 828 | the query that was passed, for example if bound values were used | - | ||||||||||||||||||||||||
| 829 | with a prepared query and the underlying database doesn't support | - | ||||||||||||||||||||||||
| 830 | prepared queries. | - | ||||||||||||||||||||||||
| 831 | - | |||||||||||||||||||||||||
| 832 | \sa exec(), setQuery() | - | ||||||||||||||||||||||||
| 833 | */ | - | ||||||||||||||||||||||||
| 834 | QString QSqlResult::executedQuery() const | - | ||||||||||||||||||||||||
| 835 | { | - | ||||||||||||||||||||||||
| 836 | Q_D(const QSqlResult); | - | ||||||||||||||||||||||||
| 837 | return d->executedQuery; executed 1 time by 1 test: return d->executedQuery;Executed by:
| 1 | ||||||||||||||||||||||||
| 838 | } | - | ||||||||||||||||||||||||
| 839 | - | |||||||||||||||||||||||||
| 840 | /*! | - | ||||||||||||||||||||||||
| 841 | Resets the number of bind parameters. | - | ||||||||||||||||||||||||
| 842 | */ | - | ||||||||||||||||||||||||
| 843 | void QSqlResult::resetBindCount() | - | ||||||||||||||||||||||||
| 844 | { | - | ||||||||||||||||||||||||
| 845 | Q_D(QSqlResult); | - | ||||||||||||||||||||||||
| 846 | d->resetBindCount(); | - | ||||||||||||||||||||||||
| 847 | } executed 116732 times by 7 tests: end of blockExecuted by:
| 116732 | ||||||||||||||||||||||||
| 848 | - | |||||||||||||||||||||||||
| 849 | /*! | - | ||||||||||||||||||||||||
| 850 | Returns the name of the bound value at position \a index in the | - | ||||||||||||||||||||||||
| 851 | current record (row). | - | ||||||||||||||||||||||||
| 852 | - | |||||||||||||||||||||||||
| 853 | \sa boundValue() | - | ||||||||||||||||||||||||
| 854 | */ | - | ||||||||||||||||||||||||
| 855 | QString QSqlResult::boundValueName(int index) const | - | ||||||||||||||||||||||||
| 856 | { | - | ||||||||||||||||||||||||
| 857 | Q_D(const QSqlResult); | - | ||||||||||||||||||||||||
| 858 | return d->holderAt(index); executed 154 times by 1 test: return d->holderAt(index);Executed by:
| 154 | ||||||||||||||||||||||||
| 859 | } | - | ||||||||||||||||||||||||
| 860 | - | |||||||||||||||||||||||||
| 861 | /*! | - | ||||||||||||||||||||||||
| 862 | Returns \c true if at least one of the query's bound values is a \c | - | ||||||||||||||||||||||||
| 863 | QSql::Out or a QSql::InOut; otherwise returns \c false. | - | ||||||||||||||||||||||||
| 864 | - | |||||||||||||||||||||||||
| 865 | \sa bindValueType() | - | ||||||||||||||||||||||||
| 866 | */ | - | ||||||||||||||||||||||||
| 867 | bool QSqlResult::hasOutValues() const | - | ||||||||||||||||||||||||
| 868 | { | - | ||||||||||||||||||||||||
| 869 | Q_D(const QSqlResult); | - | ||||||||||||||||||||||||
| 870 | if (d->types.isEmpty())
| 0 | ||||||||||||||||||||||||
| 871 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 872 | QHash<int, QSql::ParamType>::ConstIterator it; | - | ||||||||||||||||||||||||
| 873 | for (it = d->types.constBegin(); it != d->types.constEnd(); ++it) {
| 0 | ||||||||||||||||||||||||
| 874 | if (it.value() != QSql::In)
| 0 | ||||||||||||||||||||||||
| 875 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 876 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 877 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 878 | } | - | ||||||||||||||||||||||||
| 879 | - | |||||||||||||||||||||||||
| 880 | /*! | - | ||||||||||||||||||||||||
| 881 | Returns the current record if the query is active; otherwise | - | ||||||||||||||||||||||||
| 882 | returns an empty QSqlRecord. | - | ||||||||||||||||||||||||
| 883 | - | |||||||||||||||||||||||||
| 884 | The default implementation always returns an empty QSqlRecord. | - | ||||||||||||||||||||||||
| 885 | - | |||||||||||||||||||||||||
| 886 | \sa isActive() | - | ||||||||||||||||||||||||
| 887 | */ | - | ||||||||||||||||||||||||
| 888 | QSqlRecord QSqlResult::record() const | - | ||||||||||||||||||||||||
| 889 | { | - | ||||||||||||||||||||||||
| 890 | return QSqlRecord(); never executed: return QSqlRecord(); | 0 | ||||||||||||||||||||||||
| 891 | } | - | ||||||||||||||||||||||||
| 892 | - | |||||||||||||||||||||||||
| 893 | /*! | - | ||||||||||||||||||||||||
| 894 | Returns the object ID of the most recent inserted row if the | - | ||||||||||||||||||||||||
| 895 | database supports it. | - | ||||||||||||||||||||||||
| 896 | An invalid QVariant will be returned if the query did not | - | ||||||||||||||||||||||||
| 897 | insert any value or if the database does not report the id back. | - | ||||||||||||||||||||||||
| 898 | If more than one row was touched by the insert, the behavior is | - | ||||||||||||||||||||||||
| 899 | undefined. | - | ||||||||||||||||||||||||
| 900 | - | |||||||||||||||||||||||||
| 901 | Note that for Oracle databases the row's ROWID will be returned, | - | ||||||||||||||||||||||||
| 902 | while for MySQL databases the row's auto-increment field will | - | ||||||||||||||||||||||||
| 903 | be returned. | - | ||||||||||||||||||||||||
| 904 | - | |||||||||||||||||||||||||
| 905 | \sa QSqlDriver::hasFeature() | - | ||||||||||||||||||||||||
| 906 | */ | - | ||||||||||||||||||||||||
| 907 | QVariant QSqlResult::lastInsertId() const | - | ||||||||||||||||||||||||
| 908 | { | - | ||||||||||||||||||||||||
| 909 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||||||||||||||
| 910 | } | - | ||||||||||||||||||||||||
| 911 | - | |||||||||||||||||||||||||
| 912 | /*! \internal | - | ||||||||||||||||||||||||
| 913 | */ | - | ||||||||||||||||||||||||
| 914 | void QSqlResult::virtual_hook(int, void *) | - | ||||||||||||||||||||||||
| 915 | { | - | ||||||||||||||||||||||||
| 916 | } | - | ||||||||||||||||||||||||
| 917 | - | |||||||||||||||||||||||||
| 918 | /*! \internal | - | ||||||||||||||||||||||||
| 919 | \since 4.2 | - | ||||||||||||||||||||||||
| 920 | - | |||||||||||||||||||||||||
| 921 | Executes a prepared query in batch mode if the driver supports it, | - | ||||||||||||||||||||||||
| 922 | otherwise emulates a batch execution using bindValue() and exec(). | - | ||||||||||||||||||||||||
| 923 | QSqlDriver::hasFeature() can be used to find out whether a driver | - | ||||||||||||||||||||||||
| 924 | supports batch execution. | - | ||||||||||||||||||||||||
| 925 | - | |||||||||||||||||||||||||
| 926 | Batch execution can be faster for large amounts of data since it | - | ||||||||||||||||||||||||
| 927 | reduces network roundtrips. | - | ||||||||||||||||||||||||
| 928 | - | |||||||||||||||||||||||||
| 929 | For batch executions, bound values have to be provided as lists | - | ||||||||||||||||||||||||
| 930 | of variants (QVariantList). | - | ||||||||||||||||||||||||
| 931 | - | |||||||||||||||||||||||||
| 932 | Each list must contain values of the same type. All lists must | - | ||||||||||||||||||||||||
| 933 | contain equal amount of values (rows). | - | ||||||||||||||||||||||||
| 934 | - | |||||||||||||||||||||||||
| 935 | NULL values are passed in as typed QVariants, for example | - | ||||||||||||||||||||||||
| 936 | \c {QVariant(QVariant::Int)} for an integer NULL value. | - | ||||||||||||||||||||||||
| 937 | - | |||||||||||||||||||||||||
| 938 | Example: | - | ||||||||||||||||||||||||
| 939 | - | |||||||||||||||||||||||||
| 940 | \snippet code/src_sql_kernel_qsqlresult.cpp 0 | - | ||||||||||||||||||||||||
| 941 | - | |||||||||||||||||||||||||
| 942 | Here, we insert two rows into a SQL table, with each row containing three values. | - | ||||||||||||||||||||||||
| 943 | - | |||||||||||||||||||||||||
| 944 | \sa exec(), QSqlDriver::hasFeature() | - | ||||||||||||||||||||||||
| 945 | */ | - | ||||||||||||||||||||||||
| 946 | bool QSqlResult::execBatch(bool arrayBind) | - | ||||||||||||||||||||||||
| 947 | { | - | ||||||||||||||||||||||||
| 948 | Q_UNUSED(arrayBind); | - | ||||||||||||||||||||||||
| 949 | Q_D(QSqlResult); | - | ||||||||||||||||||||||||
| 950 | - | |||||||||||||||||||||||||
| 951 | QVector<QVariant> values = d->values; | - | ||||||||||||||||||||||||
| 952 | if (values.count() == 0)
| 0-2 | ||||||||||||||||||||||||
| 953 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 954 | for (int i = 0; i < values.at(0).toList().count(); ++i) {
| 2 | ||||||||||||||||||||||||
| 955 | for (int j = 0; j < values.count(); ++j)
| 2 | ||||||||||||||||||||||||
| 956 | bindValue(j, values.at(j).toList().at(i), QSql::In); executed 2 times by 1 test: bindValue(j, values.at(j).toList().at(i), QSql::In);Executed by:
| 2 | ||||||||||||||||||||||||
| 957 | if (!exec())
| 0-2 | ||||||||||||||||||||||||
| 958 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 959 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 960 | return true; executed 2 times by 1 test: return true;Executed by:
| 2 | ||||||||||||||||||||||||
| 961 | } | - | ||||||||||||||||||||||||
| 962 | - | |||||||||||||||||||||||||
| 963 | /*! \internal | - | ||||||||||||||||||||||||
| 964 | */ | - | ||||||||||||||||||||||||
| 965 | void QSqlResult::detachFromResultSet() | - | ||||||||||||||||||||||||
| 966 | { | - | ||||||||||||||||||||||||
| 967 | } | - | ||||||||||||||||||||||||
| 968 | - | |||||||||||||||||||||||||
| 969 | /*! \internal | - | ||||||||||||||||||||||||
| 970 | */ | - | ||||||||||||||||||||||||
| 971 | void QSqlResult::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy policy) | - | ||||||||||||||||||||||||
| 972 | { | - | ||||||||||||||||||||||||
| 973 | Q_D(QSqlResult); | - | ||||||||||||||||||||||||
| 974 | d->precisionPolicy = policy; | - | ||||||||||||||||||||||||
| 975 | } executed 4994 times by 10 tests: end of blockExecuted by:
| 4994 | ||||||||||||||||||||||||
| 976 | - | |||||||||||||||||||||||||
| 977 | /*! \internal | - | ||||||||||||||||||||||||
| 978 | */ | - | ||||||||||||||||||||||||
| 979 | QSql::NumericalPrecisionPolicy QSqlResult::numericalPrecisionPolicy() const | - | ||||||||||||||||||||||||
| 980 | { | - | ||||||||||||||||||||||||
| 981 | Q_D(const QSqlResult); | - | ||||||||||||||||||||||||
| 982 | return d->precisionPolicy; executed 2809 times by 9 tests: return d->precisionPolicy;Executed by:
| 2809 | ||||||||||||||||||||||||
| 983 | } | - | ||||||||||||||||||||||||
| 984 | - | |||||||||||||||||||||||||
| 985 | /*! \internal | - | ||||||||||||||||||||||||
| 986 | */ | - | ||||||||||||||||||||||||
| 987 | bool QSqlResult::nextResult() | - | ||||||||||||||||||||||||
| 988 | { | - | ||||||||||||||||||||||||
| 989 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 990 | } | - | ||||||||||||||||||||||||
| 991 | - | |||||||||||||||||||||||||
| 992 | /*! | - | ||||||||||||||||||||||||
| 993 | Returns the low-level database handle for this result set | - | ||||||||||||||||||||||||
| 994 | wrapped in a QVariant or an invalid QVariant if there is no handle. | - | ||||||||||||||||||||||||
| 995 | - | |||||||||||||||||||||||||
| 996 | \warning Use this with uttermost care and only if you know what you're doing. | - | ||||||||||||||||||||||||
| 997 | - | |||||||||||||||||||||||||
| 998 | \warning The handle returned here can become a stale pointer if the result | - | ||||||||||||||||||||||||
| 999 | is modified (for example, if you clear it). | - | ||||||||||||||||||||||||
| 1000 | - | |||||||||||||||||||||||||
| 1001 | \warning The handle can be NULL if the result was not executed yet. | - | ||||||||||||||||||||||||
| 1002 | - | |||||||||||||||||||||||||
| 1003 | The handle returned here is database-dependent, you should query the type | - | ||||||||||||||||||||||||
| 1004 | name of the variant before accessing it. | - | ||||||||||||||||||||||||
| 1005 | - | |||||||||||||||||||||||||
| 1006 | This example retrieves the handle for a sqlite result: | - | ||||||||||||||||||||||||
| 1007 | - | |||||||||||||||||||||||||
| 1008 | \snippet code/src_sql_kernel_qsqlresult.cpp 1 | - | ||||||||||||||||||||||||
| 1009 | - | |||||||||||||||||||||||||
| 1010 | This snippet returns the handle for PostgreSQL or MySQL: | - | ||||||||||||||||||||||||
| 1011 | - | |||||||||||||||||||||||||
| 1012 | \snippet code/src_sql_kernel_qsqlresult.cpp 2 | - | ||||||||||||||||||||||||
| 1013 | - | |||||||||||||||||||||||||
| 1014 | \sa QSqlDriver::handle() | - | ||||||||||||||||||||||||
| 1015 | */ | - | ||||||||||||||||||||||||
| 1016 | QVariant QSqlResult::handle() const | - | ||||||||||||||||||||||||
| 1017 | { | - | ||||||||||||||||||||||||
| 1018 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||||||||||||||
| 1019 | } | - | ||||||||||||||||||||||||
| 1020 | - | |||||||||||||||||||||||||
| 1021 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |