/ Check-in [6dc7b2f1]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix harmless compiler warnings for MSVC in the showdb/showwal command line tools.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | toolWarnings
Files: files | file ages | folders
SHA1:6dc7b2f119eb92da17c9e914bdad30a9ceaebdb5
User & Date: mistachkin 2014-07-18 21:16:37
Context
2014-07-19
15:30
Fix warnings caused by the previous commit. check-in: 89634a41 user: mistachkin tags: toolWarnings
2014-07-18
21:16
Fix harmless compiler warnings for MSVC in the showdb/showwal command line tools. check-in: 6dc7b2f1 user: mistachkin tags: toolWarnings
21:02
Update clean targets with the recently added command-line tools. check-in: 2beefa68 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to tool/showdb.c.

     5      5   #include <ctype.h>
     6      6   #include <sys/types.h>
     7      7   #include <sys/stat.h>
     8      8   #include <fcntl.h>
     9      9   
    10     10   #if !defined(_MSC_VER)
    11     11   #include <unistd.h>
           12  +#else
           13  +#include <io.h>
    12     14   #endif
    13     15   
    14     16   #include <stdlib.h>
    15     17   #include <string.h>
    16     18   #include "sqlite3.h"
    17     19   
    18     20   
................................................................................
   186    188     print_decode_line(aData, 92, 4, "Change counter for version number");
   187    189     print_decode_line(aData, 96, 4, "SQLite version number");
   188    190   }
   189    191   
   190    192   /*
   191    193   ** Describe cell content.
   192    194   */
   193         -static int describeContent(
          195  +static i64 describeContent(
   194    196     unsigned char *a,       /* Cell content */
   195         -  int nLocal,             /* Bytes in a[] */
          197  +  i64 nLocal,             /* Bytes in a[] */
   196    198     char *zDesc             /* Write description here */
   197    199   ){
   198         -  int nDesc = 0;
   199         -  int n, i, j;
   200         -  i64 x, v;
          200  +  i64 nDesc = 0;
          201  +  int n, j;
          202  +  i64 i, x, v;
   201    203     const unsigned char *pData;
   202    204     const unsigned char *pLimit;
   203    205     char sep = ' ';
   204    206   
   205    207     pLimit = &a[nLocal];
   206    208     n = decodeVarint(a, &x);
   207    209     pData = &a[x];
................................................................................
   233    235         sprintf(zDesc, "real");
   234    236         pData += 8;
   235    237       }else if( x==8 ){
   236    238         sprintf(zDesc, "0");
   237    239       }else if( x==9 ){
   238    240         sprintf(zDesc, "1");
   239    241       }else if( x>=12 ){
   240         -      int size = (x-12)/2;
          242  +      i64 size = (x-12)/2;
   241    243         if( (x&1)==0 ){
   242    244           sprintf(zDesc, "blob(%d)", size);
   243    245         }else{
   244    246           sprintf(zDesc, "txt(%d)", size);
   245    247         }
   246    248         pData += size;
   247    249       }
................................................................................
   252    254     return nDesc;
   253    255   }
   254    256   
   255    257   /*
   256    258   ** Compute the local payload size given the total payload size and
   257    259   ** the page size.
   258    260   */
   259         -static int localPayload(i64 nPayload, char cType){
   260         -  int maxLocal;
   261         -  int minLocal;
   262         -  int surplus;
   263         -  int nLocal;
          261  +static i64 localPayload(i64 nPayload, char cType){
          262  +  i64 maxLocal;
          263  +  i64 minLocal;
          264  +  i64 surplus;
          265  +  i64 nLocal;
   264    266     if( cType==13 ){
   265    267       /* Table leaf */
   266    268       maxLocal = pagesize-35;
   267    269       minLocal = (pagesize-12)*32/255-23;
   268    270     }else{
   269    271       maxLocal = (pagesize-12)*64/255-23;
   270    272       minLocal = (pagesize-12)*32/255-23;
................................................................................
   284    286     
   285    287   
   286    288   /*
   287    289   ** Create a description for a single cell.
   288    290   **
   289    291   ** The return value is the local cell size.
   290    292   */
   291         -static int describeCell(
          293  +static i64 describeCell(
   292    294     unsigned char cType,    /* Page type */
   293    295     unsigned char *a,       /* Cell content */
   294    296     int showCellContent,    /* Show cell content if true */
   295    297     char **pzDesc           /* Store description here */
   296    298   ){
   297    299     int i;
   298         -  int nDesc = 0;
          300  +  i64 nDesc = 0;
   299    301     int n = 0;
   300    302     int leftChild;
   301    303     i64 nPayload;
   302    304     i64 rowid;
   303         -  int nLocal;
          305  +  i64 nLocal;
   304    306     static char zDesc[1000];
   305    307     i = 0;
   306    308     if( cType<=5 ){
   307    309       leftChild = ((a[0]*256 + a[1])*256 + a[2])*256 + a[3];
   308    310       a += 4;
   309    311       n += 4;
   310    312       sprintf(zDesc, "lx: %d ", leftChild);
................................................................................
   369    371   static void decodeCell(
   370    372     unsigned char *a,       /* Page content (without the page-1 header) */
   371    373     unsigned pgno,          /* Page number */
   372    374     int iCell,              /* Cell index */
   373    375     int szPgHdr,            /* Size of the page header.  0 or 100 */
   374    376     int ofst                /* Cell begins at a[ofst] */
   375    377   ){
   376         -  int i, j, k;
          378  +  int i, j;
   377    379     int leftChild;
          380  +  i64 k;
   378    381     i64 nPayload;
   379    382     i64 rowid;
   380    383     i64 nHdr;
   381    384     i64 iType;
   382         -  int nLocal;
          385  +  i64 nLocal;
   383    386     unsigned char *x = a + ofst;
   384    387     unsigned char *end;
   385    388     unsigned char cType = a[0];
   386    389     int nCol = 0;
   387    390     int szCol[2000];
   388    391     int ofstCol[2000];
   389    392     int typeCol[2000];
................................................................................
   448    451              sprintf(zNm, (iType&1)==0 ? "blob(%d)" : "text(%d)", sz);
   449    452              zTypeName = zNm;
   450    453              break;
   451    454            }
   452    455          }
   453    456          printf("%s\n", zTypeName);
   454    457          szCol[nCol] = sz;
   455         -       ofstCol[nCol] = k;
          458  +       ofstCol[nCol] = (int)k;
   456    459          typeCol[nCol] = (int)iType;
   457    460          k += sz;
   458    461          nCol++;
   459    462          j += i;
   460    463       }
   461    464       for(i=0; i<nCol && ofstCol[i]+szCol[i]<=nLocal; i++){
   462    465          int s = ofstCol[i];
................................................................................
   581    584       memset(zMap, '1', hdrSize);
   582    585       memset(&zMap[hdrSize], 'H', iCellPtr);
   583    586       memset(&zMap[hdrSize+iCellPtr], 'P', 2*nCell);
   584    587     }
   585    588     for(i=0; i<nCell; i++){
   586    589       int cofst = iCellPtr + i*2;
   587    590       char *zDesc;
   588         -    int n;
          591  +    i64 n;
   589    592   
   590    593       cofst = a[cofst]*256 + a[cofst+1];
   591    594       n = describeCell(a[0], &a[cofst-hdrSize], showCellContent, &zDesc);
   592    595       if( showMap ){
   593    596         char zBuf[30];
   594         -      memset(&zMap[cofst], '*', n);
          597  +      memset(&zMap[cofst], '*', (size_t)n);
   595    598         zMap[cofst] = '[';
   596    599         zMap[cofst+n-1] = ']';
   597    600         sprintf(zBuf, "%d", i);
   598    601         j = strlen(zBuf);
   599    602         if( j<=n-2 ) memcpy(&zMap[cofst+1], zBuf, j);
   600    603       }
   601    604       if( cellToDecode==(-2) ){
................................................................................
   688    691     int pgno,               /* page containing the cell */
   689    692     int cellno              /* Index of the cell on the page */
   690    693   ){
   691    694     int i;
   692    695     int n = 0;
   693    696     i64 nPayload;
   694    697     i64 rowid;
   695         -  int nLocal;
          698  +  i64 nLocal;
   696    699     i = 0;
   697    700     if( cType<=5 ){
   698    701       a += 4;
   699    702       n += 4;
   700    703     }
   701    704     if( cType!=5 ){
   702    705       i = decodeVarint(a, &nPayload);
................................................................................
   889    892     zPageUse = 0;
   890    893   }
   891    894   
   892    895   /*
   893    896   ** Try to figure out how every page in the database file is being used.
   894    897   */
   895    898   static void ptrmap_coverage_report(const char *zDbName){
   896         -  unsigned int pgno;
          899  +  int pgno;
   897    900     unsigned char *aHdr;
   898    901     unsigned char *a;
   899    902     int usable;
   900    903     int perPage;
   901         -  unsigned int i;
          904  +  int i;
   902    905   
   903    906     /* Avoid the pathological case */
   904    907     if( mxPage<1 ){
   905    908       printf("empty database\n");
   906    909       return;
   907    910     }
   908    911   

Changes to tool/showwal.c.

     2      2   ** A utility for printing content from a write-ahead log file.
     3      3   */
     4      4   #include <stdio.h>
     5      5   #include <ctype.h>
     6      6   #include <sys/types.h>
     7      7   #include <sys/stat.h>
     8      8   #include <fcntl.h>
            9  +
           10  +#if !defined(_MSC_VER)
     9     11   #include <unistd.h>
           12  +#else
           13  +#include <io.h>
           14  +#endif
           15  +
    10     16   #include <stdlib.h>
    11     17   #include <string.h>
    12     18   
    13     19   
    14     20   static int pagesize = 1024;     /* Size of a database page */
    15     21   static int fd = -1;             /* File descriptor for reading the WAL file */
    16     22   static int mxFrame = 0;         /* Last frame */
................................................................................
   269    275       }
   270    276     }
   271    277     free(aData);
   272    278   }
   273    279   /*
   274    280   ** Describe cell content.
   275    281   */
   276         -static int describeContent(
          282  +static i64 describeContent(
   277    283     unsigned char *a,       /* Cell content */
   278         -  int nLocal,             /* Bytes in a[] */
          284  +  i64 nLocal,             /* Bytes in a[] */
   279    285     char *zDesc             /* Write description here */
   280    286   ){
   281    287     int nDesc = 0;
   282         -  int n, i, j;
   283         -  i64 x, v;
          288  +  int n, j;
          289  +  i64 i, x, v;
   284    290     const unsigned char *pData;
   285    291     const unsigned char *pLimit;
   286    292     char sep = ' ';
   287    293   
   288    294     pLimit = &a[nLocal];
   289    295     n = decodeVarint(a, &x);
   290    296     pData = &a[x];
................................................................................
   316    322         sprintf(zDesc, "real");
   317    323         pData += 8;
   318    324       }else if( x==8 ){
   319    325         sprintf(zDesc, "0");
   320    326       }else if( x==9 ){
   321    327         sprintf(zDesc, "1");
   322    328       }else if( x>=12 ){
   323         -      int size = (x-12)/2;
          329  +      i64 size = (x-12)/2;
   324    330         if( (x&1)==0 ){
   325    331           sprintf(zDesc, "blob(%d)", size);
   326    332         }else{
   327    333           sprintf(zDesc, "txt(%d)", size);
   328    334         }
   329    335         pData += size;
   330    336       }
................................................................................
   335    341     return nDesc;
   336    342   }
   337    343   
   338    344   /*
   339    345   ** Compute the local payload size given the total payload size and
   340    346   ** the page size.
   341    347   */
   342         -static int localPayload(i64 nPayload, char cType){
   343         -  int maxLocal;
   344         -  int minLocal;
   345         -  int surplus;
   346         -  int nLocal;
          348  +static i64 localPayload(i64 nPayload, char cType){
          349  +  i64 maxLocal;
          350  +  i64 minLocal;
          351  +  i64 surplus;
          352  +  i64 nLocal;
   347    353     if( cType==13 ){
   348    354       /* Table leaf */
   349    355       maxLocal = pagesize-35;
   350    356       minLocal = (pagesize-12)*32/255-23;
   351    357     }else{
   352    358       maxLocal = (pagesize-12)*64/255-23;
   353    359       minLocal = (pagesize-12)*32/255-23;
................................................................................
   366    372   }
   367    373   
   368    374   /*
   369    375   ** Create a description for a single cell.
   370    376   **
   371    377   ** The return value is the local cell size.
   372    378   */
   373         -static int describeCell(
          379  +static i64 describeCell(
   374    380     unsigned char cType,    /* Page type */
   375    381     unsigned char *a,       /* Cell content */
   376    382     int showCellContent,    /* Show cell content if true */
   377    383     char **pzDesc           /* Store description here */
   378    384   ){
   379    385     int i;
   380         -  int nDesc = 0;
          386  +  i64 nDesc = 0;
   381    387     int n = 0;
   382    388     int leftChild;
   383    389     i64 nPayload;
   384    390     i64 rowid;
   385         -  int nLocal;
          391  +  i64 nLocal;
   386    392     static char zDesc[1000];
   387    393     i = 0;
   388    394     if( cType<=5 ){
   389    395       leftChild = ((a[0]*256 + a[1])*256 + a[2])*256 + a[3];
   390    396       a += 4;
   391    397       n += 4;
   392    398       sprintf(zDesc, "lx: %d ", leftChild);
................................................................................
   475    481       memset(zMap, '1', hdrSize);
   476    482       memset(&zMap[hdrSize], 'H', iCellPtr);
   477    483       memset(&zMap[hdrSize+iCellPtr], 'P', 2*nCell);
   478    484     }
   479    485     for(i=0; i<nCell; i++){
   480    486       int cofst = iCellPtr + i*2;
   481    487       char *zDesc;
   482         -    int n;
          488  +    i64 n;
   483    489   
   484    490       cofst = a[cofst]*256 + a[cofst+1];
   485    491       n = describeCell(a[0], &a[cofst-hdrSize], showCellContent, &zDesc);
   486    492       if( showMap ){
   487    493         char zBuf[30];
   488         -      memset(&zMap[cofst], '*', n);
          494  +      memset(&zMap[cofst], '*', (size_t)n);
   489    495         zMap[cofst] = '[';
   490    496         zMap[cofst+n-1] = ']';
   491    497         sprintf(zBuf, "%d", i);
   492    498         j = strlen(zBuf);
   493    499         if( j<=n-2 ) memcpy(&zMap[cofst+1], zBuf, j);
   494    500       }
   495    501       printf(" %03x: cell[%d] %s\n", cofst, i, zDesc);