OLD | NEW |
1 /* | 1 /* |
2 ** A utility for printing all or part of an SQLite database file. | 2 ** A utility for printing all or part of an SQLite database file. |
3 */ | 3 */ |
4 #include <stdio.h> | 4 #include <stdio.h> |
5 #include <ctype.h> | 5 #include <ctype.h> |
6 #define ISDIGIT(X) isdigit((unsigned char)(X)) | 6 #define ISDIGIT(X) isdigit((unsigned char)(X)) |
7 #define ISPRINT(X) isprint((unsigned char)(X)) | 7 #define ISPRINT(X) isprint((unsigned char)(X)) |
8 #include <sys/types.h> | 8 #include <sys/types.h> |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 #include <fcntl.h> | 10 #include <fcntl.h> |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 aData = sqlite3_malloc(nByte+32); | 144 aData = sqlite3_malloc(nByte+32); |
145 if( aData==0 ) out_of_memory(); | 145 if( aData==0 ) out_of_memory(); |
146 memset(aData, 0, nByte+32); | 146 memset(aData, 0, nByte+32); |
147 if( g.bRaw==0 ){ | 147 if( g.bRaw==0 ){ |
148 int rc = g.pFd->pMethods->xRead(g.pFd, (void*)aData, nByte, ofst); | 148 int rc = g.pFd->pMethods->xRead(g.pFd, (void*)aData, nByte, ofst); |
149 if( rc!=SQLITE_OK && rc!=SQLITE_IOERR_SHORT_READ ){ | 149 if( rc!=SQLITE_OK && rc!=SQLITE_IOERR_SHORT_READ ){ |
150 fprintf(stderr, "error in xRead() - %d\n", rc); | 150 fprintf(stderr, "error in xRead() - %d\n", rc); |
151 exit(1); | 151 exit(1); |
152 } | 152 } |
153 }else{ | 153 }else{ |
154 lseek(g.dbfd, ofst, SEEK_SET); | 154 lseek(g.dbfd, (long)ofst, SEEK_SET); |
155 got = read(g.dbfd, aData, nByte); | 155 got = read(g.dbfd, aData, nByte); |
156 if( got>0 && got<nByte ) memset(aData+got, 0, nByte-got); | 156 if( got>0 && got<nByte ) memset(aData+got, 0, nByte-got); |
157 } | 157 } |
158 return aData; | 158 return aData; |
159 } | 159 } |
160 | 160 |
161 /* | 161 /* |
162 ** Return the size of the file in byte. | 162 ** Return the size of the file in byte. |
163 */ | 163 */ |
164 static sqlite3_int64 fileGetsize(void){ | 164 static sqlite3_int64 fileGetsize(void){ |
(...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1091 | 1091 |
1092 fileOpen(zPrg, azArg[1]); | 1092 fileOpen(zPrg, azArg[1]); |
1093 szFile = fileGetsize(); | 1093 szFile = fileGetsize(); |
1094 | 1094 |
1095 zPgSz = fileRead(16, 2); | 1095 zPgSz = fileRead(16, 2); |
1096 g.pagesize = zPgSz[0]*256 + zPgSz[1]*65536; | 1096 g.pagesize = zPgSz[0]*256 + zPgSz[1]*65536; |
1097 if( g.pagesize==0 ) g.pagesize = 1024; | 1097 if( g.pagesize==0 ) g.pagesize = 1024; |
1098 sqlite3_free(zPgSz); | 1098 sqlite3_free(zPgSz); |
1099 | 1099 |
1100 printf("Pagesize: %d\n", g.pagesize); | 1100 printf("Pagesize: %d\n", g.pagesize); |
1101 g.mxPage = (szFile+g.pagesize-1)/g.pagesize; | 1101 g.mxPage = (int)((szFile+g.pagesize-1)/g.pagesize); |
1102 | 1102 |
1103 printf("Available pages: 1..%d\n", g.mxPage); | 1103 printf("Available pages: 1..%d\n", g.mxPage); |
1104 if( nArg==2 ){ | 1104 if( nArg==2 ){ |
1105 int i; | 1105 int i; |
1106 for(i=1; i<=g.mxPage; i++) print_page(i); | 1106 for(i=1; i<=g.mxPage; i++) print_page(i); |
1107 }else{ | 1107 }else{ |
1108 int i; | 1108 int i; |
1109 for(i=2; i<nArg; i++){ | 1109 for(i=2; i<nArg; i++){ |
1110 int iStart, iEnd; | 1110 int iStart, iEnd; |
1111 char *zLeft; | 1111 char *zLeft; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1170 } | 1170 } |
1171 while( iStart<=iEnd ){ | 1171 while( iStart<=iEnd ){ |
1172 print_page(iStart); | 1172 print_page(iStart); |
1173 iStart++; | 1173 iStart++; |
1174 } | 1174 } |
1175 } | 1175 } |
1176 } | 1176 } |
1177 fileClose(); | 1177 fileClose(); |
1178 return 0; | 1178 return 0; |
1179 } | 1179 } |
OLD | NEW |