| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/sql/kernel/qsqlresult.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | QString QSqlResultPrivate::holderAt(int index) const | - | ||||||||||||||||||
| 6 | { | - | ||||||||||||||||||
| 7 | return holders.size() > index ? holders.at(index).holderName : fieldSerial(index); | - | ||||||||||||||||||
| 8 | } | - | ||||||||||||||||||
| 9 | - | |||||||||||||||||||
| 10 | - | |||||||||||||||||||
| 11 | QString QSqlResultPrivate::fieldSerial(int i) const | - | ||||||||||||||||||
| 12 | { | - | ||||||||||||||||||
| 13 | ushort arr[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | - | ||||||||||||||||||
| 14 | ushort *end = &arr[(sizeof(arr)/sizeof(*arr))]; | - | ||||||||||||||||||
| 15 | ushort *ptr = end; | - | ||||||||||||||||||
| 16 | - | |||||||||||||||||||
| 17 | while (i > 0) { | - | ||||||||||||||||||
| 18 | *(--ptr) = 'a' + i % 16; | - | ||||||||||||||||||
| 19 | i >>= 4; | - | ||||||||||||||||||
| 20 | } | - | ||||||||||||||||||
| 21 | - | |||||||||||||||||||
| 22 | const int nb = end - ptr; | - | ||||||||||||||||||
| 23 | *(--ptr) = 'a' + nb; | - | ||||||||||||||||||
| 24 | *(--ptr) = ':'; | - | ||||||||||||||||||
| 25 | - | |||||||||||||||||||
| 26 | return QString::fromUtf16(ptr, int(end - ptr)); | - | ||||||||||||||||||
| 27 | } | - | ||||||||||||||||||
| 28 | - | |||||||||||||||||||
| 29 | static bool qIsAlnum(QChar ch) | - | ||||||||||||||||||
| 30 | { | - | ||||||||||||||||||
| 31 | uint u = uint(ch.unicode()); | - | ||||||||||||||||||
| 32 | - | |||||||||||||||||||
| 33 | return u - 'a' < 26 || u - 'A' < 26 || u - '0' < 10 || u == '_'; | - | ||||||||||||||||||
| 34 | } | - | ||||||||||||||||||
| 35 | - | |||||||||||||||||||
| 36 | QString QSqlResultPrivate::positionalToNamedBinding(const QString &query) const | - | ||||||||||||||||||
| 37 | { | - | ||||||||||||||||||
| 38 | int n = query.size(); | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | QString result; | - | ||||||||||||||||||
| 41 | result.reserve(n * 5 / 4); | - | ||||||||||||||||||
| 42 | QChar closingQuote; | - | ||||||||||||||||||
| 43 | int count = 0; | - | ||||||||||||||||||
| 44 | bool ignoreBraces = (sqldriver->d_func()->dbmsType() == QSqlDriver::PostgreSQL); | - | ||||||||||||||||||
| 45 | - | |||||||||||||||||||
| 46 | for (int i = 0; i < n
| 13-253 | ||||||||||||||||||
| 47 | QChar ch = query.at(i); | - | ||||||||||||||||||
| 48 | if (!closingQuote.isNull()
| 38-215 | ||||||||||||||||||
| 49 | if (ch == closingQuote
| 16-22 | ||||||||||||||||||
| 50 | if (closingQuote == QLatin1Char(']')
| 8 | ||||||||||||||||||
| 51 | && i + 1 < n
| 0-5 | ||||||||||||||||||
| 52 | - | |||||||||||||||||||
| 53 | ++i; | - | ||||||||||||||||||
| 54 | result += ch; | - | ||||||||||||||||||
| 55 | } executed 3 times by 1 test: else {end of blockExecuted by:
| 3 | ||||||||||||||||||
| 56 | closingQuote = QChar(); | - | ||||||||||||||||||
| 57 | } executed 13 times by 1 test: end of blockExecuted by:
| 13 | ||||||||||||||||||
| 58 | } | - | ||||||||||||||||||
| 59 | result += ch; | - | ||||||||||||||||||
| 60 | } executed 38 times by 1 test: else {end of blockExecuted by:
| 38 | ||||||||||||||||||
| 61 | if (ch == QLatin1Char('?')
| 10-205 | ||||||||||||||||||
| 62 | result += fieldSerial(count++); | - | ||||||||||||||||||
| 63 | } executed 10 times by 1 test: else {end of blockExecuted by:
| 10 | ||||||||||||||||||
| 64 | if (ch == QLatin1Char('\'')
| 0-200 | ||||||||||||||||||
| 65 | closingQuote = ch; executed 8 times by 1 test: closingQuote = ch;Executed by:
| 8 | ||||||||||||||||||
| 66 | else if (!ignoreBraces
| 0-197 | ||||||||||||||||||
| 67 | closingQuote = QLatin1Char(']'); executed 5 times by 1 test: closingQuote = QLatin1Char(']');Executed by:
| 5 | ||||||||||||||||||
| 68 | result += ch; | - | ||||||||||||||||||
| 69 | } executed 205 times by 1 test: end of blockExecuted by:
| 205 | ||||||||||||||||||
| 70 | } | - | ||||||||||||||||||
| 71 | } | - | ||||||||||||||||||
| 72 | result.squeeze(); | - | ||||||||||||||||||
| 73 | return executed 13 times by 1 test: result;return result;Executed by:
executed 13 times by 1 test: return result;Executed by:
| 13 | ||||||||||||||||||
| 74 | } | - | ||||||||||||||||||
| 75 | - | |||||||||||||||||||
| 76 | QString QSqlResultPrivate::namedToPositionalBinding(const QString &query) | - | ||||||||||||||||||
| 77 | { | - | ||||||||||||||||||
| 78 | int n = query.size(); | - | ||||||||||||||||||
| 79 | - | |||||||||||||||||||
| 80 | QString result; | - | ||||||||||||||||||
| 81 | result.reserve(n); | - | ||||||||||||||||||
| 82 | QChar closingQuote; | - | ||||||||||||||||||
| 83 | int count = 0; | - | ||||||||||||||||||
| 84 | int i = 0; | - | ||||||||||||||||||
| 85 | bool ignoreBraces = (sqldriver->d_func()->dbmsType() == QSqlDriver::PostgreSQL); | - | ||||||||||||||||||
| 86 | - | |||||||||||||||||||
| 87 | while (i < n
| 253-15899 | ||||||||||||||||||
| 88 | QChar ch = query.at(i); | - | ||||||||||||||||||
| 89 | if (!closingQuote.isNull()
| 3386-12513 | ||||||||||||||||||
| 90 | if (ch == closingQuote
| 342-3044 | ||||||||||||||||||
| 91 | if (closingQuote == QLatin1Char(']')
| 10-332 | ||||||||||||||||||
| 92 | && i + 1 < n
| 0-7 | ||||||||||||||||||
| 93 | - | |||||||||||||||||||
| 94 | ++i; | - | ||||||||||||||||||
| 95 | result += ch; | - | ||||||||||||||||||
| 96 | } executed 3 times by 1 test: else {end of blockExecuted by:
| 3 | ||||||||||||||||||
| 97 | closingQuote = QChar(); | - | ||||||||||||||||||
| 98 | } executed 339 times by 4 tests: end of blockExecuted by:
| 339 | ||||||||||||||||||
| 99 | } | - | ||||||||||||||||||
| 100 | result += ch; | - | ||||||||||||||||||
| 101 | ++i; | - | ||||||||||||||||||
| 102 | } executed 3386 times by 4 tests: else {end of blockExecuted by:
| 3386 | ||||||||||||||||||
| 103 | if (ch == QLatin1Char(':')
| 32-12481 | ||||||||||||||||||
| 104 | && (i == 0
| 0-32 | ||||||||||||||||||
| 105 | && (i + 1 < n
| 0-32 | ||||||||||||||||||
| 106 | int pos = i + 2; | - | ||||||||||||||||||
| 107 | while (pos < n
| 4-65 | ||||||||||||||||||
| 108 | ++ executed 37 times by 3 tests: pos;++pos;Executed by:
executed 37 times by 3 tests: ++pos;Executed by:
| 37 | ||||||||||||||||||
| 109 | QString holder(query.mid(i, pos - i)); | - | ||||||||||||||||||
| 110 | indexes[holder].append(count++); | - | ||||||||||||||||||
| 111 | holders.append(QHolder(holder, i)); | - | ||||||||||||||||||
| 112 | result += QLatin1Char('?'); | - | ||||||||||||||||||
| 113 | i = pos; | - | ||||||||||||||||||
| 114 | } executed 32 times by 3 tests: else {end of blockExecuted by:
| 32 | ||||||||||||||||||
| 115 | if (ch == QLatin1Char('\'')
| 0-12469 | ||||||||||||||||||
| 116 | closingQuote = ch; executed 333 times by 4 tests: closingQuote = ch;Executed by:
| 333 | ||||||||||||||||||
| 117 | else if (!ignoreBraces
| 0-12148 | ||||||||||||||||||
| 118 | closingQuote = QLatin1Char(']'); executed 7 times by 1 test: closingQuote = QLatin1Char(']');Executed by:
| 7 | ||||||||||||||||||
| 119 | result += ch; | - | ||||||||||||||||||
| 120 | ++i; | - | ||||||||||||||||||
| 121 | } executed 12481 times by 8 tests: end of blockExecuted by:
| 12481 | ||||||||||||||||||
| 122 | } | - | ||||||||||||||||||
| 123 | } | - | ||||||||||||||||||
| 124 | result.squeeze(); | - | ||||||||||||||||||
| 125 | values.resize(holders.size()); | - | ||||||||||||||||||
| 126 | return executed 253 times by 8 tests: result;return result;Executed by:
executed 253 times by 8 tests: return result;Executed by:
| 253 | ||||||||||||||||||
| 127 | } | - | ||||||||||||||||||
| 128 | QSqlResult::QSqlResult(const QSqlDriver *db) | - | ||||||||||||||||||
| 129 | { | - | ||||||||||||||||||
| 130 | d_ptr = new QSqlResultPrivate;(this, db); | - | ||||||||||||||||||
| 131 | QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 132 | d->q_ptr = this; | 0-263 | ||||||||||||||||||
d->sqldriver = const_cast<QSqlDriver *>(db);if (d->sqldriver
| ||||||||||||||||||||
| 133 | setNumericalPrecisionPolicy(d->sqldriver->numericalPrecisionPolicy()); executed 263 times by 10 tests: setNumericalPrecisionPolicy(d->sqldriver->numericalPrecisionPolicy());Executed by:
| 263 | ||||||||||||||||||
| 134 | } executed 263 times by 10 tests: end of blockExecuted by:
| 263 | ||||||||||||||||||
| 135 | - | |||||||||||||||||||
| 136 | - | |||||||||||||||||||
| 137 | - | |||||||||||||||||||
| 138 | QSqlResult::QSqlResult(QSqlResultPrivate &dd, const QSqlDriver *db) | - | ||||||||||||||||||
| 139 | {: d_ptr=(ⅆ) | - | ||||||||||||||||||
| 140 | { | - | ||||||||||||||||||
| 141 | QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 142 | d->q_ptr = this; | 0-1930 | ||||||||||||||||||
d->sqldriver = const_cast<QSqlDriver *>(db);if (d->sqldriver
| ||||||||||||||||||||
| 143 | setNumericalPrecisionPolicy(d->sqldriver->numericalPrecisionPolicy()); executed 1930 times by 9 tests: setNumericalPrecisionPolicy(d->sqldriver->numericalPrecisionPolicy());Executed by:
| 1930 | ||||||||||||||||||
| 144 | } executed 1930 times by 9 tests: end of blockExecuted by:
| 1930 | ||||||||||||||||||
| 145 | - | |||||||||||||||||||
| 146 | - | |||||||||||||||||||
| 147 | - | |||||||||||||||||||
| 148 | - | |||||||||||||||||||
| 149 | - | |||||||||||||||||||
| 150 | QSqlResult::~QSqlResult() | - | ||||||||||||||||||
| 151 | { | - | ||||||||||||||||||
| 152 | QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 153 | delete d; | - | ||||||||||||||||||
| 154 | } | - | ||||||||||||||||||
| 155 | void QSqlResult::setQuery(const QString& query) | - | ||||||||||||||||||
| 156 | { | - | ||||||||||||||||||
| 157 | QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 158 | d->sql = query; | - | ||||||||||||||||||
| 159 | } | - | ||||||||||||||||||
| 160 | QString QSqlResult::lastQuery() const | - | ||||||||||||||||||
| 161 | { | - | ||||||||||||||||||
| 162 | const QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 163 | return d->sql; | - | ||||||||||||||||||
| 164 | } | - | ||||||||||||||||||
| 165 | int QSqlResult::at() const | - | ||||||||||||||||||
| 166 | { | - | ||||||||||||||||||
| 167 | const QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 168 | return d->idx; | - | ||||||||||||||||||
| 169 | } | - | ||||||||||||||||||
| 170 | bool QSqlResult::isValid() const | - | ||||||||||||||||||
| 171 | { | - | ||||||||||||||||||
| 172 | const QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 173 | return d->idx != QSql::BeforeFirstRow && d->idx != QSql::AfterLastRow; | - | ||||||||||||||||||
| 174 | } | - | ||||||||||||||||||
| 175 | bool QSqlResult::isActive() const | - | ||||||||||||||||||
| 176 | { | - | ||||||||||||||||||
| 177 | const QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 178 | return d->active; | - | ||||||||||||||||||
| 179 | } | - | ||||||||||||||||||
| 180 | void QSqlResult::setAt(int index) | - | ||||||||||||||||||
| 181 | { | - | ||||||||||||||||||
| 182 | QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 183 | d->idx = index; | - | ||||||||||||||||||
| 184 | } | - | ||||||||||||||||||
| 185 | void QSqlResult::setSelect(bool select) | - | ||||||||||||||||||
| 186 | { | - | ||||||||||||||||||
| 187 | QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 188 | d->isSel = select; | - | ||||||||||||||||||
| 189 | } | - | ||||||||||||||||||
| 190 | bool QSqlResult::isSelect() const | - | ||||||||||||||||||
| 191 | { | - | ||||||||||||||||||
| 192 | const QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 193 | return d->isSel; | - | ||||||||||||||||||
| 194 | } | - | ||||||||||||||||||
| 195 | - | |||||||||||||||||||
| 196 | - | |||||||||||||||||||
| 197 | - | |||||||||||||||||||
| 198 | - | |||||||||||||||||||
| 199 | - | |||||||||||||||||||
| 200 | - | |||||||||||||||||||
| 201 | const QSqlDriver *QSqlResult::driver() const | - | ||||||||||||||||||
| 202 | { | - | ||||||||||||||||||
| 203 | const QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 204 | return d->sqldriver; | - | ||||||||||||||||||
| 205 | } | - | ||||||||||||||||||
| 206 | void QSqlResult::setActive(bool active) | - | ||||||||||||||||||
| 207 | { | - | ||||||||||||||||||
| 208 | QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 209 | if (active && d->executedQuery.isEmpty()) | - | ||||||||||||||||||
| 210 | d->executedQuery = d->sql; | - | ||||||||||||||||||
| 211 | - | |||||||||||||||||||
| 212 | d->active = active; | - | ||||||||||||||||||
| 213 | } | - | ||||||||||||||||||
| 214 | void QSqlResult::setLastError(const QSqlError &error) | - | ||||||||||||||||||
| 215 | { | - | ||||||||||||||||||
| 216 | QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 217 | d->error = error; | - | ||||||||||||||||||
| 218 | } | - | ||||||||||||||||||
| 219 | - | |||||||||||||||||||
| 220 | - | |||||||||||||||||||
| 221 | - | |||||||||||||||||||
| 222 | - | |||||||||||||||||||
| 223 | - | |||||||||||||||||||
| 224 | - | |||||||||||||||||||
| 225 | QSqlError QSqlResult::lastError() const | - | ||||||||||||||||||
| 226 | { | - | ||||||||||||||||||
| 227 | const QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 228 | return d->error; | - | ||||||||||||||||||
| 229 | } | - | ||||||||||||||||||
| 230 | bool QSqlResult::fetchNext() | - | ||||||||||||||||||
| 231 | { | - | ||||||||||||||||||
| 232 | return fetch(at() + 1); | - | ||||||||||||||||||
| 233 | } | - | ||||||||||||||||||
| 234 | bool QSqlResult::fetchPrevious() | - | ||||||||||||||||||
| 235 | { | - | ||||||||||||||||||
| 236 | return fetch(at() - 1); | - | ||||||||||||||||||
| 237 | } | - | ||||||||||||||||||
| 238 | - | |||||||||||||||||||
| 239 | - | |||||||||||||||||||
| 240 | - | |||||||||||||||||||
| 241 | - | |||||||||||||||||||
| 242 | - | |||||||||||||||||||
| 243 | - | |||||||||||||||||||
| 244 | - | |||||||||||||||||||
| 245 | bool QSqlResult::isForwardOnly() const | - | ||||||||||||||||||
| 246 | { | - | ||||||||||||||||||
| 247 | const QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 248 | return d->forwardOnly; | - | ||||||||||||||||||
| 249 | } | - | ||||||||||||||||||
| 250 | void QSqlResult::setForwardOnly(bool forward) | - | ||||||||||||||||||
| 251 | { | - | ||||||||||||||||||
| 252 | QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 253 | d->forwardOnly = forward; | - | ||||||||||||||||||
| 254 | } | - | ||||||||||||||||||
| 255 | bool QSqlResult::savePrepare(const QString& query) | - | ||||||||||||||||||
| 256 | { | - | ||||||||||||||||||
| 257 | QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 258 | if (!driver()) | - | ||||||||||||||||||
| 259 | return false; | - | ||||||||||||||||||
| 260 | d->clear(); | - | ||||||||||||||||||
| 261 | d->sql = query; | - | ||||||||||||||||||
| 262 | if (!driver()->hasFeature(QSqlDriver::PreparedQueries)) | - | ||||||||||||||||||
| 263 | return prepare(query); | - | ||||||||||||||||||
| 264 | - | |||||||||||||||||||
| 265 | - | |||||||||||||||||||
| 266 | d->executedQuery = d->namedToPositionalBinding(query); | - | ||||||||||||||||||
| 267 | - | |||||||||||||||||||
| 268 | if (driver()->hasFeature(QSqlDriver::NamedPlaceholders)) | - | ||||||||||||||||||
| 269 | d->executedQuery = d->positionalToNamedBinding(query); | - | ||||||||||||||||||
| 270 | - | |||||||||||||||||||
| 271 | return prepare(d->executedQuery); | - | ||||||||||||||||||
| 272 | } | - | ||||||||||||||||||
| 273 | bool QSqlResult::prepare(const QString& query) | - | ||||||||||||||||||
| 274 | { | - | ||||||||||||||||||
| 275 | QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 276 | d->sql = query; | - | ||||||||||||||||||
| 277 | if (d->holders.isEmpty()) { | - | ||||||||||||||||||
| 278 | - | |||||||||||||||||||
| 279 | d->namedToPositionalBinding(query); | - | ||||||||||||||||||
| 280 | } | - | ||||||||||||||||||
| 281 | return true; | - | ||||||||||||||||||
| 282 | } | - | ||||||||||||||||||
| 283 | - | |||||||||||||||||||
| 284 | - | |||||||||||||||||||
| 285 | - | |||||||||||||||||||
| 286 | - | |||||||||||||||||||
| 287 | - | |||||||||||||||||||
| 288 | - | |||||||||||||||||||
| 289 | - | |||||||||||||||||||
| 290 | bool QSqlResult::exec() | - | ||||||||||||||||||
| 291 | { | - | ||||||||||||||||||
| 292 | QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 293 | bool ret; | - | ||||||||||||||||||
| 294 | - | |||||||||||||||||||
| 295 | QString query = lastQuery(); | - | ||||||||||||||||||
| 296 | if (d->binds == NamedBinding) { | - | ||||||||||||||||||
| 297 | int i; | - | ||||||||||||||||||
| 298 | QVariant val; | - | ||||||||||||||||||
| 299 | QString holder; | - | ||||||||||||||||||
| 300 | for (i = d->holders.count() - 1; i >= 0; --i) { | - | ||||||||||||||||||
| 301 | holder = d->holders.at(i).holderName; | - | ||||||||||||||||||
| 302 | val = d->values.value(d->indexes.value(holder).value(0,-1)); | - | ||||||||||||||||||
| 303 | QSqlField f(QLatin1String(""), val.type()); | - | ||||||||||||||||||
| 304 | f.setValue(val); | - | ||||||||||||||||||
| 305 | query = query.replace(d->holders.at(i).holderPos, | - | ||||||||||||||||||
| 306 | holder.length(), driver()->formatValue(f)); | - | ||||||||||||||||||
| 307 | } | - | ||||||||||||||||||
| 308 | } else { | - | ||||||||||||||||||
| 309 | QString val; | - | ||||||||||||||||||
| 310 | int i = 0; | - | ||||||||||||||||||
| 311 | int idx = 0; | - | ||||||||||||||||||
| 312 | for (idx = 0; idx < d->values.count(); ++idx) { | - | ||||||||||||||||||
| 313 | i = query.indexOf(QLatin1Char('?'), i); | - | ||||||||||||||||||
| 314 | if (i == -1) | - | ||||||||||||||||||
| 315 | continue; | - | ||||||||||||||||||
| 316 | QVariant var = d->values.value(idx); | - | ||||||||||||||||||
| 317 | QSqlField f(QLatin1String(""), var.type()); | - | ||||||||||||||||||
| 318 | if (var.isNull()) | - | ||||||||||||||||||
| 319 | f.clear(); | - | ||||||||||||||||||
| 320 | else | - | ||||||||||||||||||
| 321 | f.setValue(var); | - | ||||||||||||||||||
| 322 | val = driver()->formatValue(f); | - | ||||||||||||||||||
| 323 | query = query.replace(i, 1, driver()->formatValue(f)); | - | ||||||||||||||||||
| 324 | i += val.length(); | - | ||||||||||||||||||
| 325 | } | - | ||||||||||||||||||
| 326 | } | - | ||||||||||||||||||
| 327 | - | |||||||||||||||||||
| 328 | - | |||||||||||||||||||
| 329 | QString orig = lastQuery(); | - | ||||||||||||||||||
| 330 | ret = reset(query); | - | ||||||||||||||||||
| 331 | d->executedQuery = query; | - | ||||||||||||||||||
| 332 | setQuery(orig); | - | ||||||||||||||||||
| 333 | d->resetBindCount(); | - | ||||||||||||||||||
| 334 | return ret; | - | ||||||||||||||||||
| 335 | } | - | ||||||||||||||||||
| 336 | - | |||||||||||||||||||
| 337 | - | |||||||||||||||||||
| 338 | - | |||||||||||||||||||
| 339 | - | |||||||||||||||||||
| 340 | - | |||||||||||||||||||
| 341 | - | |||||||||||||||||||
| 342 | - | |||||||||||||||||||
| 343 | void QSqlResult::bindValue(int index, const QVariant& val, QSql::ParamType paramType) | - | ||||||||||||||||||
| 344 | { | - | ||||||||||||||||||
| 345 | QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 346 | d->binds = PositionalBinding; | - | ||||||||||||||||||
| 347 | QList<int>& indexes = d->indexes[d->fieldSerial(index)]; | - | ||||||||||||||||||
| 348 | if (!indexes.contains(index)) | - | ||||||||||||||||||
| 349 | indexes.append(index); | - | ||||||||||||||||||
| 350 | if (d->values.count() <= index) | - | ||||||||||||||||||
| 351 | d->values.resize(index + 1); | - | ||||||||||||||||||
| 352 | d->values[index] = val; | - | ||||||||||||||||||
| 353 | if (paramType != QSql::In || !d->types.isEmpty()) | - | ||||||||||||||||||
| 354 | d->types[index] = paramType; | - | ||||||||||||||||||
| 355 | } | - | ||||||||||||||||||
| 356 | void QSqlResult::bindValue(const QString& placeholder, const QVariant& val, | - | ||||||||||||||||||
| 357 | QSql::ParamType paramType) | - | ||||||||||||||||||
| 358 | { | - | ||||||||||||||||||
| 359 | QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 360 | d->binds = NamedBinding; | - | ||||||||||||||||||
| 361 | - | |||||||||||||||||||
| 362 | - | |||||||||||||||||||
| 363 | const QList<int> indexes = d->indexes.value(placeholder); | - | ||||||||||||||||||
| 364 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(indexes)>::type> _container_((indexes)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (int idx = *_container_.i; _container_.control; _container_.control = 0: indexes) { | - | ||||||||||||||||||
| 365 | if (d->values.count() <= idx
| 0-40 | ||||||||||||||||||
| 366 | d->values.resize(idx + 1); never executed: d->values.resize(idx + 1); | 0 | ||||||||||||||||||
| 367 | d->values[idx] = val; | - | ||||||||||||||||||
| 368 | if (paramType != QSql::In
| 0-40 | ||||||||||||||||||
| 369 | d->types[idx] = paramType; never executed: d->types[idx] = paramType; | 0 | ||||||||||||||||||
| 370 | } executed 40 times by 1 test: end of blockExecuted by:
| 40 | ||||||||||||||||||
| 371 | } executed 48 times by 2 tests: end of blockExecuted by:
| 48 | ||||||||||||||||||
| 372 | - | |||||||||||||||||||
| 373 | - | |||||||||||||||||||
| 374 | - | |||||||||||||||||||
| 375 | - | |||||||||||||||||||
| 376 | - | |||||||||||||||||||
| 377 | - | |||||||||||||||||||
| 378 | - | |||||||||||||||||||
| 379 | void QSqlResult::addBindValue(const QVariant& val, QSql::ParamType paramType) | - | ||||||||||||||||||
| 380 | { | - | ||||||||||||||||||
| 381 | QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 382 | d->binds = PositionalBinding; | - | ||||||||||||||||||
| 383 | bindValue(d->bindCount, val, paramType); | - | ||||||||||||||||||
| 384 | ++d->bindCount; | - | ||||||||||||||||||
| 385 | } | - | ||||||||||||||||||
| 386 | - | |||||||||||||||||||
| 387 | - | |||||||||||||||||||
| 388 | - | |||||||||||||||||||
| 389 | - | |||||||||||||||||||
| 390 | - | |||||||||||||||||||
| 391 | - | |||||||||||||||||||
| 392 | - | |||||||||||||||||||
| 393 | QVariant QSqlResult::boundValue(int index) const | - | ||||||||||||||||||
| 394 | { | - | ||||||||||||||||||
| 395 | const QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 396 | return d->values.value(index); | - | ||||||||||||||||||
| 397 | } | - | ||||||||||||||||||
| 398 | QVariant QSqlResult::boundValue(const QString& placeholder) const | - | ||||||||||||||||||
| 399 | { | - | ||||||||||||||||||
| 400 | const QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 401 | QList<int> indexes = d->indexes.value(placeholder); | - | ||||||||||||||||||
| 402 | return d->values.value(indexes.value(0,-1)); | - | ||||||||||||||||||
| 403 | } | - | ||||||||||||||||||
| 404 | - | |||||||||||||||||||
| 405 | - | |||||||||||||||||||
| 406 | - | |||||||||||||||||||
| 407 | - | |||||||||||||||||||
| 408 | - | |||||||||||||||||||
| 409 | - | |||||||||||||||||||
| 410 | QSql::ParamType QSqlResult::bindValueType(int index) const | - | ||||||||||||||||||
| 411 | { | - | ||||||||||||||||||
| 412 | const QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 413 | return d->types.value(index, QSql::In); | - | ||||||||||||||||||
| 414 | } | - | ||||||||||||||||||
| 415 | - | |||||||||||||||||||
| 416 | - | |||||||||||||||||||
| 417 | - | |||||||||||||||||||
| 418 | - | |||||||||||||||||||
| 419 | - | |||||||||||||||||||
| 420 | - | |||||||||||||||||||
| 421 | - | |||||||||||||||||||
| 422 | QSql::ParamType QSqlResult::bindValueType(const QString& placeholder) const | - | ||||||||||||||||||
| 423 | { | - | ||||||||||||||||||
| 424 | const QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 425 | return d->types.value(d->indexes.value(placeholder).value(0,-1), QSql::In); | - | ||||||||||||||||||
| 426 | } | - | ||||||||||||||||||
| 427 | - | |||||||||||||||||||
| 428 | - | |||||||||||||||||||
| 429 | - | |||||||||||||||||||
| 430 | - | |||||||||||||||||||
| 431 | - | |||||||||||||||||||
| 432 | - | |||||||||||||||||||
| 433 | int QSqlResult::boundValueCount() const | - | ||||||||||||||||||
| 434 | { | - | ||||||||||||||||||
| 435 | const QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 436 | return d->values.count(); | - | ||||||||||||||||||
| 437 | } | - | ||||||||||||||||||
| 438 | - | |||||||||||||||||||
| 439 | - | |||||||||||||||||||
| 440 | - | |||||||||||||||||||
| 441 | - | |||||||||||||||||||
| 442 | - | |||||||||||||||||||
| 443 | - | |||||||||||||||||||
| 444 | - | |||||||||||||||||||
| 445 | QVector<QVariant>& QSqlResult::boundValues() const | - | ||||||||||||||||||
| 446 | { | - | ||||||||||||||||||
| 447 | const QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 448 | return const_cast<QSqlResultPrivate *>(d)->values; | - | ||||||||||||||||||
| 449 | } | - | ||||||||||||||||||
| 450 | - | |||||||||||||||||||
| 451 | - | |||||||||||||||||||
| 452 | - | |||||||||||||||||||
| 453 | - | |||||||||||||||||||
| 454 | QSqlResult::BindingSyntax QSqlResult::bindingSyntax() const | - | ||||||||||||||||||
| 455 | { | - | ||||||||||||||||||
| 456 | const QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 457 | return d->binds; | - | ||||||||||||||||||
| 458 | } | - | ||||||||||||||||||
| 459 | - | |||||||||||||||||||
| 460 | - | |||||||||||||||||||
| 461 | - | |||||||||||||||||||
| 462 | - | |||||||||||||||||||
| 463 | - | |||||||||||||||||||
| 464 | void QSqlResult::clear() | - | ||||||||||||||||||
| 465 | { | - | ||||||||||||||||||
| 466 | QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 467 | d->clear(); | - | ||||||||||||||||||
| 468 | } | - | ||||||||||||||||||
| 469 | QString QSqlResult::executedQuery() const | - | ||||||||||||||||||
| 470 | { | - | ||||||||||||||||||
| 471 | const QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 472 | return d->executedQuery; | - | ||||||||||||||||||
| 473 | } | - | ||||||||||||||||||
| 474 | - | |||||||||||||||||||
| 475 | - | |||||||||||||||||||
| 476 | - | |||||||||||||||||||
| 477 | - | |||||||||||||||||||
| 478 | void QSqlResult::resetBindCount() | - | ||||||||||||||||||
| 479 | { | - | ||||||||||||||||||
| 480 | QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 481 | d->resetBindCount(); | - | ||||||||||||||||||
| 482 | } | - | ||||||||||||||||||
| 483 | - | |||||||||||||||||||
| 484 | - | |||||||||||||||||||
| 485 | - | |||||||||||||||||||
| 486 | - | |||||||||||||||||||
| 487 | - | |||||||||||||||||||
| 488 | - | |||||||||||||||||||
| 489 | - | |||||||||||||||||||
| 490 | QString QSqlResult::boundValueName(int index) const | - | ||||||||||||||||||
| 491 | { | - | ||||||||||||||||||
| 492 | const QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 493 | return d->holderAt(index); | - | ||||||||||||||||||
| 494 | } | - | ||||||||||||||||||
| 495 | - | |||||||||||||||||||
| 496 | - | |||||||||||||||||||
| 497 | - | |||||||||||||||||||
| 498 | - | |||||||||||||||||||
| 499 | - | |||||||||||||||||||
| 500 | - | |||||||||||||||||||
| 501 | - | |||||||||||||||||||
| 502 | bool QSqlResult::hasOutValues() const | - | ||||||||||||||||||
| 503 | { | - | ||||||||||||||||||
| 504 | const QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 505 | if (d->types.isEmpty()) | - | ||||||||||||||||||
| 506 | return false; | - | ||||||||||||||||||
| 507 | QHash<int, QSql::ParamType>::ConstIterator it; | - | ||||||||||||||||||
| 508 | for (it = d->types.constBegin(); it != d->types.constEnd(); ++it) { | - | ||||||||||||||||||
| 509 | if (it.value() != QSql::In) | - | ||||||||||||||||||
| 510 | return true; | - | ||||||||||||||||||
| 511 | } | - | ||||||||||||||||||
| 512 | return false; | - | ||||||||||||||||||
| 513 | } | - | ||||||||||||||||||
| 514 | QSqlRecord QSqlResult::record() const | - | ||||||||||||||||||
| 515 | { | - | ||||||||||||||||||
| 516 | return QSqlRecord(); | - | ||||||||||||||||||
| 517 | } | - | ||||||||||||||||||
| 518 | QVariant QSqlResult::lastInsertId() const | - | ||||||||||||||||||
| 519 | { | - | ||||||||||||||||||
| 520 | return QVariant(); | - | ||||||||||||||||||
| 521 | } | - | ||||||||||||||||||
| 522 | - | |||||||||||||||||||
| 523 | - | |||||||||||||||||||
| 524 | - | |||||||||||||||||||
| 525 | void QSqlResult::virtual_hook(int, void *) | - | ||||||||||||||||||
| 526 | { | - | ||||||||||||||||||
| 527 | } | - | ||||||||||||||||||
| 528 | bool QSqlResult::execBatch(bool arrayBind) | - | ||||||||||||||||||
| 529 | { | - | ||||||||||||||||||
| 530 | (void)arrayBind;; | - | ||||||||||||||||||
| 531 | QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 532 | - | |||||||||||||||||||
| 533 | QVector<QVariant> values = d->values; | - | ||||||||||||||||||
| 534 | if (values.count() == 0) | - | ||||||||||||||||||
| 535 | return false; | - | ||||||||||||||||||
| 536 | for (int i = 0; i < values.at(0).toList().count(); ++i) { | - | ||||||||||||||||||
| 537 | for (int j = 0; j < values.count(); ++j) | - | ||||||||||||||||||
| 538 | bindValue(j, values.at(j).toList().at(i), QSql::In); | - | ||||||||||||||||||
| 539 | if (!exec()) | - | ||||||||||||||||||
| 540 | return false; | - | ||||||||||||||||||
| 541 | } | - | ||||||||||||||||||
| 542 | return true; | - | ||||||||||||||||||
| 543 | } | - | ||||||||||||||||||
| 544 | - | |||||||||||||||||||
| 545 | - | |||||||||||||||||||
| 546 | - | |||||||||||||||||||
| 547 | void QSqlResult::detachFromResultSet() | - | ||||||||||||||||||
| 548 | { | - | ||||||||||||||||||
| 549 | } | - | ||||||||||||||||||
| 550 | - | |||||||||||||||||||
| 551 | - | |||||||||||||||||||
| 552 | - | |||||||||||||||||||
| 553 | void QSqlResult::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy policy) | - | ||||||||||||||||||
| 554 | { | - | ||||||||||||||||||
| 555 | QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 556 | d->precisionPolicy = policy; | - | ||||||||||||||||||
| 557 | } | - | ||||||||||||||||||
| 558 | - | |||||||||||||||||||
| 559 | - | |||||||||||||||||||
| 560 | - | |||||||||||||||||||
| 561 | QSql::NumericalPrecisionPolicy QSqlResult::numericalPrecisionPolicy() const | - | ||||||||||||||||||
| 562 | { | - | ||||||||||||||||||
| 563 | const QSqlResultPrivate * const d = d_func(); | - | ||||||||||||||||||
| 564 | return d->precisionPolicy; | - | ||||||||||||||||||
| 565 | } | - | ||||||||||||||||||
| 566 | - | |||||||||||||||||||
| 567 | - | |||||||||||||||||||
| 568 | - | |||||||||||||||||||
| 569 | bool QSqlResult::nextResult() | - | ||||||||||||||||||
| 570 | { | - | ||||||||||||||||||
| 571 | return false; | - | ||||||||||||||||||
| 572 | } | - | ||||||||||||||||||
| 573 | QVariant QSqlResult::handle() const | - | ||||||||||||||||||
| 574 | { | - | ||||||||||||||||||
| 575 | return QVariant(); | - | ||||||||||||||||||
| 576 | } | - | ||||||||||||||||||
| 577 | - | |||||||||||||||||||
| 578 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |