OpenCoverage

dbstat.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/sqlite/src/src/dbstat.c
Switch to Source codePreprocessed file
LineSourceCount
1typedef struct StatTable StatTable;-
2typedef struct StatCursor StatCursor;-
3typedef struct StatPage StatPage;-
4typedef struct StatCell StatCell;-
5-
6struct StatCell {-
7 int nLocal;-
8 u32 iChildPg;-
9 int nOvfl;-
10 u32 *aOvfl;-
11 int nLastOvfl;-
12 int iOvfl;-
13};-
14-
15struct 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-
31struct 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-
53struct StatTable {-
54 sqlite3_vtab base;-
55 sqlite3 *db;-
56 int iDb;-
57};-
58static 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
argc>=4Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test (438)
){
5-11
70 Token nm;-
71 sqlite3TokenInit(&nm, (char*)argv[3]);-
72 iDb = sqlite3FindDb(db, &nm);-
73 if( iDb<0
iDb<0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test (438)
){
1-4
74 *pzErr = sqlite3_mprintf("no such database: %s", argv[3]);-
75 return
executed 1 time by 1 test: return 1;
Executed by:
  • Self test (438)
1;
executed 1 time by 1 test: return 1;
Executed by:
  • Self test (438)
1
76 }-
77 }
executed 4 times by 1 test: end of block
Executed by:
  • Self test (438)
else{
4
78 iDb = 0;-
79 }
executed 11 times by 1 test: end of block
Executed by:
  • Self test (438)
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
rc==0Description
TRUEevaluated 15 times by 1 test
Evaluated by:
  • Self test (438)
FALSEnever evaluated
){
0-15
82 pTab = (StatTable *)sqlite3_malloc64(sizeof(StatTable));-
83 if( pTab==0
pTab==0Description
TRUEnever evaluated
FALSEevaluated 15 times by 1 test
Evaluated by:
  • Self test (438)
) rc = 7;
never executed: rc = 7;
0-15
84 }
executed 15 times by 1 test: end of block
Executed by:
  • Self test (438)
15
85-
86 -
87 ((void) (0))-
88 ;-
89 if( rc==0
rc==0Description
TRUEevaluated 15 times by 1 test
Evaluated by:
  • Self test (438)
FALSEnever evaluated
){
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:
  • Self test (438)
15
94-
95 *ppVtab = (sqlite3_vtab*)pTab;-
96 return
executed 15 times by 1 test: return rc;
Executed by:
  • Self test (438)
rc;
executed 15 times by 1 test: return rc;
Executed by:
  • Self test (438)
15
97}-
98-
99-
100-
101-
102static int statDisconnect(sqlite3_vtab *pVtab){-
103 sqlite3_free(pVtab);-
104 return
executed 15 times by 1 test: return 0;
Executed by:
  • Self test (438)
0;
executed 15 times by 1 test: return 0;
Executed by:
  • Self test (438)
15
105}-
106static 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
i<pIdxInfo->nConstraintDescription
TRUEevaluated 17 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 21 times by 1 test
Evaluated by:
  • Self test (438)
; i++){
17-21
117 if( pIdxInfo->aConstraint[i].usable==0
pIdxInfo->aCon...t[i].usable==0Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test (438)
) continue;
never executed: continue;
0-17
118 if( pIdxInfo->aConstraint[i].op!=2
pIdxInfo->aConstraint[i].op!=2Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 15 times by 1 test
Evaluated by:
  • Self test (438)
) continue;
executed 2 times by 1 test: continue;
Executed by:
  • Self test (438)
2-15
119 if( pIdxInfo->aConstraint[i].iColumn!=10
pIdxInfo->aCon...i].iColumn!=10Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test (438)
) continue;
executed 12 times by 1 test: continue;
Executed by:
  • Self test (438)
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:
  • Self test (438)
3
125 }-
126-
127-
128-
129-
130-
131-
132 if( ( pIdxInfo->nOrderBy==1
pIdxInfo->nOrderBy==1Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test (438)
6-18
133 && pIdxInfo->aOrderBy[0].iColumn==0
pIdxInfo->aOrd...[0].iColumn==0Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test (438)
0-6
134 && pIdxInfo->aOrderBy[0].desc==0
pIdxInfo->aOrderBy[0].desc==0Description
TRUEnever evaluated
FALSEnever evaluated
0
135 ) ||-
136 ( pIdxInfo->nOrderBy==2
pIdxInfo->nOrderBy==2Description
TRUEnever evaluated
FALSEevaluated 24 times by 1 test
Evaluated by:
  • Self test (438)
0-24
137 && pIdxInfo->aOrderBy[0].iColumn==0
pIdxInfo->aOrd...[0].iColumn==0Description
TRUEnever evaluated
FALSEnever evaluated
0
138 && pIdxInfo->aOrderBy[0].desc==0
pIdxInfo->aOrderBy[0].desc==0Description
TRUEnever evaluated
FALSEnever evaluated
0
139 && pIdxInfo->aOrderBy[1].iColumn==1
pIdxInfo->aOrd...[1].iColumn==1Description
TRUEnever evaluated
FALSEnever evaluated
0
140 && pIdxInfo->aOrderBy[1].desc==0
pIdxInfo->aOrderBy[1].desc==0Description
TRUEnever evaluated
FALSEnever evaluated
0
141 )-
142 ){-
143 pIdxInfo->orderByConsumed = 1;-
144 }
never executed: end of block
0
145-
146 return
executed 24 times by 1 test: return 0;
Executed by:
  • Self test (438)
0;
executed 24 times by 1 test: return 0;
Executed by:
  • Self test (438)
24
147}-
148-
149-
150-
151-
152static 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
pCsr==0Description
TRUEnever evaluated
FALSEevaluated 23 times by 1 test
Evaluated by:
  • Self test (438)
){
0-23
158 return
never executed: return 7;
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:
  • Self test (438)
23
164-
165 *ppCursor = (sqlite3_vtab_cursor *)pCsr;-
166 return
executed 23 times by 1 test: return 0;
Executed by:
  • Self test (438)
0;
executed 23 times by 1 test: return 0;
Executed by:
  • Self test (438)
23
167}-
168-
169static void statClearPage(StatPage *p){-
170 int i;-
171 if( p->aCell
p->aCellDescription
TRUEevaluated 1303 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1475 times by 1 test
Evaluated by:
  • Self test (438)
){
1303-1475
172 for(i=0; i<p->nCell
i<p->nCellDescription
TRUEevaluated 5841 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1303 times by 1 test
Evaluated by:
  • Self test (438)
; i++){
1303-5841
173 sqlite3_free(p->aCell[i].aOvfl);-
174 }
executed 5841 times by 1 test: end of block
Executed by:
  • Self test (438)
5841
175 sqlite3_free(p->aCell);-
176 }
executed 1303 times by 1 test: end of block
Executed by:
  • Self test (438)
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:
  • Self test (438)
2778
181-
182static 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])))
i<((int)(sizeo...r->aPage[0])))Description
TRUEevaluated 1472 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 46 times by 1 test
Evaluated by:
  • Self test (438)
; i++){
46-1472
186 statClearPage(&pCsr->aPage[i]);-
187 }
executed 1472 times by 1 test: end of block
Executed by:
  • Self test (438)
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:
  • Self test (438)
46
193-
194-
195-
196-
197static 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: return 0;
Executed by:
  • Self test (438)
0;
executed 23 times by 1 test: return 0;
Executed by:
  • Self test (438)
23
203}-
204-
205static 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
flags==0x0DDescription
TRUEevaluated 1709 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 3176 times by 1 test
Evaluated by:
  • Self test (438)
){
1709-3176
216 nMinLocal = (nUsable - 12) * 32 / 255 - 23;-
217 nMaxLocal = nUsable - 35;-
218 }
executed 1709 times by 1 test: end of block
Executed by:
  • Self test (438)
else{
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:
  • Self test (438)
3176
222-
223 nLocal = nMinLocal + (nTotal - nMinLocal) % (nUsable - 4);-
224 if( nLocal>nMaxLocal
nLocal>nMaxLocalDescription
TRUEevaluated 2358 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 2527 times by 1 test
Evaluated by:
  • Self test (438)
) nLocal = nMinLocal;
executed 2358 times by 1 test: nLocal = nMinLocal;
Executed by:
  • Self test (438)
2358-2527
225 *pnLocal = nLocal;-
226}
executed 4885 times by 1 test: end of block
Executed by:
  • Self test (438)
4885
227-
228static 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
p->flags==0x0ADescription
TRUEevaluated 234 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1072 times by 1 test
Evaluated by:
  • Self test (438)
|| p->flags==0x0D
p->flags==0x0DDescription
TRUEevaluated 1006 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 66 times by 1 test
Evaluated by:
  • Self test (438)
);
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
iOffDescription
TRUEevaluated 48 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1306 times by 1 test
Evaluated by:
  • Self test (438)
){
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:
  • Self test (438)
48
252 p->nUnused = nUnused;-
253 p->iRightChildPg = isLeaf
isLeafDescription
TRUEevaluated 1240 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 66 times by 1 test
Evaluated by:
  • Self test (438)
? 0 : sqlite3Get4byte(&aHdr[8]);
66-1240
254 szPage = sqlite3BtreeGetPageSize(pBt);-
255-
256 if( p->nCell
p->nCellDescription
TRUEevaluated 1303 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test (438)
){
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
p->aCell==0Description
TRUEnever evaluated
FALSEevaluated 1303 times by 1 test
Evaluated by:
  • Self test (438)
) return
never executed: return 7;
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
i<p->nCellDescription
TRUEevaluated 5841 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1303 times by 1 test
Evaluated by:
  • Self test (438)
; i++){
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
!isLeafDescription
TRUEevaluated 1157 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 4684 times by 1 test
Evaluated by:
  • Self test (438)
){
1157-4684
272 pCell->iChildPg = sqlite3Get4byte(&aData[iOff]);-
273 iOff += 4;-
274 }
executed 1157 times by 1 test: end of block
Executed by:
  • Self test (438)
1157
275 if( p->flags==0x05
p->flags==0x05Description
TRUEevaluated 956 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 4885 times by 1 test
Evaluated by:
  • Self test (438)
){
956-4885
276-
277 }
executed 956 times by 1 test: end of block
Executed by:
  • Self test (438)
else{
956
278 u32 nPayload;-
279 int nLocal;-
280 iOff += (u8)((*(
(*(&aData[iOff])<(u8)0x80)Description
TRUEevaluated 1264 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 3621 times by 1 test
Evaluated by:
  • Self test (438)
&aData[iOff])<(u8)0x80)
(*(&aData[iOff])<(u8)0x80)Description
TRUEevaluated 1264 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 3621 times by 1 test
Evaluated by:
  • Self test (438)
?((nPayload)=(u32)*(&aData[iOff])),1:sqlite3GetVarint32((&aData[iOff]),(u32 *)&(nPayload)));
1264-3621
281 if( p->flags==0x0D
p->flags==0x0DDescription
TRUEevaluated 1709 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 3176 times by 1 test
Evaluated by:
  • Self test (438)
){
1709-3176
282 u64 dummy;-
283 iOff += sqlite3GetVarint(&aData[iOff], &dummy);-
284 }
executed 1709 times by 1 test: end of block
Executed by:
  • Self test (438)
1709
285 if( nPayload>(u32)p->nMxPayload
nPayload>(u32)p->nMxPayloadDescription
TRUEevaluated 1430 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 3455 times by 1 test
Evaluated by:
  • Self test (438)
) p->nMxPayload = nPayload;
executed 1430 times by 1 test: p->nMxPayload = nPayload;
Executed by:
  • Self test (438)
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
nPayload>(u32)nLocalDescription
TRUEevaluated 2426 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 2459 times by 1 test
Evaluated by:
  • Self test (438)
){
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
pCell->aOvfl==0Description
TRUEnever evaluated
FALSEevaluated 2426 times by 1 test
Evaluated by:
  • Self test (438)
) return
never executed: return 7;
7;
never executed: return 7;
0-2426
304 pCell->aOvfl[0] = sqlite3Get4byte(&aData[iOff+nLocal]);-
305 for(j=1; j<nOvfl
j<nOvflDescription
TRUEevaluated 90 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 2426 times by 1 test
Evaluated by:
  • Self test (438)
; j++){
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
rc!=0Description
TRUEnever evaluated
FALSEevaluated 90 times by 1 test
Evaluated by:
  • Self test (438)
){
0-90
311 -
312 ((void) (0))-
313 ;-
314 return
never executed: return rc;
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:
  • Self test (438)
90
319 }
executed 2426 times by 1 test: end of block
Executed by:
  • Self test (438)
2426
320 }
executed 4885 times by 1 test: end of block
Executed by:
  • Self test (438)
4885
321 }-
322 }
executed 1303 times by 1 test: end of block
Executed by:
  • Self test (438)
1303
323-
324 return
executed 1306 times by 1 test: return 0;
Executed by:
  • Self test (438)
0;
executed 1306 times by 1 test: return 0;
Executed by:
  • Self test (438)
1306
325}-
326-
327-
328-
329-
330-
331static 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
sqlite3OsFileC...230440, &x)==0Description
TRUEnever evaluated
FALSEevaluated 3822 times by 1 test
Evaluated by:
  • Self test (438)
){
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:
  • Self test (438)
3822
352-
353-
354-
355-
356static 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-
368statNextRestart:
code before this statement executed 3928 times by 1 test: statNextRestart:
Executed by:
  • Self test (438)
3928
369 if( pCsr->aPage[0].pPg==0
pCsr->aPage[0].pPg==0Description
TRUEevaluated 106 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 5045 times by 1 test
Evaluated by:
  • Self test (438)
){
106-5045
370 rc = sqlite3_step(pCsr->pStmt);-
371 if( rc==100
rc==100Description
TRUEevaluated 84 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 22 times by 1 test
Evaluated by:
  • Self test (438)
){
22-84
372 int nPage;-
373 u32 iRoot = (u32)sqlite3_column_int64(pCsr->pStmt, 1);-
374 sqlite3PagerPagecount(pPager, &nPage);-
375 if( nPage==0
nPage==0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 83 times by 1 test
Evaluated by:
  • Self test (438)
){
1-83
376 pCsr->isEof = 1;-
377 return
executed 1 time by 1 test: return sqlite3_reset(pCsr->pStmt);
Executed by:
  • Self test (438)
sqlite3_reset(pCsr->pStmt);
executed 1 time by 1 test: return sqlite3_reset(pCsr->pStmt);
Executed by:
  • Self test (438)
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
z==0Description
TRUEnever evaluated
FALSEevaluated 83 times by 1 test
Evaluated by:
  • Self test (438)
) rc = 7;
never executed: rc = 7;
0-83
385 }
executed 83 times by 1 test: end of block
Executed by:
  • Self test (438)
else{
83
386 pCsr->isEof = 1;-
387 return
executed 22 times by 1 test: return sqlite3_reset(pCsr->pStmt);
Executed by:
  • Self test (438)
sqlite3_reset(pCsr->pStmt);
executed 22 times by 1 test: return sqlite3_reset(pCsr->pStmt);
Executed by:
  • Self test (438)
22
388 }-
389 }else{-
390-
391-
392 StatPage *p = &pCsr->aPage[pCsr->iPage];-
393-
394 while( p->iCell<p->nCell
p->iCell<p->nCellDescription
TRUEevaluated 8357 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1372 times by 1 test
Evaluated by:
  • Self test (438)
){
1372-8357
395 StatCell *pCell = &p->aCell[p->iCell];-
396 if( pCell->iOvfl<pCell->nOvfl
pCell->iOvfl<pCell->nOvflDescription
TRUEevaluated 2516 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 5841 times by 1 test
Evaluated by:
  • Self test (438)
){
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
pCell->iOvfl<pCell->nOvfl-1Description
TRUEevaluated 90 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 2426 times by 1 test
Evaluated by:
  • Self test (438)
){
90-2426
411 pCsr->nUnused = 0;-
412 pCsr->nPayload = nUsable - 4;-
413 }
executed 90 times by 1 test: end of block
Executed by:
  • Self test (438)
else{
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:
  • Self test (438)
2426
417 pCell->iOvfl++;-
418 statSizeAndOffset(pCsr);-
419 return
executed 2516 times by 1 test: return z==0 ? 7 : 0;
Executed by:
  • Self test (438)
z==0
z==0Description
TRUEnever evaluated
FALSEevaluated 2516 times by 1 test
Evaluated by:
  • Self test (438)
? 7 : 0;
executed 2516 times by 1 test: return z==0 ? 7 : 0;
Executed by:
  • Self test (438)
0-2516
420 }-
421 if( p->iRightChildPg
p->iRightChildPgDescription
TRUEevaluated 1157 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 4684 times by 1 test
Evaluated by:
  • Self test (438)
) break;
executed 1157 times by 1 test: break;
Executed by:
  • Self test (438)
1157-4684
422 p->iCell++;-
423 }
executed 4684 times by 1 test: end of block
Executed by:
  • Self test (438)
4684
424-
425 if( !p->iRightChildPg
!p->iRightChildPgDescription
TRUEevaluated 1240 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1289 times by 1 test
Evaluated by:
  • Self test (438)
|| p->iCell>p->nCell
p->iCell>p->nCellDescription
TRUEevaluated 66 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1223 times by 1 test
Evaluated by:
  • Self test (438)
){
66-1289
426 statClearPage(p);-
427 if( pCsr->iPage==0
pCsr->iPage==0Description
TRUEevaluated 83 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1223 times by 1 test
Evaluated by:
  • Self test (438)
) return
executed 83 times by 1 test: return statNext(pCursor);
Executed by:
  • Self test (438)
statNext(pCursor);
executed 83 times by 1 test: return statNext(pCursor);
Executed by:
  • Self test (438)
83-1223
428 pCsr->iPage--;-
429 goto
executed 1223 times by 1 test: goto statNextRestart;
Executed by:
  • Self test (438)
statNextRestart;
executed 1223 times by 1 test: goto statNextRestart;
Executed by:
  • Self test (438)
1223
430 }-
431 pCsr->iPage++;-
432 -
433 ((void) (0))-
434 ;-
435-
436 if( p->iCell==p->nCell
p->iCell==p->nCellDescription
TRUEevaluated 66 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1157 times by 1 test
Evaluated by:
  • Self test (438)
){
66-1157
437 p[1].iPgno = p->iRightChildPg;-
438 }
executed 66 times by 1 test: end of block
Executed by:
  • Self test (438)
else{
66
439 p[1].iPgno = p->aCell[p->iCell].iChildPg;-
440 }
executed 1157 times by 1 test: end of block
Executed by:
  • Self test (438)
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
z==0Description
TRUEnever evaluated
FALSEevaluated 1223 times by 1 test
Evaluated by:
  • Self test (438)
) rc = 7;
never executed: rc = 7;
0-1223
446 }
executed 1223 times by 1 test: end of block
Executed by:
  • Self test (438)
1223
447-
448-
449-
450-
451-
452 if( rc==0
rc==0Description
TRUEevaluated 1306 times by 1 test
Evaluated by:
  • Self test (438)
FALSEnever evaluated
){
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
rc==0Description
TRUEevaluated 1306 times by 1 test
Evaluated by:
  • Self test (438)
FALSEnever evaluated
){
0-1306
460 statSizeAndOffset(pCsr);-
461-
462 switch( p->flags ){-
463 case
executed 15 times by 1 test: case 0x05:
Executed by:
  • Self test (438)
0x05:
executed 15 times by 1 test: case 0x05:
Executed by:
  • Self test (438)
15
464 case
executed 51 times by 1 test: case 0x02:
Executed by:
  • Self test (438)
0x02:
executed 51 times by 1 test: case 0x02:
Executed by:
  • Self test (438)
51
465 pCsr->zPagetype = "internal";-
466 break;
executed 66 times by 1 test: break;
Executed by:
  • Self test (438)
66
467 case
executed 1006 times by 1 test: case 0x0D:
Executed by:
  • Self test (438)
0x0D:
executed 1006 times by 1 test: case 0x0D:
Executed by:
  • Self test (438)
1006
468 case
executed 234 times by 1 test: case 0x0A:
Executed by:
  • Self test (438)
0x0A:
executed 234 times by 1 test: case 0x0A:
Executed by:
  • Self test (438)
234
469 pCsr->zPagetype = "leaf";-
470 break;
executed 1240 times by 1 test: break;
Executed by:
  • Self test (438)
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
z==0Description
TRUEnever evaluated
FALSEevaluated 1306 times by 1 test
Evaluated by:
  • Self test (438)
) rc = 7;
never executed: rc = 7;
0-1306
480 nPayload = 0;-
481 for(i=0; i<p->nCell
i<p->nCellDescription
TRUEevaluated 5841 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1306 times by 1 test
Evaluated by:
  • Self test (438)
; i++){
1306-5841
482 nPayload += p->aCell[i].nLocal;-
483 }
executed 5841 times by 1 test: end of block
Executed by:
  • Self test (438)
5841
484 pCsr->nPayload = nPayload;-
485 }
executed 1306 times by 1 test: end of block
Executed by:
  • Self test (438)
1306
486 }
executed 1306 times by 1 test: end of block
Executed by:
  • Self test (438)
1306
487-
488 return
executed 1306 times by 1 test: return rc;
Executed by:
  • Self test (438)
rc;
executed 1306 times by 1 test: return rc;
Executed by:
  • Self test (438)
1306
489}-
490-
491static int statEof(sqlite3_vtab_cursor *pCursor){-
492 StatCursor *pCsr = (StatCursor *)pCursor;-
493 return
executed 3845 times by 1 test: return pCsr->isEof;
Executed by:
  • Self test (438)
pCsr->isEof;
executed 3845 times by 1 test: return pCsr->isEof;
Executed by:
  • Self test (438)
3845
494}-
495-
496static 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
idxNum==1Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 20 times by 1 test
Evaluated by:
  • Self test (438)
){
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
pCsr->iDb<0Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test (438)
){
0-3
511 sqlite3_free(pCursor->pVtab->zErrMsg);-
512 pCursor->pVtab->zErrMsg = sqlite3_mprintf("no such schema: %s", zDbase);-
513 return
never executed: return pCursor->pVtab->zErrMsg ? 1 : 7;
pCursor->pVtab->zErrMsg
pCursor->pVtab->zErrMsgDescription
TRUEnever evaluated
FALSEnever evaluated
? 1 : 7;
never executed: return pCursor->pVtab->zErrMsg ? 1 : 7;
0
514 }-
515 }
executed 3 times by 1 test: end of block
Executed by:
  • Self test (438)
else{
3
516 pCsr->iDb = pTab->iDb;-
517 }
executed 20 times by 1 test: end of block
Executed by:
  • Self test (438)
20
518 statResetCsr(pCsr);-
519 sqlite3_finalize(pCsr->pStmt);-
520 pCsr->pStmt = 0;-
521 zMaster = pCsr->iDb==1
pCsr->iDb==1Description
TRUEnever evaluated
FALSEevaluated 23 times by 1 test
Evaluated by:
  • Self test (438)
? "sqlite_temp_master" : "sqlite_master";
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
zSql==0Description
TRUEnever evaluated
FALSEevaluated 23 times by 1 test
Evaluated by:
  • Self test (438)
){
0-23
529 return
never executed: return 7;
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:
  • Self test (438)
23
534-
535 if( rc==0
rc==0Description
TRUEevaluated 23 times by 1 test
Evaluated by:
  • Self test (438)
FALSEnever evaluated
){
0-23
536 rc = statNext(pCursor);-
537 }
executed 23 times by 1 test: end of block
Executed by:
  • Self test (438)
23
538 return
executed 23 times by 1 test: return rc;
Executed by:
  • Self test (438)
rc;
executed 23 times by 1 test: return rc;
Executed by:
  • Self test (438)
23
539}-
540-
541static 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: case 0:
Executed by:
  • Self test (438)
0:
executed 3618 times by 1 test: case 0:
Executed by:
  • Self test (438)
3618
549 sqlite3_result_text(ctx, pCsr->zName, -1, ((sqlite3_destructor_type)-1));-
550 break;
executed 3618 times by 1 test: break;
Executed by:
  • Self test (438)
3618
551 case
executed 60 times by 1 test: case 1:
Executed by:
  • Self test (438)
1:
executed 60 times by 1 test: case 1:
Executed by:
  • Self test (438)
60
552 sqlite3_result_text(ctx, pCsr->zPath, -1, ((sqlite3_destructor_type)-1));-
553 break;
executed 60 times by 1 test: break;
Executed by:
  • Self test (438)
60
554 case
executed 1221 times by 1 test: case 2:
Executed by:
  • Self test (438)
2:
executed 1221 times by 1 test: case 2:
Executed by:
  • Self test (438)
1221
555 sqlite3_result_int64(ctx, pCsr->iPageno);-
556 break;
executed 1221 times by 1 test: break;
Executed by:
  • Self test (438)
1221
557 case
executed 60 times by 1 test: case 3:
Executed by:
  • Self test (438)
3:
executed 60 times by 1 test: case 3:
Executed by:
  • Self test (438)
60
558 sqlite3_result_text(ctx, pCsr->zPagetype, -1, ((sqlite3_destructor_type)0));-
559 break;
executed 60 times by 1 test: break;
Executed by:
  • Self test (438)
60
560 case
executed 60 times by 1 test: case 4:
Executed by:
  • Self test (438)
4:
executed 60 times by 1 test: case 4:
Executed by:
  • Self test (438)
60
561 sqlite3_result_int(ctx, pCsr->nCell);-
562 break;
executed 60 times by 1 test: break;
Executed by:
  • Self test (438)
60
563 case
executed 60 times by 1 test: case 5:
Executed by:
  • Self test (438)
5:
executed 60 times by 1 test: case 5:
Executed by:
  • Self test (438)
60
564 sqlite3_result_int(ctx, pCsr->nPayload);-
565 break;
executed 60 times by 1 test: break;
Executed by:
  • Self test (438)
60
566 case
executed 60 times by 1 test: case 6:
Executed by:
  • Self test (438)
6:
executed 60 times by 1 test: case 6:
Executed by:
  • Self test (438)
60
567 sqlite3_result_int(ctx, pCsr->nUnused);-
568 break;
executed 60 times by 1 test: break;
Executed by:
  • Self test (438)
60
569 case
executed 60 times by 1 test: case 7:
Executed by:
  • Self test (438)
7:
executed 60 times by 1 test: case 7:
Executed by:
  • Self test (438)
60
570 sqlite3_result_int(ctx, pCsr->nMxPayload);-
571 break;
executed 60 times by 1 test: break;
Executed by:
  • Self test (438)
60
572 case
executed 12 times by 1 test: case 8:
Executed by:
  • Self test (438)
8:
executed 12 times by 1 test: case 8:
Executed by:
  • Self test (438)
12
573 sqlite3_result_int64(ctx, pCsr->iOffset);-
574 break;
executed 12 times by 1 test: break;
Executed by:
  • Self test (438)
12
575 case
executed 12 times by 1 test: case 9:
Executed by:
  • Self test (438)
9:
executed 12 times by 1 test: case 9:
Executed by:
  • Self test (438)
12
576 sqlite3_result_int(ctx, pCsr->szPage);-
577 break;
executed 12 times by 1 test: break;
Executed by:
  • Self test (438)
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: return 0;
Executed by:
  • Self test (438)
0;
executed 5223 times by 1 test: return 0;
Executed by:
  • Self test (438)
5223
586}-
587-
588static int statRowid(sqlite3_vtab_cursor *pCursor, sqlite_int64 *pRowid){-
589 StatCursor *pCsr = (StatCursor *)pCursor;-
590 *pRowid = pCsr->iPageno;-
591 return
never executed: return 0;
0;
never executed: return 0;
0
592}-
593-
594-
595-
596-
597int 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: return sqlite3_create_module(db, "dbstat", &dbstat_module, 0);
Executed by:
  • Self test (438)
sqlite3_create_module(db, "dbstat", &dbstat_module, 0);
executed 4 times by 1 test: return sqlite3_create_module(db, "dbstat", &dbstat_module, 0);
Executed by:
  • Self test (438)
4
624}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.2