Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/sqlite/src/src/dbstat.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | typedef struct StatTable StatTable; | - | ||||||||||||
2 | typedef struct StatCursor StatCursor; | - | ||||||||||||
3 | typedef struct StatPage StatPage; | - | ||||||||||||
4 | typedef struct StatCell StatCell; | - | ||||||||||||
5 | - | |||||||||||||
6 | struct StatCell { | - | ||||||||||||
7 | int nLocal; | - | ||||||||||||
8 | u32 iChildPg; | - | ||||||||||||
9 | int nOvfl; | - | ||||||||||||
10 | u32 *aOvfl; | - | ||||||||||||
11 | int nLastOvfl; | - | ||||||||||||
12 | int iOvfl; | - | ||||||||||||
13 | }; | - | ||||||||||||
14 | - | |||||||||||||
15 | struct StatPage { | - | ||||||||||||
16 | u32 iPgno; | - | ||||||||||||
17 | DbPage *pPg; | - | ||||||||||||
18 | int iCell; | - | ||||||||||||
19 | - | |||||||||||||
20 | char *zPath; | - | ||||||||||||
21 | - | |||||||||||||
22 | - | |||||||||||||
23 | u8 flags; | - | ||||||||||||
24 | int nCell; | - | ||||||||||||
25 | int nUnused; | - | ||||||||||||
26 | StatCell *aCell; | - | ||||||||||||
27 | u32 iRightChildPg; | - | ||||||||||||
28 | int nMxPayload; | - | ||||||||||||
29 | }; | - | ||||||||||||
30 | - | |||||||||||||
31 | struct StatCursor { | - | ||||||||||||
32 | sqlite3_vtab_cursor base; | - | ||||||||||||
33 | sqlite3_stmt *pStmt; | - | ||||||||||||
34 | int isEof; | - | ||||||||||||
35 | int iDb; | - | ||||||||||||
36 | - | |||||||||||||
37 | StatPage aPage[32]; | - | ||||||||||||
38 | int iPage; | - | ||||||||||||
39 | - | |||||||||||||
40 | - | |||||||||||||
41 | char *zName; | - | ||||||||||||
42 | char *zPath; | - | ||||||||||||
43 | u32 iPageno; | - | ||||||||||||
44 | char *zPagetype; | - | ||||||||||||
45 | int nCell; | - | ||||||||||||
46 | int nPayload; | - | ||||||||||||
47 | int nUnused; | - | ||||||||||||
48 | int nMxPayload; | - | ||||||||||||
49 | i64 iOffset; | - | ||||||||||||
50 | int szPage; | - | ||||||||||||
51 | }; | - | ||||||||||||
52 | - | |||||||||||||
53 | struct StatTable { | - | ||||||||||||
54 | sqlite3_vtab base; | - | ||||||||||||
55 | sqlite3 *db; | - | ||||||||||||
56 | int iDb; | - | ||||||||||||
57 | }; | - | ||||||||||||
58 | static int statConnect( | - | ||||||||||||
59 | sqlite3 *db, | - | ||||||||||||
60 | void *pAux, | - | ||||||||||||
61 | int argc, const char *const*argv, | - | ||||||||||||
62 | sqlite3_vtab **ppVtab, | - | ||||||||||||
63 | char **pzErr | - | ||||||||||||
64 | ){ | - | ||||||||||||
65 | StatTable *pTab = 0; | - | ||||||||||||
66 | int rc = 0; | - | ||||||||||||
67 | int iDb; | - | ||||||||||||
68 | - | |||||||||||||
69 | if( argc>=4
| 5-11 | ||||||||||||
70 | Token nm; | - | ||||||||||||
71 | sqlite3TokenInit(&nm, (char*)argv[3]); | - | ||||||||||||
72 | iDb = sqlite3FindDb(db, &nm); | - | ||||||||||||
73 | if( iDb<0
| 1-4 | ||||||||||||
74 | *pzErr = sqlite3_mprintf("no such database: %s", argv[3]); | - | ||||||||||||
75 | return executed 1 time by 1 test: 1;return 1; Executed by:
executed 1 time by 1 test: return 1; Executed by:
| 1 | ||||||||||||
76 | } | - | ||||||||||||
77 | } executed 4 times by 1 test: else{end of block Executed by:
| 4 | ||||||||||||
78 | iDb = 0; | - | ||||||||||||
79 | } executed 11 times by 1 test: end of block Executed by:
| 11 | ||||||||||||
80 | rc = sqlite3_declare_vtab(db, "CREATE TABLE xx( " " name TEXT, /* Name of table or index */" " path TEXT, /* Path to page from root */" " pageno INTEGER, /* Page number */" " pagetype TEXT, /* 'internal', 'leaf' or 'overflow' */" " ncell INTEGER, /* Cells on page (0 for overflow) */" " payload INTEGER, /* Bytes of payload on this page */" " unused INTEGER, /* Bytes of unused space on this page */" " mx_payload INTEGER, /* Largest payload size of all cells */" " pgoffset INTEGER, /* Offset of page in file */" " pgsize INTEGER, /* Size of the page */" " schema TEXT HIDDEN /* Database schema being analyzed */" ");"); | - | ||||||||||||
81 | if( rc==0
| 0-15 | ||||||||||||
82 | pTab = (StatTable *)sqlite3_malloc64(sizeof(StatTable)); | - | ||||||||||||
83 | if( pTab==0
never executed: rc = 7; | 0-15 | ||||||||||||
84 | } executed 15 times by 1 test: end of block Executed by:
| 15 | ||||||||||||
85 | - | |||||||||||||
86 | - | |||||||||||||
87 | ((void) (0)) | - | ||||||||||||
88 | ; | - | ||||||||||||
89 | if( rc==0
| 0-15 | ||||||||||||
90 | memset(pTab, 0, sizeof(StatTable)); | - | ||||||||||||
91 | pTab->db = db; | - | ||||||||||||
92 | pTab->iDb = iDb; | - | ||||||||||||
93 | } executed 15 times by 1 test: end of block Executed by:
| 15 | ||||||||||||
94 | - | |||||||||||||
95 | *ppVtab = (sqlite3_vtab*)pTab; | - | ||||||||||||
96 | return executed 15 times by 1 test: rc;return rc; Executed by:
executed 15 times by 1 test: return rc; Executed by:
| 15 | ||||||||||||
97 | } | - | ||||||||||||
98 | - | |||||||||||||
99 | - | |||||||||||||
100 | - | |||||||||||||
101 | - | |||||||||||||
102 | static int statDisconnect(sqlite3_vtab *pVtab){ | - | ||||||||||||
103 | sqlite3_free(pVtab); | - | ||||||||||||
104 | return executed 15 times by 1 test: 0;return 0; Executed by:
executed 15 times by 1 test: return 0; Executed by:
| 15 | ||||||||||||
105 | } | - | ||||||||||||
106 | static int statBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){ | - | ||||||||||||
107 | int i; | - | ||||||||||||
108 | - | |||||||||||||
109 | pIdxInfo->estimatedCost = 1.0e6; | - | ||||||||||||
110 | - | |||||||||||||
111 | - | |||||||||||||
112 | - | |||||||||||||
113 | - | |||||||||||||
114 | - | |||||||||||||
115 | - | |||||||||||||
116 | for(i=0; i<pIdxInfo->nConstraint
| 17-21 | ||||||||||||
117 | if( pIdxInfo->aConstraint[i].usable==0
never executed: continue; | 0-17 | ||||||||||||
118 | if( pIdxInfo->aConstraint[i].op!=2
executed 2 times by 1 test: continue; Executed by:
| 2-15 | ||||||||||||
119 | if( pIdxInfo->aConstraint[i].iColumn!=10
executed 12 times by 1 test: continue; Executed by:
| 3-12 | ||||||||||||
120 | pIdxInfo->idxNum = 1; | - | ||||||||||||
121 | pIdxInfo->estimatedCost = 1.0; | - | ||||||||||||
122 | pIdxInfo->aConstraintUsage[i].argvIndex = 1; | - | ||||||||||||
123 | pIdxInfo->aConstraintUsage[i].omit = 1; | - | ||||||||||||
124 | break; executed 3 times by 1 test: break; Executed by:
| 3 | ||||||||||||
125 | } | - | ||||||||||||
126 | - | |||||||||||||
127 | - | |||||||||||||
128 | - | |||||||||||||
129 | - | |||||||||||||
130 | - | |||||||||||||
131 | - | |||||||||||||
132 | if( ( pIdxInfo->nOrderBy==1
| 6-18 | ||||||||||||
133 | && pIdxInfo->aOrderBy[0].iColumn==0
| 0-6 | ||||||||||||
134 | && pIdxInfo->aOrderBy[0].desc==0
| 0 | ||||||||||||
135 | ) || | - | ||||||||||||
136 | ( pIdxInfo->nOrderBy==2
| 0-24 | ||||||||||||
137 | && pIdxInfo->aOrderBy[0].iColumn==0
| 0 | ||||||||||||
138 | && pIdxInfo->aOrderBy[0].desc==0
| 0 | ||||||||||||
139 | && pIdxInfo->aOrderBy[1].iColumn==1
| 0 | ||||||||||||
140 | && pIdxInfo->aOrderBy[1].desc==0
| 0 | ||||||||||||
141 | ) | - | ||||||||||||
142 | ){ | - | ||||||||||||
143 | pIdxInfo->orderByConsumed = 1; | - | ||||||||||||
144 | } never executed: end of block | 0 | ||||||||||||
145 | - | |||||||||||||
146 | return executed 24 times by 1 test: 0;return 0; Executed by:
executed 24 times by 1 test: return 0; Executed by:
| 24 | ||||||||||||
147 | } | - | ||||||||||||
148 | - | |||||||||||||
149 | - | |||||||||||||
150 | - | |||||||||||||
151 | - | |||||||||||||
152 | static int statOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){ | - | ||||||||||||
153 | StatTable *pTab = (StatTable *)pVTab; | - | ||||||||||||
154 | StatCursor *pCsr; | - | ||||||||||||
155 | - | |||||||||||||
156 | pCsr = (StatCursor *)sqlite3_malloc64(sizeof(StatCursor)); | - | ||||||||||||
157 | if( pCsr==0
| 0-23 | ||||||||||||
158 | return never executed: 7;return 7; never executed: return 7; | 0 | ||||||||||||
159 | }else{ | - | ||||||||||||
160 | memset(pCsr, 0, sizeof(StatCursor)); | - | ||||||||||||
161 | pCsr->base.pVtab = pVTab; | - | ||||||||||||
162 | pCsr->iDb = pTab->iDb; | - | ||||||||||||
163 | } executed 23 times by 1 test: end of block Executed by:
| 23 | ||||||||||||
164 | - | |||||||||||||
165 | *ppCursor = (sqlite3_vtab_cursor *)pCsr; | - | ||||||||||||
166 | return executed 23 times by 1 test: 0;return 0; Executed by:
executed 23 times by 1 test: return 0; Executed by:
| 23 | ||||||||||||
167 | } | - | ||||||||||||
168 | - | |||||||||||||
169 | static void statClearPage(StatPage *p){ | - | ||||||||||||
170 | int i; | - | ||||||||||||
171 | if( p->aCell
| 1303-1475 | ||||||||||||
172 | for(i=0; i<p->nCell
| 1303-5841 | ||||||||||||
173 | sqlite3_free(p->aCell[i].aOvfl); | - | ||||||||||||
174 | } executed 5841 times by 1 test: end of block Executed by:
| 5841 | ||||||||||||
175 | sqlite3_free(p->aCell); | - | ||||||||||||
176 | } executed 1303 times by 1 test: end of block Executed by:
| 1303 | ||||||||||||
177 | sqlite3PagerUnref(p->pPg); | - | ||||||||||||
178 | sqlite3_free(p->zPath); | - | ||||||||||||
179 | memset(p, 0, sizeof(StatPage)); | - | ||||||||||||
180 | } executed 2778 times by 1 test: end of block Executed by:
| 2778 | ||||||||||||
181 | - | |||||||||||||
182 | static void statResetCsr(StatCursor *pCsr){ | - | ||||||||||||
183 | int i; | - | ||||||||||||
184 | sqlite3_reset(pCsr->pStmt); | - | ||||||||||||
185 | for(i=0; i<((int)(sizeof(pCsr->aPage)/sizeof(pCsr->aPage[0])))
| 46-1472 | ||||||||||||
186 | statClearPage(&pCsr->aPage[i]); | - | ||||||||||||
187 | } executed 1472 times by 1 test: end of block Executed by:
| 1472 | ||||||||||||
188 | pCsr->iPage = 0; | - | ||||||||||||
189 | sqlite3_free(pCsr->zPath); | - | ||||||||||||
190 | pCsr->zPath = 0; | - | ||||||||||||
191 | pCsr->isEof = 0; | - | ||||||||||||
192 | } executed 46 times by 1 test: end of block Executed by:
| 46 | ||||||||||||
193 | - | |||||||||||||
194 | - | |||||||||||||
195 | - | |||||||||||||
196 | - | |||||||||||||
197 | static int statClose(sqlite3_vtab_cursor *pCursor){ | - | ||||||||||||
198 | StatCursor *pCsr = (StatCursor *)pCursor; | - | ||||||||||||
199 | statResetCsr(pCsr); | - | ||||||||||||
200 | sqlite3_finalize(pCsr->pStmt); | - | ||||||||||||
201 | sqlite3_free(pCsr); | - | ||||||||||||
202 | return executed 23 times by 1 test: 0;return 0; Executed by:
executed 23 times by 1 test: return 0; Executed by:
| 23 | ||||||||||||
203 | } | - | ||||||||||||
204 | - | |||||||||||||
205 | static void getLocalPayload( | - | ||||||||||||
206 | int nUsable, | - | ||||||||||||
207 | u8 flags, | - | ||||||||||||
208 | int nTotal, | - | ||||||||||||
209 | int *pnLocal | - | ||||||||||||
210 | ){ | - | ||||||||||||
211 | int nLocal; | - | ||||||||||||
212 | int nMinLocal; | - | ||||||||||||
213 | int nMaxLocal; | - | ||||||||||||
214 | - | |||||||||||||
215 | if( flags==0x0D
| 1709-3176 | ||||||||||||
216 | nMinLocal = (nUsable - 12) * 32 / 255 - 23; | - | ||||||||||||
217 | nMaxLocal = nUsable - 35; | - | ||||||||||||
218 | } executed 1709 times by 1 test: else{end of block Executed by:
| 1709 | ||||||||||||
219 | nMinLocal = (nUsable - 12) * 32 / 255 - 23; | - | ||||||||||||
220 | nMaxLocal = (nUsable - 12) * 64 / 255 - 23; | - | ||||||||||||
221 | } executed 3176 times by 1 test: end of block Executed by:
| 3176 | ||||||||||||
222 | - | |||||||||||||
223 | nLocal = nMinLocal + (nTotal - nMinLocal) % (nUsable - 4); | - | ||||||||||||
224 | if( nLocal>nMaxLocal
executed 2358 times by 1 test: nLocal = nMinLocal; Executed by:
| 2358-2527 | ||||||||||||
225 | *pnLocal = nLocal; | - | ||||||||||||
226 | } executed 4885 times by 1 test: end of block Executed by:
| 4885 | ||||||||||||
227 | - | |||||||||||||
228 | static int statDecodePage(Btree *pBt, StatPage *p){ | - | ||||||||||||
229 | int nUnused; | - | ||||||||||||
230 | int iOff; | - | ||||||||||||
231 | int nHdr; | - | ||||||||||||
232 | int isLeaf; | - | ||||||||||||
233 | int szPage; | - | ||||||||||||
234 | - | |||||||||||||
235 | u8 *aData = sqlite3PagerGetData(p->pPg); | - | ||||||||||||
236 | u8 *aHdr = &aData[p->iPgno==1 ? 100 : 0]; | - | ||||||||||||
237 | - | |||||||||||||
238 | p->flags = aHdr[0]; | - | ||||||||||||
239 | p->nCell = ((&aHdr[3])[0]<<8 | (&aHdr[3])[1]); | - | ||||||||||||
240 | p->nMxPayload = 0; | - | ||||||||||||
241 | - | |||||||||||||
242 | isLeaf = (p->flags==0x0A
| 66-1072 | ||||||||||||
243 | nHdr = 12 - isLeaf*4 + (p->iPgno==1)*100; | - | ||||||||||||
244 | - | |||||||||||||
245 | nUnused = ((&aHdr[5])[0]<<8 | (&aHdr[5])[1]) - nHdr - 2*p->nCell; | - | ||||||||||||
246 | nUnused += (int)aHdr[7]; | - | ||||||||||||
247 | iOff = ((&aHdr[1])[0]<<8 | (&aHdr[1])[1]); | - | ||||||||||||
248 | while( iOff
| 48-1306 | ||||||||||||
249 | nUnused += ((&aData[iOff+2])[0]<<8 | (&aData[iOff+2])[1]); | - | ||||||||||||
250 | iOff = ((&aData[iOff])[0]<<8 | (&aData[iOff])[1]); | - | ||||||||||||
251 | } executed 48 times by 1 test: end of block Executed by:
| 48 | ||||||||||||
252 | p->nUnused = nUnused; | - | ||||||||||||
253 | p->iRightChildPg = isLeaf
| 66-1240 | ||||||||||||
254 | szPage = sqlite3BtreeGetPageSize(pBt); | - | ||||||||||||
255 | - | |||||||||||||
256 | if( p->nCell
| 3-1303 | ||||||||||||
257 | int i; | - | ||||||||||||
258 | int nUsable; | - | ||||||||||||
259 | - | |||||||||||||
260 | sqlite3BtreeEnter(pBt); | - | ||||||||||||
261 | nUsable = szPage - sqlite3BtreeGetReserveNoMutex(pBt); | - | ||||||||||||
262 | sqlite3BtreeLeave(pBt); | - | ||||||||||||
263 | p->aCell = sqlite3_malloc64((p->nCell+1) * sizeof(StatCell)); | - | ||||||||||||
264 | if( p->aCell==0
never executed: 7;return 7; never executed: return 7; | 0-1303 | ||||||||||||
265 | memset(p->aCell, 0, (p->nCell+1) * sizeof(StatCell)); | - | ||||||||||||
266 | - | |||||||||||||
267 | for(i=0; i<p->nCell
| 1303-5841 | ||||||||||||
268 | StatCell *pCell = &p->aCell[i]; | - | ||||||||||||
269 | - | |||||||||||||
270 | iOff = ((&aData[nHdr+i*2])[0]<<8 | (&aData[nHdr+i*2])[1]); | - | ||||||||||||
271 | if( !isLeaf
| 1157-4684 | ||||||||||||
272 | pCell->iChildPg = sqlite3Get4byte(&aData[iOff]); | - | ||||||||||||
273 | iOff += 4; | - | ||||||||||||
274 | } executed 1157 times by 1 test: end of block Executed by:
| 1157 | ||||||||||||
275 | if( p->flags==0x05
| 956-4885 | ||||||||||||
276 | - | |||||||||||||
277 | } executed 956 times by 1 test: else{end of block Executed by:
| 956 | ||||||||||||
278 | u32 nPayload; | - | ||||||||||||
279 | int nLocal; | - | ||||||||||||
280 | iOff += (u8)((*(
| 1264-3621 | ||||||||||||
281 | if( p->flags==0x0D
| 1709-3176 | ||||||||||||
282 | u64 dummy; | - | ||||||||||||
283 | iOff += sqlite3GetVarint(&aData[iOff], &dummy); | - | ||||||||||||
284 | } executed 1709 times by 1 test: end of block Executed by:
| 1709 | ||||||||||||
285 | if( nPayload>(u32)p->nMxPayload
executed 1430 times by 1 test: p->nMxPayload = nPayload; Executed by:
| 1430-3455 | ||||||||||||
286 | getLocalPayload(nUsable, p->flags, nPayload, &nLocal); | - | ||||||||||||
287 | pCell->nLocal = nLocal; | - | ||||||||||||
288 | - | |||||||||||||
289 | ((void) (0)) | - | ||||||||||||
290 | ; | - | ||||||||||||
291 | - | |||||||||||||
292 | ((void) (0)) | - | ||||||||||||
293 | ; | - | ||||||||||||
294 | - | |||||||||||||
295 | ((void) (0)) | - | ||||||||||||
296 | ; | - | ||||||||||||
297 | if( nPayload>(u32)nLocal
| 2426-2459 | ||||||||||||
298 | int j; | - | ||||||||||||
299 | int nOvfl = ((nPayload - nLocal) + nUsable-4 - 1) / (nUsable - 4); | - | ||||||||||||
300 | pCell->nLastOvfl = (nPayload-nLocal) - (nOvfl-1) * (nUsable-4); | - | ||||||||||||
301 | pCell->nOvfl = nOvfl; | - | ||||||||||||
302 | pCell->aOvfl = sqlite3_malloc64(sizeof(u32)*nOvfl); | - | ||||||||||||
303 | if( pCell->aOvfl==0
never executed: 7;return 7; never executed: return 7; | 0-2426 | ||||||||||||
304 | pCell->aOvfl[0] = sqlite3Get4byte(&aData[iOff+nLocal]); | - | ||||||||||||
305 | for(j=1; j<nOvfl
| 90-2426 | ||||||||||||
306 | int rc; | - | ||||||||||||
307 | u32 iPrev = pCell->aOvfl[j-1]; | - | ||||||||||||
308 | DbPage *pPg = 0; | - | ||||||||||||
309 | rc = sqlite3PagerGet(sqlite3BtreePager(pBt), iPrev, &pPg, 0); | - | ||||||||||||
310 | if( rc!=0
| 0-90 | ||||||||||||
311 | - | |||||||||||||
312 | ((void) (0)) | - | ||||||||||||
313 | ; | - | ||||||||||||
314 | return never executed: rc;return rc; never executed: return rc; | 0 | ||||||||||||
315 | } | - | ||||||||||||
316 | pCell->aOvfl[j] = sqlite3Get4byte(sqlite3PagerGetData(pPg)); | - | ||||||||||||
317 | sqlite3PagerUnref(pPg); | - | ||||||||||||
318 | } executed 90 times by 1 test: end of block Executed by:
| 90 | ||||||||||||
319 | } executed 2426 times by 1 test: end of block Executed by:
| 2426 | ||||||||||||
320 | } executed 4885 times by 1 test: end of block Executed by:
| 4885 | ||||||||||||
321 | } | - | ||||||||||||
322 | } executed 1303 times by 1 test: end of block Executed by:
| 1303 | ||||||||||||
323 | - | |||||||||||||
324 | return executed 1306 times by 1 test: 0;return 0; Executed by:
executed 1306 times by 1 test: return 0; Executed by:
| 1306 | ||||||||||||
325 | } | - | ||||||||||||
326 | - | |||||||||||||
327 | - | |||||||||||||
328 | - | |||||||||||||
329 | - | |||||||||||||
330 | - | |||||||||||||
331 | static void statSizeAndOffset(StatCursor *pCsr){ | - | ||||||||||||
332 | StatTable *pTab = (StatTable *)((sqlite3_vtab_cursor *)pCsr)->pVtab; | - | ||||||||||||
333 | Btree *pBt = pTab->db->aDb[pTab->iDb].pBt; | - | ||||||||||||
334 | Pager *pPager = sqlite3BtreePager(pBt); | - | ||||||||||||
335 | sqlite3_file *fd; | - | ||||||||||||
336 | sqlite3_int64 x[2]; | - | ||||||||||||
337 | - | |||||||||||||
338 | - | |||||||||||||
339 | pCsr->szPage = sqlite3BtreeGetPageSize(pBt); | - | ||||||||||||
340 | pCsr->iOffset = (i64)pCsr->szPage * (pCsr->iPageno - 1); | - | ||||||||||||
341 | - | |||||||||||||
342 | - | |||||||||||||
343 | - | |||||||||||||
344 | - | |||||||||||||
345 | fd = sqlite3PagerFile(pPager); | - | ||||||||||||
346 | x[0] = pCsr->iPageno; | - | ||||||||||||
347 | if( sqlite3OsFileControl(fd, 230440, &x)==0
| 0-3822 | ||||||||||||
348 | pCsr->iOffset = x[0]; | - | ||||||||||||
349 | pCsr->szPage = (int)x[1]; | - | ||||||||||||
350 | } never executed: end of block | 0 | ||||||||||||
351 | } executed 3822 times by 1 test: end of block Executed by:
| 3822 | ||||||||||||
352 | - | |||||||||||||
353 | - | |||||||||||||
354 | - | |||||||||||||
355 | - | |||||||||||||
356 | static int statNext(sqlite3_vtab_cursor *pCursor){ | - | ||||||||||||
357 | int rc; | - | ||||||||||||
358 | int nPayload; | - | ||||||||||||
359 | char *z; | - | ||||||||||||
360 | StatCursor *pCsr = (StatCursor *)pCursor; | - | ||||||||||||
361 | StatTable *pTab = (StatTable *)pCursor->pVtab; | - | ||||||||||||
362 | Btree *pBt = pTab->db->aDb[pCsr->iDb].pBt; | - | ||||||||||||
363 | Pager *pPager = sqlite3BtreePager(pBt); | - | ||||||||||||
364 | - | |||||||||||||
365 | sqlite3_free(pCsr->zPath); | - | ||||||||||||
366 | pCsr->zPath = 0; | - | ||||||||||||
367 | - | |||||||||||||
368 | statNextRestart: code before this statement executed 3928 times by 1 test: statNextRestart: Executed by:
| 3928 | ||||||||||||
369 | if( pCsr->aPage[0].pPg==0
| 106-5045 | ||||||||||||
370 | rc = sqlite3_step(pCsr->pStmt); | - | ||||||||||||
371 | if( rc==100
| 22-84 | ||||||||||||
372 | int nPage; | - | ||||||||||||
373 | u32 iRoot = (u32)sqlite3_column_int64(pCsr->pStmt, 1); | - | ||||||||||||
374 | sqlite3PagerPagecount(pPager, &nPage); | - | ||||||||||||
375 | if( nPage==0
| 1-83 | ||||||||||||
376 | pCsr->isEof = 1; | - | ||||||||||||
377 | return executed 1 time by 1 test: sqlite3_reset(pCsr->pStmt);return sqlite3_reset(pCsr->pStmt); Executed by:
executed 1 time by 1 test: return sqlite3_reset(pCsr->pStmt); Executed by:
| 1 | ||||||||||||
378 | } | - | ||||||||||||
379 | rc = sqlite3PagerGet(pPager, iRoot, &pCsr->aPage[0].pPg, 0); | - | ||||||||||||
380 | pCsr->aPage[0].iPgno = iRoot; | - | ||||||||||||
381 | pCsr->aPage[0].iCell = 0; | - | ||||||||||||
382 | pCsr->aPage[0].zPath = z = sqlite3_mprintf("/"); | - | ||||||||||||
383 | pCsr->iPage = 0; | - | ||||||||||||
384 | if( z==0
never executed: rc = 7; | 0-83 | ||||||||||||
385 | } executed 83 times by 1 test: else{end of block Executed by:
| 83 | ||||||||||||
386 | pCsr->isEof = 1; | - | ||||||||||||
387 | return executed 22 times by 1 test: sqlite3_reset(pCsr->pStmt);return sqlite3_reset(pCsr->pStmt); Executed by:
executed 22 times by 1 test: return sqlite3_reset(pCsr->pStmt); Executed by:
| 22 | ||||||||||||
388 | } | - | ||||||||||||
389 | }else{ | - | ||||||||||||
390 | - | |||||||||||||
391 | - | |||||||||||||
392 | StatPage *p = &pCsr->aPage[pCsr->iPage]; | - | ||||||||||||
393 | - | |||||||||||||
394 | while( p->iCell<p->nCell
| 1372-8357 | ||||||||||||
395 | StatCell *pCell = &p->aCell[p->iCell]; | - | ||||||||||||
396 | if( pCell->iOvfl<pCell->nOvfl
| 2516-5841 | ||||||||||||
397 | int nUsable; | - | ||||||||||||
398 | sqlite3BtreeEnter(pBt); | - | ||||||||||||
399 | nUsable = sqlite3BtreeGetPageSize(pBt) - | - | ||||||||||||
400 | sqlite3BtreeGetReserveNoMutex(pBt); | - | ||||||||||||
401 | sqlite3BtreeLeave(pBt); | - | ||||||||||||
402 | pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0); | - | ||||||||||||
403 | pCsr->iPageno = pCell->aOvfl[pCell->iOvfl]; | - | ||||||||||||
404 | pCsr->zPagetype = "overflow"; | - | ||||||||||||
405 | pCsr->nCell = 0; | - | ||||||||||||
406 | pCsr->nMxPayload = 0; | - | ||||||||||||
407 | pCsr->zPath = z = sqlite3_mprintf( | - | ||||||||||||
408 | "%s%.3x+%.6x", p->zPath, p->iCell, pCell->iOvfl | - | ||||||||||||
409 | ); | - | ||||||||||||
410 | if( pCell->iOvfl<pCell->nOvfl-1
| 90-2426 | ||||||||||||
411 | pCsr->nUnused = 0; | - | ||||||||||||
412 | pCsr->nPayload = nUsable - 4; | - | ||||||||||||
413 | } executed 90 times by 1 test: else{end of block Executed by:
| 90 | ||||||||||||
414 | pCsr->nPayload = pCell->nLastOvfl; | - | ||||||||||||
415 | pCsr->nUnused = nUsable - 4 - pCsr->nPayload; | - | ||||||||||||
416 | } executed 2426 times by 1 test: end of block Executed by:
| 2426 | ||||||||||||
417 | pCell->iOvfl++; | - | ||||||||||||
418 | statSizeAndOffset(pCsr); | - | ||||||||||||
419 | return executed 2516 times by 1 test: z==0return z==0 ? 7 : 0; Executed by:
executed 2516 times by 1 test: return z==0 ? 7 : 0; Executed by:
| 0-2516 | ||||||||||||
420 | } | - | ||||||||||||
421 | if( p->iRightChildPg
executed 1157 times by 1 test: break; Executed by:
| 1157-4684 | ||||||||||||
422 | p->iCell++; | - | ||||||||||||
423 | } executed 4684 times by 1 test: end of block Executed by:
| 4684 | ||||||||||||
424 | - | |||||||||||||
425 | if( !p->iRightChildPg
| 66-1289 | ||||||||||||
426 | statClearPage(p); | - | ||||||||||||
427 | if( pCsr->iPage==0
executed 83 times by 1 test: statNext(pCursor);return statNext(pCursor); Executed by:
executed 83 times by 1 test: return statNext(pCursor); Executed by:
| 83-1223 | ||||||||||||
428 | pCsr->iPage--; | - | ||||||||||||
429 | goto executed 1223 times by 1 test: statNextRestart;goto statNextRestart; Executed by:
executed 1223 times by 1 test: goto statNextRestart; Executed by:
| 1223 | ||||||||||||
430 | } | - | ||||||||||||
431 | pCsr->iPage++; | - | ||||||||||||
432 | - | |||||||||||||
433 | ((void) (0)) | - | ||||||||||||
434 | ; | - | ||||||||||||
435 | - | |||||||||||||
436 | if( p->iCell==p->nCell
| 66-1157 | ||||||||||||
437 | p[1].iPgno = p->iRightChildPg; | - | ||||||||||||
438 | } executed 66 times by 1 test: else{end of block Executed by:
| 66 | ||||||||||||
439 | p[1].iPgno = p->aCell[p->iCell].iChildPg; | - | ||||||||||||
440 | } executed 1157 times by 1 test: end of block Executed by:
| 1157 | ||||||||||||
441 | rc = sqlite3PagerGet(pPager, p[1].iPgno, &p[1].pPg, 0); | - | ||||||||||||
442 | p[1].iCell = 0; | - | ||||||||||||
443 | p[1].zPath = z = sqlite3_mprintf("%s%.3x/", p->zPath, p->iCell); | - | ||||||||||||
444 | p->iCell++; | - | ||||||||||||
445 | if( z==0
never executed: rc = 7; | 0-1223 | ||||||||||||
446 | } executed 1223 times by 1 test: end of block Executed by:
| 1223 | ||||||||||||
447 | - | |||||||||||||
448 | - | |||||||||||||
449 | - | |||||||||||||
450 | - | |||||||||||||
451 | - | |||||||||||||
452 | if( rc==0
| 0-1306 | ||||||||||||
453 | int i; | - | ||||||||||||
454 | StatPage *p = &pCsr->aPage[pCsr->iPage]; | - | ||||||||||||
455 | pCsr->zName = (char *)sqlite3_column_text(pCsr->pStmt, 0); | - | ||||||||||||
456 | pCsr->iPageno = p->iPgno; | - | ||||||||||||
457 | - | |||||||||||||
458 | rc = statDecodePage(pBt, p); | - | ||||||||||||
459 | if( rc==0
| 0-1306 | ||||||||||||
460 | statSizeAndOffset(pCsr); | - | ||||||||||||
461 | - | |||||||||||||
462 | switch( p->flags ){ | - | ||||||||||||
463 | case executed 15 times by 1 test: 0x05:case 0x05: Executed by:
executed 15 times by 1 test: case 0x05: Executed by:
| 15 | ||||||||||||
464 | case executed 51 times by 1 test: 0x02:case 0x02: Executed by:
executed 51 times by 1 test: case 0x02: Executed by:
| 51 | ||||||||||||
465 | pCsr->zPagetype = "internal"; | - | ||||||||||||
466 | break; executed 66 times by 1 test: break; Executed by:
| 66 | ||||||||||||
467 | case executed 1006 times by 1 test: 0x0D:case 0x0D: Executed by:
executed 1006 times by 1 test: case 0x0D: Executed by:
| 1006 | ||||||||||||
468 | case executed 234 times by 1 test: 0x0A:case 0x0A: Executed by:
executed 234 times by 1 test: case 0x0A: Executed by:
| 234 | ||||||||||||
469 | pCsr->zPagetype = "leaf"; | - | ||||||||||||
470 | break; executed 1240 times by 1 test: break; Executed by:
| 1240 | ||||||||||||
471 | default never executed: :default: never executed: default: | 0 | ||||||||||||
472 | pCsr->zPagetype = "corrupted"; | - | ||||||||||||
473 | break; never executed: break; | 0 | ||||||||||||
474 | } | - | ||||||||||||
475 | pCsr->nCell = p->nCell; | - | ||||||||||||
476 | pCsr->nUnused = p->nUnused; | - | ||||||||||||
477 | pCsr->nMxPayload = p->nMxPayload; | - | ||||||||||||
478 | pCsr->zPath = z = sqlite3_mprintf("%s", p->zPath); | - | ||||||||||||
479 | if( z==0
never executed: rc = 7; | 0-1306 | ||||||||||||
480 | nPayload = 0; | - | ||||||||||||
481 | for(i=0; i<p->nCell
| 1306-5841 | ||||||||||||
482 | nPayload += p->aCell[i].nLocal; | - | ||||||||||||
483 | } executed 5841 times by 1 test: end of block Executed by:
| 5841 | ||||||||||||
484 | pCsr->nPayload = nPayload; | - | ||||||||||||
485 | } executed 1306 times by 1 test: end of block Executed by:
| 1306 | ||||||||||||
486 | } executed 1306 times by 1 test: end of block Executed by:
| 1306 | ||||||||||||
487 | - | |||||||||||||
488 | return executed 1306 times by 1 test: rc;return rc; Executed by:
executed 1306 times by 1 test: return rc; Executed by:
| 1306 | ||||||||||||
489 | } | - | ||||||||||||
490 | - | |||||||||||||
491 | static int statEof(sqlite3_vtab_cursor *pCursor){ | - | ||||||||||||
492 | StatCursor *pCsr = (StatCursor *)pCursor; | - | ||||||||||||
493 | return executed 3845 times by 1 test: pCsr->isEof;return pCsr->isEof; Executed by:
executed 3845 times by 1 test: return pCsr->isEof; Executed by:
| 3845 | ||||||||||||
494 | } | - | ||||||||||||
495 | - | |||||||||||||
496 | static int statFilter( | - | ||||||||||||
497 | sqlite3_vtab_cursor *pCursor, | - | ||||||||||||
498 | int idxNum, const char *idxStr, | - | ||||||||||||
499 | int argc, sqlite3_value **argv | - | ||||||||||||
500 | ){ | - | ||||||||||||
501 | StatCursor *pCsr = (StatCursor *)pCursor; | - | ||||||||||||
502 | StatTable *pTab = (StatTable*)(pCursor->pVtab); | - | ||||||||||||
503 | char *zSql; | - | ||||||||||||
504 | int rc = 0; | - | ||||||||||||
505 | char *zMaster; | - | ||||||||||||
506 | - | |||||||||||||
507 | if( idxNum==1
| 3-20 | ||||||||||||
508 | const char *zDbase = (const char*)sqlite3_value_text(argv[0]); | - | ||||||||||||
509 | pCsr->iDb = sqlite3FindDbName(pTab->db, zDbase); | - | ||||||||||||
510 | if( pCsr->iDb<0
| 0-3 | ||||||||||||
511 | sqlite3_free(pCursor->pVtab->zErrMsg); | - | ||||||||||||
512 | pCursor->pVtab->zErrMsg = sqlite3_mprintf("no such schema: %s", zDbase); | - | ||||||||||||
513 | return never executed: pCursor->pVtab->zErrMsgreturn pCursor->pVtab->zErrMsg ? 1 : 7;
never executed: return pCursor->pVtab->zErrMsg ? 1 : 7; | 0 | ||||||||||||
514 | } | - | ||||||||||||
515 | } executed 3 times by 1 test: else{end of block Executed by:
| 3 | ||||||||||||
516 | pCsr->iDb = pTab->iDb; | - | ||||||||||||
517 | } executed 20 times by 1 test: end of block Executed by:
| 20 | ||||||||||||
518 | statResetCsr(pCsr); | - | ||||||||||||
519 | sqlite3_finalize(pCsr->pStmt); | - | ||||||||||||
520 | pCsr->pStmt = 0; | - | ||||||||||||
521 | zMaster = pCsr->iDb==1
| 0-23 | ||||||||||||
522 | zSql = sqlite3_mprintf( | - | ||||||||||||
523 | "SELECT 'sqlite_master' AS name, 1 AS rootpage, 'table' AS type" | - | ||||||||||||
524 | " UNION ALL " | - | ||||||||||||
525 | "SELECT name, rootpage, type" | - | ||||||||||||
526 | " FROM \"%w\".%s WHERE rootpage!=0" | - | ||||||||||||
527 | " ORDER BY name", pTab->db->aDb[pCsr->iDb].zDbSName, zMaster); | - | ||||||||||||
528 | if( zSql==0
| 0-23 | ||||||||||||
529 | return never executed: 7;return 7; never executed: return 7; | 0 | ||||||||||||
530 | }else{ | - | ||||||||||||
531 | rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pStmt, 0); | - | ||||||||||||
532 | sqlite3_free(zSql); | - | ||||||||||||
533 | } executed 23 times by 1 test: end of block Executed by:
| 23 | ||||||||||||
534 | - | |||||||||||||
535 | if( rc==0
| 0-23 | ||||||||||||
536 | rc = statNext(pCursor); | - | ||||||||||||
537 | } executed 23 times by 1 test: end of block Executed by:
| 23 | ||||||||||||
538 | return executed 23 times by 1 test: rc;return rc; Executed by:
executed 23 times by 1 test: return rc; Executed by:
| 23 | ||||||||||||
539 | } | - | ||||||||||||
540 | - | |||||||||||||
541 | static int statColumn( | - | ||||||||||||
542 | sqlite3_vtab_cursor *pCursor, | - | ||||||||||||
543 | sqlite3_context *ctx, | - | ||||||||||||
544 | int i | - | ||||||||||||
545 | ){ | - | ||||||||||||
546 | StatCursor *pCsr = (StatCursor *)pCursor; | - | ||||||||||||
547 | switch( i ){ | - | ||||||||||||
548 | case executed 3618 times by 1 test: 0:case 0: Executed by:
executed 3618 times by 1 test: case 0: Executed by:
| 3618 | ||||||||||||
549 | sqlite3_result_text(ctx, pCsr->zName, -1, ((sqlite3_destructor_type)-1)); | - | ||||||||||||
550 | break; executed 3618 times by 1 test: break; Executed by:
| 3618 | ||||||||||||
551 | case executed 60 times by 1 test: 1:case 1: Executed by:
executed 60 times by 1 test: case 1: Executed by:
| 60 | ||||||||||||
552 | sqlite3_result_text(ctx, pCsr->zPath, -1, ((sqlite3_destructor_type)-1)); | - | ||||||||||||
553 | break; executed 60 times by 1 test: break; Executed by:
| 60 | ||||||||||||
554 | case executed 1221 times by 1 test: 2:case 2: Executed by:
executed 1221 times by 1 test: case 2: Executed by:
| 1221 | ||||||||||||
555 | sqlite3_result_int64(ctx, pCsr->iPageno); | - | ||||||||||||
556 | break; executed 1221 times by 1 test: break; Executed by:
| 1221 | ||||||||||||
557 | case executed 60 times by 1 test: 3:case 3: Executed by:
executed 60 times by 1 test: case 3: Executed by:
| 60 | ||||||||||||
558 | sqlite3_result_text(ctx, pCsr->zPagetype, -1, ((sqlite3_destructor_type)0)); | - | ||||||||||||
559 | break; executed 60 times by 1 test: break; Executed by:
| 60 | ||||||||||||
560 | case executed 60 times by 1 test: 4:case 4: Executed by:
executed 60 times by 1 test: case 4: Executed by:
| 60 | ||||||||||||
561 | sqlite3_result_int(ctx, pCsr->nCell); | - | ||||||||||||
562 | break; executed 60 times by 1 test: break; Executed by:
| 60 | ||||||||||||
563 | case executed 60 times by 1 test: 5:case 5: Executed by:
executed 60 times by 1 test: case 5: Executed by:
| 60 | ||||||||||||
564 | sqlite3_result_int(ctx, pCsr->nPayload); | - | ||||||||||||
565 | break; executed 60 times by 1 test: break; Executed by:
| 60 | ||||||||||||
566 | case executed 60 times by 1 test: 6:case 6: Executed by:
executed 60 times by 1 test: case 6: Executed by:
| 60 | ||||||||||||
567 | sqlite3_result_int(ctx, pCsr->nUnused); | - | ||||||||||||
568 | break; executed 60 times by 1 test: break; Executed by:
| 60 | ||||||||||||
569 | case executed 60 times by 1 test: 7:case 7: Executed by:
executed 60 times by 1 test: case 7: Executed by:
| 60 | ||||||||||||
570 | sqlite3_result_int(ctx, pCsr->nMxPayload); | - | ||||||||||||
571 | break; executed 60 times by 1 test: break; Executed by:
| 60 | ||||||||||||
572 | case executed 12 times by 1 test: 8:case 8: Executed by:
executed 12 times by 1 test: case 8: Executed by:
| 12 | ||||||||||||
573 | sqlite3_result_int64(ctx, pCsr->iOffset); | - | ||||||||||||
574 | break; executed 12 times by 1 test: break; Executed by:
| 12 | ||||||||||||
575 | case executed 12 times by 1 test: 9:case 9: Executed by:
executed 12 times by 1 test: case 9: Executed by:
| 12 | ||||||||||||
576 | sqlite3_result_int(ctx, pCsr->szPage); | - | ||||||||||||
577 | break; executed 12 times by 1 test: break; Executed by:
| 12 | ||||||||||||
578 | default never executed: :default: never executed: {default: | 0 | ||||||||||||
579 | sqlite3 *db = sqlite3_context_db_handle(ctx); | - | ||||||||||||
580 | int iDb = pCsr->iDb; | - | ||||||||||||
581 | sqlite3_result_text(ctx, db->aDb[iDb].zDbSName, -1, ((sqlite3_destructor_type)0)); | - | ||||||||||||
582 | break; never executed: break; | 0 | ||||||||||||
583 | } | - | ||||||||||||
584 | } | - | ||||||||||||
585 | return executed 5223 times by 1 test: 0;return 0; Executed by:
executed 5223 times by 1 test: return 0; Executed by:
| 5223 | ||||||||||||
586 | } | - | ||||||||||||
587 | - | |||||||||||||
588 | static int statRowid(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){ | - | ||||||||||||
589 | StatCursor *pCsr = (StatCursor *)pCursor; | - | ||||||||||||
590 | *pRowid = pCsr->iPageno; | - | ||||||||||||
591 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
592 | } | - | ||||||||||||
593 | - | |||||||||||||
594 | - | |||||||||||||
595 | - | |||||||||||||
596 | - | |||||||||||||
597 | int sqlite3DbstatRegister(sqlite3 *db){ | - | ||||||||||||
598 | static sqlite3_module dbstat_module = { | - | ||||||||||||
599 | 0, | - | ||||||||||||
600 | statConnect, | - | ||||||||||||
601 | statConnect, | - | ||||||||||||
602 | statBestIndex, | - | ||||||||||||
603 | statDisconnect, | - | ||||||||||||
604 | statDisconnect, | - | ||||||||||||
605 | statOpen, | - | ||||||||||||
606 | statClose, | - | ||||||||||||
607 | statFilter, | - | ||||||||||||
608 | statNext, | - | ||||||||||||
609 | statEof, | - | ||||||||||||
610 | statColumn, | - | ||||||||||||
611 | statRowid, | - | ||||||||||||
612 | 0, | - | ||||||||||||
613 | 0, | - | ||||||||||||
614 | 0, | - | ||||||||||||
615 | 0, | - | ||||||||||||
616 | 0, | - | ||||||||||||
617 | 0, | - | ||||||||||||
618 | 0, | - | ||||||||||||
619 | 0, | - | ||||||||||||
620 | 0, | - | ||||||||||||
621 | 0, | - | ||||||||||||
622 | }; | - | ||||||||||||
623 | return executed 4 times by 1 test: sqlite3_create_module(db, "dbstat", &dbstat_module, 0);return sqlite3_create_module(db, "dbstat", &dbstat_module, 0); Executed by:
executed 4 times by 1 test: return sqlite3_create_module(db, "dbstat", &dbstat_module, 0); Executed by:
| 4 | ||||||||||||
624 | } | - | ||||||||||||
Switch to Source code | Preprocessed file |