/ Changes On Branch branch-3.30
Login

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

Changes In Branch branch-3.30 Excluding Merge-Ins

This is equivalent to a diff from c20a3533 to 4146c629

2019-12-19
03:14
More restrictions on changes to shadow tables when in defensive mode. (Leaf check-in: 4146c629 user: drh tags: branch-3.30)
2019-11-16
16:54
More restrictions on changes to shadow tables when in defensive mode. (check-in: bae76a5c user: drh tags: trunk)
2019-11-14
23:08
Backport support for the sqlite3_hard_heap_limit64() interface and the hard_heap_limit pragma to the 3.30 branch. (check-in: ba27012d user: drh tags: branch-3.30)
2019-10-10
15:42
Version number to 3.30.1. (check-in: 12e28cc7 user: drh tags: branch-3.30)
2019-10-05
17:29
Have sqlite3.c automatically turn on osinst logging for all connections. (check-in: eea231f8 user: dan tags: osinst)
14:39
Performance optimization to the lookaside-memory disabling mechanism. (check-in: 17ce1c49 user: drh tags: trunk)
2019-10-04
16:15
Bring the wal2 branch up to date with version 3.30.0 (check-in: 16e1dced user: drh tags: wal2)
16:08
Bring the begin-concurrent-pnu branch up-to-date with version 3.30.0. (check-in: a4d26bcf user: drh tags: begin-concurrent-pnu)
15:52
Bring the begin-concurrent branch up-to-date with the 3.30.0 release. (check-in: abd1b4df user: drh tags: begin-concurrent)
15:41
Bring the apple-osx branch up-to-date with the 3.30.0 release. (check-in: 76b26aca user: drh tags: apple-osx)
15:31
Bring the reuse-schema branch up-to-date with version 3.30.0. (check-in: 6e09afec user: drh tags: reuse-schema)
15:03
Version 3.30.0 (check-in: c20a3533 user: drh tags: trunk, release, version-3.30.0)
2019-10-03
16:02
Avoid running a couple of tests in affinity2.test as part of the valgrind permutations, as the way floating point computations are simulated by valgrind causes them to fail. (check-in: 7f9a4b60 user: dan tags: trunk)

Changes to VERSION.

     1         -3.30.0
            1  +3.30.1

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.30.0.
            3  +# Generated by GNU Autoconf 2.69 for sqlite 3.30.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.30.0'
   730         -PACKAGE_STRING='sqlite 3.30.0'
          729  +PACKAGE_VERSION='3.30.1'
          730  +PACKAGE_STRING='sqlite 3.30.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
................................................................................
  1462   1462   #
  1463   1463   # Report the --help message.
  1464   1464   #
  1465   1465   if test "$ac_init_help" = "long"; then
  1466   1466     # Omit some internal or obsolete options to make the list less imposing.
  1467   1467     # This message is too long to be a string in the A/UX 3.1 sh.
  1468   1468     cat <<_ACEOF
  1469         -\`configure' configures sqlite 3.30.0 to adapt to many kinds of systems.
         1469  +\`configure' configures sqlite 3.30.1 to adapt to many kinds of systems.
  1470   1470   
  1471   1471   Usage: $0 [OPTION]... [VAR=VALUE]...
  1472   1472   
  1473   1473   To assign environment variables (e.g., CC, CFLAGS...), specify them as
  1474   1474   VAR=VALUE.  See below for descriptions of some of the useful variables.
  1475   1475   
  1476   1476   Defaults for the options are specified in brackets.
................................................................................
  1527   1527     --build=BUILD     configure for building on BUILD [guessed]
  1528   1528     --host=HOST       cross-compile to build programs to run on HOST [BUILD]
  1529   1529   _ACEOF
  1530   1530   fi
  1531   1531   
  1532   1532   if test -n "$ac_init_help"; then
  1533   1533     case $ac_init_help in
  1534         -     short | recursive ) echo "Configuration of sqlite 3.30.0:";;
         1534  +     short | recursive ) echo "Configuration of sqlite 3.30.1:";;
  1535   1535      esac
  1536   1536     cat <<\_ACEOF
  1537   1537   
  1538   1538   Optional Features:
  1539   1539     --disable-option-checking  ignore unrecognized --enable/--with options
  1540   1540     --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  1541   1541     --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
................................................................................
  1653   1653       cd "$ac_pwd" || { ac_status=$?; break; }
  1654   1654     done
  1655   1655   fi
  1656   1656   
  1657   1657   test -n "$ac_init_help" && exit $ac_status
  1658   1658   if $ac_init_version; then
  1659   1659     cat <<\_ACEOF
  1660         -sqlite configure 3.30.0
         1660  +sqlite configure 3.30.1
  1661   1661   generated by GNU Autoconf 2.69
  1662   1662   
  1663   1663   Copyright (C) 2012 Free Software Foundation, Inc.
  1664   1664   This configure script is free software; the Free Software Foundation
  1665   1665   gives unlimited permission to copy, distribute and modify it.
  1666   1666   _ACEOF
  1667   1667     exit
................................................................................
  2072   2072     eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  2073   2073   
  2074   2074   } # ac_fn_c_check_header_mongrel
  2075   2075   cat >config.log <<_ACEOF
  2076   2076   This file contains any messages produced by compilers while
  2077   2077   running configure, to aid debugging if configure makes a mistake.
  2078   2078   
  2079         -It was created by sqlite $as_me 3.30.0, which was
         2079  +It was created by sqlite $as_me 3.30.1, which was
  2080   2080   generated by GNU Autoconf 2.69.  Invocation command line was
  2081   2081   
  2082   2082     $ $0 $@
  2083   2083   
  2084   2084   _ACEOF
  2085   2085   exec 5>>config.log
  2086   2086   {
................................................................................
 12228  12228   test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1
 12229  12229   
 12230  12230   cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 12231  12231   # Save the log message, to keep $0 and so on meaningful, and to
 12232  12232   # report actual input values of CONFIG_FILES etc. instead of their
 12233  12233   # values after options handling.
 12234  12234   ac_log="
 12235         -This file was extended by sqlite $as_me 3.30.0, which was
        12235  +This file was extended by sqlite $as_me 3.30.1, which was
 12236  12236   generated by GNU Autoconf 2.69.  Invocation command line was
 12237  12237   
 12238  12238     CONFIG_FILES    = $CONFIG_FILES
 12239  12239     CONFIG_HEADERS  = $CONFIG_HEADERS
 12240  12240     CONFIG_LINKS    = $CONFIG_LINKS
 12241  12241     CONFIG_COMMANDS = $CONFIG_COMMANDS
 12242  12242     $ $0 $@
................................................................................
 12294  12294   
 12295  12295   Report bugs to the package provider."
 12296  12296   
 12297  12297   _ACEOF
 12298  12298   cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 12299  12299   ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 12300  12300   ac_cs_version="\\
 12301         -sqlite config.status 3.30.0
        12301  +sqlite config.status 3.30.1
 12302  12302   configured by $0, generated by GNU Autoconf 2.69,
 12303  12303     with options \\"\$ac_cs_config\\"
 12304  12304   
 12305  12305   Copyright (C) 2012 Free Software Foundation, Inc.
 12306  12306   This config.status script is free software; the Free Software Foundation
 12307  12307   gives unlimited permission to copy, distribute and modify it."
 12308  12308   

Changes to ext/fts5/test/fts5misc.test.

    54     54   db close
    55     55   sqlite3 db test.db
    56     56   
    57     57   do_catchsql_test 1.3.3 {
    58     58     SELECT a FROM t1
    59     59       WHERE rank = (SELECT highlight(t1, 4, '<b>', '</b>') FROM t1('*reads'));
    60     60   } {1 {no such cursor: 1}}
           61  +
           62  +#-------------------------------------------------------------------------
           63  +reset_db
           64  +do_execsql_test 2.0 {
           65  +  CREATE TABLE t0(c0);
           66  +  CREATE VIRTUAL TABLE vt0 USING fts5(c0);
           67  +}
           68  +do_execsql_test 2.1.1 {
           69  +  BEGIN TRANSACTION;
           70  +  INSERT INTO vt0(c0) VALUES ('xyz');
           71  +}
           72  +do_execsql_test 2.1.2 {
           73  +  ALTER TABLE t0 ADD COLUMN c5;
           74  +}
           75  +do_execsql_test 2.1.3 {
           76  +  INSERT INTO vt0(vt0) VALUES('integrity-check');
           77  +}
           78  +do_execsql_test 2.1.4 {
           79  +  INSERT INTO vt0(c0) VALUES ('abc');
           80  +  COMMIT
           81  +}
           82  +do_execsql_test 2.1.5 {
           83  +  INSERT INTO vt0(vt0) VALUES('integrity-check');
           84  +}
           85  +
           86  +reset_db
           87  +do_execsql_test 2.2.1 {
           88  +  CREATE TABLE t0(c0);
           89  +  CREATE VIRTUAL TABLE vt0 USING fts5(c0);
           90  +  BEGIN TRANSACTION;
           91  +  INSERT INTO vt0(c0) VALUES ('xyz');
           92  +}
           93  +
           94  +breakpoint
           95  +do_execsql_test 2.2.2 {
           96  +  ALTER TABLE t0 RENAME TO t1;
           97  +}
           98  +do_execsql_test 2.2.3 {
           99  +  INSERT INTO vt0(vt0) VALUES('integrity-check');
          100  +}
          101  +do_execsql_test 2.2.4 {
          102  +  INSERT INTO vt0(c0) VALUES ('abc');
          103  +  COMMIT;
          104  +}
          105  +do_execsql_test 2.2.5 {
          106  +  INSERT INTO vt0(vt0) VALUES('integrity-check');
          107  +}
          108  +
    61    109   
    62    110   finish_test
    63    111   

Changes to src/alter.c.

    27     27   ** in pParse->zErr (system tables may not be altered) and returns non-zero.
    28     28   **
    29     29   ** Or, if zName is not a system table, zero is returned.
    30     30   */
    31     31   static int isAlterableTable(Parse *pParse, Table *pTab){
    32     32     if( 0==sqlite3StrNICmp(pTab->zName, "sqlite_", 7) 
    33     33   #ifndef SQLITE_OMIT_VIRTUALTABLE
    34         -   || ( (pTab->tabFlags & TF_Shadow) 
    35         -     && (pParse->db->flags & SQLITE_Defensive)
    36         -     && pParse->db->nVdbeExec==0
           34  +   || ( (pTab->tabFlags & TF_Shadow)!=0
           35  +        && sqlite3ReadOnlyShadowTables(pParse->db)
    37     36      )
    38     37   #endif
    39     38     ){
    40     39       sqlite3ErrorMsg(pParse, "table %s may not be altered", pTab->zName);
    41     40       return 1;
    42     41     }
    43     42     return 0;
................................................................................
   431    430       sqlite3ErrorMsg(pParse, "Cannot add a column to a view");
   432    431       goto exit_begin_add_column;
   433    432     }
   434    433     if( SQLITE_OK!=isAlterableTable(pParse, pTab) ){
   435    434       goto exit_begin_add_column;
   436    435     }
   437    436   
          437  +  sqlite3MayAbort(pParse);
   438    438     assert( pTab->addColOffset>0 );
   439    439     iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
   440    440   
   441    441     /* Put a copy of the Table struct in Parse.pNewTable for the
   442    442     ** sqlite3AddColumn() function and friends to modify.  But modify
   443    443     ** the name by adding an "sqlite_altertab_" prefix.  By adding this
   444    444     ** prefix, we insure that the name will not collide with an existing

Changes to src/build.c.

   852    852       ){
   853    853         if( sqlite3Config.bExtraSchemaChecks ){
   854    854           sqlite3ErrorMsg(pParse, ""); /* corruptSchema() will supply the error */
   855    855           return SQLITE_ERROR;
   856    856         }
   857    857       }
   858    858     }else{
   859         -    if( pParse->nested==0 
   860         -     && 0==sqlite3StrNICmp(zName, "sqlite_", 7)
          859  +    if( (pParse->nested==0 && 0==sqlite3StrNICmp(zName, "sqlite_", 7))
          860  +     || (sqlite3ReadOnlyShadowTables(db) && sqlite3ShadowTableName(db, zName))
   861    861       ){
   862    862         sqlite3ErrorMsg(pParse, "object name reserved for internal use: %s",
   863    863                         zName);
   864    864         return SQLITE_ERROR;
   865    865       }
          866  +
   866    867     }
   867    868     return SQLITE_OK;
   868    869   }
   869    870   
   870    871   /*
   871    872   ** Return the PRIMARY KEY index of a table
   872    873   */
................................................................................
  1998   1999   /*
  1999   2000   ** Return true if zName is a shadow table name in the current database
  2000   2001   ** connection.
  2001   2002   **
  2002   2003   ** zName is temporarily modified while this routine is running, but is
  2003   2004   ** restored to its original value prior to this routine returning.
  2004   2005   */
  2005         -static int isShadowTableName(sqlite3 *db, char *zName){
         2006  +int sqlite3ShadowTableName(sqlite3 *db, const char *zName){
  2006   2007     char *zTail;                  /* Pointer to the last "_" in zName */
  2007   2008     Table *pTab;                  /* Table that zName is a shadow of */
  2008   2009     Module *pMod;                 /* Module for the virtual table */
  2009   2010   
  2010   2011     zTail = strrchr(zName, '_');
  2011   2012     if( zTail==0 ) return 0;
  2012   2013     *zTail = 0;
................................................................................
  2016   2017     if( !IsVirtual(pTab) ) return 0;
  2017   2018     pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->azModuleArg[0]);
  2018   2019     if( pMod==0 ) return 0;
  2019   2020     if( pMod->pModule->iVersion<3 ) return 0;
  2020   2021     if( pMod->pModule->xShadowName==0 ) return 0;
  2021   2022     return pMod->pModule->xShadowName(zTail+1);
  2022   2023   }
  2023         -#else
  2024         -# define isShadowTableName(x,y) 0
  2025   2024   #endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
  2026   2025   
  2027   2026   /*
  2028   2027   ** This routine is called to report the final ")" that terminates
  2029   2028   ** a CREATE TABLE statement.
  2030   2029   **
  2031   2030   ** The table structure that other action routines have been building
................................................................................
  2059   2058     if( pEnd==0 && pSelect==0 ){
  2060   2059       return;
  2061   2060     }
  2062   2061     assert( !db->mallocFailed );
  2063   2062     p = pParse->pNewTable;
  2064   2063     if( p==0 ) return;
  2065   2064   
  2066         -  if( pSelect==0 && isShadowTableName(db, p->zName) ){
         2065  +  if( pSelect==0 && sqlite3ShadowTableName(db, p->zName) ){
  2067   2066       p->tabFlags |= TF_Shadow;
  2068   2067     }
  2069   2068   
  2070   2069     /* If the db->init.busy is 1 it means we are reading the SQL off the
  2071   2070     ** "sqlite_master" or "sqlite_temp_master" table on the disk.
  2072   2071     ** So do not write to the disk again.  Extract the root page number
  2073   2072     ** for the table from the db->init.newTnum field.  (The page number
................................................................................
  2741   2740       sqlite3VdbeAddOp4(v, OP_VDestroy, iDb, 0, 0, pTab->zName, 0);
  2742   2741       sqlite3MayAbort(pParse);
  2743   2742     }
  2744   2743     sqlite3VdbeAddOp4(v, OP_DropTable, iDb, 0, 0, pTab->zName, 0);
  2745   2744     sqlite3ChangeCookie(pParse, iDb);
  2746   2745     sqliteViewResetAll(db, iDb);
  2747   2746   }
         2747  +
         2748  +/*
         2749  +** Return TRUE if shadow tables should be read-only in the current
         2750  +** context.
         2751  +*/
         2752  +int sqlite3ReadOnlyShadowTables(sqlite3 *db){
         2753  +#ifndef SQLITE_OMIT_VIRTUALTABLE
         2754  +  if( (db->flags & SQLITE_Defensive)!=0
         2755  +   && db->pVtabCtx==0
         2756  +   && db->nVdbeExec==0
         2757  +  ){
         2758  +    return 1;
         2759  +  }
         2760  +#endif
         2761  +  return 0;
         2762  +}
         2763  +
         2764  +/*
         2765  +** Return true if it is not allowed to drop the given table
         2766  +*/
         2767  +static int tableMayNotBeDropped(sqlite3 *db, Table *pTab){
         2768  +  if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 ){
         2769  +    if( sqlite3StrNICmp(pTab->zName+7, "stat", 4)==0 ) return 0;
         2770  +    if( sqlite3StrNICmp(pTab->zName+7, "parameters", 10)==0 ) return 0;
         2771  +    return 1;
         2772  +  }
         2773  +  if( (pTab->tabFlags & TF_Shadow)!=0 && sqlite3ReadOnlyShadowTables(db) ){
         2774  +    return 1;
         2775  +  }
         2776  +  return 0;
         2777  +}
  2748   2778   
  2749   2779   /*
  2750   2780   ** This routine is called to do the work of a DROP TABLE statement.
  2751   2781   ** pName is the name of the table to be dropped.
  2752   2782   */
  2753   2783   void sqlite3DropTable(Parse *pParse, SrcList *pName, int isView, int noErr){
  2754   2784     Table *pTab;
................................................................................
  2811   2841         goto exit_drop_table;
  2812   2842       }
  2813   2843       if( sqlite3AuthCheck(pParse, SQLITE_DELETE, pTab->zName, 0, zDb) ){
  2814   2844         goto exit_drop_table;
  2815   2845       }
  2816   2846     }
  2817   2847   #endif
  2818         -  if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 
  2819         -    && sqlite3StrNICmp(pTab->zName+7, "stat", 4)!=0
  2820         -    && sqlite3StrNICmp(pTab->zName+7, "parameters", 10)!=0 ){
         2848  +  if( tableMayNotBeDropped(db, pTab) ){
  2821   2849       sqlite3ErrorMsg(pParse, "table %s may not be dropped", pTab->zName);
  2822   2850       goto exit_drop_table;
  2823   2851     }
  2824   2852   
  2825   2853   #ifndef SQLITE_OMIT_VIEW
  2826   2854     /* Ensure DROP TABLE is not used on a view, and DROP VIEW is not used
  2827   2855     ** on a table.

Changes to src/delete.c.

    66     66     }
    67     67     if( (pTab->tabFlags & (TF_Readonly|TF_Shadow))==0 ) return 0;
    68     68     db = pParse->db;
    69     69     if( (pTab->tabFlags & TF_Readonly)!=0 ){
    70     70       return sqlite3WritableSchema(db)==0 && pParse->nested==0;
    71     71     }
    72     72     assert( pTab->tabFlags & TF_Shadow );
    73         -  return (db->flags & SQLITE_Defensive)!=0 
    74         -#ifndef SQLITE_OMIT_VIRTUALTABLE
    75         -          && db->pVtabCtx==0
    76         -#endif
    77         -          && db->nVdbeExec==0;
           73  +  return sqlite3ReadOnlyShadowTables(db);
    78     74   }
    79     75   
    80     76   /*
    81     77   ** Check to make sure the given table is writable.  If it is not
    82     78   ** writable, generate an error message and return 1.  If it is
    83     79   ** writable return 0;
    84     80   */

Changes to src/expr.c.

  5142   5142       case TK_ISNULL:
  5143   5143       case TK_NOTNULL:
  5144   5144       case TK_IS:
  5145   5145       case TK_OR:
  5146   5146       case TK_CASE:
  5147   5147       case TK_IN:
  5148   5148       case TK_FUNCTION:
         5149  +    case TK_TRUTH:
  5149   5150         testcase( pExpr->op==TK_ISNOT );
  5150   5151         testcase( pExpr->op==TK_ISNULL );
  5151   5152         testcase( pExpr->op==TK_NOTNULL );
  5152   5153         testcase( pExpr->op==TK_IS );
  5153   5154         testcase( pExpr->op==TK_OR );
  5154   5155         testcase( pExpr->op==TK_CASE );
  5155   5156         testcase( pExpr->op==TK_IN );
  5156   5157         testcase( pExpr->op==TK_FUNCTION );
         5158  +      testcase( pExpr->op==TK_TRUTH );
  5157   5159         return WRC_Prune;
  5158   5160       case TK_COLUMN:
  5159   5161         if( pWalker->u.iCur==pExpr->iTable ){
  5160   5162           pWalker->eCode = 1;
  5161   5163           return WRC_Abort;
  5162   5164         }
  5163   5165         return WRC_Prune;

Changes to src/loadext.c.

   464    464     sqlite3_value_frombind,
   465    465     /* Version 3.30.0 and later */
   466    466   #ifndef SQLITE_OMIT_VIRTUALTABLE
   467    467     sqlite3_drop_modules,
   468    468   #else
   469    469     0,
   470    470   #endif
          471  +  /* Version 3.31.0 and later */
          472  +  sqlite3_hard_heap_limit64,
   471    473   };
   472    474   
   473    475   /*
   474    476   ** Attempt to load an SQLite extension library contained in the file
   475    477   ** zFile.  The entry point is zProc.  zProc may be 0 in which case a
   476    478   ** default entry point name (sqlite3_extension_init) is used.  Use
   477    479   ** of the default name is recommended.

Changes to src/malloc.c.

    28     28     ** is a no-op returning zero if SQLite is not compiled with
    29     29     ** SQLITE_ENABLE_MEMORY_MANAGEMENT. */
    30     30     UNUSED_PARAMETER(n);
    31     31     return 0;
    32     32   #endif
    33     33   }
    34     34   
           35  +/*
           36  +** Default value of the hard heap limit.  0 means "no limit".
           37  +*/
           38  +#ifndef SQLITE_MAX_MEMORY
           39  +# define SQLITE_MAX_MEMORY 0
           40  +#endif
           41  +
    35     42   /*
    36     43   ** State information local to the memory allocation subsystem.
    37     44   */
    38     45   static SQLITE_WSD struct Mem0Global {
    39     46     sqlite3_mutex *mutex;         /* Mutex to serialize access */
    40     47     sqlite3_int64 alarmThreshold; /* The soft heap limit */
           48  +  sqlite3_int64 hardLimit;      /* The hard upper bound on memory */
    41     49   
    42     50     /*
    43     51     ** True if heap is nearly "full" where "full" is defined by the
    44     52     ** sqlite3_soft_heap_limit() setting.
    45     53     */
    46     54     int nearlyFull;
    47         -} mem0 = { 0, 0, 0 };
           55  +} mem0 = { 0, SQLITE_MAX_MEMORY, SQLITE_MAX_MEMORY, 0 };
    48     56   
    49     57   #define mem0 GLOBAL(struct Mem0Global, mem0)
    50     58   
    51     59   /*
    52     60   ** Return the memory allocator mutex. sqlite3_status() needs it.
    53     61   */
    54     62   sqlite3_mutex *sqlite3MallocMutex(void){
................................................................................
    70     78     (void)pArg;
    71     79     (void)iThreshold;
    72     80     return SQLITE_OK;
    73     81   }
    74     82   #endif
    75     83   
    76     84   /*
    77         -** Set the soft heap-size limit for the library. Passing a zero or 
    78         -** negative value indicates no limit.
           85  +** Set the soft heap-size limit for the library.  An argument of
           86  +** zero disables the limit.  A negative argument is a no-op used to
           87  +** obtain the return value.
           88  +**
           89  +** The return value is the value of the heap limit just before this
           90  +** interface was called.
           91  +**
           92  +** If the hard heap limit is enabled, then the soft heap limit cannot
           93  +** be disabled nor raised above the hard heap limit.
    79     94   */
    80     95   sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 n){
    81     96     sqlite3_int64 priorLimit;
    82     97     sqlite3_int64 excess;
    83     98     sqlite3_int64 nUsed;
    84     99   #ifndef SQLITE_OMIT_AUTOINIT
    85    100     int rc = sqlite3_initialize();
................................................................................
    86    101     if( rc ) return -1;
    87    102   #endif
    88    103     sqlite3_mutex_enter(mem0.mutex);
    89    104     priorLimit = mem0.alarmThreshold;
    90    105     if( n<0 ){
    91    106       sqlite3_mutex_leave(mem0.mutex);
    92    107       return priorLimit;
          108  +  }
          109  +  if( mem0.hardLimit>0 && (n>mem0.hardLimit || n==0) ){
          110  +    n = mem0.hardLimit;
    93    111     }
    94    112     mem0.alarmThreshold = n;
    95    113     nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
    96    114     mem0.nearlyFull = (n>0 && n<=nUsed);
    97    115     sqlite3_mutex_leave(mem0.mutex);
    98    116     excess = sqlite3_memory_used() - n;
    99    117     if( excess>0 ) sqlite3_release_memory((int)(excess & 0x7fffffff));
   100    118     return priorLimit;
   101    119   }
   102    120   void sqlite3_soft_heap_limit(int n){
   103    121     if( n<0 ) n = 0;
   104    122     sqlite3_soft_heap_limit64(n);
   105    123   }
          124  +
          125  +/*
          126  +** Set the hard heap-size limit for the library. An argument of zero
          127  +** disables the hard heap limit.  A negative argument is a no-op used
          128  +** to obtain the return value without affecting the hard heap limit.
          129  +**
          130  +** The return value is the value of the hard heap limit just prior to
          131  +** calling this interface.
          132  +**
          133  +** Setting the hard heap limit will also activate the soft heap limit
          134  +** and constrain the soft heap limit to be no more than the hard heap
          135  +** limit.
          136  +*/
          137  +sqlite3_int64 sqlite3_hard_heap_limit64(sqlite3_int64 n){
          138  +  sqlite3_int64 priorLimit;
          139  +#ifndef SQLITE_OMIT_AUTOINIT
          140  +  int rc = sqlite3_initialize();
          141  +  if( rc ) return -1;
          142  +#endif
          143  +  sqlite3_mutex_enter(mem0.mutex);
          144  +  priorLimit = mem0.hardLimit;
          145  +  if( n>=0 ){
          146  +    mem0.hardLimit = n;
          147  +    if( n<mem0.alarmThreshold || mem0.alarmThreshold==0 ){
          148  +      mem0.alarmThreshold = n;
          149  +    }
          150  +  }
          151  +  sqlite3_mutex_leave(mem0.mutex);
          152  +  return priorLimit;
          153  +}
          154  +
   106    155   
   107    156   /*
   108    157   ** Initialize the memory allocation subsystem.
   109    158   */
   110    159   int sqlite3MallocInit(void){
   111    160     int rc;
   112    161     if( sqlite3GlobalConfig.m.xMalloc==0 ){
................................................................................
   186    235     /* In Firefox (circa 2017-02-08), xRoundup() is remapped to an internal
   187    236     ** implementation of malloc_good_size(), which must be called in debug
   188    237     ** mode and specifically when the DMD "Dark Matter Detector" is enabled
   189    238     ** or else a crash results.  Hence, do not attempt to optimize out the
   190    239     ** following xRoundup() call. */
   191    240     nFull = sqlite3GlobalConfig.m.xRoundup(n);
   192    241   
   193         -#ifdef SQLITE_MAX_MEMORY
   194         -  if( sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)+nFull>SQLITE_MAX_MEMORY ){
   195         -    *pp = 0;
   196         -    return;
   197         -  }
   198         -#endif
   199         -
   200    242     sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, n);
   201    243     if( mem0.alarmThreshold>0 ){
   202    244       sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
   203    245       if( nUsed >= mem0.alarmThreshold - nFull ){
   204    246         mem0.nearlyFull = 1;
   205    247         sqlite3MallocAlarm(nFull);
          248  +      if( mem0.hardLimit ){
          249  +        nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
          250  +        if( nUsed >= mem0.hardLimit - nFull ){
          251  +          *pp = 0;
          252  +          return;
          253  +        }
          254  +      }
   206    255       }else{
   207    256         mem0.nearlyFull = 0;
   208    257       }
   209    258     }
   210    259     p = sqlite3GlobalConfig.m.xMalloc(nFull);
   211    260   #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
   212    261     if( p==0 && mem0.alarmThreshold>0 ){

Changes to src/pragma.c.

  2075   2075       sqlite3_int64 N;
  2076   2076       if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){
  2077   2077         sqlite3_soft_heap_limit64(N);
  2078   2078       }
  2079   2079       returnSingleInt(v, sqlite3_soft_heap_limit64(-1));
  2080   2080       break;
  2081   2081     }
         2082  +
         2083  +  /*
         2084  +  **   PRAGMA hard_heap_limit
         2085  +  **   PRAGMA hard_heap_limit = N
         2086  +  **
         2087  +  ** Invoke sqlite3_hard_heap_limit64() to query or set the hard heap
         2088  +  ** limit.  The hard heap limit can be activated or lowered by this
         2089  +  ** pragma, but not raised or deactivated.  Only the
         2090  +  ** sqlite3_hard_heap_limit64() C-language API can raise or deactivate
         2091  +  ** the hard heap limit.  This allows an application to set a heap limit
         2092  +  ** constraint that cannot be relaxed by an untrusted SQL script.
         2093  +  */
         2094  +  case PragTyp_HARD_HEAP_LIMIT: {
         2095  +    sqlite3_int64 N;
         2096  +    if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){
         2097  +      sqlite3_int64 iPrior = sqlite3_hard_heap_limit64(-1);
         2098  +      if( N>0 && (iPrior==0 || iPrior>N) ) sqlite3_hard_heap_limit64(N);
         2099  +    }
         2100  +    returnSingleInt(v, sqlite3_hard_heap_limit64(-1));
         2101  +    break;
         2102  +  }
  2082   2103   
  2083   2104     /*
  2084   2105     **   PRAGMA threads
  2085   2106     **   PRAGMA threads = N
  2086   2107     **
  2087   2108     ** Configure the maximum number of worker threads.  Return the new
  2088   2109     ** maximum, which might be less than requested.

Changes to src/pragma.h.

    17     17   #define PragTyp_DATA_STORE_DIRECTORY           9
    18     18   #define PragTyp_DATABASE_LIST                 10
    19     19   #define PragTyp_DEFAULT_CACHE_SIZE            11
    20     20   #define PragTyp_ENCODING                      12
    21     21   #define PragTyp_FOREIGN_KEY_CHECK             13
    22     22   #define PragTyp_FOREIGN_KEY_LIST              14
    23     23   #define PragTyp_FUNCTION_LIST                 15
    24         -#define PragTyp_INCREMENTAL_VACUUM            16
    25         -#define PragTyp_INDEX_INFO                    17
    26         -#define PragTyp_INDEX_LIST                    18
    27         -#define PragTyp_INTEGRITY_CHECK               19
    28         -#define PragTyp_JOURNAL_MODE                  20
    29         -#define PragTyp_JOURNAL_SIZE_LIMIT            21
    30         -#define PragTyp_LOCK_PROXY_FILE               22
    31         -#define PragTyp_LOCKING_MODE                  23
    32         -#define PragTyp_PAGE_COUNT                    24
    33         -#define PragTyp_MMAP_SIZE                     25
    34         -#define PragTyp_MODULE_LIST                   26
    35         -#define PragTyp_OPTIMIZE                      27
    36         -#define PragTyp_PAGE_SIZE                     28
    37         -#define PragTyp_PRAGMA_LIST                   29
    38         -#define PragTyp_SECURE_DELETE                 30
    39         -#define PragTyp_SHRINK_MEMORY                 31
    40         -#define PragTyp_SOFT_HEAP_LIMIT               32
    41         -#define PragTyp_SYNCHRONOUS                   33
    42         -#define PragTyp_TABLE_INFO                    34
    43         -#define PragTyp_TEMP_STORE                    35
    44         -#define PragTyp_TEMP_STORE_DIRECTORY          36
    45         -#define PragTyp_THREADS                       37
    46         -#define PragTyp_WAL_AUTOCHECKPOINT            38
    47         -#define PragTyp_WAL_CHECKPOINT                39
    48         -#define PragTyp_ACTIVATE_EXTENSIONS           40
    49         -#define PragTyp_KEY                           41
    50         -#define PragTyp_LOCK_STATUS                   42
    51         -#define PragTyp_STATS                         43
           24  +#define PragTyp_HARD_HEAP_LIMIT               16
           25  +#define PragTyp_INCREMENTAL_VACUUM            17
           26  +#define PragTyp_INDEX_INFO                    18
           27  +#define PragTyp_INDEX_LIST                    19
           28  +#define PragTyp_INTEGRITY_CHECK               20
           29  +#define PragTyp_JOURNAL_MODE                  21
           30  +#define PragTyp_JOURNAL_SIZE_LIMIT            22
           31  +#define PragTyp_LOCK_PROXY_FILE               23
           32  +#define PragTyp_LOCKING_MODE                  24
           33  +#define PragTyp_PAGE_COUNT                    25
           34  +#define PragTyp_MMAP_SIZE                     26
           35  +#define PragTyp_MODULE_LIST                   27
           36  +#define PragTyp_OPTIMIZE                      28
           37  +#define PragTyp_PAGE_SIZE                     29
           38  +#define PragTyp_PRAGMA_LIST                   30
           39  +#define PragTyp_SECURE_DELETE                 31
           40  +#define PragTyp_SHRINK_MEMORY                 32
           41  +#define PragTyp_SOFT_HEAP_LIMIT               33
           42  +#define PragTyp_SYNCHRONOUS                   34
           43  +#define PragTyp_TABLE_INFO                    35
           44  +#define PragTyp_TEMP_STORE                    36
           45  +#define PragTyp_TEMP_STORE_DIRECTORY          37
           46  +#define PragTyp_THREADS                       38
           47  +#define PragTyp_WAL_AUTOCHECKPOINT            39
           48  +#define PragTyp_WAL_CHECKPOINT                40
           49  +#define PragTyp_ACTIVATE_EXTENSIONS           41
           50  +#define PragTyp_KEY                           42
           51  +#define PragTyp_LOCK_STATUS                   43
           52  +#define PragTyp_STATS                         44
    52     53   
    53     54   /* Property flags associated with various pragma. */
    54     55   #define PragFlg_NeedSchema 0x01 /* Force schema load before running */
    55     56   #define PragFlg_NoColumns  0x02 /* OP_ResultRow called with zero columns */
    56     57   #define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */
    57     58   #define PragFlg_ReadOnly   0x08 /* Read-only HEADER_VALUE */
    58     59   #define PragFlg_Result0    0x10 /* Acts as query when no argument */
................................................................................
   315    316    {/* zName:     */ "function_list",
   316    317     /* ePragTyp:  */ PragTyp_FUNCTION_LIST,
   317    318     /* ePragFlg:  */ PragFlg_Result0,
   318    319     /* ColNames:  */ 41, 2,
   319    320     /* iArg:      */ 0 },
   320    321   #endif
   321    322   #endif
          323  + {/* zName:     */ "hard_heap_limit",
          324  +  /* ePragTyp:  */ PragTyp_HARD_HEAP_LIMIT,
          325  +  /* ePragFlg:  */ PragFlg_Result0,
          326  +  /* ColNames:  */ 0, 0,
          327  +  /* iArg:      */ 0 },
   322    328   #if defined(SQLITE_HAS_CODEC)
   323    329    {/* zName:     */ "hexkey",
   324    330     /* ePragTyp:  */ PragTyp_KEY,
   325    331     /* ePragFlg:  */ 0,
   326    332     /* ColNames:  */ 0, 0,
   327    333     /* iArg:      */ 2 },
   328    334    {/* zName:     */ "hexrekey",

Changes to src/select.c.

    96     96       sqlite3ExprDelete(db, p->pHaving);
    97     97       sqlite3ExprListDelete(db, p->pOrderBy);
    98     98       sqlite3ExprDelete(db, p->pLimit);
    99     99   #ifndef SQLITE_OMIT_WINDOWFUNC
   100    100       if( OK_IF_ALWAYS_TRUE(p->pWinDefn) ){
   101    101         sqlite3WindowListDelete(db, p->pWinDefn);
   102    102       }
   103         -#endif
   104         -    if( OK_IF_ALWAYS_TRUE(p->pWith) ) sqlite3WithDelete(db, p->pWith);
   105    103       assert( p->pWin==0 );
          104  +#endif
          105  +    if( OK_IF_ALWAYS_TRUE(p->pWith) ) sqlite3WithDelete(db, p->pWith);
   106    106       if( bFree ) sqlite3DbFreeNN(db, p);
   107    107       p = pPrior;
   108    108       bFree = 1;
   109    109     }
   110    110   }
   111    111   
   112    112   /*
................................................................................
  3499   3499       pExpr->pLeft = substExpr(pSubst, pExpr->pLeft);
  3500   3500       pExpr->pRight = substExpr(pSubst, pExpr->pRight);
  3501   3501       if( ExprHasProperty(pExpr, EP_xIsSelect) ){
  3502   3502         substSelect(pSubst, pExpr->x.pSelect, 1);
  3503   3503       }else{
  3504   3504         substExprList(pSubst, pExpr->x.pList);
  3505   3505       }
         3506  +#ifndef SQLITE_OMIT_WINDOWFUNC
         3507  +    if( ExprHasProperty(pExpr, EP_WinFunc) ){
         3508  +      Window *pWin = pExpr->y.pWin;
         3509  +      pWin->pFilter = substExpr(pSubst, pWin->pFilter);
         3510  +      substExprList(pSubst, pWin->pPartition);
         3511  +      substExprList(pSubst, pWin->pOrderBy);
         3512  +    }
         3513  +#endif
  3506   3514     }
  3507   3515     return pExpr;
  3508   3516   }
  3509   3517   static void substExprList(
  3510   3518     SubstContext *pSubst, /* Description of the substitution */
  3511   3519     ExprList *pList       /* List to scan and in which to make substitutes */
  3512   3520   ){

Changes to src/sqlite.h.in.

  1738   1738   **
  1739   1739   ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
  1740   1740   ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
  1741   1741   ** interpreted as a boolean, which enables or disables the collection of
  1742   1742   ** memory allocation statistics. ^(When memory allocation statistics are
  1743   1743   ** disabled, the following SQLite interfaces become non-operational:
  1744   1744   **   <ul>
         1745  +**   <li> [sqlite3_hard_heap_limit64()]
  1745   1746   **   <li> [sqlite3_memory_used()]
  1746   1747   **   <li> [sqlite3_memory_highwater()]
  1747   1748   **   <li> [sqlite3_soft_heap_limit64()]
  1748   1749   **   <li> [sqlite3_status64()]
  1749   1750   **   </ul>)^
  1750   1751   ** ^Memory allocation statistics are enabled by default unless SQLite is
  1751   1752   ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
................................................................................
  6111   6112   **
  6112   6113   ** See also: [sqlite3_release_memory()]
  6113   6114   */
  6114   6115   int sqlite3_db_release_memory(sqlite3*);
  6115   6116   
  6116   6117   /*
  6117   6118   ** CAPI3REF: Impose A Limit On Heap Size
         6119  +**
         6120  +** These interfaces impose limits on the amount of heap memory that will be
         6121  +** by all database connections within a single process.
  6118   6122   **
  6119   6123   ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
  6120   6124   ** soft limit on the amount of heap memory that may be allocated by SQLite.
  6121   6125   ** ^SQLite strives to keep heap memory utilization below the soft heap
  6122   6126   ** limit by reducing the number of pages held in the page cache
  6123   6127   ** as heap memory usages approaches the limit.
  6124   6128   ** ^The soft heap limit is "soft" because even though SQLite strives to stay
  6125   6129   ** below the limit, it will exceed the limit rather than generate
  6126   6130   ** an [SQLITE_NOMEM] error.  In other words, the soft heap limit 
  6127   6131   ** is advisory only.
  6128   6132   **
  6129         -** ^The return value from sqlite3_soft_heap_limit64() is the size of
  6130         -** the soft heap limit prior to the call, or negative in the case of an
         6133  +** ^The sqlite3_hard_heap_limit64(N) interface sets a hard upper bound of
         6134  +** N bytes on the amount of memory that will be allocated.  ^The
         6135  +** sqlite3_hard_heap_limit64(N) interface is similar to
         6136  +** sqlite3_soft_heap_limit64(N) except that memory allocations will fail
         6137  +** when the hard heap limit is reached.
         6138  +**
         6139  +** ^The return value from both sqlite3_soft_heap_limit64() and
         6140  +** sqlite3_hard_heap_limit64() is the size of
         6141  +** the heap limit prior to the call, or negative in the case of an
  6131   6142   ** error.  ^If the argument N is negative
  6132         -** then no change is made to the soft heap limit.  Hence, the current
  6133         -** size of the soft heap limit can be determined by invoking
  6134         -** sqlite3_soft_heap_limit64() with a negative argument.
         6143  +** then no change is made to the heap limit.  Hence, the current
         6144  +** size of heap limits can be determined by invoking
         6145  +** sqlite3_soft_heap_limit64(-1) or sqlite3_hard_heap_limit(-1).
  6135   6146   **
  6136         -** ^If the argument N is zero then the soft heap limit is disabled.
         6147  +** ^Setting the heap limits to zero disables the heap limiter mechanism.
  6137   6148   **
  6138         -** ^(The soft heap limit is not enforced in the current implementation
         6149  +** ^The soft heap limit may not be greater than the hard heap limit.
         6150  +** ^If the hard heap limit is enabled and if sqlite3_soft_heap_limit(N)
         6151  +** is invoked with a value of N that is greater than the hard heap limit,
         6152  +** the the soft heap limit is set to the value of the hard heap limit.
         6153  +** ^The soft heap limit is automatically enabled whenever the hard heap
         6154  +** limit is enabled. ^When sqlite3_hard_heap_limit64(N) is invoked and
         6155  +** the soft heap limit is outside the range of 1..N, then the soft heap
         6156  +** limit is set to N.  ^Invoking sqlite3_soft_heap_limit64(0) when the
         6157  +** hard heap limit is enabled makes the soft heap limit equal to the
         6158  +** hard heap limit.
         6159  +**
         6160  +** The memory allocation limits can also be adjusted using
         6161  +** [PRAGMA soft_heap_limit] and [PRAGMA hard_heap_limit].
         6162  +**
         6163  +** ^(The heap limits are not enforced in the current implementation
  6139   6164   ** if one or more of following conditions are true:
  6140   6165   **
  6141   6166   ** <ul>
  6142         -** <li> The soft heap limit is set to zero.
         6167  +** <li> The limit value is set to zero.
  6143   6168   ** <li> Memory accounting is disabled using a combination of the
  6144   6169   **      [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and
  6145   6170   **      the [SQLITE_DEFAULT_MEMSTATUS] compile-time option.
  6146   6171   ** <li> An alternative page cache implementation is specified using
  6147   6172   **      [sqlite3_config]([SQLITE_CONFIG_PCACHE2],...).
  6148   6173   ** <li> The page cache allocates from its own memory pool supplied
  6149   6174   **      by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
  6150   6175   **      from the heap.
  6151   6176   ** </ul>)^
  6152   6177   **
  6153         -** Beginning with SQLite [version 3.7.3] ([dateof:3.7.3]), 
  6154         -** the soft heap limit is enforced
  6155         -** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT]
  6156         -** compile-time option is invoked.  With [SQLITE_ENABLE_MEMORY_MANAGEMENT],
  6157         -** the soft heap limit is enforced on every memory allocation.  Without
  6158         -** [SQLITE_ENABLE_MEMORY_MANAGEMENT], the soft heap limit is only enforced
  6159         -** when memory is allocated by the page cache.  Testing suggests that because
  6160         -** the page cache is the predominate memory user in SQLite, most
  6161         -** applications will achieve adequate soft heap limit enforcement without
  6162         -** the use of [SQLITE_ENABLE_MEMORY_MANAGEMENT].
  6163         -**
  6164         -** The circumstances under which SQLite will enforce the soft heap limit may
         6178  +** The circumstances under which SQLite will enforce the heap limits may
  6165   6179   ** changes in future releases of SQLite.
  6166   6180   */
  6167   6181   sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N);
         6182  +sqlite3_int64 sqlite3_hard_heap_limit64(sqlite3_int64 N);
  6168   6183   
  6169   6184   /*
  6170   6185   ** CAPI3REF: Deprecated Soft Heap Limit Interface
  6171   6186   ** DEPRECATED
  6172   6187   **
  6173   6188   ** This is a deprecated version of the [sqlite3_soft_heap_limit64()]
  6174   6189   ** interface.  This routine is provided for historical compatibility

Changes to src/sqlite3ext.h.

   320    320     /* Version 3.26.0 and later */
   321    321     const char *(*normalized_sql)(sqlite3_stmt*);
   322    322     /* Version 3.28.0 and later */
   323    323     int (*stmt_isexplain)(sqlite3_stmt*);
   324    324     int (*value_frombind)(sqlite3_value*);
   325    325     /* Version 3.30.0 and later */
   326    326     int (*drop_modules)(sqlite3*,const char**);
          327  +  sqlite3_int64 (*hard_heap_limit64)(sqlite3_int64);
   327    328   };
   328    329   
   329    330   /*
   330    331   ** This is the function signature used for all extension entry points.  It
   331    332   ** is also defined in the file "loadext.c".
   332    333   */
   333    334   typedef int (*sqlite3_loadext_entry)(
................................................................................
   614    615   /* Version 3.26.0 and later */
   615    616   #define sqlite3_normalized_sql         sqlite3_api->normalized_sql
   616    617   /* Version 3.28.0 and later */
   617    618   #define sqlite3_stmt_isexplain         sqlite3_api->isexplain
   618    619   #define sqlite3_value_frombind         sqlite3_api->frombind
   619    620   /* Version 3.30.0 and later */
   620    621   #define sqlite3_drop_modules           sqlite3_api->drop_modules
          622  +#define sqlite3_hard_heap_limit64      sqlite3_api->hard_heap_limit64
   621    623   #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
   622    624   
   623    625   #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
   624    626     /* This case when the file really is being compiled as a loadable 
   625    627     ** extension */
   626    628   # define SQLITE_EXTENSION_INIT1     const sqlite3_api_routines *sqlite3_api=0;
   627    629   # define SQLITE_EXTENSION_INIT2(v)  sqlite3_api=v;

Changes to src/sqliteInt.h.

  2581   2581   */
  2582   2582   #define EXPRDUP_REDUCE         0x0001  /* Used reduced-size Expr nodes */
  2583   2583   
  2584   2584   /*
  2585   2585   ** True if the expression passed as an argument was a function with
  2586   2586   ** an OVER() clause (a window function).
  2587   2587   */
  2588         -#define IsWindowFunc(p) ( \
         2588  +#ifdef SQLITE_OMIT_WINDOWFUNC
         2589  +# define IsWindowFunc(p) 0
         2590  +#else
         2591  +# define IsWindowFunc(p) ( \
  2589   2592       ExprHasProperty((p), EP_WinFunc) && p->y.pWin->eFrmType!=TK_FILTER \
  2590         -)
         2593  + )
         2594  +#endif
  2591   2595   
  2592   2596   /*
  2593   2597   ** A list of expressions.  Each expression may optionally have a
  2594   2598   ** name.  An expr/name combination can be used in several ways, such
  2595   2599   ** as the list of "expr AS ID" fields following a "SELECT" or in the
  2596   2600   ** list of "ID = expr" items in an UPDATE.  A list of expressions can
  2597   2601   ** also be used as the argument to a function, in which case the a.zName
................................................................................
  4476   4480        sqlite3*,
  4477   4481        const char*,
  4478   4482        const sqlite3_module*,
  4479   4483        void*,
  4480   4484        void(*)(void*)
  4481   4485      );
  4482   4486   #  define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
         4487  +#endif
         4488  +int sqlite3ReadOnlyShadowTables(sqlite3 *db);
         4489  +#ifndef SQLITE_OMIT_VIRTUALTABLE
         4490  +  int sqlite3ShadowTableName(sqlite3 *db, const char *zName);
         4491  +#else
         4492  +# define sqlite3ShadowTableName(A,B) 0
  4483   4493   #endif
  4484   4494   int sqlite3VtabEponymousTableInit(Parse*,Module*);
  4485   4495   void sqlite3VtabEponymousTableClear(sqlite3*,Module*);
  4486   4496   void sqlite3VtabMakeWritable(Parse*,Table*);
  4487   4497   void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*, int);
  4488   4498   void sqlite3VtabFinishParse(Parse*, Token*);
  4489   4499   void sqlite3VtabArgInit(Parse*);

Changes to src/test1.c.

  5521   5521     if( objc==2 ){
  5522   5522       if( Tcl_GetWideIntFromObj(interp, objv[1], &N) ) return TCL_ERROR;
  5523   5523     }
  5524   5524     amt = sqlite3_soft_heap_limit64(N);
  5525   5525     Tcl_SetObjResult(interp, Tcl_NewWideIntObj(amt));
  5526   5526     return TCL_OK;
  5527   5527   }
         5528  +
         5529  +/*
         5530  +** Usage:  sqlite3_hard_heap_limit ?N?
         5531  +**
         5532  +** Query or set the hard heap limit for the current thread.  The
         5533  +** limit is only changed if the N is present.  The previous limit
         5534  +** is returned.
         5535  +*/
         5536  +static int SQLITE_TCLAPI test_hard_heap_limit(
         5537  +  void * clientData,
         5538  +  Tcl_Interp *interp,
         5539  +  int objc,
         5540  +  Tcl_Obj *CONST objv[]
         5541  +){
         5542  +  sqlite3_int64 amt;
         5543  +  Tcl_WideInt N = -1;
         5544  +  if( objc!=1 && objc!=2 ){
         5545  +    Tcl_WrongNumArgs(interp, 1, objv, "?N?");
         5546  +    return TCL_ERROR;
         5547  +  }
         5548  +  if( objc==2 ){
         5549  +    if( Tcl_GetWideIntFromObj(interp, objv[1], &N) ) return TCL_ERROR;
         5550  +  }
         5551  +  amt = sqlite3_hard_heap_limit64(N);
         5552  +  Tcl_SetObjResult(interp, Tcl_NewWideIntObj(amt));
         5553  +  return TCL_OK;
         5554  +}
  5528   5555   
  5529   5556   /*
  5530   5557   ** Usage:   sqlite3_thread_cleanup
  5531   5558   **
  5532   5559   ** Call the sqlite3_thread_cleanup API.
  5533   5560   */
  5534   5561   static int SQLITE_TCLAPI test_thread_cleanup(
................................................................................
  7969   7996        { "sqlite3_release_memory",        test_release_memory,     0},
  7970   7997        { "sqlite3_db_release_memory",     test_db_release_memory,  0},
  7971   7998        { "sqlite3_db_cacheflush",         test_db_cacheflush,      0},
  7972   7999        { "sqlite3_system_errno",          test_system_errno,       0},
  7973   8000        { "sqlite3_db_filename",           test_db_filename,        0},
  7974   8001        { "sqlite3_db_readonly",           test_db_readonly,        0},
  7975   8002        { "sqlite3_soft_heap_limit",       test_soft_heap_limit,    0},
         8003  +     { "sqlite3_soft_heap_limit64",     test_soft_heap_limit,    0},
         8004  +     { "sqlite3_hard_heap_limit64",     test_hard_heap_limit,    0},
  7976   8005        { "sqlite3_thread_cleanup",        test_thread_cleanup,     0},
  7977   8006        { "sqlite3_pager_refcounts",       test_pager_refcounts,    0},
  7978   8007   
  7979   8008        { "sqlite3_load_extension",        test_load_extension,     0},
  7980   8009        { "sqlite3_enable_load_extension", test_enable_load,        0},
  7981   8010        { "sqlite3_extended_result_codes", test_extended_result_codes, 0},
  7982   8011        { "sqlite3_limit",                 test_limit,                 0},

Changes to src/treeview.c.

    62     62       }
    63     63       sqlite3_str_append(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
    64     64     }
    65     65     if( zFormat!=0 ){
    66     66       va_start(ap, zFormat);
    67     67       sqlite3_str_vappendf(&acc, zFormat, ap);
    68     68       va_end(ap);
    69         -    assert( acc.nChar>0 );
           69  +    assert( acc.nChar>0 || acc.accError );
    70     70       sqlite3_str_append(&acc, "\n", 1);
    71     71     }
    72     72     sqlite3StrAccumFinish(&acc);
    73     73     fprintf(stdout,"%s", zBuf);
    74     74     fflush(stdout);
    75     75   }
    76     76   

Changes to src/vdbe.c.

  4534   4534     BtCursor *pCrsr;
  4535   4535     int res;
  4536   4536     u64 iKey;
  4537   4537   
  4538   4538     pIn3 = &aMem[pOp->p3];
  4539   4539     testcase( pIn3->flags & MEM_Int );
  4540   4540     testcase( pIn3->flags & MEM_IntReal );
         4541  +  testcase( pIn3->flags & MEM_Real );
         4542  +  testcase( (pIn3->flags & (MEM_Str|MEM_Int))==MEM_Str );
  4541   4543     if( (pIn3->flags & (MEM_Int|MEM_IntReal))==0 ){
  4542         -    /* Make sure pIn3->u.i contains a valid integer representation of
  4543         -    ** the key value, but do not change the datatype of the register, as
  4544         -    ** other parts of the perpared statement might be depending on the
  4545         -    ** current datatype. */
  4546         -    u16 origFlags = pIn3->flags;
  4547         -    int isNotInt;
  4548         -    applyAffinity(pIn3, SQLITE_AFF_NUMERIC, encoding);
  4549         -    isNotInt = (pIn3->flags & MEM_Int)==0;
  4550         -    pIn3->flags = origFlags;
  4551         -    if( isNotInt ) goto jump_to_p2;
         4544  +    /* If pIn3->u.i does not contain an integer, compute iKey as the
         4545  +    ** integer value of pIn3.  Jump to P2 if pIn3 cannot be converted
         4546  +    ** into an integer without loss of information.  Take care to avoid
         4547  +    ** changing the datatype of pIn3, however, as it is used by other
         4548  +    ** parts of the prepared statement. */
         4549  +    Mem x = pIn3[0];
         4550  +    applyAffinity(&x, SQLITE_AFF_NUMERIC, encoding);
         4551  +    if( (x.flags & MEM_Int)==0 ) goto jump_to_p2;
         4552  +    iKey = x.u.i;
         4553  +    goto notExistsWithKey;
  4552   4554     }
  4553   4555     /* Fall through into OP_NotExists */
  4554   4556   case OP_NotExists:          /* jump, in3 */
  4555   4557     pIn3 = &aMem[pOp->p3];
  4556   4558     assert( (pIn3->flags & MEM_Int)!=0 || pOp->opcode==OP_SeekRowid );
  4557   4559     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
         4560  +  iKey = pIn3->u.i;
         4561  +notExistsWithKey:
  4558   4562     pC = p->apCsr[pOp->p1];
  4559   4563     assert( pC!=0 );
  4560   4564   #ifdef SQLITE_DEBUG
  4561   4565     if( pOp->opcode==OP_SeekRowid ) pC->seekOp = OP_SeekRowid;
  4562   4566   #endif
  4563   4567     assert( pC->isTable );
  4564   4568     assert( pC->eCurType==CURTYPE_BTREE );
  4565   4569     pCrsr = pC->uc.pCursor;
  4566   4570     assert( pCrsr!=0 );
  4567   4571     res = 0;
  4568         -  iKey = pIn3->u.i;
  4569   4572     rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res);
  4570   4573     assert( rc==SQLITE_OK || res==0 );
  4571   4574     pC->movetoTarget = iKey;  /* Used by OP_Delete */
  4572   4575     pC->nullRow = 0;
  4573   4576     pC->cacheStatus = CACHE_STALE;
  4574   4577     pC->deferredMoveto = 0;
  4575   4578     VdbeBranchTaken(res!=0,2);

Changes to src/vdbeaux.c.

   636    636     memset(&sIter, 0, sizeof(sIter));
   637    637     sIter.v = v;
   638    638   
   639    639     while( (pOp = opIterNext(&sIter))!=0 ){
   640    640       int opcode = pOp->opcode;
   641    641       if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename 
   642    642        || opcode==OP_VDestroy
   643         -     || (opcode==OP_Function0 && pOp->p4.pFunc->funcFlags&SQLITE_FUNC_INTERNAL)
          643  +     || (opcode==OP_ParseSchema && pOp->p4.z==0)
   644    644        || ((opcode==OP_Halt || opcode==OP_HaltIfNull) 
   645    645         && ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
   646    646       ){
   647    647         hasAbort = 1;
   648    648         break;
   649    649       }
   650    650       if( opcode==OP_CreateBtree && pOp->p3==BTREE_INTKEY ) hasCreateTable = 1;

Changes to test/altertab.test.

   542    542       CREATE VIRTUAL TABLE y1 USING fts3;
   543    543     }
   544    544   
   545    545     do_catchsql_test 16.1 {
   546    546       INSERT INTO y1_segments VALUES(1, X'1234567890');
   547    547     } {1 {table y1_segments may not be modified}}
   548    548   
   549         -  do_catchsql_test 16.2 {
          549  +  do_catchsql_test 16.20 {
          550  +    DROP TABLE y1_segments;
          551  +  } {1 {table y1_segments may not be dropped}}
          552  +
          553  +  do_catchsql_test 16.21 {
          554  +    DROP TABLE y1_segments;
          555  +  } {1 {table y1_segments may not be dropped}}
          556  +
          557  +  sqlite3_db_config db DEFENSIVE 0
          558  +  do_catchsql_test 16.22 {
   550    559       ALTER TABLE y1_segments RENAME TO abc;
   551         -  } {1 {table y1_segments may not be altered}}
          560  +  } {0 {}}
          561  +  sqlite3_db_config db DEFENSIVE 1
          562  +  do_catchsql_test 16.23 {
          563  +    CREATE TABLE y1_segments AS SELECT * FROM abc;
          564  +  } {1 {object name reserved for internal use: y1_segments}}
          565  +  do_catchsql_test 16.24 {
          566  +    CREATE VIEW y1_segments AS SELECT * FROM abc;
          567  +  } {1 {object name reserved for internal use: y1_segments}}
          568  +  sqlite3_db_config db DEFENSIVE 0
          569  +  do_catchsql_test 16.25 {
          570  +    ALTER TABLE abc RENAME TO y1_segments;
          571  +  } {0 {}}
          572  +  sqlite3_db_config db DEFENSIVE 1
   552    573   
   553         -  do_execsql_test 16.3 {
          574  +  do_execsql_test 16.30 {
   554    575       ALTER TABLE y1 RENAME TO z1;
   555    576     }
   556    577   
   557    578     do_execsql_test 16.4 {
   558    579       SELECT * FROM z1_segments;
   559    580     }
   560    581   }

Changes to test/filter1.test.

   159    159   } {2.0 5.0 10.0}
   160    160   do_execsql_test 4.3 {
   161    161     SELECT a, avg(c) FILTER (WHERE b!=1) AS h FROM t1 GROUP BY a ORDER BY avg(c);
   162    162   } {c 2.0 a 10.0 b 5.0}
   163    163   do_execsql_test 4.4 {
   164    164     SELECT a, avg(c) FILTER (WHERE b!=1) FROM t1 GROUP BY a ORDER BY 2
   165    165   } {c 2.0 b 5.0 a 10.0}
          166  +
          167  +#-------------------------------------------------------------------------
          168  +reset_db
          169  +do_execsql_test 5.0 {
          170  +  CREATE TABLE t1(a, b);
          171  +  INSERT INTO t1 VALUES(1, 2);
          172  +  INSERT INTO t1 VALUES(1, 3);
          173  +}
          174  +
          175  +do_execsql_test 5.1 {
          176  +  SELECT count(*) FILTER (WHERE b>2) FROM (SELECT * FROM t1) 
          177  +} {1}
          178  +
          179  +do_execsql_test 5.2 {
          180  +  SELECT count(*) FILTER (WHERE b>2) OVER () FROM (SELECT * FROM t1) 
          181  +} {1 1}
          182  +
          183  +do_execsql_test 5.3 {
          184  +  SELECT count(*) FILTER (WHERE b>2) OVER (ORDER BY b) FROM (SELECT * FROM t1) 
          185  +} {0 1}
   166    186   
   167    187   finish_test
   168    188   

Changes to test/fuzzcheck.c.

   448    448   static int giTimeout = 10000;   /* Defaults to 10 seconds */
   449    449   
   450    450   /* Maximum number of progress handler callbacks */
   451    451   static unsigned int mxProgressCb = 2000;
   452    452   
   453    453   /* Maximum string length in SQLite */
   454    454   static int lengthLimit = 1000000;
          455  +
          456  +/* Limit on the amount of heap memory that can be used */
          457  +static sqlite3_int64 heapLimit = 1000000000;
   455    458   
   456    459   /* Maximum byte-code program length in SQLite */
   457    460   static int vdbeOpLimit = 25000;
   458    461   
   459    462   /* Maximum size of the in-memory database */
   460    463   static sqlite3_int64 maxDbSize = 104857600;
   461    464   
................................................................................
   773    776     ** maximum length of a string or blob */
   774    777     if( vdbeOpLimit>0 ){
   775    778       sqlite3_limit(cx.db, SQLITE_LIMIT_VDBE_OP, vdbeOpLimit);
   776    779     }
   777    780     if( lengthLimit>0 ){
   778    781       sqlite3_limit(cx.db, SQLITE_LIMIT_LENGTH, lengthLimit);
   779    782     }
          783  +  sqlite3_hard_heap_limit64(heapLimit);
   780    784   
   781    785     if( nDb>=20 && aDb[18]==2 && aDb[19]==2 ){
   782    786       aDb[18] = aDb[19] = 1;
   783    787     }
   784    788     rc = sqlite3_deserialize(cx.db, "main", aDb, nDb, nDb,
   785    789             SQLITE_DESERIALIZE_RESIZEABLE |
   786    790             SQLITE_DESERIALIZE_FREEONCLOSE);
................................................................................
  1337   1341     int iSrcDb;                  /* Loop over all source databases */
  1338   1342     int nTest = 0;               /* Total number of tests performed */
  1339   1343     char *zDbName = "";          /* Appreviated name of a source database */
  1340   1344     const char *zFailCode = 0;   /* Value of the TEST_FAILURE env variable */
  1341   1345     int cellSzCkFlag = 0;        /* --cell-size-check */
  1342   1346     int sqlFuzz = 0;             /* True for SQL fuzz. False for DB fuzz */
  1343   1347     int iTimeout = 120;          /* Default 120-second timeout */
  1344         -  int nMem = 0;                /* Memory limit */
         1348  +  int nMem = 0;                /* Memory limit override */
  1345   1349     int nMemThisDb = 0;          /* Memory limit set by the CONFIG table */
  1346   1350     char *zExpDb = 0;            /* Write Databases to files in this directory */
  1347   1351     char *zExpSql = 0;           /* Write SQL to files in this directory */
  1348   1352     void *pHeap = 0;             /* Heap for use by SQLite */
  1349   1353     int ossFuzz = 0;             /* enable OSS-FUZZ testing */
  1350   1354     int ossFuzzThisDb = 0;       /* ossFuzz value for this particular database */
  1351   1355     int nativeMalloc = 0;        /* Turn off MEMSYS3/5 and lookaside if true */
................................................................................
  1387   1391           showHelp();
  1388   1392           return 0;
  1389   1393         }else
  1390   1394         if( strcmp(z,"info")==0 ){
  1391   1395           infoFlag = 1;
  1392   1396         }else
  1393   1397         if( strcmp(z,"limit-mem")==0 ){
  1394         -#if !defined(SQLITE_ENABLE_MEMSYS3) && !defined(SQLITE_ENABLE_MEMSYS5)
  1395         -        fatalError("the %s option requires -DSQLITE_ENABLE_MEMSYS5 or _MEMSYS3",
  1396         -                   argv[i]);
  1397         -#else
  1398   1398           if( i>=argc-1 ) fatalError("missing arguments on %s", argv[i]);
  1399   1399           nMem = integerValue(argv[++i]);
  1400         -#endif
  1401   1400         }else
  1402   1401         if( strcmp(z,"limit-vdbe")==0 ){
  1403   1402           vdbeLimitFlag = 1;
  1404   1403         }else
  1405   1404         if( strcmp(z,"load-sql")==0 ){
  1406   1405           zInsSql = "INSERT INTO xsql(sqltext)VALUES(CAST(readfile(?1) AS text))";
  1407   1406           iFirstInsArg = i+1;
................................................................................
  1582   1581         while( SQLITE_ROW==sqlite3_step(pStmt) ){
  1583   1582           const char *zName = (const char *)sqlite3_column_text(pStmt,0);
  1584   1583           if( zName==0 ) continue;
  1585   1584           if( strcmp(zName, "oss-fuzz")==0 ){
  1586   1585             ossFuzzThisDb = sqlite3_column_int(pStmt,1);
  1587   1586             if( verboseFlag ) printf("Config: oss-fuzz=%d\n", ossFuzzThisDb);
  1588   1587           }
  1589         -        if( strcmp(zName, "limit-mem")==0 && !nativeMalloc ){
  1590         -#if !defined(SQLITE_ENABLE_MEMSYS3) && !defined(SQLITE_ENABLE_MEMSYS5)
  1591         -          fatalError("the limit-mem option requires -DSQLITE_ENABLE_MEMSYS5"
  1592         -                     " or _MEMSYS3");
  1593         -#else
         1588  +        if( strcmp(zName, "limit-mem")==0 ){
  1594   1589             nMemThisDb = sqlite3_column_int(pStmt,1);
  1595   1590             if( verboseFlag ) printf("Config: limit-mem=%d\n", nMemThisDb);
  1596         -#endif
  1597   1591           }
  1598   1592         }
  1599   1593         sqlite3_finalize(pStmt);
  1600   1594       }
  1601   1595   
  1602   1596       if( zInsSql ){
  1603   1597         sqlite3_create_function(db, "readfile", 1, SQLITE_UTF8, 0,
................................................................................
  1716   1710       sqlite3_close(db);
  1717   1711       if( sqlite3_memory_used()>0 ){
  1718   1712         fatalError("SQLite has memory in use before the start of testing");
  1719   1713       }
  1720   1714   
  1721   1715       /* Limit available memory, if requested */
  1722   1716       sqlite3_shutdown();
  1723         -    if( nMemThisDb>0 && !nativeMalloc ){
  1724         -      pHeap = realloc(pHeap, nMemThisDb);
  1725         -      if( pHeap==0 ){
  1726         -        fatalError("failed to allocate %d bytes of heap memory", nMem);
         1717  +    if( nMemThisDb>0 && nMem==0 ){
         1718  +      if( !nativeMalloc ){
         1719  +        pHeap = realloc(pHeap, nMemThisDb);
         1720  +        if( pHeap==0 ){
         1721  +          fatalError("failed to allocate %d bytes of heap memory", nMem);
         1722  +        }
         1723  +        sqlite3_config(SQLITE_CONFIG_HEAP, pHeap, nMemThisDb, 128);
         1724  +      }else{
         1725  +        sqlite3_hard_heap_limit64((sqlite3_int64)nMemThisDb);
  1727   1726         }
  1728         -      sqlite3_config(SQLITE_CONFIG_HEAP, pHeap, nMemThisDb, 128);
         1727  +    }else{
         1728  +      sqlite3_hard_heap_limit64(0);
  1729   1729       }
  1730   1730   
  1731   1731       /* Disable lookaside with the --native-malloc option */
  1732   1732       if( nativeMalloc ){
  1733   1733         sqlite3_config(SQLITE_CONFIG_LOOKASIDE, 0, 0);
  1734   1734       }
  1735   1735     

Changes to test/join.test.

   879    879     INSERT INTO t1(x) VALUES(0),(1);
   880    880     SELECT * FROM t1 LEFT JOIN (SELECT abs(1) AS y FROM t1) ON x WHERE NOT(y='a');
   881    881   } {1 1 1 1}
   882    882   do_execsql_test join-17.110 {
   883    883     SELECT * FROM t1 LEFT JOIN (SELECT abs(1)+2 AS y FROM t1) ON x
   884    884      WHERE NOT(y='a');
   885    885   } {1 3 1 3}
          886  +
          887  +#-------------------------------------------------------------------------
          888  +reset_db
          889  +do_execsql_test join-18.1 {
          890  +  CREATE TABLE t0(a);
          891  +  CREATE TABLE t1(b);
          892  +  CREATE VIEW v0 AS SELECT a FROM t1 LEFT JOIN t0;
          893  +  INSERT INTO t1 VALUES (1);
          894  +} {}
          895  +
          896  +do_execsql_test join-18.2 {
          897  +  SELECT * FROM v0 WHERE NOT(v0.a IS FALSE);
          898  +} {{}}
          899  +
          900  +do_execsql_test join-18.3 {
          901  +  SELECT * FROM t1 LEFT JOIN t0 WHERE NOT(a IS FALSE);
          902  +} {1 {}}
          903  +
          904  +do_execsql_test join-18.4 {
          905  +  SELECT NOT(v0.a IS FALSE) FROM v0
          906  +} {1}
   886    907   
   887    908   finish_test
          909  +

Changes to test/ossfuzz.c.

   150    150     cx.iCutoffTime = cx.iLastCb + 10000;  /* Now + 10 seconds */
   151    151   #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
   152    152     sqlite3_progress_handler(cx.db, 10, progress_handler, (void*)&cx);
   153    153   #endif
   154    154   
   155    155     /* Set a limit on the maximum size of a prepared statement */
   156    156     sqlite3_limit(cx.db, SQLITE_LIMIT_VDBE_OP, 25000);
          157  +
          158  +  /* Limit total memory available to SQLite to 20MB */
          159  +  sqlite3_hard_heap_limit64(20000000);
   157    160   
   158    161     /* Set a limit on the maximum length of a string or BLOB.  Without this
   159    162     ** limit, fuzzers will invoke randomblob(N) for a large N, and the process
   160    163     ** will timeout trying to generate the huge blob */
   161    164     sqlite3_limit(cx.db, SQLITE_LIMIT_LENGTH, 50000);
   162    165   
   163    166     /* Bit 1 of the selector enables foreign key constraints */

Changes to test/tester.tcl.

   384    384   
   385    385   # Print a HELP message and exit
   386    386   #
   387    387   proc print_help_and_quit {} {
   388    388     puts {Options:
   389    389     --pause                  Wait for user input before continuing
   390    390     --soft-heap-limit=N      Set the soft-heap-limit to N
          391  +  --hard-heap-limit=N      Set the hard-heap-limit to N
   391    392     --maxerror=N             Quit after N errors
   392    393     --verbose=(0|1)          Control the amount of output.  Default '1'
   393    394     --output=FILE            set --verbose=2 and output to FILE.  Implies -q
   394    395     -q                       Shorthand for --verbose=0
   395    396     --help                   This message
   396    397   }
   397    398     exit 1
................................................................................
   404    405   if {[info exists cmdlinearg]==0} {
   405    406   
   406    407     # Parse any options specified in the $argv array. This script accepts the
   407    408     # following options:
   408    409     #
   409    410     #   --pause
   410    411     #   --soft-heap-limit=NN
          412  +  #   --hard-heap-limit=NN
   411    413     #   --maxerror=NN
   412    414     #   --malloctrace=N
   413    415     #   --backtrace=N
   414    416     #   --binarylog=N
   415    417     #   --soak=N
   416    418     #   --file-retries=N
   417    419     #   --file-retry-delay=N
................................................................................
   420    422     #   --verbose=$val
   421    423     #   --output=$filename
   422    424     #   -q                                      Reduce output
   423    425     #   --testdir=$dir                          Run tests in subdirectory $dir
   424    426     #   --help
   425    427     #
   426    428     set cmdlinearg(soft-heap-limit)    0
          429  +  set cmdlinearg(hard-heap-limit)    0
   427    430     set cmdlinearg(maxerror)        1000
   428    431     set cmdlinearg(malloctrace)        0
   429    432     set cmdlinearg(backtrace)         10
   430    433     set cmdlinearg(binarylog)          0
   431    434     set cmdlinearg(soak)               0
   432    435     set cmdlinearg(file-retries)       0
   433    436     set cmdlinearg(file-retry-delay)   0
................................................................................
   446    449           puts -nonewline "Press RETURN to begin..."
   447    450           flush stdout
   448    451           gets stdin
   449    452         }
   450    453         {^-+soft-heap-limit=.+$} {
   451    454           foreach {dummy cmdlinearg(soft-heap-limit)} [split $a =] break
   452    455         }
          456  +      {^-+hard-heap-limit=.+$} {
          457  +        foreach {dummy cmdlinearg(hard-heap-limit)} [split $a =] break
          458  +      }
   453    459         {^-+maxerror=.+$} {
   454    460           foreach {dummy cmdlinearg(maxerror)} [split $a =] break
   455    461         }
   456    462         {^-+malloctrace=.+$} {
   457    463           foreach {dummy cmdlinearg(malloctrace)} [split $a =] break
   458    464           if {$cmdlinearg(malloctrace)} {
   459    465             if {0==$::sqlite_options(memdebug)} {
................................................................................
   582    588     }
   583    589   }
   584    590   
   585    591   # Update the soft-heap-limit each time this script is run. In that
   586    592   # way if an individual test file changes the soft-heap-limit, it
   587    593   # will be reset at the start of the next test file.
   588    594   #
   589         -sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit)
          595  +sqlite3_soft_heap_limit64 $cmdlinearg(soft-heap-limit)
          596  +sqlite3_hard_heap_limit64 $cmdlinearg(hard-heap-limit)
   590    597   
   591    598   # Create a test database
   592    599   #
   593    600   proc reset_db {} {
   594    601     catch {db close}
   595    602     forcedelete test.db
   596    603     forcedelete test.db-journal
................................................................................
  1203   1210   
  1204   1211     vfs_unlink_test
  1205   1212     sqlite3 db {}
  1206   1213     # sqlite3_clear_tsd_memdebug
  1207   1214     db close
  1208   1215     sqlite3_reset_auto_extension
  1209   1216   
  1210         -  sqlite3_soft_heap_limit 0
         1217  +  sqlite3_soft_heap_limit64 0
         1218  +  sqlite3_hard_heap_limit64 0
  1211   1219     set nTest [incr_ntest]
  1212   1220     set nErr [set_test_counter errors]
  1213   1221   
  1214   1222     set nKnown 0
  1215   1223     if {[file readable known-problems.txt]} {
  1216   1224       set fd [open known-problems.txt]
  1217   1225       set content [read $fd]

Changes to test/window1.test.

  1185   1185       count () OVER win3
  1186   1186     FROM t1
  1187   1187     WINDOW win1 AS (ORDER BY a GROUPS BETWEEN 4 PRECEDING AND 1 FOLLOWING
  1188   1188                     EXCLUDE CURRENT ROW),
  1189   1189            win2 AS (PARTITION BY b ORDER BY a),
  1190   1190            win3 AS (win2 RANGE BETWEEN 5.2 PRECEDING AND true PRECEDING );
  1191   1191   } {1 1}
         1192  +
         1193  +#-------------------------------------------------------------------------
         1194  +reset_db
         1195  +do_execsql_test 31.1 {
         1196  +  CREATE TABLE t1(a, b);
         1197  +  CREATE TABLE t2(c, d);
         1198  +  CREATE TABLE t3(e, f);
         1199  +
         1200  +  INSERT INTO t1 VALUES(1, 1);
         1201  +  INSERT INTO t2 VALUES(1, 1);
         1202  +  INSERT INTO t3 VALUES(1, 1);
         1203  +}
         1204  +
         1205  +do_execsql_test 31.2 {
         1206  +  SELECT d IN (SELECT sum(c) OVER (ORDER BY e+c) FROM t3) FROM (
         1207  +    SELECT * FROM t2
         1208  +  );
         1209  +} {1}
         1210  +
         1211  +do_execsql_test 31.3 {
         1212  +  SELECT d IN (SELECT sum(c) OVER (PARTITION BY d ORDER BY e+c) FROM t3) FROM (
         1213  +    SELECT * FROM t2
         1214  +  );
         1215  +} {1}
         1216  +
         1217  +do_catchsql_test 31.3 {
         1218  +  SELECT d IN (
         1219  +    SELECT sum(c) OVER ( ROWS BETWEEN d FOLLOWING AND UNBOUNDED FOLLOWING) 
         1220  +    FROM t3
         1221  +  )
         1222  +  FROM (
         1223  +    SELECT * FROM t2
         1224  +  );
         1225  +} {1 {frame starting offset must be a non-negative integer}}
         1226  +
         1227  +do_catchsql_test 31.3 {
         1228  +  SELECT d IN (
         1229  +    SELECT sum(c) OVER ( ROWS BETWEEN CURRENT ROW AND c FOLLOWING) 
         1230  +    FROM t3
         1231  +  )
         1232  +  FROM (
         1233  +    SELECT * FROM t2
         1234  +  );
         1235  +} {1 {frame ending offset must be a non-negative integer}}
  1192   1236   
  1193   1237   finish_test

Changes to tool/mkpragmatab.tcl.

   401    401     IF:   defined(SQLITE_HAS_CODEC)
   402    402   
   403    403     NAME: activate_extensions
   404    404     IF:   defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD)
   405    405   
   406    406     NAME: soft_heap_limit
   407    407     FLAG: Result0
          408  +
          409  +  NAME: hard_heap_limit
          410  +  FLAG: Result0
   408    411   
   409    412     NAME: threads
   410    413     FLAG: Result0
   411    414   
   412    415     NAME: optimize
   413    416     FLAG: Result1 NeedSchema
   414    417