/ Check-in [ae16310c]
Login

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

Overview
Comment:Merge enhancements from trunk via tempfiles-lazy-open.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tempfiles-25
Files: files | file ages | folders
SHA1: ae16310c4e9a9b7e94874bd912fc6a4324cfaa2b
User & Date: drh 2016-04-13 19:20:23
Context
2016-04-18
13:30
sqlite3PCachePerecentDirty() should return 0 if the pcache is empty. check-in: 85f3d80e user: drh tags: tempfiles-25
2016-04-13
19:20
Merge enhancements from trunk via tempfiles-lazy-open. check-in: ae16310c user: drh tags: tempfiles-25
16:52
On commit, flush dirty temp-file pages only if the file is already open and 25% or more of the cache is dirty. check-in: f6babf29 user: dan tags: tempfiles-25
16:02
Merge enhancements from trunk. Closed-Leaf check-in: e2edd34e user: drh tags: tempfiles-lazy-open
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts3/fts3_test.c.

   454    454         rc = SQLITE_NOMEM;
   455    455       }else{
   456    456         int i;
   457    457   
   458    458         if( pCsr->iLangid & 0x00000001 ){
   459    459           for(i=0; i<nToken; i++) pCsr->aBuffer[i] = pToken[i];
   460    460         }else{
   461         -        for(i=0; i<nToken; i++) pCsr->aBuffer[i] = testTolower(pToken[i]);
          461  +        for(i=0; i<nToken; i++) pCsr->aBuffer[i] = (char)testTolower(pToken[i]);
   462    462         }
   463    463         pCsr->iToken++;
   464    464         pCsr->iInput = (int)(p - pCsr->aInput);
   465    465   
   466    466         *ppToken = pCsr->aBuffer;
   467    467         *pnBytes = nToken;
   468    468         *piStartOffset = (int)(pToken - pCsr->aInput);

Changes to ext/fts3/tool/fts3view.c.

   394    394              "         WHERE (a.blockid BETWEEN b.start_block"
   395    395                                          " AND b.leaves_end_block)"
   396    396              "           AND (b.level%%1024)==%d)",
   397    397              pgsz-45, zTab, zTab, i);
   398    398       if( sqlite3_step(pStmt)==SQLITE_ROW
   399    399        && (nLeaf = sqlite3_column_int(pStmt, 0))>0
   400    400       ){
   401         -      nIdx = sqlite3_column_int(pStmt, 5);
   402    401         sqlite3_int64 sz;
          402  +      nIdx = sqlite3_column_int(pStmt, 5);
   403    403         printf("For level %d:\n", i);
   404    404         printf("  Number of indexes...................... %9d\n", nIdx);
   405    405         printf("  Number of leaf segments................ %9d\n", nLeaf);
   406    406         if( nIdx>1 ){
   407    407           printf("  Average leaf segments per index........ %11.1f\n",
   408    408                  (double)nLeaf/(double)nIdx);
   409    409         }

Changes to ext/fts5/fts5_hash.c.

   341    341       }else{
   342    342         /* Append a new column value, if necessary */
   343    343         assert( iCol>=p->iCol );
   344    344         if( iCol!=p->iCol ){
   345    345           if( pHash->eDetail==FTS5_DETAIL_FULL ){
   346    346             pPtr[p->nData++] = 0x01;
   347    347             p->nData += sqlite3Fts5PutVarint(&pPtr[p->nData], iCol);
   348         -          p->iCol = iCol;
          348  +          p->iCol = (i16)iCol;
   349    349             p->iPos = 0;
   350    350           }else{
   351    351             bNew = 1;
   352         -          p->iCol = iPos = iCol;
          352  +          p->iCol = (i16)(iPos = iCol);
   353    353           }
   354    354         }
   355    355   
   356    356         /* Append the new position offset, if necessary */
   357    357         if( bNew ){
   358    358           p->nData += sqlite3Fts5PutVarint(&pPtr[p->nData], iPos - p->iPos + 2);
   359    359           p->iPos = iPos;

Changes to ext/fts5/fts5_index.c.

  3240   3240       while( a<pEnd ){
  3241   3241         iPrev += (int)a++[0] - 2;
  3242   3242         while( *aiCol<iPrev ){
  3243   3243           aiCol++;
  3244   3244           if( aiCol==aiColEnd ) goto setoutputs_col_out;
  3245   3245         }
  3246   3246         if( *aiCol==iPrev ){
  3247         -        *aOut++ = (iPrev - iPrevOut) + 2;
         3247  +        *aOut++ = (u8)((iPrev - iPrevOut) + 2);
  3248   3248           iPrevOut = iPrev;
  3249   3249         }
  3250   3250       }
  3251   3251   
  3252   3252   setoutputs_col_out:
  3253   3253       pIter->base.pData = pIter->poslist.p;
  3254   3254       pIter->base.nData = aOut - pIter->poslist.p;

Changes to ext/misc/amatch.c.

   621    621     {
   622    622       pRule = sqlite3_malloc( sizeof(*pRule) + nFrom + nTo );
   623    623       if( pRule==0 ){
   624    624         rc = SQLITE_NOMEM;
   625    625       }else{
   626    626         memset(pRule, 0, sizeof(*pRule));
   627    627         pRule->zFrom = &pRule->zTo[nTo+1];
   628         -      pRule->nFrom = nFrom;
          628  +      pRule->nFrom = (amatch_len)nFrom;
   629    629         memcpy(pRule->zFrom, zFrom, nFrom+1);
   630    630         memcpy(pRule->zTo, zTo, nTo+1);
   631         -      pRule->nTo = nTo;
          631  +      pRule->nTo = (amatch_len)nTo;
   632    632         pRule->rCost = rCost;
   633    633         pRule->iLang = (int)iLang;
   634    634       }
   635    635     }
   636    636   
   637    637     *ppRule = pRule;
   638    638     return rc;
................................................................................
  1077   1077     }
  1078   1078     pWord = sqlite3_malloc( sizeof(*pWord) + nBase + nTail - 1 );
  1079   1079     if( pWord==0 ) return;
  1080   1080     memset(pWord, 0, sizeof(*pWord));
  1081   1081     pWord->rCost = rCost;
  1082   1082     pWord->iSeq = pCur->nWord++;
  1083   1083     amatchWriteCost(pWord);
  1084         -  pWord->nMatch = nMatch;
         1084  +  pWord->nMatch = (short)nMatch;
  1085   1085     pWord->pNext = pCur->pAllWords;
  1086   1086     pCur->pAllWords = pWord;
  1087   1087     pWord->sCost.zKey = pWord->zCost;
  1088   1088     pWord->sCost.pWord = pWord;
  1089   1089     pOther = amatchAvlInsert(&pCur->pCost, &pWord->sCost);
  1090   1090     assert( pOther==0 ); (void)pOther;
  1091   1091     pWord->sWord.zKey = pWord->zWord;
................................................................................
  1158   1158   #ifdef AMATCH_TRACE_1
  1159   1159       printf("PROCESS [%s][%.*s^%s] %d (\"%s\" \"%s\")\n",
  1160   1160          pWord->zWord+2, pWord->nMatch, pCur->zInput, pCur->zInput+pWord->nMatch,
  1161   1161          pWord->rCost, pWord->zWord, pWord->zCost);
  1162   1162   #endif
  1163   1163       nWord = (int)strlen(pWord->zWord+2);
  1164   1164       if( nWord+20>nBuf ){
  1165         -      nBuf = nWord+100;
         1165  +      nBuf = (char)(nWord+100);
  1166   1166         zBuf = sqlite3_realloc(zBuf, nBuf);
  1167   1167         if( zBuf==0 ) return SQLITE_NOMEM;
  1168   1168       }
  1169   1169       amatchStrcpy(zBuf, pWord->zWord+2);
  1170   1170       zNext[0] = 0;
  1171   1171       zNextIn[0] = pCur->zInput[pWord->nMatch];
  1172   1172       if( zNextIn[0] ){

Changes to ext/misc/fuzzer.c.

   340    340       pRule = sqlite3_malloc( sizeof(*pRule) + nFrom + nTo );
   341    341       if( pRule==0 ){
   342    342         rc = SQLITE_NOMEM;
   343    343       }else{
   344    344         memset(pRule, 0, sizeof(*pRule));
   345    345         pRule->zFrom = pRule->zTo;
   346    346         pRule->zFrom += nTo + 1;
   347         -      pRule->nFrom = nFrom;
          347  +      pRule->nFrom = (fuzzer_len)nFrom;
   348    348         memcpy(pRule->zFrom, zFrom, nFrom+1);
   349    349         memcpy(pRule->zTo, zTo, nTo+1);
   350         -      pRule->nTo = nTo;
          350  +      pRule->nTo = (fuzzer_len)nTo;
   351    351         pRule->rCost = nCost;
   352    352         pRule->iRuleset = (int)iRuleset;
   353    353       }
   354    354     }
   355    355   
   356    356     *ppRule = pRule;
   357    357     return rc;

Changes to ext/misc/regexp.c.

   132    132     unsigned nAlloc;            /* Slots allocated for aOp[] and aArg[] */
   133    133   };
   134    134   
   135    135   /* Add a state to the given state set if it is not already there */
   136    136   static void re_add_state(ReStateSet *pSet, int newState){
   137    137     unsigned i;
   138    138     for(i=0; i<pSet->nState; i++) if( pSet->aState[i]==newState ) return;
   139         -  pSet->aState[pSet->nState++] = newState;
          139  +  pSet->aState[pSet->nState++] = (ReStateNumber)newState;
   140    140   }
   141    141   
   142    142   /* Extract the next unicode character from *pzIn and return it.  Advance
   143    143   ** *pzIn to the first byte past the end of the character returned.  To
   144    144   ** be clear:  this routine converts utf8 to unicode.  This routine is 
   145    145   ** optimized for the common case where the next character is a single byte.
   146    146   */
................................................................................
   354    354     int i;
   355    355     if( p->nAlloc<=p->nState && re_resize(p, p->nAlloc*2) ) return 0;
   356    356     for(i=p->nState; i>iBefore; i--){
   357    357       p->aOp[i] = p->aOp[i-1];
   358    358       p->aArg[i] = p->aArg[i-1];
   359    359     }
   360    360     p->nState++;
   361         -  p->aOp[iBefore] = op;
          361  +  p->aOp[iBefore] = (char)op;
   362    362     p->aArg[iBefore] = arg;
   363    363     return iBefore;
   364    364   }
   365    365   
   366    366   /* Append a new opcode and argument to the end of the RE under construction.
   367    367   */
   368    368   static int re_append(ReCompiled *p, int op, int arg){
................................................................................
   673    673     ** regex engine over the string.  Do not worry able trying to match
   674    674     ** unicode characters beyond plane 0 - those are very rare and this is
   675    675     ** just an optimization. */
   676    676     if( pRe->aOp[0]==RE_OP_ANYSTAR ){
   677    677       for(j=0, i=1; j<sizeof(pRe->zInit)-2 && pRe->aOp[i]==RE_OP_MATCH; i++){
   678    678         unsigned x = pRe->aArg[i];
   679    679         if( x<=127 ){
   680         -        pRe->zInit[j++] = x;
          680  +        pRe->zInit[j++] = (unsigned char)x;
   681    681         }else if( x<=0xfff ){
   682         -        pRe->zInit[j++] = 0xc0 | (x>>6);
          682  +        pRe->zInit[j++] = (unsigned char)(0xc0 | (x>>6));
   683    683           pRe->zInit[j++] = 0x80 | (x&0x3f);
   684    684         }else if( x<=0xffff ){
   685         -        pRe->zInit[j++] = 0xd0 | (x>>12);
          685  +        pRe->zInit[j++] = (unsigned char)(0xd0 | (x>>12));
   686    686           pRe->zInit[j++] = 0x80 | ((x>>6)&0x3f);
   687    687           pRe->zInit[j++] = 0x80 | (x&0x3f);
   688    688         }else{
   689    689           break;
   690    690         }
   691    691       }
   692    692       if( j>0 && pRe->zInit[j-1]==0 ) j--;

Changes to ext/misc/spellfix.c.

   386    386     }
   387    387     for(nB=0; zB[nB]; nB++){
   388    388       if( zB[nB]&0x80 ) return -2;
   389    389     }
   390    390   
   391    391     /* Special processing if either string is empty */
   392    392     if( nA==0 ){
   393         -    cBprev = dc;
          393  +    cBprev = (char)dc;
   394    394       for(xB=res=0; (cB = zB[xB])!=0; xB++){
   395    395         res += insertOrDeleteCost(cBprev, cB, zB[xB+1])/FINAL_INS_COST_DIV;
   396    396         cBprev = cB;
   397    397       }
   398    398       return res;
   399    399     }
   400    400     if( nB==0 ){
   401         -    cAprev = dc;
          401  +    cAprev = (char)dc;
   402    402       for(xA=res=0; (cA = zA[xA])!=0; xA++){
   403    403         res += insertOrDeleteCost(cAprev, cA, zA[xA+1]);
   404    404         cAprev = cA;
   405    405       }
   406    406       return res;
   407    407     }
   408    408   
................................................................................
   416    416       m = toFree = sqlite3_malloc64( (nB+1)*5*sizeof(m[0])/4 );
   417    417       if( m==0 ) return -3;
   418    418     }
   419    419     cx = (char*)&m[nB+1];
   420    420   
   421    421     /* Compute the Wagner edit distance */
   422    422     m[0] = 0;
   423         -  cx[0] = dc;
   424         -  cBprev = dc;
          423  +  cx[0] = (char)dc;
          424  +  cBprev = (char)dc;
   425    425     for(xB=1; xB<=nB; xB++){
   426    426       cBnext = zB[xB];
   427    427       cB = zB[xB-1];
   428    428       cx[xB] = cB;
   429    429       m[xB] = m[xB-1] + insertOrDeleteCost(cBprev, cB, cBnext);
   430    430       cBprev = cB;
   431    431     }
   432         -  cAprev = dc;
          432  +  cAprev = (char)dc;
   433    433     for(xA=1; xA<=nA; xA++){
   434    434       int lastA = (xA==nA);
   435    435       cA = zA[xA-1];
   436    436       cAnext = zA[xA];
   437    437       if( cA=='*' && lastA ) break;
   438    438       d = m[0];
   439    439       dc = cx[0];
................................................................................
   472    472                insCost, delCost, subCost, totalCost, ncx?ncx:' ');
   473    473   #endif
   474    474   
   475    475         /* Update the matrix */
   476    476         d = m[xB];
   477    477         dc = cx[xB];
   478    478         m[xB] = totalCost;
   479         -      cx[xB] = ncx;
          479  +      cx[xB] = (char)ncx;
   480    480         cBprev = cB;
   481    481       }
   482    482       cAprev = cA;
   483    483     }
   484    484   
   485    485     /* Free the wagner matrix and return the result */
   486    486     if( cA=='*' ){
................................................................................
   707    707         pLang->iSubCost = iCost;
   708    708       }else{
   709    709         EditDist3Cost *pCost;
   710    710         int nExtra = nFrom + nTo - 4;
   711    711         if( nExtra<0 ) nExtra = 0;
   712    712         pCost = sqlite3_malloc64( sizeof(*pCost) + nExtra );
   713    713         if( pCost==0 ){ rc = SQLITE_NOMEM; break; }
   714         -      pCost->nFrom = nFrom;
   715         -      pCost->nTo = nTo;
   716         -      pCost->iCost = iCost;
          714  +      pCost->nFrom = (u8)nFrom;
          715  +      pCost->nTo = (u8)nTo;
          716  +      pCost->iCost = (u16)iCost;
   717    717         memcpy(pCost->a, zFrom, nFrom);
   718    718         memcpy(pCost->a + nFrom, zTo, nTo);
   719    719         pCost->pNext = pLang->pCost;
   720    720         pLang->pCost = pCost; 
   721    721       }
   722    722     }
   723    723     rc2 = sqlite3_finalize(pStmt);
................................................................................
  1612   1612     if( zOut==0 ) return 0;
  1613   1613     nOut = 0;
  1614   1614     while( nIn>0 ){
  1615   1615       c = utf8Read(zIn, nIn, &sz);
  1616   1616       zIn += sz;
  1617   1617       nIn -= sz;
  1618   1618       if( c<=127 ){
  1619         -      zOut[nOut++] = c;
         1619  +      zOut[nOut++] = (unsigned char)c;
  1620   1620       }else{
  1621   1621         int xTop, xBtm, x;
  1622   1622         xTop = sizeof(translit)/sizeof(translit[0]) - 1;
  1623   1623         xBtm = 0;
  1624   1624         while( xTop>=xBtm ){
  1625   1625           x = (xTop + xBtm)/2;
  1626   1626           if( translit[x].cFrom==c ){

Changes to ext/rbu/sqlite3rbu.c.

  3352   3352   /*
  3353   3353   ** If the error code currently stored in the RBU handle is SQLITE_CONSTRAINT,
  3354   3354   ** then edit any error message string so as to remove all occurrences of
  3355   3355   ** the pattern "rbu_imp_[0-9]*".
  3356   3356   */
  3357   3357   static void rbuEditErrmsg(sqlite3rbu *p){
  3358   3358     if( p->rc==SQLITE_CONSTRAINT && p->zErrmsg ){
  3359         -    int i;
         3359  +    unsigned int i;
  3360   3360       size_t nErrmsg = strlen(p->zErrmsg);
  3361   3361       for(i=0; i<(nErrmsg-8); i++){
  3362   3362         if( memcmp(&p->zErrmsg[i], "rbu_imp_", 8)==0 ){
  3363   3363           int nDel = 8;
  3364   3364           while( p->zErrmsg[i+nDel]>='0' && p->zErrmsg[i+nDel]<='9' ) nDel++;
  3365   3365           memmove(&p->zErrmsg[i], &p->zErrmsg[i+nDel], nErrmsg + 1 - i - nDel);
  3366   3366           nErrmsg -= nDel;

Changes to ext/session/sqlite3session.c.

   931    931     char *zPragma;
   932    932     sqlite3_stmt *pStmt;
   933    933     int rc;
   934    934     int nByte;
   935    935     int nDbCol = 0;
   936    936     int nThis;
   937    937     int i;
   938         -  u8 *pAlloc;
          938  +  u8 *pAlloc = 0;
   939    939     char **azCol = 0;
   940         -  u8 *abPK;
          940  +  u8 *abPK = 0;
   941    941   
   942    942     assert( pazCol && pabPK );
   943    943   
   944    944     nThis = sqlite3Strlen30(zThis);
   945    945     zPragma = sqlite3_mprintf("PRAGMA '%q'.table_info('%q')", zDb, zThis);
   946    946     if( !zPragma ) return SQLITE_NOMEM;
   947    947   
................................................................................
  1589   1589     SessionTable *pTab;
  1590   1590   
  1591   1591     for(pTab=pList; pTab; pTab=pNext){
  1592   1592       int i;
  1593   1593       pNext = pTab->pNext;
  1594   1594       for(i=0; i<pTab->nChange; i++){
  1595   1595         SessionChange *p;
  1596         -      SessionChange *pNext;
  1597         -      for(p=pTab->apChange[i]; p; p=pNext){
  1598         -        pNext = p->pNext;
         1596  +      SessionChange *pNextChange;
         1597  +      for(p=pTab->apChange[i]; p; p=pNextChange){
         1598  +        pNextChange = p->pNext;
  1599   1599           sqlite3_free(p);
  1600   1600         }
  1601   1601       }
  1602   1602       sqlite3_free((char*)pTab->azCol);  /* cast works around VC++ bug */
  1603   1603       sqlite3_free(pTab->apChange);
  1604   1604       sqlite3_free(pTab);
  1605   1605     }
................................................................................
  2878   2878       }
  2879   2879   
  2880   2880       if( p->bPatchset && p->op==SQLITE_UPDATE ){
  2881   2881         /* If this is an UPDATE that is part of a patchset, then all PK and
  2882   2882         ** modified fields are present in the new.* record. The old.* record
  2883   2883         ** is currently completely empty. This block shifts the PK fields from
  2884   2884         ** new.* to old.*, to accommodate the code that reads these arrays.  */
  2885         -      int i;
  2886   2885         for(i=0; i<p->nCol; i++){
  2887   2886           assert( p->apValue[i]==0 );
  2888   2887           assert( p->abPK[i]==0 || p->apValue[i+p->nCol] );
  2889   2888           if( p->abPK[i] ){
  2890   2889             p->apValue[i] = p->apValue[i+p->nCol];
  2891   2890             p->apValue[i+p->nCol] = 0;
  2892   2891           }
................................................................................
  3651   3650     int eType,                      /* Either CHANGESET_DATA or CONFLICT */
  3652   3651     SessionApplyCtx *p,             /* changeset_apply() context */
  3653   3652     sqlite3_changeset_iter *pIter,  /* Changeset iterator */
  3654   3653     int(*xConflict)(void *, int, sqlite3_changeset_iter*),
  3655   3654     void *pCtx,                     /* First argument for conflict handler */
  3656   3655     int *pbReplace                  /* OUT: Set to true if PK row is found */
  3657   3656   ){
  3658         -  int res;                        /* Value returned by conflict handler */
         3657  +  int res = 0;                    /* Value returned by conflict handler */
  3659   3658     int rc;
  3660   3659     int nCol;
  3661   3660     int op;
  3662   3661     const char *zDummy;
  3663   3662   
  3664   3663     sqlite3changeset_op(pIter, &zDummy, &nCol, &op, 0);
  3665   3664   

Changes to ext/session/test_session.c.

   310    310         case SQLITE_TEXT: {
   311    311           const char *z = (char*)sqlite3_value_blob(pVal);
   312    312           int n = sqlite3_value_bytes(pVal);
   313    313           Tcl_ListObjAppendElement(0, pList, Tcl_NewStringObj("t", 1));
   314    314           pObj = Tcl_NewStringObj(z, n);
   315    315           break;
   316    316         }
   317         -      case SQLITE_BLOB:
          317  +      default:
          318  +        assert( sqlite3_value_type(pVal)==SQLITE_BLOB );
   318    319           Tcl_ListObjAppendElement(0, pList, Tcl_NewStringObj("b", 1));
   319    320           pObj = Tcl_NewByteArrayObj(
   320    321               sqlite3_value_blob(pVal),
   321    322               sqlite3_value_bytes(pVal)
   322    323           );
   323    324           break;
   324    325       }
................................................................................
   867    868         zPK[i] = (abPK[i] ? 'X' : '.');
   868    869       }
   869    870       Tcl_ListObjAppendElement(0, pVar, Tcl_NewStringObj(zPK, -1));
   870    871       ckfree(zPK);
   871    872   
   872    873       pOld = Tcl_NewObj();
   873    874       if( op!=SQLITE_INSERT ){
   874         -      int i;
   875    875         for(i=0; i<nCol; i++){
   876    876           sqlite3_value *pVal;
   877    877           sqlite3changeset_old(pIter, i, &pVal);
   878    878           test_append_value(pOld, pVal);
   879    879         }
   880    880       }
   881    881       pNew = Tcl_NewObj();
   882    882       if( op!=SQLITE_DELETE ){
   883         -      int i;
   884    883         for(i=0; i<nCol; i++){
   885    884           sqlite3_value *pVal;
   886    885           sqlite3changeset_new(pIter, i, &pVal);
   887    886           test_append_value(pNew, pVal);
   888    887         }
   889    888       }
   890    889       Tcl_ListObjAppendElement(0, pVar, pOld);

Changes to src/date.c.

    46     46   #include "sqliteInt.h"
    47     47   #include <stdlib.h>
    48     48   #include <assert.h>
    49     49   #include <time.h>
    50     50   
    51     51   #ifndef SQLITE_OMIT_DATETIME_FUNCS
    52     52   
           53  +/*
           54  +** The MSVC CRT on Windows CE may not have a localtime() function.
           55  +** So declare a substitute.  The substitute function itself is
           56  +** defined in "os_win.c".
           57  +*/
           58  +#if !defined(SQLITE_OMIT_LOCALTIME) && defined(_WIN32_WCE) && \
           59  +    (!defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API)
           60  +struct tm *__cdecl localtime(const time_t *);
           61  +#endif
    53     62   
    54     63   /*
    55     64   ** A structure for holding a single date and time.
    56     65   */
    57     66   typedef struct DateTime DateTime;
    58     67   struct DateTime {
    59     68     sqlite3_int64 iJD; /* The julian day number times 86400000 */
................................................................................
   414    423   */
   415    424   static void clearYMD_HMS_TZ(DateTime *p){
   416    425     p->validYMD = 0;
   417    426     p->validHMS = 0;
   418    427     p->validTZ = 0;
   419    428   }
   420    429   
          430  +#ifndef SQLITE_OMIT_LOCALTIME
   421    431   /*
   422    432   ** On recent Windows platforms, the localtime_s() function is available
   423    433   ** as part of the "Secure CRT". It is essentially equivalent to 
   424    434   ** localtime_r() available under most POSIX platforms, except that the 
   425    435   ** order of the parameters is reversed.
   426    436   **
   427    437   ** See http://msdn.microsoft.com/en-us/library/a442x3ye(VS.80).aspx.
................................................................................
   432    442   */
   433    443   #if !HAVE_LOCALTIME_R && !HAVE_LOCALTIME_S \
   434    444       && defined(_MSC_VER) && defined(_CRT_INSECURE_DEPRECATE)
   435    445   #undef  HAVE_LOCALTIME_S
   436    446   #define HAVE_LOCALTIME_S 1
   437    447   #endif
   438    448   
   439         -#ifndef SQLITE_OMIT_LOCALTIME
   440    449   /*
   441    450   ** The following routine implements the rough equivalent of localtime_r()
   442    451   ** using whatever operating-system specific localtime facility that
   443    452   ** is available.  This routine returns 0 on success and
   444    453   ** non-zero on any kind of error.
   445    454   **
   446    455   ** If the sqlite3GlobalConfig.bLocaltimeFault variable is true then this

Changes to src/os_win.c.

  2114   2114       sqlite3_log(SQLITE_NOTICE,
  2115   2115         "delayed %dms for lock/sharing conflict at line %d",
  2116   2116         winIoerrRetryDelay*nRetry*(nRetry+1)/2, lineno
  2117   2117       );
  2118   2118     }
  2119   2119   }
  2120   2120   
  2121         -#if SQLITE_OS_WINCE
  2122         -/*************************************************************************
  2123         -** This section contains code for WinCE only.
         2121  +/*
         2122  +** This #if does not rely on the SQLITE_OS_WINCE define because the
         2123  +** corresponding section in "date.c" cannot use it.
  2124   2124   */
  2125         -#if !defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API
         2125  +#if !defined(SQLITE_OMIT_LOCALTIME) && defined(_WIN32_WCE) && \
         2126  +    (!defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API)
  2126   2127   /*
  2127         -** The MSVC CRT on Windows CE may not have a localtime() function.  So
  2128         -** create a substitute.
         2128  +** The MSVC CRT on Windows CE may not have a localtime() function.
         2129  +** So define a substitute.
  2129   2130   */
  2130         -#include <time.h>
         2131  +#  include <time.h>
  2131   2132   struct tm *__cdecl localtime(const time_t *t)
  2132   2133   {
  2133   2134     static struct tm y;
  2134   2135     FILETIME uTm, lTm;
  2135   2136     SYSTEMTIME pTm;
  2136   2137     sqlite3_int64 t64;
  2137   2138     t64 = *t;
................................................................................
  2147   2148     y.tm_hour = pTm.wHour;
  2148   2149     y.tm_min = pTm.wMinute;
  2149   2150     y.tm_sec = pTm.wSecond;
  2150   2151     return &y;
  2151   2152   }
  2152   2153   #endif
  2153   2154   
         2155  +#if SQLITE_OS_WINCE
         2156  +/*************************************************************************
         2157  +** This section contains code for WinCE only.
         2158  +*/
  2154   2159   #define HANDLE_TO_WINFILE(a) (winFile*)&((char*)a)[-(int)offsetof(winFile,h)]
  2155   2160   
  2156   2161   /*
  2157   2162   ** Acquire a lock on the handle h
  2158   2163   */
  2159   2164   static void winceMutexAcquire(HANDLE h){
  2160   2165      DWORD dwErr;

Changes to src/shell.c.

   665    665   #define MODE_Semi     3  /* Same as MODE_List but append ";" to each line */
   666    666   #define MODE_Html     4  /* Generate an XHTML table */
   667    667   #define MODE_Insert   5  /* Generate SQL "insert" statements */
   668    668   #define MODE_Tcl      6  /* Generate ANSI-C or TCL quoted elements */
   669    669   #define MODE_Csv      7  /* Quote strings, numbers are plain */
   670    670   #define MODE_Explain  8  /* Like MODE_Column, but do not truncate data */
   671    671   #define MODE_Ascii    9  /* Use ASCII unit and record separators (0x1F/0x1E) */
          672  +#define MODE_Pretty  10  /* Pretty-print schemas */
   672    673   
   673    674   static const char *modeDescr[] = {
   674    675     "line",
   675    676     "column",
   676    677     "list",
   677    678     "semi",
   678    679     "html",
   679    680     "insert",
   680    681     "tcl",
   681    682     "csv",
   682    683     "explain",
   683    684     "ascii",
          685  +  "prettyprint",
   684    686   };
   685    687   
   686    688   /*
   687    689   ** These are the column/row/line separators used by the various
   688    690   ** import/export modes.
   689    691   */
   690    692   #define SEP_Column    "|"
................................................................................
  1050   1052             utf8_printf(p->out,"%-*.*s%s",w,w,
  1051   1053                 azArg[i] ? azArg[i] : p->nullValue,
  1052   1054                 i==nArg-1 ? rowSep : "  ");
  1053   1055           }
  1054   1056         }
  1055   1057         break;
  1056   1058       }
  1057         -    case MODE_Semi:
         1059  +    case MODE_Semi: {   /* .schema and .fullschema output */
         1060  +      utf8_printf(p->out, "%s;\n", azArg[0]);
         1061  +      break;
         1062  +    }
         1063  +    case MODE_Pretty: {  /* .schema and .fullschema with --indent */
         1064  +      char *z;
         1065  +      int i,j;
         1066  +      int nParen = 0;
         1067  +      char cEnd = 0;
         1068  +      char c;
         1069  +      int nLine = 0;
         1070  +      assert( nArg==1 );
         1071  +      if( azArg[0]==0 ) break;
         1072  +      if( sqlite3_strlike("CREATE VIEW%", azArg[0], 0)==0
         1073  +       || sqlite3_strlike("CREATE TRIG%", azArg[0], 0)==0
         1074  +      ){
         1075  +        utf8_printf(p->out, "%s;\n", azArg[0]);
         1076  +        break;
         1077  +      }
         1078  +      z = sqlite3_mprintf("%s", azArg[0]);
         1079  +      j = 0;
         1080  +      for(i=0; IsSpace(z[i]); i++){}
         1081  +      for(; (c = z[i])!=0; i++){
         1082  +        if( IsSpace(c) ){
         1083  +          if( IsSpace(z[j-1]) || z[j-1]=='(' ) continue;
         1084  +        }else if( (c=='(' || c==')') && j>0 && IsSpace(z[j-1]) ){
         1085  +          j--;
         1086  +        }
         1087  +        z[j++] = c;
         1088  +      }
         1089  +      while( j>0 && IsSpace(z[j-1]) ){ j--; }
         1090  +      z[j] = 0;
         1091  +      if( strlen30(z)>=79 ){
         1092  +        for(i=j=0; z[i]; i++){
         1093  +          char c = z[i];
         1094  +          if( c==cEnd ){
         1095  +            cEnd = 0;
         1096  +          }else if( c=='"' || c=='\'' || c=='`' ){
         1097  +            cEnd = c;
         1098  +          }else if( c=='[' ){
         1099  +            cEnd = ']';
         1100  +          }else if( c=='(' ){
         1101  +            nParen++;
         1102  +          }else if( c==')' ){
         1103  +            nParen--;
         1104  +            if( nLine>0 && nParen==0 && j>0 ){
         1105  +              utf8_printf(p->out, "%.*s\n", j, z);
         1106  +              j = 0;
         1107  +            }
         1108  +          }
         1109  +          z[j++] = c;
         1110  +          if( nParen==1 && (c=='(' || c==',' || c=='\n') ){
         1111  +            if( c=='\n' ) j--;
         1112  +            utf8_printf(p->out, "%.*s\n  ", j, z);
         1113  +            j = 0;
         1114  +            nLine++;
         1115  +            while( IsSpace(z[i+1]) ){ i++; }
         1116  +          }
         1117  +        }
         1118  +        z[j] = 0;
         1119  +      }
         1120  +      utf8_printf(p->out, "%s;\n", z);
         1121  +      sqlite3_free(z);
         1122  +      break;
         1123  +    }
  1058   1124       case MODE_List: {
  1059   1125         if( p->cnt++==0 && p->showHeader ){
  1060   1126           for(i=0; i<nArg; i++){
  1061   1127             utf8_printf(p->out,"%s%s",azCol[i],
  1062   1128                     i==nArg-1 ? p->rowSeparator : p->colSeparator);
  1063   1129           }
  1064   1130         }
................................................................................
  1065   1131         if( azArg==0 ) break;
  1066   1132         for(i=0; i<nArg; i++){
  1067   1133           char *z = azArg[i];
  1068   1134           if( z==0 ) z = p->nullValue;
  1069   1135           utf8_printf(p->out, "%s", z);
  1070   1136           if( i<nArg-1 ){
  1071   1137             utf8_printf(p->out, "%s", p->colSeparator);
  1072         -        }else if( p->cMode==MODE_Semi ){
  1073         -          utf8_printf(p->out, ";%s", p->rowSeparator);
  1074   1138           }else{
  1075   1139             utf8_printf(p->out, "%s", p->rowSeparator);
  1076   1140           }
  1077   1141         }
  1078   1142         break;
  1079   1143       }
  1080   1144       case MODE_Html: {
................................................................................
  2020   2084     ".dump ?TABLE? ...      Dump the database in an SQL text format\n"
  2021   2085     "                         If TABLE specified, only dump tables matching\n"
  2022   2086     "                         LIKE pattern TABLE.\n"
  2023   2087     ".echo on|off           Turn command echo on or off\n"
  2024   2088     ".eqp on|off            Enable or disable automatic EXPLAIN QUERY PLAN\n"
  2025   2089     ".exit                  Exit this program\n"
  2026   2090     ".explain ?on|off|auto? Turn EXPLAIN output mode on or off or to automatic\n"
  2027         -  ".fullschema            Show schema and the content of sqlite_stat tables\n"
         2091  +  ".fullschema ?--indent? Show schema and the content of sqlite_stat tables\n"
  2028   2092     ".headers on|off        Turn display of headers on or off\n"
  2029   2093     ".help                  Show this message\n"
  2030   2094     ".import FILE TABLE     Import data from FILE into TABLE\n"
  2031   2095     ".indexes ?TABLE?       Show names of all indexes\n"
  2032   2096     "                         If TABLE specified, only show indexes for tables\n"
  2033   2097     "                         matching LIKE pattern TABLE.\n"
  2034   2098   #ifdef SQLITE_ENABLE_IOTRACE
................................................................................
  2056   2120     ".print STRING...       Print literal STRING\n"
  2057   2121     ".prompt MAIN CONTINUE  Replace the standard prompts\n"
  2058   2122     ".quit                  Exit this program\n"
  2059   2123     ".read FILENAME         Execute SQL in FILENAME\n"
  2060   2124     ".restore ?DB? FILE     Restore content of DB (default \"main\") from FILE\n"
  2061   2125     ".save FILE             Write in-memory database into FILE\n"
  2062   2126     ".scanstats on|off      Turn sqlite3_stmt_scanstatus() metrics on or off\n"
  2063         -  ".schema ?TABLE?        Show the CREATE statements\n"
  2064         -  "                         If TABLE specified, only show tables matching\n"
  2065         -  "                         LIKE pattern TABLE.\n"
         2127  +  ".schema ?PATTERN?      Show the CREATE statements matching PATTERN\n"
         2128  +  "                          Add --indent for pretty-printing\n"
  2066   2129     ".separator COL ?ROW?   Change the column separator and optionally the row\n"
  2067   2130     "                         separator for both the output mode and .import\n"
  2068   2131   #if defined(SQLITE_ENABLE_SESSION)
  2069   2132     ".session CMD ...       Create or control sessions\n"
  2070   2133   #endif
  2071   2134     ".shell CMD ARGS...     Run CMD ARGS... in a system shell\n"
  2072   2135     ".show                  Show the current values for various settings\n"
................................................................................
  2928   2991   /*
  2929   2992   ** Print an out-of-memory message to stderr and return 1.
  2930   2993   */
  2931   2994   static int shellNomemError(void){
  2932   2995     raw_printf(stderr, "Error: out of memory\n");
  2933   2996     return 1;
  2934   2997   }
         2998  +
         2999  +/*
         3000  +** Compare the string as a command-line option with either one or two
         3001  +** initial "-" characters.
         3002  +*/
         3003  +static int optionMatch(const char *zStr, const char *zOpt){
         3004  +  if( zStr[0]!='-' ) return 0;
         3005  +  zStr++;
         3006  +  if( zStr[0]=='-' ) zStr++;
         3007  +  return strcmp(zStr, zOpt)==0;
         3008  +}
  2935   3009   
  2936   3010   /*
  2937   3011   ** If an input line begins with "." then invoke this routine to
  2938   3012   ** process that line.
  2939   3013   **
  2940   3014   ** Return 1 on error, 2 to exit, and 0 otherwise.
  2941   3015   */
................................................................................
  3215   3289       }
  3216   3290     }else
  3217   3291   
  3218   3292     if( c=='f' && strncmp(azArg[0], "fullschema", n)==0 ){
  3219   3293       ShellState data;
  3220   3294       char *zErrMsg = 0;
  3221   3295       int doStats = 0;
  3222         -    if( nArg!=1 ){
  3223         -      raw_printf(stderr, "Usage: .fullschema\n");
  3224         -      rc = 1;
  3225         -      goto meta_command_exit;
  3226         -    }
  3227         -    open_db(p, 0);
  3228   3296       memcpy(&data, p, sizeof(data));
  3229   3297       data.showHeader = 0;
  3230   3298       data.cMode = data.mode = MODE_Semi;
         3299  +    if( nArg==2 && optionMatch(azArg[1], "indent") ){
         3300  +      data.cMode = data.mode = MODE_Pretty;
         3301  +      nArg = 1;
         3302  +    }
         3303  +    if( nArg!=1 ){
         3304  +      raw_printf(stderr, "Usage: .fullschema ?--indent?\n");
         3305  +      rc = 1;
         3306  +      goto meta_command_exit;
         3307  +    }
         3308  +    open_db(p, 0);
  3231   3309       rc = sqlite3_exec(p->db,
  3232   3310          "SELECT sql FROM"
  3233   3311          "  (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
  3234   3312          "     FROM sqlite_master UNION ALL"
  3235   3313          "   SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) "
  3236   3314          "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%' "
  3237   3315          "ORDER BY rowid",
................................................................................
  3858   3936     if( c=='s' && strncmp(azArg[0], "schema", n)==0 ){
  3859   3937       ShellState data;
  3860   3938       char *zErrMsg = 0;
  3861   3939       open_db(p, 0);
  3862   3940       memcpy(&data, p, sizeof(data));
  3863   3941       data.showHeader = 0;
  3864   3942       data.cMode = data.mode = MODE_Semi;
  3865         -    if( nArg==2 ){
         3943  +    if( nArg>=2 && optionMatch(azArg[1], "indent") ){
         3944  +      data.cMode = data.mode = MODE_Pretty;
         3945  +      nArg--;
         3946  +      if( nArg==2 ) azArg[1] = azArg[2];
         3947  +    }
         3948  +    if( nArg==2 && azArg[1][0]!='-' ){
  3866   3949         int i;
  3867   3950         for(i=0; azArg[1][i]; i++) azArg[1][i] = ToLower(azArg[1][i]);
  3868   3951         if( strcmp(azArg[1],"sqlite_master")==0 ){
  3869   3952           char *new_argv[2], *new_colv[2];
  3870   3953           new_argv[0] = "CREATE TABLE sqlite_master (\n"
  3871   3954                         "  type text,\n"
  3872   3955                         "  name text,\n"
................................................................................
  3913   3996            "     FROM sqlite_master UNION ALL"
  3914   3997            "   SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) "
  3915   3998            "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%' "
  3916   3999            "ORDER BY rowid",
  3917   4000            callback, &data, &zErrMsg
  3918   4001         );
  3919   4002       }else{
  3920         -      raw_printf(stderr, "Usage: .schema ?LIKE-PATTERN?\n");
         4003  +      raw_printf(stderr, "Usage: .schema ?--indent? ?LIKE-PATTERN?\n");
  3921   4004         rc = 1;
  3922   4005         goto meta_command_exit;
  3923   4006       }
  3924   4007       if( zErrMsg ){
  3925   4008         utf8_printf(stderr,"Error: %s\n", zErrMsg);
  3926   4009         sqlite3_free(zErrMsg);
  3927   4010         rc = 1;

Changes to src/tclsqlite.c.

  3031   3031     */
  3032   3032     case DB_WAL_HOOK: 
  3033   3033     case DB_UPDATE_HOOK: 
  3034   3034     case DB_ROLLBACK_HOOK: {
  3035   3035       /* set ppHook to point at pUpdateHook or pRollbackHook, depending on 
  3036   3036       ** whether [$db update_hook] or [$db rollback_hook] was invoked.
  3037   3037       */
  3038         -    Tcl_Obj **ppHook; 
         3038  +    Tcl_Obj **ppHook = 0; 
  3039   3039       if( choice==DB_WAL_HOOK ) ppHook = &pDb->pWalHook;
  3040   3040       if( choice==DB_UPDATE_HOOK ) ppHook = &pDb->pUpdateHook;
  3041   3041       if( choice==DB_ROLLBACK_HOOK ) ppHook = &pDb->pRollbackHook;
  3042   3042       if( objc>3 ){
  3043   3043          Tcl_WrongNumArgs(interp, 2, objv, "?SCRIPT?");
  3044   3044          return TCL_ERROR;
  3045   3045       }

Changes to src/test_multiplex.c.

   535    535   
   536    536     if( rc==SQLITE_OK ){
   537    537       const char *zUri = (flags & SQLITE_OPEN_URI) ? zName : 0;
   538    538       /* assign pointers to extra space allocated */
   539    539       memset(pGroup, 0, sz);
   540    540       pMultiplexOpen->pGroup = pGroup;
   541    541       pGroup->bEnabled = (unsigned char)-1;
   542         -    pGroup->bTruncate = sqlite3_uri_boolean(zUri, "truncate", 
          542  +    pGroup->bTruncate = (unsigned char)sqlite3_uri_boolean(zUri, "truncate", 
   543    543                                      (flags & SQLITE_OPEN_MAIN_DB)==0);
   544    544       pGroup->szChunk = (int)sqlite3_uri_int64(zUri, "chunksize",
   545    545                                           SQLITE_MULTIPLEX_CHUNK_SIZE);
   546    546       pGroup->szChunk = (pGroup->szChunk+0xffff)&~0xffff;
   547    547       if( zName ){
   548    548         char *p = (char *)&pGroup[1];
   549    549         pGroup->zName = p;
................................................................................
   974    974     sqlite3_file *pSubOpen;
   975    975   
   976    976     if( !gMultiplex.isInitialized ) return SQLITE_MISUSE;
   977    977     switch( op ){
   978    978       case MULTIPLEX_CTRL_ENABLE:
   979    979         if( pArg ) {
   980    980           int bEnabled = *(int *)pArg;
   981         -        pGroup->bEnabled = bEnabled;
          981  +        pGroup->bEnabled = (unsigned char)bEnabled;
   982    982           rc = SQLITE_OK;
   983    983         }
   984    984         break;
   985    985       case MULTIPLEX_CTRL_SET_CHUNK_SIZE:
   986    986         if( pArg ) {
   987    987           unsigned int szChunk = *(unsigned*)pArg;
   988    988           if( szChunk<1 ){

Changes to src/test_onefile.c.

   504    504     fs_real_file *pReal = p->pReal;
   505    505     sqlite3_file *pRealFile = pReal->pFile;
   506    506     int rc = SQLITE_OK;
   507    507   
   508    508     if( p->eType==DATABASE_FILE ){
   509    509       unsigned char zSize[4];
   510    510       zSize[0] = (pReal->nDatabase&0xFF000000)>>24;
   511         -    zSize[1] = (pReal->nDatabase&0x00FF0000)>>16;
          511  +    zSize[1] = (unsigned char)((pReal->nDatabase&0x00FF0000)>>16);
   512    512       zSize[2] = (pReal->nDatabase&0x0000FF00)>>8;
   513    513       zSize[3] = (pReal->nDatabase&0x000000FF);
   514    514       rc = pRealFile->pMethods->xWrite(pRealFile, zSize, 4, 0);
   515    515     }
   516    516     if( rc==SQLITE_OK ){
   517    517       rc = pRealFile->pMethods->xSync(pRealFile, flags&(~SQLITE_SYNC_DATAONLY));
   518    518     }

Changes to src/test_osinst.c.

   640    640     sqlite3_io_error_persist = persist;
   641    641     sqlite3_diskfull_pending = diskfull;
   642    642   #endif
   643    643   }
   644    644   
   645    645   static void put32bits(unsigned char *p, unsigned int v){
   646    646     p[0] = v>>24;
   647         -  p[1] = v>>16;
   648         -  p[2] = v>>8;
   649         -  p[3] = v;
          647  +  p[1] = (unsigned char)(v>>16);
          648  +  p[2] = (unsigned char)(v>>8);
          649  +  p[3] = (unsigned char)v;
   650    650   }
   651    651   
   652    652   static void vfslog_call(
   653    653     sqlite3_vfs *pVfs,
   654    654     int eEvent,
   655    655     int iFileid,
   656    656     sqlite3_int64 nClick,

Changes to test/shell1.test.

   564    564   } {0 {}}
   565    565   do_test shell1-3.21.2 {
   566    566     catchcmd "test.db" ".schema FOO"
   567    567   } {0 {}}
   568    568   do_test shell1-3.21.3 {
   569    569     # too many arguments
   570    570     catchcmd "test.db" ".schema FOO BAD"
   571         -} {1 {Usage: .schema ?LIKE-PATTERN?}}
          571  +} {1 {Usage: .schema ?--indent? ?LIKE-PATTERN?}}
   572    572   
   573    573   do_test shell1-3.21.4 {
   574    574     catchcmd "test.db" {
   575    575        CREATE TABLE t1(x);
   576    576        CREATE VIEW v2 AS SELECT x+1 AS y FROM t1;
   577    577        CREATE VIEW v1 AS SELECT y+1 FROM v2;
   578    578     }

Changes to test/speedtest1.c.

    26     26     "  --scratch N SZ      Configure scratch memory for N slots of SZ bytes each\n"
    27     27     "  --serialized        Set serialized threading mode\n"
    28     28     "  --singlethread      Set single-threaded mode - disables all mutexing\n"
    29     29     "  --sqlonly           No-op.  Only show the SQL that would have been run.\n"
    30     30     "  --shrink-memory     Invoke sqlite3_db_release_memory() frequently.\n"
    31     31     "  --size N            Relative test size.  Default=100\n"
    32     32     "  --stats             Show statistics at the end\n"
           33  +  "  --temp N            N from 0 to 9.  0: no temp table. 9: all temp tables\n"
    33     34     "  --testset T         Run test-set T\n"
    34     35     "  --trace             Turn on SQL tracing\n"
    35     36     "  --threads N         Use up to N threads for sorting\n"
    36     37     "  --utf16be           Set text encoding to UTF-16BE\n"
    37     38     "  --utf16le           Set text encoding to UTF-16LE\n"
    38     39     "  --verify            Run additional verification steps.\n"
    39     40     "  --without-rowid     Use WITHOUT ROWID where appropriate\n"
................................................................................
    65     66     sqlite3_int64 iTotal;      /* Total time */
    66     67     int bWithoutRowid;         /* True for --without-rowid */
    67     68     int bReprepare;            /* True to reprepare the SQL on each rerun */
    68     69     int bSqlOnly;              /* True to print the SQL once only */
    69     70     int bExplain;              /* Print SQL with EXPLAIN prefix */
    70     71     int bVerify;               /* Try to verify that results are correct */
    71     72     int bMemShrink;            /* Call sqlite3_db_release_memory() often */
           73  +  int eTemp;                 /* 0: no TEMP.  9: always TEMP. */
    72     74     int szTest;                /* Scale factor for test iterations */
    73     75     const char *zWR;           /* Might be WITHOUT ROWID */
    74     76     const char *zNN;           /* Might be NOT NULL */
    75     77     const char *zPK;           /* Might be UNIQUE or PRIMARY KEY */
    76     78     unsigned int x, y;         /* Pseudo-random number generator state */
    77     79     int nResult;               /* Size of the current result */
    78     80     char zResult[3000];        /* Text of the current result */
    79     81   } g;
           82  +
           83  +/* Return " TEMP" or "", as appropriate for creating a table.
           84  +*/
           85  +static const char *isTemp(int N){
           86  +  return g.eTemp>=N ? " TEMP" : "";
           87  +}
    80     88   
    81     89   
    82     90   /* Print an error message and exit */
    83     91   static void fatal_error(const char *zMsg, ...){
    84     92     va_list ap;
    85     93     va_start(ap, zMsg);
    86     94     vfprintf(stderr, zMsg, ap);
................................................................................
   455    463     int len;                      /* Length of the zNum[] string */
   456    464     char zNum[2000];              /* A number name */
   457    465   
   458    466     sz = n = g.szTest*500;
   459    467     maxb = roundup_allones(sz);
   460    468     speedtest1_begin_test(100, "%d INSERTs into table with no index", n);
   461    469     speedtest1_exec("BEGIN");
   462         -  speedtest1_exec("CREATE TABLE t1(a INTEGER %s, b INTEGER %s, c TEXT %s);",
   463         -                  g.zNN, g.zNN, g.zNN);
          470  +  speedtest1_exec("CREATE%s TABLE t1(a INTEGER %s, b INTEGER %s, c TEXT %s);",
          471  +                  isTemp(9), g.zNN, g.zNN, g.zNN);
   464    472     speedtest1_prepare("INSERT INTO t1 VALUES(?1,?2,?3); --  %d times", n);
   465    473     for(i=1; i<=n; i++){
   466    474       x1 = swizzle(i,maxb);
   467    475       speedtest1_numbername(x1, zNum, sizeof(zNum));
   468    476       sqlite3_bind_int64(g.pStmt, 1, (sqlite3_int64)x1);
   469    477       sqlite3_bind_int(g.pStmt, 2, i);
   470    478       sqlite3_bind_text(g.pStmt, 3, zNum, -1, SQLITE_STATIC);
................................................................................
   473    481     speedtest1_exec("COMMIT");
   474    482     speedtest1_end_test();
   475    483   
   476    484   
   477    485     n = sz;
   478    486     speedtest1_begin_test(110, "%d ordered INSERTS with one index/PK", n);
   479    487     speedtest1_exec("BEGIN");
   480         -  speedtest1_exec("CREATE TABLE t2(a INTEGER %s %s, b INTEGER %s, c TEXT %s) %s",
   481         -                   g.zNN, g.zPK, g.zNN, g.zNN, g.zWR);
          488  +  speedtest1_exec(
          489  +     "CREATE%s TABLE t2(a INTEGER %s %s, b INTEGER %s, c TEXT %s) %s",
          490  +     isTemp(5), g.zNN, g.zPK, g.zNN, g.zNN, g.zWR);
   482    491     speedtest1_prepare("INSERT INTO t2 VALUES(?1,?2,?3); -- %d times", n);
   483    492     for(i=1; i<=n; i++){
   484    493       x1 = swizzle(i,maxb);
   485    494       speedtest1_numbername(x1, zNum, sizeof(zNum));
   486    495       sqlite3_bind_int(g.pStmt, 1, i);
   487    496       sqlite3_bind_int64(g.pStmt, 2, (sqlite3_int64)x1);
   488    497       sqlite3_bind_text(g.pStmt, 3, zNum, -1, SQLITE_STATIC);
................................................................................
   491    500     speedtest1_exec("COMMIT");
   492    501     speedtest1_end_test();
   493    502   
   494    503   
   495    504     n = sz;
   496    505     speedtest1_begin_test(120, "%d unordered INSERTS with one index/PK", n);
   497    506     speedtest1_exec("BEGIN");
   498         -  speedtest1_exec("CREATE TABLE t3(a INTEGER %s %s, b INTEGER %s, c TEXT %s) %s",
   499         -                   g.zNN, g.zPK, g.zNN, g.zNN, g.zWR);
          507  +  speedtest1_exec(
          508  +      "CREATE%s TABLE t3(a INTEGER %s %s, b INTEGER %s, c TEXT %s) %s",
          509  +      isTemp(3), g.zNN, g.zPK, g.zNN, g.zNN, g.zWR);
   500    510     speedtest1_prepare("INSERT INTO t3 VALUES(?1,?2,?3); -- %d times", n);
   501    511     for(i=1; i<=n; i++){
   502    512       x1 = swizzle(i,maxb);
   503    513       speedtest1_numbername(x1, zNum, sizeof(zNum));
   504    514       sqlite3_bind_int(g.pStmt, 2, i);
   505    515       sqlite3_bind_int64(g.pStmt, 1, (sqlite3_int64)x1);
   506    516       sqlite3_bind_text(g.pStmt, 3, zNum, -1, SQLITE_STATIC);
................................................................................
   650    660     speedtest1_exec("COMMIT");
   651    661     speedtest1_end_test();
   652    662   
   653    663     n = sz;
   654    664     speedtest1_begin_test(180, "%d INSERTS with three indexes", n);
   655    665     speedtest1_exec("BEGIN");
   656    666     speedtest1_exec(
   657         -    "CREATE TABLE t4(\n"
          667  +    "CREATE%s TABLE t4(\n"
   658    668       "  a INTEGER %s %s,\n"
   659    669       "  b INTEGER %s,\n"
   660    670       "  c TEXT %s\n"
   661    671       ") %s",
   662         -    g.zNN, g.zPK, g.zNN, g.zNN, g.zWR);
          672  +    isTemp(1), g.zNN, g.zPK, g.zNN, g.zNN, g.zWR);
   663    673     speedtest1_exec("CREATE INDEX t4b ON t4(b)");
   664    674     speedtest1_exec("CREATE INDEX t4c ON t4(c)");
   665    675     speedtest1_exec("INSERT INTO t4 SELECT * FROM t1");
   666    676     speedtest1_exec("COMMIT");
   667    677     speedtest1_end_test();
   668    678   
   669    679     n = sz;
................................................................................
  1043   1053       sqlite3_bind_int(g.pStmt, 7, z1);
  1044   1054       speedtest1_run();
  1045   1055     }
  1046   1056     speedtest1_exec("COMMIT");
  1047   1057     speedtest1_end_test();
  1048   1058   
  1049   1059     speedtest1_begin_test(101, "Copy from rtree to a regular table");
  1050         -  speedtest1_exec("CREATE TABLE t1(id INTEGER PRIMARY KEY,x0,x1,y0,y1,z0,z1)");
         1060  +  speedtest1_exec(" TABLE t1(id INTEGER PRIMARY KEY,x0,x1,y0,y1,z0,z1)");
  1051   1061     speedtest1_exec("INSERT INTO t1 SELECT * FROM rt1");
  1052   1062     speedtest1_end_test();
  1053   1063   
  1054   1064     n = g.szTest*20;
  1055   1065     speedtest1_begin_test(110, "%d one-dimensional intersect slice queries", n);
  1056   1066     speedtest1_prepare("SELECT count(*) FROM rt1 WHERE x0>=?1 AND x1<=?2");
  1057   1067     iStep = mxCoord/n;
................................................................................
  1317   1327         }else if( strcmp(z,"shrink-memory")==0 ){
  1318   1328           g.bMemShrink = 1;
  1319   1329         }else if( strcmp(z,"size")==0 ){
  1320   1330           if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]);
  1321   1331           g.szTest = integerValue(argv[++i]);
  1322   1332         }else if( strcmp(z,"stats")==0 ){
  1323   1333           showStats = 1;
         1334  +      }else if( strcmp(z,"temp")==0 ){
         1335  +        if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]);
         1336  +        i++;
         1337  +        if( argv[i][0]<'0' || argv[i][0]>'9' || argv[i][1]!=0 ){
         1338  +          fatal_error("argument to --temp should be integer between 0 and 9");
         1339  +        }
         1340  +        g.eTemp = argv[i][0] - '0';
  1324   1341         }else if( strcmp(z,"testset")==0 ){
  1325   1342           if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]);
  1326   1343           zTSet = argv[++i];
  1327   1344         }else if( strcmp(z,"trace")==0 ){
  1328   1345           doTrace = 1;
  1329   1346         }else if( strcmp(z,"threads")==0 ){
  1330   1347           if( i>=argc-1 ) fatal_error("missing argument on %s\n", argv[i]);
................................................................................
  1348   1365       }else if( zDbName==0 ){
  1349   1366         zDbName = argv[i];
  1350   1367       }else{
  1351   1368         fatal_error("surplus argument: %s\nUse \"%s -?\" for help\n",
  1352   1369                     argv[i], argv[0]);
  1353   1370       }
  1354   1371     }
  1355         -#if 0
  1356         -  if( zDbName==0 ){
  1357         -    fatal_error(zHelp, argv[0]);
  1358         -  }
  1359         -#endif
         1372  +  if( zDbName!=0 ) unlink(zDbName);
  1360   1373   #if SQLITE_VERSION_NUMBER>=3006001
  1361   1374     if( nHeap>0 ){
  1362   1375       pHeap = malloc( nHeap );
  1363   1376       if( pHeap==0 ) fatal_error("cannot allocate %d-byte heap\n", nHeap);
  1364   1377       rc = sqlite3_config(SQLITE_CONFIG_HEAP, pHeap, nHeap, mnHeap);
  1365   1378       if( rc ) fatal_error("heap configuration failed: %d\n", rc);
  1366   1379     }

Changes to tool/logest.c.

   143    143       }else if( strcmp(z,"log")==0 ){
   144    144         if( n>0 ) a[n-1] = logEstFromInteger(a[n-1]) - 33;
   145    145       }else if( strcmp(z,"nlogn")==0 ){
   146    146         if( n>0 ) a[n-1] += logEstFromInteger(a[n-1]) - 33;
   147    147       }else if( strcmp(z,"inv")==0 ){
   148    148         if( n>0 ) a[n-1] = -a[n-1];
   149    149       }else if( z[0]=='^' ){
   150         -      a[n++] = atoi(z+1);
          150  +      a[n++] = (LogEst)atoi(z+1);
   151    151       }else if( isInteger(z) ){
   152    152         a[n++] = logEstFromInteger(atoi(z));
   153    153       }else if( isFloat(z) && z[0]!='-' ){
   154    154         a[n++] = logEstFromDouble(atof(z));
   155    155       }else{
   156    156         showHelp(argv[0]);
   157    157       }

Changes to tool/showdb.c.

   147    147     if( g.bRaw==0 ){
   148    148       int rc = g.pFd->pMethods->xRead(g.pFd, (void*)aData, nByte, ofst);
   149    149       if( rc!=SQLITE_OK && rc!=SQLITE_IOERR_SHORT_READ ){
   150    150         fprintf(stderr, "error in xRead() - %d\n", rc);
   151    151         exit(1);
   152    152       }
   153    153     }else{
   154         -    lseek(g.dbfd, ofst, SEEK_SET);
          154  +    lseek(g.dbfd, (long)ofst, SEEK_SET);
   155    155       got = read(g.dbfd, aData, nByte);
   156    156       if( got>0 && got<nByte ) memset(aData+got, 0, nByte-got);
   157    157     }
   158    158     return aData;
   159    159   }
   160    160   
   161    161   /*
................................................................................
  1094   1094   
  1095   1095     zPgSz = fileRead(16, 2);
  1096   1096     g.pagesize = zPgSz[0]*256 + zPgSz[1]*65536;
  1097   1097     if( g.pagesize==0 ) g.pagesize = 1024;
  1098   1098     sqlite3_free(zPgSz);
  1099   1099   
  1100   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   1103     printf("Available pages: 1..%d\n", g.mxPage);
  1104   1104     if( nArg==2 ){
  1105   1105       int i;
  1106   1106       for(i=1; i<=g.mxPage; i++) print_page(i);
  1107   1107     }else{
  1108   1108       int i;