Fossil SCM

Update the built-in SQLite to the latest 3.38.0 beta.

drh 2022-02-15 23:34 trunk
Commit abd90eb5a83aba7f73f44afa43986074f1171ec7edd8f312af43c67eee5133dd
+242 -12
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -39,14 +39,14 @@
3939
** Optionally #include a user-defined header, whereby compilation options
4040
** may be set prior to where they take effect, but after platform setup.
4141
** If SQLITE_CUSTOM_INCLUDE=? is defined, its value names the #include
4242
** file. Note that this macro has a like effect on sqlite3.c compilation.
4343
*/
44
+# define SHELL_STRINGIFY_(f) #f
45
+# define SHELL_STRINGIFY(f) SHELL_STRINGIFY_(f)
4446
#ifdef SQLITE_CUSTOM_INCLUDE
45
-# define INC_STRINGIFY_(f) #f
46
-# define INC_STRINGIFY(f) INC_STRINGIFY_(f)
47
-# include INC_STRINGIFY(SQLITE_CUSTOM_INCLUDE)
47
+# include SHELL_STRINGIFY(SQLITE_CUSTOM_INCLUDE)
4848
#endif
4949
5050
/*
5151
** Determine if we are dealing with WinRT, which provides only a subset of
5252
** the full Win32 API.
@@ -13388,11 +13388,16 @@
1338813388
if( ur==0x7ff0000000000000LL ){
1338913389
raw_printf(p->out, "1e999");
1339013390
}else if( ur==0xfff0000000000000LL ){
1339113391
raw_printf(p->out, "-1e999");
1339213392
}else{
13393
- sqlite3_snprintf(50,z,"%!.20g", r);
13393
+ sqlite3_int64 ir = (sqlite3_int64)r;
13394
+ if( r==(double)ir ){
13395
+ sqlite3_snprintf(50,z,"%lld.0", ir);
13396
+ }else{
13397
+ sqlite3_snprintf(50,z,"%!.20g", r);
13398
+ }
1339413399
raw_printf(p->out, "%s", z);
1339513400
}
1339613401
}else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
1339713402
const void *pBlob = sqlite3_column_blob(p->pStmt, i);
1339813403
int nBlob = sqlite3_column_bytes(p->pStmt, i);
@@ -16828,14 +16833,14 @@
1682816833
}
1682916834
1683016835
/*
1683116836
** Run an SQL command and return the single integer result.
1683216837
*/
16833
-static int db_int(ShellState *p, const char *zSql){
16838
+static int db_int(sqlite3 *db, const char *zSql){
1683416839
sqlite3_stmt *pStmt;
1683516840
int res = 0;
16836
- sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
16841
+ sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
1683716842
if( pStmt && sqlite3_step(pStmt)==SQLITE_ROW ){
1683816843
res = sqlite3_column_int(pStmt,0);
1683916844
}
1684016845
sqlite3_finalize(pStmt);
1684116846
return res;
@@ -16936,11 +16941,11 @@
1693616941
}else{
1693716942
zSchemaTab = sqlite3_mprintf("\"%w\".sqlite_schema", zDb);
1693816943
}
1693916944
for(i=0; i<ArraySize(aQuery); i++){
1694016945
char *zSql = sqlite3_mprintf(aQuery[i].zSql, zSchemaTab);
16941
- int val = db_int(p, zSql);
16946
+ int val = db_int(p->db, zSql);
1694216947
sqlite3_free(zSql);
1694316948
utf8_printf(p->out, "%-20s %d\n", aQuery[i].zName, val);
1694416949
}
1694516950
sqlite3_free(zSchemaTab);
1694616951
sqlite3_file_control(p->db, zDb, SQLITE_FCNTL_DATA_VERSION, &iDataVersion);
@@ -18299,10 +18304,11 @@
1829918304
*pRc = SQLITE_NOMEM;
1830018305
}
1830118306
}
1830218307
return z;
1830318308
}
18309
+
1830418310
1830518311
/*
1830618312
** When running the ".recover" command, each output table, and the special
1830718313
** orphaned row table if it is required, is represented by an instance
1830818314
** of the following struct.
@@ -18896,10 +18902,225 @@
1889618902
sqlite3_exec(pState->db, "DETACH recovery", 0, 0, 0);
1889718903
return rc;
1889818904
}
1889918905
#endif /* !(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB) */
1890018906
18907
+
18908
+/*
18909
+ * zAutoColumn(zCol, &db, ?) => Maybe init db, add column zCol to it.
18910
+ * zAutoColumn(0, &db, ?) => (db!=0) Form columns spec for CREATE TABLE,
18911
+ * close db and set it to 0, and return the columns spec, to later
18912
+ * be sqlite3_free()'ed by the caller.
18913
+ * The return is 0 when either:
18914
+ * (a) The db was not initialized and zCol==0 (There are no columns.)
18915
+ * (b) zCol!=0 (Column was added, db initialized as needed.)
18916
+ * The 3rd argument, pRenamed, references an out parameter. If the
18917
+ * pointer is non-zero, its referent will be set to a summary of renames
18918
+ * done if renaming was necessary, or set to 0 if none was done. The out
18919
+ * string (if any) must be sqlite3_free()'ed by the caller.
18920
+ */
18921
+#ifdef SHELL_DEBUG
18922
+#define rc_err_oom_die(rc) \
18923
+ if( rc==SQLITE_NOMEM ) shell_check_oom(0); \
18924
+ else if(!(rc==SQLITE_OK||rc==SQLITE_DONE)) \
18925
+ fprintf(stderr,"E:%d\n",rc), assert(0)
18926
+#else
18927
+static void rc_err_oom_die(int rc){
18928
+ if( rc==SQLITE_NOMEM ) shell_check_oom(0);
18929
+ assert(rc==SQLITE_OK||rc==SQLITE_DONE);
18930
+}
18931
+#endif
18932
+
18933
+#ifdef SHELL_COLFIX_DB /* If this is set, the DB can be in a file. */
18934
+static char zCOL_DB[] = SHELL_STRINGIFY(SHELL_COLFIX_DB);
18935
+#else /* Otherwise, memory is faster/better for the transient DB. */
18936
+static const char *zCOL_DB = ":memory:";
18937
+#endif
18938
+
18939
+/* Define character (as C string) to separate generated column ordinal
18940
+ * from protected part of incoming column names. This defaults to "_"
18941
+ * so that incoming column identifiers that did not need not be quoted
18942
+ * remain usable without being quoted. It must be one character.
18943
+ */
18944
+#ifndef SHELL_AUTOCOLUMN_SEP
18945
+# define AUTOCOLUMN_SEP "_"
18946
+#else
18947
+# define AUTOCOLUMN_SEP SHELL_STRINGIFY(SHELL_AUTOCOLUMN_SEP)
18948
+#endif
18949
+
18950
+static char *zAutoColumn(const char *zColNew, sqlite3 **pDb, char **pzRenamed){
18951
+ /* Queries and D{D,M}L used here */
18952
+ static const char * const zTabMake = "\
18953
+CREATE TABLE ColNames(\
18954
+ cpos INTEGER PRIMARY KEY,\
18955
+ name TEXT, nlen INT, chop INT, reps INT, suff TEXT);\
18956
+CREATE VIEW RepeatedNames AS \
18957
+SELECT DISTINCT t.name FROM ColNames t \
18958
+WHERE t.name COLLATE NOCASE IN (\
18959
+ SELECT o.name FROM ColNames o WHERE o.cpos<>t.cpos\
18960
+);\
18961
+";
18962
+ static const char * const zTabFill = "\
18963
+INSERT INTO ColNames(name,nlen,chop,reps,suff)\
18964
+ VALUES(iif(length(?1)>0,?1,'?'),max(length(?1),1),0,0,'')\
18965
+";
18966
+ static const char * const zHasDupes = "\
18967
+SELECT count(DISTINCT (substring(name,1,nlen-chop)||suff) COLLATE NOCASE)\
18968
+ <count(name) FROM ColNames\
18969
+";
18970
+#ifdef SHELL_COLUMN_RENAME_CLEAN
18971
+ static const char * const zDedoctor = "\
18972
+UPDATE ColNames SET chop=iif(\
18973
+ (substring(name,nlen,1) BETWEEN '0' AND '9')\
18974
+ AND (rtrim(name,'0123456790') glob '*"AUTOCOLUMN_SEP"'),\
18975
+ nlen-length(rtrim(name, '"AUTOCOLUMN_SEP"0123456789')),\
18976
+ 0\
18977
+)\
18978
+";
18979
+#endif
18980
+ static const char * const zSetReps = "\
18981
+UPDATE ColNames AS t SET reps=\
18982
+(SELECT count(*) FROM ColNames d \
18983
+ WHERE substring(t.name,1,t.nlen-t.chop)=substring(d.name,1,d.nlen-d.chop)\
18984
+ COLLATE NOCASE\
18985
+)\
18986
+";
18987
+#ifdef SQLITE_ENABLE_MATH_FUNCTIONS
18988
+ static const char * const zColDigits = "\
18989
+SELECT CAST(ceil(log(count(*)+0.5)) AS INT) FROM ColNames \
18990
+";
18991
+#endif
18992
+ static const char * const zRenameRank =
18993
+#ifdef SHELL_COLUMN_RENAME_CLEAN
18994
+ "UPDATE ColNames AS t SET suff="
18995
+ "iif(reps>1, printf('%c%0*d', '"AUTOCOLUMN_SEP"', $1, cpos), '')"
18996
+#else /* ...RENAME_MINIMAL_ONE_PASS */
18997
+"WITH Lzn(nlz) AS (" /* Find minimum extraneous leading 0's for uniqueness */
18998
+" SELECT 0 AS nlz"
18999
+" UNION"
19000
+" SELECT nlz+1 AS nlz FROM Lzn"
19001
+" WHERE EXISTS("
19002
+" SELECT 1"
19003
+" FROM ColNames t, ColNames o"
19004
+" WHERE"
19005
+" iif(t.name IN (SELECT * FROM RepeatedNames),"
19006
+" printf('%s"AUTOCOLUMN_SEP"%s',"
19007
+" t.name, substring(printf('%.*c%0.*d',nlz+1,'0',$1,t.cpos),2)),"
19008
+" t.name"
19009
+" )"
19010
+" ="
19011
+" iif(o.name IN (SELECT * FROM RepeatedNames),"
19012
+" printf('%s"AUTOCOLUMN_SEP"%s',"
19013
+" o.name, substring(printf('%.*c%0.*d',nlz+1,'0',$1,o.cpos),2)),"
19014
+" o.name"
19015
+" )"
19016
+" COLLATE NOCASE"
19017
+" AND o.cpos<>t.cpos"
19018
+" GROUP BY t.cpos"
19019
+" )"
19020
+") UPDATE Colnames AS t SET"
19021
+" chop = 0," /* No chopping, never touch incoming names. */
19022
+" suff = iif(name IN (SELECT * FROM RepeatedNames),"
19023
+" printf('"AUTOCOLUMN_SEP"%s', substring("
19024
+" printf('%.*c%0.*d',(SELECT max(nlz) FROM Lzn)+1,'0',1,t.cpos),2)),"
19025
+" ''"
19026
+" )"
19027
+#endif
19028
+ ;
19029
+ static const char * const zCollectVar = "\
19030
+SELECT\
19031
+ '('||x'0a'\
19032
+ || group_concat(\
19033
+ cname||' TEXT',\
19034
+ ','||iif((cpos-1)%4>0, ' ', x'0a'||' '))\
19035
+ ||')' AS ColsSpec \
19036
+FROM (\
19037
+ SELECT cpos, printf('\"%w\"',printf('%.*s%s', nlen-chop,name,suff)) AS cname \
19038
+ FROM ColNames ORDER BY cpos\
19039
+)";
19040
+ static const char * const zRenamesDone =
19041
+ "SELECT group_concat("
19042
+ " printf('\"%w\" to \"%w\"',name,printf('%.*s%s', nlen-chop, name, suff)),"
19043
+ " ','||x'0a')"
19044
+ "FROM ColNames WHERE suff<>'' OR chop!=0"
19045
+ ;
19046
+ int rc;
19047
+ sqlite3_stmt *pStmt = 0;
19048
+ assert(pDb!=0);
19049
+ if( zColNew ){
19050
+ /* Add initial or additional column. Init db if necessary. */
19051
+ if( *pDb==0 ){
19052
+ if( SQLITE_OK!=sqlite3_open(zCOL_DB, pDb) ) return 0;
19053
+#ifdef SHELL_COLFIX_DB
19054
+ if(*zCOL_DB!=':')
19055
+ sqlite3_exec(*pDb,"drop table if exists ColNames;"
19056
+ "drop view if exists RepeatedNames;",0,0,0);
19057
+#endif
19058
+ rc = sqlite3_exec(*pDb, zTabMake, 0, 0, 0);
19059
+ rc_err_oom_die(rc);
19060
+ }
19061
+ assert(*pDb!=0);
19062
+ rc = sqlite3_prepare_v2(*pDb, zTabFill, -1, &pStmt, 0);
19063
+ rc_err_oom_die(rc);
19064
+ rc = sqlite3_bind_text(pStmt, 1, zColNew, -1, 0);
19065
+ rc_err_oom_die(rc);
19066
+ rc = sqlite3_step(pStmt);
19067
+ rc_err_oom_die(rc);
19068
+ sqlite3_finalize(pStmt);
19069
+ return 0;
19070
+ }else if( *pDb==0 ){
19071
+ return 0;
19072
+ }else{
19073
+ /* Formulate the columns spec, close the DB, zero *pDb. */
19074
+ char *zColsSpec = 0;
19075
+ int hasDupes = db_int(*pDb, zHasDupes);
19076
+#ifdef SQLITE_ENABLE_MATH_FUNCTIONS
19077
+ int nDigits = (hasDupes)? db_int(*pDb, zColDigits) : 0;
19078
+#else
19079
+# define nDigits 2
19080
+#endif
19081
+ if( hasDupes ){
19082
+#ifdef SHELL_COLUMN_RENAME_CLEAN
19083
+ rc = sqlite3_exec(*pDb, zDedoctor, 0, 0, 0);
19084
+ rc_err_oom_die(rc);
19085
+#endif
19086
+ rc = sqlite3_exec(*pDb, zSetReps, 0, 0, 0);
19087
+ rc_err_oom_die(rc);
19088
+ rc = sqlite3_prepare_v2(*pDb, zRenameRank, -1, &pStmt, 0);
19089
+ rc_err_oom_die(rc);
19090
+ sqlite3_bind_int(pStmt, 1, nDigits);
19091
+ rc = sqlite3_step(pStmt);
19092
+ sqlite3_finalize(pStmt);
19093
+ assert(rc==SQLITE_DONE);
19094
+ }
19095
+ assert(db_int(*pDb, zHasDupes)==0); /* Consider: remove this */
19096
+ rc = sqlite3_prepare_v2(*pDb, zCollectVar, -1, &pStmt, 0);
19097
+ rc_err_oom_die(rc);
19098
+ rc = sqlite3_step(pStmt);
19099
+ if( rc==SQLITE_ROW ){
19100
+ zColsSpec = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 0));
19101
+ }else{
19102
+ zColsSpec = 0;
19103
+ }
19104
+ if( pzRenamed!=0 ){
19105
+ if( !hasDupes ) *pzRenamed = 0;
19106
+ else{
19107
+ sqlite3_finalize(pStmt);
19108
+ if( SQLITE_OK==sqlite3_prepare_v2(*pDb, zRenamesDone, -1, &pStmt, 0)
19109
+ && SQLITE_ROW==sqlite3_step(pStmt) ){
19110
+ *pzRenamed = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 0));
19111
+ }else
19112
+ *pzRenamed = 0;
19113
+ }
19114
+ }
19115
+ sqlite3_finalize(pStmt);
19116
+ sqlite3_close(*pDb);
19117
+ *pDb = 0;
19118
+ return zColsSpec;
19119
+ }
19120
+}
19121
+
1890119122
/*
1890219123
** If an input line begins with "." then invoke this routine to
1890319124
** process that line.
1890419125
**
1890519126
** Return 1 on error, 2 to exit, and 0 otherwise.
@@ -19844,24 +20065,33 @@
1984420065
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
1984520066
import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */
1984620067
if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(p->db))==0 ){
1984720068
char *zCreate = sqlite3_mprintf("CREATE TABLE \"%w\".\"%w\"",
1984820069
zSchema, zTable);
19849
- char cSep = '(';
20070
+ sqlite3 *dbCols = 0;
20071
+ char *zRenames = 0;
20072
+ char *zColDefs;
1985020073
while( xRead(&sCtx) ){
19851
- zCreate = sqlite3_mprintf("%z%c\n \"%w\" TEXT", zCreate, cSep, sCtx.z);
19852
- cSep = ',';
20074
+ zAutoColumn(sCtx.z, &dbCols, 0);
1985320075
if( sCtx.cTerm!=sCtx.cColSep ) break;
1985420076
}
19855
- if( cSep=='(' ){
20077
+ zColDefs = zAutoColumn(0, &dbCols, &zRenames);
20078
+ if( zRenames!=0 ){
20079
+ utf8_printf((stdin_is_interactive && p->in==stdin)? p->out : stderr,
20080
+ "Columns renamed during .import %s due to duplicates:\n"
20081
+ "%s\n", sCtx.zFile, zRenames);
20082
+ sqlite3_free(zRenames);
20083
+ }
20084
+ assert(dbCols==0);
20085
+ if( zColDefs==0 ){
1985620086
sqlite3_free(zCreate);
1985720087
import_cleanup(&sCtx);
1985820088
utf8_printf(stderr,"%s: empty file\n", sCtx.zFile);
1985920089
rc = 1;
1986020090
goto meta_command_exit;
1986120091
}
19862
- zCreate = sqlite3_mprintf("%z\n)", zCreate);
20092
+ zCreate = sqlite3_mprintf("%z%z\n", zCreate, zColDefs);
1986320093
if( eVerbose>=1 ){
1986420094
utf8_printf(p->out, "%s\n", zCreate);
1986520095
}
1986620096
rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
1986720097
if( rc ){
1986820098
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -39,14 +39,14 @@
39 ** Optionally #include a user-defined header, whereby compilation options
40 ** may be set prior to where they take effect, but after platform setup.
41 ** If SQLITE_CUSTOM_INCLUDE=? is defined, its value names the #include
42 ** file. Note that this macro has a like effect on sqlite3.c compilation.
43 */
 
 
44 #ifdef SQLITE_CUSTOM_INCLUDE
45 # define INC_STRINGIFY_(f) #f
46 # define INC_STRINGIFY(f) INC_STRINGIFY_(f)
47 # include INC_STRINGIFY(SQLITE_CUSTOM_INCLUDE)
48 #endif
49
50 /*
51 ** Determine if we are dealing with WinRT, which provides only a subset of
52 ** the full Win32 API.
@@ -13388,11 +13388,16 @@
13388 if( ur==0x7ff0000000000000LL ){
13389 raw_printf(p->out, "1e999");
13390 }else if( ur==0xfff0000000000000LL ){
13391 raw_printf(p->out, "-1e999");
13392 }else{
13393 sqlite3_snprintf(50,z,"%!.20g", r);
 
 
 
 
 
13394 raw_printf(p->out, "%s", z);
13395 }
13396 }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
13397 const void *pBlob = sqlite3_column_blob(p->pStmt, i);
13398 int nBlob = sqlite3_column_bytes(p->pStmt, i);
@@ -16828,14 +16833,14 @@
16828 }
16829
16830 /*
16831 ** Run an SQL command and return the single integer result.
16832 */
16833 static int db_int(ShellState *p, const char *zSql){
16834 sqlite3_stmt *pStmt;
16835 int res = 0;
16836 sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
16837 if( pStmt && sqlite3_step(pStmt)==SQLITE_ROW ){
16838 res = sqlite3_column_int(pStmt,0);
16839 }
16840 sqlite3_finalize(pStmt);
16841 return res;
@@ -16936,11 +16941,11 @@
16936 }else{
16937 zSchemaTab = sqlite3_mprintf("\"%w\".sqlite_schema", zDb);
16938 }
16939 for(i=0; i<ArraySize(aQuery); i++){
16940 char *zSql = sqlite3_mprintf(aQuery[i].zSql, zSchemaTab);
16941 int val = db_int(p, zSql);
16942 sqlite3_free(zSql);
16943 utf8_printf(p->out, "%-20s %d\n", aQuery[i].zName, val);
16944 }
16945 sqlite3_free(zSchemaTab);
16946 sqlite3_file_control(p->db, zDb, SQLITE_FCNTL_DATA_VERSION, &iDataVersion);
@@ -18299,10 +18304,11 @@
18299 *pRc = SQLITE_NOMEM;
18300 }
18301 }
18302 return z;
18303 }
 
18304
18305 /*
18306 ** When running the ".recover" command, each output table, and the special
18307 ** orphaned row table if it is required, is represented by an instance
18308 ** of the following struct.
@@ -18896,10 +18902,225 @@
18896 sqlite3_exec(pState->db, "DETACH recovery", 0, 0, 0);
18897 return rc;
18898 }
18899 #endif /* !(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB) */
18900
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18901 /*
18902 ** If an input line begins with "." then invoke this routine to
18903 ** process that line.
18904 **
18905 ** Return 1 on error, 2 to exit, and 0 otherwise.
@@ -19844,24 +20065,33 @@
19844 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
19845 import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */
19846 if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(p->db))==0 ){
19847 char *zCreate = sqlite3_mprintf("CREATE TABLE \"%w\".\"%w\"",
19848 zSchema, zTable);
19849 char cSep = '(';
 
 
19850 while( xRead(&sCtx) ){
19851 zCreate = sqlite3_mprintf("%z%c\n \"%w\" TEXT", zCreate, cSep, sCtx.z);
19852 cSep = ',';
19853 if( sCtx.cTerm!=sCtx.cColSep ) break;
19854 }
19855 if( cSep=='(' ){
 
 
 
 
 
 
 
 
19856 sqlite3_free(zCreate);
19857 import_cleanup(&sCtx);
19858 utf8_printf(stderr,"%s: empty file\n", sCtx.zFile);
19859 rc = 1;
19860 goto meta_command_exit;
19861 }
19862 zCreate = sqlite3_mprintf("%z\n)", zCreate);
19863 if( eVerbose>=1 ){
19864 utf8_printf(p->out, "%s\n", zCreate);
19865 }
19866 rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
19867 if( rc ){
19868
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -39,14 +39,14 @@
39 ** Optionally #include a user-defined header, whereby compilation options
40 ** may be set prior to where they take effect, but after platform setup.
41 ** If SQLITE_CUSTOM_INCLUDE=? is defined, its value names the #include
42 ** file. Note that this macro has a like effect on sqlite3.c compilation.
43 */
44 # define SHELL_STRINGIFY_(f) #f
45 # define SHELL_STRINGIFY(f) SHELL_STRINGIFY_(f)
46 #ifdef SQLITE_CUSTOM_INCLUDE
47 # include SHELL_STRINGIFY(SQLITE_CUSTOM_INCLUDE)
 
 
48 #endif
49
50 /*
51 ** Determine if we are dealing with WinRT, which provides only a subset of
52 ** the full Win32 API.
@@ -13388,11 +13388,16 @@
13388 if( ur==0x7ff0000000000000LL ){
13389 raw_printf(p->out, "1e999");
13390 }else if( ur==0xfff0000000000000LL ){
13391 raw_printf(p->out, "-1e999");
13392 }else{
13393 sqlite3_int64 ir = (sqlite3_int64)r;
13394 if( r==(double)ir ){
13395 sqlite3_snprintf(50,z,"%lld.0", ir);
13396 }else{
13397 sqlite3_snprintf(50,z,"%!.20g", r);
13398 }
13399 raw_printf(p->out, "%s", z);
13400 }
13401 }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
13402 const void *pBlob = sqlite3_column_blob(p->pStmt, i);
13403 int nBlob = sqlite3_column_bytes(p->pStmt, i);
@@ -16828,14 +16833,14 @@
16833 }
16834
16835 /*
16836 ** Run an SQL command and return the single integer result.
16837 */
16838 static int db_int(sqlite3 *db, const char *zSql){
16839 sqlite3_stmt *pStmt;
16840 int res = 0;
16841 sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
16842 if( pStmt && sqlite3_step(pStmt)==SQLITE_ROW ){
16843 res = sqlite3_column_int(pStmt,0);
16844 }
16845 sqlite3_finalize(pStmt);
16846 return res;
@@ -16936,11 +16941,11 @@
16941 }else{
16942 zSchemaTab = sqlite3_mprintf("\"%w\".sqlite_schema", zDb);
16943 }
16944 for(i=0; i<ArraySize(aQuery); i++){
16945 char *zSql = sqlite3_mprintf(aQuery[i].zSql, zSchemaTab);
16946 int val = db_int(p->db, zSql);
16947 sqlite3_free(zSql);
16948 utf8_printf(p->out, "%-20s %d\n", aQuery[i].zName, val);
16949 }
16950 sqlite3_free(zSchemaTab);
16951 sqlite3_file_control(p->db, zDb, SQLITE_FCNTL_DATA_VERSION, &iDataVersion);
@@ -18299,10 +18304,11 @@
18304 *pRc = SQLITE_NOMEM;
18305 }
18306 }
18307 return z;
18308 }
18309
18310
18311 /*
18312 ** When running the ".recover" command, each output table, and the special
18313 ** orphaned row table if it is required, is represented by an instance
18314 ** of the following struct.
@@ -18896,10 +18902,225 @@
18902 sqlite3_exec(pState->db, "DETACH recovery", 0, 0, 0);
18903 return rc;
18904 }
18905 #endif /* !(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB) */
18906
18907
18908 /*
18909 * zAutoColumn(zCol, &db, ?) => Maybe init db, add column zCol to it.
18910 * zAutoColumn(0, &db, ?) => (db!=0) Form columns spec for CREATE TABLE,
18911 * close db and set it to 0, and return the columns spec, to later
18912 * be sqlite3_free()'ed by the caller.
18913 * The return is 0 when either:
18914 * (a) The db was not initialized and zCol==0 (There are no columns.)
18915 * (b) zCol!=0 (Column was added, db initialized as needed.)
18916 * The 3rd argument, pRenamed, references an out parameter. If the
18917 * pointer is non-zero, its referent will be set to a summary of renames
18918 * done if renaming was necessary, or set to 0 if none was done. The out
18919 * string (if any) must be sqlite3_free()'ed by the caller.
18920 */
18921 #ifdef SHELL_DEBUG
18922 #define rc_err_oom_die(rc) \
18923 if( rc==SQLITE_NOMEM ) shell_check_oom(0); \
18924 else if(!(rc==SQLITE_OK||rc==SQLITE_DONE)) \
18925 fprintf(stderr,"E:%d\n",rc), assert(0)
18926 #else
18927 static void rc_err_oom_die(int rc){
18928 if( rc==SQLITE_NOMEM ) shell_check_oom(0);
18929 assert(rc==SQLITE_OK||rc==SQLITE_DONE);
18930 }
18931 #endif
18932
18933 #ifdef SHELL_COLFIX_DB /* If this is set, the DB can be in a file. */
18934 static char zCOL_DB[] = SHELL_STRINGIFY(SHELL_COLFIX_DB);
18935 #else /* Otherwise, memory is faster/better for the transient DB. */
18936 static const char *zCOL_DB = ":memory:";
18937 #endif
18938
18939 /* Define character (as C string) to separate generated column ordinal
18940 * from protected part of incoming column names. This defaults to "_"
18941 * so that incoming column identifiers that did not need not be quoted
18942 * remain usable without being quoted. It must be one character.
18943 */
18944 #ifndef SHELL_AUTOCOLUMN_SEP
18945 # define AUTOCOLUMN_SEP "_"
18946 #else
18947 # define AUTOCOLUMN_SEP SHELL_STRINGIFY(SHELL_AUTOCOLUMN_SEP)
18948 #endif
18949
18950 static char *zAutoColumn(const char *zColNew, sqlite3 **pDb, char **pzRenamed){
18951 /* Queries and D{D,M}L used here */
18952 static const char * const zTabMake = "\
18953 CREATE TABLE ColNames(\
18954 cpos INTEGER PRIMARY KEY,\
18955 name TEXT, nlen INT, chop INT, reps INT, suff TEXT);\
18956 CREATE VIEW RepeatedNames AS \
18957 SELECT DISTINCT t.name FROM ColNames t \
18958 WHERE t.name COLLATE NOCASE IN (\
18959 SELECT o.name FROM ColNames o WHERE o.cpos<>t.cpos\
18960 );\
18961 ";
18962 static const char * const zTabFill = "\
18963 INSERT INTO ColNames(name,nlen,chop,reps,suff)\
18964 VALUES(iif(length(?1)>0,?1,'?'),max(length(?1),1),0,0,'')\
18965 ";
18966 static const char * const zHasDupes = "\
18967 SELECT count(DISTINCT (substring(name,1,nlen-chop)||suff) COLLATE NOCASE)\
18968 <count(name) FROM ColNames\
18969 ";
18970 #ifdef SHELL_COLUMN_RENAME_CLEAN
18971 static const char * const zDedoctor = "\
18972 UPDATE ColNames SET chop=iif(\
18973 (substring(name,nlen,1) BETWEEN '0' AND '9')\
18974 AND (rtrim(name,'0123456790') glob '*"AUTOCOLUMN_SEP"'),\
18975 nlen-length(rtrim(name, '"AUTOCOLUMN_SEP"0123456789')),\
18976 0\
18977 )\
18978 ";
18979 #endif
18980 static const char * const zSetReps = "\
18981 UPDATE ColNames AS t SET reps=\
18982 (SELECT count(*) FROM ColNames d \
18983 WHERE substring(t.name,1,t.nlen-t.chop)=substring(d.name,1,d.nlen-d.chop)\
18984 COLLATE NOCASE\
18985 )\
18986 ";
18987 #ifdef SQLITE_ENABLE_MATH_FUNCTIONS
18988 static const char * const zColDigits = "\
18989 SELECT CAST(ceil(log(count(*)+0.5)) AS INT) FROM ColNames \
18990 ";
18991 #endif
18992 static const char * const zRenameRank =
18993 #ifdef SHELL_COLUMN_RENAME_CLEAN
18994 "UPDATE ColNames AS t SET suff="
18995 "iif(reps>1, printf('%c%0*d', '"AUTOCOLUMN_SEP"', $1, cpos), '')"
18996 #else /* ...RENAME_MINIMAL_ONE_PASS */
18997 "WITH Lzn(nlz) AS (" /* Find minimum extraneous leading 0's for uniqueness */
18998 " SELECT 0 AS nlz"
18999 " UNION"
19000 " SELECT nlz+1 AS nlz FROM Lzn"
19001 " WHERE EXISTS("
19002 " SELECT 1"
19003 " FROM ColNames t, ColNames o"
19004 " WHERE"
19005 " iif(t.name IN (SELECT * FROM RepeatedNames),"
19006 " printf('%s"AUTOCOLUMN_SEP"%s',"
19007 " t.name, substring(printf('%.*c%0.*d',nlz+1,'0',$1,t.cpos),2)),"
19008 " t.name"
19009 " )"
19010 " ="
19011 " iif(o.name IN (SELECT * FROM RepeatedNames),"
19012 " printf('%s"AUTOCOLUMN_SEP"%s',"
19013 " o.name, substring(printf('%.*c%0.*d',nlz+1,'0',$1,o.cpos),2)),"
19014 " o.name"
19015 " )"
19016 " COLLATE NOCASE"
19017 " AND o.cpos<>t.cpos"
19018 " GROUP BY t.cpos"
19019 " )"
19020 ") UPDATE Colnames AS t SET"
19021 " chop = 0," /* No chopping, never touch incoming names. */
19022 " suff = iif(name IN (SELECT * FROM RepeatedNames),"
19023 " printf('"AUTOCOLUMN_SEP"%s', substring("
19024 " printf('%.*c%0.*d',(SELECT max(nlz) FROM Lzn)+1,'0',1,t.cpos),2)),"
19025 " ''"
19026 " )"
19027 #endif
19028 ;
19029 static const char * const zCollectVar = "\
19030 SELECT\
19031 '('||x'0a'\
19032 || group_concat(\
19033 cname||' TEXT',\
19034 ','||iif((cpos-1)%4>0, ' ', x'0a'||' '))\
19035 ||')' AS ColsSpec \
19036 FROM (\
19037 SELECT cpos, printf('\"%w\"',printf('%.*s%s', nlen-chop,name,suff)) AS cname \
19038 FROM ColNames ORDER BY cpos\
19039 )";
19040 static const char * const zRenamesDone =
19041 "SELECT group_concat("
19042 " printf('\"%w\" to \"%w\"',name,printf('%.*s%s', nlen-chop, name, suff)),"
19043 " ','||x'0a')"
19044 "FROM ColNames WHERE suff<>'' OR chop!=0"
19045 ;
19046 int rc;
19047 sqlite3_stmt *pStmt = 0;
19048 assert(pDb!=0);
19049 if( zColNew ){
19050 /* Add initial or additional column. Init db if necessary. */
19051 if( *pDb==0 ){
19052 if( SQLITE_OK!=sqlite3_open(zCOL_DB, pDb) ) return 0;
19053 #ifdef SHELL_COLFIX_DB
19054 if(*zCOL_DB!=':')
19055 sqlite3_exec(*pDb,"drop table if exists ColNames;"
19056 "drop view if exists RepeatedNames;",0,0,0);
19057 #endif
19058 rc = sqlite3_exec(*pDb, zTabMake, 0, 0, 0);
19059 rc_err_oom_die(rc);
19060 }
19061 assert(*pDb!=0);
19062 rc = sqlite3_prepare_v2(*pDb, zTabFill, -1, &pStmt, 0);
19063 rc_err_oom_die(rc);
19064 rc = sqlite3_bind_text(pStmt, 1, zColNew, -1, 0);
19065 rc_err_oom_die(rc);
19066 rc = sqlite3_step(pStmt);
19067 rc_err_oom_die(rc);
19068 sqlite3_finalize(pStmt);
19069 return 0;
19070 }else if( *pDb==0 ){
19071 return 0;
19072 }else{
19073 /* Formulate the columns spec, close the DB, zero *pDb. */
19074 char *zColsSpec = 0;
19075 int hasDupes = db_int(*pDb, zHasDupes);
19076 #ifdef SQLITE_ENABLE_MATH_FUNCTIONS
19077 int nDigits = (hasDupes)? db_int(*pDb, zColDigits) : 0;
19078 #else
19079 # define nDigits 2
19080 #endif
19081 if( hasDupes ){
19082 #ifdef SHELL_COLUMN_RENAME_CLEAN
19083 rc = sqlite3_exec(*pDb, zDedoctor, 0, 0, 0);
19084 rc_err_oom_die(rc);
19085 #endif
19086 rc = sqlite3_exec(*pDb, zSetReps, 0, 0, 0);
19087 rc_err_oom_die(rc);
19088 rc = sqlite3_prepare_v2(*pDb, zRenameRank, -1, &pStmt, 0);
19089 rc_err_oom_die(rc);
19090 sqlite3_bind_int(pStmt, 1, nDigits);
19091 rc = sqlite3_step(pStmt);
19092 sqlite3_finalize(pStmt);
19093 assert(rc==SQLITE_DONE);
19094 }
19095 assert(db_int(*pDb, zHasDupes)==0); /* Consider: remove this */
19096 rc = sqlite3_prepare_v2(*pDb, zCollectVar, -1, &pStmt, 0);
19097 rc_err_oom_die(rc);
19098 rc = sqlite3_step(pStmt);
19099 if( rc==SQLITE_ROW ){
19100 zColsSpec = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 0));
19101 }else{
19102 zColsSpec = 0;
19103 }
19104 if( pzRenamed!=0 ){
19105 if( !hasDupes ) *pzRenamed = 0;
19106 else{
19107 sqlite3_finalize(pStmt);
19108 if( SQLITE_OK==sqlite3_prepare_v2(*pDb, zRenamesDone, -1, &pStmt, 0)
19109 && SQLITE_ROW==sqlite3_step(pStmt) ){
19110 *pzRenamed = sqlite3_mprintf("%s", sqlite3_column_text(pStmt, 0));
19111 }else
19112 *pzRenamed = 0;
19113 }
19114 }
19115 sqlite3_finalize(pStmt);
19116 sqlite3_close(*pDb);
19117 *pDb = 0;
19118 return zColsSpec;
19119 }
19120 }
19121
19122 /*
19123 ** If an input line begins with "." then invoke this routine to
19124 ** process that line.
19125 **
19126 ** Return 1 on error, 2 to exit, and 0 otherwise.
@@ -19844,24 +20065,33 @@
20065 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
20066 import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */
20067 if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(p->db))==0 ){
20068 char *zCreate = sqlite3_mprintf("CREATE TABLE \"%w\".\"%w\"",
20069 zSchema, zTable);
20070 sqlite3 *dbCols = 0;
20071 char *zRenames = 0;
20072 char *zColDefs;
20073 while( xRead(&sCtx) ){
20074 zAutoColumn(sCtx.z, &dbCols, 0);
 
20075 if( sCtx.cTerm!=sCtx.cColSep ) break;
20076 }
20077 zColDefs = zAutoColumn(0, &dbCols, &zRenames);
20078 if( zRenames!=0 ){
20079 utf8_printf((stdin_is_interactive && p->in==stdin)? p->out : stderr,
20080 "Columns renamed during .import %s due to duplicates:\n"
20081 "%s\n", sCtx.zFile, zRenames);
20082 sqlite3_free(zRenames);
20083 }
20084 assert(dbCols==0);
20085 if( zColDefs==0 ){
20086 sqlite3_free(zCreate);
20087 import_cleanup(&sCtx);
20088 utf8_printf(stderr,"%s: empty file\n", sCtx.zFile);
20089 rc = 1;
20090 goto meta_command_exit;
20091 }
20092 zCreate = sqlite3_mprintf("%z%z\n", zCreate, zColDefs);
20093 if( eVerbose>=1 ){
20094 utf8_printf(p->out, "%s\n", zCreate);
20095 }
20096 rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
20097 if( rc ){
20098
+81 -36
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452452
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453
** [sqlite_version()] and [sqlite_source_id()].
454454
*/
455455
#define SQLITE_VERSION "3.38.0"
456456
#define SQLITE_VERSION_NUMBER 3038000
457
-#define SQLITE_SOURCE_ID "2022-02-10 15:40:40 85cb6014751a0572d28ebd839331d5d7a78de45c9e522adcd834a8a85746f32e"
457
+#define SQLITE_SOURCE_ID "2022-02-15 13:23:09 9edaeed56f2282fd4da935454178c38ab49d259aed96d4e720aae09050a53006"
458458
459459
/*
460460
** CAPI3REF: Run-Time Library Version Numbers
461461
** KEYWORDS: sqlite3_version sqlite3_sourceid
462462
**
@@ -19193,10 +19193,11 @@
1919319193
#endif
1919419194
#ifndef SQLITE_UNTESTABLE
1919519195
int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */
1919619196
#endif
1919719197
int bLocaltimeFault; /* True to fail localtime() calls */
19198
+ int (*xAltLocaltime)(const void*,void*); /* Alternative localtime() routine */
1919819199
int iOnceResetThreshold; /* When to reset OP_Once counters */
1919919200
u32 szSorterRef; /* Min size in bytes to use sorter-refs */
1920019201
unsigned int iPrngSeed; /* Alternative fixed seed for the PRNG */
1920119202
/* vvvv--- must be last ---vvv */
1920219203
#ifdef SQLITE_DEBUG
@@ -21873,10 +21874,11 @@
2187321874
#endif
2187421875
#ifndef SQLITE_UNTESTABLE
2187521876
0, /* xTestCallback */
2187621877
#endif
2187721878
0, /* bLocaltimeFault */
21879
+ 0, /* xAltLocaltime */
2187821880
0x7ffffffe, /* iOnceResetThreshold */
2187921881
SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */
2188021882
0, /* iPrngSeed */
2188121883
};
2188221884
@@ -23547,12 +23549,14 @@
2354723549
** The following routine implements the rough equivalent of localtime_r()
2354823550
** using whatever operating-system specific localtime facility that
2354923551
** is available. This routine returns 0 on success and
2355023552
** non-zero on any kind of error.
2355123553
**
23552
-** If the sqlite3GlobalConfig.bLocaltimeFault variable is true then this
23553
-** routine will always fail.
23554
+** If the sqlite3GlobalConfig.bLocaltimeFault variable is non-zero then this
23555
+** routine will always fail. If bLocaltimeFault is nonzero and
23556
+** sqlite3GlobalConfig.xAltLocaltime is not NULL, then xAltLocaltime() is
23557
+** invoked in place of the OS-defined localtime() function.
2355423558
**
2355523559
** EVIDENCE-OF: R-62172-00036 In this implementation, the standard C
2355623560
** library function localtime_r() is used to assist in the calculation of
2355723561
** local time.
2355823562
*/
@@ -23564,20 +23568,34 @@
2356423568
sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN);
2356523569
#endif
2356623570
sqlite3_mutex_enter(mutex);
2356723571
pX = localtime(t);
2356823572
#ifndef SQLITE_UNTESTABLE
23569
- if( sqlite3GlobalConfig.bLocaltimeFault ) pX = 0;
23573
+ if( sqlite3GlobalConfig.bLocaltimeFault ){
23574
+ if( sqlite3GlobalConfig.xAltLocaltime!=0
23575
+ && 0==sqlite3GlobalConfig.xAltLocaltime((const void*)t,(void*)pTm)
23576
+ ){
23577
+ pX = pTm;
23578
+ }else{
23579
+ pX = 0;
23580
+ }
23581
+ }
2357023582
#endif
2357123583
if( pX ) *pTm = *pX;
2357223584
#if SQLITE_THREADSAFE>0
2357323585
sqlite3_mutex_leave(mutex);
2357423586
#endif
2357523587
rc = pX==0;
2357623588
#else
2357723589
#ifndef SQLITE_UNTESTABLE
23578
- if( sqlite3GlobalConfig.bLocaltimeFault ) return 1;
23590
+ if( sqlite3GlobalConfig.bLocaltimeFault ){
23591
+ if( sqlite3GlobalConfig.xAltLocaltime!=0 ){
23592
+ return sqlite3GlobalConfig.xAltLocaltime((const void*)t,(void*)pTm);
23593
+ }else{
23594
+ return 1;
23595
+ }
23596
+ }
2357923597
#endif
2358023598
#if HAVE_LOCALTIME_R
2358123599
rc = localtime_r(t, pTm)==0;
2358223600
#else
2358323601
rc = localtime_s(pTm, t);
@@ -57114,11 +57132,11 @@
5711457132
** Once this function has been called, the transaction must either be
5711557133
** rolled back or committed. It is not safe to call this function and
5711657134
** then continue writing to the database.
5711757135
*/
5711857136
SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){
57119
- assert( pPager->dbSize>=nPage );
57137
+ assert( pPager->dbSize>=nPage || CORRUPT_DB );
5712057138
assert( pPager->eState>=PAGER_WRITER_CACHEMOD );
5712157139
pPager->dbSize = nPage;
5712257140
5712357141
/* At one point the code here called assertTruncateConstraint() to
5712457142
** ensure that all pages being truncated away by this operation are,
@@ -57666,16 +57684,10 @@
5766657684
PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno));
5766757685
rc = write32bits(pPager->sjfd, offset, pPg->pgno);
5766857686
if( rc==SQLITE_OK ){
5766957687
rc = sqlite3OsWrite(pPager->sjfd, pData2, pPager->pageSize, offset+4);
5767057688
}
57671
- if( rc!=SQLITE_OK ){
57672
- /* Subjournal writes should be "atomic" in the sense that we should
57673
- ** never allow a partial write. If anything goes wrong, make sure
57674
- ** to roll back any partial writes that may have occurred */
57675
- (void)sqlite3OsTruncate(pPager->sjfd, offset);
57676
- }
5767757689
}
5767857690
}
5767957691
if( rc==SQLITE_OK ){
5768057692
pPager->nSubRec++;
5768157693
assert( pPager->nSavepoint>0 );
@@ -67892,11 +67904,11 @@
6789267904
iPtr = iFreeBlk;
6789367905
}
6789467906
if( iFreeBlk>pPage->pBt->usableSize-4 ){ /* TH3: corrupt081.100 */
6789567907
return SQLITE_CORRUPT_PAGE(pPage);
6789667908
}
67897
- assert( iFreeBlk>iPtr || iFreeBlk==0 );
67909
+ assert( iFreeBlk>iPtr || iFreeBlk==0 || CORRUPT_DB );
6789867910
6789967911
/* At this point:
6790067912
** iFreeBlk: First freeblock after iStart, or zero if none
6790167913
** iPtr: The address of a pointer to iFreeBlk
6790267914
**
@@ -72521,11 +72533,11 @@
7252172533
7252272534
assert( sqlite3_mutex_held(pBt->mutex) );
7252372535
assert( CORRUPT_DB || iPage>1 );
7252472536
assert( !pMemPage || pMemPage->pgno==iPage );
7252572537
72526
- if( NEVER(iPage<2) || iPage>pBt->nPage ){
72538
+ if( iPage<2 || iPage>pBt->nPage ){
7252772539
return SQLITE_CORRUPT_BKPT;
7252872540
}
7252972541
if( pMemPage ){
7253072542
pPage = pMemPage;
7253172543
sqlite3PagerRef(pPage->pDbPage);
@@ -72956,10 +72968,16 @@
7295672968
data = pPage->aData;
7295772969
ptr = &pPage->aCellIdx[2*idx];
7295872970
assert( pPage->pBt->usableSize > (u32)(ptr-data) );
7295972971
pc = get2byte(ptr);
7296072972
hdr = pPage->hdrOffset;
72973
+#if 0 /* Not required. Omit for efficiency */
72974
+ if( pc<hdr+pPage->nCell*2 ){
72975
+ *pRC = SQLITE_CORRUPT_BKPT;
72976
+ return;
72977
+ }
72978
+#endif
7296172979
testcase( pc==(u32)get2byte(&data[hdr+5]) );
7296272980
testcase( pc+sz==pPage->pBt->usableSize );
7296372981
if( pc+sz > pPage->pBt->usableSize ){
7296472982
*pRC = SQLITE_CORRUPT_BKPT;
7296572983
return;
@@ -75726,11 +75744,11 @@
7572675744
return SQLITE_CORRUPT_BKPT;
7572775745
}
7572875746
rc = getAndInitPage(pBt, pgno, &pPage, 0, 0);
7572975747
if( rc ) return rc;
7573075748
if( (pBt->openFlags & BTREE_SINGLE)==0
75731
- && sqlite3PagerPageRefcount(pPage->pDbPage)!=1
75749
+ && sqlite3PagerPageRefcount(pPage->pDbPage) != (1 + (pgno==1))
7573275750
){
7573375751
rc = SQLITE_CORRUPT_BKPT;
7573475752
goto cleardatabasepage_out;
7573575753
}
7573675754
hdr = pPage->hdrOffset;
@@ -86595,11 +86613,14 @@
8659586613
case SQLITE_INTEGER: {
8659686614
rc = sqlite3_bind_int64(pStmt, i, pValue->u.i);
8659786615
break;
8659886616
}
8659986617
case SQLITE_FLOAT: {
86600
- rc = sqlite3_bind_double(pStmt, i, sqlite3VdbeRealValue((Mem*)pValue));
86618
+ assert( pValue->flags & (MEM_Real|MEM_IntReal) );
86619
+ rc = sqlite3_bind_double(pStmt, i,
86620
+ (pValue->flags & MEM_Real) ? pValue->u.r : (double)pValue->u.i
86621
+ );
8660186622
break;
8660286623
}
8660386624
case SQLITE_BLOB: {
8660486625
if( pValue->flags & MEM_Zero ){
8660586626
rc = sqlite3_bind_zeroblob(pStmt, i, pValue->u.nZero);
@@ -99823,10 +99844,13 @@
9982399844
}
9982499845
return rc;
9982599846
}
9982699847
9982799848
99849
+/* Forward reference */
99850
+static int memjrnlTruncate(sqlite3_file *pJfd, sqlite_int64 size);
99851
+
9982899852
/*
9982999853
** Write data to the file.
9983099854
*/
9983199855
static int memjrnlWrite(
9983299856
sqlite3_file *pJfd, /* The journal file into which to write */
@@ -99853,26 +99877,24 @@
9985399877
/* An in-memory journal file should only ever be appended to. Random
9985499878
** access writes are not required. The only exception to this is when
9985599879
** the in-memory journal is being used by a connection using the
9985699880
** atomic-write optimization. In this case the first 28 bytes of the
9985799881
** journal file may be written as part of committing the transaction. */
99858
- assert( iOfst==p->endpoint.iOffset || iOfst==0 );
99859
-#if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
99860
- || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
99882
+ assert( iOfst<=p->endpoint.iOffset );
99883
+ if( iOfst>0 && iOfst!=p->endpoint.iOffset ){
99884
+ memjrnlTruncate(pJfd, iOfst);
99885
+ }
9986199886
if( iOfst==0 && p->pFirst ){
9986299887
assert( p->nChunkSize>iAmt );
9986399888
memcpy((u8*)p->pFirst->zChunk, zBuf, iAmt);
99864
- }else
99865
-#else
99866
- assert( iOfst>0 || p->pFirst==0 );
99867
-#endif
99868
- {
99889
+ }else{
9986999890
while( nWrite>0 ){
9987099891
FileChunk *pChunk = p->endpoint.pChunk;
9987199892
int iChunkOffset = (int)(p->endpoint.iOffset%p->nChunkSize);
9987299893
int iSpace = MIN(nWrite, p->nChunkSize - iChunkOffset);
9987399894
99895
+ assert( pChunk!=0 || iChunkOffset==0 );
9987499896
if( iChunkOffset==0 ){
9987599897
/* New chunk is required to extend the file. */
9987699898
FileChunk *pNew = sqlite3_malloc(fileChunkSize(p->nChunkSize));
9987799899
if( !pNew ){
9987899900
return SQLITE_IOERR_NOMEM_BKPT;
@@ -99883,14 +99905,15 @@
9988399905
pChunk->pNext = pNew;
9988499906
}else{
9988599907
assert( !p->pFirst );
9988699908
p->pFirst = pNew;
9988799909
}
99888
- p->endpoint.pChunk = pNew;
99910
+ pChunk = p->endpoint.pChunk = pNew;
9988999911
}
9989099912
99891
- memcpy((u8*)p->endpoint.pChunk->zChunk + iChunkOffset, zWrite, iSpace);
99913
+ assert( pChunk!=0 );
99914
+ memcpy((u8*)pChunk->zChunk + iChunkOffset, zWrite, iSpace);
9989299915
zWrite += iSpace;
9989399916
nWrite -= iSpace;
9989499917
p->endpoint.iOffset += iSpace;
9989599918
}
9989699919
}
@@ -122104,12 +122127,13 @@
122104122127
UNUSED_PARAMETER(argc);
122105122128
sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
122106122129
sqlite3QuoteValue(&str,argv[0]);
122107122130
sqlite3_result_text(context, sqlite3StrAccumFinish(&str), str.nChar,
122108122131
SQLITE_DYNAMIC);
122109
- if( str.accError==SQLITE_NOMEM ){
122110
- sqlite3_result_error_nomem(context);
122132
+ if( str.accError!=SQLITE_OK ){
122133
+ sqlite3_result_null(context);
122134
+ sqlite3_result_error_code(context, str.accError);
122111122135
}
122112122136
}
122113122137
122114122138
/*
122115122139
** The unicode() function. Return the integer unicode code-point value
@@ -165463,10 +165487,13 @@
165463165487
{
165464165488
Expr *temp1 = tokenExpr(pParse,TK_ID,yymsp[-4].minor.yy0);
165465165489
Expr *temp2 = tokenExpr(pParse,TK_ID,yymsp[-2].minor.yy0);
165466165490
Expr *temp3 = tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0);
165467165491
Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3);
165492
+ if( IN_RENAME_OBJECT ){
165493
+ sqlite3RenameTokenRemap(pParse, 0, temp1);
165494
+ }
165468165495
yylhsminor.yy528 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4);
165469165496
}
165470165497
yymsp[-4].minor.yy528 = yylhsminor.yy528;
165471165498
break;
165472165499
case 182: /* term ::= NULL|FLOAT|BLOB */
@@ -172333,16 +172360,20 @@
172333172360
** is called immediately after installing the new callback and the return
172334172361
** value from sqlite3FaultSim(0) becomes the return from
172335172362
** sqlite3_test_control().
172336172363
*/
172337172364
case SQLITE_TESTCTRL_FAULT_INSTALL: {
172338
- /* MSVC is picky about pulling func ptrs from va lists.
172339
- ** http://support.microsoft.com/kb/47961
172365
+ /* A bug in MSVC prevents it from understanding pointers to functions
172366
+ ** types in the second argument to va_arg(). Work around the problem
172367
+ ** using a typedef.
172368
+ ** http://support.microsoft.com/kb/47961 <-- dead hyperlink
172369
+ ** Search at http://web.archive.org/ to find the 2015-03-16 archive
172370
+ ** of the link above to see the original text.
172340172371
** sqlite3GlobalConfig.xTestCallback = va_arg(ap, int(*)(int));
172341172372
*/
172342
- typedef int(*TESTCALLBACKFUNC_t)(int);
172343
- sqlite3GlobalConfig.xTestCallback = va_arg(ap, TESTCALLBACKFUNC_t);
172373
+ typedef int(*sqlite3FaultFuncType)(int);
172374
+ sqlite3GlobalConfig.xTestCallback = va_arg(ap, sqlite3FaultFuncType);
172344172375
rc = sqlite3FaultSim(0);
172345172376
break;
172346172377
}
172347172378
172348172379
/*
@@ -172465,17 +172496,31 @@
172465172496
sqlite3 *db = va_arg(ap, sqlite3*);
172466172497
db->dbOptFlags = va_arg(ap, u32);
172467172498
break;
172468172499
}
172469172500
172470
- /* sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, int onoff);
172501
+ /* sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, onoff, xAlt);
172502
+ **
172503
+ ** If parameter onoff is 1, subsequent calls to localtime() fail.
172504
+ ** If 2, then invoke xAlt() instead of localtime(). If 0, normal
172505
+ ** processing.
172506
+ **
172507
+ ** xAlt arguments are void pointers, but they really want to be:
172508
+ **
172509
+ ** int xAlt(const time_t*, struct tm*);
172471172510
**
172472
- ** If parameter onoff is non-zero, subsequent calls to localtime()
172473
- ** and its variants fail. If onoff is zero, undo this setting.
172511
+ ** xAlt should write results in to struct tm object of its 2nd argument
172512
+ ** and return zero on success, or return non-zero on failure.
172474172513
*/
172475172514
case SQLITE_TESTCTRL_LOCALTIME_FAULT: {
172476172515
sqlite3GlobalConfig.bLocaltimeFault = va_arg(ap, int);
172516
+ if( sqlite3GlobalConfig.bLocaltimeFault==2 ){
172517
+ typedef int(*sqlite3LocaltimeType)(const void*,void*);
172518
+ sqlite3GlobalConfig.xAltLocaltime = va_arg(ap, sqlite3LocaltimeType);
172519
+ }else{
172520
+ sqlite3GlobalConfig.xAltLocaltime = 0;
172521
+ }
172477172522
break;
172478172523
}
172479172524
172480172525
/* sqlite3_test_control(SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, sqlite3*);
172481172526
**
@@ -234245,11 +234290,11 @@
234245234290
int nArg, /* Number of args */
234246234291
sqlite3_value **apUnused /* Function arguments */
234247234292
){
234248234293
assert( nArg==0 );
234249234294
UNUSED_PARAM2(nArg, apUnused);
234250
- sqlite3_result_text(pCtx, "fts5: 2022-02-10 15:40:40 85cb6014751a0572d28ebd839331d5d7a78de45c9e522adcd834a8a85746f32e", -1, SQLITE_TRANSIENT);
234295
+ sqlite3_result_text(pCtx, "fts5: 2022-02-15 13:23:09 9edaeed56f2282fd4da935454178c38ab49d259aed96d4e720aae09050a53006", -1, SQLITE_TRANSIENT);
234251234296
}
234252234297
234253234298
/*
234254234299
** Return true if zName is the extension on one of the shadow tables used
234255234300
** by this module.
234256234301
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.38.0"
456 #define SQLITE_VERSION_NUMBER 3038000
457 #define SQLITE_SOURCE_ID "2022-02-10 15:40:40 85cb6014751a0572d28ebd839331d5d7a78de45c9e522adcd834a8a85746f32e"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -19193,10 +19193,11 @@
19193 #endif
19194 #ifndef SQLITE_UNTESTABLE
19195 int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */
19196 #endif
19197 int bLocaltimeFault; /* True to fail localtime() calls */
 
19198 int iOnceResetThreshold; /* When to reset OP_Once counters */
19199 u32 szSorterRef; /* Min size in bytes to use sorter-refs */
19200 unsigned int iPrngSeed; /* Alternative fixed seed for the PRNG */
19201 /* vvvv--- must be last ---vvv */
19202 #ifdef SQLITE_DEBUG
@@ -21873,10 +21874,11 @@
21873 #endif
21874 #ifndef SQLITE_UNTESTABLE
21875 0, /* xTestCallback */
21876 #endif
21877 0, /* bLocaltimeFault */
 
21878 0x7ffffffe, /* iOnceResetThreshold */
21879 SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */
21880 0, /* iPrngSeed */
21881 };
21882
@@ -23547,12 +23549,14 @@
23547 ** The following routine implements the rough equivalent of localtime_r()
23548 ** using whatever operating-system specific localtime facility that
23549 ** is available. This routine returns 0 on success and
23550 ** non-zero on any kind of error.
23551 **
23552 ** If the sqlite3GlobalConfig.bLocaltimeFault variable is true then this
23553 ** routine will always fail.
 
 
23554 **
23555 ** EVIDENCE-OF: R-62172-00036 In this implementation, the standard C
23556 ** library function localtime_r() is used to assist in the calculation of
23557 ** local time.
23558 */
@@ -23564,20 +23568,34 @@
23564 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN);
23565 #endif
23566 sqlite3_mutex_enter(mutex);
23567 pX = localtime(t);
23568 #ifndef SQLITE_UNTESTABLE
23569 if( sqlite3GlobalConfig.bLocaltimeFault ) pX = 0;
 
 
 
 
 
 
 
 
23570 #endif
23571 if( pX ) *pTm = *pX;
23572 #if SQLITE_THREADSAFE>0
23573 sqlite3_mutex_leave(mutex);
23574 #endif
23575 rc = pX==0;
23576 #else
23577 #ifndef SQLITE_UNTESTABLE
23578 if( sqlite3GlobalConfig.bLocaltimeFault ) return 1;
 
 
 
 
 
 
23579 #endif
23580 #if HAVE_LOCALTIME_R
23581 rc = localtime_r(t, pTm)==0;
23582 #else
23583 rc = localtime_s(pTm, t);
@@ -57114,11 +57132,11 @@
57114 ** Once this function has been called, the transaction must either be
57115 ** rolled back or committed. It is not safe to call this function and
57116 ** then continue writing to the database.
57117 */
57118 SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){
57119 assert( pPager->dbSize>=nPage );
57120 assert( pPager->eState>=PAGER_WRITER_CACHEMOD );
57121 pPager->dbSize = nPage;
57122
57123 /* At one point the code here called assertTruncateConstraint() to
57124 ** ensure that all pages being truncated away by this operation are,
@@ -57666,16 +57684,10 @@
57666 PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno));
57667 rc = write32bits(pPager->sjfd, offset, pPg->pgno);
57668 if( rc==SQLITE_OK ){
57669 rc = sqlite3OsWrite(pPager->sjfd, pData2, pPager->pageSize, offset+4);
57670 }
57671 if( rc!=SQLITE_OK ){
57672 /* Subjournal writes should be "atomic" in the sense that we should
57673 ** never allow a partial write. If anything goes wrong, make sure
57674 ** to roll back any partial writes that may have occurred */
57675 (void)sqlite3OsTruncate(pPager->sjfd, offset);
57676 }
57677 }
57678 }
57679 if( rc==SQLITE_OK ){
57680 pPager->nSubRec++;
57681 assert( pPager->nSavepoint>0 );
@@ -67892,11 +67904,11 @@
67892 iPtr = iFreeBlk;
67893 }
67894 if( iFreeBlk>pPage->pBt->usableSize-4 ){ /* TH3: corrupt081.100 */
67895 return SQLITE_CORRUPT_PAGE(pPage);
67896 }
67897 assert( iFreeBlk>iPtr || iFreeBlk==0 );
67898
67899 /* At this point:
67900 ** iFreeBlk: First freeblock after iStart, or zero if none
67901 ** iPtr: The address of a pointer to iFreeBlk
67902 **
@@ -72521,11 +72533,11 @@
72521
72522 assert( sqlite3_mutex_held(pBt->mutex) );
72523 assert( CORRUPT_DB || iPage>1 );
72524 assert( !pMemPage || pMemPage->pgno==iPage );
72525
72526 if( NEVER(iPage<2) || iPage>pBt->nPage ){
72527 return SQLITE_CORRUPT_BKPT;
72528 }
72529 if( pMemPage ){
72530 pPage = pMemPage;
72531 sqlite3PagerRef(pPage->pDbPage);
@@ -72956,10 +72968,16 @@
72956 data = pPage->aData;
72957 ptr = &pPage->aCellIdx[2*idx];
72958 assert( pPage->pBt->usableSize > (u32)(ptr-data) );
72959 pc = get2byte(ptr);
72960 hdr = pPage->hdrOffset;
 
 
 
 
 
 
72961 testcase( pc==(u32)get2byte(&data[hdr+5]) );
72962 testcase( pc+sz==pPage->pBt->usableSize );
72963 if( pc+sz > pPage->pBt->usableSize ){
72964 *pRC = SQLITE_CORRUPT_BKPT;
72965 return;
@@ -75726,11 +75744,11 @@
75726 return SQLITE_CORRUPT_BKPT;
75727 }
75728 rc = getAndInitPage(pBt, pgno, &pPage, 0, 0);
75729 if( rc ) return rc;
75730 if( (pBt->openFlags & BTREE_SINGLE)==0
75731 && sqlite3PagerPageRefcount(pPage->pDbPage)!=1
75732 ){
75733 rc = SQLITE_CORRUPT_BKPT;
75734 goto cleardatabasepage_out;
75735 }
75736 hdr = pPage->hdrOffset;
@@ -86595,11 +86613,14 @@
86595 case SQLITE_INTEGER: {
86596 rc = sqlite3_bind_int64(pStmt, i, pValue->u.i);
86597 break;
86598 }
86599 case SQLITE_FLOAT: {
86600 rc = sqlite3_bind_double(pStmt, i, sqlite3VdbeRealValue((Mem*)pValue));
 
 
 
86601 break;
86602 }
86603 case SQLITE_BLOB: {
86604 if( pValue->flags & MEM_Zero ){
86605 rc = sqlite3_bind_zeroblob(pStmt, i, pValue->u.nZero);
@@ -99823,10 +99844,13 @@
99823 }
99824 return rc;
99825 }
99826
99827
 
 
 
99828 /*
99829 ** Write data to the file.
99830 */
99831 static int memjrnlWrite(
99832 sqlite3_file *pJfd, /* The journal file into which to write */
@@ -99853,26 +99877,24 @@
99853 /* An in-memory journal file should only ever be appended to. Random
99854 ** access writes are not required. The only exception to this is when
99855 ** the in-memory journal is being used by a connection using the
99856 ** atomic-write optimization. In this case the first 28 bytes of the
99857 ** journal file may be written as part of committing the transaction. */
99858 assert( iOfst==p->endpoint.iOffset || iOfst==0 );
99859 #if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
99860 || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
 
99861 if( iOfst==0 && p->pFirst ){
99862 assert( p->nChunkSize>iAmt );
99863 memcpy((u8*)p->pFirst->zChunk, zBuf, iAmt);
99864 }else
99865 #else
99866 assert( iOfst>0 || p->pFirst==0 );
99867 #endif
99868 {
99869 while( nWrite>0 ){
99870 FileChunk *pChunk = p->endpoint.pChunk;
99871 int iChunkOffset = (int)(p->endpoint.iOffset%p->nChunkSize);
99872 int iSpace = MIN(nWrite, p->nChunkSize - iChunkOffset);
99873
 
99874 if( iChunkOffset==0 ){
99875 /* New chunk is required to extend the file. */
99876 FileChunk *pNew = sqlite3_malloc(fileChunkSize(p->nChunkSize));
99877 if( !pNew ){
99878 return SQLITE_IOERR_NOMEM_BKPT;
@@ -99883,14 +99905,15 @@
99883 pChunk->pNext = pNew;
99884 }else{
99885 assert( !p->pFirst );
99886 p->pFirst = pNew;
99887 }
99888 p->endpoint.pChunk = pNew;
99889 }
99890
99891 memcpy((u8*)p->endpoint.pChunk->zChunk + iChunkOffset, zWrite, iSpace);
 
99892 zWrite += iSpace;
99893 nWrite -= iSpace;
99894 p->endpoint.iOffset += iSpace;
99895 }
99896 }
@@ -122104,12 +122127,13 @@
122104 UNUSED_PARAMETER(argc);
122105 sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
122106 sqlite3QuoteValue(&str,argv[0]);
122107 sqlite3_result_text(context, sqlite3StrAccumFinish(&str), str.nChar,
122108 SQLITE_DYNAMIC);
122109 if( str.accError==SQLITE_NOMEM ){
122110 sqlite3_result_error_nomem(context);
 
122111 }
122112 }
122113
122114 /*
122115 ** The unicode() function. Return the integer unicode code-point value
@@ -165463,10 +165487,13 @@
165463 {
165464 Expr *temp1 = tokenExpr(pParse,TK_ID,yymsp[-4].minor.yy0);
165465 Expr *temp2 = tokenExpr(pParse,TK_ID,yymsp[-2].minor.yy0);
165466 Expr *temp3 = tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0);
165467 Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3);
 
 
 
165468 yylhsminor.yy528 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4);
165469 }
165470 yymsp[-4].minor.yy528 = yylhsminor.yy528;
165471 break;
165472 case 182: /* term ::= NULL|FLOAT|BLOB */
@@ -172333,16 +172360,20 @@
172333 ** is called immediately after installing the new callback and the return
172334 ** value from sqlite3FaultSim(0) becomes the return from
172335 ** sqlite3_test_control().
172336 */
172337 case SQLITE_TESTCTRL_FAULT_INSTALL: {
172338 /* MSVC is picky about pulling func ptrs from va lists.
172339 ** http://support.microsoft.com/kb/47961
 
 
 
 
172340 ** sqlite3GlobalConfig.xTestCallback = va_arg(ap, int(*)(int));
172341 */
172342 typedef int(*TESTCALLBACKFUNC_t)(int);
172343 sqlite3GlobalConfig.xTestCallback = va_arg(ap, TESTCALLBACKFUNC_t);
172344 rc = sqlite3FaultSim(0);
172345 break;
172346 }
172347
172348 /*
@@ -172465,17 +172496,31 @@
172465 sqlite3 *db = va_arg(ap, sqlite3*);
172466 db->dbOptFlags = va_arg(ap, u32);
172467 break;
172468 }
172469
172470 /* sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, int onoff);
 
 
 
 
 
 
 
 
172471 **
172472 ** If parameter onoff is non-zero, subsequent calls to localtime()
172473 ** and its variants fail. If onoff is zero, undo this setting.
172474 */
172475 case SQLITE_TESTCTRL_LOCALTIME_FAULT: {
172476 sqlite3GlobalConfig.bLocaltimeFault = va_arg(ap, int);
 
 
 
 
 
 
172477 break;
172478 }
172479
172480 /* sqlite3_test_control(SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, sqlite3*);
172481 **
@@ -234245,11 +234290,11 @@
234245 int nArg, /* Number of args */
234246 sqlite3_value **apUnused /* Function arguments */
234247 ){
234248 assert( nArg==0 );
234249 UNUSED_PARAM2(nArg, apUnused);
234250 sqlite3_result_text(pCtx, "fts5: 2022-02-10 15:40:40 85cb6014751a0572d28ebd839331d5d7a78de45c9e522adcd834a8a85746f32e", -1, SQLITE_TRANSIENT);
234251 }
234252
234253 /*
234254 ** Return true if zName is the extension on one of the shadow tables used
234255 ** by this module.
234256
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.38.0"
456 #define SQLITE_VERSION_NUMBER 3038000
457 #define SQLITE_SOURCE_ID "2022-02-15 13:23:09 9edaeed56f2282fd4da935454178c38ab49d259aed96d4e720aae09050a53006"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -19193,10 +19193,11 @@
19193 #endif
19194 #ifndef SQLITE_UNTESTABLE
19195 int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */
19196 #endif
19197 int bLocaltimeFault; /* True to fail localtime() calls */
19198 int (*xAltLocaltime)(const void*,void*); /* Alternative localtime() routine */
19199 int iOnceResetThreshold; /* When to reset OP_Once counters */
19200 u32 szSorterRef; /* Min size in bytes to use sorter-refs */
19201 unsigned int iPrngSeed; /* Alternative fixed seed for the PRNG */
19202 /* vvvv--- must be last ---vvv */
19203 #ifdef SQLITE_DEBUG
@@ -21873,10 +21874,11 @@
21874 #endif
21875 #ifndef SQLITE_UNTESTABLE
21876 0, /* xTestCallback */
21877 #endif
21878 0, /* bLocaltimeFault */
21879 0, /* xAltLocaltime */
21880 0x7ffffffe, /* iOnceResetThreshold */
21881 SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */
21882 0, /* iPrngSeed */
21883 };
21884
@@ -23547,12 +23549,14 @@
23549 ** The following routine implements the rough equivalent of localtime_r()
23550 ** using whatever operating-system specific localtime facility that
23551 ** is available. This routine returns 0 on success and
23552 ** non-zero on any kind of error.
23553 **
23554 ** If the sqlite3GlobalConfig.bLocaltimeFault variable is non-zero then this
23555 ** routine will always fail. If bLocaltimeFault is nonzero and
23556 ** sqlite3GlobalConfig.xAltLocaltime is not NULL, then xAltLocaltime() is
23557 ** invoked in place of the OS-defined localtime() function.
23558 **
23559 ** EVIDENCE-OF: R-62172-00036 In this implementation, the standard C
23560 ** library function localtime_r() is used to assist in the calculation of
23561 ** local time.
23562 */
@@ -23564,20 +23568,34 @@
23568 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN);
23569 #endif
23570 sqlite3_mutex_enter(mutex);
23571 pX = localtime(t);
23572 #ifndef SQLITE_UNTESTABLE
23573 if( sqlite3GlobalConfig.bLocaltimeFault ){
23574 if( sqlite3GlobalConfig.xAltLocaltime!=0
23575 && 0==sqlite3GlobalConfig.xAltLocaltime((const void*)t,(void*)pTm)
23576 ){
23577 pX = pTm;
23578 }else{
23579 pX = 0;
23580 }
23581 }
23582 #endif
23583 if( pX ) *pTm = *pX;
23584 #if SQLITE_THREADSAFE>0
23585 sqlite3_mutex_leave(mutex);
23586 #endif
23587 rc = pX==0;
23588 #else
23589 #ifndef SQLITE_UNTESTABLE
23590 if( sqlite3GlobalConfig.bLocaltimeFault ){
23591 if( sqlite3GlobalConfig.xAltLocaltime!=0 ){
23592 return sqlite3GlobalConfig.xAltLocaltime((const void*)t,(void*)pTm);
23593 }else{
23594 return 1;
23595 }
23596 }
23597 #endif
23598 #if HAVE_LOCALTIME_R
23599 rc = localtime_r(t, pTm)==0;
23600 #else
23601 rc = localtime_s(pTm, t);
@@ -57114,11 +57132,11 @@
57132 ** Once this function has been called, the transaction must either be
57133 ** rolled back or committed. It is not safe to call this function and
57134 ** then continue writing to the database.
57135 */
57136 SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){
57137 assert( pPager->dbSize>=nPage || CORRUPT_DB );
57138 assert( pPager->eState>=PAGER_WRITER_CACHEMOD );
57139 pPager->dbSize = nPage;
57140
57141 /* At one point the code here called assertTruncateConstraint() to
57142 ** ensure that all pages being truncated away by this operation are,
@@ -57666,16 +57684,10 @@
57684 PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno));
57685 rc = write32bits(pPager->sjfd, offset, pPg->pgno);
57686 if( rc==SQLITE_OK ){
57687 rc = sqlite3OsWrite(pPager->sjfd, pData2, pPager->pageSize, offset+4);
57688 }
 
 
 
 
 
 
57689 }
57690 }
57691 if( rc==SQLITE_OK ){
57692 pPager->nSubRec++;
57693 assert( pPager->nSavepoint>0 );
@@ -67892,11 +67904,11 @@
67904 iPtr = iFreeBlk;
67905 }
67906 if( iFreeBlk>pPage->pBt->usableSize-4 ){ /* TH3: corrupt081.100 */
67907 return SQLITE_CORRUPT_PAGE(pPage);
67908 }
67909 assert( iFreeBlk>iPtr || iFreeBlk==0 || CORRUPT_DB );
67910
67911 /* At this point:
67912 ** iFreeBlk: First freeblock after iStart, or zero if none
67913 ** iPtr: The address of a pointer to iFreeBlk
67914 **
@@ -72521,11 +72533,11 @@
72533
72534 assert( sqlite3_mutex_held(pBt->mutex) );
72535 assert( CORRUPT_DB || iPage>1 );
72536 assert( !pMemPage || pMemPage->pgno==iPage );
72537
72538 if( iPage<2 || iPage>pBt->nPage ){
72539 return SQLITE_CORRUPT_BKPT;
72540 }
72541 if( pMemPage ){
72542 pPage = pMemPage;
72543 sqlite3PagerRef(pPage->pDbPage);
@@ -72956,10 +72968,16 @@
72968 data = pPage->aData;
72969 ptr = &pPage->aCellIdx[2*idx];
72970 assert( pPage->pBt->usableSize > (u32)(ptr-data) );
72971 pc = get2byte(ptr);
72972 hdr = pPage->hdrOffset;
72973 #if 0 /* Not required. Omit for efficiency */
72974 if( pc<hdr+pPage->nCell*2 ){
72975 *pRC = SQLITE_CORRUPT_BKPT;
72976 return;
72977 }
72978 #endif
72979 testcase( pc==(u32)get2byte(&data[hdr+5]) );
72980 testcase( pc+sz==pPage->pBt->usableSize );
72981 if( pc+sz > pPage->pBt->usableSize ){
72982 *pRC = SQLITE_CORRUPT_BKPT;
72983 return;
@@ -75726,11 +75744,11 @@
75744 return SQLITE_CORRUPT_BKPT;
75745 }
75746 rc = getAndInitPage(pBt, pgno, &pPage, 0, 0);
75747 if( rc ) return rc;
75748 if( (pBt->openFlags & BTREE_SINGLE)==0
75749 && sqlite3PagerPageRefcount(pPage->pDbPage) != (1 + (pgno==1))
75750 ){
75751 rc = SQLITE_CORRUPT_BKPT;
75752 goto cleardatabasepage_out;
75753 }
75754 hdr = pPage->hdrOffset;
@@ -86595,11 +86613,14 @@
86613 case SQLITE_INTEGER: {
86614 rc = sqlite3_bind_int64(pStmt, i, pValue->u.i);
86615 break;
86616 }
86617 case SQLITE_FLOAT: {
86618 assert( pValue->flags & (MEM_Real|MEM_IntReal) );
86619 rc = sqlite3_bind_double(pStmt, i,
86620 (pValue->flags & MEM_Real) ? pValue->u.r : (double)pValue->u.i
86621 );
86622 break;
86623 }
86624 case SQLITE_BLOB: {
86625 if( pValue->flags & MEM_Zero ){
86626 rc = sqlite3_bind_zeroblob(pStmt, i, pValue->u.nZero);
@@ -99823,10 +99844,13 @@
99844 }
99845 return rc;
99846 }
99847
99848
99849 /* Forward reference */
99850 static int memjrnlTruncate(sqlite3_file *pJfd, sqlite_int64 size);
99851
99852 /*
99853 ** Write data to the file.
99854 */
99855 static int memjrnlWrite(
99856 sqlite3_file *pJfd, /* The journal file into which to write */
@@ -99853,26 +99877,24 @@
99877 /* An in-memory journal file should only ever be appended to. Random
99878 ** access writes are not required. The only exception to this is when
99879 ** the in-memory journal is being used by a connection using the
99880 ** atomic-write optimization. In this case the first 28 bytes of the
99881 ** journal file may be written as part of committing the transaction. */
99882 assert( iOfst<=p->endpoint.iOffset );
99883 if( iOfst>0 && iOfst!=p->endpoint.iOffset ){
99884 memjrnlTruncate(pJfd, iOfst);
99885 }
99886 if( iOfst==0 && p->pFirst ){
99887 assert( p->nChunkSize>iAmt );
99888 memcpy((u8*)p->pFirst->zChunk, zBuf, iAmt);
99889 }else{
 
 
 
 
99890 while( nWrite>0 ){
99891 FileChunk *pChunk = p->endpoint.pChunk;
99892 int iChunkOffset = (int)(p->endpoint.iOffset%p->nChunkSize);
99893 int iSpace = MIN(nWrite, p->nChunkSize - iChunkOffset);
99894
99895 assert( pChunk!=0 || iChunkOffset==0 );
99896 if( iChunkOffset==0 ){
99897 /* New chunk is required to extend the file. */
99898 FileChunk *pNew = sqlite3_malloc(fileChunkSize(p->nChunkSize));
99899 if( !pNew ){
99900 return SQLITE_IOERR_NOMEM_BKPT;
@@ -99883,14 +99905,15 @@
99905 pChunk->pNext = pNew;
99906 }else{
99907 assert( !p->pFirst );
99908 p->pFirst = pNew;
99909 }
99910 pChunk = p->endpoint.pChunk = pNew;
99911 }
99912
99913 assert( pChunk!=0 );
99914 memcpy((u8*)pChunk->zChunk + iChunkOffset, zWrite, iSpace);
99915 zWrite += iSpace;
99916 nWrite -= iSpace;
99917 p->endpoint.iOffset += iSpace;
99918 }
99919 }
@@ -122104,12 +122127,13 @@
122127 UNUSED_PARAMETER(argc);
122128 sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
122129 sqlite3QuoteValue(&str,argv[0]);
122130 sqlite3_result_text(context, sqlite3StrAccumFinish(&str), str.nChar,
122131 SQLITE_DYNAMIC);
122132 if( str.accError!=SQLITE_OK ){
122133 sqlite3_result_null(context);
122134 sqlite3_result_error_code(context, str.accError);
122135 }
122136 }
122137
122138 /*
122139 ** The unicode() function. Return the integer unicode code-point value
@@ -165463,10 +165487,13 @@
165487 {
165488 Expr *temp1 = tokenExpr(pParse,TK_ID,yymsp[-4].minor.yy0);
165489 Expr *temp2 = tokenExpr(pParse,TK_ID,yymsp[-2].minor.yy0);
165490 Expr *temp3 = tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0);
165491 Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3);
165492 if( IN_RENAME_OBJECT ){
165493 sqlite3RenameTokenRemap(pParse, 0, temp1);
165494 }
165495 yylhsminor.yy528 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4);
165496 }
165497 yymsp[-4].minor.yy528 = yylhsminor.yy528;
165498 break;
165499 case 182: /* term ::= NULL|FLOAT|BLOB */
@@ -172333,16 +172360,20 @@
172360 ** is called immediately after installing the new callback and the return
172361 ** value from sqlite3FaultSim(0) becomes the return from
172362 ** sqlite3_test_control().
172363 */
172364 case SQLITE_TESTCTRL_FAULT_INSTALL: {
172365 /* A bug in MSVC prevents it from understanding pointers to functions
172366 ** types in the second argument to va_arg(). Work around the problem
172367 ** using a typedef.
172368 ** http://support.microsoft.com/kb/47961 <-- dead hyperlink
172369 ** Search at http://web.archive.org/ to find the 2015-03-16 archive
172370 ** of the link above to see the original text.
172371 ** sqlite3GlobalConfig.xTestCallback = va_arg(ap, int(*)(int));
172372 */
172373 typedef int(*sqlite3FaultFuncType)(int);
172374 sqlite3GlobalConfig.xTestCallback = va_arg(ap, sqlite3FaultFuncType);
172375 rc = sqlite3FaultSim(0);
172376 break;
172377 }
172378
172379 /*
@@ -172465,17 +172496,31 @@
172496 sqlite3 *db = va_arg(ap, sqlite3*);
172497 db->dbOptFlags = va_arg(ap, u32);
172498 break;
172499 }
172500
172501 /* sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, onoff, xAlt);
172502 **
172503 ** If parameter onoff is 1, subsequent calls to localtime() fail.
172504 ** If 2, then invoke xAlt() instead of localtime(). If 0, normal
172505 ** processing.
172506 **
172507 ** xAlt arguments are void pointers, but they really want to be:
172508 **
172509 ** int xAlt(const time_t*, struct tm*);
172510 **
172511 ** xAlt should write results in to struct tm object of its 2nd argument
172512 ** and return zero on success, or return non-zero on failure.
172513 */
172514 case SQLITE_TESTCTRL_LOCALTIME_FAULT: {
172515 sqlite3GlobalConfig.bLocaltimeFault = va_arg(ap, int);
172516 if( sqlite3GlobalConfig.bLocaltimeFault==2 ){
172517 typedef int(*sqlite3LocaltimeType)(const void*,void*);
172518 sqlite3GlobalConfig.xAltLocaltime = va_arg(ap, sqlite3LocaltimeType);
172519 }else{
172520 sqlite3GlobalConfig.xAltLocaltime = 0;
172521 }
172522 break;
172523 }
172524
172525 /* sqlite3_test_control(SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, sqlite3*);
172526 **
@@ -234245,11 +234290,11 @@
234290 int nArg, /* Number of args */
234291 sqlite3_value **apUnused /* Function arguments */
234292 ){
234293 assert( nArg==0 );
234294 UNUSED_PARAM2(nArg, apUnused);
234295 sqlite3_result_text(pCtx, "fts5: 2022-02-15 13:23:09 9edaeed56f2282fd4da935454178c38ab49d259aed96d4e720aae09050a53006", -1, SQLITE_TRANSIENT);
234296 }
234297
234298 /*
234299 ** Return true if zName is the extension on one of the shadow tables used
234300 ** by this module.
234301
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.38.0"
150150
#define SQLITE_VERSION_NUMBER 3038000
151
-#define SQLITE_SOURCE_ID "2022-02-10 15:40:40 85cb6014751a0572d28ebd839331d5d7a78de45c9e522adcd834a8a85746f32e"
151
+#define SQLITE_SOURCE_ID "2022-02-15 13:23:09 9edaeed56f2282fd4da935454178c38ab49d259aed96d4e720aae09050a53006"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
157157
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.38.0"
150 #define SQLITE_VERSION_NUMBER 3038000
151 #define SQLITE_SOURCE_ID "2022-02-10 15:40:40 85cb6014751a0572d28ebd839331d5d7a78de45c9e522adcd834a8a85746f32e"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.38.0"
150 #define SQLITE_VERSION_NUMBER 3038000
151 #define SQLITE_SOURCE_ID "2022-02-15 13:23:09 9edaeed56f2282fd4da935454178c38ab49d259aed96d4e720aae09050a53006"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button