/ Check-in [e8c20a88]
Login

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

Overview
Comment:Merge recent enhancements from trunk.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | apple-osx
Files: files | file ages | folders
SHA3-256: e8c20a88c14d496fc79dddcac5db0a47aa037598b3b65a07e4422f7df75cce2c
User & Date: drh 2018-11-26 23:35:13
Context
2018-11-30
18:22
Merge the pre-3.26.0 fixes from trunk. check-in: 2c76ce4f user: drh tags: apple-osx
2018-11-26
23:35
Merge recent enhancements from trunk. check-in: e8c20a88 user: drh tags: apple-osx
18:09
Do not allow direct access to internal-use SQL functions such as sqlite_rename_column() and sqlite3_rename_table() except when the new SQLITE_TESTCTRL_INTERNAL_FUNCTIONS flag is set. check-in: 6e133054 user: drh tags: trunk
2018-11-10
20:07
Merge the read-only shadow table and defensive mode enhancments from trunk. check-in: 977fc44e user: drh tags: apple-osx
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Makefile.in.

   470    470     $(TOP)/src/build.c \
   471    471     $(TOP)/src/ctime.c \
   472    472     $(TOP)/src/date.c \
   473    473     $(TOP)/src/dbpage.c \
   474    474     $(TOP)/src/dbstat.c \
   475    475     $(TOP)/src/expr.c \
   476    476     $(TOP)/src/func.c \
          477  +  $(TOP)/src/global.c \
   477    478     $(TOP)/src/insert.c \
   478    479     $(TOP)/src/wal.c \
   479    480     $(TOP)/src/main.c \
   480    481     $(TOP)/src/mem5.c \
   481    482     $(TOP)/src/os.c \
   482    483     $(TOP)/src/os_unix.c \
   483    484     $(TOP)/src/os_win.c \
................................................................................
   686    687     -DSQLITE_DEBUG \
   687    688     -DSQLITE_ENABLE_DBSTAT_VTAB \
   688    689     -DSQLITE_ENABLE_RTREE \
   689    690     -DSQLITE_ENABLE_FTS4 \
   690    691     -DSQLITE_EANBLE_FTS5
   691    692   
   692    693   dbfuzz2:	$(TOP)/test/dbfuzz2.c sqlite3.c sqlite3.h
   693         -	clang-6.0 -I. -g -O0 -fsanitize=fuzzer,undefined -o dbfuzz2 \
          694  +	clang-6.0 -I. -g -O0 -fsanitize=fuzzer,undefined,address -o dbfuzz2 \
   694    695   		$(DBFUZZ2_OPTS) $(TOP)/test/dbfuzz2.c sqlite3.c
   695    696   	mkdir -p dbfuzz2-dir
   696    697   	cp $(TOP)/test/dbfuzz2-seed* dbfuzz2-dir
   697    698   
   698    699   mptester$(TEXE):	sqlite3.lo $(TOP)/mptest/mptest.c
   699    700   	$(LTLINK) -o $@ -I. $(TOP)/mptest/mptest.c sqlite3.lo \
   700    701   		$(TLIBS) -rpath "$(libdir)"

Changes to ext/fts5/fts5_index.c.

  5398   5398   
  5399   5399       if( p->rc ){
  5400   5400         sqlite3Fts5IterClose((Fts5IndexIter*)pRet);
  5401   5401         pRet = 0;
  5402   5402         fts5CloseReader(p);
  5403   5403       }
  5404   5404   
  5405         -    *ppIter = &pRet->base;
         5405  +    *ppIter = (Fts5IndexIter*)pRet;
  5406   5406       sqlite3Fts5BufferFree(&buf);
  5407   5407     }
  5408   5408     return fts5IndexReturn(p);
  5409   5409   }
  5410   5410   
  5411   5411   /*
  5412   5412   ** Return true if the iterator passed as the only argument is at EOF.

Changes to ext/fts5/fts5_vocab.c.

   427    427   static int fts5VocabInstanceNext(Fts5VocabCursor *pCsr){
   428    428     int eDetail = pCsr->pConfig->eDetail;
   429    429     int rc = SQLITE_OK;
   430    430     Fts5IndexIter *pIter = pCsr->pIter;
   431    431     i64 *pp = &pCsr->iInstPos;
   432    432     int *po = &pCsr->iInstOff;
   433    433     
          434  +  assert( sqlite3Fts5IterEof(pIter)==0 );
          435  +  assert( pCsr->bEof==0 );
   434    436     while( eDetail==FTS5_DETAIL_NONE
   435    437         || sqlite3Fts5PoslistNext64(pIter->pData, pIter->nData, po, pp) 
   436    438     ){
   437    439       pCsr->iInstPos = 0;
   438    440       pCsr->iInstOff = 0;
   439    441   
   440    442       rc = sqlite3Fts5IterNextScan(pCsr->pIter);
   441    443       if( rc==SQLITE_OK ){
   442    444         rc = fts5VocabInstanceNewTerm(pCsr);
   443         -      if( eDetail==FTS5_DETAIL_NONE ) break;
          445  +      if( pCsr->bEof || eDetail==FTS5_DETAIL_NONE ) break;
   444    446       }
   445    447       if( rc ){
   446    448         pCsr->bEof = 1;
   447    449         break;
   448    450       }
   449    451     }
   450    452   

Changes to ext/fts5/test/fts5vocab2.test.

     9      9   #
    10     10   #***********************************************************************
    11     11   #
    12     12   # The tests in this file focus on testing the fts5vocab module.
    13     13   #
    14     14   
    15     15   source [file join [file dirname [info script]] fts5_common.tcl]
    16         -set testprefix fts5vocab
           16  +set testprefix fts5vocab2
    17     17   
    18     18   # If SQLITE_ENABLE_FTS5 is defined, omit this file.
    19     19   ifcapable !fts5 {
    20     20     finish_test
    21     21     return
    22     22   }
    23     23   

Changes to ext/misc/csv.c.

    15     15   **
    16     16   ** Usage:
    17     17   **
    18     18   **    .load ./csv
    19     19   **    CREATE VIRTUAL TABLE temp.csv USING csv(filename=FILENAME);
    20     20   **    SELECT * FROM csv;
    21     21   **
    22         -** The columns are named "c1", "c2", "c3", ... by default.  But the
    23         -** application can define its own CREATE TABLE statement as an additional
    24         -** parameter.  For example:
           22  +** The columns are named "c1", "c2", "c3", ... by default.  Or the
           23  +** application can define its own CREATE TABLE statement using the
           24  +** schema= parameter, like this:
    25     25   **
    26     26   **    CREATE VIRTUAL TABLE temp.csv2 USING csv(
    27     27   **       filename = "../http.log",
    28     28   **       schema = "CREATE TABLE x(date,ipaddr,url,referrer,userAgent)"
    29     29   **    );
    30     30   **
    31     31   ** Instead of specifying a file, the text of the CSV can be loaded using
    32     32   ** the data= parameter.
    33     33   **
    34     34   ** If the columns=N parameter is supplied, then the CSV file is assumed to have
    35         -** N columns.  If the columns parameter is omitted, the CSV file is opened
    36         -** as soon as the virtual table is constructed and the first row of the CSV
    37         -** is read in order to count the tables.
           35  +** N columns.  If both the columns= and schema= parameters are omitted, then
           36  +** the number and names of the columns is determined by the first line of
           37  +** the CSV input.
    38     38   **
    39     39   ** Some extra debugging features (used for testing virtual tables) are available
    40     40   ** if this module is compiled with -DSQLITE_TEST.
    41     41   */
    42     42   #include <sqlite3ext.h>
    43     43   SQLITE_EXTENSION_INIT1
    44     44   #include <string.h>
................................................................................
   432    432      || (z[0]=='0' && z[1]==0)
   433    433     ){
   434    434       return 0;
   435    435     }
   436    436     return -1;
   437    437   }
   438    438   
          439  +/* Check to see if the string is of the form:  "TAG = BOOLEAN" or just "TAG".
          440  +** If it is, set *pValue to be the value of the boolean ("true" if there is
          441  +** not "= BOOLEAN" component) and return non-zero.  If the input string
          442  +** does not begin with TAG, return zero.
          443  +*/
          444  +static int csv_boolean_parameter(
          445  +  const char *zTag,       /* Tag we are looking for */
          446  +  int nTag,               /* Size of the tag in bytes */
          447  +  const char *z,          /* Input parameter */
          448  +  int *pValue             /* Write boolean value here */
          449  +){
          450  +  int b;
          451  +  z = csv_skip_whitespace(z);
          452  +  if( strncmp(zTag, z, nTag)!=0 ) return 0;
          453  +  z = csv_skip_whitespace(z + nTag);
          454  +  if( z[0]==0 ){
          455  +    *pValue = 1;
          456  +    return 1;
          457  +  }
          458  +  if( z[0]!='=' ) return 0;
          459  +  z = csv_skip_whitespace(z+1);
          460  +  b = csv_boolean(z);
          461  +  if( b>=0 ){
          462  +    *pValue = b;
          463  +    return 1;
          464  +  }
          465  +  return 0;
          466  +}
   439    467   
   440    468   /*
   441    469   ** Parameters:
   442    470   **    filename=FILENAME          Name of file containing CSV content
   443    471   **    data=TEXT                  Direct CSV content.
   444    472   **    schema=SCHEMA              Alternative CSV schema.
   445    473   **    header=YES|NO              First row of CSV defines the names of
................................................................................
   465    493     CsvTable *pNew = 0;        /* The CsvTable object to construct */
   466    494     int bHeader = -1;          /* header= flags.  -1 means not seen yet */
   467    495     int rc = SQLITE_OK;        /* Result code from this routine */
   468    496     int i, j;                  /* Loop counters */
   469    497   #ifdef SQLITE_TEST
   470    498     int tstFlags = 0;          /* Value for testflags=N parameter */
   471    499   #endif
          500  +  int b;                     /* Value of a boolean parameter */
   472    501     int nCol = -99;            /* Value of the columns= parameter */
   473    502     CsvReader sRdr;            /* A CSV file reader used to store an error
   474    503                                ** message and/or to count the number of columns */
   475    504     static const char *azParam[] = {
   476    505        "filename", "data", "schema", 
   477    506     };
   478    507     char *azPValue[3];         /* Parameter values */
................................................................................
   489    518       const char *zValue;
   490    519       for(j=0; j<sizeof(azParam)/sizeof(azParam[0]); j++){
   491    520         if( csv_string_parameter(&sRdr, azParam[j], z, &azPValue[j]) ) break;
   492    521       }
   493    522       if( j<sizeof(azParam)/sizeof(azParam[0]) ){
   494    523         if( sRdr.zErr[0] ) goto csvtab_connect_error;
   495    524       }else
   496         -    if( (zValue = csv_parameter("header",6,z))!=0 ){
   497         -      int x;
          525  +    if( csv_boolean_parameter("header",6,z,&b) ){
   498    526         if( bHeader>=0 ){
   499    527           csv_errmsg(&sRdr, "more than one 'header' parameter");
   500    528           goto csvtab_connect_error;
   501    529         }
   502         -      x = csv_boolean(zValue);
   503         -      if( x==1 ){
   504         -        bHeader = 1;
   505         -      }else if( x==0 ){
   506         -        bHeader = 0;
   507         -      }else{
   508         -        csv_errmsg(&sRdr, "unrecognized argument to 'header': %s", zValue);
   509         -        goto csvtab_connect_error;
   510         -      }
          530  +      bHeader = b;
   511    531       }else
   512    532   #ifdef SQLITE_TEST
   513    533       if( (zValue = csv_parameter("testflags",9,z))!=0 ){
   514    534         tstFlags = (unsigned int)atoi(zValue);
   515    535       }else
   516    536   #endif
   517    537       if( (zValue = csv_parameter("columns",7,z))!=0 ){
   518    538         if( nCol>0 ){
   519    539           csv_errmsg(&sRdr, "more than one 'columns' parameter");
   520    540           goto csvtab_connect_error;
   521    541         }
   522    542         nCol = atoi(zValue);
   523    543         if( nCol<=0 ){
   524         -        csv_errmsg(&sRdr, "must have at least one column");
          544  +        csv_errmsg(&sRdr, "column= value must be positive");
   525    545           goto csvtab_connect_error;
   526    546         }
   527    547       }else
   528    548       {
   529         -      csv_errmsg(&sRdr, "unrecognized parameter '%s'", z);
          549  +      csv_errmsg(&sRdr, "bad parameter: '%s'", z);
   530    550         goto csvtab_connect_error;
   531    551       }
   532    552     }
   533    553     if( (CSV_FILENAME==0)==(CSV_DATA==0) ){
   534         -    csv_errmsg(&sRdr, "must either filename= or data= but not both");
          554  +    csv_errmsg(&sRdr, "must specify either filename= or data= but not both");
   535    555       goto csvtab_connect_error;
   536    556     }
   537         -  if( nCol<=0 && csv_reader_open(&sRdr, CSV_FILENAME, CSV_DATA) ){
          557  +
          558  +  if( (nCol<=0 || bHeader==1)
          559  +   && csv_reader_open(&sRdr, CSV_FILENAME, CSV_DATA)
          560  +  ){
   538    561       goto csvtab_connect_error;
   539    562     }
   540    563     pNew = sqlite3_malloc( sizeof(*pNew) );
   541    564     *ppVtab = (sqlite3_vtab*)pNew;
   542    565     if( pNew==0 ) goto csvtab_connect_oom;
   543    566     memset(pNew, 0, sizeof(*pNew));
   544         -  if( nCol>0 ){
          567  +  if( CSV_SCHEMA==0 ){
          568  +    sqlite3_str *pStr = sqlite3_str_new(0);
          569  +    char *zSep = "";
          570  +    int iCol = 0;
          571  +    sqlite3_str_appendf(pStr, "CREATE TABLE x(");
          572  +    if( nCol<0 && bHeader<1 ){
          573  +      nCol = 0;
          574  +      do{
          575  +        csv_read_one_field(&sRdr);
          576  +        nCol++;
          577  +      }while( sRdr.cTerm==',' );
          578  +    }
          579  +    if( nCol>0 && bHeader<1 ){
          580  +      for(iCol=0; iCol<nCol; iCol++){
          581  +        sqlite3_str_appendf(pStr, "%sc%d TEXT", zSep, iCol);
          582  +        zSep = ",";
          583  +      }
          584  +    }else{
          585  +      do{
          586  +        char *z = csv_read_one_field(&sRdr);
          587  +        if( (nCol>0 && iCol<nCol) || (nCol<0 && bHeader) ){
          588  +          sqlite3_str_appendf(pStr,"%s\"%w\" TEXT", zSep, z);
          589  +          zSep = ",";
          590  +          iCol++;
          591  +        }
          592  +      }while( sRdr.cTerm==',' );
          593  +      if( nCol<0 ){
          594  +        nCol = iCol;
          595  +      }else{
          596  +        while( iCol<nCol ){
          597  +          sqlite3_str_appendf(pStr,"%sc%d TEXT", zSep, ++iCol);
          598  +          zSep = ",";
          599  +        }
          600  +      }
          601  +    }
   545    602       pNew->nCol = nCol;
   546         -  }else{
          603  +    sqlite3_str_appendf(pStr, ")");
          604  +    CSV_SCHEMA = sqlite3_str_finish(pStr);
          605  +    if( CSV_SCHEMA==0 ) goto csvtab_connect_oom;
          606  +  }else if( nCol<0 ){
   547    607       do{
   548    608         csv_read_one_field(&sRdr);
   549    609         pNew->nCol++;
   550    610       }while( sRdr.cTerm==',' );
          611  +  }else{
          612  +    pNew->nCol = nCol;
   551    613     }
   552    614     pNew->zFilename = CSV_FILENAME;  CSV_FILENAME = 0;
   553    615     pNew->zData = CSV_DATA;          CSV_DATA = 0;
   554    616   #ifdef SQLITE_TEST
   555    617     pNew->tstFlags = tstFlags;
   556    618   #endif
   557         -  pNew->iStart = bHeader==1 ? ftell(sRdr.in) : 0;
   558         -  csv_reader_reset(&sRdr);
   559         -  if( CSV_SCHEMA==0 ){
   560         -    char *zSep = "";
   561         -    CSV_SCHEMA = sqlite3_mprintf("CREATE TABLE x(");
   562         -    if( CSV_SCHEMA==0 ) goto csvtab_connect_oom;
   563         -    for(i=0; i<pNew->nCol; i++){
   564         -      CSV_SCHEMA = sqlite3_mprintf("%z%sc%d TEXT",CSV_SCHEMA, zSep, i);
   565         -      zSep = ",";
   566         -    }
   567         -    CSV_SCHEMA = sqlite3_mprintf("%z);", CSV_SCHEMA);
          619  +  if( bHeader!=1 ){
          620  +    pNew->iStart = 0;
          621  +  }else if( pNew->zData ){
          622  +    pNew->iStart = (int)sRdr.iIn;
          623  +  }else{
          624  +    pNew->iStart = ftell(sRdr.in);
   568    625     }
          626  +  csv_reader_reset(&sRdr);
   569    627     rc = sqlite3_declare_vtab(db, CSV_SCHEMA);
   570         -  if( rc ) goto csvtab_connect_error;
          628  +  if( rc ){
          629  +    csv_errmsg(&sRdr, "bad schema: '%s' - %s", CSV_SCHEMA, sqlite3_errmsg(db));
          630  +    goto csvtab_connect_error;
          631  +  }
   571    632     for(i=0; i<sizeof(azPValue)/sizeof(azPValue[0]); i++){
   572    633       sqlite3_free(azPValue[i]);
   573    634     }
   574    635     return SQLITE_OK;
   575    636   
   576    637   csvtab_connect_oom:
   577    638     rc = SQLITE_NOMEM;

Changes to ext/misc/explain.c.

    14     14   ** EXPLAIN output from an SQL statement.
    15     15   **
    16     16   ** Usage example:
    17     17   **
    18     18   **     .load ./explain
    19     19   **     SELECT p2 FROM explain('SELECT * FROM sqlite_master')
    20     20   **      WHERE opcode='OpenRead';
           21  +**
           22  +** This module was originally written to help simplify SQLite testing,
           23  +** by providing an easier means of verifying certain patterns in the
           24  +** generated bytecode.
    21     25   */
    22     26   #if !defined(SQLITEINT_H)
    23     27   #include "sqlite3ext.h"
    24     28   #endif
    25     29   SQLITE_EXTENSION_INIT1
    26     30   #include <assert.h>
    27     31   #include <string.h>
................................................................................
   228    232   ** a query plan for each invocation and compute an estimated cost for that
   229    233   ** plan.
   230    234   */
   231    235   static int explainBestIndex(
   232    236     sqlite3_vtab *tab,
   233    237     sqlite3_index_info *pIdxInfo
   234    238   ){
   235         -  int i;
          239  +  int i;                  /* Loop counter */
          240  +  int idx = -1;           /* Index of a usable == constraint against SQL */
          241  +  int unusable = 0;       /* True if there are unusable constraints on SQL */
   236    242   
   237         -  pIdxInfo->estimatedCost = (double)1000000;
   238    243     pIdxInfo->estimatedRows = 500;
   239    244     for(i=0; i<pIdxInfo->nConstraint; i++){
   240    245       struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[i];
   241         -    if( p->usable
   242         -     && p->iColumn==EXPLN_COLUMN_SQL
   243         -     && p->op==SQLITE_INDEX_CONSTRAINT_EQ
   244         -    ){
   245         -      pIdxInfo->estimatedCost = 10.0;
   246         -      pIdxInfo->idxNum = 1;
   247         -      pIdxInfo->aConstraintUsage[i].argvIndex = 1;
   248         -      pIdxInfo->aConstraintUsage[i].omit = 1;
   249         -      break;
          246  +    if( p->iColumn!=EXPLN_COLUMN_SQL ) continue;
          247  +    if( !p->usable ){
          248  +      unusable = 1;
          249  +    }else if( p->op==SQLITE_INDEX_CONSTRAINT_EQ ){
          250  +      idx = i;
   250    251       }
   251    252     }
          253  +  if( idx>=0 ){
          254  +    /* There exists a usable == constraint against the SQL column */
          255  +    pIdxInfo->estimatedCost = 10.0;
          256  +    pIdxInfo->idxNum = 1;
          257  +    pIdxInfo->aConstraintUsage[idx].argvIndex = 1;
          258  +    pIdxInfo->aConstraintUsage[idx].omit = 1;
          259  +  }else if( unusable ){
          260  +    /* There are unusable constraints against the SQL column.  Do not allow
          261  +    ** this plan to continue forward. */
          262  +    return SQLITE_CONSTRAINT;
          263  +  }
   252    264     return SQLITE_OK;
   253    265   }
   254    266   
   255    267   /*
   256    268   ** This following structure defines all the methods for the 
   257    269   ** explain virtual table.
   258    270   */

Changes to ext/misc/fileio.c.

   102    102   #  define mkdir(path,mode) _mkdir(path)
   103    103   #  define lstat(path,buf) stat(path,buf)
   104    104   #endif
   105    105   #include <time.h>
   106    106   #include <errno.h>
   107    107   
   108    108   
          109  +/*
          110  +** Structure of the fsdir() table-valued function
          111  +*/
          112  +                 /*    0    1    2     3    4           5             */
   109    113   #define FSDIR_SCHEMA "(name,mode,mtime,data,path HIDDEN,dir HIDDEN)"
          114  +#define FSDIR_COLUMN_NAME     0     /* Name of the file */
          115  +#define FSDIR_COLUMN_MODE     1     /* Access mode */
          116  +#define FSDIR_COLUMN_MTIME    2     /* Last modification time */
          117  +#define FSDIR_COLUMN_DATA     3     /* File content */
          118  +#define FSDIR_COLUMN_PATH     4     /* Path to top of search */
          119  +#define FSDIR_COLUMN_DIR      5     /* Path is relative to this directory */
          120  +
   110    121   
   111    122   /*
   112    123   ** Set the result stored by context ctx to a blob containing the 
   113    124   ** contents of file zName.
   114    125   */
   115    126   static void readFileContents(sqlite3_context *ctx, const char *zName){
   116    127     FILE *in;
................................................................................
   691    702   static int fsdirColumn(
   692    703     sqlite3_vtab_cursor *cur,   /* The cursor */
   693    704     sqlite3_context *ctx,       /* First argument to sqlite3_result_...() */
   694    705     int i                       /* Which column to return */
   695    706   ){
   696    707     fsdir_cursor *pCur = (fsdir_cursor*)cur;
   697    708     switch( i ){
   698         -    case 0: { /* name */
          709  +    case FSDIR_COLUMN_NAME: {
   699    710         sqlite3_result_text(ctx, &pCur->zPath[pCur->nBase], -1, SQLITE_TRANSIENT);
   700    711         break;
   701    712       }
   702    713   
   703         -    case 1: /* mode */
          714  +    case FSDIR_COLUMN_MODE:
   704    715         sqlite3_result_int64(ctx, pCur->sStat.st_mode);
   705    716         break;
   706    717   
   707         -    case 2: /* mtime */
          718  +    case FSDIR_COLUMN_MTIME:
   708    719         sqlite3_result_int64(ctx, pCur->sStat.st_mtime);
   709    720         break;
   710    721   
   711         -    case 3: { /* data */
          722  +    case FSDIR_COLUMN_DATA: {
   712    723         mode_t m = pCur->sStat.st_mode;
   713    724         if( S_ISDIR(m) ){
   714    725           sqlite3_result_null(ctx);
   715    726   #if !defined(_WIN32) && !defined(WIN32)
   716    727         }else if( S_ISLNK(m) ){
   717    728           char aStatic[64];
   718    729           char *aBuf = aStatic;
................................................................................
   734    745           sqlite3_result_text(ctx, aBuf, n, SQLITE_TRANSIENT);
   735    746           if( aBuf!=aStatic ) sqlite3_free(aBuf);
   736    747   #endif
   737    748         }else{
   738    749           readFileContents(ctx, pCur->zPath);
   739    750         }
   740    751       }
          752  +    case FSDIR_COLUMN_PATH:
          753  +    default: {
          754  +      /* The FSDIR_COLUMN_PATH and FSDIR_COLUMN_DIR are input parameters.
          755  +      ** always return their values as NULL */
          756  +      break;
          757  +    }
   741    758     }
   742    759     return SQLITE_OK;
   743    760   }
   744    761   
   745    762   /*
   746    763   ** Return the rowid for the current row. In this implementation, the
   747    764   ** first row returned is assigned rowid value 1, and each subsequent
................................................................................
   760    777   static int fsdirEof(sqlite3_vtab_cursor *cur){
   761    778     fsdir_cursor *pCur = (fsdir_cursor*)cur;
   762    779     return (pCur->zPath==0);
   763    780   }
   764    781   
   765    782   /*
   766    783   ** xFilter callback.
          784  +**
          785  +** idxNum==1   PATH parameter only
          786  +** idxNum==2   Both PATH and DIR supplied
   767    787   */
   768    788   static int fsdirFilter(
   769    789     sqlite3_vtab_cursor *cur, 
   770    790     int idxNum, const char *idxStr,
   771    791     int argc, sqlite3_value **argv
   772    792   ){
   773    793     const char *zDir = 0;
................................................................................
   812    832   ** that uses the generate_series virtual table.  This routine needs to create
   813    833   ** a query plan for each invocation and compute an estimated cost for that
   814    834   ** plan.
   815    835   **
   816    836   ** In this implementation idxNum is used to represent the
   817    837   ** query plan.  idxStr is unused.
   818    838   **
   819         -** The query plan is represented by bits in idxNum:
          839  +** The query plan is represented by values of idxNum:
   820    840   **
   821         -**  (1)  start = $value  -- constraint exists
   822         -**  (2)  stop = $value   -- constraint exists
   823         -**  (4)  step = $value   -- constraint exists
   824         -**  (8)  output in descending order
          841  +**  (1)  The path value is supplied by argv[0]
          842  +**  (2)  Path is in argv[0] and dir is in argv[1]
   825    843   */
   826    844   static int fsdirBestIndex(
   827    845     sqlite3_vtab *tab,
   828    846     sqlite3_index_info *pIdxInfo
   829    847   ){
   830    848     int i;                 /* Loop over constraints */
   831         -  int idx4 = -1;
   832         -  int idx5 = -1;
          849  +  int idxPath = -1;      /* Index in pIdxInfo->aConstraint of PATH= */
          850  +  int idxDir = -1;       /* Index in pIdxInfo->aConstraint of DIR= */
          851  +  int seenPath = 0;      /* True if an unusable PATH= constraint is seen */
          852  +  int seenDir = 0;       /* True if an unusable DIR= constraint is seen */
   833    853     const struct sqlite3_index_constraint *pConstraint;
   834    854   
   835    855     (void)tab;
   836    856     pConstraint = pIdxInfo->aConstraint;
   837    857     for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
   838         -    if( pConstraint->usable==0 ) continue;
   839    858       if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
   840         -    if( pConstraint->iColumn==4 ) idx4 = i;
   841         -    if( pConstraint->iColumn==5 ) idx5 = i;
          859  +    switch( pConstraint->iColumn ){
          860  +      case FSDIR_COLUMN_PATH: {
          861  +        if( pConstraint->usable ){
          862  +          idxPath = i;
          863  +          seenPath = 0;
          864  +        }else if( idxPath<0 ){
          865  +          seenPath = 1;
          866  +        }
          867  +        break;
          868  +      }
          869  +      case FSDIR_COLUMN_DIR: {
          870  +        if( pConstraint->usable ){
          871  +          idxDir = i;
          872  +          seenDir = 0;
          873  +        }else if( idxDir<0 ){
          874  +          seenDir = 1;
          875  +        }
          876  +        break;
          877  +      }
          878  +    } 
          879  +  }
          880  +  if( seenPath || seenDir ){
          881  +    /* If input parameters are unusable, disallow this plan */
          882  +    return SQLITE_CONSTRAINT;
   842    883     }
   843    884   
   844         -  if( idx4<0 ){
          885  +  if( idxPath<0 ){
   845    886       pIdxInfo->idxNum = 0;
   846         -    pIdxInfo->estimatedCost = (double)(((sqlite3_int64)1) << 50);
          887  +    /* The pIdxInfo->estimatedCost should have been initialized to a huge
          888  +    ** number.  Leave it unchanged. */
          889  +    pIdxInfo->estimatedRows = 0x7fffffff;
   847    890     }else{
   848         -    pIdxInfo->aConstraintUsage[idx4].omit = 1;
   849         -    pIdxInfo->aConstraintUsage[idx4].argvIndex = 1;
   850         -    if( idx5>=0 ){
   851         -      pIdxInfo->aConstraintUsage[idx5].omit = 1;
   852         -      pIdxInfo->aConstraintUsage[idx5].argvIndex = 2;
          891  +    pIdxInfo->aConstraintUsage[idxPath].omit = 1;
          892  +    pIdxInfo->aConstraintUsage[idxPath].argvIndex = 1;
          893  +    if( idxDir>=0 ){
          894  +      pIdxInfo->aConstraintUsage[idxDir].omit = 1;
          895  +      pIdxInfo->aConstraintUsage[idxDir].argvIndex = 2;
   853    896         pIdxInfo->idxNum = 2;
   854    897         pIdxInfo->estimatedCost = 10.0;
   855    898       }else{
   856    899         pIdxInfo->idxNum = 1;
   857    900         pIdxInfo->estimatedCost = 100.0;
   858    901       }
   859    902     }

Changes to ext/misc/json1.c.

  1990   1990   #define JEACH_VALUE   1
  1991   1991   #define JEACH_TYPE    2
  1992   1992   #define JEACH_ATOM    3
  1993   1993   #define JEACH_ID      4
  1994   1994   #define JEACH_PARENT  5
  1995   1995   #define JEACH_FULLKEY 6
  1996   1996   #define JEACH_PATH    7
         1997  +/* The xBestIndex method assumes that the JSON and ROOT columns are
         1998  +** the last two columns in the table.  Should this ever changes, be
         1999  +** sure to update the xBestIndex method. */
  1997   2000   #define JEACH_JSON    8
  1998   2001   #define JEACH_ROOT    9
  1999   2002   
  2000   2003     UNUSED_PARAM(pzErr);
  2001   2004     UNUSED_PARAM(argv);
  2002   2005     UNUSED_PARAM(argc);
  2003   2006     UNUSED_PARAM(pAux);
................................................................................
  2247   2250   ** 1 if the constraint is found, 3 if the constraint and zRoot are found,
  2248   2251   ** and 0 otherwise.
  2249   2252   */
  2250   2253   static int jsonEachBestIndex(
  2251   2254     sqlite3_vtab *tab,
  2252   2255     sqlite3_index_info *pIdxInfo
  2253   2256   ){
  2254         -  int i;
  2255         -  int jsonIdx = -1;
  2256         -  int rootIdx = -1;
         2257  +  int i;                     /* Loop counter or computed array index */
         2258  +  int aIdx[2];               /* Index of constraints for JSON and ROOT */
         2259  +  int unusableMask = 0;      /* Mask of unusable JSON and ROOT constraints */
         2260  +  int idxMask = 0;           /* Mask of usable == constraints JSON and ROOT */
  2257   2261     const struct sqlite3_index_constraint *pConstraint;
  2258   2262   
         2263  +  /* This implementation assumes that JSON and ROOT are the last two
         2264  +  ** columns in the table */
         2265  +  assert( JEACH_ROOT == JEACH_JSON+1 );
  2259   2266     UNUSED_PARAM(tab);
         2267  +  aIdx[0] = aIdx[1] = -1;
  2260   2268     pConstraint = pIdxInfo->aConstraint;
  2261   2269     for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
  2262         -    if( pConstraint->usable==0 ) continue;
  2263         -    if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
  2264         -    switch( pConstraint->iColumn ){
  2265         -      case JEACH_JSON:   jsonIdx = i;    break;
  2266         -      case JEACH_ROOT:   rootIdx = i;    break;
  2267         -      default:           /* no-op */     break;
         2270  +    int iCol;
         2271  +    int iMask;
         2272  +    if( pConstraint->iColumn < JEACH_JSON ) continue;
         2273  +    iCol = pConstraint->iColumn - JEACH_JSON;
         2274  +    assert( iCol==0 || iCol==1 );
         2275  +    iMask = 1 << iCol;
         2276  +    if( pConstraint->usable==0 ){
         2277  +      unusableMask |= iMask;
         2278  +    }else if( pConstraint->op==SQLITE_INDEX_CONSTRAINT_EQ ){
         2279  +      aIdx[iCol] = i;
         2280  +      idxMask |= iMask;
  2268   2281       }
  2269   2282     }
  2270         -  if( jsonIdx<0 ){
         2283  +  if( (unusableMask & ~idxMask)!=0 ){
         2284  +    /* If there are any unusable constraints on JSON or ROOT, then reject
         2285  +    ** this entire plan */
         2286  +    return SQLITE_CONSTRAINT;
         2287  +  }
         2288  +  if( aIdx[0]<0 ){
         2289  +    /* No JSON input.  Leave estimatedCost at the huge value that it was
         2290  +    ** initialized to to discourage the query planner from selecting this
         2291  +    ** plan. */
  2271   2292       pIdxInfo->idxNum = 0;
  2272         -    pIdxInfo->estimatedCost = 1e99;
  2273   2293     }else{
  2274   2294       pIdxInfo->estimatedCost = 1.0;
  2275         -    pIdxInfo->aConstraintUsage[jsonIdx].argvIndex = 1;
  2276         -    pIdxInfo->aConstraintUsage[jsonIdx].omit = 1;
  2277         -    if( rootIdx<0 ){
  2278         -      pIdxInfo->idxNum = 1;
         2295  +    i = aIdx[0];
         2296  +    pIdxInfo->aConstraintUsage[i].argvIndex = 1;
         2297  +    pIdxInfo->aConstraintUsage[i].omit = 1;
         2298  +    if( aIdx[1]<0 ){
         2299  +      pIdxInfo->idxNum = 1;  /* Only JSON supplied.  Plan 1 */
  2279   2300       }else{
  2280         -      pIdxInfo->aConstraintUsage[rootIdx].argvIndex = 2;
  2281         -      pIdxInfo->aConstraintUsage[rootIdx].omit = 1;
  2282         -      pIdxInfo->idxNum = 3;
         2301  +      i = aIdx[1];
         2302  +      pIdxInfo->aConstraintUsage[i].argvIndex = 2;
         2303  +      pIdxInfo->aConstraintUsage[i].omit = 1;
         2304  +      pIdxInfo->idxNum = 3;  /* Both JSON and ROOT are supplied.  Plan 3 */
  2283   2305       }
  2284   2306     }
  2285   2307     return SQLITE_OK;
  2286   2308   }
  2287   2309   
  2288   2310   /* Start a search on a new JSON string */
  2289   2311   static int jsonEachFilter(

Changes to ext/misc/series.c.

   309    309   **  (4)  step = $value   -- constraint exists
   310    310   **  (8)  output in descending order
   311    311   */
   312    312   static int seriesBestIndex(
   313    313     sqlite3_vtab *tab,
   314    314     sqlite3_index_info *pIdxInfo
   315    315   ){
   316         -  int i;                 /* Loop over constraints */
          316  +  int i, j;              /* Loop over constraints */
   317    317     int idxNum = 0;        /* The query plan bitmask */
   318         -  int startIdx = -1;     /* Index of the start= constraint, or -1 if none */
   319         -  int stopIdx = -1;      /* Index of the stop= constraint, or -1 if none */
   320         -  int stepIdx = -1;      /* Index of the step= constraint, or -1 if none */
          318  +  int unusableMask = 0;  /* Mask of unusable constraints */
   321    319     int nArg = 0;          /* Number of arguments that seriesFilter() expects */
          320  +  int aIdx[3];           /* Constraints on start, stop, and step */
          321  +  const struct sqlite3_index_constraint *pConstraint;
   322    322   
   323         -  const struct sqlite3_index_constraint *pConstraint;
          323  +  /* This implementation assumes that the start, stop, and step columns
          324  +  ** are the last three columns in the virtual table. */
          325  +  assert( SERIES_COLUMN_STOP == SERIES_COLUMN_START+1 );
          326  +  assert( SERIES_COLUMN_STEP == SERIES_COLUMN_START+2 );
          327  +  aIdx[0] = aIdx[1] = aIdx[2] = -1;
   324    328     pConstraint = pIdxInfo->aConstraint;
   325    329     for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
   326         -    if( pConstraint->usable==0 ) continue;
   327         -    if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
   328         -    switch( pConstraint->iColumn ){
   329         -      case SERIES_COLUMN_START:
   330         -        startIdx = i;
   331         -        idxNum |= 1;
   332         -        break;
   333         -      case SERIES_COLUMN_STOP:
   334         -        stopIdx = i;
   335         -        idxNum |= 2;
   336         -        break;
   337         -      case SERIES_COLUMN_STEP:
   338         -        stepIdx = i;
   339         -        idxNum |= 4;
   340         -        break;
          330  +    int iCol;    /* 0 for start, 1 for stop, 2 for step */
          331  +    int iMask;   /* bitmask for those column */
          332  +    if( pConstraint->iColumn<SERIES_COLUMN_START ) continue;
          333  +    iCol = pConstraint->iColumn - SERIES_COLUMN_START;
          334  +    assert( iCol>=0 && iCol<=2 );
          335  +    iMask = 1 << iCol;
          336  +    if( pConstraint->usable==0 ){
          337  +      unusableMask |=  iMask;
          338  +      continue;
          339  +    }else if( pConstraint->op==SQLITE_INDEX_CONSTRAINT_EQ ){
          340  +      idxNum |= iMask;
          341  +      aIdx[iCol] = i;
          342  +    }
          343  +  }
          344  +  for(i=0; i<3; i++){
          345  +    if( (j = aIdx[i])>=0 ){
          346  +      pIdxInfo->aConstraintUsage[j].argvIndex = ++nArg;
          347  +      pIdxInfo->aConstraintUsage[j].omit = !SQLITE_SERIES_CONSTRAINT_VERIFY;
   341    348       }
   342    349     }
   343         -  if( startIdx>=0 ){
   344         -    pIdxInfo->aConstraintUsage[startIdx].argvIndex = ++nArg;
   345         -    pIdxInfo->aConstraintUsage[startIdx].omit= !SQLITE_SERIES_CONSTRAINT_VERIFY;
   346         -  }
   347         -  if( stopIdx>=0 ){
   348         -    pIdxInfo->aConstraintUsage[stopIdx].argvIndex = ++nArg;
   349         -    pIdxInfo->aConstraintUsage[stopIdx].omit = !SQLITE_SERIES_CONSTRAINT_VERIFY;
   350         -  }
   351         -  if( stepIdx>=0 ){
   352         -    pIdxInfo->aConstraintUsage[stepIdx].argvIndex = ++nArg;
   353         -    pIdxInfo->aConstraintUsage[stepIdx].omit = !SQLITE_SERIES_CONSTRAINT_VERIFY;
          350  +  if( (unusableMask & ~idxNum)!=0 ){
          351  +    /* The start, stop, and step columns are inputs.  Therefore if there
          352  +    ** are unusable constraints on any of start, stop, or step then
          353  +    ** this plan is unusable */
          354  +    return SQLITE_CONSTRAINT;
   354    355     }
   355    356     if( (idxNum & 3)==3 ){
   356    357       /* Both start= and stop= boundaries are available.  This is the 
   357    358       ** the preferred case */
   358    359       pIdxInfo->estimatedCost = (double)(2 - ((idxNum&4)!=0));
   359    360       pIdxInfo->estimatedRows = 1000;
   360    361       if( pIdxInfo->nOrderBy==1 ){
................................................................................
   361    362         if( pIdxInfo->aOrderBy[0].desc ) idxNum |= 8;
   362    363         pIdxInfo->orderByConsumed = 1;
   363    364       }
   364    365     }else{
   365    366       /* If either boundary is missing, we have to generate a huge span
   366    367       ** of numbers.  Make this case very expensive so that the query
   367    368       ** planner will work hard to avoid it. */
   368         -    pIdxInfo->estimatedCost = (double)2147483647;
   369    369       pIdxInfo->estimatedRows = 2147483647;
   370    370     }
   371    371     pIdxInfo->idxNum = idxNum;
   372    372     return SQLITE_OK;
   373    373   }
   374    374   
   375    375   /*

Changes to ext/misc/zipfile.c.

  1292   1292   ** xBestIndex callback.
  1293   1293   */
  1294   1294   static int zipfileBestIndex(
  1295   1295     sqlite3_vtab *tab,
  1296   1296     sqlite3_index_info *pIdxInfo
  1297   1297   ){
  1298   1298     int i;
         1299  +  int idx = -1;
         1300  +  int unusable = 0;
  1299   1301   
  1300   1302     for(i=0; i<pIdxInfo->nConstraint; i++){
  1301   1303       const struct sqlite3_index_constraint *pCons = &pIdxInfo->aConstraint[i];
  1302         -    if( pCons->usable==0 ) continue;
  1303         -    if( pCons->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
  1304   1304       if( pCons->iColumn!=ZIPFILE_F_COLUMN_IDX ) continue;
  1305         -    break;
         1305  +    if( pCons->usable==0 ){
         1306  +      unusable = 1;
         1307  +    }else if( pCons->op==SQLITE_INDEX_CONSTRAINT_EQ ){
         1308  +      idx = i;
         1309  +    }
  1306   1310     }
  1307         -
  1308         -  if( i<pIdxInfo->nConstraint ){
  1309         -    pIdxInfo->aConstraintUsage[i].argvIndex = 1;
  1310         -    pIdxInfo->aConstraintUsage[i].omit = 1;
         1311  +  if( idx>=0 ){
         1312  +    pIdxInfo->aConstraintUsage[idx].argvIndex = 1;
         1313  +    pIdxInfo->aConstraintUsage[idx].omit = 1;
  1311   1314       pIdxInfo->estimatedCost = 1000.0;
  1312   1315       pIdxInfo->idxNum = 1;
  1313         -  }else{
  1314         -    pIdxInfo->estimatedCost = (double)(((sqlite3_int64)1) << 50);
  1315         -    pIdxInfo->idxNum = 0;
         1316  +  }else if( unusable ){
         1317  +    return SQLITE_CONSTRAINT;
  1316   1318     }
  1317         -
  1318   1319     return SQLITE_OK;
  1319   1320   }
  1320   1321   
  1321   1322   static ZipfileEntry *zipfileNewEntry(const char *zPath){
  1322   1323     ZipfileEntry *pNew;
  1323   1324     pNew = sqlite3_malloc(sizeof(ZipfileEntry));
  1324   1325     if( pNew ){

Changes to ext/rtree/geopoly.c.

   523    523     int argc,
   524    524     sqlite3_value **argv
   525    525   ){
   526    526     GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
   527    527     if( p ){
   528    528       if( geopolyArea(p)<0.0 ){
   529    529         int ii, jj;
   530         -      for(ii=2, jj=p->nVertex*2 - 4; ii<jj; ii+=2, jj-=2){
          530  +      for(ii=2, jj=p->nVertex*2 - 2; ii<jj; ii+=2, jj-=2){
   531    531           GeoCoord t = p->a[ii];
   532    532           p->a[ii] = p->a[jj];
   533    533           p->a[jj] = t;
   534    534           t = p->a[ii+1];
   535    535           p->a[ii+1] = p->a[jj+1];
   536    536           p->a[jj+1] = t;
   537    537         }

Changes to main.mk.

   395    395     $(TOP)/src/btree.c \
   396    396     $(TOP)/src/build.c \
   397    397     $(TOP)/src/date.c \
   398    398     $(TOP)/src/dbpage.c \
   399    399     $(TOP)/src/dbstat.c \
   400    400     $(TOP)/src/expr.c \
   401    401     $(TOP)/src/func.c \
          402  +  $(TOP)/src/global.c \
   402    403     $(TOP)/src/insert.c \
   403    404     $(TOP)/src/wal.c \
   404    405     $(TOP)/src/main.c \
   405    406     $(TOP)/src/mem5.c \
   406    407     $(TOP)/src/os.c \
   407    408     $(TOP)/src/os_unix.c \
   408    409     $(TOP)/src/os_win.c \

Changes to src/alter.c.

   663    663     }
   664    664   }
   665    665   #else
   666    666   # define renameTokenCheckAll(x,y)
   667    667   #endif
   668    668   
   669    669   /*
   670         -** Add a new RenameToken object mapping parse tree element pPtr into
   671         -** token *pToken to the Parse object currently under construction.
          670  +** Remember that the parser tree element pPtr was created using
          671  +** the token pToken.
   672    672   **
   673         -** Return a copy of pPtr.
          673  +** In other words, construct a new RenameToken object and add it
          674  +** to the list of RenameToken objects currently being built up
          675  +** in pParse->pRename.
          676  +**
          677  +** The pPtr argument is returned so that this routine can be used
          678  +** with tail recursion in tokenExpr() routine, for a small performance
          679  +** improvement.
   674    680   */
   675    681   void *sqlite3RenameTokenMap(Parse *pParse, void *pPtr, Token *pToken){
   676    682     RenameToken *pNew;
   677    683     assert( pPtr || pParse->db->mallocFailed );
   678    684     renameTokenCheckAll(pParse, pPtr);
   679    685     pNew = sqlite3DbMallocZero(pParse->db, sizeof(RenameToken));
   680    686     if( pNew ){
................................................................................
  1178   1184   **   8. bTemp:    True if zSql comes from temp schema
  1179   1185   **
  1180   1186   ** Do a column rename operation on the CREATE statement given in zSql.
  1181   1187   ** The iCol-th column (left-most is 0) of table zTable is renamed from zCol
  1182   1188   ** into zNew.  The name should be quoted if bQuote is true.
  1183   1189   **
  1184   1190   ** This function is used internally by the ALTER TABLE RENAME COLUMN command.
  1185         -** Though accessible to application code, it is not intended for use by
  1186         -** applications.  The existance of this function, and the way it works,
  1187         -** is subject to change without notice.
  1188         -**
  1189         -** If any of the parameters are out-of-bounds, then simply return NULL.
  1190         -** An out-of-bounds parameter can only occur when the application calls
  1191         -** this function directly.  The parameters will always be well-formed when
  1192         -** this routine is invoked by the bytecode for a legitimate ALTER TABLE
  1193         -** statement.
         1191  +** It is only accessible to SQL created using sqlite3NestedParse().  It is
         1192  +** not reachable from ordinary SQL passed into sqlite3_prepare().
  1194   1193   */
  1195   1194   static void renameColumnFunc(
  1196   1195     sqlite3_context *context,
  1197   1196     int NotUsed,
  1198   1197     sqlite3_value **argv
  1199   1198   ){
  1200   1199     sqlite3 *db = sqlite3_context_db_handle(context);
................................................................................
  1594   1593   }
  1595   1594   
  1596   1595   /*
  1597   1596   ** Register built-in functions used to help implement ALTER TABLE
  1598   1597   */
  1599   1598   void sqlite3AlterFunctions(void){
  1600   1599     static FuncDef aAlterTableFuncs[] = {
  1601         -    FUNCTION(sqlite_rename_column,  9, 0, 0, renameColumnFunc),
  1602         -    FUNCTION(sqlite_rename_table,  7, 0, 0, renameTableFunc),
  1603         -    FUNCTION(sqlite_rename_test,  5, 0, 0, renameTableTest),
         1600  +    INTERNAL_FUNCTION(sqlite_rename_column, 9, renameColumnFunc),
         1601  +    INTERNAL_FUNCTION(sqlite_rename_table,  7, renameTableFunc),
         1602  +    INTERNAL_FUNCTION(sqlite_rename_test,   5, renameTableTest),
  1604   1603     };
  1605   1604     sqlite3InsertBuiltinFuncs(aAlterTableFuncs, ArraySize(aAlterTableFuncs));
  1606   1605   }
  1607   1606   #endif  /* SQLITE_ALTER_TABLE */

Changes to src/attach.c.

    96     96       ** reopen it as a MemDB */
    97     97       pVfs = sqlite3_vfs_find("memdb");
    98     98       if( pVfs==0 ) return;
    99     99       pNew = &db->aDb[db->init.iDb];
   100    100       if( pNew->pBt ) sqlite3BtreeClose(pNew->pBt);
   101    101       pNew->pBt = 0;
   102    102       pNew->pSchema = 0;
   103         -    rc = sqlite3BtreeOpen(pVfs, "x", db, &pNew->pBt, 0, SQLITE_OPEN_MAIN_DB);
          103  +    rc = sqlite3BtreeOpen(pVfs, "x\0", db, &pNew->pBt, 0, SQLITE_OPEN_MAIN_DB);
   104    104     }else{
   105    105       /* This is a real ATTACH
   106    106       **
   107    107       ** Check for the following errors:
   108    108       **
   109    109       **     * Too many attached databases,
   110    110       **     * Transaction currently open

Changes to src/btree.c.

  4760   4760             rc = getOverflowPage(pBt, nextPage, 0, &nextPage);
  4761   4761           }
  4762   4762           offset -= ovflSize;
  4763   4763         }else{
  4764   4764           /* Need to read this page properly. It contains some of the
  4765   4765           ** range of data that is being read (eOp==0) or written (eOp!=0).
  4766   4766           */
  4767         -#ifdef SQLITE_DIRECT_OVERFLOW_READ
  4768         -        sqlite3_file *fd;      /* File from which to do direct overflow read */
  4769         -#endif
  4770   4767           int a = amt;
  4771   4768           if( a + offset > ovflSize ){
  4772   4769             a = ovflSize - offset;
  4773   4770           }
  4774   4771   
  4775   4772   #ifdef SQLITE_DIRECT_OVERFLOW_READ
  4776   4773           /* If all the following are true:
  4777   4774           **
  4778   4775           **   1) this is a read operation, and 
  4779   4776           **   2) data is required from the start of this overflow page, and
  4780         -        **   3) there is no open write-transaction, and
         4777  +        **   3) there are no dirty pages in the page-cache
  4781   4778           **   4) the database is file-backed, and
  4782   4779           **   5) the page is not in the WAL file
  4783   4780           **   6) at least 4 bytes have already been read into the output buffer 
  4784   4781           **
  4785   4782           ** then data can be read directly from the database file into the
  4786   4783           ** output buffer, bypassing the page-cache altogether. This speeds
  4787   4784           ** up loading large records that span many overflow pages.
  4788   4785           */
  4789   4786           if( eOp==0                                             /* (1) */
  4790   4787            && offset==0                                          /* (2) */
  4791         -         && pBt->inTransaction==TRANS_READ                     /* (3) */
  4792         -         && (fd = sqlite3PagerFile(pBt->pPager))->pMethods     /* (4) */
  4793         -         && 0==sqlite3PagerUseWal(pBt->pPager, nextPage)       /* (5) */
         4788  +         && sqlite3PagerDirectReadOk(pBt->pPager, nextPage)    /* (3,4,5) */
  4794   4789            && &pBuf[-4]>=pBufStart                               /* (6) */
  4795   4790           ){
         4791  +          sqlite3_file *fd = sqlite3PagerFile(pBt->pPager);
  4796   4792             u8 aSave[4];
  4797   4793             u8 *aWrite = &pBuf[-4];
  4798   4794             assert( aWrite>=pBufStart );                         /* due to (6) */
  4799   4795             memcpy(aSave, aWrite, 4);
  4800   4796             rc = sqlite3OsRead(fd, aWrite, a+4, (i64)pBt->pageSize*(nextPage-1));
  4801   4797             nextPage = get4byte(aWrite);
  4802   4798             memcpy(aWrite, aSave, 4);

Changes to src/dbpage.c.

   115    115     ** unavailable
   116    116     */
   117    117     for(i=0; i<pIdxInfo->nConstraint; i++){
   118    118       struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[i];
   119    119       if( p->iColumn!=DBPAGE_COLUMN_SCHEMA ) continue;
   120    120       if( p->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
   121    121       if( !p->usable ){
   122         -      /* No solution.  Use the default SQLITE_BIG_DBL cost */
   123         -      pIdxInfo->estimatedRows = 0x7fffffff;
   124         -      return SQLITE_OK;
          122  +      /* No solution. */
          123  +      return SQLITE_CONSTRAINT;
   125    124       }
   126    125       iPlan = 2;
   127    126       pIdxInfo->aConstraintUsage[i].argvIndex = 1;
   128    127       pIdxInfo->aConstraintUsage[i].omit = 1;
   129    128       break;
   130    129     }
   131    130   

Changes to src/dbstat.c.

   190    190   ** operate on a different database schema, so check for it.
   191    191   **
   192    192   ** idxNum is normally 0, but will be 1 if a schema=? constraint exists.
   193    193   */
   194    194   static int statBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
   195    195     int i;
   196    196   
   197         -  pIdxInfo->estimatedCost = 1.0e6;  /* Initial cost estimate */
   198         -
   199    197     /* Look for a valid schema=? constraint.  If found, change the idxNum to
   200    198     ** 1 and request the value of that constraint be sent to xFilter.  And
   201    199     ** lower the cost estimate to encourage the constrained version to be
   202    200     ** used.
   203    201     */
   204    202     for(i=0; i<pIdxInfo->nConstraint; i++){
   205         -    if( pIdxInfo->aConstraint[i].usable==0 ) continue;
   206         -    if( pIdxInfo->aConstraint[i].op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
   207    203       if( pIdxInfo->aConstraint[i].iColumn!=10 ) continue;
          204  +    if( pIdxInfo->aConstraint[i].usable==0 ) return SQLITE_CONSTRAINT;
          205  +    if( pIdxInfo->aConstraint[i].op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
   208    206       pIdxInfo->idxNum = 1;
   209    207       pIdxInfo->estimatedCost = 1.0;
   210    208       pIdxInfo->aConstraintUsage[i].argvIndex = 1;
   211    209       pIdxInfo->aConstraintUsage[i].omit = 1;
   212    210       break;
   213    211     }
   214    212   
................................................................................
   393    391           if( nLocal<0 ) goto statPageIsCorrupt;
   394    392           pCell->nLocal = nLocal;
   395    393           assert( nPayload>=(u32)nLocal );
   396    394           assert( nLocal<=(nUsable-35) );
   397    395           if( nPayload>(u32)nLocal ){
   398    396             int j;
   399    397             int nOvfl = ((nPayload - nLocal) + nUsable-4 - 1) / (nUsable - 4);
          398  +          if( iOff+nLocal>nUsable ) goto statPageIsCorrupt;
   400    399             pCell->nLastOvfl = (nPayload-nLocal) - (nOvfl-1) * (nUsable-4);
   401    400             pCell->nOvfl = nOvfl;
   402    401             pCell->aOvfl = sqlite3_malloc64(sizeof(u32)*nOvfl);
   403    402             if( pCell->aOvfl==0 ) return SQLITE_NOMEM_BKPT;
   404    403             pCell->aOvfl[0] = sqlite3Get4byte(&aData[iOff+nLocal]);
   405    404             for(j=1; j<nOvfl; j++){
   406    405               int rc;

Changes to src/global.c.

   236    236      0,                         /* xVdbeBranch */
   237    237      0,                         /* pVbeBranchArg */
   238    238   #endif
   239    239   #ifndef SQLITE_UNTESTABLE
   240    240      0,                         /* xTestCallback */
   241    241   #endif
   242    242      0,                         /* bLocaltimeFault */
          243  +   0,                         /* bInternalFunctions */
   243    244      0x7ffffffe,                /* iOnceResetThreshold */
   244    245      SQLITE_DEFAULT_SORTERREF_SIZE   /* szSorterRef */
   245    246   };
   246    247   
   247    248   /*
   248    249   ** Hash table for global functions - functions common to all
   249    250   ** database connections.  After initialization, this table is

Changes to src/main.c.

  4078   4078         sqlite3 *db = va_arg(ap, sqlite3*);
  4079   4079         db->dbOptFlags = (u16)(va_arg(ap, int) & 0xffff);
  4080   4080         break;
  4081   4081       }
  4082   4082   
  4083   4083       /*   sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, int onoff);
  4084   4084       **
  4085         -    ** If parameter onoff is non-zero, configure the wrappers so that all
  4086         -    ** subsequent calls to localtime() and variants fail. If onoff is zero,
  4087         -    ** undo this setting.
         4085  +    ** If parameter onoff is non-zero, subsequent calls to localtime()
         4086  +    ** and its variants fail. If onoff is zero, undo this setting.
  4088   4087       */
  4089   4088       case SQLITE_TESTCTRL_LOCALTIME_FAULT: {
  4090   4089         sqlite3GlobalConfig.bLocaltimeFault = va_arg(ap, int);
  4091   4090         break;
  4092   4091       }
         4092  +
         4093  +    /*   sqlite3_test_control(SQLITE_TESTCTRL_INTERNAL_FUNCS, int onoff);
         4094  +    **
         4095  +    ** If parameter onoff is non-zero, internal-use-only SQL functions
         4096  +    ** are visible to ordinary SQL.  This is useful for testing but is
         4097  +    ** unsafe because invalid parameters to those internal-use-only functions
         4098  +    ** can result in crashes or segfaults.
         4099  +    */
         4100  +    case SQLITE_TESTCTRL_INTERNAL_FUNCTIONS: {
         4101  +      sqlite3GlobalConfig.bInternalFunctions = va_arg(ap, int);
         4102  +      break;
         4103  +    }
  4093   4104   
  4094   4105       /*   sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, int);
  4095   4106       **
  4096   4107       ** Set or clear a flag that indicates that the database file is always well-
  4097   4108       ** formed and never corrupt.  This flag is clear by default, indicating that
  4098   4109       ** database files might have arbitrary corruption.  Setting the flag during
  4099   4110       ** testing causes certain assert() statements in the code to be activated

Changes to src/os_win.c.

   280    280     winceLock local;        /* Locks obtained by this instance of winFile */
   281    281     winceLock *shared;      /* Global shared lock memory for the file  */
   282    282   #endif
   283    283   #if SQLITE_MAX_MMAP_SIZE>0
   284    284     int nFetchOut;                /* Number of outstanding xFetch references */
   285    285     HANDLE hMap;                  /* Handle for accessing memory mapping */
   286    286     void *pMapRegion;             /* Area memory mapped */
   287         -  sqlite3_int64 mmapSize;       /* Usable size of mapped region */
   288         -  sqlite3_int64 mmapSizeActual; /* Actual size of mapped region */
          287  +  sqlite3_int64 mmapSize;       /* Size of mapped region */
   289    288     sqlite3_int64 mmapSizeMax;    /* Configured FCNTL_MMAP_SIZE value */
   290    289   #endif
   291    290   };
   292    291   
   293    292   /*
   294    293   ** The winVfsAppData structure is used for the pAppData member for all of the
   295    294   ** Win32 VFS variants.
................................................................................
  2902   2901   */
  2903   2902   static int winTruncate(sqlite3_file *id, sqlite3_int64 nByte){
  2904   2903     winFile *pFile = (winFile*)id;  /* File handle object */
  2905   2904     int rc = SQLITE_OK;             /* Return code for this function */
  2906   2905     DWORD lastErrno;
  2907   2906   #if SQLITE_MAX_MMAP_SIZE>0
  2908   2907     sqlite3_int64 oldMmapSize;
         2908  +  if( pFile->nFetchOut>0 ){
         2909  +    /* File truncation is a no-op if there are outstanding memory mapped
         2910  +    ** pages.  This is because truncating the file means temporarily unmapping
         2911  +    ** the file, and that might delete memory out from under existing cursors.
         2912  +    **
         2913  +    ** This can result in incremental vacuum not truncating the file,
         2914  +    ** if there is an active read cursor when the incremental vacuum occurs.
         2915  +    ** No real harm comes of this - the database file is not corrupted,
         2916  +    ** though some folks might complain that the file is bigger than it
         2917  +    ** needs to be.
         2918  +    **
         2919  +    ** The only feasible work-around is to defer the truncation until after
         2920  +    ** all references to memory-mapped content are closed.  That is doable,
         2921  +    ** but involves adding a few branches in the common write code path which
         2922  +    ** could slow down normal operations slightly.  Hence, we have decided for
         2923  +    ** now to simply make trancations a no-op if there are pending reads.  We
         2924  +    ** can maybe revisit this decision in the future.
         2925  +    */
         2926  +    return SQLITE_OK;
         2927  +  }
  2909   2928   #endif
  2910   2929   
  2911   2930     assert( pFile );
  2912   2931     SimulateIOError(return SQLITE_IOERR_TRUNCATE);
  2913   2932     OSTRACE(("TRUNCATE pid=%lu, pFile=%p, file=%p, size=%lld, lock=%d\n",
  2914   2933              osGetCurrentProcessId(), pFile, pFile->h, nByte, pFile->locktype));
  2915   2934   
................................................................................
  4339   4358   /*
  4340   4359   ** Cleans up the mapped region of the specified file, if any.
  4341   4360   */
  4342   4361   #if SQLITE_MAX_MMAP_SIZE>0
  4343   4362   static int winUnmapfile(winFile *pFile){
  4344   4363     assert( pFile!=0 );
  4345   4364     OSTRACE(("UNMAP-FILE pid=%lu, pFile=%p, hMap=%p, pMapRegion=%p, "
  4346         -           "mmapSize=%lld, mmapSizeActual=%lld, mmapSizeMax=%lld\n",
         4365  +           "mmapSize=%lld, mmapSizeMax=%lld\n",
  4347   4366              osGetCurrentProcessId(), pFile, pFile->hMap, pFile->pMapRegion,
  4348         -           pFile->mmapSize, pFile->mmapSizeActual, pFile->mmapSizeMax));
         4367  +           pFile->mmapSize, pFile->mmapSizeMax));
  4349   4368     if( pFile->pMapRegion ){
  4350   4369       if( !osUnmapViewOfFile(pFile->pMapRegion) ){
  4351   4370         pFile->lastErrno = osGetLastError();
  4352   4371         OSTRACE(("UNMAP-FILE pid=%lu, pFile=%p, pMapRegion=%p, "
  4353   4372                  "rc=SQLITE_IOERR_MMAP\n", osGetCurrentProcessId(), pFile,
  4354   4373                  pFile->pMapRegion));
  4355   4374         return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno,
  4356   4375                            "winUnmapfile1", pFile->zPath);
  4357   4376       }
  4358   4377       pFile->pMapRegion = 0;
  4359   4378       pFile->mmapSize = 0;
  4360         -    pFile->mmapSizeActual = 0;
  4361   4379     }
  4362   4380     if( pFile->hMap!=NULL ){
  4363   4381       if( !osCloseHandle(pFile->hMap) ){
  4364   4382         pFile->lastErrno = osGetLastError();
  4365   4383         OSTRACE(("UNMAP-FILE pid=%lu, pFile=%p, hMap=%p, rc=SQLITE_IOERR_MMAP\n",
  4366   4384                  osGetCurrentProcessId(), pFile, pFile->hMap));
  4367   4385         return winLogError(SQLITE_IOERR_MMAP, pFile->lastErrno,
................................................................................
  4464   4482         /* Log the error, but continue normal operation using xRead/xWrite */
  4465   4483         OSTRACE(("MAP-FILE-MAP pid=%lu, pFile=%p, rc=%s\n",
  4466   4484                  osGetCurrentProcessId(), pFd, sqlite3ErrName(rc)));
  4467   4485         return SQLITE_OK;
  4468   4486       }
  4469   4487       pFd->pMapRegion = pNew;
  4470   4488       pFd->mmapSize = nMap;
  4471         -    pFd->mmapSizeActual = nMap;
  4472   4489     }
  4473   4490   
  4474   4491     OSTRACE(("MAP-FILE pid=%lu, pFile=%p, rc=SQLITE_OK\n",
  4475   4492              osGetCurrentProcessId(), pFd));
  4476   4493     return SQLITE_OK;
  4477   4494   }
  4478   4495   #endif /* SQLITE_MAX_MMAP_SIZE>0 */
................................................................................
  5266   5283     }
  5267   5284     pFile->lastErrno = NO_ERROR;
  5268   5285     pFile->zPath = zName;
  5269   5286   #if SQLITE_MAX_MMAP_SIZE>0
  5270   5287     pFile->hMap = NULL;
  5271   5288     pFile->pMapRegion = 0;
  5272   5289     pFile->mmapSize = 0;
  5273         -  pFile->mmapSizeActual = 0;
  5274   5290     pFile->mmapSizeMax = sqlite3GlobalConfig.szMmap;
  5275   5291   #endif
  5276   5292   
  5277   5293     OpenCounter(+1);
  5278   5294     return rc;
  5279   5295   }
  5280   5296   

Changes to src/pager.c.

   820    820   **   if( isOpen(pPager->jfd) ){ ...
   821    821   **
   822    822   ** instead of
   823    823   **
   824    824   **   if( pPager->jfd->pMethods ){ ...
   825    825   */
   826    826   #define isOpen(pFd) ((pFd)->pMethods!=0)
          827  +
          828  +#ifdef SQLITE_DIRECT_OVERFLOW_READ
          829  +/*
          830  +** Return true if page pgno can be read directly from the database file
          831  +** by the b-tree layer. This is the case if:
          832  +**
          833  +**   * the database file is open,
          834  +**   * there are no dirty pages in the cache, and
          835  +**   * the desired page is not currently in the wal file.
          836  +*/
          837  +int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno){
          838  +  if( pPager->fd->pMethods==0 ) return 0;
          839  +  if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0;
          840  +#ifndef SQLITE_OMIT_WAL
          841  +  if( pPager->pWal ){
          842  +    u32 iRead = 0;
          843  +    int rc;
          844  +    rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iRead);
          845  +    return (rc==SQLITE_OK && iRead==0);
          846  +  }
          847  +#endif
          848  +  return 1;
          849  +}
          850  +#endif
   827    851   
   828    852   /*
   829    853   ** Return true if this pager uses a write-ahead log to read page pgno.
   830    854   ** Return false if the pager reads pgno directly from the database.
   831    855   */
   832    856   #if !defined(SQLITE_OMIT_WAL) && defined(SQLITE_DIRECT_OVERFLOW_READ)
   833    857   int sqlite3PagerUseWal(Pager *pPager, Pgno pgno){

Changes to src/pager.h.

   188    188     int sqlite3PagerSnapshotRecover(Pager *pPager);
   189    189     int sqlite3PagerSnapshotCheck(Pager *pPager, sqlite3_snapshot *pSnapshot);
   190    190     void sqlite3PagerSnapshotUnlock(Pager *pPager);
   191    191   # endif
   192    192   #else
   193    193   # define sqlite3PagerUseWal(x,y) 0
   194    194   #endif
          195  +
          196  +#ifdef SQLITE_DIRECT_OVERFLOW_READ
          197  +  int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno);
          198  +#endif
   195    199   
   196    200   #ifdef SQLITE_ENABLE_ZIPVFS
   197    201     int sqlite3PagerWalFramesize(Pager *pPager);
   198    202   #endif
   199    203   
   200    204   /* Functions used to query pager state and configuration. */
   201    205   u8 sqlite3PagerIsreadonly(Pager*);

Changes to src/pcache.c.

   851    851   int sqlite3PCachePercentDirty(PCache *pCache){
   852    852     PgHdr *pDirty;
   853    853     int nDirty = 0;
   854    854     int nCache = numberOfCachePages(pCache);
   855    855     for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext) nDirty++;
   856    856     return nCache ? (int)(((i64)nDirty * 100) / nCache) : 0;
   857    857   }
          858  +
          859  +#ifdef SQLITE_DIRECT_OVERFLOW_READ
          860  +/* 
          861  +** Return true if there are one or more dirty pages in the cache. Else false.
          862  +*/
          863  +int sqlite3PCacheIsDirty(PCache *pCache){
          864  +  return (pCache->pDirty!=0);
          865  +}
          866  +#endif
   858    867   
   859    868   #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
   860    869   /*
   861    870   ** For all dirty pages currently in the cache, invoke the specified
   862    871   ** callback. This is only used if the SQLITE_CHECK_PAGES macro is
   863    872   ** defined.
   864    873   */

Changes to src/pcache.h.

   178    178   
   179    179   /* Return the header size */
   180    180   int sqlite3HeaderSizePcache(void);
   181    181   int sqlite3HeaderSizePcache1(void);
   182    182   
   183    183   /* Number of dirty pages as a percentage of the configured cache size */
   184    184   int sqlite3PCachePercentDirty(PCache*);
          185  +
          186  +#ifdef SQLITE_DIRECT_OVERFLOW_READ
          187  +int sqlite3PCacheIsDirty(PCache *pCache);
          188  +#endif
   185    189   
   186    190   #endif /* _PCACHE_H_ */

Changes to src/pragma.c.

  1082   1082     ** dflt_value: The default value for the column, if any.
  1083   1083     ** pk:         Non-zero for PK fields.
  1084   1084     */
  1085   1085     case PragTyp_TABLE_INFO: if( zRight ){
  1086   1086       Table *pTab;
  1087   1087       pTab = sqlite3LocateTable(pParse, LOCATE_NOERR, zRight, zDb);
  1088   1088       if( pTab ){
         1089  +      int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
  1089   1090         int i, k;
  1090   1091         int nHidden = 0;
  1091   1092         Column *pCol;
  1092   1093         Index *pPk = sqlite3PrimaryKeyIndex(pTab);
  1093   1094         pParse->nMem = 7;
  1094         -      sqlite3CodeVerifySchema(pParse, iDb);
         1095  +      sqlite3CodeVerifySchema(pParse, iTabDb);
  1095   1096         sqlite3ViewGetColumnNames(pParse, pTab);
  1096   1097         for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
  1097   1098           int isHidden = IsHiddenColumn(pCol);
  1098   1099           if( isHidden && pPragma->iArg==0 ){
  1099   1100             nHidden++;
  1100   1101             continue;
  1101   1102           }
................................................................................
  1148   1149   #endif
  1149   1150   
  1150   1151     case PragTyp_INDEX_INFO: if( zRight ){
  1151   1152       Index *pIdx;
  1152   1153       Table *pTab;
  1153   1154       pIdx = sqlite3FindIndex(db, zRight, zDb);
  1154   1155       if( pIdx ){
         1156  +      int iIdxDb = sqlite3SchemaToIndex(db, pIdx->pSchema);
  1155   1157         int i;
  1156   1158         int mx;
  1157   1159         if( pPragma->iArg ){
  1158   1160           /* PRAGMA index_xinfo (newer version with more rows and columns) */
  1159   1161           mx = pIdx->nColumn;
  1160   1162           pParse->nMem = 6;
  1161   1163         }else{
  1162   1164           /* PRAGMA index_info (legacy version) */
  1163   1165           mx = pIdx->nKeyCol;
  1164   1166           pParse->nMem = 3;
  1165   1167         }
  1166   1168         pTab = pIdx->pTable;
  1167         -      sqlite3CodeVerifySchema(pParse, iDb);
         1169  +      sqlite3CodeVerifySchema(pParse, iIdxDb);
  1168   1170         assert( pParse->nMem<=pPragma->nPragCName );
  1169   1171         for(i=0; i<mx; i++){
  1170   1172           i16 cnum = pIdx->aiColumn[i];
  1171   1173           sqlite3VdbeMultiLoad(v, 1, "iisX", i, cnum,
  1172   1174                                cnum<0 ? 0 : pTab->aCol[cnum].zName);
  1173   1175           if( pPragma->iArg ){
  1174   1176             sqlite3VdbeMultiLoad(v, 4, "isiX",
................................................................................
  1184   1186   
  1185   1187     case PragTyp_INDEX_LIST: if( zRight ){
  1186   1188       Index *pIdx;
  1187   1189       Table *pTab;
  1188   1190       int i;
  1189   1191       pTab = sqlite3FindTable(db, zRight, zDb);
  1190   1192       if( pTab ){
         1193  +      int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
  1191   1194         pParse->nMem = 5;
  1192         -      sqlite3CodeVerifySchema(pParse, iDb);
         1195  +      sqlite3CodeVerifySchema(pParse, iTabDb);
  1193   1196         for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){
  1194   1197           const char *azOrigin[] = { "c", "u", "pk" };
  1195   1198           sqlite3VdbeMultiLoad(v, 1, "isisi",
  1196   1199              i,
  1197   1200              pIdx->zName,
  1198   1201              IsUniqueIndex(pIdx),
  1199   1202              azOrigin[pIdx->idxType],
................................................................................
  1232   1235     case PragTyp_FUNCTION_LIST: {
  1233   1236       int i;
  1234   1237       HashElem *j;
  1235   1238       FuncDef *p;
  1236   1239       pParse->nMem = 2;
  1237   1240       for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){
  1238   1241         for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash ){
         1242  +        if( p->funcFlags & SQLITE_FUNC_INTERNAL ) continue;
  1239   1243           sqlite3VdbeMultiLoad(v, 1, "si", p->zName, 1);
  1240   1244         }
  1241   1245       }
  1242   1246       for(j=sqliteHashFirst(&db->aFunc); j; j=sqliteHashNext(j)){
  1243   1247         p = (FuncDef*)sqliteHashData(j);
  1244   1248         sqlite3VdbeMultiLoad(v, 1, "si", p->zName, 0);
  1245   1249       }
................................................................................
  1273   1277     case PragTyp_FOREIGN_KEY_LIST: if( zRight ){
  1274   1278       FKey *pFK;
  1275   1279       Table *pTab;
  1276   1280       pTab = sqlite3FindTable(db, zRight, zDb);
  1277   1281       if( pTab ){
  1278   1282         pFK = pTab->pFKey;
  1279   1283         if( pFK ){
         1284  +        int iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
  1280   1285           int i = 0; 
  1281   1286           pParse->nMem = 8;
  1282         -        sqlite3CodeVerifySchema(pParse, iDb);
         1287  +        sqlite3CodeVerifySchema(pParse, iTabDb);
  1283   1288           while(pFK){
  1284   1289             int j;
  1285   1290             for(j=0; j<pFK->nCol; j++){
  1286   1291               sqlite3VdbeMultiLoad(v, 1, "iissssss",
  1287   1292                      i,
  1288   1293                      j,
  1289   1294                      pFK->zTo,
................................................................................
  1320   1325       int addrOk;            /* Jump here if the key is OK */
  1321   1326       int *aiCols;           /* child to parent column mapping */
  1322   1327   
  1323   1328       regResult = pParse->nMem+1;
  1324   1329       pParse->nMem += 4;
  1325   1330       regKey = ++pParse->nMem;
  1326   1331       regRow = ++pParse->nMem;
  1327         -    sqlite3CodeVerifySchema(pParse, iDb);
  1328   1332       k = sqliteHashFirst(&db->aDb[iDb].pSchema->tblHash);
  1329   1333       while( k ){
         1334  +      int iTabDb;
  1330   1335         if( zRight ){
  1331   1336           pTab = sqlite3LocateTable(pParse, 0, zRight, zDb);
  1332   1337           k = 0;
  1333   1338         }else{
  1334   1339           pTab = (Table*)sqliteHashData(k);
  1335   1340           k = sqliteHashNext(k);
  1336   1341         }
  1337   1342         if( pTab==0 || pTab->pFKey==0 ) continue;
  1338         -      sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
         1343  +      iTabDb = sqlite3SchemaToIndex(db, pTab->pSchema);
         1344  +      sqlite3CodeVerifySchema(pParse, iTabDb);
         1345  +      sqlite3TableLock(pParse, iTabDb, pTab->tnum, 0, pTab->zName);
  1339   1346         if( pTab->nCol+regRow>pParse->nMem ) pParse->nMem = pTab->nCol + regRow;
  1340         -      sqlite3OpenTable(pParse, 0, iDb, pTab, OP_OpenRead);
         1347  +      sqlite3OpenTable(pParse, 0, iTabDb, pTab, OP_OpenRead);
  1341   1348         sqlite3VdbeLoadString(v, regResult, pTab->zName);
  1342   1349         for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){
  1343   1350           pParent = sqlite3FindTable(db, pFK->zTo, zDb);
  1344   1351           if( pParent==0 ) continue;
  1345   1352           pIdx = 0;
  1346         -        sqlite3TableLock(pParse, iDb, pParent->tnum, 0, pParent->zName);
         1353  +        sqlite3TableLock(pParse, iTabDb, pParent->tnum, 0, pParent->zName);
  1347   1354           x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, 0);
  1348   1355           if( x==0 ){
  1349   1356             if( pIdx==0 ){
  1350         -            sqlite3OpenTable(pParse, i, iDb, pParent, OP_OpenRead);
         1357  +            sqlite3OpenTable(pParse, i, iTabDb, pParent, OP_OpenRead);
  1351   1358             }else{
  1352         -            sqlite3VdbeAddOp3(v, OP_OpenRead, i, pIdx->tnum, iDb);
         1359  +            sqlite3VdbeAddOp3(v, OP_OpenRead, i, pIdx->tnum, iTabDb);
  1353   1360               sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
  1354   1361             }
  1355   1362           }else{
  1356   1363             k = 0;
  1357   1364             break;
  1358   1365           }
  1359   1366         }

Changes to src/resolve.c.

   766    766           }
   767    767           if( (pDef->funcFlags & SQLITE_FUNC_CONSTANT)==0 ){
   768    768             /* Date/time functions that use 'now', and other functions like
   769    769             ** sqlite_version() that might change over time cannot be used
   770    770             ** in an index. */
   771    771             notValid(pParse, pNC, "non-deterministic functions",
   772    772                      NC_IdxExpr|NC_PartIdx);
          773  +        }
          774  +        if( (pDef->funcFlags & SQLITE_FUNC_INTERNAL)!=0
          775  +         && pParse->nested==0
          776  +         && sqlite3Config.bInternalFunctions==0
          777  +        ){
          778  +          /* Internal-use-only functions are disallowed unless the
          779  +          ** SQL is being compiled using sqlite3NestedParse() */
          780  +          no_such_func = 1;
          781  +          pDef = 0;
   773    782           }
   774    783         }
   775    784   
   776    785         if( 0==IN_RENAME_OBJECT ){
   777    786   #ifndef SQLITE_OMIT_WINDOWFUNC
   778    787           assert( is_agg==0 || (pDef->funcFlags & SQLITE_FUNC_MINMAX)
   779    788             || (pDef->xValue==0 && pDef->xInverse==0)

Changes to src/shell.c.in.

  7673   7673         { "always",             SQLITE_TESTCTRL_ALWAYS,        "BOOLEAN"            },
  7674   7674         { "assert",             SQLITE_TESTCTRL_ASSERT,        "BOOLEAN"            },
  7675   7675       /*{ "benign_malloc_hooks",SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS, ""          },*/
  7676   7676       /*{ "bitvec_test",        SQLITE_TESTCTRL_BITVEC_TEST,   ""                },*/
  7677   7677         { "byteorder",          SQLITE_TESTCTRL_BYTEORDER,     ""                   },
  7678   7678       /*{ "fault_install",      SQLITE_TESTCTRL_FAULT_INSTALL, ""                }, */
  7679   7679         { "imposter",           SQLITE_TESTCTRL_IMPOSTER,   "SCHEMA ON/OFF ROOTPAGE"},
         7680  +      { "internal_functions", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, "BOOLEAN"       },
  7680   7681         { "localtime_fault",    SQLITE_TESTCTRL_LOCALTIME_FAULT,"BOOLEAN"           },
  7681   7682         { "never_corrupt",      SQLITE_TESTCTRL_NEVER_CORRUPT, "BOOLEAN"            },
  7682   7683         { "optimizations",      SQLITE_TESTCTRL_OPTIMIZATIONS, "DISABLE-MASK"       },
  7683   7684   #ifdef YYCOVERAGE
  7684   7685         { "parser_coverage",    SQLITE_TESTCTRL_PARSER_COVERAGE, ""                 },
  7685   7686   #endif
  7686   7687         { "pending_byte",       SQLITE_TESTCTRL_PENDING_BYTE,  "OFFSET  "           },
................................................................................
  7767   7768               isOk = 3;
  7768   7769             }
  7769   7770             break;
  7770   7771   
  7771   7772           /* sqlite3_test_control(int, int) */
  7772   7773           case SQLITE_TESTCTRL_ASSERT:
  7773   7774           case SQLITE_TESTCTRL_ALWAYS:
         7775  +        case SQLITE_TESTCTRL_INTERNAL_FUNCTIONS:
  7774   7776             if( nArg==3 ){
  7775   7777               int opt = booleanValue(azArg[2]);
  7776   7778               rc2 = sqlite3_test_control(testctrl, opt);
  7777   7779               isOk = 1;
  7778   7780             }
  7779   7781             break;
  7780   7782   
................................................................................
  8061   8063   /*
  8062   8064   ** We need a default sqlite3_complete() implementation to use in case
  8063   8065   ** the shell is compiled with SQLITE_OMIT_COMPLETE.  The default assumes
  8064   8066   ** any arbitrary text is a complete SQL statement.  This is not very
  8065   8067   ** user-friendly, but it does seem to work.
  8066   8068   */
  8067   8069   #ifdef SQLITE_OMIT_COMPLETE
  8068         -int sqlite3_complete(const char *zSql){ return 1; }
         8070  +#define sqlite3_complete(x) 1
  8069   8071   #endif
  8070   8072   
  8071   8073   /*
  8072   8074   ** Return true if zSql is a complete SQL statement.  Return false if it
  8073   8075   ** ends in the middle of a string literal or C-style comment.
  8074   8076   */
  8075   8077   static int line_is_complete(char *zSql, int nSql){

Changes to src/sqlite.h.in.

  2014   2014   ** Existing configuration options might be discontinued.  Applications
  2015   2015   ** should check the return code from [sqlite3_db_config()] to make sure that
  2016   2016   ** the call worked.  ^The [sqlite3_db_config()] interface will return a
  2017   2017   ** non-zero [error code] if a discontinued or unsupported configuration option
  2018   2018   ** is invoked.
  2019   2019   **
  2020   2020   ** <dl>
         2021  +** [[SQLITE_DBCONFIG_LOOKASIDE]]
  2021   2022   ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt>
  2022   2023   ** <dd> ^This option takes three additional arguments that determine the 
  2023   2024   ** [lookaside memory allocator] configuration for the [database connection].
  2024   2025   ** ^The first argument (the third parameter to [sqlite3_db_config()] is a
  2025   2026   ** pointer to a memory buffer to use for lookaside memory.
  2026   2027   ** ^The first argument after the SQLITE_DBCONFIG_LOOKASIDE verb
  2027   2028   ** may be NULL in which case SQLite will allocate the
................................................................................
  2036   2037   ** connection is not currently using lookaside memory, or in other words
  2037   2038   ** when the "current value" returned by
  2038   2039   ** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
  2039   2040   ** Any attempt to change the lookaside memory configuration when lookaside
  2040   2041   ** memory is in use leaves the configuration unchanged and returns 
  2041   2042   ** [SQLITE_BUSY].)^</dd>
  2042   2043   **
         2044  +** [[SQLITE_DBCONFIG_ENABLE_FKEY]]
  2043   2045   ** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
  2044   2046   ** <dd> ^This option is used to enable or disable the enforcement of
  2045   2047   ** [foreign key constraints].  There should be two additional arguments.
  2046   2048   ** The first argument is an integer which is 0 to disable FK enforcement,
  2047   2049   ** positive to enable FK enforcement or negative to leave FK enforcement
  2048   2050   ** unchanged.  The second parameter is a pointer to an integer into which
  2049   2051   ** is written 0 or 1 to indicate whether FK enforcement is off or on
  2050   2052   ** following this call.  The second parameter may be a NULL pointer, in
  2051   2053   ** which case the FK enforcement setting is not reported back. </dd>
  2052   2054   **
         2055  +** [[SQLITE_DBCONFIG_ENABLE_TRIGGER]]
  2053   2056   ** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt>
  2054   2057   ** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
  2055   2058   ** There should be two additional arguments.
  2056   2059   ** The first argument is an integer which is 0 to disable triggers,
  2057   2060   ** positive to enable triggers or negative to leave the setting unchanged.
  2058   2061   ** The second parameter is a pointer to an integer into which
  2059   2062   ** is written 0 or 1 to indicate whether triggers are disabled or enabled
  2060   2063   ** following this call.  The second parameter may be a NULL pointer, in
  2061   2064   ** which case the trigger setting is not reported back. </dd>
  2062   2065   **
         2066  +** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
  2063   2067   ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
  2064   2068   ** <dd> ^This option is used to enable or disable the two-argument
  2065   2069   ** version of the [fts3_tokenizer()] function which is part of the
  2066   2070   ** [FTS3] full-text search engine extension.
  2067   2071   ** There should be two additional arguments.
  2068   2072   ** The first argument is an integer which is 0 to disable fts3_tokenizer() or
  2069   2073   ** positive to enable fts3_tokenizer() or negative to leave the setting
  2070   2074   ** unchanged.
  2071   2075   ** The second parameter is a pointer to an integer into which
  2072   2076   ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
  2073   2077   ** following this call.  The second parameter may be a NULL pointer, in
  2074   2078   ** which case the new setting is not reported back. </dd>
  2075   2079   **
         2080  +** [[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION]]
  2076   2081   ** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
  2077   2082   ** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
  2078   2083   ** interface independently of the [load_extension()] SQL function.
  2079   2084   ** The [sqlite3_enable_load_extension()] API enables or disables both the
  2080   2085   ** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
  2081   2086   ** There should be two additional arguments.
  2082   2087   ** When the first argument to this interface is 1, then only the C-API is
................................................................................
  2086   2091   ** C-API or the SQL function.
  2087   2092   ** The second parameter is a pointer to an integer into which
  2088   2093   ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
  2089   2094   ** is disabled or enabled following this call.  The second parameter may
  2090   2095   ** be a NULL pointer, in which case the new setting is not reported back.
  2091   2096   ** </dd>
  2092   2097   **
  2093         -** <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
         2098  +** [[SQLITE_DBCONFIG_MAINDBNAME]] <dt>SQLITE_DBCONFIG_MAINDBNAME</dt>
  2094   2099   ** <dd> ^This option is used to change the name of the "main" database
  2095   2100   ** schema.  ^The sole argument is a pointer to a constant UTF8 string
  2096   2101   ** which will become the new schema name in place of "main".  ^SQLite
  2097   2102   ** does not make a copy of the new main schema name string, so the application
  2098   2103   ** must ensure that the argument passed into this DBCONFIG option is unchanged
  2099   2104   ** until after the database connection closes.
  2100   2105   ** </dd>
  2101   2106   **
         2107  +** [[SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE]] 
  2102   2108   ** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt>
  2103   2109   ** <dd> Usually, when a database in wal mode is closed or detached from a 
  2104   2110   ** database handle, SQLite checks if this will mean that there are now no 
  2105   2111   ** connections at all to the database. If so, it performs a checkpoint 
  2106   2112   ** operation before closing the connection. This option may be used to
  2107   2113   ** override this behaviour. The first parameter passed to this operation
  2108   2114   ** is an integer - positive to disable checkpoints-on-close, or zero (the
  2109   2115   ** default) to enable them, and negative to leave the setting unchanged.
  2110   2116   ** The second parameter is a pointer to an integer
  2111   2117   ** into which is written 0 or 1 to indicate whether checkpoints-on-close
  2112   2118   ** have been disabled - 0 if they are not disabled, 1 if they are.
  2113   2119   ** </dd>
  2114   2120   **
  2115         -** <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>
         2121  +** [[SQLITE_DBCONFIG_ENABLE_QPSG]] <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>
  2116   2122   ** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates
  2117   2123   ** the [query planner stability guarantee] (QPSG).  When the QPSG is active,
  2118   2124   ** a single SQL query statement will always use the same algorithm regardless
  2119   2125   ** of values of [bound parameters].)^ The QPSG disables some query optimizations
  2120   2126   ** that look at the values of bound parameters, which can make some queries
  2121   2127   ** slower.  But the QPSG has the advantage of more predictable behavior.  With
  2122   2128   ** the QPSG active, SQLite will always use the same query plan in the field as
................................................................................
  2124   2130   ** The first argument to this setting is an integer which is 0 to disable 
  2125   2131   ** the QPSG, positive to enable QPSG, or negative to leave the setting
  2126   2132   ** unchanged. The second parameter is a pointer to an integer into which
  2127   2133   ** is written 0 or 1 to indicate whether the QPSG is disabled or enabled
  2128   2134   ** following this call.
  2129   2135   ** </dd>
  2130   2136   **
  2131         -** <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt>
         2137  +** [[SQLITE_DBCONFIG_TRIGGER_EQP]] <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt>
  2132   2138   ** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not 
  2133   2139   ** include output for any operations performed by trigger programs. This
  2134   2140   ** option is used to set or clear (the default) a flag that governs this
  2135   2141   ** behavior. The first parameter passed to this operation is an integer -
  2136   2142   ** positive to enable output for trigger programs, or zero to disable it,
  2137   2143   ** or negative to leave the setting unchanged.
  2138   2144   ** The second parameter is a pointer to an integer into which is written 
  2139   2145   ** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if 
  2140   2146   ** it is not disabled, 1 if it is.  
  2141   2147   ** </dd>
  2142   2148   **
  2143         -** <dt>SQLITE_DBCONFIG_RESET_DATABASE</dt>
         2149  +** [[SQLITE_DBCONFIG_RESET_DATABASE]] <dt>SQLITE_DBCONFIG_RESET_DATABASE</dt>
  2144   2150   ** <dd> Set the SQLITE_DBCONFIG_RESET_DATABASE flag and then run
  2145   2151   ** [VACUUM] in order to reset a database back to an empty database
  2146   2152   ** with no schema and no content. The following process works even for
  2147   2153   ** a badly corrupted database file:
  2148   2154   ** <ol>
  2149   2155   ** <li> If the database connection is newly opened, make sure it has read the
  2150   2156   **      database schema by preparing then discarding some query against the
................................................................................
  2156   2162   ** <li> [sqlite3_exec](db, "[VACUUM]", 0, 0, 0);
  2157   2163   ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);
  2158   2164   ** </ol>
  2159   2165   ** Because resetting a database is destructive and irreversible, the
  2160   2166   ** process requires the use of this obscure API and multiple steps to help
  2161   2167   ** ensure that it does not happen by accident.
  2162   2168   **
  2163         -** <dt>SQLITE_DBCONFIG_DEFENSIVE</dt>
         2169  +** [[SQLITE_DBCONFIG_DEFENSIVE]] <dt>SQLITE_DBCONFIG_DEFENSIVE</dt>
  2164   2170   ** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the
  2165   2171   ** "defensive" flag for a database connection.  When the defensive
  2166   2172   ** flag is enabled, language features that allow ordinary SQL to 
  2167   2173   ** deliberately corrupt the database file are disabled.  The disabled
  2168   2174   ** features include but are not limited to the following:
  2169   2175   ** <ul>
  2170   2176   ** <li> The [PRAGMA writable_schema=ON] statement.
  2171   2177   ** <li> Writes to the [sqlite_dbpage] virtual table.
  2172         -** <li> Direct writes to shadow tables.
         2178  +** <li> Direct writes to [shadow tables].
  2173   2179   ** </ul>
  2174   2180   ** </dd>
  2175   2181   ** </dl>
  2176   2182   */
  2177   2183   #define SQLITE_DBCONFIG_MAINDBNAME            1000 /* const char* */
  2178   2184   #define SQLITE_DBCONFIG_LOOKASIDE             1001 /* void* int int */
  2179   2185   #define SQLITE_DBCONFIG_ENABLE_FKEY           1002 /* int int* */
................................................................................
  7233   7239   #define SQLITE_TESTCTRL_PENDING_BYTE            11
  7234   7240   #define SQLITE_TESTCTRL_ASSERT                  12
  7235   7241   #define SQLITE_TESTCTRL_ALWAYS                  13
  7236   7242   #define SQLITE_TESTCTRL_RESERVE                 14
  7237   7243   #define SQLITE_TESTCTRL_OPTIMIZATIONS           15
  7238   7244   #define SQLITE_TESTCTRL_ISKEYWORD               16  /* NOT USED */
  7239   7245   #define SQLITE_TESTCTRL_SCRATCHMALLOC           17  /* NOT USED */
         7246  +#define SQLITE_TESTCTRL_INTERNAL_FUNCTIONS      17
  7240   7247   #define SQLITE_TESTCTRL_LOCALTIME_FAULT         18
  7241   7248   #define SQLITE_TESTCTRL_EXPLAIN_STMT            19  /* NOT USED */
  7242   7249   #define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD    19
  7243   7250   #define SQLITE_TESTCTRL_NEVER_CORRUPT           20
  7244   7251   #define SQLITE_TESTCTRL_VDBE_COVERAGE           21
  7245   7252   #define SQLITE_TESTCTRL_BYTEORDER               22
  7246   7253   #define SQLITE_TESTCTRL_ISINIT                  23
................................................................................
  8645   8652   ** CAPI3REF: Virtual Table Configuration Options
  8646   8653   **
  8647   8654   ** These macros define the various options to the
  8648   8655   ** [sqlite3_vtab_config()] interface that [virtual table] implementations
  8649   8656   ** can use to customize and optimize their behavior.
  8650   8657   **
  8651   8658   ** <dl>
         8659  +** [[SQLITE_VTAB_CONSTRAINT_SUPPORT]]
  8652   8660   ** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT
  8653   8661   ** <dd>Calls of the form
  8654   8662   ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported,
  8655   8663   ** where X is an integer.  If X is zero, then the [virtual table] whose
  8656   8664   ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not
  8657   8665   ** support constraints.  In this configuration (which is the default) if
  8658   8666   ** a call to the [xUpdate] method returns [SQLITE_CONSTRAINT], then the entire

Changes to src/sqliteInt.h.

  1695   1695   #define SQLITE_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */
  1696   1696   #define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */
  1697   1697   #define SQLITE_FUNC_MINMAX   0x1000 /* True for min() and max() aggregates */
  1698   1698   #define SQLITE_FUNC_SLOCHNG  0x2000 /* "Slow Change". Value constant during a
  1699   1699                                       ** single query - might change over time */
  1700   1700   #define SQLITE_FUNC_AFFINITY 0x4000 /* Built-in affinity() function */
  1701   1701   #define SQLITE_FUNC_OFFSET   0x8000 /* Built-in sqlite_offset() function */
  1702         -#define SQLITE_FUNC_WINDOW  0x10000 /* Built-in window-only function */
  1703         -#define SQLITE_FUNC_WINDOW_SIZE  0x20000  /* Requires partition size as arg. */
         1702  +#define SQLITE_FUNC_WINDOW   0x00010000 /* Built-in window-only function */
         1703  +#define SQLITE_FUNC_WINDOW_SIZE 0x20000 /* Requires partition size as arg. */
         1704  +#define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */
  1704   1705   
  1705   1706   /*
  1706   1707   ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
  1707   1708   ** used to create the initializers for the FuncDef structures.
  1708   1709   **
  1709   1710   **   FUNCTION(zName, nArg, iArg, bNC, xFunc)
  1710   1711   **     Used to create a scalar function definition of a function zName
................................................................................
  1772   1773      (void *)arg, 0, likeFunc, 0, 0, 0, #zName, {0} }
  1773   1774   #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal, xValue) \
  1774   1775     {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \
  1775   1776      SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xValue,0,#zName, {0}}
  1776   1777   #define AGGREGATE2(zName, nArg, arg, nc, xStep, xFinal, extraFlags) \
  1777   1778     {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|extraFlags, \
  1778   1779      SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xFinal,0,#zName, {0}}
  1779         -
  1780   1780   #define WAGGREGATE(zName, nArg, arg, nc, xStep, xFinal, xValue, xInverse, f) \
  1781   1781     {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL)|f, \
  1782   1782      SQLITE_INT_TO_PTR(arg), 0, xStep,xFinal,xValue,xInverse,#zName, {0}}
         1783  +#define INTERNAL_FUNCTION(zName, nArg, xFunc) \
         1784  +  {nArg, SQLITE_FUNC_INTERNAL|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \
         1785  +   0, 0, xFunc, 0, 0, 0, #zName, {0} }
         1786  +
  1783   1787   
  1784   1788   /*
  1785   1789   ** All current savepoints are stored in a linked list starting at
  1786   1790   ** sqlite3.pSavepoint. The first element in the list is the most recently
  1787   1791   ** opened savepoint. Savepoints are added to the list by the vdbe
  1788   1792   ** OP_Savepoint instruction.
  1789   1793   */
................................................................................
  3426   3430     void (*xVdbeBranch)(void*,unsigned iSrcLine,u8 eThis,u8 eMx);  /* Callback */
  3427   3431     void *pVdbeBranchArg;                                     /* 1st argument */
  3428   3432   #endif
  3429   3433   #ifndef SQLITE_UNTESTABLE
  3430   3434     int (*xTestCallback)(int);        /* Invoked by sqlite3FaultSim() */
  3431   3435   #endif
  3432   3436     int bLocaltimeFault;              /* True to fail localtime() calls */
         3437  +  int bInternalFunctions;           /* Internal SQL functions are visible */
  3433   3438     int iOnceResetThreshold;          /* When to reset OP_Once counters */
  3434   3439     u32 szSorterRef;                  /* Min size in bytes to use sorter-refs */
  3435   3440   };
  3436   3441   
  3437   3442   /*
  3438   3443   ** This macro is used inside of assert() statements to indicate that
  3439   3444   ** the assert is only valid on a well-formed database.  Instead of:

Changes to src/test1.c.

  6516   6516     sqlite3_test_control(SQLITE_TESTCTRL_PRNG_RESET);
  6517   6517     return TCL_OK;
  6518   6518   }
  6519   6519   
  6520   6520   /*
  6521   6521   ** tclcmd:  database_may_be_corrupt
  6522   6522   **
  6523         -** Indicate that database files might be corrupt.  In other words, set the normal
         6523  +** Indicate that database files might be corrupt. In other words, set the normal
  6524   6524   ** state of operation.
  6525   6525   */
  6526   6526   static int SQLITE_TCLAPI database_may_be_corrupt(
  6527   6527     ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
  6528   6528     Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
  6529   6529     int objc,              /* Number of arguments */
  6530   6530     Tcl_Obj *CONST objv[]  /* Command arguments */
................................................................................
  6531   6531   ){
  6532   6532     sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, 0);
  6533   6533     return TCL_OK;
  6534   6534   }
  6535   6535   /*
  6536   6536   ** tclcmd:  database_never_corrupt
  6537   6537   **
  6538         -** Indicate that database files are always well-formed.  This enables extra assert()
  6539         -** statements that test conditions that are always true for well-formed databases.
         6538  +** Indicate that database files are always well-formed. This enables
         6539  +** extra assert() statements that test conditions that are always true
         6540  +** for well-formed databases.
  6540   6541   */
  6541   6542   static int SQLITE_TCLAPI database_never_corrupt(
  6542   6543     ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
  6543   6544     Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
  6544   6545     int objc,              /* Number of arguments */
  6545   6546     Tcl_Obj *CONST objv[]  /* Command arguments */
  6546   6547   ){
................................................................................
  6898   6899     int objc,
  6899   6900     Tcl_Obj *CONST objv[]
  6900   6901   ){
  6901   6902     struct Verb {
  6902   6903       const char *zName;
  6903   6904       int i;
  6904   6905     } aVerb[] = {
  6905         -    { "SQLITE_TESTCTRL_LOCALTIME_FAULT", SQLITE_TESTCTRL_LOCALTIME_FAULT }, 
  6906         -    { "SQLITE_TESTCTRL_SORTER_MMAP",     SQLITE_TESTCTRL_SORTER_MMAP     }, 
  6907         -    { "SQLITE_TESTCTRL_IMPOSTER",        SQLITE_TESTCTRL_IMPOSTER        },
         6906  +    { "SQLITE_TESTCTRL_LOCALTIME_FAULT",    SQLITE_TESTCTRL_LOCALTIME_FAULT }, 
         6907  +    { "SQLITE_TESTCTRL_SORTER_MMAP",        SQLITE_TESTCTRL_SORTER_MMAP     }, 
         6908  +    { "SQLITE_TESTCTRL_IMPOSTER",           SQLITE_TESTCTRL_IMPOSTER        },
         6909  +    { "SQLITE_TESTCTRL_INTERNAL_FUNCTIONS", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS},
  6908   6910     };
  6909   6911     int iVerb;
  6910   6912     int iFlag;
  6911   6913     int rc;
  6912   6914   
  6913   6915     if( objc<2 ){
  6914   6916       Tcl_WrongNumArgs(interp, 1, objv, "VERB ARGS...");
................................................................................
  6918   6920     rc = Tcl_GetIndexFromObjStruct(
  6919   6921         interp, objv[1], aVerb, sizeof(aVerb[0]), "VERB", 0, &iVerb
  6920   6922     );
  6921   6923     if( rc!=TCL_OK ) return rc;
  6922   6924   
  6923   6925     iFlag = aVerb[iVerb].i;
  6924   6926     switch( iFlag ){
         6927  +    case SQLITE_TESTCTRL_INTERNAL_FUNCTIONS:
  6925   6928       case SQLITE_TESTCTRL_LOCALTIME_FAULT: {
  6926   6929         int val;
  6927   6930         if( objc!=3 ){
  6928   6931           Tcl_WrongNumArgs(interp, 2, objv, "ONOFF");
  6929   6932           return TCL_ERROR;
  6930   6933         }
  6931   6934         if( Tcl_GetBooleanFromObj(interp, objv[2], &val) ) return TCL_ERROR;
  6932         -      sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, val);
         6935  +      sqlite3_test_control(iFlag, val);
  6933   6936         break;
  6934   6937       }
  6935   6938   
  6936   6939       case SQLITE_TESTCTRL_SORTER_MMAP: {
  6937   6940         int val;
  6938   6941         sqlite3 *db;
  6939   6942         if( objc!=4 ){

Changes to src/vdbeInt.h.

   467    467   u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
   468    468   void sqlite3VdbeDeleteAuxData(sqlite3*, AuxData**, int, int);
   469    469   
   470    470   int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
   471    471   int sqlite3VdbeIdxKeyCompare(sqlite3*,VdbeCursor*,UnpackedRecord*,int*);
   472    472   int sqlite3VdbeIdxRowid(sqlite3*, BtCursor*, i64*);
   473    473   int sqlite3VdbeExec(Vdbe*);
          474  +#ifndef SQLITE_OMIT_EXPLAIN
   474    475   int sqlite3VdbeList(Vdbe*);
          476  +#endif
   475    477   int sqlite3VdbeHalt(Vdbe*);
   476    478   int sqlite3VdbeChangeEncoding(Mem *, int);
   477    479   int sqlite3VdbeMemTooBig(Mem*);
   478    480   int sqlite3VdbeMemCopy(Mem*, const Mem*);
   479    481   void sqlite3VdbeMemShallowCopy(Mem*, const Mem*, int);
   480    482   void sqlite3VdbeMemMove(Mem*, Mem*);
   481    483   int sqlite3VdbeMemNulTerminate(Mem*);
................................................................................
   506    508   void sqlite3VdbeMemCast(Mem*,u8,u8);
   507    509   int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*);
   508    510   void sqlite3VdbeMemRelease(Mem *p);
   509    511   int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
   510    512   #ifndef SQLITE_OMIT_WINDOWFUNC
   511    513   int sqlite3VdbeMemAggValue(Mem*, Mem*, FuncDef*);
   512    514   #endif
          515  +#ifndef SQLITE_OMIT_EXPLAIN
   513    516   const char *sqlite3OpcodeName(int);
          517  +#endif
   514    518   int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
   515    519   int sqlite3VdbeMemClearAndResize(Mem *pMem, int n);
   516    520   int sqlite3VdbeCloseStatement(Vdbe *, int);
   517    521   #ifdef SQLITE_DEBUG
   518    522   int sqlite3VdbeFrameIsValid(VdbeFrame*);
   519    523   #endif
   520    524   void sqlite3VdbeFrameMemDel(void*);      /* Destructor on Mem */

Changes to src/where.c.

  1027   1027   
  1028   1028   /*
  1029   1029   ** The table object reference passed as the second argument to this function
  1030   1030   ** must represent a virtual table. This function invokes the xBestIndex()
  1031   1031   ** method of the virtual table with the sqlite3_index_info object that
  1032   1032   ** comes in as the 3rd argument to this function.
  1033   1033   **
  1034         -** If an error occurs, pParse is populated with an error message and a
  1035         -** non-zero value is returned. Otherwise, 0 is returned and the output
  1036         -** part of the sqlite3_index_info structure is left populated.
         1034  +** If an error occurs, pParse is populated with an error message and an
         1035  +** appropriate error code is returned.  A return of SQLITE_CONSTRAINT from
         1036  +** xBestIndex is not considered an error.  SQLITE_CONSTRAINT indicates that
         1037  +** the current configuration of "unusable" flags in sqlite3_index_info can
         1038  +** not result in a valid plan.
  1037   1039   **
  1038   1040   ** Whether or not an error is returned, it is the responsibility of the
  1039   1041   ** caller to eventually free p->idxStr if p->needToFreeIdxStr indicates
  1040   1042   ** that this is required.
  1041   1043   */
  1042   1044   static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){
  1043   1045     sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab;
  1044   1046     int rc;
  1045   1047   
  1046   1048     TRACE_IDX_INPUTS(p);
  1047   1049     rc = pVtab->pModule->xBestIndex(pVtab, p);
  1048   1050     TRACE_IDX_OUTPUTS(p);
  1049   1051   
  1050         -  if( rc!=SQLITE_OK ){
         1052  +  if( rc!=SQLITE_OK && rc!=SQLITE_CONSTRAINT ){
  1051   1053       if( rc==SQLITE_NOMEM ){
  1052   1054         sqlite3OomFault(pParse->db);
  1053   1055       }else if( !pVtab->zErrMsg ){
  1054   1056         sqlite3ErrorMsg(pParse, "%s", sqlite3ErrStr(rc));
  1055   1057       }else{
  1056   1058         sqlite3ErrorMsg(pParse, "%s", pVtab->zErrMsg);
  1057   1059       }
  1058   1060     }
  1059   1061     sqlite3_free(pVtab->zErrMsg);
  1060   1062     pVtab->zErrMsg = 0;
  1061         -
  1062         -#if 0
  1063         -  /* This error is now caught by the caller.
  1064         -  ** Search for "xBestIndex malfunction" below */
  1065         -  for(i=0; i<p->nConstraint; i++){
  1066         -    if( !p->aConstraint[i].usable && p->aConstraintUsage[i].argvIndex>0 ){
  1067         -      sqlite3ErrorMsg(pParse, 
  1068         -          "table %s: xBestIndex returned an invalid plan", pTab->zName);
  1069         -    }
  1070         -  }
  1071         -#endif
  1072         -
  1073         -  return pParse->nErr;
         1063  +  return rc;
  1074   1064   }
  1075   1065   #endif /* !defined(SQLITE_OMIT_VIRTUALTABLE) */
  1076   1066   
  1077   1067   #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
  1078   1068   /*
  1079   1069   ** Estimate the location of a particular key among all keys in an
  1080   1070   ** index.  Store the results in aStat as follows:
................................................................................
  3139   3129     pIdxInfo->estimatedCost = SQLITE_BIG_DBL / (double)2;
  3140   3130     pIdxInfo->estimatedRows = 25;
  3141   3131     pIdxInfo->idxFlags = 0;
  3142   3132     pIdxInfo->colUsed = (sqlite3_int64)pSrc->colUsed;
  3143   3133   
  3144   3134     /* Invoke the virtual table xBestIndex() method */
  3145   3135     rc = vtabBestIndex(pParse, pSrc->pTab, pIdxInfo);
  3146         -  if( rc ) return rc;
         3136  +  if( rc ){
         3137  +    if( rc==SQLITE_CONSTRAINT ){
         3138  +      /* If the xBestIndex method returns SQLITE_CONSTRAINT, that means
         3139  +      ** that the particular combination of parameters provided is unusable.
         3140  +      ** Make no entries in the loop table.
         3141  +      */
         3142  +      WHERETRACE(0xffff, ("  ^^^^--- non-viable plan rejected!\n"));
         3143  +      return SQLITE_OK;
         3144  +    }
         3145  +    return rc;
         3146  +  }
  3147   3147   
  3148   3148     mxTerm = -1;
  3149   3149     assert( pNew->nLSlot>=nConstraint );
  3150   3150     for(i=0; i<nConstraint; i++) pNew->aLTerm[i] = 0;
  3151   3151     pNew->u.vtab.omitMask = 0;
  3152   3152     pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint;
  3153   3153     for(i=0; i<nConstraint; i++, pIdxCons++){

Changes to test/alter.test.

   680    680     }
   681    681   } {1 18 2 9}
   682    682   
   683    683   #--------------------------------------------------------------------------
   684    684   # alter-9.X - Special test: Make sure the sqlite_rename_column() and
   685    685   # rename_table() functions do not crash when handed bad input.
   686    686   #
          687  +sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 1
   687    688   do_test alter-9.1 {
   688    689     execsql {SELECT SQLITE_RENAME_COLUMN(0,0,0,0,0,0,0,0,0)}
   689    690   } {{}}
   690    691   foreach {tn sql} {
   691    692       1 { SELECT SQLITE_RENAME_TABLE(0,0,0,0,0,0,0) }
   692    693       2 { SELECT SQLITE_RENAME_TABLE(10,20,30,40,50,60,70) }
   693    694       3 { SELECT SQLITE_RENAME_TABLE('foo','foo','foo','foo','foo','foo','foo') }
   694    695   } {
   695    696     do_test alter-9.2.$tn {
   696    697       catch { execsql $sql }
   697    698     } 1
   698    699   }
          700  +sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 0
          701  +
          702  +# If the INTERNAL_FUNCTIONS test-control is disabled (which is the default),
          703  +# then the sqlite_rename_table() SQL function is not accessible to ordinary SQL.
          704  +#
          705  +do_catchsql_test alter-9.3 {
          706  +  SELECT sqlite_rename_table(0,0,0,0,0,0,0);
          707  +} {1 {no such function: sqlite_rename_table}}
   699    708   
   700    709   #------------------------------------------------------------------------
   701    710   # alter-10.X - Make sure ALTER TABLE works with multi-byte UTF-8 characters 
   702    711   # in the names.
   703    712   #
   704    713   do_test alter-10.1 {
   705    714     execsql "CREATE TABLE xyz(x UNIQUE)"

Changes to test/altercol.test.

   614    614       ALTER TABLE x1 RENAME COLUMN t TO ttt;
   615    615     } "1 {error in trigger tr1: $error}"
   616    616   }
   617    617   
   618    618   #-------------------------------------------------------------------------
   619    619   # Passing invalid parameters directly to sqlite_rename_column().
   620    620   #
          621  +sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 1
   621    622   do_execsql_test 14.1 {
   622    623     CREATE TABLE ddd(sql, type, object, db, tbl, icol, znew, bquote);
   623    624     INSERT INTO ddd VALUES(
   624    625         'CREATE TABLE x1(i INTEGER, t TEXT)',
   625    626         'table', 'x1', 'main', 'x1', -1, 'zzz', 0
   626    627     ), (
   627    628         'CREATE TABLE x1(i INTEGER, t TEXT)',
................................................................................
   636    637   } {}
   637    638   
   638    639   do_execsql_test 14.2 {
   639    640     SELECT 
   640    641     sqlite_rename_column(sql, type, object, db, tbl, icol, znew, bquote, 0)
   641    642     FROM ddd;
   642    643   } {{} {} {} {}}
          644  +sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 0
          645  +
          646  +# If the INTERNAL_FUNCTIONS test-control is disabled (which is the default)
          647  +# then the sqlite_rename_table() SQL function is not accessible to
          648  +# ordinary SQL.
          649  +#
          650  +do_catchsql_test 14.3 {
          651  +  SELECT sqlite_rename_column(0,0,0,0,0,0,0,0,0);
          652  +} {1 {no such function: sqlite_rename_column}}
   643    653   
   644    654   #-------------------------------------------------------------------------
   645    655   #
   646    656   reset_db
   647    657   do_execsql_test 15.0 {
   648    658     CREATE TABLE xxx(a, b, c);
   649    659     SELECT a AS d FROM xxx WHERE d=0;

Changes to test/altertab.test.

   236    236       ), (
   237    237           'main', 'CREATE TABLE x1(i INTEGER, t TEXT)', NULL, 'eee', 0
   238    238       ), (
   239    239           'main', NULL, 'ddd', 'eee', 0
   240    240       );
   241    241     } {}
   242    242     
          243  +  sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 1
   243    244     do_execsql_test 7.2 {
   244    245       SELECT 
   245    246       sqlite_rename_table(db, 0, 0, sql, zOld, zNew, bTemp)
   246    247       FROM ddd;
   247    248     } {{} {} {}}
          249  +  sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 0
   248    250   }
   249    251   
   250    252   #-------------------------------------------------------------------------
   251    253   #
   252    254   reset_db
   253    255   forcedelete test.db2
   254    256   do_execsql_test 8.1 {

Changes to test/attach.test.

   725    725         END;
   726    726       } db2
   727    727     } {1 {trigger r5 cannot reference objects in database temp}}
   728    728   } ;# endif subquery
   729    729   ifcapable json1 {
   730    730     do_test attach-5.10 {
   731    731       db close
          732  +    catch {db2 close}
   732    733       forcedelete test.db
   733    734       sqlite3 db test.db
   734    735       db eval {
   735    736         CREATE TABLE t1(x);
   736    737         CREATE TABLE t2(a,b);
   737    738         CREATE TRIGGER x1 AFTER INSERT ON t1 BEGIN
   738    739           INSERT INTO t2(a,b) SELECT key, value FROM json_each(NEW.x);

Changes to test/bestindex4.test.

   151    151   }
   152    152   
   153    153   do_execsql_test 2.0 {
   154    154     CREATE VIRTUAL TABLE x1 USING tcl(vtab_command);
   155    155     CREATE TABLE t1 (x INT PRIMARY KEY);
   156    156   } {}
   157    157   
   158         -do_execsql_test 2.1 {
   159         -  EXPLAIN QUERY PLAN SELECT * FROM t1, x1 WHERE x1.d=t1.x;
          158  +do_eqp_test 2.1 {
          159  +  SELECT * FROM t1, x1 WHERE x1.d=t1.x;
   160    160   } {
   161         -  3 0 0 {SCAN TABLE x1 VIRTUAL TABLE INDEX 0:}
   162         -  7 0 0 {SEARCH TABLE t1 USING COVERING INDEX sqlite_autoindex_t1_1 (x=?)}
          161  +  QUERY PLAN
          162  +  |--SCAN TABLE x1 VIRTUAL TABLE INDEX 0:
          163  +  `--SEARCH TABLE t1 USING COVERING INDEX sqlite_autoindex_t1_1 (x=?)
   163    164   }
   164    165   
   165         -do_execsql_test 2.2 {
   166         -  EXPLAIN QUERY PLAN SELECT * FROM t1, x1(t1.x)
          166  +do_eqp_test 2.2 {
          167  +  SELECT * FROM t1, x1(t1.x)
   167    168   } {
   168         -  3 0 0 {SCAN TABLE t1} 
   169         -  5 0 0 {SCAN TABLE x1 VIRTUAL TABLE INDEX 555:}
          169  +  QUERY PLAN
          170  +  |--SCAN TABLE t1
          171  +  `--SCAN TABLE x1 VIRTUAL TABLE INDEX 555:
   170    172   }
   171    173   
   172    174   
   173    175   finish_test

Changes to test/csv01.test.

    33     33   } {9 10 11 12}
    34     34   do_execsql_test 1.1 {
    35     35     SELECT * FROM t1 WHERE c1='10';
    36     36   } {9 10 11 12}
    37     37   do_execsql_test 1.2 {
    38     38     SELECT rowid FROM t1;
    39     39   } {1 2 3 4}
           40  +
           41  +do_execsql_test 1.3 {
           42  +  DROP TABLE temp.t1;
           43  +  CREATE VIRTUAL TABLE temp.t1 USING csv(
           44  +    data=
           45  +'a,b,"mix-bloom-eel","soft opinion"
           46  +1,2,3,4
           47  +5,6,7,8
           48  +9,10,11,12
           49  +13,14,15,16
           50  +',
           51  +    header=1
           52  +  );
           53  +  SELECT * FROM t1 WHERE "soft opinion"=12;
           54  +} {9 10 11 12}
           55  +do_execsql_test 1.4 {
           56  +  SELECT name FROM pragma_table_xinfo('t1');
           57  +} {a b mix-bloom-eel {soft opinion}}
           58  +
           59  +do_execsql_test 1.5 {
           60  +  DROP TABLE temp.t1;
           61  +  CREATE VIRTUAL TABLE temp.t1 USING csv(
           62  +    data=
           63  +'a,b,"mix-bloom-eel","soft opinion"
           64  +1,2,3,4
           65  +5,6,7,8
           66  +9,10,11,12
           67  +13,14,15,16
           68  +',
           69  +    header=false
           70  +  );
           71  +  SELECT * FROM t1 WHERE c1='b';
           72  +} {a b mix-bloom-eel {soft opinion}}
           73  +do_execsql_test 1.6 {
           74  +  SELECT name FROM pragma_table_xinfo('t1');
           75  +} {c0 c1 c2 c3}
           76  +
           77  +do_execsql_test 1.7 {
           78  +  DROP TABLE temp.t1;
           79  +  CREATE VIRTUAL TABLE temp.t1 USING csv(
           80  +    data=
           81  +'a,b,"mix-bloom-eel","soft opinion"
           82  +1,2,3,4
           83  +5,6,7,8
           84  +9,10,11,12
           85  +13,14,15,16
           86  +',
           87  +    header,
           88  +    schema='CREATE TABLE x(x0,x1,x2,x3,x4)',
           89  +    columns=5
           90  +  );
           91  +  SELECT * FROM t1 WHERE x1='6';
           92  +} {5 6 7 8 {}}
           93  +do_execsql_test 1.8 {
           94  +  SELECT name FROM pragma_table_xinfo('t1');
           95  +} {x0 x1 x2 x3 x4}
           96  +
    40     97   
    41     98   do_execsql_test 2.0 {
    42     99     DROP TABLE t1;
    43    100     CREATE VIRTUAL TABLE temp.t2 USING csv(
    44    101       data=
    45    102   '1,2,3,4
    46    103   5,6,7,8
................................................................................
   103    160   9,10,11,12
   104    161   13,14,15,16',
   105    162       columns=4,
   106    163       schema=
   107    164         'CREATE TABLE t3(a,b,c,d,PRIMARY KEY(a,b)) WITHOUT ROWID',
   108    165       testflags=1
   109    166     );
   110         -} {1 {vtable constructor failed: t4}}
          167  +} {1 {bad schema: 'CREATE TABLE t3(a,b,c,d,PRIMARY KEY(a,b)) WITHOUT ROWID' - not an error}}
   111    168   
   112    169   # WITHOUT ROWID tables with a single-column PRIMARY KEY may be writable.
   113    170   do_catchsql_test 4.1 {
   114    171     DROP TABLE IF EXISTS t4;
   115    172     CREATE VIRTUAL TABLE temp.t4 USING csv_wr(
   116    173       data=
   117    174   '1,2,3,4
................................................................................
   134    191         9,10,11,12
   135    192         13,14,15,16',
   136    193         columns=4,
   137    194         schema=
   138    195         'CREATE TABLE t3(a,b,c,d) WITHOUT ROWID',
   139    196         testflags=1
   140    197         );
   141         -} {1 {vtable constructor failed: t5}}
          198  +} {1 {bad schema: 'CREATE TABLE t3(a,b,c,d) WITHOUT ROWID' - PRIMARY KEY missing on table t3}}
   142    199   
   143    200   # 2018-04-24
   144    201   # Memory leak reported on the sqlite-users mailing list by Ralf Junker.
   145    202   #
   146    203   do_catchsql_test 4.3 {
   147    204     CREATE VIRTUAL TABLE IF NOT EXISTS temp.t1
   148    205     USING csv(filename='FileDoesNotExist.csv');

Changes to test/e_fkey.test.

  2793   2793         SELECT sql FROM sqlite_master WHERE name = 'c';
  2794   2794       ROLLBACK;
  2795   2795     }
  2796   2796   } {{CREATE TABLE c(b REFERENCES "parent"(a))}}
  2797   2797   do_test e_fkey-61.2.2 {
  2798   2798     execsql {
  2799   2799       PRAGMA foreign_keys = OFF;
         2800  +    PRAGMA legacy_alter_table = ON;
  2800   2801       ALTER TABLE p RENAME TO parent;
  2801   2802       SELECT sql FROM sqlite_master WHERE name = 'c';
  2802   2803     }
  2803   2804   } {{CREATE TABLE c(b REFERENCES p(a))}}
  2804   2805   do_test e_fkey-61.2.3 {
  2805   2806     execsql { PRAGMA foreign_keys = ON }
         2807  +  execsql { PRAGMA legacy_alter_table = OFF }
  2806   2808   } {}
  2807   2809   
  2808   2810   do_test e_fkey-61.3.1 {
  2809   2811     drop_all_tables
  2810   2812     execsql {
  2811   2813       CREATE TABLE p(a UNIQUE);
  2812   2814       CREATE TABLE c(b REFERENCES p(a) ON DELETE SET NULL);

Changes to test/fkey2.test.

   983    983     # Test the sqlite_rename_parent() function directly.
   984    984     #
   985    985     proc test_rename_parent {zCreate zOld zNew} {
   986    986       db eval {SELECT sqlite_rename_table(
   987    987           'main', 'table', 't1', $zCreate, $zOld, $zNew, 0
   988    988       )}
   989    989     }
          990  +  sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 1
   990    991     do_test fkey2-14.2.1.1 {
   991    992       test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t2 t3
   992    993     } {{CREATE TABLE t1(a REFERENCES "t3")}}
   993    994     do_test fkey2-14.2.1.2 {
   994    995       test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t4 t3
   995    996     } {{CREATE TABLE t1(a REFERENCES t2)}}
   996    997     do_test fkey2-14.2.1.3 {
   997    998       test_rename_parent {CREATE TABLE t1(a REFERENCES "t2")} t2 t3
   998    999     } {{CREATE TABLE t1(a REFERENCES "t3")}}
         1000  +  sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 0
   999   1001     
  1000   1002     # Test ALTER TABLE RENAME TABLE a bit.
  1001   1003     #
  1002   1004     do_test fkey2-14.2.2.1 {
  1003   1005       drop_all_tables
  1004   1006       execsql {
  1005   1007         CREATE TABLE t1(a PRIMARY KEY, b REFERENCES t1);
................................................................................
  1064   1066         PRAGMA foreign_keys = off;
  1065   1067         ALTER TABLE t2 ADD COLUMN h DEFAULT 'text' REFERENCES t1;
  1066   1068         PRAGMA foreign_keys = on;
  1067   1069         SELECT sql FROM temp.sqlite_master WHERE name='t2';
  1068   1070       }
  1069   1071     } {{CREATE TABLE t2(a, b, c REFERENCES t1, d DEFAULT NULL REFERENCES t1, e REFERENCES t1 DEFAULT NULL, h DEFAULT 'text' REFERENCES t1)}}
  1070   1072   
         1073  +  sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 1
  1071   1074     do_test fkey2-14.2tmp.1.1 {
  1072   1075       test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t2 t3
  1073   1076     } {{CREATE TABLE t1(a REFERENCES "t3")}}
  1074   1077     do_test fkey2-14.2tmp.1.2 {
  1075   1078       test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t4 t3
  1076   1079     } {{CREATE TABLE t1(a REFERENCES t2)}}
  1077   1080     do_test fkey2-14.2tmp.1.3 {
  1078   1081       test_rename_parent {CREATE TABLE t1(a REFERENCES "t2")} t2 t3
  1079   1082     } {{CREATE TABLE t1(a REFERENCES "t3")}}
         1083  +  sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 0
  1080   1084     
  1081   1085     # Test ALTER TABLE RENAME TABLE a bit.
  1082   1086     #
  1083   1087     do_test fkey2-14.2tmp.2.1 {
  1084   1088       drop_all_tables
  1085   1089       execsql {
  1086   1090         CREATE TEMP TABLE t1(a PRIMARY KEY, b REFERENCES t1);
................................................................................
  1146   1150         PRAGMA foreign_keys = off;
  1147   1151         ALTER TABLE t2 ADD COLUMN h DEFAULT 'text' REFERENCES t1;
  1148   1152         PRAGMA foreign_keys = on;
  1149   1153         SELECT sql FROM aux.sqlite_master WHERE name='t2';
  1150   1154       }
  1151   1155     } {{CREATE TABLE t2(a, b, c REFERENCES t1, d DEFAULT NULL REFERENCES t1, e REFERENCES t1 DEFAULT NULL, h DEFAULT 'text' REFERENCES t1)}}
  1152   1156   
         1157  +  sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 1
  1153   1158     do_test fkey2-14.2aux.1.1 {
  1154   1159       test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t2 t3
  1155   1160     } {{CREATE TABLE t1(a REFERENCES "t3")}}
  1156   1161     do_test fkey2-14.2aux.1.2 {
  1157   1162       test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t4 t3
  1158   1163     } {{CREATE TABLE t1(a REFERENCES t2)}}
  1159   1164     do_test fkey2-14.2aux.1.3 {
  1160   1165       test_rename_parent {CREATE TABLE t1(a REFERENCES "t2")} t2 t3
  1161   1166     } {{CREATE TABLE t1(a REFERENCES "t3")}}
         1167  +  sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 0
  1162   1168     
  1163   1169     # Test ALTER TABLE RENAME TABLE a bit.
  1164   1170     #
  1165   1171     do_test fkey2-14.2aux.2.1 {
  1166   1172       drop_all_tables
  1167   1173       execsql {
  1168   1174         CREATE TABLE aux.t1(a PRIMARY KEY, b REFERENCES t1);

Changes to test/fuzzcheck.c.

   401    401   }
   402    402   
   403    403   
   404    404   /* Return the current wall-clock time */
   405    405   static sqlite3_int64 timeOfDay(void){
   406    406     static sqlite3_vfs *clockVfs = 0;
   407    407     sqlite3_int64 t;
   408         -  if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(0);
          408  +  if( clockVfs==0 ){
          409  +    clockVfs = sqlite3_vfs_find(0);
          410  +    if( clockVfs==0 ) return 0;
          411  +  }
   409    412     if( clockVfs->iVersion>=1 && clockVfs->xCurrentTimeInt64!=0 ){
   410    413       clockVfs->xCurrentTimeInt64(clockVfs, &t);
   411    414     }else{
   412    415       double r;
   413    416       clockVfs->xCurrentTime(clockVfs, &r);
   414    417       t = (sqlite3_int64)(r*86400000.0);
   415    418     }
................................................................................
   862    865     void *pHeap = 0;             /* Heap for use by SQLite */
   863    866     int ossFuzz = 0;             /* enable OSS-FUZZ testing */
   864    867     int ossFuzzThisDb = 0;       /* ossFuzz value for this particular database */
   865    868     int nativeMalloc = 0;        /* Turn off MEMSYS3/5 and lookaside if true */
   866    869     sqlite3_vfs *pDfltVfs;       /* The default VFS */
   867    870     int openFlags4Data;          /* Flags for sqlite3_open_v2() */
   868    871   
          872  +  sqlite3_initialize();
   869    873     iBegin = timeOfDay();
   870    874   #ifdef __unix__
   871    875     signal(SIGALRM, timeoutHandler);
   872    876   #endif
   873    877     g.zArgv0 = argv[0];
   874    878     openFlags4Data = SQLITE_OPEN_READONLY;
   875    879     zFailCode = getenv("TEST_FAILURE");

Changes to test/fuzzdata7.db.

cannot compute difference between binary files

Changes to test/incrvacuum.test.

   778    778     catchsql {INSERT INTO t2 SELECT * FROM t1}
   779    779   
   780    780     execsql { 
   781    781       COMMIT;
   782    782       PRAGMA integrity_check;
   783    783     }
   784    784   } {ok}
          785  +
          786  +#-------------------------------------------------------------------------
          787  +# At one point it was unsafe to truncate a db file on windows while there
          788  +# were outstanding xFetch() references. This test case attempts to hit
          789  +# that case.
          790  +#
          791  +reset_db
          792  +do_execsql_test incrvacuum-16.0 {
          793  +  PRAGMA auto_vacuum = 2;
          794  +  CREATE TABLE t3(a);
          795  +  INSERT INTO t3 VALUES(1), (2), (3), (4);
          796  +
          797  +  CREATE TABLE t2(x);
          798  +  INSERT INTO t2 VALUES( randomblob(1000) );
          799  +  INSERT INTO t2 VALUES( randomblob(1000) );
          800  +  INSERT INTO t2 VALUES( randomblob(1000) );
          801  +  INSERT INTO t2 VALUES( randomblob(1000) );
          802  +  INSERT INTO t2 VALUES( randomblob(1000) );
          803  +  INSERT INTO t2 VALUES( randomblob(1000) );
          804  +} {}
          805  +
          806  +# Reopen db to ensure the page-cache is empty.
          807  +#
          808  +db close
          809  +sqlite3 db test.db
          810  +
          811  +# Open db in mmap-mode. Open a transaction, delete some data, then run
          812  +# incremental-vacuum. Do not commit the transaction. 
          813  +#
          814  +do_execsql_test incrvacuum-16.1 {
          815  +  PRAGMA mmap_size = 1000000;
          816  +  BEGIN;
          817  +  DELETE FROM t2;
          818  +  PRAGMA incremental_vacuum = 1000;
          819  +} {1000000}
          820  +
          821  +# Scan through table t3 (which is all clean pages - so mmap is used). Then,
          822  +# midway through, commit the transaction. This causes the db to be truncated
          823  +# while there are outstanding xFetch pages.
          824  +#
          825  +do_test incrvacuum-16.2 {
          826  +  set res [list]
          827  +  db eval { SELECT a FROM t3 } {
          828  +    if {$a==3} { db eval COMMIT }
          829  +    lappend res $a
          830  +  }
          831  +  set res
          832  +} {1 2 3 4}
   785    833   
   786    834   finish_test

Changes to test/loadext.test.

    57     57   #
    58     58   set dlerror_nosuchfile \
    59     59       {%s: cannot open shared object file: No such file or directory}
    60     60   set dlerror_notadll    {%s: file too short}
    61     61   set dlerror_nosymbol   {%s: undefined symbol: %s}
    62     62   
    63     63   if {$::tcl_platform(os) eq "Darwin"} {
    64         -  set dlerror_nosuchfile {dlopen(%s, 10): image not found}
    65         -  set dlerror_notadll    {dlopen(%1$s, 10): no suitable image found.*}
    66         -  set dlerror_nosymbol   {dlsym(XXX, %2$s): symbol not found}
           64  +  set dlerror_nosuchfile {dlopen.%s, 10.: .*image.*found.*}
           65  +  set dlerror_notadll    {dlopen.%1$s, 10.: .*image.*found.*}
           66  +  set dlerror_nosymbol   {dlsym.XXX, %2$s.: symbol not found}
    67     67   }
    68     68   
    69     69   if {$::tcl_platform(platform) eq "windows"} {
    70     70     set dlerror_nosuchfile {The specified module could not be found.*}
    71     71     set dlerror_notadll    {%%1 is not a valid Win32 application.*}
    72     72     set dlerror_nosymbol   {The specified procedure could not be found.*}
    73     73   }

Changes to test/ossfuzz.c.

    32     32   
    33     33   /* Return the current real-world time in milliseconds since the
    34     34   ** Julian epoch (-4714-11-24).
    35     35   */
    36     36   static sqlite3_int64 timeOfDay(void){
    37     37     static sqlite3_vfs *clockVfs = 0;
    38     38     sqlite3_int64 t;
    39         -  if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(0);
           39  +  if( clockVfs==0 ){
           40  +    clockVfs = sqlite3_vfs_find(0);
           41  +    if( clockVfs==0 ) return 0;
           42  +  }
    40     43     if( clockVfs->iVersion>=2 && clockVfs->xCurrentTimeInt64!=0 ){
    41     44       clockVfs->xCurrentTimeInt64(clockVfs, &t);
    42     45     }else{
    43     46       double r;
    44     47       clockVfs->xCurrentTime(clockVfs, &r);
    45     48       t = (sqlite3_int64)(r*86400000.0);
    46     49     }
................................................................................
    52     55   */
    53     56   typedef struct FuzzCtx {
    54     57     sqlite3 *db;               /* The database connection */
    55     58     sqlite3_int64 iCutoffTime; /* Stop processing at this time. */
    56     59     sqlite3_int64 iLastCb;     /* Time recorded for previous progress callback */
    57     60     sqlite3_int64 mxInterval;  /* Longest interval between two progress calls */
    58     61     unsigned nCb;              /* Number of progress callbacks */
           62  +  unsigned execCnt;          /* Number of calls to the sqlite3_exec callback */
    59     63   } FuzzCtx;
    60     64   
    61         -#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
    62     65   /*
    63     66   ** Progress handler callback.
    64     67   **
    65     68   ** The argument is the cutoff-time after which all processing should
    66     69   ** stop.  So return non-zero if the cut-off time is exceeded.
    67     70   */
    68     71   static int progress_handler(void *pClientData) {
................................................................................
    70     73     sqlite3_int64 iNow = timeOfDay();
    71     74     int rc = iNow>=p->iCutoffTime;
    72     75     sqlite3_int64 iDiff = iNow - p->iLastCb;
    73     76     if( iDiff > p->mxInterval ) p->mxInterval = iDiff;
    74     77     p->nCb++;
    75     78     return rc;
    76     79   }
    77         -#endif
    78     80   
    79     81   /*
    80     82   ** Disallow debugging pragmas such as "PRAGMA vdbe_debug" and
    81     83   ** "PRAGMA parser_trace" since they can dramatically increase the
    82     84   ** amount of output without actually testing anything useful.
    83     85   */
    84     86   static int block_debug_pragmas(
................................................................................
    97     99     }
    98    100     return SQLITE_OK;
    99    101   }
   100    102   
   101    103   /*
   102    104   ** Callback for sqlite3_exec().
   103    105   */
   104         -static int exec_handler(void *pCnt, int argc, char **argv, char **namev){
          106  +static int exec_handler(void *pClientData, int argc, char **argv, char **namev){
          107  +  FuzzCtx *p = (FuzzCtx*)pClientData;
   105    108     int i;
   106    109     if( argv ){
   107    110       for(i=0; i<argc; i++) sqlite3_free(sqlite3_mprintf("%s", argv[i]));
   108    111     }
   109         -  return ((*(int*)pCnt)--)<=0;
          112  +  return (p->execCnt--)<=0 || progress_handler(pClientData);
   110    113   }
   111    114   
   112    115   /*
   113    116   ** Main entry point.  The fuzzer invokes this function with each
   114    117   ** fuzzed input.
   115    118   */
   116    119   int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
   117         -  int execCnt = 0;         /* Abort row callback when count reaches zero */
   118    120     char *zErrMsg = 0;       /* Error message returned by sqlite_exec() */
   119    121     uint8_t uSelector;       /* First byte of input data[] */
   120    122     int rc;                  /* Return code from various interfaces */
   121    123     char *zSql;              /* Zero-terminated copy of data[] */
   122    124     FuzzCtx cx;              /* Fuzzing context */
   123    125   
   124    126     memset(&cx, 0, sizeof(cx));
................................................................................
   130    132     if( data[1]=='\n' ){
   131    133       uSelector = data[0];  data += 2; size -= 2;
   132    134     }else{
   133    135       uSelector = 0xfd;
   134    136     }
   135    137   
   136    138     /* Open the database connection.  Only use an in-memory database. */
          139  +  if( sqlite3_initialize() ) return 0;
   137    140     rc = sqlite3_open_v2("fuzz.db", &cx.db,
   138    141              SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_MEMORY, 0);
   139    142     if( rc ) return 0;
   140    143   
   141         -#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
   142    144     /* Invoke the progress handler frequently to check to see if we
   143    145     ** are taking too long.  The progress handler will return true
   144    146     ** (which will block further processing) if more than 10 seconds have
   145    147     ** elapsed since the start of the test.
   146    148     */
   147    149     cx.iLastCb = timeOfDay();
   148    150     cx.iCutoffTime = cx.iLastCb + 10000;  /* Now + 10 seconds */
          151  +#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
   149    152     sqlite3_progress_handler(cx.db, 10, progress_handler, (void*)&cx);
   150    153   #endif
   151    154   
   152    155     /* Set a limit on the maximum size of a prepared statement */
   153    156     sqlite3_limit(cx.db, SQLITE_LIMIT_VDBE_OP, 25000);
   154    157   
   155    158     /* Bit 1 of the selector enables foreign key constraints */
................................................................................
   157    160     uSelector >>= 1;
   158    161   
   159    162     /* Do not allow debugging pragma statements that might cause excess output */
   160    163     sqlite3_set_authorizer(cx.db, block_debug_pragmas, 0);
   161    164   
   162    165     /* Remaining bits of the selector determine a limit on the number of
   163    166     ** output rows */
   164         -  execCnt = uSelector + 1;
          167  +  cx.execCnt = uSelector + 1;
   165    168   
   166    169     /* Run the SQL.  The sqlite_exec() interface expects a zero-terminated
   167    170     ** string, so make a copy. */
   168    171     zSql = sqlite3_mprintf("%.*s", (int)size, data);
   169    172   #ifndef SQLITE_OMIT_COMPLETE
   170    173     sqlite3_complete(zSql);
   171    174   #endif
   172         -  sqlite3_exec(cx.db, zSql, exec_handler, (void*)&execCnt, &zErrMsg);
          175  +  sqlite3_exec(cx.db, zSql, exec_handler, (void*)&cx, &zErrMsg);
   173    176   
   174    177     /* Show any errors */
   175    178     if( (mDebug & FUZZ_SHOW_ERRORS)!=0 && zErrMsg ){
   176    179       printf("Error: %s\n", zErrMsg);
   177    180     }
   178    181   
   179    182     /* Cleanup and return */

Changes to test/pragma4.test.

    98     98       CREATE TABLE t2(y);
    99     99       DROP TABLE t1;
   100    100     }
   101    101     string map {\[ x \] x \173 {} \175 {}} \
   102    102       [db eval {EXPLAIN PRAGMA integrity_check}]
   103    103   } {/ IntegrityCk 2 2 1 x[0-9]+,1x /}
   104    104   
          105  +
          106  +#--------------------------------------------------------------------------
          107  +#
          108  +reset_db
          109  +forcedelete test.db2
          110  +do_execsql_test 4.1.1 {
          111  +  CREATE TABLE t1(a, b, c);
          112  +  ATTACH 'test.db2' AS aux;
          113  +  CREATE TABLE aux.t2(d, e, f);
          114  +}
          115  +do_execsql_test 4.1.2 { PRAGMA table_info = t1 } {
          116  +  0 a {} 0 {} 0 1 b {} 0 {} 0 2 c {} 0 {} 0
          117  +}
          118  +do_execsql_test 4.1.3 { PRAGMA table_info = t2 } {
          119  +  0 d {} 0 {} 0 1 e {} 0 {} 0 2 f {} 0 {} 0
          120  +}
          121  +do_test 4.1.4 { 
          122  +  sqlite3 db3 test.db
          123  +  sqlite3 db2 test.db2
          124  +  execsql { DROP TABLE t1 } db3
          125  +  execsql { DROP TABLE t2 } db2
          126  +} {}
          127  +do_execsql_test 4.1.5 { PRAGMA table_info = t1 }
          128  +do_execsql_test 4.1.6 { PRAGMA table_info = t2 }
          129  +
          130  +db2 close
          131  +db3 close
          132  +reset_db
          133  +forcedelete test.db2
          134  +do_execsql_test 4.2.1 {
          135  +  CREATE TABLE t1(a, b, c);
          136  +  ATTACH 'test.db2' AS aux;
          137  +  CREATE TABLE aux.t2(d, e, f);
          138  +}
          139  +do_execsql_test 4.2.2 { SELECT * FROM pragma_table_info('t1') } {
          140  +  0 a {} 0 {} 0 1 b {} 0 {} 0 2 c {} 0 {} 0
          141  +}
          142  +do_execsql_test 4.2.3 { SELECT * FROM pragma_table_info('t2') } {
          143  +  0 d {} 0 {} 0 1 e {} 0 {} 0 2 f {} 0 {} 0
          144  +}
          145  +do_test 4.2.4 { 
          146  +  sqlite3 db3 test.db
          147  +  sqlite3 db2 test.db2
          148  +  execsql { DROP TABLE t1 } db3
          149  +  execsql { DROP TABLE t2 } db2
          150  +} {}
          151  +do_execsql_test 4.2.5 { SELECT * FROM pragma_table_info('t1') } 
          152  +do_execsql_test 4.2.6 { SELECT * FROM pragma_table_info('t2') } 
          153  +
          154  +db2 close
          155  +db3 close
          156  +reset_db
          157  +forcedelete test.db2
          158  +do_execsql_test 4.3.1 {
          159  +  CREATE TABLE t1(a, b, c);
          160  +  CREATE INDEX i1 ON t1(b);
          161  +  ATTACH 'test.db2' AS aux;
          162  +  CREATE TABLE aux.t2(d, e, f);
          163  +  CREATE INDEX aux.i2 ON t2(e);
          164  +}
          165  +do_execsql_test 4.3.2 { SELECT * FROM pragma_index_info('i1') } {0 1 b}
          166  +do_execsql_test 4.3.3 { SELECT * FROM pragma_index_info('i2') } {0 1 e}
          167  +do_test 4.3.4 { 
          168  +  sqlite3 db3 test.db
          169  +  sqlite3 db2 test.db2
          170  +  execsql { DROP INDEX i1 } db3
          171  +  execsql { DROP INDEX i2 } db2
          172  +} {}
          173  +do_execsql_test 4.3.5 { SELECT * FROM pragma_index_info('i1') } 
          174  +do_execsql_test 4.3.6 { SELECT * FROM pragma_index_info('i2') } 
          175  +
          176  +do_execsql_test 4.4.0 {
          177  +  CREATE INDEX main.i1 ON t1(b, c);
          178  +  CREATE INDEX aux.i2 ON t2(e, f);
          179  +}
          180  +do_execsql_test 4.4.1 { SELECT * FROM pragma_index_list('t1') } {0 i1 0 c 0}
          181  +do_execsql_test 4.4.2 { SELECT * FROM pragma_index_list('t2') } {0 i2 0 c 0}
          182  +do_test 4.4.3 { 
          183  +  execsql { DROP INDEX i1 } db3
          184  +  execsql { DROP INDEX i2 } db2
          185  +} {}
          186  +do_execsql_test 4.4.5 { SELECT * FROM pragma_index_list('t1') } {}
          187  +do_execsql_test 4.4.6 { SELECT * FROM pragma_index_list('t2') } {}
          188  +
          189  +do_execsql_test 4.5.0 {
          190  +  CREATE UNIQUE INDEX main.i1 ON t1(a);
          191  +  CREATE UNIQUE INDEX aux.i2 ON t2(d);
          192  +  CREATE TABLE main.c1 (a, b, c REFERENCES t1(a));
          193  +  CREATE TABLE aux.c2 (d, e, r REFERENCES t2(d));
          194  +}
          195  +do_execsql_test 4.5.1 { SELECT * FROM pragma_foreign_key_list('c1') } {
          196  +  0 0 t1 c a {NO ACTION} {NO ACTION} NONE
          197  +}
          198  +do_execsql_test 4.5.2 { SELECT * FROM pragma_foreign_key_list('c2') } {
          199  +  0 0 t2 r d {NO ACTION} {NO ACTION} NONE
          200  +}
          201  +do_test 4.5.3 { 
          202  +  execsql { DROP TABLE c1 } db3
          203  +  execsql { DROP TABLE c2 } db2
          204  +} {}
          205  +do_execsql_test 4.5.1 { SELECT * FROM pragma_foreign_key_list('c1') }
          206  +do_execsql_test 4.5.2 { SELECT * FROM pragma_foreign_key_list('c2') } 
          207  +
          208  +do_execsql_test 4.6.0 {
          209  +  CREATE TABLE main.c1 (a, b, c REFERENCES t1(a));
          210  +  CREATE TABLE aux.c2 (d, e, r REFERENCES t2(d));
          211  +  INSERT INTO main.c1 VALUES(1, 2, 3);
          212  +  INSERT INTO aux.c2 VALUES(4, 5, 6);
          213  +}
          214  +do_execsql_test 4.6.1 { pragma foreign_key_check('c1') } {
          215  +  c1 1 t1 0
          216  +}
          217  +do_execsql_test 4.6.2 { pragma foreign_key_check('c2') } {
          218  +  c2 1 t2 0
          219  +}
          220  +do_test 4.6.3 { 
          221  +  execsql { DROP TABLE c2 } db2
          222  +} {}
          223  +do_execsql_test 4.6.4 { pragma foreign_key_check('c1') } {c1 1 t1 0}
          224  +do_catchsql_test 4.6.5 { 
          225  +  pragma foreign_key_check('c2') 
          226  +} {1 {no such table: c2}}
          227  +
   105    228   finish_test
          229  +

Changes to test/tempdb2.test.

    72     72     ROLLBACK;
    73     73   }
    74     74   
    75     75   do_execsql_test 1.4 {
    76     76     SELECT b=int2str(2) FROM t1
    77     77   } {1 1 1}
    78     78   
           79  +#-------------------------------------------------------------------------
           80  +db close
           81  +sqlite3 db ""
           82  +db func int2str int2str
           83  +
           84  +do_execsql_test 2.0 {
           85  +  PRAGMA cache_size = -100;
           86  +  CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
           87  +  WITH c(x) AS ( VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100 ) 
           88  +    INSERT INTO t1 SELECT x, int2str(x) FROM c;
           89  +}
           90  +
           91  +do_execsql_test 2.1 {
           92  +  INSERT INTO t1 VALUES(10001, int2str(1001) || int2str(1001) || int2str(1001));
           93  +}
           94  +
           95  +do_execsql_test 2.2 {
           96  +  SELECT b FROM t1 WHERE a = 10001;
           97  +} "[int2str 1001][int2str 1001][int2str 1001]"
           98  +
    79     99   finish_test
          100  +

Changes to test/without_rowid3.test.

   949    949     # Test the sqlite_rename_parent() function directly.
   950    950     #
   951    951     proc test_rename_parent {zCreate zOld zNew} {
   952    952       db eval {SELECT sqlite_rename_table(
   953    953           'main', 'table', 't1', $zCreate, $zOld, $zNew, 0
   954    954       )}
   955    955     }
          956  +  sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 1
   956    957     do_test without_rowid3-14.2.1.1 {
   957    958       test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t2 t3
   958    959     } {{CREATE TABLE t1(a REFERENCES "t3")}}
   959    960     do_test without_rowid3-14.2.1.2 {
   960    961       test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t4 t3
   961    962     } {{CREATE TABLE t1(a REFERENCES t2)}}
   962    963     do_test without_rowid3-14.2.1.3 {
   963    964       test_rename_parent {CREATE TABLE t1(a REFERENCES "t2")} t2 t3
   964    965     } {{CREATE TABLE t1(a REFERENCES "t3")}}
          966  +  sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 0
   965    967     
   966    968     # Test ALTER TABLE RENAME TABLE a bit.
   967    969     #
   968    970     do_test without_rowid3-14.2.2.1 {
   969    971       drop_all_tables
   970    972       execsql {
   971    973         CREATE TABLE t1(a PRIMARY KEY, b REFERENCES t1) WITHOUT rowid;
................................................................................
  1033   1035         PRAGMA foreign_keys = off;
  1034   1036         ALTER TABLE t2 ADD COLUMN h DEFAULT 'text' REFERENCES t1;
  1035   1037         PRAGMA foreign_keys = on;
  1036   1038         SELECT sql FROM temp.sqlite_master WHERE name='t2';
  1037   1039       }
  1038   1040     } {{CREATE TABLE t2(a, b, c REFERENCES t1, d DEFAULT NULL REFERENCES t1, e REFERENCES t1 DEFAULT NULL, h DEFAULT 'text' REFERENCES t1)}}
  1039   1041   
         1042  +  sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 1
  1040   1043     do_test without_rowid3-14.2tmp.1.1 {
  1041   1044       test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t2 t3
  1042   1045     } {{CREATE TABLE t1(a REFERENCES "t3")}}
  1043   1046     do_test without_rowid3-14.2tmp.1.2 {
  1044   1047       test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t4 t3
  1045   1048     } {{CREATE TABLE t1(a REFERENCES t2)}}
  1046   1049     do_test without_rowid3-14.2tmp.1.3 {
  1047   1050       test_rename_parent {CREATE TABLE t1(a REFERENCES "t2")} t2 t3
  1048   1051     } {{CREATE TABLE t1(a REFERENCES "t3")}}
         1052  +  sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 0
  1049   1053     
  1050   1054     # Test ALTER TABLE RENAME TABLE a bit.
  1051   1055     #
  1052   1056     do_test without_rowid3-14.2tmp.2.1 {
  1053   1057       drop_all_tables
  1054   1058       execsql {
  1055   1059         CREATE TEMP TABLE t1(a PRIMARY KEY, b REFERENCES t1) WITHOUT rowid;
................................................................................
  1118   1122         PRAGMA foreign_keys = off;
  1119   1123         ALTER TABLE t2 ADD COLUMN h DEFAULT 'text' REFERENCES t1;
  1120   1124         PRAGMA foreign_keys = on;
  1121   1125         SELECT sql FROM aux.sqlite_master WHERE name='t2';
  1122   1126       }
  1123   1127     } {{CREATE TABLE t2(a, b, c REFERENCES t1, d DEFAULT NULL REFERENCES t1, e REFERENCES t1 DEFAULT NULL, h DEFAULT 'text' REFERENCES t1)}}
  1124   1128   
         1129  +  sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 1
  1125   1130     do_test without_rowid3-14.2aux.1.1 {
  1126   1131       test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t2 t3
  1127   1132     } {{CREATE TABLE t1(a REFERENCES "t3")}}
  1128   1133     do_test without_rowid3-14.2aux.1.2 {
  1129   1134       test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t4 t3
  1130   1135     } {{CREATE TABLE t1(a REFERENCES t2)}}
  1131   1136     do_test without_rowid3-14.2aux.1.3 {
  1132   1137       test_rename_parent {CREATE TABLE t1(a REFERENCES "t2")} t2 t3
  1133   1138     } {{CREATE TABLE t1(a REFERENCES "t3")}}
         1139  +  sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS 0
  1134   1140     
  1135   1141     # Test ALTER TABLE RENAME TABLE a bit.
  1136   1142     #
  1137   1143     do_test without_rowid3-14.2aux.2.1 {
  1138   1144       drop_all_tables
  1139   1145       execsql {
  1140   1146         CREATE TABLE aux.t1(a PRIMARY KEY, b REFERENCES t1) WITHOUT rowid;

Changes to test/zipfile.test.

   757    757     SELECT name, data FROM z ORDER BY name;
   758    758   } {b0 two b2 one}
   759    759   do_execsql_test 11.11 {
   760    760     UPDATE z SET name = name || 'suffix';
   761    761     SELECT name, data FROM z ORDER BY name;
   762    762   } {b0suffix two b2suffix one}
   763    763   
          764  +
          765  +if {$tcl_platform(platform)!="windows"} {
          766  +  do_test 12.0 {
          767  +    catch { file delete -force subdir }
          768  +    foreach {path sz} {
          769  +      subdir/x1.txt     143
          770  +      subdir/x2.txt     153
          771  +    } {
          772  +      set dir [file dirname $path]
          773  +      catch { file mkdir $dir }
          774  +      set fd [open $path w]
          775  +      puts -nonewline $fd [string repeat 1 $sz]
          776  +      close $fd
          777  +    }
          778  +  } {}
          779  +  
          780  +  do_execsql_test 12.1 {
          781  +    SELECT name FROM fsdir('subdir') ORDER BY 1;
          782  +  } {subdir subdir/x1.txt subdir/x2.txt}
          783  +  
          784  +  do_execsql_test 12.2 {
          785  +    CREATE TABLE d AS SELECT 'subdir' d;
          786  +    CREATE TABLE x AS SELECT 1 x;
          787  +  }
          788  +  
          789  +  do_execsql_test 12.4 {
          790  +    SELECT name FROM d JOIN x JOIN fsdir(d) ORDER BY 1;
          791  +  } {subdir subdir/x1.txt subdir/x2.txt}
          792  +
          793  +  do_execsql_test 12.5 {
          794  +    SELECT name FROM d JOIN x JOIN fsdir('.', d) ORDER BY 1;
          795  +  } {. ./x1.txt ./x2.txt}
          796  +}
          797  +
   764    798   finish_test

Changes to tool/warnings.sh.

    12     12     # Use these for testing on Linux and Mac OSX:
    13     13     WARNING_OPTS="-Wshadow -Wall -Wextra -pedantic-errors -Wno-long-long"
    14     14     WARNING_ANDROID_OPTS="-Wshadow -Wall -Wextra"
    15     15   fi
    16     16   
    17     17   rm -f sqlite3.c
    18     18   make sqlite3.c
    19         -echo '********** No optimizations.  Includes FTS4/5, RTREE, JSON1 ***'
           19  +echo '********** No optimizations.  Includes FTS4/5, GEOPOLY, JSON1 ***'
    20     20   echo '**********    ' Options: $WARNING_OPTS
    21     21   gcc -c $WARNING_OPTS -std=c89 \
    22         -      -ansi -DHAVE_STDINT_H -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_RTREE \
           22  +      -ansi -DHAVE_STDINT_H -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_GEOPOLY \
    23     23         -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 \
    24     24         sqlite3.c
    25     25   if test x`uname` = 'xLinux'; then
    26     26   echo '********** Android configuration ******************************'
    27     27   echo '**********    ' Options: $WARNING_ANDROID_OPTS
    28     28   gcc -c \
    29     29     -DHAVE_USLEEP=1 \
................................................................................
    48     48     -Os sqlite3.c shell.c
    49     49   fi
    50     50   echo '********** No optimizations. ENABLE_STAT4. THREADSAFE=0 *******'
    51     51   echo '**********    ' Options: $WARNING_OPTS
    52     52   gcc -c $WARNING_OPTS -std=c89 \
    53     53         -ansi -DSQLITE_ENABLE_STAT4 -DSQLITE_THREADSAFE=0 \
    54     54         sqlite3.c
    55         -echo '********** Optimized -O3.  Includes FTS4/5, RTREE, JSON1 ******'
           55  +echo '********** Optimized -O3.  Includes FTS4/5, GEOPOLY, JSON1 ******'
    56     56   echo '**********    ' Options: $WARNING_OPTS
    57     57   gcc -O3 -c $WARNING_OPTS -std=c89 \
    58         -      -ansi -DHAVE_STDINT_H -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_RTREE \
           58  +      -ansi -DHAVE_STDINT_H -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_GEOPOLY \
    59     59         -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 \
    60     60         sqlite3.c