/ Check-in [9f6f1180]
Login

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

Overview
Comment:Merge changes from trunk.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | upsert
Files: files | file ages | folders
SHA3-256: 9f6f11805eb7cc02f7eb3044250f3981d46d2dbf0c421bd73e7f8b437390db25
User & Date: drh 2018-04-12 12:25:45
Context
2018-04-12
13:15
Add the Upsert object for holding upsert clause information. check-in: d83eaed5 user: drh tags: upsert
12:25
Merge changes from trunk. check-in: 9f6f1180 user: drh tags: upsert
2018-04-11
17:10
Help the parser run faster by avoiding the "explain ::= ." production. check-in: d7ec7b59 user: drh tags: trunk
2018-04-10
00:30
Update the top-level README.md file to point to the whynotget.html document. check-in: 7dfd4543 user: drh tags: upsert
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Makefile.msc.

  1668   1668   $(SQLITE3DLL):	$(LIBOBJ) $(LIBRESOBJS) $(CORE_LINK_DEP)
  1669   1669   	$(LD) $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) /DLL $(CORE_LINK_OPTS) /OUT:$@ $(LIBOBJ) $(LIBRESOBJS) $(LTLIBS) $(TLIBS)
  1670   1670   
  1671   1671   # <<block2>>
  1672   1672   sqlite3.def:	libsqlite3.lib
  1673   1673   	echo EXPORTS > sqlite3.def
  1674   1674   	dumpbin /all libsqlite3.lib \
  1675         -		| $(TCLSH_CMD) $(TOP)\tool\replace.tcl include "^\s+1 _?(sqlite3(?:session|changeset|changegroup)?_[^@]*)(?:@\d+)?$$" \1 \
         1675  +		| $(TCLSH_CMD) $(TOP)\tool\replace.tcl include "^\s+1 _?(sqlite3(?:session|changeset|changegroup|rebaser)?_[^@]*)(?:@\d+)?$$" \1 \
  1676   1676   		| sort >> sqlite3.def
  1677   1677   # <</block2>>
  1678   1678   
  1679   1679   $(SQLITE3EXE):	shell.c $(SHELL_CORE_DEP) $(LIBRESOBJS) $(SHELL_CORE_SRC) $(SQLITE3H)
  1680   1680   	$(LTLINK) $(SHELL_COMPILE_OPTS) $(READLINE_FLAGS) shell.c $(SHELL_CORE_SRC) \
  1681   1681   		/link $(SQLITE3EXEPDB) $(LDFLAGS) $(LTLINKOPTS) $(SHELL_LINK_OPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS)
  1682   1682   

Changes to VERSION.

     1         -3.23.0
            1  +3.23.1

Changes to autoconf/Makefile.msc.

   962    962   
   963    963   Replace.exe:
   964    964   	$(CSC) /target:exe $(TOP)\Replace.cs
   965    965   
   966    966   sqlite3.def:	Replace.exe $(LIBOBJ)
   967    967   	echo EXPORTS > sqlite3.def
   968    968   	dumpbin /all $(LIBOBJ) \
   969         -		| .\Replace.exe "^\s+/EXPORT:_?(sqlite3(?:session|changeset|changegroup)?_[^@,]*)(?:@\d+|,DATA)?$$" $$1 true \
          969  +		| .\Replace.exe "^\s+/EXPORT:_?(sqlite3(?:session|changeset|changegroup|rebaser)?_[^@,]*)(?:@\d+|,DATA)?$$" $$1 true \
   970    970   		| sort >> sqlite3.def
   971    971   
   972    972   $(SQLITE3EXE):	shell.c $(SHELL_CORE_DEP) $(LIBRESOBJS) $(SHELL_CORE_SRC) $(SQLITE3H)
   973    973   	$(LTLINK) $(SHELL_COMPILE_OPTS) $(READLINE_FLAGS) shell.c $(SHELL_CORE_SRC) \
   974    974   		/link $(SQLITE3EXEPDB) $(LDFLAGS) $(LTLINKOPTS) $(SHELL_LINK_OPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS)
   975    975   
   976    976   

Changes to configure.

     1      1   #! /bin/sh
     2      2   # Guess values for system-dependent variables and create Makefiles.
     3         -# Generated by GNU Autoconf 2.69 for sqlite 3.23.0.
            3  +# Generated by GNU Autoconf 2.69 for sqlite 3.23.1.
     4      4   #
     5      5   #
     6      6   # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
     7      7   #
     8      8   #
     9      9   # This configure script is free software; the Free Software Foundation
    10     10   # gives unlimited permission to copy, distribute and modify it.
................................................................................
   722    722   subdirs=
   723    723   MFLAGS=
   724    724   MAKEFLAGS=
   725    725   
   726    726   # Identity of this package.
   727    727   PACKAGE_NAME='sqlite'
   728    728   PACKAGE_TARNAME='sqlite'
   729         -PACKAGE_VERSION='3.23.0'
   730         -PACKAGE_STRING='sqlite 3.23.0'
          729  +PACKAGE_VERSION='3.23.1'
          730  +PACKAGE_STRING='sqlite 3.23.1'
   731    731   PACKAGE_BUGREPORT=''
   732    732   PACKAGE_URL=''
   733    733   
   734    734   # Factoring default headers for most tests.
   735    735   ac_includes_default="\
   736    736   #include <stdio.h>
   737    737   #ifdef HAVE_SYS_TYPES_H
................................................................................
  1461   1461   #
  1462   1462   # Report the --help message.
  1463   1463   #
  1464   1464   if test "$ac_init_help" = "long"; then
  1465   1465     # Omit some internal or obsolete options to make the list less imposing.
  1466   1466     # This message is too long to be a string in the A/UX 3.1 sh.
  1467   1467     cat <<_ACEOF
  1468         -\`configure' configures sqlite 3.23.0 to adapt to many kinds of systems.
         1468  +\`configure' configures sqlite 3.23.1 to adapt to many kinds of systems.
  1469   1469   
  1470   1470   Usage: $0 [OPTION]... [VAR=VALUE]...
  1471   1471   
  1472   1472   To assign environment variables (e.g., CC, CFLAGS...), specify them as
  1473   1473   VAR=VALUE.  See below for descriptions of some of the useful variables.
  1474   1474   
  1475   1475   Defaults for the options are specified in brackets.
................................................................................
  1526   1526     --build=BUILD     configure for building on BUILD [guessed]
  1527   1527     --host=HOST       cross-compile to build programs to run on HOST [BUILD]
  1528   1528   _ACEOF
  1529   1529   fi
  1530   1530   
  1531   1531   if test -n "$ac_init_help"; then
  1532   1532     case $ac_init_help in
  1533         -     short | recursive ) echo "Configuration of sqlite 3.23.0:";;
         1533  +     short | recursive ) echo "Configuration of sqlite 3.23.1:";;
  1534   1534      esac
  1535   1535     cat <<\_ACEOF
  1536   1536   
  1537   1537   Optional Features:
  1538   1538     --disable-option-checking  ignore unrecognized --enable/--with options
  1539   1539     --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  1540   1540     --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
................................................................................
  1651   1651       cd "$ac_pwd" || { ac_status=$?; break; }
  1652   1652     done
  1653   1653   fi
  1654   1654   
  1655   1655   test -n "$ac_init_help" && exit $ac_status
  1656   1656   if $ac_init_version; then
  1657   1657     cat <<\_ACEOF
  1658         -sqlite configure 3.23.0
         1658  +sqlite configure 3.23.1
  1659   1659   generated by GNU Autoconf 2.69
  1660   1660   
  1661   1661   Copyright (C) 2012 Free Software Foundation, Inc.
  1662   1662   This configure script is free software; the Free Software Foundation
  1663   1663   gives unlimited permission to copy, distribute and modify it.
  1664   1664   _ACEOF
  1665   1665     exit
................................................................................
  2070   2070     eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  2071   2071   
  2072   2072   } # ac_fn_c_check_header_mongrel
  2073   2073   cat >config.log <<_ACEOF
  2074   2074   This file contains any messages produced by compilers while
  2075   2075   running configure, to aid debugging if configure makes a mistake.
  2076   2076   
  2077         -It was created by sqlite $as_me 3.23.0, which was
         2077  +It was created by sqlite $as_me 3.23.1, which was
  2078   2078   generated by GNU Autoconf 2.69.  Invocation command line was
  2079   2079   
  2080   2080     $ $0 $@
  2081   2081   
  2082   2082   _ACEOF
  2083   2083   exec 5>>config.log
  2084   2084   {
................................................................................
 12238  12238   test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1
 12239  12239   
 12240  12240   cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 12241  12241   # Save the log message, to keep $0 and so on meaningful, and to
 12242  12242   # report actual input values of CONFIG_FILES etc. instead of their
 12243  12243   # values after options handling.
 12244  12244   ac_log="
 12245         -This file was extended by sqlite $as_me 3.23.0, which was
        12245  +This file was extended by sqlite $as_me 3.23.1, which was
 12246  12246   generated by GNU Autoconf 2.69.  Invocation command line was
 12247  12247   
 12248  12248     CONFIG_FILES    = $CONFIG_FILES
 12249  12249     CONFIG_HEADERS  = $CONFIG_HEADERS
 12250  12250     CONFIG_LINKS    = $CONFIG_LINKS
 12251  12251     CONFIG_COMMANDS = $CONFIG_COMMANDS
 12252  12252     $ $0 $@
................................................................................
 12304  12304   
 12305  12305   Report bugs to the package provider."
 12306  12306   
 12307  12307   _ACEOF
 12308  12308   cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 12309  12309   ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 12310  12310   ac_cs_version="\\
 12311         -sqlite config.status 3.23.0
        12311  +sqlite config.status 3.23.1
 12312  12312   configured by $0, generated by GNU Autoconf 2.69,
 12313  12313     with options \\"\$ac_cs_config\\"
 12314  12314   
 12315  12315   Copyright (C) 2012 Free Software Foundation, Inc.
 12316  12316   This config.status script is free software; the Free Software Foundation
 12317  12317   gives unlimited permission to copy, distribute and modify it."
 12318  12318   

Changes to ext/fts5/fts5_main.c.

   530    530                                       FTS5_BI_ROWID_GE, 0, 0, -1},
   531    531     };
   532    532   
   533    533     int aColMap[3];
   534    534     aColMap[0] = -1;
   535    535     aColMap[1] = nCol;
   536    536     aColMap[2] = nCol+1;
          537  +
          538  +  assert( SQLITE_INDEX_CONSTRAINT_EQ<SQLITE_INDEX_CONSTRAINT_MATCH );
          539  +  assert( SQLITE_INDEX_CONSTRAINT_GT<SQLITE_INDEX_CONSTRAINT_MATCH );
          540  +  assert( SQLITE_INDEX_CONSTRAINT_LE<SQLITE_INDEX_CONSTRAINT_MATCH );
          541  +  assert( SQLITE_INDEX_CONSTRAINT_GE<SQLITE_INDEX_CONSTRAINT_MATCH );
          542  +  assert( SQLITE_INDEX_CONSTRAINT_LE<SQLITE_INDEX_CONSTRAINT_MATCH );
   537    543   
   538    544     /* Set idxFlags flags for all WHERE clause terms that will be used. */
   539    545     for(i=0; i<pInfo->nConstraint; i++){
   540    546       struct sqlite3_index_constraint *p = &pInfo->aConstraint[i];
   541    547       int iCol = p->iColumn;
   542    548   
   543    549       if( (p->op==SQLITE_INDEX_CONSTRAINT_MATCH && iCol>=0 && iCol<=nCol)
................................................................................
   549    555           aConstraint[0].iConsIndex = i;
   550    556         }else{
   551    557           /* As there exists an unusable MATCH constraint this is an 
   552    558           ** unusable plan. Set a prohibitively high cost. */
   553    559           pInfo->estimatedCost = 1e50;
   554    560           return SQLITE_OK;
   555    561         }
   556         -    }else{
          562  +    }else if( p->op<=SQLITE_INDEX_CONSTRAINT_MATCH ){
   557    563         int j;
   558    564         for(j=1; j<ArraySize(aConstraint); j++){
   559    565           struct Constraint *pC = &aConstraint[j];
   560         -        if( iCol==aColMap[pC->iCol] && p->op & pC->op && p->usable ){
          566  +        if( iCol==aColMap[pC->iCol] && (p->op & pC->op) && p->usable ){
   561    567             pC->iConsIndex = i;
   562    568             idxFlags |= pC->fts5op;
   563    569           }
   564    570         }
   565    571       }
   566    572     }
   567    573   

Changes to ext/fts5/test/fts5aa.test.

   586    586       INSERT INTO t9(rowid, x) VALUES(3, 'bbb');
   587    587     COMMIT;
   588    588   }
   589    589   
   590    590   do_execsql_test 22.1 {
   591    591     SELECT rowid FROM t9('a*')
   592    592   } {1}
          593  +
          594  +#-------------------------------------------------------------------------
          595  +do_execsql_test 23.0 {
          596  +  CREATE VIRTUAL TABLE t10 USING fts5(x, detail=%DETAIL%);
          597  +  CREATE TABLE t11(x);
          598  +}
          599  +do_execsql_test 23.1 {
          600  +  SELECT * FROM t11, t10 WHERE t11.x = t10.x AND t10.rowid IS NULL;
          601  +}
          602  +do_execsql_test 23.2 {
          603  +  SELECT * FROM t11, t10 WHERE t10.rowid IS NULL;
          604  +}
   593    605   
   594    606   }
   595    607   
   596    608   expand_all_sql db
   597    609   finish_test

Changes to ext/session/session1.test.

   607    607   do_iterator_test $tn.12.2 * {
   608    608     UPDATE t1 SET b='one' WHERE a=1;
   609    609   } {
   610    610     {UPDATE t1 0 X.. {i 1 {} {} i 1} {{} {} {} {} t one}}
   611    611     {UPDATE t1 0 X.. {i 2 {} {} i 2} {{} {} {} {} t one}}
   612    612     {UPDATE t1 0 X.. {i 3 {} {} i 3} {{} {} {} {} t one}}
   613    613   }
          614  +
          615  +#-------------------------------------------------------------------------
          616  +# Test that no savepoint is used if -nosavepoint is specified.
          617  +#
          618  +do_execsql_test $tn.13.1 {
          619  +  CREATE TABLE x1(a INTEGER PRIMARY KEY, b)%WR%;
          620  +}
          621  +do_test $tn.13.2 {
          622  +  execsql BEGIN
          623  +  set C [changeset_from_sql {
          624  +    INSERT INTO x1 VALUES(1, 'one');
          625  +    INSERT INTO x1 VALUES(2, 'two');
          626  +    INSERT INTO x1 VALUES(3, 'three');
          627  +  }]
          628  +  execsql ROLLBACK
          629  +  execsql {
          630  +    INSERT INTO x1 VALUES(1, 'i');
          631  +    INSERT INTO x1 VALUES(2, 'ii');
          632  +    INSERT INTO x1 VALUES(3, 'iii');
          633  +  }
          634  +} {}
          635  +
          636  +proc xConflict {args} {
          637  +  set ret [lindex $::CONFLICT_HANDLERS 0]
          638  +  set ::CONFLICT_HANDLERS [lrange $::CONFLICT_HANDLERS 1 end]
          639  +  set ret
          640  +}
          641  +do_test $tn.13.3 {
          642  +  set CONFLICT_HANDLERS [list REPLACE REPLACE ABORT]
          643  +  execsql BEGIN
          644  +  catch { sqlite3changeset_apply_v2 db $C xConflict } msg
          645  +  execsql {
          646  +    SELECT * FROM x1
          647  +  }
          648  +} {1 i 2 ii 3 iii}
          649  +do_test $tn.13.3 {
          650  +  set CONFLICT_HANDLERS [list REPLACE REPLACE ABORT]
          651  +  execsql ROLLBACK
          652  +  execsql BEGIN
          653  +  catch { sqlite3changeset_apply_v2 -nosavepoint db $C xConflict } msg
          654  +  execsql { SELECT * FROM x1 }
          655  +} {1 one 2 two 3 iii}
          656  +execsql ROLLBACK
   614    657   
   615    658   }]
   616    659   }
   617    660   
   618    661   
   619    662   finish_test

Changes to ext/session/sqlite3session.c.

  4230   4230     ),
  4231   4231     int(*xConflict)(
  4232   4232       void *pCtx,                   /* Copy of fifth arg to _apply() */
  4233   4233       int eConflict,                /* DATA, MISSING, CONFLICT, CONSTRAINT */
  4234   4234       sqlite3_changeset_iter *p     /* Handle describing change and conflict */
  4235   4235     ),
  4236   4236     void *pCtx,                     /* First argument passed to xConflict */
  4237         -  void **ppRebase, int *pnRebase  /* OUT: Rebase information */
         4237  +  void **ppRebase, int *pnRebase, /* OUT: Rebase information */
         4238  +  int flags                       /* SESSION_APPLY_XXX flags */
  4238   4239   ){
  4239   4240     int schemaMismatch = 0;
  4240         -  int rc;                         /* Return code */
         4241  +  int rc = SQLITE_OK;             /* Return code */
  4241   4242     const char *zTab = 0;           /* Name of current table */
  4242   4243     int nTab = 0;                   /* Result of sqlite3Strlen30(zTab) */
  4243   4244     SessionApplyCtx sApply;         /* changeset_apply() context object */
  4244   4245     int bPatchset;
  4245   4246   
  4246   4247     assert( xConflict!=0 );
  4247   4248   
  4248   4249     pIter->in.bNoDiscard = 1;
  4249   4250     memset(&sApply, 0, sizeof(sApply));
  4250   4251     sqlite3_mutex_enter(sqlite3_db_mutex(db));
  4251         -  rc = sqlite3_exec(db, "SAVEPOINT changeset_apply", 0, 0, 0);
         4252  +  if( (flags & SQLITE_CHANGESETAPPLY_NOSAVEPOINT)==0 ){
         4253  +    rc = sqlite3_exec(db, "SAVEPOINT changeset_apply", 0, 0, 0);
         4254  +  }
  4252   4255     if( rc==SQLITE_OK ){
  4253   4256       rc = sqlite3_exec(db, "PRAGMA defer_foreign_keys = 1", 0, 0, 0);
  4254   4257     }
  4255   4258     while( rc==SQLITE_OK && SQLITE_ROW==sqlite3changeset_next(pIter) ){
  4256   4259       int nCol;
  4257   4260       int op;
  4258   4261       const char *zNew;
................................................................................
  4382   4385         if( res!=SQLITE_CHANGESET_OMIT ){
  4383   4386           rc = SQLITE_CONSTRAINT;
  4384   4387         }
  4385   4388       }
  4386   4389     }
  4387   4390     sqlite3_exec(db, "PRAGMA defer_foreign_keys = 0", 0, 0, 0);
  4388   4391   
  4389         -  if( rc==SQLITE_OK ){
  4390         -    rc = sqlite3_exec(db, "RELEASE changeset_apply", 0, 0, 0);
  4391         -  }else{
  4392         -    sqlite3_exec(db, "ROLLBACK TO changeset_apply", 0, 0, 0);
  4393         -    sqlite3_exec(db, "RELEASE changeset_apply", 0, 0, 0);
         4392  +  if( (flags & SQLITE_CHANGESETAPPLY_NOSAVEPOINT)==0 ){
         4393  +    if( rc==SQLITE_OK ){
         4394  +      rc = sqlite3_exec(db, "RELEASE changeset_apply", 0, 0, 0);
         4395  +    }else{
         4396  +      sqlite3_exec(db, "ROLLBACK TO changeset_apply", 0, 0, 0);
         4397  +      sqlite3_exec(db, "RELEASE changeset_apply", 0, 0, 0);
         4398  +    }
  4394   4399     }
  4395   4400   
  4396   4401     if( rc==SQLITE_OK && bPatchset==0 && ppRebase && pnRebase ){
  4397   4402       *ppRebase = (void*)sApply.rebase.aBuf;
  4398   4403       *pnRebase = sApply.rebase.nBuf;
  4399   4404       sApply.rebase.aBuf = 0;
  4400   4405     }
................................................................................
  4423   4428     ),
  4424   4429     int(*xConflict)(
  4425   4430       void *pCtx,                   /* Copy of sixth arg to _apply() */
  4426   4431       int eConflict,                /* DATA, MISSING, CONFLICT, CONSTRAINT */
  4427   4432       sqlite3_changeset_iter *p     /* Handle describing change and conflict */
  4428   4433     ),
  4429   4434     void *pCtx,                     /* First argument passed to xConflict */
  4430         -  void **ppRebase, int *pnRebase
         4435  +  void **ppRebase, int *pnRebase,
         4436  +  int flags
  4431   4437   ){
  4432   4438     sqlite3_changeset_iter *pIter;  /* Iterator to skip through changeset */  
  4433   4439     int rc = sqlite3changeset_start(&pIter, nChangeset, pChangeset);
  4434   4440     if( rc==SQLITE_OK ){
  4435   4441       rc = sessionChangesetApply(
  4436         -        db, pIter, xFilter, xConflict, pCtx, ppRebase, pnRebase
         4442  +        db, pIter, xFilter, xConflict, pCtx, ppRebase, pnRebase, flags
  4437   4443       );
  4438   4444     }
  4439   4445     return rc;
  4440   4446   }
  4441   4447   
  4442   4448   /*
  4443   4449   ** Apply the changeset passed via pChangeset/nChangeset to the main database
................................................................................
  4456   4462       void *pCtx,                   /* Copy of fifth arg to _apply() */
  4457   4463       int eConflict,                /* DATA, MISSING, CONFLICT, CONSTRAINT */
  4458   4464       sqlite3_changeset_iter *p     /* Handle describing change and conflict */
  4459   4465     ),
  4460   4466     void *pCtx                      /* First argument passed to xConflict */
  4461   4467   ){
  4462   4468     return sqlite3changeset_apply_v2(
  4463         -      db, nChangeset, pChangeset, xFilter, xConflict, pCtx, 0, 0
         4469  +      db, nChangeset, pChangeset, xFilter, xConflict, pCtx, 0, 0, 0
  4464   4470     );
  4465   4471   }
  4466   4472   
  4467   4473   /*
  4468   4474   ** Apply the changeset passed via xInput/pIn to the main database
  4469   4475   ** attached to handle "db". Invoke the supplied conflict handler callback
  4470   4476   ** to resolve any conflicts encountered while applying the change.
................................................................................
  4479   4485     ),
  4480   4486     int(*xConflict)(
  4481   4487       void *pCtx,                   /* Copy of sixth arg to _apply() */
  4482   4488       int eConflict,                /* DATA, MISSING, CONFLICT, CONSTRAINT */
  4483   4489       sqlite3_changeset_iter *p     /* Handle describing change and conflict */
  4484   4490     ),
  4485   4491     void *pCtx,                     /* First argument passed to xConflict */
  4486         -  void **ppRebase, int *pnRebase
         4492  +  void **ppRebase, int *pnRebase,
         4493  +  int flags
  4487   4494   ){
  4488   4495     sqlite3_changeset_iter *pIter;  /* Iterator to skip through changeset */  
  4489   4496     int rc = sqlite3changeset_start_strm(&pIter, xInput, pIn);
  4490   4497     if( rc==SQLITE_OK ){
  4491   4498       rc = sessionChangesetApply(
  4492         -        db, pIter, xFilter, xConflict, pCtx, ppRebase, pnRebase
         4499  +        db, pIter, xFilter, xConflict, pCtx, ppRebase, pnRebase, flags
  4493   4500       );
  4494   4501     }
  4495   4502     return rc;
  4496   4503   }
  4497   4504   int sqlite3changeset_apply_strm(
  4498   4505     sqlite3 *db,                    /* Apply change to "main" db of this handle */
  4499   4506     int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
................................................................................
  4506   4513       void *pCtx,                   /* Copy of sixth arg to _apply() */
  4507   4514       int eConflict,                /* DATA, MISSING, CONFLICT, CONSTRAINT */
  4508   4515       sqlite3_changeset_iter *p     /* Handle describing change and conflict */
  4509   4516     ),
  4510   4517     void *pCtx                      /* First argument passed to xConflict */
  4511   4518   ){
  4512   4519     return sqlite3changeset_apply_v2_strm(
  4513         -      db, xInput, pIn, xFilter, xConflict, pCtx, 0, 0
         4520  +      db, xInput, pIn, xFilter, xConflict, pCtx, 0, 0, 0
  4514   4521     );
  4515   4522   }
  4516   4523   
  4517   4524   /*
  4518   4525   ** sqlite3_changegroup handle.
  4519   4526   */
  4520   4527   struct sqlite3_changegroup {

Changes to ext/session/sqlite3session.h.

  1091   1091   ** may set (*ppRebase) to point to a "rebase" that may be used with the 
  1092   1092   ** sqlite3_rebaser APIs buffer before returning. In this case (*pnRebase)
  1093   1093   ** is set to the size of the buffer in bytes. It is the responsibility of the
  1094   1094   ** caller to eventually free any such buffer using sqlite3_free(). The buffer
  1095   1095   ** is only allocated and populated if one or more conflicts were encountered
  1096   1096   ** while applying the patchset. See comments surrounding the sqlite3_rebaser
  1097   1097   ** APIs for further details.
         1098  +**
         1099  +** The behavior of sqlite3changeset_apply_v2() and its streaming equivalent
         1100  +** may be modified by passing a combination of
         1101  +** [SQLITE_CHANGESETAPPLY_NOSAVEPOINT | supported flags] as the 9th parameter.
         1102  +**
         1103  +** Note that the sqlite3changeset_apply_v2() API is still <b>experimental</b>
         1104  +** and therefore subject to change.
  1098   1105   */
  1099   1106   int sqlite3changeset_apply(
  1100   1107     sqlite3 *db,                    /* Apply change to "main" db of this handle */
  1101   1108     int nChangeset,                 /* Size of changeset in bytes */
  1102   1109     void *pChangeset,               /* Changeset blob */
  1103   1110     int(*xFilter)(
  1104   1111       void *pCtx,                   /* Copy of sixth arg to _apply() */
................................................................................
  1121   1128     ),
  1122   1129     int(*xConflict)(
  1123   1130       void *pCtx,                   /* Copy of sixth arg to _apply() */
  1124   1131       int eConflict,                /* DATA, MISSING, CONFLICT, CONSTRAINT */
  1125   1132       sqlite3_changeset_iter *p     /* Handle describing change and conflict */
  1126   1133     ),
  1127   1134     void *pCtx,                     /* First argument passed to xConflict */
  1128         -  void **ppRebase, int *pnRebase
         1135  +  void **ppRebase, int *pnRebase, /* OUT: Rebase data */
         1136  +  int flags                       /* Combination of SESSION_APPLY_* flags */
  1129   1137   );
  1130   1138   
         1139  +/*
         1140  +** CAPI3REF: Flags for sqlite3changeset_apply_v2
         1141  +**
         1142  +** The following flags may passed via the 9th parameter to
         1143  +** [sqlite3changeset_apply_v2] and [sqlite3changeset_apply_v2_strm]:
         1144  +**
         1145  +** <dl>
         1146  +** <dt>SQLITE_CHANGESETAPPLY_NOSAVEPOINT <dd>
         1147  +**   Usually, the sessions module encloses all operations performed by
         1148  +**   a single call to apply_v2() or apply_v2_strm() in a [SAVEPOINT]. The
         1149  +**   SAVEPOINT is committed if the changeset or patchset is successfully
         1150  +**   applied, or rolled back if an error occurs. Specifying this flag
         1151  +**   causes the sessions module to omit this savepoint. In this case, if the
         1152  +**   caller has an open transaction or savepoint when apply_v2() is called, 
         1153  +**   it may revert the partially applied changeset by rolling it back.
         1154  +*/
         1155  +#define SQLITE_CHANGESETAPPLY_NOSAVEPOINT   0x0001
         1156  +
  1131   1157   /* 
  1132   1158   ** CAPI3REF: Constants Passed To The Conflict Handler
  1133   1159   **
  1134   1160   ** Values that may be passed as the second argument to a conflict-handler.
  1135   1161   **
  1136   1162   ** <dl>
  1137   1163   ** <dt>SQLITE_CHANGESET_DATA<dd>
................................................................................
  1384   1410   **
  1385   1411   ** The six streaming API xxx_strm() functions serve similar purposes to the 
  1386   1412   ** corresponding non-streaming API functions:
  1387   1413   **
  1388   1414   ** <table border=1 style="margin-left:8ex;margin-right:8ex">
  1389   1415   **   <tr><th>Streaming function<th>Non-streaming equivalent</th>
  1390   1416   **   <tr><td>sqlite3changeset_apply_strm<td>[sqlite3changeset_apply] 
         1417  +**   <tr><td>sqlite3changeset_apply_strm_v2<td>[sqlite3changeset_apply_v2] 
  1391   1418   **   <tr><td>sqlite3changeset_concat_strm<td>[sqlite3changeset_concat] 
  1392   1419   **   <tr><td>sqlite3changeset_invert_strm<td>[sqlite3changeset_invert] 
  1393   1420   **   <tr><td>sqlite3changeset_start_strm<td>[sqlite3changeset_start] 
  1394   1421   **   <tr><td>sqlite3session_changeset_strm<td>[sqlite3session_changeset] 
  1395   1422   **   <tr><td>sqlite3session_patchset_strm<td>[sqlite3session_patchset] 
  1396   1423   ** </table>
  1397   1424   **
................................................................................
  1493   1520     ),
  1494   1521     int(*xConflict)(
  1495   1522       void *pCtx,                   /* Copy of sixth arg to _apply() */
  1496   1523       int eConflict,                /* DATA, MISSING, CONFLICT, CONSTRAINT */
  1497   1524       sqlite3_changeset_iter *p     /* Handle describing change and conflict */
  1498   1525     ),
  1499   1526     void *pCtx,                     /* First argument passed to xConflict */
  1500         -  void **ppRebase, int *pnRebase
         1527  +  void **ppRebase, int *pnRebase,
         1528  +  int flags
  1501   1529   );
  1502   1530   int sqlite3changeset_concat_strm(
  1503   1531     int (*xInputA)(void *pIn, void *pData, int *pnData),
  1504   1532     void *pInA,
  1505   1533     int (*xInputB)(void *pIn, void *pData, int *pnData),
  1506   1534     void *pInB,
  1507   1535     int (*xOutput)(void *pOut, const void *pData, int nData),

Changes to ext/session/test_session.c.

   727    727     int rc;                         /* Return code from changeset_invert() */
   728    728     void *pChangeset;               /* Buffer containing changeset */
   729    729     int nChangeset;                 /* Size of buffer aChangeset in bytes */
   730    730     TestConflictHandler ctx;
   731    731     TestStreamInput sStr;
   732    732     void *pRebase = 0;
   733    733     int nRebase = 0;
          734  +  int flags = 0;                  /* Flags for apply_v2() */
   734    735   
   735    736     memset(&sStr, 0, sizeof(sStr));
   736    737     sStr.nStream = test_tcl_integer(interp, SESSION_STREAM_TCL_VAR);
          738  +
          739  +  /* Check for the -nosavepoint flag */
          740  +  if( bV2 && objc>1 ){
          741  +    const char *z1 = Tcl_GetString(objv[1]);
          742  +    int n = strlen(z1);
          743  +    if( n>1 && n<=12 && 0==sqlite3_strnicmp("-nosavepoint", z1, n) ){
          744  +      flags = SQLITE_CHANGESETAPPLY_NOSAVEPOINT;
          745  +      objc--;
          746  +      objv++;
          747  +    }
          748  +  }
   737    749   
   738    750     if( objc!=4 && objc!=5 ){
   739         -    Tcl_WrongNumArgs(interp, 1, objv, 
   740         -        "DB CHANGESET CONFLICT-SCRIPT ?FILTER-SCRIPT?"
   741         -    );
          751  +    const char *zMsg;
          752  +    if( bV2 ){
          753  +      zMsg = "?-nosavepoint? DB CHANGESET CONFLICT-SCRIPT ?FILTER-SCRIPT?";
          754  +    }else{
          755  +      zMsg = "DB CHANGESET CONFLICT-SCRIPT ?FILTER-SCRIPT?";
          756  +    }
          757  +    Tcl_WrongNumArgs(interp, 1, objv, zMsg);
   742    758       return TCL_ERROR;
   743    759     }
   744    760     if( 0==Tcl_GetCommandInfo(interp, Tcl_GetString(objv[1]), &info) ){
   745         -    Tcl_AppendResult(interp, "no such handle: ", Tcl_GetString(objv[2]), 0);
          761  +    Tcl_AppendResult(interp, "no such handle: ", Tcl_GetString(objv[1]), 0);
   746    762       return TCL_ERROR;
   747    763     }
   748    764     db = *(sqlite3 **)info.objClientData;
   749    765     pChangeset = (void *)Tcl_GetByteArrayFromObj(objv[2], &nChangeset);
   750    766     ctx.pConflictScript = objv[3];
   751    767     ctx.pFilterScript = objc==5 ? objv[4] : 0;
   752    768     ctx.interp = interp;
................................................................................
   755    771       if( bV2==0 ){
   756    772         rc = sqlite3changeset_apply(db, nChangeset, pChangeset, 
   757    773             (objc==5)?test_filter_handler:0, test_conflict_handler, (void *)&ctx
   758    774         );
   759    775       }else{
   760    776         rc = sqlite3changeset_apply_v2(db, nChangeset, pChangeset, 
   761    777             (objc==5)?test_filter_handler:0, test_conflict_handler, (void *)&ctx,
   762         -          &pRebase, &nRebase
          778  +          &pRebase, &nRebase, flags
   763    779         );
   764    780       }
   765    781     }else{
   766    782       sStr.aData = (unsigned char*)pChangeset;
   767    783       sStr.nData = nChangeset;
   768    784       if( bV2==0 ){
   769    785         rc = sqlite3changeset_apply_strm(db, testStreamInput, (void*)&sStr,
................................................................................
   770    786             (objc==5) ? test_filter_handler : 0, 
   771    787             test_conflict_handler, (void *)&ctx
   772    788         );
   773    789       }else{
   774    790         rc = sqlite3changeset_apply_v2_strm(db, testStreamInput, (void*)&sStr,
   775    791             (objc==5) ? test_filter_handler : 0, 
   776    792             test_conflict_handler, (void *)&ctx,
   777         -          &pRebase, &nRebase
          793  +          &pRebase, &nRebase, flags
   778    794         );
   779    795       }
   780    796     }
   781    797   
   782    798     if( rc!=SQLITE_OK ){
   783    799       return test_session_error(interp, rc, 0);
   784    800     }else{

Changes to src/attach.c.

   498    498         pItem->zDatabase = 0;
   499    499         pItem->pSchema = pFix->pSchema;
   500    500       }
   501    501   #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER)
   502    502       if( sqlite3FixSelect(pFix, pItem->pSelect) ) return 1;
   503    503       if( sqlite3FixExpr(pFix, pItem->pOn) ) return 1;
   504    504   #endif
          505  +    if( pItem->fg.isTabFunc && sqlite3FixExprList(pFix, pItem->u1.pFuncArg) ){
          506  +      return 1;
          507  +    }
   505    508     }
   506    509     return 0;
   507    510   }
   508    511   #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER)
   509    512   int sqlite3FixSelect(
   510    513     DbFixer *pFix,       /* Context of the fixation */
   511    514     Select *pSelect      /* The SELECT statement to be fixed to one database */

Changes to src/build.c.

  1492   1492   ** the schema-version whenever the schema changes.
  1493   1493   */
  1494   1494   void sqlite3ChangeCookie(Parse *pParse, int iDb){
  1495   1495     sqlite3 *db = pParse->db;
  1496   1496     Vdbe *v = pParse->pVdbe;
  1497   1497     assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
  1498   1498     sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_SCHEMA_VERSION, 
  1499         -                    db->aDb[iDb].pSchema->schema_cookie+1);
         1499  +                   (int)(1+(unsigned)db->aDb[iDb].pSchema->schema_cookie));
  1500   1500   }
  1501   1501   
  1502   1502   /*
  1503   1503   ** Measure the number of characters needed to output the given
  1504   1504   ** identifier.  The number returned includes any quotes used
  1505   1505   ** but does not include the null terminator.
  1506   1506   **

Changes to src/expr.c.

  5014   5014     ** a later stage of processing, so the TK_AGG_FUNCTION case does not
  5015   5015     ** need to be considered here. */
  5016   5016     assert( pExpr->op!=TK_AGG_COLUMN );
  5017   5017     testcase( pExpr->op==TK_AGG_FUNCTION );
  5018   5018   
  5019   5019     if( ExprHasProperty(pExpr, EP_FromJoin) ) return WRC_Prune;
  5020   5020     switch( pExpr->op ){
         5021  +    case TK_ISNOT:
         5022  +    case TK_NOT:
  5021   5023       case TK_ISNULL:
  5022   5024       case TK_IS:
  5023   5025       case TK_OR:
  5024   5026       case TK_CASE:
  5025   5027       case TK_IN:
  5026   5028       case TK_FUNCTION:
         5029  +      testcase( pExpr->op==TK_ISNOT );
         5030  +      testcase( pExpr->op==TK_NOT );
  5027   5031         testcase( pExpr->op==TK_ISNULL );
  5028   5032         testcase( pExpr->op==TK_IS );
  5029   5033         testcase( pExpr->op==TK_OR );
  5030   5034         testcase( pExpr->op==TK_CASE );
  5031   5035         testcase( pExpr->op==TK_IN );
  5032   5036         testcase( pExpr->op==TK_FUNCTION );
  5033   5037         return WRC_Prune;

Changes to src/os.c.

   121    121   ** and we need to know about the failures.  Use sqlite3OsFileControlHint()
   122    122   ** when simply tossing information over the wall to the VFS and we do not
   123    123   ** really care if the VFS receives and understands the information since it
   124    124   ** is only a hint and can be safely ignored.  The sqlite3OsFileControlHint()
   125    125   ** routine has no return value since the return value would be meaningless.
   126    126   */
   127    127   int sqlite3OsFileControl(sqlite3_file *id, int op, void *pArg){
          128  +  if( id->pMethods==0 ) return SQLITE_NOTFOUND;
   128    129   #ifdef SQLITE_TEST
   129    130     if( op!=SQLITE_FCNTL_COMMIT_PHASETWO
   130    131      && op!=SQLITE_FCNTL_LOCK_TIMEOUT
   131    132     ){
   132    133       /* Faults are not injected into COMMIT_PHASETWO because, assuming SQLite
   133    134       ** is using a regular VFS, it is called after the corresponding
   134    135       ** transaction has been committed. Injecting a fault at this point
................................................................................
   138    139       ** The core must call OsFileControl() though, not OsFileControlHint(),
   139    140       ** as if a custom VFS (e.g. zipvfs) returns an error here, it probably
   140    141       ** means the commit really has failed and an error should be returned
   141    142       ** to the user.  */
   142    143       DO_OS_MALLOC_TEST(id);
   143    144     }
   144    145   #endif
   145         -  if( id->pMethods==0 ) return SQLITE_NOTFOUND;
   146    146     return id->pMethods->xFileControl(id, op, pArg);
   147    147   }
   148    148   void sqlite3OsFileControlHint(sqlite3_file *id, int op, void *pArg){
   149    149     if( id->pMethods ) (void)id->pMethods->xFileControl(id, op, pArg);
   150    150   }
   151    151   
   152    152   int sqlite3OsSectorSize(sqlite3_file *id){

Changes to src/parse.y.

   126    126   } // end %include
   127    127   
   128    128   // Input is a single SQL command
   129    129   input ::= cmdlist.
   130    130   cmdlist ::= cmdlist ecmd.
   131    131   cmdlist ::= ecmd.
   132    132   ecmd ::= SEMI.
   133         -ecmd ::= explain cmdx SEMI.
   134         -explain ::= .
          133  +ecmd ::= cmdx SEMI.
   135    134   %ifndef SQLITE_OMIT_EXPLAIN
          135  +ecmd ::= explain cmdx.
   136    136   explain ::= EXPLAIN.              { pParse->explain = 1; }
   137    137   explain ::= EXPLAIN QUERY PLAN.   { pParse->explain = 2; }
   138    138   %endif  SQLITE_OMIT_EXPLAIN
   139    139   cmdx ::= cmd.           { sqlite3FinishCoding(pParse); }
   140    140   
   141    141   ///////////////////// Begin and end transactions. ////////////////////////////
   142    142   //
................................................................................
   477    477         ){
   478    478           sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
   479    479         }
   480    480       }
   481    481     }
   482    482   }
   483    483   
   484         -select(A) ::= with(W) selectnowith(X). {
          484  +select(A) ::= WITH wqlist(W) selectnowith(X). {
          485  +  Select *p = X;
          486  +  if( p ){
          487  +    p->pWith = W;
          488  +    parserDoubleLinkSelect(pParse, p);
          489  +  }else{
          490  +    sqlite3WithDelete(pParse->db, W);
          491  +  }
          492  +  A = p;
          493  +}
          494  +select(A) ::= WITH RECURSIVE wqlist(W) selectnowith(X). {
   485    495     Select *p = X;
   486    496     if( p ){
   487    497       p->pWith = W;
   488    498       parserDoubleLinkSelect(pParse, p);
   489    499     }else{
   490    500       sqlite3WithDelete(pParse->db, W);
   491    501     }
   492         -  A = p; /*A-overwrites-W*/
          502  +  A = p;
          503  +}
          504  +select(A) ::= selectnowith(X). {
          505  +  Select *p = X;
          506  +  if( p ){
          507  +    parserDoubleLinkSelect(pParse, p);
          508  +  }
          509  +  A = p; /*A-overwrites-X*/
   493    510   }
   494    511   
   495    512   selectnowith(A) ::= oneselect(A).
   496    513   %ifndef SQLITE_OMIT_COMPOUND_SELECT
   497    514   selectnowith(A) ::= selectnowith(A) multiselect_op(Y) oneselect(Z).  {
   498    515     Select *pRhs = Z;
   499    516     Select *pLhs = A;
................................................................................
   679    696   
   680    697   %type dbnm {Token}
   681    698   dbnm(A) ::= .          {A.z=0; A.n=0;}
   682    699   dbnm(A) ::= DOT nm(X). {A = X;}
   683    700   
   684    701   %type fullname {SrcList*}
   685    702   %destructor fullname {sqlite3SrcListDelete(pParse->db, $$);}
   686         -fullname(A) ::= nm(X) dbnm(Y).  
          703  +fullname(A) ::= nm(X).  
          704  +   {A = sqlite3SrcListAppend(pParse->db,0,&X,0); /*A-overwrites-X*/}
          705  +fullname(A) ::= nm(X) DOT nm(Y).  
   687    706      {A = sqlite3SrcListAppend(pParse->db,0,&X,&Y); /*A-overwrites-X*/}
   688    707   
   689    708   %type joinop {int}
   690    709   joinop(X) ::= COMMA|JOIN.              { X = JT_INNER; }
   691    710   joinop(X) ::= JOIN_KW(A) JOIN.
   692    711                     {X = sqlite3JoinType(pParse,&A,0,0);  /*X-overwrites-A*/}
   693    712   joinop(X) ::= JOIN_KW(A) nm(B) JOIN.
................................................................................
   792    811                            {A = sqlite3PExpr(pParse,TK_LIMIT,X,Y);}
   793    812   limit_opt(A) ::= LIMIT expr(X) COMMA expr(Y). 
   794    813                            {A = sqlite3PExpr(pParse,TK_LIMIT,Y,X);}
   795    814   
   796    815   /////////////////////////// The DELETE statement /////////////////////////////
   797    816   //
   798    817   %ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
   799         -cmd ::= with(C) DELETE FROM fullname(X) indexed_opt(I) where_opt(W) 
          818  +cmd ::= with DELETE FROM fullname(X) indexed_opt(I) where_opt(W) 
   800    819           orderby_opt(O) limit_opt(L). {
   801         -  sqlite3WithPush(pParse, C, 1);
   802    820     sqlite3SrcListIndexedBy(pParse, X, &I);
   803    821     sqlite3DeleteFrom(pParse,X,W,O,L);
   804    822   }
   805    823   %endif
   806    824   %ifndef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
   807         -cmd ::= with(C) DELETE FROM fullname(X) indexed_opt(I) where_opt(W). {
   808         -  sqlite3WithPush(pParse, C, 1);
          825  +cmd ::= with DELETE FROM fullname(X) indexed_opt(I) where_opt(W). {
   809    826     sqlite3SrcListIndexedBy(pParse, X, &I);
   810    827     sqlite3DeleteFrom(pParse,X,W,0,0);
   811    828   }
   812    829   %endif
   813    830   
   814    831   %type where_opt {Expr*}
   815    832   %destructor where_opt {sqlite3ExprDelete(pParse->db, $$);}
................................................................................
   816    833   
   817    834   where_opt(A) ::= .                    {A = 0;}
   818    835   where_opt(A) ::= WHERE expr(X).       {A = X;}
   819    836   
   820    837   ////////////////////////// The UPDATE command ////////////////////////////////
   821    838   //
   822    839   %ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
   823         -cmd ::= with(C) UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y)
          840  +cmd ::= with UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y)
   824    841           where_opt(W) orderby_opt(O) limit_opt(L).  {
   825         -  sqlite3WithPush(pParse, C, 1);
   826    842     sqlite3SrcListIndexedBy(pParse, X, &I);
   827    843     sqlite3ExprListCheckLength(pParse,Y,"set list"); 
   828    844     sqlite3Update(pParse,X,Y,W,R,O,L);
   829    845   }
   830    846   %endif
   831    847   %ifndef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
   832         -cmd ::= with(C) UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y)
          848  +cmd ::= with UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y)
   833    849           where_opt(W).  {
   834         -  sqlite3WithPush(pParse, C, 1);
   835    850     sqlite3SrcListIndexedBy(pParse, X, &I);
   836    851     sqlite3ExprListCheckLength(pParse,Y,"set list"); 
   837    852     sqlite3Update(pParse,X,Y,W,R,0,0);
   838    853   }
   839    854   %endif
   840    855   
   841    856   %type setlist {ExprList*}
................................................................................
   854    869   }
   855    870   setlist(A) ::= LP idlist(X) RP EQ expr(Y). {
   856    871     A = sqlite3ExprListAppendVector(pParse, 0, X, Y);
   857    872   }
   858    873   
   859    874   ////////////////////////// The INSERT command /////////////////////////////////
   860    875   //
   861         -cmd ::= with(W) insert_cmd(R) INTO fullname(X) idlist_opt(F) select(S)
          876  +cmd ::= with insert_cmd(R) INTO fullname(X) idlist_opt(F) select(S)
   862    877           upsert(U). {
   863         -  sqlite3WithPush(pParse, W, 1);
   864    878     sqlite3Insert(pParse, X, S, F, upsertType(pParse, R, U.e), U.p);
   865    879   }
   866         -cmd ::= with(W) insert_cmd(R) INTO fullname(X) idlist_opt(F) DEFAULT VALUES.
          880  +cmd ::= with insert_cmd(R) INTO fullname(X) idlist_opt(F) DEFAULT VALUES.
   867    881   {
   868         -  sqlite3WithPush(pParse, W, 1);
   869    882     sqlite3Insert(pParse, X, 0, F, R, 0);
   870    883   }
   871    884   
   872    885   %type upsert {struct Upsert}
   873    886   %destructor upsert {sqlite3ExprListDelete(pParse->db,$$.p);}
   874    887   upsert(A) ::= . {
   875    888     A.p = 0;
................................................................................
  1552   1565   anylist ::= .
  1553   1566   anylist ::= anylist LP anylist RP.
  1554   1567   anylist ::= anylist ANY.
  1555   1568   %endif  SQLITE_OMIT_VIRTUALTABLE
  1556   1569   
  1557   1570   
  1558   1571   //////////////////////// COMMON TABLE EXPRESSIONS ////////////////////////////
  1559         -%type with {With*}
  1560   1572   %type wqlist {With*}
  1561         -%destructor with {sqlite3WithDelete(pParse->db, $$);}
  1562   1573   %destructor wqlist {sqlite3WithDelete(pParse->db, $$);}
  1563   1574   
  1564         -with(A) ::= . {A = 0;}
         1575  +with ::= .
  1565   1576   %ifndef SQLITE_OMIT_CTE
  1566         -with(A) ::= WITH wqlist(W).              { A = W; }
  1567         -with(A) ::= WITH RECURSIVE wqlist(W).    { A = W; }
         1577  +with ::= WITH wqlist(W).              { sqlite3WithPush(pParse, W, 1); }
         1578  +with ::= WITH RECURSIVE wqlist(W).    { sqlite3WithPush(pParse, W, 1); }
  1568   1579   
  1569   1580   wqlist(A) ::= nm(X) eidlist_opt(Y) AS LP select(Z) RP. {
  1570   1581     A = sqlite3WithAdd(pParse, 0, &X, Y, Z); /*A-overwrites-X*/
  1571   1582   }
  1572   1583   wqlist(A) ::= wqlist(A) COMMA nm(X) eidlist_opt(Y) AS LP select(Z) RP. {
  1573   1584     A = sqlite3WithAdd(pParse, A, &X, Y, Z);
  1574   1585   }
  1575   1586   %endif  SQLITE_OMIT_CTE

Changes to src/select.c.

  1243   1243     int eDest = pDest->eDest;
  1244   1244     int iParm = pDest->iSDParm;
  1245   1245     int regRow;
  1246   1246     int regRowid;
  1247   1247     int iCol;
  1248   1248     int nKey;
  1249   1249     int iSortTab;                   /* Sorter cursor to read from */
  1250         -  int nSortData;                  /* Trailing values to read from sorter */
  1251   1250     int i;
  1252   1251     int bSeq;                       /* True if sorter record includes seq. no. */
  1253   1252     struct ExprList_item *aOutEx = p->pEList->a;
  1254   1253   
  1255   1254     assert( addrBreak<0 );
  1256   1255     if( pSort->labelBkOut ){
  1257   1256       sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
................................................................................
  1258   1257       sqlite3VdbeGoto(v, addrBreak);
  1259   1258       sqlite3VdbeResolveLabel(v, pSort->labelBkOut);
  1260   1259     }
  1261   1260     iTab = pSort->iECursor;
  1262   1261     if( eDest==SRT_Output || eDest==SRT_Coroutine || eDest==SRT_Mem ){
  1263   1262       regRowid = 0;
  1264   1263       regRow = pDest->iSdst;
  1265         -    nSortData = nColumn;
  1266   1264     }else{
  1267   1265       regRowid = sqlite3GetTempReg(pParse);
  1268   1266       regRow = sqlite3GetTempRange(pParse, nColumn);
  1269         -    nSortData = nColumn;
  1270   1267     }
  1271   1268     nKey = pOrderBy->nExpr - pSort->nOBSat;
  1272   1269     if( pSort->sortFlags & SORTFLAG_UseSorter ){
  1273   1270       int regSortOut = ++pParse->nMem;
  1274   1271       iSortTab = pParse->nTab++;
  1275   1272       if( pSort->labelBkOut ){
  1276   1273         addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
  1277   1274       }
  1278         -    sqlite3VdbeAddOp3(v, OP_OpenPseudo, iSortTab, regSortOut, nKey+1+nSortData);
         1275  +    sqlite3VdbeAddOp3(v, OP_OpenPseudo, iSortTab, regSortOut, nKey+1+nColumn);
  1279   1276       if( addrOnce ) sqlite3VdbeJumpHere(v, addrOnce);
  1280   1277       addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
  1281   1278       VdbeCoverage(v);
  1282   1279       codeOffset(v, p->iOffset, addrContinue);
  1283   1280       sqlite3VdbeAddOp3(v, OP_SorterData, iTab, regSortOut, iSortTab);
  1284   1281       bSeq = 0;
  1285   1282     }else{
  1286   1283       addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v);
  1287   1284       codeOffset(v, p->iOffset, addrContinue);
  1288   1285       iSortTab = iTab;
  1289   1286       bSeq = 1;
  1290   1287     }
  1291         -  for(i=0, iCol=nKey+bSeq-1; i<nSortData; i++){
         1288  +  for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){
  1292   1289       if( aOutEx[i].u.x.iOrderByCol==0 ) iCol++;
  1293   1290     }
  1294         -  for(i=nSortData-1; i>=0; i--){
         1291  +  for(i=nColumn-1; i>=0; i--){
  1295   1292       int iRead;
  1296   1293       if( aOutEx[i].u.x.iOrderByCol ){
  1297   1294         iRead = aOutEx[i].u.x.iOrderByCol-1;
  1298   1295       }else{
  1299   1296         iRead = iCol--;
  1300   1297       }
  1301   1298       sqlite3VdbeAddOp3(v, OP_Column, iSortTab, iRead, regRow+i);
................................................................................
  4374   4371     }
  4375   4372     assert( p->pSrc!=0 );
  4376   4373     if( (selFlags & SF_Expanded)!=0 ){
  4377   4374       return WRC_Prune;
  4378   4375     }
  4379   4376     pTabList = p->pSrc;
  4380   4377     pEList = p->pEList;
  4381         -  if( OK_IF_ALWAYS_TRUE(p->pWith) ){
  4382         -    sqlite3WithPush(pParse, p->pWith, 0);
  4383         -  }
         4378  +  sqlite3WithPush(pParse, p->pWith, 0);
  4384   4379   
  4385   4380     /* Make sure cursor numbers have been assigned to all entries in
  4386   4381     ** the FROM clause of the SELECT statement.
  4387   4382     */
  4388   4383     sqlite3SrcListAssignCursors(pParse, pTabList);
  4389   4384   
  4390   4385     /* Look up every table named in the FROM clause of the select.  If

Changes to src/shell.c.in.

  3729   3729       if( f==0 ){
  3730   3730         utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
  3731   3731       }
  3732   3732     }
  3733   3733     return f;
  3734   3734   }
  3735   3735   
  3736         -#if !defined(SQLITE_UNTESTABLE)
  3737   3736   #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT)
  3738   3737   /*
  3739   3738   ** A routine for handling output from sqlite3_trace().
  3740   3739   */
  3741   3740   static int sql_trace_callback(
  3742   3741     unsigned mType,
  3743   3742     void *pArg,
................................................................................
  3751   3750       const char *z = (const char*)pX;
  3752   3751       int i = strlen30(z);
  3753   3752       while( i>0 && z[i-1]==';' ){ i--; }
  3754   3753       utf8_printf(f, "%.*s;\n", i, z);
  3755   3754     }
  3756   3755     return 0;
  3757   3756   }
  3758         -#endif
  3759   3757   #endif
  3760   3758   
  3761   3759   /*
  3762   3760   ** A no-op routine that runs with the ".breakpoint" doc-command.  This is
  3763   3761   ** a useful spot to set a debugger breakpoint.
  3764   3762   */
  3765   3763   static void test_breakpoint(void){

Changes to src/where.c.

  2369   2369     int rc = SQLITE_OK;             /* Return code */
  2370   2370     LogEst rSize;                   /* Number of rows in the table */
  2371   2371     LogEst rLogSize;                /* Logarithm of table size */
  2372   2372     WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */
  2373   2373   
  2374   2374     pNew = pBuilder->pNew;
  2375   2375     if( db->mallocFailed ) return SQLITE_NOMEM_BKPT;
  2376         -  WHERETRACE(0x800, ("BEGIN addBtreeIdx(%s), nEq=%d\n",
  2377         -                     pProbe->zName, pNew->u.btree.nEq));
         2376  +  WHERETRACE(0x800, ("BEGIN %s.addBtreeIdx(%s), nEq=%d\n",
         2377  +                     pProbe->pTable->zName,pProbe->zName, pNew->u.btree.nEq));
  2378   2378   
  2379   2379     assert( (pNew->wsFlags & WHERE_VIRTUALTABLE)==0 );
  2380   2380     assert( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 );
  2381   2381     if( pNew->wsFlags & WHERE_BTM_LIMIT ){
  2382   2382       opMask = WO_LT|WO_LE;
  2383   2383     }else{
  2384   2384       assert( pNew->u.btree.nBtm==0 );
................................................................................
  2656   2656       whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nIter + nInMul);
  2657   2657       pNew->nOut = saved_nOut;
  2658   2658       pNew->u.btree.nEq = saved_nEq;
  2659   2659       pNew->nSkip = saved_nSkip;
  2660   2660       pNew->wsFlags = saved_wsFlags;
  2661   2661     }
  2662   2662   
  2663         -  WHERETRACE(0x800, ("END addBtreeIdx(%s), nEq=%d, rc=%d\n",
  2664         -                      pProbe->zName, saved_nEq, rc));
         2663  +  WHERETRACE(0x800, ("END %s.addBtreeIdx(%s), nEq=%d, rc=%d\n",
         2664  +                      pProbe->pTable->zName, pProbe->zName, saved_nEq, rc));
  2665   2665     return rc;
  2666   2666   }
  2667   2667   
  2668   2668   /*
  2669   2669   ** Return True if it is possible that pIndex might be useful in
  2670   2670   ** implementing the ORDER BY clause in pBuilder.
  2671   2671   **
................................................................................
  3095   3095         int j = pIdxCons->iTermOffset;
  3096   3096         if( iTerm>=nConstraint
  3097   3097          || j<0
  3098   3098          || j>=pWC->nTerm
  3099   3099          || pNew->aLTerm[iTerm]!=0
  3100   3100          || pIdxCons->usable==0
  3101   3101         ){
  3102         -        rc = SQLITE_ERROR;
  3103   3102           sqlite3ErrorMsg(pParse,"%s.xBestIndex malfunction",pSrc->pTab->zName);
  3104         -        return rc;
         3103  +        testcase( pIdxInfo->needToFreeIdxStr );
         3104  +        return SQLITE_ERROR;
  3105   3105         }
  3106   3106         testcase( iTerm==nConstraint-1 );
  3107   3107         testcase( j==0 );
  3108   3108         testcase( j==pWC->nTerm-1 );
  3109   3109         pTerm = &pWC->a[j];
  3110   3110         pNew->prereq |= pTerm->prereqRight;
  3111   3111         assert( iTerm<pNew->nLSlot );
................................................................................
  3125   3125           *pbIn = 1; assert( (mExclude & WO_IN)==0 );
  3126   3126         }
  3127   3127       }
  3128   3128     }
  3129   3129     pNew->u.vtab.omitMask &= ~mNoOmit;
  3130   3130   
  3131   3131     pNew->nLTerm = mxTerm+1;
         3132  +  for(i=0; i<=mxTerm; i++){
         3133  +    if( pNew->aLTerm[i]==0 ){
         3134  +      /* The non-zero argvIdx values must be contiguous.  Raise an
         3135  +      ** error if they are not */
         3136  +      sqlite3ErrorMsg(pParse,"%s.xBestIndex malfunction",pSrc->pTab->zName);
         3137  +      testcase( pIdxInfo->needToFreeIdxStr );
         3138  +      return SQLITE_ERROR;
         3139  +    }
         3140  +  }
  3132   3141     assert( pNew->nLTerm<=pNew->nLSlot );
  3133   3142     pNew->u.vtab.idxNum = pIdxInfo->idxNum;
  3134   3143     pNew->u.vtab.needFree = pIdxInfo->needToFreeIdxStr;
  3135   3144     pIdxInfo->needToFreeIdxStr = 0;
  3136   3145     pNew->u.vtab.idxStr = pIdxInfo->idxStr;
  3137   3146     pNew->u.vtab.isOrdered = (i8)(pIdxInfo->orderByConsumed ?
  3138   3147         pIdxInfo->nOrderBy : 0);
................................................................................
  3240   3249     nConstraint = p->nConstraint;
  3241   3250     if( whereLoopResize(pParse->db, pNew, nConstraint) ){
  3242   3251       sqlite3DbFree(pParse->db, p);
  3243   3252       return SQLITE_NOMEM_BKPT;
  3244   3253     }
  3245   3254   
  3246   3255     /* First call xBestIndex() with all constraints usable. */
         3256  +  WHERETRACE(0x800, ("BEGIN %s.addVirtual()\n", pSrc->pTab->zName));
  3247   3257     WHERETRACE(0x40, ("  VirtualOne: all usable\n"));
  3248   3258     rc = whereLoopAddVirtualOne(pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn);
  3249   3259   
  3250   3260     /* If the call to xBestIndex() with all terms enabled produced a plan
  3251   3261     ** that does not require any source tables (IOW: a plan with mBest==0),
  3252   3262     ** then there is no point in making any further calls to xBestIndex() 
  3253   3263     ** since they will all return the same result (if the xBestIndex()
................................................................................
  3315   3325         rc = whereLoopAddVirtualOne(
  3316   3326             pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn);
  3317   3327       }
  3318   3328     }
  3319   3329   
  3320   3330     if( p->needToFreeIdxStr ) sqlite3_free(p->idxStr);
  3321   3331     sqlite3DbFreeNN(pParse->db, p);
         3332  +  WHERETRACE(0x800, ("END %s.addVirtual(), rc=%d\n", pSrc->pTab->zName, rc));
  3322   3333     return rc;
  3323   3334   }
  3324   3335   #endif /* SQLITE_OMIT_VIRTUALTABLE */
  3325   3336   
  3326   3337   /*
  3327   3338   ** Add WhereLoop entries to handle OR terms.  This works for either
  3328   3339   ** btrees or virtual tables.

Changes to test/join.test.

   801    801       FROM t1 LEFT JOIN t2
   802    802      WHERE CASE WHEN FALSE THEN a=x ELSE 1 END;
   803    803   } {1 2 {} {} x 3 4 {} {} x}
   804    804   do_execsql_test join-15.105 {
   805    805     SELECT *, 'x'
   806    806       FROM t1 LEFT JOIN t2
   807    807      WHERE a IN (1,3,x,y);
          808  +} {1 2 {} {} x 3 4 {} {} x}
          809  +do_execsql_test join-15.106 {
          810  +  SELECT *, 'x' 
          811  +    FROM t1 LEFT JOIN t2 
          812  +   WHERE NOT ( 'x'='y' AND t2.y=1 );
          813  +} {1 2 {} {} x 3 4 {} {} x}
          814  +do_execsql_test join-15.107 {
          815  +  SELECT *, 'x' 
          816  +    FROM t1 LEFT JOIN t2 
          817  +   WHERE t2.y IS NOT 'abc'
   808    818   } {1 2 {} {} x 3 4 {} {} x}
   809    819   do_execsql_test join-15.110 {
   810    820     DROP TABLE t1;
   811    821     DROP TABLE t2;
   812    822     CREATE TABLE t1(a INTEGER PRIMARY KEY, b INTEGER);
   813    823     INSERT INTO t1(a,b) VALUES(1,0),(11,1),(12,1),(13,1),(121,12);
   814    824     CREATE INDEX t1b ON t1(b);

Changes to test/triggerE.test.

    53     53     2 { BEFORE DELETE ON t1 BEGIN SELECT ?; END; }
    54     54     3 { BEFORE DELETE ON t1 BEGIN SELECT * FROM (SELECT * FROM (SELECT ?)); END; }
    55     55     5 { BEFORE DELETE ON t1 BEGIN SELECT * FROM t2 GROUP BY ?; END; }
    56     56     6 { BEFORE DELETE ON t1 BEGIN SELECT * FROM t2 LIMIT ?; END; }
    57     57     7 { BEFORE DELETE ON t1 BEGIN SELECT * FROM t2 ORDER BY ?; END; }
    58     58     8 { BEFORE UPDATE ON t1 BEGIN UPDATE t2 SET c = ?; END; }
    59     59     9 { BEFORE UPDATE ON t1 BEGIN UPDATE t2 SET c = 1 WHERE d = ?; END; }
           60  + 10 { AFTER INSERT ON t1 BEGIN SELECT * FROM pragma_stats(?); END; }
    60     61   } {
    61     62     catchsql {drop trigger tr1}
    62     63     do_catchsql_test 1.1.$tn "CREATE TRIGGER tr1 $defn" [list 1 $errmsg]
    63     64     do_catchsql_test 1.2.$tn "CREATE TEMP TRIGGER tr1 $defn" [list 1 $errmsg]
    64     65   }
    65     66   
    66     67   #-------------------------------------------------------------------------

Changes to tool/mkmsvcmin.tcl.

    79     79   set blocks(2) [string trimleft [string map [list \\\\ \\] {
    80     80   Replace.exe:
    81     81   	$(CSC) /target:exe $(TOP)\Replace.cs
    82     82   
    83     83   sqlite3.def:	Replace.exe $(LIBOBJ)
    84     84   	echo EXPORTS > sqlite3.def
    85     85   	dumpbin /all $(LIBOBJ) \\
    86         -		| .\Replace.exe "^\s+/EXPORT:_?(sqlite3(?:session|changeset|changegroup)?_[^@,]*)(?:@\d+|,DATA)?$$" $$1 true \\
           86  +		| .\Replace.exe "^\s+/EXPORT:_?(sqlite3(?:session|changeset|changegroup|rebaser)?_[^@,]*)(?:@\d+|,DATA)?$$" $$1 true \\
    87     87   		| sort >> sqlite3.def
    88     88   }]]
    89     89   
    90     90   set data "#### DO NOT EDIT ####\n"
    91     91   append data "# This makefile is automatically "
    92     92   append data "generated from the [file tail $fromFileName] at\n"
    93     93   append data "# the root of the canonical SQLite source tree (not the\n"