kernel/qsqlresult.cpp

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

Generated by Squish Coco Non-Commercial