/ Check-in [df3cdf9f]
Login

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

Overview
Comment:Merge the latest changes from trunk into the apple-osx branch.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | apple-osx
Files: files | file ages | folders
SHA1: df3cdf9f0690f2724c7e4e0adb2e3bd4b1a4dd26
User & Date: drh 2015-01-02 19:17:44
Context
2015-01-08
19:55
Merge the testing enhancements and the unlimited VALUES enhancement from trunk. check-in: cc780842 user: drh tags: apple-osx
2015-01-02
19:17
Merge the latest changes from trunk into the apple-osx branch. check-in: df3cdf9f user: drh tags: apple-osx
15:55
Add the SQLITE_CONFIG_PMASZ start-time option. check-in: acb0d1e8 user: drh tags: trunk
2014-12-16
00:29
Merge latest fixes and enhancements from trunk into apple-osx. check-in: 2c1d8dda user: drh tags: apple-osx
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Makefile.in.

    18     18   TOP = @srcdir@
    19     19   
    20     20   # C Compiler and options for use in building executables that
    21     21   # will run on the platform that is doing the build.
    22     22   #
    23     23   BCC = @BUILD_CC@ @BUILD_CFLAGS@
    24     24   
    25         -# C Compile and options for use in building executables that 
           25  +# TCC is the C Compile and options for use in building executables that 
    26     26   # will run on the target platform.  (BCC and TCC are usually the
    27         -# same unless your are cross-compiling.)
           27  +# same unless your are cross-compiling.)  Separate CC and CFLAGS macros
           28  +# are provide so that these aspects of the build process can be changed
           29  +# on the "make" command-line.  Ex:  "make CC=clang CFLAGS=-fsanitize=undefined"
    28     30   #
    29         -TCC = @CC@ @CPPFLAGS@ @CFLAGS@ -I. -I${TOP}/src -I${TOP}/ext/rtree
           31  +CC = @CC@
           32  +CFLAGS = @CPPFLAGS@ @CFLAGS@
           33  +TCC = $(CC) $(CFLAGS) -I. -I${TOP}/src -I${TOP}/ext/rtree
    30     34   
    31     35   # Define this for the autoconf-based build, so that the code knows it can
    32     36   # include the generated config.h
    33     37   # 
    34     38   TCC += -D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite
    35     39   
    36     40   # Define -DNDEBUG to compile without debugging (i.e., for production usage)
................................................................................
   539    543   		-o $@ $(TOP)/src/shell.c libsqlite3.la \
   540    544   		$(LIBREADLINE) $(TLIBS) -rpath "$(libdir)"
   541    545   
   542    546   mptester$(EXE):	sqlite3.c $(TOP)/mptest/mptest.c
   543    547   	$(LTLINK) -o $@ -I. $(TOP)/mptest/mptest.c sqlite3.c \
   544    548   		$(TLIBS) -rpath "$(libdir)"
   545    549   
          550  +mptest:	mptester$(EXE)
          551  +	rm -f mptest1.db
          552  +	./mptester$(EXE) mptest1.db $(TOP)/mptest/crash01.test
          553  +	rm -f mptest2.db
          554  +	./mptester$(EXE) mptest2.db $(TOP)/mptest/multiwrite01.test
   546    555   
   547    556   # This target creates a directory named "tsrc" and fills it with
   548    557   # copies of all of the C source code and header files needed to
   549    558   # build on the target system.  Some of the C source code and header
   550    559   # files are automatically generated.  This target takes care of
   551    560   # all that automatic generation.
   552    561   #
................................................................................
   977    986   	$(LTLINK) -I. -o $@ $(TOP)/tool/logest.c
   978    987   
   979    988   wordcount$(TEXE):	$(TOP)/test/wordcount.c sqlite3.c
   980    989   	$(LTLINK) -o $@ $(TOP)/test/wordcount.c sqlite3.c $(TLIBS)
   981    990   
   982    991   speedtest1$(TEXE):	$(TOP)/test/wordcount.c sqlite3.lo
   983    992   	$(LTLINK) -o $@ $(TOP)/test/speedtest1.c sqlite3.lo $(TLIBS)
          993  +
          994  +# This target will fail if the SQLite amalgamation contains any exported
          995  +# symbols that do not begin with "sqlite3_". It is run as part of the
          996  +# releasetest.tcl script.
          997  +#
          998  +checksymbols: sqlite3.lo
          999  +	nm -g --defined-only sqlite3.o | grep -v " sqlite3_" ; test $$? -ne 0
         1000  +	echo '0 errors out of 1 tests'
         1001  +
         1002  +# The next two rules are used to support the "threadtest" target. Building
         1003  +# threadtest runs a few thread-safety tests that are implemented in C. This
         1004  +# target is invoked by the releasetest.tcl script.
         1005  +# 
         1006  +THREADTEST3_SRC = $(TOP)/test/threadtest3.c    \
         1007  +                  $(TOP)/test/tt3_checkpoint.c \
         1008  +                  $(TOP)/test/tt3_index.c      \
         1009  +                  $(TOP)/test/tt3_vacuum.c      \
         1010  +                  $(TOP)/test/tt3_stress.c      \
         1011  +                  $(TOP)/test/tt3_lookaside1.c
         1012  +
         1013  +threadtest3$(TEXE): sqlite3.lo $(THREADTEST3_SRC)
         1014  +	$(LTLINK) $(TOP)/test/threadtest3.c sqlite3.lo -o $@ $(TLIBS)
         1015  +
         1016  +threadtest: threadtest3$(TEXE)
         1017  +	./threadtest3$(TEXE)
         1018  +
         1019  +releasetest:	
         1020  +	$(TCLSH_CMD) $(TOP)/test/releasetest.tcl
   984   1021   
   985   1022   # Standard install and cleanup targets
   986   1023   #
   987   1024   lib_install:	libsqlite3.la
   988   1025   	$(INSTALL) -d $(DESTDIR)$(libdir)
   989   1026   	$(LTINSTALL) libsqlite3.la $(DESTDIR)$(libdir)
   990   1027   	

Changes to Makefile.msc.

   104    104   !ENDIF
   105    105   
   106    106   # Set this to one of the following values to enable various debugging
   107    107   # features.  Each level includes the debugging options from the previous
   108    108   # levels.  Currently, the recognized values for DEBUG are:
   109    109   #
   110    110   # 0 == NDEBUG: Disables assert() and other runtime diagnostics.
   111         -# 1 == Disables NDEBUG and all optimizations and then enables PDBs.
   112         -# 2 == SQLITE_DEBUG: Enables various diagnostics messages and code.
   113         -# 3 == SQLITE_WIN32_MALLOC_VALIDATE: Validate the Win32 native heap per call.
   114         -# 4 == SQLITE_DEBUG_OS_TRACE: Enables output from the OSTRACE() macros.
   115         -# 5 == SQLITE_ENABLE_IOTRACE: Enables output from the IOTRACE() macros.
          111  +# 1 == SQLITE_ENABLE_API_ARMOR: extra attempts to detect misuse of the API.
          112  +# 2 == Disables NDEBUG and all optimizations and then enables PDBs.
          113  +# 3 == SQLITE_DEBUG: Enables various diagnostics messages and code.
          114  +# 4 == SQLITE_WIN32_MALLOC_VALIDATE: Validate the Win32 native heap per call.
          115  +# 5 == SQLITE_DEBUG_OS_TRACE: Enables output from the OSTRACE() macros.
          116  +# 6 == SQLITE_ENABLE_IOTRACE: Enables output from the IOTRACE() macros.
   116    117   #
   117    118   !IFNDEF DEBUG
   118    119   DEBUG = 0
   119    120   !ENDIF
   120    121   
   121    122   # Enable use of available compiler optimizations?  Normally, this should be
   122    123   # non-zero.  Setting this to zero, thus disabling all compiler optimizations,
................................................................................
   276    277   
   277    278   # Also, we need to dynamically link to the correct MSVC runtime
   278    279   # when compiling for WinRT (e.g. debug or release) OR if the
   279    280   # USE_CRT_DLL option is set to force dynamically linking to the
   280    281   # MSVC runtime library.
   281    282   #
   282    283   !IF $(FOR_WINRT)!=0 || $(USE_CRT_DLL)!=0
   283         -!IF $(DEBUG)>0
          284  +!IF $(DEBUG)>1
   284    285   TCC = $(TCC) -MDd
   285    286   BCC = $(BCC) -MDd
   286    287   !ELSE
   287    288   TCC = $(TCC) -MD
   288    289   BCC = $(BCC) -MD
   289    290   !ENDIF
   290    291   !ELSE
   291         -!IF $(DEBUG)>0
          292  +!IF $(DEBUG)>1
   292    293   TCC = $(TCC) -MTd
   293    294   BCC = $(BCC) -MTd
   294    295   !ELSE
   295    296   TCC = $(TCC) -MT
   296    297   BCC = $(BCC) -MT
   297    298   !ENDIF
   298    299   !ENDIF
................................................................................
   309    310   !ENDIF
   310    311   
   311    312   # The mksqlite3c.tcl script accepts some options on the command
   312    313   # line.  When compiling with debugging enabled, some of these
   313    314   # options are necessary in order to allow debugging symbols to
   314    315   # work correctly with Visual Studio when using the amalgamation.
   315    316   #
   316         -!IF $(DEBUG)>0
          317  +!IF $(DEBUG)>1
   317    318   MKSQLITE3C_ARGS = --linemacros
   318    319   !ELSE
   319    320   MKSQLITE3C_ARGS =
   320    321   !ENDIF
   321    322   
   322    323   # Define -DNDEBUG to compile without debugging (i.e., for production usage)
   323    324   # Omitting the define will cause extra debugging code to be inserted and
................................................................................
   325    326   #
   326    327   !IF $(DEBUG)==0
   327    328   TCC = $(TCC) -DNDEBUG
   328    329   BCC = $(BCC) -DNDEBUG
   329    330   RCC = $(RCC) -DNDEBUG
   330    331   !ENDIF
   331    332   
   332         -!IF $(DEBUG)>1
          333  +!IF $(DEBUG)>0
          334  +TCC = $(TCC) -DSQLITE_ENABLE_API_ARMOR
          335  +RCC = $(RCC) -DSQLITE_ENABLE_API_ARMOR
          336  +!ENDIF
          337  +
          338  +!IF $(DEBUG)>2
   333    339   TCC = $(TCC) -DSQLITE_DEBUG
   334    340   RCC = $(RCC) -DSQLITE_DEBUG
   335    341   !ENDIF
   336    342   
   337         -!IF $(DEBUG)>3
          343  +!IF $(DEBUG)>4
   338    344   TCC = $(TCC) -DSQLITE_DEBUG_OS_TRACE=1
   339    345   RCC = $(RCC) -DSQLITE_DEBUG_OS_TRACE=1
   340    346   !ENDIF
   341    347   
   342         -!IF $(DEBUG)>4
          348  +!IF $(DEBUG)>5
   343    349   TCC = $(TCC) -DSQLITE_ENABLE_IOTRACE
   344    350   RCC = $(RCC) -DSQLITE_ENABLE_IOTRACE
   345    351   !ENDIF
   346    352   
   347    353   # Prevent warnings about "insecure" MSVC runtime library functions
   348    354   # being used.
   349    355   #
................................................................................
   367    373   #
   368    374   !ELSEIF $(WIN32HEAP)!=0
   369    375   TCC = $(TCC) -DSQLITE_WIN32_MALLOC=1
   370    376   RCC = $(RCC) -DSQLITE_WIN32_MALLOC=1
   371    377   
   372    378   # Validate the heap on every call into the native Win32 heap subsystem?
   373    379   #
   374         -!IF $(DEBUG)>2
          380  +!IF $(DEBUG)>3
   375    381   TCC = $(TCC) -DSQLITE_WIN32_MALLOC_VALIDATE=1
   376    382   RCC = $(RCC) -DSQLITE_WIN32_MALLOC_VALIDATE=1
   377    383   !ENDIF
   378    384   !ENDIF
   379    385   
   380    386   # The locations of the Tcl header and library files.  Also, the library that
   381    387   # non-stubs enabled programs using Tcl must link against.  These variables
................................................................................
   478    484   # nmake /f Makefile.msc all "OPTS=-DSQLITE_ENABLE_FOO=1 -DSQLITE_OMIT_FOO=1"
   479    485   #
   480    486   TCC = $(TCC) $(OPTS)
   481    487   RCC = $(RCC) $(OPTS)
   482    488   
   483    489   # If compiling for debugging, add some defines.
   484    490   #
   485         -!IF $(DEBUG)>0
          491  +!IF $(DEBUG)>1
   486    492   TCC = $(TCC) -D_DEBUG
   487    493   BCC = $(BCC) -D_DEBUG
   488    494   RCC = $(RCC) -D_DEBUG
   489    495   !ENDIF
   490    496   
   491    497   # If optimizations are enabled or disabled (either implicitly or
   492    498   # explicitly), add the necessary flags.
   493    499   #
   494         -!IF $(DEBUG)>0 || $(OPTIMIZATIONS)==0
          500  +!IF $(DEBUG)>1 || $(OPTIMIZATIONS)==0
   495    501   TCC = $(TCC) -Od
   496    502   BCC = $(BCC) -Od
   497    503   !ELSEIF $(OPTIMIZATIONS)>=3
   498    504   TCC = $(TCC) -Ox
   499    505   BCC = $(BCC) -Ox
   500    506   !ELSEIF $(OPTIMIZATIONS)==2
   501    507   TCC = $(TCC) -O2
................................................................................
   503    509   !ELSEIF $(OPTIMIZATIONS)==1
   504    510   TCC = $(TCC) -O1
   505    511   BCC = $(BCC) -O1
   506    512   !ENDIF
   507    513   
   508    514   # If symbols are enabled (or compiling for debugging), enable PDBs.
   509    515   #
   510         -!IF $(DEBUG)>0 || $(SYMBOLS)!=0
          516  +!IF $(DEBUG)>1 || $(SYMBOLS)!=0
   511    517   TCC = $(TCC) -Zi
   512    518   BCC = $(BCC) -Zi
   513    519   !ENDIF
   514    520   
   515    521   # If ICU support is enabled, add the compiler options for it.
   516    522   #
   517    523   !IF $(USE_ICU)!=0
................................................................................
   588    594   LTLINKOPTS = $(LTLINKOPTS) /DYNAMICBASE
   589    595   LTLINKOPTS = $(LTLINKOPTS) WindowsPhoneCore.lib RuntimeObject.lib PhoneAppModelHost.lib
   590    596   LTLINKOPTS = $(LTLINKOPTS) /NODEFAULTLIB:kernel32.lib /NODEFAULTLIB:ole32.lib
   591    597   !ENDIF
   592    598   
   593    599   # If either debugging or symbols are enabled, enable PDBs.
   594    600   #
   595         -!IF $(DEBUG)>0 || $(SYMBOLS)!=0
          601  +!IF $(DEBUG)>1 || $(SYMBOLS)!=0
   596    602   LDFLAGS = /DEBUG
   597    603   !ENDIF
   598    604   
   599    605   # Start with the Tcl related linker options.
   600    606   #
   601    607   !IF $(NO_TCL)==0
   602    608   LTLIBPATHS = /LIBPATH:$(TCLLIBDIR)

Changes to README.md.

    49     49   
    50     50   There are several build options that can be set via the NMAKE command
    51     51   line.  For example, to build for WinRT, simply add "FOR_WINRT=1" argument
    52     52   to the "sqlite3.dll" command line above.  When debugging into the SQLite
    53     53   code, adding the "DEBUG=1" argument to one of the above command lines is
    54     54   recommended.
    55     55   
    56         -SQLite does not require Tcl to run, but a Tcl installation is required
    57         -by the makefiles (including those for MSVC).  SQLite contains a lot of
    58         -generated code and Tcl is used to do much of that code generation.  The
    59         -makefiles also require AWK.
           56  +SQLite does not require [Tcl](http://www.tcl.tk/) to run, but a Tcl installation
           57  +is required by the makefiles (including those for MSVC).  SQLite contains
           58  +a lot of generated code and Tcl is used to do much of that code generation.
           59  +The makefiles also require AWK.
    60     60   
    61     61   ## Source Code Tour
    62     62   
    63     63   Most of the core source files are in the **src/** subdirectory.  But
    64     64   src/ also contains files used to build the "testfixture" test harness;
    65     65   those file all begin with "test".  And src/ contains the "shell.c" file
    66     66   which is the main program for the "sqlite3.exe" command-line shell and
................................................................................
    91     91   of the automatically-generated files, simply run "make target_source".
    92     92   The "target_source" make target will create a subdirectory "tsrc/" and
    93     93   fill it with all the source files needed to build SQLite, both
    94     94   manually-edited files and automatically-generated files.
    95     95   
    96     96   The SQLite interface is defined by the **sqlite3.h** header file, which is
    97     97   generated from src/sqlite.h.in, ./manifest.uuid, and ./VERSION.  The
    98         -Tcl script at tool/mksqlite3h.tcl does the conversion.  The manifest.uuid
    99         -file contains the SHA1 hash of the particular check-in and is used to generate
   100         -the SQLITE_SOURCE_ID macro.  The VERSION file contains the current SQLite
   101         -version number.  The sqlite3.h header is really just a copy of src/sqlite.h.in
   102         -with the source-id and version number inserted at just the right spots.
   103         -Note that comment text in the sqlite3.h file is used to generate much of
   104         -the SQLite API documentation.  The Tcl scripts used to generate that
   105         -documentation are in a separate source repository.
           98  +[Tcl script](http://www.tcl.tk) at tool/mksqlite3h.tcl does the conversion.
           99  +The manifest.uuid file contains the SHA1 hash of the particular check-in
          100  +and is used to generate the SQLITE\_SOURCE\_ID macro.  The VERSION file
          101  +contains the current SQLite version number.  The sqlite3.h header is really
          102  +just a copy of src/sqlite.h.in with the source-id and version number inserted
          103  +at just the right spots. Note that comment text in the sqlite3.h file is
          104  +used to generate much of the SQLite API documentation.  The Tcl scripts
          105  +used to generate that documentation are in a separate source repository.
   106    106   
   107    107   The SQL language parser is **parse.c** which is generate from a grammar in
   108    108   the src/parse.y file.  The conversion of "parse.y" into "parse.c" is done
   109    109   by the [lemon](./doc/lemon.html) LALR(1) parser generator.  The source code
   110    110   for lemon is at tool/lemon.c.  Lemon uses a
   111    111   template for generating its parser.  A generic template is in tool/lempar.c,
   112    112   but SQLite uses a slightly modified template found in src/lempar.c.

Changes to ext/misc/fuzzer.c.

   338    338     }else{
   339    339   
   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         -      pRule->zFrom = &pRule->zTo[nTo+1];
          345  +      pRule->zFrom = pRule->zTo;
          346  +      pRule->zFrom += nTo + 1;
   346    347         pRule->nFrom = nFrom;
   347    348         memcpy(pRule->zFrom, zFrom, nFrom+1);
   348    349         memcpy(pRule->zTo, zTo, nTo+1);
   349    350         pRule->nTo = nTo;
   350    351         pRule->rCost = nCost;
   351    352         pRule->iRuleset = (int)iRuleset;
   352    353       }

Changes to ext/rtree/rtree.c.

  1179   1179       pCur->aPoint = pNew;
  1180   1180       pCur->nPointAlloc = nNew;
  1181   1181     }
  1182   1182     i = pCur->nPoint++;
  1183   1183     pNew = pCur->aPoint + i;
  1184   1184     pNew->rScore = rScore;
  1185   1185     pNew->iLevel = iLevel;
  1186         -  assert( iLevel>=0 && iLevel<=RTREE_MAX_DEPTH );
         1186  +  assert( iLevel<=RTREE_MAX_DEPTH );
  1187   1187     while( i>0 ){
  1188   1188       RtreeSearchPoint *pParent;
  1189   1189       j = (i-1)/2;
  1190   1190       pParent = pCur->aPoint + j;
  1191   1191       if( rtreeSearchPointCompare(pNew, pParent)>=0 ) break;
  1192   1192       rtreeSearchPointSwap(pCur, j, i);
  1193   1193       i = j;

Changes to mptest/mptest.c.

  1391   1391       }
  1392   1392       sqlite3_finalize(pStmt);
  1393   1393     }
  1394   1394     sqlite3_close(g.db);  
  1395   1395     maybeClose(g.pLog);
  1396   1396     maybeClose(g.pErrLog);
  1397   1397     if( iClient==0 ){
  1398         -    printf("Summary: %d errors in %d tests\n", g.nError, g.nTest);
         1398  +    printf("Summary: %d errors out of %d tests\n", g.nError, g.nTest);
  1399   1399     }
  1400   1400     return g.nError>0;
  1401   1401   }

Changes to src/analyze.c.

   444    444       u8 *pSpace;                     /* Allocated space not yet assigned */
   445    445       int i;                          /* Used to iterate through p->aSample[] */
   446    446   
   447    447       p->iGet = -1;
   448    448       p->mxSample = mxSample;
   449    449       p->nPSample = (tRowcnt)(sqlite3_value_int64(argv[2])/(mxSample/3+1) + 1);
   450    450       p->current.anLt = &p->current.anEq[nColUp];
   451         -    p->iPrn = nCol*0x689e962d ^ sqlite3_value_int(argv[2])*0xd0944565;
          451  +    p->iPrn = 0x689e962d*(u32)nCol ^ 0xd0944565*(u32)sqlite3_value_int(argv[2]);
   452    452     
   453    453       /* Set up the Stat4Accum.a[] and aBest[] arrays */
   454    454       p->a = (struct Stat4Sample*)&p->current.anLt[nColUp];
   455    455       p->aBest = &p->a[mxSample];
   456    456       pSpace = (u8*)(&p->a[mxSample+nCol]);
   457    457       for(i=0; i<(mxSample+nCol); i++){
   458    458         p->a[i].anEq = (tRowcnt *)pSpace; pSpace += (sizeof(tRowcnt) * nColUp);

Changes to src/btree.c.

  3573   3573       assert( pBt->inTransaction==TRANS_WRITE );
  3574   3574       assert( pBt->nTransaction>0 );
  3575   3575       rc = sqlite3PagerCommitPhaseTwo(pBt->pPager);
  3576   3576       if( rc!=SQLITE_OK && bCleanup==0 ){
  3577   3577         sqlite3BtreeLeave(p);
  3578   3578         return rc;
  3579   3579       }
         3580  +    p->iDataVersion--;  /* Compensate for pPager->iDataVersion++; */
  3580   3581       pBt->inTransaction = TRANS_READ;
  3581   3582       btreeClearHasContent(pBt);
  3582   3583     }
  3583   3584   
  3584   3585     btreeEndTransaction(p);
  3585   3586     sqlite3BtreeLeave(p);
  3586   3587     return SQLITE_OK;
................................................................................
  6887   6888           memcpy(apCell[nCell], &pOld->aData[8], 4);
  6888   6889         }else{
  6889   6890           assert( leafCorrection==4 );
  6890   6891           if( szCell[nCell]<4 ){
  6891   6892             /* Do not allow any cells smaller than 4 bytes. If a smaller cell
  6892   6893             ** does exist, pad it with 0x00 bytes. */
  6893   6894             assert( szCell[nCell]==3 );
  6894         -          assert( apCell[nCell]==&pTemp[iSpace1-3] );
  6895         -          pTemp[iSpace1++] = 0x00;
         6895  +          assert( apCell[nCell]==&aSpace1[iSpace1-3] );
         6896  +          aSpace1[iSpace1++] = 0x00;
  6896   6897             szCell[nCell] = 4;
  6897   6898           }
  6898   6899         }
  6899   6900         nCell++;
  6900   6901       }
  6901   6902     }
  6902   6903   
................................................................................
  8200   8201   ** is the number of free pages currently in the database.  Meta[1]
  8201   8202   ** through meta[15] are available for use by higher layers.  Meta[0]
  8202   8203   ** is read-only, the others are read/write.
  8203   8204   ** 
  8204   8205   ** The schema layer numbers meta values differently.  At the schema
  8205   8206   ** layer (and the SetCookie and ReadCookie opcodes) the number of
  8206   8207   ** free pages is not visible.  So Cookie[0] is the same as Meta[1].
         8208  +**
         8209  +** This routine treats Meta[BTREE_DATA_VERSION] as a special case.  Instead
         8210  +** of reading the value out of the header, it instead loads the "DataVersion"
         8211  +** from the pager.  The BTREE_DATA_VERSION value is not actually stored in the
         8212  +** database file.  It is a number computed by the pager.  But its access
         8213  +** pattern is the same as header meta values, and so it is convenient to
         8214  +** read it from this routine.
  8207   8215   */
  8208   8216   void sqlite3BtreeGetMeta(Btree *p, int idx, u32 *pMeta){
  8209   8217     BtShared *pBt = p->pBt;
  8210   8218   
  8211   8219     sqlite3BtreeEnter(p);
  8212   8220     assert( p->inTrans>TRANS_NONE );
  8213   8221     assert( SQLITE_OK==querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK) );
  8214   8222     assert( pBt->pPage1 );
  8215   8223     assert( idx>=0 && idx<=15 );
  8216   8224   
  8217         -  *pMeta = get4byte(&pBt->pPage1->aData[36 + idx*4]);
         8225  +  if( idx==BTREE_DATA_VERSION ){
         8226  +    *pMeta = sqlite3PagerDataVersion(pBt->pPager) + p->iDataVersion;
         8227  +  }else{
         8228  +    *pMeta = get4byte(&pBt->pPage1->aData[36 + idx*4]);
         8229  +  }
  8218   8230   
  8219   8231     /* If auto-vacuum is disabled in this build and this is an auto-vacuum
  8220   8232     ** database, mark the database as read-only.  */
  8221   8233   #ifdef SQLITE_OMIT_AUTOVACUUM
  8222   8234     if( idx==BTREE_LARGEST_ROOT_PAGE && *pMeta>0 ){
  8223   8235       pBt->btsFlags |= BTS_READ_ONLY;
  8224   8236     }
................................................................................
  9157   9169   int sqlite3BtreeIsReadonly(Btree *p){
  9158   9170     return (p->pBt->btsFlags & BTS_READ_ONLY)!=0;
  9159   9171   }
  9160   9172   
  9161   9173   /*
  9162   9174   ** Return the size of the header added to each page by this module.
  9163   9175   */
  9164         -int sqlite3HeaderSizeBtree(void){ return sizeof(MemPage); }
         9176  +int sqlite3HeaderSizeBtree(void){ return ROUND8(sizeof(MemPage)); }

Changes to src/btree.h.

    15     15   */
    16     16   #ifndef _BTREE_H_
    17     17   #define _BTREE_H_
    18     18   
    19     19   /* TODO: This definition is just included so other modules compile. It
    20     20   ** needs to be revisited.
    21     21   */
    22         -#define SQLITE_N_BTREE_META 10
           22  +#define SQLITE_N_BTREE_META 16
    23     23   
    24     24   /*
    25     25   ** If defined as non-zero, auto-vacuum is enabled by default. Otherwise
    26     26   ** it must be turned on for each database using "PRAGMA auto_vacuum = 1".
    27     27   */
    28     28   #ifndef SQLITE_DEFAULT_AUTOVACUUM
    29     29     #define SQLITE_DEFAULT_AUTOVACUUM 0
................................................................................
   130    130   ** SQLite database header may be found using the following formula:
   131    131   **
   132    132   **   offset = 36 + (idx * 4)
   133    133   **
   134    134   ** For example, the free-page-count field is located at byte offset 36 of
   135    135   ** the database file header. The incr-vacuum-flag field is located at
   136    136   ** byte offset 64 (== 36+4*7).
          137  +**
          138  +** The BTREE_DATA_VERSION value is not really a value stored in the header.
          139  +** It is a read-only number computed by the pager.  But we merge it with
          140  +** the header value access routines since its access pattern is the same.
          141  +** Call it a "virtual meta value".
   137    142   */
   138    143   #define BTREE_FREE_PAGE_COUNT     0
   139    144   #define BTREE_SCHEMA_VERSION      1
   140    145   #define BTREE_FILE_FORMAT         2
   141    146   #define BTREE_DEFAULT_CACHE_SIZE  3
   142    147   #define BTREE_LARGEST_ROOT_PAGE   4
   143    148   #define BTREE_TEXT_ENCODING       5
   144    149   #define BTREE_USER_VERSION        6
   145    150   #define BTREE_INCR_VACUUM         7
   146    151   #define BTREE_APPLICATION_ID      8
          152  +#define BTREE_DATA_VERSION        15  /* A virtual meta-value */
   147    153   
   148    154   /*
   149    155   ** Values that may be OR'd together to form the second argument of an
   150    156   ** sqlite3BtreeCursorHints() call.
   151    157   */
   152    158   #define BTREE_BULKLOAD 0x00000001
   153    159   

Changes to src/btreeInt.h.

   347    347     sqlite3 *db;       /* The database connection holding this btree */
   348    348     BtShared *pBt;     /* Sharable content of this btree */
   349    349     u8 inTrans;        /* TRANS_NONE, TRANS_READ or TRANS_WRITE */
   350    350     u8 sharable;       /* True if we can share pBt with another db */
   351    351     u8 locked;         /* True if db currently has pBt locked */
   352    352     int wantToLock;    /* Number of nested calls to sqlite3BtreeEnter() */
   353    353     int nBackup;       /* Number of backup operations reading this btree */
          354  +  u32 iDataVersion;  /* Combines with pBt->pPager->iDataVersion */
   354    355     Btree *pNext;      /* List of other sharable Btrees from the same db */
   355    356     Btree *pPrev;      /* Back pointer of the same list */
   356    357   #ifndef SQLITE_OMIT_SHARED_CACHE
   357    358     BtLock lock;       /* Object used to lock page 1 */
   358    359   #endif
   359    360   };
   360    361   

Changes to src/build.c.

  1709   1709       assert( pParse->pNewTable==pTab );
  1710   1710       pPk = sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0);
  1711   1711       if( pPk==0 ) return;
  1712   1712       pPk->idxType = SQLITE_IDXTYPE_PRIMARYKEY;
  1713   1713       pTab->iPKey = -1;
  1714   1714     }else{
  1715   1715       pPk = sqlite3PrimaryKeyIndex(pTab);
         1716  +    /*
         1717  +    ** Remove all redundant columns from the PRIMARY KEY.  For example, change
         1718  +    ** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)".  Later
         1719  +    ** code assumes the PRIMARY KEY contains no repeated columns.
         1720  +    */
         1721  +    for(i=j=1; i<pPk->nKeyCol; i++){
         1722  +      if( hasColumn(pPk->aiColumn, j, pPk->aiColumn[i]) ){
         1723  +        pPk->nColumn--;
         1724  +      }else{
         1725  +        pPk->aiColumn[j++] = pPk->aiColumn[i];
         1726  +      }
         1727  +    }
         1728  +    pPk->nKeyCol = j;
  1716   1729     }
  1717   1730     pPk->isCovering = 1;
  1718   1731     assert( pPk!=0 );
  1719   1732     nPk = pPk->nKeyCol;
  1720   1733   
  1721   1734     /* Make sure every column of the PRIMARY KEY is NOT NULL */
  1722   1735     for(i=0; i<nPk; i++){

Changes to src/complete.c.

   101    101   ** to recognize the end of a trigger can be omitted.  All we have to do
   102    102   ** is look for a semicolon that is not part of an string or comment.
   103    103   */
   104    104   int sqlite3_complete(const char *zSql){
   105    105     u8 state = 0;   /* Current state, using numbers defined in header comment */
   106    106     u8 token;       /* Value of the next token */
   107    107   
   108         -#ifdef SQLITE_ENABLE_API_ARMOR
   109         -  if( zSql==0 ){
   110         -    (void)SQLITE_MISUSE_BKPT;
   111         -    return 0;
   112         -  }
   113         -#endif
   114         -
   115    108   #ifndef SQLITE_OMIT_TRIGGER
   116    109     /* A complex statement machine used to detect the end of a CREATE TRIGGER
   117    110     ** statement.  This is the normal case.
   118    111     */
   119    112     static const u8 trans[8][8] = {
   120    113                        /* Token:                                                */
   121    114        /* State:       **  SEMI  WS  OTHER  EXPLAIN  CREATE  TEMP  TRIGGER  END */
................................................................................
   136    129                        /* Token:           */
   137    130        /* State:       **  SEMI  WS  OTHER */
   138    131        /* 0 INVALID: */ {    1,  0,     2, },
   139    132        /* 1   START: */ {    1,  1,     2, },
   140    133        /* 2  NORMAL: */ {    1,  2,     2, },
   141    134     };
   142    135   #endif /* SQLITE_OMIT_TRIGGER */
          136  +
          137  +#ifdef SQLITE_ENABLE_API_ARMOR
          138  +  if( zSql==0 ){
          139  +    (void)SQLITE_MISUSE_BKPT;
          140  +    return 0;
          141  +  }
          142  +#endif
   143    143   
   144    144     while( *zSql ){
   145    145       switch( *zSql ){
   146    146         case ';': {  /* A semicolon */
   147    147           token = tkSEMI;
   148    148           break;
   149    149         }

Changes to src/fkey.c.

   433    433       ** incrementing a counter. This is necessary as the VM code is being
   434    434       ** generated for will not open a statement transaction.  */
   435    435       assert( nIncr==1 );
   436    436       sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY,
   437    437           OE_Abort, 0, P4_STATIC, P5_ConstraintFK);
   438    438     }else{
   439    439       if( nIncr>0 && pFKey->isDeferred==0 ){
   440         -      sqlite3ParseToplevel(pParse)->mayAbort = 1;
          440  +      sqlite3MayAbort(pParse);
   441    441       }
   442    442       sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
   443    443     }
   444    444   
   445    445     sqlite3VdbeResolveLabel(v, iOk);
   446    446     sqlite3VdbeAddOp1(v, OP_Close, iCur);
   447    447   }
................................................................................
   504    504   
   505    505   /*
   506    506   ** This function is called to generate code executed when a row is deleted
   507    507   ** from the parent table of foreign key constraint pFKey and, if pFKey is 
   508    508   ** deferred, when a row is inserted into the same table. When generating
   509    509   ** code for an SQL UPDATE operation, this function may be called twice -
   510    510   ** once to "delete" the old row and once to "insert" the new row.
          511  +**
          512  +** Parameter nIncr is passed -1 when inserting a row (as this may decrease
          513  +** the number of FK violations in the db) or +1 when deleting one (as this
          514  +** may increase the number of FK constraint problems).
   511    515   **
   512    516   ** The code generated by this function scans through the rows in the child
   513    517   ** table that correspond to the parent table row being deleted or inserted.
   514    518   ** For each child row found, one of the following actions is taken:
   515    519   **
   516    520   **   Operation | FK type   | Action taken
   517    521   **   --------------------------------------------------------------------------
................................................................................
   621    625     /* Resolve the references in the WHERE clause. */
   622    626     memset(&sNameContext, 0, sizeof(NameContext));
   623    627     sNameContext.pSrcList = pSrc;
   624    628     sNameContext.pParse = pParse;
   625    629     sqlite3ResolveExprNames(&sNameContext, pWhere);
   626    630   
   627    631     /* Create VDBE to loop through the entries in pSrc that match the WHERE
   628         -  ** clause. If the constraint is not deferred, throw an exception for
   629         -  ** each row found. Otherwise, for deferred constraints, increment the
   630         -  ** deferred constraint counter by nIncr for each row selected.  */
          632  +  ** clause. For each row found, increment either the deferred or immediate
          633  +  ** foreign key constraint counter. */
   631    634     pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0);
   632         -  if( nIncr>0 && pFKey->isDeferred==0 ){
   633         -    sqlite3ParseToplevel(pParse)->mayAbort = 1;
   634         -  }
   635    635     sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr);
   636    636     if( pWInfo ){
   637    637       sqlite3WhereEnd(pWInfo);
   638    638     }
   639    639   
   640    640     /* Clean up the WHERE clause constructed above. */
   641    641     sqlite3ExprDelete(db, pWhere);
................................................................................
   805    805             return 1;
   806    806           }
   807    807         }
   808    808       }
   809    809     }
   810    810     return 0;
   811    811   }
          812  +
          813  +/*
          814  +** Return true if the parser passed as the first argument is being
          815  +** used to code a trigger that is really a "SET NULL" action belonging
          816  +** to trigger pFKey.
          817  +*/
          818  +static int isSetNullAction(Parse *pParse, FKey *pFKey){
          819  +  Parse *pTop = sqlite3ParseToplevel(pParse);
          820  +  if( pTop->pTriggerPrg ){
          821  +    Trigger *p = pTop->pTriggerPrg->pTrigger;
          822  +    if( (p==pFKey->apTrigger[0] && pFKey->aAction[0]==OE_SetNull)
          823  +     || (p==pFKey->apTrigger[1] && pFKey->aAction[1]==OE_SetNull)
          824  +    ){
          825  +      return 1;
          826  +    }
          827  +  }
          828  +  return 0;
          829  +}
   812    830   
   813    831   /*
   814    832   ** This function is called when inserting, deleting or updating a row of
   815    833   ** table pTab to generate VDBE code to perform foreign key constraint 
   816    834   ** processing for the operation.
   817    835   **
   818    836   ** For a DELETE operation, parameter regOld is passed the index of the
................................................................................
   858    876     for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){
   859    877       Table *pTo;                   /* Parent table of foreign key pFKey */
   860    878       Index *pIdx = 0;              /* Index on key columns in pTo */
   861    879       int *aiFree = 0;
   862    880       int *aiCol;
   863    881       int iCol;
   864    882       int i;
   865         -    int isIgnore = 0;
          883  +    int bIgnore = 0;
   866    884   
   867    885       if( aChange 
   868    886        && sqlite3_stricmp(pTab->zName, pFKey->zTo)!=0
   869    887        && fkChildIsModified(pTab, pFKey, aChange, bChngRowid)==0 
   870    888       ){
   871    889         continue;
   872    890       }
................................................................................
   917    935         /* Request permission to read the parent key columns. If the 
   918    936         ** authorization callback returns SQLITE_IGNORE, behave as if any
   919    937         ** values read from the parent table are NULL. */
   920    938         if( db->xAuth ){
   921    939           int rcauth;
   922    940           char *zCol = pTo->aCol[pIdx ? pIdx->aiColumn[i] : pTo->iPKey].zName;
   923    941           rcauth = sqlite3AuthReadCol(pParse, pTo->zName, zCol, iDb);
   924         -        isIgnore = (rcauth==SQLITE_IGNORE);
          942  +        bIgnore = (rcauth==SQLITE_IGNORE);
   925    943         }
   926    944   #endif
   927    945       }
   928    946   
   929    947       /* Take a shared-cache advisory read-lock on the parent table. Allocate 
   930    948       ** a cursor to use to search the unique index on the parent key columns 
   931    949       ** in the parent table.  */
................................................................................
   932    950       sqlite3TableLock(pParse, iDb, pTo->tnum, 0, pTo->zName);
   933    951       pParse->nTab++;
   934    952   
   935    953       if( regOld!=0 ){
   936    954         /* A row is being removed from the child table. Search for the parent.
   937    955         ** If the parent does not exist, removing the child row resolves an 
   938    956         ** outstanding foreign key constraint violation. */
   939         -      fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regOld, -1,isIgnore);
          957  +      fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regOld, -1, bIgnore);
   940    958       }
   941         -    if( regNew!=0 ){
          959  +    if( regNew!=0 && !isSetNullAction(pParse, pFKey) ){
   942    960         /* A row is being added to the child table. If a parent row cannot
   943         -      ** be found, adding the child row has violated the FK constraint. */ 
   944         -      fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regNew, +1,isIgnore);
          961  +      ** be found, adding the child row has violated the FK constraint. 
          962  +      **
          963  +      ** If this operation is being performed as part of a trigger program
          964  +      ** that is actually a "SET NULL" action belonging to this very 
          965  +      ** foreign key, then omit this scan altogether. As all child key
          966  +      ** values are guaranteed to be NULL, it is not possible for adding
          967  +      ** this row to cause an FK violation.  */
          968  +      fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regNew, +1, bIgnore);
   945    969       }
   946    970   
   947    971       sqlite3DbFree(db, aiFree);
   948    972     }
   949    973   
   950    974     /* Loop through all the foreign key constraints that refer to this table.
   951    975     ** (the "child" constraints) */
................................................................................
   958    982         continue;
   959    983       }
   960    984   
   961    985       if( !pFKey->isDeferred && !(db->flags & SQLITE_DeferFKs) 
   962    986        && !pParse->pToplevel && !pParse->isMultiWrite 
   963    987       ){
   964    988         assert( regOld==0 && regNew!=0 );
   965         -      /* Inserting a single row into a parent table cannot cause an immediate
   966         -      ** foreign key violation. So do nothing in this case.  */
          989  +      /* Inserting a single row into a parent table cannot cause (or fix)
          990  +      ** an immediate foreign key violation. So do nothing in this case.  */
   967    991         continue;
   968    992       }
   969    993   
   970    994       if( sqlite3FkLocateIndex(pParse, pTab, pFKey, &pIdx, &aiCol) ){
   971    995         if( !isIgnoreErrors || db->mallocFailed ) return;
   972    996         continue;
   973    997       }
................................................................................
   983   1007         pItem->pTab->nRef++;
   984   1008         pItem->iCursor = pParse->nTab++;
   985   1009     
   986   1010         if( regNew!=0 ){
   987   1011           fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regNew, -1);
   988   1012         }
   989   1013         if( regOld!=0 ){
   990         -        /* If there is a RESTRICT action configured for the current operation
   991         -        ** on the parent table of this FK, then throw an exception 
   992         -        ** immediately if the FK constraint is violated, even if this is a
   993         -        ** deferred trigger. That's what RESTRICT means. To defer checking
   994         -        ** the constraint, the FK should specify NO ACTION (represented
   995         -        ** using OE_None). NO ACTION is the default.  */
         1014  +        int eAction = pFKey->aAction[aChange!=0];
   996   1015           fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regOld, 1);
         1016  +        /* If this is a deferred FK constraint, or a CASCADE or SET NULL
         1017  +        ** action applies, then any foreign key violations caused by
         1018  +        ** removing the parent key will be rectified by the action trigger.
         1019  +        ** So do not set the "may-abort" flag in this case.
         1020  +        **
         1021  +        ** Note 1: If the FK is declared "ON UPDATE CASCADE", then the
         1022  +        ** may-abort flag will eventually be set on this statement anyway
         1023  +        ** (when this function is called as part of processing the UPDATE
         1024  +        ** within the action trigger).
         1025  +        **
         1026  +        ** Note 2: At first glance it may seem like SQLite could simply omit
         1027  +        ** all OP_FkCounter related scans when either CASCADE or SET NULL
         1028  +        ** applies. The trouble starts if the CASCADE or SET NULL action 
         1029  +        ** trigger causes other triggers or action rules attached to the 
         1030  +        ** child table to fire. In these cases the fk constraint counters
         1031  +        ** might be set incorrectly if any OP_FkCounter related scans are 
         1032  +        ** omitted.  */
         1033  +        if( !pFKey->isDeferred && eAction!=OE_Cascade && eAction!=OE_SetNull ){
         1034  +          sqlite3MayAbort(pParse);
         1035  +        }
   997   1036         }
   998   1037         pItem->zName = 0;
   999   1038         sqlite3SrcListDelete(db, pSrc);
  1000   1039       }
  1001   1040       sqlite3DbFree(db, aiCol);
  1002   1041     }
  1003   1042   }

Changes to src/global.c.

   148    148   ** SQLITE_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if
   149    149   ** that compile-time option is omitted.
   150    150   */
   151    151   #ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN
   152    152   # define SQLITE_ALLOW_COVERING_INDEX_SCAN 1
   153    153   #endif
   154    154   
          155  +/* The minimum PMA size is set to this value multiplied by the database
          156  +** page size in bytes.
          157  +*/
          158  +#ifndef SQLITE_SORTER_PMASZ
          159  +# define SQLITE_SORTER_PMASZ 250
          160  +#endif
          161  +
   155    162   /*
   156    163   ** The following singleton contains the global configuration for
   157    164   ** the SQLite library.
   158    165   */
   159    166   SQLITE_WSD struct Sqlite3Config sqlite3Config = {
   160    167      SQLITE_DEFAULT_MEMSTATUS,  /* bMemstat */
   161    168      1,                         /* bCoreMutex */
................................................................................
   178    185      0,                         /* szScratch */
   179    186      0,                         /* nScratch */
   180    187      (void*)0,                  /* pPage */
   181    188      0,                         /* szPage */
   182    189      0,                         /* nPage */
   183    190      0,                         /* mxParserStack */
   184    191      0,                         /* sharedCacheEnabled */
          192  +   SQLITE_SORTER_PMASZ,       /* szPma */
   185    193      /* All the rest should always be initialized to zero */
   186    194      0,                         /* isInit */
   187    195      0,                         /* inProgress */
   188    196      0,                         /* isMutexInit */
   189    197      0,                         /* isMallocInit */
   190    198      0,                         /* isPCacheInit */
   191    199      0,                         /* nRefInitMutex */

Changes to src/main.c.

    61     61   #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
    62     62   /*
    63     63   ** If the following function pointer is not NULL and if
    64     64   ** SQLITE_ENABLE_IOTRACE is enabled, then messages describing
    65     65   ** I/O active are written using this function.  These messages
    66     66   ** are intended for debugging activity only.
    67     67   */
    68         -void (*sqlite3IoTrace)(const char*, ...) = 0;
           68  +/* not-private */ void (*sqlite3IoTrace)(const char*, ...) = 0;
    69     69   #endif
    70     70   
    71     71   /*
    72     72   ** If the following global variable points to a string which is the
    73     73   ** name of a directory, then that directory will be used to store
    74     74   ** temporary files.
    75     75   **
................................................................................
   270    270   ** there are outstanding database connections or memory allocations or
   271    271   ** while any part of SQLite is otherwise in use in any thread.  This
   272    272   ** routine is not threadsafe.  But it is safe to invoke this routine
   273    273   ** on when SQLite is already shut down.  If SQLite is already shut down
   274    274   ** when this routine is invoked, then this routine is a harmless no-op.
   275    275   */
   276    276   int sqlite3_shutdown(void){
          277  +#ifdef SQLITE_OMIT_WSD
          278  +  int rc = sqlite3_wsd_init(4096, 24);
          279  +  if( rc!=SQLITE_OK ){
          280  +    return rc;
          281  +  }
          282  +#endif
          283  +
   277    284     if( sqlite3GlobalConfig.isInit ){
   278    285   #ifdef SQLITE_EXTRA_SHUTDOWN
   279    286       void SQLITE_EXTRA_SHUTDOWN(void);
   280    287       SQLITE_EXTRA_SHUTDOWN();
   281    288   #endif
   282    289       sqlite3_os_end();
   283    290       sqlite3_reset_auto_extension();
................................................................................
   585    592         /* EVIDENCE-OF: R-34926-03360 SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit
   586    593         ** unsigned integer value that specifies the maximum size of the created
   587    594         ** heap. */
   588    595         sqlite3GlobalConfig.nHeap = va_arg(ap, int);
   589    596         break;
   590    597       }
   591    598   #endif
          599  +
          600  +    case SQLITE_CONFIG_PMASZ: {
          601  +      sqlite3GlobalConfig.szPma = va_arg(ap, unsigned int);
          602  +      break;
          603  +    }
   592    604   
   593    605       default: {
   594    606         rc = SQLITE_ERROR;
   595    607         break;
   596    608       }
   597    609     }
   598    610     va_end(ap);
................................................................................
  3786   3798   }
  3787   3799   
  3788   3800   /*
  3789   3801   ** Return the filename of the database associated with a database
  3790   3802   ** connection.
  3791   3803   */
  3792   3804   const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){
         3805  +  Btree *pBt;
  3793   3806   #ifdef SQLITE_ENABLE_API_ARMOR
  3794   3807     if( !sqlite3SafetyCheckOk(db) ){
  3795   3808       (void)SQLITE_MISUSE_BKPT;
  3796   3809       return 0;
  3797   3810     }
  3798   3811   #endif
  3799         -  Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
         3812  +  pBt = sqlite3DbNameToBtree(db, zDbName);
  3800   3813     return pBt ? sqlite3BtreeGetFilename(pBt) : 0;
  3801   3814   }
  3802   3815   
  3803   3816   /*
  3804   3817   ** Return 1 if database is read-only or 0 if read/write.  Return -1 if
  3805   3818   ** no such database exists.
  3806   3819   */
  3807   3820   int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){
         3821  +  Btree *pBt;
  3808   3822   #ifdef SQLITE_ENABLE_API_ARMOR
  3809   3823     if( !sqlite3SafetyCheckOk(db) ){
  3810   3824       (void)SQLITE_MISUSE_BKPT;
  3811   3825       return -1;
  3812   3826     }
  3813   3827   #endif
  3814         -  Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
         3828  +  pBt = sqlite3DbNameToBtree(db, zDbName);
  3815   3829     return pBt ? sqlite3BtreeIsReadonly(pBt) : -1;
  3816   3830   }
  3817   3831   
  3818   3832   #if (SQLITE_ENABLE_APPLE_SPI>0) && defined(__APPLE__)
  3819   3833   
  3820   3834   #include "sqlite3_private.h"
  3821   3835   

Changes to src/mutex_w32.c.

   205    205   #else
   206    206           InitializeCriticalSection(&p->mutex);
   207    207   #endif
   208    208         }
   209    209         break;
   210    210       }
   211    211       default: {
          212  +#ifdef SQLITE_ENABLE_API_ARMOR
          213  +      if( iType-2<0 || iType-2>=ArraySize(winMutex_staticMutexes) ){
          214  +        (void)SQLITE_MISUSE_BKPT;
          215  +        return 0;
          216  +      }
          217  +#endif
   212    218         assert( iType-2 >= 0 );
   213    219         assert( iType-2 < ArraySize(winMutex_staticMutexes) );
   214    220         assert( winMutex_isInit==1 );
   215    221         p = &winMutex_staticMutexes[iType-2];
   216    222   #ifdef SQLITE_DEBUG
   217    223         p->id = iType;
   218    224   #ifdef SQLITE_WIN32_MUTEX_TRACE_STATIC

Changes to src/os_unix.c.

  4118   4118         ** or an error number on  failure". See the manpage for details. */
  4119   4119         int err;
  4120   4120         do{
  4121   4121           err = osFallocate(pFile->h, buf.st_size, nSize-buf.st_size);
  4122   4122         }while( err==EINTR );
  4123   4123         if( err ) return SQLITE_IOERR_WRITE;
  4124   4124   #else
  4125         -      /* If the OS does not have posix_fallocate(), fake it. First use
  4126         -      ** ftruncate() to set the file size, then write a single byte to
  4127         -      ** the last byte in each block within the extended region. This
  4128         -      ** is the same technique used by glibc to implement posix_fallocate()
  4129         -      ** on systems that do not have a real fallocate() system call.
         4125  +      /* If the OS does not have posix_fallocate(), fake it. Write a 
         4126  +      ** single byte to the last byte in each block that falls entirely
         4127  +      ** within the extended region. Then, if required, a single byte
         4128  +      ** at offset (nSize-1), to set the size of the file correctly.
         4129  +      ** This is a similar technique to that used by glibc on systems
         4130  +      ** that do not have a real fallocate() call.
  4130   4131         */
  4131   4132         int nBlk = buf.st_blksize;  /* File-system block size */
  4132   4133         i64 iWrite;                 /* Next offset to write to */
  4133   4134   
  4134   4135         if( robust_ftruncate(pFile->h, nSize) ){
  4135   4136           storeLastErrno(pFile, errno);
  4136   4137           return unixLogError(SQLITE_IOERR_TRUNCATE, "ftruncate", pFile->zPath);
  4137   4138         }
  4138   4139         iWrite = ((buf.st_size + 2*nBlk - 1)/nBlk)*nBlk-1;
  4139         -      while( iWrite<nSize ){
         4140  +      assert( iWrite>=buf.st_size );
         4141  +      assert( (iWrite/nBlk)==((buf.st_size+nBlk-1)/nBlk) );
         4142  +      assert( ((iWrite+1)%nBlk)==0 );
         4143  +      for(/*no-op*/; iWrite<nSize; iWrite+=nBlk ){
  4140   4144           int nWrite = seekAndWrite(pFile, iWrite, "", 1);
  4141   4145           if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
  4142         -        iWrite += nBlk;
         4146  +      }
         4147  +      if( nSize%nBlk ){
         4148  +        int nWrite = seekAndWrite(pFile, nSize-1, "", 1);
         4149  +        if( nWrite!=1 ) return SQLITE_IOERR_WRITE;
  4143   4150         }
  4144   4151   #endif
  4145   4152       }
  4146   4153     }
  4147   4154   
  4148   4155   #if SQLITE_MAX_MMAP_SIZE>0
  4149   4156     if( pFile->mmapSizeMax>0 && nByte>pFile->mmapSize ){

Changes to src/os_win.c.

  2475   2475   */
  2476   2476   static int winRead(
  2477   2477     sqlite3_file *id,          /* File to read from */
  2478   2478     void *pBuf,                /* Write content into this buffer */
  2479   2479     int amt,                   /* Number of bytes to read */
  2480   2480     sqlite3_int64 offset       /* Begin reading at this offset */
  2481   2481   ){
  2482         -#if !SQLITE_OS_WINCE
         2482  +#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
  2483   2483     OVERLAPPED overlapped;          /* The offset for ReadFile. */
  2484   2484   #endif
  2485   2485     winFile *pFile = (winFile*)id;  /* file handle */
  2486   2486     DWORD nRead;                    /* Number of bytes actually read from file */
  2487   2487     int nRetry = 0;                 /* Number of retrys */
  2488   2488   
  2489   2489     assert( id!=0 );
................................................................................
  2507   2507         pBuf = &((u8 *)pBuf)[nCopy];
  2508   2508         amt -= nCopy;
  2509   2509         offset += nCopy;
  2510   2510       }
  2511   2511     }
  2512   2512   #endif
  2513   2513   
  2514         -#if SQLITE_OS_WINCE
         2514  +#if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED)
  2515   2515     if( winSeekFile(pFile, offset) ){
  2516   2516       OSTRACE(("READ file=%p, rc=SQLITE_FULL\n", pFile->h));
  2517   2517       return SQLITE_FULL;
  2518   2518     }
  2519   2519     while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){
  2520   2520   #else
  2521   2521     memset(&overlapped, 0, sizeof(OVERLAPPED));
................................................................................
  2579   2579         pBuf = &((u8 *)pBuf)[nCopy];
  2580   2580         amt -= nCopy;
  2581   2581         offset += nCopy;
  2582   2582       }
  2583   2583     }
  2584   2584   #endif
  2585   2585   
  2586         -#if SQLITE_OS_WINCE
         2586  +#if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED)
  2587   2587     rc = winSeekFile(pFile, offset);
  2588   2588     if( rc==0 ){
  2589   2589   #else
  2590   2590     {
  2591   2591   #endif
  2592         -#if !SQLITE_OS_WINCE
         2592  +#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
  2593   2593       OVERLAPPED overlapped;        /* The offset for WriteFile. */
  2594   2594   #endif
  2595   2595       u8 *aRem = (u8 *)pBuf;        /* Data yet to be written */
  2596   2596       int nRem = amt;               /* Number of bytes yet to be written */
  2597   2597       DWORD nWrite;                 /* Bytes written by each WriteFile() call */
  2598   2598       DWORD lastErrno = NO_ERROR;   /* Value returned by GetLastError() */
  2599   2599   
  2600         -#if !SQLITE_OS_WINCE
         2600  +#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
  2601   2601       memset(&overlapped, 0, sizeof(OVERLAPPED));
  2602   2602       overlapped.Offset = (LONG)(offset & 0xffffffff);
  2603   2603       overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
  2604   2604   #endif
  2605   2605   
  2606   2606       while( nRem>0 ){
  2607         -#if SQLITE_OS_WINCE
         2607  +#if SQLITE_OS_WINCE || defined(SQLITE_WIN32_NO_OVERLAPPED)
  2608   2608         if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){
  2609   2609   #else
  2610   2610         if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, &overlapped) ){
  2611   2611   #endif
  2612   2612           if( winRetryIoerr(&nRetry, &lastErrno) ) continue;
  2613   2613           break;
  2614   2614         }
  2615   2615         assert( nWrite==0 || nWrite<=(DWORD)nRem );
  2616   2616         if( nWrite==0 || nWrite>(DWORD)nRem ){
  2617   2617           lastErrno = osGetLastError();
  2618   2618           break;
  2619   2619         }
  2620         -#if !SQLITE_OS_WINCE
         2620  +#if !SQLITE_OS_WINCE && !defined(SQLITE_WIN32_NO_OVERLAPPED)
  2621   2621         offset += nWrite;
  2622   2622         overlapped.Offset = (LONG)(offset & 0xffffffff);
  2623   2623         overlapped.OffsetHigh = (LONG)((offset>>32) & 0x7fffffff);
  2624   2624   #endif
  2625   2625         aRem += nWrite;
  2626   2626         nRem -= nWrite;
  2627   2627       }

Changes to src/pager.c.

   642    642     */
   643    643     u8 eState;                  /* Pager state (OPEN, READER, WRITER_LOCKED..) */
   644    644     u8 eLock;                   /* Current lock held on database file */
   645    645     u8 changeCountDone;         /* Set after incrementing the change-counter */
   646    646     u8 setMaster;               /* True if a m-j name has been written to jrnl */
   647    647     u8 doNotSpill;              /* Do not spill the cache when non-zero */
   648    648     u8 subjInMemory;            /* True to use in-memory sub-journals */
          649  +  u8 bUseFetch;               /* True to use xFetch() */
          650  +  u8 hasBeenUsed;             /* True if any content previously read from this pager*/
   649    651     Pgno dbSize;                /* Number of pages in the database */
   650    652     Pgno dbOrigSize;            /* dbSize before the current transaction */
   651    653     Pgno dbFileSize;            /* Number of pages in the database file */
   652    654     Pgno dbHintSize;            /* Value passed to FCNTL_SIZE_HINT call */
   653    655     int errCode;                /* One of several kinds of errors */
   654    656     int nRec;                   /* Pages journalled since last j-header written */
   655    657     u32 cksumInit;              /* Quasi-random value added to every checksum */
................................................................................
   659    661     sqlite3_file *jfd;          /* File descriptor for main journal */
   660    662     sqlite3_file *sjfd;         /* File descriptor for sub-journal */
   661    663     i64 journalOff;             /* Current write offset in the journal file */
   662    664     i64 journalHdr;             /* Byte offset to previous journal header */
   663    665     sqlite3_backup *pBackup;    /* Pointer to list of ongoing backup processes */
   664    666     PagerSavepoint *aSavepoint; /* Array of active savepoints */
   665    667     int nSavepoint;             /* Number of elements in aSavepoint[] */
          668  +  u32 iDataVersion;           /* Changes whenever database content changes */
   666    669     char dbFileVers[16];        /* Changes whenever database file changes */
   667    670   
   668         -  u8 bUseFetch;               /* True to use xFetch() */
   669    671     int nMmapOut;               /* Number of mmap pages currently outstanding */
   670    672     sqlite3_int64 szMmap;       /* Desired maximum mmap size */
   671    673     PgHdr *pMmapFreelist;       /* List of free mmap page headers (pDirty) */
   672    674     /*
   673    675     ** End of the routinely-changing class members
   674    676     ***************************************************************************/
   675    677   
................................................................................
  1677   1679     return rc;
  1678   1680   }
  1679   1681   
  1680   1682   /*
  1681   1683   ** Discard the entire contents of the in-memory page-cache.
  1682   1684   */
  1683   1685   static void pager_reset(Pager *pPager){
         1686  +  pPager->iDataVersion++;
  1684   1687     sqlite3BackupRestart(pPager->pBackup);
  1685   1688     sqlite3PcacheClear(pPager->pPCache);
  1686   1689   }
         1690  +
         1691  +/*
         1692  +** Return the pPager->iDataVersion value
         1693  +*/
         1694  +u32 sqlite3PagerDataVersion(Pager *pPager){
         1695  +  assert( pPager->eState>PAGER_OPEN );
         1696  +  return pPager->iDataVersion;
         1697  +}
  1687   1698   
  1688   1699   /*
  1689   1700   ** Free all structures in the Pager.aSavepoint[] array and set both
  1690   1701   ** Pager.aSavepoint and Pager.nSavepoint to zero. Close the sub-journal
  1691   1702   ** if it is open and the pager is not in exclusive mode.
  1692   1703   */
  1693   1704   static void releaseAllSavepoints(Pager *pPager){
................................................................................
  3895   3906   static int pagerAcquireMapPage(
  3896   3907     Pager *pPager,                  /* Pager object */
  3897   3908     Pgno pgno,                      /* Page number */
  3898   3909     void *pData,                    /* xFetch()'d data for this page */
  3899   3910     PgHdr **ppPage                  /* OUT: Acquired page object */
  3900   3911   ){
  3901   3912     PgHdr *p;                       /* Memory mapped page to return */
  3902         -
         3913  +  
  3903   3914     if( pPager->pMmapFreelist ){
  3904   3915       *ppPage = p = pPager->pMmapFreelist;
  3905   3916       pPager->pMmapFreelist = p->pDirty;
  3906   3917       p->pDirty = 0;
  3907   3918       memset(p->pExtra, 0, pPager->nExtra);
  3908   3919     }else{
  3909   3920       *ppPage = p = (PgHdr *)sqlite3MallocZero(sizeof(PgHdr) + pPager->nExtra);
................................................................................
  5137   5148   
  5138   5149         assert( pPager->eState==PAGER_OPEN );
  5139   5150         assert( (pPager->eLock==SHARED_LOCK)
  5140   5151              || (pPager->exclusiveMode && pPager->eLock>SHARED_LOCK)
  5141   5152         );
  5142   5153       }
  5143   5154   
  5144         -    if( !pPager->tempFile && (
  5145         -        pPager->pBackup 
  5146         -     || sqlite3PcachePagecount(pPager->pPCache)>0 
  5147         -     || USEFETCH(pPager)
  5148         -    )){
  5149         -      /* The shared-lock has just been acquired on the database file
  5150         -      ** and there are already pages in the cache (from a previous
  5151         -      ** read or write transaction).  Check to see if the database
  5152         -      ** has been modified.  If the database has changed, flush the
  5153         -      ** cache.
         5155  +    if( !pPager->tempFile && pPager->hasBeenUsed ){
         5156  +      /* The shared-lock has just been acquired then check to
         5157  +      ** see if the database has been modified.  If the database has changed,
         5158  +      ** flush the cache.  The pPager->hasBeenUsed flag prevents this from
         5159  +      ** occurring on the very first access to a file, in order to save a
         5160  +      ** single unnecessary sqlite3OsRead() call at the start-up.
  5154   5161         **
  5155   5162         ** Database changes is detected by looking at 15 bytes beginning
  5156   5163         ** at offset 24 into the file.  The first 4 of these 16 bytes are
  5157   5164         ** a 32-bit counter that is incremented with each change.  The
  5158   5165         ** other bytes change randomly with each file change when
  5159   5166         ** a codec is in use.
  5160   5167         ** 
................................................................................
  5311   5318     assert( pPager->eState>=PAGER_READER );
  5312   5319     assert( assert_pager_state(pPager) );
  5313   5320     assert( noContent==0 || bMmapOk==0 );
  5314   5321   
  5315   5322     if( pgno==0 ){
  5316   5323       return SQLITE_CORRUPT_BKPT;
  5317   5324     }
         5325  +  pPager->hasBeenUsed = 1;
  5318   5326   
  5319   5327     /* If the pager is in the error state, return an error immediately. 
  5320   5328     ** Otherwise, request the page from the PCache layer. */
  5321   5329     if( pPager->errCode!=SQLITE_OK ){
  5322   5330       rc = pPager->errCode;
  5323   5331     }else{
  5324   5332       if( bMmapOk && pagerUseWal(pPager) ){
................................................................................
  5460   5468   */
  5461   5469   DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno){
  5462   5470     sqlite3_pcache_page *pPage;
  5463   5471     assert( pPager!=0 );
  5464   5472     assert( pgno!=0 );
  5465   5473     assert( pPager->pPCache!=0 );
  5466   5474     pPage = sqlite3PcacheFetch(pPager->pPCache, pgno, 0);
         5475  +  assert( pPage==0 || pPager->hasBeenUsed );
  5467   5476     return sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pPage);
  5468   5477   }
  5469   5478   
  5470   5479   /*
  5471   5480   ** Release a page reference.
  5472   5481   **
  5473   5482   ** If the number of references to the page drop to zero, then the
................................................................................
  6329   6338     ){
  6330   6339       assert( pPager->journalOff==JOURNAL_HDR_SZ(pPager) || !pPager->journalOff );
  6331   6340       pPager->eState = PAGER_READER;
  6332   6341       return SQLITE_OK;
  6333   6342     }
  6334   6343   
  6335   6344     PAGERTRACE(("COMMIT %d\n", PAGERID(pPager)));
         6345  +  pPager->iDataVersion++;
  6336   6346     rc = pager_end_transaction(pPager, pPager->setMaster, 1);
  6337   6347     return pager_error(pPager, rc);
  6338   6348   }
  6339   6349   
  6340   6350   /*
  6341   6351   ** If a write transaction is open, then all changes made within the 
  6342   6352   ** transaction are reverted and the current write-transaction is closed.

Changes to src/pager.h.

   168    168   
   169    169   #ifdef SQLITE_ENABLE_ZIPVFS
   170    170     int sqlite3PagerWalFramesize(Pager *pPager);
   171    171   #endif
   172    172   
   173    173   /* Functions used to query pager state and configuration. */
   174    174   u8 sqlite3PagerIsreadonly(Pager*);
          175  +u32 sqlite3PagerDataVersion(Pager*);
   175    176   int sqlite3PagerRefcount(Pager*);
   176    177   int sqlite3PagerMemUsed(Pager*);
   177    178   const char *sqlite3PagerFilename(Pager*, int);
   178    179   const sqlite3_vfs *sqlite3PagerVfs(Pager*);
   179    180   sqlite3_file *sqlite3PagerFile(Pager*);
   180    181   sqlite3_file *sqlite3PagerWalFile(Pager *pPager);
   181    182   const char *sqlite3PagerJournalname(Pager*);

Changes to src/pcache.c.

   192    192   ** are no outstanding page references when this function is called.
   193    193   */
   194    194   int sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
   195    195     assert( pCache->nRef==0 && pCache->pDirty==0 );
   196    196     if( pCache->szPage ){
   197    197       sqlite3_pcache *pNew;
   198    198       pNew = sqlite3GlobalConfig.pcache2.xCreate(
   199         -                szPage, pCache->szExtra + sizeof(PgHdr), pCache->bPurgeable
          199  +                szPage, pCache->szExtra + ROUND8(sizeof(PgHdr)),
          200  +                pCache->bPurgeable
   200    201       );
   201    202       if( pNew==0 ) return SQLITE_NOMEM;
   202    203       sqlite3GlobalConfig.pcache2.xCachesize(pNew, numberOfCachePages(pCache));
   203    204       if( pCache->pCache ){
   204    205         sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
   205    206       }
   206    207       pCache->pCache = pNew;
................................................................................
   651    652     sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache);
   652    653   }
   653    654   
   654    655   /*
   655    656   ** Return the size of the header added by this middleware layer
   656    657   ** in the page-cache hierarchy.
   657    658   */
   658         -int sqlite3HeaderSizePcache(void){ return sizeof(PgHdr); }
          659  +int sqlite3HeaderSizePcache(void){ return ROUND8(sizeof(PgHdr)); }
   659    660   
   660    661   
   661    662   #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
   662    663   /*
   663    664   ** For all dirty pages currently in the cache, invoke the specified
   664    665   ** callback. This is only used if the SQLITE_CHECK_PAGES macro is
   665    666   ** defined.

Changes to src/pcache1.c.

   292    292     p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);
   293    293     if( !pPg || !p ){
   294    294       pcache1Free(pPg);
   295    295       sqlite3_free(p);
   296    296       pPg = 0;
   297    297     }
   298    298   #else
   299         -  pPg = pcache1Alloc(sizeof(PgHdr1) + pCache->szPage + pCache->szExtra);
          299  +  pPg = pcache1Alloc(ROUND8(sizeof(PgHdr1)) + pCache->szPage + pCache->szExtra);
   300    300     p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
   301    301   #endif
   302    302     pcache1EnterMutex(pCache->pGroup);
   303    303   
   304    304     if( pPg ){
   305    305       p->page.pBuf = pPg;
   306    306       p->page.pExtra = &p[1];
................................................................................
   980    980     };
   981    981     sqlite3_config(SQLITE_CONFIG_PCACHE2, &defaultMethods);
   982    982   }
   983    983   
   984    984   /*
   985    985   ** Return the size of the header on each page of this PCACHE implementation.
   986    986   */
   987         -int sqlite3HeaderSizePcache1(void){ return sizeof(PgHdr1); }
          987  +int sqlite3HeaderSizePcache1(void){ return ROUND8(sizeof(PgHdr1)); }
   988    988   
   989    989   #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
   990    990   /*
   991    991   ** This function is called to free superfluous dynamically allocated memory
   992    992   ** held by the pager system. Memory in use by any SQLite pager allocated
   993    993   ** by the current thread may be sqlite3_free()ed.
   994    994   **

Changes to src/pragma.c.

    67     67   #define PragTyp_ACTIVATE_EXTENSIONS           36
    68     68   #define PragTyp_HEXKEY                        37
    69     69   #define PragTyp_KEY                           38
    70     70   #define PragTyp_REKEY                         39
    71     71   #define PragTyp_LOCK_STATUS                   40
    72     72   #define PragTyp_PARSER_TRACE                  41
    73     73   #define PragFlag_NeedSchema           0x01
           74  +#define PragFlag_ReadOnly             0x02
    74     75   static const struct sPragmaNames {
    75     76     const char *const zName;  /* Name of pragma */
    76     77     u8 ePragTyp;              /* PragTyp_XXX value */
    77     78     u8 mPragFlag;             /* Zero or more PragFlag_XXX values */
    78     79     u32 iArg;                 /* Extra argument */
    79     80   } aPragmaNames[] = {
    80     81   #if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD)
................................................................................
    83     84       /* ePragFlag: */ 0,
    84     85       /* iArg:      */ 0 },
    85     86   #endif
    86     87   #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
    87     88     { /* zName:     */ "application_id",
    88     89       /* ePragTyp:  */ PragTyp_HEADER_VALUE,
    89     90       /* ePragFlag: */ 0,
    90         -    /* iArg:      */ 0 },
           91  +    /* iArg:      */ BTREE_APPLICATION_ID },
    91     92   #endif
    92     93   #if !defined(SQLITE_OMIT_AUTOVACUUM)
    93     94     { /* zName:     */ "auto_vacuum",
    94     95       /* ePragTyp:  */ PragTyp_AUTO_VACUUM,
    95     96       /* ePragFlag: */ PragFlag_NeedSchema,
    96     97       /* iArg:      */ 0 },
    97     98   #endif
................................................................................
   149    150   #endif
   150    151   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
   151    152     { /* zName:     */ "data_store_directory",
   152    153       /* ePragTyp:  */ PragTyp_DATA_STORE_DIRECTORY,
   153    154       /* ePragFlag: */ 0,
   154    155       /* iArg:      */ 0 },
   155    156   #endif
          157  +#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
          158  +  { /* zName:     */ "data_version",
          159  +    /* ePragTyp:  */ PragTyp_HEADER_VALUE,
          160  +    /* ePragFlag: */ PragFlag_ReadOnly,
          161  +    /* iArg:      */ BTREE_DATA_VERSION },
          162  +#endif
   156    163   #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
   157    164     { /* zName:     */ "database_list",
   158    165       /* ePragTyp:  */ PragTyp_DATABASE_LIST,
   159    166       /* ePragFlag: */ PragFlag_NeedSchema,
   160    167       /* iArg:      */ 0 },
   161    168   #endif
   162    169   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
................................................................................
   204    211       /* ePragFlag: */ 0,
   205    212       /* iArg:      */ SQLITE_ForeignKeys },
   206    213   #endif
   207    214   #endif
   208    215   #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
   209    216     { /* zName:     */ "freelist_count",
   210    217       /* ePragTyp:  */ PragTyp_HEADER_VALUE,
   211         -    /* ePragFlag: */ 0,
   212         -    /* iArg:      */ 0 },
          218  +    /* ePragFlag: */ PragFlag_ReadOnly,
          219  +    /* iArg:      */ BTREE_FREE_PAGE_COUNT },
   213    220   #endif
   214    221   #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   215    222     { /* zName:     */ "full_column_names",
   216    223       /* ePragTyp:  */ PragTyp_FLAG,
   217    224       /* ePragFlag: */ 0,
   218    225       /* iArg:      */ SQLITE_FullColNames },
   219    226     { /* zName:     */ "fullfsync",
................................................................................
   357    364       /* ePragFlag: */ 0,
   358    365       /* iArg:      */ SQLITE_ReverseOrder },
   359    366   #endif
   360    367   #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
   361    368     { /* zName:     */ "schema_version",
   362    369       /* ePragTyp:  */ PragTyp_HEADER_VALUE,
   363    370       /* ePragFlag: */ 0,
   364         -    /* iArg:      */ 0 },
          371  +    /* iArg:      */ BTREE_SCHEMA_VERSION },
   365    372   #endif
   366    373   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   367    374     { /* zName:     */ "secure_delete",
   368    375       /* ePragTyp:  */ PragTyp_SECURE_DELETE,
   369    376       /* ePragFlag: */ 0,
   370    377       /* iArg:      */ 0 },
   371    378   #endif
................................................................................
   423    430       /* ePragTyp:  */ PragTyp_THREADS,
   424    431       /* ePragFlag: */ 0,
   425    432       /* iArg:      */ 0 },
   426    433   #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
   427    434     { /* zName:     */ "user_version",
   428    435       /* ePragTyp:  */ PragTyp_HEADER_VALUE,
   429    436       /* ePragFlag: */ 0,
   430         -    /* iArg:      */ 0 },
          437  +    /* iArg:      */ BTREE_USER_VERSION },
   431    438   #endif
   432    439   #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   433    440   #if defined(SQLITE_DEBUG)
   434    441     { /* zName:     */ "vdbe_addoptrace",
   435    442       /* ePragTyp:  */ PragTyp_FLAG,
   436    443       /* ePragFlag: */ 0,
   437    444       /* iArg:      */ SQLITE_VdbeAddopTrace },
................................................................................
   466    473   #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   467    474     { /* zName:     */ "writable_schema",
   468    475       /* ePragTyp:  */ PragTyp_FLAG,
   469    476       /* ePragFlag: */ 0,
   470    477       /* iArg:      */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
   471    478   #endif
   472    479   };
   473         -/* Number of pragmas: 57 on by default, 70 total. */
          480  +/* Number of pragmas: 58 on by default, 71 total. */
   474    481   /* End of the automatically generated pragma table.
   475    482   ***************************************************************************/
   476    483   
   477    484   /*
   478    485   ** Interpret the given string as a safety level.  Return 0 for OFF,
   479    486   ** 1 for ON or NORMAL and 2 for FULL.  Return 1 for an empty or 
   480    487   ** unrecognized string argument.  The FULL option is disallowed
................................................................................
  2138   2145     ** the schema-version is potentially dangerous and may lead to program
  2139   2146     ** crashes or database corruption. Use with caution!
  2140   2147     **
  2141   2148     ** The user-version is not used internally by SQLite. It may be used by
  2142   2149     ** applications for any purpose.
  2143   2150     */
  2144   2151     case PragTyp_HEADER_VALUE: {
  2145         -    int iCookie;   /* Cookie index. 1 for schema-cookie, 6 for user-cookie. */
         2152  +    int iCookie = aPragmaNames[mid].iArg;  /* Which cookie to read or write */
  2146   2153       sqlite3VdbeUsesBtree(v, iDb);
  2147         -    switch( zLeft[0] ){
  2148         -      case 'a': case 'A':
  2149         -        iCookie = BTREE_APPLICATION_ID;
  2150         -        break;
  2151         -      case 'f': case 'F':
  2152         -        iCookie = BTREE_FREE_PAGE_COUNT;
  2153         -        break;
  2154         -      case 's': case 'S':
  2155         -        iCookie = BTREE_SCHEMA_VERSION;
  2156         -        break;
  2157         -      default:
  2158         -        iCookie = BTREE_USER_VERSION;
  2159         -        break;
  2160         -    }
  2161         -
  2162         -    if( zRight && iCookie!=BTREE_FREE_PAGE_COUNT ){
         2154  +    if( zRight && (aPragmaNames[mid].mPragFlag & PragFlag_ReadOnly)==0 ){
  2163   2155         /* Write the specified cookie value */
  2164   2156         static const VdbeOpList setCookie[] = {
  2165   2157           { OP_Transaction,    0,  1,  0},    /* 0 */
  2166   2158           { OP_Integer,        0,  1,  0},    /* 1 */
  2167   2159           { OP_SetCookie,      0,  0,  1},    /* 2 */
  2168   2160         };
  2169   2161         int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie, 0);

Changes to src/sqlite.h.in.

  1566   1566   ** This configuration should not be used if an application-define page
  1567   1567   ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2]
  1568   1568   ** configuration option.
  1569   1569   ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
  1570   1570   ** 8-byte aligned
  1571   1571   ** memory, the size of each page buffer (sz), and the number of pages (N).
  1572   1572   ** The sz argument should be the size of the largest database page
  1573         -** (a power of two between 512 and 32768) plus some extra bytes for each
         1573  +** (a power of two between 512 and 65536) plus some extra bytes for each
  1574   1574   ** page header.  ^The number of extra bytes needed by the page header
  1575   1575   ** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option 
  1576   1576   ** to [sqlite3_config()].
  1577   1577   ** ^It is harmless, apart from the wasted memory,
  1578   1578   ** for the sz parameter to be larger than necessary.  The first
  1579   1579   ** argument should pointer to an 8-byte aligned block of memory that
  1580   1580   ** is at least sz*N bytes of memory, otherwise subsequent behavior is
................................................................................
  1746   1746   ** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
  1747   1747   ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
  1748   1748   ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
  1749   1749   ** is a pointer to an integer and writes into that integer the number of extra
  1750   1750   ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
  1751   1751   ** The amount of extra space required can change depending on the compiler,
  1752   1752   ** target platform, and SQLite version.
         1753  +**
         1754  +** [[SQLITE_CONFIG_PMASZ]]
         1755  +** <dt>SQLITE_CONFIG_PMASZ
         1756  +** <dd>^The SQLITE_CONFIG_PMASZ option takes a single parameter which
         1757  +** is an unsigned integer and sets the "Minimum PMA Size" for the multithreaded
         1758  +** sorter to that integer.  The default minimum PMA Size is set by the
         1759  +** [SQLITE_SORTER_PMASZ] compile-time option.  New threads are launched
         1760  +** to help with sort operations when multithreaded sorting
         1761  +** is enabled (using the [PRAGMA threads] command) and the amount of content
         1762  +** to be sorted exceeds the page size times the minimum of the
         1763  +** [PRAGMA cache_size] setting and this value.
  1753   1764   ** </dl>
  1754   1765   */
  1755   1766   #define SQLITE_CONFIG_SINGLETHREAD  1  /* nil */
  1756   1767   #define SQLITE_CONFIG_MULTITHREAD   2  /* nil */
  1757   1768   #define SQLITE_CONFIG_SERIALIZED    3  /* nil */
  1758   1769   #define SQLITE_CONFIG_MALLOC        4  /* sqlite3_mem_methods* */
  1759   1770   #define SQLITE_CONFIG_GETMALLOC     5  /* sqlite3_mem_methods* */
................................................................................
  1772   1783   #define SQLITE_CONFIG_PCACHE2      18  /* sqlite3_pcache_methods2* */
  1773   1784   #define SQLITE_CONFIG_GETPCACHE2   19  /* sqlite3_pcache_methods2* */
  1774   1785   #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20  /* int */
  1775   1786   #define SQLITE_CONFIG_SQLLOG       21  /* xSqllog, void* */
  1776   1787   #define SQLITE_CONFIG_MMAP_SIZE    22  /* sqlite3_int64, sqlite3_int64 */
  1777   1788   #define SQLITE_CONFIG_WIN32_HEAPSIZE      23  /* int nByte */
  1778   1789   #define SQLITE_CONFIG_PCACHE_HDRSZ        24  /* int *psz */
         1790  +#define SQLITE_CONFIG_PMASZ               25  /* unsigned int szPma */
  1779   1791   
  1780   1792   /*
  1781   1793   ** CAPI3REF: Database Connection Configuration Options
  1782   1794   **
  1783   1795   ** These constants are the available integer configuration options that
  1784   1796   ** can be passed as the second argument to the [sqlite3_db_config()] interface.
  1785   1797   **

Changes to src/sqliteInt.h.

  2845   2845     int szScratch;                    /* Size of each scratch buffer */
  2846   2846     int nScratch;                     /* Number of scratch buffers */
  2847   2847     void *pPage;                      /* Page cache memory */
  2848   2848     int szPage;                       /* Size of each page in pPage[] */
  2849   2849     int nPage;                        /* Number of pages in pPage[] */
  2850   2850     int mxParserStack;                /* maximum depth of the parser stack */
  2851   2851     int sharedCacheEnabled;           /* true if shared-cache mode enabled */
         2852  +  u32 szPma;                        /* Maximum Sorter PMA size */
  2852   2853     /* The above might be initialized to non-zero.  The following need to always
  2853   2854     ** initially be zero, however. */
  2854   2855     int isInit;                       /* True after initialization has finished */
  2855   2856     int inProgress;                   /* True while initialization in progress */
  2856   2857     int isMutexInit;                  /* True after mutexes are initialized */
  2857   2858     int isMallocInit;                 /* True after malloc is initialized */
  2858   2859     int isPCacheInit;                 /* True after malloc is initialized */

Changes to src/table.c.

   123    123     int *pnColumn,              /* Write the number of columns of result here */
   124    124     char **pzErrMsg             /* Write error messages here */
   125    125   ){
   126    126     int rc;
   127    127     TabResult res;
   128    128   
   129    129   #ifdef SQLITE_ENABLE_API_ARMOR
   130         -  if( pazResult==0 ) return SQLITE_MISUSE_BKPT;
          130  +  if( !sqlite3SafetyCheckOk(db) || pazResult==0 ) return SQLITE_MISUSE_BKPT;
   131    131   #endif
   132    132     *pazResult = 0;
   133    133     if( pnColumn ) *pnColumn = 0;
   134    134     if( pnRow ) *pnRow = 0;
   135    135     if( pzErrMsg ) *pzErrMsg = 0;
   136    136     res.zErrMsg = 0;
   137    137     res.nRow = 0;

Changes to src/test1.c.

  3684   3684     rc = sqlite3_prepare_v2(db, zCopy, bytes, &pStmt, objc>=5 ? &zTail : 0);
  3685   3685     free(zCopy);
  3686   3686     zTail = &zSql[(zTail - zCopy)];
  3687   3687   
  3688   3688     assert(rc==SQLITE_OK || pStmt==0);
  3689   3689     Tcl_ResetResult(interp);
  3690   3690     if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
  3691         -  if( zTail && objc>=5 ){
         3691  +  if( rc==SQLITE_OK && zTail && objc>=5 ){
  3692   3692       if( bytes>=0 ){
  3693   3693         bytes = bytes - (int)(zTail-zSql);
  3694   3694       }
  3695   3695       Tcl_ObjSetVar2(interp, objv[4], 0, Tcl_NewStringObj(zTail, bytes), 0);
  3696   3696     }
  3697   3697     if( rc!=SQLITE_OK ){
  3698   3698       assert( pStmt==0 );

Changes to src/test8.c.

   644    644   ** This module uses only sqlite3_index_info.idxStr, not 
   645    645   ** sqlite3_index_info.idxNum. So to test idxNum, when idxStr is set
   646    646   ** in echoBestIndex(), idxNum is set to the corresponding hash value.
   647    647   ** In echoFilter(), code assert()s that the supplied idxNum value is
   648    648   ** indeed the hash of the supplied idxStr.
   649    649   */
   650    650   static int hashString(const char *zString){
   651         -  int val = 0;
          651  +  u32 val = 0;
   652    652     int ii;
   653    653     for(ii=0; zString[ii]; ii++){
   654    654       val = (val << 3) + (int)zString[ii];
   655    655     }
   656         -  return val;
          656  +  return (int)(val&0x7fffffff);
   657    657   }
   658    658   
   659    659   /* 
   660    660   ** Echo virtual table module xFilter method.
   661    661   */
   662    662   static int echoFilter(
   663    663     sqlite3_vtab_cursor *pVtabCursor, 

Changes to src/test_malloc.c.

  1256   1256   
  1257   1257     rc = sqlite3_config(SQLITE_CONFIG_COVERING_INDEX_SCAN, bUseCis);
  1258   1258     Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE);
  1259   1259   
  1260   1260     return TCL_OK;
  1261   1261   }
  1262   1262   
         1263  +/*
         1264  +** Usage:    sqlite3_config_pmasz  INTEGER
         1265  +**
         1266  +** Set the minimum PMA size.
         1267  +*/
         1268  +static int test_config_pmasz(
         1269  +  void * clientData, 
         1270  +  Tcl_Interp *interp,
         1271  +  int objc,
         1272  +  Tcl_Obj *CONST objv[]
         1273  +){
         1274  +  int rc;
         1275  +  int iPmaSz;
         1276  +
         1277  +  if( objc!=2 ){
         1278  +    Tcl_WrongNumArgs(interp, 1, objv, "BOOL");
         1279  +    return TCL_ERROR;
         1280  +  }
         1281  +  if( Tcl_GetIntFromObj(interp, objv[1], &iPmaSz) ){
         1282  +    return TCL_ERROR;
         1283  +  }
         1284  +
         1285  +  rc = sqlite3_config(SQLITE_CONFIG_PMASZ, iPmaSz);
         1286  +  Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE);
         1287  +
         1288  +  return TCL_OK;
         1289  +}
         1290  +
  1263   1291   
  1264   1292   /*
  1265   1293   ** Usage:    sqlite3_dump_memsys3  FILENAME
  1266   1294   **           sqlite3_dump_memsys5  FILENAME
  1267   1295   **
  1268   1296   ** Write a summary of unfreed memsys3 allocations to FILENAME.
  1269   1297   */
................................................................................
  1510   1538        { "sqlite3_config_heap",        test_config_heap              ,0 },
  1511   1539        { "sqlite3_config_heap_size",   test_config_heap_size         ,0 },
  1512   1540        { "sqlite3_config_memstatus",   test_config_memstatus         ,0 },
  1513   1541        { "sqlite3_config_lookaside",   test_config_lookaside         ,0 },
  1514   1542        { "sqlite3_config_error",       test_config_error             ,0 },
  1515   1543        { "sqlite3_config_uri",         test_config_uri               ,0 },
  1516   1544        { "sqlite3_config_cis",         test_config_cis               ,0 },
         1545  +     { "sqlite3_config_pmasz",       test_config_pmasz             ,0 },
  1517   1546        { "sqlite3_db_config_lookaside",test_db_config_lookaside      ,0 },
  1518   1547        { "sqlite3_dump_memsys3",       test_dump_memsys3             ,3 },
  1519   1548        { "sqlite3_dump_memsys5",       test_dump_memsys3             ,5 },
  1520   1549        { "sqlite3_install_memsys3",    test_install_memsys3          ,0 },
  1521   1550        { "sqlite3_memdebug_vfs_oom_test", test_vfs_oom_test          ,0 },
  1522   1551     };
  1523   1552     int i;

Changes to src/tokenize.c.

   387    387     int tokenType;                  /* type of the next token */
   388    388     int lastTokenParsed = -1;       /* type of the previous token */
   389    389     u8 enableLookaside;             /* Saved value of db->lookaside.bEnabled */
   390    390     sqlite3 *db = pParse->db;       /* The database connection */
   391    391     int mxSqlLen;                   /* Max length of an SQL string */
   392    392   
   393    393   
          394  +#ifdef SQLITE_ENABLE_API_ARMOR
          395  +  if( zSql==0 || pzErrMsg==0 ) return SQLITE_MISUSE_BKPT;
          396  +#endif
   394    397     mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
   395    398     if( db->nVdbeActive==0 ){
   396    399       db->u1.isInterrupted = 0;
   397    400     }
   398    401     pParse->rc = SQLITE_OK;
   399    402     pParse->zTail = zSql;
   400    403     i = 0;

Changes to src/vdbeaux.c.

   392    392   ** match, or false otherwise. This function is intended to be used as
   393    393   ** part of an assert statement in the compiler. Similar to:
   394    394   **
   395    395   **   assert( sqlite3VdbeAssertMayAbort(pParse->pVdbe, pParse->mayAbort) );
   396    396   */
   397    397   int sqlite3VdbeAssertMayAbort(Vdbe *v, int mayAbort){
   398    398     int hasAbort = 0;
          399  +  int hasFkCounter = 0;
   399    400     Op *pOp;
   400    401     VdbeOpIter sIter;
   401    402     memset(&sIter, 0, sizeof(sIter));
   402    403     sIter.v = v;
   403    404   
   404    405     while( (pOp = opIterNext(&sIter))!=0 ){
   405    406       int opcode = pOp->opcode;
   406    407       if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename 
   407         -#ifndef SQLITE_OMIT_FOREIGN_KEY
   408         -     || (opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1) 
   409         -#endif
   410    408        || ((opcode==OP_Halt || opcode==OP_HaltIfNull) 
   411    409         && ((pOp->p1&0xff)==SQLITE_CONSTRAINT && pOp->p2==OE_Abort))
   412    410       ){
   413    411         hasAbort = 1;
   414    412         break;
   415    413       }
          414  +#ifndef SQLITE_OMIT_FOREIGN_KEY
          415  +    if( opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1 ){
          416  +      hasFkCounter = 1;
          417  +    }
          418  +#endif
   416    419     }
   417    420     sqlite3DbFree(v->db, sIter.apSub);
   418    421   
   419    422     /* Return true if hasAbort==mayAbort. Or if a malloc failure occurred.
   420    423     ** If malloc failed, then the while() loop above may not have iterated
   421    424     ** through all opcodes and hasAbort may be set incorrectly. Return
   422    425     ** true for this case to prevent the assert() in the callers frame
   423    426     ** from failing.  */
   424         -  return ( v->db->mallocFailed || hasAbort==mayAbort );
          427  +  return ( v->db->mallocFailed || hasAbort==mayAbort || hasFkCounter );
   425    428   }
   426    429   #endif /* SQLITE_DEBUG - the sqlite3AssertMayAbort() function */
   427    430   
   428    431   /*
   429    432   ** Loop through the program looking for P2 values that are negative
   430    433   ** on jump instructions.  Each such value is a label.  Resolve the
   431    434   ** label by setting the P2 value to its correct non-zero value.

Changes to src/vdbesort.c.

   148    148   #endif
   149    149   
   150    150   /*
   151    151   ** Hard-coded maximum amount of data to accumulate in memory before flushing
   152    152   ** to a level 0 PMA. The purpose of this limit is to prevent various integer
   153    153   ** overflows. 512MiB.
   154    154   */
   155         -#define SQLITE_MAX_MXPMASIZE    (1<<29)
          155  +#define SQLITE_MAX_PMASZ    (1<<29)
   156    156   
   157    157   /*
   158    158   ** Private objects used by the sorter
   159    159   */
   160    160   typedef struct MergeEngine MergeEngine;     /* Merge PMAs together */
   161    161   typedef struct PmaReader PmaReader;         /* Incrementally read one PMA */
   162    162   typedef struct PmaWriter PmaWriter;         /* Incrementally write one PMA */
................................................................................
   444    444   /* Return a pointer to the buffer containing the record data for SorterRecord
   445    445   ** object p. Should be used as if:
   446    446   **
   447    447   **   void *SRVAL(SorterRecord *p) { return (void*)&p[1]; }
   448    448   */
   449    449   #define SRVAL(p) ((void*)((SorterRecord*)(p) + 1))
   450    450   
   451         -/* The minimum PMA size is set to this value multiplied by the database
   452         -** page size in bytes.  */
   453         -#ifndef SQLITE_SORTER_PMASZ
   454         -# define SQLITE_SORTER_PMASZ 10
   455         -#endif
   456    451   
   457    452   /* Maximum number of PMAs that a single MergeEngine can merge */
   458    453   #define SORTER_MAX_MERGE_COUNT 16
   459    454   
   460    455   static int vdbeIncrSwap(IncrMerger*);
   461    456   static void vdbeIncrFree(IncrMerger *);
   462    457   
................................................................................
   847    842       pSorter->db = db;
   848    843       for(i=0; i<pSorter->nTask; i++){
   849    844         SortSubtask *pTask = &pSorter->aTask[i];
   850    845         pTask->pSorter = pSorter;
   851    846       }
   852    847   
   853    848       if( !sqlite3TempInMemory(db) ){
   854         -      pSorter->mnPmaSize = SQLITE_SORTER_PMASZ * pgsz;
          849  +      u32 szPma = sqlite3GlobalConfig.szPma;
          850  +      pSorter->mnPmaSize = szPma * pgsz;
   855    851         mxCache = db->aDb[0].pSchema->cache_size;
   856         -      if( mxCache<SQLITE_SORTER_PMASZ ) mxCache = SQLITE_SORTER_PMASZ;
   857         -      pSorter->mxPmaSize = MIN((i64)mxCache*pgsz, SQLITE_MAX_MXPMASIZE);
          852  +      if( mxCache<szPma ) mxCache = szPma;
          853  +      pSorter->mxPmaSize = MIN((i64)mxCache*pgsz, SQLITE_MAX_PMASZ);
   858    854   
   859    855         /* EVIDENCE-OF: R-26747-61719 When the application provides any amount of
   860    856         ** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary
   861    857         ** large heap allocations.
   862    858         */
   863    859         if( sqlite3GlobalConfig.pScratch==0 ){
   864    860           assert( pSorter->iMemory==0 );
................................................................................
  1128   1124   ** the VFS has memory mapped it.
  1129   1125   **
  1130   1126   ** Whether or not the file does end up memory mapped of course depends on
  1131   1127   ** the specific VFS implementation.
  1132   1128   */
  1133   1129   static void vdbeSorterExtendFile(sqlite3 *db, sqlite3_file *pFd, i64 nByte){
  1134   1130     if( nByte<=(i64)(db->nMaxSorterMmap) && pFd->pMethods->iVersion>=3 ){
  1135         -    int rc = sqlite3OsTruncate(pFd, nByte);
  1136         -    if( rc==SQLITE_OK ){
  1137         -      void *p = 0;
  1138         -      sqlite3OsFetch(pFd, 0, (int)nByte, &p);
  1139         -      sqlite3OsUnfetch(pFd, 0, p);
  1140         -    }
         1131  +    void *p = 0;
         1132  +    int chunksize = 4*1024;
         1133  +    sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_CHUNK_SIZE, &chunksize);
         1134  +    sqlite3OsFileControlHint(pFd, SQLITE_FCNTL_SIZE_HINT, &nByte);
         1135  +    sqlite3OsFetch(pFd, 0, (int)nByte, &p);
         1136  +    sqlite3OsUnfetch(pFd, 0, p);
  1141   1137     }
  1142   1138   }
  1143   1139   #else
  1144   1140   # define vdbeSorterExtendFile(x,y,z)
  1145   1141   #endif
  1146   1142   
  1147   1143   /*

Changes to src/wal.c.

  2416   2416       if( rc!=SQLITE_OK ){
  2417   2417         return rc;
  2418   2418       }
  2419   2419       nCollide = HASHTABLE_NSLOT;
  2420   2420       for(iKey=walHash(pgno); aHash[iKey]; iKey=walNextHash(iKey)){
  2421   2421         u32 iFrame = aHash[iKey] + iZero;
  2422   2422         if( iFrame<=iLast && aPgno[aHash[iKey]]==pgno ){
  2423         -        /* assert( iFrame>iRead ); -- not true if there is corruption */
         2423  +        assert( iFrame>iRead || CORRUPT_DB );
  2424   2424           iRead = iFrame;
  2425   2425         }
  2426   2426         if( (nCollide--)==0 ){
  2427   2427           return SQLITE_CORRUPT_BKPT;
  2428   2428         }
  2429   2429       }
  2430   2430     }

Changes to test/bigsort.test.

    16     16   
    17     17   #--------------------------------------------------------------------
    18     18   # At one point there was an overflow problem if the product of the 
    19     19   # cache-size and page-size was larger than 2^31. Causing an infinite 
    20     20   # loop if the product was also an integer multiple of 2^32, or 
    21     21   # inefficiency otherwise.
    22     22   #
           23  +# This test causes thrashing on machines with smaller amounts of
           24  +# memory.  Make sure the host has at least 8GB available before running
           25  +# this test.
           26  +#
           27  +if {[catch {exec free | grep Mem:} out] || [lindex $out 1]<8000000} {
           28  +  finish_test
           29  +  return
           30  +}
           31  +
    23     32   do_execsql_test 1.0 {
    24     33     PRAGMA page_size = 1024;
    25     34     CREATE TABLE t1(a, b);
    26     35     BEGIN;
    27     36     WITH data(x,y) AS (
    28     37       SELECT 1, zeroblob(10000)
    29     38       UNION ALL
................................................................................
    35     44   do_execsql_test 1.1 {
    36     45     PRAGMA cache_size = 4194304;
    37     46     CREATE INDEX i1 ON t1(a, b);
    38     47   }
    39     48   
    40     49   
    41     50   finish_test
    42         -
    43         -

Changes to test/e_walauto.test.

    62     62       }
    63     63     }
    64     64   } {
    65     65   
    66     66     eval $code
    67     67   
    68     68     reset_db
           69  +  execsql { PRAGMA auto_vacuum = 0 }
    69     70     do_execsql_test 1.$tn.0 { PRAGMA journal_mode = WAL } {wal}
    70     71     do_execsql_test 1.$tn.1 { CREATE TABLE t1(a, b) }
    71         -  set shmfd [open "test.db-shm"]
           72  +  set shmfd [open "test.db-shm" rb]
    72     73   
    73     74     # EVIDENCE-OF: R-41531-51083 Every new database connection defaults to
    74     75     # having the auto-checkpoint enabled with a threshold of 1000 or
    75     76     # SQLITE_DEFAULT_WAL_AUTOCHECKPOINT pages.
    76     77     #
    77     78     do_autocommit_threshold_test 1.$tn.2 1000
    78     79     db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) }

Changes to test/e_walckpt.test.

   243    243     testvfs tvfs
   244    244     tvfs filter xWrite
   245    245     sqlite3 db test.db -vfs tvfs
   246    246     sqlite3 db2 test.db -vfs tvfs
   247    247   
   248    248     do_test $tn.3.2.1 {
   249    249       db2 eval {
          250  +      PRAGMA auto_vacuum = 0;
   250    251         PRAGMA journal_mode = WAL;
   251    252         CREATE TABLE t1(x, y);
   252    253         INSERT INTO t1 VALUES(1,2);
   253    254         INSERT INTO t1 VALUES(3,4);
   254    255         INSERT INTO t1 VALUES(5,6);
   255    256       }
   256    257       file size test.db-wal
................................................................................
   702    703   }
   703    704   
   704    705   reset_db
   705    706   sqlite3 db2 test.db
   706    707   
   707    708   do_test 6.1 {
   708    709     execsql {
          710  +    PRAGMA auto_vacuum = 0; 
   709    711       PRAGMA journal_mode = WAL;
   710    712       CREATE TABLE t1(a, b);
   711    713       INSERT INTO t1 VALUES(1, 2);
   712    714     }
   713    715     file size test.db-wal
   714    716   } [wal_file_size 3 1024]
   715    717   

Changes to test/fkey5.test.

   248    248   do_test fkey5-6.5 {
   249    249     db eval {
   250    250       PRAGMA foreign_key_check(c12);
   251    251     }
   252    252   } {c12 1 p4 0 c12 3 p4 0 c12 6 p4 0}
   253    253   
   254    254   do_test fkey5-7.1 {
          255  +  set res {}
   255    256     db eval {
   256    257       INSERT OR IGNORE INTO c13 SELECT * FROM c12;
   257    258       INSERT OR IGNORE INTO C14 SELECT * FROM c12;
   258    259       DELETE FROM c12;
   259    260       PRAGMA foreign_key_check;
          261  +  } {
          262  +    lappend res [list $table $rowid $fkid $parent]
   260    263     }
   261         -} {c14 1 p4 0 c14 3 p4 0 c14 6 p4 0 c13 1 p3 0 c13 2 p3 0 c13 3 p3 0 c13 4 p3 0 c13 5 p3 0 c13 6 p3 0}
          264  +  lsort $res
          265  +} {{c13 1 0 p3} {c13 2 0 p3} {c13 3 0 p3} {c13 4 0 p3} {c13 5 0 p3} {c13 6 0 p3} {c14 1 0 p4} {c14 3 0 p4} {c14 6 0 p4}}
   262    266   do_test fkey5-7.2 {
   263    267     db eval {
   264    268       PRAGMA foreign_key_check(c14);
   265    269     }
   266    270   } {c14 1 p4 0 c14 3 p4 0 c14 6 p4 0}
   267    271   do_test fkey5-7.3 {
   268    272     db eval {

Added test/fkey8.test.

            1  +# 2001 September 15
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# This file implements regression tests for SQLite library.
           12  +#
           13  +# This file implements tests for foreign keys.
           14  +#
           15  +
           16  +set testdir [file dirname $argv0]
           17  +source $testdir/tester.tcl
           18  +set testprefix fkey8
           19  +
           20  +ifcapable {!foreignkey} {
           21  +  finish_test
           22  +  return
           23  +}
           24  +do_execsql_test 1.0 { PRAGMA foreign_keys = 1; }
           25  +
           26  +
           27  +foreach {tn use_stmt sql schema} {
           28  +  1   1 "DELETE FROM p1" {
           29  +    CREATE TABLE p1(a PRIMARY KEY);
           30  +    CREATE TABLE c1(b REFERENCES p1);
           31  +  }
           32  +
           33  +  2.1     0 "DELETE FROM p1" {
           34  +    CREATE TABLE p1(a PRIMARY KEY);
           35  +    CREATE TABLE c1(b REFERENCES p1 ON DELETE CASCADE);
           36  +  }
           37  +  2.2   0 "DELETE FROM p1" {
           38  +    CREATE TABLE p1(a PRIMARY KEY);
           39  +    CREATE TABLE c1(b REFERENCES p1 ON DELETE SET NULL);
           40  +  }
           41  +  2.3   1 "DELETE FROM p1" {
           42  +    CREATE TABLE p1(a PRIMARY KEY);
           43  +    CREATE TABLE c1(b REFERENCES p1 ON DELETE SET DEFAULT);
           44  +  }
           45  +
           46  +  3   1 "DELETE FROM p1" {
           47  +    CREATE TABLE p1(a PRIMARY KEY);
           48  +    CREATE TABLE c1(b REFERENCES p1 ON DELETE CASCADE);
           49  +    CREATE TRIGGER ct1 AFTER DELETE ON c1 BEGIN
           50  +      INSERT INTO p1 VALUES('x');
           51  +    END;
           52  +  }
           53  +
           54  +  4   1 "DELETE FROM p1" {
           55  +    CREATE TABLE p1(a PRIMARY KEY);
           56  +    CREATE TABLE c1(b REFERENCES p1 ON DELETE CASCADE, c PRIMARY KEY);
           57  +    CREATE TABLE cc1(d REFERENCES c1);
           58  +  }
           59  +
           60  +  5.1   0 "DELETE FROM p1" {
           61  +    CREATE TABLE p1(a PRIMARY KEY);
           62  +    CREATE TABLE c1(b REFERENCES p1 ON DELETE CASCADE, c PRIMARY KEY);
           63  +    CREATE TABLE cc1(d REFERENCES c1 ON DELETE CASCADE);
           64  +  }
           65  +  5.2   0 "DELETE FROM p1" {
           66  +    CREATE TABLE p1(a PRIMARY KEY);
           67  +    CREATE TABLE c1(b REFERENCES p1 ON DELETE CASCADE, c PRIMARY KEY);
           68  +    CREATE TABLE cc1(d REFERENCES c1 ON DELETE SET NULL);
           69  +  }
           70  +  5.3   1 "DELETE FROM p1" {
           71  +    CREATE TABLE p1(a PRIMARY KEY);
           72  +    CREATE TABLE c1(b REFERENCES p1 ON DELETE CASCADE, c PRIMARY KEY);
           73  +    CREATE TABLE cc1(d REFERENCES c1 ON DELETE SET DEFAULT);
           74  +  }
           75  +
           76  +  6.1   1 "UPDATE p1 SET a = ?" {
           77  +    CREATE TABLE p1(a PRIMARY KEY);
           78  +    CREATE TABLE c1(b REFERENCES p1 ON UPDATE SET NULL, c);
           79  +  }
           80  +  6.2   0 "UPDATE OR IGNORE p1 SET a = ?" {
           81  +    CREATE TABLE p1(a PRIMARY KEY);
           82  +    CREATE TABLE c1(b REFERENCES p1 ON UPDATE SET NULL, c);
           83  +  }
           84  +  6.3   1 "UPDATE OR IGNORE p1 SET a = ?" {
           85  +    CREATE TABLE p1(a PRIMARY KEY);
           86  +    CREATE TABLE c1(b REFERENCES p1 ON UPDATE CASCADE, c);
           87  +  }
           88  +  6.4   1 "UPDATE OR IGNORE p1 SET a = ?" {
           89  +    CREATE TABLE p1(a PRIMARY KEY);
           90  +    CREATE TABLE c1(b NOT NULL REFERENCES p1 ON UPDATE SET NULL, c);
           91  +  }
           92  +
           93  +} {
           94  +  drop_all_tables
           95  +  do_test 1.$tn {
           96  +    execsql $schema
           97  +    set stmt [sqlite3_prepare_v2 db $sql -1 dummy]
           98  +    set ret [uses_stmt_journal $stmt]
           99  +    sqlite3_finalize $stmt
          100  +    set ret
          101  +  } $use_stmt
          102  +}
          103  +
          104  +
          105  +finish_test
          106  +

Changes to test/memsubsys1.test.

   178    178     set maxreq [lindex [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0] 2]
   179    179     expr {$maxreq<7000}
   180    180   } 1
   181    181   do_test memsubsys1-4.6 {
   182    182     set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2]
   183    183   } 1
   184    184   
   185         -# Test 5:  Activate both PAGECACHE and SCRATCH.  But make the page size
          185  +# Test 5:  Activate both PAGECACHE and SCRATCH.  But make the page size is
   186    186   # such that the SCRATCH allocations are too small.
   187    187   #
   188    188   db close
   189    189   sqlite3_shutdown
   190    190   sqlite3_config_pagecache [expr 4096+$xtra_size] 24
   191         -sqlite3_config_scratch 6000 2
          191  +sqlite3_config_scratch 4000 2
   192    192   sqlite3_initialize
   193    193   reset_highwater_marks
   194    194   build_test_db memsubsys1-5 {PRAGMA page_size=4096}
   195    195   #show_memstats
   196    196   do_test memsubsys1-5.3 {
   197    197     set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]
   198         -} 24
          198  +} {/^2[34]$/}
   199    199   set msize [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0]
   200    200   if {[lindex $msize 2]!=0} {
   201    201     do_test memsubsys1-5.4 {
   202    202       set maxreq [lindex [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0] 2]
   203    203       expr {$maxreq>4096}
   204    204     } 1
   205    205     do_test memsubsys1-5.5 {
................................................................................
   220    220   sqlite3_config_scratch 25300 1
   221    221   sqlite3_initialize
   222    222   reset_highwater_marks
   223    223   build_test_db memsubsys1-6 {PRAGMA page_size=4096}
   224    224   #show_memstats
   225    225   do_test memsubsys1-6.3 {
   226    226     set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]
   227         -} 24
          227  +} {/^2[34]$/}
   228    228   #do_test memsubsys1-6.4 {
   229    229   #  set maxreq [lindex [sqlite3_status SQLITE_STATUS_MALLOC_SIZE 0] 2]
   230    230   #  expr {$maxreq>4096 && $maxreq<=(4096+$xtra_size)}
   231    231   #} 1
   232    232   do_test memsubsys1-6.5 {
   233    233     set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2]
   234    234   } 1

Changes to test/notify2.test.

    97     97     opendb
    98     98   
    99     99     #after 2000
   100    100   
   101    101     # This loop runs for ~20 seconds.
   102    102     #
   103    103     set iStart [clock_seconds]
          104  +  set nOp 0
          105  +  set nAttempt 0
   104    106     while { ([clock_seconds]-$iStart) < $nSecond } {
   105    107   
   106    108       # Each transaction does 3 operations. Each operation is either a read
   107    109       # or write of a randomly selected table (t1, t2 or t3). Set the variables
   108    110       # $SQL(1), $SQL(2) and $SQL(3) to the SQL commands used to implement
   109    111       # each operation.
   110    112       #
................................................................................
   124    126               DROP INDEX IF EXISTS yyy.xxx_i;
   125    127         }
   126    128         ]]
   127    129       }
   128    130   
   129    131       # Execute the SQL transaction.
   130    132       #
          133  +    incr nAttempt
   131    134       set rc [catch { execsql_blocking $::DB "
   132    135           BEGIN;
   133    136             $SQL(1);
   134    137             $SQL(2);
   135    138             $SQL(3);
   136    139           COMMIT;
   137    140         "
................................................................................
   150    153         # Hit some other kind of error. This is a malfunction.
   151    154         error $msg
   152    155       } else {
   153    156         # No error occurred. Check that any SELECT statements in the transaction
   154    157         # returned "1". Otherwise, the invariant was false, indicating that
   155    158         # some malfunction has occurred.
   156    159         foreach r $msg { if {$r != 1} { puts "Invariant check failed: $msg" } }
          160  +      incr nOp
   157    161       }
   158    162     }
   159    163   
   160    164     # Close the database connection and return 0.
   161    165     #
   162    166     sqlite3_close $::DB
   163         -  expr 0
          167  +  list $nOp $nAttempt
   164    168   }
   165    169   
   166    170   foreach {iTest xStep xPrepare} {
   167    171     1 sqlite3_blocking_step sqlite3_blocking_prepare_v2
   168    172     2 sqlite3_step          sqlite3_nonblocking_prepare_v2
   169    173   } {
   170    174     forcedelete test.db test2.db test3.db
................................................................................
   200    204     unset -nocomplain finished
   201    205     for {set ii 0} {$ii < $nThread} {incr ii} {
   202    206       thread_spawn finished($ii) $ThreadSetup $ThreadProgram
   203    207     }
   204    208     for {set ii 0} {$ii < $nThread} {incr ii} {
   205    209       do_test notify2-$iTest.2.$ii {
   206    210         if {![info exists finished($ii)]} { vwait finished($ii) }
   207         -      set finished($ii)
          211  +      incr anSuccess($xStep) [lindex $finished($ii) 0]
          212  +      incr anAttempt($xStep) [lindex $finished($ii) 1]
          213  +      expr 0
   208    214       } {0}
   209    215     }
   210    216   
   211    217     # Count the total number of succesful writes.
   212    218     do_test notify2-$iTest.3.1 {
   213    219       sqlite3 db test.db
   214    220       execsql {
................................................................................
   221    227              + (SELECT max(a) FROM t3)
   222    228       }]
   223    229       db close
   224    230     } {}
   225    231   }
   226    232   
   227    233   # The following tests checks to make sure sqlite3_blocking_step() is
   228         -# faster than sqlite3_step().  blocking_step() is always faster on
   229         -# multi-core and is usually faster on single-core.  But sometimes, by
   230         -# chance, step() will be faster on a single core, in which case the
          234  +# faster than sqlite3_step(). "Faster" in this case means uses fewer
          235  +# CPU cycles. This is not always the same as faster in wall-clock time 
          236  +# for this type of test. The number of CPU cycles per transaction is 
          237  +# roughly proportional to the number of attempts made (i.e. one plus the 
          238  +# number of SQLITE_BUSY or SQLITE_LOCKED errors that require the transaction 
          239  +# to be retried). So this test just measures that a greater percentage of
          240  +# transactions attempted using blocking_step() succeed.
          241  +#
          242  +# The blocking_step() function is almost always faster on multi-core and is
          243  +# usually faster on single-core.  But sometimes, by chance, step() will be
          244  +# faster on a single core, in which case the
   231    245   # following test will fail.
   232    246   #
   233    247   puts "The following test seeks to demonstrate that the sqlite3_unlock_notify()"
   234         -puts "interface helps multi-core systems to run faster.  This test sometimes"
   235         -puts "fails on single-core machines."
          248  +puts "interface helps multi-core systems to run more efficiently.  This test"
          249  +puts "sometimes fails on single-core machines."
   236    250   puts [array get anWrite]
   237    251   do_test notify2-3 {
   238         -  expr {$anWrite(sqlite3_blocking_step) > $anWrite(sqlite3_step)}
          252  +  set blocking [expr {
          253  +    double($anSuccess(sqlite3_blocking_step)) /
          254  +    double($anAttempt(sqlite3_blocking_step)) 
          255  +  }]
          256  +  set non [expr {
          257  +    double($anSuccess(sqlite3_step)) /
          258  +    double($anAttempt(sqlite3_step)) 
          259  +  }]
          260  +  puts -nonewline [format " blocking: %.1f%% non-blocking %.1f%% ..." \
          261  +    [expr $blocking*100.0] [expr $non*100.0]]
          262  +
          263  +  expr {$blocking > $non}
   239    264   } {1}
   240    265   
   241    266   sqlite3_enable_shared_cache $::enable_shared_cache
   242    267   finish_test

Changes to test/percentile.test.

   196    196         0          0.0
   197    197       100    9999990.0
   198    198        50    2749999.5
   199    199        10      99999.9
   200    200     } {
   201    201       do_test percentile-2.1.$in {
   202    202         execsql {
   203         -        SELECT percentile(x, $in) from t3;
          203  +        SELECT round(percentile(x, $in),1) from t3;
   204    204         }
   205    205       } $out
   206    206     }
   207    207   }
   208    208   
   209    209   finish_test

Changes to test/permutations.test.

   114    114     walthread.test rtree3.test indexfault.test securedel2.test
   115    115     sort3.test sort4.test fts4growth.test fts4growth2.test
   116    116     bigsort.test
   117    117   }]
   118    118   if {[info exists ::env(QUICKTEST_INCLUDE)]} {
   119    119     set allquicktests [concat $allquicktests $::env(QUICKTEST_INCLUDE)]
   120    120   }
          121  +if {[info exists ::env(QUICKTEST_OMIT)]} {
          122  +  foreach x [split $::env(QUICKTEST_OMIT) ,] {
          123  +    regsub -all \\y$x\\y $allquicktests {} allquicktests
          124  +  }
          125  +}
   121    126   
   122    127   #############################################################################
   123    128   # Start of tests
   124    129   #
   125    130   
   126    131   #-------------------------------------------------------------------------
   127    132   # Define the generic test suites:
................................................................................
   137    142     This test suite is the same as the "quick" tests, except that some files
   138    143     that test malloc and IO errors are omitted.
   139    144   } -files [
   140    145     test_set $allquicktests -exclude *malloc* *ioerr* *fault*
   141    146   ]
   142    147   
   143    148   test_suite "mmap" -prefix "mm-" -description {
   144         -  Similar to veryquick. Except with memory mapping disabled.
          149  +  Similar to veryquick. Except with memory mapping enabled.
   145    150   } -presql {
   146    151     pragma mmap_size = 268435456;
   147    152   } -files [
   148    153     test_set $allquicktests -exclude *malloc* *ioerr* *fault* -include malloc.test
   149    154   ]
   150    155   
   151    156   test_suite "valgrind" -prefix "" -description {
................................................................................
   686    691   
   687    692     # Exclude stmt.test, which expects sub-journals to use temporary files.
   688    693     stmt.test
   689    694   
   690    695     zerodamage.test
   691    696   
   692    697     # WAL mode is different.
   693         -  wal* tkt-2d1a5c67d.test backcompat.test
          698  +  wal* tkt-2d1a5c67d.test backcompat.test e_wal*
   694    699   }]
   695    700   
   696    701   ifcapable mem3 {
   697    702     test_suite "memsys3" -description {
   698    703       Run tests using the allocator in mem3.c.
   699    704     } -files [test_set $::allquicktests -exclude {
   700    705       autovacuum.test           delete3.test              manydb.test

Added test/pragma3.test.

            1  +# 2014-12-19
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# This file implements regression tests for SQLite library.
           12  +#
           13  +# This file implements tests for PRAGMA data_version command.
           14  +#
           15  +
           16  +set testdir [file dirname $argv0]
           17  +source $testdir/tester.tcl
           18  +
           19  +do_execsql_test pragma3-100 {
           20  +  PRAGMA data_version;
           21  +} {1}
           22  +do_execsql_test pragma3-101 {
           23  +  PRAGMA temp.data_version;
           24  +} {1}
           25  +
           26  +# Writing to the pragma is a no-op 
           27  +do_execsql_test pragma3-102 {
           28  +  PRAGMA main.data_version=1234;
           29  +  PRAGMA main.data_version;
           30  +} {1 1}
           31  +
           32  +# EVIDENCE-OF: R-27726-60934 The "PRAGMA data_version" command provides
           33  +# an indication that the database file has been modified.
           34  +#
           35  +# EVIDENCE-OF: R-47505-58569 The "PRAGMA data_version" value is
           36  +# unchanged for commits made on the same database connection.
           37  +#
           38  +do_execsql_test pragma3-110 {
           39  +  PRAGMA data_version;
           40  +  BEGIN IMMEDIATE;
           41  +  PRAGMA data_version;
           42  +  CREATE TABLE t1(a);
           43  +  INSERT INTO t1 VALUES(100),(200),(300);
           44  +  PRAGMA data_version;
           45  +  COMMIT;
           46  +  SELECT * FROM t1;
           47  +  PRAGMA data_version;
           48  +} {1 1 1 100 200 300 1}
           49  +
           50  +sqlite3 db2 test.db
           51  +do_test pragma3-120 {
           52  +  db2 eval {
           53  +    SELECT * FROM t1;
           54  +    PRAGMA data_version;
           55  +  }
           56  +} {100 200 300 1}
           57  +
           58  +do_execsql_test pragma3-130 {
           59  +  PRAGMA data_version;
           60  +  BEGIN IMMEDIATE;
           61  +  PRAGMA data_version;
           62  +  INSERT INTO t1 VALUES(400),(500);
           63  +  PRAGMA data_version;
           64  +  COMMIT;
           65  +  SELECT * FROM t1;
           66  +  PRAGMA data_version;
           67  +  PRAGMA shrink_memory;
           68  +} {1 1 1 100 200 300 400 500 1}
           69  +
           70  +# EVIDENCE-OF: R-63005-41812 The integer values returned by two
           71  +# invocations of "PRAGMA data_version" from the same connection will be
           72  +# different if changes were committed to the database by any other
           73  +# connection in the interim.
           74  +#
           75  +# Value went from 1 in pragma3-120 to 2 here.
           76  +#
           77  +do_test pragma3-140 {
           78  +  db2 eval {
           79  +    SELECT * FROM t1;
           80  +    PRAGMA data_version;
           81  +    BEGIN IMMEDIATE;
           82  +    PRAGMA data_version;
           83  +    UPDATE t1 SET a=a+1;
           84  +    COMMIT;
           85  +    SELECT * FROM t1;
           86  +    PRAGMA data_version;
           87  +  }
           88  +} {100 200 300 400 500 2 2 101 201 301 401 501 2}
           89  +do_execsql_test pragma3-150 {
           90  +  SELECT * FROM t1;
           91  +  PRAGMA data_version;
           92  +} {101 201 301 401 501 2}
           93  +
           94  +#
           95  +do_test pragma3-160 {
           96  +  db eval {
           97  +    BEGIN;
           98  +    PRAGMA data_version;
           99  +    UPDATE t1 SET a=555 WHERE a=501;
          100  +    PRAGMA data_version;
          101  +    SELECT * FROM t1 ORDER BY a;
          102  +    PRAGMA data_version;
          103  +  }
          104  +} {2 2 101 201 301 401 555 2}
          105  +do_test pragma3-170 {
          106  +  db2 eval {
          107  +    PRAGMA data_version;
          108  +  }
          109  +} {2}
          110  +do_test pragma3-180 {
          111  +  db eval {
          112  +    COMMIT;
          113  +    PRAGMA data_version;
          114  +  }
          115  +} {2}
          116  +do_test pragma3-190 {
          117  +  db2 eval {
          118  +    PRAGMA data_version;
          119  +  }
          120  +} {3}
          121  +
          122  +# EVIDENCE-OF: R-19326-44825 The "PRAGMA data_version" value is a local
          123  +# property of each database connection and so values returned by two
          124  +# concurrent invocations of "PRAGMA data_version" on separate database
          125  +# connections are often different even though the underlying database is
          126  +# identical.
          127  +#
          128  +do_test pragma3-195 {
          129  +  expr {[db eval {PRAGMA data_version}]!=[db2 eval {PRAGMA data_version}]}
          130  +} {1}
          131  +
          132  +# EVIDENCE-OF: R-54562-06892 The behavior of "PRAGMA data_version" is
          133  +# the same for all database connections, including database connections
          134  +# in separate processes and shared cache database connections.
          135  +#
          136  +# The next block checks the behavior for separate processes.
          137  +#
          138  +do_test pragma3-200 {
          139  +  db eval {PRAGMA data_version; SELECT * FROM t1;}
          140  +} {2 101 201 301 401 555}
          141  +do_test pragma3-201 {
          142  +  set fd [open pragma3.txt wb]
          143  +  puts $fd {
          144  +     sqlite3 db test.db;
          145  +     db eval {DELETE FROM t1 WHERE a>300};
          146  +     db close;
          147  +     exit;
          148  +  }
          149  +  close $fd
          150  +  exec [info nameofexec] pragma3.txt
          151  +  forcedelete pragma3.txt
          152  +  db eval {
          153  +    PRAGMA data_version;
          154  +    SELECT * FROM t1;
          155  +  }
          156  +} {3 101 201}
          157  +db2 close
          158  +db close
          159  +
          160  +# EVIDENCE-OF: R-54562-06892 The behavior of "PRAGMA data_version" is
          161  +# the same for all database connections, including database connections
          162  +# in separate processes and shared cache database connections.
          163  +#
          164  +# The next block checks that behavior is the same for shared-cache.
          165  +#
          166  +ifcapable shared_cache {
          167  +  set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
          168  +  sqlite3 db test.db
          169  +  sqlite3 db2 test.db
          170  +  do_test pragma3-300 {
          171  +    db eval {
          172  +      PRAGMA data_version;
          173  +      BEGIN;
          174  +      CREATE TABLE t3(a,b,c);
          175  +      CREATE TABLE t4(x,y,z);
          176  +      INSERT INTO t4 VALUES(123,456,789);
          177  +      PRAGMA data_version;
          178  +      COMMIT;
          179  +      PRAGMA data_version;
          180  +    }
          181  +  } {1 1 1}
          182  +  do_test pragma3-310 {
          183  +    db2 eval {
          184  +      PRAGMA data_version;
          185  +      BEGIN;
          186  +      INSERT INTO t3(a,b,c) VALUES('abc','def','ghi');
          187  +      SELECT * FROM t3;
          188  +      PRAGMA data_version;
          189  +    }
          190  +  } {2 abc def ghi 2}
          191  +  # The transaction in db2 has not yet committed, so the data_version in
          192  +  # db is unchanged.
          193  +  do_test pragma3-320 {
          194  +    db eval {
          195  +      PRAGMA data_version;
          196  +      SELECT * FROM t4;
          197  +    }
          198  +  } {1 123 456 789}
          199  +  do_test pragma3-330 {
          200  +    db2 eval {
          201  +      COMMIT;
          202  +      PRAGMA data_version;
          203  +      SELECT * FROM t4;
          204  +    }
          205  +  } {2 123 456 789}
          206  +  do_test pragma3-340 {
          207  +    db eval {
          208  +      PRAGMA data_version;
          209  +      SELECT * FROM t3;
          210  +      SELECT * FROM t4;
          211  +    }
          212  +  } {2 abc def ghi 123 456 789}
          213  +  db2 close
          214  +  db close
          215  +  sqlite3_enable_shared_cache $::enable_shared_cache
          216  +}
          217  +
          218  +# Make sure this also works in WAL mode
          219  +#
          220  +# This will not work with the in-memory journal permutation, as opening
          221  +# [db2] switches the journal mode back to "memory"
          222  +#
          223  +ifcapable wal {
          224  +if {[permutation]!="inmemory_journal"} {
          225  +
          226  +  sqlite3 db test.db
          227  +  db eval {PRAGMA journal_mode=WAL}
          228  +  sqlite3 db2 test.db
          229  +  do_test pragma3-400 {
          230  +    db eval {
          231  +      PRAGMA data_version;
          232  +      PRAGMA journal_mode;
          233  +      SELECT * FROM t1;
          234  +    }
          235  +  } {2 wal 101 201}
          236  +  do_test pragma3-410 {
          237  +    db2 eval {
          238  +      PRAGMA data_version;
          239  +      PRAGMA journal_mode;
          240  +      SELECT * FROM t1;
          241  +    }
          242  +  } {2 wal 101 201}
          243  +  do_test pragma3-420 {
          244  +    db eval {UPDATE t1 SET a=111*(a/100); PRAGMA data_version; SELECT * FROM t1}
          245  +  } {2 111 222}
          246  +  do_test pragma3-430 {
          247  +    db2 eval {PRAGMA data_version; SELECT * FROM t1;}
          248  +  } {3 111 222}
          249  +  db2 close
          250  +}
          251  +}
          252  +
          253  +finish_test

Deleted test/releasetest.mk.

     1         -########################################################
     2         -TOP=/home/drh/sqlite/sqlite
     3         -
     4         -TCL_FLAGS=-I/home/drh/tcltk/86linux
     5         -LIBTCL=/home/drh/tcltk/86linux/libtcl8.6.a -lm -ldl -lpthread
     6         -
     7         -BCC = gcc
     8         -TCC = gcc -ansi -g $(CFLAGS)
     9         -NAWK   = awk
    10         -AR     = ar cr
    11         -RANLIB = ranlib
    12         -THREADLIB = -lpthread -ldl -lz
    13         -include $(TOP)/main.mk
    14         -########################################################

Changes to test/releasetest.tcl.

     1         -
     2         -set rcsid {$Id: $}
     3         -
            1  +#!/usr/bin/tclsh
            2  +#
     4      3   # Documentation for this script. This may be output to stderr
     5      4   # if the script is invoked incorrectly. See the [process_options]
     6      5   # proc below.
     7      6   #
     8      7   set ::USAGE_MESSAGE {
     9      8   This Tcl script is used to test the various configurations required
    10         -before releasing a new version. Supported command line options (all 
            9  +before releasing a new version. Supported command line options (all
    11     10   optional) are:
    12     11   
    13         -    -makefile PATH-TO-MAKEFILE           (default "releasetest.mk")
    14         -    -platform PLATFORM                   (see below)
    15         -    -quick    BOOLEAN                    (default "0")
    16         -    -config   CONFIGNAME                 (Run only CONFIGNAME)
           12  +    --srcdir   TOP-OF-SQLITE-TREE      (see below)
           13  +    --platform PLATFORM                (see below)
           14  +    --config   CONFIGNAME              (Run only CONFIGNAME)
           15  +    --quick                            (Run "veryquick.test" only)
           16  +    --buildonly                        (Just build testfixture - do not run)
           17  +    --dryrun                           (Print what would have happened)
           18  +    --info                             (Show diagnostic info)
    17     19   
    18         -The default value for -makefile is "./releasetest.mk".
           20  +The default value for --srcdir is the parent of the directory holding
           21  +this script.
    19     22   
    20         -The script determines the default value for -platform using the
    21         -$tcl_platform(os) and $tcl_platform(machine) variables. Supported 
           23  +The script determines the default value for --platform using the
           24  +$tcl_platform(os) and $tcl_platform(machine) variables. Supported
    22     25   platforms are "Linux-x86", "Linux-x86_64" and "Darwin-i386".
    23     26   
    24         -If the -quick option is set to true, then the "veryquick.test" script
    25         -is run for all compilation configurations. Otherwise, sometimes "all.test"
    26         -is run, sometimes "veryquick.test".
    27         -
    28         -Almost any SQLite makefile (except those generated by configure - see below)
    29         -should work. The following properties are required:
    30         -
    31         -  * The makefile should support the "fulltest" target.
    32         -  * The makefile should support the variable "OPTS" as a way to pass
    33         -    options from the make command line to lemon and the C compiler.
    34         -
    35         -More precisely, the following invocation must be supported:
    36         -
    37         -  make -f $::MAKEFILE fulltest OPTS="-DSQLITE_SECURE_DELETE=1 -DSQLITE_DEBUG=1"
    38         -
    39         -Makefiles generated by the sqlite configure program cannot be used as
    40         -they do not respect the OPTS variable.
    41         -
    42         -Example Makefile contents:
    43         -
    44         -  ########################################################
    45         -  TOP=/home/dan/work/sqlite/sqlite
    46         -
    47         -  TCL_FLAGS=-I/home/dan/tcl/include
    48         -  LIBTCL=-L/home/dan/tcl/lib -ltcl
    49         -
    50         -  BCC = gcc
    51         -  TCC = gcc -ansi -g $(CFLAGS)
    52         -  NAWK   = awk
    53         -  AR     = ar cr
    54         -  RANLIB = ranlib
    55         -  THREADLIB = -lpthread -ldl
    56         -  include $(TOP)/main.mk
    57         -  ########################################################
           27  +Every test begins with a fresh run of the configure script at the top
           28  +of the SQLite source tree.
    58     29   }
    59     30   
    60     31   array set ::Configs {
    61     32     "Default" {
    62     33       -O2
    63     34     }
    64     35     "Ftrapv" {
    65     36       -O2 -ftrapv
    66         -    -DSQLITE_MAX_ATTACHED=55
           37  +    -DSQLITE_MAX_ATTACHED=125
    67     38       -DSQLITE_TCL_DEFAULT_FULLMUTEX=1
    68     39     }
           40  +  "Sanitize" {
           41  +    CC=clang -fsanitize=undefined
           42  +    -DSQLITE_ENABLE_STAT4
           43  +  }
    69     44     "Unlock-Notify" {
    70     45       -O2
    71     46       -DSQLITE_ENABLE_UNLOCK_NOTIFY
    72     47       -DSQLITE_THREADSAFE
    73     48       -DSQLITE_TCL_DEFAULT_FULLMUTEX=1
    74     49     }
    75     50     "Secure-Delete" {
................................................................................
    90     65       -DSQLITE_ENABLE_MEMSYS5=1
    91     66       -DSQLITE_ENABLE_MEMSYS3=1
    92     67       -DSQLITE_ENABLE_COLUMN_METADATA=1
    93     68       -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT=1
    94     69       -DSQLITE_SECURE_DELETE=1
    95     70       -DSQLITE_SOUNDEX=1
    96     71       -DSQLITE_ENABLE_ATOMIC_WRITE=1
    97         -    -DSQLITE_ENABLE_IOTRACE=1
    98     72       -DSQLITE_ENABLE_MEMORY_MANAGEMENT=1
    99     73       -DSQLITE_ENABLE_OVERSIZE_CELL_CHECK=1
           74  +    -DSQLITE_ENABLE_STAT4
   100     75     }
   101     76     "Debug-One" {
   102     77       -O2
   103     78       -DSQLITE_DEBUG=1
   104     79       -DSQLITE_MEMDEBUG=1
   105     80       -DSQLITE_MUTEX_NOOP=1
   106     81       -DSQLITE_TCL_DEFAULT_FULLMUTEX=1
   107     82       -DSQLITE_ENABLE_FTS3=1
   108     83       -DSQLITE_ENABLE_RTREE=1
   109     84       -DSQLITE_ENABLE_MEMSYS5=1
   110     85       -DSQLITE_ENABLE_MEMSYS3=1
   111     86       -DSQLITE_ENABLE_COLUMN_METADATA=1
           87  +    -DSQLITE_ENABLE_STAT4
   112     88     }
   113     89     "Device-One" {
   114     90       -O2
   115     91       -DSQLITE_DEBUG=1
   116     92       -DSQLITE_DEFAULT_AUTOVACUUM=1
   117     93       -DSQLITE_DEFAULT_CACHE_SIZE=64
   118     94       -DSQLITE_DEFAULT_PAGE_SIZE=1024
................................................................................
   145    121       -DSQLITE_THREADSAFE=2
   146    122     }
   147    123     "Locking-Style" {
   148    124       -O2
   149    125       -DSQLITE_ENABLE_LOCKING_STYLE=1
   150    126     }
   151    127     "OS-X" {
          128  +    -O1   # Avoid a compiler bug in gcc 4.2.1 build 5658
   152    129       -DSQLITE_OMIT_LOAD_EXTENSION=1
   153    130       -DSQLITE_DEFAULT_MEMSTATUS=0
   154    131       -DSQLITE_THREADSAFE=2
   155    132       -DSQLITE_OS_UNIX=1
   156    133       -DSQLITE_ENABLE_LOCKING_STYLE=1
   157    134       -DUSE_PREAD=1
   158    135       -DSQLITE_ENABLE_RTREE=1
   159    136       -DSQLITE_ENABLE_FTS3=1
   160    137       -DSQLITE_ENABLE_FTS3_PARENTHESIS=1
   161    138       -DSQLITE_DEFAULT_CACHE_SIZE=1000
   162    139       -DSQLITE_MAX_LENGTH=2147483645
   163    140       -DSQLITE_MAX_VARIABLE_NUMBER=500000
   164         -    -DSQLITE_DEBUG=1 
          141  +    -DSQLITE_DEBUG=1
   165    142       -DSQLITE_PREFER_PROXY_LOCKING=1
          143  +    -DSQLITE_ENABLE_API_ARMOR=1
   166    144     }
   167    145     "Extra-Robustness" {
   168    146       -DSQLITE_ENABLE_OVERSIZE_CELL_CHECK=1
   169    147       -DSQLITE_MAX_ATTACHED=62
   170    148     }
   171    149     "Devkit" {
   172    150       -DSQLITE_DEFAULT_FILE_FORMAT=4
................................................................................
   184    162       -DHAVE_USLEEP=1
   185    163     }
   186    164   }
   187    165   
   188    166   array set ::Platforms {
   189    167     Linux-x86_64 {
   190    168       "Check-Symbols"           checksymbols
   191         -    "Debug-One"               test
          169  +    "Debug-One"               "mptest test"
   192    170       "Secure-Delete"           test
   193    171       "Unlock-Notify"           "QUICKTEST_INCLUDE=notify2.test test"
   194    172       "Update-Delete-Limit"     test
   195    173       "Extra-Robustness"        test
   196    174       "Device-Two"              test
   197    175       "Ftrapv"                  test
          176  +    "Sanitize"                {QUICKTEST_OMIT=func4.test,nan.test test}
   198    177       "No-lookaside"            test
   199    178       "Devkit"                  test
   200    179       "Default"                 "threadtest fulltest"
   201    180       "Device-One"              fulltest
   202    181     }
   203    182     Linux-i686 {
   204    183       "Devkit"                  test
   205    184       "Unlock-Notify"           "QUICKTEST_INCLUDE=notify2.test test"
   206    185       "Device-One"              test
   207    186       "Device-Two"              test
   208    187       "Default"                 "threadtest fulltest"
   209    188     }
   210    189     Darwin-i386 {
   211         -    "Locking-Style"           test
          190  +    "Locking-Style"           "mptest test"
          191  +    "OS-X"                    "threadtest fulltest"
          192  +  }
          193  +  Darwin-x86_64 {
          194  +    "Locking-Style"           "mptest test"
   212    195       "OS-X"                    "threadtest fulltest"
   213    196     }
          197  +  "Windows NT-intel" {
          198  +    "Default"                 "mptest fulltestonly"
          199  +  }
   214    200   }
   215    201   
   216    202   
   217    203   # End of configuration section.
   218    204   #########################################################################
   219    205   #########################################################################
   220    206   
................................................................................
   222    208     foreach {v t} $value {
   223    209       if {0==[info exists ::Configs($v)]} {
   224    210         puts stderr "No such configuration: \"$v\""
   225    211         exit -1
   226    212       }
   227    213     }
   228    214   }
          215  +
          216  +# Open the file $logfile and look for a report on the number of errors
          217  +# and the number of test cases run.  Add these values to the global
          218  +# $::NERRCASE and $::NTESTCASE variables.
          219  +#
          220  +# If any errors occur, then write into $errmsgVar the text of an appropriate
          221  +# one-line error message to show on the output.
          222  +#
          223  +proc count_tests_and_errors {logfile rcVar errmsgVar} {
          224  +  if {$::DRYRUN} return
          225  +  upvar 1 $rcVar rc $errmsgVar errmsg
          226  +  set fd [open $logfile rb]
          227  +  set seen 0
          228  +  while {![eof $fd]} {
          229  +    set line [gets $fd]
          230  +    if {[regexp {(\d+) errors out of (\d+) tests} $line all nerr ntest]} {
          231  +      incr ::NERRCASE $nerr
          232  +      incr ::NTESTCASE $ntest
          233  +      set seen 1
          234  +      if {$nerr>0} {
          235  +        set rc 1
          236  +        set errmsg $line
          237  +      }
          238  +    }
          239  +    if {[regexp {runtime error: +(.*)} $line all msg]} {
          240  +      incr ::NERRCASE
          241  +      if {$rc==0} {
          242  +        set rc 1
          243  +        set errmsg $msg
          244  +      }
          245  +    }
          246  +  }
          247  +  close $fd
          248  +  if {!$seen} {
          249  +    set rc 1
          250  +    set errmsg "Test did not complete"
          251  +  }
          252  +}
   229    253   
   230    254   proc run_test_suite {name testtarget config} {
   231         -  
   232         -  # Tcl variable $opts is used to build up the value used to set the 
          255  +  # Tcl variable $opts is used to build up the value used to set the
   233    256     # OPTS Makefile variable. Variable $cflags holds the value for
   234    257     # CFLAGS. The makefile will pass OPTS to both gcc and lemon, but
   235    258     # CFLAGS is only passed to gcc.
   236    259     #
   237         -  set cflags ""
          260  +  set cflags "-g"
   238    261     set opts ""
          262  +  regsub -all {#[^\n]*\n} $config \n config
   239    263     foreach arg $config {
   240    264       if {[string match -D* $arg]} {
   241    265         lappend opts $arg
          266  +    } elseif {[string match CC=* $arg]} {
          267  +      lappend testtarget $arg
   242    268       } else {
   243    269         lappend cflags $arg
   244    270       }
   245    271     }
   246    272   
   247    273     set cflags [join $cflags " "]
   248    274     set opts   [join $opts " "]
................................................................................
   254    280   
   255    281     if {$::tcl_platform(platform)=="windows"} {
   256    282       append opts " -DSQLITE_OS_WIN=1"
   257    283     } else {
   258    284       append opts " -DSQLITE_OS_UNIX=1"
   259    285     }
   260    286   
   261         -  # Run the test.
   262         -  #
   263         -  set makefile [file normalize $::MAKEFILE]
   264         -  file mkdir $dir
   265         -  puts -nonewline "Testing configuration \"$name\" (logfile=$dir/test.log)..."
   266         -  flush stdout
          287  +  dryrun file mkdir $dir
          288  +  if {!$::DRYRUN} {
          289  +    set title ${name}($testtarget)
          290  +    set n [string length $title]
          291  +    puts -nonewline "${title}[string repeat . [expr {63-$n}]]"
          292  +    flush stdout
          293  +  }
   267    294   
   268         -  set makecmd [concat                                  \
   269         -    [list exec make -C $dir -f $makefile clean]        \
   270         -    $testtarget                                        \
   271         -    [list CFLAGS=$cflags OPTS=$opts >& $dir/test.log]  \
   272         -  ]
   273         -
   274         -  set tm1 [clock seconds] 
   275         -  set rc [catch $makecmd]
          295  +  set tm1 [clock seconds]
          296  +  set origdir [pwd]
          297  +  dryrun cd $dir
          298  +  set errmsg {}
          299  +  set rc [catch [configureCommand]]
          300  +  if {!$rc} {
          301  +    set rc [catch [makeCommand $testtarget $cflags $opts]]
          302  +    count_tests_and_errors test.log rc errmsg
          303  +  }
   276    304     set tm2 [clock seconds]
          305  +  dryrun cd $origdir
   277    306   
   278         -  set minutes [expr {($tm2-$tm1)/60}]
   279         -  set seconds [expr {($tm2-$tm1)%60}]
   280         -  puts -nonewline [format " (%d:%.2d) " $minutes $seconds]
   281         -  if {$rc} {
   282         -    puts "FAILED."
          307  +  if {!$::DRYRUN} {
          308  +    set hours [expr {($tm2-$tm1)/3600}]
          309  +    set minutes [expr {(($tm2-$tm1)/60)%60}]
          310  +    set seconds [expr {($tm2-$tm1)%60}]
          311  +    set tm [format (%02d:%02d:%02d) $hours $minutes $seconds]
          312  +    if {$rc} {
          313  +      puts " FAIL $tm"
          314  +      incr ::NERR
          315  +      if {$errmsg!=""} {puts "     $errmsg"}
          316  +    } else {
          317  +      puts " Ok   $tm"
          318  +    }
          319  +  }
          320  +}
          321  +
          322  +# The following procedure returns the "configure" command to be exectued for
          323  +# the current platform, which may be Windows (via MinGW, etc).
          324  +#
          325  +proc configureCommand {} {
          326  +  set result [list dryrun exec]
          327  +  if {$::tcl_platform(platform)=="windows"} {
          328  +    lappend result sh
          329  +  }
          330  +  lappend result $::SRCDIR/configure -enable-load-extension >& test.log
          331  +}
          332  +
          333  +# The following procedure returns the "make" command to be executed for the
          334  +# specified targets, compiler flags, and options.
          335  +#
          336  +proc makeCommand { targets cflags opts } {
          337  +  set result [list dryrun exec make clean]
          338  +  foreach target $targets {
          339  +    lappend result $target
          340  +  }
          341  +  lappend result CFLAGS=$cflags OPTS=$opts >>& test.log
          342  +}
          343  +
          344  +# The following procedure either prints its arguments (if ::DRYRUN is true)
          345  +# or executes the command of its arguments in the calling context
          346  +# (if ::DRYRUN is false).
          347  +#
          348  +proc dryrun {args} {
          349  +  if {$::DRYRUN} {
          350  +    puts $args
   283    351     } else {
   284         -    puts "Ok."
          352  +    uplevel 1 $args
   285    353     }
   286    354   }
   287    355   
   288    356   
   289    357   # This proc processes the command line options passed to this script.
   290    358   # Currently the only option supported is "-makefile", default
   291    359   # "releasetest.mk". Set the ::MAKEFILE variable to the value of this
   292    360   # option.
   293    361   #
   294    362   proc process_options {argv} {
   295         -  set ::MAKEFILE releasetest.mk                       ;# Default value
   296         -  set ::QUICK    0                                    ;# Default value
          363  +  set ::SRCDIR    [file normalize [file dirname [file dirname $::argv0]]]
          364  +  set ::QUICK     0
          365  +  set ::BUILDONLY 0
          366  +  set ::DRYRUN    0
          367  +  set ::EXEC      exec
   297    368     set config {}
   298    369     set platform $::tcl_platform(os)-$::tcl_platform(machine)
   299    370   
   300    371     for {set i 0} {$i < [llength $argv]} {incr i} {
   301         -    switch -- [lindex $argv $i] {
   302         -      -makefile {
          372  +    set x [lindex $argv $i]
          373  +    if {[regexp {^--[a-z]} $x]} {set x [string range $x 1 end]}
          374  +    switch -- $x {
          375  +      -srcdir {
   303    376           incr i
   304         -        set ::MAKEFILE [lindex $argv $i]
          377  +        set ::SRCDIR [file normalize [lindex $argv $i]]
   305    378         }
   306    379   
   307    380         -platform {
   308    381           incr i
   309    382           set platform [lindex $argv $i]
   310    383         }
   311    384   
   312    385         -quick {
   313         -        incr i
   314         -        set ::QUICK [lindex $argv $i]
          386  +        set ::QUICK 1
   315    387         }
   316    388   
   317    389         -config {
   318    390           incr i
   319    391           set config [lindex $argv $i]
   320    392         }
   321         -  
          393  +
          394  +      -buildonly {
          395  +        set ::BUILDONLY 1
          396  +      }
          397  +
          398  +      -dryrun {
          399  +        set ::DRYRUN 1
          400  +      }
          401  +
          402  +      -info {
          403  +        puts "Command-line Options:"
          404  +        puts "   --srcdir $::SRCDIR"
          405  +        puts "   --platform [list $platform]"
          406  +        puts "   --config [list $config]"
          407  +        if {$::QUICK}     {puts "   --quick"}
          408  +        if {$::BUILDONLY} {puts "   --buildonly"}
          409  +        if {$::DRYRUN}    {puts "   --dryrun"}
          410  +        puts "\nAvailable --platform options:"
          411  +        foreach y [lsort [array names ::Platforms]] {
          412  +          puts "   [list $y]"
          413  +        }
          414  +        puts "\nAvailable --config options:"
          415  +        foreach y [lsort [array names ::Configs]] {
          416  +          puts "   [list $y]"
          417  +        }
          418  +        exit
          419  +      }
          420  +
   322    421         default {
   323    422           puts stderr ""
   324    423           puts stderr [string trim $::USAGE_MESSAGE]
   325    424           exit -1
   326    425         }
   327    426       }
   328    427     }
   329    428   
   330         -  set ::MAKEFILE [file normalize $::MAKEFILE]
   331         -
   332    429     if {0==[info exists ::Platforms($platform)]} {
   333    430       puts "Unknown platform: $platform"
   334    431       puts -nonewline "Set the -platform option to "
   335    432       set print [list]
   336    433       foreach p [array names ::Platforms] {
   337    434         lappend print "\"$p\""
   338    435       }
................................................................................
   343    440   
   344    441     if {$config!=""} {
   345    442       if {[llength $config]==1} {lappend config fulltest}
   346    443       set ::CONFIGLIST $config
   347    444     } else {
   348    445       set ::CONFIGLIST $::Platforms($platform)
   349    446     }
   350         -  puts "Running the following configurations for $platform:"
          447  +  puts "Running the following test configurations for $platform:"
   351    448     puts "    [string trim $::CONFIGLIST]"
          449  +  puts -nonewline "Flags:"
          450  +  if {$::DRYRUN} {puts -nonewline " --dryrun"}
          451  +  if {$::BUILDONLY} {puts -nonewline " --buildonly"}
          452  +  if {$::QUICK} {puts -nonewline " --quick"}
          453  +  puts ""
   352    454   }
   353    455   
   354    456   # Main routine.
   355    457   #
   356    458   proc main {argv} {
   357    459   
   358    460     # Process any command line options.
   359    461     process_options $argv
          462  +  puts [string repeat * 79]
   360    463   
          464  +  set ::NERR 0
          465  +  set ::NTEST 0
          466  +  set ::NTESTCASE 0
          467  +  set ::NERRCASE 0
          468  +  set STARTTIME [clock seconds]
   361    469     foreach {zConfig target} $::CONFIGLIST {
   362    470       if {$::QUICK} {set target test}
          471  +    if {$::BUILDONLY} {set target testfixture}
   363    472       set config_options $::Configs($zConfig)
   364    473   
          474  +    incr NTEST
   365    475       run_test_suite $zConfig $target $config_options
   366    476   
   367    477       # If the configuration included the SQLITE_DEBUG option, then remove
   368    478       # it and run veryquick.test. If it did not include the SQLITE_DEBUG option
   369    479       # add it and run veryquick.test.
   370         -    if {$target!="checksymbols"} {
          480  +    if {$target!="checksymbols" && !$::BUILDONLY} {
   371    481         set debug_idx [lsearch -glob $config_options -DSQLITE_DEBUG*]
          482  +      set xtarget $target
          483  +      regsub -all {fulltest[a-z]*} $xtarget test xtarget
   372    484         if {$debug_idx < 0} {
   373         -        run_test_suite "${zConfig}_debug" test [
   374         -          concat $config_options -DSQLITE_DEBUG=1
   375         -        ]
          485  +        incr NTEST
          486  +        append config_options " -DSQLITE_DEBUG=1"
          487  +        run_test_suite "${zConfig}_debug" $xtarget $config_options
   376    488         } else {
   377         -        run_test_suite "${zConfig}_ndebug" test [
   378         -          lreplace $config_options $debug_idx $debug_idx
   379         -        ]
          489  +        incr NTEST
          490  +        regsub { *-DSQLITE_MEMDEBUG[^ ]* *} $config_options { } config_options
          491  +        regsub { *-DSQLITE_DEBUG[^ ]* *} $config_options { } config_options
          492  +        run_test_suite "${zConfig}_ndebug" $xtarget $config_options
   380    493         }
   381    494       }
   382         -
   383    495     }
          496  +
          497  +  set elapsetime [expr {[clock seconds]-$STARTTIME}]
          498  +  set hr [expr {$elapsetime/3600}]
          499  +  set min [expr {($elapsetime/60)%60}]
          500  +  set sec [expr {$elapsetime%60}]
          501  +  set etime [format (%02d:%02d:%02d) $hr $min $sec]
          502  +  puts [string repeat * 79]
          503  +  puts "$::NERRCASE failures of $::NTESTCASE tests run in $etime"
   384    504   }
   385    505   
   386    506   main $argv

Changes to test/sort.test.

    12     12   # This file implements regression tests for SQLite library.  The
    13     13   # focus of this file is testing the sorter (code in vdbesort.c).
    14     14   #
    15     15   
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   set testprefix sort
           19  +db close
           20  +sqlite3_shutdown
           21  +sqlite3_config_pmasz 10
           22  +sqlite3_initialize
           23  +sqlite3 db test.db
    19     24   
    20     25   # Create a bunch of data to sort against
    21     26   #
    22     27   do_test sort-1.0 {
    23     28     execsql {
    24     29       CREATE TABLE t1(
    25     30          n int,

Changes to test/sort2.test.

    13     13   # Specifically, the tests in this file attempt to verify that 
    14     14   # multi-threaded sorting works.
    15     15   #
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   set testprefix sort2
           20  +db close
           21  +sqlite3_shutdown
           22  +sqlite3_config_pmasz 10
           23  +sqlite3_initialize
           24  +sqlite3 db test.db
    20     25   
    21     26   foreach {tn script} {
    22     27     1 { }
    23     28     2 {
    24     29       catch { db close }
    25     30       reset_db
    26     31       catch { db eval {PRAGMA threads=7} }

Changes to test/sort4.test.

    13     13   # The tests in this file are brute force tests of the multi-threaded
    14     14   # sorter.
    15     15   #
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   set testprefix sort4
           20  +db close
           21  +sqlite3_shutdown
           22  +sqlite3_config_pmasz 10
           23  +sqlite3_initialize
           24  +sqlite3 db test.db
           25  +
    20     26   
    21     27   # Configure the sorter to use 3 background threads.
    22     28   db eval {PRAGMA threads=3}
    23     29   
    24     30   # Minimum number of seconds to run for. If the value is 0, each test
    25     31   # is run exactly once. Otherwise, tests are repeated until the timeout
    26     32   # expires.

Changes to test/sortfault.test.

    13     13   # Specifically, it tests the effects of fault injection on the sorter
    14     14   # module (code in vdbesort.c).
    15     15   #
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   set testprefix sortfault
           20  +db close
           21  +sqlite3_shutdown
           22  +sqlite3_config_pmasz 10
           23  +sqlite3_initialize
           24  +sqlite3 db test.db
           25  +
    20     26   
    21     27   do_execsql_test 1.0 {
    22     28     PRAGMA cache_size = 5;
    23     29   }
    24     30   
    25     31   foreach {tn mmap_limit nWorker tmpstore threadsmode fakeheap lookaside} {
    26     32             1          0       0     file multithread    false     false

Changes to test/threadtest3.c.

     1         -
     2      1   /*
            2  +** 2010-07-22
            3  +**
            4  +** The author disclaims copyright to this source code.  In place of
            5  +** a legal notice, here is a blessing:
            6  +**
            7  +**    May you do good and not evil.
            8  +**    May you find forgiveness for yourself and forgive others.
            9  +**    May you share freely, never taking more than you give.
           10  +**
           11  +*************************************************************************
           12  +**
     3     13   ** The code in this file runs a few multi-threaded test cases using the
     4     14   ** SQLite library. It can be compiled to an executable on unix using the
     5     15   ** following command:
     6     16   **
     7     17   **   gcc -O2 threadtest3.c sqlite3.c -ldl -lpthread -lm
     8     18   **
     9         -** Then run the compiled program. The exit status is non-zero if any tests
    10         -** failed (hopefully there is also some output to stdout to clarify what went
    11         -** wrong).
           19  +** Even though threadtest3.c is the only C source code file mentioned on
           20  +** the compiler command-line, #include macros are used to pull in additional
           21  +** C code files named "tt3_*.c".
    12     22   **
    13         -** There are three parts to the code in this file, in the following order:
           23  +** After compiling, run this program with an optional argument telling
           24  +** which test to run.  All tests are run if no argument is given.  The
           25  +** argument can be a glob pattern to match multiple tests.  Examples:
    14     26   **
    15         -**   1. Code for the SQL aggregate function md5sum() copied from 
    16         -**      tclsqlite.c in the SQLite distribution. The names of all the 
    17         -**      types and functions in this section begin with "MD5" or "md5".
    18         -**
    19         -**   2. A set of utility functions that may be used to implement
    20         -**      multi-threaded test cases. These are all called by test code
    21         -**      via macros that help with error reporting. The macros are defined
    22         -**      immediately below this comment.
           27  +**        ./a.out                 -- Run all tests
           28  +**        ./a.out walthread3      -- Run the "walthread3" test
           29  +**        ./a.out 'wal*'          -- Run all of the wal* tests
           30  +**        ./a.out --help          -- List all available tests
    23     31   **
    24         -**   3. The test code itself. And a main() routine to drive the test 
    25         -**      code.
           32  +** The exit status is non-zero if any test fails.
           33  +*/
           34  +
           35  +/* 
           36  +** The "Set Error Line" macro.
    26     37   */
    27         -
    28         -/*************************************************************************
    29         -** Start of test code/infrastructure interface macros.
    30         -**
    31         -** The following macros constitute the interface between the test
    32         -** programs and the test infrastructure. Test infrastructure code 
    33         -** does not itself use any of these macros. Test code should not
    34         -** call any of the macroname_x() functions directly.
    35         -**
    36         -** See the header comments above the corresponding macroname_x()
    37         -** function for a description of each interface.
    38         -*/
           38  +#define SEL(e) ((e)->iLine = ((e)->rc ? (e)->iLine : __LINE__))
    39     39   
    40     40   /* Database functions */
    41     41   #define opendb(w,x,y,z)         (SEL(w), opendb_x(w,x,y,z))
    42     42   #define closedb(y,z)            (SEL(y), closedb_x(y,z))
    43     43   
    44     44   /* Functions to execute SQL */
    45     45   #define sql_script(x,y,z)       (SEL(x), sql_script_x(x,y,z))
................................................................................
   387    387     char zBuf[33];
   388    388     p = sqlite3_aggregate_context(context, sizeof(*p));
   389    389     MD5Final(digest,p);
   390    390     MD5DigestToBase16(digest, zBuf);
   391    391     sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
   392    392   }
   393    393   
   394         -/*************************************************************************
          394  +/*
   395    395   ** End of copied md5sum() code.
   396         -*/
          396  +**************************************************************************/
   397    397   
   398    398   typedef sqlite3_int64 i64;
   399    399   
   400    400   typedef struct Error Error;
   401    401   typedef struct Sqlite Sqlite;
   402    402   typedef struct Statement Statement;
   403    403   
................................................................................
   443    443     sqlite3_free(p->zErr);
   444    444     p->zErr = 0;
   445    445     p->rc = 0;
   446    446   }
   447    447   
   448    448   static void print_err(Error *p){
   449    449     if( p->rc!=SQLITE_OK ){
   450         -    printf("Error: (%d) \"%s\" at line %d\n", p->rc, p->zErr, p->iLine);
   451         -    nGlobalErr++;
          450  +    int isWarn = 0;
          451  +    if( p->rc==SQLITE_SCHEMA ) isWarn = 1;
          452  +    if( sqlite3_strglob("* - no such table: *",p->zErr)==0 ) isWarn = 1;
          453  +    printf("%s: (%d) \"%s\" at line %d\n", isWarn ? "Warning" : "Error",
          454  +            p->rc, p->zErr, p->iLine);
          455  +    if( !isWarn ) nGlobalErr++;
          456  +    fflush(stdout);
   452    457     }
   453    458   }
   454    459   
   455    460   static void print_and_free_err(Error *p){
   456    461     print_err(p);
   457    462     free_err(p);
   458    463   }
................................................................................
   781    786       pNext = p->pNext;
   782    787       int rc;
   783    788       rc = pthread_join(p->tid, &ret);
   784    789       if( rc!=0 ){
   785    790         if( pErr->rc==SQLITE_OK ) system_error(pErr, rc);
   786    791       }else{
   787    792         printf("Thread %d says: %s\n", p->iTid, (ret==0 ? "..." : (char *)ret));
          793  +      fflush(stdout);
   788    794       }
   789    795       sqlite3_free(p);
   790    796     }
   791    797     pThreads->pThread = 0;
   792    798   }
   793    799   
   794    800   static i64 filesize_x(
................................................................................
   894    900       }else{
   895    901         ret = (t >= timelimit);
   896    902       }
   897    903     }
   898    904     return ret;
   899    905   }
   900    906   
   901         -/* 
   902         -** The "Set Error Line" macro.
   903         -*/
   904         -#define SEL(e) ((e)->iLine = ((e)->rc ? (e)->iLine : __LINE__))
   905         -
   906    907   
   907    908   /*************************************************************************
   908    909   **************************************************************************
   909    910   **************************************************************************
   910    911   ** End infrastructure. Begin tests.
   911    912   */
   912    913   
................................................................................
   980    981     sql_script(&err, &db,
   981    982         "PRAGMA journal_mode = WAL;"
   982    983         "CREATE TABLE t1(x PRIMARY KEY);"
   983    984         "INSERT INTO t1 VALUES(randomblob(100));"
   984    985         "INSERT INTO t1 VALUES(randomblob(100));"
   985    986         "INSERT INTO t1 SELECT md5sum(x) FROM t1;"
   986    987     );
          988  +  closedb(&err, &db);
   987    989   
   988    990     setstoptime(&err, nMs);
   989    991     for(i=0; i<WALTHREAD1_NTHREAD; i++){
   990    992       launch_thread(&err, &threads, walthread1_thread, 0);
   991    993     }
   992    994     launch_thread(&err, &threads, walthread1_ckpt_thread, 0);
   993    995     join_all_threads(&err, &threads);
................................................................................
  1423   1425   #include "tt3_index.c"
  1424   1426   #include "tt3_lookaside1.c"
  1425   1427   #include "tt3_vacuum.c"
  1426   1428   #include "tt3_stress.c"
  1427   1429   
  1428   1430   int main(int argc, char **argv){
  1429   1431     struct ThreadTest {
  1430         -    void (*xTest)(int);
  1431         -    const char *zTest;
  1432         -    int nMs;
         1432  +    void (*xTest)(int);   /* Routine for running this test */
         1433  +    const char *zTest;    /* Name of this test */
         1434  +    int nMs;              /* How long to run this test, in milliseconds */
  1433   1435     } aTest[] = {
  1434   1436       { walthread1, "walthread1", 20000 },
  1435   1437       { walthread2, "walthread2", 20000 },
  1436   1438       { walthread3, "walthread3", 20000 },
  1437   1439       { walthread4, "walthread4", 20000 },
  1438         -    { walthread5, "walthread5",  1000 },
  1439   1440       { walthread5, "walthread5",  1000 },
  1440   1441       
  1441   1442       { cgt_pager_1,      "cgt_pager_1", 0 },
  1442   1443       { dynamic_triggers, "dynamic_triggers", 20000 },
  1443   1444   
  1444   1445       { checkpoint_starvation_1, "checkpoint_starvation_1", 10000 },
  1445   1446       { checkpoint_starvation_2, "checkpoint_starvation_2", 10000 },
................................................................................
  1446   1447   
  1447   1448       { create_drop_index_1, "create_drop_index_1", 10000 },
  1448   1449       { lookaside1,          "lookaside1", 10000 },
  1449   1450       { vacuum1,             "vacuum1", 10000 },
  1450   1451       { stress1,             "stress1", 10000 },
  1451   1452       { stress2,             "stress2", 60000 },
  1452   1453     };
  1453         -
  1454         -  int i;
  1455         -  int bTestfound = 0;
         1454  +  static char *substArgv[] = { 0, "*", 0 };
         1455  +  int i, iArg;
         1456  +  int nTestfound = 0;
  1456   1457   
  1457   1458     sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
  1458         -  sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
  1459         -
  1460         -  for(i=0; i<sizeof(aTest)/sizeof(aTest[0]); i++){
  1461         -    char const *z = aTest[i].zTest;
  1462         -    if( argc>1 ){
  1463         -      int iArg;
  1464         -      for(iArg=1; iArg<argc; iArg++){
  1465         -        if( 0==sqlite3_strglob(argv[iArg], z) ) break;
         1459  +  if( argc<2 ){
         1460  +    argc = 2;
         1461  +    argv = substArgv;
         1462  +  }
         1463  +  for(iArg=1; iArg<argc; iArg++){
         1464  +    for(i=0; i<sizeof(aTest)/sizeof(aTest[0]); i++){
         1465  +      if( sqlite3_strglob(argv[iArg],aTest[i].zTest)==0 ) break;
         1466  +    }
         1467  +    if( i>=sizeof(aTest)/sizeof(aTest[0]) ) goto usage;   
         1468  +  }
         1469  +  for(iArg=1; iArg<argc; iArg++){
         1470  +    for(i=0; i<sizeof(aTest)/sizeof(aTest[0]); i++){
         1471  +      char const *z = aTest[i].zTest;
         1472  +      if( sqlite3_strglob(argv[iArg],z)==0 ){
         1473  +        printf("Running %s for %d seconds...\n", z, aTest[i].nMs/1000);
         1474  +        fflush(stdout);
         1475  +        aTest[i].xTest(aTest[i].nMs);
         1476  +        nTestfound++;
  1466   1477         }
  1467         -      if( iArg==argc ) continue;
  1468   1478       }
  1469         -
  1470         -    printf("Running %s for %d seconds...\n", z, aTest[i].nMs/1000);
  1471         -    aTest[i].xTest(aTest[i].nMs);
  1472         -    bTestfound++;
  1473   1479     }
  1474         -  if( bTestfound==0 ) goto usage;
         1480  +  if( nTestfound==0 ) goto usage;
  1475   1481   
  1476         -  printf("Total of %d errors across all tests\n", nGlobalErr);
         1482  +  printf("%d errors out of %d tests\n", nGlobalErr, nTestfound);
  1477   1483     return (nGlobalErr>0 ? 255 : 0);
  1478   1484   
  1479   1485    usage:
  1480   1486     printf("Usage: %s [testname|testprefix*]...\n", argv[0]);
  1481   1487     printf("Available tests are:\n");
  1482   1488     for(i=0; i<sizeof(aTest)/sizeof(aTest[0]); i++){
  1483   1489       printf("   %s\n", aTest[i].zTest);
  1484   1490     }
  1485   1491   
  1486   1492     return 254;
  1487   1493   }
  1488         -
  1489         -

Changes to test/tt3_checkpoint.c.

     1      1   /*
     2         -** 2001 September 15
            2  +** 2011-02-02
     3      3   **
     4      4   ** The author disclaims copyright to this source code.  In place of
     5      5   ** a legal notice, here is a blessing:
     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
................................................................................
   142    142     CheckpointStarvationCtx ctx = { SQLITE_CHECKPOINT_RESTART, 0 };
   143    143     checkpoint_starvation_main(nMs, &ctx);
   144    144     if( ctx.nMaxFrame>CHECKPOINT_STARVATION_FRAMELIMIT+10 ){
   145    145       test_error(&err, "WAL grew too large - %d frames", ctx.nMaxFrame);
   146    146     }
   147    147     print_and_free_err(&err);
   148    148   }
   149         -
   150         -

Changes to test/wal5.test.

   370    370     #
   371    371     do_multiclient_test tn {
   372    372   
   373    373       code1 $do_wal_checkpoint
   374    374       code2 $do_wal_checkpoint
   375    375       code3 $do_wal_checkpoint
   376    376   
   377         -    do_test 3.$tn.1 {
          377  +    do_test 4.$tn.1 {
   378    378         sql1 {
   379    379           PRAGMA page_size = 1024;
          380  +        PRAGMA auto_vacuum = 0;
   380    381           PRAGMA journal_mode = WAL;
   381    382           PRAGMA synchronous = normal;
   382    383           CREATE TABLE t1(x, y);
   383    384           CREATE INDEX i1 ON t1(x, y);
   384    385           INSERT INTO t1 VALUES(1, 2);
   385    386           INSERT INTO t1 VALUES(3, 4);
   386    387         }
   387    388         file size test.db-wal
   388    389       } [wal_file_size 8 1024]
   389    390   
   390         -    do_test 3.$tn.2 { do_wal_checkpoint db -mode truncate } {0 0 0}
   391         -    do_test 3.$tn.3 { file size test.db-wal } 0
          391  +    do_test 4.$tn.2 { do_wal_checkpoint db -mode truncate } {0 0 0}
          392  +    do_test 4.$tn.3 { file size test.db-wal } 0
   392    393   
   393         -    do_test 3.$tn.4 {
          394  +    do_test 4.$tn.4 {
   394    395         sql2 { SELECT * FROM t1 }
   395    396       } {1 2 3 4}
   396    397   
   397         -    do_test 3.$tn.5 {
          398  +    do_test 4.$tn.5 {
   398    399         sql2 { INSERT INTO t1 VALUES('a', 'b') }
   399    400         file size test.db-wal
   400    401       } [wal_file_size 2 1024]
   401    402   
   402    403     }
   403    404   }
   404    405   
   405    406   
   406    407   finish_test

Added test/without_rowid6.test.

            1  +# 2014-12-28
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +#
           12  +# Verify that WITHOUT ROWID tables work correctly when the PRIMARY KEY
           13  +# has redundant columns.
           14  +#
           15  +
           16  +set testdir [file dirname $argv0]
           17  +source $testdir/tester.tcl
           18  +
           19  +do_execsql_test without_rowid6-100 {
           20  +  CREATE TABLE t1(a,b,c,d,e, PRIMARY KEY(a,b,c,a,b,c,d,a,b,c)) WITHOUT ROWID;
           21  +  CREATE INDEX t1a ON t1(b, b);
           22  +  WITH RECURSIVE
           23  +    c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<1000)
           24  +  INSERT INTO t1(a,b,c,d,e) SELECT i, i+1000, printf('x%dy',i), 0, 0 FROM c;
           25  +  ANALYZE;
           26  +} {}
           27  +do_execsql_test without_rowid6-110 {
           28  +  SELECT c FROM t1 WHERE a=123;
           29  +} {x123y}
           30  +do_execsql_test without_rowid6-120 {
           31  +  SELECT c FROM t1 WHERE b=1123;
           32  +} {x123y}
           33  +do_execsql_test without_rowid6-130 {
           34  +  SELECT c FROM t1 ORDER BY a DESC LIMIT 5;
           35  +} {x1000y x999y x998y x997y x996y}
           36  +do_execsql_test without_rowid6-140 {
           37  +  SELECT c FROM t1 ORDER BY b LIMIT 5;
           38  +} {x1y x2y x3y x4y x5y}
           39  +
           40  +
           41  +finish_test

Changes to tool/lemon.c.

  1493   1493     static int mhflag = 0;
  1494   1494     static int nolinenosflag = 0;
  1495   1495     static int noResort = 0;
  1496   1496     static struct s_options options[] = {
  1497   1497       {OPT_FLAG, "b", (char*)&basisflag, "Print only the basis in report."},
  1498   1498       {OPT_FLAG, "c", (char*)&compress, "Don't compress the action table."},
  1499   1499       {OPT_FSTR, "D", (char*)handle_D_option, "Define an %ifdef macro."},
  1500         -    {OPT_FSTR, "T", (char*)handle_T_option, "Specify a template file."},
         1500  +    {OPT_FSTR, "f", 0, "Ignored.  (Placeholder for -f compiler options.)"},
  1501   1501       {OPT_FLAG, "g", (char*)&rpflag, "Print grammar without actions."},
         1502  +    {OPT_FSTR, "I", 0, "Ignored.  (Placeholder for '-I' compiler options.)"},
  1502   1503       {OPT_FLAG, "m", (char*)&mhflag, "Output a makeheaders compatible file."},
  1503   1504       {OPT_FLAG, "l", (char*)&nolinenosflag, "Do not print #line statements."},
         1505  +    {OPT_FSTR, "O", 0, "Ignored.  (Placeholder for '-O' compiler options.)"},
  1504   1506       {OPT_FLAG, "p", (char*)&showPrecedenceConflict,
  1505   1507                       "Show conflicts resolved by precedence rules"},
  1506   1508       {OPT_FLAG, "q", (char*)&quiet, "(Quiet) Don't print the report file."},
  1507   1509       {OPT_FLAG, "r", (char*)&noResort, "Do not sort or renumber states"},
  1508   1510       {OPT_FLAG, "s", (char*)&statistics,
  1509   1511                                      "Print parser stats to standard output."},
  1510   1512       {OPT_FLAG, "x", (char*)&version, "Print the version number."},
         1513  +    {OPT_FSTR, "T", (char*)handle_T_option, "Specify a template file."},
         1514  +    {OPT_FSTR, "W", 0, "Ignored.  (Placeholder for '-W' compiler options.)"},
  1511   1515       {OPT_FLAG,0,0,0}
  1512   1516     };
  1513   1517     int i;
  1514   1518     int exitcode;
  1515   1519     struct lemon lem;
  1516   1520   
  1517   1521     OptInit(argv,options,stderr);
................................................................................
  1808   1812     v = argv[i][0]=='-' ? 1 : 0;
  1809   1813     if( op[j].label==0 ){
  1810   1814       if( err ){
  1811   1815         fprintf(err,"%sundefined option.\n",emsg);
  1812   1816         errline(i,1,err);
  1813   1817       }
  1814   1818       errcnt++;
         1819  +  }else if( op[j].arg==0 ){
         1820  +    /* Ignore this option */
  1815   1821     }else if( op[j].type==OPT_FLAG ){
  1816   1822       *((int*)op[j].arg) = v;
  1817   1823     }else if( op[j].type==OPT_FFLAG ){
  1818   1824       (*(void(*)(int))(op[j].arg))(v);
  1819   1825     }else if( op[j].type==OPT_FSTR ){
  1820   1826       (*(void(*)(char *))(op[j].arg))(&argv[i][2]);
  1821   1827     }else{
................................................................................
  1997   2003       switch( op[i].type ){
  1998   2004         case OPT_FLAG:
  1999   2005         case OPT_FFLAG:
  2000   2006           fprintf(errstream,"  -%-*s  %s\n",max,op[i].label,op[i].message);
  2001   2007           break;
  2002   2008         case OPT_INT:
  2003   2009         case OPT_FINT:
  2004         -        fprintf(errstream,"  %s=<integer>%*s  %s\n",op[i].label,
         2010  +        fprintf(errstream,"  -%s<integer>%*s  %s\n",op[i].label,
  2005   2011             (int)(max-lemonStrlen(op[i].label)-9),"",op[i].message);
  2006   2012           break;
  2007   2013         case OPT_DBL:
  2008   2014         case OPT_FDBL:
  2009         -        fprintf(errstream,"  %s=<real>%*s  %s\n",op[i].label,
         2015  +        fprintf(errstream,"  -%s<real>%*s  %s\n",op[i].label,
  2010   2016             (int)(max-lemonStrlen(op[i].label)-6),"",op[i].message);
  2011   2017           break;
  2012   2018         case OPT_STR:
  2013   2019         case OPT_FSTR:
  2014         -        fprintf(errstream,"  %s=<string>%*s  %s\n",op[i].label,
         2020  +        fprintf(errstream,"  -%s<string>%*s  %s\n",op[i].label,
  2015   2021             (int)(max-lemonStrlen(op[i].label)-8),"",op[i].message);
  2016   2022           break;
  2017   2023       }
  2018   2024     }
  2019   2025   }
  2020   2026   /*********************** From the file "parse.c" ****************************/
  2021   2027   /*

Changes to tool/mkpragmatab.tcl.

   242    242     IF:   !defined(SQLITE_OMIT_INTEGRITY_CHECK)
   243    243   
   244    244     NAME: encoding
   245    245     IF:   !defined(SQLITE_OMIT_UTF16)
   246    246   
   247    247     NAME: schema_version
   248    248     TYPE: HEADER_VALUE
          249  +  ARG:  BTREE_SCHEMA_VERSION
   249    250     IF:   !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
   250    251   
   251    252     NAME: user_version
   252    253     TYPE: HEADER_VALUE
          254  +  ARG:  BTREE_USER_VERSION
          255  +  IF:   !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
          256  +
          257  +  NAME: data_version
          258  +  TYPE: HEADER_VALUE
          259  +  ARG:  BTREE_DATA_VERSION
          260  +  FLAG: ReadOnly
   253    261     IF:   !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
   254    262   
   255    263     NAME: freelist_count
   256    264     TYPE: HEADER_VALUE
          265  +  ARG:  BTREE_FREE_PAGE_COUNT
          266  +  FLAG: ReadOnly
   257    267     IF:   !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
   258    268   
   259    269     NAME: application_id
   260    270     TYPE: HEADER_VALUE
          271  +  ARG:  BTREE_APPLICATION_ID
   261    272     IF:   !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
   262    273   
   263    274     NAME: compile_options
   264    275     IF:   !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
   265    276   
   266    277     NAME: wal_checkpoint
   267    278     FLAG: NeedSchema

Changes to tool/mksqlite3c.tcl.

   209    209               set line {const char sqlite3_version[] = SQLITE_VERSION;}
   210    210             }
   211    211             regsub {^SQLITE_EXTERN } $line {} line
   212    212             puts $out "SQLITE_API $line"
   213    213           }
   214    214         } elseif {[regexp {^(SQLITE_EXTERN )?void \(\*sqlite3IoTrace\)} $line]} {
   215    215           regsub {^SQLITE_EXTERN } $line {} line
   216         -        puts $out "SQLITE_PRIVATE $line"
          216  +        puts $out $line
   217    217         } elseif {[regexp {^void \(\*sqlite3Os} $line]} {
   218    218           puts $out "SQLITE_PRIVATE $line"
   219    219         } else {
   220    220           puts $out $line
   221    221         }
   222    222       } else {
   223    223         puts $out $line