Fossil SCM

Update the built-in SQLite to the latest 3.27.0 alpha. Updates to the change log.

drh 2019-01-27 19:32 trunk
Commit 5280c1ab9a054182fd3c906430bc57228cb98517ad58ee7cc348308ef2f8c745
+42 -2
--- src/shell.c
+++ src/shell.c
@@ -154,10 +154,13 @@
154154
# define access(f,m) _access((f),(m))
155155
# endif
156156
# ifndef unlink
157157
# define unlink _unlink
158158
# endif
159
+# ifndef strdup
160
+# define strdup _strdup
161
+# endif
159162
# undef popen
160163
# define popen _popen
161164
# undef pclose
162165
# define pclose _pclose
163166
#else
@@ -8683,10 +8686,11 @@
86838686
struct ShellState {
86848687
sqlite3 *db; /* The database */
86858688
u8 autoExplain; /* Automatically turn on .explain mode */
86868689
u8 autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
86878690
u8 autoEQPtest; /* autoEQP is in test mode */
8691
+ u8 autoEQPtrace; /* autoEQP is in trace mode */
86888692
u8 statsOn; /* True to display memory stats before each finalize */
86898693
u8 scanstatsOn; /* True to display scan stats before each finalize */
86908694
u8 openMode; /* SHELL_OPEN_NORMAL, _APPENDVFS, or _ZIPFILE */
86918695
u8 doXdgOpen; /* Invoke start/open/xdg-open in output_reset() */
86928696
u8 nEqpLevel; /* Depth of the EQP output graph */
@@ -8705,10 +8709,11 @@
87058709
int normalMode; /* Output mode before ".explain on" */
87068710
int writableSchema; /* True if PRAGMA writable_schema=ON */
87078711
int showHeader; /* True to show column names in List or Column mode */
87088712
int nCheck; /* Number of ".check" commands run */
87098713
unsigned shellFlgs; /* Various flags */
8714
+ sqlite3_int64 szMax; /* --maxsize argument to .open */
87108715
char *zDestTable; /* Name of destination table when MODE_Insert */
87118716
char *zTempFile; /* Temporary file that might need deleting */
87128717
char zTestcase[30]; /* Name of current test case */
87138718
char colSeparator[20]; /* Column separator character for several modes */
87148719
char rowSeparator[20]; /* Row separator character for MODE_Ascii */
@@ -11077,11 +11082,17 @@
1107711082
" Options:",
1107811083
" --preserve-rowids Include ROWID values in the output",
1107911084
" --newlines Allow unescaped newline characters in output",
1108011085
" TABLE is LIKE pattern for the tables to dump",
1108111086
".echo on|off Turn command echo on or off",
11082
- ".eqp on|off|full Enable or disable automatic EXPLAIN QUERY PLAN",
11087
+ ".eqp on|off|full|... Enable or disable automatic EXPLAIN QUERY PLAN",
11088
+ " Other Modes:",
11089
+#ifdef SQLITE_DEBUG
11090
+ " test Show raw EXPLAIN QUERY PLAN output",
11091
+ " trace Like \"full\" but also enable \"PRAGMA vdbe_trace\"",
11092
+#endif
11093
+ " trigger Like \"full\" but also show trigger bytecode",
1108311094
".excel Display the output of next command in a spreadsheet",
1108411095
".exit ?CODE? Exit this program with return-code CODE",
1108511096
".expert EXPERIMENTAL. Suggest indexes for specified queries",
1108611097
/* Because explain mode comes on automatically now, the ".explain" mode
1108711098
** is removed from the help screen. It is still supported for legacy, however */
@@ -11129,10 +11140,11 @@
1112911140
" Options:",
1113011141
" --append Use appendvfs to append database to the end of FILE",
1113111142
#ifdef SQLITE_ENABLE_DESERIALIZE
1113211143
" --deserialize Load into memory useing sqlite3_deserialize()",
1113311144
" --hexdb Load the output of \"dbtotxt\" as an in-memory database",
11145
+ " --maxsize N Maximum size for --hexdb or --deserialized database",
1113411146
#endif
1113511147
" --new Initialize FILE to an empty database",
1113611148
" --readonly Open FILE readonly",
1113711149
" --zip FILE is a ZIP archive",
1113811150
".output ?FILE? Send output to FILE or stdout if FILE is omitted",
@@ -11607,10 +11619,13 @@
1160711619
SQLITE_DESERIALIZE_RESIZEABLE |
1160811620
SQLITE_DESERIALIZE_FREEONCLOSE);
1160911621
if( rc ){
1161011622
utf8_printf(stderr, "Error: sqlite3_deserialize() returns %d\n", rc);
1161111623
}
11624
+ if( p->szMax>0 ){
11625
+ sqlite3_file_control(p->db, "main", SQLITE_FCNTL_SIZE_LIMIT, &p->szMax);
11626
+ }
1161211627
}
1161311628
#endif
1161411629
}
1161511630
}
1161611631
@@ -13936,22 +13951,34 @@
1393613951
}else
1393713952
1393813953
if( c=='e' && strncmp(azArg[0], "eqp", n)==0 ){
1393913954
if( nArg==2 ){
1394013955
p->autoEQPtest = 0;
13956
+ if( p->autoEQPtrace ){
13957
+ if( p->db ) sqlite3_exec(p->db, "PRAGMA vdbe_trace=OFF;", 0, 0, 0);
13958
+ p->autoEQPtrace = 0;
13959
+ }
1394113960
if( strcmp(azArg[1],"full")==0 ){
1394213961
p->autoEQP = AUTOEQP_full;
1394313962
}else if( strcmp(azArg[1],"trigger")==0 ){
1394413963
p->autoEQP = AUTOEQP_trigger;
13964
+#ifdef SQLITE_DEBUG
1394513965
}else if( strcmp(azArg[1],"test")==0 ){
1394613966
p->autoEQP = AUTOEQP_on;
1394713967
p->autoEQPtest = 1;
13968
+ }else if( strcmp(azArg[1],"trace")==0 ){
13969
+ p->autoEQP = AUTOEQP_full;
13970
+ p->autoEQPtrace = 1;
13971
+ open_db(p, 0);
13972
+ sqlite3_exec(p->db, "SELECT name FROM sqlite_master LIMIT 1", 0, 0, 0);
13973
+ sqlite3_exec(p->db, "PRAGMA vdbe_trace=ON;", 0, 0, 0);
13974
+#endif
1394813975
}else{
1394913976
p->autoEQP = (u8)booleanValue(azArg[1]);
1395013977
}
1395113978
}else{
13952
- raw_printf(stderr, "Usage: .eqp off|on|trigger|full\n");
13979
+ raw_printf(stderr, "Usage: .eqp off|on|trace|trigger|full\n");
1395313980
rc = 1;
1395413981
}
1395513982
}else
1395613983
1395713984
if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
@@ -14521,10 +14548,11 @@
1452114548
p->db = 0;
1452214549
p->zDbFilename = 0;
1452314550
sqlite3_free(p->zFreeOnClose);
1452414551
p->zFreeOnClose = 0;
1452514552
p->openMode = SHELL_OPEN_UNSPEC;
14553
+ p->szMax = 0;
1452614554
/* Check for command-line arguments */
1452714555
for(iName=1; iName<nArg && azArg[iName][0]=='-'; iName++){
1452814556
const char *z = azArg[iName];
1452914557
if( optionMatch(z,"new") ){
1453014558
newFlag = 1;
@@ -14539,10 +14567,12 @@
1453914567
#ifdef SQLITE_ENABLE_DESERIALIZE
1454014568
}else if( optionMatch(z, "deserialize") ){
1454114569
p->openMode = SHELL_OPEN_DESERIALIZE;
1454214570
}else if( optionMatch(z, "hexdb") ){
1454314571
p->openMode = SHELL_OPEN_HEXDB;
14572
+ }else if( optionMatch(z, "maxsize") && iName+1<nArg ){
14573
+ p->szMax = integerValue(azArg[++iName]);
1454414574
#endif /* SQLITE_ENABLE_DESERIALIZE */
1454514575
}else if( z[0]=='-' ){
1454614576
utf8_printf(stderr, "unknown option: %s\n", z);
1454714577
rc = 1;
1454814578
goto meta_command_exit;
@@ -16229,10 +16259,13 @@
1622916259
" -bail stop after hitting an error\n"
1623016260
" -batch force batch I/O\n"
1623116261
" -column set output mode to 'column'\n"
1623216262
" -cmd COMMAND run \"COMMAND\" before reading stdin\n"
1623316263
" -csv set output mode to 'csv'\n"
16264
+#if defined(SQLITE_ENABLE_DESERIALIZE)
16265
+ " -deserialize open the database using sqlite3_deserialize()\n"
16266
+#endif
1623416267
" -echo print commands before execution\n"
1623516268
" -init FILENAME read/process named file\n"
1623616269
" -[no]header turn headers on or off\n"
1623716270
#if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
1623816271
" -heap SIZE Size of heap for memsys3 or memsys5\n"
@@ -16241,10 +16274,13 @@
1624116274
" -html set output mode to HTML\n"
1624216275
" -interactive force interactive I/O\n"
1624316276
" -line set output mode to 'line'\n"
1624416277
" -list set output mode to 'list'\n"
1624516278
" -lookaside SIZE N use N entries of SZ bytes for lookaside memory\n"
16279
+#if defined(SQLITE_ENABLE_DESERIALIZE)
16280
+ " -maxsize N maximum size for a --deserialize database\n"
16281
+#endif
1624616282
" -mmap N default mmap size set to N\n"
1624716283
#ifdef SQLITE_ENABLE_MULTIPLEX
1624816284
" -multiplex enable the multiplexor VFS\n"
1624916285
#endif
1625016286
" -newline SEP set output row separator. Default: '\\n'\n"
@@ -16551,10 +16587,12 @@
1655116587
}else if( strcmp(z,"-append")==0 ){
1655216588
data.openMode = SHELL_OPEN_APPENDVFS;
1655316589
#ifdef SQLITE_ENABLE_DESERIALIZE
1655416590
}else if( strcmp(z,"-deserialize")==0 ){
1655516591
data.openMode = SHELL_OPEN_DESERIALIZE;
16592
+ }else if( strcmp(z,"-maxsize")==0 && i+1<argc ){
16593
+ data.szMax = integerValue(argv[++i]);
1655616594
#endif
1655716595
}else if( strcmp(z,"-readonly")==0 ){
1655816596
data.openMode = SHELL_OPEN_READONLY;
1655916597
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB)
1656016598
}else if( strncmp(z, "-A",2)==0 ){
@@ -16652,10 +16690,12 @@
1665216690
}else if( strcmp(z,"-append")==0 ){
1665316691
data.openMode = SHELL_OPEN_APPENDVFS;
1665416692
#ifdef SQLITE_ENABLE_DESERIALIZE
1665516693
}else if( strcmp(z,"-deserialize")==0 ){
1665616694
data.openMode = SHELL_OPEN_DESERIALIZE;
16695
+ }else if( strcmp(z,"-maxsize")==0 && i+1<argc ){
16696
+ data.szMax = integerValue(argv[++i]);
1665716697
#endif
1665816698
}else if( strcmp(z,"-readonly")==0 ){
1665916699
data.openMode = SHELL_OPEN_READONLY;
1666016700
}else if( strcmp(z,"-ascii")==0 ){
1666116701
data.mode = MODE_Ascii;
1666216702
--- src/shell.c
+++ src/shell.c
@@ -154,10 +154,13 @@
154 # define access(f,m) _access((f),(m))
155 # endif
156 # ifndef unlink
157 # define unlink _unlink
158 # endif
 
 
 
159 # undef popen
160 # define popen _popen
161 # undef pclose
162 # define pclose _pclose
163 #else
@@ -8683,10 +8686,11 @@
8683 struct ShellState {
8684 sqlite3 *db; /* The database */
8685 u8 autoExplain; /* Automatically turn on .explain mode */
8686 u8 autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
8687 u8 autoEQPtest; /* autoEQP is in test mode */
 
8688 u8 statsOn; /* True to display memory stats before each finalize */
8689 u8 scanstatsOn; /* True to display scan stats before each finalize */
8690 u8 openMode; /* SHELL_OPEN_NORMAL, _APPENDVFS, or _ZIPFILE */
8691 u8 doXdgOpen; /* Invoke start/open/xdg-open in output_reset() */
8692 u8 nEqpLevel; /* Depth of the EQP output graph */
@@ -8705,10 +8709,11 @@
8705 int normalMode; /* Output mode before ".explain on" */
8706 int writableSchema; /* True if PRAGMA writable_schema=ON */
8707 int showHeader; /* True to show column names in List or Column mode */
8708 int nCheck; /* Number of ".check" commands run */
8709 unsigned shellFlgs; /* Various flags */
 
8710 char *zDestTable; /* Name of destination table when MODE_Insert */
8711 char *zTempFile; /* Temporary file that might need deleting */
8712 char zTestcase[30]; /* Name of current test case */
8713 char colSeparator[20]; /* Column separator character for several modes */
8714 char rowSeparator[20]; /* Row separator character for MODE_Ascii */
@@ -11077,11 +11082,17 @@
11077 " Options:",
11078 " --preserve-rowids Include ROWID values in the output",
11079 " --newlines Allow unescaped newline characters in output",
11080 " TABLE is LIKE pattern for the tables to dump",
11081 ".echo on|off Turn command echo on or off",
11082 ".eqp on|off|full Enable or disable automatic EXPLAIN QUERY PLAN",
 
 
 
 
 
 
11083 ".excel Display the output of next command in a spreadsheet",
11084 ".exit ?CODE? Exit this program with return-code CODE",
11085 ".expert EXPERIMENTAL. Suggest indexes for specified queries",
11086 /* Because explain mode comes on automatically now, the ".explain" mode
11087 ** is removed from the help screen. It is still supported for legacy, however */
@@ -11129,10 +11140,11 @@
11129 " Options:",
11130 " --append Use appendvfs to append database to the end of FILE",
11131 #ifdef SQLITE_ENABLE_DESERIALIZE
11132 " --deserialize Load into memory useing sqlite3_deserialize()",
11133 " --hexdb Load the output of \"dbtotxt\" as an in-memory database",
 
11134 #endif
11135 " --new Initialize FILE to an empty database",
11136 " --readonly Open FILE readonly",
11137 " --zip FILE is a ZIP archive",
11138 ".output ?FILE? Send output to FILE or stdout if FILE is omitted",
@@ -11607,10 +11619,13 @@
11607 SQLITE_DESERIALIZE_RESIZEABLE |
11608 SQLITE_DESERIALIZE_FREEONCLOSE);
11609 if( rc ){
11610 utf8_printf(stderr, "Error: sqlite3_deserialize() returns %d\n", rc);
11611 }
 
 
 
11612 }
11613 #endif
11614 }
11615 }
11616
@@ -13936,22 +13951,34 @@
13936 }else
13937
13938 if( c=='e' && strncmp(azArg[0], "eqp", n)==0 ){
13939 if( nArg==2 ){
13940 p->autoEQPtest = 0;
 
 
 
 
13941 if( strcmp(azArg[1],"full")==0 ){
13942 p->autoEQP = AUTOEQP_full;
13943 }else if( strcmp(azArg[1],"trigger")==0 ){
13944 p->autoEQP = AUTOEQP_trigger;
 
13945 }else if( strcmp(azArg[1],"test")==0 ){
13946 p->autoEQP = AUTOEQP_on;
13947 p->autoEQPtest = 1;
 
 
 
 
 
 
 
13948 }else{
13949 p->autoEQP = (u8)booleanValue(azArg[1]);
13950 }
13951 }else{
13952 raw_printf(stderr, "Usage: .eqp off|on|trigger|full\n");
13953 rc = 1;
13954 }
13955 }else
13956
13957 if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
@@ -14521,10 +14548,11 @@
14521 p->db = 0;
14522 p->zDbFilename = 0;
14523 sqlite3_free(p->zFreeOnClose);
14524 p->zFreeOnClose = 0;
14525 p->openMode = SHELL_OPEN_UNSPEC;
 
14526 /* Check for command-line arguments */
14527 for(iName=1; iName<nArg && azArg[iName][0]=='-'; iName++){
14528 const char *z = azArg[iName];
14529 if( optionMatch(z,"new") ){
14530 newFlag = 1;
@@ -14539,10 +14567,12 @@
14539 #ifdef SQLITE_ENABLE_DESERIALIZE
14540 }else if( optionMatch(z, "deserialize") ){
14541 p->openMode = SHELL_OPEN_DESERIALIZE;
14542 }else if( optionMatch(z, "hexdb") ){
14543 p->openMode = SHELL_OPEN_HEXDB;
 
 
14544 #endif /* SQLITE_ENABLE_DESERIALIZE */
14545 }else if( z[0]=='-' ){
14546 utf8_printf(stderr, "unknown option: %s\n", z);
14547 rc = 1;
14548 goto meta_command_exit;
@@ -16229,10 +16259,13 @@
16229 " -bail stop after hitting an error\n"
16230 " -batch force batch I/O\n"
16231 " -column set output mode to 'column'\n"
16232 " -cmd COMMAND run \"COMMAND\" before reading stdin\n"
16233 " -csv set output mode to 'csv'\n"
 
 
 
16234 " -echo print commands before execution\n"
16235 " -init FILENAME read/process named file\n"
16236 " -[no]header turn headers on or off\n"
16237 #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
16238 " -heap SIZE Size of heap for memsys3 or memsys5\n"
@@ -16241,10 +16274,13 @@
16241 " -html set output mode to HTML\n"
16242 " -interactive force interactive I/O\n"
16243 " -line set output mode to 'line'\n"
16244 " -list set output mode to 'list'\n"
16245 " -lookaside SIZE N use N entries of SZ bytes for lookaside memory\n"
 
 
 
16246 " -mmap N default mmap size set to N\n"
16247 #ifdef SQLITE_ENABLE_MULTIPLEX
16248 " -multiplex enable the multiplexor VFS\n"
16249 #endif
16250 " -newline SEP set output row separator. Default: '\\n'\n"
@@ -16551,10 +16587,12 @@
16551 }else if( strcmp(z,"-append")==0 ){
16552 data.openMode = SHELL_OPEN_APPENDVFS;
16553 #ifdef SQLITE_ENABLE_DESERIALIZE
16554 }else if( strcmp(z,"-deserialize")==0 ){
16555 data.openMode = SHELL_OPEN_DESERIALIZE;
 
 
16556 #endif
16557 }else if( strcmp(z,"-readonly")==0 ){
16558 data.openMode = SHELL_OPEN_READONLY;
16559 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB)
16560 }else if( strncmp(z, "-A",2)==0 ){
@@ -16652,10 +16690,12 @@
16652 }else if( strcmp(z,"-append")==0 ){
16653 data.openMode = SHELL_OPEN_APPENDVFS;
16654 #ifdef SQLITE_ENABLE_DESERIALIZE
16655 }else if( strcmp(z,"-deserialize")==0 ){
16656 data.openMode = SHELL_OPEN_DESERIALIZE;
 
 
16657 #endif
16658 }else if( strcmp(z,"-readonly")==0 ){
16659 data.openMode = SHELL_OPEN_READONLY;
16660 }else if( strcmp(z,"-ascii")==0 ){
16661 data.mode = MODE_Ascii;
16662
--- src/shell.c
+++ src/shell.c
@@ -154,10 +154,13 @@
154 # define access(f,m) _access((f),(m))
155 # endif
156 # ifndef unlink
157 # define unlink _unlink
158 # endif
159 # ifndef strdup
160 # define strdup _strdup
161 # endif
162 # undef popen
163 # define popen _popen
164 # undef pclose
165 # define pclose _pclose
166 #else
@@ -8683,10 +8686,11 @@
8686 struct ShellState {
8687 sqlite3 *db; /* The database */
8688 u8 autoExplain; /* Automatically turn on .explain mode */
8689 u8 autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
8690 u8 autoEQPtest; /* autoEQP is in test mode */
8691 u8 autoEQPtrace; /* autoEQP is in trace mode */
8692 u8 statsOn; /* True to display memory stats before each finalize */
8693 u8 scanstatsOn; /* True to display scan stats before each finalize */
8694 u8 openMode; /* SHELL_OPEN_NORMAL, _APPENDVFS, or _ZIPFILE */
8695 u8 doXdgOpen; /* Invoke start/open/xdg-open in output_reset() */
8696 u8 nEqpLevel; /* Depth of the EQP output graph */
@@ -8705,10 +8709,11 @@
8709 int normalMode; /* Output mode before ".explain on" */
8710 int writableSchema; /* True if PRAGMA writable_schema=ON */
8711 int showHeader; /* True to show column names in List or Column mode */
8712 int nCheck; /* Number of ".check" commands run */
8713 unsigned shellFlgs; /* Various flags */
8714 sqlite3_int64 szMax; /* --maxsize argument to .open */
8715 char *zDestTable; /* Name of destination table when MODE_Insert */
8716 char *zTempFile; /* Temporary file that might need deleting */
8717 char zTestcase[30]; /* Name of current test case */
8718 char colSeparator[20]; /* Column separator character for several modes */
8719 char rowSeparator[20]; /* Row separator character for MODE_Ascii */
@@ -11077,11 +11082,17 @@
11082 " Options:",
11083 " --preserve-rowids Include ROWID values in the output",
11084 " --newlines Allow unescaped newline characters in output",
11085 " TABLE is LIKE pattern for the tables to dump",
11086 ".echo on|off Turn command echo on or off",
11087 ".eqp on|off|full|... Enable or disable automatic EXPLAIN QUERY PLAN",
11088 " Other Modes:",
11089 #ifdef SQLITE_DEBUG
11090 " test Show raw EXPLAIN QUERY PLAN output",
11091 " trace Like \"full\" but also enable \"PRAGMA vdbe_trace\"",
11092 #endif
11093 " trigger Like \"full\" but also show trigger bytecode",
11094 ".excel Display the output of next command in a spreadsheet",
11095 ".exit ?CODE? Exit this program with return-code CODE",
11096 ".expert EXPERIMENTAL. Suggest indexes for specified queries",
11097 /* Because explain mode comes on automatically now, the ".explain" mode
11098 ** is removed from the help screen. It is still supported for legacy, however */
@@ -11129,10 +11140,11 @@
11140 " Options:",
11141 " --append Use appendvfs to append database to the end of FILE",
11142 #ifdef SQLITE_ENABLE_DESERIALIZE
11143 " --deserialize Load into memory useing sqlite3_deserialize()",
11144 " --hexdb Load the output of \"dbtotxt\" as an in-memory database",
11145 " --maxsize N Maximum size for --hexdb or --deserialized database",
11146 #endif
11147 " --new Initialize FILE to an empty database",
11148 " --readonly Open FILE readonly",
11149 " --zip FILE is a ZIP archive",
11150 ".output ?FILE? Send output to FILE or stdout if FILE is omitted",
@@ -11607,10 +11619,13 @@
11619 SQLITE_DESERIALIZE_RESIZEABLE |
11620 SQLITE_DESERIALIZE_FREEONCLOSE);
11621 if( rc ){
11622 utf8_printf(stderr, "Error: sqlite3_deserialize() returns %d\n", rc);
11623 }
11624 if( p->szMax>0 ){
11625 sqlite3_file_control(p->db, "main", SQLITE_FCNTL_SIZE_LIMIT, &p->szMax);
11626 }
11627 }
11628 #endif
11629 }
11630 }
11631
@@ -13936,22 +13951,34 @@
13951 }else
13952
13953 if( c=='e' && strncmp(azArg[0], "eqp", n)==0 ){
13954 if( nArg==2 ){
13955 p->autoEQPtest = 0;
13956 if( p->autoEQPtrace ){
13957 if( p->db ) sqlite3_exec(p->db, "PRAGMA vdbe_trace=OFF;", 0, 0, 0);
13958 p->autoEQPtrace = 0;
13959 }
13960 if( strcmp(azArg[1],"full")==0 ){
13961 p->autoEQP = AUTOEQP_full;
13962 }else if( strcmp(azArg[1],"trigger")==0 ){
13963 p->autoEQP = AUTOEQP_trigger;
13964 #ifdef SQLITE_DEBUG
13965 }else if( strcmp(azArg[1],"test")==0 ){
13966 p->autoEQP = AUTOEQP_on;
13967 p->autoEQPtest = 1;
13968 }else if( strcmp(azArg[1],"trace")==0 ){
13969 p->autoEQP = AUTOEQP_full;
13970 p->autoEQPtrace = 1;
13971 open_db(p, 0);
13972 sqlite3_exec(p->db, "SELECT name FROM sqlite_master LIMIT 1", 0, 0, 0);
13973 sqlite3_exec(p->db, "PRAGMA vdbe_trace=ON;", 0, 0, 0);
13974 #endif
13975 }else{
13976 p->autoEQP = (u8)booleanValue(azArg[1]);
13977 }
13978 }else{
13979 raw_printf(stderr, "Usage: .eqp off|on|trace|trigger|full\n");
13980 rc = 1;
13981 }
13982 }else
13983
13984 if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
@@ -14521,10 +14548,11 @@
14548 p->db = 0;
14549 p->zDbFilename = 0;
14550 sqlite3_free(p->zFreeOnClose);
14551 p->zFreeOnClose = 0;
14552 p->openMode = SHELL_OPEN_UNSPEC;
14553 p->szMax = 0;
14554 /* Check for command-line arguments */
14555 for(iName=1; iName<nArg && azArg[iName][0]=='-'; iName++){
14556 const char *z = azArg[iName];
14557 if( optionMatch(z,"new") ){
14558 newFlag = 1;
@@ -14539,10 +14567,12 @@
14567 #ifdef SQLITE_ENABLE_DESERIALIZE
14568 }else if( optionMatch(z, "deserialize") ){
14569 p->openMode = SHELL_OPEN_DESERIALIZE;
14570 }else if( optionMatch(z, "hexdb") ){
14571 p->openMode = SHELL_OPEN_HEXDB;
14572 }else if( optionMatch(z, "maxsize") && iName+1<nArg ){
14573 p->szMax = integerValue(azArg[++iName]);
14574 #endif /* SQLITE_ENABLE_DESERIALIZE */
14575 }else if( z[0]=='-' ){
14576 utf8_printf(stderr, "unknown option: %s\n", z);
14577 rc = 1;
14578 goto meta_command_exit;
@@ -16229,10 +16259,13 @@
16259 " -bail stop after hitting an error\n"
16260 " -batch force batch I/O\n"
16261 " -column set output mode to 'column'\n"
16262 " -cmd COMMAND run \"COMMAND\" before reading stdin\n"
16263 " -csv set output mode to 'csv'\n"
16264 #if defined(SQLITE_ENABLE_DESERIALIZE)
16265 " -deserialize open the database using sqlite3_deserialize()\n"
16266 #endif
16267 " -echo print commands before execution\n"
16268 " -init FILENAME read/process named file\n"
16269 " -[no]header turn headers on or off\n"
16270 #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
16271 " -heap SIZE Size of heap for memsys3 or memsys5\n"
@@ -16241,10 +16274,13 @@
16274 " -html set output mode to HTML\n"
16275 " -interactive force interactive I/O\n"
16276 " -line set output mode to 'line'\n"
16277 " -list set output mode to 'list'\n"
16278 " -lookaside SIZE N use N entries of SZ bytes for lookaside memory\n"
16279 #if defined(SQLITE_ENABLE_DESERIALIZE)
16280 " -maxsize N maximum size for a --deserialize database\n"
16281 #endif
16282 " -mmap N default mmap size set to N\n"
16283 #ifdef SQLITE_ENABLE_MULTIPLEX
16284 " -multiplex enable the multiplexor VFS\n"
16285 #endif
16286 " -newline SEP set output row separator. Default: '\\n'\n"
@@ -16551,10 +16587,12 @@
16587 }else if( strcmp(z,"-append")==0 ){
16588 data.openMode = SHELL_OPEN_APPENDVFS;
16589 #ifdef SQLITE_ENABLE_DESERIALIZE
16590 }else if( strcmp(z,"-deserialize")==0 ){
16591 data.openMode = SHELL_OPEN_DESERIALIZE;
16592 }else if( strcmp(z,"-maxsize")==0 && i+1<argc ){
16593 data.szMax = integerValue(argv[++i]);
16594 #endif
16595 }else if( strcmp(z,"-readonly")==0 ){
16596 data.openMode = SHELL_OPEN_READONLY;
16597 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB)
16598 }else if( strncmp(z, "-A",2)==0 ){
@@ -16652,10 +16690,12 @@
16690 }else if( strcmp(z,"-append")==0 ){
16691 data.openMode = SHELL_OPEN_APPENDVFS;
16692 #ifdef SQLITE_ENABLE_DESERIALIZE
16693 }else if( strcmp(z,"-deserialize")==0 ){
16694 data.openMode = SHELL_OPEN_DESERIALIZE;
16695 }else if( strcmp(z,"-maxsize")==0 && i+1<argc ){
16696 data.szMax = integerValue(argv[++i]);
16697 #endif
16698 }else if( strcmp(z,"-readonly")==0 ){
16699 data.openMode = SHELL_OPEN_READONLY;
16700 }else if( strcmp(z,"-ascii")==0 ){
16701 data.mode = MODE_Ascii;
16702
+433 -167
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1162,11 +1162,11 @@
11621162
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11631163
** [sqlite_version()] and [sqlite_source_id()].
11641164
*/
11651165
#define SQLITE_VERSION "3.27.0"
11661166
#define SQLITE_VERSION_NUMBER 3027000
1167
-#define SQLITE_SOURCE_ID "2019-01-21 17:57:31 505ed9a47825240979338a24044559613fbbd2a7850bdff70c7164da054ec63d"
1167
+#define SQLITE_SOURCE_ID "2019-01-27 02:45:32 9cf8ebd141aa2eb661d457624c76433bd9e4abfdef04aa52e28bc169172calt1"
11681168
11691169
/*
11701170
** CAPI3REF: Run-Time Library Version Numbers
11711171
** KEYWORDS: sqlite3_version sqlite3_sourceid
11721172
**
@@ -1860,10 +1860,19 @@
18601860
** current transaction. This hint is not guaranteed to be accurate but it
18611861
** is often close. The underlying VFS might choose to preallocate database
18621862
** file space based on this hint in order to help writes to the database
18631863
** file run faster.
18641864
**
1865
+** <li>[[SQLITE_FCNTL_SIZE_LIMIT]]
1866
+** The [SQLITE_FCNTL_SIZE_LIMIT] opcode is used by in-memory VFS that
1867
+** implements [sqlite3_deserialize()] to set an upper bound on the size
1868
+** of the in-memory database. The argument is a pointer to a [sqlite3_int64].
1869
+** If the integer pointed to is negative, then it is filled in with the
1870
+** current limit. Otherwise the limit is set to the larger of the value
1871
+** of the integer pointed to and the current database size. The integer
1872
+** pointed to is set to the new limit.
1873
+**
18651874
** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]
18661875
** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
18671876
** extends and truncates the database file in chunks of a size specified
18681877
** by the user. The fourth argument to [sqlite3_file_control()] should
18691878
** point to an integer (type int) containing the new chunk-size to use
@@ -2168,10 +2177,11 @@
21682177
#define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 31
21692178
#define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32
21702179
#define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33
21712180
#define SQLITE_FCNTL_LOCK_TIMEOUT 34
21722181
#define SQLITE_FCNTL_DATA_VERSION 35
2182
+#define SQLITE_FCNTL_SIZE_LIMIT 36
21732183
21742184
/* deprecated names */
21752185
#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
21762186
#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
21772187
#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -12272,16 +12282,12 @@
1227212282
** should be greater than or equal to zero and smaller than the value
1227312283
** output by xInstCount().
1227412284
**
1227512285
** Usually, output parameter *piPhrase is set to the phrase number, *piCol
1227612286
** to the column in which it occurs and *piOff the token offset of the
12277
-** first token of the phrase. The exception is if the table was created
12278
-** with the offsets=0 option specified. In this case *piOff is always
12279
-** set to -1.
12280
-**
12281
-** Returns SQLITE_OK if successful, or an error code (i.e. SQLITE_NOMEM)
12282
-** if an error occurs.
12287
+** first token of the phrase. Returns SQLITE_OK if successful, or an error
12288
+** code (i.e. SQLITE_NOMEM) if an error occurs.
1228312289
**
1228412290
** This API can be quite slow if used with an FTS5 table created with the
1228512291
** "detail=none" or "detail=column" option.
1228612292
**
1228712293
** xRowid:
@@ -46564,16 +46570,22 @@
4656446570
4656546571
/* An open file */
4656646572
struct MemFile {
4656746573
sqlite3_file base; /* IO methods */
4656846574
sqlite3_int64 sz; /* Size of the file */
46569
- sqlite3_int64 szMax; /* Space allocated to aData */
46575
+ sqlite3_int64 szAlloc; /* Space allocated to aData */
46576
+ sqlite3_int64 szMax; /* Maximum allowed size of the file */
4657046577
unsigned char *aData; /* content of the file */
4657146578
int nMmap; /* Number of memory mapped pages */
4657246579
unsigned mFlags; /* Flags */
4657346580
int eLock; /* Most recent lock against this file */
4657446581
};
46582
+
46583
+/* The default maximum size of an in-memory database */
46584
+#ifndef SQLITE_MEMDB_DEFAULT_MAXSIZE
46585
+# define SQLITE_MEMDB_DEFAULT_MAXSIZE 1073741824
46586
+#endif
4657546587
4657646588
/*
4657746589
** Methods for MemFile
4657846590
*/
4657946591
static int memdbClose(sqlite3_file*);
@@ -46690,14 +46702,19 @@
4669046702
static int memdbEnlarge(MemFile *p, sqlite3_int64 newSz){
4669146703
unsigned char *pNew;
4669246704
if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || p->nMmap>0 ){
4669346705
return SQLITE_FULL;
4669446706
}
46707
+ if( newSz>p->szMax ){
46708
+ return SQLITE_FULL;
46709
+ }
46710
+ newSz *= 2;
46711
+ if( newSz>p->szMax ) newSz = p->szMax;
4669546712
pNew = sqlite3_realloc64(p->aData, newSz);
4669646713
if( pNew==0 ) return SQLITE_NOMEM;
4669746714
p->aData = pNew;
46698
- p->szMax = newSz;
46715
+ p->szAlloc = newSz;
4669946716
return SQLITE_OK;
4670046717
}
4670146718
4670246719
/*
4670346720
** Write data to an memdb-file.
@@ -46707,14 +46724,15 @@
4670746724
const void *z,
4670846725
int iAmt,
4670946726
sqlite_int64 iOfst
4671046727
){
4671146728
MemFile *p = (MemFile *)pFile;
46729
+ if( NEVER(p->mFlags & SQLITE_DESERIALIZE_READONLY) ) return SQLITE_READONLY;
4671246730
if( iOfst+iAmt>p->sz ){
4671346731
int rc;
46714
- if( iOfst+iAmt>p->szMax
46715
- && (rc = memdbEnlarge(p, (iOfst+iAmt)*2))!=SQLITE_OK
46732
+ if( iOfst+iAmt>p->szAlloc
46733
+ && (rc = memdbEnlarge(p, iOfst+iAmt))!=SQLITE_OK
4671646734
){
4671746735
return rc;
4671846736
}
4671946737
if( iOfst>p->sz ) memset(p->aData+p->sz, 0, iOfst-p->sz);
4672046738
p->sz = iOfst+iAmt;
@@ -46756,10 +46774,15 @@
4675646774
/*
4675746775
** Lock an memdb-file.
4675846776
*/
4675946777
static int memdbLock(sqlite3_file *pFile, int eLock){
4676046778
MemFile *p = (MemFile *)pFile;
46779
+ if( eLock>SQLITE_LOCK_SHARED
46780
+ && (p->mFlags & SQLITE_DESERIALIZE_READONLY)!=0
46781
+ ){
46782
+ return SQLITE_READONLY;
46783
+ }
4676146784
p->eLock = eLock;
4676246785
return SQLITE_OK;
4676346786
}
4676446787
4676546788
#if 0 /* Never used because memdbAccess() always returns false */
@@ -46779,10 +46802,23 @@
4677946802
MemFile *p = (MemFile *)pFile;
4678046803
int rc = SQLITE_NOTFOUND;
4678146804
if( op==SQLITE_FCNTL_VFSNAME ){
4678246805
*(char**)pArg = sqlite3_mprintf("memdb(%p,%lld)", p->aData, p->sz);
4678346806
rc = SQLITE_OK;
46807
+ }
46808
+ if( op==SQLITE_FCNTL_SIZE_LIMIT ){
46809
+ sqlite3_int64 iLimit = *(sqlite3_int64*)pArg;
46810
+ if( iLimit<p->sz ){
46811
+ if( iLimit<0 ){
46812
+ iLimit = p->szMax;
46813
+ }else{
46814
+ iLimit = p->sz;
46815
+ }
46816
+ }
46817
+ p->szMax = iLimit;
46818
+ *(sqlite3_int64*)pArg = iLimit;
46819
+ rc = SQLITE_OK;
4678446820
}
4678546821
return rc;
4678646822
}
4678746823
4678846824
#if 0 /* Not used because of SQLITE_IOCAP_POWERSAFE_OVERWRITE */
@@ -46810,12 +46846,17 @@
4681046846
sqlite3_int64 iOfst,
4681146847
int iAmt,
4681246848
void **pp
4681346849
){
4681446850
MemFile *p = (MemFile *)pFile;
46815
- p->nMmap++;
46816
- *pp = (void*)(p->aData + iOfst);
46851
+ if( iOfst+iAmt>p->sz ){
46852
+ assert( CORRUPT_DB );
46853
+ *pp = 0;
46854
+ }else{
46855
+ p->nMmap++;
46856
+ *pp = (void*)(p->aData + iOfst);
46857
+ }
4681746858
return SQLITE_OK;
4681846859
}
4681946860
4682046861
/* Release a memory-mapped page */
4682146862
static int memdbUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){
@@ -46841,10 +46882,11 @@
4684146882
memset(p, 0, sizeof(*p));
4684246883
p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE;
4684346884
assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */
4684446885
*pOutFlags = flags | SQLITE_OPEN_MEMORY;
4684546886
p->base.pMethods = &memdb_io_methods;
46887
+ p->szMax = SQLITE_MEMDB_DEFAULT_MAXSIZE;
4684646888
return SQLITE_OK;
4684746889
}
4684846890
4684946891
#if 0 /* Only used to delete rollback journals, master journals, and WAL
4685046892
** files, none of which exist in memdb. So this routine is never used */
@@ -47090,11 +47132,15 @@
4709047132
if( p==0 ){
4709147133
rc = SQLITE_ERROR;
4709247134
}else{
4709347135
p->aData = pData;
4709447136
p->sz = szDb;
47137
+ p->szAlloc = szBuf;
4709547138
p->szMax = szBuf;
47139
+ if( p->szMax<SQLITE_MEMDB_DEFAULT_MAXSIZE ){
47140
+ p->szMax = SQLITE_MEMDB_DEFAULT_MAXSIZE;
47141
+ }
4709647142
p->mFlags = mFlags;
4709747143
rc = SQLITE_OK;
4709847144
}
4709947145
4710047146
end_deserialize:
@@ -63737,15 +63783,16 @@
6373763783
){
6373863784
int rc; /* Status code */
6373963785
UnpackedRecord *pIdxKey; /* Unpacked index key */
6374063786
6374163787
if( pKey ){
63788
+ KeyInfo *pKeyInfo = pCur->pKeyInfo;
6374263789
assert( nKey==(i64)(int)nKey );
63743
- pIdxKey = sqlite3VdbeAllocUnpackedRecord(pCur->pKeyInfo);
63790
+ pIdxKey = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
6374463791
if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT;
63745
- sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey, pIdxKey);
63746
- if( pIdxKey->nField==0 ){
63792
+ sqlite3VdbeRecordUnpack(pKeyInfo, (int)nKey, pKey, pIdxKey);
63793
+ if( pIdxKey->nField==0 || pIdxKey->nField>pKeyInfo->nAllField ){
6374763794
rc = SQLITE_CORRUPT_BKPT;
6374863795
goto moveto_done;
6374963796
}
6375063797
}else{
6375163798
pIdxKey = 0;
@@ -68408,11 +68455,11 @@
6840868455
nCell = (int)pCur->info.nKey;
6840968456
testcase( nCell<0 ); /* True if key size is 2^32 or more */
6841068457
testcase( nCell==0 ); /* Invalid key size: 0x80 0x80 0x00 */
6841168458
testcase( nCell==1 ); /* Invalid key size: 0x80 0x80 0x01 */
6841268459
testcase( nCell==2 ); /* Minimum legal index key size */
68413
- if( nCell<2 ){
68460
+ if( nCell<2 || nCell/pCur->pBt->usableSize>pCur->pBt->nPage ){
6841468461
rc = SQLITE_CORRUPT_PAGE(pPage);
6841568462
goto moveto_finish;
6841668463
}
6841768464
pCellKey = sqlite3Malloc( nCell+18 );
6841868465
if( pCellKey==0 ){
@@ -69042,11 +69089,11 @@
6904269089
*ppPage = 0;
6904369090
}
6904469091
TRACE(("ALLOCATE: %d from end of file\n", *pPgno));
6904569092
}
6904669093
69047
- assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
69094
+ assert( CORRUPT_DB || *pPgno!=PENDING_BYTE_PAGE(pBt) );
6904869095
6904969096
end_allocate_page:
6905069097
releasePage(pTrunk);
6905169098
releasePage(pPrevTrunk);
6905269099
assert( rc!=SQLITE_OK || sqlite3PagerPageRefcount((*ppPage)->pDbPage)<=1 );
@@ -69626,20 +69673,85 @@
6962669673
}
6962769674
#endif
6962869675
}
6962969676
}
6963069677
69678
+/*
69679
+** The following parameters determine how many adjacent pages get involved
69680
+** in a balancing operation. NN is the number of neighbors on either side
69681
+** of the page that participate in the balancing operation. NB is the
69682
+** total number of pages that participate, including the target page and
69683
+** NN neighbors on either side.
69684
+**
69685
+** The minimum value of NN is 1 (of course). Increasing NN above 1
69686
+** (to 2 or 3) gives a modest improvement in SELECT and DELETE performance
69687
+** in exchange for a larger degradation in INSERT and UPDATE performance.
69688
+** The value of NN appears to give the best results overall.
69689
+**
69690
+** (Later:) The description above makes it seem as if these values are
69691
+** tunable - as if you could change them and recompile and it would all work.
69692
+** But that is unlikely. NB has been 3 since the inception of SQLite and
69693
+** we have never tested any other value.
69694
+*/
69695
+#define NN 1 /* Number of neighbors on either side of pPage */
69696
+#define NB 3 /* (NN*2+1): Total pages involved in the balance */
69697
+
6963169698
/*
6963269699
** A CellArray object contains a cache of pointers and sizes for a
6963369700
** consecutive sequence of cells that might be held on multiple pages.
69701
+**
69702
+** The cells in this array are the divider cell or cells from the pParent
69703
+** page plus up to three child pages. There are a total of nCell cells.
69704
+**
69705
+** pRef is a pointer to one of the pages that contributes cells. This is
69706
+** used to access information such as MemPage.intKey and MemPage.pBt->pageSize
69707
+** which should be common to all pages that contribute cells to this array.
69708
+**
69709
+** apCell[] and szCell[] hold, respectively, pointers to the start of each
69710
+** cell and the size of each cell. Some of the apCell[] pointers might refer
69711
+** to overflow cells. In other words, some apCel[] pointers might not point
69712
+** to content area of the pages.
69713
+**
69714
+** A szCell[] of zero means the size of that cell has not yet been computed.
69715
+**
69716
+** The cells come from as many as four different pages:
69717
+**
69718
+** -----------
69719
+** | Parent |
69720
+** -----------
69721
+** / | \
69722
+** / | \
69723
+** --------- --------- ---------
69724
+** |Child-1| |Child-2| |Child-3|
69725
+** --------- --------- ---------
69726
+**
69727
+** The order of cells is in the array is:
69728
+**
69729
+** 1. All cells from Child-1 in order
69730
+** 2. The first divider cell from Parent
69731
+** 3. All cells from Child-2 in order
69732
+** 4. The second divider cell from Parent
69733
+** 5. All cells from Child-3 in order
69734
+**
69735
+** The apEnd[] array holds pointer to the end of page for Child-1, the
69736
+** Parent, Child-2, the Parent (again), and Child-3. The ixNx[] array
69737
+** holds the number of cells contained in each of these 5 stages, and
69738
+** all stages to the left. Hence:
69739
+** ixNx[0] = Number of cells in Child-1.
69740
+** ixNx[1] = Number of cells in Child-1 plus 1 for first divider.
69741
+** ixNx[2] = Number of cells in Child-1 and Child-2 + 1 for 1st divider.
69742
+** ixNx[3] = Number of cells in Child-1 and Child-2 + both divider cells
69743
+** ixNx[4] = Total number of cells.
6963469744
*/
6963569745
typedef struct CellArray CellArray;
6963669746
struct CellArray {
6963769747
int nCell; /* Number of cells in apCell[] */
6963869748
MemPage *pRef; /* Reference page */
6963969749
u8 **apCell; /* All cells begin balanced */
6964069750
u16 *szCell; /* Local size of all cells in apCell[] */
69751
+ u8 *apEnd[NB*2]; /* MemPage.aDataEnd values */
69752
+ int ixNx[NB*2]; /* Index of at which we move to the next apEnd[] */
6964169753
};
6964269754
6964369755
/*
6964469756
** Make sure the cell sizes at idx, idx+1, ..., idx+N-1 have been
6964569757
** computed.
@@ -69686,41 +69798,62 @@
6968669798
**
6968769799
** The MemPage.nFree field is invalidated by this function. It is the
6968869800
** responsibility of the caller to set it correctly.
6968969801
*/
6969069802
static int rebuildPage(
69691
- MemPage *pPg, /* Edit this page */
69803
+ CellArray *pCArray, /* Content to be added to page pPg */
69804
+ int iFirst, /* First cell in pCArray to use */
6969269805
int nCell, /* Final number of cells on page */
69693
- u8 **apCell, /* Array of cells */
69694
- u16 *szCell /* Array of cell sizes */
69806
+ MemPage *pPg /* The page to be reconstructed */
6969569807
){
6969669808
const int hdr = pPg->hdrOffset; /* Offset of header on pPg */
6969769809
u8 * const aData = pPg->aData; /* Pointer to data for pPg */
6969869810
const int usableSize = pPg->pBt->usableSize;
6969969811
u8 * const pEnd = &aData[usableSize];
69700
- int i;
69812
+ int i = iFirst; /* Which cell to copy from pCArray*/
69813
+ int j; /* Start of cell content area */
69814
+ int iEnd = i+nCell; /* Loop terminator */
6970169815
u8 *pCellptr = pPg->aCellIdx;
6970269816
u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
6970369817
u8 *pData;
69818
+ int k; /* Current slot in pCArray->apEnd[] */
69819
+ u8 *pSrcEnd; /* Current pCArray->apEnd[k] value */
6970469820
69705
- i = get2byte(&aData[hdr+5]);
69706
- memcpy(&pTmp[i], &aData[i], usableSize - i);
69821
+ assert( i<iEnd );
69822
+ j = get2byte(&aData[hdr+5]);
69823
+ memcpy(&pTmp[j], &aData[j], usableSize - j);
69824
+
69825
+ for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
69826
+ pSrcEnd = pCArray->apEnd[k];
6970769827
6970869828
pData = pEnd;
69709
- for(i=0; i<nCell; i++){
69710
- u8 *pCell = apCell[i];
69829
+ while( 1/*exit by break*/ ){
69830
+ u8 *pCell = pCArray->apCell[i];
69831
+ u16 sz = pCArray->szCell[i];
69832
+ assert( sz>0 );
6971169833
if( SQLITE_WITHIN(pCell,aData,pEnd) ){
69712
- if( ((uptr)(pCell+szCell[i]))>(uptr)pEnd ) return SQLITE_CORRUPT_BKPT;
69834
+ if( ((uptr)(pCell+sz))>(uptr)pEnd ) return SQLITE_CORRUPT_BKPT;
6971369835
pCell = &pTmp[pCell - aData];
69836
+ }else if( (uptr)(pCell+sz)>(uptr)pSrcEnd
69837
+ && (uptr)(pCell)<(uptr)pSrcEnd
69838
+ ){
69839
+ return SQLITE_CORRUPT_BKPT;
6971469840
}
69715
- pData -= szCell[i];
69841
+
69842
+ pData -= sz;
6971669843
put2byte(pCellptr, (pData - aData));
6971769844
pCellptr += 2;
6971869845
if( pData < pCellptr ) return SQLITE_CORRUPT_BKPT;
69719
- memcpy(pData, pCell, szCell[i]);
69720
- assert( szCell[i]==pPg->xCellSize(pPg, pCell) || CORRUPT_DB );
69721
- testcase( szCell[i]!=pPg->xCellSize(pPg,pCell) );
69846
+ memcpy(pData, pCell, sz);
69847
+ assert( sz==pPg->xCellSize(pPg, pCell) || CORRUPT_DB );
69848
+ testcase( sz!=pPg->xCellSize(pPg,pCell) );
69849
+ i++;
69850
+ if( i>=iEnd ) break;
69851
+ if( pCArray->ixNx[k]<=i ){
69852
+ k++;
69853
+ pSrcEnd = pCArray->apEnd[k];
69854
+ }
6972269855
}
6972369856
6972469857
/* The pPg->nFree field is now set incorrectly. The caller will fix it. */
6972569858
pPg->nCell = nCell;
6972669859
pPg->nOverflow = 0;
@@ -69731,16 +69864,15 @@
6973169864
aData[hdr+7] = 0x00;
6973269865
return SQLITE_OK;
6973369866
}
6973469867
6973569868
/*
69736
-** Array apCell[] contains nCell pointers to b-tree cells. Array szCell
69737
-** contains the size in bytes of each such cell. This function attempts to
69738
-** add the cells stored in the array to page pPg. If it cannot (because
69739
-** the page needs to be defragmented before the cells will fit), non-zero
69740
-** is returned. Otherwise, if the cells are added successfully, zero is
69741
-** returned.
69869
+** The pCArray objects contains pointers to b-tree cells and the cell sizes.
69870
+** This function attempts to add the cells stored in the array to page pPg.
69871
+** If it cannot (because the page needs to be defragmented before the cells
69872
+** will fit), non-zero is returned. Otherwise, if the cells are added
69873
+** successfully, zero is returned.
6974269874
**
6974369875
** Argument pCellptr points to the first entry in the cell-pointer array
6974469876
** (part of page pPg) to populate. After cell apCell[0] is written to the
6974569877
** page body, a 16-bit offset is written to pCellptr. And so on, for each
6974669878
** cell in the array. It is the responsibility of the caller to ensure
@@ -69758,22 +69890,27 @@
6975869890
** cells in apCell[], then the cells do not fit and non-zero is returned.
6975969891
*/
6976069892
static int pageInsertArray(
6976169893
MemPage *pPg, /* Page to add cells to */
6976269894
u8 *pBegin, /* End of cell-pointer array */
69763
- u8 **ppData, /* IN/OUT: Page content -area pointer */
69895
+ u8 **ppData, /* IN/OUT: Page content-area pointer */
6976469896
u8 *pCellptr, /* Pointer to cell-pointer area */
6976569897
int iFirst, /* Index of first cell to add */
6976669898
int nCell, /* Number of cells to add to pPg */
6976769899
CellArray *pCArray /* Array of cells */
6976869900
){
69769
- int i;
69770
- u8 *aData = pPg->aData;
69771
- u8 *pData = *ppData;
69772
- int iEnd = iFirst + nCell;
69901
+ int i = iFirst; /* Loop counter - cell index to insert */
69902
+ u8 *aData = pPg->aData; /* Complete page */
69903
+ u8 *pData = *ppData; /* Content area. A subset of aData[] */
69904
+ int iEnd = iFirst + nCell; /* End of loop. One past last cell to ins */
69905
+ int k; /* Current slot in pCArray->apEnd[] */
69906
+ u8 *pEnd; /* Maximum extent of cell data */
6977369907
assert( CORRUPT_DB || pPg->hdrOffset==0 ); /* Never called on page 1 */
69774
- for(i=iFirst; i<iEnd; i++){
69908
+ if( iEnd<=iFirst ) return 0;
69909
+ for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
69910
+ pEnd = pCArray->apEnd[k];
69911
+ while( 1 /*Exit by break*/ ){
6977569912
int sz, rc;
6977669913
u8 *pSlot;
6977769914
sz = cachedCellSize(pCArray, i);
6977869915
if( (aData[1]==0 && aData[2]==0) || (pSlot = pageFindSlot(pPg,sz,&rc))==0 ){
6977969916
if( (pData - pBegin)<sz ) return 1;
@@ -69784,24 +69921,37 @@
6978469921
** database. But they might for a corrupt database. Hence use memmove()
6978569922
** since memcpy() sends SIGABORT with overlapping buffers on OpenBSD */
6978669923
assert( (pSlot+sz)<=pCArray->apCell[i]
6978769924
|| pSlot>=(pCArray->apCell[i]+sz)
6978869925
|| CORRUPT_DB );
69926
+ if( (uptr)(pCArray->apCell[i]+sz)>(uptr)pEnd
69927
+ && (uptr)(pCArray->apCell[i])<(uptr)pEnd
69928
+ ){
69929
+ assert( CORRUPT_DB );
69930
+ (void)SQLITE_CORRUPT_BKPT;
69931
+ return 1;
69932
+ }
6978969933
memmove(pSlot, pCArray->apCell[i], sz);
6979069934
put2byte(pCellptr, (pSlot - aData));
6979169935
pCellptr += 2;
69936
+ i++;
69937
+ if( i>=iEnd ) break;
69938
+ if( pCArray->ixNx[k]<=i ){
69939
+ k++;
69940
+ pEnd = pCArray->apEnd[k];
69941
+ }
6979269942
}
6979369943
*ppData = pData;
6979469944
return 0;
6979569945
}
6979669946
6979769947
/*
69798
-** Array apCell[] contains nCell pointers to b-tree cells. Array szCell
69799
-** contains the size in bytes of each such cell. This function adds the
69800
-** space associated with each cell in the array that is currently stored
69801
-** within the body of pPg to the pPg free-list. The cell-pointers and other
69802
-** fields of the page are not updated.
69948
+** The pCArray object contains pointers to b-tree cells and their sizes.
69949
+**
69950
+** This function adds the space associated with each cell in the array
69951
+** that is currently stored within the body of pPg to the pPg free-list.
69952
+** The cell-pointers and other fields of the page are not updated.
6980369953
**
6980469954
** This function returns the total number of cells added to the free-list.
6980569955
*/
6980669956
static int pageFreeArray(
6980769957
MemPage *pPg, /* Page to edit */
@@ -69847,13 +69997,13 @@
6984769997
}
6984869998
return nRet;
6984969999
}
6985070000
6985170001
/*
69852
-** apCell[] and szCell[] contains pointers to and sizes of all cells in the
69853
-** pages being balanced. The current page, pPg, has pPg->nCell cells starting
69854
-** with apCell[iOld]. After balancing, this page should hold nNew cells
70002
+** pCArray contains pointers to and sizes of all cells in the pages being
70003
+** balanced. The current page, pPg, has pPg->nCell cells starting with
70004
+** pCArray->apCell[iOld]. After balancing, this page should hold nNew cells
6985570005
** starting at apCell[iNew].
6985670006
**
6985770007
** This routine makes the necessary adjustments to pPg so that it contains
6985870008
** the correct cells after being balanced.
6985970009
**
@@ -69949,27 +70099,12 @@
6994970099
6995070100
return SQLITE_OK;
6995170101
editpage_fail:
6995270102
/* Unable to edit this page. Rebuild it from scratch instead. */
6995370103
populateCellCache(pCArray, iNew, nNew);
69954
- return rebuildPage(pPg, nNew, &pCArray->apCell[iNew], &pCArray->szCell[iNew]);
69955
-}
69956
-
69957
-/*
69958
-** The following parameters determine how many adjacent pages get involved
69959
-** in a balancing operation. NN is the number of neighbors on either side
69960
-** of the page that participate in the balancing operation. NB is the
69961
-** total number of pages that participate, including the target page and
69962
-** NN neighbors on either side.
69963
-**
69964
-** The minimum value of NN is 1 (of course). Increasing NN above 1
69965
-** (to 2 or 3) gives a modest improvement in SELECT and DELETE performance
69966
-** in exchange for a larger degradation in INSERT and UPDATE performance.
69967
-** The value of NN appears to give the best results overall.
69968
-*/
69969
-#define NN 1 /* Number of neighbors on either side of pPage */
69970
-#define NB (NN*2+1) /* Total pages involved in the balance */
70104
+ return rebuildPage(pCArray, iNew, nNew, pPg);
70105
+}
6997170106
6997270107
6997370108
#ifndef SQLITE_OMIT_QUICKBALANCE
6997470109
/*
6997570110
** This version of balance() handles the common special case where
@@ -70016,16 +70151,26 @@
7001670151
7001770152
u8 *pOut = &pSpace[4];
7001870153
u8 *pCell = pPage->apOvfl[0];
7001970154
u16 szCell = pPage->xCellSize(pPage, pCell);
7002070155
u8 *pStop;
70156
+ CellArray b;
7002170157
7002270158
assert( sqlite3PagerIswriteable(pNew->pDbPage) );
70023
- assert( pPage->aData[0]==(PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF) );
70159
+ assert( CORRUPT_DB || pPage->aData[0]==(PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF) );
7002470160
zeroPage(pNew, PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF);
70025
- rc = rebuildPage(pNew, 1, &pCell, &szCell);
70026
- if( NEVER(rc) ) return rc;
70161
+ b.nCell = 1;
70162
+ b.pRef = pPage;
70163
+ b.apCell = &pCell;
70164
+ b.szCell = &szCell;
70165
+ b.apEnd[0] = pPage->aDataEnd;
70166
+ b.ixNx[0] = 2;
70167
+ rc = rebuildPage(&b, 0, 1, pNew);
70168
+ if( NEVER(rc) ){
70169
+ releasePage(pNew);
70170
+ return rc;
70171
+ }
7002770172
pNew->nFree = pBt->usableSize - pNew->cellOffset - 2 - szCell;
7002870173
7002970174
/* If this is an auto-vacuum database, update the pointer map
7003070175
** with entries for the new page, and any pointer from the
7003170176
** cell on the page to an overflow page. If either of these
@@ -70501,10 +70646,14 @@
7050170646
**
7050270647
*/
7050370648
usableSpace = pBt->usableSize - 12 + leafCorrection;
7050470649
for(i=0; i<nOld; i++){
7050570650
MemPage *p = apOld[i];
70651
+ b.apEnd[i*2] = p->aDataEnd;
70652
+ b.apEnd[i*2+1] = pParent->aDataEnd;
70653
+ b.ixNx[i*2] = cntOld[i];
70654
+ b.ixNx[i*2+1] = cntOld[i]+1;
7050670655
szNew[i] = usableSpace - p->nFree;
7050770656
for(j=0; j<p->nOverflow; j++){
7050870657
szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]);
7050970658
}
7051070659
cntNew[i] = cntOld[i];
@@ -71182,11 +71331,15 @@
7118271331
iAmt = nData;
7118371332
}
7118471333
if( memcmp(pDest, ((u8*)pX->pData) + iOffset, iAmt)!=0 ){
7118571334
int rc = sqlite3PagerWrite(pPage->pDbPage);
7118671335
if( rc ) return rc;
71187
- memcpy(pDest, ((u8*)pX->pData) + iOffset, iAmt);
71336
+ /* In a corrupt database, it is possible for the source and destination
71337
+ ** buffers to overlap. This is harmless since the database is already
71338
+ ** corrupt but it does cause valgrind and ASAN warnings. So use
71339
+ ** memmove(). */
71340
+ memmove(pDest, ((u8*)pX->pData) + iOffset, iAmt);
7118871341
}
7118971342
}
7119071343
return SQLITE_OK;
7119171344
}
7119271345
@@ -71596,10 +71749,11 @@
7159671749
** from the internal node. The 'previous' entry is used for this instead
7159771750
** of the 'next' entry, as the previous entry is always a part of the
7159871751
** sub-tree headed by the child page of the cell being deleted. This makes
7159971752
** balancing the tree following the delete operation easier. */
7160071753
if( !pPage->leaf ){
71754
+ pCur->skipNext = 0;
7160171755
rc = sqlite3BtreePrevious(pCur, 0);
7160271756
assert( rc!=SQLITE_DONE );
7160371757
if( rc ) return rc;
7160471758
}
7160571759
@@ -74199,11 +74353,11 @@
7419974353
**
7420074354
** Return SQLITE_OK on success or an error code (probably SQLITE_NOMEM)
7420174355
** if unable to complete the resizing.
7420274356
*/
7420374357
SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize(Mem *pMem, int szNew){
74204
- assert( szNew>0 );
74358
+ assert( CORRUPT_DB || szNew>0 );
7420574359
assert( (pMem->flags & MEM_Dyn)==0 || pMem->szMalloc==0 );
7420674360
if( pMem->szMalloc<szNew ){
7420774361
return sqlite3VdbeMemGrow(pMem, szNew, 0);
7420874362
}
7420974363
assert( (pMem->flags & MEM_Dyn)==0 );
@@ -75486,13 +75640,15 @@
7548675640
else if( op==TK_FUNCTION && pCtx!=0 ){
7548775641
rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx);
7548875642
}
7548975643
#endif
7549075644
else if( op==TK_TRUEFALSE ){
75491
- pVal = valueNew(db, pCtx);
75492
- pVal->flags = MEM_Int;
75493
- pVal->u.i = pExpr->u.zToken[4]==0;
75645
+ pVal = valueNew(db, pCtx);
75646
+ if( pVal ){
75647
+ pVal->flags = MEM_Int;
75648
+ pVal->u.i = pExpr->u.zToken[4]==0;
75649
+ }
7549475650
}
7549575651
7549675652
*ppVal = pVal;
7549775653
return rc;
7549875654
@@ -76483,11 +76639,11 @@
7648376639
while( (pOp = opIterNext(&sIter))!=0 ){
7648476640
int opcode = pOp->opcode;
7648576641
if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename
7648676642
|| opcode==OP_VDestroy
7648776643
|| ((opcode==OP_Halt || opcode==OP_HaltIfNull)
76488
- && ((pOp->p1&0xff)==SQLITE_CONSTRAINT && pOp->p2==OE_Abort))
76644
+ && ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
7648976645
){
7649076646
hasAbort = 1;
7649176647
break;
7649276648
}
7649376649
if( opcode==OP_CreateBtree && pOp->p3==BTREE_INTKEY ) hasCreateTable = 1;
@@ -79639,11 +79795,11 @@
7963979795
int nKey, /* Size of the binary record */
7964079796
const void *pKey, /* The binary record */
7964179797
UnpackedRecord *p /* Populate this structure before returning. */
7964279798
){
7964379799
const unsigned char *aKey = (const unsigned char *)pKey;
79644
- int d;
79800
+ u32 d;
7964579801
u32 idx; /* Offset in aKey[] to read from */
7964679802
u16 u; /* Unsigned loop counter */
7964779803
u32 szHdr;
7964879804
Mem *pMem = p->aMem;
7964979805
@@ -79650,11 +79806,11 @@
7965079806
p->default_rc = 0;
7965179807
assert( EIGHT_BYTE_ALIGNMENT(pMem) );
7965279808
idx = getVarint32(aKey, szHdr);
7965379809
d = szHdr;
7965479810
u = 0;
79655
- while( idx<szHdr && d<=nKey ){
79811
+ while( idx<szHdr && d<=(u32)nKey ){
7965679812
u32 serial_type;
7965779813
7965879814
idx += getVarint32(&aKey[idx], serial_type);
7965979815
pMem->enc = pKeyInfo->enc;
7966079816
pMem->db = pKeyInfo->db;
@@ -79663,11 +79819,11 @@
7966379819
pMem->z = 0;
7966479820
d += sqlite3VdbeSerialGet(&aKey[d], serial_type, pMem);
7966579821
pMem++;
7966679822
if( (++u)>=p->nField ) break;
7966779823
}
79668
- if( d>nKey && u ){
79824
+ if( d>(u32)nKey && u ){
7966979825
assert( CORRUPT_DB );
7967079826
/* In a corrupt record entry, the last pMem might have been set up using
7967179827
** uninitialized memory. Overwrite its value with NULL, to prevent
7967279828
** warnings from MSAN. */
7967379829
sqlite3VdbeMemSetNull(pMem-1);
@@ -79747,11 +79903,12 @@
7974779903
*/
7974879904
d1 += sqlite3VdbeSerialGet(&aKey1[d1], serial_type1, &mem1);
7974979905
7975079906
/* Do the comparison
7975179907
*/
79752
- rc = sqlite3MemCompare(&mem1, &pPKey2->aMem[i], pKeyInfo->aColl[i]);
79908
+ rc = sqlite3MemCompare(&mem1, &pPKey2->aMem[i],
79909
+ pKeyInfo->nAllField>i ? pKeyInfo->aColl[i] : 0);
7975379910
if( rc!=0 ){
7975479911
assert( mem1.szMalloc==0 ); /* See comment below */
7975579912
if( pKeyInfo->aSortOrder[i] ){
7975679913
rc = -rc; /* Invert the result for DESC sort order. */
7975779914
}
@@ -80178,14 +80335,16 @@
8017880335
rc = +1;
8017980336
}else{
8018080337
mem1.n = (serial_type - 12) / 2;
8018180338
testcase( (d1+mem1.n)==(unsigned)nKey1 );
8018280339
testcase( (d1+mem1.n+1)==(unsigned)nKey1 );
80183
- if( (d1+mem1.n) > (unsigned)nKey1 ){
80340
+ if( (d1+mem1.n) > (unsigned)nKey1
80341
+ || (pKeyInfo = pPKey2->pKeyInfo)->nAllField<=i
80342
+ ){
8018480343
pPKey2->errCode = (u8)SQLITE_CORRUPT_BKPT;
8018580344
return 0; /* Corruption */
80186
- }else if( (pKeyInfo = pPKey2->pKeyInfo)->aColl[i] ){
80345
+ }else if( pKeyInfo->aColl[i] ){
8018780346
mem1.enc = pKeyInfo->enc;
8018880347
mem1.db = pKeyInfo->db;
8018980348
mem1.flags = MEM_Str;
8019080349
mem1.z = (char*)&aKey1[d1];
8019180350
rc = vdbeCompareMemString(
@@ -83382,10 +83541,11 @@
8338283541
** accordingly.
8338383542
*/
8338483543
static u16 SQLITE_NOINLINE computeNumericType(Mem *pMem){
8338583544
assert( (pMem->flags & (MEM_Int|MEM_Real))==0 );
8338683545
assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 );
83546
+ ExpandBlob(pMem);
8338783547
if( sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc)==0 ){
8338883548
return 0;
8338983549
}
8339083550
if( sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc)==0 ){
8339183551
return MEM_Int;
@@ -89257,10 +89417,21 @@
8925789417
memset(pFrame->aOnce, 0, (pProgram->nOp + 7)/8);
8925889418
p->aOp = aOp = pProgram->aOp;
8925989419
p->nOp = pProgram->nOp;
8926089420
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
8926189421
p->anExec = 0;
89422
+#endif
89423
+#ifdef SQLITE_DEBUG
89424
+ /* Verify that second and subsequent executions of the same trigger do not
89425
+ ** try to reuse register values from the first use. */
89426
+ {
89427
+ int i;
89428
+ for(i=0; i<p->nMem; i++){
89429
+ aMem[i].pScopyFrom = 0; /* Prevent false-positive AboutToChange() errs */
89430
+ aMem[i].flags |= MEM_Undefined; /* Cause a fault if this reg is reused */
89431
+ }
89432
+ }
8926289433
#endif
8926389434
pOp = &aOp[-1];
8926489435
8926589436
break;
8926689437
}
@@ -94431,10 +94602,26 @@
9443194602
/* #include "sqliteInt.h" */
9443294603
/* #include <stdlib.h> */
9443394604
/* #include <string.h> */
9443494605
9443594606
94607
+#if !defined(SQLITE_OMIT_WINDOWFUNC)
94608
+/*
94609
+** Walk all expressions linked into the list of Window objects passed
94610
+** as the second argument.
94611
+*/
94612
+static int walkWindowList(Walker *pWalker, Window *pList){
94613
+ Window *pWin;
94614
+ for(pWin=pList; pWin; pWin=pWin->pNextWin){
94615
+ if( sqlite3WalkExprList(pWalker, pWin->pOrderBy) ) return WRC_Abort;
94616
+ if( sqlite3WalkExprList(pWalker, pWin->pPartition) ) return WRC_Abort;
94617
+ if( sqlite3WalkExpr(pWalker, pWin->pFilter) ) return WRC_Abort;
94618
+ }
94619
+ return WRC_Continue;
94620
+}
94621
+#endif
94622
+
9443694623
/*
9443794624
** Walk an expression tree. Invoke the callback once for each node
9443894625
** of the expression, while descending. (In other words, the callback
9443994626
** is invoked before visiting children.)
9444094627
**
@@ -94470,14 +94657,11 @@
9447094657
}else if( pExpr->x.pList ){
9447194658
if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
9447294659
}
9447394660
#ifndef SQLITE_OMIT_WINDOWFUNC
9447494661
if( ExprHasProperty(pExpr, EP_WinFunc) ){
94475
- Window *pWin = pExpr->y.pWin;
94476
- if( sqlite3WalkExprList(pWalker, pWin->pPartition) ) return WRC_Abort;
94477
- if( sqlite3WalkExprList(pWalker, pWin->pOrderBy) ) return WRC_Abort;
94478
- if( sqlite3WalkExpr(pWalker, pWin->pFilter) ) return WRC_Abort;
94662
+ if( walkWindowList(pWalker, pExpr->y.pWin) ) return WRC_Abort;
9447994663
}
9448094664
#endif
9448194665
}
9448294666
break;
9448394667
}
@@ -94513,10 +94697,20 @@
9451394697
if( sqlite3WalkExpr(pWalker, p->pWhere) ) return WRC_Abort;
9451494698
if( sqlite3WalkExprList(pWalker, p->pGroupBy) ) return WRC_Abort;
9451594699
if( sqlite3WalkExpr(pWalker, p->pHaving) ) return WRC_Abort;
9451694700
if( sqlite3WalkExprList(pWalker, p->pOrderBy) ) return WRC_Abort;
9451794701
if( sqlite3WalkExpr(pWalker, p->pLimit) ) return WRC_Abort;
94702
+#if !defined(SQLITE_OMIT_WINDOWFUNC) && !defined(SQLITE_OMIT_ALTERTABLE)
94703
+ {
94704
+ Parse *pParse = pWalker->pParse;
94705
+ if( pParse && IN_RENAME_OBJECT ){
94706
+ int rc = walkWindowList(pWalker, p->pWinDefn);
94707
+ assert( rc==WRC_Continue );
94708
+ return rc;
94709
+ }
94710
+ }
94711
+#endif
9451894712
return WRC_Continue;
9451994713
}
9452094714
9452194715
/*
9452294716
** Walk the parse trees associated with all subqueries in the
@@ -95442,14 +95636,14 @@
9544295636
sqlite3WalkExprList(pWalker, pList);
9544395637
if( is_agg ){
9544495638
#ifndef SQLITE_OMIT_WINDOWFUNC
9544595639
if( pExpr->y.pWin ){
9544695640
Select *pSel = pNC->pWinSelect;
95641
+ sqlite3WindowUpdate(pParse, pSel->pWinDefn, pExpr->y.pWin, pDef);
9544795642
sqlite3WalkExprList(pWalker, pExpr->y.pWin->pPartition);
9544895643
sqlite3WalkExprList(pWalker, pExpr->y.pWin->pOrderBy);
9544995644
sqlite3WalkExpr(pWalker, pExpr->y.pWin->pFilter);
95450
- sqlite3WindowUpdate(pParse, pSel->pWinDefn, pExpr->y.pWin, pDef);
9545195645
if( 0==pSel->pWin
9545295646
|| 0==sqlite3WindowCompare(pParse, pSel->pWin, pExpr->y.pWin)
9545395647
){
9545495648
pExpr->y.pWin->pNextWin = pSel->pWin;
9545595649
pSel->pWin = pExpr->y.pWin;
@@ -95744,38 +95938,35 @@
9574495938
}
9574595939
if( !db->mallocFailed ){
9574695940
assert(pDup);
9574795941
iCol = resolveOrderByTermToExprList(pParse, pSelect, pDup);
9574895942
}
95749
- if( IN_RENAME_OBJECT ){
95750
- if( iCol>0 ){
95751
- pItem->done = 1;
95752
- continue;
95753
- }
95754
- }else{
95943
+ if( !IN_RENAME_OBJECT ){
9575595944
sqlite3ExprDelete(db, pDup);
9575695945
}
9575795946
}
9575895947
}
9575995948
if( iCol>0 ){
9576095949
/* Convert the ORDER BY term into an integer column number iCol,
9576195950
** taking care to preserve the COLLATE clause if it exists */
95762
- Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
95763
- if( pNew==0 ) return 1;
95764
- pNew->flags |= EP_IntValue;
95765
- pNew->u.iValue = iCol;
95766
- if( pItem->pExpr==pE ){
95767
- pItem->pExpr = pNew;
95768
- }else{
95769
- Expr *pParent = pItem->pExpr;
95770
- assert( pParent->op==TK_COLLATE );
95771
- while( pParent->pLeft->op==TK_COLLATE ) pParent = pParent->pLeft;
95772
- assert( pParent->pLeft==pE );
95773
- pParent->pLeft = pNew;
95774
- }
95775
- sqlite3ExprDelete(db, pE);
95776
- pItem->u.x.iOrderByCol = (u16)iCol;
95951
+ if( !IN_RENAME_OBJECT ){
95952
+ Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
95953
+ if( pNew==0 ) return 1;
95954
+ pNew->flags |= EP_IntValue;
95955
+ pNew->u.iValue = iCol;
95956
+ if( pItem->pExpr==pE ){
95957
+ pItem->pExpr = pNew;
95958
+ }else{
95959
+ Expr *pParent = pItem->pExpr;
95960
+ assert( pParent->op==TK_COLLATE );
95961
+ while( pParent->pLeft->op==TK_COLLATE ) pParent = pParent->pLeft;
95962
+ assert( pParent->pLeft==pE );
95963
+ pParent->pLeft = pNew;
95964
+ }
95965
+ sqlite3ExprDelete(db, pE);
95966
+ pItem->u.x.iOrderByCol = (u16)iCol;
95967
+ }
9577795968
pItem->done = 1;
9577895969
}else{
9577995970
moreToDo = 1;
9578095971
}
9578195972
}
@@ -96119,10 +96310,21 @@
9611996310
"the GROUP BY clause");
9612096311
return WRC_Abort;
9612196312
}
9612296313
}
9612396314
}
96315
+
96316
+ if( IN_RENAME_OBJECT ){
96317
+ Window *pWin;
96318
+ for(pWin=p->pWinDefn; pWin; pWin=pWin->pNextWin){
96319
+ if( sqlite3ResolveExprListNames(&sNC, pWin->pOrderBy)
96320
+ || sqlite3ResolveExprListNames(&sNC, pWin->pPartition)
96321
+ ){
96322
+ return WRC_Abort;
96323
+ }
96324
+ }
96325
+ }
9612496326
9612596327
/* If this is part of a compound SELECT, check that it has the right
9612696328
** number of expressions in the select list. */
9612796329
if( p->pNext && p->pEList->nExpr!=p->pNext->pEList->nExpr ){
9612896330
sqlite3SelectWrongNumTermsError(pParse, p->pNext);
@@ -101683,10 +101885,11 @@
101683101885
w.xExprCallback = analyzeAggregate;
101684101886
w.xSelectCallback = analyzeAggregatesInSelect;
101685101887
w.xSelectCallback2 = analyzeAggregatesInSelectEnd;
101686101888
w.walkerDepth = 0;
101687101889
w.u.pNC = pNC;
101890
+ w.pParse = 0;
101688101891
assert( pNC->pSrcList!=0 );
101689101892
sqlite3WalkExpr(&w, pExpr);
101690101893
}
101691101894
101692101895
/*
@@ -120153,22 +120356,26 @@
120153120356
/* ePragFlg: */ PragFlg_Result0,
120154120357
/* ColNames: */ 0, 0,
120155120358
/* iArg: */ 0 },
120156120359
#endif
120157120360
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120361
+#if !defined(SQLITE_OMIT_DEPRECATED)
120158120362
{/* zName: */ "count_changes",
120159120363
/* ePragTyp: */ PragTyp_FLAG,
120160120364
/* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120161120365
/* ColNames: */ 0, 0,
120162120366
/* iArg: */ SQLITE_CountRows },
120367
+#endif
120163120368
#endif
120164120369
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
120370
+#if !defined(SQLITE_OMIT_DEPRECATED)
120165120371
{/* zName: */ "data_store_directory",
120166120372
/* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY,
120167120373
/* ePragFlg: */ PragFlg_NoColumns1,
120168120374
/* ColNames: */ 0, 0,
120169120375
/* iArg: */ 0 },
120376
+#endif
120170120377
#endif
120171120378
#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
120172120379
{/* zName: */ "data_version",
120173120380
/* ePragTyp: */ PragTyp_HEADER_VALUE,
120174120381
/* ePragFlg: */ PragFlg_ReadOnly|PragFlg_Result0,
@@ -120180,16 +120387,18 @@
120180120387
/* ePragTyp: */ PragTyp_DATABASE_LIST,
120181120388
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0,
120182120389
/* ColNames: */ 35, 3,
120183120390
/* iArg: */ 0 },
120184120391
#endif
120185
-#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
120392
+#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
120393
+#if !defined(SQLITE_OMIT_DEPRECATED)
120186120394
{/* zName: */ "default_cache_size",
120187120395
/* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE,
120188120396
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
120189120397
/* ColNames: */ 45, 1,
120190120398
/* iArg: */ 0 },
120399
+#endif
120191120400
#endif
120192120401
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120193120402
#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
120194120403
{/* zName: */ "defer_foreign_keys",
120195120404
/* ePragTyp: */ PragTyp_FLAG,
@@ -120197,15 +120406,17 @@
120197120406
/* ColNames: */ 0, 0,
120198120407
/* iArg: */ SQLITE_DeferFKs },
120199120408
#endif
120200120409
#endif
120201120410
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120411
+#if !defined(SQLITE_OMIT_DEPRECATED)
120202120412
{/* zName: */ "empty_result_callbacks",
120203120413
/* ePragTyp: */ PragTyp_FLAG,
120204120414
/* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120205120415
/* ColNames: */ 0, 0,
120206120416
/* iArg: */ SQLITE_NullCallback },
120417
+#endif
120207120418
#endif
120208120419
#if !defined(SQLITE_OMIT_UTF16)
120209120420
{/* zName: */ "encoding",
120210120421
/* ePragTyp: */ PragTyp_ENCODING,
120211120422
/* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
@@ -120241,15 +120452,19 @@
120241120452
/* ePragFlg: */ PragFlg_ReadOnly|PragFlg_Result0,
120242120453
/* ColNames: */ 0, 0,
120243120454
/* iArg: */ BTREE_FREE_PAGE_COUNT },
120244120455
#endif
120245120456
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120457
+#if !defined(SQLITE_OMIT_DEPRECATED)
120246120458
{/* zName: */ "full_column_names",
120247120459
/* ePragTyp: */ PragTyp_FLAG,
120248120460
/* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120249120461
/* ColNames: */ 0, 0,
120250120462
/* iArg: */ SQLITE_FullColNames },
120463
+#endif
120464
+#endif
120465
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120251120466
{/* zName: */ "fullfsync",
120252120467
/* ePragTyp: */ PragTyp_FLAG,
120253120468
/* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120254120469
/* ColNames: */ 0, 0,
120255120470
/* iArg: */ SQLITE_FullFSync },
@@ -120472,15 +120687,17 @@
120472120687
/* ePragFlg: */ PragFlg_Result0,
120473120688
/* ColNames: */ 0, 0,
120474120689
/* iArg: */ 0 },
120475120690
#endif
120476120691
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120692
+#if !defined(SQLITE_OMIT_DEPRECATED)
120477120693
{/* zName: */ "short_column_names",
120478120694
/* ePragTyp: */ PragTyp_FLAG,
120479120695
/* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120480120696
/* ColNames: */ 0, 0,
120481120697
/* iArg: */ SQLITE_ShortColNames },
120698
+#endif
120482120699
#endif
120483120700
{/* zName: */ "shrink_memory",
120484120701
/* ePragTyp: */ PragTyp_SHRINK_MEMORY,
120485120702
/* ePragFlg: */ PragFlg_NoColumns,
120486120703
/* ColNames: */ 0, 0,
@@ -120529,15 +120746,19 @@
120529120746
{/* zName: */ "temp_store",
120530120747
/* ePragTyp: */ PragTyp_TEMP_STORE,
120531120748
/* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120532120749
/* ColNames: */ 0, 0,
120533120750
/* iArg: */ 0 },
120751
+#endif
120752
+#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
120753
+#if !defined(SQLITE_OMIT_DEPRECATED)
120534120754
{/* zName: */ "temp_store_directory",
120535120755
/* ePragTyp: */ PragTyp_TEMP_STORE_DIRECTORY,
120536120756
/* ePragFlg: */ PragFlg_NoColumns1,
120537120757
/* ColNames: */ 0, 0,
120538120758
/* iArg: */ 0 },
120759
+#endif
120539120760
#endif
120540120761
#if defined(SQLITE_HAS_CODEC)
120541120762
{/* zName: */ "textkey",
120542120763
/* ePragTyp: */ PragTyp_KEY,
120543120764
/* ePragFlg: */ 0,
@@ -126101,13 +126322,13 @@
126101126322
126102126323
savedFlags = db->flags;
126103126324
db->flags &= ~(u64)SQLITE_FullColNames;
126104126325
db->flags |= SQLITE_ShortColNames;
126105126326
sqlite3SelectPrep(pParse, pSelect, 0);
126327
+ db->flags = savedFlags;
126106126328
if( pParse->nErr ) return 0;
126107126329
while( pSelect->pPrior ) pSelect = pSelect->pPrior;
126108
- db->flags = savedFlags;
126109126330
pTab = sqlite3DbMallocZero(db, sizeof(Table) );
126110126331
if( pTab==0 ){
126111126332
return 0;
126112126333
}
126113126334
/* The sqlite3ResultSetOfSelect() is only used n contexts where lookaside
@@ -132377,10 +132598,11 @@
132377132598
132378132599
/* There is one entry in the aRegIdx[] array for each index on the table
132379132600
** being updated. Fill in aRegIdx[] with a register number that will hold
132380132601
** the key for accessing each index.
132381132602
*/
132603
+ if( onError==OE_Replace ) bReplace = 1;
132382132604
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
132383132605
int reg;
132384132606
if( chngKey || hasFK>1 || pIdx==pPk
132385132607
|| indexWhereClauseMightChange(pIdx,aXRef,chngRowid)
132386132608
){
@@ -132390,13 +132612,11 @@
132390132612
reg = 0;
132391132613
for(i=0; i<pIdx->nKeyCol; i++){
132392132614
if( indexColumnIsBeingUpdated(pIdx, i, aXRef, chngRowid) ){
132393132615
reg = ++pParse->nMem;
132394132616
pParse->nMem += pIdx->nColumn;
132395
- if( (onError==OE_Replace)
132396
- || (onError==OE_Default && pIdx->onError==OE_Replace)
132397
- ){
132617
+ if( onError==OE_Default && pIdx->onError==OE_Replace ){
132398132618
bReplace = 1;
132399132619
}
132400132620
break;
132401132621
}
132402132622
}
@@ -145794,10 +146014,11 @@
145794146014
VdbeCoverageIf(v, eCond==2);
145795146015
sqlite3VdbeAddOp3(v, aOp[eCond], regZero, sqlite3VdbeCurrentAddr(v)+2, reg);
145796146016
VdbeCoverageNeverNullIf(v, eCond==0);
145797146017
VdbeCoverageNeverNullIf(v, eCond==1);
145798146018
VdbeCoverageNeverNullIf(v, eCond==2);
146019
+ sqlite3MayAbort(pParse);
145799146020
sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_ERROR, OE_Abort);
145800146021
sqlite3VdbeAppendP4(v, (void*)azErr[eCond], P4_STATIC);
145801146022
sqlite3ReleaseTempReg(pParse, regZero);
145802146023
}
145803146024
@@ -150949,12 +151170,14 @@
150949151170
** expr1 NOT IN ()
150950151171
**
150951151172
** simplify to constants 0 (false) and 1 (true), respectively,
150952151173
** regardless of the value of expr1.
150953151174
*/
150954
- sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy490);
150955
- yymsp[-4].minor.yy490 = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[yymsp[-3].minor.yy96],1);
151175
+ if( IN_RENAME_OBJECT==0 ){
151176
+ sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy490);
151177
+ yymsp[-4].minor.yy490 = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[yymsp[-3].minor.yy96],1);
151178
+ }
150956151179
}else if( yymsp[-1].minor.yy42->nExpr==1 ){
150957151180
/* Expressions of the form:
150958151181
**
150959151182
** expr1 IN (?1)
150960151183
** expr1 NOT IN (?2)
@@ -158741,10 +158964,22 @@
158741158964
** Terminator values for position-lists and column-lists.
158742158965
*/
158743158966
#define POS_COLUMN (1) /* Column-list terminator */
158744158967
#define POS_END (0) /* Position-list terminator */
158745158968
158969
+/*
158970
+** The assert_fts3_nc() macro is similar to the assert() macro, except that it
158971
+** is used for assert() conditions that are true only if it can be
158972
+** guranteed that the database is not corrupt.
158973
+*/
158974
+#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
158975
+SQLITE_API extern int sqlite3_fts3_may_be_corrupt;
158976
+# define assert_fts3_nc(x) assert(sqlite3_fts3_may_be_corrupt || (x))
158977
+#else
158978
+# define assert_fts3_nc(x) assert(x)
158979
+#endif
158980
+
158746158981
/*
158747158982
** This section provides definitions to allow the
158748158983
** FTS3 extension to be compiled outside of the
158749158984
** amalgamation.
158750158985
*/
@@ -159265,10 +159500,18 @@
159265159500
SQLITE_PRIVATE int sqlite3Fts3Always(int b) { assert( b ); return b; }
159266159501
SQLITE_PRIVATE int sqlite3Fts3Never(int b) { assert( !b ); return b; }
159267159502
# endif
159268159503
#endif
159269159504
159505
+/*
159506
+** This variable is set to false when running tests for which the on disk
159507
+** structures should not be corrupt. Otherwise, true. If it is false, extra
159508
+** assert() conditions in the fts3 code are activated - conditions that are
159509
+** only true if it is guaranteed that the fts3 database is not corrupt.
159510
+*/
159511
+SQLITE_API int sqlite3_fts3_may_be_corrupt = 1;
159512
+
159270159513
/*
159271159514
** Write a 64-bit variable-length integer to memory starting at p[0].
159272159515
** The length of data written will be between 1 and FTS3_VARINT_MAX bytes.
159273159516
** The number of bytes written is returned.
159274159517
*/
@@ -161493,11 +161736,11 @@
161493161736
** docids to grow.
161494161737
**
161495161738
** A symetric argument may be made if the doclists are in descending
161496161739
** order.
161497161740
*/
161498
- aOut = sqlite3_malloc64((sqlite3_int64)n1+n2+FTS3_VARINT_MAX-1);
161741
+ aOut = sqlite3_malloc64((i64)n1+n2+FTS3_VARINT_MAX-1+FTS3_BUFFER_PADDING);
161499161742
if( !aOut ) return SQLITE_NOMEM;
161500161743
161501161744
p = aOut;
161502161745
fts3GetDeltaVarint3(&p1, pEnd1, 0, &i1);
161503161746
fts3GetDeltaVarint3(&p2, pEnd2, 0, &i2);
@@ -161522,14 +161765,16 @@
161522161765
}
161523161766
161524161767
if( rc!=SQLITE_OK ){
161525161768
sqlite3_free(aOut);
161526161769
p = aOut = 0;
161770
+ }else{
161771
+ assert( (p-aOut)<=n1+n2+FTS3_VARINT_MAX-1 );
161772
+ memset(&aOut[(p-aOut)], 0, FTS3_BUFFER_PADDING);
161527161773
}
161528161774
*paOut = aOut;
161529161775
*pnOut = (int)(p-aOut);
161530
- assert( *pnOut<=n1+n2+FTS3_VARINT_MAX-1 );
161531161776
return rc;
161532161777
}
161533161778
161534161779
/*
161535161780
** This function does a "phrase" merge of two doclists. In a phrase merge,
@@ -162803,11 +163048,10 @@
162803163048
*/
162804163049
static int fts3RollbackToMethod(sqlite3_vtab *pVtab, int iSavepoint){
162805163050
Fts3Table *p = (Fts3Table*)pVtab;
162806163051
UNUSED_PARAMETER(iSavepoint);
162807163052
assert( p->inTransaction );
162808
- assert( p->mxSavepoint >= iSavepoint );
162809163053
TESTONLY( p->mxSavepoint = iSavepoint );
162810163054
sqlite3Fts3PendingTermsClear(p);
162811163055
return SQLITE_OK;
162812163056
}
162813163057
@@ -169623,11 +169867,11 @@
169623169867
int iLangid, /* Language id */
169624169868
int iIndex, /* Index in p->aIndex[] */
169625169869
int iLevel /* Level of segments */
169626169870
){
169627169871
sqlite3_int64 iBase; /* First absolute level for iLangid/iIndex */
169628
- assert( iLangid>=0 );
169872
+ assert_fts3_nc( iLangid>=0 );
169629169873
assert( p->nIndex>0 );
169630169874
assert( iIndex>=0 && iIndex<p->nIndex );
169631169875
169632169876
iBase = ((sqlite3_int64)iLangid * p->nIndex + iIndex) * FTS3_SEGDIR_MAXLEVEL;
169633169877
return iBase + iLevel;
@@ -171310,10 +171554,15 @@
171310171554
}
171311171555
nData = pWriter->nData;
171312171556
171313171557
nPrefix = fts3PrefixCompress(pWriter->zTerm, pWriter->nTerm, zTerm, nTerm);
171314171558
nSuffix = nTerm-nPrefix;
171559
+
171560
+ /* If nSuffix is zero or less, then zTerm/nTerm must be a prefix of
171561
+ ** pWriter->zTerm/pWriter->nTerm. i.e. must be equal to or less than when
171562
+ ** compared with BINARY collation. This indicates corruption. */
171563
+ if( nSuffix<=0 ) return FTS_CORRUPT_VTAB;
171315171564
171316171565
/* Figure out how many bytes are required by this new entry */
171317171566
nReq = sqlite3Fts3VarintLen(nPrefix) + /* varint containing prefix size */
171318171567
sqlite3Fts3VarintLen(nSuffix) + /* varint containing suffix size */
171319171568
nSuffix + /* Term suffix */
@@ -199230,16 +199479,12 @@
199230199479
** should be greater than or equal to zero and smaller than the value
199231199480
** output by xInstCount().
199232199481
**
199233199482
** Usually, output parameter *piPhrase is set to the phrase number, *piCol
199234199483
** to the column in which it occurs and *piOff the token offset of the
199235
-** first token of the phrase. The exception is if the table was created
199236
-** with the offsets=0 option specified. In this case *piOff is always
199237
-** set to -1.
199238
-**
199239
-** Returns SQLITE_OK if successful, or an error code (i.e. SQLITE_NOMEM)
199240
-** if an error occurs.
199484
+** first token of the phrase. Returns SQLITE_OK if successful, or an error
199485
+** code (i.e. SQLITE_NOMEM) if an error occurs.
199241199486
**
199242199487
** This API can be quite slow if used with an FTS5 table created with the
199243199488
** "detail=none" or "detail=column" option.
199244199489
**
199245199490
** xRowid:
@@ -199777,10 +200022,16 @@
199777200022
# define assert_nc(x) assert(sqlite3_fts5_may_be_corrupt || (x))
199778200023
#else
199779200024
# define assert_nc(x) assert(x)
199780200025
#endif
199781200026
200027
+/*
200028
+** A version of memcmp() that does not cause asan errors if one of the pointer
200029
+** parameters is NULL and the number of bytes to compare is zero.
200030
+*/
200031
+#define fts5Memcmp(s1, s2, n) ((n)==0 ? 0 : memcmp((s1), (s2), (n)))
200032
+
199782200033
/* Mark a function parameter as unused, to suppress nuisance compiler
199783200034
** warnings. */
199784200035
#ifndef UNUSED_PARAM
199785200036
# define UNUSED_PARAM(X) (void)(X)
199786200037
#endif
@@ -199964,11 +200215,11 @@
199964200215
/* Write and decode big-endian 32-bit integer values */
199965200216
static void sqlite3Fts5Put32(u8*, int);
199966200217
static int sqlite3Fts5Get32(const u8*);
199967200218
199968200219
#define FTS5_POS2COLUMN(iPos) (int)(iPos >> 32)
199969
-#define FTS5_POS2OFFSET(iPos) (int)(iPos & 0xFFFFFFFF)
200220
+#define FTS5_POS2OFFSET(iPos) (int)(iPos & 0x7FFFFFFF)
199970200221
199971200222
typedef struct Fts5PoslistReader Fts5PoslistReader;
199972200223
struct Fts5PoslistReader {
199973200224
/* Variables used only by sqlite3Fts5PoslistIterXXX() functions. */
199974200225
const u8 *a; /* Position list to iterate through */
@@ -202320,25 +202571,26 @@
202320202571
int iOff = 0;
202321202572
int iFirst = -1;
202322202573
int nInst;
202323202574
int nScore = 0;
202324202575
int iLast = 0;
202576
+ sqlite3_int64 iEnd = (sqlite3_int64)iPos + nToken;
202325202577
202326202578
rc = pApi->xInstCount(pFts, &nInst);
202327202579
for(i=0; i<nInst && rc==SQLITE_OK; i++){
202328202580
rc = pApi->xInst(pFts, i, &ip, &ic, &iOff);
202329
- if( rc==SQLITE_OK && ic==iCol && iOff>=iPos && iOff<(iPos+nToken) ){
202581
+ if( rc==SQLITE_OK && ic==iCol && iOff>=iPos && iOff<iEnd ){
202330202582
nScore += (aSeen[ip] ? 1 : 1000);
202331202583
aSeen[ip] = 1;
202332202584
if( iFirst<0 ) iFirst = iOff;
202333202585
iLast = iOff + pApi->xPhraseSize(pFts, ip);
202334202586
}
202335202587
}
202336202588
202337202589
*pnScore = nScore;
202338202590
if( piPos ){
202339
- int iAdj = iFirst - (nToken - (iLast-iFirst)) / 2;
202591
+ sqlite3_int64 iAdj = iFirst - (nToken - (iLast-iFirst)) / 2;
202340202592
if( (iAdj+nToken)>nDocsize ) iAdj = nDocsize - nToken;
202341202593
if( iAdj<0 ) iAdj = 0;
202342202594
*piPos = iAdj;
202343202595
}
202344202596
@@ -202882,11 +203134,11 @@
202882203134
if( iVal==1 ){
202883203135
fts5FastGetVarint32(a, i, iVal);
202884203136
iOff = ((i64)iVal) << 32;
202885203137
fts5FastGetVarint32(a, i, iVal);
202886203138
}
202887
- *piOff = iOff + (iVal-2);
203139
+ *piOff = iOff + ((iVal-2) & 0x7FFFFFFF);
202888203140
*pi = i;
202889203141
return 0;
202890203142
}
202891203143
}
202892203144
@@ -208054,11 +208306,11 @@
208054208306
**
208055208307
** res = *pLeft - *pRight
208056208308
*/
208057208309
static int fts5BufferCompare(Fts5Buffer *pLeft, Fts5Buffer *pRight){
208058208310
int nCmp = MIN(pLeft->n, pRight->n);
208059
- int res = memcmp(pLeft->p, pRight->p, nCmp);
208311
+ int res = fts5Memcmp(pLeft->p, pRight->p, nCmp);
208060208312
return (res==0 ? (pLeft->n - pRight->n) : res);
208061208313
}
208062208314
208063208315
static int fts5LeafFirstTermOff(Fts5Data *pLeaf){
208064208316
int ret;
@@ -209982,11 +210234,11 @@
209982210234
assert( pRes->iFirst==i2 );
209983210235
}else if( p2->pLeaf==0 ){
209984210236
assert( pRes->iFirst==i1 );
209985210237
}else{
209986210238
int nMin = MIN(p1->term.n, p2->term.n);
209987
- int res = memcmp(p1->term.p, p2->term.p, nMin);
210239
+ int res = fts5Memcmp(p1->term.p, p2->term.p, nMin);
209988210240
if( res==0 ) res = p1->term.n - p2->term.n;
209989210241
209990210242
if( res==0 ){
209991210243
assert( pRes->bTermEq==1 );
209992210244
assert( p1->iRowid!=p2->iRowid );
@@ -211028,11 +211280,11 @@
211028211280
u32 mask;
211029211281
memset(aUsed, 0, sizeof(aUsed));
211030211282
for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
211031211283
for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
211032211284
int iId = pStruct->aLevel[iLvl].aSeg[iSeg].iSegid;
211033
- if( iId<=FTS5_MAX_SEGMENT ){
211285
+ if( iId<=FTS5_MAX_SEGMENT && iId>0 ){
211034211286
aUsed[(iId-1) / 32] |= (u32)1 << ((iId-1) % 32);
211035211287
}
211036211288
}
211037211289
}
211038211290
@@ -211575,11 +211827,11 @@
211575211827
*/
211576211828
static void fts5TrimSegments(Fts5Index *p, Fts5Iter *pIter){
211577211829
int i;
211578211830
Fts5Buffer buf;
211579211831
memset(&buf, 0, sizeof(Fts5Buffer));
211580
- for(i=0; i<pIter->nSeg; i++){
211832
+ for(i=0; i<pIter->nSeg && p->rc==SQLITE_OK; i++){
211581211833
Fts5SegIter *pSeg = &pIter->aSeg[i];
211582211834
if( pSeg->pSeg==0 ){
211583211835
/* no-op */
211584211836
}else if( pSeg->pLeaf==0 ){
211585211837
/* All keys from this input segment have been transfered to the output.
@@ -211595,37 +211847,45 @@
211595211847
u8 aHdr[4] = {0x00, 0x00, 0x00, 0x00};
211596211848
211597211849
iLeafRowid = FTS5_SEGMENT_ROWID(iId, pSeg->iTermLeafPgno);
211598211850
pData = fts5DataRead(p, iLeafRowid);
211599211851
if( pData ){
211600
- fts5BufferZero(&buf);
211601
- fts5BufferGrow(&p->rc, &buf, pData->nn);
211602
- fts5BufferAppendBlob(&p->rc, &buf, sizeof(aHdr), aHdr);
211603
- fts5BufferAppendVarint(&p->rc, &buf, pSeg->term.n);
211604
- fts5BufferAppendBlob(&p->rc, &buf, pSeg->term.n, pSeg->term.p);
211605
- fts5BufferAppendBlob(&p->rc, &buf, pData->szLeaf-iOff, &pData->p[iOff]);
211606
- if( p->rc==SQLITE_OK ){
211607
- /* Set the szLeaf field */
211608
- fts5PutU16(&buf.p[2], (u16)buf.n);
211609
- }
211610
-
211611
- /* Set up the new page-index array */
211612
- fts5BufferAppendVarint(&p->rc, &buf, 4);
211613
- if( pSeg->iLeafPgno==pSeg->iTermLeafPgno
211614
- && pSeg->iEndofDoclist<pData->szLeaf
211615
- ){
211616
- int nDiff = pData->szLeaf - pSeg->iEndofDoclist;
211617
- fts5BufferAppendVarint(&p->rc, &buf, buf.n - 1 - nDiff - 4);
211618
- fts5BufferAppendBlob(&p->rc, &buf,
211619
- pData->nn - pSeg->iPgidxOff, &pData->p[pSeg->iPgidxOff]
211620
- );
211621
- }
211622
-
211623
- fts5DataRelease(pData);
211624
- pSeg->pSeg->pgnoFirst = pSeg->iTermLeafPgno;
211625
- fts5DataDelete(p, FTS5_SEGMENT_ROWID(iId, 1), iLeafRowid);
211626
- fts5DataWrite(p, iLeafRowid, buf.p, buf.n);
211852
+ if( iOff>pData->szLeaf ){
211853
+ /* This can occur if the pages that the segments occupy overlap - if
211854
+ ** a single page has been assigned to more than one segment. In
211855
+ ** this case a prior iteration of this loop may have corrupted the
211856
+ ** segment currently being trimmed. */
211857
+ p->rc = FTS5_CORRUPT;
211858
+ }else{
211859
+ fts5BufferZero(&buf);
211860
+ fts5BufferGrow(&p->rc, &buf, pData->nn);
211861
+ fts5BufferAppendBlob(&p->rc, &buf, sizeof(aHdr), aHdr);
211862
+ fts5BufferAppendVarint(&p->rc, &buf, pSeg->term.n);
211863
+ fts5BufferAppendBlob(&p->rc, &buf, pSeg->term.n, pSeg->term.p);
211864
+ fts5BufferAppendBlob(&p->rc, &buf, pData->szLeaf-iOff,&pData->p[iOff]);
211865
+ if( p->rc==SQLITE_OK ){
211866
+ /* Set the szLeaf field */
211867
+ fts5PutU16(&buf.p[2], (u16)buf.n);
211868
+ }
211869
+
211870
+ /* Set up the new page-index array */
211871
+ fts5BufferAppendVarint(&p->rc, &buf, 4);
211872
+ if( pSeg->iLeafPgno==pSeg->iTermLeafPgno
211873
+ && pSeg->iEndofDoclist<pData->szLeaf
211874
+ ){
211875
+ int nDiff = pData->szLeaf - pSeg->iEndofDoclist;
211876
+ fts5BufferAppendVarint(&p->rc, &buf, buf.n - 1 - nDiff - 4);
211877
+ fts5BufferAppendBlob(&p->rc, &buf,
211878
+ pData->nn - pSeg->iPgidxOff, &pData->p[pSeg->iPgidxOff]
211879
+ );
211880
+ }
211881
+
211882
+ pSeg->pSeg->pgnoFirst = pSeg->iTermLeafPgno;
211883
+ fts5DataDelete(p, FTS5_SEGMENT_ROWID(iId, 1), iLeafRowid);
211884
+ fts5DataWrite(p, iLeafRowid, buf.p, buf.n);
211885
+ }
211886
+ fts5DataRelease(pData);
211627211887
}
211628211888
}
211629211889
}
211630211890
fts5BufferFree(&buf);
211631211891
}
@@ -211713,11 +211973,11 @@
211713211973
int nPos; /* position-list size field value */
211714211974
int nTerm;
211715211975
const u8 *pTerm;
211716211976
211717211977
pTerm = fts5MultiIterTerm(pIter, &nTerm);
211718
- if( nTerm!=term.n || memcmp(pTerm, term.p, nTerm) ){
211978
+ if( nTerm!=term.n || fts5Memcmp(pTerm, term.p, nTerm) ){
211719211979
if( pnRem && writer.nLeafWritten>nRem ){
211720211980
break;
211721211981
}
211722211982
fts5BufferSet(&p->rc, &term, nTerm, pTerm);
211723211983
bTermWritten =0;
@@ -212469,10 +212729,11 @@
212469212729
/* WRITEPOSLISTSIZE */
212470212730
fts5BufferSafeAppendVarint(&out, tmp.n * 2);
212471212731
fts5BufferSafeAppendBlob(&out, tmp.p, tmp.n);
212472212732
fts5DoclistIterNext(&i1);
212473212733
fts5DoclistIterNext(&i2);
212734
+ assert( out.n<=(p1->n+p2->n+9) );
212474212735
if( i1.aPoslist==0 || i2.aPoslist==0 ) break;
212475212736
}
212476212737
}
212477212738
212478212739
if( i1.aPoslist ){
@@ -212570,11 +212831,11 @@
212570212831
}
212571212832
fts5BufferFree(&aBuf[i]);
212572212833
}
212573212834
fts5MultiIterFree(p1);
212574212835
212575
- pData = fts5IdxMalloc(p, sizeof(Fts5Data) + doclist.n);
212836
+ pData = fts5IdxMalloc(p, sizeof(Fts5Data)+doclist.n+FTS5_DATA_ZERO_PADDING);
212576212837
if( pData ){
212577212838
pData->p = (u8*)&pData[1];
212578212839
pData->nn = pData->szLeaf = doclist.n;
212579212840
if( doclist.n ) memcpy(pData->p, doclist.p, doclist.n);
212580212841
fts5MultiIterNew2(p, pData, bDesc, ppIter);
@@ -213336,11 +213597,11 @@
213336213597
iRowidOff = fts5LeafFirstRowidOff(pLeaf);
213337213598
if( iRowidOff>=iOff || iOff>=pLeaf->szLeaf ){
213338213599
p->rc = FTS5_CORRUPT;
213339213600
}else{
213340213601
iOff += fts5GetVarint32(&pLeaf->p[iOff], nTerm);
213341
- res = memcmp(&pLeaf->p[iOff], zIdxTerm, MIN(nTerm, nIdxTerm));
213602
+ res = fts5Memcmp(&pLeaf->p[iOff], zIdxTerm, MIN(nTerm, nIdxTerm));
213342213603
if( res==0 ) res = nTerm - nIdxTerm;
213343213604
if( res<0 ) p->rc = FTS5_CORRUPT;
213344213605
}
213345213606
213346213607
fts5IntegrityCheckPgidx(p, pLeaf);
@@ -215772,10 +216033,11 @@
215772216033
*/
215773216034
static int fts5CacheInstArray(Fts5Cursor *pCsr){
215774216035
int rc = SQLITE_OK;
215775216036
Fts5PoslistReader *aIter; /* One iterator for each phrase */
215776216037
int nIter; /* Number of iterators/phrases */
216038
+ int nCol = ((Fts5Table*)pCsr->base.pVtab)->pConfig->nCol;
215777216039
215778216040
nIter = sqlite3Fts5ExprPhraseCount(pCsr->pExpr);
215779216041
if( pCsr->aInstIter==0 ){
215780216042
sqlite3_int64 nByte = sizeof(Fts5PoslistReader) * nIter;
215781216043
pCsr->aInstIter = (Fts5PoslistReader*)sqlite3Fts5MallocZero(&rc, nByte);
@@ -215825,10 +216087,14 @@
215825216087
215826216088
aInst = &pCsr->aInst[3 * (nInst-1)];
215827216089
aInst[0] = iBest;
215828216090
aInst[1] = FTS5_POS2COLUMN(aIter[iBest].iPos);
215829216091
aInst[2] = FTS5_POS2OFFSET(aIter[iBest].iPos);
216092
+ if( aInst[1]<0 || aInst[1]>=nCol ){
216093
+ rc = FTS5_CORRUPT;
216094
+ break;
216095
+ }
215830216096
sqlite3Fts5PoslistReaderNext(&aIter[iBest]);
215831216097
}
215832216098
}
215833216099
215834216100
pCsr->nInstCount = nInst;
@@ -216636,11 +216902,11 @@
216636216902
int nArg, /* Number of args */
216637216903
sqlite3_value **apUnused /* Function arguments */
216638216904
){
216639216905
assert( nArg==0 );
216640216906
UNUSED_PARAM2(nArg, apUnused);
216641
- sqlite3_result_text(pCtx, "fts5: 2019-01-21 16:12:20 6c33a303ebbb0f5193ead535280ba63118e14fb4f9977ce80dc716a0b082ec99", -1, SQLITE_TRANSIENT);
216907
+ sqlite3_result_text(pCtx, "fts5: 2019-01-26 23:34:50 a3ea1a822d3a110f4f186f2fc8550f435c8c98635d058096b7be9d4df7066b8b", -1, SQLITE_TRANSIENT);
216642216908
}
216643216909
216644216910
/*
216645216911
** Return true if zName is the extension on one of the shadow tables used
216646216912
** by this module.
@@ -221399,12 +221665,12 @@
221399221665
}
221400221666
#endif /* SQLITE_CORE */
221401221667
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
221402221668
221403221669
/************** End of stmt.c ************************************************/
221404
-#if __LINE__!=221404
221670
+#if __LINE__!=221670
221405221671
#undef SQLITE_SOURCE_ID
221406
-#define SQLITE_SOURCE_ID "2019-01-21 17:57:31 505ed9a47825240979338a24044559613fbbd2a7850bdff70c7164da054ealt2"
221672
+#define SQLITE_SOURCE_ID "2019-01-27 02:45:32 9cf8ebd141aa2eb661d457624c76433bd9e4abfdef04aa52e28bc169172calt2"
221407221673
#endif
221408221674
/* Return the source-id for this library */
221409221675
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
221410221676
/************************** End of sqlite3.c ******************************/
221411221677
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1162,11 +1162,11 @@
1162 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1163 ** [sqlite_version()] and [sqlite_source_id()].
1164 */
1165 #define SQLITE_VERSION "3.27.0"
1166 #define SQLITE_VERSION_NUMBER 3027000
1167 #define SQLITE_SOURCE_ID "2019-01-21 17:57:31 505ed9a47825240979338a24044559613fbbd2a7850bdff70c7164da054ec63d"
1168
1169 /*
1170 ** CAPI3REF: Run-Time Library Version Numbers
1171 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1172 **
@@ -1860,10 +1860,19 @@
1860 ** current transaction. This hint is not guaranteed to be accurate but it
1861 ** is often close. The underlying VFS might choose to preallocate database
1862 ** file space based on this hint in order to help writes to the database
1863 ** file run faster.
1864 **
 
 
 
 
 
 
 
 
 
1865 ** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]
1866 ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
1867 ** extends and truncates the database file in chunks of a size specified
1868 ** by the user. The fourth argument to [sqlite3_file_control()] should
1869 ** point to an integer (type int) containing the new chunk-size to use
@@ -2168,10 +2177,11 @@
2168 #define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 31
2169 #define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32
2170 #define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33
2171 #define SQLITE_FCNTL_LOCK_TIMEOUT 34
2172 #define SQLITE_FCNTL_DATA_VERSION 35
 
2173
2174 /* deprecated names */
2175 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
2176 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
2177 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -12272,16 +12282,12 @@
12272 ** should be greater than or equal to zero and smaller than the value
12273 ** output by xInstCount().
12274 **
12275 ** Usually, output parameter *piPhrase is set to the phrase number, *piCol
12276 ** to the column in which it occurs and *piOff the token offset of the
12277 ** first token of the phrase. The exception is if the table was created
12278 ** with the offsets=0 option specified. In this case *piOff is always
12279 ** set to -1.
12280 **
12281 ** Returns SQLITE_OK if successful, or an error code (i.e. SQLITE_NOMEM)
12282 ** if an error occurs.
12283 **
12284 ** This API can be quite slow if used with an FTS5 table created with the
12285 ** "detail=none" or "detail=column" option.
12286 **
12287 ** xRowid:
@@ -46564,16 +46570,22 @@
46564
46565 /* An open file */
46566 struct MemFile {
46567 sqlite3_file base; /* IO methods */
46568 sqlite3_int64 sz; /* Size of the file */
46569 sqlite3_int64 szMax; /* Space allocated to aData */
 
46570 unsigned char *aData; /* content of the file */
46571 int nMmap; /* Number of memory mapped pages */
46572 unsigned mFlags; /* Flags */
46573 int eLock; /* Most recent lock against this file */
46574 };
 
 
 
 
 
46575
46576 /*
46577 ** Methods for MemFile
46578 */
46579 static int memdbClose(sqlite3_file*);
@@ -46690,14 +46702,19 @@
46690 static int memdbEnlarge(MemFile *p, sqlite3_int64 newSz){
46691 unsigned char *pNew;
46692 if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || p->nMmap>0 ){
46693 return SQLITE_FULL;
46694 }
 
 
 
 
 
46695 pNew = sqlite3_realloc64(p->aData, newSz);
46696 if( pNew==0 ) return SQLITE_NOMEM;
46697 p->aData = pNew;
46698 p->szMax = newSz;
46699 return SQLITE_OK;
46700 }
46701
46702 /*
46703 ** Write data to an memdb-file.
@@ -46707,14 +46724,15 @@
46707 const void *z,
46708 int iAmt,
46709 sqlite_int64 iOfst
46710 ){
46711 MemFile *p = (MemFile *)pFile;
 
46712 if( iOfst+iAmt>p->sz ){
46713 int rc;
46714 if( iOfst+iAmt>p->szMax
46715 && (rc = memdbEnlarge(p, (iOfst+iAmt)*2))!=SQLITE_OK
46716 ){
46717 return rc;
46718 }
46719 if( iOfst>p->sz ) memset(p->aData+p->sz, 0, iOfst-p->sz);
46720 p->sz = iOfst+iAmt;
@@ -46756,10 +46774,15 @@
46756 /*
46757 ** Lock an memdb-file.
46758 */
46759 static int memdbLock(sqlite3_file *pFile, int eLock){
46760 MemFile *p = (MemFile *)pFile;
 
 
 
 
 
46761 p->eLock = eLock;
46762 return SQLITE_OK;
46763 }
46764
46765 #if 0 /* Never used because memdbAccess() always returns false */
@@ -46779,10 +46802,23 @@
46779 MemFile *p = (MemFile *)pFile;
46780 int rc = SQLITE_NOTFOUND;
46781 if( op==SQLITE_FCNTL_VFSNAME ){
46782 *(char**)pArg = sqlite3_mprintf("memdb(%p,%lld)", p->aData, p->sz);
46783 rc = SQLITE_OK;
 
 
 
 
 
 
 
 
 
 
 
 
 
46784 }
46785 return rc;
46786 }
46787
46788 #if 0 /* Not used because of SQLITE_IOCAP_POWERSAFE_OVERWRITE */
@@ -46810,12 +46846,17 @@
46810 sqlite3_int64 iOfst,
46811 int iAmt,
46812 void **pp
46813 ){
46814 MemFile *p = (MemFile *)pFile;
46815 p->nMmap++;
46816 *pp = (void*)(p->aData + iOfst);
 
 
 
 
 
46817 return SQLITE_OK;
46818 }
46819
46820 /* Release a memory-mapped page */
46821 static int memdbUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){
@@ -46841,10 +46882,11 @@
46841 memset(p, 0, sizeof(*p));
46842 p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE;
46843 assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */
46844 *pOutFlags = flags | SQLITE_OPEN_MEMORY;
46845 p->base.pMethods = &memdb_io_methods;
 
46846 return SQLITE_OK;
46847 }
46848
46849 #if 0 /* Only used to delete rollback journals, master journals, and WAL
46850 ** files, none of which exist in memdb. So this routine is never used */
@@ -47090,11 +47132,15 @@
47090 if( p==0 ){
47091 rc = SQLITE_ERROR;
47092 }else{
47093 p->aData = pData;
47094 p->sz = szDb;
 
47095 p->szMax = szBuf;
 
 
 
47096 p->mFlags = mFlags;
47097 rc = SQLITE_OK;
47098 }
47099
47100 end_deserialize:
@@ -63737,15 +63783,16 @@
63737 ){
63738 int rc; /* Status code */
63739 UnpackedRecord *pIdxKey; /* Unpacked index key */
63740
63741 if( pKey ){
 
63742 assert( nKey==(i64)(int)nKey );
63743 pIdxKey = sqlite3VdbeAllocUnpackedRecord(pCur->pKeyInfo);
63744 if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT;
63745 sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey, pIdxKey);
63746 if( pIdxKey->nField==0 ){
63747 rc = SQLITE_CORRUPT_BKPT;
63748 goto moveto_done;
63749 }
63750 }else{
63751 pIdxKey = 0;
@@ -68408,11 +68455,11 @@
68408 nCell = (int)pCur->info.nKey;
68409 testcase( nCell<0 ); /* True if key size is 2^32 or more */
68410 testcase( nCell==0 ); /* Invalid key size: 0x80 0x80 0x00 */
68411 testcase( nCell==1 ); /* Invalid key size: 0x80 0x80 0x01 */
68412 testcase( nCell==2 ); /* Minimum legal index key size */
68413 if( nCell<2 ){
68414 rc = SQLITE_CORRUPT_PAGE(pPage);
68415 goto moveto_finish;
68416 }
68417 pCellKey = sqlite3Malloc( nCell+18 );
68418 if( pCellKey==0 ){
@@ -69042,11 +69089,11 @@
69042 *ppPage = 0;
69043 }
69044 TRACE(("ALLOCATE: %d from end of file\n", *pPgno));
69045 }
69046
69047 assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
69048
69049 end_allocate_page:
69050 releasePage(pTrunk);
69051 releasePage(pPrevTrunk);
69052 assert( rc!=SQLITE_OK || sqlite3PagerPageRefcount((*ppPage)->pDbPage)<=1 );
@@ -69626,20 +69673,85 @@
69626 }
69627 #endif
69628 }
69629 }
69630
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69631 /*
69632 ** A CellArray object contains a cache of pointers and sizes for a
69633 ** consecutive sequence of cells that might be held on multiple pages.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69634 */
69635 typedef struct CellArray CellArray;
69636 struct CellArray {
69637 int nCell; /* Number of cells in apCell[] */
69638 MemPage *pRef; /* Reference page */
69639 u8 **apCell; /* All cells begin balanced */
69640 u16 *szCell; /* Local size of all cells in apCell[] */
 
 
69641 };
69642
69643 /*
69644 ** Make sure the cell sizes at idx, idx+1, ..., idx+N-1 have been
69645 ** computed.
@@ -69686,41 +69798,62 @@
69686 **
69687 ** The MemPage.nFree field is invalidated by this function. It is the
69688 ** responsibility of the caller to set it correctly.
69689 */
69690 static int rebuildPage(
69691 MemPage *pPg, /* Edit this page */
 
69692 int nCell, /* Final number of cells on page */
69693 u8 **apCell, /* Array of cells */
69694 u16 *szCell /* Array of cell sizes */
69695 ){
69696 const int hdr = pPg->hdrOffset; /* Offset of header on pPg */
69697 u8 * const aData = pPg->aData; /* Pointer to data for pPg */
69698 const int usableSize = pPg->pBt->usableSize;
69699 u8 * const pEnd = &aData[usableSize];
69700 int i;
 
 
69701 u8 *pCellptr = pPg->aCellIdx;
69702 u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
69703 u8 *pData;
 
 
69704
69705 i = get2byte(&aData[hdr+5]);
69706 memcpy(&pTmp[i], &aData[i], usableSize - i);
 
 
 
 
69707
69708 pData = pEnd;
69709 for(i=0; i<nCell; i++){
69710 u8 *pCell = apCell[i];
 
 
69711 if( SQLITE_WITHIN(pCell,aData,pEnd) ){
69712 if( ((uptr)(pCell+szCell[i]))>(uptr)pEnd ) return SQLITE_CORRUPT_BKPT;
69713 pCell = &pTmp[pCell - aData];
 
 
 
 
69714 }
69715 pData -= szCell[i];
 
69716 put2byte(pCellptr, (pData - aData));
69717 pCellptr += 2;
69718 if( pData < pCellptr ) return SQLITE_CORRUPT_BKPT;
69719 memcpy(pData, pCell, szCell[i]);
69720 assert( szCell[i]==pPg->xCellSize(pPg, pCell) || CORRUPT_DB );
69721 testcase( szCell[i]!=pPg->xCellSize(pPg,pCell) );
 
 
 
 
 
 
69722 }
69723
69724 /* The pPg->nFree field is now set incorrectly. The caller will fix it. */
69725 pPg->nCell = nCell;
69726 pPg->nOverflow = 0;
@@ -69731,16 +69864,15 @@
69731 aData[hdr+7] = 0x00;
69732 return SQLITE_OK;
69733 }
69734
69735 /*
69736 ** Array apCell[] contains nCell pointers to b-tree cells. Array szCell
69737 ** contains the size in bytes of each such cell. This function attempts to
69738 ** add the cells stored in the array to page pPg. If it cannot (because
69739 ** the page needs to be defragmented before the cells will fit), non-zero
69740 ** is returned. Otherwise, if the cells are added successfully, zero is
69741 ** returned.
69742 **
69743 ** Argument pCellptr points to the first entry in the cell-pointer array
69744 ** (part of page pPg) to populate. After cell apCell[0] is written to the
69745 ** page body, a 16-bit offset is written to pCellptr. And so on, for each
69746 ** cell in the array. It is the responsibility of the caller to ensure
@@ -69758,22 +69890,27 @@
69758 ** cells in apCell[], then the cells do not fit and non-zero is returned.
69759 */
69760 static int pageInsertArray(
69761 MemPage *pPg, /* Page to add cells to */
69762 u8 *pBegin, /* End of cell-pointer array */
69763 u8 **ppData, /* IN/OUT: Page content -area pointer */
69764 u8 *pCellptr, /* Pointer to cell-pointer area */
69765 int iFirst, /* Index of first cell to add */
69766 int nCell, /* Number of cells to add to pPg */
69767 CellArray *pCArray /* Array of cells */
69768 ){
69769 int i;
69770 u8 *aData = pPg->aData;
69771 u8 *pData = *ppData;
69772 int iEnd = iFirst + nCell;
 
 
69773 assert( CORRUPT_DB || pPg->hdrOffset==0 ); /* Never called on page 1 */
69774 for(i=iFirst; i<iEnd; i++){
 
 
 
69775 int sz, rc;
69776 u8 *pSlot;
69777 sz = cachedCellSize(pCArray, i);
69778 if( (aData[1]==0 && aData[2]==0) || (pSlot = pageFindSlot(pPg,sz,&rc))==0 ){
69779 if( (pData - pBegin)<sz ) return 1;
@@ -69784,24 +69921,37 @@
69784 ** database. But they might for a corrupt database. Hence use memmove()
69785 ** since memcpy() sends SIGABORT with overlapping buffers on OpenBSD */
69786 assert( (pSlot+sz)<=pCArray->apCell[i]
69787 || pSlot>=(pCArray->apCell[i]+sz)
69788 || CORRUPT_DB );
 
 
 
 
 
 
 
69789 memmove(pSlot, pCArray->apCell[i], sz);
69790 put2byte(pCellptr, (pSlot - aData));
69791 pCellptr += 2;
 
 
 
 
 
 
69792 }
69793 *ppData = pData;
69794 return 0;
69795 }
69796
69797 /*
69798 ** Array apCell[] contains nCell pointers to b-tree cells. Array szCell
69799 ** contains the size in bytes of each such cell. This function adds the
69800 ** space associated with each cell in the array that is currently stored
69801 ** within the body of pPg to the pPg free-list. The cell-pointers and other
69802 ** fields of the page are not updated.
69803 **
69804 ** This function returns the total number of cells added to the free-list.
69805 */
69806 static int pageFreeArray(
69807 MemPage *pPg, /* Page to edit */
@@ -69847,13 +69997,13 @@
69847 }
69848 return nRet;
69849 }
69850
69851 /*
69852 ** apCell[] and szCell[] contains pointers to and sizes of all cells in the
69853 ** pages being balanced. The current page, pPg, has pPg->nCell cells starting
69854 ** with apCell[iOld]. After balancing, this page should hold nNew cells
69855 ** starting at apCell[iNew].
69856 **
69857 ** This routine makes the necessary adjustments to pPg so that it contains
69858 ** the correct cells after being balanced.
69859 **
@@ -69949,27 +70099,12 @@
69949
69950 return SQLITE_OK;
69951 editpage_fail:
69952 /* Unable to edit this page. Rebuild it from scratch instead. */
69953 populateCellCache(pCArray, iNew, nNew);
69954 return rebuildPage(pPg, nNew, &pCArray->apCell[iNew], &pCArray->szCell[iNew]);
69955 }
69956
69957 /*
69958 ** The following parameters determine how many adjacent pages get involved
69959 ** in a balancing operation. NN is the number of neighbors on either side
69960 ** of the page that participate in the balancing operation. NB is the
69961 ** total number of pages that participate, including the target page and
69962 ** NN neighbors on either side.
69963 **
69964 ** The minimum value of NN is 1 (of course). Increasing NN above 1
69965 ** (to 2 or 3) gives a modest improvement in SELECT and DELETE performance
69966 ** in exchange for a larger degradation in INSERT and UPDATE performance.
69967 ** The value of NN appears to give the best results overall.
69968 */
69969 #define NN 1 /* Number of neighbors on either side of pPage */
69970 #define NB (NN*2+1) /* Total pages involved in the balance */
69971
69972
69973 #ifndef SQLITE_OMIT_QUICKBALANCE
69974 /*
69975 ** This version of balance() handles the common special case where
@@ -70016,16 +70151,26 @@
70016
70017 u8 *pOut = &pSpace[4];
70018 u8 *pCell = pPage->apOvfl[0];
70019 u16 szCell = pPage->xCellSize(pPage, pCell);
70020 u8 *pStop;
 
70021
70022 assert( sqlite3PagerIswriteable(pNew->pDbPage) );
70023 assert( pPage->aData[0]==(PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF) );
70024 zeroPage(pNew, PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF);
70025 rc = rebuildPage(pNew, 1, &pCell, &szCell);
70026 if( NEVER(rc) ) return rc;
 
 
 
 
 
 
 
 
 
70027 pNew->nFree = pBt->usableSize - pNew->cellOffset - 2 - szCell;
70028
70029 /* If this is an auto-vacuum database, update the pointer map
70030 ** with entries for the new page, and any pointer from the
70031 ** cell on the page to an overflow page. If either of these
@@ -70501,10 +70646,14 @@
70501 **
70502 */
70503 usableSpace = pBt->usableSize - 12 + leafCorrection;
70504 for(i=0; i<nOld; i++){
70505 MemPage *p = apOld[i];
 
 
 
 
70506 szNew[i] = usableSpace - p->nFree;
70507 for(j=0; j<p->nOverflow; j++){
70508 szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]);
70509 }
70510 cntNew[i] = cntOld[i];
@@ -71182,11 +71331,15 @@
71182 iAmt = nData;
71183 }
71184 if( memcmp(pDest, ((u8*)pX->pData) + iOffset, iAmt)!=0 ){
71185 int rc = sqlite3PagerWrite(pPage->pDbPage);
71186 if( rc ) return rc;
71187 memcpy(pDest, ((u8*)pX->pData) + iOffset, iAmt);
 
 
 
 
71188 }
71189 }
71190 return SQLITE_OK;
71191 }
71192
@@ -71596,10 +71749,11 @@
71596 ** from the internal node. The 'previous' entry is used for this instead
71597 ** of the 'next' entry, as the previous entry is always a part of the
71598 ** sub-tree headed by the child page of the cell being deleted. This makes
71599 ** balancing the tree following the delete operation easier. */
71600 if( !pPage->leaf ){
 
71601 rc = sqlite3BtreePrevious(pCur, 0);
71602 assert( rc!=SQLITE_DONE );
71603 if( rc ) return rc;
71604 }
71605
@@ -74199,11 +74353,11 @@
74199 **
74200 ** Return SQLITE_OK on success or an error code (probably SQLITE_NOMEM)
74201 ** if unable to complete the resizing.
74202 */
74203 SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize(Mem *pMem, int szNew){
74204 assert( szNew>0 );
74205 assert( (pMem->flags & MEM_Dyn)==0 || pMem->szMalloc==0 );
74206 if( pMem->szMalloc<szNew ){
74207 return sqlite3VdbeMemGrow(pMem, szNew, 0);
74208 }
74209 assert( (pMem->flags & MEM_Dyn)==0 );
@@ -75486,13 +75640,15 @@
75486 else if( op==TK_FUNCTION && pCtx!=0 ){
75487 rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx);
75488 }
75489 #endif
75490 else if( op==TK_TRUEFALSE ){
75491 pVal = valueNew(db, pCtx);
75492 pVal->flags = MEM_Int;
75493 pVal->u.i = pExpr->u.zToken[4]==0;
 
 
75494 }
75495
75496 *ppVal = pVal;
75497 return rc;
75498
@@ -76483,11 +76639,11 @@
76483 while( (pOp = opIterNext(&sIter))!=0 ){
76484 int opcode = pOp->opcode;
76485 if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename
76486 || opcode==OP_VDestroy
76487 || ((opcode==OP_Halt || opcode==OP_HaltIfNull)
76488 && ((pOp->p1&0xff)==SQLITE_CONSTRAINT && pOp->p2==OE_Abort))
76489 ){
76490 hasAbort = 1;
76491 break;
76492 }
76493 if( opcode==OP_CreateBtree && pOp->p3==BTREE_INTKEY ) hasCreateTable = 1;
@@ -79639,11 +79795,11 @@
79639 int nKey, /* Size of the binary record */
79640 const void *pKey, /* The binary record */
79641 UnpackedRecord *p /* Populate this structure before returning. */
79642 ){
79643 const unsigned char *aKey = (const unsigned char *)pKey;
79644 int d;
79645 u32 idx; /* Offset in aKey[] to read from */
79646 u16 u; /* Unsigned loop counter */
79647 u32 szHdr;
79648 Mem *pMem = p->aMem;
79649
@@ -79650,11 +79806,11 @@
79650 p->default_rc = 0;
79651 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
79652 idx = getVarint32(aKey, szHdr);
79653 d = szHdr;
79654 u = 0;
79655 while( idx<szHdr && d<=nKey ){
79656 u32 serial_type;
79657
79658 idx += getVarint32(&aKey[idx], serial_type);
79659 pMem->enc = pKeyInfo->enc;
79660 pMem->db = pKeyInfo->db;
@@ -79663,11 +79819,11 @@
79663 pMem->z = 0;
79664 d += sqlite3VdbeSerialGet(&aKey[d], serial_type, pMem);
79665 pMem++;
79666 if( (++u)>=p->nField ) break;
79667 }
79668 if( d>nKey && u ){
79669 assert( CORRUPT_DB );
79670 /* In a corrupt record entry, the last pMem might have been set up using
79671 ** uninitialized memory. Overwrite its value with NULL, to prevent
79672 ** warnings from MSAN. */
79673 sqlite3VdbeMemSetNull(pMem-1);
@@ -79747,11 +79903,12 @@
79747 */
79748 d1 += sqlite3VdbeSerialGet(&aKey1[d1], serial_type1, &mem1);
79749
79750 /* Do the comparison
79751 */
79752 rc = sqlite3MemCompare(&mem1, &pPKey2->aMem[i], pKeyInfo->aColl[i]);
 
79753 if( rc!=0 ){
79754 assert( mem1.szMalloc==0 ); /* See comment below */
79755 if( pKeyInfo->aSortOrder[i] ){
79756 rc = -rc; /* Invert the result for DESC sort order. */
79757 }
@@ -80178,14 +80335,16 @@
80178 rc = +1;
80179 }else{
80180 mem1.n = (serial_type - 12) / 2;
80181 testcase( (d1+mem1.n)==(unsigned)nKey1 );
80182 testcase( (d1+mem1.n+1)==(unsigned)nKey1 );
80183 if( (d1+mem1.n) > (unsigned)nKey1 ){
 
 
80184 pPKey2->errCode = (u8)SQLITE_CORRUPT_BKPT;
80185 return 0; /* Corruption */
80186 }else if( (pKeyInfo = pPKey2->pKeyInfo)->aColl[i] ){
80187 mem1.enc = pKeyInfo->enc;
80188 mem1.db = pKeyInfo->db;
80189 mem1.flags = MEM_Str;
80190 mem1.z = (char*)&aKey1[d1];
80191 rc = vdbeCompareMemString(
@@ -83382,10 +83541,11 @@
83382 ** accordingly.
83383 */
83384 static u16 SQLITE_NOINLINE computeNumericType(Mem *pMem){
83385 assert( (pMem->flags & (MEM_Int|MEM_Real))==0 );
83386 assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 );
 
83387 if( sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc)==0 ){
83388 return 0;
83389 }
83390 if( sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc)==0 ){
83391 return MEM_Int;
@@ -89257,10 +89417,21 @@
89257 memset(pFrame->aOnce, 0, (pProgram->nOp + 7)/8);
89258 p->aOp = aOp = pProgram->aOp;
89259 p->nOp = pProgram->nOp;
89260 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
89261 p->anExec = 0;
 
 
 
 
 
 
 
 
 
 
 
89262 #endif
89263 pOp = &aOp[-1];
89264
89265 break;
89266 }
@@ -94431,10 +94602,26 @@
94431 /* #include "sqliteInt.h" */
94432 /* #include <stdlib.h> */
94433 /* #include <string.h> */
94434
94435
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94436 /*
94437 ** Walk an expression tree. Invoke the callback once for each node
94438 ** of the expression, while descending. (In other words, the callback
94439 ** is invoked before visiting children.)
94440 **
@@ -94470,14 +94657,11 @@
94470 }else if( pExpr->x.pList ){
94471 if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
94472 }
94473 #ifndef SQLITE_OMIT_WINDOWFUNC
94474 if( ExprHasProperty(pExpr, EP_WinFunc) ){
94475 Window *pWin = pExpr->y.pWin;
94476 if( sqlite3WalkExprList(pWalker, pWin->pPartition) ) return WRC_Abort;
94477 if( sqlite3WalkExprList(pWalker, pWin->pOrderBy) ) return WRC_Abort;
94478 if( sqlite3WalkExpr(pWalker, pWin->pFilter) ) return WRC_Abort;
94479 }
94480 #endif
94481 }
94482 break;
94483 }
@@ -94513,10 +94697,20 @@
94513 if( sqlite3WalkExpr(pWalker, p->pWhere) ) return WRC_Abort;
94514 if( sqlite3WalkExprList(pWalker, p->pGroupBy) ) return WRC_Abort;
94515 if( sqlite3WalkExpr(pWalker, p->pHaving) ) return WRC_Abort;
94516 if( sqlite3WalkExprList(pWalker, p->pOrderBy) ) return WRC_Abort;
94517 if( sqlite3WalkExpr(pWalker, p->pLimit) ) return WRC_Abort;
 
 
 
 
 
 
 
 
 
 
94518 return WRC_Continue;
94519 }
94520
94521 /*
94522 ** Walk the parse trees associated with all subqueries in the
@@ -95442,14 +95636,14 @@
95442 sqlite3WalkExprList(pWalker, pList);
95443 if( is_agg ){
95444 #ifndef SQLITE_OMIT_WINDOWFUNC
95445 if( pExpr->y.pWin ){
95446 Select *pSel = pNC->pWinSelect;
 
95447 sqlite3WalkExprList(pWalker, pExpr->y.pWin->pPartition);
95448 sqlite3WalkExprList(pWalker, pExpr->y.pWin->pOrderBy);
95449 sqlite3WalkExpr(pWalker, pExpr->y.pWin->pFilter);
95450 sqlite3WindowUpdate(pParse, pSel->pWinDefn, pExpr->y.pWin, pDef);
95451 if( 0==pSel->pWin
95452 || 0==sqlite3WindowCompare(pParse, pSel->pWin, pExpr->y.pWin)
95453 ){
95454 pExpr->y.pWin->pNextWin = pSel->pWin;
95455 pSel->pWin = pExpr->y.pWin;
@@ -95744,38 +95938,35 @@
95744 }
95745 if( !db->mallocFailed ){
95746 assert(pDup);
95747 iCol = resolveOrderByTermToExprList(pParse, pSelect, pDup);
95748 }
95749 if( IN_RENAME_OBJECT ){
95750 if( iCol>0 ){
95751 pItem->done = 1;
95752 continue;
95753 }
95754 }else{
95755 sqlite3ExprDelete(db, pDup);
95756 }
95757 }
95758 }
95759 if( iCol>0 ){
95760 /* Convert the ORDER BY term into an integer column number iCol,
95761 ** taking care to preserve the COLLATE clause if it exists */
95762 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
95763 if( pNew==0 ) return 1;
95764 pNew->flags |= EP_IntValue;
95765 pNew->u.iValue = iCol;
95766 if( pItem->pExpr==pE ){
95767 pItem->pExpr = pNew;
95768 }else{
95769 Expr *pParent = pItem->pExpr;
95770 assert( pParent->op==TK_COLLATE );
95771 while( pParent->pLeft->op==TK_COLLATE ) pParent = pParent->pLeft;
95772 assert( pParent->pLeft==pE );
95773 pParent->pLeft = pNew;
95774 }
95775 sqlite3ExprDelete(db, pE);
95776 pItem->u.x.iOrderByCol = (u16)iCol;
 
 
95777 pItem->done = 1;
95778 }else{
95779 moreToDo = 1;
95780 }
95781 }
@@ -96119,10 +96310,21 @@
96119 "the GROUP BY clause");
96120 return WRC_Abort;
96121 }
96122 }
96123 }
 
 
 
 
 
 
 
 
 
 
 
96124
96125 /* If this is part of a compound SELECT, check that it has the right
96126 ** number of expressions in the select list. */
96127 if( p->pNext && p->pEList->nExpr!=p->pNext->pEList->nExpr ){
96128 sqlite3SelectWrongNumTermsError(pParse, p->pNext);
@@ -101683,10 +101885,11 @@
101683 w.xExprCallback = analyzeAggregate;
101684 w.xSelectCallback = analyzeAggregatesInSelect;
101685 w.xSelectCallback2 = analyzeAggregatesInSelectEnd;
101686 w.walkerDepth = 0;
101687 w.u.pNC = pNC;
 
101688 assert( pNC->pSrcList!=0 );
101689 sqlite3WalkExpr(&w, pExpr);
101690 }
101691
101692 /*
@@ -120153,22 +120356,26 @@
120153 /* ePragFlg: */ PragFlg_Result0,
120154 /* ColNames: */ 0, 0,
120155 /* iArg: */ 0 },
120156 #endif
120157 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
 
120158 {/* zName: */ "count_changes",
120159 /* ePragTyp: */ PragTyp_FLAG,
120160 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120161 /* ColNames: */ 0, 0,
120162 /* iArg: */ SQLITE_CountRows },
 
120163 #endif
120164 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
 
120165 {/* zName: */ "data_store_directory",
120166 /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY,
120167 /* ePragFlg: */ PragFlg_NoColumns1,
120168 /* ColNames: */ 0, 0,
120169 /* iArg: */ 0 },
 
120170 #endif
120171 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
120172 {/* zName: */ "data_version",
120173 /* ePragTyp: */ PragTyp_HEADER_VALUE,
120174 /* ePragFlg: */ PragFlg_ReadOnly|PragFlg_Result0,
@@ -120180,16 +120387,18 @@
120180 /* ePragTyp: */ PragTyp_DATABASE_LIST,
120181 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0,
120182 /* ColNames: */ 35, 3,
120183 /* iArg: */ 0 },
120184 #endif
120185 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
 
120186 {/* zName: */ "default_cache_size",
120187 /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE,
120188 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
120189 /* ColNames: */ 45, 1,
120190 /* iArg: */ 0 },
 
120191 #endif
120192 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120193 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
120194 {/* zName: */ "defer_foreign_keys",
120195 /* ePragTyp: */ PragTyp_FLAG,
@@ -120197,15 +120406,17 @@
120197 /* ColNames: */ 0, 0,
120198 /* iArg: */ SQLITE_DeferFKs },
120199 #endif
120200 #endif
120201 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
 
120202 {/* zName: */ "empty_result_callbacks",
120203 /* ePragTyp: */ PragTyp_FLAG,
120204 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120205 /* ColNames: */ 0, 0,
120206 /* iArg: */ SQLITE_NullCallback },
 
120207 #endif
120208 #if !defined(SQLITE_OMIT_UTF16)
120209 {/* zName: */ "encoding",
120210 /* ePragTyp: */ PragTyp_ENCODING,
120211 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
@@ -120241,15 +120452,19 @@
120241 /* ePragFlg: */ PragFlg_ReadOnly|PragFlg_Result0,
120242 /* ColNames: */ 0, 0,
120243 /* iArg: */ BTREE_FREE_PAGE_COUNT },
120244 #endif
120245 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
 
120246 {/* zName: */ "full_column_names",
120247 /* ePragTyp: */ PragTyp_FLAG,
120248 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120249 /* ColNames: */ 0, 0,
120250 /* iArg: */ SQLITE_FullColNames },
 
 
 
120251 {/* zName: */ "fullfsync",
120252 /* ePragTyp: */ PragTyp_FLAG,
120253 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120254 /* ColNames: */ 0, 0,
120255 /* iArg: */ SQLITE_FullFSync },
@@ -120472,15 +120687,17 @@
120472 /* ePragFlg: */ PragFlg_Result0,
120473 /* ColNames: */ 0, 0,
120474 /* iArg: */ 0 },
120475 #endif
120476 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
 
120477 {/* zName: */ "short_column_names",
120478 /* ePragTyp: */ PragTyp_FLAG,
120479 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120480 /* ColNames: */ 0, 0,
120481 /* iArg: */ SQLITE_ShortColNames },
 
120482 #endif
120483 {/* zName: */ "shrink_memory",
120484 /* ePragTyp: */ PragTyp_SHRINK_MEMORY,
120485 /* ePragFlg: */ PragFlg_NoColumns,
120486 /* ColNames: */ 0, 0,
@@ -120529,15 +120746,19 @@
120529 {/* zName: */ "temp_store",
120530 /* ePragTyp: */ PragTyp_TEMP_STORE,
120531 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120532 /* ColNames: */ 0, 0,
120533 /* iArg: */ 0 },
 
 
 
120534 {/* zName: */ "temp_store_directory",
120535 /* ePragTyp: */ PragTyp_TEMP_STORE_DIRECTORY,
120536 /* ePragFlg: */ PragFlg_NoColumns1,
120537 /* ColNames: */ 0, 0,
120538 /* iArg: */ 0 },
 
120539 #endif
120540 #if defined(SQLITE_HAS_CODEC)
120541 {/* zName: */ "textkey",
120542 /* ePragTyp: */ PragTyp_KEY,
120543 /* ePragFlg: */ 0,
@@ -126101,13 +126322,13 @@
126101
126102 savedFlags = db->flags;
126103 db->flags &= ~(u64)SQLITE_FullColNames;
126104 db->flags |= SQLITE_ShortColNames;
126105 sqlite3SelectPrep(pParse, pSelect, 0);
 
126106 if( pParse->nErr ) return 0;
126107 while( pSelect->pPrior ) pSelect = pSelect->pPrior;
126108 db->flags = savedFlags;
126109 pTab = sqlite3DbMallocZero(db, sizeof(Table) );
126110 if( pTab==0 ){
126111 return 0;
126112 }
126113 /* The sqlite3ResultSetOfSelect() is only used n contexts where lookaside
@@ -132377,10 +132598,11 @@
132377
132378 /* There is one entry in the aRegIdx[] array for each index on the table
132379 ** being updated. Fill in aRegIdx[] with a register number that will hold
132380 ** the key for accessing each index.
132381 */
 
132382 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
132383 int reg;
132384 if( chngKey || hasFK>1 || pIdx==pPk
132385 || indexWhereClauseMightChange(pIdx,aXRef,chngRowid)
132386 ){
@@ -132390,13 +132612,11 @@
132390 reg = 0;
132391 for(i=0; i<pIdx->nKeyCol; i++){
132392 if( indexColumnIsBeingUpdated(pIdx, i, aXRef, chngRowid) ){
132393 reg = ++pParse->nMem;
132394 pParse->nMem += pIdx->nColumn;
132395 if( (onError==OE_Replace)
132396 || (onError==OE_Default && pIdx->onError==OE_Replace)
132397 ){
132398 bReplace = 1;
132399 }
132400 break;
132401 }
132402 }
@@ -145794,10 +146014,11 @@
145794 VdbeCoverageIf(v, eCond==2);
145795 sqlite3VdbeAddOp3(v, aOp[eCond], regZero, sqlite3VdbeCurrentAddr(v)+2, reg);
145796 VdbeCoverageNeverNullIf(v, eCond==0);
145797 VdbeCoverageNeverNullIf(v, eCond==1);
145798 VdbeCoverageNeverNullIf(v, eCond==2);
 
145799 sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_ERROR, OE_Abort);
145800 sqlite3VdbeAppendP4(v, (void*)azErr[eCond], P4_STATIC);
145801 sqlite3ReleaseTempReg(pParse, regZero);
145802 }
145803
@@ -150949,12 +151170,14 @@
150949 ** expr1 NOT IN ()
150950 **
150951 ** simplify to constants 0 (false) and 1 (true), respectively,
150952 ** regardless of the value of expr1.
150953 */
150954 sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy490);
150955 yymsp[-4].minor.yy490 = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[yymsp[-3].minor.yy96],1);
 
 
150956 }else if( yymsp[-1].minor.yy42->nExpr==1 ){
150957 /* Expressions of the form:
150958 **
150959 ** expr1 IN (?1)
150960 ** expr1 NOT IN (?2)
@@ -158741,10 +158964,22 @@
158741 ** Terminator values for position-lists and column-lists.
158742 */
158743 #define POS_COLUMN (1) /* Column-list terminator */
158744 #define POS_END (0) /* Position-list terminator */
158745
 
 
 
 
 
 
 
 
 
 
 
 
158746 /*
158747 ** This section provides definitions to allow the
158748 ** FTS3 extension to be compiled outside of the
158749 ** amalgamation.
158750 */
@@ -159265,10 +159500,18 @@
159265 SQLITE_PRIVATE int sqlite3Fts3Always(int b) { assert( b ); return b; }
159266 SQLITE_PRIVATE int sqlite3Fts3Never(int b) { assert( !b ); return b; }
159267 # endif
159268 #endif
159269
 
 
 
 
 
 
 
 
159270 /*
159271 ** Write a 64-bit variable-length integer to memory starting at p[0].
159272 ** The length of data written will be between 1 and FTS3_VARINT_MAX bytes.
159273 ** The number of bytes written is returned.
159274 */
@@ -161493,11 +161736,11 @@
161493 ** docids to grow.
161494 **
161495 ** A symetric argument may be made if the doclists are in descending
161496 ** order.
161497 */
161498 aOut = sqlite3_malloc64((sqlite3_int64)n1+n2+FTS3_VARINT_MAX-1);
161499 if( !aOut ) return SQLITE_NOMEM;
161500
161501 p = aOut;
161502 fts3GetDeltaVarint3(&p1, pEnd1, 0, &i1);
161503 fts3GetDeltaVarint3(&p2, pEnd2, 0, &i2);
@@ -161522,14 +161765,16 @@
161522 }
161523
161524 if( rc!=SQLITE_OK ){
161525 sqlite3_free(aOut);
161526 p = aOut = 0;
 
 
 
161527 }
161528 *paOut = aOut;
161529 *pnOut = (int)(p-aOut);
161530 assert( *pnOut<=n1+n2+FTS3_VARINT_MAX-1 );
161531 return rc;
161532 }
161533
161534 /*
161535 ** This function does a "phrase" merge of two doclists. In a phrase merge,
@@ -162803,11 +163048,10 @@
162803 */
162804 static int fts3RollbackToMethod(sqlite3_vtab *pVtab, int iSavepoint){
162805 Fts3Table *p = (Fts3Table*)pVtab;
162806 UNUSED_PARAMETER(iSavepoint);
162807 assert( p->inTransaction );
162808 assert( p->mxSavepoint >= iSavepoint );
162809 TESTONLY( p->mxSavepoint = iSavepoint );
162810 sqlite3Fts3PendingTermsClear(p);
162811 return SQLITE_OK;
162812 }
162813
@@ -169623,11 +169867,11 @@
169623 int iLangid, /* Language id */
169624 int iIndex, /* Index in p->aIndex[] */
169625 int iLevel /* Level of segments */
169626 ){
169627 sqlite3_int64 iBase; /* First absolute level for iLangid/iIndex */
169628 assert( iLangid>=0 );
169629 assert( p->nIndex>0 );
169630 assert( iIndex>=0 && iIndex<p->nIndex );
169631
169632 iBase = ((sqlite3_int64)iLangid * p->nIndex + iIndex) * FTS3_SEGDIR_MAXLEVEL;
169633 return iBase + iLevel;
@@ -171310,10 +171554,15 @@
171310 }
171311 nData = pWriter->nData;
171312
171313 nPrefix = fts3PrefixCompress(pWriter->zTerm, pWriter->nTerm, zTerm, nTerm);
171314 nSuffix = nTerm-nPrefix;
 
 
 
 
 
171315
171316 /* Figure out how many bytes are required by this new entry */
171317 nReq = sqlite3Fts3VarintLen(nPrefix) + /* varint containing prefix size */
171318 sqlite3Fts3VarintLen(nSuffix) + /* varint containing suffix size */
171319 nSuffix + /* Term suffix */
@@ -199230,16 +199479,12 @@
199230 ** should be greater than or equal to zero and smaller than the value
199231 ** output by xInstCount().
199232 **
199233 ** Usually, output parameter *piPhrase is set to the phrase number, *piCol
199234 ** to the column in which it occurs and *piOff the token offset of the
199235 ** first token of the phrase. The exception is if the table was created
199236 ** with the offsets=0 option specified. In this case *piOff is always
199237 ** set to -1.
199238 **
199239 ** Returns SQLITE_OK if successful, or an error code (i.e. SQLITE_NOMEM)
199240 ** if an error occurs.
199241 **
199242 ** This API can be quite slow if used with an FTS5 table created with the
199243 ** "detail=none" or "detail=column" option.
199244 **
199245 ** xRowid:
@@ -199777,10 +200022,16 @@
199777 # define assert_nc(x) assert(sqlite3_fts5_may_be_corrupt || (x))
199778 #else
199779 # define assert_nc(x) assert(x)
199780 #endif
199781
 
 
 
 
 
 
199782 /* Mark a function parameter as unused, to suppress nuisance compiler
199783 ** warnings. */
199784 #ifndef UNUSED_PARAM
199785 # define UNUSED_PARAM(X) (void)(X)
199786 #endif
@@ -199964,11 +200215,11 @@
199964 /* Write and decode big-endian 32-bit integer values */
199965 static void sqlite3Fts5Put32(u8*, int);
199966 static int sqlite3Fts5Get32(const u8*);
199967
199968 #define FTS5_POS2COLUMN(iPos) (int)(iPos >> 32)
199969 #define FTS5_POS2OFFSET(iPos) (int)(iPos & 0xFFFFFFFF)
199970
199971 typedef struct Fts5PoslistReader Fts5PoslistReader;
199972 struct Fts5PoslistReader {
199973 /* Variables used only by sqlite3Fts5PoslistIterXXX() functions. */
199974 const u8 *a; /* Position list to iterate through */
@@ -202320,25 +202571,26 @@
202320 int iOff = 0;
202321 int iFirst = -1;
202322 int nInst;
202323 int nScore = 0;
202324 int iLast = 0;
 
202325
202326 rc = pApi->xInstCount(pFts, &nInst);
202327 for(i=0; i<nInst && rc==SQLITE_OK; i++){
202328 rc = pApi->xInst(pFts, i, &ip, &ic, &iOff);
202329 if( rc==SQLITE_OK && ic==iCol && iOff>=iPos && iOff<(iPos+nToken) ){
202330 nScore += (aSeen[ip] ? 1 : 1000);
202331 aSeen[ip] = 1;
202332 if( iFirst<0 ) iFirst = iOff;
202333 iLast = iOff + pApi->xPhraseSize(pFts, ip);
202334 }
202335 }
202336
202337 *pnScore = nScore;
202338 if( piPos ){
202339 int iAdj = iFirst - (nToken - (iLast-iFirst)) / 2;
202340 if( (iAdj+nToken)>nDocsize ) iAdj = nDocsize - nToken;
202341 if( iAdj<0 ) iAdj = 0;
202342 *piPos = iAdj;
202343 }
202344
@@ -202882,11 +203134,11 @@
202882 if( iVal==1 ){
202883 fts5FastGetVarint32(a, i, iVal);
202884 iOff = ((i64)iVal) << 32;
202885 fts5FastGetVarint32(a, i, iVal);
202886 }
202887 *piOff = iOff + (iVal-2);
202888 *pi = i;
202889 return 0;
202890 }
202891 }
202892
@@ -208054,11 +208306,11 @@
208054 **
208055 ** res = *pLeft - *pRight
208056 */
208057 static int fts5BufferCompare(Fts5Buffer *pLeft, Fts5Buffer *pRight){
208058 int nCmp = MIN(pLeft->n, pRight->n);
208059 int res = memcmp(pLeft->p, pRight->p, nCmp);
208060 return (res==0 ? (pLeft->n - pRight->n) : res);
208061 }
208062
208063 static int fts5LeafFirstTermOff(Fts5Data *pLeaf){
208064 int ret;
@@ -209982,11 +210234,11 @@
209982 assert( pRes->iFirst==i2 );
209983 }else if( p2->pLeaf==0 ){
209984 assert( pRes->iFirst==i1 );
209985 }else{
209986 int nMin = MIN(p1->term.n, p2->term.n);
209987 int res = memcmp(p1->term.p, p2->term.p, nMin);
209988 if( res==0 ) res = p1->term.n - p2->term.n;
209989
209990 if( res==0 ){
209991 assert( pRes->bTermEq==1 );
209992 assert( p1->iRowid!=p2->iRowid );
@@ -211028,11 +211280,11 @@
211028 u32 mask;
211029 memset(aUsed, 0, sizeof(aUsed));
211030 for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
211031 for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
211032 int iId = pStruct->aLevel[iLvl].aSeg[iSeg].iSegid;
211033 if( iId<=FTS5_MAX_SEGMENT ){
211034 aUsed[(iId-1) / 32] |= (u32)1 << ((iId-1) % 32);
211035 }
211036 }
211037 }
211038
@@ -211575,11 +211827,11 @@
211575 */
211576 static void fts5TrimSegments(Fts5Index *p, Fts5Iter *pIter){
211577 int i;
211578 Fts5Buffer buf;
211579 memset(&buf, 0, sizeof(Fts5Buffer));
211580 for(i=0; i<pIter->nSeg; i++){
211581 Fts5SegIter *pSeg = &pIter->aSeg[i];
211582 if( pSeg->pSeg==0 ){
211583 /* no-op */
211584 }else if( pSeg->pLeaf==0 ){
211585 /* All keys from this input segment have been transfered to the output.
@@ -211595,37 +211847,45 @@
211595 u8 aHdr[4] = {0x00, 0x00, 0x00, 0x00};
211596
211597 iLeafRowid = FTS5_SEGMENT_ROWID(iId, pSeg->iTermLeafPgno);
211598 pData = fts5DataRead(p, iLeafRowid);
211599 if( pData ){
211600 fts5BufferZero(&buf);
211601 fts5BufferGrow(&p->rc, &buf, pData->nn);
211602 fts5BufferAppendBlob(&p->rc, &buf, sizeof(aHdr), aHdr);
211603 fts5BufferAppendVarint(&p->rc, &buf, pSeg->term.n);
211604 fts5BufferAppendBlob(&p->rc, &buf, pSeg->term.n, pSeg->term.p);
211605 fts5BufferAppendBlob(&p->rc, &buf, pData->szLeaf-iOff, &pData->p[iOff]);
211606 if( p->rc==SQLITE_OK ){
211607 /* Set the szLeaf field */
211608 fts5PutU16(&buf.p[2], (u16)buf.n);
211609 }
211610
211611 /* Set up the new page-index array */
211612 fts5BufferAppendVarint(&p->rc, &buf, 4);
211613 if( pSeg->iLeafPgno==pSeg->iTermLeafPgno
211614 && pSeg->iEndofDoclist<pData->szLeaf
211615 ){
211616 int nDiff = pData->szLeaf - pSeg->iEndofDoclist;
211617 fts5BufferAppendVarint(&p->rc, &buf, buf.n - 1 - nDiff - 4);
211618 fts5BufferAppendBlob(&p->rc, &buf,
211619 pData->nn - pSeg->iPgidxOff, &pData->p[pSeg->iPgidxOff]
211620 );
211621 }
211622
211623 fts5DataRelease(pData);
211624 pSeg->pSeg->pgnoFirst = pSeg->iTermLeafPgno;
211625 fts5DataDelete(p, FTS5_SEGMENT_ROWID(iId, 1), iLeafRowid);
211626 fts5DataWrite(p, iLeafRowid, buf.p, buf.n);
 
 
 
 
 
 
 
 
211627 }
211628 }
211629 }
211630 fts5BufferFree(&buf);
211631 }
@@ -211713,11 +211973,11 @@
211713 int nPos; /* position-list size field value */
211714 int nTerm;
211715 const u8 *pTerm;
211716
211717 pTerm = fts5MultiIterTerm(pIter, &nTerm);
211718 if( nTerm!=term.n || memcmp(pTerm, term.p, nTerm) ){
211719 if( pnRem && writer.nLeafWritten>nRem ){
211720 break;
211721 }
211722 fts5BufferSet(&p->rc, &term, nTerm, pTerm);
211723 bTermWritten =0;
@@ -212469,10 +212729,11 @@
212469 /* WRITEPOSLISTSIZE */
212470 fts5BufferSafeAppendVarint(&out, tmp.n * 2);
212471 fts5BufferSafeAppendBlob(&out, tmp.p, tmp.n);
212472 fts5DoclistIterNext(&i1);
212473 fts5DoclistIterNext(&i2);
 
212474 if( i1.aPoslist==0 || i2.aPoslist==0 ) break;
212475 }
212476 }
212477
212478 if( i1.aPoslist ){
@@ -212570,11 +212831,11 @@
212570 }
212571 fts5BufferFree(&aBuf[i]);
212572 }
212573 fts5MultiIterFree(p1);
212574
212575 pData = fts5IdxMalloc(p, sizeof(Fts5Data) + doclist.n);
212576 if( pData ){
212577 pData->p = (u8*)&pData[1];
212578 pData->nn = pData->szLeaf = doclist.n;
212579 if( doclist.n ) memcpy(pData->p, doclist.p, doclist.n);
212580 fts5MultiIterNew2(p, pData, bDesc, ppIter);
@@ -213336,11 +213597,11 @@
213336 iRowidOff = fts5LeafFirstRowidOff(pLeaf);
213337 if( iRowidOff>=iOff || iOff>=pLeaf->szLeaf ){
213338 p->rc = FTS5_CORRUPT;
213339 }else{
213340 iOff += fts5GetVarint32(&pLeaf->p[iOff], nTerm);
213341 res = memcmp(&pLeaf->p[iOff], zIdxTerm, MIN(nTerm, nIdxTerm));
213342 if( res==0 ) res = nTerm - nIdxTerm;
213343 if( res<0 ) p->rc = FTS5_CORRUPT;
213344 }
213345
213346 fts5IntegrityCheckPgidx(p, pLeaf);
@@ -215772,10 +216033,11 @@
215772 */
215773 static int fts5CacheInstArray(Fts5Cursor *pCsr){
215774 int rc = SQLITE_OK;
215775 Fts5PoslistReader *aIter; /* One iterator for each phrase */
215776 int nIter; /* Number of iterators/phrases */
 
215777
215778 nIter = sqlite3Fts5ExprPhraseCount(pCsr->pExpr);
215779 if( pCsr->aInstIter==0 ){
215780 sqlite3_int64 nByte = sizeof(Fts5PoslistReader) * nIter;
215781 pCsr->aInstIter = (Fts5PoslistReader*)sqlite3Fts5MallocZero(&rc, nByte);
@@ -215825,10 +216087,14 @@
215825
215826 aInst = &pCsr->aInst[3 * (nInst-1)];
215827 aInst[0] = iBest;
215828 aInst[1] = FTS5_POS2COLUMN(aIter[iBest].iPos);
215829 aInst[2] = FTS5_POS2OFFSET(aIter[iBest].iPos);
 
 
 
 
215830 sqlite3Fts5PoslistReaderNext(&aIter[iBest]);
215831 }
215832 }
215833
215834 pCsr->nInstCount = nInst;
@@ -216636,11 +216902,11 @@
216636 int nArg, /* Number of args */
216637 sqlite3_value **apUnused /* Function arguments */
216638 ){
216639 assert( nArg==0 );
216640 UNUSED_PARAM2(nArg, apUnused);
216641 sqlite3_result_text(pCtx, "fts5: 2019-01-21 16:12:20 6c33a303ebbb0f5193ead535280ba63118e14fb4f9977ce80dc716a0b082ec99", -1, SQLITE_TRANSIENT);
216642 }
216643
216644 /*
216645 ** Return true if zName is the extension on one of the shadow tables used
216646 ** by this module.
@@ -221399,12 +221665,12 @@
221399 }
221400 #endif /* SQLITE_CORE */
221401 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
221402
221403 /************** End of stmt.c ************************************************/
221404 #if __LINE__!=221404
221405 #undef SQLITE_SOURCE_ID
221406 #define SQLITE_SOURCE_ID "2019-01-21 17:57:31 505ed9a47825240979338a24044559613fbbd2a7850bdff70c7164da054ealt2"
221407 #endif
221408 /* Return the source-id for this library */
221409 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
221410 /************************** End of sqlite3.c ******************************/
221411
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1162,11 +1162,11 @@
1162 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1163 ** [sqlite_version()] and [sqlite_source_id()].
1164 */
1165 #define SQLITE_VERSION "3.27.0"
1166 #define SQLITE_VERSION_NUMBER 3027000
1167 #define SQLITE_SOURCE_ID "2019-01-27 02:45:32 9cf8ebd141aa2eb661d457624c76433bd9e4abfdef04aa52e28bc169172calt1"
1168
1169 /*
1170 ** CAPI3REF: Run-Time Library Version Numbers
1171 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1172 **
@@ -1860,10 +1860,19 @@
1860 ** current transaction. This hint is not guaranteed to be accurate but it
1861 ** is often close. The underlying VFS might choose to preallocate database
1862 ** file space based on this hint in order to help writes to the database
1863 ** file run faster.
1864 **
1865 ** <li>[[SQLITE_FCNTL_SIZE_LIMIT]]
1866 ** The [SQLITE_FCNTL_SIZE_LIMIT] opcode is used by in-memory VFS that
1867 ** implements [sqlite3_deserialize()] to set an upper bound on the size
1868 ** of the in-memory database. The argument is a pointer to a [sqlite3_int64].
1869 ** If the integer pointed to is negative, then it is filled in with the
1870 ** current limit. Otherwise the limit is set to the larger of the value
1871 ** of the integer pointed to and the current database size. The integer
1872 ** pointed to is set to the new limit.
1873 **
1874 ** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]
1875 ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
1876 ** extends and truncates the database file in chunks of a size specified
1877 ** by the user. The fourth argument to [sqlite3_file_control()] should
1878 ** point to an integer (type int) containing the new chunk-size to use
@@ -2168,10 +2177,11 @@
2177 #define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 31
2178 #define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32
2179 #define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33
2180 #define SQLITE_FCNTL_LOCK_TIMEOUT 34
2181 #define SQLITE_FCNTL_DATA_VERSION 35
2182 #define SQLITE_FCNTL_SIZE_LIMIT 36
2183
2184 /* deprecated names */
2185 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
2186 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
2187 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -12272,16 +12282,12 @@
12282 ** should be greater than or equal to zero and smaller than the value
12283 ** output by xInstCount().
12284 **
12285 ** Usually, output parameter *piPhrase is set to the phrase number, *piCol
12286 ** to the column in which it occurs and *piOff the token offset of the
12287 ** first token of the phrase. Returns SQLITE_OK if successful, or an error
12288 ** code (i.e. SQLITE_NOMEM) if an error occurs.
 
 
 
 
12289 **
12290 ** This API can be quite slow if used with an FTS5 table created with the
12291 ** "detail=none" or "detail=column" option.
12292 **
12293 ** xRowid:
@@ -46564,16 +46570,22 @@
46570
46571 /* An open file */
46572 struct MemFile {
46573 sqlite3_file base; /* IO methods */
46574 sqlite3_int64 sz; /* Size of the file */
46575 sqlite3_int64 szAlloc; /* Space allocated to aData */
46576 sqlite3_int64 szMax; /* Maximum allowed size of the file */
46577 unsigned char *aData; /* content of the file */
46578 int nMmap; /* Number of memory mapped pages */
46579 unsigned mFlags; /* Flags */
46580 int eLock; /* Most recent lock against this file */
46581 };
46582
46583 /* The default maximum size of an in-memory database */
46584 #ifndef SQLITE_MEMDB_DEFAULT_MAXSIZE
46585 # define SQLITE_MEMDB_DEFAULT_MAXSIZE 1073741824
46586 #endif
46587
46588 /*
46589 ** Methods for MemFile
46590 */
46591 static int memdbClose(sqlite3_file*);
@@ -46690,14 +46702,19 @@
46702 static int memdbEnlarge(MemFile *p, sqlite3_int64 newSz){
46703 unsigned char *pNew;
46704 if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || p->nMmap>0 ){
46705 return SQLITE_FULL;
46706 }
46707 if( newSz>p->szMax ){
46708 return SQLITE_FULL;
46709 }
46710 newSz *= 2;
46711 if( newSz>p->szMax ) newSz = p->szMax;
46712 pNew = sqlite3_realloc64(p->aData, newSz);
46713 if( pNew==0 ) return SQLITE_NOMEM;
46714 p->aData = pNew;
46715 p->szAlloc = newSz;
46716 return SQLITE_OK;
46717 }
46718
46719 /*
46720 ** Write data to an memdb-file.
@@ -46707,14 +46724,15 @@
46724 const void *z,
46725 int iAmt,
46726 sqlite_int64 iOfst
46727 ){
46728 MemFile *p = (MemFile *)pFile;
46729 if( NEVER(p->mFlags & SQLITE_DESERIALIZE_READONLY) ) return SQLITE_READONLY;
46730 if( iOfst+iAmt>p->sz ){
46731 int rc;
46732 if( iOfst+iAmt>p->szAlloc
46733 && (rc = memdbEnlarge(p, iOfst+iAmt))!=SQLITE_OK
46734 ){
46735 return rc;
46736 }
46737 if( iOfst>p->sz ) memset(p->aData+p->sz, 0, iOfst-p->sz);
46738 p->sz = iOfst+iAmt;
@@ -46756,10 +46774,15 @@
46774 /*
46775 ** Lock an memdb-file.
46776 */
46777 static int memdbLock(sqlite3_file *pFile, int eLock){
46778 MemFile *p = (MemFile *)pFile;
46779 if( eLock>SQLITE_LOCK_SHARED
46780 && (p->mFlags & SQLITE_DESERIALIZE_READONLY)!=0
46781 ){
46782 return SQLITE_READONLY;
46783 }
46784 p->eLock = eLock;
46785 return SQLITE_OK;
46786 }
46787
46788 #if 0 /* Never used because memdbAccess() always returns false */
@@ -46779,10 +46802,23 @@
46802 MemFile *p = (MemFile *)pFile;
46803 int rc = SQLITE_NOTFOUND;
46804 if( op==SQLITE_FCNTL_VFSNAME ){
46805 *(char**)pArg = sqlite3_mprintf("memdb(%p,%lld)", p->aData, p->sz);
46806 rc = SQLITE_OK;
46807 }
46808 if( op==SQLITE_FCNTL_SIZE_LIMIT ){
46809 sqlite3_int64 iLimit = *(sqlite3_int64*)pArg;
46810 if( iLimit<p->sz ){
46811 if( iLimit<0 ){
46812 iLimit = p->szMax;
46813 }else{
46814 iLimit = p->sz;
46815 }
46816 }
46817 p->szMax = iLimit;
46818 *(sqlite3_int64*)pArg = iLimit;
46819 rc = SQLITE_OK;
46820 }
46821 return rc;
46822 }
46823
46824 #if 0 /* Not used because of SQLITE_IOCAP_POWERSAFE_OVERWRITE */
@@ -46810,12 +46846,17 @@
46846 sqlite3_int64 iOfst,
46847 int iAmt,
46848 void **pp
46849 ){
46850 MemFile *p = (MemFile *)pFile;
46851 if( iOfst+iAmt>p->sz ){
46852 assert( CORRUPT_DB );
46853 *pp = 0;
46854 }else{
46855 p->nMmap++;
46856 *pp = (void*)(p->aData + iOfst);
46857 }
46858 return SQLITE_OK;
46859 }
46860
46861 /* Release a memory-mapped page */
46862 static int memdbUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){
@@ -46841,10 +46882,11 @@
46882 memset(p, 0, sizeof(*p));
46883 p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE;
46884 assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */
46885 *pOutFlags = flags | SQLITE_OPEN_MEMORY;
46886 p->base.pMethods = &memdb_io_methods;
46887 p->szMax = SQLITE_MEMDB_DEFAULT_MAXSIZE;
46888 return SQLITE_OK;
46889 }
46890
46891 #if 0 /* Only used to delete rollback journals, master journals, and WAL
46892 ** files, none of which exist in memdb. So this routine is never used */
@@ -47090,11 +47132,15 @@
47132 if( p==0 ){
47133 rc = SQLITE_ERROR;
47134 }else{
47135 p->aData = pData;
47136 p->sz = szDb;
47137 p->szAlloc = szBuf;
47138 p->szMax = szBuf;
47139 if( p->szMax<SQLITE_MEMDB_DEFAULT_MAXSIZE ){
47140 p->szMax = SQLITE_MEMDB_DEFAULT_MAXSIZE;
47141 }
47142 p->mFlags = mFlags;
47143 rc = SQLITE_OK;
47144 }
47145
47146 end_deserialize:
@@ -63737,15 +63783,16 @@
63783 ){
63784 int rc; /* Status code */
63785 UnpackedRecord *pIdxKey; /* Unpacked index key */
63786
63787 if( pKey ){
63788 KeyInfo *pKeyInfo = pCur->pKeyInfo;
63789 assert( nKey==(i64)(int)nKey );
63790 pIdxKey = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
63791 if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT;
63792 sqlite3VdbeRecordUnpack(pKeyInfo, (int)nKey, pKey, pIdxKey);
63793 if( pIdxKey->nField==0 || pIdxKey->nField>pKeyInfo->nAllField ){
63794 rc = SQLITE_CORRUPT_BKPT;
63795 goto moveto_done;
63796 }
63797 }else{
63798 pIdxKey = 0;
@@ -68408,11 +68455,11 @@
68455 nCell = (int)pCur->info.nKey;
68456 testcase( nCell<0 ); /* True if key size is 2^32 or more */
68457 testcase( nCell==0 ); /* Invalid key size: 0x80 0x80 0x00 */
68458 testcase( nCell==1 ); /* Invalid key size: 0x80 0x80 0x01 */
68459 testcase( nCell==2 ); /* Minimum legal index key size */
68460 if( nCell<2 || nCell/pCur->pBt->usableSize>pCur->pBt->nPage ){
68461 rc = SQLITE_CORRUPT_PAGE(pPage);
68462 goto moveto_finish;
68463 }
68464 pCellKey = sqlite3Malloc( nCell+18 );
68465 if( pCellKey==0 ){
@@ -69042,11 +69089,11 @@
69089 *ppPage = 0;
69090 }
69091 TRACE(("ALLOCATE: %d from end of file\n", *pPgno));
69092 }
69093
69094 assert( CORRUPT_DB || *pPgno!=PENDING_BYTE_PAGE(pBt) );
69095
69096 end_allocate_page:
69097 releasePage(pTrunk);
69098 releasePage(pPrevTrunk);
69099 assert( rc!=SQLITE_OK || sqlite3PagerPageRefcount((*ppPage)->pDbPage)<=1 );
@@ -69626,20 +69673,85 @@
69673 }
69674 #endif
69675 }
69676 }
69677
69678 /*
69679 ** The following parameters determine how many adjacent pages get involved
69680 ** in a balancing operation. NN is the number of neighbors on either side
69681 ** of the page that participate in the balancing operation. NB is the
69682 ** total number of pages that participate, including the target page and
69683 ** NN neighbors on either side.
69684 **
69685 ** The minimum value of NN is 1 (of course). Increasing NN above 1
69686 ** (to 2 or 3) gives a modest improvement in SELECT and DELETE performance
69687 ** in exchange for a larger degradation in INSERT and UPDATE performance.
69688 ** The value of NN appears to give the best results overall.
69689 **
69690 ** (Later:) The description above makes it seem as if these values are
69691 ** tunable - as if you could change them and recompile and it would all work.
69692 ** But that is unlikely. NB has been 3 since the inception of SQLite and
69693 ** we have never tested any other value.
69694 */
69695 #define NN 1 /* Number of neighbors on either side of pPage */
69696 #define NB 3 /* (NN*2+1): Total pages involved in the balance */
69697
69698 /*
69699 ** A CellArray object contains a cache of pointers and sizes for a
69700 ** consecutive sequence of cells that might be held on multiple pages.
69701 **
69702 ** The cells in this array are the divider cell or cells from the pParent
69703 ** page plus up to three child pages. There are a total of nCell cells.
69704 **
69705 ** pRef is a pointer to one of the pages that contributes cells. This is
69706 ** used to access information such as MemPage.intKey and MemPage.pBt->pageSize
69707 ** which should be common to all pages that contribute cells to this array.
69708 **
69709 ** apCell[] and szCell[] hold, respectively, pointers to the start of each
69710 ** cell and the size of each cell. Some of the apCell[] pointers might refer
69711 ** to overflow cells. In other words, some apCel[] pointers might not point
69712 ** to content area of the pages.
69713 **
69714 ** A szCell[] of zero means the size of that cell has not yet been computed.
69715 **
69716 ** The cells come from as many as four different pages:
69717 **
69718 ** -----------
69719 ** | Parent |
69720 ** -----------
69721 ** / | \
69722 ** / | \
69723 ** --------- --------- ---------
69724 ** |Child-1| |Child-2| |Child-3|
69725 ** --------- --------- ---------
69726 **
69727 ** The order of cells is in the array is:
69728 **
69729 ** 1. All cells from Child-1 in order
69730 ** 2. The first divider cell from Parent
69731 ** 3. All cells from Child-2 in order
69732 ** 4. The second divider cell from Parent
69733 ** 5. All cells from Child-3 in order
69734 **
69735 ** The apEnd[] array holds pointer to the end of page for Child-1, the
69736 ** Parent, Child-2, the Parent (again), and Child-3. The ixNx[] array
69737 ** holds the number of cells contained in each of these 5 stages, and
69738 ** all stages to the left. Hence:
69739 ** ixNx[0] = Number of cells in Child-1.
69740 ** ixNx[1] = Number of cells in Child-1 plus 1 for first divider.
69741 ** ixNx[2] = Number of cells in Child-1 and Child-2 + 1 for 1st divider.
69742 ** ixNx[3] = Number of cells in Child-1 and Child-2 + both divider cells
69743 ** ixNx[4] = Total number of cells.
69744 */
69745 typedef struct CellArray CellArray;
69746 struct CellArray {
69747 int nCell; /* Number of cells in apCell[] */
69748 MemPage *pRef; /* Reference page */
69749 u8 **apCell; /* All cells begin balanced */
69750 u16 *szCell; /* Local size of all cells in apCell[] */
69751 u8 *apEnd[NB*2]; /* MemPage.aDataEnd values */
69752 int ixNx[NB*2]; /* Index of at which we move to the next apEnd[] */
69753 };
69754
69755 /*
69756 ** Make sure the cell sizes at idx, idx+1, ..., idx+N-1 have been
69757 ** computed.
@@ -69686,41 +69798,62 @@
69798 **
69799 ** The MemPage.nFree field is invalidated by this function. It is the
69800 ** responsibility of the caller to set it correctly.
69801 */
69802 static int rebuildPage(
69803 CellArray *pCArray, /* Content to be added to page pPg */
69804 int iFirst, /* First cell in pCArray to use */
69805 int nCell, /* Final number of cells on page */
69806 MemPage *pPg /* The page to be reconstructed */
 
69807 ){
69808 const int hdr = pPg->hdrOffset; /* Offset of header on pPg */
69809 u8 * const aData = pPg->aData; /* Pointer to data for pPg */
69810 const int usableSize = pPg->pBt->usableSize;
69811 u8 * const pEnd = &aData[usableSize];
69812 int i = iFirst; /* Which cell to copy from pCArray*/
69813 int j; /* Start of cell content area */
69814 int iEnd = i+nCell; /* Loop terminator */
69815 u8 *pCellptr = pPg->aCellIdx;
69816 u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
69817 u8 *pData;
69818 int k; /* Current slot in pCArray->apEnd[] */
69819 u8 *pSrcEnd; /* Current pCArray->apEnd[k] value */
69820
69821 assert( i<iEnd );
69822 j = get2byte(&aData[hdr+5]);
69823 memcpy(&pTmp[j], &aData[j], usableSize - j);
69824
69825 for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
69826 pSrcEnd = pCArray->apEnd[k];
69827
69828 pData = pEnd;
69829 while( 1/*exit by break*/ ){
69830 u8 *pCell = pCArray->apCell[i];
69831 u16 sz = pCArray->szCell[i];
69832 assert( sz>0 );
69833 if( SQLITE_WITHIN(pCell,aData,pEnd) ){
69834 if( ((uptr)(pCell+sz))>(uptr)pEnd ) return SQLITE_CORRUPT_BKPT;
69835 pCell = &pTmp[pCell - aData];
69836 }else if( (uptr)(pCell+sz)>(uptr)pSrcEnd
69837 && (uptr)(pCell)<(uptr)pSrcEnd
69838 ){
69839 return SQLITE_CORRUPT_BKPT;
69840 }
69841
69842 pData -= sz;
69843 put2byte(pCellptr, (pData - aData));
69844 pCellptr += 2;
69845 if( pData < pCellptr ) return SQLITE_CORRUPT_BKPT;
69846 memcpy(pData, pCell, sz);
69847 assert( sz==pPg->xCellSize(pPg, pCell) || CORRUPT_DB );
69848 testcase( sz!=pPg->xCellSize(pPg,pCell) );
69849 i++;
69850 if( i>=iEnd ) break;
69851 if( pCArray->ixNx[k]<=i ){
69852 k++;
69853 pSrcEnd = pCArray->apEnd[k];
69854 }
69855 }
69856
69857 /* The pPg->nFree field is now set incorrectly. The caller will fix it. */
69858 pPg->nCell = nCell;
69859 pPg->nOverflow = 0;
@@ -69731,16 +69864,15 @@
69864 aData[hdr+7] = 0x00;
69865 return SQLITE_OK;
69866 }
69867
69868 /*
69869 ** The pCArray objects contains pointers to b-tree cells and the cell sizes.
69870 ** This function attempts to add the cells stored in the array to page pPg.
69871 ** If it cannot (because the page needs to be defragmented before the cells
69872 ** will fit), non-zero is returned. Otherwise, if the cells are added
69873 ** successfully, zero is returned.
 
69874 **
69875 ** Argument pCellptr points to the first entry in the cell-pointer array
69876 ** (part of page pPg) to populate. After cell apCell[0] is written to the
69877 ** page body, a 16-bit offset is written to pCellptr. And so on, for each
69878 ** cell in the array. It is the responsibility of the caller to ensure
@@ -69758,22 +69890,27 @@
69890 ** cells in apCell[], then the cells do not fit and non-zero is returned.
69891 */
69892 static int pageInsertArray(
69893 MemPage *pPg, /* Page to add cells to */
69894 u8 *pBegin, /* End of cell-pointer array */
69895 u8 **ppData, /* IN/OUT: Page content-area pointer */
69896 u8 *pCellptr, /* Pointer to cell-pointer area */
69897 int iFirst, /* Index of first cell to add */
69898 int nCell, /* Number of cells to add to pPg */
69899 CellArray *pCArray /* Array of cells */
69900 ){
69901 int i = iFirst; /* Loop counter - cell index to insert */
69902 u8 *aData = pPg->aData; /* Complete page */
69903 u8 *pData = *ppData; /* Content area. A subset of aData[] */
69904 int iEnd = iFirst + nCell; /* End of loop. One past last cell to ins */
69905 int k; /* Current slot in pCArray->apEnd[] */
69906 u8 *pEnd; /* Maximum extent of cell data */
69907 assert( CORRUPT_DB || pPg->hdrOffset==0 ); /* Never called on page 1 */
69908 if( iEnd<=iFirst ) return 0;
69909 for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
69910 pEnd = pCArray->apEnd[k];
69911 while( 1 /*Exit by break*/ ){
69912 int sz, rc;
69913 u8 *pSlot;
69914 sz = cachedCellSize(pCArray, i);
69915 if( (aData[1]==0 && aData[2]==0) || (pSlot = pageFindSlot(pPg,sz,&rc))==0 ){
69916 if( (pData - pBegin)<sz ) return 1;
@@ -69784,24 +69921,37 @@
69921 ** database. But they might for a corrupt database. Hence use memmove()
69922 ** since memcpy() sends SIGABORT with overlapping buffers on OpenBSD */
69923 assert( (pSlot+sz)<=pCArray->apCell[i]
69924 || pSlot>=(pCArray->apCell[i]+sz)
69925 || CORRUPT_DB );
69926 if( (uptr)(pCArray->apCell[i]+sz)>(uptr)pEnd
69927 && (uptr)(pCArray->apCell[i])<(uptr)pEnd
69928 ){
69929 assert( CORRUPT_DB );
69930 (void)SQLITE_CORRUPT_BKPT;
69931 return 1;
69932 }
69933 memmove(pSlot, pCArray->apCell[i], sz);
69934 put2byte(pCellptr, (pSlot - aData));
69935 pCellptr += 2;
69936 i++;
69937 if( i>=iEnd ) break;
69938 if( pCArray->ixNx[k]<=i ){
69939 k++;
69940 pEnd = pCArray->apEnd[k];
69941 }
69942 }
69943 *ppData = pData;
69944 return 0;
69945 }
69946
69947 /*
69948 ** The pCArray object contains pointers to b-tree cells and their sizes.
69949 **
69950 ** This function adds the space associated with each cell in the array
69951 ** that is currently stored within the body of pPg to the pPg free-list.
69952 ** The cell-pointers and other fields of the page are not updated.
69953 **
69954 ** This function returns the total number of cells added to the free-list.
69955 */
69956 static int pageFreeArray(
69957 MemPage *pPg, /* Page to edit */
@@ -69847,13 +69997,13 @@
69997 }
69998 return nRet;
69999 }
70000
70001 /*
70002 ** pCArray contains pointers to and sizes of all cells in the pages being
70003 ** balanced. The current page, pPg, has pPg->nCell cells starting with
70004 ** pCArray->apCell[iOld]. After balancing, this page should hold nNew cells
70005 ** starting at apCell[iNew].
70006 **
70007 ** This routine makes the necessary adjustments to pPg so that it contains
70008 ** the correct cells after being balanced.
70009 **
@@ -69949,27 +70099,12 @@
70099
70100 return SQLITE_OK;
70101 editpage_fail:
70102 /* Unable to edit this page. Rebuild it from scratch instead. */
70103 populateCellCache(pCArray, iNew, nNew);
70104 return rebuildPage(pCArray, iNew, nNew, pPg);
70105 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70106
70107
70108 #ifndef SQLITE_OMIT_QUICKBALANCE
70109 /*
70110 ** This version of balance() handles the common special case where
@@ -70016,16 +70151,26 @@
70151
70152 u8 *pOut = &pSpace[4];
70153 u8 *pCell = pPage->apOvfl[0];
70154 u16 szCell = pPage->xCellSize(pPage, pCell);
70155 u8 *pStop;
70156 CellArray b;
70157
70158 assert( sqlite3PagerIswriteable(pNew->pDbPage) );
70159 assert( CORRUPT_DB || pPage->aData[0]==(PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF) );
70160 zeroPage(pNew, PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF);
70161 b.nCell = 1;
70162 b.pRef = pPage;
70163 b.apCell = &pCell;
70164 b.szCell = &szCell;
70165 b.apEnd[0] = pPage->aDataEnd;
70166 b.ixNx[0] = 2;
70167 rc = rebuildPage(&b, 0, 1, pNew);
70168 if( NEVER(rc) ){
70169 releasePage(pNew);
70170 return rc;
70171 }
70172 pNew->nFree = pBt->usableSize - pNew->cellOffset - 2 - szCell;
70173
70174 /* If this is an auto-vacuum database, update the pointer map
70175 ** with entries for the new page, and any pointer from the
70176 ** cell on the page to an overflow page. If either of these
@@ -70501,10 +70646,14 @@
70646 **
70647 */
70648 usableSpace = pBt->usableSize - 12 + leafCorrection;
70649 for(i=0; i<nOld; i++){
70650 MemPage *p = apOld[i];
70651 b.apEnd[i*2] = p->aDataEnd;
70652 b.apEnd[i*2+1] = pParent->aDataEnd;
70653 b.ixNx[i*2] = cntOld[i];
70654 b.ixNx[i*2+1] = cntOld[i]+1;
70655 szNew[i] = usableSpace - p->nFree;
70656 for(j=0; j<p->nOverflow; j++){
70657 szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]);
70658 }
70659 cntNew[i] = cntOld[i];
@@ -71182,11 +71331,15 @@
71331 iAmt = nData;
71332 }
71333 if( memcmp(pDest, ((u8*)pX->pData) + iOffset, iAmt)!=0 ){
71334 int rc = sqlite3PagerWrite(pPage->pDbPage);
71335 if( rc ) return rc;
71336 /* In a corrupt database, it is possible for the source and destination
71337 ** buffers to overlap. This is harmless since the database is already
71338 ** corrupt but it does cause valgrind and ASAN warnings. So use
71339 ** memmove(). */
71340 memmove(pDest, ((u8*)pX->pData) + iOffset, iAmt);
71341 }
71342 }
71343 return SQLITE_OK;
71344 }
71345
@@ -71596,10 +71749,11 @@
71749 ** from the internal node. The 'previous' entry is used for this instead
71750 ** of the 'next' entry, as the previous entry is always a part of the
71751 ** sub-tree headed by the child page of the cell being deleted. This makes
71752 ** balancing the tree following the delete operation easier. */
71753 if( !pPage->leaf ){
71754 pCur->skipNext = 0;
71755 rc = sqlite3BtreePrevious(pCur, 0);
71756 assert( rc!=SQLITE_DONE );
71757 if( rc ) return rc;
71758 }
71759
@@ -74199,11 +74353,11 @@
74353 **
74354 ** Return SQLITE_OK on success or an error code (probably SQLITE_NOMEM)
74355 ** if unable to complete the resizing.
74356 */
74357 SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize(Mem *pMem, int szNew){
74358 assert( CORRUPT_DB || szNew>0 );
74359 assert( (pMem->flags & MEM_Dyn)==0 || pMem->szMalloc==0 );
74360 if( pMem->szMalloc<szNew ){
74361 return sqlite3VdbeMemGrow(pMem, szNew, 0);
74362 }
74363 assert( (pMem->flags & MEM_Dyn)==0 );
@@ -75486,13 +75640,15 @@
75640 else if( op==TK_FUNCTION && pCtx!=0 ){
75641 rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx);
75642 }
75643 #endif
75644 else if( op==TK_TRUEFALSE ){
75645 pVal = valueNew(db, pCtx);
75646 if( pVal ){
75647 pVal->flags = MEM_Int;
75648 pVal->u.i = pExpr->u.zToken[4]==0;
75649 }
75650 }
75651
75652 *ppVal = pVal;
75653 return rc;
75654
@@ -76483,11 +76639,11 @@
76639 while( (pOp = opIterNext(&sIter))!=0 ){
76640 int opcode = pOp->opcode;
76641 if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename
76642 || opcode==OP_VDestroy
76643 || ((opcode==OP_Halt || opcode==OP_HaltIfNull)
76644 && ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
76645 ){
76646 hasAbort = 1;
76647 break;
76648 }
76649 if( opcode==OP_CreateBtree && pOp->p3==BTREE_INTKEY ) hasCreateTable = 1;
@@ -79639,11 +79795,11 @@
79795 int nKey, /* Size of the binary record */
79796 const void *pKey, /* The binary record */
79797 UnpackedRecord *p /* Populate this structure before returning. */
79798 ){
79799 const unsigned char *aKey = (const unsigned char *)pKey;
79800 u32 d;
79801 u32 idx; /* Offset in aKey[] to read from */
79802 u16 u; /* Unsigned loop counter */
79803 u32 szHdr;
79804 Mem *pMem = p->aMem;
79805
@@ -79650,11 +79806,11 @@
79806 p->default_rc = 0;
79807 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
79808 idx = getVarint32(aKey, szHdr);
79809 d = szHdr;
79810 u = 0;
79811 while( idx<szHdr && d<=(u32)nKey ){
79812 u32 serial_type;
79813
79814 idx += getVarint32(&aKey[idx], serial_type);
79815 pMem->enc = pKeyInfo->enc;
79816 pMem->db = pKeyInfo->db;
@@ -79663,11 +79819,11 @@
79819 pMem->z = 0;
79820 d += sqlite3VdbeSerialGet(&aKey[d], serial_type, pMem);
79821 pMem++;
79822 if( (++u)>=p->nField ) break;
79823 }
79824 if( d>(u32)nKey && u ){
79825 assert( CORRUPT_DB );
79826 /* In a corrupt record entry, the last pMem might have been set up using
79827 ** uninitialized memory. Overwrite its value with NULL, to prevent
79828 ** warnings from MSAN. */
79829 sqlite3VdbeMemSetNull(pMem-1);
@@ -79747,11 +79903,12 @@
79903 */
79904 d1 += sqlite3VdbeSerialGet(&aKey1[d1], serial_type1, &mem1);
79905
79906 /* Do the comparison
79907 */
79908 rc = sqlite3MemCompare(&mem1, &pPKey2->aMem[i],
79909 pKeyInfo->nAllField>i ? pKeyInfo->aColl[i] : 0);
79910 if( rc!=0 ){
79911 assert( mem1.szMalloc==0 ); /* See comment below */
79912 if( pKeyInfo->aSortOrder[i] ){
79913 rc = -rc; /* Invert the result for DESC sort order. */
79914 }
@@ -80178,14 +80335,16 @@
80335 rc = +1;
80336 }else{
80337 mem1.n = (serial_type - 12) / 2;
80338 testcase( (d1+mem1.n)==(unsigned)nKey1 );
80339 testcase( (d1+mem1.n+1)==(unsigned)nKey1 );
80340 if( (d1+mem1.n) > (unsigned)nKey1
80341 || (pKeyInfo = pPKey2->pKeyInfo)->nAllField<=i
80342 ){
80343 pPKey2->errCode = (u8)SQLITE_CORRUPT_BKPT;
80344 return 0; /* Corruption */
80345 }else if( pKeyInfo->aColl[i] ){
80346 mem1.enc = pKeyInfo->enc;
80347 mem1.db = pKeyInfo->db;
80348 mem1.flags = MEM_Str;
80349 mem1.z = (char*)&aKey1[d1];
80350 rc = vdbeCompareMemString(
@@ -83382,10 +83541,11 @@
83541 ** accordingly.
83542 */
83543 static u16 SQLITE_NOINLINE computeNumericType(Mem *pMem){
83544 assert( (pMem->flags & (MEM_Int|MEM_Real))==0 );
83545 assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 );
83546 ExpandBlob(pMem);
83547 if( sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc)==0 ){
83548 return 0;
83549 }
83550 if( sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc)==0 ){
83551 return MEM_Int;
@@ -89257,10 +89417,21 @@
89417 memset(pFrame->aOnce, 0, (pProgram->nOp + 7)/8);
89418 p->aOp = aOp = pProgram->aOp;
89419 p->nOp = pProgram->nOp;
89420 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
89421 p->anExec = 0;
89422 #endif
89423 #ifdef SQLITE_DEBUG
89424 /* Verify that second and subsequent executions of the same trigger do not
89425 ** try to reuse register values from the first use. */
89426 {
89427 int i;
89428 for(i=0; i<p->nMem; i++){
89429 aMem[i].pScopyFrom = 0; /* Prevent false-positive AboutToChange() errs */
89430 aMem[i].flags |= MEM_Undefined; /* Cause a fault if this reg is reused */
89431 }
89432 }
89433 #endif
89434 pOp = &aOp[-1];
89435
89436 break;
89437 }
@@ -94431,10 +94602,26 @@
94602 /* #include "sqliteInt.h" */
94603 /* #include <stdlib.h> */
94604 /* #include <string.h> */
94605
94606
94607 #if !defined(SQLITE_OMIT_WINDOWFUNC)
94608 /*
94609 ** Walk all expressions linked into the list of Window objects passed
94610 ** as the second argument.
94611 */
94612 static int walkWindowList(Walker *pWalker, Window *pList){
94613 Window *pWin;
94614 for(pWin=pList; pWin; pWin=pWin->pNextWin){
94615 if( sqlite3WalkExprList(pWalker, pWin->pOrderBy) ) return WRC_Abort;
94616 if( sqlite3WalkExprList(pWalker, pWin->pPartition) ) return WRC_Abort;
94617 if( sqlite3WalkExpr(pWalker, pWin->pFilter) ) return WRC_Abort;
94618 }
94619 return WRC_Continue;
94620 }
94621 #endif
94622
94623 /*
94624 ** Walk an expression tree. Invoke the callback once for each node
94625 ** of the expression, while descending. (In other words, the callback
94626 ** is invoked before visiting children.)
94627 **
@@ -94470,14 +94657,11 @@
94657 }else if( pExpr->x.pList ){
94658 if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
94659 }
94660 #ifndef SQLITE_OMIT_WINDOWFUNC
94661 if( ExprHasProperty(pExpr, EP_WinFunc) ){
94662 if( walkWindowList(pWalker, pExpr->y.pWin) ) return WRC_Abort;
 
 
 
94663 }
94664 #endif
94665 }
94666 break;
94667 }
@@ -94513,10 +94697,20 @@
94697 if( sqlite3WalkExpr(pWalker, p->pWhere) ) return WRC_Abort;
94698 if( sqlite3WalkExprList(pWalker, p->pGroupBy) ) return WRC_Abort;
94699 if( sqlite3WalkExpr(pWalker, p->pHaving) ) return WRC_Abort;
94700 if( sqlite3WalkExprList(pWalker, p->pOrderBy) ) return WRC_Abort;
94701 if( sqlite3WalkExpr(pWalker, p->pLimit) ) return WRC_Abort;
94702 #if !defined(SQLITE_OMIT_WINDOWFUNC) && !defined(SQLITE_OMIT_ALTERTABLE)
94703 {
94704 Parse *pParse = pWalker->pParse;
94705 if( pParse && IN_RENAME_OBJECT ){
94706 int rc = walkWindowList(pWalker, p->pWinDefn);
94707 assert( rc==WRC_Continue );
94708 return rc;
94709 }
94710 }
94711 #endif
94712 return WRC_Continue;
94713 }
94714
94715 /*
94716 ** Walk the parse trees associated with all subqueries in the
@@ -95442,14 +95636,14 @@
95636 sqlite3WalkExprList(pWalker, pList);
95637 if( is_agg ){
95638 #ifndef SQLITE_OMIT_WINDOWFUNC
95639 if( pExpr->y.pWin ){
95640 Select *pSel = pNC->pWinSelect;
95641 sqlite3WindowUpdate(pParse, pSel->pWinDefn, pExpr->y.pWin, pDef);
95642 sqlite3WalkExprList(pWalker, pExpr->y.pWin->pPartition);
95643 sqlite3WalkExprList(pWalker, pExpr->y.pWin->pOrderBy);
95644 sqlite3WalkExpr(pWalker, pExpr->y.pWin->pFilter);
 
95645 if( 0==pSel->pWin
95646 || 0==sqlite3WindowCompare(pParse, pSel->pWin, pExpr->y.pWin)
95647 ){
95648 pExpr->y.pWin->pNextWin = pSel->pWin;
95649 pSel->pWin = pExpr->y.pWin;
@@ -95744,38 +95938,35 @@
95938 }
95939 if( !db->mallocFailed ){
95940 assert(pDup);
95941 iCol = resolveOrderByTermToExprList(pParse, pSelect, pDup);
95942 }
95943 if( !IN_RENAME_OBJECT ){
 
 
 
 
 
95944 sqlite3ExprDelete(db, pDup);
95945 }
95946 }
95947 }
95948 if( iCol>0 ){
95949 /* Convert the ORDER BY term into an integer column number iCol,
95950 ** taking care to preserve the COLLATE clause if it exists */
95951 if( !IN_RENAME_OBJECT ){
95952 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
95953 if( pNew==0 ) return 1;
95954 pNew->flags |= EP_IntValue;
95955 pNew->u.iValue = iCol;
95956 if( pItem->pExpr==pE ){
95957 pItem->pExpr = pNew;
95958 }else{
95959 Expr *pParent = pItem->pExpr;
95960 assert( pParent->op==TK_COLLATE );
95961 while( pParent->pLeft->op==TK_COLLATE ) pParent = pParent->pLeft;
95962 assert( pParent->pLeft==pE );
95963 pParent->pLeft = pNew;
95964 }
95965 sqlite3ExprDelete(db, pE);
95966 pItem->u.x.iOrderByCol = (u16)iCol;
95967 }
95968 pItem->done = 1;
95969 }else{
95970 moreToDo = 1;
95971 }
95972 }
@@ -96119,10 +96310,21 @@
96310 "the GROUP BY clause");
96311 return WRC_Abort;
96312 }
96313 }
96314 }
96315
96316 if( IN_RENAME_OBJECT ){
96317 Window *pWin;
96318 for(pWin=p->pWinDefn; pWin; pWin=pWin->pNextWin){
96319 if( sqlite3ResolveExprListNames(&sNC, pWin->pOrderBy)
96320 || sqlite3ResolveExprListNames(&sNC, pWin->pPartition)
96321 ){
96322 return WRC_Abort;
96323 }
96324 }
96325 }
96326
96327 /* If this is part of a compound SELECT, check that it has the right
96328 ** number of expressions in the select list. */
96329 if( p->pNext && p->pEList->nExpr!=p->pNext->pEList->nExpr ){
96330 sqlite3SelectWrongNumTermsError(pParse, p->pNext);
@@ -101683,10 +101885,11 @@
101885 w.xExprCallback = analyzeAggregate;
101886 w.xSelectCallback = analyzeAggregatesInSelect;
101887 w.xSelectCallback2 = analyzeAggregatesInSelectEnd;
101888 w.walkerDepth = 0;
101889 w.u.pNC = pNC;
101890 w.pParse = 0;
101891 assert( pNC->pSrcList!=0 );
101892 sqlite3WalkExpr(&w, pExpr);
101893 }
101894
101895 /*
@@ -120153,22 +120356,26 @@
120356 /* ePragFlg: */ PragFlg_Result0,
120357 /* ColNames: */ 0, 0,
120358 /* iArg: */ 0 },
120359 #endif
120360 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120361 #if !defined(SQLITE_OMIT_DEPRECATED)
120362 {/* zName: */ "count_changes",
120363 /* ePragTyp: */ PragTyp_FLAG,
120364 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120365 /* ColNames: */ 0, 0,
120366 /* iArg: */ SQLITE_CountRows },
120367 #endif
120368 #endif
120369 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
120370 #if !defined(SQLITE_OMIT_DEPRECATED)
120371 {/* zName: */ "data_store_directory",
120372 /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY,
120373 /* ePragFlg: */ PragFlg_NoColumns1,
120374 /* ColNames: */ 0, 0,
120375 /* iArg: */ 0 },
120376 #endif
120377 #endif
120378 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
120379 {/* zName: */ "data_version",
120380 /* ePragTyp: */ PragTyp_HEADER_VALUE,
120381 /* ePragFlg: */ PragFlg_ReadOnly|PragFlg_Result0,
@@ -120180,16 +120387,18 @@
120387 /* ePragTyp: */ PragTyp_DATABASE_LIST,
120388 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0,
120389 /* ColNames: */ 35, 3,
120390 /* iArg: */ 0 },
120391 #endif
120392 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
120393 #if !defined(SQLITE_OMIT_DEPRECATED)
120394 {/* zName: */ "default_cache_size",
120395 /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE,
120396 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
120397 /* ColNames: */ 45, 1,
120398 /* iArg: */ 0 },
120399 #endif
120400 #endif
120401 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120402 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
120403 {/* zName: */ "defer_foreign_keys",
120404 /* ePragTyp: */ PragTyp_FLAG,
@@ -120197,15 +120406,17 @@
120406 /* ColNames: */ 0, 0,
120407 /* iArg: */ SQLITE_DeferFKs },
120408 #endif
120409 #endif
120410 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120411 #if !defined(SQLITE_OMIT_DEPRECATED)
120412 {/* zName: */ "empty_result_callbacks",
120413 /* ePragTyp: */ PragTyp_FLAG,
120414 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120415 /* ColNames: */ 0, 0,
120416 /* iArg: */ SQLITE_NullCallback },
120417 #endif
120418 #endif
120419 #if !defined(SQLITE_OMIT_UTF16)
120420 {/* zName: */ "encoding",
120421 /* ePragTyp: */ PragTyp_ENCODING,
120422 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
@@ -120241,15 +120452,19 @@
120452 /* ePragFlg: */ PragFlg_ReadOnly|PragFlg_Result0,
120453 /* ColNames: */ 0, 0,
120454 /* iArg: */ BTREE_FREE_PAGE_COUNT },
120455 #endif
120456 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120457 #if !defined(SQLITE_OMIT_DEPRECATED)
120458 {/* zName: */ "full_column_names",
120459 /* ePragTyp: */ PragTyp_FLAG,
120460 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120461 /* ColNames: */ 0, 0,
120462 /* iArg: */ SQLITE_FullColNames },
120463 #endif
120464 #endif
120465 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120466 {/* zName: */ "fullfsync",
120467 /* ePragTyp: */ PragTyp_FLAG,
120468 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120469 /* ColNames: */ 0, 0,
120470 /* iArg: */ SQLITE_FullFSync },
@@ -120472,15 +120687,17 @@
120687 /* ePragFlg: */ PragFlg_Result0,
120688 /* ColNames: */ 0, 0,
120689 /* iArg: */ 0 },
120690 #endif
120691 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120692 #if !defined(SQLITE_OMIT_DEPRECATED)
120693 {/* zName: */ "short_column_names",
120694 /* ePragTyp: */ PragTyp_FLAG,
120695 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120696 /* ColNames: */ 0, 0,
120697 /* iArg: */ SQLITE_ShortColNames },
120698 #endif
120699 #endif
120700 {/* zName: */ "shrink_memory",
120701 /* ePragTyp: */ PragTyp_SHRINK_MEMORY,
120702 /* ePragFlg: */ PragFlg_NoColumns,
120703 /* ColNames: */ 0, 0,
@@ -120529,15 +120746,19 @@
120746 {/* zName: */ "temp_store",
120747 /* ePragTyp: */ PragTyp_TEMP_STORE,
120748 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120749 /* ColNames: */ 0, 0,
120750 /* iArg: */ 0 },
120751 #endif
120752 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
120753 #if !defined(SQLITE_OMIT_DEPRECATED)
120754 {/* zName: */ "temp_store_directory",
120755 /* ePragTyp: */ PragTyp_TEMP_STORE_DIRECTORY,
120756 /* ePragFlg: */ PragFlg_NoColumns1,
120757 /* ColNames: */ 0, 0,
120758 /* iArg: */ 0 },
120759 #endif
120760 #endif
120761 #if defined(SQLITE_HAS_CODEC)
120762 {/* zName: */ "textkey",
120763 /* ePragTyp: */ PragTyp_KEY,
120764 /* ePragFlg: */ 0,
@@ -126101,13 +126322,13 @@
126322
126323 savedFlags = db->flags;
126324 db->flags &= ~(u64)SQLITE_FullColNames;
126325 db->flags |= SQLITE_ShortColNames;
126326 sqlite3SelectPrep(pParse, pSelect, 0);
126327 db->flags = savedFlags;
126328 if( pParse->nErr ) return 0;
126329 while( pSelect->pPrior ) pSelect = pSelect->pPrior;
 
126330 pTab = sqlite3DbMallocZero(db, sizeof(Table) );
126331 if( pTab==0 ){
126332 return 0;
126333 }
126334 /* The sqlite3ResultSetOfSelect() is only used n contexts where lookaside
@@ -132377,10 +132598,11 @@
132598
132599 /* There is one entry in the aRegIdx[] array for each index on the table
132600 ** being updated. Fill in aRegIdx[] with a register number that will hold
132601 ** the key for accessing each index.
132602 */
132603 if( onError==OE_Replace ) bReplace = 1;
132604 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
132605 int reg;
132606 if( chngKey || hasFK>1 || pIdx==pPk
132607 || indexWhereClauseMightChange(pIdx,aXRef,chngRowid)
132608 ){
@@ -132390,13 +132612,11 @@
132612 reg = 0;
132613 for(i=0; i<pIdx->nKeyCol; i++){
132614 if( indexColumnIsBeingUpdated(pIdx, i, aXRef, chngRowid) ){
132615 reg = ++pParse->nMem;
132616 pParse->nMem += pIdx->nColumn;
132617 if( onError==OE_Default && pIdx->onError==OE_Replace ){
 
 
132618 bReplace = 1;
132619 }
132620 break;
132621 }
132622 }
@@ -145794,10 +146014,11 @@
146014 VdbeCoverageIf(v, eCond==2);
146015 sqlite3VdbeAddOp3(v, aOp[eCond], regZero, sqlite3VdbeCurrentAddr(v)+2, reg);
146016 VdbeCoverageNeverNullIf(v, eCond==0);
146017 VdbeCoverageNeverNullIf(v, eCond==1);
146018 VdbeCoverageNeverNullIf(v, eCond==2);
146019 sqlite3MayAbort(pParse);
146020 sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_ERROR, OE_Abort);
146021 sqlite3VdbeAppendP4(v, (void*)azErr[eCond], P4_STATIC);
146022 sqlite3ReleaseTempReg(pParse, regZero);
146023 }
146024
@@ -150949,12 +151170,14 @@
151170 ** expr1 NOT IN ()
151171 **
151172 ** simplify to constants 0 (false) and 1 (true), respectively,
151173 ** regardless of the value of expr1.
151174 */
151175 if( IN_RENAME_OBJECT==0 ){
151176 sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy490);
151177 yymsp[-4].minor.yy490 = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[yymsp[-3].minor.yy96],1);
151178 }
151179 }else if( yymsp[-1].minor.yy42->nExpr==1 ){
151180 /* Expressions of the form:
151181 **
151182 ** expr1 IN (?1)
151183 ** expr1 NOT IN (?2)
@@ -158741,10 +158964,22 @@
158964 ** Terminator values for position-lists and column-lists.
158965 */
158966 #define POS_COLUMN (1) /* Column-list terminator */
158967 #define POS_END (0) /* Position-list terminator */
158968
158969 /*
158970 ** The assert_fts3_nc() macro is similar to the assert() macro, except that it
158971 ** is used for assert() conditions that are true only if it can be
158972 ** guranteed that the database is not corrupt.
158973 */
158974 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
158975 SQLITE_API extern int sqlite3_fts3_may_be_corrupt;
158976 # define assert_fts3_nc(x) assert(sqlite3_fts3_may_be_corrupt || (x))
158977 #else
158978 # define assert_fts3_nc(x) assert(x)
158979 #endif
158980
158981 /*
158982 ** This section provides definitions to allow the
158983 ** FTS3 extension to be compiled outside of the
158984 ** amalgamation.
158985 */
@@ -159265,10 +159500,18 @@
159500 SQLITE_PRIVATE int sqlite3Fts3Always(int b) { assert( b ); return b; }
159501 SQLITE_PRIVATE int sqlite3Fts3Never(int b) { assert( !b ); return b; }
159502 # endif
159503 #endif
159504
159505 /*
159506 ** This variable is set to false when running tests for which the on disk
159507 ** structures should not be corrupt. Otherwise, true. If it is false, extra
159508 ** assert() conditions in the fts3 code are activated - conditions that are
159509 ** only true if it is guaranteed that the fts3 database is not corrupt.
159510 */
159511 SQLITE_API int sqlite3_fts3_may_be_corrupt = 1;
159512
159513 /*
159514 ** Write a 64-bit variable-length integer to memory starting at p[0].
159515 ** The length of data written will be between 1 and FTS3_VARINT_MAX bytes.
159516 ** The number of bytes written is returned.
159517 */
@@ -161493,11 +161736,11 @@
161736 ** docids to grow.
161737 **
161738 ** A symetric argument may be made if the doclists are in descending
161739 ** order.
161740 */
161741 aOut = sqlite3_malloc64((i64)n1+n2+FTS3_VARINT_MAX-1+FTS3_BUFFER_PADDING);
161742 if( !aOut ) return SQLITE_NOMEM;
161743
161744 p = aOut;
161745 fts3GetDeltaVarint3(&p1, pEnd1, 0, &i1);
161746 fts3GetDeltaVarint3(&p2, pEnd2, 0, &i2);
@@ -161522,14 +161765,16 @@
161765 }
161766
161767 if( rc!=SQLITE_OK ){
161768 sqlite3_free(aOut);
161769 p = aOut = 0;
161770 }else{
161771 assert( (p-aOut)<=n1+n2+FTS3_VARINT_MAX-1 );
161772 memset(&aOut[(p-aOut)], 0, FTS3_BUFFER_PADDING);
161773 }
161774 *paOut = aOut;
161775 *pnOut = (int)(p-aOut);
 
161776 return rc;
161777 }
161778
161779 /*
161780 ** This function does a "phrase" merge of two doclists. In a phrase merge,
@@ -162803,11 +163048,10 @@
163048 */
163049 static int fts3RollbackToMethod(sqlite3_vtab *pVtab, int iSavepoint){
163050 Fts3Table *p = (Fts3Table*)pVtab;
163051 UNUSED_PARAMETER(iSavepoint);
163052 assert( p->inTransaction );
 
163053 TESTONLY( p->mxSavepoint = iSavepoint );
163054 sqlite3Fts3PendingTermsClear(p);
163055 return SQLITE_OK;
163056 }
163057
@@ -169623,11 +169867,11 @@
169867 int iLangid, /* Language id */
169868 int iIndex, /* Index in p->aIndex[] */
169869 int iLevel /* Level of segments */
169870 ){
169871 sqlite3_int64 iBase; /* First absolute level for iLangid/iIndex */
169872 assert_fts3_nc( iLangid>=0 );
169873 assert( p->nIndex>0 );
169874 assert( iIndex>=0 && iIndex<p->nIndex );
169875
169876 iBase = ((sqlite3_int64)iLangid * p->nIndex + iIndex) * FTS3_SEGDIR_MAXLEVEL;
169877 return iBase + iLevel;
@@ -171310,10 +171554,15 @@
171554 }
171555 nData = pWriter->nData;
171556
171557 nPrefix = fts3PrefixCompress(pWriter->zTerm, pWriter->nTerm, zTerm, nTerm);
171558 nSuffix = nTerm-nPrefix;
171559
171560 /* If nSuffix is zero or less, then zTerm/nTerm must be a prefix of
171561 ** pWriter->zTerm/pWriter->nTerm. i.e. must be equal to or less than when
171562 ** compared with BINARY collation. This indicates corruption. */
171563 if( nSuffix<=0 ) return FTS_CORRUPT_VTAB;
171564
171565 /* Figure out how many bytes are required by this new entry */
171566 nReq = sqlite3Fts3VarintLen(nPrefix) + /* varint containing prefix size */
171567 sqlite3Fts3VarintLen(nSuffix) + /* varint containing suffix size */
171568 nSuffix + /* Term suffix */
@@ -199230,16 +199479,12 @@
199479 ** should be greater than or equal to zero and smaller than the value
199480 ** output by xInstCount().
199481 **
199482 ** Usually, output parameter *piPhrase is set to the phrase number, *piCol
199483 ** to the column in which it occurs and *piOff the token offset of the
199484 ** first token of the phrase. Returns SQLITE_OK if successful, or an error
199485 ** code (i.e. SQLITE_NOMEM) if an error occurs.
 
 
 
 
199486 **
199487 ** This API can be quite slow if used with an FTS5 table created with the
199488 ** "detail=none" or "detail=column" option.
199489 **
199490 ** xRowid:
@@ -199777,10 +200022,16 @@
200022 # define assert_nc(x) assert(sqlite3_fts5_may_be_corrupt || (x))
200023 #else
200024 # define assert_nc(x) assert(x)
200025 #endif
200026
200027 /*
200028 ** A version of memcmp() that does not cause asan errors if one of the pointer
200029 ** parameters is NULL and the number of bytes to compare is zero.
200030 */
200031 #define fts5Memcmp(s1, s2, n) ((n)==0 ? 0 : memcmp((s1), (s2), (n)))
200032
200033 /* Mark a function parameter as unused, to suppress nuisance compiler
200034 ** warnings. */
200035 #ifndef UNUSED_PARAM
200036 # define UNUSED_PARAM(X) (void)(X)
200037 #endif
@@ -199964,11 +200215,11 @@
200215 /* Write and decode big-endian 32-bit integer values */
200216 static void sqlite3Fts5Put32(u8*, int);
200217 static int sqlite3Fts5Get32(const u8*);
200218
200219 #define FTS5_POS2COLUMN(iPos) (int)(iPos >> 32)
200220 #define FTS5_POS2OFFSET(iPos) (int)(iPos & 0x7FFFFFFF)
200221
200222 typedef struct Fts5PoslistReader Fts5PoslistReader;
200223 struct Fts5PoslistReader {
200224 /* Variables used only by sqlite3Fts5PoslistIterXXX() functions. */
200225 const u8 *a; /* Position list to iterate through */
@@ -202320,25 +202571,26 @@
202571 int iOff = 0;
202572 int iFirst = -1;
202573 int nInst;
202574 int nScore = 0;
202575 int iLast = 0;
202576 sqlite3_int64 iEnd = (sqlite3_int64)iPos + nToken;
202577
202578 rc = pApi->xInstCount(pFts, &nInst);
202579 for(i=0; i<nInst && rc==SQLITE_OK; i++){
202580 rc = pApi->xInst(pFts, i, &ip, &ic, &iOff);
202581 if( rc==SQLITE_OK && ic==iCol && iOff>=iPos && iOff<iEnd ){
202582 nScore += (aSeen[ip] ? 1 : 1000);
202583 aSeen[ip] = 1;
202584 if( iFirst<0 ) iFirst = iOff;
202585 iLast = iOff + pApi->xPhraseSize(pFts, ip);
202586 }
202587 }
202588
202589 *pnScore = nScore;
202590 if( piPos ){
202591 sqlite3_int64 iAdj = iFirst - (nToken - (iLast-iFirst)) / 2;
202592 if( (iAdj+nToken)>nDocsize ) iAdj = nDocsize - nToken;
202593 if( iAdj<0 ) iAdj = 0;
202594 *piPos = iAdj;
202595 }
202596
@@ -202882,11 +203134,11 @@
203134 if( iVal==1 ){
203135 fts5FastGetVarint32(a, i, iVal);
203136 iOff = ((i64)iVal) << 32;
203137 fts5FastGetVarint32(a, i, iVal);
203138 }
203139 *piOff = iOff + ((iVal-2) & 0x7FFFFFFF);
203140 *pi = i;
203141 return 0;
203142 }
203143 }
203144
@@ -208054,11 +208306,11 @@
208306 **
208307 ** res = *pLeft - *pRight
208308 */
208309 static int fts5BufferCompare(Fts5Buffer *pLeft, Fts5Buffer *pRight){
208310 int nCmp = MIN(pLeft->n, pRight->n);
208311 int res = fts5Memcmp(pLeft->p, pRight->p, nCmp);
208312 return (res==0 ? (pLeft->n - pRight->n) : res);
208313 }
208314
208315 static int fts5LeafFirstTermOff(Fts5Data *pLeaf){
208316 int ret;
@@ -209982,11 +210234,11 @@
210234 assert( pRes->iFirst==i2 );
210235 }else if( p2->pLeaf==0 ){
210236 assert( pRes->iFirst==i1 );
210237 }else{
210238 int nMin = MIN(p1->term.n, p2->term.n);
210239 int res = fts5Memcmp(p1->term.p, p2->term.p, nMin);
210240 if( res==0 ) res = p1->term.n - p2->term.n;
210241
210242 if( res==0 ){
210243 assert( pRes->bTermEq==1 );
210244 assert( p1->iRowid!=p2->iRowid );
@@ -211028,11 +211280,11 @@
211280 u32 mask;
211281 memset(aUsed, 0, sizeof(aUsed));
211282 for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
211283 for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
211284 int iId = pStruct->aLevel[iLvl].aSeg[iSeg].iSegid;
211285 if( iId<=FTS5_MAX_SEGMENT && iId>0 ){
211286 aUsed[(iId-1) / 32] |= (u32)1 << ((iId-1) % 32);
211287 }
211288 }
211289 }
211290
@@ -211575,11 +211827,11 @@
211827 */
211828 static void fts5TrimSegments(Fts5Index *p, Fts5Iter *pIter){
211829 int i;
211830 Fts5Buffer buf;
211831 memset(&buf, 0, sizeof(Fts5Buffer));
211832 for(i=0; i<pIter->nSeg && p->rc==SQLITE_OK; i++){
211833 Fts5SegIter *pSeg = &pIter->aSeg[i];
211834 if( pSeg->pSeg==0 ){
211835 /* no-op */
211836 }else if( pSeg->pLeaf==0 ){
211837 /* All keys from this input segment have been transfered to the output.
@@ -211595,37 +211847,45 @@
211847 u8 aHdr[4] = {0x00, 0x00, 0x00, 0x00};
211848
211849 iLeafRowid = FTS5_SEGMENT_ROWID(iId, pSeg->iTermLeafPgno);
211850 pData = fts5DataRead(p, iLeafRowid);
211851 if( pData ){
211852 if( iOff>pData->szLeaf ){
211853 /* This can occur if the pages that the segments occupy overlap - if
211854 ** a single page has been assigned to more than one segment. In
211855 ** this case a prior iteration of this loop may have corrupted the
211856 ** segment currently being trimmed. */
211857 p->rc = FTS5_CORRUPT;
211858 }else{
211859 fts5BufferZero(&buf);
211860 fts5BufferGrow(&p->rc, &buf, pData->nn);
211861 fts5BufferAppendBlob(&p->rc, &buf, sizeof(aHdr), aHdr);
211862 fts5BufferAppendVarint(&p->rc, &buf, pSeg->term.n);
211863 fts5BufferAppendBlob(&p->rc, &buf, pSeg->term.n, pSeg->term.p);
211864 fts5BufferAppendBlob(&p->rc, &buf, pData->szLeaf-iOff,&pData->p[iOff]);
211865 if( p->rc==SQLITE_OK ){
211866 /* Set the szLeaf field */
211867 fts5PutU16(&buf.p[2], (u16)buf.n);
211868 }
211869
211870 /* Set up the new page-index array */
211871 fts5BufferAppendVarint(&p->rc, &buf, 4);
211872 if( pSeg->iLeafPgno==pSeg->iTermLeafPgno
211873 && pSeg->iEndofDoclist<pData->szLeaf
211874 ){
211875 int nDiff = pData->szLeaf - pSeg->iEndofDoclist;
211876 fts5BufferAppendVarint(&p->rc, &buf, buf.n - 1 - nDiff - 4);
211877 fts5BufferAppendBlob(&p->rc, &buf,
211878 pData->nn - pSeg->iPgidxOff, &pData->p[pSeg->iPgidxOff]
211879 );
211880 }
211881
211882 pSeg->pSeg->pgnoFirst = pSeg->iTermLeafPgno;
211883 fts5DataDelete(p, FTS5_SEGMENT_ROWID(iId, 1), iLeafRowid);
211884 fts5DataWrite(p, iLeafRowid, buf.p, buf.n);
211885 }
211886 fts5DataRelease(pData);
211887 }
211888 }
211889 }
211890 fts5BufferFree(&buf);
211891 }
@@ -211713,11 +211973,11 @@
211973 int nPos; /* position-list size field value */
211974 int nTerm;
211975 const u8 *pTerm;
211976
211977 pTerm = fts5MultiIterTerm(pIter, &nTerm);
211978 if( nTerm!=term.n || fts5Memcmp(pTerm, term.p, nTerm) ){
211979 if( pnRem && writer.nLeafWritten>nRem ){
211980 break;
211981 }
211982 fts5BufferSet(&p->rc, &term, nTerm, pTerm);
211983 bTermWritten =0;
@@ -212469,10 +212729,11 @@
212729 /* WRITEPOSLISTSIZE */
212730 fts5BufferSafeAppendVarint(&out, tmp.n * 2);
212731 fts5BufferSafeAppendBlob(&out, tmp.p, tmp.n);
212732 fts5DoclistIterNext(&i1);
212733 fts5DoclistIterNext(&i2);
212734 assert( out.n<=(p1->n+p2->n+9) );
212735 if( i1.aPoslist==0 || i2.aPoslist==0 ) break;
212736 }
212737 }
212738
212739 if( i1.aPoslist ){
@@ -212570,11 +212831,11 @@
212831 }
212832 fts5BufferFree(&aBuf[i]);
212833 }
212834 fts5MultiIterFree(p1);
212835
212836 pData = fts5IdxMalloc(p, sizeof(Fts5Data)+doclist.n+FTS5_DATA_ZERO_PADDING);
212837 if( pData ){
212838 pData->p = (u8*)&pData[1];
212839 pData->nn = pData->szLeaf = doclist.n;
212840 if( doclist.n ) memcpy(pData->p, doclist.p, doclist.n);
212841 fts5MultiIterNew2(p, pData, bDesc, ppIter);
@@ -213336,11 +213597,11 @@
213597 iRowidOff = fts5LeafFirstRowidOff(pLeaf);
213598 if( iRowidOff>=iOff || iOff>=pLeaf->szLeaf ){
213599 p->rc = FTS5_CORRUPT;
213600 }else{
213601 iOff += fts5GetVarint32(&pLeaf->p[iOff], nTerm);
213602 res = fts5Memcmp(&pLeaf->p[iOff], zIdxTerm, MIN(nTerm, nIdxTerm));
213603 if( res==0 ) res = nTerm - nIdxTerm;
213604 if( res<0 ) p->rc = FTS5_CORRUPT;
213605 }
213606
213607 fts5IntegrityCheckPgidx(p, pLeaf);
@@ -215772,10 +216033,11 @@
216033 */
216034 static int fts5CacheInstArray(Fts5Cursor *pCsr){
216035 int rc = SQLITE_OK;
216036 Fts5PoslistReader *aIter; /* One iterator for each phrase */
216037 int nIter; /* Number of iterators/phrases */
216038 int nCol = ((Fts5Table*)pCsr->base.pVtab)->pConfig->nCol;
216039
216040 nIter = sqlite3Fts5ExprPhraseCount(pCsr->pExpr);
216041 if( pCsr->aInstIter==0 ){
216042 sqlite3_int64 nByte = sizeof(Fts5PoslistReader) * nIter;
216043 pCsr->aInstIter = (Fts5PoslistReader*)sqlite3Fts5MallocZero(&rc, nByte);
@@ -215825,10 +216087,14 @@
216087
216088 aInst = &pCsr->aInst[3 * (nInst-1)];
216089 aInst[0] = iBest;
216090 aInst[1] = FTS5_POS2COLUMN(aIter[iBest].iPos);
216091 aInst[2] = FTS5_POS2OFFSET(aIter[iBest].iPos);
216092 if( aInst[1]<0 || aInst[1]>=nCol ){
216093 rc = FTS5_CORRUPT;
216094 break;
216095 }
216096 sqlite3Fts5PoslistReaderNext(&aIter[iBest]);
216097 }
216098 }
216099
216100 pCsr->nInstCount = nInst;
@@ -216636,11 +216902,11 @@
216902 int nArg, /* Number of args */
216903 sqlite3_value **apUnused /* Function arguments */
216904 ){
216905 assert( nArg==0 );
216906 UNUSED_PARAM2(nArg, apUnused);
216907 sqlite3_result_text(pCtx, "fts5: 2019-01-26 23:34:50 a3ea1a822d3a110f4f186f2fc8550f435c8c98635d058096b7be9d4df7066b8b", -1, SQLITE_TRANSIENT);
216908 }
216909
216910 /*
216911 ** Return true if zName is the extension on one of the shadow tables used
216912 ** by this module.
@@ -221399,12 +221665,12 @@
221665 }
221666 #endif /* SQLITE_CORE */
221667 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
221668
221669 /************** End of stmt.c ************************************************/
221670 #if __LINE__!=221670
221671 #undef SQLITE_SOURCE_ID
221672 #define SQLITE_SOURCE_ID "2019-01-27 02:45:32 9cf8ebd141aa2eb661d457624c76433bd9e4abfdef04aa52e28bc169172calt2"
221673 #endif
221674 /* Return the source-id for this library */
221675 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
221676 /************************** End of sqlite3.c ******************************/
221677
+13 -7
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126126
#define SQLITE_VERSION "3.27.0"
127127
#define SQLITE_VERSION_NUMBER 3027000
128
-#define SQLITE_SOURCE_ID "2019-01-21 17:57:31 505ed9a47825240979338a24044559613fbbd2a7850bdff70c7164da054ec63d"
128
+#define SQLITE_SOURCE_ID "2019-01-27 02:45:32 9cf8ebd141aa2eb661d457624c76433bd9e4abfdef04aa52e28bc169172calt1"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
@@ -821,10 +821,19 @@
821821
** current transaction. This hint is not guaranteed to be accurate but it
822822
** is often close. The underlying VFS might choose to preallocate database
823823
** file space based on this hint in order to help writes to the database
824824
** file run faster.
825825
**
826
+** <li>[[SQLITE_FCNTL_SIZE_LIMIT]]
827
+** The [SQLITE_FCNTL_SIZE_LIMIT] opcode is used by in-memory VFS that
828
+** implements [sqlite3_deserialize()] to set an upper bound on the size
829
+** of the in-memory database. The argument is a pointer to a [sqlite3_int64].
830
+** If the integer pointed to is negative, then it is filled in with the
831
+** current limit. Otherwise the limit is set to the larger of the value
832
+** of the integer pointed to and the current database size. The integer
833
+** pointed to is set to the new limit.
834
+**
826835
** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]
827836
** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
828837
** extends and truncates the database file in chunks of a size specified
829838
** by the user. The fourth argument to [sqlite3_file_control()] should
830839
** point to an integer (type int) containing the new chunk-size to use
@@ -1129,10 +1138,11 @@
11291138
#define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 31
11301139
#define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32
11311140
#define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33
11321141
#define SQLITE_FCNTL_LOCK_TIMEOUT 34
11331142
#define SQLITE_FCNTL_DATA_VERSION 35
1143
+#define SQLITE_FCNTL_SIZE_LIMIT 36
11341144
11351145
/* deprecated names */
11361146
#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
11371147
#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
11381148
#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -11233,16 +11243,12 @@
1123311243
** should be greater than or equal to zero and smaller than the value
1123411244
** output by xInstCount().
1123511245
**
1123611246
** Usually, output parameter *piPhrase is set to the phrase number, *piCol
1123711247
** to the column in which it occurs and *piOff the token offset of the
11238
-** first token of the phrase. The exception is if the table was created
11239
-** with the offsets=0 option specified. In this case *piOff is always
11240
-** set to -1.
11241
-**
11242
-** Returns SQLITE_OK if successful, or an error code (i.e. SQLITE_NOMEM)
11243
-** if an error occurs.
11248
+** first token of the phrase. Returns SQLITE_OK if successful, or an error
11249
+** code (i.e. SQLITE_NOMEM) if an error occurs.
1124411250
**
1124511251
** This API can be quite slow if used with an FTS5 table created with the
1124611252
** "detail=none" or "detail=column" option.
1124711253
**
1124811254
** xRowid:
1124911255
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.27.0"
127 #define SQLITE_VERSION_NUMBER 3027000
128 #define SQLITE_SOURCE_ID "2019-01-21 17:57:31 505ed9a47825240979338a24044559613fbbd2a7850bdff70c7164da054ec63d"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -821,10 +821,19 @@
821 ** current transaction. This hint is not guaranteed to be accurate but it
822 ** is often close. The underlying VFS might choose to preallocate database
823 ** file space based on this hint in order to help writes to the database
824 ** file run faster.
825 **
 
 
 
 
 
 
 
 
 
826 ** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]
827 ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
828 ** extends and truncates the database file in chunks of a size specified
829 ** by the user. The fourth argument to [sqlite3_file_control()] should
830 ** point to an integer (type int) containing the new chunk-size to use
@@ -1129,10 +1138,11 @@
1129 #define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 31
1130 #define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32
1131 #define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33
1132 #define SQLITE_FCNTL_LOCK_TIMEOUT 34
1133 #define SQLITE_FCNTL_DATA_VERSION 35
 
1134
1135 /* deprecated names */
1136 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
1137 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
1138 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -11233,16 +11243,12 @@
11233 ** should be greater than or equal to zero and smaller than the value
11234 ** output by xInstCount().
11235 **
11236 ** Usually, output parameter *piPhrase is set to the phrase number, *piCol
11237 ** to the column in which it occurs and *piOff the token offset of the
11238 ** first token of the phrase. The exception is if the table was created
11239 ** with the offsets=0 option specified. In this case *piOff is always
11240 ** set to -1.
11241 **
11242 ** Returns SQLITE_OK if successful, or an error code (i.e. SQLITE_NOMEM)
11243 ** if an error occurs.
11244 **
11245 ** This API can be quite slow if used with an FTS5 table created with the
11246 ** "detail=none" or "detail=column" option.
11247 **
11248 ** xRowid:
11249
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.27.0"
127 #define SQLITE_VERSION_NUMBER 3027000
128 #define SQLITE_SOURCE_ID "2019-01-27 02:45:32 9cf8ebd141aa2eb661d457624c76433bd9e4abfdef04aa52e28bc169172calt1"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -821,10 +821,19 @@
821 ** current transaction. This hint is not guaranteed to be accurate but it
822 ** is often close. The underlying VFS might choose to preallocate database
823 ** file space based on this hint in order to help writes to the database
824 ** file run faster.
825 **
826 ** <li>[[SQLITE_FCNTL_SIZE_LIMIT]]
827 ** The [SQLITE_FCNTL_SIZE_LIMIT] opcode is used by in-memory VFS that
828 ** implements [sqlite3_deserialize()] to set an upper bound on the size
829 ** of the in-memory database. The argument is a pointer to a [sqlite3_int64].
830 ** If the integer pointed to is negative, then it is filled in with the
831 ** current limit. Otherwise the limit is set to the larger of the value
832 ** of the integer pointed to and the current database size. The integer
833 ** pointed to is set to the new limit.
834 **
835 ** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]
836 ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
837 ** extends and truncates the database file in chunks of a size specified
838 ** by the user. The fourth argument to [sqlite3_file_control()] should
839 ** point to an integer (type int) containing the new chunk-size to use
@@ -1129,10 +1138,11 @@
1138 #define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 31
1139 #define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32
1140 #define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33
1141 #define SQLITE_FCNTL_LOCK_TIMEOUT 34
1142 #define SQLITE_FCNTL_DATA_VERSION 35
1143 #define SQLITE_FCNTL_SIZE_LIMIT 36
1144
1145 /* deprecated names */
1146 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
1147 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
1148 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -11233,16 +11243,12 @@
11243 ** should be greater than or equal to zero and smaller than the value
11244 ** output by xInstCount().
11245 **
11246 ** Usually, output parameter *piPhrase is set to the phrase number, *piCol
11247 ** to the column in which it occurs and *piOff the token offset of the
11248 ** first token of the phrase. Returns SQLITE_OK if successful, or an error
11249 ** code (i.e. SQLITE_NOMEM) if an error occurs.
 
 
 
 
11250 **
11251 ** This API can be quite slow if used with an FTS5 table created with the
11252 ** "detail=none" or "detail=column" option.
11253 **
11254 ** xRowid:
11255
+15 -1
--- www/changes.wiki
+++ www/changes.wiki
@@ -30,26 +30,40 @@
3030
* Break out Wiki setup into a separate /setup_wiki page, accessible
3131
on the standard menus through Admin/Wiki.
3232
* Add "Next" and "Previous" buttons on the /wdiff page, allowing
3333
the user to step through the versions of a wiki page.
3434
* Improve the display of the /whistory page.
35
+ * Omit the "HH:MM" timestamps on timeline graphs on narrow-screen
36
+ devices, to improve horizontal space uses. This helps make Fossil
37
+ more mobile-friendly.
3538
* Enhance /wcontent to show a sortable list of Wiki pages together
3639
with the number of revisions and the most recent change time for
3740
each page.
3841
* Hyperlinks to Wiki pages on the /timeline go to the specific
3942
version of the Wiki page named in the timeline, not to the latest
4043
version.
4144
* Enhancements to the "amend", "tag", and "reparent" commands, including
4245
adding options --override-date, --override-user, and --dry-run.
46
+ * Add the global --comment-format command-line option and the
47
+ comment-format setting to control the display of the command-line
48
+ timeline.
49
+ * Change the "fossil reparent" command so that it only works from
50
+ within an active checkout.
4351
* On the /setup_ucap_list, show administrators how many users have
4452
each capability. The counts are a hyperlink to the /setup_ulist
4553
page showing the subset of users that have that capability.
54
+ * Provide the ability to redirect all HTTP pages to HTTPS. Formerly
55
+ one could cause this to occur for the /login page only. That option
56
+ still exists, but the redirect can now also be done for all pages.
4657
* "Compress" the built-in javascript by omitting comments and
4758
leading and trailing whitespace.
59
+ * Detect when the repository used by a checkout is swapped out for
60
+ a clone that uses different RID values, and make appropriate adjustments
61
+ to the checkout database to avoid any problems.
4862
* Add the backoffice-disable setting to completely disable the
4963
backoffice feature.
50
- * Update the built-in SQLite to version 3.26.0.
64
+ * Update the built-in SQLite to version 3.27.0 alpha.
5165
* Various other small enhancements to webpages and documentation.
5266
5367
5468
<a name='v2_7'></a>
5569
<h2>Changes for Version 2.7 (2018-09-22)</h2>
5670
--- www/changes.wiki
+++ www/changes.wiki
@@ -30,26 +30,40 @@
30 * Break out Wiki setup into a separate /setup_wiki page, accessible
31 on the standard menus through Admin/Wiki.
32 * Add "Next" and "Previous" buttons on the /wdiff page, allowing
33 the user to step through the versions of a wiki page.
34 * Improve the display of the /whistory page.
 
 
 
35 * Enhance /wcontent to show a sortable list of Wiki pages together
36 with the number of revisions and the most recent change time for
37 each page.
38 * Hyperlinks to Wiki pages on the /timeline go to the specific
39 version of the Wiki page named in the timeline, not to the latest
40 version.
41 * Enhancements to the "amend", "tag", and "reparent" commands, including
42 adding options --override-date, --override-user, and --dry-run.
 
 
 
 
 
43 * On the /setup_ucap_list, show administrators how many users have
44 each capability. The counts are a hyperlink to the /setup_ulist
45 page showing the subset of users that have that capability.
 
 
 
46 * "Compress" the built-in javascript by omitting comments and
47 leading and trailing whitespace.
 
 
 
48 * Add the backoffice-disable setting to completely disable the
49 backoffice feature.
50 * Update the built-in SQLite to version 3.26.0.
51 * Various other small enhancements to webpages and documentation.
52
53
54 <a name='v2_7'></a>
55 <h2>Changes for Version 2.7 (2018-09-22)</h2>
56
--- www/changes.wiki
+++ www/changes.wiki
@@ -30,26 +30,40 @@
30 * Break out Wiki setup into a separate /setup_wiki page, accessible
31 on the standard menus through Admin/Wiki.
32 * Add "Next" and "Previous" buttons on the /wdiff page, allowing
33 the user to step through the versions of a wiki page.
34 * Improve the display of the /whistory page.
35 * Omit the "HH:MM" timestamps on timeline graphs on narrow-screen
36 devices, to improve horizontal space uses. This helps make Fossil
37 more mobile-friendly.
38 * Enhance /wcontent to show a sortable list of Wiki pages together
39 with the number of revisions and the most recent change time for
40 each page.
41 * Hyperlinks to Wiki pages on the /timeline go to the specific
42 version of the Wiki page named in the timeline, not to the latest
43 version.
44 * Enhancements to the "amend", "tag", and "reparent" commands, including
45 adding options --override-date, --override-user, and --dry-run.
46 * Add the global --comment-format command-line option and the
47 comment-format setting to control the display of the command-line
48 timeline.
49 * Change the "fossil reparent" command so that it only works from
50 within an active checkout.
51 * On the /setup_ucap_list, show administrators how many users have
52 each capability. The counts are a hyperlink to the /setup_ulist
53 page showing the subset of users that have that capability.
54 * Provide the ability to redirect all HTTP pages to HTTPS. Formerly
55 one could cause this to occur for the /login page only. That option
56 still exists, but the redirect can now also be done for all pages.
57 * "Compress" the built-in javascript by omitting comments and
58 leading and trailing whitespace.
59 * Detect when the repository used by a checkout is swapped out for
60 a clone that uses different RID values, and make appropriate adjustments
61 to the checkout database to avoid any problems.
62 * Add the backoffice-disable setting to completely disable the
63 backoffice feature.
64 * Update the built-in SQLite to version 3.27.0 alpha.
65 * Various other small enhancements to webpages and documentation.
66
67
68 <a name='v2_7'></a>
69 <h2>Changes for Version 2.7 (2018-09-22)</h2>
70

Keyboard Shortcuts

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