Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/sql/kernel/qsqlcachedresult.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||||||||
2 | - | |||||||||||||||||||||||||
3 | - | |||||||||||||||||||||||||
4 | static const uint initial_cache_size = 128; | - | ||||||||||||||||||||||||
5 | - | |||||||||||||||||||||||||
classQSqlCachedResultPrivate{ | ||||||||||||||||||||||||||
public:::QSqlCachedResultPrivate(); | ||||||||||||||||||||||||||
bool canSeek(int i) const; | ||||||||||||||||||||||||||
inline int cacheCount()QSqlCachedResult *q, const ; | ||||||||||||||||||||||||||
void initQSqlDriver *drv) | ||||||||||||||||||||||||||
7 | : QSqlResultPrivate(int countq, bool fo); | - | ||||||||||||||||||||||||
void cleanup(); | ||||||||||||||||||||||||||
int nextIndex(); | ||||||||||||||||||||||||||
void revertLast(); | ||||||||||||||||||||||||||
QSqlCachedResult::ValueCache cache; | ||||||||||||||||||||||||||
int rowCacheEnd; | ||||||||||||||||||||||||||
int colCount; | ||||||||||||||||||||||||||
bool forwardOnly; | ||||||||||||||||||||||||||
bool atEnd; | ||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
QSqlCachedResultPrivate::QSqlCachedResultPrivate():drv), | ||||||||||||||||||||||||||
8 | rowCacheEnd(0), | - | ||||||||||||||||||||||||
9 | colCount(0), forwardOnly(false), | - | ||||||||||||||||||||||||
10 | atEnd(false) | - | ||||||||||||||||||||||||
11 | { | - | ||||||||||||||||||||||||
12 | } executed 1930 times by 9 tests: end of block Executed by:
| 1930 | ||||||||||||||||||||||||
13 | - | |||||||||||||||||||||||||
14 | void QSqlCachedResultPrivate::cleanup() | - | ||||||||||||||||||||||||
15 | { | - | ||||||||||||||||||||||||
16 | cache.clear(); | - | ||||||||||||||||||||||||
17 | forwardOnly = false;atEnd = false; | - | ||||||||||||||||||||||||
18 | colCount = 0; | - | ||||||||||||||||||||||||
19 | rowCacheEnd = 0; | - | ||||||||||||||||||||||||
20 | } executed 8636 times by 9 tests: end of block Executed by:
| 8636 | ||||||||||||||||||||||||
21 | - | |||||||||||||||||||||||||
22 | void QSqlCachedResultPrivate::init(int count, bool fo) | - | ||||||||||||||||||||||||
23 | { | - | ||||||||||||||||||||||||
24 | ((!(count)) ? qt_assert("count",__FILE__,9081) : qt_noop()); | - | ||||||||||||||||||||||||
25 | cleanup(); | - | ||||||||||||||||||||||||
26 | forwardOnly = fo; | - | ||||||||||||||||||||||||
27 | colCount = count; | - | ||||||||||||||||||||||||
28 | if (fo) { | - | ||||||||||||||||||||||||
29 | cache.resize(count); | - | ||||||||||||||||||||||||
30 | rowCacheEnd = count; | - | ||||||||||||||||||||||||
31 | } else { | - | ||||||||||||||||||||||||
32 | cache.resize(initial_cache_size * count); | - | ||||||||||||||||||||||||
33 | } | - | ||||||||||||||||||||||||
34 | } | - | ||||||||||||||||||||||||
35 | - | |||||||||||||||||||||||||
36 | int QSqlCachedResultPrivate::nextIndex() | - | ||||||||||||||||||||||||
37 | { | - | ||||||||||||||||||||||||
38 | if (forwardOnly) | - | ||||||||||||||||||||||||
39 | return 0; | - | ||||||||||||||||||||||||
40 | int newIdx = rowCacheEnd; | - | ||||||||||||||||||||||||
41 | if (newIdx + colCount > cache.size()) | - | ||||||||||||||||||||||||
42 | cache.resize(qMin(cache.size() * 2, cache.size() + 10000)); | - | ||||||||||||||||||||||||
43 | rowCacheEnd += colCount; | - | ||||||||||||||||||||||||
44 | - | |||||||||||||||||||||||||
45 | return newIdx; | - | ||||||||||||||||||||||||
46 | } | - | ||||||||||||||||||||||||
47 | - | |||||||||||||||||||||||||
48 | bool QSqlCachedResultPrivate::canSeek(int i) const | - | ||||||||||||||||||||||||
49 | { | - | ||||||||||||||||||||||||
50 | if (forwardOnly || i < 0) | - | ||||||||||||||||||||||||
51 | return false; | - | ||||||||||||||||||||||||
52 | return rowCacheEnd >= (i + 1) * colCount; | - | ||||||||||||||||||||||||
53 | } | - | ||||||||||||||||||||||||
54 | - | |||||||||||||||||||||||||
55 | void QSqlCachedResultPrivate::revertLast() | - | ||||||||||||||||||||||||
56 | { | - | ||||||||||||||||||||||||
57 | if (forwardOnly) | - | ||||||||||||||||||||||||
58 | return; | - | ||||||||||||||||||||||||
59 | rowCacheEnd -= colCount; | - | ||||||||||||||||||||||||
60 | } | - | ||||||||||||||||||||||||
61 | - | |||||||||||||||||||||||||
62 | inline int QSqlCachedResultPrivate::cacheCount() const | - | ||||||||||||||||||||||||
63 | { | - | ||||||||||||||||||||||||
64 | ((!(!forwardOnly)) ? qt_assert("!forwardOnly",__FILE__,130121) : qt_noop()); | - | ||||||||||||||||||||||||
65 | ((!(colCount)) ? qt_assert("colCount",__FILE__,131122) : qt_noop()); | - | ||||||||||||||||||||||||
66 | return rowCacheEnd / colCount; | - | ||||||||||||||||||||||||
67 | } | - | ||||||||||||||||||||||||
68 | - | |||||||||||||||||||||||||
69 | - | |||||||||||||||||||||||||
70 | - | |||||||||||||||||||||||||
71 | QSqlCachedResult::QSqlCachedResult(const QSqlDriver * db):QSqlCachedResultPrivate &d) | - | ||||||||||||||||||||||||
72 | : QSqlResult(db) | - | ||||||||||||||||||||||||
{d= new QSqlCachedResultPrivate(); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
QSqlCachedResult::~QSqlCachedResult()) | ||||||||||||||||||||||||||
73 | { | - | ||||||||||||||||||||||||
delete d;} executed 1930 times by 9 tests: end of block Executed by:
| ||||||||||||||||||||||||||
75 | - | |||||||||||||||||||||||||
76 | void QSqlCachedResult::init(int colCount) | - | ||||||||||||||||||||||||
77 | { | - | ||||||||||||||||||||||||
78 | QSqlCachedResultPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
79 | d->init(colCount, isForwardOnly()); | - | ||||||||||||||||||||||||
80 | } executed 1124 times by 9 tests: end of block Executed by:
| 1124 | ||||||||||||||||||||||||
81 | - | |||||||||||||||||||||||||
82 | bool QSqlCachedResult::fetch(int i) | - | ||||||||||||||||||||||||
83 | { | - | ||||||||||||||||||||||||
84 | QSqlCachedResultPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
85 | if ((
| 0-2662 | ||||||||||||||||||||||||
86 | return executed 2 times by 1 test: false;return false; Executed by:
executed 2 times by 1 test: return false; Executed by:
| 2 | ||||||||||||||||||||||||
87 | if (at() == i
| 944-1716 | ||||||||||||||||||||||||
88 | return executed 1716 times by 5 tests: true;return true; Executed by:
executed 1716 times by 5 tests: return true; Executed by:
| 1716 | ||||||||||||||||||||||||
89 | if (d->forwardOnly
| 1-943 | ||||||||||||||||||||||||
90 | - | |||||||||||||||||||||||||
91 | if (at() > i
| 0-1 | ||||||||||||||||||||||||
92 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||||||||
93 | while(at() < i - 1
| 1-3 | ||||||||||||||||||||||||
94 | if (!gotoNext(d->cache, -1)
| 0-3 | ||||||||||||||||||||||||
95 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||||||||
96 | setAt(at() + 1); | - | ||||||||||||||||||||||||
97 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||||||||
98 | if (!gotoNext(d->cache, 0)
| 0-1 | ||||||||||||||||||||||||
99 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||||||||
100 | setAt(at() + 1); | - | ||||||||||||||||||||||||
101 | return executed 1 time by 1 test: true;return true; Executed by:
executed 1 time by 1 test: return true; Executed by:
| 1 | ||||||||||||||||||||||||
102 | } | - | ||||||||||||||||||||||||
103 | if (d->canSeek(i)
| 404-539 | ||||||||||||||||||||||||
104 | setAt(i); | - | ||||||||||||||||||||||||
105 | return executed 539 times by 5 tests: true;return true; Executed by:
executed 539 times by 5 tests: return true; Executed by:
| 539 | ||||||||||||||||||||||||
106 | } | - | ||||||||||||||||||||||||
107 | if (d->rowCacheEnd > 0
| 13-391 | ||||||||||||||||||||||||
108 | setAt(d->cacheCount()); executed 13 times by 3 tests: setAt(d->cacheCount()); Executed by:
| 13 | ||||||||||||||||||||||||
109 | while (at() < i + 1
| 132-34438 | ||||||||||||||||||||||||
110 | if (!cacheNext()
| 272-34166 | ||||||||||||||||||||||||
111 | if (d->canSeek(i)
| 2-270 | ||||||||||||||||||||||||
112 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||||||||||||||
113 | return executed 270 times by 5 tests: false;return false; Executed by:
executed 270 times by 5 tests: return false; Executed by:
| 270 | ||||||||||||||||||||||||
114 | } | - | ||||||||||||||||||||||||
115 | } executed 34166 times by 5 tests: end of block Executed by:
| 34166 | ||||||||||||||||||||||||
116 | setAt(i); | - | ||||||||||||||||||||||||
117 | - | |||||||||||||||||||||||||
118 | return executed 134 times by 4 tests: true;return true; Executed by:
executed 134 times by 4 tests: return true; Executed by:
| 134 | ||||||||||||||||||||||||
119 | } | - | ||||||||||||||||||||||||
120 | - | |||||||||||||||||||||||||
121 | bool QSqlCachedResult::fetchNext() | - | ||||||||||||||||||||||||
122 | { | - | ||||||||||||||||||||||||
123 | QSqlCachedResultPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
124 | if (d->canSeek(at() + 1)
| 1750-1958 | ||||||||||||||||||||||||
125 | setAt(at() + 1); | - | ||||||||||||||||||||||||
126 | return executed 1750 times by 5 tests: true;return true; Executed by:
executed 1750 times by 5 tests: return true; Executed by:
| 1750 | ||||||||||||||||||||||||
127 | } | - | ||||||||||||||||||||||||
128 | return executed 1958 times by 8 tests: cacheNext();return cacheNext(); Executed by:
executed 1958 times by 8 tests: return cacheNext(); Executed by:
| 1958 | ||||||||||||||||||||||||
129 | } | - | ||||||||||||||||||||||||
130 | - | |||||||||||||||||||||||||
131 | bool QSqlCachedResult::fetchPrevious() | - | ||||||||||||||||||||||||
132 | { | - | ||||||||||||||||||||||||
133 | return fetch(at() - 1); | - | ||||||||||||||||||||||||
134 | } | - | ||||||||||||||||||||||||
135 | - | |||||||||||||||||||||||||
136 | bool QSqlCachedResult::fetchFirst() | - | ||||||||||||||||||||||||
137 | { | - | ||||||||||||||||||||||||
138 | QSqlCachedResultPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
139 | if (d->forwardOnly
| 0-615 | ||||||||||||||||||||||||
140 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||||||||
141 | } | - | ||||||||||||||||||||||||
142 | if (d->canSeek(0)
| 1-702 | ||||||||||||||||||||||||
143 | setAt(0); | - | ||||||||||||||||||||||||
144 | return executed 1 time by 1 test: true;return true; Executed by:
executed 1 time by 1 test: return true; Executed by:
| 1 | ||||||||||||||||||||||||
145 | } | - | ||||||||||||||||||||||||
146 | return executed 702 times by 8 tests: cacheNext();return cacheNext(); Executed by:
executed 702 times by 8 tests: return cacheNext(); Executed by:
| 702 | ||||||||||||||||||||||||
147 | } | - | ||||||||||||||||||||||||
148 | - | |||||||||||||||||||||||||
149 | bool QSqlCachedResult::fetchLast() | - | ||||||||||||||||||||||||
150 | { | - | ||||||||||||||||||||||||
151 | QSqlCachedResultPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
152 | if (d->atEnd
| 4-6 | ||||||||||||||||||||||||
153 | if (d->forwardOnly
| 0-4 | ||||||||||||||||||||||||
154 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||||||||||||||
155 | else | - | ||||||||||||||||||||||||
156 | return executed 4 times by 1 test: fetch(d->cacheCount() - 1);return fetch(d->cacheCount() - 1); Executed by:
executed 4 times by 1 test: return fetch(d->cacheCount() - 1); Executed by:
| 4 | ||||||||||||||||||||||||
157 | } | - | ||||||||||||||||||||||||
158 | - | |||||||||||||||||||||||||
159 | int i = at(); | - | ||||||||||||||||||||||||
160 | while (fetchNext()
| 6-22 | ||||||||||||||||||||||||
161 | ++ executed 22 times by 1 test: i;++i; Executed by:
executed 22 times by 1 test: ++i; Executed by:
| 22 | ||||||||||||||||||||||||
162 | if (d->forwardOnly
| 0-4 | ||||||||||||||||||||||||
163 | setAt(i); | - | ||||||||||||||||||||||||
164 | return executed 2 times by 1 test: true;return true; Executed by:
executed 2 times by 1 test: return true; Executed by:
| 2 | ||||||||||||||||||||||||
165 | } else { | - | ||||||||||||||||||||||||
166 | return executed 4 times by 1 test: fetch(i);return fetch(i); Executed by:
executed 4 times by 1 test: return fetch(i); Executed by:
| 4 | ||||||||||||||||||||||||
167 | } | - | ||||||||||||||||||||||||
168 | } | - | ||||||||||||||||||||||||
169 | - | |||||||||||||||||||||||||
170 | QVariant QSqlCachedResult::data(int i) | - | ||||||||||||||||||||||||
171 | { | - | ||||||||||||||||||||||||
172 | const QSqlCachedResultPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
173 | int idx = d->forwardOnly
| 3489-5649 | ||||||||||||||||||||||||
174 | if (i >= d->colCount
| 0-9138 | ||||||||||||||||||||||||
175 | return never executed: QVariant();return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||||||||||||||
176 | - | |||||||||||||||||||||||||
177 | return executed 9138 times by 8 tests: d->cache.at(idx);return d->cache.at(idx); Executed by:
executed 9138 times by 8 tests: return d->cache.at(idx); Executed by:
| 9138 | ||||||||||||||||||||||||
178 | } | - | ||||||||||||||||||||||||
179 | - | |||||||||||||||||||||||||
180 | bool QSqlCachedResult::isNull(int i) | - | ||||||||||||||||||||||||
181 | { | - | ||||||||||||||||||||||||
182 | const QSqlCachedResultPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
183 | int idx = d->forwardOnly
| 0-10 | ||||||||||||||||||||||||
184 | if (i >= d->colCount
| 0-9 | ||||||||||||||||||||||||
185 | return executed 1 time by 1 test: true;return true; Executed by:
executed 1 time by 1 test: return true; Executed by:
| 1 | ||||||||||||||||||||||||
186 | - | |||||||||||||||||||||||||
187 | return executed 9 times by 1 test: d->cache.at(idx).isNull();return d->cache.at(idx).isNull(); Executed by:
executed 9 times by 1 test: return d->cache.at(idx).isNull(); Executed by:
| 9 | ||||||||||||||||||||||||
188 | } | - | ||||||||||||||||||||||||
189 | - | |||||||||||||||||||||||||
190 | void QSqlCachedResult::cleanup() | - | ||||||||||||||||||||||||
191 | { | - | ||||||||||||||||||||||||
192 | QSqlCachedResultPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
193 | setAt(QSql::BeforeFirstRow); | - | ||||||||||||||||||||||||
194 | setActive(false); | - | ||||||||||||||||||||||||
195 | d->cleanup(); | - | ||||||||||||||||||||||||
196 | } executed 7512 times by 9 tests: end of block Executed by:
| 7512 | ||||||||||||||||||||||||
197 | - | |||||||||||||||||||||||||
198 | void QSqlCachedResult::clearValues() | - | ||||||||||||||||||||||||
199 | { | - | ||||||||||||||||||||||||
200 | QSqlCachedResultPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
201 | setAt(QSql::BeforeFirstRow); | - | ||||||||||||||||||||||||
202 | d->rowCacheEnd = 0; | - | ||||||||||||||||||||||||
203 | d->atEnd = false; | - | ||||||||||||||||||||||||
204 | } executed 119111 times by 9 tests: end of block Executed by:
| 119111 | ||||||||||||||||||||||||
205 | - | |||||||||||||||||||||||||
206 | bool QSqlCachedResult::cacheNext() | - | ||||||||||||||||||||||||
207 | { | - | ||||||||||||||||||||||||
208 | QSqlCachedResultPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
209 | if (d->atEnd
| 262-36836 | ||||||||||||||||||||||||
210 | return executed 262 times by 5 tests: false;return false; Executed by:
executed 262 times by 5 tests: return false; Executed by:
| 262 | ||||||||||||||||||||||||
211 | - | |||||||||||||||||||||||||
212 | if(isForwardOnly()
| 2237-34599 | ||||||||||||||||||||||||
213 | d->cache.clear();d->cache.resize(d->colCount); | - | ||||||||||||||||||||||||
214 | } executed 2237 times by 8 tests: end of block Executed by:
| 2237 | ||||||||||||||||||||||||
215 | - | |||||||||||||||||||||||||
216 | if (!gotoNext(d->cache, d->nextIndex())
| 838-35998 | ||||||||||||||||||||||||
217 | d->revertLast(); | - | ||||||||||||||||||||||||
218 | d->atEnd = true; | - | ||||||||||||||||||||||||
219 | return executed 838 times by 8 tests: false;return false; Executed by:
executed 838 times by 8 tests: return false; Executed by:
| 838 | ||||||||||||||||||||||||
220 | } | - | ||||||||||||||||||||||||
221 | setAt(at() + 1); | - | ||||||||||||||||||||||||
222 | return executed 35998 times by 8 tests: true;return true; Executed by:
executed 35998 times by 8 tests: return true; Executed by:
| 35998 | ||||||||||||||||||||||||
223 | } | - | ||||||||||||||||||||||||
224 | - | |||||||||||||||||||||||||
225 | int QSqlCachedResult::colCount() const | - | ||||||||||||||||||||||||
226 | { | - | ||||||||||||||||||||||||
227 | const QSqlCachedResultPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
228 | return never executed: d->colCount;return d->colCount; never executed: return d->colCount; | 0 | ||||||||||||||||||||||||
229 | } | - | ||||||||||||||||||||||||
230 | - | |||||||||||||||||||||||||
231 | QSqlCachedResult::ValueCache &QSqlCachedResult::cache() | - | ||||||||||||||||||||||||
232 | { | - | ||||||||||||||||||||||||
233 | QSqlCachedResultPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
234 | return never executed: d->cache;return d->cache; never executed: return d->cache; | 0 | ||||||||||||||||||||||||
235 | } | - | ||||||||||||||||||||||||
236 | - | |||||||||||||||||||||||||
237 | void QSqlCachedResult::virtual_hook(int id, void *data) | - | ||||||||||||||||||||||||
238 | { | - | ||||||||||||||||||||||||
239 | QSqlResult::virtual_hook(id, data); | - | ||||||||||||||||||||||||
240 | } | - | ||||||||||||||||||||||||
241 | - | |||||||||||||||||||||||||
242 | void QSqlCachedResult::detachFromResultSet() | - | ||||||||||||||||||||||||
243 | { | - | ||||||||||||||||||||||||
244 | cleanup(); | - | ||||||||||||||||||||||||
245 | } | - | ||||||||||||||||||||||||
246 | - | |||||||||||||||||||||||||
247 | void QSqlCachedResult::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy policy) | - | ||||||||||||||||||||||||
248 | { | - | ||||||||||||||||||||||||
249 | QSqlResult::setNumericalPrecisionPolicy(policy); | - | ||||||||||||||||||||||||
250 | cleanup(); | - | ||||||||||||||||||||||||
251 | } | - | ||||||||||||||||||||||||
252 | - | |||||||||||||||||||||||||
253 | - | |||||||||||||||||||||||||
254 | - | |||||||||||||||||||||||||
Switch to Source code | Preprocessed file |