blob: 82b8c9f14f98353e6400490126f641c25d99fc77 [file] [log] [blame]
drh0de8c112002-07-06 16:32:14 +00001/*
2** A utility for printing all or part of an SQLite database file.
3*/
4#include <stdio.h>
5#include <ctype.h>
6#include <sys/types.h>
7#include <sys/stat.h>
8#include <fcntl.h>
mistachkin026262b2012-10-13 09:31:20 +00009
10#if !defined(_MSC_VER)
drh0de8c112002-07-06 16:32:14 +000011#include <unistd.h>
mistachkin0461cc42014-07-18 21:16:37 +000012#else
13#include <io.h>
mistachkin026262b2012-10-13 09:31:20 +000014#endif
15
drh0de8c112002-07-06 16:32:14 +000016#include <stdlib.h>
drh562cedb2010-04-26 15:44:07 +000017#include <string.h>
drh3aeea462012-04-03 14:59:50 +000018#include "sqlite3.h"
drh0de8c112002-07-06 16:32:14 +000019
20
drh562cedb2010-04-26 15:44:07 +000021static int pagesize = 1024; /* Size of a database page */
22static int db = -1; /* File descriptor for reading the DB */
23static int mxPage = 0; /* Last page number */
24static int perLine = 16; /* HEX elements to print per line */
drh0de8c112002-07-06 16:32:14 +000025
drh562cedb2010-04-26 15:44:07 +000026typedef long long int i64; /* Datatype for 64-bit integers */
27
28
29/*
30** Convert the var-int format into i64. Return the number of bytes
31** in the var-int. Write the var-int value into *pVal.
32*/
drh7ecc1472010-04-26 16:47:12 +000033static int decodeVarint(const unsigned char *z, i64 *pVal){
drh562cedb2010-04-26 15:44:07 +000034 i64 v = 0;
drh7ecc1472010-04-26 16:47:12 +000035 int i;
36 for(i=0; i<8; i++){
drh562cedb2010-04-26 15:44:07 +000037 v = (v<<7) + (z[i]&0x7f);
38 if( (z[i]&0x80)==0 ){ *pVal = v; return i+1; }
39 }
40 v = (v<<8) + (z[i]&0xff);
41 *pVal = v;
42 return 9;
43}
44
drh7d105f82010-08-23 15:26:49 +000045/*
46** Extract a big-endian 32-bit integer
47*/
48static unsigned int decodeInt32(const unsigned char *z){
49 return (z[0]<<24) + (z[1]<<16) + (z[2]<<8) + z[3];
50}
51
drh562cedb2010-04-26 15:44:07 +000052/* Report an out-of-memory error and die.
53*/
drh0de8c112002-07-06 16:32:14 +000054static void out_of_memory(void){
55 fprintf(stderr,"Out of memory...\n");
56 exit(1);
57}
58
drh562cedb2010-04-26 15:44:07 +000059/*
60** Read content from the file.
61**
62** Space to hold the content is obtained from malloc() and needs to be
63** freed by the caller.
64*/
65static unsigned char *getContent(int ofst, int nByte){
66 unsigned char *aData;
drh5240aeb2011-01-06 01:26:38 +000067 aData = malloc(nByte+32);
drh562cedb2010-04-26 15:44:07 +000068 if( aData==0 ) out_of_memory();
drhb7787ee2011-01-06 15:51:18 +000069 memset(aData, 0, nByte+32);
drh562cedb2010-04-26 15:44:07 +000070 lseek(db, ofst, SEEK_SET);
drh4bb77ec2014-06-30 11:14:26 +000071 if( read(db, aData, nByte)<nByte ) memset(aData, 0, nByte);
drh562cedb2010-04-26 15:44:07 +000072 return aData;
73}
74
75/*
76** Print a range of bytes as hex and as ascii.
77*/
78static unsigned char *print_byte_range(
79 int ofst, /* First byte in the range of bytes to print */
80 int nByte, /* Number of bytes to print */
81 int printOfst /* Add this amount to the index on the left column */
82){
drh0de8c112002-07-06 16:32:14 +000083 unsigned char *aData;
84 int i, j;
drh562cedb2010-04-26 15:44:07 +000085 const char *zOfstFmt;
86
87 if( ((printOfst+nByte)&~0xfff)==0 ){
88 zOfstFmt = " %03x: ";
89 }else if( ((printOfst+nByte)&~0xffff)==0 ){
90 zOfstFmt = " %04x: ";
91 }else if( ((printOfst+nByte)&~0xfffff)==0 ){
92 zOfstFmt = " %05x: ";
93 }else if( ((printOfst+nByte)&~0xffffff)==0 ){
94 zOfstFmt = " %06x: ";
95 }else{
96 zOfstFmt = " %08x: ";
97 }
98
99 aData = getContent(ofst, nByte);
100 for(i=0; i<nByte; i += perLine){
101 fprintf(stdout, zOfstFmt, i+printOfst);
drhc9ac5ca2005-11-04 22:03:30 +0000102 for(j=0; j<perLine; j++){
drh562cedb2010-04-26 15:44:07 +0000103 if( i+j>nByte ){
104 fprintf(stdout, " ");
105 }else{
106 fprintf(stdout,"%02x ", aData[i+j]);
107 }
drh0de8c112002-07-06 16:32:14 +0000108 }
drhc9ac5ca2005-11-04 22:03:30 +0000109 for(j=0; j<perLine; j++){
drh562cedb2010-04-26 15:44:07 +0000110 if( i+j>nByte ){
111 fprintf(stdout, " ");
112 }else{
113 fprintf(stdout,"%c", isprint(aData[i+j]) ? aData[i+j] : '.');
114 }
drh0de8c112002-07-06 16:32:14 +0000115 }
116 fprintf(stdout,"\n");
117 }
drh562cedb2010-04-26 15:44:07 +0000118 return aData;
119}
120
121/*
122** Print an entire page of content as hex
123*/
drhdb718d82014-01-28 20:36:22 +0000124static void print_page(int iPg){
drh562cedb2010-04-26 15:44:07 +0000125 int iStart;
126 unsigned char *aData;
127 iStart = (iPg-1)*pagesize;
128 fprintf(stdout, "Page %d: (offsets 0x%x..0x%x)\n",
129 iPg, iStart, iStart+pagesize-1);
130 aData = print_byte_range(iStart, pagesize, 0);
drh0de8c112002-07-06 16:32:14 +0000131 free(aData);
132}
133
drh6a30cd52014-06-19 23:38:53 +0000134
drh562cedb2010-04-26 15:44:07 +0000135/* Print a line of decode output showing a 4-byte integer.
136*/
drhdb718d82014-01-28 20:36:22 +0000137static void print_decode_line(
drh562cedb2010-04-26 15:44:07 +0000138 unsigned char *aData, /* Content being decoded */
139 int ofst, int nByte, /* Start and size of decode */
140 const char *zMsg /* Message to append */
141){
142 int i, j;
143 int val = aData[ofst];
144 char zBuf[100];
145 sprintf(zBuf, " %03x: %02x", ofst, aData[ofst]);
mistachkinef607032014-07-19 15:40:39 +0000146 i = (int)strlen(zBuf);
drh562cedb2010-04-26 15:44:07 +0000147 for(j=1; j<4; j++){
148 if( j>=nByte ){
149 sprintf(&zBuf[i], " ");
150 }else{
151 sprintf(&zBuf[i], " %02x", aData[ofst+j]);
152 val = val*256 + aData[ofst+j];
153 }
mistachkinef607032014-07-19 15:40:39 +0000154 i += (int)strlen(&zBuf[i]);
drh562cedb2010-04-26 15:44:07 +0000155 }
156 sprintf(&zBuf[i], " %9d", val);
drh7ecc1472010-04-26 16:47:12 +0000157 printf("%s %s\n", zBuf, zMsg);
drh562cedb2010-04-26 15:44:07 +0000158}
159
160/*
161** Decode the database header.
162*/
drh7ecc1472010-04-26 16:47:12 +0000163static void print_db_header(void){
drh562cedb2010-04-26 15:44:07 +0000164 unsigned char *aData;
165 aData = print_byte_range(0, 100, 0);
166 printf("Decoded:\n");
167 print_decode_line(aData, 16, 2, "Database page size");
168 print_decode_line(aData, 18, 1, "File format write version");
169 print_decode_line(aData, 19, 1, "File format read version");
170 print_decode_line(aData, 20, 1, "Reserved space at end of page");
171 print_decode_line(aData, 24, 4, "File change counter");
172 print_decode_line(aData, 28, 4, "Size of database in pages");
173 print_decode_line(aData, 32, 4, "Page number of first freelist page");
174 print_decode_line(aData, 36, 4, "Number of freelist pages");
175 print_decode_line(aData, 40, 4, "Schema cookie");
176 print_decode_line(aData, 44, 4, "Schema format version");
177 print_decode_line(aData, 48, 4, "Default page cache size");
178 print_decode_line(aData, 52, 4, "Largest auto-vac root page");
179 print_decode_line(aData, 56, 4, "Text encoding");
180 print_decode_line(aData, 60, 4, "User version");
181 print_decode_line(aData, 64, 4, "Incremental-vacuum mode");
drh4ee09b42013-05-01 19:49:27 +0000182 print_decode_line(aData, 68, 4, "Application ID");
drh562cedb2010-04-26 15:44:07 +0000183 print_decode_line(aData, 72, 4, "meta[8]");
184 print_decode_line(aData, 76, 4, "meta[9]");
185 print_decode_line(aData, 80, 4, "meta[10]");
186 print_decode_line(aData, 84, 4, "meta[11]");
187 print_decode_line(aData, 88, 4, "meta[12]");
drhb28e59b2010-06-17 02:13:39 +0000188 print_decode_line(aData, 92, 4, "Change counter for version number");
drhc6d2b4a2010-04-26 17:30:52 +0000189 print_decode_line(aData, 96, 4, "SQLite version number");
drh562cedb2010-04-26 15:44:07 +0000190}
191
drh7ecc1472010-04-26 16:47:12 +0000192/*
drh100335b2011-01-05 21:20:52 +0000193** Describe cell content.
194*/
mistachkin0461cc42014-07-18 21:16:37 +0000195static i64 describeContent(
drh5240aeb2011-01-06 01:26:38 +0000196 unsigned char *a, /* Cell content */
mistachkin0461cc42014-07-18 21:16:37 +0000197 i64 nLocal, /* Bytes in a[] */
drh5240aeb2011-01-06 01:26:38 +0000198 char *zDesc /* Write description here */
drh100335b2011-01-05 21:20:52 +0000199){
mistachkin0461cc42014-07-18 21:16:37 +0000200 i64 nDesc = 0;
201 int n, j;
202 i64 i, x, v;
drh100335b2011-01-05 21:20:52 +0000203 const unsigned char *pData;
drh5240aeb2011-01-06 01:26:38 +0000204 const unsigned char *pLimit;
drh100335b2011-01-05 21:20:52 +0000205 char sep = ' ';
206
drh5240aeb2011-01-06 01:26:38 +0000207 pLimit = &a[nLocal];
drh100335b2011-01-05 21:20:52 +0000208 n = decodeVarint(a, &x);
209 pData = &a[x];
210 a += n;
211 i = x - n;
drh5240aeb2011-01-06 01:26:38 +0000212 while( i>0 && pData<=pLimit ){
drh100335b2011-01-05 21:20:52 +0000213 n = decodeVarint(a, &x);
214 a += n;
215 i -= n;
drh5240aeb2011-01-06 01:26:38 +0000216 nLocal -= n;
drh100335b2011-01-05 21:20:52 +0000217 zDesc[0] = sep;
218 sep = ',';
219 nDesc++;
220 zDesc++;
221 if( x==0 ){
drh5240aeb2011-01-06 01:26:38 +0000222 sprintf(zDesc, "*"); /* NULL is a "*" */
drh100335b2011-01-05 21:20:52 +0000223 }else if( x>=1 && x<=6 ){
224 v = (signed char)pData[0];
225 pData++;
226 switch( x ){
227 case 6: v = (v<<16) + (pData[0]<<8) + pData[1]; pData += 2;
228 case 5: v = (v<<16) + (pData[0]<<8) + pData[1]; pData += 2;
229 case 4: v = (v<<8) + pData[0]; pData++;
230 case 3: v = (v<<8) + pData[0]; pData++;
231 case 2: v = (v<<8) + pData[0]; pData++;
232 }
233 sprintf(zDesc, "%lld", v);
234 }else if( x==7 ){
235 sprintf(zDesc, "real");
236 pData += 8;
237 }else if( x==8 ){
238 sprintf(zDesc, "0");
239 }else if( x==9 ){
240 sprintf(zDesc, "1");
241 }else if( x>=12 ){
mistachkin0461cc42014-07-18 21:16:37 +0000242 i64 size = (x-12)/2;
drhb2c062d2011-01-05 21:46:52 +0000243 if( (x&1)==0 ){
mistachkin35683972014-07-19 15:30:01 +0000244 sprintf(zDesc, "blob(%lld)", size);
drh100335b2011-01-05 21:20:52 +0000245 }else{
mistachkin35683972014-07-19 15:30:01 +0000246 sprintf(zDesc, "txt(%lld)", size);
drh100335b2011-01-05 21:20:52 +0000247 }
248 pData += size;
249 }
mistachkinef607032014-07-19 15:40:39 +0000250 j = (int)strlen(zDesc);
drh100335b2011-01-05 21:20:52 +0000251 zDesc += j;
252 nDesc += j;
253 }
254 return nDesc;
255}
drh5240aeb2011-01-06 01:26:38 +0000256
257/*
258** Compute the local payload size given the total payload size and
259** the page size.
260*/
mistachkin0461cc42014-07-18 21:16:37 +0000261static i64 localPayload(i64 nPayload, char cType){
262 i64 maxLocal;
263 i64 minLocal;
264 i64 surplus;
265 i64 nLocal;
drh5240aeb2011-01-06 01:26:38 +0000266 if( cType==13 ){
267 /* Table leaf */
268 maxLocal = pagesize-35;
269 minLocal = (pagesize-12)*32/255-23;
270 }else{
271 maxLocal = (pagesize-12)*64/255-23;
272 minLocal = (pagesize-12)*32/255-23;
273 }
274 if( nPayload>maxLocal ){
275 surplus = minLocal + (nPayload-minLocal)%(pagesize-4);
276 if( surplus<=maxLocal ){
277 nLocal = surplus;
278 }else{
279 nLocal = minLocal;
280 }
281 }else{
282 nLocal = nPayload;
283 }
284 return nLocal;
285}
drh100335b2011-01-05 21:20:52 +0000286
287
288/*
drh7ecc1472010-04-26 16:47:12 +0000289** Create a description for a single cell.
drh5240aeb2011-01-06 01:26:38 +0000290**
291** The return value is the local cell size.
drh7ecc1472010-04-26 16:47:12 +0000292*/
mistachkin0461cc42014-07-18 21:16:37 +0000293static i64 describeCell(
drh100335b2011-01-05 21:20:52 +0000294 unsigned char cType, /* Page type */
295 unsigned char *a, /* Cell content */
296 int showCellContent, /* Show cell content if true */
297 char **pzDesc /* Store description here */
298){
drh7ecc1472010-04-26 16:47:12 +0000299 int i;
mistachkin0461cc42014-07-18 21:16:37 +0000300 i64 nDesc = 0;
drh7ecc1472010-04-26 16:47:12 +0000301 int n = 0;
302 int leftChild;
303 i64 nPayload;
304 i64 rowid;
mistachkin0461cc42014-07-18 21:16:37 +0000305 i64 nLocal;
drh100335b2011-01-05 21:20:52 +0000306 static char zDesc[1000];
drh7ecc1472010-04-26 16:47:12 +0000307 i = 0;
308 if( cType<=5 ){
309 leftChild = ((a[0]*256 + a[1])*256 + a[2])*256 + a[3];
310 a += 4;
311 n += 4;
drh100335b2011-01-05 21:20:52 +0000312 sprintf(zDesc, "lx: %d ", leftChild);
drh7ecc1472010-04-26 16:47:12 +0000313 nDesc = strlen(zDesc);
314 }
315 if( cType!=5 ){
316 i = decodeVarint(a, &nPayload);
317 a += i;
318 n += i;
drh100335b2011-01-05 21:20:52 +0000319 sprintf(&zDesc[nDesc], "n: %lld ", nPayload);
drh7ecc1472010-04-26 16:47:12 +0000320 nDesc += strlen(&zDesc[nDesc]);
drh5240aeb2011-01-06 01:26:38 +0000321 nLocal = localPayload(nPayload, cType);
322 }else{
323 nPayload = nLocal = 0;
drh7ecc1472010-04-26 16:47:12 +0000324 }
325 if( cType==5 || cType==13 ){
326 i = decodeVarint(a, &rowid);
327 a += i;
328 n += i;
drh100335b2011-01-05 21:20:52 +0000329 sprintf(&zDesc[nDesc], "r: %lld ", rowid);
drh7ecc1472010-04-26 16:47:12 +0000330 nDesc += strlen(&zDesc[nDesc]);
331 }
drhb7787ee2011-01-06 15:51:18 +0000332 if( nLocal<nPayload ){
333 int ovfl;
334 unsigned char *b = &a[nLocal];
335 ovfl = ((b[0]*256 + b[1])*256 + b[2])*256 + b[3];
336 sprintf(&zDesc[nDesc], "ov: %d ", ovfl);
337 nDesc += strlen(&zDesc[nDesc]);
338 n += 4;
339 }
drh100335b2011-01-05 21:20:52 +0000340 if( showCellContent && cType!=5 ){
drh5240aeb2011-01-06 01:26:38 +0000341 nDesc += describeContent(a, nLocal, &zDesc[nDesc-1]);
drh100335b2011-01-05 21:20:52 +0000342 }
drh7ecc1472010-04-26 16:47:12 +0000343 *pzDesc = zDesc;
drh5240aeb2011-01-06 01:26:38 +0000344 return nLocal+n;
drh7ecc1472010-04-26 16:47:12 +0000345}
346
drh6a30cd52014-06-19 23:38:53 +0000347/* Print an offset followed by nByte bytes. Add extra white-space
348** at the end so that subsequent text is aligned.
349*/
350static void printBytes(
351 unsigned char *aData, /* Content being decoded */
352 unsigned char *aStart, /* Start of content to be printed */
353 int nByte /* Number of bytes to print */
354){
355 int j;
356 printf(" %03x: ", (int)(aStart-aData));
357 for(j=0; j<9; j++){
358 if( j>=nByte ){
359 printf(" ");
360 }else{
361 printf("%02x ", aStart[j]);
362 }
363 }
364}
365
366
367/*
368** Write a full decode on stdout for the cell at a[ofst].
369** Assume the page contains a header of size szPgHdr bytes.
370*/
371static void decodeCell(
372 unsigned char *a, /* Page content (without the page-1 header) */
373 unsigned pgno, /* Page number */
374 int iCell, /* Cell index */
375 int szPgHdr, /* Size of the page header. 0 or 100 */
376 int ofst /* Cell begins at a[ofst] */
377){
mistachkin0461cc42014-07-18 21:16:37 +0000378 int i, j;
drh6a30cd52014-06-19 23:38:53 +0000379 int leftChild;
mistachkin0461cc42014-07-18 21:16:37 +0000380 i64 k;
drh6a30cd52014-06-19 23:38:53 +0000381 i64 nPayload;
382 i64 rowid;
383 i64 nHdr;
384 i64 iType;
mistachkin0461cc42014-07-18 21:16:37 +0000385 i64 nLocal;
drh6a30cd52014-06-19 23:38:53 +0000386 unsigned char *x = a + ofst;
387 unsigned char *end;
388 unsigned char cType = a[0];
drh419e0402014-06-20 01:32:42 +0000389 int nCol = 0;
390 int szCol[2000];
391 int ofstCol[2000];
392 int typeCol[2000];
drh6a30cd52014-06-19 23:38:53 +0000393
drh419e0402014-06-20 01:32:42 +0000394 printf("Cell[%d]:\n", iCell);
drh6a30cd52014-06-19 23:38:53 +0000395 if( cType<=5 ){
396 leftChild = ((x[0]*256 + x[1])*256 + x[2])*256 + x[3];
397 printBytes(a, x, 4);
398 printf("left child page:: %d\n", leftChild);
399 x += 4;
400 }
401 if( cType!=5 ){
402 i = decodeVarint(x, &nPayload);
403 printBytes(a, x, i);
404 nLocal = localPayload(nPayload, cType);
drh419e0402014-06-20 01:32:42 +0000405 if( nLocal==nPayload ){
mistachkin35683972014-07-19 15:30:01 +0000406 printf("payload-size: %lld\n", nPayload);
drh419e0402014-06-20 01:32:42 +0000407 }else{
mistachkin35683972014-07-19 15:30:01 +0000408 printf("payload-size: %lld (%lld local, %lld overflow)\n",
409 nPayload, nLocal, nPayload-nLocal);
drh419e0402014-06-20 01:32:42 +0000410 }
drh6a30cd52014-06-19 23:38:53 +0000411 x += i;
412 }else{
413 nPayload = nLocal = 0;
414 }
415 end = x + nLocal;
416 if( cType==5 || cType==13 ){
417 i = decodeVarint(x, &rowid);
418 printBytes(a, x, i);
419 printf("rowid: %lld\n", rowid);
420 x += i;
421 }
422 if( nLocal>0 ){
423 i = decodeVarint(x, &nHdr);
424 printBytes(a, x, i);
drh419e0402014-06-20 01:32:42 +0000425 printf("record-header-size: %d\n", (int)nHdr);
drh6a30cd52014-06-19 23:38:53 +0000426 j = i;
drh419e0402014-06-20 01:32:42 +0000427 nCol = 0;
428 k = nHdr;
drh6a30cd52014-06-19 23:38:53 +0000429 while( x+j<end && j<nHdr ){
430 const char *zTypeName;
431 int sz = 0;
432 char zNm[30];
433 i = decodeVarint(x+j, &iType);
434 printBytes(a, x+j, i);
drh419e0402014-06-20 01:32:42 +0000435 printf("typecode[%d]: %d - ", nCol, (int)iType);
drh6a30cd52014-06-19 23:38:53 +0000436 switch( iType ){
437 case 0: zTypeName = "NULL"; sz = 0; break;
438 case 1: zTypeName = "int8"; sz = 1; break;
439 case 2: zTypeName = "int16"; sz = 2; break;
440 case 3: zTypeName = "int24"; sz = 3; break;
441 case 4: zTypeName = "int32"; sz = 4; break;
442 case 5: zTypeName = "int48"; sz = 6; break;
443 case 6: zTypeName = "int64"; sz = 8; break;
444 case 7: zTypeName = "double"; sz = 8; break;
445 case 8: zTypeName = "zero"; sz = 0; break;
446 case 9: zTypeName = "one"; sz = 0; break;
447 case 10:
448 case 11: zTypeName = "error"; sz = 0; break;
449 default: {
450 sz = (int)(iType-12)/2;
451 sprintf(zNm, (iType&1)==0 ? "blob(%d)" : "text(%d)", sz);
452 zTypeName = zNm;
453 break;
454 }
455 }
456 printf("%s\n", zTypeName);
drh419e0402014-06-20 01:32:42 +0000457 szCol[nCol] = sz;
mistachkin0461cc42014-07-18 21:16:37 +0000458 ofstCol[nCol] = (int)k;
drh419e0402014-06-20 01:32:42 +0000459 typeCol[nCol] = (int)iType;
460 k += sz;
461 nCol++;
drh6a30cd52014-06-19 23:38:53 +0000462 j += i;
463 }
drh419e0402014-06-20 01:32:42 +0000464 for(i=0; i<nCol && ofstCol[i]+szCol[i]<=nLocal; i++){
465 int s = ofstCol[i];
466 i64 v;
467 const unsigned char *pData;
468 if( szCol[i]==0 ) continue;
469 printBytes(a, x+s, szCol[i]);
470 printf("data[%d]: ", i);
471 pData = x+s;
472 if( typeCol[i]<=7 ){
473 v = (signed char)pData[0];
474 for(k=1; k<szCol[i]; k++){
475 v = (v<<8) + pData[k];
476 }
477 if( typeCol[i]==7 ){
478 double r;
479 memcpy(&r, &v, sizeof(r));
480 printf("%#g\n", r);
481 }else{
482 printf("%lld\n", v);
483 }
484 }else{
drh56e67dd2014-06-20 13:55:06 +0000485 int ii, jj;
486 char zConst[32];
487 if( (typeCol[i]&1)==0 ){
488 zConst[0] = 'x';
489 zConst[1] = '\'';
490 for(ii=2, jj=0; jj<szCol[i] && ii<24; jj++, ii+=2){
491 sprintf(zConst+ii, "%02x", pData[jj]);
492 }
493 }else{
494 zConst[0] = '\'';
495 for(ii=1, jj=0; jj<szCol[i] && ii<24; jj++, ii++){
496 zConst[ii] = isprint(pData[jj]) ? pData[jj] : '.';
497 }
498 zConst[ii] = 0;
499 }
500 if( jj<szCol[i] ){
501 memcpy(zConst+ii, "...'", 5);
502 }else{
503 memcpy(zConst+ii, "'", 2);
504 }
505 printf("%s\n", zConst);
drh419e0402014-06-20 01:32:42 +0000506 }
507 j = ofstCol[i] + szCol[i];
508 }
drh6a30cd52014-06-19 23:38:53 +0000509 }
510 if( j<nLocal ){
511 printBytes(a, x+j, 0);
mistachkin35683972014-07-19 15:30:01 +0000512 printf("... %lld bytes of content ...\n", nLocal-j);
drh6a30cd52014-06-19 23:38:53 +0000513 }
514 if( nLocal<nPayload ){
515 printBytes(a, x+nLocal, 4);
drh419e0402014-06-20 01:32:42 +0000516 printf("overflow-page: %d\n", decodeInt32(x+nLocal));
drh6a30cd52014-06-19 23:38:53 +0000517 }
518}
519
520
drh7ecc1472010-04-26 16:47:12 +0000521/*
522** Decode a btree page
523*/
drh100335b2011-01-05 21:20:52 +0000524static void decode_btree_page(
525 unsigned char *a, /* Page content */
526 int pgno, /* Page number */
527 int hdrSize, /* Size of the page header. 0 or 100 */
528 char *zArgs /* Flags to control formatting */
529){
drh7ecc1472010-04-26 16:47:12 +0000530 const char *zType = "unknown";
531 int nCell;
drh5240aeb2011-01-06 01:26:38 +0000532 int i, j;
drh7ecc1472010-04-26 16:47:12 +0000533 int iCellPtr;
drh100335b2011-01-05 21:20:52 +0000534 int showCellContent = 0;
drh5240aeb2011-01-06 01:26:38 +0000535 int showMap = 0;
drh6a30cd52014-06-19 23:38:53 +0000536 int cellToDecode = -2;
drh5240aeb2011-01-06 01:26:38 +0000537 char *zMap = 0;
drh7ecc1472010-04-26 16:47:12 +0000538 switch( a[0] ){
539 case 2: zType = "index interior node"; break;
540 case 5: zType = "table interior node"; break;
541 case 10: zType = "index leaf"; break;
542 case 13: zType = "table leaf"; break;
543 }
drh100335b2011-01-05 21:20:52 +0000544 while( zArgs[0] ){
545 switch( zArgs[0] ){
546 case 'c': showCellContent = 1; break;
drh5240aeb2011-01-06 01:26:38 +0000547 case 'm': showMap = 1; break;
drh6a30cd52014-06-19 23:38:53 +0000548 case 'd': {
549 if( !isdigit(zArgs[1]) ){
550 cellToDecode = -1;
551 }else{
552 cellToDecode = 0;
553 while( isdigit(zArgs[1]) ){
554 zArgs++;
555 cellToDecode = cellToDecode*10 + zArgs[0] - '0';
556 }
557 }
558 break;
559 }
drh100335b2011-01-05 21:20:52 +0000560 }
561 zArgs++;
562 }
drh7ecc1472010-04-26 16:47:12 +0000563 nCell = a[3]*256 + a[4];
drh6a30cd52014-06-19 23:38:53 +0000564 iCellPtr = (a[0]==2 || a[0]==5) ? 12 : 8;
drh419e0402014-06-20 01:32:42 +0000565 if( cellToDecode>=nCell ){
drh6a30cd52014-06-19 23:38:53 +0000566 printf("Page %d has only %d cells\n", pgno, nCell);
567 return;
drh5240aeb2011-01-06 01:26:38 +0000568 }
drh419e0402014-06-20 01:32:42 +0000569 printf("Header on btree page %d:\n", pgno);
570 print_decode_line(a, 0, 1, zType);
571 print_decode_line(a, 1, 2, "Offset to first freeblock");
572 print_decode_line(a, 3, 2, "Number of cells on this page");
573 print_decode_line(a, 5, 2, "Offset to cell content area");
574 print_decode_line(a, 7, 1, "Fragmented byte count");
575 if( a[0]==2 || a[0]==5 ){
576 print_decode_line(a, 8, 4, "Right child");
577 }
578 if( cellToDecode==(-2) && nCell>0 ){
579 printf(" key: lx=left-child n=payload-size r=rowid\n");
580 }
drh5240aeb2011-01-06 01:26:38 +0000581 if( showMap ){
582 zMap = malloc(pagesize);
583 memset(zMap, '.', pagesize);
584 memset(zMap, '1', hdrSize);
585 memset(&zMap[hdrSize], 'H', iCellPtr);
586 memset(&zMap[hdrSize+iCellPtr], 'P', 2*nCell);
587 }
drh7ecc1472010-04-26 16:47:12 +0000588 for(i=0; i<nCell; i++){
589 int cofst = iCellPtr + i*2;
590 char *zDesc;
mistachkin0461cc42014-07-18 21:16:37 +0000591 i64 n;
drh5240aeb2011-01-06 01:26:38 +0000592
drh7ecc1472010-04-26 16:47:12 +0000593 cofst = a[cofst]*256 + a[cofst+1];
drh5240aeb2011-01-06 01:26:38 +0000594 n = describeCell(a[0], &a[cofst-hdrSize], showCellContent, &zDesc);
595 if( showMap ){
596 char zBuf[30];
mistachkin0461cc42014-07-18 21:16:37 +0000597 memset(&zMap[cofst], '*', (size_t)n);
drh5240aeb2011-01-06 01:26:38 +0000598 zMap[cofst] = '[';
599 zMap[cofst+n-1] = ']';
600 sprintf(zBuf, "%d", i);
mistachkinef607032014-07-19 15:40:39 +0000601 j = (int)strlen(zBuf);
drh5240aeb2011-01-06 01:26:38 +0000602 if( j<=n-2 ) memcpy(&zMap[cofst+1], zBuf, j);
603 }
drh6a30cd52014-06-19 23:38:53 +0000604 if( cellToDecode==(-2) ){
605 printf(" %03x: cell[%d] %s\n", cofst, i, zDesc);
606 }else if( cellToDecode==(-1) || cellToDecode==i ){
607 decodeCell(a, pgno, i, hdrSize, cofst-hdrSize);
608 }
drh7ecc1472010-04-26 16:47:12 +0000609 }
drh5240aeb2011-01-06 01:26:38 +0000610 if( showMap ){
drh419e0402014-06-20 01:32:42 +0000611 printf("Page map: (H=header P=cell-index 1=page-1-header .=free-space)\n");
drh5240aeb2011-01-06 01:26:38 +0000612 for(i=0; i<pagesize; i+=64){
613 printf(" %03x: %.64s\n", i, &zMap[i]);
614 }
615 free(zMap);
drh6a30cd52014-06-19 23:38:53 +0000616 }
drh7ecc1472010-04-26 16:47:12 +0000617}
618
drh7d105f82010-08-23 15:26:49 +0000619/*
620** Decode a freelist trunk page.
621*/
622static void decode_trunk_page(
623 int pgno, /* The page number */
624 int pagesize, /* Size of each page */
625 int detail, /* Show leaf pages if true */
626 int recursive /* Follow the trunk change if true */
627){
drhdb718d82014-01-28 20:36:22 +0000628 int n, i;
drh7d105f82010-08-23 15:26:49 +0000629 unsigned char *a;
630 while( pgno>0 ){
631 a = getContent((pgno-1)*pagesize, pagesize);
632 printf("Decode of freelist trunk page %d:\n", pgno);
633 print_decode_line(a, 0, 4, "Next freelist trunk page");
634 print_decode_line(a, 4, 4, "Number of entries on this page");
635 if( detail ){
636 n = (int)decodeInt32(&a[4]);
637 for(i=0; i<n; i++){
638 unsigned int x = decodeInt32(&a[8+4*i]);
639 char zIdx[10];
640 sprintf(zIdx, "[%d]", i);
641 printf(" %5s %7u", zIdx, x);
642 if( i%5==4 ) printf("\n");
643 }
644 if( i%5!=0 ) printf("\n");
645 }
646 if( !recursive ){
647 pgno = 0;
648 }else{
649 pgno = (int)decodeInt32(&a[0]);
650 }
651 free(a);
652 }
653}
654
655/*
drh3aeea462012-04-03 14:59:50 +0000656** A short text comment on the use of each page.
657*/
658static char **zPageUse;
659
660/*
661** Add a comment on the use of a page.
662*/
663static void page_usage_msg(int pgno, const char *zFormat, ...){
664 va_list ap;
665 char *zMsg;
666
667 va_start(ap, zFormat);
668 zMsg = sqlite3_vmprintf(zFormat, ap);
669 va_end(ap);
670 if( pgno<=0 || pgno>mxPage ){
drhedf9a172013-03-05 01:46:26 +0000671 printf("ERROR: page %d out of range 1..%d: %s\n",
drh3aeea462012-04-03 14:59:50 +0000672 pgno, mxPage, zMsg);
673 sqlite3_free(zMsg);
674 return;
675 }
676 if( zPageUse[pgno]!=0 ){
677 printf("ERROR: page %d used multiple times:\n", pgno);
678 printf("ERROR: previous: %s\n", zPageUse[pgno]);
drh103a70f2013-02-19 20:25:16 +0000679 printf("ERROR: current: %s\n", zMsg);
drh3aeea462012-04-03 14:59:50 +0000680 sqlite3_free(zPageUse[pgno]);
681 }
682 zPageUse[pgno] = zMsg;
683}
684
685/*
686** Find overflow pages of a cell and describe their usage.
687*/
688static void page_usage_cell(
689 unsigned char cType, /* Page type */
690 unsigned char *a, /* Cell content */
691 int pgno, /* page containing the cell */
692 int cellno /* Index of the cell on the page */
693){
694 int i;
drh3aeea462012-04-03 14:59:50 +0000695 int n = 0;
696 i64 nPayload;
697 i64 rowid;
mistachkin0461cc42014-07-18 21:16:37 +0000698 i64 nLocal;
drh3aeea462012-04-03 14:59:50 +0000699 i = 0;
700 if( cType<=5 ){
701 a += 4;
702 n += 4;
703 }
704 if( cType!=5 ){
705 i = decodeVarint(a, &nPayload);
706 a += i;
707 n += i;
708 nLocal = localPayload(nPayload, cType);
709 }else{
710 nPayload = nLocal = 0;
711 }
712 if( cType==5 || cType==13 ){
713 i = decodeVarint(a, &rowid);
714 a += i;
715 n += i;
716 }
717 if( nLocal<nPayload ){
718 int ovfl = decodeInt32(a+nLocal);
719 int cnt = 0;
720 while( ovfl && (cnt++)<mxPage ){
721 page_usage_msg(ovfl, "overflow %d from cell %d of page %d",
722 cnt, cellno, pgno);
723 a = getContent((ovfl-1)*pagesize, 4);
724 ovfl = decodeInt32(a);
725 free(a);
726 }
727 }
728}
729
730
731/*
732** Describe the usages of a b-tree page
733*/
734static void page_usage_btree(
735 int pgno, /* Page to describe */
736 int parent, /* Parent of this page. 0 for root pages */
737 int idx, /* Which child of the parent */
738 const char *zName /* Name of the table */
739){
740 unsigned char *a;
741 const char *zType = "corrupt node";
742 int nCell;
743 int i;
744 int hdr = pgno==1 ? 100 : 0;
745
746 if( pgno<=0 || pgno>mxPage ) return;
747 a = getContent((pgno-1)*pagesize, pagesize);
748 switch( a[hdr] ){
749 case 2: zType = "interior node of index"; break;
750 case 5: zType = "interior node of table"; break;
751 case 10: zType = "leaf of index"; break;
752 case 13: zType = "leaf of table"; break;
753 }
754 if( parent ){
755 page_usage_msg(pgno, "%s [%s], child %d of page %d",
756 zType, zName, idx, parent);
757 }else{
758 page_usage_msg(pgno, "root %s [%s]", zType, zName);
759 }
760 nCell = a[hdr+3]*256 + a[hdr+4];
761 if( a[hdr]==2 || a[hdr]==5 ){
762 int cellstart = hdr+12;
763 unsigned int child;
764 for(i=0; i<nCell; i++){
765 int ofst;
766
767 ofst = cellstart + i*2;
768 ofst = a[ofst]*256 + a[ofst+1];
769 child = decodeInt32(a+ofst);
770 page_usage_btree(child, pgno, i, zName);
771 }
772 child = decodeInt32(a+cellstart-4);
773 page_usage_btree(child, pgno, i, zName);
774 }
775 if( a[hdr]==2 || a[hdr]==10 || a[hdr]==13 ){
776 int cellstart = hdr + 8 + 4*(a[hdr]<=5);
777 for(i=0; i<nCell; i++){
778 int ofst;
779 ofst = cellstart + i*2;
780 ofst = a[ofst]*256 + a[ofst+1];
781 page_usage_cell(a[hdr], a+ofst, pgno, i);
782 }
783 }
784 free(a);
785}
786
787/*
788** Determine page usage by the freelist
789*/
790static void page_usage_freelist(int pgno){
791 unsigned char *a;
792 int cnt = 0;
793 int i;
794 int n;
795 int iNext;
796 int parent = 1;
797
798 while( pgno>0 && pgno<=mxPage && (cnt++)<mxPage ){
799 page_usage_msg(pgno, "freelist trunk #%d child of %d", cnt, parent);
800 a = getContent((pgno-1)*pagesize, pagesize);
801 iNext = decodeInt32(a);
802 n = decodeInt32(a+4);
803 for(i=0; i<n; i++){
804 int child = decodeInt32(a + (i*4+8));
805 page_usage_msg(child, "freelist leaf, child %d of trunk page %d",
806 i, pgno);
807 }
808 free(a);
809 parent = pgno;
810 pgno = iNext;
811 }
812}
813
814/*
drh344a97b2013-02-19 22:26:51 +0000815** Determine pages used as PTRMAP pages
816*/
817static void page_usage_ptrmap(unsigned char *a){
818 if( a[55] ){
819 int usable = pagesize - a[20];
820 int pgno = 2;
821 int perPage = usable/5;
822 while( pgno<=mxPage ){
823 page_usage_msg(pgno, "PTRMAP page covering %d..%d",
824 pgno+1, pgno+perPage);
825 pgno += perPage + 1;
826 }
827 }
828}
829
830/*
drh3aeea462012-04-03 14:59:50 +0000831** Try to figure out how every page in the database file is being used.
832*/
833static void page_usage_report(const char *zDbName){
drh00e637f2013-02-19 18:45:11 +0000834 int i, j;
drh3aeea462012-04-03 14:59:50 +0000835 int rc;
836 sqlite3 *db;
837 sqlite3_stmt *pStmt;
838 unsigned char *a;
drh00e637f2013-02-19 18:45:11 +0000839 char zQuery[200];
drh3aeea462012-04-03 14:59:50 +0000840
841 /* Avoid the pathological case */
842 if( mxPage<1 ){
843 printf("empty database\n");
844 return;
845 }
846
847 /* Open the database file */
848 rc = sqlite3_open(zDbName, &db);
849 if( rc ){
850 printf("cannot open database: %s\n", sqlite3_errmsg(db));
851 sqlite3_close(db);
852 return;
853 }
854
855 /* Set up global variables zPageUse[] and mxPage to record page
856 ** usages */
857 zPageUse = sqlite3_malloc( sizeof(zPageUse[0])*(mxPage+1) );
858 if( zPageUse==0 ) out_of_memory();
859 memset(zPageUse, 0, sizeof(zPageUse[0])*(mxPage+1));
860
861 /* Discover the usage of each page */
862 a = getContent(0, 100);
863 page_usage_freelist(decodeInt32(a+32));
drh344a97b2013-02-19 22:26:51 +0000864 page_usage_ptrmap(a);
drh3aeea462012-04-03 14:59:50 +0000865 free(a);
866 page_usage_btree(1, 0, 0, "sqlite_master");
drh00e637f2013-02-19 18:45:11 +0000867 sqlite3_exec(db, "PRAGMA writable_schema=ON", 0, 0, 0);
868 for(j=0; j<2; j++){
869 sqlite3_snprintf(sizeof(zQuery), zQuery,
870 "SELECT type, name, rootpage FROM SQLITE_MASTER WHERE rootpage"
871 " ORDER BY rowid %s", j?"DESC":"");
872 rc = sqlite3_prepare_v2(db, zQuery, -1, &pStmt, 0);
873 if( rc==SQLITE_OK ){
874 while( sqlite3_step(pStmt)==SQLITE_ROW ){
875 int pgno = sqlite3_column_int(pStmt, 2);
drhdb718d82014-01-28 20:36:22 +0000876 page_usage_btree(pgno, 0, 0, (const char*)sqlite3_column_text(pStmt,1));
drh00e637f2013-02-19 18:45:11 +0000877 }
878 }else{
879 printf("ERROR: cannot query database: %s\n", sqlite3_errmsg(db));
drh3aeea462012-04-03 14:59:50 +0000880 }
drh00e637f2013-02-19 18:45:11 +0000881 rc = sqlite3_finalize(pStmt);
882 if( rc==SQLITE_OK ) break;
drh3aeea462012-04-03 14:59:50 +0000883 }
drh3aeea462012-04-03 14:59:50 +0000884 sqlite3_close(db);
885
886 /* Print the report and free memory used */
887 for(i=1; i<=mxPage; i++){
888 printf("%5d: %s\n", i, zPageUse[i] ? zPageUse[i] : "???");
889 sqlite3_free(zPageUse[i]);
890 }
891 sqlite3_free(zPageUse);
892 zPageUse = 0;
893}
894
895/*
drh344a97b2013-02-19 22:26:51 +0000896** Try to figure out how every page in the database file is being used.
897*/
898static void ptrmap_coverage_report(const char *zDbName){
mistachkin0461cc42014-07-18 21:16:37 +0000899 int pgno;
drh344a97b2013-02-19 22:26:51 +0000900 unsigned char *aHdr;
901 unsigned char *a;
902 int usable;
903 int perPage;
mistachkin0461cc42014-07-18 21:16:37 +0000904 int i;
drh344a97b2013-02-19 22:26:51 +0000905
906 /* Avoid the pathological case */
907 if( mxPage<1 ){
908 printf("empty database\n");
909 return;
910 }
911
912 /* Make sure PTRMAPs are used in this database */
913 aHdr = getContent(0, 100);
914 if( aHdr[55]==0 ){
915 printf("database does not use PTRMAP pages\n");
916 return;
917 }
918 usable = pagesize - aHdr[20];
919 perPage = usable/5;
920 free(aHdr);
921 printf("%5d: root of sqlite_master\n", 1);
922 for(pgno=2; pgno<=mxPage; pgno += perPage+1){
923 printf("%5d: PTRMAP page covering %d..%d\n", pgno,
924 pgno+1, pgno+perPage);
925 a = getContent((pgno-1)*pagesize, usable);
926 for(i=0; i+5<=usable && pgno+1+i/5<=mxPage; i+=5){
927 const char *zType = "???";
928 unsigned int iFrom = decodeInt32(&a[i+1]);
929 switch( a[i] ){
930 case 1: zType = "b-tree root page"; break;
931 case 2: zType = "freelist page"; break;
932 case 3: zType = "first page of overflow"; break;
933 case 4: zType = "later page of overflow"; break;
934 case 5: zType = "b-tree non-root page"; break;
935 }
936 printf("%5d: %s, parent=%u\n", pgno+1+i/5, zType, iFrom);
937 }
938 free(a);
939 }
940}
941
942/*
drh7d105f82010-08-23 15:26:49 +0000943** Print a usage comment
944*/
945static void usage(const char *argv0){
946 fprintf(stderr, "Usage %s FILENAME ?args...?\n\n", argv0);
947 fprintf(stderr,
948 "args:\n"
949 " dbheader Show database header\n"
drh3aeea462012-04-03 14:59:50 +0000950 " pgidx Index of how each page is used\n"
drh344a97b2013-02-19 22:26:51 +0000951 " ptrmap Show all PTRMAP page content\n"
drh7d105f82010-08-23 15:26:49 +0000952 " NNN..MMM Show hex of pages NNN through MMM\n"
953 " NNN..end Show hex of pages NNN through end of file\n"
954 " NNNb Decode btree page NNN\n"
drh5240aeb2011-01-06 01:26:38 +0000955 " NNNbc Decode btree page NNN and show content\n"
956 " NNNbm Decode btree page NNN and show a layout map\n"
drh6a30cd52014-06-19 23:38:53 +0000957 " NNNbdCCC Decode cell CCC on btree page NNN\n"
drh7d105f82010-08-23 15:26:49 +0000958 " NNNt Decode freelist trunk page NNN\n"
drh47fb0002011-04-13 16:52:41 +0000959 " NNNtd Show leaf freelist pages on the decode\n"
dan53d89cd2014-08-20 10:42:16 +0000960 " NNNtr Recursively decode freelist starting at NNN\n"
drh7d105f82010-08-23 15:26:49 +0000961 );
962}
963
drh0de8c112002-07-06 16:32:14 +0000964int main(int argc, char **argv){
965 struct stat sbuf;
drh562cedb2010-04-26 15:44:07 +0000966 unsigned char zPgSz[2];
drh0de8c112002-07-06 16:32:14 +0000967 if( argc<2 ){
drh7d105f82010-08-23 15:26:49 +0000968 usage(argv[0]);
drh0de8c112002-07-06 16:32:14 +0000969 exit(1);
970 }
971 db = open(argv[1], O_RDONLY);
972 if( db<0 ){
973 fprintf(stderr,"%s: can't open %s\n", argv[0], argv[1]);
974 exit(1);
975 }
drh562cedb2010-04-26 15:44:07 +0000976 zPgSz[0] = 0;
977 zPgSz[1] = 0;
978 lseek(db, 16, SEEK_SET);
drh4bb77ec2014-06-30 11:14:26 +0000979 if( read(db, zPgSz, 2)<2 ) memset(zPgSz, 0, 2);
drh7d105f82010-08-23 15:26:49 +0000980 pagesize = zPgSz[0]*256 + zPgSz[1]*65536;
drh562cedb2010-04-26 15:44:07 +0000981 if( pagesize==0 ) pagesize = 1024;
982 printf("Pagesize: %d\n", pagesize);
drh0de8c112002-07-06 16:32:14 +0000983 fstat(db, &sbuf);
drh562cedb2010-04-26 15:44:07 +0000984 mxPage = sbuf.st_size/pagesize;
985 printf("Available pages: 1..%d\n", mxPage);
drh0de8c112002-07-06 16:32:14 +0000986 if( argc==2 ){
987 int i;
988 for(i=1; i<=mxPage; i++) print_page(i);
989 }else{
990 int i;
991 for(i=2; i<argc; i++){
992 int iStart, iEnd;
993 char *zLeft;
drh562cedb2010-04-26 15:44:07 +0000994 if( strcmp(argv[i], "dbheader")==0 ){
995 print_db_header();
996 continue;
997 }
drh3aeea462012-04-03 14:59:50 +0000998 if( strcmp(argv[i], "pgidx")==0 ){
999 page_usage_report(argv[1]);
1000 continue;
1001 }
drh344a97b2013-02-19 22:26:51 +00001002 if( strcmp(argv[i], "ptrmap")==0 ){
1003 ptrmap_coverage_report(argv[1]);
1004 continue;
1005 }
1006 if( strcmp(argv[i], "help")==0 ){
1007 usage(argv[0]);
1008 continue;
1009 }
drh562cedb2010-04-26 15:44:07 +00001010 if( !isdigit(argv[i][0]) ){
1011 fprintf(stderr, "%s: unknown option: [%s]\n", argv[0], argv[i]);
1012 continue;
1013 }
drh0de8c112002-07-06 16:32:14 +00001014 iStart = strtol(argv[i], &zLeft, 0);
1015 if( zLeft && strcmp(zLeft,"..end")==0 ){
1016 iEnd = mxPage;
1017 }else if( zLeft && zLeft[0]=='.' && zLeft[1]=='.' ){
1018 iEnd = strtol(&zLeft[2], 0, 0);
drh7ecc1472010-04-26 16:47:12 +00001019 }else if( zLeft && zLeft[0]=='b' ){
1020 int ofst, nByte, hdrSize;
1021 unsigned char *a;
1022 if( iStart==1 ){
1023 ofst = hdrSize = 100;
1024 nByte = pagesize-100;
1025 }else{
1026 hdrSize = 0;
1027 ofst = (iStart-1)*pagesize;
1028 nByte = pagesize;
1029 }
1030 a = getContent(ofst, nByte);
drh100335b2011-01-05 21:20:52 +00001031 decode_btree_page(a, iStart, hdrSize, &zLeft[1]);
drh7ecc1472010-04-26 16:47:12 +00001032 free(a);
1033 continue;
drh7d105f82010-08-23 15:26:49 +00001034 }else if( zLeft && zLeft[0]=='t' ){
drh7d105f82010-08-23 15:26:49 +00001035 int detail = 0;
1036 int recursive = 0;
1037 int i;
1038 for(i=1; zLeft[i]; i++){
1039 if( zLeft[i]=='r' ) recursive = 1;
1040 if( zLeft[i]=='d' ) detail = 1;
1041 }
1042 decode_trunk_page(iStart, pagesize, detail, recursive);
1043 continue;
drh0de8c112002-07-06 16:32:14 +00001044 }else{
1045 iEnd = iStart;
1046 }
1047 if( iStart<1 || iEnd<iStart || iEnd>mxPage ){
1048 fprintf(stderr,
1049 "Page argument should be LOWER?..UPPER?. Range 1 to %d\n",
1050 mxPage);
1051 exit(1);
1052 }
1053 while( iStart<=iEnd ){
1054 print_page(iStart);
1055 iStart++;
1056 }
1057 }
1058 }
1059 close(db);
drhdb718d82014-01-28 20:36:22 +00001060 return 0;
drh0de8c112002-07-06 16:32:14 +00001061}