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