kernel/qsqlcachedresult.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4static const uint initial_cache_size = 128; -
5 -
6class QSqlCachedResultPrivate -
7{ -
8public: -
9 QSqlCachedResultPrivate(); -
10 bool canSeek(int i) const; -
11 inline int cacheCount() const; -
12 void init(int count, bool fo); -
13 void cleanup(); -
14 int nextIndex(); -
15 void revertLast(); -
16 -
17 QSqlCachedResult::ValueCache cache; -
18 int rowCacheEnd; -
19 int colCount; -
20 bool forwardOnly; -
21 bool atEnd; -
22}; -
23 -
24QSqlCachedResultPrivate::QSqlCachedResultPrivate(): -
25 rowCacheEnd(0), colCount(0), forwardOnly(false), atEnd(false) -
26{ -
27}
executed: }
Execution Count:1924
1924
28 -
29void QSqlCachedResultPrivate::cleanup() -
30{ -
31 cache.clear(); -
32 forwardOnly = false; -
33 atEnd = false; -
34 colCount = 0; -
35 rowCacheEnd = 0; -
36}
executed: }
Execution Count:8611
8611
37 -
38void QSqlCachedResultPrivate::init(int count, bool fo) -
39{ -
40 qt_noop(); -
41 cleanup(); -
42 forwardOnly = fo; -
43 colCount = count; -
44 if (fo) {
evaluated: fo
TRUEFALSE
yes
Evaluation Count:638
yes
Evaluation Count:481
481-638
45 cache.resize(count); -
46 rowCacheEnd = count; -
47 } else {
executed: }
Execution Count:638
638
48 cache.resize(initial_cache_size * count); -
49 }
executed: }
Execution Count:481
481
50} -
51 -
52int QSqlCachedResultPrivate::nextIndex() -
53{ -
54 if (forwardOnly)
evaluated: forwardOnly
TRUEFALSE
yes
Evaluation Count:2500
yes
Evaluation Count:34594
2500-34594
55 return 0;
executed: return 0;
Execution Count:2500
2500
56 int newIdx = rowCacheEnd; -
57 if (newIdx + colCount > cache.size())
evaluated: newIdx + colCount > cache.size()
TRUEFALSE
yes
Evaluation Count:244
yes
Evaluation Count:34350
244-34350
58 cache.resize(qMin(cache.size() * 2, cache.size() + 10000));
executed: cache.resize(qMin(cache.size() * 2, cache.size() + 10000));
Execution Count:244
244
59 rowCacheEnd += colCount; -
60 -
61 return newIdx;
executed: return newIdx;
Execution Count:34594
34594
62} -
63 -
64bool QSqlCachedResultPrivate::canSeek(int i) const -
65{ -
66 if (forwardOnly || i < 0)
evaluated: forwardOnly
TRUEFALSE
yes
Evaluation Count:2501
yes
Evaluation Count:3376
partially evaluated: i < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3376
0-3376
67 return false;
executed: return false;
Execution Count:2501
2501
68 return rowCacheEnd >= (i + 1) * colCount;
executed: return rowCacheEnd >= (i + 1) * colCount;
Execution Count:3376
3376
69} -
70 -
71void QSqlCachedResultPrivate::revertLast() -
72{ -
73 if (forwardOnly)
evaluated: forwardOnly
TRUEFALSE
yes
Evaluation Count:569
yes
Evaluation Count:280
280-569
74 return;
executed: return;
Execution Count:569
569
75 rowCacheEnd -= colCount; -
76}
executed: }
Execution Count:280
280
77 -
78inline int QSqlCachedResultPrivate::cacheCount() const -
79{ -
80 qt_noop(); -
81 qt_noop(); -
82 return rowCacheEnd / colCount;
executed: return rowCacheEnd / colCount;
Execution Count:16
16
83} -
84 -
85 -
86 -
87QSqlCachedResult::QSqlCachedResult(const QSqlDriver * db): QSqlResult (db) -
88{ -
89 d = new QSqlCachedResultPrivate(); -
90}
executed: }
Execution Count:1924
1924
91 -
92QSqlCachedResult::~QSqlCachedResult() -
93{ -
94 delete d; -
95}
executed: }
Execution Count:1924
1924
96 -
97void QSqlCachedResult::init(int colCount) -
98{ -
99 d->init(colCount, isForwardOnly()); -
100}
executed: }
Execution Count:1119
1119
101 -
102bool QSqlCachedResult::fetch(int i) -
103{ -
104 if ((!isActive()) || (i < 0))
partially evaluated: (!isActive())
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2659
evaluated: (i < 0)
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:2657
0-2659
105 return false;
executed: return false;
Execution Count:2
2
106 if (at() == i)
evaluated: at() == i
TRUEFALSE
yes
Evaluation Count:1715
yes
Evaluation Count:942
942-1715
107 return true;
executed: return true;
Execution Count:1715
1715
108 if (d->forwardOnly) {
evaluated: d->forwardOnly
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:941
1-941
109 -
110 if (at() > i || at() == QSql::AfterLastRow)
partially evaluated: at() > i
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
partially evaluated: at() == QSql::AfterLastRow
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
111 return false;
never executed: return false;
0
112 while(at() < i - 1) {
evaluated: at() < i - 1
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:1
1-3
113 if (!gotoNext(d->cache, -1))
partially evaluated: !gotoNext(d->cache, -1)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
114 return false;
never executed: return false;
0
115 setAt(at() + 1); -
116 }
executed: }
Execution Count:3
3
117 if (!gotoNext(d->cache, 0))
partially evaluated: !gotoNext(d->cache, 0)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
118 return false;
never executed: return false;
0
119 setAt(at() + 1); -
120 return true;
executed: return true;
Execution Count:1
1
121 } -
122 if (d->canSeek(i)) {
evaluated: d->canSeek(i)
TRUEFALSE
yes
Evaluation Count:537
yes
Evaluation Count:404
404-537
123 setAt(i); -
124 return true;
executed: return true;
Execution Count:537
537
125 } -
126 if (d->rowCacheEnd > 0)
evaluated: d->rowCacheEnd > 0
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:391
13-391
127 setAt(d->cacheCount());
executed: setAt(d->cacheCount());
Execution Count:13
13
128 while (at() < i + 1) {
evaluated: at() < i + 1
TRUEFALSE
yes
Evaluation Count:34438
yes
Evaluation Count:132
132-34438
129 if (!cacheNext()) {
evaluated: !cacheNext()
TRUEFALSE
yes
Evaluation Count:272
yes
Evaluation Count:34166
272-34166
130 if (d->canSeek(i))
evaluated: d->canSeek(i)
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:270
2-270
131 break;
executed: break;
Execution Count:2
2
132 return false;
executed: return false;
Execution Count:270
270
133 } -
134 }
executed: }
Execution Count:34166
34166
135 setAt(i); -
136 -
137 return true;
executed: return true;
Execution Count:134
134
138} -
139 -
140bool QSqlCachedResult::fetchNext() -
141{ -
142 if (d->canSeek(at() + 1)) {
evaluated: d->canSeek(at() + 1)
TRUEFALSE
yes
Evaluation Count:1746
yes
Evaluation Count:2208
1746-2208
143 setAt(at() + 1); -
144 return true;
executed: return true;
Execution Count:1746
1746
145 } -
146 return cacheNext();
executed: return cacheNext();
Execution Count:2208
2208
147} -
148 -
149bool QSqlCachedResult::fetchPrevious() -
150{ -
151 return fetch(at() - 1);
executed: return fetch(at() - 1);
Execution Count:40
40
152} -
153 -
154bool QSqlCachedResult::fetchFirst() -
155{ -
156 if (d->forwardOnly && at() != QSql::BeforeFirstRow) {
evaluated: d->forwardOnly
TRUEFALSE
yes
Evaluation Count:626
yes
Evaluation Count:84
partially evaluated: at() != QSql::BeforeFirstRow
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:626
0-626
157 return false;
never executed: return false;
0
158 } -
159 if (d->canSeek(0)) {
evaluated: d->canSeek(0)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:709
1-709
160 setAt(0); -
161 return true;
executed: return true;
Execution Count:1
1
162 } -
163 return cacheNext();
executed: return cacheNext();
Execution Count:709
709
164} -
165 -
166bool QSqlCachedResult::fetchLast() -
167{ -
168 if (d->atEnd) {
evaluated: d->atEnd
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:6
3-6
169 if (d->forwardOnly)
partially evaluated: d->forwardOnly
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
170 return false;
never executed: return false;
0
171 else -
172 return fetch(d->cacheCount() - 1);
executed: return fetch(d->cacheCount() - 1);
Execution Count:3
3
173 } -
174 -
175 int i = at(); -
176 while (fetchNext())
evaluated: fetchNext()
TRUEFALSE
yes
Evaluation Count:22
yes
Evaluation Count:6
6-22
177 ++i;
executed: ++i;
Execution Count:22
22
178 if (d->forwardOnly && at() == QSql::AfterLastRow) {
evaluated: d->forwardOnly
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:4
partially evaluated: at() == QSql::AfterLastRow
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-4
179 setAt(i); -
180 return true;
executed: return true;
Execution Count:2
2
181 } else { -
182 return fetch(i);
executed: return fetch(i);
Execution Count:4
4
183 } -
184} -
185 -
186QVariant QSqlCachedResult::data(int i) -
187{ -
188 int idx = d->forwardOnly ? i : at() * d->colCount + i;
evaluated: d->forwardOnly
TRUEFALSE
yes
Evaluation Count:5889
yes
Evaluation Count:3473
3473-5889
189 if (i >= d->colCount || i < 0 || at() < 0 || idx >= d->rowCacheEnd)
partially evaluated: i >= d->colCount
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:9362
partially evaluated: i < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:9362
partially evaluated: at() < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:9361
partially evaluated: idx >= d->rowCacheEnd
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:9361
0-9362
190 return QVariant();
never executed: return QVariant();
0
191 -
192 return d->cache.at(idx);
executed: return d->cache.at(idx);
Execution Count:9361
9361
193} -
194 -
195bool QSqlCachedResult::isNull(int i) -
196{ -
197 int idx = d->forwardOnly ? i : at() * d->colCount + i;
partially evaluated: d->forwardOnly
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5
0-5
198 if (i > d->colCount || i < 0 || at() < 0 || idx >= d->rowCacheEnd)
partially evaluated: i > d->colCount
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5
partially evaluated: i < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5
partially evaluated: at() < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5
partially evaluated: idx >= d->rowCacheEnd
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5
0-5
199 return true;
never executed: return true;
0
200 -
201 return d->cache.at(idx).isNull();
executed: return d->cache.at(idx).isNull();
Execution Count:5
5
202} -
203 -
204void QSqlCachedResult::cleanup() -
205{ -
206 setAt(QSql::BeforeFirstRow); -
207 setActive(false); -
208 d->cleanup(); -
209}
executed: }
Execution Count:7492
7492
210 -
211void QSqlCachedResult::clearValues() -
212{ -
213 setAt(QSql::BeforeFirstRow); -
214 d->rowCacheEnd = 0; -
215 d->atEnd = false; -
216}
executed: }
Execution Count:119104
119104
217 -
218bool QSqlCachedResult::cacheNext() -
219{ -
220 if (d->atEnd)
evaluated: d->atEnd
TRUEFALSE
yes
Evaluation Count:261
yes
Evaluation Count:37094
261-37094
221 return false;
executed: return false;
Execution Count:261
261
222 -
223 if(isForwardOnly()) {
evaluated: isForwardOnly()
TRUEFALSE
yes
Evaluation Count:2500
yes
Evaluation Count:34594
2500-34594
224 d->cache.clear(); -
225 d->cache.resize(d->colCount); -
226 }
executed: }
Execution Count:2500
2500
227 -
228 if (!gotoNext(d->cache, d->nextIndex())) {
evaluated: !gotoNext(d->cache, d->nextIndex())
TRUEFALSE
yes
Evaluation Count:849
yes
Evaluation Count:36245
849-36245
229 d->revertLast(); -
230 d->atEnd = true; -
231 return false;
executed: return false;
Execution Count:849
849
232 } -
233 setAt(at() + 1); -
234 return true;
executed: return true;
Execution Count:36245
36245
235} -
236 -
237int QSqlCachedResult::colCount() const -
238{ -
239 return d->colCount;
never executed: return d->colCount;
0
240} -
241 -
242QSqlCachedResult::ValueCache &QSqlCachedResult::cache() -
243{ -
244 return d->cache;
never executed: return d->cache;
0
245} -
246 -
247void QSqlCachedResult::virtual_hook(int id, void *data) -
248{ -
249 QSqlResult::virtual_hook(id, data); -
250}
never executed: }
0
251 -
252void QSqlCachedResult::detachFromResultSet() -
253{ -
254 cleanup(); -
255}
never executed: }
0
256 -
257void QSqlCachedResult::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy policy) -
258{ -
259 QSqlResult::setNumericalPrecisionPolicy(policy); -
260 cleanup(); -
261}
executed: }
Execution Count:2787
2787
262 -
263 -
264 -
265 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial