/ Check-in [161d91e4]
Login

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

Overview
Comment:Merge the SQLITE_OMIT_CODEC_FROM_TCL compile-time option from trunk.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | apple-osx
Files: files | file ages | folders
SHA1: 161d91e485059efb36b7bc74d091f9721b76dcbf
User & Date: drh 2016-03-16 01:09:07
Context
2016-03-18
00:58
Merge recent enhancements from trunk. check-in: ec052b4f user: drh tags: apple-osx
2016-03-16
01:09
Merge the SQLITE_OMIT_CODEC_FROM_TCL compile-time option from trunk. check-in: 161d91e4 user: drh tags: apple-osx
01:03
Add the SQLITE_OMIT_CODEC_FROM_TCL compile-time option. check-in: 45f7f0c8 user: drh tags: trunk
2016-03-15
12:45
Merge updates from trunk - FTS5 fixes and enhancemenets to the tests scripts so that they work with SEE. check-in: f41a7361 user: drh tags: apple-osx
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to src/os_win.c.

  3253   3253     OSTRACE(("FCNTL file=%p, op=%d, pArg=%p\n", pFile->h, op, pArg));
  3254   3254     switch( op ){
  3255   3255       case SQLITE_FCNTL_LOCKSTATE: {
  3256   3256         *(int*)pArg = pFile->locktype;
  3257   3257         OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
  3258   3258         return SQLITE_OK;
  3259   3259       }
  3260         -    case SQLITE_LAST_ERRNO: {
         3260  +    case SQLITE_FCNTL_LAST_ERRNO: {
  3261   3261         *(int*)pArg = (int)pFile->lastErrno;
  3262   3262         OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));
  3263   3263         return SQLITE_OK;
  3264   3264       }
  3265   3265       case SQLITE_FCNTL_CHUNK_SIZE: {
  3266   3266         pFile->szChunk = *(int *)pArg;
  3267   3267         OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h));

Changes to src/pragma.c.

  1435   1435       }
  1436   1436       sqlite3VdbeAddOp2(v, OP_Integer, mxErr, 1);  /* reg[1] holds errors left */
  1437   1437   
  1438   1438       /* Do an integrity check on each database file */
  1439   1439       for(i=0; i<db->nDb; i++){
  1440   1440         HashElem *x;
  1441   1441         Hash *pTbls;
         1442  +      int *aRoot;
  1442   1443         int cnt = 0;
  1443   1444   
  1444   1445         if( OMIT_TEMPDB && i==1 ) continue;
  1445   1446         if( iDb>=0 && i!=iDb ) continue;
  1446   1447   
  1447   1448         sqlite3CodeVerifySchema(pParse, i);
  1448   1449         addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Halt if out of errors */
  1449   1450         VdbeCoverage(v);
  1450   1451         sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
  1451   1452         sqlite3VdbeJumpHere(v, addr);
  1452   1453   
  1453   1454         /* Do an integrity check of the B-Tree
  1454   1455         **
  1455         -      ** Begin by filling registers 2, 3, ... with the root pages numbers
         1456  +      ** Begin by finding the root pages numbers
  1456   1457         ** for all tables and indices in the database.
  1457   1458         */
  1458   1459         assert( sqlite3SchemaMutexHeld(db, i, 0) );
  1459   1460         pTbls = &db->aDb[i].pSchema->tblHash;
  1460         -      for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
         1461  +      for(cnt=0, x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
         1462  +        Table *pTab = sqliteHashData(x);
         1463  +        Index *pIdx;
         1464  +        if( HasRowid(pTab) ) cnt++;
         1465  +        for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ cnt++; }
         1466  +      }
         1467  +      aRoot = sqlite3DbMallocRawNN(db, sizeof(int)*(cnt+1));
         1468  +      if( aRoot==0 ) break;
         1469  +      for(cnt=0, x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
  1461   1470           Table *pTab = sqliteHashData(x);
  1462   1471           Index *pIdx;
  1463         -        if( HasRowid(pTab) ){
  1464         -          sqlite3VdbeAddOp2(v, OP_Integer, pTab->tnum, 2+cnt);
  1465         -          VdbeComment((v, "%s", pTab->zName));
  1466         -          cnt++;
  1467         -        }
         1472  +        if( HasRowid(pTab) ) aRoot[cnt++] = pTab->tnum;
  1468   1473           for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
  1469         -          sqlite3VdbeAddOp2(v, OP_Integer, pIdx->tnum, 2+cnt);
  1470         -          VdbeComment((v, "%s", pIdx->zName));
  1471         -          cnt++;
         1474  +          aRoot[cnt++] = pIdx->tnum;
  1472   1475           }
  1473   1476         }
         1477  +      aRoot[cnt] = 0;
  1474   1478   
  1475   1479         /* Make sure sufficient number of registers have been allocated */
  1476         -      pParse->nMem = MAX( pParse->nMem, cnt+8 );
         1480  +      pParse->nMem = MAX( pParse->nMem, 14 );
  1477   1481   
  1478   1482         /* Do the b-tree integrity checks */
  1479         -      sqlite3VdbeAddOp3(v, OP_IntegrityCk, 2, cnt, 1);
         1483  +      sqlite3VdbeAddOp4(v, OP_IntegrityCk, 2, cnt, 1, (char*)aRoot,P4_INTARRAY);
  1480   1484         sqlite3VdbeChangeP5(v, (u8)i);
  1481   1485         addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v);
  1482   1486         sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
  1483   1487            sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
  1484   1488            P4_DYNAMIC);
  1485   1489         sqlite3VdbeAddOp3(v, OP_Move, 2, 4, 1);
  1486   1490         sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2);

Changes to src/select.c.

  4966   4966           SELECTTRACE(0x100,pParse,p,("After WHERE-clause push-down:\n"));
  4967   4967           sqlite3TreeViewSelect(0, p, 0);
  4968   4968         }
  4969   4969   #endif
  4970   4970       }
  4971   4971   
  4972   4972       /* Generate code to implement the subquery
         4973  +    **
         4974  +    ** The subquery is implemented as a co-routine if all of these are true:
         4975  +    **   (1)  The subquery is guaranteed to be the outer loop (so that it
         4976  +    **        does not need to be computed more than once)
         4977  +    **   (2)  The ALL keyword after SELECT is omitted.  (Applications are
         4978  +    **        allowed to say "SELECT ALL" instead of just "SELECT" to disable
         4979  +    **        the use of co-routines.)
         4980  +    **   (3)  Co-routines are not disabled using sqlite3_test_control()
         4981  +    **        with SQLITE_TESTCTRL_OPTIMIZATIONS.
         4982  +    **
         4983  +    ** TODO: Are there other reasons beside (1) to use a co-routine
         4984  +    ** implementation?
  4973   4985       */
  4974         -    if( pTabList->nSrc==1
  4975         -     && (p->selFlags & SF_All)==0
  4976         -     && OptimizationEnabled(db, SQLITE_SubqCoroutine)
         4986  +    if( i==0
         4987  +     && (pTabList->nSrc==1
         4988  +            || (pTabList->a[1].fg.jointype&(JT_LEFT|JT_CROSS))!=0)  /* (1) */
         4989  +     && (p->selFlags & SF_All)==0                                   /* (2) */
         4990  +     && OptimizationEnabled(db, SQLITE_SubqCoroutine)               /* (3) */
  4977   4991       ){
  4978   4992         /* Implement a co-routine that will return a single row of the result
  4979   4993         ** set on each invocation.
  4980   4994         */
  4981   4995         int addrTop = sqlite3VdbeCurrentAddr(v)+1;
  4982   4996         pItem->regReturn = ++pParse->nMem;
  4983   4997         sqlite3VdbeAddOp3(v, OP_InitCoroutine, pItem->regReturn, 0, addrTop);

Changes to src/tclsqlite.c.

  2570   2570   
  2571   2571     /*
  2572   2572     **     $db rekey KEY
  2573   2573     **
  2574   2574     ** Change the encryption key on the currently open database.
  2575   2575     */
  2576   2576     case DB_REKEY: {
  2577         -#ifdef SQLITE_HAS_CODEC
         2577  +#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL)
  2578   2578       int nKey;
  2579   2579       void *pKey;
  2580   2580   #endif
  2581   2581       if( objc!=3 ){
  2582   2582         Tcl_WrongNumArgs(interp, 2, objv, "KEY");
  2583   2583         return TCL_ERROR;
  2584   2584       }
  2585         -#ifdef SQLITE_HAS_CODEC
         2585  +#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL)
  2586   2586       pKey = Tcl_GetByteArrayFromObj(objv[2], &nKey);
  2587   2587       rc = sqlite3_rekey(pDb->db, pKey, nKey);
  2588   2588       if( rc ){
  2589   2589         Tcl_AppendResult(interp, sqlite3_errstr(rc), (char*)0);
  2590   2590         rc = TCL_ERROR;
  2591   2591       }
  2592   2592   #endif
................................................................................
  2951   2951     const char *zArg;
  2952   2952     char *zErrMsg;
  2953   2953     int i;
  2954   2954     const char *zFile;
  2955   2955     const char *zVfs = 0;
  2956   2956     int flags;
  2957   2957     Tcl_DString translatedFilename;
  2958         -#ifdef SQLITE_HAS_CODEC
         2958  +#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL)
  2959   2959     void *pKey = 0;
  2960   2960     int nKey = 0;
  2961   2961   #endif
  2962   2962     int rc;
  2963   2963   
  2964   2964     /* In normal use, each TCL interpreter runs in a single thread.  So
  2965   2965     ** by default, we can turn of mutexing on SQLite database connections.
................................................................................
  2980   2980         return TCL_OK;
  2981   2981       }
  2982   2982       if( strcmp(zArg,"-sourceid")==0 ){
  2983   2983         Tcl_AppendResult(interp,sqlite3_sourceid(), (char*)0);
  2984   2984         return TCL_OK;
  2985   2985       }
  2986   2986       if( strcmp(zArg,"-has-codec")==0 ){
  2987         -#ifdef SQLITE_HAS_CODEC
         2987  +#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL)
  2988   2988         Tcl_AppendResult(interp,"1",(char*)0);
  2989   2989   #else
  2990   2990         Tcl_AppendResult(interp,"0",(char*)0);
  2991   2991   #endif
  2992   2992         return TCL_OK;
  2993   2993       }
  2994   2994     }
  2995   2995     for(i=3; i+1<objc; i+=2){
  2996   2996       zArg = Tcl_GetString(objv[i]);
  2997   2997       if( strcmp(zArg,"-key")==0 ){
  2998         -#ifdef SQLITE_HAS_CODEC
         2998  +#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL)
  2999   2999         pKey = Tcl_GetByteArrayFromObj(objv[i+1], &nKey);
  3000   3000   #endif
  3001   3001       }else if( strcmp(zArg, "-vfs")==0 ){
  3002   3002         zVfs = Tcl_GetString(objv[i+1]);
  3003   3003       }else if( strcmp(zArg, "-readonly")==0 ){
  3004   3004         int b;
  3005   3005         if( Tcl_GetBooleanFromObj(interp, objv[i+1], &b) ) return TCL_ERROR;
................................................................................
  3049   3049         return TCL_ERROR;
  3050   3050       }
  3051   3051     }
  3052   3052     if( objc<3 || (objc&1)!=1 ){
  3053   3053       Tcl_WrongNumArgs(interp, 1, objv, 
  3054   3054         "HANDLE FILENAME ?-vfs VFSNAME? ?-readonly BOOLEAN? ?-create BOOLEAN?"
  3055   3055         " ?-nomutex BOOLEAN? ?-fullmutex BOOLEAN? ?-uri BOOLEAN?"
  3056         -#ifdef SQLITE_HAS_CODEC
         3056  +#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL)
  3057   3057         " ?-key CODECKEY?"
  3058   3058   #endif
  3059   3059       );
  3060   3060       return TCL_ERROR;
  3061   3061     }
  3062   3062     zErrMsg = 0;
  3063   3063     p = (SqliteDb*)Tcl_Alloc( sizeof(*p) );
................................................................................
  3075   3075         zErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(p->db));
  3076   3076         sqlite3_close(p->db);
  3077   3077         p->db = 0;
  3078   3078       }
  3079   3079     }else{
  3080   3080       zErrMsg = sqlite3_mprintf("%s", sqlite3_errstr(rc));
  3081   3081     }
  3082         -#ifdef SQLITE_HAS_CODEC
         3082  +#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL)
  3083   3083     if( p->db ){
  3084   3084       sqlite3_key(p->db, pKey, nKey);
  3085   3085     }
  3086   3086   #endif
  3087   3087     if( p->db==0 ){
  3088   3088       Tcl_SetResult(interp, zErrMsg, TCL_VOLATILE);
  3089   3089       Tcl_Free((char*)p);

Changes to src/test1.c.

   647    647   */
   648    648   static int test_key(
   649    649     void *NotUsed,
   650    650     Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
   651    651     int argc,              /* Number of arguments */
   652    652     char **argv            /* Text of each argument */
   653    653   ){
   654         -#ifdef SQLITE_HAS_CODEC
          654  +#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL)
   655    655     sqlite3 *db;
   656    656     const char *zKey;
   657    657     int nKey;
   658    658     if( argc!=3 ){
   659    659       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   660    660          " FILENAME\"", 0);
   661    661       return TCL_ERROR;

Changes to src/vdbe.c.

  5419   5419   case OP_DropTrigger: {
  5420   5420     sqlite3UnlinkAndDeleteTrigger(db, pOp->p1, pOp->p4.z);
  5421   5421     break;
  5422   5422   }
  5423   5423   
  5424   5424   
  5425   5425   #ifndef SQLITE_OMIT_INTEGRITY_CHECK
  5426         -/* Opcode: IntegrityCk P1 P2 P3 * P5
         5426  +/* Opcode: IntegrityCk P1 P2 P3 P4 P5
  5427   5427   **
  5428   5428   ** Do an analysis of the currently open database.  Store in
  5429   5429   ** register P1 the text of an error message describing any problems.
  5430   5430   ** If no problems are found, store a NULL in register P1.
  5431   5431   **
  5432   5432   ** The register P3 contains the maximum number of allowed errors.
  5433   5433   ** At most reg(P3) errors will be reported.
  5434   5434   ** In other words, the analysis stops as soon as reg(P1) errors are 
  5435   5435   ** seen.  Reg(P1) is updated with the number of errors remaining.
  5436   5436   **
  5437         -** The root page numbers of all tables in the database are integer
  5438         -** stored in reg(P1), reg(P1+1), reg(P1+2), ....  There are P2 tables
  5439         -** total.
         5437  +** The root page numbers of all tables in the database are integers
         5438  +** stored in P4_INTARRAY argument.
  5440   5439   **
  5441   5440   ** If P5 is not zero, the check is done on the auxiliary database
  5442   5441   ** file, not the main database file.
  5443   5442   **
  5444   5443   ** This opcode is used to implement the integrity_check pragma.
  5445   5444   */
  5446   5445   case OP_IntegrityCk: {
  5447   5446     int nRoot;      /* Number of tables to check.  (Number of root pages.) */
  5448   5447     int *aRoot;     /* Array of rootpage numbers for tables to be checked */
  5449         -  int j;          /* Loop counter */
  5450   5448     int nErr;       /* Number of errors reported */
  5451   5449     char *z;        /* Text of the error report */
  5452   5450     Mem *pnErr;     /* Register keeping track of errors remaining */
  5453   5451   
  5454   5452     assert( p->bIsReader );
  5455   5453     nRoot = pOp->p2;
         5454  +  aRoot = pOp->p4.ai;
  5456   5455     assert( nRoot>0 );
  5457         -  aRoot = sqlite3DbMallocRawNN(db, sizeof(int)*(nRoot+1) );
  5458         -  if( aRoot==0 ) goto no_mem;
         5456  +  assert( aRoot[nRoot]==0 );
  5459   5457     assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
  5460   5458     pnErr = &aMem[pOp->p3];
  5461   5459     assert( (pnErr->flags & MEM_Int)!=0 );
  5462   5460     assert( (pnErr->flags & (MEM_Str|MEM_Blob))==0 );
  5463   5461     pIn1 = &aMem[pOp->p1];
  5464         -  for(j=0; j<nRoot; j++){
  5465         -    aRoot[j] = (int)sqlite3VdbeIntValue(&pIn1[j]);
  5466         -  }
  5467         -  aRoot[j] = 0;
  5468   5462     assert( pOp->p5<db->nDb );
  5469   5463     assert( DbMaskTest(p->btreeMask, pOp->p5) );
  5470   5464     z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, aRoot, nRoot,
  5471   5465                                    (int)pnErr->u.i, &nErr);
  5472         -  sqlite3DbFree(db, aRoot);
  5473   5466     pnErr->u.i -= nErr;
  5474   5467     sqlite3VdbeMemSetNull(pIn1);
  5475   5468     if( nErr==0 ){
  5476   5469       assert( z==0 );
  5477   5470     }else if( z==0 ){
  5478   5471       goto no_mem;
  5479   5472     }else{

Changes to src/vdbeInt.h.

   377    377     int pc;                 /* The program counter */
   378    378     int rc;                 /* Value to return */
   379    379   #ifdef SQLITE_DEBUG
   380    380     int rcApp;              /* errcode set by sqlite3_result_error_code() */
   381    381   #endif
   382    382     u16 nResColumn;         /* Number of columns in one row of the result set */
   383    383     u8 errorAction;         /* Recovery action to do in case of an error */
          384  +  bft expired:1;          /* True if the VM needs to be recompiled */
          385  +  bft doingRerun:1;       /* True if rerunning after an auto-reprepare */
   384    386     u8 minWriteFileFormat;  /* Minimum file format for writable database files */
   385    387     bft explain:2;          /* True if EXPLAIN present on SQL command */
   386    388     bft changeCntOn:1;      /* True to update the change-counter */
   387         -  bft expired:1;          /* True if the VM needs to be recompiled */
   388    389     bft runOnlyOnce:1;      /* Automatically expire on reset */
   389    390     bft usesStmtJournal:1;  /* True if uses a statement journal */
   390    391     bft readOnly:1;         /* True for statements that do not write */
   391    392     bft bIsReader:1;        /* True for statements that read */
   392    393     bft isPrepareV2:1;      /* True if prepared with prepare_v2() */
   393         -  bft doingRerun:1;       /* True if rerunning after an auto-reprepare */
   394    394     int nChange;            /* Number of db changes made since last reset */
   395    395     yDbMask btreeMask;      /* Bitmask of db->aDb[] entries referenced */
   396    396     yDbMask lockMask;       /* Subset of btreeMask that requires a lock */
   397    397     int iStatement;         /* Statement number (or 0 if has not opened stmt) */
   398    398     u32 aCounter[5];        /* Counters used by sqlite3_stmt_status() */
   399    399   #ifndef SQLITE_OMIT_TRACE
   400    400     i64 startTime;          /* Time when query started - used for profiling */

Changes to test/select4.test.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this file is testing UNION, INTERSECT and EXCEPT operators
    13     13   # in SELECT statements.
    14     14   #
    15         -# $Id: select4.test,v 1.30 2009/04/16 00:24:24 drh Exp $
    16     15   
    17     16   set testdir [file dirname $argv0]
    18     17   source $testdir/tester.tcl
    19     18   
    20     19   # Most tests in this file depend on compound-select. But there are a couple
    21     20   # right at the end that test DISTINCT, so we cannot omit the entire file.
    22     21   #
................................................................................
   931    930      WHERE t0.a=t1.a AND t1.a=33 AND t0.b=456
   932    931     UNION
   933    932     SELECT DISTINCT t0.id, t0.a, t0.b
   934    933       FROM tx AS t0, tx AS t1
   935    934      WHERE t0.a=t1.a AND t1.a=33 AND t0.b=789
   936    935      ORDER BY 1;
   937    936   } {1 33 456 2 33 789}
          937  +
          938  +# Enhancement (2016-03-15):  Use a co-routine for subqueries if the
          939  +# subquery is guaranteed to be the outer-most query
          940  +#
          941  +do_execsql_test select4-16.1 {
          942  +  DROP TABLE IF EXISTS t1;
          943  +  CREATE TABLE t1(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,
          944  +  PRIMARY KEY(a,b DESC)) WITHOUT ROWID;
          945  +
          946  +  WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100)
          947  +  INSERT INTO t1(a,b,c,d)
          948  +    SELECT x%10, x/10, x, printf('xyz%dabc',x) FROM c;
          949  +
          950  +  SELECT t3.c FROM 
          951  +    (SELECT a,max(b) AS m FROM t1 WHERE a>=5 GROUP BY a) AS t2
          952  +    JOIN t1 AS t3
          953  +  WHERE t2.a=t3.a AND t2.m=t3.b
          954  +  ORDER BY t3.a;
          955  +} {95 96 97 98 99}
          956  +do_execsql_test select4-16.2 {
          957  +  SELECT t3.c FROM 
          958  +    (SELECT a,max(b) AS m FROM t1 WHERE a>=5 GROUP BY a) AS t2
          959  +    CROSS JOIN t1 AS t3
          960  +  WHERE t2.a=t3.a AND t2.m=t3.b
          961  +  ORDER BY t3.a;
          962  +} {95 96 97 98 99}
          963  +do_execsql_test select4-16.3 {
          964  +  SELECT t3.c FROM 
          965  +    (SELECT a,max(b) AS m FROM t1 WHERE a>=5 GROUP BY a) AS t2
          966  +    LEFT JOIN t1 AS t3
          967  +  WHERE t2.a=t3.a AND t2.m=t3.b
          968  +  ORDER BY t3.a;
          969  +} {95 96 97 98 99}
          970  +
          971  +
          972  +
   938    973   
   939    974   finish_test