sqlite: upgraded package to upstream

Upgraded dev-db/sqlite to version 3.31.1 on amd64

BUG=chromium:1040167, b:147888523
TEST=CQ passes
RELEASE_NOTE=Upgraded dev-db/sqlite to 3.31.1.

Change-Id: If41092b227278c9cc5bf4dbf40bc300bbb342d31
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/overlays/portage-stable/+/2108702
Tested-by: Allen Webb <allenwebb@google.com>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Allen Webb <allenwebb@google.com>
(cherry picked from commit cf34f078bf498e0e8a9e02ee536f3186f194a197)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/overlays/portage-stable/+/2130468
Reviewed-by: Allen Webb <allenwebb@google.com>
Commit-Queue: Vaibhav Rustagi <vaibhavrustagi@google.com>
Tested-by: Vaibhav Rustagi <vaibhavrustagi@google.com>
Auto-Submit: Vaibhav Rustagi <vaibhavrustagi@google.com>
diff --git a/dev-db/sqlite/Manifest b/dev-db/sqlite/Manifest
index be394b8..a5126e7 100644
--- a/dev-db/sqlite/Manifest
+++ b/dev-db/sqlite/Manifest
@@ -1,3 +1,3 @@
-DIST sqlite-autoconf-3300100.tar.gz 2848951 BLAKE2B 3a541a2b07ebbaf7ddca4693b71765e2ecd11974dd64b4a7a19eaee4eea8a17a6004c69f3b2163213fe7568480152709745e029107711813d4bdd41052763cd1 SHA512 9ec0283c417fb0323b0e43550af2a49e9a63988e4212c27ea62cc9da3534caa6faf5bdc7e051b6772c4ce61560a433b3d3288b68e05e9ba8495f61a3bcebda3e
-DIST sqlite-doc-3300100.zip 9485342 BLAKE2B bf5e3909a327c773106d4990b3e3be5dd63db2dbc1a7f8a7c1bd16f39bec83a6b2a98c4c56ded3b58f4087dcdcc934e542db36e142bf338a411ed7115d67d6b3 SHA512 373e843015307071443a0db5fb930f9120718f6118cc2e21b506fdc8535fbe6996e9889e8b5809ffb91257addfe778bdf3412a81e11f6bced2c5e0330337d00d
-DIST sqlite-src-3300100.zip 12648162 BLAKE2B bb239bac9115c74778de0347b4f4e24a82f149f55fe7dea8b89eb859bfe4cf6f6c2f065f5e1741c40624bb88ecd395140064a41d475a1c64a0188990fd6248e7 SHA512 f40236d0bb25f3ea01a1192dace3b6732fb671fbdabb7cfa8d0cc2b99d21aef00ae380999fdee904501cb03304644cddfb2506951f36a2f6a83693f311c3c11d
+DIST sqlite-autoconf-3310100.tar.gz 2887243 BLAKE2B ef5d40b6e6c59a51ae95368eb9f6a938188813f89d5328ea1c1180ef35f124c14b3e83b0832ae5c2fa24cc2df352f1b0ea5f20b64d0762d50a700d9895f9a12e SHA512 d85250ba5f78f0c918880f663741709aba662192f04888b2324a0df17affdf5b8540e8428c6c7315119806e7adad758ea281c9b403c0ad94ac6a9bd1b93fd617
+DIST sqlite-doc-3310100.zip 9600405 BLAKE2B 324fb7a0a38bc56476e41504c14996e9d5d83ac659403991515413d49f5ee3aad064ccece25f52b6041ef26bf23f320a9be1b6b02c5fbe96c36372107f54fc2e SHA512 5572e2c2dac30c014ef9cd60a620b7a7bb610f91a47e2890c0641540d39b9d5ce0e914ee697583130317633918b7827e2612a7cbc024f5bd6aa22ad28a78b56b
+DIST sqlite-src-3310100.zip 12510166 BLAKE2B a856695e8552b8b4dcb28452fdbd48305fdb9072f9d6587f4b1f4445daf386e920eb936dcb50fdfe41a49f84b26a7c5fedcffea5acf3ba3fa935c36695d4b8ee SHA512 af92a00877bcd90372d6f83a27fea12b4fe8d1155b223a6bccbccc31bb8e3d2269cd9e68f329bc55f70d1068ccbf220ff5abccea6f593fd7a3a4bdd732d1cdbe
diff --git a/dev-db/sqlite/files/sqlite-3.30.1-CVE-2019-19880.patch b/dev-db/sqlite/files/sqlite-3.30.1-CVE-2019-19880.patch
deleted file mode 100644
index caaf62a..0000000
--- a/dev-db/sqlite/files/sqlite-3.30.1-CVE-2019-19880.patch
+++ /dev/null
@@ -1,19 +0,0 @@
-Pick sqlite upstream patch from
-https://github.com/sqlite/sqlite/commit/75e95e1fcd52d3ec8282edb75ac8cd0814095d54
-to fix CVE-2019-19880.
-diff --git a/sqlite3.c b/sqlite3.c
-index 8fd740b..1a5886b 100644
---- a/sqlite3.c
-+++ b/sqlite3.c
-@@ -147583,9 +147583,11 @@ static ExprList *exprListAppendList(
-     int nInit = pList ? pList->nExpr : 0;
-     for(i=0; i<pAppend->nExpr; i++){
-       Expr *pDup = sqlite3ExprDup(pParse->db, pAppend->a[i].pExpr, 0);
-+      assert( pDup==0 || !ExprHasProperty(pDup, EP_MemToken) );
-       if( bIntToNull && pDup && pDup->op==TK_INTEGER ){
-         pDup->op = TK_NULL;
-         pDup->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse);
-+        pDup->u.zToken = 0;
-       }
-       pList = sqlite3ExprListAppend(pParse, pList, pDup);
-       if( pList ) pList->a[nInit+i].sortFlags = pAppend->a[i].sortFlags;
diff --git a/dev-db/sqlite/files/sqlite-3.30.1-CVE-2019-20218.patch b/dev-db/sqlite/files/sqlite-3.30.1-CVE-2019-20218.patch
deleted file mode 100644
index 440ff03..0000000
--- a/dev-db/sqlite/files/sqlite-3.30.1-CVE-2019-20218.patch
+++ /dev/null
@@ -1,27 +0,0 @@
-From 47f431ae4b0f8e7851ba17f190b606ccbcf52acd Mon Sep 17 00:00:00 2001
-From: Gwendal Grignou <gwendal@chromium.org>
-Date: Fri, 17 Jan 2020 16:46:21 -0800
-Subject: [PATCH] Pick sqlite upstream patch from
- https://github.com/sqlite/sqlite/commit/a6c1a71cde082e09750465d5675699062922e387.patch
- to fix CVE-2019-20218.
-
----
- sqlite3.c | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/sqlite3.c b/sqlite3.c
-index 1a5886b..4df15f8 100644
---- a/sqlite3.c
-+++ b/sqlite3.c
-@@ -130566,7 +130566,7 @@ static int selectExpander(Walker *pWalker, Select *p){
- 
-   /* Process NATURAL keywords, and ON and USING clauses of joins.
-   */
--  if( db->mallocFailed || sqliteProcessJoin(pParse, p) ){
-+  if( pParse->nErr || db->mallocFailed || sqliteProcessJoin(pParse, p) ){
-     return WRC_Abort;
-   }
- 
--- 
-2.24.1
-
diff --git a/dev-db/sqlite/files/sqlite-3.31.0-full_archive-build.patch b/dev-db/sqlite/files/sqlite-3.31.0-full_archive-build.patch
new file mode 100644
index 0000000..9ff44c0
--- /dev/null
+++ b/dev-db/sqlite/files/sqlite-3.31.0-full_archive-build.patch
@@ -0,0 +1,466 @@
+Move some code to libsqlite3.so to avoid duplication.
+Link executables against libsqlite3.so.
+Increase timeout for fuzzcheck.
+Fix building with dlopen() not available.
+
+--- /Makefile.in
++++ /Makefile.in
+@@ -311,6 +311,9 @@
+ # Source code for extensions
+ #
+ SRC += \
++  $(TOP)/ext/expert/sqlite3expert.c \
++  $(TOP)/ext/expert/sqlite3expert.h
++SRC += \
+   $(TOP)/ext/fts1/fts1.c \
+   $(TOP)/ext/fts1/fts1.h \
+   $(TOP)/ext/fts1/fts1_hash.c \
+@@ -363,8 +366,12 @@
+   $(TOP)/ext/rbu/sqlite3rbu.h \
+   $(TOP)/ext/rbu/sqlite3rbu.c
+ SRC += \
++  $(TOP)/ext/misc/appendvfs.c \
++  $(TOP)/ext/misc/dbdata.c \
+   $(TOP)/ext/misc/json1.c \
+-  $(TOP)/ext/misc/stmt.c
++  $(TOP)/ext/misc/sqlar.c \
++  $(TOP)/ext/misc/stmt.c \
++  $(TOP)/ext/misc/zipfile.c
+ 
+ # Generated source code files
+ #
+@@ -435,7 +442,6 @@
+ # Statically linked extensions
+ #
+ TESTSRC += \
+-  $(TOP)/ext/expert/sqlite3expert.c \
+   $(TOP)/ext/expert/test_expert.c \
+   $(TOP)/ext/misc/amatch.c \
+   $(TOP)/ext/misc/carray.c \
+@@ -461,7 +467,6 @@
+   $(TOP)/ext/misc/totype.c \
+   $(TOP)/ext/misc/unionvtab.c \
+   $(TOP)/ext/misc/wholenumber.c \
+-  $(TOP)/ext/misc/zipfile.c \
+   $(TOP)/ext/userauth/userauth.c
+ 
+ # Source code to the library files needed by the test fixture
+@@ -639,25 +644,25 @@
+ 
+ libtclsqlite3.la:	tclsqlite.lo libsqlite3.la
+ 	$(LTLINK) -no-undefined -o $@ tclsqlite.lo \
+-		libsqlite3.la @TCL_STUB_LIB_SPEC@ $(TLIBS) \
++		libsqlite3.la @TCL_STUB_LIB_SPEC@ \
+ 		-rpath "$(TCLLIBDIR)" \
+ 		-version-info "8:6:8" \
+ 		-avoid-version
+ 
+-sqlite3$(TEXE):	shell.c sqlite3.c
+-	$(LTLINK) $(READLINE_FLAGS) $(SHELL_OPT) -o $@ \
+-		shell.c sqlite3.c \
+-		$(LIBREADLINE) $(TLIBS) -rpath "$(libdir)"
++sqlite3$(TEXE):	shell.c libsqlite3.la
++	$(LTLINK) $(READLINE_FLAGS) -o $@ \
++		shell.c libsqlite3.la \
++		$(LIBREADLINE)
+ 
+-sqldiff$(TEXE):	$(TOP)/tool/sqldiff.c sqlite3.lo sqlite3.h
+-	$(LTLINK) -o $@ $(TOP)/tool/sqldiff.c sqlite3.lo $(TLIBS)
++sqldiff$(TEXE):	$(TOP)/tool/sqldiff.c libsqlite3.la
++	$(LTLINK) -o $@ $(TOP)/tool/sqldiff.c libsqlite3.la
+ 
+-dbhash$(TEXE):	$(TOP)/tool/dbhash.c sqlite3.lo sqlite3.h
+-	$(LTLINK) -o $@ $(TOP)/tool/dbhash.c sqlite3.lo $(TLIBS)
++dbhash$(TEXE):	$(TOP)/tool/dbhash.c libsqlite3.la
++	$(LTLINK) -o $@ $(TOP)/tool/dbhash.c libsqlite3.la
+ 
+-scrub$(TEXE):	$(TOP)/ext/misc/scrub.c sqlite3.lo
++scrub$(TEXE):	$(TOP)/ext/misc/scrub.c libsqlite3.la
+ 	$(LTLINK) -o $@ -I. -DSCRUB_STANDALONE \
+-		$(TOP)/ext/misc/scrub.c sqlite3.lo $(TLIBS)
++		$(TOP)/ext/misc/scrub.c libsqlite3.la
+ 
+ srcck1$(BEXE):	$(TOP)/tool/srcck1.c
+ 	$(BCC) -o srcck1$(BEXE) $(TOP)/tool/srcck1.c
+@@ -767,7 +772,7 @@
+ # Rule to build the amalgamation
+ #
+ sqlite3.lo:	sqlite3.c
+-	$(LTCOMPILE) $(TEMP_STORE) -c sqlite3.c
++	$(LTCOMPILE) $(SHELL_OPT) $(TEMP_STORE) -c sqlite3.c
+ 
+ # Rules to build the LEMON compiler generator
+ #
+@@ -1064,14 +1069,9 @@
+ # Source files that go into making shell.c
+ SHELL_SRC = \
+ 	$(TOP)/src/shell.c.in \
+-        $(TOP)/ext/misc/appendvfs.c \
+ 	$(TOP)/ext/misc/shathree.c \
+ 	$(TOP)/ext/misc/fileio.c \
+ 	$(TOP)/ext/misc/completion.c \
+-	$(TOP)/ext/misc/sqlar.c \
+-	$(TOP)/ext/expert/sqlite3expert.c \
+-	$(TOP)/ext/expert/sqlite3expert.h \
+-	$(TOP)/ext/misc/zipfile.c \
+ 	$(TOP)/ext/misc/memtrace.c \
+         $(TOP)/src/test_windirent.c
+ 
+@@ -1239,11 +1239,11 @@
+ 
+ # Fuzz testing
+ fuzztest:	fuzzcheck$(TEXE) $(FUZZDATA) sessionfuzz$(TEXE) $(TOP)/test/sessionfuzz-data1.db
+-	./fuzzcheck$(TEXE) $(FUZZDATA)
++	./fuzzcheck$(TEXE) --timeout 3600 $(FUZZDATA)
+ 	./sessionfuzz$(TEXE) run $(TOP)/test/sessionfuzz-data1.db
+ 
+ valgrindfuzz:	fuzzcheck$(TEXT) $(FUZZDATA) sessionfuzz$(TEXE) $(TOP)/test/sessionfuzz-data1.db
+-	valgrind ./fuzzcheck$(TEXE) --cell-size-check --limit-mem 10M --timeout 600 $(FUZZDATA)
++	valgrind ./fuzzcheck$(TEXE) --cell-size-check --limit-mem 10M --timeout 3600 $(FUZZDATA)
+ 	valgrind ./sessionfuzz$(TEXE) run $(TOP)/test/sessionfuzz-data1.db
+ 
+ # The veryquick.test TCL tests.
+@@ -1274,24 +1274,23 @@
+ smoketest:	$(TESTPROGS) fuzzcheck$(TEXE)
+ 	./testfixture$(TEXE) $(TOP)/test/main.test $(TESTOPTS)
+ 
+-sqlite3_analyzer.c: sqlite3.c $(TOP)/src/tclsqlite.c $(TOP)/tool/spaceanal.tcl $(TOP)/tool/mkccode.tcl $(TOP)/tool/sqlite3_analyzer.c.in
++sqlite3_analyzer.c:	$(TOP)/src/tclsqlite.c $(TOP)/tool/spaceanal.tcl $(TOP)/tool/mkccode.tcl $(TOP)/tool/sqlite3_analyzer.c.in
+ 	$(TCLSH_CMD) $(TOP)/tool/mkccode.tcl $(TOP)/tool/sqlite3_analyzer.c.in >sqlite3_analyzer.c
+ 
+-sqlite3_analyzer$(TEXE): sqlite3_analyzer.c
+-	$(LTLINK) sqlite3_analyzer.c -o $@ $(LIBTCL) $(TLIBS)
++sqlite3_analyzer$(TEXE):	sqlite3_analyzer.c libsqlite3.la
++	$(LTLINK) sqlite3_analyzer.c -o $@ libsqlite3.la $(LIBTCL)
+ 
+-sqltclsh.c: sqlite3.c $(TOP)/src/tclsqlite.c $(TOP)/tool/sqltclsh.tcl $(TOP)/ext/misc/appendvfs.c $(TOP)/tool/mkccode.tcl $(TOP)/tool/sqltclsh.c.in
++sqltclsh.c:	$(TOP)/src/tclsqlite.c $(TOP)/tool/sqltclsh.tcl $(TOP)/tool/mkccode.tcl $(TOP)/tool/sqltclsh.c.in
+ 	$(TCLSH_CMD) $(TOP)/tool/mkccode.tcl $(TOP)/tool/sqltclsh.c.in >sqltclsh.c
+ 
+-sqltclsh$(TEXE): sqltclsh.c
+-	$(LTLINK) sqltclsh.c -o $@ $(LIBTCL) $(TLIBS)
++sqltclsh$(TEXE):	sqltclsh.c libsqlite3.la
++	$(LTLINK) sqltclsh.c -o $@ libsqlite3.la $(LIBTCL)
+ 
+-sqlite3_expert$(TEXE): $(TOP)/ext/expert/sqlite3expert.h $(TOP)/ext/expert/sqlite3expert.c $(TOP)/ext/expert/expert.c sqlite3.c
+-	$(LTLINK)	$(TOP)/ext/expert/sqlite3expert.h $(TOP)/ext/expert/sqlite3expert.c $(TOP)/ext/expert/expert.c sqlite3.c -o sqlite3_expert $(TLIBS)
++sqlite3_expert$(TEXE):	$(TOP)/ext/expert/sqlite3expert.h $(TOP)/ext/expert/expert.c libsqlite3.la
++	$(LTLINK) $(TOP)/ext/expert/expert.c -o sqlite3_expert libsqlite3.la
+ 
+ CHECKER_DEPS =\
+   $(TOP)/tool/mkccode.tcl \
+-  sqlite3.c \
+   $(TOP)/src/tclsqlite.c \
+   $(TOP)/ext/repair/sqlite3_checker.tcl \
+   $(TOP)/ext/repair/checkindex.c \
+@@ -1302,36 +1301,36 @@
+ sqlite3_checker.c:	$(CHECKER_DEPS)
+ 	$(TCLSH_CMD) $(TOP)/tool/mkccode.tcl $(TOP)/ext/repair/sqlite3_checker.c.in >$@
+ 
+-sqlite3_checker$(TEXE):	sqlite3_checker.c
+-	$(LTLINK) sqlite3_checker.c -o $@ $(LIBTCL) $(TLIBS)
++sqlite3_checker$(TEXE):	sqlite3_checker.c libsqlite3.la
++	$(LTLINK) sqlite3_checker.c -o $@ libsqlite3.la $(LIBTCL)
+ 
+-dbdump$(TEXE): $(TOP)/ext/misc/dbdump.c sqlite3.lo
++dbdump$(TEXE):	$(TOP)/ext/misc/dbdump.c libsqlite3.la
+ 	$(LTLINK) -DDBDUMP_STANDALONE -o $@ \
+-           $(TOP)/ext/misc/dbdump.c sqlite3.lo $(TLIBS)
++           $(TOP)/ext/misc/dbdump.c libsqlite3.la
+ 
+-dbtotxt$(TEXE): $(TOP)/tool/dbtotxt.c
+-	$(LTLINK)-o $@ $(TOP)/tool/dbtotxt.c
++dbtotxt$(TEXE):	$(TOP)/tool/dbtotxt.c
++	$(LTLINK) -o $@ $(TOP)/tool/dbtotxt.c
+ 
+-showdb$(TEXE):	$(TOP)/tool/showdb.c sqlite3.lo
+-	$(LTLINK) -o $@ $(TOP)/tool/showdb.c sqlite3.lo $(TLIBS)
++showdb$(TEXE):	$(TOP)/tool/showdb.c libsqlite3.la
++	$(LTLINK) -o $@ $(TOP)/tool/showdb.c libsqlite3.la
+ 
+-showstat4$(TEXE):	$(TOP)/tool/showstat4.c sqlite3.lo
+-	$(LTLINK) -o $@ $(TOP)/tool/showstat4.c sqlite3.lo $(TLIBS)
++showstat4$(TEXE):	$(TOP)/tool/showstat4.c libsqlite3.la
++	$(LTLINK) -o $@ $(TOP)/tool/showstat4.c libsqlite3.la
+ 
+-showjournal$(TEXE):	$(TOP)/tool/showjournal.c sqlite3.lo
+-	$(LTLINK) -o $@ $(TOP)/tool/showjournal.c sqlite3.lo $(TLIBS)
++showjournal$(TEXE):	$(TOP)/tool/showjournal.c
++	$(LTLINK) -o $@ $(TOP)/tool/showjournal.c
+ 
+-showwal$(TEXE):	$(TOP)/tool/showwal.c sqlite3.lo
+-	$(LTLINK) -o $@ $(TOP)/tool/showwal.c sqlite3.lo $(TLIBS)
++showwal$(TEXE):	$(TOP)/tool/showwal.c
++	$(LTLINK) -o $@ $(TOP)/tool/showwal.c
+ 
+ showshm$(TEXE):	$(TOP)/tool/showshm.c
+ 	$(LTLINK) -o $@ $(TOP)/tool/showshm.c
+ 
+-index_usage$(TEXE): $(TOP)/tool/index_usage.c sqlite3.lo
+-	$(LTLINK) $(SHELL_OPT) -o $@ $(TOP)/tool/index_usage.c sqlite3.lo $(TLIBS)
++index_usage$(TEXE):	$(TOP)/tool/index_usage.c libsqlite3.la
++	$(LTLINK) -o $@ $(TOP)/tool/index_usage.c libsqlite3.la
+ 
+-changeset$(TEXE):	$(TOP)/ext/session/changeset.c sqlite3.lo
+-	$(LTLINK) -o $@ $(TOP)/ext/session/changeset.c sqlite3.lo $(TLIBS)
++changeset$(TEXE):	$(TOP)/ext/session/changeset.c libsqlite3.la
++	$(LTLINK) -o $@ $(TOP)/ext/session/changeset.c libsqlite3.la
+ 
+ changesetfuzz$(TEXE):	$(TOP)/ext/session/changesetfuzz.c sqlite3.lo
+ 	$(LTLINK) -o $@ $(TOP)/ext/session/changesetfuzz.c sqlite3.lo $(TLIBS)
+@@ -1356,11 +1355,11 @@
+ kvtest$(TEXE):	$(TOP)/test/kvtest.c sqlite3.c
+ 	$(LTLINK) $(KV_OPT) -o $@ $(TOP)/test/kvtest.c sqlite3.c $(TLIBS)
+ 
+-rbu$(EXE): $(TOP)/ext/rbu/rbu.c $(TOP)/ext/rbu/sqlite3rbu.c sqlite3.lo
+-	$(LTLINK) -I. -o $@ $(TOP)/ext/rbu/rbu.c sqlite3.lo $(TLIBS)
++rbu$(EXE):	$(TOP)/ext/rbu/rbu.c libsqlite3.la
++	$(LTLINK) -I. -o $@ $(TOP)/ext/rbu/rbu.c libsqlite3.la
+ 
+-loadfts$(EXE): $(TOP)/tool/loadfts.c libsqlite3.la
+-	$(LTLINK) $(TOP)/tool/loadfts.c libsqlite3.la -o $@ $(TLIBS)
++loadfts$(EXE):	$(TOP)/tool/loadfts.c libsqlite3.la
++	$(LTLINK) $(TOP)/tool/loadfts.c libsqlite3.la -o $@
+ 
+ # This target will fail if the SQLite amalgamation contains any exported
+ # symbols that do not begin with "sqlite3_". It is run as part of the
+--- /configure.ac
++++ /configure.ac
+@@ -587,6 +587,9 @@
+ if test "${enable_load_extension}" = "yes" ; then
+   OPT_FEATURE_FLAGS=""
+   AC_SEARCH_LIBS(dlopen, dl)
++  if test "${ac_cv_search_dlopen}" = "no" ; then
++    OPT_FEATURE_FLAGS="-DSQLITE_OMIT_LOAD_EXTENSION=1"
++  fi
+ else
+   OPT_FEATURE_FLAGS="-DSQLITE_OMIT_LOAD_EXTENSION=1"
+ fi
+--- /ext/misc/sqlar.c
++++ /ext/misc/sqlar.c
+@@ -14,6 +14,8 @@
+ ** for working with sqlar archives and used by the shell tool's built-in
+ ** sqlar support.
+ */
++#ifdef SQLITE_HAVE_ZLIB
++
+ #include "sqlite3ext.h"
+ SQLITE_EXTENSION_INIT1
+ #include <zlib.h>
+@@ -121,3 +123,5 @@
+   }
+   return rc;
+ }
++
++#endif /* SQLITE_HAVE_ZLIB */
+--- /ext/misc/zipfile.c
++++ /ext/misc/zipfile.c
+@@ -24,6 +24,8 @@
+ **    *  No support for zip64 extensions
+ **    *  Only the "inflate/deflate" (zlib) compression method is supported
+ */
++#ifdef SQLITE_HAVE_ZLIB
++
+ #include "sqlite3ext.h"
+ SQLITE_EXTENSION_INIT1
+ #include <stdio.h>
+@@ -2186,3 +2188,5 @@
+   (void)pzErrMsg;  /* Unused parameter */
+   return zipfileRegister(db);
+ }
++
++#endif /* SQLITE_HAVE_ZLIB */
+--- /ext/repair/sqlite3_checker.c.in
++++ /ext/repair/sqlite3_checker.c.in
+@@ -2,6 +2,7 @@
+ ** Read an SQLite database file and analyze its space utilization.  Generate
+ ** text on standard output.
+ */
++#define SQLITE_CORE 1
+ #define TCLSH_INIT_PROC sqlite3_checker_init_proc
+ #define SQLITE_ENABLE_DBPAGE_VTAB 1
+ #define SQLITE_ENABLE_JSON1 1
+@@ -14,7 +15,7 @@
+ #define SQLITE_OMIT_SHARED_CACHE 1
+ #define SQLITE_DEFAULT_MEMSTATUS 0
+ #define SQLITE_MAX_EXPR_DEPTH 0
+-INCLUDE sqlite3.c
++#include "sqlite3.h"
+ INCLUDE $ROOT/src/tclsqlite.c
+ INCLUDE $ROOT/ext/misc/btreeinfo.c
+ INCLUDE $ROOT/ext/repair/checkindex.c
+--- /src/shell.c.in
++++ /src/shell.c.in
+@@ -61,6 +61,7 @@
+ #include <stdio.h>
+ #include <assert.h>
+ #include "sqlite3.h"
++#include "ext/expert/sqlite3expert.h"
+ typedef sqlite3_int64 i64;
+ typedef sqlite3_uint64 u64;
+ typedef unsigned char u8;
+@@ -127,6 +128,10 @@
+ # define SHELL_USE_LOCAL_GETLINE 1
+ #endif
+ 
++#ifdef SQLITE_HAVE_ZLIB
++#include <zlib.h>
++#endif
++
+ 
+ #if defined(_WIN32) || defined(WIN32)
+ # include <io.h>
+@@ -939,18 +944,7 @@
+ INCLUDE ../ext/misc/shathree.c
+ INCLUDE ../ext/misc/fileio.c
+ INCLUDE ../ext/misc/completion.c
+-INCLUDE ../ext/misc/appendvfs.c
+ INCLUDE ../ext/misc/memtrace.c
+-#ifdef SQLITE_HAVE_ZLIB
+-INCLUDE ../ext/misc/zipfile.c
+-INCLUDE ../ext/misc/sqlar.c
+-#endif
+-INCLUDE ../ext/expert/sqlite3expert.h
+-INCLUDE ../ext/expert/sqlite3expert.c
+-
+-#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
+-INCLUDE ../ext/misc/dbdata.c
+-#endif
+ 
+ #if defined(SQLITE_ENABLE_SESSION)
+ /*
+@@ -4173,10 +4167,13 @@
+     sqlite3_shathree_init(p->db, 0, 0);
+     sqlite3_completion_init(p->db, 0, 0);
+ #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
++    extern int sqlite3_dbdata_init(sqlite3 *, char **, const sqlite3_api_routines *);
+     sqlite3_dbdata_init(p->db, 0, 0);
+ #endif
+ #ifdef SQLITE_HAVE_ZLIB
++    extern int sqlite3_zipfile_init(sqlite3 *, char **, const sqlite3_api_routines *);
+     sqlite3_zipfile_init(p->db, 0, 0);
++    extern int sqlite3_sqlar_init(sqlite3 *, char **, const sqlite3_api_routines *);
+     sqlite3_sqlar_init(p->db, 0, 0);
+ #endif
+     sqlite3_create_function(p->db, "shell_add_schema", 3, SQLITE_UTF8, 0,
+@@ -6176,6 +6173,7 @@
+         goto end_ar_command;
+       }
+       sqlite3_fileio_init(cmd.db, 0, 0);
++      extern int sqlite3_sqlar_init(sqlite3 *, char **, const sqlite3_api_routines *);
+       sqlite3_sqlar_init(cmd.db, 0, 0);
+       sqlite3_create_function(cmd.db, "shell_putsnl", 1, SQLITE_UTF8, cmd.p,
+                               shellPutsFunc, 0, 0);
+@@ -10354,6 +10352,7 @@
+ #endif
+   }
+   data.out = stdout;
++  extern int sqlite3_appendvfs_init(sqlite3 *, char **, const sqlite3_api_routines *);
+   sqlite3_appendvfs_init(0,0,0);
+ 
+   /* Go ahead and open the database file if it already exists.  If the
+--- /test/sessionfuzz.c
++++ /test/sessionfuzz.c
+@@ -700,42 +700,6 @@
+ #include <assert.h>
+ #include "zlib.h"
+ 
+-/*
+-** Implementation of the "sqlar_uncompress(X,SZ)" SQL function
+-**
+-** Parameter SZ is interpreted as an integer. If it is less than or
+-** equal to zero, then this function returns a copy of X. Or, if
+-** SZ is equal to the size of X when interpreted as a blob, also
+-** return a copy of X. Otherwise, decompress blob X using zlib
+-** utility function uncompress() and return the results (another
+-** blob).
+-*/
+-static void sqlarUncompressFunc(
+-  sqlite3_context *context,
+-  int argc,
+-  sqlite3_value **argv
+-){
+-  uLong nData;
+-  uLongf sz;
+-
+-  assert( argc==2 );
+-  sz = sqlite3_value_int(argv[1]);
+-
+-  if( sz<=0 || sz==(nData = sqlite3_value_bytes(argv[0])) ){
+-    sqlite3_result_value(context, argv[0]);
+-  }else{
+-    const Bytef *pData= sqlite3_value_blob(argv[0]);
+-    Bytef *pOut = sqlite3_malloc(sz);
+-    if( Z_OK!=uncompress(pOut, &sz, pData, nData) ){
+-      sqlite3_result_error(context, "error in uncompress()", -1);
+-    }else{
+-      sqlite3_result_blob(context, pOut, sz, SQLITE_TRANSIENT);
+-    }
+-    sqlite3_free(pOut);
+-  }
+-}
+-
+-
+ /* Run a chunk of SQL.  If any errors happen, print an error message
+ ** and exit.
+ */
+--- /tool/mksqlite3c.tcl
++++ /tool/mksqlite3c.tcl
+@@ -117,6 +117,7 @@
+    rtree.h
+    sqlite3session.h
+    sqlite3.h
++   sqlite3expert.h
+    sqlite3ext.h
+    sqlite3rbu.h
+    sqliteicu.h
+@@ -403,6 +404,11 @@
+    sqlite3session.c
+    fts5.c
+    stmt.c
++   appendvfs.c
++   dbdata.c
++   sqlar.c
++   sqlite3expert.c
++   zipfile.c
+ } {
+   copy_file tsrc/$file
+ }
+--- /tool/sqlite3_analyzer.c.in
++++ /tool/sqlite3_analyzer.c.in
+@@ -14,9 +14,6 @@
+ #define SQLITE_DEFAULT_MEMSTATUS 0
+ #define SQLITE_MAX_EXPR_DEPTH 0
+ #define SQLITE_OMIT_LOAD_EXTENSION 1
+-#ifndef USE_EXTERNAL_SQLITE
+-INCLUDE sqlite3.c
+-#endif
+ INCLUDE $ROOT/src/tclsqlite.c
+ 
+ const char *sqlite3_analyzer_init_proc(Tcl_Interp *interp){
+--- /tool/sqltclsh.c.in
++++ /tool/sqltclsh.c.in
+@@ -27,19 +27,17 @@
+ #define SQLITE_OMIT_SHARED_CACHE 1
+ #define SQLITE_DEFAULT_MEMSTATUS 0
+ #define SQLITE_MAX_EXPR_DEPTH 0
+-INCLUDE sqlite3.c
+-INCLUDE $ROOT/ext/misc/appendvfs.c
+-#ifdef SQLITE_HAVE_ZLIB
+-INCLUDE $ROOT/ext/misc/zipfile.c
+-INCLUDE $ROOT/ext/misc/sqlar.c
+-#endif
++#include "sqlite3.h"
+ INCLUDE $ROOT/src/tclsqlite.c
+ 
+ const char *sqlite3_tclapp_init_proc(Tcl_Interp *interp){
+   (void)interp;
++  extern int sqlite3_appendvfs_init(sqlite3 *,char **, const sqlite3_api_routines *);
+   sqlite3_appendvfs_init(0,0,0);
+ #ifdef SQLITE_HAVE_ZLIB
++  extern int sqlite3_sqlar_init(sqlite3 *, char **, const sqlite3_api_routines *);
+   sqlite3_auto_extension((void(*)(void))sqlite3_sqlar_init);
++  extern int sqlite3_zipfile_init(sqlite3 *, char **, const sqlite3_api_routines *);
+   sqlite3_auto_extension((void(*)(void))sqlite3_zipfile_init);
+ #endif
+ 
diff --git a/dev-db/sqlite/files/sqlite-3.31.1-full_archive-architectures.patch b/dev-db/sqlite/files/sqlite-3.31.1-full_archive-architectures.patch
new file mode 100644
index 0000000..a0cf751
--- /dev/null
+++ b/dev-db/sqlite/files/sqlite-3.31.1-full_archive-architectures.patch
@@ -0,0 +1,72 @@
+https://sqlite.org/cgi/src/info/04885763c4cd00cb
+https://sqlite.org/cgi/src/info/b20503aaf5b6595a
+
+--- /ext/fts5/test/fts5matchinfo.test
++++ /ext/fts5/test/fts5matchinfo.test
+@@ -500,14 +500,18 @@
+   INSERT INTO t1 VALUES('c', 'd');
+ }
+ 
++if {$tcl_platform(byteOrder)=="littleEndian"} {
++  set res {X'02000000'}
++} else {
++  set res {X'00000002'}
++}
+ do_execsql_test 15.1 {
+   SELECT quote(matchinfo(t1, 'n')) FROM t1 LIMIT 1;
+-} {X'02000000'}
+-
++} $res
+ do_execsql_test 15.2 {
+   DELETE FROM t1_content WHERE rowid=1;
+   SELECT quote(matchinfo(t1, 'n')) FROM t1 LIMIT 1;
+-} {X'02000000'}
++} $res
+ 
+ fts5_aux_test_functions db
+ do_execsql_test 15.3 {
+@@ -517,4 +521,3 @@
+ }
+ 
+ finish_test
+-
+--- /src/insert.c
++++ /src/insert.c
+@@ -2170,12 +2170,14 @@
+             x = *sqlite3VdbeGetOp(v, addrConflictCk);
+             if( x.opcode!=OP_IdxRowid ){
+               int p2;      /* New P2 value for copied conflict check opcode */
++              const char *zP4;
+               if( sqlite3OpcodeProperty[x.opcode]&OPFLG_JUMP ){
+                 p2 = lblRecheckOk;
+               }else{
+                 p2 = x.p2;
+               }
+-              sqlite3VdbeAddOp4(v, x.opcode, x.p1, p2, x.p3, x.p4.z, x.p4type);
++              zP4 = x.p4type==P4_INT32 ? SQLITE_INT_TO_PTR(x.p4.i) : x.p4.z;
++              sqlite3VdbeAddOp4(v, x.opcode, x.p1, p2, x.p3, zP4, x.p4type);
+               sqlite3VdbeChangeP5(v, x.p5);
+               VdbeCoverageIf(v, p2!=x.p2);
+             }
+--- /test/fts4aa.test
++++ /test/fts4aa.test
+@@ -229,13 +229,18 @@
+ # 2019-11-18 https://bugs.chromium.org/p/chromium/issues/detail?id=1025467
+ db close
+ sqlite3 db :memory:
++if {$tcl_platform(byteOrder)=="littleEndian"} {
++  set res {X'0200000000000000000000000E0000000E00000001000000010000000100000001000000'}
++} else {
++  set res {X'0000000200000000000000000000000E0000000E00000001000000010000000100000001'}
++}
+ do_execsql_test fts4aa-6.10 {
+   CREATE VIRTUAL TABLE f USING fts4();
+   INSERT INTO f_segdir VALUES (77,91,0,0,'255 77',x'0001308000004d5c4ddddddd4d4d7b4d4d4d614d8019ff4d05000001204d4d2e4d6e4d4d4d4b4d6c4d004d4d4d4d4d4d3d000000004d5d4d4d645d4d004d4d4d4d4d4d4d4d4d454d6910004d05ffff054d646c4d004d5d4d4d4d4d3d000000004d4d4d4d4d4d4d4d4d4d4d69624d4d4d04004d4d4d4d4d604d4ce1404d554d45');
+   INSERT INTO f_segdir VALUES (77,108,0,0,'255 77',x'0001310000fa64004d4d4d3c5d4d654d4d4d614d8000ff4d05000001204d4d2e4d6e4d4d4dff4d4d4d4d4d4d00104d4d4d4d000000004d4d4d0400311d4d4d4d4d4d4d4d4d4d684d6910004d05ffff054d4d6c4d004d4d4d4d4d4d3d000000004d4d4d4d644d4d4d4d4d4d69624d4d4d03ed4d4d4d4d4d604d4ce1404d550080');
+   INSERT INTO f_stat VALUES (0,x'80808080100000000064004d4d4d3c4d4d654d4d4d614d8000ff4df6ff1a00204d4d2e4d6e4d4d4d104d4d4d4d4d4d00104d4d4d4d4d4d69574d4d4d000031044d4d4d3e4d4d4c4d05004d6910');
+   SELECT quote(matchinfo(f,'pnax')) from f where f match '0 1';
+-} {X'0200000000000000000000000E0000000E00000001000000010000000100000001000000'}
++} $res
+ 
+ # 2019-11-18 Detect infinite loop in fts3SelectLeaf()
+ db close
diff --git a/dev-db/sqlite/files/sqlite-3.31.1-full_archive-security_fixes.patch b/dev-db/sqlite/files/sqlite-3.31.1-full_archive-security_fixes.patch
new file mode 100644
index 0000000..c0bb714
--- /dev/null
+++ b/dev-db/sqlite/files/sqlite-3.31.1-full_archive-security_fixes.patch
@@ -0,0 +1,163 @@
+https://sqlite.org/cgi/src/info/9d0d4ab95dc0c56e
+https://sqlite.org/cgi/src/info/abc473fb8fb99900
+https://sqlite.org/cgi/src/info/5aeb5a2d295e10d5
+https://sqlite.org/cgi/src/info/a67cf5b7d37d5b14
+https://sqlite.org/cgi/src/info/14d14eb537075c6a
+https://sqlite.org/cgi/src/info/c431b3fd8fd0f6a6
+
+--- /src/expr.c
++++ /src/expr.c
+@@ -5463,19 +5463,25 @@
+     case TK_LT:
+     case TK_LE:
+     case TK_GT:
+-    case TK_GE:
++    case TK_GE: {
++      Expr *pLeft = pExpr->pLeft;
++      Expr *pRight = pExpr->pRight;
+       testcase( pExpr->op==TK_EQ );
+       testcase( pExpr->op==TK_NE );
+       testcase( pExpr->op==TK_LT );
+       testcase( pExpr->op==TK_LE );
+       testcase( pExpr->op==TK_GT );
+       testcase( pExpr->op==TK_GE );
+-      if( (pExpr->pLeft->op==TK_COLUMN && IsVirtual(pExpr->pLeft->y.pTab))
+-       || (pExpr->pRight->op==TK_COLUMN && IsVirtual(pExpr->pRight->y.pTab))
++      /* The y.pTab=0 assignment in wherecode.c always happens after the
++      ** impliesNotNullRow() test */
++      if( (pLeft->op==TK_COLUMN && ALWAYS(pLeft->y.pTab!=0)
++                               && IsVirtual(pLeft->y.pTab))
++       || (pRight->op==TK_COLUMN && ALWAYS(pRight->y.pTab!=0)
++                               && IsVirtual(pRight->y.pTab))
+       ){
+-       return WRC_Prune;
++        return WRC_Prune;
+       }
+-
++    }
+     default:
+       return WRC_Continue;
+   }
+--- /src/resolve.c
++++ /src/resolve.c
+@@ -1051,7 +1051,7 @@
+       assert( !ExprHasProperty(pExpr, EP_Reduced) );
+       /* Handle special cases of "x IS TRUE", "x IS FALSE", "x IS NOT TRUE",
+       ** and "x IS NOT FALSE". */
+-      if( pRight->op==TK_ID ){
++      if( pRight && pRight->op==TK_ID ){
+         int rc = resolveExprStep(pWalker, pRight);
+         if( rc==WRC_Abort ) return WRC_Abort;
+         if( pRight->op==TK_TRUEFALSE ){
+--- /src/select.c
++++ /src/select.c
+@@ -2806,6 +2806,7 @@
+         /* Generate code to take the intersection of the two temporary
+         ** tables.
+         */
++        if( rc ) break;
+         assert( p->pEList );
+         iBreak = sqlite3VdbeMakeLabel(pParse);
+         iCont = sqlite3VdbeMakeLabel(pParse);
+@@ -5148,7 +5149,7 @@
+             pNew = sqlite3ExprListAppend(pParse, pNew, pExpr);
+             sqlite3TokenInit(&sColname, zColname);
+             sqlite3ExprListSetName(pParse, pNew, &sColname, 0);
+-            if( pNew && (p->selFlags & SF_NestedFrom)!=0 ){
++            if( pNew && (p->selFlags & SF_NestedFrom)!=0 && !IN_RENAME_OBJECT ){
+               struct ExprList_item *pX = &pNew->a[pNew->nExpr-1];
+               sqlite3DbFree(db, pX->zEName);
+               if( pSub ){
+--- /src/sqliteInt.h
++++ /src/sqliteInt.h
+@@ -2153,8 +2153,11 @@
+ */
+ #ifndef SQLITE_OMIT_VIRTUALTABLE
+ #  define IsVirtual(X)      ((X)->nModuleArg)
++#  define ExprIsVtab(X)  \
++              ((X)->op==TK_COLUMN && (X)->y.pTab!=0 && (X)->y.pTab->nModuleArg)
+ #else
+ #  define IsVirtual(X)      0
++#  define ExprIsVtab(X)     0
+ #endif
+ 
+ /*
+--- /src/whereexpr.c
++++ /src/whereexpr.c
+@@ -377,7 +377,8 @@
+     **       MATCH(expression,vtab_column)
+     */
+     pCol = pList->a[1].pExpr;
+-    if( pCol->op==TK_COLUMN && IsVirtual(pCol->y.pTab) ){
++    testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 );
++    if( ExprIsVtab(pCol) ){
+       for(i=0; i<ArraySize(aOp); i++){
+         if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){
+           *peOp2 = aOp[i].eOp2;
+@@ -399,7 +400,8 @@
+     ** with function names in an arbitrary case.
+     */
+     pCol = pList->a[0].pExpr;
+-    if( pCol->op==TK_COLUMN && IsVirtual(pCol->y.pTab) ){
++    testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 );
++    if( ExprIsVtab(pCol) ){
+       sqlite3_vtab *pVtab;
+       sqlite3_module *pMod;
+       void (*xNotUsed)(sqlite3_context*,int,sqlite3_value**);
+@@ -422,10 +424,12 @@
+     int res = 0;
+     Expr *pLeft = pExpr->pLeft;
+     Expr *pRight = pExpr->pRight;
+-    if( pLeft->op==TK_COLUMN && IsVirtual(pLeft->y.pTab) ){
++    testcase( pLeft->op==TK_COLUMN && pLeft->y.pTab==0 );
++    if( ExprIsVtab(pLeft) ){
+       res++;
+     }
+-    if( pRight && pRight->op==TK_COLUMN && IsVirtual(pRight->y.pTab) ){
++    testcase( pRight && pRight->op==TK_COLUMN && pRight->y.pTab==0 );
++    if( pRight && ExprIsVtab(pRight) ){
+       res++;
+       SWAP(Expr*, pLeft, pRight);
+     }
+--- /test/altertab.test
++++ /test/altertab.test
+@@ -613,4 +613,21 @@
+   SELECT sql FROM sqlite_master;
+ } {{CREATE TABLE t0 (c1 INTEGER, PRIMARY KEY(c1))}}
+ 
++# 2020-02-23 ticket f50af3e8a565776b
++reset_db
++do_execsql_test 19.100 {
++  CREATE TABLE t1(x);
++  CREATE VIEW t2 AS SELECT 1 FROM t1, (t1 AS a0, t1);
++  ALTER TABLE t1 RENAME TO t3;
++  SELECT sql FROM sqlite_master;
++} {{CREATE TABLE "t3"(x)} {CREATE VIEW t2 AS SELECT 1 FROM "t3", ("t3" AS a0, "t3")}}
++do_execsql_test 19.110 {
++  INSERT INTO t3(x) VALUES(123);
++  SELECT * FROM t2;
++} {1}
++do_execsql_test 19.120 {
++  INSERT INTO t3(x) VALUES('xyz');
++  SELECT * FROM t2;
++} {1 1 1 1 1 1 1 1}
++
+ finish_test
+--- /test/windowfault.test
++++ /test/windowfault.test
+@@ -263,4 +263,15 @@
+   faultsim_test_result {0 {}}
+ }
+ 
++do_faultsim_test 11 -faults oom* -prep {
++} -body {
++  execsql {
++    VALUES(false),(current_date collate binary) 
++    intersect 
++    values(count() not like group_concat(cast(cast(0e00 as text) as integer) <= NULL || 0.4e-0 || 0x8 & true ) over () collate rtrim);
++  }
++} -test {
++  faultsim_test_result {0 {}}
++}
++
+ finish_test
diff --git a/dev-db/sqlite/files/sqlite-3.31.1-nonfull_archive-architectures.patch b/dev-db/sqlite/files/sqlite-3.31.1-nonfull_archive-architectures.patch
new file mode 100644
index 0000000..79f6f07
--- /dev/null
+++ b/dev-db/sqlite/files/sqlite-3.31.1-nonfull_archive-architectures.patch
@@ -0,0 +1,20 @@
+https://sqlite.org/cgi/src/info/04885763c4cd00cb
+
+--- /sqlite3.c
++++ /sqlite3.c
+@@ -121302,12 +121302,14 @@
+             x = *sqlite3VdbeGetOp(v, addrConflictCk);
+             if( x.opcode!=OP_IdxRowid ){
+               int p2;      /* New P2 value for copied conflict check opcode */
++              const char *zP4;
+               if( sqlite3OpcodeProperty[x.opcode]&OPFLG_JUMP ){
+                 p2 = lblRecheckOk;
+               }else{
+                 p2 = x.p2;
+               }
+-              sqlite3VdbeAddOp4(v, x.opcode, x.p1, p2, x.p3, x.p4.z, x.p4type);
++              zP4 = x.p4type==P4_INT32 ? SQLITE_INT_TO_PTR(x.p4.i) : x.p4.z;
++              sqlite3VdbeAddOp4(v, x.opcode, x.p1, p2, x.p3, zP4, x.p4type);
+               sqlite3VdbeChangeP5(v, x.p5);
+               VdbeCoverageIf(v, p2!=x.p2);
+             }
diff --git a/dev-db/sqlite/files/sqlite-3.31.1-nonfull_archive-security_fixes.patch b/dev-db/sqlite/files/sqlite-3.31.1-nonfull_archive-security_fixes.patch
new file mode 100644
index 0000000..3bbbbf7
--- /dev/null
+++ b/dev-db/sqlite/files/sqlite-3.31.1-nonfull_archive-security_fixes.patch
@@ -0,0 +1,112 @@
+https://sqlite.org/cgi/src/info/9d0d4ab95dc0c56e
+https://sqlite.org/cgi/src/info/abc473fb8fb99900
+https://sqlite.org/cgi/src/info/5aeb5a2d295e10d5
+https://sqlite.org/cgi/src/info/a67cf5b7d37d5b14
+https://sqlite.org/cgi/src/info/c431b3fd8fd0f6a6
+
+--- /sqlite3.c
++++ /sqlite3.c
+@@ -17428,8 +17428,11 @@
+ */
+ #ifndef SQLITE_OMIT_VIRTUALTABLE
+ #  define IsVirtual(X)      ((X)->nModuleArg)
++#  define ExprIsVtab(X)  \
++              ((X)->op==TK_COLUMN && (X)->y.pTab!=0 && (X)->y.pTab->nModuleArg)
+ #else
+ #  define IsVirtual(X)      0
++#  define ExprIsVtab(X)     0
+ #endif
+ 
+ /*
+@@ -97816,7 +97819,7 @@
+       assert( !ExprHasProperty(pExpr, EP_Reduced) );
+       /* Handle special cases of "x IS TRUE", "x IS FALSE", "x IS NOT TRUE",
+       ** and "x IS NOT FALSE". */
+-      if( pRight->op==TK_ID ){
++      if( pRight && pRight->op==TK_ID ){
+         int rc = resolveExprStep(pWalker, pRight);
+         if( rc==WRC_Abort ) return WRC_Abort;
+         if( pRight->op==TK_TRUEFALSE ){
+@@ -104133,19 +104136,25 @@
+     case TK_LT:
+     case TK_LE:
+     case TK_GT:
+-    case TK_GE:
++    case TK_GE: {
++      Expr *pLeft = pExpr->pLeft;
++      Expr *pRight = pExpr->pRight;
+       testcase( pExpr->op==TK_EQ );
+       testcase( pExpr->op==TK_NE );
+       testcase( pExpr->op==TK_LT );
+       testcase( pExpr->op==TK_LE );
+       testcase( pExpr->op==TK_GT );
+       testcase( pExpr->op==TK_GE );
+-      if( (pExpr->pLeft->op==TK_COLUMN && IsVirtual(pExpr->pLeft->y.pTab))
+-       || (pExpr->pRight->op==TK_COLUMN && IsVirtual(pExpr->pRight->y.pTab))
++      /* The y.pTab=0 assignment in wherecode.c always happens after the
++      ** impliesNotNullRow() test */
++      if( (pLeft->op==TK_COLUMN && ALWAYS(pLeft->y.pTab!=0)
++                               && IsVirtual(pLeft->y.pTab))
++       || (pRight->op==TK_COLUMN && ALWAYS(pRight->y.pTab!=0)
++                               && IsVirtual(pRight->y.pTab))
+       ){
+-       return WRC_Prune;
++        return WRC_Prune;
+       }
+-
++    }
+     default:
+       return WRC_Continue;
+   }
+@@ -130673,6 +130682,7 @@
+         /* Generate code to take the intersection of the two temporary
+         ** tables.
+         */
++        if( rc ) break;
+         assert( p->pEList );
+         iBreak = sqlite3VdbeMakeLabel(pParse);
+         iCont = sqlite3VdbeMakeLabel(pParse);
+@@ -133015,7 +133025,7 @@
+             pNew = sqlite3ExprListAppend(pParse, pNew, pExpr);
+             sqlite3TokenInit(&sColname, zColname);
+             sqlite3ExprListSetName(pParse, pNew, &sColname, 0);
+-            if( pNew && (p->selFlags & SF_NestedFrom)!=0 ){
++            if( pNew && (p->selFlags & SF_NestedFrom)!=0 && !IN_RENAME_OBJECT ){
+               struct ExprList_item *pX = &pNew->a[pNew->nExpr-1];
+               sqlite3DbFree(db, pX->zEName);
+               if( pSub ){
+@@ -142593,7 +142603,8 @@
+     **       MATCH(expression,vtab_column)
+     */
+     pCol = pList->a[1].pExpr;
+-    if( pCol->op==TK_COLUMN && IsVirtual(pCol->y.pTab) ){
++    testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 );
++    if( ExprIsVtab(pCol) ){
+       for(i=0; i<ArraySize(aOp); i++){
+         if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){
+           *peOp2 = aOp[i].eOp2;
+@@ -142615,7 +142626,8 @@
+     ** with function names in an arbitrary case.
+     */
+     pCol = pList->a[0].pExpr;
+-    if( pCol->op==TK_COLUMN && IsVirtual(pCol->y.pTab) ){
++    testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 );
++    if( ExprIsVtab(pCol) ){
+       sqlite3_vtab *pVtab;
+       sqlite3_module *pMod;
+       void (*xNotUsed)(sqlite3_context*,int,sqlite3_value**);
+@@ -142638,10 +142650,12 @@
+     int res = 0;
+     Expr *pLeft = pExpr->pLeft;
+     Expr *pRight = pExpr->pRight;
+-    if( pLeft->op==TK_COLUMN && IsVirtual(pLeft->y.pTab) ){
++    testcase( pLeft->op==TK_COLUMN && pLeft->y.pTab==0 );
++    if( ExprIsVtab(pLeft) ){
+       res++;
+     }
+-    if( pRight && pRight->op==TK_COLUMN && IsVirtual(pRight->y.pTab) ){
++    testcase( pRight && pRight->op==TK_COLUMN && pRight->y.pTab==0 );
++    if( pRight && ExprIsVtab(pRight) ){
+       res++;
+       SWAP(Expr*, pLeft, pRight);
+     }
diff --git a/dev-db/sqlite/sqlite-3.30.1-r3.ebuild b/dev-db/sqlite/sqlite-3.30.1-r3.ebuild
deleted file mode 120000
index 3a305fe..0000000
--- a/dev-db/sqlite/sqlite-3.30.1-r3.ebuild
+++ /dev/null
@@ -1 +0,0 @@
-sqlite-3.30.1.ebuild
\ No newline at end of file
diff --git a/dev-db/sqlite/sqlite-3.30.1.ebuild b/dev-db/sqlite/sqlite-3.31.1.ebuild
similarity index 92%
rename from dev-db/sqlite/sqlite-3.30.1.ebuild
rename to dev-db/sqlite/sqlite-3.31.1.ebuild
index 867085e..dfea153 100644
--- a/dev-db/sqlite/sqlite-3.30.1.ebuild
+++ b/dev-db/sqlite/sqlite-3.31.1.ebuild
@@ -1,4 +1,4 @@
-# Copyright 1999-2019 Gentoo Authors
+# Copyright 1999-2020 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 EAPI="7"
@@ -6,9 +6,9 @@
 inherit autotools flag-o-matic multilib-minimal toolchain-funcs
 
 if [[ "${PV}" != "9999" ]]; then
-    SRC_PV="$(printf "%u%02u%02u%02u" $(ver_rs 1- " "))"
-    DOC_PV="${SRC_PV}"
-    # DOC_PV="$(printf "%u%02u%02u00" $(ver_rs 1-3 " "))"
+	SRC_PV="$(printf "%u%02u%02u%02u" $(ver_rs 1- " "))"
+	DOC_PV="${SRC_PV}"
+	# DOC_PV="$(printf "%u%02u%02u00" $(ver_rs 1-3 " "))"
 fi
 
 DESCRIPTION="SQL database engine"
@@ -16,11 +16,11 @@
 if [[ "${PV}" == "9999" ]]; then
 	SRC_URI=""
 else
-	SRC_URI="doc? ( https://sqlite.org/2019/${PN}-doc-${DOC_PV}.zip )
-		tcl? ( https://sqlite.org/2019/${PN}-src-${SRC_PV}.zip )
-		test? ( https://sqlite.org/2019/${PN}-src-${SRC_PV}.zip )
-		tools? ( https://sqlite.org/2019/${PN}-src-${SRC_PV}.zip )
-		!tcl? ( !test? ( !tools? ( https://sqlite.org/2019/${PN}-autoconf-${SRC_PV}.tar.gz ) ) )"
+	SRC_URI="doc? ( https://sqlite.org/2020/${PN}-doc-${DOC_PV}.zip )
+		tcl? ( https://sqlite.org/2020/${PN}-src-${SRC_PV}.zip )
+		test? ( https://sqlite.org/2020/${PN}-src-${SRC_PV}.zip )
+		tools? ( https://sqlite.org/2020/${PN}-src-${SRC_PV}.zip )
+		!tcl? ( !test? ( !tools? ( https://sqlite.org/2020/${PN}-autoconf-${SRC_PV}.tar.gz ) ) )"
 fi
 
 LICENSE="public-domain"
@@ -124,7 +124,9 @@
 
 src_prepare() {
 	if full_archive; then
-		eapply "${FILESDIR}/${PN}-3.29.0-full_archive-build.patch"
+		eapply "${FILESDIR}/${PN}-3.31.0-full_archive-build.patch"
+		eapply "${FILESDIR}/${PN}-3.31.1-full_archive-architectures.patch"
+		eapply "${FILESDIR}/${PN}-3.31.1-full_archive-security_fixes.patch"
 
 		eapply_user
 
@@ -133,6 +135,8 @@
 		sed -e "s/AC_CHECK_FUNCS(.*)/AC_CHECK_FUNCS([fdatasync fullfsync gmtime_r isnan localtime_r localtime_s malloc_usable_size posix_fallocate pread pread64 pwrite pwrite64 strchrnul usleep utime])/" -i configure.ac || die "sed failed"
 	else
 		eapply "${FILESDIR}/${PN}-3.25.0-nonfull_archive-build.patch"
+		eapply "${FILESDIR}/${PN}-3.31.1-nonfull_archive-architectures.patch"
+		eapply "${FILESDIR}/${PN}-3.31.1-nonfull_archive-security_fixes.patch"
 
 		eapply_user
 
@@ -144,12 +148,6 @@
 			-i configure.ac || die "sed failed"
 	fi
 
-	# Fix CVE-2019-19880.
-	eapply "${FILESDIR}/sqlite-3.30.1-CVE-2019-19880.patch"
-
-	# Fix CVE-2019-20218.
-	eapply "${FILESDIR}/sqlite-3.30.1-CVE-2019-20218.patch"
-
 	eautoreconf
 
 	multilib_copy_sources
diff --git a/metadata/md5-cache/dev-db/sqlite-3.30.1-r3 b/metadata/md5-cache/dev-db/sqlite-3.30.1-r3
deleted file mode 100644
index e6f2093..0000000
--- a/metadata/md5-cache/dev-db/sqlite-3.30.1-r3
+++ /dev/null
@@ -1,15 +0,0 @@
-BDEPEND=doc? ( app-arch/unzip ) tcl? ( app-arch/unzip >=dev-lang/tcl-8.6:0 ) test? ( app-arch/unzip >=dev-lang/tcl-8.6:0 ) tools? ( app-arch/unzip >=dev-lang/tcl-8.6:0 ) >=app-portage/elt-patches-20170815
-DEFINED_PHASES=compile configure install prepare setup test unpack
-DEPEND=sys-libs/zlib:0=[abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_ppc_32(-)?,abi_ppc_64(-)?,abi_s390_32(-)?,abi_s390_64(-)?,abi_arm_32(-)?,abi_arm_64(-)?] icu? ( dev-libs/icu:0=[abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_ppc_32(-)?,abi_ppc_64(-)?,abi_s390_32(-)?,abi_s390_64(-)?,abi_arm_32(-)?,abi_arm_64(-)?] ) readline? ( sys-libs/readline:0=[abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_ppc_32(-)?,abi_ppc_64(-)?,abi_s390_32(-)?,abi_s390_64(-)?,abi_arm_32(-)?,abi_arm_64(-)?] ) tcl? ( dev-lang/tcl:0=[abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_ppc_32(-)?,abi_ppc_64(-)?,abi_s390_32(-)?,abi_s390_64(-)?,abi_arm_32(-)?,abi_arm_64(-)?] ) tools? ( dev-lang/tcl:0=[abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_ppc_32(-)?,abi_ppc_64(-)?,abi_s390_32(-)?,abi_s390_64(-)?,abi_arm_32(-)?,abi_arm_64(-)?] ) test? ( >=dev-lang/tcl-8.6:0[abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_ppc_32(-)?,abi_ppc_64(-)?,abi_s390_32(-)?,abi_s390_64(-)?,abi_arm_32(-)?,abi_arm_64(-)?] ) !<sys-devel/gettext-0.18.1.1-r3 || ( >=sys-devel/automake-1.16.1:1.16 >=sys-devel/automake-1.15.1:1.15 ) >=sys-devel/autoconf-2.69 >=sys-devel/libtool-2.4
-DESCRIPTION=SQL database engine
-EAPI=7
-HOMEPAGE=https://sqlite.org/
-IUSE=debug doc icu +readline secure-delete static-libs tcl test tools abi_x86_32 abi_x86_64 abi_x86_x32 abi_mips_n32 abi_mips_n64 abi_mips_o32 abi_ppc_32 abi_ppc_64 abi_s390_32 abi_s390_64 abi_arm_32 abi_arm_64
-KEYWORDS=*
-LICENSE=public-domain
-RDEPEND=sys-libs/zlib:0=[abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_ppc_32(-)?,abi_ppc_64(-)?,abi_s390_32(-)?,abi_s390_64(-)?,abi_arm_32(-)?,abi_arm_64(-)?] icu? ( dev-libs/icu:0=[abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_ppc_32(-)?,abi_ppc_64(-)?,abi_s390_32(-)?,abi_s390_64(-)?,abi_arm_32(-)?,abi_arm_64(-)?] ) readline? ( sys-libs/readline:0=[abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_ppc_32(-)?,abi_ppc_64(-)?,abi_s390_32(-)?,abi_s390_64(-)?,abi_arm_32(-)?,abi_arm_64(-)?] ) tcl? ( dev-lang/tcl:0=[abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_ppc_32(-)?,abi_ppc_64(-)?,abi_s390_32(-)?,abi_s390_64(-)?,abi_arm_32(-)?,abi_arm_64(-)?] ) tools? ( dev-lang/tcl:0=[abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_ppc_32(-)?,abi_ppc_64(-)?,abi_s390_32(-)?,abi_s390_64(-)?,abi_arm_32(-)?,abi_arm_64(-)?] )
-RESTRICT=!test? ( test )
-SLOT=3
-SRC_URI=doc? ( https://sqlite.org/2019/sqlite-doc-3300100.zip ) tcl? ( https://sqlite.org/2019/sqlite-src-3300100.zip ) test? ( https://sqlite.org/2019/sqlite-src-3300100.zip ) tools? ( https://sqlite.org/2019/sqlite-src-3300100.zip ) !tcl? ( !test? ( !tools? ( https://sqlite.org/2019/sqlite-autoconf-3300100.tar.gz ) ) )
-_eclasses_=autotools	d0e5375d47f4c809f406eb892e531513	eutils	06133990e861be0fe60c2b428fd025d9	flag-o-matic	5d5921a298e95441da2f85be419894c0	libtool	f143db5a74ccd9ca28c1234deffede96	multibuild	40fe59465edacd730c644ec2bc197809	multilib	b2f01ad412baf81650c23fcf0975fa33	multilib-build	1979aa0ff4d356d32507ca4650d9f37d	multilib-minimal	8bddda43703ba94d8341f4e247f97566	toolchain-funcs	209edad4a5c4812e7b2f8021650974f0
-_md5_=1ca01c8415bf6ec95a4d648fad8d30ae
diff --git a/metadata/md5-cache/dev-db/sqlite-3.30.1 b/metadata/md5-cache/dev-db/sqlite-3.31.1
similarity index 90%
rename from metadata/md5-cache/dev-db/sqlite-3.30.1
rename to metadata/md5-cache/dev-db/sqlite-3.31.1
index e6f2093..0c1a5b1 100644
--- a/metadata/md5-cache/dev-db/sqlite-3.30.1
+++ b/metadata/md5-cache/dev-db/sqlite-3.31.1
@@ -10,6 +10,6 @@
 RDEPEND=sys-libs/zlib:0=[abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_ppc_32(-)?,abi_ppc_64(-)?,abi_s390_32(-)?,abi_s390_64(-)?,abi_arm_32(-)?,abi_arm_64(-)?] icu? ( dev-libs/icu:0=[abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_ppc_32(-)?,abi_ppc_64(-)?,abi_s390_32(-)?,abi_s390_64(-)?,abi_arm_32(-)?,abi_arm_64(-)?] ) readline? ( sys-libs/readline:0=[abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_ppc_32(-)?,abi_ppc_64(-)?,abi_s390_32(-)?,abi_s390_64(-)?,abi_arm_32(-)?,abi_arm_64(-)?] ) tcl? ( dev-lang/tcl:0=[abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_ppc_32(-)?,abi_ppc_64(-)?,abi_s390_32(-)?,abi_s390_64(-)?,abi_arm_32(-)?,abi_arm_64(-)?] ) tools? ( dev-lang/tcl:0=[abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_ppc_32(-)?,abi_ppc_64(-)?,abi_s390_32(-)?,abi_s390_64(-)?,abi_arm_32(-)?,abi_arm_64(-)?] )
 RESTRICT=!test? ( test )
 SLOT=3
-SRC_URI=doc? ( https://sqlite.org/2019/sqlite-doc-3300100.zip ) tcl? ( https://sqlite.org/2019/sqlite-src-3300100.zip ) test? ( https://sqlite.org/2019/sqlite-src-3300100.zip ) tools? ( https://sqlite.org/2019/sqlite-src-3300100.zip ) !tcl? ( !test? ( !tools? ( https://sqlite.org/2019/sqlite-autoconf-3300100.tar.gz ) ) )
+SRC_URI=doc? ( https://sqlite.org/2020/sqlite-doc-3310100.zip ) tcl? ( https://sqlite.org/2020/sqlite-src-3310100.zip ) test? ( https://sqlite.org/2020/sqlite-src-3310100.zip ) tools? ( https://sqlite.org/2020/sqlite-src-3310100.zip ) !tcl? ( !test? ( !tools? ( https://sqlite.org/2020/sqlite-autoconf-3310100.tar.gz ) ) )
 _eclasses_=autotools	d0e5375d47f4c809f406eb892e531513	eutils	06133990e861be0fe60c2b428fd025d9	flag-o-matic	5d5921a298e95441da2f85be419894c0	libtool	f143db5a74ccd9ca28c1234deffede96	multibuild	40fe59465edacd730c644ec2bc197809	multilib	b2f01ad412baf81650c23fcf0975fa33	multilib-build	1979aa0ff4d356d32507ca4650d9f37d	multilib-minimal	8bddda43703ba94d8341f4e247f97566	toolchain-funcs	209edad4a5c4812e7b2f8021650974f0
-_md5_=1ca01c8415bf6ec95a4d648fad8d30ae
+_md5_=e840b461df7d8f3292b3ba04d0458a5a