git: ea656f7cdcc1 - stable/13 - sqlite3: Vendor import of sqlite3 3.42.0
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 05 Jun 2023 03:41:35 UTC
The branch stable/13 has been updated by cy:
URL: https://cgit.FreeBSD.org/src/commit/?id=ea656f7cdcc1fedd5cd62bc9b983c748f814fca2
commit ea656f7cdcc1fedd5cd62bc9b983c748f814fca2
Author: Cy Schubert <cy@FreeBSD.org>
AuthorDate: 2023-05-28 14:31:36 +0000
Commit: Cy Schubert <cy@FreeBSD.org>
CommitDate: 2023-06-05 01:38:55 +0000
sqlite3: Vendor import of sqlite3 3.42.0
Release notes at https://www.sqlite.org/releaselog/3_42_0.html.
Obtained from: https://www.sqlite.org/2023/sqlite-autoconf-3420000.tar.gz
Merge commit '92b2b066353ddd32e1d59f8c52c430d552d9a9a5' into sqlite3/main
(cherry picked from commit 402cee1f19b613bae844a176156a41cdfa507585)
---
contrib/sqlite3/configure | 20 +-
contrib/sqlite3/configure.ac | 2 +-
contrib/sqlite3/shell.c | 1016 ++++--
contrib/sqlite3/sqlite3.c | 6955 +++++++++++++++++++++++++-------------
contrib/sqlite3/sqlite3.h | 202 +-
contrib/sqlite3/sqlite3rc.h | 2 +-
contrib/sqlite3/tea/configure | 18 +-
contrib/sqlite3/tea/configure.ac | 2 +-
8 files changed, 5524 insertions(+), 2693 deletions(-)
diff --git a/contrib/sqlite3/configure b/contrib/sqlite3/configure
index dea9860d00ee..1016e350c37f 100755
--- a/contrib/sqlite3/configure
+++ b/contrib/sqlite3/configure
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.71 for sqlite 3.41.2.
+# Generated by GNU Autoconf 2.71 for sqlite 3.42.0.
#
# Report bugs to <http://www.sqlite.org>.
#
@@ -621,8 +621,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='sqlite'
PACKAGE_TARNAME='sqlite'
-PACKAGE_VERSION='3.41.2'
-PACKAGE_STRING='sqlite 3.41.2'
+PACKAGE_VERSION='3.42.0'
+PACKAGE_STRING='sqlite 3.42.0'
PACKAGE_BUGREPORT='http://www.sqlite.org'
PACKAGE_URL=''
@@ -1367,7 +1367,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
-\`configure' configures sqlite 3.41.2 to adapt to many kinds of systems.
+\`configure' configures sqlite 3.42.0 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1438,7 +1438,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of sqlite 3.41.2:";;
+ short | recursive ) echo "Configuration of sqlite 3.42.0:";;
esac
cat <<\_ACEOF
@@ -1563,7 +1563,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
-sqlite configure 3.41.2
+sqlite configure 3.42.0
generated by GNU Autoconf 2.71
Copyright (C) 2021 Free Software Foundation, Inc.
@@ -1833,7 +1833,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
-It was created by sqlite $as_me 3.41.2, which was
+It was created by sqlite $as_me 3.42.0, which was
generated by GNU Autoconf 2.71. Invocation command line was
$ $0$ac_configure_args_raw
@@ -3106,7 +3106,7 @@ fi
# Define the identity of the package.
PACKAGE='sqlite'
- VERSION='3.41.2'
+ VERSION='3.42.0'
printf "%s\n" "#define PACKAGE \"$PACKAGE\"" >>confdefs.h
@@ -15314,7 +15314,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
-This file was extended by sqlite $as_me 3.41.2, which was
+This file was extended by sqlite $as_me 3.42.0, which was
generated by GNU Autoconf 2.71. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -15373,7 +15373,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config='$ac_cs_config_escaped'
ac_cs_version="\\
-sqlite config.status 3.41.2
+sqlite config.status 3.42.0
configured by $0, generated by GNU Autoconf 2.71,
with options \\"\$ac_cs_config\\"
diff --git a/contrib/sqlite3/configure.ac b/contrib/sqlite3/configure.ac
index 290f160afc56..a706a4753049 100644
--- a/contrib/sqlite3/configure.ac
+++ b/contrib/sqlite3/configure.ac
@@ -10,7 +10,7 @@
#
AC_PREREQ(2.61)
-AC_INIT(sqlite, 3.41.2, http://www.sqlite.org)
+AC_INIT(sqlite, 3.42.0, http://www.sqlite.org)
AC_CONFIG_SRCDIR([sqlite3.c])
AC_CONFIG_AUX_DIR([.])
diff --git a/contrib/sqlite3/shell.c b/contrib/sqlite3/shell.c
index e6495d75128e..647a214226cc 100644
--- a/contrib/sqlite3/shell.c
+++ b/contrib/sqlite3/shell.c
@@ -117,6 +117,7 @@ typedef unsigned short int u16;
#include <string.h>
#include <stdio.h>
#include <assert.h>
+#include <math.h>
#include "sqlite3.h"
typedef sqlite3_int64 i64;
typedef sqlite3_uint64 u64;
@@ -245,6 +246,7 @@ typedef unsigned char u8;
#if SQLITE_OS_WINRT
#include <intrin.h>
#endif
+#define WIN32_LEAN_AND_MEAN
#include <windows.h>
/* string conversion routines only needed on Win32 */
@@ -459,11 +461,25 @@ static void endTimer(void){
static int bail_on_error = 0;
/*
-** Threat stdin as an interactive input if the following variable
+** Treat stdin as an interactive input if the following variable
** is true. Otherwise, assume stdin is connected to a file or pipe.
*/
static int stdin_is_interactive = 1;
+#if (defined(_WIN32) || defined(WIN32)) && SHELL_USE_LOCAL_GETLINE \
+ && !defined(SHELL_OMIT_WIN_UTF8)
+# define SHELL_WIN_UTF8_OPT 1
+#else
+# define SHELL_WIN_UTF8_OPT 0
+#endif
+
+#if SHELL_WIN_UTF8_OPT
+/*
+** Setup console for UTF-8 input/output when following variable true.
+*/
+static int console_utf8 = 0;
+#endif
+
/*
** On Windows systems we have to know if standard output is a console
** in order to translate UTF-8 into MBCS. The following variable is
@@ -596,16 +612,150 @@ static char *dynamicContinuePrompt(void){
}
#endif /* !defined(SQLITE_OMIT_DYNAPROMPT) */
+#if SHELL_WIN_UTF8_OPT
+/* Following struct is used for -utf8 operation. */
+static struct ConsoleState {
+ int stdinEof; /* EOF has been seen on console input */
+ int infsMode; /* Input file stream mode upon shell start */
+ UINT inCodePage; /* Input code page upon shell start */
+ UINT outCodePage; /* Output code page upon shell start */
+ HANDLE hConsoleIn; /* Console input handle */
+ DWORD consoleMode; /* Console mode upon shell start */
+} conState = { 0, 0, 0, 0, INVALID_HANDLE_VALUE, 0 };
+
+#ifndef _O_U16TEXT /* For build environments lacking this constant: */
+# define _O_U16TEXT 0x20000
+#endif
+
+/*
+** Prepare console, (if known to be a WIN32 console), for UTF-8
+** input (from either typing or suitable paste operations) and for
+** UTF-8 rendering. This may "fail" with a message to stderr, where
+** the preparation is not done and common "code page" issues occur.
+*/
+static void console_prepare(void){
+ HANDLE hCI = GetStdHandle(STD_INPUT_HANDLE);
+ DWORD consoleMode = 0;
+ if( isatty(0) && GetFileType(hCI)==FILE_TYPE_CHAR
+ && GetConsoleMode( hCI, &consoleMode) ){
+ if( !IsValidCodePage(CP_UTF8) ){
+ fprintf(stderr, "Cannot use UTF-8 code page.\n");
+ console_utf8 = 0;
+ return;
+ }
+ conState.hConsoleIn = hCI;
+ conState.consoleMode = consoleMode;
+ conState.inCodePage = GetConsoleCP();
+ conState.outCodePage = GetConsoleOutputCP();
+ SetConsoleCP(CP_UTF8);
+ SetConsoleOutputCP(CP_UTF8);
+ consoleMode |= ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT;
+ SetConsoleMode(conState.hConsoleIn, consoleMode);
+ conState.infsMode = _setmode(_fileno(stdin), _O_U16TEXT);
+ console_utf8 = 1;
+ }else{
+ console_utf8 = 0;
+ }
+}
+
+/*
+** Undo the effects of console_prepare(), if any.
+*/
+static void SQLITE_CDECL console_restore(void){
+ if( console_utf8 && conState.inCodePage!=0
+ && conState.hConsoleIn!=INVALID_HANDLE_VALUE ){
+ _setmode(_fileno(stdin), conState.infsMode);
+ SetConsoleCP(conState.inCodePage);
+ SetConsoleOutputCP(conState.outCodePage);
+ SetConsoleMode(conState.hConsoleIn, conState.consoleMode);
+ /* Avoid multiple calls. */
+ conState.hConsoleIn = INVALID_HANDLE_VALUE;
+ conState.consoleMode = 0;
+ console_utf8 = 0;
+ }
+}
+
+/*
+** Collect input like fgets(...) with special provisions for input
+** from the Windows console to get around its strange coding issues.
+** Defers to plain fgets() when input is not interactive or when the
+** startup option, -utf8, has not been provided or taken effect.
+*/
+static char* utf8_fgets(char *buf, int ncmax, FILE *fin){
+ if( fin==0 ) fin = stdin;
+ if( fin==stdin && stdin_is_interactive && console_utf8 ){
+# define SQLITE_IALIM 150
+ wchar_t wbuf[SQLITE_IALIM];
+ int lend = 0;
+ int noc = 0;
+ if( ncmax==0 || conState.stdinEof ) return 0;
+ buf[0] = 0;
+ while( noc<ncmax-7-1 && !lend ){
+ /* There is room for at least 2 more characters and a 0-terminator. */
+ int na = (ncmax > SQLITE_IALIM*4+1 + noc)
+ ? SQLITE_IALIM : (ncmax-1 - noc)/4;
+# undef SQLITE_IALIM
+ DWORD nbr = 0;
+ BOOL bRC = ReadConsoleW(conState.hConsoleIn, wbuf, na, &nbr, 0);
+ if( !bRC || (noc==0 && nbr==0) ) return 0;
+ if( nbr > 0 ){
+ int nmb = WideCharToMultiByte(CP_UTF8,WC_COMPOSITECHECK|WC_DEFAULTCHAR,
+ wbuf,nbr,0,0,0,0);
+ if( nmb !=0 && noc+nmb <= ncmax ){
+ int iseg = noc;
+ nmb = WideCharToMultiByte(CP_UTF8,WC_COMPOSITECHECK|WC_DEFAULTCHAR,
+ wbuf,nbr,buf+noc,nmb,0,0);
+ noc += nmb;
+ /* Fixup line-ends as coded by Windows for CR (or "Enter".)*/
+ if( noc > 0 ){
+ if( buf[noc-1]=='\n' ){
+ lend = 1;
+ if( noc > 1 && buf[noc-2]=='\r' ){
+ buf[noc-2] = '\n';
+ --noc;
+ }
+ }
+ }
+ /* Check for ^Z (anywhere in line) too. */
+ while( iseg < noc ){
+ if( buf[iseg]==0x1a ){
+ conState.stdinEof = 1;
+ noc = iseg; /* Chop ^Z and anything following. */
+ break;
+ }
+ ++iseg;
+ }
+ }else break; /* Drop apparent garbage in. (Could assert.) */
+ }else break;
+ }
+ /* If got nothing, (after ^Z chop), must be at end-of-file. */
+ if( noc == 0 ) return 0;
+ buf[noc] = 0;
+ return buf;
+ }else{
+ return fgets(buf, ncmax, fin);
+ }
+}
+
+# define fgets(b,n,f) utf8_fgets(b,n,f)
+#endif /* SHELL_WIN_UTF8_OPT */
+
/*
** Render output like fprintf(). Except, if the output is going to the
-** console and if this is running on a Windows machine, translate the
-** output from UTF-8 into MBCS.
+** console and if this is running on a Windows machine, and if the -utf8
+** option is unavailable or (available and inactive), translate the
+** output from UTF-8 into MBCS for output through 8-bit stdout stream.
+** (With -utf8 active, no translation is needed and must not be done.)
*/
#if defined(_WIN32) || defined(WIN32)
void utf8_printf(FILE *out, const char *zFormat, ...){
va_list ap;
va_start(ap, zFormat);
- if( stdout_is_console && (out==stdout || out==stderr) ){
+ if( stdout_is_console && (out==stdout || out==stderr)
+# if SHELL_WIN_UTF8_OPT
+ && !console_utf8
+# endif
+ ){
char *z1 = sqlite3_vmprintf(zFormat, ap);
char *z2 = sqlite3_win32_utf8_to_mbcs_v2(z1, 0);
sqlite3_free(z1);
@@ -637,7 +787,7 @@ static void shell_out_of_memory(void){
/* Check a pointer to see if it is NULL. If it is NULL, exit with an
** out-of-memory error.
*/
-static void shell_check_oom(void *p){
+static void shell_check_oom(const void *p){
if( p==0 ) shell_out_of_memory();
}
@@ -816,9 +966,14 @@ static char *local_getline(char *zLine, FILE *in){
}
}
#if defined(_WIN32) || defined(WIN32)
- /* For interactive input on Windows systems, translate the
- ** multi-byte characterset characters into UTF-8. */
- if( stdin_is_interactive && in==stdin ){
+ /* For interactive input on Windows systems, without -utf8,
+ ** translate the multi-byte characterset characters into UTF-8.
+ ** This is the translation that predates the -utf8 option. */
+ if( stdin_is_interactive && in==stdin
+# if SHELL_WIN_UTF8_OPT
+ && !console_utf8
+# endif /* SHELL_WIN_UTF8_OPT */
+ ){
char *zTrans = sqlite3_win32_mbcs_to_utf8_v2(zLine, 0);
if( zTrans ){
i64 nTrans = strlen(zTrans)+1;
@@ -859,10 +1014,21 @@ static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
#if SHELL_USE_LOCAL_GETLINE
printf("%s", zPrompt);
fflush(stdout);
- zResult = local_getline(zPrior, stdin);
+ do{
+ zResult = local_getline(zPrior, stdin);
+ zPrior = 0;
+ /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
+ if( zResult==0 ) sqlite3_sleep(50);
+ }while( zResult==0 && seenInterrupt>0 );
#else
free(zPrior);
zResult = shell_readline(zPrompt);
+ while( zResult==0 ){
+ /* ^C trap creates a false EOF, so let "interrupt" thread catch up. */
+ sqlite3_sleep(50);
+ if( seenInterrupt==0 ) break;
+ zResult = shell_readline("");
+ }
if( zResult && *zResult ) shell_add_history(zResult);
#endif
}
@@ -1002,6 +1168,7 @@ static void appendText(ShellText *p, const char *zAppend, char quote){
*/
static char quoteChar(const char *zName){
int i;
+ if( zName==0 ) return '"';
if( !isalpha((unsigned char)zName[0]) && zName[0]!='_' ) return '"';
for(i=0; zName[i]; i++){
if( !isalnum((unsigned char)zName[i]) && zName[i]!='_' ) return '"';
@@ -1645,7 +1812,8 @@ int sqlite3MemTraceDeactivate(void){
**
******************************************************************************
**
-** This SQLite extension implements functions that compute SHA3 hashes.
+** This SQLite extension implements functions that compute SHA3 hashes
+** in the way described by the (U.S.) NIST FIPS 202 SHA-3 Standard.
** Two SQL functions are implemented:
**
** sha3(X,SIZE)
@@ -3173,6 +3341,7 @@ SQLITE_EXTENSION_INIT1;
#define U8_TYPEDEF
#endif
+/* Decoding table, ASCII (7-bit) value to base 64 digit value or other */
static const u8 b64DigitValues[128] = {
/* HT LF VT FF CR */
ND,ND,ND,ND, ND,ND,ND,ND, ND,WS,WS,WS, WS,WS,ND,ND,
@@ -3244,9 +3413,9 @@ static char* toBase64( u8 *pIn, int nbIn, char *pOut ){
}
/* Skip over text which is not base64 numeral(s). */
-static char * skipNonB64( char *s ){
+static char * skipNonB64( char *s, int nc ){
char c;
- while( (c = *s) && !IS_BX_DIGIT(BX_DV_PROTO(c)) ) ++s;
+ while( nc-- > 0 && (c = *s) && !IS_BX_DIGIT(BX_DV_PROTO(c)) ) ++s;
return s;
}
@@ -3255,7 +3424,7 @@ static u8* fromBase64( char *pIn, int ncIn, u8 *pOut ){
if( ncIn>0 && pIn[ncIn-1]=='\n' ) --ncIn;
while( ncIn>0 && *pIn!=PAD_CHAR ){
static signed char nboi[] = { 0, 0, 1, 2, 3 };
- char *pUse = skipNonB64(pIn);
+ char *pUse = skipNonB64(pIn, ncIn);
unsigned long qv = 0L;
int nti, nbo, nac;
ncIn -= (pUse - pIn);
@@ -3315,9 +3484,16 @@ static void base64(sqlite3_context *context, int na, sqlite3_value *av[]){
sqlite3_result_error(context, "blob expanded to base64 too big", -1);
return;
}
+ bBuf = (u8*)sqlite3_value_blob(av[0]);
+ if( !bBuf ){
+ if( SQLITE_NOMEM==sqlite3_errcode(sqlite3_context_db_handle(context)) ){
+ goto memFail;
+ }
+ sqlite3_result_text(context,"",-1,SQLITE_STATIC);
+ break;
+ }
cBuf = sqlite3_malloc(nc);
if( !cBuf ) goto memFail;
- bBuf = (u8*)sqlite3_value_blob(av[0]);
nc = (int)(toBase64(bBuf, nb, cBuf) - cBuf);
sqlite3_result_text(context, cBuf, nc, sqlite3_free);
break;
@@ -3330,9 +3506,16 @@ static void base64(sqlite3_context *context, int na, sqlite3_value *av[]){
}else if( nb<1 ){
nb = 1;
}
+ cBuf = (char *)sqlite3_value_text(av[0]);
+ if( !cBuf ){
+ if( SQLITE_NOMEM==sqlite3_errcode(sqlite3_context_db_handle(context)) ){
+ goto memFail;
+ }
+ sqlite3_result_zeroblob(context, 0);
+ break;
+ }
bBuf = sqlite3_malloc(nb);
if( !bBuf ) goto memFail;
- cBuf = (char *)sqlite3_value_text(av[0]);
nb = (int)(fromBase64(cBuf, nc, bBuf) - bBuf);
sqlite3_result_blob(context, bBuf, nb, sqlite3_free);
break;
@@ -3520,9 +3703,9 @@ static u8 base85DigitValue( char c ){
#define B85_DARK_MAX 80
-static char * skipNonB85( char *s ){
+static char * skipNonB85( char *s, int nc ){
char c;
- while( (c = *s) && !IS_B85(c) ) ++s;
+ while( nc-- > 0 && (c = *s) && !IS_B85(c) ) ++s;
return s;
}
@@ -3592,7 +3775,7 @@ static u8* fromBase85( char *pIn, int ncIn, u8 *pOut ){
if( ncIn>0 && pIn[ncIn-1]=='\n' ) --ncIn;
while( ncIn>0 ){
static signed char nboi[] = { 0, 0, 1, 2, 3, 4 };
- char *pUse = skipNonB85(pIn);
+ char *pUse = skipNonB85(pIn, ncIn);
unsigned long qv = 0L;
int nti, nbo;
ncIn -= (pUse - pIn);
@@ -3677,9 +3860,16 @@ static void base85(sqlite3_context *context, int na, sqlite3_value *av[]){
sqlite3_result_error(context, "blob expanded to base85 too big", -1);
return;
}
+ bBuf = (u8*)sqlite3_value_blob(av[0]);
+ if( !bBuf ){
+ if( SQLITE_NOMEM==sqlite3_errcode(sqlite3_context_db_handle(context)) ){
+ goto memFail;
+ }
+ sqlite3_result_text(context,"",-1,SQLITE_STATIC);
+ break;
+ }
cBuf = sqlite3_malloc(nc);
if( !cBuf ) goto memFail;
- bBuf = (u8*)sqlite3_value_blob(av[0]);
nc = (int)(toBase85(bBuf, nb, cBuf, "\n") - cBuf);
sqlite3_result_text(context, cBuf, nc, sqlite3_free);
break;
@@ -3692,9 +3882,16 @@ static void base85(sqlite3_context *context, int na, sqlite3_value *av[]){
}else if( nb<1 ){
nb = 1;
}
+ cBuf = (char *)sqlite3_value_text(av[0]);
+ if( !cBuf ){
+ if( SQLITE_NOMEM==sqlite3_errcode(sqlite3_context_db_handle(context)) ){
+ goto memFail;
+ }
+ sqlite3_result_zeroblob(context, 0);
+ break;
+ }
bBuf = sqlite3_malloc(nb);
if( !bBuf ) goto memFail;
- cBuf = (char *)sqlite3_value_text(av[0]);
nb = (int)(fromBase85(cBuf, nc, bBuf) - bBuf);
sqlite3_result_blob(context, bBuf, nb, sqlite3_free);
break;
@@ -4114,7 +4311,7 @@ int sqlite3_ieee_init(
/************************* End ../ext/misc/ieee754.c ********************/
/************************* Begin ../ext/misc/series.c ******************/
/*
-** 2015-08-18
+** 2015-08-18, 2023-04-28
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
@@ -4127,7 +4324,19 @@ int sqlite3_ieee_init(
**
** This file demonstrates how to create a table-valued-function using
** a virtual table. This demo implements the generate_series() function
-** which gives similar results to the eponymous function in PostgreSQL.
+** which gives the same results as the eponymous function in PostgreSQL,
+** within the limitation that its arguments are signed 64-bit integers.
+**
+** Considering its equivalents to generate_series(start,stop,step): A
+** value V[n] sequence is produced for integer n ascending from 0 where
+** ( V[n] == start + n * step && sgn(V[n] - stop) * sgn(step) >= 0 )
+** for each produced value (independent of production time ordering.)
+**
+** All parameters must be either integer or convertable to integer.
+** The start parameter is required.
+** The stop parameter defaults to (1<<32)-1 (aka 4294967295 or 0xffffffff)
+** The step parameter defaults to 1 and 0 is treated as 1.
+**
** Examples:
**
** SELECT * FROM generate_series(0,100,5);
@@ -4143,6 +4352,14 @@ int sqlite3_ieee_init(
**
** Integers 20 through 29.
**
+** SELECT * FROM generate_series(0,-100,-5);
+**
+** Integers 0 -5 -10 ... -100.
+**
+** SELECT * FROM generate_series(0,-1);
+**
+** Empty sequence.
+**
** HOW IT WORKS
**
** The generate_series "function" is really a virtual table with the
@@ -4155,6 +4372,9 @@ int sqlite3_ieee_init(
** step HIDDEN
** );
**
+** The virtual table also has a rowid, logically equivalent to n+1 where
+** "n" is the ascending integer in the aforesaid production definition.
+**
** Function arguments in queries against this virtual table are translated
** into equality constraints against successive hidden columns. In other
** words, the following pairs of queries are equivalent to each other:
@@ -4187,9 +4407,126 @@ int sqlite3_ieee_init(
SQLITE_EXTENSION_INIT1
#include <assert.h>
#include <string.h>
+#include <limits.h>
#ifndef SQLITE_OMIT_VIRTUALTABLE
+/*
+** Return that member of a generate_series(...) sequence whose 0-based
+** index is ix. The 0th member is given by smBase. The sequence members
+** progress per ix increment by smStep.
+*/
+static sqlite3_int64 genSeqMember(sqlite3_int64 smBase,
+ sqlite3_int64 smStep,
+ sqlite3_uint64 ix){
+ if( ix>=(sqlite3_uint64)LLONG_MAX ){
+ /* Get ix into signed i64 range. */
+ ix -= (sqlite3_uint64)LLONG_MAX;
+ /* With 2's complement ALU, this next can be 1 step, but is split into
+ * 2 for UBSAN's satisfaction (and hypothetical 1's complement ALUs.) */
+ smBase += (LLONG_MAX/2) * smStep;
+ smBase += (LLONG_MAX - LLONG_MAX/2) * smStep;
+ }
+ /* Under UBSAN (or on 1's complement machines), must do this last term
+ * in steps to avoid the dreaded (and harmless) signed multiply overlow. */
+ if( ix>=2 ){
+ sqlite3_int64 ix2 = (sqlite3_int64)ix/2;
+ smBase += ix2*smStep;
+ ix -= ix2;
+ }
+ return smBase + ((sqlite3_int64)ix)*smStep;
+}
+
+/* typedef unsigned char u8; */
+
+typedef struct SequenceSpec {
+ sqlite3_int64 iBase; /* Starting value ("start") */
+ sqlite3_int64 iTerm; /* Given terminal value ("stop") */
+ sqlite3_int64 iStep; /* Increment ("step") */
+ sqlite3_uint64 uSeqIndexMax; /* maximum sequence index (aka "n") */
+ sqlite3_uint64 uSeqIndexNow; /* Current index during generation */
+ sqlite3_int64 iValueNow; /* Current value during generation */
+ u8 isNotEOF; /* Sequence generation not exhausted */
+ u8 isReversing; /* Sequence is being reverse generated */
+} SequenceSpec;
+
+/*
+** Prepare a SequenceSpec for use in generating an integer series
+** given initialized iBase, iTerm and iStep values. Sequence is
+** initialized per given isReversing. Other members are computed.
+*/
+static void setupSequence( SequenceSpec *pss ){
+ int bSameSigns;
+ pss->uSeqIndexMax = 0;
+ pss->isNotEOF = 0;
+ bSameSigns = (pss->iBase < 0)==(pss->iTerm < 0);
+ if( pss->iTerm < pss->iBase ){
+ sqlite3_uint64 nuspan = 0;
+ if( bSameSigns ){
+ nuspan = (sqlite3_uint64)(pss->iBase - pss->iTerm);
+ }else{
+ /* Under UBSAN (or on 1's complement machines), must do this in steps.
+ * In this clause, iBase>=0 and iTerm<0 . */
+ nuspan = 1;
+ nuspan += pss->iBase;
+ nuspan += -(pss->iTerm+1);
+ }
+ if( pss->iStep<0 ){
+ pss->isNotEOF = 1;
+ if( nuspan==ULONG_MAX ){
+ pss->uSeqIndexMax = ( pss->iStep>LLONG_MIN )? nuspan/-pss->iStep : 1;
+ }else if( pss->iStep>LLONG_MIN ){
+ pss->uSeqIndexMax = nuspan/-pss->iStep;
+ }
+ }
+ }else if( pss->iTerm > pss->iBase ){
+ sqlite3_uint64 puspan = 0;
+ if( bSameSigns ){
+ puspan = (sqlite3_uint64)(pss->iTerm - pss->iBase);
+ }else{
+ /* Under UBSAN (or on 1's complement machines), must do this in steps.
+ * In this clause, iTerm>=0 and iBase<0 . */
+ puspan = 1;
+ puspan += pss->iTerm;
+ puspan += -(pss->iBase+1);
+ }
+ if( pss->iStep>0 ){
+ pss->isNotEOF = 1;
+ pss->uSeqIndexMax = puspan/pss->iStep;
+ }
+ }else if( pss->iTerm == pss->iBase ){
+ pss->isNotEOF = 1;
+ pss->uSeqIndexMax = 0;
+ }
+ pss->uSeqIndexNow = (pss->isReversing)? pss->uSeqIndexMax : 0;
+ pss->iValueNow = (pss->isReversing)
+ ? genSeqMember(pss->iBase, pss->iStep, pss->uSeqIndexMax)
+ : pss->iBase;
+}
+/*
+** Progress sequence generator to yield next value, if any.
+** Leave its state to either yield next value or be at EOF.
+** Return whether there is a next value, or 0 at EOF.
+*/
+static int progressSequence( SequenceSpec *pss ){
+ if( !pss->isNotEOF ) return 0;
+ if( pss->isReversing ){
+ if( pss->uSeqIndexNow > 0 ){
+ pss->uSeqIndexNow--;
+ pss->iValueNow -= pss->iStep;
+ }else{
+ pss->isNotEOF = 0;
+ }
+ }else{
+ if( pss->uSeqIndexNow < pss->uSeqIndexMax ){
+ pss->uSeqIndexNow++;
+ pss->iValueNow += pss->iStep;
+ }else{
+ pss->isNotEOF = 0;
+ }
+ }
+ return pss->isNotEOF;
+}
/* series_cursor is a subclass of sqlite3_vtab_cursor which will
** serve as the underlying representation of a cursor that scans
@@ -4198,12 +4535,7 @@ SQLITE_EXTENSION_INIT1
typedef struct series_cursor series_cursor;
struct series_cursor {
sqlite3_vtab_cursor base; /* Base class - must be first */
- int isDesc; /* True to count down rather than up */
- sqlite3_int64 iRowid; /* The rowid */
- sqlite3_int64 iValue; /* Current value ("value") */
- sqlite3_int64 mnValue; /* Mimimum value ("start") */
- sqlite3_int64 mxValue; /* Maximum value ("stop") */
- sqlite3_int64 iStep; /* Increment ("step") */
+ SequenceSpec ss; /* (this) Derived class data */
};
/*
@@ -4285,12 +4617,7 @@ static int seriesClose(sqlite3_vtab_cursor *cur){
*/
static int seriesNext(sqlite3_vtab_cursor *cur){
series_cursor *pCur = (series_cursor*)cur;
- if( pCur->isDesc ){
- pCur->iValue -= pCur->iStep;
- }else{
- pCur->iValue += pCur->iStep;
- }
- pCur->iRowid++;
+ progressSequence( & pCur->ss );
return SQLITE_OK;
}
@@ -4306,23 +4633,23 @@ static int seriesColumn(
series_cursor *pCur = (series_cursor*)cur;
sqlite3_int64 x = 0;
switch( i ){
- case SERIES_COLUMN_START: x = pCur->mnValue; break;
- case SERIES_COLUMN_STOP: x = pCur->mxValue; break;
- case SERIES_COLUMN_STEP: x = pCur->iStep; break;
- default: x = pCur->iValue; break;
+ case SERIES_COLUMN_START: x = pCur->ss.iBase; break;
+ case SERIES_COLUMN_STOP: x = pCur->ss.iTerm; break;
+ case SERIES_COLUMN_STEP: x = pCur->ss.iStep; break;
+ default: x = pCur->ss.iValueNow; break;
}
sqlite3_result_int64(ctx, x);
return SQLITE_OK;
}
/*
-** Return the rowid for the current row. In this implementation, the
-** first row returned is assigned rowid value 1, and each subsequent
-** row a value 1 more than that of the previous.
+** Return the rowid for the current row, logically equivalent to n+1 where
+** "n" is the ascending integer in the aforesaid production definition.
*/
static int seriesRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
series_cursor *pCur = (series_cursor*)cur;
- *pRowid = pCur->iRowid;
+ sqlite3_uint64 n = pCur->ss.uSeqIndexNow;
+ *pRowid = (sqlite3_int64)((n<0xffffffffffffffff)? n+1 : 0);
return SQLITE_OK;
}
@@ -4332,14 +4659,10 @@ static int seriesRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
*/
static int seriesEof(sqlite3_vtab_cursor *cur){
series_cursor *pCur = (series_cursor*)cur;
- if( pCur->isDesc ){
- return pCur->iValue < pCur->mnValue;
- }else{
- return pCur->iValue > pCur->mxValue;
- }
+ return !pCur->ss.isNotEOF;
}
-/* True to cause run-time checking of the start=, stop=, and/or step=
+/* True to cause run-time checking of the start=, stop=, and/or step=
** parameters. The only reason to do this is for testing the
** constraint checking logic for virtual tables in the SQLite core.
*/
@@ -4350,7 +4673,7 @@ static int seriesEof(sqlite3_vtab_cursor *cur){
/*
** This method is called to "rewind" the series_cursor object back
** to the first row of output. This method is always called at least
-** once prior to any call to seriesColumn() or seriesRowid() or
+** once prior to any call to seriesColumn() or seriesRowid() or
** seriesEof().
**
** The query plan selected by seriesBestIndex is passed in the idxNum
@@ -4370,7 +4693,7 @@ static int seriesEof(sqlite3_vtab_cursor *cur){
** (so that seriesEof() will return true) if the table is empty.
*/
static int seriesFilter(
- sqlite3_vtab_cursor *pVtabCursor,
+ sqlite3_vtab_cursor *pVtabCursor,
int idxNum, const char *idxStrUnused,
int argc, sqlite3_value **argv
){
@@ -4378,46 +4701,41 @@ static int seriesFilter(
int i = 0;
(void)idxStrUnused;
if( idxNum & 1 ){
- pCur->mnValue = sqlite3_value_int64(argv[i++]);
+ pCur->ss.iBase = sqlite3_value_int64(argv[i++]);
}else{
- pCur->mnValue = 0;
+ pCur->ss.iBase = 0;
}
if( idxNum & 2 ){
- pCur->mxValue = sqlite3_value_int64(argv[i++]);
+ pCur->ss.iTerm = sqlite3_value_int64(argv[i++]);
}else{
- pCur->mxValue = 0xffffffff;
+ pCur->ss.iTerm = 0xffffffff;
}
if( idxNum & 4 ){
- pCur->iStep = sqlite3_value_int64(argv[i++]);
- if( pCur->iStep==0 ){
- pCur->iStep = 1;
- }else if( pCur->iStep<0 ){
- pCur->iStep = -pCur->iStep;
+ pCur->ss.iStep = sqlite3_value_int64(argv[i++]);
+ if( pCur->ss.iStep==0 ){
+ pCur->ss.iStep = 1;
+ }else if( pCur->ss.iStep<0 ){
if( (idxNum & 16)==0 ) idxNum |= 8;
}
}else{
- pCur->iStep = 1;
+ pCur->ss.iStep = 1;
}
for(i=0; i<argc; i++){
if( sqlite3_value_type(argv[i])==SQLITE_NULL ){
/* If any of the constraints have a NULL value, then return no rows.
** See ticket https://www.sqlite.org/src/info/fac496b61722daf2 */
- pCur->mnValue = 1;
- pCur->mxValue = 0;
+ pCur->ss.iBase = 1;
+ pCur->ss.iTerm = 0;
+ pCur->ss.iStep = 1;
break;
}
}
if( idxNum & 8 ){
- pCur->isDesc = 1;
- pCur->iValue = pCur->mxValue;
- if( pCur->iStep>0 ){
- pCur->iValue -= (pCur->mxValue - pCur->mnValue)%pCur->iStep;
- }
+ pCur->ss.isReversing = pCur->ss.iStep > 0;
}else{
- pCur->isDesc = 0;
- pCur->iValue = pCur->mnValue;
+ pCur->ss.isReversing = pCur->ss.iStep < 0;
}
- pCur->iRowid = 1;
+ setupSequence( &pCur->ss );
return SQLITE_OK;
}
@@ -5172,7 +5490,7 @@ static const char *re_subcompile_string(ReCompiled *p){
break;
}
case '[': {
- int iFirst = p->nState;
+ unsigned int iFirst = p->nState;
if( rePeek(p)=='^' ){
re_append(p, RE_OP_CC_EXC, 0);
p->sIn.i++;
@@ -5196,7 +5514,7 @@ static const char *re_subcompile_string(ReCompiled *p){
if( rePeek(p)==']' ){ p->sIn.i++; break; }
}
if( c==0 ) return "unclosed '['";
- p->aArg[iFirst] = p->nState - iFirst;
+ if( p->nState>iFirst ) p->aArg[iFirst] = p->nState - iFirst;
break;
}
case '\\': {
@@ -8773,7 +9091,10 @@ static int zipfileColumn(
** it to be a directory either if the mode suggests so, or if
** the final character in the name is '/'. */
u32 mode = pCDS->iExternalAttr >> 16;
- if( !(mode & S_IFDIR) && pCDS->zFile[pCDS->nFile-1]!='/' ){
+ if( !(mode & S_IFDIR)
+ && pCDS->nFile>=1
+ && pCDS->zFile[pCDS->nFile-1]!='/'
+ ){
sqlite3_result_blob(ctx, "", 0, SQLITE_STATIC);
}
}
@@ -9210,9 +9531,19 @@ static u32 zipfileGetTime(sqlite3_value *pVal){
*/
static void zipfileRemoveEntryFromList(ZipfileTab *pTab, ZipfileEntry *pOld){
if( pOld ){
- ZipfileEntry **pp;
- for(pp=&pTab->pFirstEntry; (*pp)!=pOld; pp=&((*pp)->pNext));
- *pp = (*pp)->pNext;
+ if( pTab->pFirstEntry==pOld ){
+ pTab->pFirstEntry = pOld->pNext;
+ if( pTab->pLastEntry==pOld ) pTab->pLastEntry = 0;
+ }else{
+ ZipfileEntry *p;
+ for(p=pTab->pFirstEntry; p; p=p->pNext){
+ if( p->pNext==pOld ){
+ p->pNext = pOld->pNext;
+ if( pTab->pLastEntry==pOld ) pTab->pLastEntry = p;
+ break;
+ }
+ }
+ }
zipfileEntryFree(pOld);
}
}
@@ -12678,6 +13009,7 @@ static int dbdataConnect(
(void)argc;
(void)argv;
(void)pzErr;
+ sqlite3_vtab_config(db, SQLITE_VTAB_USES_ALL_SCHEMAS);
if( rc==SQLITE_OK ){
pTab = (DbdataTable*)sqlite3_malloc64(sizeof(DbdataTable));
if( pTab==0 ){
@@ -13323,8 +13655,6 @@ static int dbdataFilter(
}
if( rc==SQLITE_OK ){
rc = sqlite3_bind_text(pCsr->pStmt, 1, zSchema, -1, SQLITE_TRANSIENT);
- }else{
- pTab->base.zErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(pTab->db));
}
/* Try to determine the encoding of the db by inspecting the header
@@ -13333,6 +13663,10 @@ static int dbdataFilter(
rc = dbdataGetEncoding(pCsr);
}
+ if( rc!=SQLITE_OK ){
+ pTab->base.zErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(pTab->db));
+ }
+
if( rc==SQLITE_OK ){
rc = dbdataNext(pCursor);
}
@@ -14571,7 +14905,7 @@ static void recoverAddTable(
int iField = sqlite3_column_int(pStmt, 0);
int iCol = sqlite3_column_int(pStmt, 1);
- assert( iField<pNew->nCol && iCol<pNew->nCol );
+ assert( iCol<pNew->nCol );
pNew->aCol[iCol].iField = iField;
pNew->bIntkey = 0;
@@ -16335,7 +16669,7 @@ int sqlite3_recover_finish(sqlite3_recover *p){
#endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
/************************* End ../ext/recover/sqlite3recover.c ********************/
-# endif
+# endif /* SQLITE_HAVE_SQLITE3R */
#endif
#ifdef SQLITE_SHELL_EXTSRC
# include SHELL_STRINGIFY(SQLITE_SHELL_EXTSRC)
@@ -16517,6 +16851,7 @@ static ShellState shellState;
#define SHFLG_HeaderSet 0x00000080 /* showHeader has been specified */
#define SHFLG_DumpDataOnly 0x00000100 /* .dump show data only */
#define SHFLG_DumpNoSys 0x00000200 /* .dump omits system tables */
+#define SHFLG_TestingMode 0x00000400 /* allow unsafe testing features */
/*
** Macros for testing and setting shellFlgs
@@ -16760,6 +17095,7 @@ static void editFunc(
}else{
/* If the file did not originally contain \r\n then convert any new
** \r\n back into \n */
+ p[sz] = 0;
for(i=j=0; i<sz; i++){
if( p[i]=='\r' && p[i+1]=='\n' ) i++;
p[j++] = p[i];
@@ -16850,6 +17186,7 @@ static void output_quoted_string(FILE *out, const char *z){
int i;
char c;
setBinaryMode(out, 1);
+ if( z==0 ) return;
for(i=0; (c = z[i])!=0 && c!='\''; i++){}
if( c==0 ){
utf8_printf(out,"'%s'",z);
@@ -16979,6 +17316,7 @@ static void output_c_string(FILE *out, const char *z){
*/
static void output_json_string(FILE *out, const char *z, i64 n){
unsigned int c;
+ if( z==0 ) z = "";
*** 12654 LINES SKIPPED ***