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) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtSql module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include "private/qsqlcachedresult_p.h"-
35-
36#include <qvariant.h>-
37#include <qdatetime.h>-
38#include <qvector.h>-
39-
40QT_BEGIN_NAMESPACE-
41-
42/*-
43 QSqlCachedResult is a convenience class for databases that only allow-
44 forward only fetching. It will cache all the results so we can iterate-
45 backwards over the results again.-
46-
47 All you need to do is to inherit from QSqlCachedResult and reimplement-
48 gotoNext(). gotoNext() will have a reference to the internal cache and-
49 will give you an index where you can start filling in your data. Special-
50 case: If the user actually wants a forward-only query, idx will be -1-
51 to indicate that we are not interested in the actual values.-
52*/-
53-
54static const uint initial_cache_size = 128;-
55-
56class QSqlCachedResultPrivate-
57{-
58public:-
59 QSqlCachedResultPrivate();-
60 bool canSeek(int i) const;-
61 inline int cacheCount() const;-
62 void init(int count, bool fo);-
63 void cleanup();-
64 int nextIndex();-
65 void revertLast();-
66-
67 QSqlCachedResult::ValueCache cache;-
68 int rowCacheEnd;-
69 int colCount;-
70 bool forwardOnly;-
71 bool atEnd;-
72};-
73-
74QSqlCachedResultPrivate::QSqlCachedResultPrivate():-
75 rowCacheEnd(0), colCount(0), forwardOnly(false), atEnd(false)-
76{-
77}
executed 1932 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
1932
78-
79void QSqlCachedResultPrivate::cleanup()-
80{-
81 cache.clear();-
82 forwardOnly = false;-
83 atEnd = false;-
84 colCount = 0;-
85 rowCacheEnd = 0;-
86}
executed 8645 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
8645
87-
88void QSqlCachedResultPrivate::init(int count, bool fo)-
89{-
90 Q_ASSERT(count);-
91 cleanup();-
92 forwardOnly = fo;-
93 colCount = count;-
94 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 486 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
486-639
95 cache.resize(count);-
96 rowCacheEnd = count;-
97 } 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
98 cache.resize(initial_cache_size * count);-
99 }
executed 486 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
486
100}-
101-
102int QSqlCachedResultPrivate::nextIndex()-
103{-
104 if (forwardOnly)
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 34600 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
2238-34600
105 return 0;
executed 2238 times by 8 tests: return 0;
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
2238
106 int newIdx = rowCacheEnd;-
107 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 34356 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
244-34356
108 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
109 rowCacheEnd += colCount;-
110-
111 return newIdx;
executed 34600 times by 8 tests: return newIdx;
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
34600
112}-
113-
114bool QSqlCachedResultPrivate::canSeek(int i) const-
115{-
116 if (forwardOnly || i < 0)
forwardOnlyDescription
TRUEevaluated 2239 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
FALSEevaluated 3389 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 3389 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
0-3389
117 return false;
executed 2239 times by 8 tests: return false;
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
2239
118 return rowCacheEnd >= (i + 1) * colCount;
executed 3389 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
3389
119}-
120-
121void QSqlCachedResultPrivate::revertLast()-
122{-
123 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
124 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
125 rowCacheEnd -= colCount;-
126}
executed 280 times by 6 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
280
127-
128inline int QSqlCachedResultPrivate::cacheCount() const-
129{-
130 Q_ASSERT(!forwardOnly);-
131 Q_ASSERT(colCount);-
132 return rowCacheEnd / colCount;
executed 17 times by 3 tests: return rowCacheEnd / colCount;
Executed by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
17
133}-
134-
135//////////////-
136-
137QSqlCachedResult::QSqlCachedResult(const QSqlDriver * db): QSqlResult (db)-
138{-
139 d = new QSqlCachedResultPrivate();-
140}
executed 1932 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
1932
141-
142QSqlCachedResult::~QSqlCachedResult()-
143{-
144 delete d;-
145}
executed 1932 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
1932
146-
147void QSqlCachedResult::init(int colCount)-
148{-
149 d->init(colCount, isForwardOnly());-
150}
executed 1125 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
1125
151-
152bool QSqlCachedResult::fetch(int i)-
153{-
154 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
155 return false;
executed 2 times by 1 test: return false;
Executed by:
  • tst_QSqlQuery
2
156 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
157 return true;
executed 1716 times by 5 tests: return true;
Executed by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
1716
158 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
159 // speed hack - do not copy values if not needed-
160 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
161 return false;
never executed: return false;
0
162 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
163 if (!gotoNext(d->cache, -1))
!gotoNext(d->cache, -1)Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QSqlQuery
0-3
164 return false;
never executed: return false;
0
165 setAt(at() + 1);-
166 }
executed 3 times by 1 test: end of block
Executed by:
  • tst_QSqlQuery
3
167 if (!gotoNext(d->cache, 0))
!gotoNext(d->cache, 0)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSqlQuery
0-1
168 return false;
never executed: return false;
0
169 setAt(at() + 1);-
170 return true;
executed 1 time by 1 test: return true;
Executed by:
  • tst_QSqlQuery
1
171 }-
172 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
173 setAt(i);-
174 return true;
executed 539 times by 5 tests: return true;
Executed by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
539
175 }-
176 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
177 setAt(d->cacheCount());
executed 13 times by 3 tests: setAt(d->cacheCount());
Executed by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
13
178 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
179 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
180 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
181 break;
executed 2 times by 1 test: break;
Executed by:
  • tst_QSqlQuery
2
182 return false;
executed 270 times by 5 tests: return false;
Executed by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
270
183 }-
184 }
executed 34166 times by 5 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
34166
185 setAt(i);-
186-
187 return true;
executed 134 times by 4 tests: return true;
Executed by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlTableModel
134
188}-
189-
190bool QSqlCachedResult::fetchNext()-
191{-
192 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 1959 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
1750-1959
193 setAt(at() + 1);-
194 return true;
executed 1750 times by 5 tests: return true;
Executed by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
1750
195 }-
196 return cacheNext();
executed 1959 times by 8 tests: return cacheNext();
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
1959
197}-
198-
199bool QSqlCachedResult::fetchPrevious()-
200{-
201 return fetch(at() - 1);
executed 40 times by 3 tests: return fetch(at() - 1);
Executed by:
  • tst_QSqlQuery
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
40
202}-
203-
204bool QSqlCachedResult::fetchFirst()-
205{-
206 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 89 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
207 return false;
never executed: return false;
0
208 }-
209 if (d->canSeek(0)) {
d->canSeek(0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSqlQuery
FALSEevaluated 703 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
1-703
210 setAt(0);-
211 return true;
executed 1 time by 1 test: return true;
Executed by:
  • tst_QSqlQuery
1
212 }-
213 return cacheNext();
executed 703 times by 8 tests: return cacheNext();
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
703
214}-
215-
216bool QSqlCachedResult::fetchLast()-
217{-
218 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
219 if (d->forwardOnly)
d->forwardOnlyDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QSqlQuery
0-4
220 return false;
never executed: return false;
0
221 else-
222 return fetch(d->cacheCount() - 1);
executed 4 times by 1 test: return fetch(d->cacheCount() - 1);
Executed by:
  • tst_QSqlQuery
4
223 }-
224-
225 int i = at();-
226 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
227 ++i; /* brute force */
executed 22 times by 1 test: ++i;
Executed by:
  • tst_QSqlQuery
22
228 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
229 setAt(i);-
230 return true;
executed 2 times by 1 test: return true;
Executed by:
  • tst_QSqlQuery
2
231 } else {-
232 return fetch(i);
executed 4 times by 1 test: return fetch(i);
Executed by:
  • tst_QSqlQuery
4
233 }-
234}-
235-
236QVariant QSqlCachedResult::data(int i)-
237{-
238 int idx = d->forwardOnly ? i : at() * d->colCount + i;
d->forwardOnlyDescription
TRUEevaluated 5650 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
FALSEevaluated 3492 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
3492-5650
239 if (i >= d->colCount || i < 0 || at() < 0 || idx >= d->rowCacheEnd)
i >= d->colCountDescription
TRUEnever evaluated
FALSEevaluated 9142 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 9142 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 9142 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 9142 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
0-9142
240 return QVariant();
never executed: return QVariant();
0
241-
242 return d->cache.at(idx);
executed 9142 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
9142
243}-
244-
245bool QSqlCachedResult::isNull(int i)-
246{-
247 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
248 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
249 return true;
executed 1 time by 1 test: return true;
Executed by:
  • tst_QSqlQuery
1
250-
251 return d->cache.at(idx).isNull();
executed 9 times by 1 test: return d->cache.at(idx).isNull();
Executed by:
  • tst_QSqlQuery
9
252}-
253-
254void QSqlCachedResult::cleanup()-
255{-
256 setAt(QSql::BeforeFirstRow);-
257 setActive(false);-
258 d->cleanup();-
259}
executed 7520 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
7520
260-
261void QSqlCachedResult::clearValues()-
262{-
263 setAt(QSql::BeforeFirstRow);-
264 d->rowCacheEnd = 0;-
265 d->atEnd = false;-
266}
executed 119114 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
119114
267-
268bool QSqlCachedResult::cacheNext()-
269{-
270 if (d->atEnd)
d->atEndDescription
TRUEevaluated 262 times by 5 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
FALSEevaluated 36838 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
262-36838
271 return false;
executed 262 times by 5 tests: return false;
Executed by:
  • tst_QItemModel
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
262
272-
273 if(isForwardOnly()) {
isForwardOnly()Description
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 34600 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
2238-34600
274 d->cache.clear();-
275 d->cache.resize(d->colCount);-
276 }
executed 2238 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
2238
277-
278 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 36000 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
838-36000
279 d->revertLast();-
280 d->atEnd = true;-
281 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
282 }-
283 setAt(at() + 1);-
284 return true;
executed 36000 times by 8 tests: return true;
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
36000
285}-
286-
287int QSqlCachedResult::colCount() const-
288{-
289 return d->colCount;
never executed: return d->colCount;
0
290}-
291-
292QSqlCachedResult::ValueCache &QSqlCachedResult::cache()-
293{-
294 return d->cache;
never executed: return d->cache;
0
295}-
296-
297void QSqlCachedResult::virtual_hook(int id, void *data)-
298{-
299 QSqlResult::virtual_hook(id, data);-
300}
never executed: end of block
0
301-
302void QSqlCachedResult::detachFromResultSet()-
303{-
304 cleanup();-
305}
never executed: end of block
0
306-
307void QSqlCachedResult::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy policy)-
308{-
309 QSqlResult::setNumericalPrecisionPolicy(policy);-
310 cleanup();-
311}
executed 2797 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
2797
312-
313-
314QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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