qsqlcachedresult.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/sql/kernel/qsqlcachedresult.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
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 "private/qsqlcachedresult_p.h"-
41-
42#include <qvariant.h>-
43#include <qdatetime.h>-
44#include <qvector.h>-
45#include <QtSql/private/qsqldriver_p.h>-
46-
47QT_BEGIN_NAMESPACE-
48-
49/*-
50 QSqlCachedResult is a convenience class for databases that only allow-
51 forward only fetching. It will cache all the results so we can iterate-
52 backwards over the results again.-
53-
54 All you need to do is to inherit from QSqlCachedResult and reimplement-
55 gotoNext(). gotoNext() will have a reference to the internal cache and-
56 will give you an index where you can start filling in your data. Special-
57 case: If the user actually wants a forward-only query, idx will be -1-
58 to indicate that we are not interested in the actual values.-
59*/-
60-
61static const uint initial_cache_size = 128;-
62-
63QSqlCachedResultPrivate::QSqlCachedResultPrivate(QSqlCachedResult *q, const QSqlDriver *drv)-
64 : QSqlResultPrivate(q, drv),-
65 rowCacheEnd(0),-
66 colCount(0),-
67 atEnd(false)-
68{-
69}
executed 1930 times by 9 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
1930
70-
71void QSqlCachedResultPrivate::cleanup()-
72{-
73 cache.clear();-
74 atEnd = false;-
75 colCount = 0;-
76 rowCacheEnd = 0;-
77}
executed 8636 times by 9 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
8636
78-
79void QSqlCachedResultPrivate::init(int count, bool fo)-
80{-
81 Q_ASSERT(count);-
82 cleanup();-
83 forwardOnly = fo;-
84 colCount = count;-
85 if (fo) {
foDescription
TRUEevaluated 639 times by 9 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
FALSEevaluated 485 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
485-639
86 cache.resize(count);-
87 rowCacheEnd = count;-
88 } else {
executed 639 times by 9 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
639
89 cache.resize(initial_cache_size * count);-
90 }
executed 485 times by 8 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
485
91}-
92-
93int QSqlCachedResultPrivate::nextIndex()-
94{-
95 if (forwardOnly)
forwardOnlyDescription
TRUEevaluated 2237 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
FALSEevaluated 34599 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
2237-34599
96 return 0;
executed 2237 times by 8 tests: return 0;
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
2237
97 int newIdx = rowCacheEnd;-
98 if (newIdx + colCount > cache.size())
newIdx + colCo...> cache.size()Description
TRUEevaluated 244 times by 3 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlQueryModel
  • tst_QSqlTableModel
FALSEevaluated 34355 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
244-34355
99 cache.resize(qMin(cache.size() * 2, cache.size() + 10000));
executed 244 times by 3 tests: cache.resize(qMin(cache.size() * 2, cache.size() + 10000));
Executed by:
  • tst_QItemModel
  • tst_QSqlQueryModel
  • tst_QSqlTableModel
244
100 rowCacheEnd += colCount;-
101-
102 return newIdx;
executed 34599 times by 8 tests: return newIdx;
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
34599
103}-
104-
105bool QSqlCachedResultPrivate::canSeek(int i) const-
106{-
107 if (forwardOnly || i < 0)
forwardOnlyDescription
TRUEevaluated 2238 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
FALSEevaluated 3388 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
i < 0Description
TRUEnever evaluated
FALSEevaluated 3388 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
0-3388
108 return false;
executed 2238 times by 8 tests: return false;
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
2238
109 return rowCacheEnd >= (i + 1) * colCount;
executed 3388 times by 8 tests: return rowCacheEnd >= (i + 1) * colCount;
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
3388
110}-
111-
112void QSqlCachedResultPrivate::revertLast()-
113{-
114 if (forwardOnly)
forwardOnlyDescription
TRUEevaluated 558 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
FALSEevaluated 280 times by 6 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
280-558
115 return;
executed 558 times by 8 tests: return;
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
558
116 rowCacheEnd -= colCount;-
117}
executed 280 times by 6 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
280
118-
119inline int QSqlCachedResultPrivate::cacheCount() const-
120{-
121 Q_ASSERT(!forwardOnly);-
122 Q_ASSERT(colCount);-
123 return rowCacheEnd / colCount;
executed 17 times by 3 tests: return rowCacheEnd / colCount;
Executed by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
17
124}-
125-
126//////////////-
127-
128QSqlCachedResult::QSqlCachedResult(QSqlCachedResultPrivate &d)-
129 : QSqlResult(d)-
130{-
131}
executed 1930 times by 9 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
1930
132-
133void QSqlCachedResult::init(int colCount)-
134{-
135 Q_D(QSqlCachedResult);-
136 d->init(colCount, isForwardOnly());-
137}
executed 1124 times by 9 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
1124
138-
139bool QSqlCachedResult::fetch(int i)-
140{-
141 Q_D(QSqlCachedResult);-
142 if ((!isActive()) || (i < 0))
(!isActive())Description
TRUEnever evaluated
FALSEevaluated 2662 times by 5 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
(i < 0)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QSqlQuery
FALSEevaluated 2660 times by 5 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
0-2662
143 return false;
executed 2 times by 1 test: return false;
Executed by:
  • tst_QSqlQuery
2
144 if (at() == i)
at() == iDescription
TRUEevaluated 1716 times by 5 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
FALSEevaluated 944 times by 5 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
944-1716
145 return true;
executed 1716 times by 5 tests: return true;
Executed by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
1716
146 if (d->forwardOnly) {
d->forwardOnlyDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSqlQuery
FALSEevaluated 943 times by 5 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
1-943
147 // speed hack - do not copy values if not needed-
148 if (at() > i || at() == QSql::AfterLastRow)
at() > iDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSqlQuery
at() == QSql::AfterLastRowDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSqlQuery
0-1
149 return false;
never executed: return false;
0
150 while(at() < i - 1) {
at() < i - 1Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QSqlQuery
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSqlQuery
1-3
151 if (!gotoNext(d->cache, -1))
!gotoNext(d->cache, -1)Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QSqlQuery
0-3
152 return false;
never executed: return false;
0
153 setAt(at() + 1);-
154 }
executed 3 times by 1 test: end of block
Executed by:
  • tst_QSqlQuery
3
155 if (!gotoNext(d->cache, 0))
!gotoNext(d->cache, 0)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSqlQuery
0-1
156 return false;
never executed: return false;
0
157 setAt(at() + 1);-
158 return true;
executed 1 time by 1 test: return true;
Executed by:
  • tst_QSqlQuery
1
159 }-
160 if (d->canSeek(i)) {
d->canSeek(i)Description
TRUEevaluated 539 times by 5 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
FALSEevaluated 404 times by 5 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
404-539
161 setAt(i);-
162 return true;
executed 539 times by 5 tests: return true;
Executed by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
539
163 }-
164 if (d->rowCacheEnd > 0)
d->rowCacheEnd > 0Description
TRUEevaluated 13 times by 3 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
FALSEevaluated 391 times by 5 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
13-391
165 setAt(d->cacheCount());
executed 13 times by 3 tests: setAt(d->cacheCount());
Executed by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
13
166 while (at() < i + 1) {
at() < i + 1Description
TRUEevaluated 34438 times by 5 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
FALSEevaluated 132 times by 4 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlTableModel
132-34438
167 if (!cacheNext()) {
!cacheNext()Description
TRUEevaluated 272 times by 5 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
FALSEevaluated 34166 times by 5 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
272-34166
168 if (d->canSeek(i))
d->canSeek(i)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QSqlQuery
FALSEevaluated 270 times by 5 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
2-270
169 break;
executed 2 times by 1 test: break;
Executed by:
  • tst_QSqlQuery
2
170 return false;
executed 270 times by 5 tests: return false;
Executed by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
270
171 }-
172 }
executed 34166 times by 5 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
34166
173 setAt(i);-
174-
175 return true;
executed 134 times by 4 tests: return true;
Executed by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlTableModel
134
176}-
177-
178bool QSqlCachedResult::fetchNext()-
179{-
180 Q_D(QSqlCachedResult);-
181 if (d->canSeek(at() + 1)) {
d->canSeek(at() + 1)Description
TRUEevaluated 1750 times by 5 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
FALSEevaluated 1958 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
1750-1958
182 setAt(at() + 1);-
183 return true;
executed 1750 times by 5 tests: return true;
Executed by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
1750
184 }-
185 return cacheNext();
executed 1958 times by 8 tests: return cacheNext();
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
1958
186}-
187-
188bool QSqlCachedResult::fetchPrevious()-
189{-
190 return fetch(at() - 1);
executed 40 times by 3 tests: return fetch(at() - 1);
Executed by:
  • tst_QSqlQuery
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
40
191}-
192-
193bool QSqlCachedResult::fetchFirst()-
194{-
195 Q_D(QSqlCachedResult);-
196 if (d->forwardOnly && at() != QSql::BeforeFirstRow) {
d->forwardOnlyDescription
TRUEevaluated 615 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
FALSEevaluated 88 times by 4 tests
Evaluated by:
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlThread
at() != QSql::BeforeFirstRowDescription
TRUEnever evaluated
FALSEevaluated 615 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
0-615
197 return false;
never executed: return false;
0
198 }-
199 if (d->canSeek(0)) {
d->canSeek(0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSqlQuery
FALSEevaluated 702 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
1-702
200 setAt(0);-
201 return true;
executed 1 time by 1 test: return true;
Executed by:
  • tst_QSqlQuery
1
202 }-
203 return cacheNext();
executed 702 times by 8 tests: return cacheNext();
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
702
204}-
205-
206bool QSqlCachedResult::fetchLast()-
207{-
208 Q_D(QSqlCachedResult);-
209 if (d->atEnd) {
d->atEndDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QSqlQuery
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tst_QSqlQuery
4-6
210 if (d->forwardOnly)
d->forwardOnlyDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QSqlQuery
0-4
211 return false;
never executed: return false;
0
212 else-
213 return fetch(d->cacheCount() - 1);
executed 4 times by 1 test: return fetch(d->cacheCount() - 1);
Executed by:
  • tst_QSqlQuery
4
214 }-
215-
216 int i = at();-
217 while (fetchNext())
fetchNext()Description
TRUEevaluated 22 times by 1 test
Evaluated by:
  • tst_QSqlQuery
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tst_QSqlQuery
6-22
218 ++i; /* brute force */
executed 22 times by 1 test: ++i;
Executed by:
  • tst_QSqlQuery
22
219 if (d->forwardOnly && at() == QSql::AfterLastRow) {
d->forwardOnlyDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QSqlQuery
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QSqlQuery
at() == QSql::AfterLastRowDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QSqlQuery
FALSEnever evaluated
0-4
220 setAt(i);-
221 return true;
executed 2 times by 1 test: return true;
Executed by:
  • tst_QSqlQuery
2
222 } else {-
223 return fetch(i);
executed 4 times by 1 test: return fetch(i);
Executed by:
  • tst_QSqlQuery
4
224 }-
225}-
226-
227QVariant QSqlCachedResult::data(int i)-
228{-
229 Q_D(const QSqlCachedResult);-
230 int idx = d->forwardOnly ? i : at() * d->colCount + i;
d->forwardOnlyDescription
TRUEevaluated 5649 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
FALSEevaluated 3489 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
3489-5649
231 if (i >= d->colCount || i < 0 || at() < 0 || idx >= d->rowCacheEnd)
i >= d->colCountDescription
TRUEnever evaluated
FALSEevaluated 9138 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
i < 0Description
TRUEnever evaluated
FALSEevaluated 9138 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
at() < 0Description
TRUEnever evaluated
FALSEevaluated 9138 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
idx >= d->rowCacheEndDescription
TRUEnever evaluated
FALSEevaluated 9138 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
0-9138
232 return QVariant();
never executed: return QVariant();
0
233-
234 return d->cache.at(idx);
executed 9138 times by 8 tests: return d->cache.at(idx);
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
9138
235}-
236-
237bool QSqlCachedResult::isNull(int i)-
238{-
239 Q_D(const QSqlCachedResult);-
240 int idx = d->forwardOnly ? i : at() * d->colCount + i;
d->forwardOnlyDescription
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • tst_QSqlQuery
0-10
241 if (i >= d->colCount || i < 0 || at() < 0 || idx >= d->rowCacheEnd)
i >= d->colCountDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSqlQuery
FALSEevaluated 9 times by 1 test
Evaluated by:
  • tst_QSqlQuery
i < 0Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • tst_QSqlQuery
at() < 0Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • tst_QSqlQuery
idx >= d->rowCacheEndDescription
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • tst_QSqlQuery
0-9
242 return true;
executed 1 time by 1 test: return true;
Executed by:
  • tst_QSqlQuery
1
243-
244 return d->cache.at(idx).isNull();
executed 9 times by 1 test: return d->cache.at(idx).isNull();
Executed by:
  • tst_QSqlQuery
9
245}-
246-
247void QSqlCachedResult::cleanup()-
248{-
249 Q_D(QSqlCachedResult);-
250 setAt(QSql::BeforeFirstRow);-
251 setActive(false);-
252 d->cleanup();-
253}
executed 7512 times by 9 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
7512
254-
255void QSqlCachedResult::clearValues()-
256{-
257 Q_D(QSqlCachedResult);-
258 setAt(QSql::BeforeFirstRow);-
259 d->rowCacheEnd = 0;-
260 d->atEnd = false;-
261}
executed 119111 times by 9 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
119111
262-
263bool QSqlCachedResult::cacheNext()-
264{-
265 Q_D(QSqlCachedResult);-
266 if (d->atEnd)
d->atEndDescription
TRUEevaluated 262 times by 5 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
FALSEevaluated 36836 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
262-36836
267 return false;
executed 262 times by 5 tests: return false;
Executed by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
262
268-
269 if(isForwardOnly()) {
isForwardOnly()Description
TRUEevaluated 2237 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
FALSEevaluated 34599 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
2237-34599
270 d->cache.resize(d->colCount);-
271 }
executed 2237 times by 8 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
2237
272-
273 if (!gotoNext(d->cache, d->nextIndex())) {
!gotoNext(d->c...->nextIndex())Description
TRUEevaluated 838 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
FALSEevaluated 35998 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
838-35998
274 d->revertLast();-
275 d->atEnd = true;-
276 return false;
executed 838 times by 8 tests: return false;
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
838
277 }-
278 setAt(at() + 1);-
279 return true;
executed 35998 times by 8 tests: return true;
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
35998
280}-
281-
282int QSqlCachedResult::colCount() const-
283{-
284 Q_D(const QSqlCachedResult);-
285 return d->colCount;
never executed: return d->colCount;
0
286}-
287-
288QSqlCachedResult::ValueCache &QSqlCachedResult::cache()-
289{-
290 Q_D(QSqlCachedResult);-
291 return d->cache;
never executed: return d->cache;
0
292}-
293-
294void QSqlCachedResult::virtual_hook(int id, void *data)-
295{-
296 QSqlResult::virtual_hook(id, data);-
297}
never executed: end of block
0
298-
299void QSqlCachedResult::detachFromResultSet()-
300{-
301 cleanup();-
302}
never executed: end of block
0
303-
304void QSqlCachedResult::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy policy)-
305{-
306 QSqlResult::setNumericalPrecisionPolicy(policy);-
307 cleanup();-
308}
executed 2794 times by 9 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
2794
309-
310-
311QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9