/ Check-in [9b4d561f]
Login

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

Overview
Comment:Merge trunk changes into this branch.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | window-functions
Files: files | file ages | folders
SHA3-256: 9b4d561f68febdab6624d8c567fb4357bf67dda500664cf708d16a76f37b8ec1
User & Date: dan 2019-03-04 21:08:53
Wiki:window-functions
Context
2019-03-05
19:29
Extend windowCodeStep() to handle any ROWS PRECEDING/FOLLOWING frame specification. check-in: af0ea136 user: dan tags: window-functions
2019-03-04
21:08
Merge trunk changes into this branch. check-in: 9b4d561f user: dan tags: window-functions
21:07
Support some "ROWS BETWEEN N PRECEDING AND M FOLLOWING" window functions without caching entire partitions. check-in: e7a91f12 user: dan tags: window-functions
07:15
Fix a problem preventing compilation with SQLITE_OMIT_UTF16. check-in: 906d1fd8 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Makefile.in.

  1420   1420   	$(INSTALL) -d $(DESTDIR)$(includedir)
  1421   1421   	$(INSTALL) -m 0644 sqlite3.h $(DESTDIR)$(includedir)
  1422   1422   	$(INSTALL) -m 0644 $(TOP)/src/sqlite3ext.h $(DESTDIR)$(includedir)
  1423   1423   	$(INSTALL) -d $(DESTDIR)$(pkgconfigdir)
  1424   1424   	$(INSTALL) -m 0644 sqlite3.pc $(DESTDIR)$(pkgconfigdir)
  1425   1425   
  1426   1426   pkgIndex.tcl:
  1427         -	echo 'package ifneeded sqlite3 $(RELEASE) [list load $(TCLLIBDIR)/libtclsqlite3$(SHLIB_SUFFIX) sqlite3]' > $@
         1427  +	echo 'package ifneeded sqlite3 $(RELEASE) [list load [file join $$dir libtclsqlite3[info sharedlibextension]] sqlite3]' > $@
  1428   1428   tcl_install:	lib_install libtclsqlite3.la pkgIndex.tcl
  1429   1429   	$(INSTALL) -d $(DESTDIR)$(TCLLIBDIR)
  1430   1430   	$(LTINSTALL) libtclsqlite3.la $(DESTDIR)$(TCLLIBDIR)
  1431   1431   	rm -f $(DESTDIR)$(TCLLIBDIR)/libtclsqlite3.la $(DESTDIR)$(TCLLIBDIR)/libtclsqlite3.a
  1432   1432   	$(INSTALL) -m 0644 pkgIndex.tcl $(DESTDIR)$(TCLLIBDIR)
  1433   1433   
  1434   1434   clean:

Changes to ext/fts3/README.tokenizers.

    48     48     returned. If only one argument is passed, a pointer to the tokenizer
    49     49     implementation currently registered as <tokenizer-name> is returned,
    50     50     encoded as a blob. Or, if no such tokenizer exists, an SQL exception
    51     51     (error) is raised.
    52     52   
    53     53     SECURITY: If the fts3 extension is used in an environment where potentially
    54     54       malicious users may execute arbitrary SQL (i.e. gears), they should be
    55         -    prevented from invoking the fts3_tokenizer() function, possibly using the
    56         -    authorisation callback.
           55  +    prevented from invoking the fts3_tokenizer() function.  The
           56  +    fts3_tokenizer() function is disabled by default. It is only enabled
           57  +    by SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER. Do not enable it in
           58  +    security sensitive environments.
    57     59   
    58     60     See "Sample code" below for an example of calling the fts3_tokenizer()
    59     61     function from C code.
    60     62   
    61     63   3. ICU Library Tokenizers
    62     64   
    63     65     If this extension is compiled with the SQLITE_ENABLE_ICU pre-processor 

Changes to ext/fts3/fts3_snippet.c.

   425    425   
   426    426     for(i=0; i<pIter->nPhrase; i++){
   427    427       SnippetPhrase *pPhrase = &pIter->aPhrase[i];
   428    428       if( pPhrase->pTail ){
   429    429         char *pCsr = pPhrase->pTail;
   430    430         int iCsr = pPhrase->iTail;
   431    431   
   432         -      while( iCsr<(iStart+pIter->nSnippet) ){
          432  +      while( iCsr<(iStart+pIter->nSnippet) && iCsr>=iStart ){
   433    433           int j;
   434    434           u64 mPhrase = (u64)1 << i;
   435    435           u64 mPos = (u64)1 << (iCsr - iStart);
   436    436           assert( iCsr>=iStart && (iCsr - iStart)<=64 );
   437    437           assert( i>=0 && i<=64 );
   438    438           if( (mCover|mCovered)&mPhrase ){
   439    439             iScore++;
................................................................................
  1539   1539     int rc;
  1540   1540   
  1541   1541     UNUSED_PARAMETER(iPhrase);
  1542   1542     rc = sqlite3Fts3EvalPhrasePoslist(p->pCsr, pExpr, p->iCol, &pList);
  1543   1543     nTerm = pExpr->pPhrase->nToken;
  1544   1544     if( pList ){
  1545   1545       fts3GetDeltaPosition(&pList, &iPos);
  1546         -    assert( iPos>=0 );
         1546  +    assert_fts3_nc( iPos>=0 );
  1547   1547     }
  1548   1548   
  1549   1549     for(iTerm=0; iTerm<nTerm; iTerm++){
  1550   1550       TermOffset *pT = &p->aTerm[p->iTerm++];
  1551   1551       pT->iOff = nTerm-iTerm-1;
  1552   1552       pT->pList = pList;
  1553   1553       pT->iPos = iPos;
................................................................................
  1649   1649           }
  1650   1650         }
  1651   1651   
  1652   1652         if( !pTerm ){
  1653   1653           /* All offsets for this column have been gathered. */
  1654   1654           rc = SQLITE_DONE;
  1655   1655         }else{
  1656         -        assert( iCurrent<=iMinPos );
         1656  +        assert_fts3_nc( iCurrent<=iMinPos );
  1657   1657           if( 0==(0xFE&*pTerm->pList) ){
  1658   1658             pTerm->pList = 0;
  1659   1659           }else{
  1660   1660             fts3GetDeltaPosition(&pTerm->pList, &pTerm->iPos);
  1661   1661           }
  1662   1662           while( rc==SQLITE_OK && iCurrent<iMinPos ){
  1663   1663             rc = pMod->xNext(pC, &ZDUMMY, &NDUMMY, &iStart, &iEnd, &iCurrent);

Changes to ext/fts3/fts3_tokenizer.c.

   102    102       if( !pPtr ){
   103    103         char *zErr = sqlite3_mprintf("unknown tokenizer: %s", zName);
   104    104         sqlite3_result_error(context, zErr, -1);
   105    105         sqlite3_free(zErr);
   106    106         return;
   107    107       }
   108    108     }
   109         -  sqlite3_result_blob(context, (void *)&pPtr, sizeof(pPtr), SQLITE_TRANSIENT);
          109  +  if( fts3TokenizerEnabled(context) ){
          110  +    sqlite3_result_blob(context, (void *)&pPtr, sizeof(pPtr), SQLITE_TRANSIENT);
          111  +  }
   110    112   }
   111    113   
   112    114   int sqlite3Fts3IsIdChar(char c){
   113    115     static const char isFtsIdChar[] = {
   114    116         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 0x */
   115    117         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 1x */
   116    118         0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 2x */

Changes to ext/fts3/fts3_write.c.

  1344   1344         return SQLITE_OK;
  1345   1345       }
  1346   1346   
  1347   1347       fts3SegReaderSetEof(pReader);
  1348   1348   
  1349   1349       /* If iCurrentBlock>=iLeafEndBlock, this is an EOF condition. All leaf 
  1350   1350       ** blocks have already been traversed.  */
  1351         -    assert( pReader->iCurrentBlock<=pReader->iLeafEndBlock );
         1351  +#ifdef CORRUPT_DB
         1352  +    assert( pReader->iCurrentBlock<=pReader->iLeafEndBlock || CORRUPT_DB );
         1353  +#endif
  1352   1354       if( pReader->iCurrentBlock>=pReader->iLeafEndBlock ){
  1353   1355         return SQLITE_OK;
  1354   1356       }
  1355   1357   
  1356   1358       rc = sqlite3Fts3ReadBlock(
  1357   1359           p, ++pReader->iCurrentBlock, &pReader->aNode, &pReader->nNode, 
  1358   1360           (bIncr ? &pReader->nPopulate : 0)

Changes to ext/fts5/test/fts5aux.test.

   271    271   
   272    272   do_execsql_test 9.3 {
   273    273     SELECT rowid FROM t1('b:a AND b:b') ORDER BY rank;
   274    274   } {
   275    275     9 10
   276    276   }
   277    277   
          278  +#-------------------------------------------------------------------------
          279  +# Test that aux. functions may not be used in aggregate queries.
          280  +#
          281  +reset_db
          282  +do_execsql_test 10.0 {
          283  +  CREATE VIRTUAL TABLE t1 USING fts5(x, y, z);
          284  +  INSERT INTO t1 VALUES('a', 'one two', 1);
          285  +  INSERT INTO t1 VALUES('b', 'two three', 2);
          286  +  INSERT INTO t1 VALUES('c', 'three four', 1);
          287  +  INSERT INTO t1 VALUES('d', 'four five', 2);
          288  +  INSERT INTO t1 VALUES('e', 'five six', 1);
          289  +  INSERT INTO t1 VALUES('f', 'six seven', 2);
          290  +}
          291  +
          292  +proc firstcol {cmd} { $cmd xColumnText 0 }
          293  +sqlite3_fts5_create_function db firstcol firstcol
          294  +
          295  +do_execsql_test 10.1.1 {
          296  +  SELECT firstcol(t1) FROM t1
          297  +} {a b c d e f}
          298  +do_execsql_test 10.1.2 {
          299  +  SELECT group_concat(x, '.') FROM t1
          300  +} {a.b.c.d.e.f}
          301  +
          302  +do_catchsql_test 10.1.3 {
          303  +  SELECT group_concat(firstcol(t1), '.') FROM t1
          304  +} {1 {unable to use function firstcol in the requested context}}
   278    305   
          306  +do_catchsql_test 10.1.4 {
          307  +  SELECT group_concat(firstcol(t1), '.') FROM t1 GROUP BY rowid
          308  +} {1 {unable to use function firstcol in the requested context}}
   279    309   
   280    310   finish_test
          311  +

Changes to ext/misc/fileio.c.

   148    148     db = sqlite3_context_db_handle(ctx);
   149    149     mxBlob = sqlite3_limit(db, SQLITE_LIMIT_LENGTH, -1);
   150    150     if( nIn>mxBlob ){
   151    151       sqlite3_result_error_code(ctx, SQLITE_TOOBIG);
   152    152       fclose(in);
   153    153       return;
   154    154     }
   155         -  pBuf = sqlite3_malloc64( nIn );
          155  +  pBuf = sqlite3_malloc64( nIn ? nIn : 1 );
   156    156     if( pBuf==0 ){
   157    157       sqlite3_result_error_nomem(ctx);
   158    158       fclose(in);
   159    159       return;
   160    160     }
   161         -  if( 1==fread(pBuf, nIn, 1, in) ){
          161  +  if( nIn==fread(pBuf, 1, nIn, in) ){
   162    162       sqlite3_result_blob64(ctx, pBuf, nIn, sqlite3_free);
   163    163     }else{
   164    164       sqlite3_result_error_code(ctx, SQLITE_IOERR);
   165    165       sqlite3_free(pBuf);
   166    166     }
   167    167     fclose(in);
   168    168   }

Added ext/misc/fossildelta.c.

            1  +/*
            2  +** 2019-02-19
            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  +**
           13  +** This SQLite extension implements the delta functions used by the RBU
           14  +** extension. Three scalar functions and one table-valued function are
           15  +** implemented here:
           16  +**
           17  +**   delta_apply(X,D)     -- apply delta D to file X and return the result
           18  +**   delta_create(X,Y)    -- compute and return a delta that carries X into Y
           19  +**   delta_output_size(D) -- blob size in bytes output from applying delta D
           20  +**   delta_parse(D)       -- returns rows describing delta D
           21  +**
           22  +** The delta format is the Fossil delta format, described in a comment
           23  +** on the delete_create() function implementation below, and also at
           24  +**
           25  +**    https://www.fossil-scm.org/fossil/doc/trunk/www/delta_format.wiki
           26  +**
           27  +** This delta format is used by the RBU extension, which is the main
           28  +** reason that these routines are included in the extension library.
           29  +** RBU does not use this extension directly.  Rather, this extension is
           30  +** provided as a convenience to developers who want to analyze RBU files 
           31  +** that contain deltas.
           32  +*/
           33  +#include <string.h>
           34  +#include <assert.h>
           35  +#include <stdlib.h>
           36  +#include "sqlite3ext.h"
           37  +SQLITE_EXTENSION_INIT1
           38  +
           39  +/*
           40  +** The "u32" type must be an unsigned 32-bit integer.  Adjust this
           41  +*/
           42  +typedef unsigned int u32;
           43  +
           44  +/*
           45  +** Must be a 16-bit value
           46  +*/
           47  +typedef short int s16;
           48  +typedef unsigned short int u16;
           49  +
           50  +
           51  +/*
           52  +** The width of a hash window in bytes.  The algorithm only works if this
           53  +** is a power of 2.
           54  +*/
           55  +#define NHASH 16
           56  +
           57  +/*
           58  +** The current state of the rolling hash.
           59  +**
           60  +** z[] holds the values that have been hashed.  z[] is a circular buffer.
           61  +** z[i] is the first entry and z[(i+NHASH-1)%NHASH] is the last entry of
           62  +** the window.
           63  +**
           64  +** Hash.a is the sum of all elements of hash.z[].  Hash.b is a weighted
           65  +** sum.  Hash.b is z[i]*NHASH + z[i+1]*(NHASH-1) + ... + z[i+NHASH-1]*1.
           66  +** (Each index for z[] should be module NHASH, of course.  The %NHASH operator
           67  +** is omitted in the prior expression for brevity.)
           68  +*/
           69  +typedef struct hash hash;
           70  +struct hash {
           71  +  u16 a, b;         /* Hash values */
           72  +  u16 i;            /* Start of the hash window */
           73  +  char z[NHASH];    /* The values that have been hashed */
           74  +};
           75  +
           76  +/*
           77  +** Initialize the rolling hash using the first NHASH characters of z[]
           78  +*/
           79  +static void hash_init(hash *pHash, const char *z){
           80  +  u16 a, b, i;
           81  +  a = b = z[0];
           82  +  for(i=1; i<NHASH; i++){
           83  +    a += z[i];
           84  +    b += a;
           85  +  }
           86  +  memcpy(pHash->z, z, NHASH);
           87  +  pHash->a = a & 0xffff;
           88  +  pHash->b = b & 0xffff;
           89  +  pHash->i = 0;
           90  +}
           91  +
           92  +/*
           93  +** Advance the rolling hash by a single character "c"
           94  +*/
           95  +static void hash_next(hash *pHash, int c){
           96  +  u16 old = pHash->z[pHash->i];
           97  +  pHash->z[pHash->i] = c;
           98  +  pHash->i = (pHash->i+1)&(NHASH-1);
           99  +  pHash->a = pHash->a - old + c;
          100  +  pHash->b = pHash->b - NHASH*old + pHash->a;
          101  +}
          102  +
          103  +/*
          104  +** Return a 32-bit hash value
          105  +*/
          106  +static u32 hash_32bit(hash *pHash){
          107  +  return (pHash->a & 0xffff) | (((u32)(pHash->b & 0xffff))<<16);
          108  +}
          109  +
          110  +/*
          111  +** Compute a hash on NHASH bytes.
          112  +**
          113  +** This routine is intended to be equivalent to:
          114  +**    hash h;
          115  +**    hash_init(&h, zInput);
          116  +**    return hash_32bit(&h);
          117  +*/
          118  +static u32 hash_once(const char *z){
          119  +  u16 a, b, i;
          120  +  a = b = z[0];
          121  +  for(i=1; i<NHASH; i++){
          122  +    a += z[i];
          123  +    b += a;
          124  +  }
          125  +  return a | (((u32)b)<<16);
          126  +}
          127  +
          128  +/*
          129  +** Write an base-64 integer into the given buffer.
          130  +*/
          131  +static void putInt(unsigned int v, char **pz){
          132  +  static const char zDigits[] =
          133  +    "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~";
          134  +  /*  123456789 123456789 123456789 123456789 123456789 123456789 123 */
          135  +  int i, j;
          136  +  char zBuf[20];
          137  +  if( v==0 ){
          138  +    *(*pz)++ = '0';
          139  +    return;
          140  +  }
          141  +  for(i=0; v>0; i++, v>>=6){
          142  +    zBuf[i] = zDigits[v&0x3f];
          143  +  }
          144  +  for(j=i-1; j>=0; j--){
          145  +    *(*pz)++ = zBuf[j];
          146  +  }
          147  +}
          148  +
          149  +/*
          150  +** Read bytes from *pz and convert them into a positive integer.  When
          151  +** finished, leave *pz pointing to the first character past the end of
          152  +** the integer.  The *pLen parameter holds the length of the string
          153  +** in *pz and is decremented once for each character in the integer.
          154  +*/
          155  +static unsigned int deltaGetInt(const char **pz, int *pLen){
          156  +  static const signed char zValue[] = {
          157  +    -1, -1, -1, -1, -1, -1, -1, -1,   -1, -1, -1, -1, -1, -1, -1, -1,
          158  +    -1, -1, -1, -1, -1, -1, -1, -1,   -1, -1, -1, -1, -1, -1, -1, -1,
          159  +    -1, -1, -1, -1, -1, -1, -1, -1,   -1, -1, -1, -1, -1, -1, -1, -1,
          160  +     0,  1,  2,  3,  4,  5,  6,  7,    8,  9, -1, -1, -1, -1, -1, -1,
          161  +    -1, 10, 11, 12, 13, 14, 15, 16,   17, 18, 19, 20, 21, 22, 23, 24,
          162  +    25, 26, 27, 28, 29, 30, 31, 32,   33, 34, 35, -1, -1, -1, -1, 36,
          163  +    -1, 37, 38, 39, 40, 41, 42, 43,   44, 45, 46, 47, 48, 49, 50, 51,
          164  +    52, 53, 54, 55, 56, 57, 58, 59,   60, 61, 62, -1, -1, -1, 63, -1,
          165  +  };
          166  +  unsigned int v = 0;
          167  +  int c;
          168  +  unsigned char *z = (unsigned char*)*pz;
          169  +  unsigned char *zStart = z;
          170  +  while( (c = zValue[0x7f&*(z++)])>=0 ){
          171  +     v = (v<<6) + c;
          172  +  }
          173  +  z--;
          174  +  *pLen -= z - zStart;
          175  +  *pz = (char*)z;
          176  +  return v;
          177  +}
          178  +
          179  +/*
          180  +** Return the number digits in the base-64 representation of a positive integer
          181  +*/
          182  +static int digit_count(int v){
          183  +  unsigned int i, x;
          184  +  for(i=1, x=64; v>=x; i++, x <<= 6){}
          185  +  return i;
          186  +}
          187  +
          188  +#ifdef __GNUC__
          189  +# define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__)
          190  +#else
          191  +# define GCC_VERSION 0
          192  +#endif
          193  +
          194  +/*
          195  +** Compute a 32-bit big-endian checksum on the N-byte buffer.  If the
          196  +** buffer is not a multiple of 4 bytes length, compute the sum that would
          197  +** have occurred if the buffer was padded with zeros to the next multiple
          198  +** of four bytes.
          199  +*/
          200  +static unsigned int checksum(const char *zIn, size_t N){
          201  +  static const int byteOrderTest = 1;
          202  +  const unsigned char *z = (const unsigned char *)zIn;
          203  +  const unsigned char *zEnd = (const unsigned char*)&zIn[N&~3];
          204  +  unsigned sum = 0;
          205  +  assert( (z - (const unsigned char*)0)%4==0 );  /* Four-byte alignment */
          206  +  if( 0==*(char*)&byteOrderTest ){
          207  +    /* This is a big-endian machine */
          208  +    while( z<zEnd ){
          209  +      sum += *(unsigned*)z;
          210  +      z += 4;
          211  +    }
          212  +  }else{
          213  +    /* A little-endian machine */
          214  +#if GCC_VERSION>=4003000
          215  +    while( z<zEnd ){
          216  +      sum += __builtin_bswap32(*(unsigned*)z);
          217  +      z += 4;
          218  +    }
          219  +#elif defined(_MSC_VER) && _MSC_VER>=1300
          220  +    while( z<zEnd ){
          221  +      sum += _byteswap_ulong(*(unsigned*)z);
          222  +      z += 4;
          223  +    }
          224  +#else
          225  +    unsigned sum0 = 0;
          226  +    unsigned sum1 = 0;
          227  +    unsigned sum2 = 0;
          228  +    while(N >= 16){
          229  +      sum0 += ((unsigned)z[0] + z[4] + z[8] + z[12]);
          230  +      sum1 += ((unsigned)z[1] + z[5] + z[9] + z[13]);
          231  +      sum2 += ((unsigned)z[2] + z[6] + z[10]+ z[14]);
          232  +      sum  += ((unsigned)z[3] + z[7] + z[11]+ z[15]);
          233  +      z += 16;
          234  +      N -= 16;
          235  +    }
          236  +    while(N >= 4){
          237  +      sum0 += z[0];
          238  +      sum1 += z[1];
          239  +      sum2 += z[2];
          240  +      sum  += z[3];
          241  +      z += 4;
          242  +      N -= 4;
          243  +    }
          244  +    sum += (sum2 << 8) + (sum1 << 16) + (sum0 << 24);
          245  +#endif
          246  +  }
          247  +  switch(N&3){
          248  +    case 3:   sum += (z[2] << 8);
          249  +    case 2:   sum += (z[1] << 16);
          250  +    case 1:   sum += (z[0] << 24);
          251  +    default:  ;
          252  +  }
          253  +  return sum;
          254  +}
          255  +
          256  +/*
          257  +** Create a new delta.
          258  +**
          259  +** The delta is written into a preallocated buffer, zDelta, which
          260  +** should be at least 60 bytes longer than the target file, zOut.
          261  +** The delta string will be NUL-terminated, but it might also contain
          262  +** embedded NUL characters if either the zSrc or zOut files are
          263  +** binary.  This function returns the length of the delta string
          264  +** in bytes, excluding the final NUL terminator character.
          265  +**
          266  +** Output Format:
          267  +**
          268  +** The delta begins with a base64 number followed by a newline.  This
          269  +** number is the number of bytes in the TARGET file.  Thus, given a
          270  +** delta file z, a program can compute the size of the output file
          271  +** simply by reading the first line and decoding the base-64 number
          272  +** found there.  The delta_output_size() routine does exactly this.
          273  +**
          274  +** After the initial size number, the delta consists of a series of
          275  +** literal text segments and commands to copy from the SOURCE file.
          276  +** A copy command looks like this:
          277  +**
          278  +**     NNN@MMM,
          279  +**
          280  +** where NNN is the number of bytes to be copied and MMM is the offset
          281  +** into the source file of the first byte (both base-64).   If NNN is 0
          282  +** it means copy the rest of the input file.  Literal text is like this:
          283  +**
          284  +**     NNN:TTTTT
          285  +**
          286  +** where NNN is the number of bytes of text (base-64) and TTTTT is the text.
          287  +**
          288  +** The last term is of the form
          289  +**
          290  +**     NNN;
          291  +**
          292  +** In this case, NNN is a 32-bit bigendian checksum of the output file
          293  +** that can be used to verify that the delta applied correctly.  All
          294  +** numbers are in base-64.
          295  +**
          296  +** Pure text files generate a pure text delta.  Binary files generate a
          297  +** delta that may contain some binary data.
          298  +**
          299  +** Algorithm:
          300  +**
          301  +** The encoder first builds a hash table to help it find matching
          302  +** patterns in the source file.  16-byte chunks of the source file
          303  +** sampled at evenly spaced intervals are used to populate the hash
          304  +** table.
          305  +**
          306  +** Next we begin scanning the target file using a sliding 16-byte
          307  +** window.  The hash of the 16-byte window in the target is used to
          308  +** search for a matching section in the source file.  When a match
          309  +** is found, a copy command is added to the delta.  An effort is
          310  +** made to extend the matching section to regions that come before
          311  +** and after the 16-byte hash window.  A copy command is only issued
          312  +** if the result would use less space that just quoting the text
          313  +** literally. Literal text is added to the delta for sections that
          314  +** do not match or which can not be encoded efficiently using copy
          315  +** commands.
          316  +*/
          317  +static int delta_create(
          318  +  const char *zSrc,      /* The source or pattern file */
          319  +  unsigned int lenSrc,   /* Length of the source file */
          320  +  const char *zOut,      /* The target file */
          321  +  unsigned int lenOut,   /* Length of the target file */
          322  +  char *zDelta           /* Write the delta into this buffer */
          323  +){
          324  +  int i, base;
          325  +  char *zOrigDelta = zDelta;
          326  +  hash h;
          327  +  int nHash;                 /* Number of hash table entries */
          328  +  int *landmark;             /* Primary hash table */
          329  +  int *collide;              /* Collision chain */
          330  +  int lastRead = -1;         /* Last byte of zSrc read by a COPY command */
          331  +
          332  +  /* Add the target file size to the beginning of the delta
          333  +  */
          334  +  putInt(lenOut, &zDelta);
          335  +  *(zDelta++) = '\n';
          336  +
          337  +  /* If the source file is very small, it means that we have no
          338  +  ** chance of ever doing a copy command.  Just output a single
          339  +  ** literal segment for the entire target and exit.
          340  +  */
          341  +  if( lenSrc<=NHASH ){
          342  +    putInt(lenOut, &zDelta);
          343  +    *(zDelta++) = ':';
          344  +    memcpy(zDelta, zOut, lenOut);
          345  +    zDelta += lenOut;
          346  +    putInt(checksum(zOut, lenOut), &zDelta);
          347  +    *(zDelta++) = ';';
          348  +    return zDelta - zOrigDelta;
          349  +  }
          350  +
          351  +  /* Compute the hash table used to locate matching sections in the
          352  +  ** source file.
          353  +  */
          354  +  nHash = lenSrc/NHASH;
          355  +  collide = sqlite3_malloc64( (sqlite3_int64)nHash*2*sizeof(int) );
          356  +  memset(collide, -1, nHash*2*sizeof(int));
          357  +  landmark = &collide[nHash];
          358  +  for(i=0; i<lenSrc-NHASH; i+=NHASH){
          359  +    int hv = hash_once(&zSrc[i]) % nHash;
          360  +    collide[i/NHASH] = landmark[hv];
          361  +    landmark[hv] = i/NHASH;
          362  +  }
          363  +
          364  +  /* Begin scanning the target file and generating copy commands and
          365  +  ** literal sections of the delta.
          366  +  */
          367  +  base = 0;    /* We have already generated everything before zOut[base] */
          368  +  while( base+NHASH<lenOut ){
          369  +    int iSrc, iBlock;
          370  +    unsigned int bestCnt, bestOfst=0, bestLitsz=0;
          371  +    hash_init(&h, &zOut[base]);
          372  +    i = 0;     /* Trying to match a landmark against zOut[base+i] */
          373  +    bestCnt = 0;
          374  +    while( 1 ){
          375  +      int hv;
          376  +      int limit = 250;
          377  +
          378  +      hv = hash_32bit(&h) % nHash;
          379  +      iBlock = landmark[hv];
          380  +      while( iBlock>=0 && (limit--)>0 ){
          381  +        /*
          382  +        ** The hash window has identified a potential match against
          383  +        ** landmark block iBlock.  But we need to investigate further.
          384  +        **
          385  +        ** Look for a region in zOut that matches zSrc. Anchor the search
          386  +        ** at zSrc[iSrc] and zOut[base+i].  Do not include anything prior to
          387  +        ** zOut[base] or after zOut[outLen] nor anything after zSrc[srcLen].
          388  +        **
          389  +        ** Set cnt equal to the length of the match and set ofst so that
          390  +        ** zSrc[ofst] is the first element of the match.  litsz is the number
          391  +        ** of characters between zOut[base] and the beginning of the match.
          392  +        ** sz will be the overhead (in bytes) needed to encode the copy
          393  +        ** command.  Only generate copy command if the overhead of the
          394  +        ** copy command is less than the amount of literal text to be copied.
          395  +        */
          396  +        int cnt, ofst, litsz;
          397  +        int j, k, x, y;
          398  +        int sz;
          399  +        int limitX;
          400  +
          401  +        /* Beginning at iSrc, match forwards as far as we can.  j counts
          402  +        ** the number of characters that match */
          403  +        iSrc = iBlock*NHASH;
          404  +        y = base+i;
          405  +        limitX = ( lenSrc-iSrc <= lenOut-y ) ? lenSrc : iSrc + lenOut - y;
          406  +        for(x=iSrc; x<limitX; x++, y++){
          407  +          if( zSrc[x]!=zOut[y] ) break;
          408  +        }
          409  +        j = x - iSrc - 1;
          410  +
          411  +        /* Beginning at iSrc-1, match backwards as far as we can.  k counts
          412  +        ** the number of characters that match */
          413  +        for(k=1; k<iSrc && k<=i; k++){
          414  +          if( zSrc[iSrc-k]!=zOut[base+i-k] ) break;
          415  +        }
          416  +        k--;
          417  +
          418  +        /* Compute the offset and size of the matching region */
          419  +        ofst = iSrc-k;
          420  +        cnt = j+k+1;
          421  +        litsz = i-k;  /* Number of bytes of literal text before the copy */
          422  +        /* sz will hold the number of bytes needed to encode the "insert"
          423  +        ** command and the copy command, not counting the "insert" text */
          424  +        sz = digit_count(i-k)+digit_count(cnt)+digit_count(ofst)+3;
          425  +        if( cnt>=sz && cnt>bestCnt ){
          426  +          /* Remember this match only if it is the best so far and it
          427  +          ** does not increase the file size */
          428  +          bestCnt = cnt;
          429  +          bestOfst = iSrc-k;
          430  +          bestLitsz = litsz;
          431  +        }
          432  +
          433  +        /* Check the next matching block */
          434  +        iBlock = collide[iBlock];
          435  +      }
          436  +
          437  +      /* We have a copy command that does not cause the delta to be larger
          438  +      ** than a literal insert.  So add the copy command to the delta.
          439  +      */
          440  +      if( bestCnt>0 ){
          441  +        if( bestLitsz>0 ){
          442  +          /* Add an insert command before the copy */
          443  +          putInt(bestLitsz,&zDelta);
          444  +          *(zDelta++) = ':';
          445  +          memcpy(zDelta, &zOut[base], bestLitsz);
          446  +          zDelta += bestLitsz;
          447  +          base += bestLitsz;
          448  +        }
          449  +        base += bestCnt;
          450  +        putInt(bestCnt, &zDelta);
          451  +        *(zDelta++) = '@';
          452  +        putInt(bestOfst, &zDelta);
          453  +        *(zDelta++) = ',';
          454  +        if( bestOfst + bestCnt -1 > lastRead ){
          455  +          lastRead = bestOfst + bestCnt - 1;
          456  +        }
          457  +        bestCnt = 0;
          458  +        break;
          459  +      }
          460  +
          461  +      /* If we reach this point, it means no match is found so far */
          462  +      if( base+i+NHASH>=lenOut ){
          463  +        /* We have reached the end of the file and have not found any
          464  +        ** matches.  Do an "insert" for everything that does not match */
          465  +        putInt(lenOut-base, &zDelta);
          466  +        *(zDelta++) = ':';
          467  +        memcpy(zDelta, &zOut[base], lenOut-base);
          468  +        zDelta += lenOut-base;
          469  +        base = lenOut;
          470  +        break;
          471  +      }
          472  +
          473  +      /* Advance the hash by one character.  Keep looking for a match */
          474  +      hash_next(&h, zOut[base+i+NHASH]);
          475  +      i++;
          476  +    }
          477  +  }
          478  +  /* Output a final "insert" record to get all the text at the end of
          479  +  ** the file that does not match anything in the source file.
          480  +  */
          481  +  if( base<lenOut ){
          482  +    putInt(lenOut-base, &zDelta);
          483  +    *(zDelta++) = ':';
          484  +    memcpy(zDelta, &zOut[base], lenOut-base);
          485  +    zDelta += lenOut-base;
          486  +  }
          487  +  /* Output the final checksum record. */
          488  +  putInt(checksum(zOut, lenOut), &zDelta);
          489  +  *(zDelta++) = ';';
          490  +  sqlite3_free(collide);
          491  +  return zDelta - zOrigDelta;
          492  +}
          493  +
          494  +/*
          495  +** Return the size (in bytes) of the output from applying
          496  +** a delta.
          497  +**
          498  +** This routine is provided so that an procedure that is able
          499  +** to call delta_apply() can learn how much space is required
          500  +** for the output and hence allocate nor more space that is really
          501  +** needed.
          502  +*/
          503  +static int delta_output_size(const char *zDelta, int lenDelta){
          504  +  int size;
          505  +  size = deltaGetInt(&zDelta, &lenDelta);
          506  +  if( *zDelta!='\n' ){
          507  +    /* ERROR: size integer not terminated by "\n" */
          508  +    return -1;
          509  +  }
          510  +  return size;
          511  +}
          512  +
          513  +
          514  +/*
          515  +** Apply a delta.
          516  +**
          517  +** The output buffer should be big enough to hold the whole output
          518  +** file and a NUL terminator at the end.  The delta_output_size()
          519  +** routine will determine this size for you.
          520  +**
          521  +** The delta string should be null-terminated.  But the delta string
          522  +** may contain embedded NUL characters (if the input and output are
          523  +** binary files) so we also have to pass in the length of the delta in
          524  +** the lenDelta parameter.
          525  +**
          526  +** This function returns the size of the output file in bytes (excluding
          527  +** the final NUL terminator character).  Except, if the delta string is
          528  +** malformed or intended for use with a source file other than zSrc,
          529  +** then this routine returns -1.
          530  +**
          531  +** Refer to the delta_create() documentation above for a description
          532  +** of the delta file format.
          533  +*/
          534  +static int delta_apply(
          535  +  const char *zSrc,      /* The source or pattern file */
          536  +  int lenSrc,            /* Length of the source file */
          537  +  const char *zDelta,    /* Delta to apply to the pattern */
          538  +  int lenDelta,          /* Length of the delta */
          539  +  char *zOut             /* Write the output into this preallocated buffer */
          540  +){
          541  +  unsigned int limit;
          542  +  unsigned int total = 0;
          543  +#ifdef FOSSIL_ENABLE_DELTA_CKSUM_TEST
          544  +  char *zOrigOut = zOut;
          545  +#endif
          546  +
          547  +  limit = deltaGetInt(&zDelta, &lenDelta);
          548  +  if( *zDelta!='\n' ){
          549  +    /* ERROR: size integer not terminated by "\n" */
          550  +    return -1;
          551  +  }
          552  +  zDelta++; lenDelta--;
          553  +  while( *zDelta && lenDelta>0 ){
          554  +    unsigned int cnt, ofst;
          555  +    cnt = deltaGetInt(&zDelta, &lenDelta);
          556  +    switch( zDelta[0] ){
          557  +      case '@': {
          558  +        zDelta++; lenDelta--;
          559  +        ofst = deltaGetInt(&zDelta, &lenDelta);
          560  +        if( lenDelta>0 && zDelta[0]!=',' ){
          561  +          /* ERROR: copy command not terminated by ',' */
          562  +          return -1;
          563  +        }
          564  +        zDelta++; lenDelta--;
          565  +        total += cnt;
          566  +        if( total>limit ){
          567  +          /* ERROR: copy exceeds output file size */
          568  +          return -1;
          569  +        }
          570  +        if( ofst+cnt > lenSrc ){
          571  +          /* ERROR: copy extends past end of input */
          572  +          return -1;
          573  +        }
          574  +        memcpy(zOut, &zSrc[ofst], cnt);
          575  +        zOut += cnt;
          576  +        break;
          577  +      }
          578  +      case ':': {
          579  +        zDelta++; lenDelta--;
          580  +        total += cnt;
          581  +        if( total>limit ){
          582  +          /* ERROR:  insert command gives an output larger than predicted */
          583  +          return -1;
          584  +        }
          585  +        if( cnt>lenDelta ){
          586  +          /* ERROR: insert count exceeds size of delta */
          587  +          return -1;
          588  +        }
          589  +        memcpy(zOut, zDelta, cnt);
          590  +        zOut += cnt;
          591  +        zDelta += cnt;
          592  +        lenDelta -= cnt;
          593  +        break;
          594  +      }
          595  +      case ';': {
          596  +        zDelta++; lenDelta--;
          597  +        zOut[0] = 0;
          598  +#ifdef FOSSIL_ENABLE_DELTA_CKSUM_TEST
          599  +        if( cnt!=checksum(zOrigOut, total) ){
          600  +          /* ERROR:  bad checksum */
          601  +          return -1;
          602  +        }
          603  +#endif
          604  +        if( total!=limit ){
          605  +          /* ERROR: generated size does not match predicted size */
          606  +          return -1;
          607  +        }
          608  +        return total;
          609  +      }
          610  +      default: {
          611  +        /* ERROR: unknown delta operator */
          612  +        return -1;
          613  +      }
          614  +    }
          615  +  }
          616  +  /* ERROR: unterminated delta */
          617  +  return -1;
          618  +}
          619  +
          620  +/*
          621  +** SQL functions:  delta_create(X,Y)
          622  +**
          623  +** Return a delta for carrying X into Y.
          624  +*/
          625  +static void deltaCreateFunc(
          626  +  sqlite3_context *context,
          627  +  int argc,
          628  +  sqlite3_value **argv
          629  +){
          630  +  const char *aOrig; int nOrig;  /* old blob */
          631  +  const char *aNew;  int nNew;   /* new blob */
          632  +  char *aOut;        int nOut;   /* output delta */
          633  +
          634  +  assert( argc==2 );
          635  +  if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
          636  +  if( sqlite3_value_type(argv[1])==SQLITE_NULL ) return;
          637  +  nOrig = sqlite3_value_bytes(argv[0]);
          638  +  aOrig = (const char*)sqlite3_value_blob(argv[0]);
          639  +  nNew = sqlite3_value_bytes(argv[1]);
          640  +  aNew = (const char*)sqlite3_value_blob(argv[1]);
          641  +  aOut = sqlite3_malloc64(nNew+70);
          642  +  if( aOut==0 ){
          643  +    sqlite3_result_error_nomem(context);
          644  +  }else{
          645  +    nOut = delta_create(aOrig, nOrig, aNew, nNew, aOut);
          646  +    if( nOut<0 ){
          647  +      sqlite3_free(aOut);
          648  +      sqlite3_result_error(context, "cannot create fossil delta", -1);
          649  +    }else{
          650  +      sqlite3_result_blob(context, aOut, nOut, sqlite3_free);
          651  +    }
          652  +  }
          653  +}
          654  +
          655  +/*
          656  +** SQL functions:  delta_apply(X,D)
          657  +**
          658  +** Return the result of applying delta D to input X.
          659  +*/
          660  +static void deltaApplyFunc(
          661  +  sqlite3_context *context,
          662  +  int argc,
          663  +  sqlite3_value **argv
          664  +){
          665  +  const char *aOrig;   int nOrig;        /* The X input */
          666  +  const char *aDelta;  int nDelta;       /* The input delta (D) */
          667  +  char *aOut;          int nOut, nOut2;  /* The output */
          668  +
          669  +  assert( argc==2 );
          670  +  if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
          671  +  if( sqlite3_value_type(argv[1])==SQLITE_NULL ) return;
          672  +  nOrig = sqlite3_value_bytes(argv[0]);
          673  +  aOrig = (const char*)sqlite3_value_blob(argv[0]);
          674  +  nDelta = sqlite3_value_bytes(argv[1]);
          675  +  aDelta = (const char*)sqlite3_value_blob(argv[1]);
          676  +
          677  +  /* Figure out the size of the output */
          678  +  nOut = delta_output_size(aDelta, nDelta);
          679  +  if( nOut<0 ){
          680  +    sqlite3_result_error(context, "corrupt fossil delta", -1);
          681  +    return;
          682  +  }
          683  +  aOut = sqlite3_malloc64((sqlite3_int64)nOut+1);
          684  +  if( aOut==0 ){
          685  +    sqlite3_result_error_nomem(context);
          686  +  }else{
          687  +    nOut2 = delta_apply(aOrig, nOrig, aDelta, nDelta, aOut);
          688  +    if( nOut2!=nOut ){
          689  +      sqlite3_free(aOut);
          690  +      sqlite3_result_error(context, "corrupt fossil delta", -1);
          691  +    }else{
          692  +      sqlite3_result_blob(context, aOut, nOut, sqlite3_free);
          693  +    }
          694  +  }
          695  +}
          696  +
          697  +
          698  +/*
          699  +** SQL functions:  delta_output_size(D)
          700  +**
          701  +** Return the size of the output that results from applying delta D.
          702  +*/
          703  +static void deltaOutputSizeFunc(
          704  +  sqlite3_context *context,
          705  +  int argc,
          706  +  sqlite3_value **argv
          707  +){
          708  +  const char *aDelta;  int nDelta;       /* The input delta (D) */
          709  +  int nOut;                              /* Size of output */
          710  +  assert( argc==1 );
          711  +  if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
          712  +  nDelta = sqlite3_value_bytes(argv[0]);
          713  +  aDelta = (const char*)sqlite3_value_blob(argv[0]);
          714  +
          715  +  /* Figure out the size of the output */
          716  +  nOut = delta_output_size(aDelta, nDelta);
          717  +  if( nOut<0 ){
          718  +    sqlite3_result_error(context, "corrupt fossil delta", -1);
          719  +    return;
          720  +  }else{
          721  +    sqlite3_result_int(context, nOut);
          722  +  }
          723  +}
          724  +
          725  +/*****************************************************************************
          726  +** Table-valued SQL function:   delta_parse(DELTA)
          727  +**
          728  +** Schema:
          729  +**
          730  +**     CREATE TABLE delta_parse(
          731  +**       op TEXT,
          732  +**       a1 INT,
          733  +**       a2 ANY,
          734  +**       delta HIDDEN BLOB
          735  +**     );
          736  +**
          737  +** Given an input DELTA, this function parses the delta and returns
          738  +** rows for each entry in the delta.  The op column has one of the
          739  +** values SIZE, COPY, INSERT, CHECKSUM, ERROR.
          740  +**
          741  +** Assuming no errors, the first row has op='SIZE'.  a1 is the size of
          742  +** the output in bytes and a2 is NULL.
          743  +**
          744  +** After the initial SIZE row, there are zero or more 'COPY' and/or 'INSERT'
          745  +** rows.  A COPY row means content is copied from the source into the
          746  +** output.  Column a1 is the number of bytes to copy and a2 is the offset
          747  +** into source from which to begin copying.  An INSERT row means to
          748  +** insert text into the output stream.  Column a1 is the number of bytes
          749  +** to insert and column is a BLOB that contains the text to be inserted.
          750  +**
          751  +** The last row of a well-formed delta will have an op value of 'CHECKSUM'.
          752  +** The a1 column will be the value of the checksum and a2 will be NULL.
          753  +**
          754  +** If the input delta is not well-formed, then a row with an op value
          755  +** of 'ERROR' is returned.  The a1 value of the ERROR row is the offset
          756  +** into the delta where the error was encountered and a2 is NULL.
          757  +*/
          758  +typedef struct deltaparsevtab_vtab deltaparsevtab_vtab;
          759  +typedef struct deltaparsevtab_cursor deltaparsevtab_cursor;
          760  +struct deltaparsevtab_vtab {
          761  +  sqlite3_vtab base;  /* Base class - must be first */
          762  +  /* No additional information needed */
          763  +};
          764  +struct deltaparsevtab_cursor {
          765  +  sqlite3_vtab_cursor base;  /* Base class - must be first */
          766  +  char *aDelta;              /* The delta being parsed */
          767  +  int nDelta;                /* Number of bytes in the delta */
          768  +  int iCursor;               /* Current cursor location */
          769  +  int eOp;                   /* Name of current operator */
          770  +  unsigned int a1, a2;       /* Arguments to current operator */
          771  +  int iNext;                 /* Next cursor value */
          772  +};
          773  +
          774  +/* Operator names:
          775  +*/
          776  +static const char *azOp[] = {
          777  +  "SIZE", "COPY", "INSERT", "CHECKSUM", "ERROR", "EOF"
          778  +};
          779  +#define DELTAPARSE_OP_SIZE         0
          780  +#define DELTAPARSE_OP_COPY         1
          781  +#define DELTAPARSE_OP_INSERT       2
          782  +#define DELTAPARSE_OP_CHECKSUM     3
          783  +#define DELTAPARSE_OP_ERROR        4
          784  +#define DELTAPARSE_OP_EOF          5
          785  +
          786  +/*
          787  +** The deltaparsevtabConnect() method is invoked to create a new
          788  +** deltaparse virtual table.
          789  +**
          790  +** Think of this routine as the constructor for deltaparsevtab_vtab objects.
          791  +**
          792  +** All this routine needs to do is:
          793  +**
          794  +**    (1) Allocate the deltaparsevtab_vtab object and initialize all fields.
          795  +**
          796  +**    (2) Tell SQLite (via the sqlite3_declare_vtab() interface) what the
          797  +**        result set of queries against the virtual table will look like.
          798  +*/
          799  +static int deltaparsevtabConnect(
          800  +  sqlite3 *db,
          801  +  void *pAux,
          802  +  int argc, const char *const*argv,
          803  +  sqlite3_vtab **ppVtab,
          804  +  char **pzErr
          805  +){
          806  +  deltaparsevtab_vtab *pNew;
          807  +  int rc;
          808  +
          809  +  rc = sqlite3_declare_vtab(db,
          810  +           "CREATE TABLE x(op,a1,a2,delta HIDDEN)"
          811  +       );
          812  +  /* For convenience, define symbolic names for the index to each column. */
          813  +#define DELTAPARSEVTAB_OP     0
          814  +#define DELTAPARSEVTAB_A1     1
          815  +#define DELTAPARSEVTAB_A2     2
          816  +#define DELTAPARSEVTAB_DELTA  3
          817  +  if( rc==SQLITE_OK ){
          818  +    pNew = sqlite3_malloc64( sizeof(*pNew) );
          819  +    *ppVtab = (sqlite3_vtab*)pNew;
          820  +    if( pNew==0 ) return SQLITE_NOMEM;
          821  +    memset(pNew, 0, sizeof(*pNew));
          822  +  }
          823  +  return rc;
          824  +}
          825  +
          826  +/*
          827  +** This method is the destructor for deltaparsevtab_vtab objects.
          828  +*/
          829  +static int deltaparsevtabDisconnect(sqlite3_vtab *pVtab){
          830  +  deltaparsevtab_vtab *p = (deltaparsevtab_vtab*)pVtab;
          831  +  sqlite3_free(p);
          832  +  return SQLITE_OK;
          833  +}
          834  +
          835  +/*
          836  +** Constructor for a new deltaparsevtab_cursor object.
          837  +*/
          838  +static int deltaparsevtabOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
          839  +  deltaparsevtab_cursor *pCur;
          840  +  pCur = sqlite3_malloc( sizeof(*pCur) );
          841  +  if( pCur==0 ) return SQLITE_NOMEM;
          842  +  memset(pCur, 0, sizeof(*pCur));
          843  +  *ppCursor = &pCur->base;
          844  +  return SQLITE_OK;
          845  +}
          846  +
          847  +/*
          848  +** Destructor for a deltaparsevtab_cursor.
          849  +*/
          850  +static int deltaparsevtabClose(sqlite3_vtab_cursor *cur){
          851  +  deltaparsevtab_cursor *pCur = (deltaparsevtab_cursor*)cur;
          852  +  sqlite3_free(pCur);
          853  +  return SQLITE_OK;
          854  +}
          855  +
          856  +
          857  +/*
          858  +** Advance a deltaparsevtab_cursor to its next row of output.
          859  +*/
          860  +static int deltaparsevtabNext(sqlite3_vtab_cursor *cur){
          861  +  deltaparsevtab_cursor *pCur = (deltaparsevtab_cursor*)cur;
          862  +  const char *z;
          863  +  int i = 0;
          864  +
          865  +  pCur->iCursor = pCur->iNext;
          866  +  z = pCur->aDelta + pCur->iCursor;
          867  +  pCur->a1 = deltaGetInt(&z, &i);
          868  +  switch( z[0] ){
          869  +    case '@': {
          870  +      z++;
          871  +      pCur->a2 = deltaGetInt(&z, &i);
          872  +      pCur->eOp = DELTAPARSE_OP_COPY;
          873  +      pCur->iNext = (int)(&z[1] - pCur->aDelta);
          874  +      break;
          875  +    }
          876  +    case ':': {
          877  +      z++;
          878  +      pCur->a2 = (unsigned int)(z - pCur->aDelta);
          879  +      pCur->eOp = DELTAPARSE_OP_INSERT;
          880  +      pCur->iNext = (int)(&z[pCur->a1] - pCur->aDelta);
          881  +      break;
          882  +    }
          883  +    case ';': {
          884  +      pCur->eOp = DELTAPARSE_OP_CHECKSUM;
          885  +      pCur->iNext = pCur->nDelta;
          886  +      break;
          887  +    }
          888  +    default: {
          889  +      if( pCur->iNext==pCur->nDelta ){
          890  +        pCur->eOp = DELTAPARSE_OP_EOF;
          891  +      }else{
          892  +        pCur->eOp = DELTAPARSE_OP_ERROR;
          893  +        pCur->iNext = pCur->nDelta;
          894  +      }
          895  +      break;
          896  +    }
          897  +  }
          898  +  return SQLITE_OK;
          899  +}
          900  +
          901  +/*
          902  +** Return values of columns for the row at which the deltaparsevtab_cursor
          903  +** is currently pointing.
          904  +*/
          905  +static int deltaparsevtabColumn(
          906  +  sqlite3_vtab_cursor *cur,   /* The cursor */
          907  +  sqlite3_context *ctx,       /* First argument to sqlite3_result_...() */
          908  +  int i                       /* Which column to return */
          909  +){
          910  +  deltaparsevtab_cursor *pCur = (deltaparsevtab_cursor*)cur;
          911  +  switch( i ){
          912  +    case DELTAPARSEVTAB_OP: {
          913  +      sqlite3_result_text(ctx, azOp[pCur->eOp], -1, SQLITE_STATIC);
          914  +      break;
          915  +    }
          916  +    case DELTAPARSEVTAB_A1: {
          917  +      sqlite3_result_int(ctx, pCur->a1);
          918  +      break;
          919  +    }
          920  +    case DELTAPARSEVTAB_A2: {
          921  +      if( pCur->eOp==DELTAPARSE_OP_COPY ){
          922  +        sqlite3_result_int(ctx, pCur->a2);
          923  +      }else if( pCur->eOp==DELTAPARSE_OP_INSERT ){
          924  +        sqlite3_result_blob(ctx, pCur->aDelta+pCur->a2, pCur->a1,
          925  +                            SQLITE_TRANSIENT);
          926  +      }
          927  +      break;
          928  +    }
          929  +    case DELTAPARSEVTAB_DELTA: {
          930  +      sqlite3_result_blob(ctx, pCur->aDelta, pCur->nDelta, SQLITE_TRANSIENT);
          931  +      break;
          932  +    }
          933  +  }
          934  +  return SQLITE_OK;
          935  +}
          936  +
          937  +/*
          938  +** Return the rowid for the current row.  In this implementation, the
          939  +** rowid is the same as the output value.
          940  +*/
          941  +static int deltaparsevtabRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
          942  +  deltaparsevtab_cursor *pCur = (deltaparsevtab_cursor*)cur;
          943  +  *pRowid = pCur->iCursor;
          944  +  return SQLITE_OK;
          945  +}
          946  +
          947  +/*
          948  +** Return TRUE if the cursor has been moved off of the last
          949  +** row of output.
          950  +*/
          951  +static int deltaparsevtabEof(sqlite3_vtab_cursor *cur){
          952  +  deltaparsevtab_cursor *pCur = (deltaparsevtab_cursor*)cur;
          953  +  return pCur->eOp==DELTAPARSE_OP_EOF;
          954  +}
          955  +
          956  +/*
          957  +** This method is called to "rewind" the deltaparsevtab_cursor object back
          958  +** to the first row of output.  This method is always called at least
          959  +** once prior to any call to deltaparsevtabColumn() or deltaparsevtabRowid() or 
          960  +** deltaparsevtabEof().
          961  +*/
          962  +static int deltaparsevtabFilter(
          963  +  sqlite3_vtab_cursor *pVtabCursor, 
          964  +  int idxNum, const char *idxStr,
          965  +  int argc, sqlite3_value **argv
          966  +){
          967  +  deltaparsevtab_cursor *pCur = (deltaparsevtab_cursor *)pVtabCursor;
          968  +  const char *a;
          969  +  int i = 0;
          970  +  pCur->eOp = DELTAPARSE_OP_ERROR;
          971  +  if( idxNum!=1 ){
          972  +    return SQLITE_OK;
          973  +  }
          974  +  pCur->nDelta = sqlite3_value_bytes(argv[0]);
          975  +  a = (const char*)sqlite3_value_blob(argv[0]);
          976  +  if( pCur->nDelta==0 || a==0 ){
          977  +    return SQLITE_OK;
          978  +  }
          979  +  pCur->aDelta = sqlite3_malloc64( pCur->nDelta+1 );
          980  +  if( pCur->aDelta==0 ){
          981  +    pCur->nDelta = 0;
          982  +    return SQLITE_NOMEM;
          983  +  }
          984  +  memcpy(pCur->aDelta, a, pCur->nDelta);
          985  +  pCur->aDelta[pCur->nDelta] = 0;
          986  +  a = pCur->aDelta;
          987  +  pCur->eOp = DELTAPARSE_OP_SIZE;
          988  +  pCur->a1 = deltaGetInt(&a, &i);
          989  +  if( a[0]!='\n' ){
          990  +    pCur->eOp = DELTAPARSE_OP_ERROR;
          991  +    pCur->a1 = pCur->a2 = 0;
          992  +    pCur->iNext = pCur->nDelta;
          993  +    return SQLITE_OK;
          994  +  }
          995  +  a++;
          996  +  pCur->iNext = (unsigned int)(a - pCur->aDelta);
          997  +  return SQLITE_OK;
          998  +}
          999  +
         1000  +/*
         1001  +** SQLite will invoke this method one or more times while planning a query
         1002  +** that uses the virtual table.  This routine needs to create
         1003  +** a query plan for each invocation and compute an estimated cost for that
         1004  +** plan.
         1005  +*/
         1006  +static int deltaparsevtabBestIndex(
         1007  +  sqlite3_vtab *tab,
         1008  +  sqlite3_index_info *pIdxInfo
         1009  +){
         1010  +  int i;
         1011  +  for(i=0; i<pIdxInfo->nConstraint; i++){
         1012  +    if( pIdxInfo->aConstraint[i].iColumn != DELTAPARSEVTAB_DELTA ) continue;
         1013  +    if( pIdxInfo->aConstraint[i].usable==0 ) continue;
         1014  +    if( pIdxInfo->aConstraint[i].op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
         1015  +    pIdxInfo->aConstraintUsage[i].argvIndex = 1;
         1016  +    pIdxInfo->aConstraintUsage[i].omit = 1;
         1017  +    pIdxInfo->estimatedCost = (double)1;
         1018  +    pIdxInfo->estimatedRows = 10;
         1019  +    pIdxInfo->idxNum = 1;
         1020  +    return SQLITE_OK;
         1021  +  }
         1022  +  pIdxInfo->idxNum = 0;
         1023  +  pIdxInfo->estimatedCost = (double)0x7fffffff;
         1024  +  pIdxInfo->estimatedRows = 0x7fffffff;
         1025  +  return SQLITE_CONSTRAINT;
         1026  +}
         1027  +
         1028  +/*
         1029  +** This following structure defines all the methods for the 
         1030  +** virtual table.
         1031  +*/
         1032  +static sqlite3_module deltaparsevtabModule = {
         1033  +  /* iVersion    */ 0,
         1034  +  /* xCreate     */ 0,
         1035  +  /* xConnect    */ deltaparsevtabConnect,
         1036  +  /* xBestIndex  */ deltaparsevtabBestIndex,
         1037  +  /* xDisconnect */ deltaparsevtabDisconnect,
         1038  +  /* xDestroy    */ 0,
         1039  +  /* xOpen       */ deltaparsevtabOpen,
         1040  +  /* xClose      */ deltaparsevtabClose,
         1041  +  /* xFilter     */ deltaparsevtabFilter,
         1042  +  /* xNext       */ deltaparsevtabNext,
         1043  +  /* xEof        */ deltaparsevtabEof,
         1044  +  /* xColumn     */ deltaparsevtabColumn,
         1045  +  /* xRowid      */ deltaparsevtabRowid,
         1046  +  /* xUpdate     */ 0,
         1047  +  /* xBegin      */ 0,
         1048  +  /* xSync       */ 0,
         1049  +  /* xCommit     */ 0,
         1050  +  /* xRollback   */ 0,
         1051  +  /* xFindMethod */ 0,
         1052  +  /* xRename     */ 0,
         1053  +  /* xSavepoint  */ 0,
         1054  +  /* xRelease    */ 0,
         1055  +  /* xRollbackTo */ 0,
         1056  +  /* xShadowName */ 0
         1057  +};
         1058  +
         1059  +
         1060  +
         1061  +#ifdef _WIN32
         1062  +__declspec(dllexport)
         1063  +#endif
         1064  +int sqlite3_fossildelta_init(
         1065  +  sqlite3 *db, 
         1066  +  char **pzErrMsg, 
         1067  +  const sqlite3_api_routines *pApi
         1068  +){
         1069  +  int rc = SQLITE_OK;
         1070  +  SQLITE_EXTENSION_INIT2(pApi);
         1071  +  (void)pzErrMsg;  /* Unused parameter */
         1072  +  rc = sqlite3_create_function(db, "delta_create", 2, SQLITE_UTF8, 0,
         1073  +                               deltaCreateFunc, 0, 0);
         1074  +  if( rc==SQLITE_OK ){
         1075  +    rc = sqlite3_create_function(db, "delta_apply", 2, SQLITE_UTF8, 0,
         1076  +                                 deltaApplyFunc, 0, 0);
         1077  +  }
         1078  +  if( rc==SQLITE_OK ){
         1079  +    rc = sqlite3_create_function(db, "delta_output_size", 1, SQLITE_UTF8, 0,
         1080  +                                 deltaOutputSizeFunc, 0, 0);
         1081  +  }
         1082  +  if( rc==SQLITE_OK ){
         1083  +    rc = sqlite3_create_module(db, "delta_parse", &deltaparsevtabModule, 0);
         1084  +  }
         1085  +  return rc;
         1086  +}

Changes to ext/misc/percentile.c.

   104    104     int eType;
   105    105     double y;
   106    106     assert( argc==2 );
   107    107   
   108    108     /* Requirement 3:  P must be a number between 0 and 100 */
   109    109     eType = sqlite3_value_numeric_type(argv[1]);
   110    110     rPct = sqlite3_value_double(argv[1]);
   111         -  if( (eType!=SQLITE_INTEGER && eType!=SQLITE_FLOAT) ||
   112         -      ((rPct = sqlite3_value_double(argv[1]))<0.0 || rPct>100.0) ){
          111  +  if( (eType!=SQLITE_INTEGER && eType!=SQLITE_FLOAT)
          112  +   || rPct<0.0 || rPct>100.0 ){
   113    113       sqlite3_result_error(pCtx, "2nd argument to percentile() is not "
   114    114                            "a number between 0.0 and 100.0", -1);
   115    115       return;
   116    116     }
   117    117   
   118    118     /* Allocate the session context. */
   119    119     p = (Percentile*)sqlite3_aggregate_context(pCtx, sizeof(*p));

Changes to ext/rbu/sqlite3rbu.c.

   680    680   
   681    681     aOut = sqlite3_malloc(nOut+1);
   682    682     if( aOut==0 ){
   683    683       sqlite3_result_error_nomem(context);
   684    684     }else{
   685    685       nOut2 = rbuDeltaApply(aOrig, nOrig, aDelta, nDelta, aOut);
   686    686       if( nOut2!=nOut ){
          687  +      sqlite3_free(aOut);
   687    688         sqlite3_result_error(context, "corrupt fossil delta", -1);
   688    689       }else{
   689    690         sqlite3_result_blob(context, aOut, nOut, sqlite3_free);
   690    691       }
   691    692     }
   692    693   }
   693    694   

Changes to ext/session/sessionB.test.

   254    254   }
   255    255   
   256    256   # INSERT + DELETE 
   257    257   do_patchconcat_test 4.3.3 {
   258    258     INSERT INTO t2 VALUES('a', 'a', 'a', 'a');
   259    259   } {
   260    260     DELETE FROM t2 WHERE c = 'a';
   261         -} {
   262         -}
          261  +} {}
   263    262   
   264    263   # INSERT + UPDATE
   265    264   do_patchconcat_test 4.3.4 {
   266    265     INSERT INTO t2 VALUES('a', 'a', 'a', 'a');
   267    266   } {
   268    267     UPDATE t2 SET d = 'b' WHERE c='a';
   269    268   } {

Changes to src/btree.c.

  1417   1417     assert( pPage->nOverflow==0 );
  1418   1418     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  1419   1419     temp = 0;
  1420   1420     src = data = pPage->aData;
  1421   1421     hdr = pPage->hdrOffset;
  1422   1422     cellOffset = pPage->cellOffset;
  1423   1423     nCell = pPage->nCell;
  1424         -  assert( nCell==get2byte(&data[hdr+3]) );
         1424  +  assert( nCell==get2byte(&data[hdr+3]) || CORRUPT_DB );
  1425   1425     iCellFirst = cellOffset + 2*nCell;
  1426   1426     usableSize = pPage->pBt->usableSize;
  1427   1427   
  1428   1428     /* This block handles pages with two or fewer free blocks and nMaxFrag
  1429   1429     ** or fewer fragmented bytes. In this case it is faster to move the
  1430   1430     ** two (or one) blocks of cells using memmove() and add the required
  1431   1431     ** offsets to each pointer in the cell-pointer array than it is to 
................................................................................
  6726   6726       }
  6727   6727       pIns = pPage->aCellIdx + i*2;
  6728   6728       memmove(pIns+2, pIns, 2*(pPage->nCell - i));
  6729   6729       put2byte(pIns, idx);
  6730   6730       pPage->nCell++;
  6731   6731       /* increment the cell count */
  6732   6732       if( (++data[pPage->hdrOffset+4])==0 ) data[pPage->hdrOffset+3]++;
  6733         -    assert( get2byte(&data[pPage->hdrOffset+3])==pPage->nCell );
         6733  +    assert( get2byte(&data[pPage->hdrOffset+3])==pPage->nCell || CORRUPT_DB );
  6734   6734   #ifndef SQLITE_OMIT_AUTOVACUUM
  6735   6735       if( pPage->pBt->autoVacuum ){
  6736   6736         /* The cell may contain a pointer to an overflow page. If so, write
  6737   6737         ** the entry for the overflow page into the pointer map.
  6738   6738         */
  6739   6739         ptrmapPutOvflPtr(pPage, pPage, pCell, pRC);
  6740   6740       }
................................................................................
  8257   8257     if( rc ){
  8258   8258       *ppChild = 0;
  8259   8259       releasePage(pChild);
  8260   8260       return rc;
  8261   8261     }
  8262   8262     assert( sqlite3PagerIswriteable(pChild->pDbPage) );
  8263   8263     assert( sqlite3PagerIswriteable(pRoot->pDbPage) );
  8264         -  assert( pChild->nCell==pRoot->nCell );
         8264  +  assert( pChild->nCell==pRoot->nCell || CORRUPT_DB );
  8265   8265   
  8266   8266     TRACE(("BALANCE: copy root %d into %d\n", pRoot->pgno, pChild->pgno));
  8267   8267   
  8268   8268     /* Copy the overflow cells from pRoot to pChild */
  8269   8269     memcpy(pChild->aiOvfl, pRoot->aiOvfl,
  8270   8270            pRoot->nOverflow*sizeof(pRoot->aiOvfl[0]));
  8271   8271     memcpy(pChild->apOvfl, pRoot->apOvfl,
................................................................................
  9612   9612   ** Check the integrity of the freelist or of an overflow page list.
  9613   9613   ** Verify that the number of pages on the list is N.
  9614   9614   */
  9615   9615   static void checkList(
  9616   9616     IntegrityCk *pCheck,  /* Integrity checking context */
  9617   9617     int isFreeList,       /* True for a freelist.  False for overflow page list */
  9618   9618     int iPage,            /* Page number for first page in the list */
  9619         -  int N                 /* Expected number of pages in the list */
         9619  +  u32 N                 /* Expected number of pages in the list */
  9620   9620   ){
  9621   9621     int i;
  9622         -  int expected = N;
         9622  +  u32 expected = N;
  9623   9623     int nErrAtStart = pCheck->nErr;
  9624   9624     while( iPage!=0 && pCheck->mxErr ){
  9625   9625       DbPage *pOvflPage;
  9626   9626       unsigned char *pOvflData;
  9627   9627       if( checkRef(pCheck, iPage) ) break;
  9628   9628       N--;
  9629   9629       if( sqlite3PagerGet(pCheck->pPager, (Pgno)iPage, &pOvflPage, 0) ){
................................................................................
  9874   9874         }
  9875   9875         maxKey = info.nKey;
  9876   9876         keyCanBeEqual = 0;     /* Only the first key on the page may ==maxKey */
  9877   9877       }
  9878   9878   
  9879   9879       /* Check the content overflow list */
  9880   9880       if( info.nPayload>info.nLocal ){
  9881         -      int nPage;       /* Number of pages on the overflow chain */
         9881  +      u32 nPage;       /* Number of pages on the overflow chain */
  9882   9882         Pgno pgnoOvfl;   /* First page of the overflow chain */
  9883   9883         assert( pc + info.nSize - 4 <= usableSize );
  9884   9884         nPage = (info.nPayload - info.nLocal + usableSize - 5)/(usableSize - 4);
  9885   9885         pgnoOvfl = get4byte(&pCell[info.nSize - 4]);
  9886   9886   #ifndef SQLITE_OMIT_AUTOVACUUM
  9887   9887         if( pBt->autoVacuum ){
  9888   9888           checkPtrmap(pCheck, pgnoOvfl, PTRMAP_OVERFLOW1, iPage);

Changes to src/build.c.

   256    256   
   257    257     if( pParse->nErr ) return;
   258    258     assert( pParse->nested<10 );  /* Nesting should only be of limited depth */
   259    259     va_start(ap, zFormat);
   260    260     zSql = sqlite3VMPrintf(db, zFormat, ap);
   261    261     va_end(ap);
   262    262     if( zSql==0 ){
   263         -    return;   /* A malloc must have failed */
          263  +    /* This can result either from an OOM or because the formatted string
          264  +    ** exceeds SQLITE_LIMIT_LENGTH.  In the latter case, we need to set
          265  +    ** an error */
          266  +    if( !db->mallocFailed ) pParse->rc = SQLITE_TOOBIG;
          267  +    return;
   264    268     }
   265    269     pParse->nested++;
   266    270     memcpy(saveBuf, PARSE_TAIL(pParse), PARSE_TAIL_SZ);
   267    271     memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
   268    272     sqlite3RunParser(pParse, zSql, &zErrMsg);
   269    273     sqlite3DbFree(db, zErrMsg);
   270    274     sqlite3DbFree(db, zSql);
................................................................................
  1987   1991         sqlite3ErrorMsg(pParse, "");
  1988   1992         return;
  1989   1993       }
  1990   1994       p->tnum = db->init.newTnum;
  1991   1995       if( p->tnum==1 ) p->tabFlags |= TF_Readonly;
  1992   1996     }
  1993   1997   
         1998  +  assert( (p->tabFlags & TF_HasPrimaryKey)==0
         1999  +       || p->iPKey>=0 || sqlite3PrimaryKeyIndex(p)!=0 );
         2000  +  assert( (p->tabFlags & TF_HasPrimaryKey)!=0
         2001  +       || (p->iPKey<0 && sqlite3PrimaryKeyIndex(p)==0) );
         2002  +
  1994   2003     /* Special processing for WITHOUT ROWID Tables */
  1995   2004     if( tabOpts & TF_WithoutRowid ){
  1996   2005       if( (p->tabFlags & TF_Autoincrement) ){
  1997   2006         sqlite3ErrorMsg(pParse,
  1998   2007             "AUTOINCREMENT not allowed on WITHOUT ROWID tables");
  1999   2008         return;
  2000   2009       }

Changes to src/expr.c.

  2548   2548       ** We will have to generate an ephemeral table to do the job.
  2549   2549       */
  2550   2550       u32 savedNQueryLoop = pParse->nQueryLoop;
  2551   2551       int rMayHaveNull = 0;
  2552   2552       eType = IN_INDEX_EPH;
  2553   2553       if( inFlags & IN_INDEX_LOOP ){
  2554   2554         pParse->nQueryLoop = 0;
  2555         -      if( pX->pLeft->iColumn<0 && !ExprHasProperty(pX, EP_xIsSelect) ){
  2556         -        eType = IN_INDEX_ROWID;
  2557         -      }
  2558   2555       }else if( prRhsHasNull ){
  2559   2556         *prRhsHasNull = rMayHaveNull = ++pParse->nMem;
  2560   2557       }
  2561   2558       assert( pX->op==TK_IN );
  2562         -    sqlite3CodeRhsOfIN(pParse, pX, iTab, eType==IN_INDEX_ROWID);
         2559  +    sqlite3CodeRhsOfIN(pParse, pX, iTab);
  2563   2560       if( rMayHaveNull ){
  2564   2561         sqlite3SetHasNullFlag(v, iTab, rMayHaveNull);
  2565   2562       }
  2566   2563       pParse->nQueryLoop = savedNQueryLoop;
  2567   2564     }
  2568   2565   
  2569   2566     if( aiMap && eType!=IN_INDEX_INDEX_ASC && eType!=IN_INDEX_INDEX_DESC ){
................................................................................
  2656   2653   **
  2657   2654   ** The pExpr parameter is the IN operator.  The cursor number for the
  2658   2655   ** constructed ephermeral table is returned.  The first time the ephemeral
  2659   2656   ** table is computed, the cursor number is also stored in pExpr->iTable,
  2660   2657   ** however the cursor number returned might not be the same, as it might
  2661   2658   ** have been duplicated using OP_OpenDup.
  2662   2659   **
  2663         -** If parameter isRowid is non-zero, then LHS of the IN operator is guaranteed
  2664         -** to be a non-null integer. In this case, the ephemeral table can be an
  2665         -** table B-Tree that keyed by only integers.  The more general cases uses
  2666         -** an index B-Tree which can have arbitrary keys, but is slower to both
  2667         -** read and write.
  2668         -**
  2669   2660   ** If the LHS expression ("x" in the examples) is a column value, or
  2670   2661   ** the SELECT statement returns a column value, then the affinity of that
  2671   2662   ** column is used to build the index keys. If both 'x' and the
  2672   2663   ** SELECT... statement are columns, then numeric affinity is used
  2673   2664   ** if either column has NUMERIC or INTEGER affinity. If neither
  2674   2665   ** 'x' nor the SELECT... statement are columns, then numeric affinity
  2675   2666   ** is used.
  2676   2667   */
  2677   2668   void sqlite3CodeRhsOfIN(
  2678   2669     Parse *pParse,          /* Parsing context */
  2679   2670     Expr *pExpr,            /* The IN operator */
  2680         -  int iTab,               /* Use this cursor number */
  2681         -  int isRowid             /* If true, LHS is a rowid */
         2671  +  int iTab                /* Use this cursor number */
  2682   2672   ){
  2683   2673     int addrOnce = 0;           /* Address of the OP_Once instruction at top */
  2684   2674     int addr;                   /* Address of OP_OpenEphemeral instruction */
  2685   2675     Expr *pLeft;                /* the LHS of the IN operator */
  2686   2676     KeyInfo *pKeyInfo = 0;      /* Key information */
  2687   2677     int nVal;                   /* Size of vector pLeft */
  2688   2678     Vdbe *v;                    /* The prepared statement under construction */
................................................................................
  2727   2717   
  2728   2718       addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
  2729   2719     }
  2730   2720   
  2731   2721     /* Check to see if this is a vector IN operator */
  2732   2722     pLeft = pExpr->pLeft;
  2733   2723     nVal = sqlite3ExprVectorSize(pLeft);
  2734         -  assert( !isRowid || nVal==1 );
  2735   2724   
  2736   2725     /* Construct the ephemeral table that will contain the content of
  2737   2726     ** RHS of the IN operator.
  2738   2727     */
  2739   2728     pExpr->iTable = iTab;
  2740         -  addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, 
  2741         -      pExpr->iTable, (isRowid?0:nVal));
         2729  +  addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, nVal);
  2742   2730   #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
  2743   2731     if( ExprHasProperty(pExpr, EP_xIsSelect) ){
  2744   2732       VdbeComment((v, "Result of SELECT %u", pExpr->x.pSelect->selId));
  2745   2733     }else{
  2746   2734       VdbeComment((v, "RHS of IN operator"));
  2747   2735     }
  2748   2736   #endif
  2749         -  pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, nVal, 1);
         2737  +  pKeyInfo = sqlite3KeyInfoAlloc(pParse->db, nVal, 1);
  2750   2738   
  2751   2739     if( ExprHasProperty(pExpr, EP_xIsSelect) ){
  2752   2740       /* Case 1:     expr IN (SELECT ...)
  2753   2741       **
  2754   2742       ** Generate code to write the results of the select into the temporary
  2755   2743       ** table allocated and opened above.
  2756   2744       */
  2757   2745       Select *pSelect = pExpr->x.pSelect;
  2758   2746       ExprList *pEList = pSelect->pEList;
  2759   2747   
  2760   2748       ExplainQueryPlan((pParse, 1, "%sLIST SUBQUERY %d",
  2761   2749           addrOnce?"":"CORRELATED ", pSelect->selId
  2762   2750       ));
  2763         -    assert( !isRowid );
  2764   2751       /* If the LHS and RHS of the IN operator do not match, that
  2765   2752       ** error will have been caught long before we reach this point. */
  2766   2753       if( ALWAYS(pEList->nExpr==nVal) ){
  2767   2754         SelectDest dest;
  2768   2755         int i;
  2769   2756         sqlite3SelectDestInit(&dest, SRT_Set, iTab);
  2770   2757         dest.zAffSdst = exprINAffinity(pParse, pExpr);
................................................................................
  2809   2796         assert( sqlite3KeyInfoIsWriteable(pKeyInfo) );
  2810   2797         pKeyInfo->aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
  2811   2798       }
  2812   2799   
  2813   2800       /* Loop through each expression in <exprlist>. */
  2814   2801       r1 = sqlite3GetTempReg(pParse);
  2815   2802       r2 = sqlite3GetTempReg(pParse);
  2816         -    if( isRowid ) sqlite3VdbeAddOp4(v, OP_Blob, 0, r2, 0, "", P4_STATIC);
  2817   2803       for(i=pList->nExpr, pItem=pList->a; i>0; i--, pItem++){
  2818   2804         Expr *pE2 = pItem->pExpr;
  2819         -      int iValToIns;
  2820   2805   
  2821   2806         /* If the expression is not constant then we will need to
  2822   2807         ** disable the test that was generated above that makes sure
  2823   2808         ** this code only executes once.  Because for a non-constant
  2824   2809         ** expression we need to rerun this code each time.
  2825   2810         */
  2826   2811         if( addrOnce && !sqlite3ExprIsConstant(pE2) ){
  2827   2812           sqlite3VdbeChangeToNoop(v, addrOnce);
  2828   2813           addrOnce = 0;
  2829   2814         }
  2830   2815   
  2831   2816         /* Evaluate the expression and insert it into the temp table */
  2832         -      if( isRowid && sqlite3ExprIsInteger(pE2, &iValToIns) ){
  2833         -        sqlite3VdbeAddOp3(v, OP_InsertInt, iTab, r2, iValToIns);
  2834         -      }else{
  2835         -        r3 = sqlite3ExprCodeTarget(pParse, pE2, r1);
  2836         -        if( isRowid ){
  2837         -          sqlite3VdbeAddOp2(v, OP_MustBeInt, r3,
  2838         -                            sqlite3VdbeCurrentAddr(v)+2);
  2839         -          VdbeCoverage(v);
  2840         -          sqlite3VdbeAddOp3(v, OP_Insert, iTab, r2, r3);
  2841         -        }else{
  2842         -          sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1);
  2843         -          sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r2, r3, 1);
  2844         -        }
  2845         -      }
         2817  +      r3 = sqlite3ExprCodeTarget(pParse, pE2, r1);
         2818  +      sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1);
         2819  +      sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r2, r3, 1);
  2846   2820       }
  2847   2821       sqlite3ReleaseTempReg(pParse, r1);
  2848   2822       sqlite3ReleaseTempReg(pParse, r2);
  2849   2823     }
  2850   2824     if( pKeyInfo ){
  2851   2825       sqlite3VdbeChangeP4(v, addr, (void *)pKeyInfo, P4_KEYINFO);
  2852   2826     }

Changes to src/func.c.

  1801   1801   ** Set the LIKEOPT flag on the 2-argument function with the given name.
  1802   1802   */
  1803   1803   static void setLikeOptFlag(sqlite3 *db, const char *zName, u8 flagVal){
  1804   1804     FuncDef *pDef;
  1805   1805     pDef = sqlite3FindFunction(db, zName, 2, SQLITE_UTF8, 0);
  1806   1806     if( ALWAYS(pDef) ){
  1807   1807       pDef->funcFlags |= flagVal;
         1808  +  }
         1809  +  pDef = sqlite3FindFunction(db, zName, 3, SQLITE_UTF8, 0);
         1810  +  if( pDef ){
         1811  +    pDef->funcFlags |= flagVal;
  1808   1812     }
  1809   1813   }
  1810   1814   
  1811   1815   /*
  1812   1816   ** Register the built-in LIKE and GLOB functions.  The caseSensitive
  1813   1817   ** parameter determines whether or not the LIKE operator is case
  1814   1818   ** sensitive.  GLOB is always case sensitive.

Changes to src/insert.c.

  1665   1665           sqlite3VdbeAddOp2(v, iField<0 ? OP_IntCopy : OP_SCopy, x, regIdx+i);
  1666   1666           VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
  1667   1667         }
  1668   1668       }
  1669   1669       sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
  1670   1670       VdbeComment((v, "for %s", pIdx->zName));
  1671   1671   #ifdef SQLITE_ENABLE_NULL_TRIM
  1672         -    if( pIdx->idxType==2 ) sqlite3SetMakeRecordP5(v, pIdx->pTable);
         1672  +    if( pIdx->idxType==SQLITE_IDXTYPE_PRIMARYKEY ){
         1673  +      sqlite3SetMakeRecordP5(v, pIdx->pTable);
         1674  +    }
  1673   1675   #endif
  1674   1676   
  1675   1677       /* In an UPDATE operation, if this index is the PRIMARY KEY index 
  1676   1678       ** of a WITHOUT ROWID table and there has been no change the
  1677   1679       ** primary key, then no collision is possible.  The collision detection
  1678   1680       ** logic below can all be skipped. */
  1679   1681       if( isUpdate && pPk==pIdx && pkChng==0 ){
................................................................................
  1915   1917       pik_flags = (useSeekResult ? OPFLAG_USESEEKRESULT : 0);
  1916   1918       if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
  1917   1919         assert( pParse->nested==0 );
  1918   1920         pik_flags |= OPFLAG_NCHANGE;
  1919   1921         pik_flags |= (update_flags & OPFLAG_SAVEPOSITION);
  1920   1922   #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
  1921   1923         if( update_flags==0 ){
  1922         -        sqlite3VdbeAddOp4(v, OP_InsertInt, 
  1923         -            iIdxCur+i, aRegIdx[i], 0, (char*)pTab, P4_TABLE
         1924  +        int r = sqlite3GetTempReg(pParse);
         1925  +        sqlite3VdbeAddOp2(v, OP_Integer, 0, r);
         1926  +        sqlite3VdbeAddOp4(v, OP_Insert, 
         1927  +            iIdxCur+i, aRegIdx[i], r, (char*)pTab, P4_TABLE
  1924   1928           );
  1925   1929           sqlite3VdbeChangeP5(v, OPFLAG_ISNOOP);
         1930  +        sqlite3ReleaseTempReg(pParse, r);
  1926   1931         }
  1927   1932   #endif
  1928   1933       }
  1929   1934       sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i],
  1930   1935                            aRegIdx[i]+1,
  1931   1936                            pIdx->uniqNotNull ? pIdx->nKeyCol: pIdx->nColumn);
  1932   1937       sqlite3VdbeChangeP5(v, pik_flags);
................................................................................
  2406   2411           if( sqlite3_stricmp(sqlite3StrBINARY, zColl) ) break;
  2407   2412         }
  2408   2413         if( i==pSrcIdx->nColumn ){
  2409   2414           idxInsFlags = OPFLAG_USESEEKRESULT;
  2410   2415           sqlite3VdbeAddOp1(v, OP_SeekEnd, iDest);
  2411   2416         }
  2412   2417       }
  2413         -    if( !HasRowid(pSrc) && pDestIdx->idxType==2 ){
         2418  +    if( !HasRowid(pSrc) && pDestIdx->idxType==SQLITE_IDXTYPE_PRIMARYKEY ){
  2414   2419         idxInsFlags |= OPFLAG_NCHANGE;
  2415   2420       }
  2416   2421       sqlite3VdbeAddOp2(v, OP_IdxInsert, iDest, regData);
  2417   2422       sqlite3VdbeChangeP5(v, idxInsFlags|OPFLAG_APPEND);
  2418   2423       sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
  2419   2424       sqlite3VdbeJumpHere(v, addr1);
  2420   2425       sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);

Changes to src/os_unix.c.

  7818   7818     ** array cannot be const.
  7819   7819     */
  7820   7820     static sqlite3_vfs aVfs[] = {
  7821   7821   #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
  7822   7822       UNIXVFS("unix",          autolockIoFinder ),
  7823   7823   #elif OS_VXWORKS
  7824   7824       UNIXVFS("unix",          vxworksIoFinder ),
         7825  +#elif __Fuchsia__
         7826  +    /* We are told that Fuchsia only supports dot-file locking */
         7827  +    UNIXVFS("unix",          dotlockIoFinder ),
  7825   7828   #else
  7826   7829       UNIXVFS("unix",          posixIoFinder ),
  7827   7830   #endif
  7828   7831       UNIXVFS("unix-none",     nolockIoFinder ),
  7829   7832       UNIXVFS("unix-dotfile",  dotlockIoFinder ),
  7830   7833       UNIXVFS("unix-excl",     posixIoFinder ),
  7831   7834   #if OS_VXWORKS

Changes to src/pager.c.

   833    833   **   * the database file is open,
   834    834   **   * there are no dirty pages in the cache, and
   835    835   **   * the desired page is not currently in the wal file.
   836    836   */
   837    837   int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno){
   838    838     if( pPager->fd->pMethods==0 ) return 0;
   839    839     if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0;
          840  +#ifdef SQLITE_HAS_CODEC
          841  +  if( pPager->xCodec!=0 ) return 0;
          842  +#endif
   840    843   #ifndef SQLITE_OMIT_WAL
   841    844     if( pPager->pWal ){
   842    845       u32 iRead = 0;
   843    846       int rc;
   844    847       rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iRead);
   845    848       return (rc==SQLITE_OK && iRead==0);
   846    849     }
................................................................................
  3782   3785       char *pNew = NULL;             /* New temp space */
  3783   3786       i64 nByte = 0;
  3784   3787   
  3785   3788       if( pPager->eState>PAGER_OPEN && isOpen(pPager->fd) ){
  3786   3789         rc = sqlite3OsFileSize(pPager->fd, &nByte);
  3787   3790       }
  3788   3791       if( rc==SQLITE_OK ){
  3789         -      pNew = (char *)sqlite3PageMalloc(pageSize);
  3790         -      if( !pNew ) rc = SQLITE_NOMEM_BKPT;
         3792  +      /* 8 bytes of zeroed overrun space is sufficient so that the b-tree
         3793  +      * cell header parser will never run off the end of the allocation */
         3794  +      pNew = (char *)sqlite3PageMalloc(pageSize+8);
         3795  +      if( !pNew ){
         3796  +        rc = SQLITE_NOMEM_BKPT;
         3797  +      }else{
         3798  +        memset(pNew+pageSize, 0, 8);
         3799  +      }
  3791   3800       }
  3792   3801   
  3793   3802       if( rc==SQLITE_OK ){
  3794   3803         pager_reset(pPager);
  3795   3804         rc = sqlite3PcacheSetPageSize(pPager->pPCache, pageSize);
  3796   3805       }
  3797   3806       if( rc==SQLITE_OK ){

Changes to src/printf.c.

   132    132   
   133    133   /*
   134    134   ** Set the StrAccum object to an error mode.
   135    135   */
   136    136   static void setStrAccumError(StrAccum *p, u8 eError){
   137    137     assert( eError==SQLITE_NOMEM || eError==SQLITE_TOOBIG );
   138    138     p->accError = eError;
   139         -  p->nAlloc = 0;
          139  +  if( p->mxAlloc ) sqlite3_str_reset(p);
   140    140   }
   141    141   
   142    142   /*
   143    143   ** Extra argument values from a PrintfArguments object
   144    144   */
   145    145   static sqlite3_int64 getIntArg(PrintfArguments *p){
   146    146     if( p->nArg<=p->nUsed ) return 0;
................................................................................
   162    162   ** of the output buffer in pAccum, then cause an SQLITE_TOOBIG error.
   163    163   ** Do the size check before the memory allocation to prevent rogue
   164    164   ** SQL from requesting large allocations using the precision or width
   165    165   ** field of the printf() function.
   166    166   */
   167    167   static char *printfTempBuf(sqlite3_str *pAccum, sqlite3_int64 n){
   168    168     char *z;
          169  +  if( pAccum->accError ) return 0;
   169    170     if( n>pAccum->nAlloc && n>pAccum->mxAlloc ){
   170    171       setStrAccumError(pAccum, SQLITE_TOOBIG);
   171    172       return 0;
   172    173     }
   173    174     z = sqlite3DbMallocRaw(pAccum->db, n);
   174    175     if( z==0 ){
   175    176       setStrAccumError(pAccum, SQLITE_NOMEM);
................................................................................
   881    882     assert( p->nChar+(i64)N >= p->nAlloc ); /* Only called if really needed */
   882    883     if( p->accError ){
   883    884       testcase(p->accError==SQLITE_TOOBIG);
   884    885       testcase(p->accError==SQLITE_NOMEM);
   885    886       return 0;
   886    887     }
   887    888     if( p->mxAlloc==0 ){
   888         -    N = p->nAlloc - p->nChar - 1;
   889    889       setStrAccumError(p, SQLITE_TOOBIG);
   890         -    return N;
          890  +    return p->nAlloc - p->nChar - 1;
   891    891     }else{
   892    892       char *zOld = isMalloced(p) ? p->zText : 0;
   893    893       i64 szNew = p->nChar;
   894    894       szNew += N + 1;
   895    895       if( szNew+p->nChar<=p->mxAlloc ){
   896    896         /* Force exponential buffer size growth as long as it does not overflow,
   897    897         ** to avoid having to call this routine too often */
................................................................................
   955    955   ** Append N bytes of text from z to the StrAccum object.  Increase the
   956    956   ** size of the memory allocation for StrAccum if necessary.
   957    957   */
   958    958   void sqlite3_str_append(sqlite3_str *p, const char *z, int N){
   959    959     assert( z!=0 || N==0 );
   960    960     assert( p->zText!=0 || p->nChar==0 || p->accError );
   961    961     assert( N>=0 );
   962         -  assert( p->accError==0 || p->nAlloc==0 );
          962  +  assert( p->accError==0 || p->nAlloc==0 || p->mxAlloc==0 );
   963    963     if( p->nChar+N >= p->nAlloc ){
   964    964       enlargeAndAppend(p,z,N);
   965    965     }else if( N ){
   966    966       assert( p->zText );
   967    967       p->nChar += N;
   968    968       memcpy(&p->zText[p->nChar-N], z, N);
   969    969     }

Changes to src/resolve.c.

  1239   1239         resolveAlias(pParse, pEList, pItem->u.x.iOrderByCol-1, pItem->pExpr,
  1240   1240                      zType,0);
  1241   1241       }
  1242   1242     }
  1243   1243     return 0;
  1244   1244   }
  1245   1245   
         1246  +#ifndef SQLITE_OMIT_WINDOWFUNC
         1247  +/*
         1248  +** Walker callback for resolveRemoveWindows().
         1249  +*/
         1250  +static int resolveRemoveWindowsCb(Walker *pWalker, Expr *pExpr){
         1251  +  if( ExprHasProperty(pExpr, EP_WinFunc) ){
         1252  +    Window **pp;
         1253  +    for(pp=&pWalker->u.pSelect->pWin; *pp; pp=&(*pp)->pNextWin){
         1254  +      if( *pp==pExpr->y.pWin ){
         1255  +        *pp = (*pp)->pNextWin;
         1256  +        break;
         1257  +      }    
         1258  +    }
         1259  +  }
         1260  +  return WRC_Continue;
         1261  +}
         1262  +
         1263  +/*
         1264  +** Remove any Window objects owned by the expression pExpr from the
         1265  +** Select.pWin list of Select object pSelect.
         1266  +*/
         1267  +static void resolveRemoveWindows(Select *pSelect, Expr *pExpr){
         1268  +  Walker sWalker;
         1269  +  memset(&sWalker, 0, sizeof(Walker));
         1270  +  sWalker.xExprCallback = resolveRemoveWindowsCb;
         1271  +  sWalker.u.pSelect = pSelect;
         1272  +  sqlite3WalkExpr(&sWalker, pExpr);
         1273  +}
         1274  +#else
         1275  +# define resolveRemoveWindows(x,y)
         1276  +#endif
         1277  +
  1246   1278   /*
  1247   1279   ** pOrderBy is an ORDER BY or GROUP BY clause in SELECT statement pSelect.
  1248   1280   ** The Name context of the SELECT statement is pNC.  zType is either
  1249   1281   ** "ORDER" or "GROUP" depending on which type of clause pOrderBy is.
  1250   1282   **
  1251   1283   ** This routine resolves each term of the clause into an expression.
  1252   1284   ** If the order-by term is an integer I between 1 and N (where N is the
................................................................................
  1305   1337       /* Otherwise, treat the ORDER BY term as an ordinary expression */
  1306   1338       pItem->u.x.iOrderByCol = 0;
  1307   1339       if( sqlite3ResolveExprNames(pNC, pE) ){
  1308   1340         return 1;
  1309   1341       }
  1310   1342       for(j=0; j<pSelect->pEList->nExpr; j++){
  1311   1343         if( sqlite3ExprCompare(0, pE, pSelect->pEList->a[j].pExpr, -1)==0 ){
  1312         -#ifndef SQLITE_OMIT_WINDOWFUNC
  1313         -        if( ExprHasProperty(pE, EP_WinFunc) ){
  1314         -          /* Since this window function is being changed into a reference
  1315         -          ** to the same window function the result set, remove the instance
  1316         -          ** of this window function from the Select.pWin list. */
  1317         -          Window **pp;
  1318         -          for(pp=&pSelect->pWin; *pp; pp=&(*pp)->pNextWin){
  1319         -            if( *pp==pE->y.pWin ){
  1320         -              *pp = (*pp)->pNextWin;
  1321         -            }    
  1322         -          }
  1323         -        }
  1324         -#endif
         1344  +        /* Since this expresion is being changed into a reference
         1345  +        ** to an identical expression in the result set, remove all Window
         1346  +        ** objects belonging to the expression from the Select.pWin list. */
         1347  +        resolveRemoveWindows(pSelect, pE);
  1325   1348           pItem->u.x.iOrderByCol = j+1;
  1326   1349         }
  1327   1350       }
  1328   1351     }
  1329   1352     return sqlite3ResolveOrderGroupBy(pParse, pSelect, pOrderBy, zType);
  1330   1353   }
  1331   1354   

Changes to src/select.c.

  5302   5302   
  5303   5303   /*
  5304   5304   ** Update the accumulator memory cells for an aggregate based on
  5305   5305   ** the current cursor position.
  5306   5306   **
  5307   5307   ** If regAcc is non-zero and there are no min() or max() aggregates
  5308   5308   ** in pAggInfo, then only populate the pAggInfo->nAccumulator accumulator
  5309         -** registers i register regAcc contains 0. The caller will take care
         5309  +** registers if register regAcc contains 0. The caller will take care
  5310   5310   ** of setting and clearing regAcc.
  5311   5311   */
  5312   5312   static void updateAccumulator(Parse *pParse, int regAcc, AggInfo *pAggInfo){
  5313   5313     Vdbe *v = pParse->pVdbe;
  5314   5314     int i;
  5315   5315     int regHit = 0;
  5316   5316     int addrHitTest = 0;

Changes to src/shell.c.in.

  2742   2742   #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_SELECTTRACE)
  2743   2743     sqlite3SelectTrace = savedSelectTrace;
  2744   2744   #endif
  2745   2745   #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
  2746   2746     sqlite3WhereTrace = savedWhereTrace;
  2747   2747   #endif
  2748   2748   }
         2749  +
         2750  +/* Name of the TEMP table that holds bind parameter values */
         2751  +#define BIND_PARAM_TABLE "$Parameters"
         2752  +
         2753  +/* Create the TEMP table used to store parameter bindings */
         2754  +static void bind_table_init(ShellState *p){
         2755  +  sqlite3_exec(p->db,
         2756  +    "CREATE TABLE IF NOT EXISTS temp.[" BIND_PARAM_TABLE "](\n"
         2757  +    "  key TEXT PRIMARY KEY,\n"
         2758  +    "  value ANY\n"
         2759  +    ") WITHOUT ROWID;",
         2760  +    0, 0, 0);
         2761  +}
         2762  +
         2763  +/*
         2764  +** Bind parameters on a prepared statement.
         2765  +**
         2766  +** Parameter bindings are taken from a TEMP table of the form:
         2767  +**
         2768  +**    CREATE TEMP TABLE "$Parameters"(key TEXT PRIMARY KEY, value)
         2769  +**    WITHOUT ROWID;
         2770  +**
         2771  +** No bindings occur if this table does not exist.  The special character '$'
         2772  +** is included in the table name to help prevent collisions with actual tables.
         2773  +** The table must be in the TEMP schema.
         2774  +*/
         2775  +static void bind_prepared_stmt(ShellState *pArg, sqlite3_stmt *pStmt){
         2776  +  int nVar;
         2777  +  int i;
         2778  +  int rc;
         2779  +  sqlite3_stmt *pQ = 0;
         2780  +
         2781  +  nVar = sqlite3_bind_parameter_count(pStmt);
         2782  +  if( nVar==0 ) return;  /* Nothing to do */
         2783  +  if( sqlite3_table_column_metadata(pArg->db, "TEMP", BIND_PARAM_TABLE,
         2784  +                                    "key", 0, 0, 0, 0, 0)!=SQLITE_OK ){
         2785  +    return; /* Parameter table does not exist */
         2786  +  }
         2787  +  rc = sqlite3_prepare_v2(pArg->db,
         2788  +          "SELECT value FROM temp.\"" BIND_PARAM_TABLE "\""
         2789  +          " WHERE key=?1", -1, &pQ, 0);
         2790  +  if( rc || pQ==0 ) return;
         2791  +  for(i=1; i<=nVar; i++){
         2792  +    char zNum[30];
         2793  +    const char *zVar = sqlite3_bind_parameter_name(pStmt, i);
         2794  +    if( zVar==0 ){
         2795  +      sqlite3_snprintf(sizeof(zNum),zNum,"?%d",i);
         2796  +      zVar = zNum;
         2797  +    }
         2798  +    sqlite3_bind_text(pQ, 1, zVar, -1, SQLITE_STATIC);
         2799  +    if( sqlite3_step(pQ)==SQLITE_ROW ){
         2800  +      sqlite3_bind_value(pStmt, i, sqlite3_column_value(pQ, 0));
         2801  +    }else{
         2802  +      sqlite3_bind_null(pStmt, i);
         2803  +    }
         2804  +    sqlite3_reset(pQ);
         2805  +  }
         2806  +  sqlite3_finalize(pQ);
         2807  +}
  2749   2808   
  2750   2809   /*
  2751   2810   ** Run a prepared statement
  2752   2811   */
  2753   2812   static void exec_prepared_stmt(
  2754   2813     ShellState *pArg,                                /* Pointer to ShellState */
  2755   2814     sqlite3_stmt *pStmt                              /* Statment to run */
................................................................................
  3062   3121           /* If the shell is currently in ".explain" mode, gather the extra
  3063   3122           ** data required to add indents to the output.*/
  3064   3123           if( pArg->cMode==MODE_Explain ){
  3065   3124             explain_data_prepare(pArg, pStmt);
  3066   3125           }
  3067   3126         }
  3068   3127   
         3128  +      bind_prepared_stmt(pArg, pStmt);
  3069   3129         exec_prepared_stmt(pArg, pStmt);
  3070   3130         explain_data_delete(pArg);
  3071   3131         eqp_render(pArg);
  3072   3132   
  3073   3133         /* print usage stats if stats on */
  3074   3134         if( pArg && pArg->statsOn ){
  3075   3135           display_stats(db, pArg, 0);
................................................................................
  3493   3553     "        --maxsize N     Maximum size for --hexdb or --deserialized database",
  3494   3554   #endif
  3495   3555     "        --new           Initialize FILE to an empty database",
  3496   3556     "        --readonly      Open FILE readonly",
  3497   3557     "        --zip           FILE is a ZIP archive",
  3498   3558     ".output ?FILE?           Send output to FILE or stdout if FILE is omitted",
  3499   3559     "     If FILE begins with '|' then open it as a pipe.",
         3560  +  ".parameter CMD ...       Manage SQL parameter bindings",
         3561  +  "   clear                   Erase all bindings",
         3562  +  "   init                    Initialize the TEMP table that holds bindings",
         3563  +  "   list                    List the current parameter bindings",
         3564  +  "   set PARAMETER VALUE     Given SQL parameter PARAMETER a value of VALUE",
         3565  +  "                           PARAMETER should start with '$', ':', '@', or '?'",
         3566  +  "   unset PARAMETER         Remove PARAMETER from the binding table",
  3500   3567     ".print STRING...         Print literal STRING",
  3501   3568   #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
  3502   3569     ".progress N              Invoke progress handler after every N opcodes",
  3503   3570     "   --limit N                 Interrupt after N progress callbacks",
  3504   3571     "   --once                    Do no more than one progress interrupt",
  3505   3572     "   --quiet|-q                No output except at interrupts",
  3506   3573     "   --reset                   Reset the count for each input and interrupt",
................................................................................
  7023   7090           p->out = stdout;
  7024   7091           rc = 1;
  7025   7092         } else {
  7026   7093           sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
  7027   7094         }
  7028   7095       }
  7029   7096     }else
         7097  +
         7098  +  if( c=='p' && n>=3 && strncmp(azArg[0], "parameter", n)==0 ){
         7099  +    open_db(p,0);
         7100  +    if( nArg<=1 ) goto parameter_syntax_error;
         7101  +
         7102  +    /* .parameter clear
         7103  +    ** Clear all bind parameters by dropping the TEMP table that holds them.
         7104  +    */
         7105  +    if( nArg==2 && strcmp(azArg[1],"clear")==0 ){
         7106  +      sqlite3_exec(p->db, "DROP TABLE IF EXISTS temp.[" BIND_PARAM_TABLE "];",
         7107  +                   0, 0, 0);
         7108  +    }else
         7109  +
         7110  +    /* .parameter list
         7111  +    ** List all bind parameters.
         7112  +    */
         7113  +    if( nArg==2 && strcmp(azArg[1],"list")==0 ){
         7114  +      sqlite3_stmt *pStmt = 0;
         7115  +      int rx;
         7116  +      int len = 0;
         7117  +      rx = sqlite3_prepare_v2(p->db,
         7118  +             "SELECT max(length(key)) "
         7119  +             "FROM temp.[" BIND_PARAM_TABLE "];", -1, &pStmt, 0);
         7120  +      if( rx==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
         7121  +        len = sqlite3_column_int(pStmt, 0);
         7122  +        if( len>40 ) len = 40;
         7123  +      }
         7124  +      sqlite3_finalize(pStmt);
         7125  +      pStmt = 0;
         7126  +      if( len ){
         7127  +        rx = sqlite3_prepare_v2(p->db,
         7128  +             "SELECT key, quote(value) "
         7129  +             "FROM temp.[" BIND_PARAM_TABLE "];", -1, &pStmt, 0);
         7130  +        while( sqlite3_step(pStmt)==SQLITE_ROW ){
         7131  +          utf8_printf(p->out, "%-*s %s\n", len, sqlite3_column_text(pStmt,0),
         7132  +                      sqlite3_column_text(pStmt,1));
         7133  +        }
         7134  +        sqlite3_finalize(pStmt);
         7135  +      }
         7136  +    }else
         7137  +
         7138  +    /* .parameter init
         7139  +    ** Make sure the TEMP table used to hold bind parameters exists.
         7140  +    ** Create it if necessary.
         7141  +    */
         7142  +    if( nArg==2 && strcmp(azArg[1],"init")==0 ){
         7143  +      bind_table_init(p);
         7144  +    }else
         7145  +
         7146  +    /* .parameter set NAME VALUE
         7147  +    ** Set or reset a bind parameter.  NAME should be the full parameter
         7148  +    ** name exactly as it appears in the query.  (ex: $abc, @def).  The
         7149  +    ** VALUE can be in either SQL literal notation, or if not it will be
         7150  +    ** understood to be a text string.
         7151  +    */
         7152  +    if( nArg==4 && strcmp(azArg[1],"set")==0 ){
         7153  +      int rx;
         7154  +      char *zSql;
         7155  +      sqlite3_stmt *pStmt;
         7156  +      const char *zKey = azArg[2];
         7157  +      const char *zValue = azArg[3];
         7158  +      bind_table_init(p);
         7159  +      zSql = sqlite3_mprintf(
         7160  +                  "REPLACE INTO temp.[" BIND_PARAM_TABLE "](key,value)"
         7161  +                  "VALUES(%Q,%s);", zKey, zValue);
         7162  +      if( zSql==0 ) shell_out_of_memory();
         7163  +      pStmt = 0;
         7164  +      rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
         7165  +      sqlite3_free(zSql);
         7166  +      if( rx!=SQLITE_OK ){
         7167  +        sqlite3_finalize(pStmt);
         7168  +        pStmt = 0;
         7169  +        zSql = sqlite3_mprintf(
         7170  +                   "REPLACE INTO temp.[" BIND_PARAM_TABLE "](key,value)"
         7171  +                   "VALUES(%Q,%Q);", zKey, zValue);
         7172  +        if( zSql==0 ) shell_out_of_memory();
         7173  +        rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
         7174  +        sqlite3_free(zSql);
         7175  +        if( rx!=SQLITE_OK ){
         7176  +          utf8_printf(p->out, "Error: %s\n", sqlite3_errmsg(p->db));
         7177  +          sqlite3_finalize(pStmt);
         7178  +          pStmt = 0;
         7179  +          rc = 1;
         7180  +        }
         7181  +      }
         7182  +      sqlite3_step(pStmt);
         7183  +      sqlite3_finalize(pStmt);
         7184  +    }else
         7185  +
         7186  +    /* .parameter unset NAME
         7187  +    ** Remove the NAME binding from the parameter binding table, if it
         7188  +    ** exists.
         7189  +    */
         7190  +    if( nArg==3 && strcmp(azArg[1],"unset")==0 ){
         7191  +      char *zSql = sqlite3_mprintf(
         7192  +          "DELETE FROM temp.[" BIND_PARAM_TABLE "] WHERE key=%Q", azArg[2]);
         7193  +      if( zSql==0 ) shell_out_of_memory();
         7194  +      sqlite3_exec(p->db, zSql, 0, 0, 0);
         7195  +      sqlite3_free(zSql);
         7196  +    }else
         7197  +    /* If no command name matches, show a syntax error */
         7198  +    parameter_syntax_error:
         7199  +    showHelp(p->out, "parameter");
         7200  +  }else
  7030   7201   
  7031   7202     if( c=='p' && n>=3 && strncmp(azArg[0], "print", n)==0 ){
  7032   7203       int i;
  7033   7204       for(i=1; i<nArg; i++){
  7034   7205         if( i>1 ) raw_printf(p->out, " ");
  7035   7206         utf8_printf(p->out, "%s", azArg[i]);
  7036   7207       }

Changes to src/sqlite.h.in.

  2082   2082   ** The second parameter is a pointer to an integer into which
  2083   2083   ** is written 0 or 1 to indicate whether triggers are disabled or enabled
  2084   2084   ** following this call.  The second parameter may be a NULL pointer, in
  2085   2085   ** which case the trigger setting is not reported back. </dd>
  2086   2086   **
  2087   2087   ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
  2088   2088   ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
  2089         -** <dd> ^This option is used to enable or disable the two-argument
  2090         -** version of the [fts3_tokenizer()] function which is part of the
         2089  +** <dd> ^This option is used to enable or disable the
         2090  +** [fts3_tokenizer()] function which is part of the
  2091   2091   ** [FTS3] full-text search engine extension.
  2092   2092   ** There should be two additional arguments.
  2093   2093   ** The first argument is an integer which is 0 to disable fts3_tokenizer() or
  2094   2094   ** positive to enable fts3_tokenizer() or negative to leave the setting
  2095   2095   ** unchanged.
  2096   2096   ** The second parameter is a pointer to an integer into which
  2097   2097   ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
................................................................................
  2365   2365   ** does not affect the value returned by sqlite3_total_changes().
  2366   2366   ** 
  2367   2367   ** ^Changes made as part of [foreign key actions] are included in the
  2368   2368   ** count, but those made as part of REPLACE constraint resolution are
  2369   2369   ** not. ^Changes to a view that are intercepted by INSTEAD OF triggers 
  2370   2370   ** are not counted.
  2371   2371   **
  2372         -** This the [sqlite3_total_changes(D)] interface only reports the number
         2372  +** The [sqlite3_total_changes(D)] interface only reports the number
  2373   2373   ** of rows that changed due to SQL statement run against database
  2374   2374   ** connection D.  Any changes by other database connections are ignored.
  2375   2375   ** To detect changes against a database file from other database
  2376   2376   ** connections use the [PRAGMA data_version] command or the
  2377   2377   ** [SQLITE_FCNTL_DATA_VERSION] [file control].
  2378   2378   ** 
  2379   2379   ** If a separate thread makes changes on the same database connection

Changes to src/sqliteInt.h.

  4283   4283   void sqlite3Reindex(Parse*, Token*, Token*);
  4284   4284   void sqlite3AlterFunctions(void);
  4285   4285   void sqlite3AlterRenameTable(Parse*, SrcList*, Token*);
  4286   4286   void sqlite3AlterRenameColumn(Parse*, SrcList*, Token*, Token*);
  4287   4287   int sqlite3GetToken(const unsigned char *, int *);
  4288   4288   void sqlite3NestedParse(Parse*, const char*, ...);
  4289   4289   void sqlite3ExpirePreparedStatements(sqlite3*, int);
  4290         -void sqlite3CodeRhsOfIN(Parse*, Expr*, int, int);
         4290  +void sqlite3CodeRhsOfIN(Parse*, Expr*, int);
  4291   4291   int sqlite3CodeSubselect(Parse*, Expr*);
  4292   4292   void sqlite3SelectPrep(Parse*, Select*, NameContext*);
  4293   4293   void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
  4294   4294   int sqlite3MatchSpanName(const char*, const char*, const char*, const char*);
  4295   4295   int sqlite3ResolveExprNames(NameContext*, Expr*);
  4296   4296   int sqlite3ResolveExprListNames(NameContext*, ExprList*);
  4297   4297   void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);

Changes to src/tclsqlite.c.

    89     89   
    90     90   /* Forward declaration */
    91     91   typedef struct SqliteDb SqliteDb;
    92     92   
    93     93   /*
    94     94   ** New SQL functions can be created as TCL scripts.  Each such function
    95     95   ** is described by an instance of the following structure.
           96  +**
           97  +** Variable eType may be set to SQLITE_INTEGER, SQLITE_FLOAT, SQLITE_TEXT,
           98  +** SQLITE_BLOB or SQLITE_NULL. If it is SQLITE_NULL, then the implementation
           99  +** attempts to determine the type of the result based on the Tcl object.
          100  +** If it is SQLITE_TEXT or SQLITE_BLOB, then a text (sqlite3_result_text())
          101  +** or blob (sqlite3_result_blob()) is returned. If it is SQLITE_INTEGER
          102  +** or SQLITE_FLOAT, then an attempt is made to return an integer or float
          103  +** value, falling back to float and then text if this is not possible.
    96    104   */
    97    105   typedef struct SqlFunc SqlFunc;
    98    106   struct SqlFunc {
    99    107     Tcl_Interp *interp;   /* The TCL interpret to execute the function */
   100    108     Tcl_Obj *pScript;     /* The Tcl_Obj representation of the script */
   101    109     SqliteDb *pDb;        /* Database connection that owns this function */
   102    110     int useEvalObjv;      /* True if it is safe to use Tcl_EvalObjv */
          111  +  int eType;            /* Type of value to return */
   103    112     char *zName;          /* Name of this function */
   104    113     SqlFunc *pNext;       /* Next function on the list of them all */
   105    114   };
   106    115   
   107    116   /*
   108    117   ** New collation sequences function can be created as TCL scripts.  Each such
   109    118   ** function is described by an instance of the following structure.
................................................................................
   146    155     Tcl_Interp *interp;        /* The interpreter used for this database */
   147    156     char *zBusy;               /* The busy callback routine */
   148    157     char *zCommit;             /* The commit hook callback routine */
   149    158     char *zTrace;              /* The trace callback routine */
   150    159     char *zTraceV2;            /* The trace_v2 callback routine */
   151    160     char *zProfile;            /* The profile callback routine */
   152    161     char *zProgress;           /* The progress callback routine */
          162  +  char *zBindFallback;       /* Callback to invoke on a binding miss */
   153    163     char *zAuth;               /* The authorization callback routine */
   154    164     int disableAuth;           /* Disable the authorizer if it exists */
   155    165     char *zNull;               /* Text to substitute for an SQL NULL value */
   156    166     SqlFunc *pFunc;            /* List of SQL functions */
   157    167     Tcl_Obj *pUpdateHook;      /* Update hook script (if any) */
   158    168     Tcl_Obj *pPreUpdateHook;   /* Pre-update hook script (if any) */
   159    169     Tcl_Obj *pRollbackHook;    /* Rollback hook script (if any) */
................................................................................
   536    546     }
   537    547     if( pDb->zTraceV2 ){
   538    548       Tcl_Free(pDb->zTraceV2);
   539    549     }
   540    550     if( pDb->zProfile ){
   541    551       Tcl_Free(pDb->zProfile);
   542    552     }
          553  +  if( pDb->zBindFallback ){
          554  +    Tcl_Free(pDb->zBindFallback);
          555  +  }
   543    556     if( pDb->zAuth ){
   544    557       Tcl_Free(pDb->zAuth);
   545    558     }
   546    559     if( pDb->zNull ){
   547    560       Tcl_Free(pDb->zNull);
   548    561     }
   549    562     if( pDb->pUpdateHook ){
................................................................................
   991   1004       sqlite3_result_error(context, Tcl_GetStringResult(p->interp), -1);
   992   1005     }else{
   993   1006       Tcl_Obj *pVar = Tcl_GetObjResult(p->interp);
   994   1007       int n;
   995   1008       u8 *data;
   996   1009       const char *zType = (pVar->typePtr ? pVar->typePtr->name : "");
   997   1010       char c = zType[0];
   998         -    if( c=='b' && strcmp(zType,"bytearray")==0 && pVar->bytes==0 ){
   999         -      /* Only return a BLOB type if the Tcl variable is a bytearray and
  1000         -      ** has no string representation. */
  1001         -      data = Tcl_GetByteArrayFromObj(pVar, &n);
  1002         -      sqlite3_result_blob(context, data, n, SQLITE_TRANSIENT);
  1003         -    }else if( c=='b' && strcmp(zType,"boolean")==0 ){
  1004         -      Tcl_GetIntFromObj(0, pVar, &n);
  1005         -      sqlite3_result_int(context, n);
  1006         -    }else if( c=='d' && strcmp(zType,"double")==0 ){
  1007         -      double r;
  1008         -      Tcl_GetDoubleFromObj(0, pVar, &r);
  1009         -      sqlite3_result_double(context, r);
  1010         -    }else if( (c=='w' && strcmp(zType,"wideInt")==0) ||
  1011         -          (c=='i' && strcmp(zType,"int")==0) ){
  1012         -      Tcl_WideInt v;
  1013         -      Tcl_GetWideIntFromObj(0, pVar, &v);
  1014         -      sqlite3_result_int64(context, v);
  1015         -    }else{
  1016         -      data = (unsigned char *)Tcl_GetStringFromObj(pVar, &n);
  1017         -      sqlite3_result_text(context, (char *)data, n, SQLITE_TRANSIENT);
  1018         -    }
         1011  +    int eType = p->eType;
         1012  +
         1013  +    if( eType==SQLITE_NULL ){
         1014  +      if( c=='b' && strcmp(zType,"bytearray")==0 && pVar->bytes==0 ){
         1015  +        /* Only return a BLOB type if the Tcl variable is a bytearray and
         1016  +        ** has no string representation. */
         1017  +        eType = SQLITE_BLOB;
         1018  +      }else if( (c=='b' && strcmp(zType,"boolean")==0)
         1019  +             || (c=='w' && strcmp(zType,"wideInt")==0)
         1020  +             || (c=='i' && strcmp(zType,"int")==0) 
         1021  +      ){
         1022  +        eType = SQLITE_INTEGER;
         1023  +      }else if( c=='d' && strcmp(zType,"double")==0 ){
         1024  +        eType = SQLITE_FLOAT;
         1025  +      }else{
         1026  +        eType = SQLITE_TEXT;
         1027  +      }
         1028  +    }
         1029  +
         1030  +    switch( eType ){
         1031  +      case SQLITE_BLOB: {
         1032  +        data = Tcl_GetByteArrayFromObj(pVar, &n);
         1033  +        sqlite3_result_blob(context, data, n, SQLITE_TRANSIENT);
         1034  +        break;
         1035  +      }
         1036  +      case SQLITE_INTEGER: {
         1037  +        Tcl_WideInt v;
         1038  +        if( TCL_OK==Tcl_GetWideIntFromObj(0, pVar, &v) ){
         1039  +          sqlite3_result_int64(context, v);
         1040  +          break;
         1041  +        }
         1042  +        /* fall-through */
         1043  +      }
         1044  +      case SQLITE_FLOAT: {
         1045  +        double r;
         1046  +        if( TCL_OK==Tcl_GetDoubleFromObj(0, pVar, &r) ){
         1047  +          sqlite3_result_double(context, r);
         1048  +          break;
         1049  +        }
         1050  +        /* fall-through */
         1051  +      }
         1052  +      default: {
         1053  +        data = (unsigned char *)Tcl_GetStringFromObj(pVar, &n);
         1054  +        sqlite3_result_text(context, (char *)data, n, SQLITE_TRANSIENT);
         1055  +        break;
         1056  +      }
         1057  +    }
         1058  +
  1019   1059     }
  1020   1060   }
  1021   1061   
  1022   1062   #ifndef SQLITE_OMIT_AUTHORIZATION
  1023   1063   /*
  1024   1064   ** This is the authentication function.  It appends the authentication
  1025   1065   ** type code and the two arguments to zCmd[] then invokes the result
................................................................................
  1261   1301     sqlite3_stmt *pStmt = 0;        /* Prepared statement object */
  1262   1302     SqlPreparedStmt *pPreStmt;      /* Pointer to cached statement */
  1263   1303     int nSql;                       /* Length of zSql in bytes */
  1264   1304     int nVar = 0;                   /* Number of variables in statement */
  1265   1305     int iParm = 0;                  /* Next free entry in apParm */
  1266   1306     char c;
  1267   1307     int i;
         1308  +  int needResultReset = 0;        /* Need to invoke Tcl_ResetResult() */
         1309  +  int rc = SQLITE_OK;             /* Value to return */
  1268   1310     Tcl_Interp *interp = pDb->interp;
  1269   1311   
  1270   1312     *ppPreStmt = 0;
  1271   1313   
  1272   1314     /* Trim spaces from the start of zSql and calculate the remaining length. */
  1273   1315     while( (c = zSql[0])==' ' || c=='\t' || c=='\r' || c=='\n' ){ zSql++; }
  1274   1316     nSql = strlen30(zSql);
................................................................................
  1348   1390     assert( 0==memcmp(pPreStmt->zSql, zSql, pPreStmt->nSql) );
  1349   1391   
  1350   1392     /* Bind values to parameters that begin with $ or : */
  1351   1393     for(i=1; i<=nVar; i++){
  1352   1394       const char *zVar = sqlite3_bind_parameter_name(pStmt, i);
  1353   1395       if( zVar!=0 && (zVar[0]=='$' || zVar[0]==':' || zVar[0]=='@') ){
  1354   1396         Tcl_Obj *pVar = Tcl_GetVar2Ex(interp, &zVar[1], 0, 0);
         1397  +      if( pVar==0 && pDb->zBindFallback!=0 ){
         1398  +        Tcl_Obj *pCmd;
         1399  +        int rx;
         1400  +        pCmd = Tcl_NewStringObj(pDb->zBindFallback, -1);
         1401  +        Tcl_IncrRefCount(pCmd);
         1402  +        Tcl_ListObjAppendElement(interp, pCmd, Tcl_NewStringObj(zVar,-1));
         1403  +        if( needResultReset ) Tcl_ResetResult(interp);
         1404  +        needResultReset = 1;
         1405  +        rx = Tcl_EvalObjEx(interp, pCmd, TCL_EVAL_DIRECT);
         1406  +        Tcl_DecrRefCount(pCmd);
         1407  +        if( rx==TCL_OK ){
         1408  +          pVar = Tcl_GetObjResult(interp);
         1409  +        }else if( rx==TCL_ERROR ){
         1410  +          rc = TCL_ERROR;
         1411  +          break;
         1412  +        }else{
         1413  +          pVar = 0;
         1414  +        }
         1415  +      }
  1355   1416         if( pVar ){
  1356   1417           int n;
  1357   1418           u8 *data;
  1358   1419           const char *zType = (pVar->typePtr ? pVar->typePtr->name : "");
  1359   1420           c = zType[0];
  1360   1421           if( zVar[0]=='@' ||
  1361   1422              (c=='b' && strcmp(zType,"bytearray")==0 && pVar->bytes==0) ){
................................................................................
  1383   1444             sqlite3_bind_text(pStmt, i, (char *)data, n, SQLITE_STATIC);
  1384   1445             Tcl_IncrRefCount(pVar);
  1385   1446             pPreStmt->apParm[iParm++] = pVar;
  1386   1447           }
  1387   1448         }else{
  1388   1449           sqlite3_bind_null(pStmt, i);
  1389   1450         }
         1451  +      if( needResultReset ) Tcl_ResetResult(pDb->interp);
  1390   1452       }
  1391   1453     }
  1392   1454     pPreStmt->nParm = iParm;
  1393   1455     *ppPreStmt = pPreStmt;
         1456  +  if( needResultReset && rc==TCL_OK ) Tcl_ResetResult(pDb->interp);
  1394   1457   
  1395         -  return TCL_OK;
         1458  +  return rc;
  1396   1459   }
  1397   1460   
  1398   1461   /*
  1399   1462   ** Release a statement reference obtained by calling dbPrepareAndBind().
  1400   1463   ** There should be exactly one call to this function for each call to
  1401   1464   ** dbPrepareAndBind().
  1402   1465   **
................................................................................
  1847   1910     int objc,
  1848   1911     Tcl_Obj *const*objv
  1849   1912   ){
  1850   1913     SqliteDb *pDb = (SqliteDb*)cd;
  1851   1914     int choice;
  1852   1915     int rc = TCL_OK;
  1853   1916     static const char *DB_strs[] = {
  1854         -    "authorizer",             "backup",                "busy",
  1855         -    "cache",                  "changes",               "close",
  1856         -    "collate",                "collation_needed",      "commit_hook",
  1857         -    "complete",               "copy",                  "deserialize",
  1858         -    "enable_load_extension",  "errorcode",             "eval",
  1859         -    "exists",                 "function",              "incrblob",
  1860         -    "interrupt",              "last_insert_rowid",     "nullvalue",
  1861         -    "onecolumn",              "preupdate",             "profile",
  1862         -    "progress",               "rekey",                 "restore",
  1863         -    "rollback_hook",          "serialize",             "status",
  1864         -    "timeout",                "total_changes",         "trace",
  1865         -    "trace_v2",               "transaction",           "unlock_notify",
  1866         -    "update_hook",            "version",               "wal_hook",
  1867         -    0                        
         1917  +    "authorizer",             "backup",                "bind_fallback",
         1918  +    "busy",                   "cache",                 "changes",
         1919  +    "close",                  "collate",               "collation_needed",
         1920  +    "commit_hook",            "complete",              "copy",
         1921  +    "deserialize",            "enable_load_extension", "errorcode",
         1922  +    "eval",                   "exists",                "function",
         1923  +    "incrblob",               "interrupt",             "last_insert_rowid",
         1924  +    "nullvalue",              "onecolumn",             "preupdate",
         1925  +    "profile",                "progress",              "rekey",
         1926  +    "restore",                "rollback_hook",         "serialize",
         1927  +    "status",                 "timeout",               "total_changes",
         1928  +    "trace",                  "trace_v2",              "transaction",
         1929  +    "unlock_notify",          "update_hook",           "version",
         1930  +    "wal_hook",               0                        
  1868   1931     };
  1869   1932     enum DB_enum {
  1870         -    DB_AUTHORIZER,            DB_BACKUP,               DB_BUSY,
  1871         -    DB_CACHE,                 DB_CHANGES,              DB_CLOSE,
  1872         -    DB_COLLATE,               DB_COLLATION_NEEDED,     DB_COMMIT_HOOK,
  1873         -    DB_COMPLETE,              DB_COPY,                 DB_DESERIALIZE,
  1874         -    DB_ENABLE_LOAD_EXTENSION, DB_ERRORCODE,            DB_EVAL,
  1875         -    DB_EXISTS,                DB_FUNCTION,             DB_INCRBLOB,
  1876         -    DB_INTERRUPT,             DB_LAST_INSERT_ROWID,    DB_NULLVALUE,
  1877         -    DB_ONECOLUMN,             DB_PREUPDATE,            DB_PROFILE,
  1878         -    DB_PROGRESS,              DB_REKEY,                DB_RESTORE,
  1879         -    DB_ROLLBACK_HOOK,         DB_SERIALIZE,            DB_STATUS,
  1880         -    DB_TIMEOUT,               DB_TOTAL_CHANGES,        DB_TRACE,
  1881         -    DB_TRACE_V2,              DB_TRANSACTION,          DB_UNLOCK_NOTIFY,
  1882         -    DB_UPDATE_HOOK,           DB_VERSION,              DB_WAL_HOOK
         1933  +    DB_AUTHORIZER,            DB_BACKUP,               DB_BIND_FALLBACK,
         1934  +    DB_BUSY,                  DB_CACHE,                DB_CHANGES,
         1935  +    DB_CLOSE,                 DB_COLLATE,              DB_COLLATION_NEEDED,
         1936  +    DB_COMMIT_HOOK,           DB_COMPLETE,             DB_COPY,
         1937  +    DB_DESERIALIZE,           DB_ENABLE_LOAD_EXTENSION,DB_ERRORCODE,
         1938  +    DB_EVAL,                  DB_EXISTS,               DB_FUNCTION,
         1939  +    DB_INCRBLOB,              DB_INTERRUPT,            DB_LAST_INSERT_ROWID,
         1940  +    DB_NULLVALUE,             DB_ONECOLUMN,            DB_PREUPDATE,
         1941  +    DB_PROFILE,               DB_PROGRESS,             DB_REKEY,
         1942  +    DB_RESTORE,               DB_ROLLBACK_HOOK,        DB_SERIALIZE,
         1943  +    DB_STATUS,                DB_TIMEOUT,              DB_TOTAL_CHANGES,
         1944  +    DB_TRACE,                 DB_TRACE_V2,             DB_TRANSACTION,
         1945  +    DB_UNLOCK_NOTIFY,         DB_UPDATE_HOOK,          DB_VERSION,
         1946  +    DB_WAL_HOOK             
  1883   1947     };
  1884   1948     /* don't leave trailing commas on DB_enum, it confuses the AIX xlc compiler */
  1885   1949   
  1886   1950     if( objc<2 ){
  1887   1951       Tcl_WrongNumArgs(interp, 1, objv, "SUBCOMMAND ...");
  1888   1952       return TCL_ERROR;
  1889   1953     }
................................................................................
  1996   2060         Tcl_AppendResult(interp, "backup failed: ",
  1997   2061              sqlite3_errmsg(pDest), (char*)0);
  1998   2062         rc = TCL_ERROR;
  1999   2063       }
  2000   2064       sqlite3_close(pDest);
  2001   2065       break;
  2002   2066     }
         2067  +
         2068  +  /*    $db bind_fallback ?CALLBACK?
         2069  +  **
         2070  +  ** When resolving bind parameters in an SQL statement, if the parameter
         2071  +  ** cannot be associated with a TCL variable then invoke CALLBACK with a
         2072  +  ** single argument that is the name of the parameter and use the return
         2073  +  ** value of the CALLBACK as the binding.  If CALLBACK returns something
         2074  +  ** other than TCL_OK or TCL_ERROR then bind a NULL.
         2075  +  **
         2076  +  ** If CALLBACK is an empty string, then revert to the default behavior 
         2077  +  ** which is to set the binding to NULL.
         2078  +  **
         2079  +  ** If CALLBACK returns an error, that causes the statement execution to
         2080  +  ** abort.  Hence, to configure a connection so that it throws an error
         2081  +  ** on an attempt to bind an unknown variable, do something like this:
         2082  +  **
         2083  +  **     proc bind_error {name} {error "no such variable: $name"}
         2084  +  **     db bind_fallback bind_error
         2085  +  */
         2086  +  case DB_BIND_FALLBACK: {
         2087  +    if( objc>3 ){
         2088  +      Tcl_WrongNumArgs(interp, 2, objv, "?CALLBACK?");
         2089  +      return TCL_ERROR;
         2090  +    }else if( objc==2 ){
         2091  +      if( pDb->zBindFallback ){
         2092  +        Tcl_AppendResult(interp, pDb->zBindFallback, (char*)0);
         2093  +      }
         2094  +    }else{
         2095  +      char *zCallback;
         2096  +      int len;
         2097  +      if( pDb->zBindFallback ){
         2098  +        Tcl_Free(pDb->zBindFallback);
         2099  +      }
         2100  +      zCallback = Tcl_GetStringFromObj(objv[2], &len);
         2101  +      if( zCallback && len>0 ){
         2102  +        pDb->zBindFallback = Tcl_Alloc( len + 1 );
         2103  +        memcpy(pDb->zBindFallback, zCallback, len+1);
         2104  +      }else{
         2105  +        pDb->zBindFallback = 0;
         2106  +      }
         2107  +    }
         2108  +    break;
         2109  +  }
  2003   2110   
  2004   2111     /*    $db busy ?CALLBACK?
  2005   2112     **
  2006   2113     ** Invoke the given callback if an SQL statement attempts to open
  2007   2114     ** a locked database file.
  2008   2115     */
  2009   2116     case DB_BUSY: {
................................................................................
  2642   2749     case DB_FUNCTION: {
  2643   2750       int flags = SQLITE_UTF8;
  2644   2751       SqlFunc *pFunc;
  2645   2752       Tcl_Obj *pScript;
  2646   2753       char *zName;
  2647   2754       int nArg = -1;
  2648   2755       int i;
         2756  +    int eType = SQLITE_NULL;
  2649   2757       if( objc<4 ){
  2650   2758         Tcl_WrongNumArgs(interp, 2, objv, "NAME ?SWITCHES? SCRIPT");
  2651   2759         return TCL_ERROR;
  2652   2760       }
  2653   2761       for(i=3; i<(objc-1); i++){
  2654   2762         const char *z = Tcl_GetString(objv[i]);
  2655   2763         int n = strlen30(z);
  2656         -      if( n>2 && strncmp(z, "-argcount",n)==0 ){
         2764  +      if( n>1 && strncmp(z, "-argcount",n)==0 ){
  2657   2765           if( i==(objc-2) ){
  2658   2766             Tcl_AppendResult(interp, "option requires an argument: ", z,(char*)0);
  2659   2767             return TCL_ERROR;
  2660   2768           }
  2661   2769           if( Tcl_GetIntFromObj(interp, objv[i+1], &nArg) ) return TCL_ERROR;
  2662   2770           if( nArg<0 ){
  2663   2771             Tcl_AppendResult(interp, "number of arguments must be non-negative",
  2664   2772                              (char*)0);
  2665   2773             return TCL_ERROR;
  2666   2774           }
  2667   2775           i++;
  2668   2776         }else
  2669         -      if( n>2 && strncmp(z, "-deterministic",n)==0 ){
         2777  +      if( n>1 && strncmp(z, "-deterministic",n)==0 ){
  2670   2778           flags |= SQLITE_DETERMINISTIC;
         2779  +      }else
         2780  +      if( n>1 && strncmp(z, "-returntype", n)==0 ){
         2781  +        const char *azType[] = {"integer", "real", "text", "blob", "any", 0};
         2782  +        assert( SQLITE_INTEGER==1 && SQLITE_FLOAT==2 && SQLITE_TEXT==3 );
         2783  +        assert( SQLITE_BLOB==4 && SQLITE_NULL==5 );
         2784  +        if( i==(objc-2) ){
         2785  +          Tcl_AppendResult(interp, "option requires an argument: ", z,(char*)0);
         2786  +          return TCL_ERROR;
         2787  +        }
         2788  +        i++;
         2789  +        if( Tcl_GetIndexFromObj(interp, objv[i], azType, "type", 0, &eType) ){
         2790  +          return TCL_ERROR;
         2791  +        }
         2792  +        eType++;
  2671   2793         }else{
  2672   2794           Tcl_AppendResult(interp, "bad option \"", z,
  2673         -            "\": must be -argcount or -deterministic", (char*)0
         2795  +            "\": must be -argcount, -deterministic or -returntype", (char*)0
  2674   2796           );
  2675   2797           return TCL_ERROR;
  2676   2798         }
  2677   2799       }
  2678   2800   
  2679   2801       pScript = objv[objc-1];
  2680   2802       zName = Tcl_GetStringFromObj(objv[2], 0);
................................................................................
  2682   2804       if( pFunc==0 ) return TCL_ERROR;
  2683   2805       if( pFunc->pScript ){
  2684   2806         Tcl_DecrRefCount(pFunc->pScript);
  2685   2807       }
  2686   2808       pFunc->pScript = pScript;
  2687   2809       Tcl_IncrRefCount(pScript);
  2688   2810       pFunc->useEvalObjv = safeToUseEvalObjv(interp, pScript);
         2811  +    pFunc->eType = eType;
  2689   2812       rc = sqlite3_create_function(pDb->db, zName, nArg, flags,
  2690   2813           pFunc, tclSqlFunc, 0, 0);
  2691   2814       if( rc!=SQLITE_OK ){
  2692   2815         rc = TCL_ERROR;
  2693   2816         Tcl_SetResult(interp, (char *)sqlite3_errmsg(pDb->db), TCL_VOLATILE);
  2694   2817       }
  2695   2818       break;

Changes to src/tokenize.c.

   556    556     int nErr = 0;                   /* Number of errors encountered */
   557    557     void *pEngine;                  /* The LEMON-generated LALR(1) parser */
   558    558     int n = 0;                      /* Length of the next token token */
   559    559     int tokenType;                  /* type of the next token */
   560    560     int lastTokenParsed = -1;       /* type of the previous token */
   561    561     sqlite3 *db = pParse->db;       /* The database connection */
   562    562     int mxSqlLen;                   /* Max length of an SQL string */
   563         -  VVA_ONLY( u8 startedWithOom = db->mallocFailed );
   564    563   #ifdef sqlite3Parser_ENGINEALWAYSONSTACK
   565    564     yyParser sEngine;    /* Space to hold the Lemon-generated Parser object */
   566    565   #endif
          566  +  VVA_ONLY( u8 startedWithOom = db->mallocFailed );
   567    567   
   568    568     assert( zSql!=0 );
   569    569     mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
   570    570     if( db->nVdbeActive==0 ){
   571    571       db->u1.isInterrupted = 0;
   572    572     }
   573    573     pParse->rc = SQLITE_OK;

Changes to src/vdbe.c.

   815    815   #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
   816    816     /* Call the progress callback if it is configured and the required number
   817    817     ** of VDBE ops have been executed (either since this invocation of
   818    818     ** sqlite3VdbeExec() or since last time the progress callback was called).
   819    819     ** If the progress callback returns non-zero, exit the virtual machine with
   820    820     ** a return code SQLITE_ABORT.
   821    821     */
   822         -  if( nVmStep>=nProgressLimit && db->xProgress!=0 ){
          822  +  while( nVmStep>=nProgressLimit && db->xProgress!=0 ){
   823    823       assert( db->nProgressOps!=0 );
   824         -    nProgressLimit = nVmStep + db->nProgressOps - (nVmStep%db->nProgressOps);
          824  +    nProgressLimit += db->nProgressOps;
   825    825       if( db->xProgress(db->pProgressArg) ){
   826    826         nProgressLimit = 0xffffffff;
   827    827         rc = SQLITE_INTERRUPT;
   828    828         goto abort_due_to_error;
   829    829       }
   830    830     }
   831    831   #endif
................................................................................
  1098   1098     pOp->opcode = OP_String;
  1099   1099     pOp->p1 = sqlite3Strlen30(pOp->p4.z);
  1100   1100   
  1101   1101   #ifndef SQLITE_OMIT_UTF16
  1102   1102     if( encoding!=SQLITE_UTF8 ){
  1103   1103       rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC);
  1104   1104       assert( rc==SQLITE_OK || rc==SQLITE_TOOBIG );
         1105  +    if( rc ) goto too_big;
  1105   1106       if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem;
  1106   1107       assert( pOut->szMalloc>0 && pOut->zMalloc==pOut->z );
  1107   1108       assert( VdbeMemDynamic(pOut)==0 );
  1108   1109       pOut->szMalloc = 0;
  1109   1110       pOut->flags |= MEM_Static;
  1110   1111       if( pOp->p4type==P4_DYNAMIC ){
  1111   1112         sqlite3DbFree(db, pOp->p4.z);
  1112   1113       }
  1113   1114       pOp->p4type = P4_DYNAMIC;
  1114   1115       pOp->p4.z = pOut->z;
  1115   1116       pOp->p1 = pOut->n;
  1116   1117     }
  1117         -  testcase( rc==SQLITE_TOOBIG );
  1118   1118   #endif
  1119   1119     if( pOp->p1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
  1120   1120       goto too_big;
  1121   1121     }
  1122   1122     assert( rc==SQLITE_OK );
  1123   1123     /* Fall through to the next case, OP_String */
  1124   1124   }
................................................................................
  4565   4565   ** and register P2 becomes ephemeral.  If the cursor is changed, the
  4566   4566   ** value of register P2 will then change.  Make sure this does not
  4567   4567   ** cause any problems.)
  4568   4568   **
  4569   4569   ** This instruction only works on tables.  The equivalent instruction
  4570   4570   ** for indices is OP_IdxInsert.
  4571   4571   */
  4572         -/* Opcode: InsertInt P1 P2 P3 P4 P5
  4573         -** Synopsis: intkey=P3 data=r[P2]
  4574         -**
  4575         -** This works exactly like OP_Insert except that the key is the
  4576         -** integer value P3, not the value of the integer stored in register P3.
  4577         -*/
  4578         -case OP_Insert: 
  4579         -case OP_InsertInt: {
         4572  +case OP_Insert: {
  4580   4573     Mem *pData;       /* MEM cell holding data for the record to be inserted */
  4581   4574     Mem *pKey;        /* MEM cell holding key  for the record */
  4582   4575     VdbeCursor *pC;   /* Cursor to table into which insert is written */
  4583   4576     int seekResult;   /* Result of prior seek or 0 if no USESEEKRESULT flag */
  4584   4577     const char *zDb;  /* database name - used by the update hook */
  4585   4578     Table *pTab;      /* Table structure - used by update and pre-update hooks */
  4586   4579     BtreePayload x;   /* Payload to be inserted */
................................................................................
  4593   4586     assert( pC->eCurType==CURTYPE_BTREE );
  4594   4587     assert( pC->uc.pCursor!=0 );
  4595   4588     assert( (pOp->p5 & OPFLAG_ISNOOP) || pC->isTable );
  4596   4589     assert( pOp->p4type==P4_TABLE || pOp->p4type>=P4_STATIC );
  4597   4590     REGISTER_TRACE(pOp->p2, pData);
  4598   4591     sqlite3VdbeIncrWriteCounter(p, pC);
  4599   4592   
  4600         -  if( pOp->opcode==OP_Insert ){
  4601         -    pKey = &aMem[pOp->p3];
  4602         -    assert( pKey->flags & MEM_Int );
  4603         -    assert( memIsValid(pKey) );
  4604         -    REGISTER_TRACE(pOp->p3, pKey);
  4605         -    x.nKey = pKey->u.i;
  4606         -  }else{
  4607         -    assert( pOp->opcode==OP_InsertInt );
  4608         -    x.nKey = pOp->p3;
  4609         -  }
         4593  +  pKey = &aMem[pOp->p3];
         4594  +  assert( pKey->flags & MEM_Int );
         4595  +  assert( memIsValid(pKey) );
         4596  +  REGISTER_TRACE(pOp->p3, pKey);
         4597  +  x.nKey = pKey->u.i;
  4610   4598   
  4611   4599     if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
  4612   4600       assert( pC->iDb>=0 );
  4613   4601       zDb = db->aDb[pC->iDb].zDbSName;
  4614   4602       pTab = pOp->p4.pTab;
  4615   4603       assert( (pOp->p5 & OPFLAG_ISNOOP) || HasRowid(pTab) );
  4616   4604     }else{
................................................................................
  6170   6158       for(i=0; i<p->nMem; i++){
  6171   6159         aMem[i].pScopyFrom = 0;  /* Prevent false-positive AboutToChange() errs */
  6172   6160         aMem[i].flags |= MEM_Undefined; /* Cause a fault if this reg is reused */
  6173   6161       }
  6174   6162     }
  6175   6163   #endif
  6176   6164     pOp = &aOp[-1];
  6177         -
  6178         -  break;
         6165  +  goto check_for_interrupt;
  6179   6166   }
  6180   6167   
  6181   6168   /* Opcode: Param P1 P2 * * *
  6182   6169   **
  6183   6170   ** This opcode is only ever present in sub-programs called via the 
  6184   6171   ** OP_Program instruction. Copy a value currently stored in a memory 
  6185   6172   ** cell of the calling (parent) frame to cell P2 in the current frames 
................................................................................
  7581   7568     }
  7582   7569   
  7583   7570     /* This is the only way out of this procedure.  We have to
  7584   7571     ** release the mutexes on btrees that were acquired at the
  7585   7572     ** top. */
  7586   7573   vdbe_return:
  7587   7574   #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
  7588         -  if( nVmStep>=nProgressLimit && db->xProgress!=0 ){
         7575  +  while( nVmStep>=nProgressLimit && db->xProgress!=0 ){
         7576  +    nProgressLimit += db->nProgressOps;
  7589   7577       if( db->xProgress(db->pProgressArg) ){
  7590   7578         nProgressLimit = 0xffffffff;
  7591   7579         rc = SQLITE_INTERRUPT;
  7592   7580         goto abort_due_to_error;
  7593   7581       }
  7594   7582     }
  7595   7583   #endif

Changes to src/vdbeapi.c.

  1116   1116   **    3      The name of the table that the column derives from
  1117   1117   **    4      The name of the table column that the result column derives from
  1118   1118   **
  1119   1119   ** If the result is not a simple column reference (if it is an expression
  1120   1120   ** or a constant) then useTypes 2, 3, and 4 return NULL.
  1121   1121   */
  1122   1122   static const void *columnName(
  1123         -  sqlite3_stmt *pStmt,
  1124         -  int N,
  1125         -  const void *(*xFunc)(Mem*),
  1126         -  int useType
         1123  +  sqlite3_stmt *pStmt,     /* The statement */
         1124  +  int N,                   /* Which column to get the name for */
         1125  +  int useUtf16,            /* True to return the name as UTF16 */
         1126  +  int useType              /* What type of name */
  1127   1127   ){
  1128   1128     const void *ret;
  1129   1129     Vdbe *p;
  1130   1130     int n;
  1131   1131     sqlite3 *db;
  1132   1132   #ifdef SQLITE_ENABLE_API_ARMOR
  1133   1133     if( pStmt==0 ){
................................................................................
  1140   1140     db = p->db;
  1141   1141     assert( db!=0 );
  1142   1142     n = sqlite3_column_count(pStmt);
  1143   1143     if( N<n && N>=0 ){
  1144   1144       N += useType*n;
  1145   1145       sqlite3_mutex_enter(db->mutex);
  1146   1146       assert( db->mallocFailed==0 );
  1147         -    ret = xFunc(&p->aColName[N]);
  1148         -     /* A malloc may have failed inside of the xFunc() call. If this
         1147  +#ifndef SQLITE_OMIT_UTF16
         1148  +    if( useUtf16 ){
         1149  +      ret = sqlite3_value_text16((sqlite3_value*)&p->aColName[N]);
         1150  +    }else
         1151  +#endif
         1152  +    {
         1153  +      ret = sqlite3_value_text((sqlite3_value*)&p->aColName[N]);
         1154  +    }
         1155  +    /* A malloc may have failed inside of the _text() call. If this
  1149   1156       ** is the case, clear the mallocFailed flag and return NULL.
  1150   1157       */
  1151   1158       if( db->mallocFailed ){
  1152   1159         sqlite3OomClear(db);
  1153   1160         ret = 0;
  1154   1161       }
  1155   1162       sqlite3_mutex_leave(db->mutex);
................................................................................
  1158   1165   }
  1159   1166   
  1160   1167   /*
  1161   1168   ** Return the name of the Nth column of the result set returned by SQL
  1162   1169   ** statement pStmt.
  1163   1170   */
  1164   1171   const char *sqlite3_column_name(sqlite3_stmt *pStmt, int N){
  1165         -  return columnName(
  1166         -      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_NAME);
         1172  +  return columnName(pStmt, N, 0, COLNAME_NAME);
  1167   1173   }
  1168   1174   #ifndef SQLITE_OMIT_UTF16
  1169   1175   const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
  1170         -  return columnName(
  1171         -      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_NAME);
         1176  +  return columnName(pStmt, N, 1, COLNAME_NAME);
  1172   1177   }
  1173   1178   #endif
  1174   1179   
  1175   1180   /*
  1176   1181   ** Constraint:  If you have ENABLE_COLUMN_METADATA then you must
  1177   1182   ** not define OMIT_DECLTYPE.
  1178   1183   */
................................................................................
  1183   1188   
  1184   1189   #ifndef SQLITE_OMIT_DECLTYPE
  1185   1190   /*
  1186   1191   ** Return the column declaration type (if applicable) of the 'i'th column
  1187   1192   ** of the result set of SQL statement pStmt.
  1188   1193   */
  1189   1194   const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){
  1190         -  return columnName(
  1191         -      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DECLTYPE);
         1195  +  return columnName(pStmt, N, 0, COLNAME_DECLTYPE);
  1192   1196   }
  1193   1197   #ifndef SQLITE_OMIT_UTF16
  1194   1198   const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
  1195         -  return columnName(
  1196         -      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DECLTYPE);
         1199  +  return columnName(pStmt, N, 1, COLNAME_DECLTYPE);
  1197   1200   }
  1198   1201   #endif /* SQLITE_OMIT_UTF16 */
  1199   1202   #endif /* SQLITE_OMIT_DECLTYPE */
  1200   1203   
  1201   1204   #ifdef SQLITE_ENABLE_COLUMN_METADATA
  1202   1205   /*
  1203   1206   ** Return the name of the database from which a result column derives.
  1204   1207   ** NULL is returned if the result column is an expression or constant or
  1205   1208   ** anything else which is not an unambiguous reference to a database column.
  1206   1209   */
  1207   1210   const char *sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){
  1208         -  return columnName(
  1209         -      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DATABASE);
         1211  +  return columnName(pStmt, N, 0, COLNAME_DATABASE);
  1210   1212   }
  1211   1213   #ifndef SQLITE_OMIT_UTF16
  1212   1214   const void *sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N){
  1213         -  return columnName(
  1214         -      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DATABASE);
         1215  +  return columnName(pStmt, N, 1, COLNAME_DATABASE);
  1215   1216   }
  1216   1217   #endif /* SQLITE_OMIT_UTF16 */
  1217   1218   
  1218   1219   /*
  1219   1220   ** Return the name of the table from which a result column derives.
  1220   1221   ** NULL is returned if the result column is an expression or constant or
  1221   1222   ** anything else which is not an unambiguous reference to a database column.
  1222   1223   */
  1223   1224   const char *sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){
  1224         -  return columnName(
  1225         -      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_TABLE);
         1225  +  return columnName(pStmt, N, 0, COLNAME_TABLE);
  1226   1226   }
  1227   1227   #ifndef SQLITE_OMIT_UTF16
  1228   1228   const void *sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N){
  1229         -  return columnName(
  1230         -      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_TABLE);
         1229  +  return columnName(pStmt, N, 1, COLNAME_TABLE);
  1231   1230   }
  1232   1231   #endif /* SQLITE_OMIT_UTF16 */
  1233   1232   
  1234   1233   /*
  1235   1234   ** Return the name of the table column from which a result column derives.
  1236   1235   ** NULL is returned if the result column is an expression or constant or
  1237   1236   ** anything else which is not an unambiguous reference to a database column.
  1238   1237   */
  1239   1238   const char *sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){
  1240         -  return columnName(
  1241         -      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_COLUMN);
         1239  +  return columnName(pStmt, N, 0, COLNAME_COLUMN);
  1242   1240   }
  1243   1241   #ifndef SQLITE_OMIT_UTF16
  1244   1242   const void *sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){
  1245         -  return columnName(
  1246         -      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_COLUMN);
         1243  +  return columnName(pStmt, N, 1, COLNAME_COLUMN);
  1247   1244   }
  1248   1245   #endif /* SQLITE_OMIT_UTF16 */
  1249   1246   #endif /* SQLITE_ENABLE_COLUMN_METADATA */
  1250   1247   
  1251   1248   
  1252   1249   /******************************* sqlite3_bind_  ***************************
  1253   1250   ** 

Changes to src/wherecode.c.

   578    578       if( pIn ){
   579    579         int iMap = 0;               /* Index in aiMap[] */
   580    580         pIn += i;
   581    581         for(i=iEq;i<pLoop->nLTerm; i++){
   582    582           if( pLoop->aLTerm[i]->pExpr==pX ){
   583    583             int iOut = iReg + i - iEq;
   584    584             if( eType==IN_INDEX_ROWID ){
   585         -            testcase( nEq>1 );  /* Happens with a UNIQUE index on ROWID */
   586    585               pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iOut);
   587    586             }else{
   588    587               int iCol = aiMap ? aiMap[iMap++] : 0;
   589    588               pIn->addrInTop = sqlite3VdbeAddOp3(v,OP_Column,iTab, iCol, iOut);
   590    589             }
   591    590             sqlite3VdbeAddOp1(v, OP_IsNull, iOut); VdbeCoverage(v);
   592    591             if( i==iEq ){
................................................................................
  1155   1154       x.iIdxCol = iIdxCol;
  1156   1155       x.pIdxExpr = aColExpr->a[iIdxCol].pExpr;
  1157   1156       sqlite3WalkExpr(&w, pWInfo->pWhere);
  1158   1157       sqlite3WalkExprList(&w, pWInfo->pOrderBy);
  1159   1158       sqlite3WalkExprList(&w, pWInfo->pResultSet);
  1160   1159     }
  1161   1160   }
         1161  +
         1162  +/*
         1163  +** The pTruth expression is always tree because it is the WHERE clause
         1164  +** a partial index that is driving a query loop.  Look through all of the
         1165  +** WHERE clause terms on the query, and if any of those terms must be
         1166  +** true because pTruth is true, then mark those WHERE clause terms as
         1167  +** coded.
         1168  +*/
         1169  +static void whereApplyPartialIndexConstraints(
         1170  +  Expr *pTruth,
         1171  +  int iTabCur,
         1172  +  WhereClause *pWC
         1173  +){
         1174  +  int i;
         1175  +  WhereTerm *pTerm;
         1176  +  while( pTruth->op==TK_AND ){
         1177  +    whereApplyPartialIndexConstraints(pTruth->pLeft, iTabCur, pWC);
         1178  +    pTruth = pTruth->pRight;
         1179  +  }
         1180  +  for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
         1181  +    Expr *pExpr;
         1182  +    if( pTerm->wtFlags & TERM_CODED ) continue;
         1183  +    pExpr = pTerm->pExpr;
         1184  +    if( sqlite3ExprCompare(0, pExpr, pTruth, iTabCur)==0 ){
         1185  +      pTerm->wtFlags |= TERM_CODED;
         1186  +    }
         1187  +  }
         1188  +}
  1162   1189   
  1163   1190   /*
  1164   1191   ** Generate code for the start of the iLevel-th loop in the WHERE clause
  1165   1192   ** implementation described by pWInfo.
  1166   1193   */
  1167   1194   Bitmask sqlite3WhereCodeOneLoopStart(
  1168   1195     Parse *pParse,       /* Parsing context */
................................................................................
  1340   1367       iReleaseReg = ++pParse->nMem;
  1341   1368       iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, bRev, iReleaseReg);
  1342   1369       if( iRowidReg!=iReleaseReg ) sqlite3ReleaseTempReg(pParse, iReleaseReg);
  1343   1370       addrNxt = pLevel->addrNxt;
  1344   1371       sqlite3VdbeAddOp3(v, OP_SeekRowid, iCur, addrNxt, iRowidReg);
  1345   1372       VdbeCoverage(v);
  1346   1373       pLevel->op = OP_Noop;
         1374  +    if( (pTerm->prereqAll & pLevel->notReady)==0 ){
         1375  +      pTerm->wtFlags |= TERM_CODED;
         1376  +    }
  1347   1377     }else if( (pLoop->wsFlags & WHERE_IPK)!=0
  1348   1378            && (pLoop->wsFlags & WHERE_COLUMN_RANGE)!=0
  1349   1379     ){
  1350   1380       /* Case 3:  We have an inequality comparison against the ROWID field.
  1351   1381       */
  1352   1382       int testOp = OP_Noop;
  1353   1383       int start;
................................................................................
  1761   1791       ** OR clause, since the transformation will become invalid once we
  1762   1792       ** move forward to the next index.
  1763   1793       ** https://sqlite.org/src/info/4e8e4857d32d401f
  1764   1794       */
  1765   1795       if( pLevel->iLeftJoin==0 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0 ){
  1766   1796         whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo);
  1767   1797       }
         1798  +
         1799  +    /* If a partial index is driving the loop, try to eliminate WHERE clause
         1800  +    ** terms from the query that must be true due to the WHERE clause of
         1801  +    ** the partial index
         1802  +    */
         1803  +    if( pIdx->pPartIdxWhere ){
         1804  +      whereApplyPartialIndexConstraints(pIdx->pPartIdxWhere, iCur, pWC);
         1805  +    }
  1768   1806   
  1769   1807       /* Record the instruction used to terminate the loop. */
  1770   1808       if( pLoop->wsFlags & WHERE_ONEROW ){
  1771   1809         pLevel->op = OP_Noop;
  1772   1810       }else if( bRev ){
  1773   1811         pLevel->op = OP_Prev;
  1774   1812       }else{

Changes to test/dbfuzz2.c.

    39     39   #include <assert.h>
    40     40   #include <stdio.h>
    41     41   #include <stdlib.h>
    42     42   #include <string.h>
    43     43   #include <stdarg.h>
    44     44   #include <ctype.h>
    45     45   #include <stdint.h>
           46  +#ifndef _WIN32
    46     47   #include <sys/time.h>
    47     48   #include <sys/resource.h>
           49  +#endif
    48     50   #include "sqlite3.h"
    49     51   
    50     52   /*
    51     53   ** This is the is the SQL that is run against the database.
    52     54   */
    53     55   static const char *azSql[] = {
    54     56     "PRAGMA integrity_check;",
................................................................................
   177    179     a = sqlite3_malloc64(nByte+1);
   178    180     if( a==0 ) return 1;
   179    181     memcpy(a, aData, nByte);
   180    182     sqlite3_deserialize(db, "main", a, nByte, nByte,
   181    183           SQLITE_DESERIALIZE_RESIZEABLE |
   182    184           SQLITE_DESERIALIZE_FREEONCLOSE);
   183    185     x = szMax;
          186  +#ifdef SQLITE_FCNTL_SIZE_LIMIT
   184    187     sqlite3_file_control(db, "main", SQLITE_FCNTL_SIZE_LIMIT, &x);
          188  +#endif
   185    189     if( bVdbeDebug ){
   186    190       sqlite3_exec(db, "PRAGMA vdbe_debug=ON", 0, 0, 0);
   187    191     }
   188    192     for(i=0; i<sizeof(azSql)/sizeof(azSql[0]); i++){
   189    193       if( eVerbosity>=1 ){
   190    194         printf("%s\n", azSql[i]);
   191    195         fflush(stdout);
................................................................................
   257    261           if( i+1==argc ){
   258    262             fprintf(stderr, "missing argument to %s\n", argv[i]);
   259    263             exit(1);
   260    264           }
   261    265           szMax = strtol(argv[++i], 0, 0);
   262    266           continue;
   263    267         }
          268  +#ifndef _WIN32
   264    269         if( strcmp(z,"max-stack")==0
   265    270          || strcmp(z,"max-data")==0
   266    271          || strcmp(z,"max-as")==0
   267    272         ){
   268    273           struct rlimit x,y;
   269    274           int resource = RLIMIT_STACK;
   270    275           char *zType = "RLIMIT_STACK";
................................................................................
   287    292           setrlimit(resource, &y);
   288    293           memset(&y,0,sizeof(y));
   289    294           getrlimit(resource, &y);
   290    295           printf("%s changed from %d to %d\n", 
   291    296                  zType, (int)x.rlim_cur, (int)y.rlim_cur);
   292    297           continue;
   293    298         }
          299  +#endif /* _WIN32 */
   294    300       }
   295    301       argv[j++] = argv[i];
   296    302     }
   297    303     argv[j] = 0;
   298    304     *pArgc = j;
   299    305     return 0;
   300    306   }

Changes to test/fts3atoken.test.

   103    103   } {1 {unknown tokenizer: nosuchtokenizer}}
   104    104   
   105    105   #--------------------------------------------------------------------------
   106    106   # Test cases fts3atoken-3.* test the three built-in tokenizers with a
   107    107   # simple input string via the built-in test function. This is as much
   108    108   # to test the test function as the tokenizer implementations.
   109    109   #
          110  +sqlite3_db_config db SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1
   110    111   do_test fts3atoken-3.1 {
   111    112     execsql {
   112    113       SELECT fts3_tokenizer_test('simple', 'I don''t see how');
   113    114     }
   114    115   } {{0 i I 1 don don 2 t t 3 see see 4 how how}}
   115    116   do_test fts3atoken-3.2 {
   116    117     execsql {

Changes to test/fts3corrupt4.test.

  2582   2582   |   4032: 6d 65 72 67 65 3d 35 0d 04 02 23 6d 65 72 67 65   merge=5...#merge
  2583   2583   |   4048: 3d 31 30 30 2c 38 11 03 02 2b 69 6e 74 65 67 72   =100,8...+integr
  2584   2584   |   4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62   ity-check....reb
  2585   2585   |   4080: 75 69 6c 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   uild....optimize
  2586   2586   | end crash-f15972acf5bc1c.db
  2587   2587   }]} {}
  2588   2588   
  2589         -breakpoint
  2590   2589   do_execsql_test 17.1 {
  2591   2590     BEGIN;
  2592   2591       INSERT INTO t1(t1) SELECT x FROM t2;
  2593   2592       UPDATE t1 SET b=quote(zeroblob(200)) WHERE a MATCH 'thread*';
  2594   2593   }
  2595   2594   
  2596   2595   do_catchsql_test 17.2 {
................................................................................
  3255   3254       INSERT INTO t1(a) SELECT randomblob(3000) FROM c;
  3256   3255   }
  3257   3256   
  3258   3257   do_execsql_test 20.2 {
  3259   3258     INSERT INTO t1(t1) VALUES('optimize');
  3260   3259   } 
  3261   3260   
         3261  +#-------------------------------------------------------------------------
         3262  +reset_db
         3263  +do_test 21.0 {
         3264  +  sqlite3 db {}
         3265  +  db deserialize [decode_hexdb {
         3266  +| size 28672 pagesize 4096 filename crash-18cc014e42e828.db
         3267  +| page 1 offset 0
         3268  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         3269  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
         3270  +|     32: 00 00 00 02 00 00 00 01 00 00 00 07 00 00 00 04   ................
         3271  +|     96: 00 00 00 00 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21   ...............!
         3272  +|    112: 0e b9 0d c8 0e 7e 0d a4 00 00 00 00 00 00 00 00   .....~..........
         3273  +|   3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c   ...........1tabl
         3274  +|   3504: 66 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42   ft2t2.CREATE TAB
         3275  +|   3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01   LE t2(x).3......
         3276  +|   3536: 82 35 74 61 62 6c 65 74 31 5f 73 75 67 64 69 72   .5tablet1_sugdir
         3277  +|   3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45   t1_segdir.CREATE
         3278  +|   3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69    TABLE 't1_segdi
         3279  +|   3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52   r'(level INTEGER
         3280  +|   3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61   ,idx INTEGER,sta
         3281  +|   3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 46 47 45 52   rt_block INTFGER
         3282  +|   3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63   ,leaves_end_bloc
         3283  +|   3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c   k INTEGER,end_bl
         3284  +|   3664: 6f 63 6b 20 49 4e 54 45 47 45 62 2c 72 6f 6f 74   ock INTEGEb,root
         3285  +|   3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45    BLOB,PRIMARY KE
         3286  +|   3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06   Y(level, idx))1.
         3287  +|   3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74   ..E...indexsqlit
         3288  +|   3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73   e_autoindex_t1_s
         3289  +|   3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72   egdir_1t1_segdir
         3290  +|   3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01   .........f...##.
         3291  +|   3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e   ..tablet1_segmen
         3292  +|   3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52   tst1_segments.CR
         3293  +|   3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73   EATE TABLE 't1_s
         3294  +|   3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64   egments'(blockid
         3295  +|   3840: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59    INTEGER PRIMARY
         3296  +|   3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42    KEY, block BLOB
         3297  +|   3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74   )j...!!...tablet
         3298  +|   3888: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74   1_contentt1_cont
         3299  +|   3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45   ent.CREATE TABLE
         3300  +|   3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f    't1_content'(do
         3301  +|   3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   cid INTEGER PRIM
         3302  +|   3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20   ARY KEY, 'c0a', 
         3303  +|   3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06   'c1b', 'c2c')8..
         3304  +|   3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52   ...._tablet1t1CR
         3305  +|   4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42   EATE VIRTUAL TAB
         3306  +|   4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33   LE t1 USING fts3
         3307  +|   4032: 28 61 2c 62 2c 63 29 00 00 00 00 00 00 00 00 00   (a,b,c).........
         3308  +| page 3 offset 8192
         3309  +|      0: 0d 00 00 00 25 0b 48 00 0f d8 0f af 0f 86 0f 74   ....%.H........t
         3310  +|     16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5   .a.N./..........
         3311  +|     32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 0d d5   ...t.[.@.$......
         3312  +|     48: 0d bb 0d a0 0d 84 0d 68 0d 4e 0d 35 0d 1b 0c fb   .......h.N.5....
         3313  +|     64: 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e 0c 24 00 00   .......x.W.>.$..
         3314  +|   2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 82 7f 00   .........?%.....
         3315  +|   2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e   .COMPILER=gcc-5.
         3316  +|   2912: 34 23 00 20 32 30 31 36 30 36 30 39 20 44 45 42   4#. 20160609 DEB
         3317  +|   2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 41 54   UG ENABLE DBSTAT
         3318  +|   2944: 20 56 54 41 42 20 45 4e 41 42 4c 45 20 46 43 53    VTAB ENABLE FCS
         3319  +|   2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e   4 ENABLE FTS5 EN
         3320  +|   2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41   ABLE GEOPOLY ENA
         3321  +|   2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45   BLE JSON1 ENABLE
         3322  +|   3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20    MEMSYS5 ENABLE 
         3323  +|   3024: 52 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59   RTREE MAX MEMORY
         3324  +|   3040: 3d 35 30 30 30 30 30 30 30 20 4f 4d 49 54 20 4c   =50000000 OMIT L
         3325  +|   3056: 4f 41 44 20 45 58 54 45 4e 53 49 4f 4e 20 54 48   OAD EXTENSION TH
         3326  +|   3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 25 0f   READSAFE=0.$..%.
         3327  +|   3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49   .THREADSAFE=0XBI
         3328  +|   3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41   NARY.#..%..THREA
         3329  +|   3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 22   DSAFE=0XNOCASE..
         3330  +|   3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d   ..%..THREADSAFE=
         3331  +|   3152: 30 58 52 54 52 49 4d 20 21 05 00 33 0f 19 4f 4d   0XRTRIM !..3..OM
         3332  +|   3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4f   IT LOAD EXTENSIO
         3333  +|   3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f   NXBINARY. ..3..O
         3334  +|   3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49   MIT LOAD EXTENSI
         3335  +|   3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17   ONXNOCASE....3..
         3336  +|   3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53   OMIT LOAD EXTENS
         3337  +|   3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19   IONXRTRIM....3..
         3338  +|   3264: 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30   MAX MEMORY=50000
         3339  +|   3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f   000XBINARY....3.
         3340  +|   3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30   .MAX MEMORY=5000
         3341  +|   3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33   0000XNOCASE....3
         3342  +|   3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30   ..MAX MEMORY=500
         3343  +|   3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25   00000XRTRIM....%
         3344  +|   3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42   ..ENABLE RTREEXB
         3345  +|   3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42   INARY....%..ENAB
         3346  +|   3392: 4c 45 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17   LE RTREEXNOCASE.
         3347  +|   3408: 19 05 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52   ...%..ENABLE RTR
         3348  +|   3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45   EEXRTRIM....)..E
         3349  +|   3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49   NABLE MEMSYS5XBI
         3350  +|   3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c   NARY....)..ENABL
         3351  +|   3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45   E MEMSYS5XNOCASE
         3352  +|   3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45   ....)..ENABLE ME
         3353  +|   3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25   MSYS5XRTRIM....%
         3354  +|   3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42   ..ENABLE JSON1XB
         3355  +|   3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42   INARY....%..ENAB
         3356  +|   3552: 4c 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17   LE JSON1XNOCASE.
         3357  +|   3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f   ...%..ENABLE JSO
         3358  +|   3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45   N1XRTRIM....)..E
         3359  +|   3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 58 42 39   NABLE GEOPOLYXB9
         3360  +|   3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 4e 41 1e 4c   NARY....)..ENA.L
         3361  +|   3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 43 41 53 45   E GEOPOLYXNOCASE
         3362  +|   3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45   ....)..ENABLE GE
         3363  +|   3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 17 0f 05 00 23   OPOLYXRTRIM....#
         3364  +|   3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49   ..ENABLE FTS5XBI
         3365  +|   3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c   NARY....#..ENABL
         3366  +|   3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0d 05   E FTS5XNOCASE...
         3367  +|   3728: 00 23 0f 16 45 4e 41 42 4c 45 20 46 54 53 35 58   .#..ENABLE FTS5X
         3368  +|   3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42   RTRIM....#..ENAB
         3369  +|   3760: 4c 45 20 46 54 53 34 58 42 48 4e 41 52 59 17 0b   LE FTS4XBHNARY..
         3370  +|   3776: 05 00 23 0e 19 45 4e 41 42 4c 45 20 46 54 53 35   ..#..ENABLE FTS5
         3371  +|   3792: 58 4e 4f 43 40 53 45 16 0a 05 00 23 0f 17 45 4e   XNOC@SE....#..EN
         3372  +|   3808: 41 42 4c 45 20 46 54 53 34 58 52 2e 52 49 4d 1e   ABLE FTS4XR.RIM.
         3373  +|   3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         3374  +|   3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e   TAT VTABXBINARY.
         3375  +|   3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         3376  +|   3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d   TAT VTABXNOCASE.
         3377  +|   3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         3378  +|   3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06   TAT VTABXRTRIM..
         3379  +|   3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52   .....DEBUGXBINAR
         3380  +|   3936: 59 11 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f   Y.......DEBUGXNO
         3381  +|   3952: 43 41 53 45 10 04 05 00 17 0f 17 44 45 42 55 47   CASE.......DEBUG
         3382  +|   3968: 58 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d   XRTRIM'...C..COM
         3383  +|   3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20   PILER=gcc-5.4.0 
         3384  +|   4000: 32 30 31 36 30 36 30 39 58 42 49 da 41 52 59 27   20160609XBI.ARY'
         3385  +|   4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67   ...C..COMPILER=g
         3386  +|   4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30   cc-5.4.0 2016060
         3387  +|   4048: 39 58 4e 4f 43 41 53 45 26 01 05 00 43 0f 17 43   9XNOCASE&...C..C
         3388  +|   4064: 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 00 00 00 00   OMPILER=gcc-....
         3389  +| page 5 offset 16384
         3390  +|      0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00   ................
         3391  +|   2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33   ...........0 253
         3392  +|   2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36   ..0.%.....201606
         3393  +|   3008: 30 3a 03 25 07 00 00 01 34 03 25 05 00 00 01 35   0:.%....4.%....5
         3394  +|   3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a   .%....0000000.%.
         3395  +|   3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00   ...compiler.%...
         3396  +|   3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 62 75   .dbstat.%....ebu
         3397  +|   3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09   g.%....enable.%.
         3398  +|   3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f   .........xtensio
         3399  +|   3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03   n.%....fts4.%...
         3400  +|   3120: 01 35 03 25 0f 00 00 03 57 63 63 03 25 03 00 01   .5.%....Wcc.%...
         3401  +|   3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f   .eopoly.%....jso
         3402  +|   3152: 6e 31 03 25 13 00 00 04 6c 6f 61 64 03 25 1c 00   n1.%....load.%..
         3403  +|   3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6d 6f 72 79   ..max.%....emory
         3404  +|   3184: 03 25 19 00 03 04 73 79 73 35 03 25 15 00 00 04   .%....sys5.%....
         3405  +|   3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03   omit.%....rtree.
         3406  +|   3216: 25 17 00 00 0a 74 68 72 65 64 64 73 61 66 65 03   %....threddsafe.
         3407  +|   3232: 25 1e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01   %....vtab.%...P.
         3408  +|   3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30   ........0 835..0
         3409  +|   3264: 12 01 06 00 01 06 00 01 06 00 1f 03 00 01 03 00   ................
         3410  +|   3280: 01 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07   .....20160609...
         3411  +|   3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05   .........4......
         3412  +|   3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04   ......5.........
         3413  +|   3328: 00 01 07 30 30 30 30 30 30 30 09 1c 04 00 01 04   ...0000000......
         3414  +|   3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02   ......binary<...
         3415  +|   3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02   ................
         3416  +|   3376: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00   ................
         3417  +|   3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03   ................
         3418  +|   3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69   ...........compi
         3419  +|   3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64   ler............d
         3420  +|   3440: 62 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01   bstat...........
         3421  +|   3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00   .ebug...........
         3422  +|   3472: 06 65 6e 61 62 6c 65 3f 07 02 00 01 02 00 01 12   .enable?........
         3423  +|   3488: 00 01 02 00 01 02 00 01 02 00 01 02 0e 97 02 00   ................
         3424  +|   3504: 01 02 00 01 cb 00 01 02 00 01 02 00 01 02 10 01   ................
         3425  +|   3520: 02 00 01 02 00 01 02 01 01 02 00 01 02 00 01 02   ................
         3426  +|   3536: 00 01 02 00 01 02 00 01 08 78 74 65 6e 73 69 6f   .........xtensio
         3427  +|   3552: 6e 09 1f 04 00 01 04 00 01 04 00 00 04 66 74 73   n............fts
         3428  +|   3568: 34 09 0a 03 00 01 03 00 01 03 00 03 01 35 09 0d   4............5..
         3429  +|   3584: 03 00 01 03 00 01 03 00 00 03 67 63 63 09 01 03   ..........gcc...
         3430  +|   3600: 00 01 03 00 01 03 00 01 06 65 6f 70 6f 6c 79 09   .........eopoly.
         3431  +|   3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31   ...........json1
         3432  +|   3632: 09 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64   ............load
         3433  +|   3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09   ............max.
         3434  +|   3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79   ...........emory
         3435  +|   3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35   ............sys5
         3436  +|   3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61   ............noca
         3437  +|   3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02   se<.............
         3438  +|   3728: 02 00 03 01 02 02 00 03 01 02 02 00 ab 01 02 02   ................
         3439  +|   3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00   ................
         3440  +|   3760: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 00   ................
         3441  +|   3776: 04 6f 6d 69 74 09 1f 12 00 01 02 00 01 02 00 00   .omit...........
         3442  +|   3792: 05 72 74 72 65 65 09 19 03 00 01 03 00 01 03 00   .rtree..........
         3443  +|   3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03   ..im<...........
         3444  +|   3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01   ................
         3445  +|   3840: 02 02 00 03 01 02 01 f0 03 01 02 02 00 03 01 02   ................
         3446  +|   3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02   ................
         3447  +|   3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02   ...threadsafe...
         3448  +|   3888: 00 01 02 00 02 02 00 00 04 76 74 61 62 09 07 04   .........vtab...
         3449  +|   3904: 00 01 04 00 01 04 00 00 01 78 b4 01 01 01 08 a2   .........x......
         3450  +|   3920: 00 01 01 01 02 00 01 01 01 02 00 02 01 01 02 00   ................
         3451  +|   3936: 01 01 01 01 ff f1 01 01 02 00 01 01 01 02 00 01   ................
         3452  +|   3952: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01   ................
         3453  +|   3968: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01   ................
         3454  +|   3984: 02 00 01 01 01 02 00 01 01 01 02 01 01 01 01 02   ................
         3455  +|   4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00   ................
         3456  +|   4016: 01 01 01 02 00 01 01 01 02 00 01 01 01 03 00 01   ................
         3457  +|   4032: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01   ................
         3458  +|   4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01   ................
         3459  +|   4064: 02 00 01 01 01 02 00 01 02 01 02 00 01 01 01 02   ................
         3460  +|   4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00   ................
         3461  +| page 6 offset 20480
         3462  +|      0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00   ................
         3463  +|   4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09   ................
         3464  +| page 7 offset 24576
         3465  +|      0: 0d 00 00 00 05 0f b8 00 00 00 00 00 00 00 00 00   ................
         3466  +|   4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 75 74 6f   ...........#auto
         3467  +|   4032: 6d 65 72 67 65 3d 35 0d 04 02 23 6d 65 72 67 65   merge=5...#merge
         3468  +|   4048: 3d 31 30 30 2c 38 11 03 02 2b 69 6e 74 65 67 72   =100,8...+integr
         3469  +|   4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62   ity-check....reb
         3470  +|   4080: 75 69 6c 64 0a 01 02 1d 00 00 00 00 00 00 00 00   uild............
         3471  +| end crash-18cc014e42e828.db
         3472  +}]} {}
         3473  +
         3474  +breakpoint
         3475  +do_catchsql_test 21.1 {
         3476  +  SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'R*';
         3477  +} {1 {database disk image is malformed}}
         3478  +
         3479  +#-------------------------------------------------------------------------
         3480  +reset_db
         3481  +do_test 22.0 {
         3482  +  sqlite3 db {}
         3483  +  db deserialize [decode_hexdb {
         3484  +| size 28672 pagesize 4096 filename crash-b794c89d922ac9.db
         3485  +| page 1 offset 0
         3486  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         3487  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
         3488  +|     32: 00 00 00 02 00 00 00 01 00 00 00 07 00 00 00 00   ................
         3489  +|     96: 00 00 00 00 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21   ...............!
         3490  +|    112: 0e b9 0d c8 0e 7e 0d a4 00 00 00 00 00 00 00 00   .....~..........
         3491  +|   3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c   ...........1tabl
         3492  +|   3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42   et2t2.CREATE TAB
         3493  +|   3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01   LE t2(x).3......
         3494  +|   3536: 82 35 74 61 61 6c 65 74 31 5f 73 65 67 64 69 72   .5taalet1_segdir
         3495  +|   3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45   t1_segdir.CREATE
         3496  +|   3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69    TABLE 't1_segdi
         3497  +|   3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52   r'(level INTEGER
         3498  +|   3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61   ,idx INTEGER,sta
         3499  +|   3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52   rt_block INTEGER
         3500  +|   3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63   ,leaves_end_bloc
         3501  +|   3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c   k INTEGER,end_bl
         3502  +|   3664: 6f 63 6b 20 49 4e 54 45 47 45 52 2c 72 6f 6f 74   ock INTEGER,root
         3503  +|   3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45    BLOB,PRIMARY KE
         3504  +|   3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06   Y(level, idx))1.
         3505  +|   3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74   ..E...indexsqlit
         3506  +|   3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73   e_autoindex_t1_s
         3507  +|   3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72   egdir_1t1_segdir
         3508  +|   3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01   .........f...##.
         3509  +|   3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e   ..tablet1_segmen
         3510  +|   3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52   tst1_segments.CR
         3511  +|   3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73   EATE TABLE 't1_s
         3512  +|   3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64   egments'(blockid
         3513  +|   3840: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59    INTEGER PRIMARY
         3514  +|   3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42    KEY, block BLOB
         3515  +|   3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74   )j...!!...tablet
         3516  +|   3888: 31 5f 63 6f 6e 84 65 6e 74 74 31 5f 63 6f 6e 74   1_con.entt1_cont
         3517  +|   3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45   ent.CREATE TABLE
         3518  +|   3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f    't1_content'(do
         3519  +|   3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   cid INTEGER PRIM
         3520  +|   3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20   ARY KEY, 'c0a', 
         3521  +|   3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06   'c1b', 'c2c')8..
         3522  +|   3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52   ...._tablet1t1CR
         3523  +|   4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42   EATE VIRTUAL TAB
         3524  +|   4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33   LE t1 USING fts3
         3525  +|   4032: 28 61 2c 62 2c 63 29 00 00 00 00 00 00 00 00 00   (a,b,c).........
         3526  +| page 3 offset 8192
         3527  +|      0: 0d 00 00 00 25 0b 48 00 0f d8 0f af 0f 86 0f 74   ....%.H........t
         3528  +|     16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5   .a.N./..........
         3529  +|     32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 0d d5   ...t.[.@.$......
         3530  +|     48: 0d bb 0d a0 0d 84 0d 68 0d 4f 0d 35 0d 1b 0c fb   .......h.O.5....
         3531  +|     64: 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e 0c 24 0c 0a   .......x.W.>.$..
         3532  +|     80: 0b 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00   .H..............
         3533  +|   2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 82 7f 00   .........?%.....
         3534  +|   2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e   .COMPILER=gcc-5.
         3535  +|   2912: 34 2e 30 20 32 30 31 36 30 36 30 39 20 44 45 42   4.0 20160609 DEB
         3536  +|   2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 41 54   UG ENABLE DBSTAT
         3537  +|   2944: 20 56 54 41 42 20 45 4e 41 42 4c 45 20 46 54 53    VTAB ENABLE FTS
         3538  +|   2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e   4 ENABLE FTS5 EN
         3539  +|   2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41   ABLE GEOPOLY ENA
         3540  +|   2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45   BLE JSON1 ENABLE
         3541  +|   3008: 20 4d 45 4d 53 49 53 35 20 45 4e 41 42 4c 45 20    MEMSIS5 ENABLE 
         3542  +|   3024: 52 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59   RTREE MAX MEMORY
         3543  +|   3040: 3d 35 30 30 30 30 30 30 30 20 4f 4d 49 54 20 4c   =50000000 OMIT L
         3544  +|   3056: 4f 41 44 20 45 58 54 45 4e 53 49 4f 4e 20 54 48   OAD EXTENSION TH
         3545  +|   3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 26 0f   READSAFE=0.$..&.
         3546  +|   3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49   .THREADSAFE=0XBI
         3547  +|   3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41   NARY.#..%..THREA
         3548  +|   3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 22   DSAFE=0XNOCASE..
         3549  +|   3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d   ..%..THREADSAFE=
         3550  +|   3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d   0XRTRIM.!..3..OM
         3551  +|   3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4f   IT LOAD EXTENSIO
         3552  +|   3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f   NXBINARY. ..3..O
         3553  +|   3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49   MIT LOAD EXTENSI
         3554  +|   3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17   ONXNOCASE....3..
         3555  +|   3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53   OMIT LOAD EXTENS
         3556  +|   3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19   IONXRTRIM....3..
         3557  +|   3264: 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30   MAX MEMORY=50000
         3558  +|   3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f   000XBINARY....3.
         3559  +|   3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30   .MAX MEMORY=5000
         3560  +|   3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33   0000XNOCASE....3
         3561  +|   3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30   ..MAX MEMORY=500
         3562  +|   3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25   00000XRTRIM....%
         3563  +|   3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42   ..ENABLE RTREEXB
         3564  +|   3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42   INARY....%..ENAB
         3565  +|   3392: 4c 55 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17   LU RTREEXNOCASE.
         3566  +|   3408: 19 05 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52   ...%..ENABLE RTR
         3567  +|   3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45   EEXRTRIM....)..E
         3568  +|   3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49   NABLE MEMSYS5XBI
         3569  +|   3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c   NARY....)..ENABL
         3570  +|   3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45   E MEMSYS5XNOCASE
         3571  +|   3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45   ....)..ENABLE ME
         3572  +|   3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25   MSYS5XRTRIM....%
         3573  +|   3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42   ..ENABLE JSON1XB
         3574  +|   3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42   INARY....%..ENAB
         3575  +|   3552: 4c 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17   LE JSON1XNOCASE.
         3576  +|   3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f   ...%..ENABLE JSO
         3577  +|   3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45   N1XRTRIM....)..E
         3578  +|   3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 58 42 49   NABLE GEOPOLYXBI
         3579  +|   3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 4e 41 42 4c   NARY....)..ENABL
         3580  +|   3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 43 41 53 45   E GEOPOLYXNOCASE
         3581  +|   3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45   ....)..ENABLE GE
         3582  +|   3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 17 0f 05 00 23   OPOLYXRTRIM....#
         3583  +|   3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49   ..ENABLE FTS5XBI
         3584  +|   3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c   NARY....#..ENABL
         3585  +|   3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0d 05   E FTS5XNOCASE...
         3586  +|   3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58   .#..ENABLE FTS5X
         3587  +|   3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42   RTRIM....#..ENAB
         3588  +|   3760: 4c 45 19 46 54 53 34 58 42 49 4e 41 52 59 17 0b   LE.FTS4XBINARY..
         3589  +|   3776: 05 00 23 0f 19 45 4e 41 42 4e f5 20 46 54 53 34   ..#..ENABN. FTS4
         3590  +|   3792: 58 4e 4f 43 41 53 45 16 0a 05 00 23 0f 17 45 4e   XNOCASE....#..EN
         3591  +|   3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e   ABLE FTS4XRTRIM.
         3592  +|   3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         3593  +|   3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e   TAT VTABXBINARY.
         3594  +|   3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         3595  +|   3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d   TAT VTABXNOCASE.
         3596  +|   3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 41 53   ...1..ENABLE DAS
         3597  +|   3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06   TAT VTABXRTRIM..
         3598  +|   3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52   .....DEBUGXBINAR
         3599  +|   3936: 59 11 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f   Y.......DEBUGXNO
         3600  +|   3952: 43 41 53 45 10 04 05 00 17 ab 17 44 45 42 55 47   CASE.......DEBUG
         3601  +|   3968: 48 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d   HRTRIM'...C..COM
         3602  +|   3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20   PILER=gcc-5.4.0 
         3603  +|   4000: 32 30 31 36 30 36 30 39 58 43 49 4e 41 52 59 27   20160609XCINARY'
         3604  +|   4016: 02 04 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67   ...C..COMPILER=g
         3605  +|   4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30   cc-5.4.0 2016060
         3606  +|   4048: 39 58 4e 4f 43 41 53 45 26 01 05 00 43 0f 17 43   9XNOCASE&...C..C
         3607  +|   4064: 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e   OMPILER=gcc-5.4.
         3608  +|   4080: 30 20 32 30 31 36 30 36 30 39 58 52 54 52 49 4d   0 20160609XRTRIM
         3609  +| page 4 offset 12288
         3610  +|      0: 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
         3611  +| page 5 offset 16384
         3612  +|      0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00   ................
         3613  +|   2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33   ...........0 253
         3614  +|   2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36   ..0.%.....201606
         3615  +|   3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35   09.%....4.%....5
         3616  +|   3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a   .%....0000000.%.
         3617  +|   3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00   ...compiler.%...
         3618  +|   3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 62 75   .dbstat.%....ebu
         3619  +|   3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09   g.%....enable.%.
         3620  +|   3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f   .........xtensio
         3621  +|   3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03   n.%....fts4.%...
         3622  +|   3120: 01 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01   .5.%....gcc.%...
         3623  +|   3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f   .eopoly.%....jso
         3624  +|   3152: 6e 31 03 25 13 00 00 04 6c 6f 61 64 03 25 1c 00   n1.%....load.%..
         3625  +|   3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6d 6f 72 79   ..max.%....emory
         3626  +|   3184: 03 25 19 00 03 04 73 79 73 35 03 25 15 00 00 04   .%....sys5.%....
         3627  +|   3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03   omit.%....rtree.
         3628  +|   3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 66 65 03   %....threadsafe.
         3629  +|   3232: 25 1e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01   %....vtab.%...P.
         3630  +|   3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30   ........0 835..0
         3631  +|   3264: 12 01 06 00 01 06 00 01 06 00 1f 03 00 01 03 00   ................
         3632  +|   3280: 01 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07   .....20160609...
         3633  +|   3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05   .........4......
         3634  +|   3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04   ......5.........
         3635  +|   3328: 00 01 07 30 30 30 30 30 30 30 09 1c 04 00 01 04   ...0000000......
         3636  +|   3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02   ......binary<...
         3637  +|   3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02   ................
         3638  +|   3376: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00   ................
         3639  +|   3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03   ................
         3640  +|   3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69   ...........compi
         3641  +|   3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64   ler............d
         3642  +|   3440: 62 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01   bstat...........
         3643  +|   3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00   .ebug...........
         3644  +|   3472: 06 65 6e 61 62 6c 65 3f 07 02 00 01 02 00 01 02   .enable?........
         3645  +|   3488: 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00   ................
         3646  +|   3504: 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01   ................
         3647  +|   3520: 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02   ................
         3648  +|   3536: 00 01 02 00 01 02 00 01 08 78 74 65 6e 73 69 6f   .........xtensio
         3649  +|   3552: 6e 09 1f 04 00 01 04 00 01 04 00 00 04 66 74 73   n............fts
         3650  +|   3568: 34 09 0a 03 d4 01 02 ff 01 03 00 03 01 35 09 0d   4............5..
         3651  +|   3584: 03 00 01 03 00 01 03 00 00 03 67 64 d3 09 01 03   ..........gd....
         3652  +|   3600: 00 01 03 00 01 03 00 01 06 65 6f 70 6f 6c 79 09   .........eopoly.
         3653  +|   3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31   ...........json1
         3654  +|   3632: 19 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64   ............load
         3655  +|   3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09   ............max.
         3656  +|   3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79   ...........emory
         3657  +|   3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35   ............sys5
         3658  +|   3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61   ............noca
         3659  +|   3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02   se<.............
         3660  +|   3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02   ................
         3661  +|   3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00   ................
         3662  +|   3760: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 00   ................
         3663  +|   3776: 04 6f 6d 69 74 09 1f 02 00 01 12 00 01 02 00 00   .omit...........
         3664  +|   3792: 05 72 74 72 65 65 09 19 03 00 01 07 80 00 f3 00   .rtree..........
         3665  +|   3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03   ..im<...........
         3666  +|   3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01   ................
         3667  +|   3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02   ................
         3668  +|   3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02   ................
         3669  +|   3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02   ...threadsafe...
         3670  +|   3888: 00 01 02 00 01 02 00 00 04 76 74 61 62 09 07 04   .........vtab...
         3671  +|   3904: 00 01 04 00 01 04 00 00 01 78 b4 01 01 01 01 02   .........x......
         3672  +|   3920: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00   ................
         3673  +|   3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01   ................
         3674  +|   3952: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01   ................
         3675  +|   3968: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01   ................
         3676  +|   3984: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02   ................
         3677  +|   4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00   ................
         3678  +|   4016: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01   ................
         3679  +|   4032: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01   ................
         3680  +|   4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01   ................
         3681  +|   4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02   ................
         3682  +|   4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00   ................
         3683  +| page 6 offset 20480
         3684  +|      0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00   ................
         3685  +|   4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09   ................
         3686  +| page 7 offset 24576
         3687  +|      0: 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
         3688  +|   4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 75 74 6f   ...........#auto
         3689  +|   4032: 6d 65 72 67 65 3d 35 0d 04 02 23 6d 65 72 67 65   merge=5...#merge
         3690  +|   4048: 3d 31 30 30 2c 38 11 03 02 2b 69 6e 74 65 67 72   =100,8...+integr
         3691  +|   4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62   ity-check....reb
         3692  +| end crash-b794c89d922ac9.db
         3693  +}]} {}
         3694  +
         3695  +do_catchsql_test 22.1 {
         3696  +  SELECT snippet(t1,'', '', '--',-1,01)==0
         3697  +    FROM t1 WHERE a MATCH 'rtree OR json1rtree OR json1';
         3698  +} {0 {0 0 0 0 0 0 0}}
  3262   3699   
  3263   3700   finish_test
  3264   3701   

Changes to test/fts3expr4.test.

    64     64     AND {PHRASE 3 0 lol+} {PHRASE 3 0 h4h+}
    65     65   }
    66     66   
    67     67   do_icu_expr_test 3.2 {*lOl* *h4h*} {
    68     68     AND {AND {AND {PHRASE 3 0 *} {PHRASE 3 0 lol+}} {PHRASE 3 0 *}} {PHRASE 3 0 h4h+}
    69     69   }
    70     70   
    71         -do_simple_expr_test 3.3 { * }    { }
           71  +do_simple_expr_test 3.3 { * }    {}
    72     72   do_simple_expr_test 3.4 { *a }   { PHRASE 3 0 a }
    73     73   do_simple_expr_test 3.5 { a*b }  { AND {PHRASE 3 0 a+} {PHRASE 3 0 b} }
    74     74   do_simple_expr_test 3.6 { *a*b } { AND {PHRASE 3 0 a+} {PHRASE 3 0 b} }
    75     75   do_simple_expr_test 3.7 { *"abc" } { PHRASE 3 0 abc }
    76     76   do_simple_expr_test 3.8 { "abc"* } { PHRASE 3 0 abc }
    77     77   do_simple_expr_test 3.8 { "ab*c" } { PHRASE 3 0 ab+ c }
    78     78   
    79     79   do_icu_expr_test    3.9 { "ab*c" } { PHRASE 3 0 ab+ * c }
    80     80   do_icu_expr_test    3.10 { ab*c } { AND {PHRASE 3 0 ab+} {PHRASE 3 0 c}}
    81     81   
    82     82   finish_test

Changes to test/fuzzdata8.db.

cannot compute difference between binary files

Changes to test/in.test.

   646    646   do_execsql_test in-14.0 {
   647    647     CREATE TABLE c1(a);
   648    648     INSERT INTO c1 VALUES(1), (2), (4), (3);
   649    649   }
   650    650   do_execsql_test in-14.1 {
   651    651     SELECT * FROM c1 WHERE a IN (SELECT a FROM c1) ORDER BY 1
   652    652   } {1 2 3 4}
          653  +
          654  +# 2019-02-20 Ticket https://www.sqlite.org/src/tktview/df46dfb631f75694fbb97033b69
          655  +#
          656  +do_execsql_test in-15.0 {
          657  +  DROP TABLE IF EXISTS t1;
          658  +  CREATE TABLE IF NOT EXISTS t1(id INTEGER PRIMARY KEY);
          659  +  INSERT INTO t1 VALUES(1);
          660  +  SELECT a.id FROM t1 AS a JOIN t1 AS b ON a.id=b.id WHERE a.id IN (1,2,3);
          661  +} {1}
          662  +do_execsql_test in-15.1 {
          663  +  DROP TABLE IF EXISTS t2;
          664  +  CREATE TABLE t2(a INTEGER PRIMARY KEY,b);
          665  +  INSERT INTO t2 VALUES(1,11);
          666  +  INSERT INTO t2 VALUES(2,22);
          667  +  INSERT INTO t2 VALUES(3,33);
          668  +  SELECT b, a IN (3,4,5) FROM t2 ORDER BY b;
          669  +} {11 0 22 0 33 1}
          670  +do_execsql_test in-15.2 {
          671  +  DROP TABLE IF EXISTS t3;
          672  +  CREATE TABLE t3(x INTEGER PRIMARY KEY);
          673  +  INSERT INTO t3 VALUES(8);
          674  +  SELECT CASE WHEN x NOT IN (5,6,7) THEN 'yes' ELSE 'no' END FROM t3;
          675  +  SELECT CASE WHEN x NOT IN (NULL,6,7) THEN 'yes' ELSE 'no' END FROM t3;
          676  +} {yes no}
          677  +do_execsql_test in-15.3 {
          678  +  SELECT CASE WHEN x NOT IN (5,6,7) OR x=0 THEN 'yes' ELSE 'no' END FROM t3;
          679  +  SELECT CASE WHEN x NOT IN (NULL,6,7) OR x=0 THEN 'yes' ELSE 'no' END FROM t3;
          680  +} {yes no}
          681  +do_execsql_test in-15.4 {
          682  +  DROP TABLE IF EXISTS t4;
          683  +  CREATE TABLE t4(a INTEGER PRIMARY KEY, b INT);
          684  +  WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<20)
          685  +    INSERT INTO t4(a,b) SELECT x, x+100 FROM c;
          686  +  SELECT b FROM t4 WHERE a IN (3,null,8) ORDER BY +b;
          687  +} {103 108}
          688  +do_execsql_test in-15.5 {
          689  +  SELECT b FROM t4 WHERE a NOT IN (3,null,8);
          690  +} {}
          691  +do_execsql_test in-15.6 {
          692  +  DROP TABLE IF EXISTS t5;
          693  +  DROP TABLE IF EXISTS t6;
          694  +  CREATE TABLE t5(id INTEGER PRIMARY KEY, name TEXT);
          695  +  CREATE TABLE t6(id INTEGER PRIMARY KEY, name TEXT, t5_id INT);
          696  +  INSERT INTO t5 VALUES(1,'Alice'),(2,'Emma');
          697  +  INSERT INTO t6 VALUES(1,'Bob',1),(2,'Cindy',1),(3,'Dave',2);
          698  +  SELECT a.*
          699  +    FROM t5 AS 'a' JOIN t5 AS 'b' ON b.id=a.id
          700  +   WHERE b.id IN (
          701  +          SELECT t6.t5_id
          702  +            FROM t6
          703  +           WHERE name='Bob'
          704  +             AND t6.t5_id IS NOT NULL
          705  +             AND t6.id IN (
          706  +                  SELECT id
          707  +                    FROM (SELECT t6.id, count(*) AS x
          708  +                            FROM t6
          709  +                           WHERE name='Bob'
          710  +                         ) AS 't'
          711  +                   WHERE x=1
          712  +                 )
          713  +             AND t6.id IN (1,id)
          714  +         );
          715  +} {1 Alice}
          716  +
   653    717   
   654    718   finish_test

Changes to test/indexfault.test.

   332    332     faultsim_restore_and_reopen
   333    333     set ::nReadCall 0
   334    334     sqlite3_soft_heap_limit 0
   335    335   } -body {
   336    336     execsql { CREATE INDEX i1 ON t1(x) }
   337    337     faultsim_test_result {0 {}} 
   338    338   }
          339  +
          340  +do_faultsim_test 5 -prep {
          341  +  reset_db
          342  +} -body {
          343  +  execsql { 
          344  + CREATE TABLE reallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallylongname(a PRIMARY KEY) WITHOUT ROWID;
          345  +  }
          346  +} -test {
          347  +  faultsim_test_result {0 {}} 
          348  +}
   339    349   
   340    350   uninstall_custom_faultsim
   341    351   
   342    352   finish_test

Changes to test/like3.test.

   173    173   } {/abc}
   174    174   do_eqp_test like3-5.211 {
   175    175     SELECT x FROM t5b WHERE x GLOB '/a*';
   176    176   } {
   177    177     QUERY PLAN
   178    178     `--SEARCH TABLE t5b USING COVERING INDEX sqlite_autoindex_t5b_1 (x>? AND x<?)
   179    179   }
          180  +
          181  +# 2019-02-27
          182  +# Verify that the LIKE optimization works with an ESCAPE clause when
          183  +# using PRAGMA case_sensitive_like=ON.
          184  +#
          185  +do_execsql_test like3-6.100 {
          186  +  DROP TABLE IF EXISTS t1;
          187  +  CREATE TABLE t1(path TEXT COLLATE nocase PRIMARY KEY,a,b,c) WITHOUT ROWID;
          188  +}
          189  +do_eqp_test like3-6.110 {
          190  +  SELECT * FROM t1 WHERE path LIKE 'a%';
          191  +} {
          192  +  QUERY PLAN
          193  +  `--SEARCH TABLE t1 USING PRIMARY KEY (path>? AND path<?)
          194  +}
          195  +do_eqp_test like3-6.120 {
          196  +  SELECT * FROM t1 WHERE path LIKE 'a%' ESCAPE '_';
          197  +} {
          198  +  QUERY PLAN
          199  +  `--SEARCH TABLE t1 USING PRIMARY KEY (path>? AND path<?)
          200  +}
          201  +do_execsql_test like3-6.200 {
          202  +  DROP TABLE IF EXISTS t2;
          203  +  CREATE TABLE t2(path TEXT,x,y,z);
          204  +  CREATE INDEX t2path ON t2(path COLLATE nocase);
          205  +  CREATE INDEX t2path2 ON t2(path);
          206  +}
          207  +do_eqp_test like3-6.210 {
          208  +  SELECT * FROM t2 WHERE path LIKE 'a%';
          209  +} {
          210  +  QUERY PLAN
          211  +  `--SEARCH TABLE t2 USING INDEX t2path (path>? AND path<?)
          212  +}
          213  +do_eqp_test like3-6.220 {
          214  +  SELECT * FROM t2 WHERE path LIKE 'a%' ESCAPE '_';
          215  +} {
          216  +  QUERY PLAN
          217  +  `--SEARCH TABLE t2 USING INDEX t2path (path>? AND path<?)
          218  +}
          219  +db eval {PRAGMA case_sensitive_like=ON}
          220  +do_eqp_test like3-6.230 {
          221  +  SELECT * FROM t2 WHERE path LIKE 'a%';
          222  +} {
          223  +  QUERY PLAN
          224  +  `--SEARCH TABLE t2 USING INDEX t2path2 (path>? AND path<?)
          225  +}
          226  +do_eqp_test like3-6.240 {
          227  +  SELECT * FROM t2 WHERE path LIKE 'a%' ESCAPE '_';
          228  +} {
          229  +  QUERY PLAN
          230  +  `--SEARCH TABLE t2 USING INDEX t2path2 (path>? AND path<?)
          231  +}
   180    232   
   181    233   finish_test

Changes to test/printf.test.

   536    536     sqlite3_mprintf_double {abc: %d %d (%1.1e) :xyz} 1 1 1.0e-20
   537    537   } {abc: 1 1 (1.0e-20) :xyz}
   538    538   do_test printf-2.1.2.9 {
   539    539     sqlite3_mprintf_double {abc: %d %d (%1.1g) :xyz} 1 1 1.0e-20
   540    540   } {abc: 1 1 (1e-20) :xyz}
   541    541   do_test printf-2.1.2.10 {
   542    542     sqlite3_mprintf_double {abc: %*.*f}  2000000000 1000000000 1.0e-20
   543         -} {abc: }
          543  +} {}
   544    544   do_test printf-2.1.3.1 {
   545    545     sqlite3_mprintf_double {abc: (%*.*f) :xyz} 1 1 1.0
   546    546   } {abc: (1.0) :xyz}
   547    547   do_test printf-2.1.3.2 {
   548    548     sqlite3_mprintf_double {abc: (%*.*e) :xyz} 1 1 1.0
   549    549   } {abc: (1.0e+00) :xyz}
   550    550   do_test printf-2.1.3.3 {

Changes to test/scanstatus.test.

   250    250       SELECT * FROM t2 WHERE x BETWEEN 20 AND 40;
   251    251     END;
   252    252     WITH d(x) AS (SELECT 1 UNION ALL SELECT x+1 AS n FROM d WHERE n<=100)
   253    253     INSERT INTO t2 SELECT x, x*2, x*3 FROM d;
   254    254   }
   255    255   
   256    256   do_execsql_test    4.1.1 { INSERT INTO t1 VALUES(1, 2, 3); }
   257         -do_scanstatus_test 4.1.2 { }
          257  +do_scanstatus_test 4.1.2 {}
   258    258   
   259    259   do_execsql_test 4.2 {
   260    260     CREATE TABLE p1(x PRIMARY KEY);
   261    261     INSERT INTO p1 VALUES(1), (2), (3), (4);
   262    262     CREATE TABLE c1(y REFERENCES p1);
   263    263     INSERT INTO c1 VALUES(1), (2), (3);
   264    264     PRAGMA foreign_keys=on;

Changes to test/tclsqlite.test.

    17     17   #
    18     18   # $Id: tclsqlite.test,v 1.73 2009/03/16 13:19:36 danielk1977 Exp $
    19     19   
    20     20   catch {sqlite3}
    21     21   
    22     22   set testdir [file dirname $argv0]
    23     23   source $testdir/tester.tcl
           24  +set testprefix tcl
    24     25   
    25     26   # Check the error messages generated by tclsqlite
    26     27   #
    27     28   set r "sqlite_orig HANDLE ?FILENAME? ?-vfs VFSNAME? ?-readonly BOOLEAN? ?-create BOOLEAN? ?-nomutex BOOLEAN? ?-fullmutex BOOLEAN? ?-uri BOOLEAN?"
    28     29   if {[sqlite3 -has-codec]} {
    29     30     append r " ?-key CODECKEY?"
    30     31   }
................................................................................
    37     38     set v [catch {sqlite3} msg]
    38     39     regsub {really_sqlite3} $msg {sqlite3} msg
    39     40     lappend v $msg
    40     41   } [list 1 "wrong # args: should be \"$r\""]
    41     42   do_test tcl-1.2 {
    42     43     set v [catch {db bogus} msg]
    43     44     lappend v $msg
    44         -} {1 {bad option "bogus": must be authorizer, backup, busy, cache, changes, close, collate, collation_needed, commit_hook, complete, copy, deserialize, enable_load_extension, errorcode, eval, exists, function, incrblob, interrupt, last_insert_rowid, nullvalue, onecolumn, preupdate, profile, progress, rekey, restore, rollback_hook, serialize, status, timeout, total_changes, trace, trace_v2, transaction, unlock_notify, update_hook, version, or wal_hook}}
           45  +} {1 {bad option "bogus": must be authorizer, backup, bind_fallback, busy, cache, changes, close, collate, collation_needed, commit_hook, complete, copy, deserialize, enable_load_extension, errorcode, eval, exists, function, incrblob, interrupt, last_insert_rowid, nullvalue, onecolumn, preupdate, profile, progress, rekey, restore, rollback_hook, serialize, status, timeout, total_changes, trace, trace_v2, transaction, unlock_notify, update_hook, version, or wal_hook}}
    45     46   do_test tcl-1.2.1 {
    46     47     set v [catch {db cache bogus} msg]
    47     48     lappend v $msg
    48     49   } {1 {bad option "bogus": must be flush or size}}
    49     50   do_test tcl-1.2.2 {
    50     51     set v [catch {db cache} msg]
    51     52     lappend v $msg
................................................................................
   707    708     unset -nocomplain x
   708    709     db eval -withoutnulls {SELECT * FROM t1} x {
   709    710       lappend res $x(a) [array names x]
   710    711     }
   711    712     set res
   712    713   } {1 {a b *} 2 {a *} 3 {a b *}}
   713    714   
          715  +#-------------------------------------------------------------------------
          716  +# Test the -type option to [db function].
          717  +#
          718  +reset_db
          719  +proc add {a b} { return [expr $a + $b] }
          720  +proc ret {a} { return $a }
          721  +
          722  +db function add_i -returntype integer add 
          723  +db function add_r -ret        real    add
          724  +db function add_t -return     text    add 
          725  +db function add_b -returntype blob    add 
          726  +db function add_a -returntype any     add 
          727  +
          728  +db function ret_i -returntype int     ret 
          729  +db function ret_r -returntype real    ret
          730  +db function ret_t -returntype text    ret 
          731  +db function ret_b -returntype blob    ret 
          732  +db function ret_a -r          any     ret 
          733  +
          734  +do_execsql_test 17.0 {
          735  +  SELECT quote( add_i(2, 3) );
          736  +  SELECT quote( add_r(2, 3) ); 
          737  +  SELECT quote( add_t(2, 3) ); 
          738  +  SELECT quote( add_b(2, 3) ); 
          739  +  SELECT quote( add_a(2, 3) ); 
          740  +} {5 5.0 '5' X'35' 5}
          741  +
          742  +do_execsql_test 17.1 {
          743  +  SELECT quote( add_i(2.2, 3.3) );
          744  +  SELECT quote( add_r(2.2, 3.3) ); 
          745  +  SELECT quote( add_t(2.2, 3.3) ); 
          746  +  SELECT quote( add_b(2.2, 3.3) ); 
          747  +  SELECT quote( add_a(2.2, 3.3) ); 
          748  +} {5.5 5.5 '5.5' X'352E35' 5.5}
          749  +
          750  +do_execsql_test 17.2 {
          751  +  SELECT quote( ret_i(2.5) );
          752  +  SELECT quote( ret_r(2.5) ); 
          753  +  SELECT quote( ret_t(2.5) ); 
          754  +  SELECT quote( ret_b(2.5) ); 
          755  +  SELECT quote( ret_a(2.5) ); 
          756  +} {2.5 2.5 '2.5' X'322E35' 2.5}
          757  +
          758  +do_execsql_test 17.3 {
          759  +  SELECT quote( ret_i('2.5') );
          760  +  SELECT quote( ret_r('2.5') ); 
          761  +  SELECT quote( ret_t('2.5') ); 
          762  +  SELECT quote( ret_b('2.5') ); 
          763  +  SELECT quote( ret_a('2.5') ); 
          764  +} {2.5 2.5 '2.5' X'322E35' '2.5'}
          765  +
          766  +do_execsql_test 17.4 {
          767  +  SELECT quote( ret_i('abc') );
          768  +  SELECT quote( ret_r('abc') ); 
          769  +  SELECT quote( ret_t('abc') ); 
          770  +  SELECT quote( ret_b('abc') ); 
          771  +  SELECT quote( ret_a('abc') ); 
          772  +} {'abc' 'abc' 'abc' X'616263' 'abc'}
          773  +
          774  +do_execsql_test 17.5 {
          775  +  SELECT quote( ret_i(X'616263') );
          776  +  SELECT quote( ret_r(X'616263') ); 
          777  +  SELECT quote( ret_t(X'616263') ); 
          778  +  SELECT quote( ret_b(X'616263') ); 
          779  +  SELECT quote( ret_a(X'616263') ); 
          780  +} {'abc' 'abc' 'abc' X'616263' X'616263'}
          781  +
          782  +do_test 17.6.1 {
          783  +  list [catch { db function xyz -return object ret } msg] $msg
          784  +} {1 {bad type "object": must be integer, real, text, blob, or any}}
          785  +
          786  +do_test 17.6.2 {
          787  +  list [catch { db function xyz -return ret } msg] $msg
          788  +} {1 {option requires an argument: -return}}
   714    789   
          790  +do_test 17.6.3 {
          791  +  list [catch { db function xyz -n object ret } msg] $msg
          792  +} {1 {bad option "-n": must be -argcount, -deterministic or -returntype}}
   715    793   
   716         -
          794  +# 2019-02-28: The "bind_fallback" command.
          795  +#
          796  +do_test 18.100 {
          797  +  unset -nocomplain bindings abc def ghi jkl mno e01 e02
          798  +  set bindings(abc) [expr {1+2}]
          799  +  set bindings(def) {hello}
          800  +  set bindings(ghi) [expr {3.1415926*1.0}]
          801  +  proc bind_callback {nm} {
          802  +    global bindings
          803  +    set n2 [string range $nm 1 end]
          804  +    if {[info exists bindings($n2)]} {
          805  +      return $bindings($n2)
          806  +    }
          807  +    if {[string match e* $n2]} {
          808  +      error "no such variable: $nm"
          809  +    }
          810  +    return -code return {}
          811  +  }
          812  +  db bind_fallback bind_callback
          813  +  db eval {SELECT $abc, typeof($abc), $def, typeof($def), $ghi, typeof($ghi)}
          814  +} {3 integer hello text 3.1415926 real}
          815  +do_test 18.110 {
          816  +  db eval {SELECT quote(@def), typeof(@def)}
          817  +} {X'68656C6C6F' blob}
          818  +do_execsql_test 18.120 {
          819  +  SELECT typeof($mno);
          820  +} {null}
          821  +do_catchsql_test 18.130 {
          822  +  SELECT $e01;
          823  +} {1 {no such variable: $e01}}
          824  +do_test 18.140 {
          825  +  db bind_fallback
          826  +} {bind_callback}
          827  +do_test 18.200 {
          828  +  db bind_fallback {}
          829  +  db eval {SELECT $abc, typeof($abc), $def, typeof($def), $ghi, typeof($ghi)}
          830  +} {{} null {} null {} null}
          831  +do_test 18.300 {
          832  +  unset -nocomplain bindings
          833  +  proc bind_callback {nm} {lappend ::bindings $nm}
          834  +  db bind_fallback bind_callback
          835  +  db eval {SELECT $abc, @def, $ghi(123), :mno}
          836  +  set bindings
          837  +} {{$abc} @def {$ghi(123)} :mno}
          838  +do_test 18.900 {
          839  +  set rc [catch {db bind_fallback a b} msg]
          840  +  lappend rc $msg
          841  +} {1 {wrong # args: should be "db bind_fallback ?CALLBACK?"}}
          842  +do_test 18.910 {
          843  +  db bind_fallback bind_fallback_does_not_exist
          844  +} {}
          845  +do_catchsql_test 19.911 {
          846  +  SELECT $abc, typeof($abc), $def, typeof($def), $ghi, typeof($ghi);
          847  +} {1 {invalid command name "bind_fallback_does_not_exist"}}
          848  +db bind_fallback {}
   717    849   
   718    850   finish_test

Changes to test/where.test.

  1421   1421     CREATE TABLE t1(a INT);
  1422   1422     CREATE INDEX t1a ON t1(a);
  1423   1423     INSERT INTO t1(a) VALUES(NULL),(NULL),(42),(NULL),(NULL);
  1424   1424     CREATE TABLE t2(dummy INT);
  1425   1425     SELECT count(*) FROM t1 LEFT JOIN t2 ON a IS NOT NULL;
  1426   1426   } {5}
  1427   1427   
         1428  +# 20190-02-22:  A bug introduced by checkin
         1429  +# https://www.sqlite.org/src/info/fa792714ae62fa98.
         1430  +#
         1431  +do_execsql_test where-23.0 {
         1432  +  DROP TABLE IF EXISTS t1;
         1433  +  DROP TABLE IF EXISTS t2;
         1434  +  CREATE TABLE t1(a INTEGER PRIMARY KEY);
         1435  +  INSERT INTO t1(a) VALUES(1),(2),(3);
         1436  +  CREATE TABLE t2(x INTEGER PRIMARY KEY, y INT);
         1437  +  INSERT INTO t2(y) VALUES(2),(3);
         1438  +  SELECT * FROM t1, t2 WHERE a=y AND y=3;
         1439  +} {3 2 3}
  1428   1440   
  1429   1441   finish_test

Changes to test/window1.test.

   695    695     SELECT rowid, sum(a) OVER w1 FROM t7 
   696    696     WINDOW w1 AS (PARTITION BY b IN (SELECT rowid FROM t7));
   697    697   } {
   698    698     2 10
   699    699     1 101
   700    700     3 101
   701    701   }
          702  +
          703  +#-------------------------------------------------------------------------
          704  +do_execsql_test 17.0 {
          705  +  CREATE TABLE t8(a);
          706  +  INSERT INTO t8 VALUES(1), (2), (3);
          707  +}
          708  +
          709  +do_execsql_test 17.1 {
          710  +  SELECT +sum(0) OVER () ORDER BY +sum(0) OVER ();
          711  +} {0}
          712  +
          713  +do_execsql_test 17.2 {
          714  +  select +sum(a) OVER () FROM t8 ORDER BY +sum(a) OVER () DESC;
          715  +} {6 6 6}
          716  +
          717  +do_execsql_test 17.3 {
          718  +  SELECT 10+sum(a) OVER (ORDER BY a) 
          719  +  FROM t8 
          720  +  ORDER BY 10+sum(a) OVER (ORDER BY a) DESC;
          721  +} {16 13 11}
   702    722   
   703    723   #-------------------------------------------------------------------------
   704    724   # Test error cases from chaining window definitions.
   705    725   #
   706    726   reset_db
   707         -do_execsql_test 17.0 {
          727  +do_execsql_test 18.0 {
   708    728     DROP TABLE IF EXISTS t1;
   709    729     CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c TEXT, d INTEGER);
   710    730     INSERT INTO t1 VALUES(1, 'odd',  'one',   1);
   711    731     INSERT INTO t1 VALUES(2, 'even', 'two',   2);
   712    732     INSERT INTO t1 VALUES(3, 'odd',  'three', 3);
   713    733     INSERT INTO t1 VALUES(4, 'even', 'four',  4);
   714    734     INSERT INTO t1 VALUES(5, 'odd',  'five',  5);
................................................................................
   736    756   
   737    757     4 {
   738    758       SELECT c, sum(d) OVER win2 FROM t1
   739    759         WINDOW win1 AS (ORDER BY b),
   740    760                win2 AS (win1 ORDER BY d)
   741    761     } {cannot override ORDER BY clause of window: win1}
   742    762   } {
   743         -  do_catchsql_test 17.1.$tn $sql [list 1 $error]
          763  +  do_catchsql_test 18.1.$tn $sql [list 1 $error]
   744    764   }
   745    765   
   746    766   foreach {tn sql error} {
   747    767     1 {
   748    768       SELECT c, sum(d) OVER (win1 ORDER BY b) FROM t1
   749    769         WINDOW win1 AS (ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING)
   750    770     } {cannot override frame specification of window: win1}
................................................................................
   760    780     } {cannot override PARTITION clause of window: win1}
   761    781   
   762    782     4 {
   763    783       SELECT c, sum(d) OVER (win1 ORDER BY d) FROM t1
   764    784         WINDOW win1 AS (ORDER BY b)
   765    785     } {cannot override ORDER BY clause of window: win1}
   766    786   } {
   767         -  do_catchsql_test 17.2.$tn $sql [list 1 $error]
          787  +  do_catchsql_test 18.2.$tn $sql [list 1 $error]
   768    788   }
   769    789   
   770         -do_execsql_test 17.3.1 {
          790  +do_execsql_test 18.3.1 {
   771    791     SELECT group_concat(c, '.') OVER (PARTITION BY b ORDER BY c)
   772    792     FROM t1
   773    793   } {four four.six four.six.two five five.one five.one.three}
   774    794   
   775         -do_execsql_test 17.3.2 {
          795  +do_execsql_test 18.3.2 {
   776    796     SELECT group_concat(c, '.') OVER (win1 ORDER BY c)
   777    797     FROM t1
   778    798     WINDOW win1 AS (PARTITION BY b)
   779    799   } {four four.six four.six.two five five.one five.one.three}
   780    800   
   781         -do_execsql_test 17.3.3 {
          801  +do_execsql_test 18.3.3 {
   782    802     SELECT group_concat(c, '.') OVER win2
   783    803     FROM t1
   784    804     WINDOW win1 AS (PARTITION BY b),
   785    805            win2 AS (win1 ORDER BY c)
   786    806   } {four four.six four.six.two five five.one five.one.three}
   787    807   
   788         -do_execsql_test 17.3.4 {
          808  +do_execsql_test 18.3.4 {
   789    809     SELECT group_concat(c, '.') OVER (win2)
   790    810     FROM t1
   791    811     WINDOW win1 AS (PARTITION BY b),
   792    812            win2 AS (win1 ORDER BY c)
   793    813   } {four four.six four.six.two five five.one five.one.three}
   794    814   
   795         -do_execsql_test 17.3.5 {
          815  +do_execsql_test 18.3.5 {
   796    816     SELECT group_concat(c, '.') OVER win5
   797    817     FROM t1
   798    818     WINDOW win1 AS (PARTITION BY b),
   799    819            win2 AS (win1),
   800    820            win3 AS (win2),
   801    821            win4 AS (win3),
   802    822            win5 AS (win4 ORDER BY c)
   803    823   } {four four.six four.six.two five five.one five.one.three}
   804    824   
   805    825   finish_test