Fossil SCM

Merge trunk. Openssl 1.1.0d -> 1.1.0e

jan.nijtmans 2017-02-18 18:13 openssl-1.1 merge
Commit 28173845f9907dce08181a3ba3d45cdd23c25660
+4
--- src/add.c
+++ src/add.c
@@ -276,10 +276,11 @@
276276
** -f|--force Add files without prompting
277277
** --ignore <CSG> Ignore files matching patterns from the
278278
** comma separated list of glob patterns.
279279
** --clean <CSG> Also ignore files matching patterns from
280280
** the comma separated list of glob patterns.
281
+** --no-dir-symlinks Disables support for directory symlinks.
281282
**
282283
** See also: addremove, rm
283284
*/
284285
void add_cmd(void){
285286
int i; /* Loop counter */
@@ -441,10 +442,11 @@
441442
** --soft Skip removing files from the checkout.
442443
** This supersedes the --hard option.
443444
** --hard Remove files from the checkout.
444445
** --case-sensitive <BOOL> Override the case-sensitive setting.
445446
** -n|--dry-run If given, display instead of run actions.
447
+** --no-dir-symlinks Disables support for directory symlinks.
446448
**
447449
** See also: addremove, add
448450
*/
449451
void delete_cmd(void){
450452
int i;
@@ -622,10 +624,11 @@
622624
** --ignore <CSG> Ignore files matching patterns from the
623625
** comma separated list of glob patterns.
624626
** --clean <CSG> Also ignore files matching patterns from
625627
** the comma separated list of glob patterns.
626628
** -n|--dry-run If given, display instead of run actions.
629
+** --no-dir-symlinks Disables support for directory symlinks.
627630
**
628631
** See also: add, rm
629632
*/
630633
void addremove_cmd(void){
631634
Blob path;
@@ -849,10 +852,11 @@
849852
** --soft Skip moving files within the checkout.
850853
** This supersedes the --hard option.
851854
** --hard Move files within the checkout.
852855
** --case-sensitive <BOOL> Override the case-sensitive setting.
853856
** -n|--dry-run If given, display instead of run actions.
857
+** --no-dir-symlinks Disables support for directory symlinks.
854858
**
855859
** See also: changes, status
856860
*/
857861
void mv_cmd(void){
858862
int i;
859863
--- src/add.c
+++ src/add.c
@@ -276,10 +276,11 @@
276 ** -f|--force Add files without prompting
277 ** --ignore <CSG> Ignore files matching patterns from the
278 ** comma separated list of glob patterns.
279 ** --clean <CSG> Also ignore files matching patterns from
280 ** the comma separated list of glob patterns.
 
281 **
282 ** See also: addremove, rm
283 */
284 void add_cmd(void){
285 int i; /* Loop counter */
@@ -441,10 +442,11 @@
441 ** --soft Skip removing files from the checkout.
442 ** This supersedes the --hard option.
443 ** --hard Remove files from the checkout.
444 ** --case-sensitive <BOOL> Override the case-sensitive setting.
445 ** -n|--dry-run If given, display instead of run actions.
 
446 **
447 ** See also: addremove, add
448 */
449 void delete_cmd(void){
450 int i;
@@ -622,10 +624,11 @@
622 ** --ignore <CSG> Ignore files matching patterns from the
623 ** comma separated list of glob patterns.
624 ** --clean <CSG> Also ignore files matching patterns from
625 ** the comma separated list of glob patterns.
626 ** -n|--dry-run If given, display instead of run actions.
 
627 **
628 ** See also: add, rm
629 */
630 void addremove_cmd(void){
631 Blob path;
@@ -849,10 +852,11 @@
849 ** --soft Skip moving files within the checkout.
850 ** This supersedes the --hard option.
851 ** --hard Move files within the checkout.
852 ** --case-sensitive <BOOL> Override the case-sensitive setting.
853 ** -n|--dry-run If given, display instead of run actions.
 
854 **
855 ** See also: changes, status
856 */
857 void mv_cmd(void){
858 int i;
859
--- src/add.c
+++ src/add.c
@@ -276,10 +276,11 @@
276 ** -f|--force Add files without prompting
277 ** --ignore <CSG> Ignore files matching patterns from the
278 ** comma separated list of glob patterns.
279 ** --clean <CSG> Also ignore files matching patterns from
280 ** the comma separated list of glob patterns.
281 ** --no-dir-symlinks Disables support for directory symlinks.
282 **
283 ** See also: addremove, rm
284 */
285 void add_cmd(void){
286 int i; /* Loop counter */
@@ -441,10 +442,11 @@
442 ** --soft Skip removing files from the checkout.
443 ** This supersedes the --hard option.
444 ** --hard Remove files from the checkout.
445 ** --case-sensitive <BOOL> Override the case-sensitive setting.
446 ** -n|--dry-run If given, display instead of run actions.
447 ** --no-dir-symlinks Disables support for directory symlinks.
448 **
449 ** See also: addremove, add
450 */
451 void delete_cmd(void){
452 int i;
@@ -622,10 +624,11 @@
624 ** --ignore <CSG> Ignore files matching patterns from the
625 ** comma separated list of glob patterns.
626 ** --clean <CSG> Also ignore files matching patterns from
627 ** the comma separated list of glob patterns.
628 ** -n|--dry-run If given, display instead of run actions.
629 ** --no-dir-symlinks Disables support for directory symlinks.
630 **
631 ** See also: add, rm
632 */
633 void addremove_cmd(void){
634 Blob path;
@@ -849,10 +852,11 @@
852 ** --soft Skip moving files within the checkout.
853 ** This supersedes the --hard option.
854 ** --hard Move files within the checkout.
855 ** --case-sensitive <BOOL> Override the case-sensitive setting.
856 ** -n|--dry-run If given, display instead of run actions.
857 ** --no-dir-symlinks Disables support for directory symlinks.
858 **
859 ** See also: changes, status
860 */
861 void mv_cmd(void){
862 int i;
863
--- src/allrepo.c
+++ src/allrepo.c
@@ -418,10 +418,11 @@
418418
if( showLabel ){
419419
int len = (int)strlen(zFilename);
420420
int nStar = 80 - (len + 15);
421421
if( nStar<2 ) nStar = 1;
422422
fossil_print("%.13c %s %.*c\n", '*', zFilename, nStar, '*');
423
+ fflush(stdout);
423424
}
424425
if( !quiet || dryRunFlag ){
425426
fossil_print("%s\n", zSyscmd);
426427
fflush(stdout);
427428
}
428429
--- src/allrepo.c
+++ src/allrepo.c
@@ -418,10 +418,11 @@
418 if( showLabel ){
419 int len = (int)strlen(zFilename);
420 int nStar = 80 - (len + 15);
421 if( nStar<2 ) nStar = 1;
422 fossil_print("%.13c %s %.*c\n", '*', zFilename, nStar, '*');
 
423 }
424 if( !quiet || dryRunFlag ){
425 fossil_print("%s\n", zSyscmd);
426 fflush(stdout);
427 }
428
--- src/allrepo.c
+++ src/allrepo.c
@@ -418,10 +418,11 @@
418 if( showLabel ){
419 int len = (int)strlen(zFilename);
420 int nStar = 80 - (len + 15);
421 if( nStar<2 ) nStar = 1;
422 fossil_print("%.13c %s %.*c\n", '*', zFilename, nStar, '*');
423 fflush(stdout);
424 }
425 if( !quiet || dryRunFlag ){
426 fossil_print("%s\n", zSyscmd);
427 fflush(stdout);
428 }
429
+42 -3
--- src/branch.c
+++ src/branch.c
@@ -239,20 +239,40 @@
239239
break;
240240
}
241241
}
242242
}
243243
244
+/*
245
+** If the branch named in the argument is open, return a RID for one of
246
+** the open leaves of that branch. If the branch does not exists or is
247
+** closed, return 0.
248
+*/
249
+int branch_is_open(const char *zBrName){
250
+ return db_int(0,
251
+ "SELECT rid FROM tagxref AS ox"
252
+ " WHERE tagid=%d"
253
+ " AND tagtype=2"
254
+ " AND value=%Q"
255
+ " AND rid IN leaf"
256
+ " AND NOT EXISTS(SELECT 1 FROM tagxref AS ix"
257
+ " WHERE tagid=%d"
258
+ " AND tagtype=1"
259
+ " AND ox.rid=ix.rid)",
260
+ TAG_BRANCH, zBrName, TAG_CLOSED
261
+ );
262
+}
263
+
244264
245265
/*
246266
** COMMAND: branch
247267
**
248268
** Usage: %fossil branch SUBCOMMAND ... ?OPTIONS?
249269
**
250270
** Run various subcommands to manage branches of the open repository or
251271
** of the repository identified by the -R or --repository option.
252272
**
253
-** %fossil branch new BRANCH-NAME BASIS ?OPTIONS?
273
+** fossil branch new BRANCH-NAME BASIS ?OPTIONS?
254274
**
255275
** Create a new branch BRANCH-NAME off of check-in BASIS.
256276
** Supported options for this subcommand include:
257277
** --private branch is private (i.e., remains local)
258278
** --bgcolor COLOR use COLOR instead of automatic background
@@ -264,16 +284,20 @@
264284
** year-month-day form, it may be truncated, the "T" may be
265285
** replaced by a space, and it may also name a timezone offset
266286
** from UTC as "-HH:MM" (westward) or "+HH:MM" (eastward).
267287
** Either no timezone suffix or "Z" means UTC.
268288
**
269
-** %fossil branch list|ls ?-a|--all|-c|--closed?
289
+** fossil branch list|ls ?-a|--all|-c|--closed?
270290
**
271291
** List all branches. Use -a or --all to list all branches and
272292
** -c or --closed to list all closed branches. The default is to
273293
** show only open branches.
274294
**
295
+** fossil branch info BRANCH-NAME
296
+**
297
+** Print information about a branch
298
+**
275299
** Options:
276300
** -R|--repository FILE Run commands on repository FILE
277301
*/
278302
void branch_cmd(void){
279303
int n;
@@ -301,13 +325,28 @@
301325
const char *zBr = db_column_text(&q, 0);
302326
int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0;
303327
fossil_print("%s%s\n", (isCur ? "* " : " "), zBr);
304328
}
305329
db_finalize(&q);
330
+ }else if( strncmp(zCmd,"info",n)==0 ){
331
+ int i;
332
+ for(i=3; i<g.argc; i++){
333
+ const char *zBrName = g.argv[i];
334
+ int rid = branch_is_open(zBrName);
335
+ if( rid==0 ){
336
+ fossil_print("%s: not an open branch\n", zBrName);
337
+ }else{
338
+ const char *zUuid = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",rid);
339
+ const char *zDate = db_text(0,
340
+ "SELECT datetime(mtime,toLocal()) FROM event"
341
+ " WHERE objid=%d", rid);
342
+ fossil_print("%s: open as of %s on %.16s\n", zBrName, zDate, zUuid);
343
+ }
344
+ }
306345
}else{
307346
fossil_fatal("branch subcommand should be one of: "
308
- "new list ls");
347
+ "info list ls new");
309348
}
310349
}
311350
312351
static const char brlistQuery[] =
313352
@ SELECT
314353
--- src/branch.c
+++ src/branch.c
@@ -239,20 +239,40 @@
239 break;
240 }
241 }
242 }
243
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
245 /*
246 ** COMMAND: branch
247 **
248 ** Usage: %fossil branch SUBCOMMAND ... ?OPTIONS?
249 **
250 ** Run various subcommands to manage branches of the open repository or
251 ** of the repository identified by the -R or --repository option.
252 **
253 ** %fossil branch new BRANCH-NAME BASIS ?OPTIONS?
254 **
255 ** Create a new branch BRANCH-NAME off of check-in BASIS.
256 ** Supported options for this subcommand include:
257 ** --private branch is private (i.e., remains local)
258 ** --bgcolor COLOR use COLOR instead of automatic background
@@ -264,16 +284,20 @@
264 ** year-month-day form, it may be truncated, the "T" may be
265 ** replaced by a space, and it may also name a timezone offset
266 ** from UTC as "-HH:MM" (westward) or "+HH:MM" (eastward).
267 ** Either no timezone suffix or "Z" means UTC.
268 **
269 ** %fossil branch list|ls ?-a|--all|-c|--closed?
270 **
271 ** List all branches. Use -a or --all to list all branches and
272 ** -c or --closed to list all closed branches. The default is to
273 ** show only open branches.
274 **
 
 
 
 
275 ** Options:
276 ** -R|--repository FILE Run commands on repository FILE
277 */
278 void branch_cmd(void){
279 int n;
@@ -301,13 +325,28 @@
301 const char *zBr = db_column_text(&q, 0);
302 int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0;
303 fossil_print("%s%s\n", (isCur ? "* " : " "), zBr);
304 }
305 db_finalize(&q);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
306 }else{
307 fossil_fatal("branch subcommand should be one of: "
308 "new list ls");
309 }
310 }
311
312 static const char brlistQuery[] =
313 @ SELECT
314
--- src/branch.c
+++ src/branch.c
@@ -239,20 +239,40 @@
239 break;
240 }
241 }
242 }
243
244 /*
245 ** If the branch named in the argument is open, return a RID for one of
246 ** the open leaves of that branch. If the branch does not exists or is
247 ** closed, return 0.
248 */
249 int branch_is_open(const char *zBrName){
250 return db_int(0,
251 "SELECT rid FROM tagxref AS ox"
252 " WHERE tagid=%d"
253 " AND tagtype=2"
254 " AND value=%Q"
255 " AND rid IN leaf"
256 " AND NOT EXISTS(SELECT 1 FROM tagxref AS ix"
257 " WHERE tagid=%d"
258 " AND tagtype=1"
259 " AND ox.rid=ix.rid)",
260 TAG_BRANCH, zBrName, TAG_CLOSED
261 );
262 }
263
264
265 /*
266 ** COMMAND: branch
267 **
268 ** Usage: %fossil branch SUBCOMMAND ... ?OPTIONS?
269 **
270 ** Run various subcommands to manage branches of the open repository or
271 ** of the repository identified by the -R or --repository option.
272 **
273 ** fossil branch new BRANCH-NAME BASIS ?OPTIONS?
274 **
275 ** Create a new branch BRANCH-NAME off of check-in BASIS.
276 ** Supported options for this subcommand include:
277 ** --private branch is private (i.e., remains local)
278 ** --bgcolor COLOR use COLOR instead of automatic background
@@ -264,16 +284,20 @@
284 ** year-month-day form, it may be truncated, the "T" may be
285 ** replaced by a space, and it may also name a timezone offset
286 ** from UTC as "-HH:MM" (westward) or "+HH:MM" (eastward).
287 ** Either no timezone suffix or "Z" means UTC.
288 **
289 ** fossil branch list|ls ?-a|--all|-c|--closed?
290 **
291 ** List all branches. Use -a or --all to list all branches and
292 ** -c or --closed to list all closed branches. The default is to
293 ** show only open branches.
294 **
295 ** fossil branch info BRANCH-NAME
296 **
297 ** Print information about a branch
298 **
299 ** Options:
300 ** -R|--repository FILE Run commands on repository FILE
301 */
302 void branch_cmd(void){
303 int n;
@@ -301,13 +325,28 @@
325 const char *zBr = db_column_text(&q, 0);
326 int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0;
327 fossil_print("%s%s\n", (isCur ? "* " : " "), zBr);
328 }
329 db_finalize(&q);
330 }else if( strncmp(zCmd,"info",n)==0 ){
331 int i;
332 for(i=3; i<g.argc; i++){
333 const char *zBrName = g.argv[i];
334 int rid = branch_is_open(zBrName);
335 if( rid==0 ){
336 fossil_print("%s: not an open branch\n", zBrName);
337 }else{
338 const char *zUuid = db_text(0,"SELECT uuid FROM blob WHERE rid=%d",rid);
339 const char *zDate = db_text(0,
340 "SELECT datetime(mtime,toLocal()) FROM event"
341 " WHERE objid=%d", rid);
342 fossil_print("%s: open as of %s on %.16s\n", zBrName, zDate, zUuid);
343 }
344 }
345 }else{
346 fossil_fatal("branch subcommand should be one of: "
347 "info list ls new");
348 }
349 }
350
351 static const char brlistQuery[] =
352 @ SELECT
353
+20 -9
--- src/checkin.c
+++ src/checkin.c
@@ -417,10 +417,11 @@
417417
** --sha1sum Verify file status using SHA1 hashing rather than
418418
** relying on file mtimes.
419419
** --case-sensitive <BOOL> Override case-sensitive setting.
420420
** --dotfiles Include unmanaged files beginning with a dot.
421421
** --ignore <CSG> Ignore unmanaged files matching CSG glob patterns.
422
+** --no-dir-symlinks Disables support for directory symlinks.
422423
**
423424
** Options specific to the changes command:
424425
** --header Identify the repository if report is non-empty.
425426
** -v|--verbose Say "(none)" if the change report is empty.
426427
** --classify Start each line with the file's change type.
@@ -824,10 +825,11 @@
824825
** --abs-paths Display absolute pathnames.
825826
** --case-sensitive <BOOL> override case-sensitive setting
826827
** --dotfiles include files beginning with a dot (".")
827828
** --header Identify the repository if there are extras
828829
** --ignore <CSG> ignore files matching patterns from the argument
830
+** --no-dir-symlinks Disables support for directory symlinks.
829831
** --rel-paths Display pathnames relative to the current working
830832
** directory.
831833
**
832834
** See also: changes, clean, status
833835
*/
@@ -855,11 +857,10 @@
855857
zIgnoreFlag = db_get("ignore-glob", 0);
856858
}
857859
pIgnore = glob_create(zIgnoreFlag);
858860
locate_unmanaged_files(g.argc-2, g.argv+2, scanFlags, pIgnore);
859861
glob_free(pIgnore);
860
- g.allowSymlinks = 1; /* Report on symbolic links */
861862
862863
blob_zero(&report);
863864
status_report(&report, flags);
864865
if( blob_size(&report) ){
865866
if( showHdr ){
@@ -899,13 +900,14 @@
899900
**
900901
** The default values for --clean, --ignore, and --keep are determined by
901902
** the (versionable) clean-glob, ignore-glob, and keep-glob settings.
902903
**
903904
** The --verily option ignores the keep-glob and ignore-glob settings and
904
-** turns on --force, --emptydirs, --dotfiles, and --disable-undo. Use the
905
-** --verily option when you really want to clean up everything. Extreme
906
-** care should be exercised when using the --verily option.
905
+** turns on the options --force, --emptydirs, --dotfiles, --disable-undo,
906
+** and --no-dir-symlinks. Use the --verily option when you really want
907
+** to clean up everything. Extreme care should be exercised when using
908
+** the --verily option.
907909
**
908910
** Options:
909911
** --allckouts Check for empty directories within any checkouts
910912
** that may be nested within the current one. This
911913
** option should be used with great care because the
@@ -931,14 +933,14 @@
931933
** -i|--prompt Prompt before removing each file. This option
932934
** implies the --disable-undo option.
933935
** -x|--verily WARNING: Removes everything that is not a managed
934936
** file or the repository itself. This option
935937
** implies the --force, --emptydirs, --dotfiles, and
936
-** --disable-undo options. Furthermore, it completely
937
-** disregards the keep-glob and ignore-glob settings.
938
-** However, it does honor the --ignore and --keep
939
-** options.
938
+** --disable-undo, and --no-dir-symlinks options.
939
+** Furthermore, it completely disregards the keep-glob
940
+** and ignore-glob settings. However, it does honor
941
+** the --ignore and --keep options.
940942
** --clean <CSG> WARNING: Never prompt to delete any files matching
941943
** this comma separated list of glob patterns. Also,
942944
** deletions of any files matching this pattern list
943945
** cannot be undone.
944946
** --ignore <CSG> Ignore files matching patterns from the
@@ -947,10 +949,11 @@
947949
** list of glob patterns.
948950
** -n|--dry-run Delete nothing, but display what would have been
949951
** deleted.
950952
** --no-prompt This option disables prompting the user for input
951953
** and assumes an answer of 'No' for every question.
954
+** --no-dir-symlinks Disables support for directory symlinks.
952955
** --temp Remove only Fossil-generated temporary files.
953956
** -v|--verbose Show all files as they are removed.
954957
**
955958
** See also: addremove, extras, status
956959
*/
@@ -995,10 +998,12 @@
995998
verilyFlag = allFileFlag = allDirFlag = 1;
996999
emptyDirsFlag = 1;
9971000
disableUndo = 1;
9981001
scanFlags |= SCAN_ALL;
9991002
zCleanFlag = 0;
1003
+ g.fNoDirSymlinks = 1; /* Forbid symlink directory traversal. */
1004
+ g.allowSymlinks = 1; /* Treat symlink files as content. */
10001005
}
10011006
if( zIgnoreFlag==0 && !verilyFlag ){
10021007
zIgnoreFlag = db_get("ignore-glob", 0);
10031008
}
10041009
if( zKeepFlag==0 && !verilyFlag ){
@@ -1011,11 +1016,10 @@
10111016
verify_all_options();
10121017
pIgnore = glob_create(zIgnoreFlag);
10131018
pKeep = glob_create(zKeepFlag);
10141019
pClean = glob_create(zCleanFlag);
10151020
nRoot = (int)strlen(g.zLocalRoot);
1016
- g.allowSymlinks = 1; /* Find symlinks too */
10171021
if( !dirsOnlyFlag ){
10181022
Stmt q;
10191023
Blob repo;
10201024
if( !dryRunFlag && !disableUndo ) undo_begin();
10211025
locate_unmanaged_files(g.argc-2, g.argv+2, scanFlags, pIgnore);
@@ -2112,10 +2116,17 @@
21122116
noSign = db_get_boolean("omitsign", 0)|noSign;
21132117
if( db_get_boolean("clearsign", 0)==0 ){ noSign = 1; }
21142118
useCksum = db_get_boolean("repo-cksum", 1);
21152119
outputManifest = db_get_manifest_setting();
21162120
verify_all_options();
2121
+
2122
+ /* Do not allow the creation of a new branch using an existing open
2123
+ ** branch name unless the --force flag is used */
2124
+ if( sCiInfo.zBranch!=0 && !forceFlag && branch_is_open(sCiInfo.zBranch) ){
2125
+ fossil_fatal("an open branch named \"%s\" already exists - use --force"
2126
+ " to override", sCiInfo.zBranch);
2127
+ }
21172128
21182129
/* Escape special characters in tags and put all tags in sorted order */
21192130
if( nTag ){
21202131
int i;
21212132
for(i=0; i<nTag; i++) sCiInfo.azTag[i] = mprintf("%F", sCiInfo.azTag[i]);
21222133
--- src/checkin.c
+++ src/checkin.c
@@ -417,10 +417,11 @@
417 ** --sha1sum Verify file status using SHA1 hashing rather than
418 ** relying on file mtimes.
419 ** --case-sensitive <BOOL> Override case-sensitive setting.
420 ** --dotfiles Include unmanaged files beginning with a dot.
421 ** --ignore <CSG> Ignore unmanaged files matching CSG glob patterns.
 
422 **
423 ** Options specific to the changes command:
424 ** --header Identify the repository if report is non-empty.
425 ** -v|--verbose Say "(none)" if the change report is empty.
426 ** --classify Start each line with the file's change type.
@@ -824,10 +825,11 @@
824 ** --abs-paths Display absolute pathnames.
825 ** --case-sensitive <BOOL> override case-sensitive setting
826 ** --dotfiles include files beginning with a dot (".")
827 ** --header Identify the repository if there are extras
828 ** --ignore <CSG> ignore files matching patterns from the argument
 
829 ** --rel-paths Display pathnames relative to the current working
830 ** directory.
831 **
832 ** See also: changes, clean, status
833 */
@@ -855,11 +857,10 @@
855 zIgnoreFlag = db_get("ignore-glob", 0);
856 }
857 pIgnore = glob_create(zIgnoreFlag);
858 locate_unmanaged_files(g.argc-2, g.argv+2, scanFlags, pIgnore);
859 glob_free(pIgnore);
860 g.allowSymlinks = 1; /* Report on symbolic links */
861
862 blob_zero(&report);
863 status_report(&report, flags);
864 if( blob_size(&report) ){
865 if( showHdr ){
@@ -899,13 +900,14 @@
899 **
900 ** The default values for --clean, --ignore, and --keep are determined by
901 ** the (versionable) clean-glob, ignore-glob, and keep-glob settings.
902 **
903 ** The --verily option ignores the keep-glob and ignore-glob settings and
904 ** turns on --force, --emptydirs, --dotfiles, and --disable-undo. Use the
905 ** --verily option when you really want to clean up everything. Extreme
906 ** care should be exercised when using the --verily option.
 
907 **
908 ** Options:
909 ** --allckouts Check for empty directories within any checkouts
910 ** that may be nested within the current one. This
911 ** option should be used with great care because the
@@ -931,14 +933,14 @@
931 ** -i|--prompt Prompt before removing each file. This option
932 ** implies the --disable-undo option.
933 ** -x|--verily WARNING: Removes everything that is not a managed
934 ** file or the repository itself. This option
935 ** implies the --force, --emptydirs, --dotfiles, and
936 ** --disable-undo options. Furthermore, it completely
937 ** disregards the keep-glob and ignore-glob settings.
938 ** However, it does honor the --ignore and --keep
939 ** options.
940 ** --clean <CSG> WARNING: Never prompt to delete any files matching
941 ** this comma separated list of glob patterns. Also,
942 ** deletions of any files matching this pattern list
943 ** cannot be undone.
944 ** --ignore <CSG> Ignore files matching patterns from the
@@ -947,10 +949,11 @@
947 ** list of glob patterns.
948 ** -n|--dry-run Delete nothing, but display what would have been
949 ** deleted.
950 ** --no-prompt This option disables prompting the user for input
951 ** and assumes an answer of 'No' for every question.
 
952 ** --temp Remove only Fossil-generated temporary files.
953 ** -v|--verbose Show all files as they are removed.
954 **
955 ** See also: addremove, extras, status
956 */
@@ -995,10 +998,12 @@
995 verilyFlag = allFileFlag = allDirFlag = 1;
996 emptyDirsFlag = 1;
997 disableUndo = 1;
998 scanFlags |= SCAN_ALL;
999 zCleanFlag = 0;
 
 
1000 }
1001 if( zIgnoreFlag==0 && !verilyFlag ){
1002 zIgnoreFlag = db_get("ignore-glob", 0);
1003 }
1004 if( zKeepFlag==0 && !verilyFlag ){
@@ -1011,11 +1016,10 @@
1011 verify_all_options();
1012 pIgnore = glob_create(zIgnoreFlag);
1013 pKeep = glob_create(zKeepFlag);
1014 pClean = glob_create(zCleanFlag);
1015 nRoot = (int)strlen(g.zLocalRoot);
1016 g.allowSymlinks = 1; /* Find symlinks too */
1017 if( !dirsOnlyFlag ){
1018 Stmt q;
1019 Blob repo;
1020 if( !dryRunFlag && !disableUndo ) undo_begin();
1021 locate_unmanaged_files(g.argc-2, g.argv+2, scanFlags, pIgnore);
@@ -2112,10 +2116,17 @@
2112 noSign = db_get_boolean("omitsign", 0)|noSign;
2113 if( db_get_boolean("clearsign", 0)==0 ){ noSign = 1; }
2114 useCksum = db_get_boolean("repo-cksum", 1);
2115 outputManifest = db_get_manifest_setting();
2116 verify_all_options();
 
 
 
 
 
 
 
2117
2118 /* Escape special characters in tags and put all tags in sorted order */
2119 if( nTag ){
2120 int i;
2121 for(i=0; i<nTag; i++) sCiInfo.azTag[i] = mprintf("%F", sCiInfo.azTag[i]);
2122
--- src/checkin.c
+++ src/checkin.c
@@ -417,10 +417,11 @@
417 ** --sha1sum Verify file status using SHA1 hashing rather than
418 ** relying on file mtimes.
419 ** --case-sensitive <BOOL> Override case-sensitive setting.
420 ** --dotfiles Include unmanaged files beginning with a dot.
421 ** --ignore <CSG> Ignore unmanaged files matching CSG glob patterns.
422 ** --no-dir-symlinks Disables support for directory symlinks.
423 **
424 ** Options specific to the changes command:
425 ** --header Identify the repository if report is non-empty.
426 ** -v|--verbose Say "(none)" if the change report is empty.
427 ** --classify Start each line with the file's change type.
@@ -824,10 +825,11 @@
825 ** --abs-paths Display absolute pathnames.
826 ** --case-sensitive <BOOL> override case-sensitive setting
827 ** --dotfiles include files beginning with a dot (".")
828 ** --header Identify the repository if there are extras
829 ** --ignore <CSG> ignore files matching patterns from the argument
830 ** --no-dir-symlinks Disables support for directory symlinks.
831 ** --rel-paths Display pathnames relative to the current working
832 ** directory.
833 **
834 ** See also: changes, clean, status
835 */
@@ -855,11 +857,10 @@
857 zIgnoreFlag = db_get("ignore-glob", 0);
858 }
859 pIgnore = glob_create(zIgnoreFlag);
860 locate_unmanaged_files(g.argc-2, g.argv+2, scanFlags, pIgnore);
861 glob_free(pIgnore);
 
862
863 blob_zero(&report);
864 status_report(&report, flags);
865 if( blob_size(&report) ){
866 if( showHdr ){
@@ -899,13 +900,14 @@
900 **
901 ** The default values for --clean, --ignore, and --keep are determined by
902 ** the (versionable) clean-glob, ignore-glob, and keep-glob settings.
903 **
904 ** The --verily option ignores the keep-glob and ignore-glob settings and
905 ** turns on the options --force, --emptydirs, --dotfiles, --disable-undo,
906 ** and --no-dir-symlinks. Use the --verily option when you really want
907 ** to clean up everything. Extreme care should be exercised when using
908 ** the --verily option.
909 **
910 ** Options:
911 ** --allckouts Check for empty directories within any checkouts
912 ** that may be nested within the current one. This
913 ** option should be used with great care because the
@@ -931,14 +933,14 @@
933 ** -i|--prompt Prompt before removing each file. This option
934 ** implies the --disable-undo option.
935 ** -x|--verily WARNING: Removes everything that is not a managed
936 ** file or the repository itself. This option
937 ** implies the --force, --emptydirs, --dotfiles, and
938 ** --disable-undo, and --no-dir-symlinks options.
939 ** Furthermore, it completely disregards the keep-glob
940 ** and ignore-glob settings. However, it does honor
941 ** the --ignore and --keep options.
942 ** --clean <CSG> WARNING: Never prompt to delete any files matching
943 ** this comma separated list of glob patterns. Also,
944 ** deletions of any files matching this pattern list
945 ** cannot be undone.
946 ** --ignore <CSG> Ignore files matching patterns from the
@@ -947,10 +949,11 @@
949 ** list of glob patterns.
950 ** -n|--dry-run Delete nothing, but display what would have been
951 ** deleted.
952 ** --no-prompt This option disables prompting the user for input
953 ** and assumes an answer of 'No' for every question.
954 ** --no-dir-symlinks Disables support for directory symlinks.
955 ** --temp Remove only Fossil-generated temporary files.
956 ** -v|--verbose Show all files as they are removed.
957 **
958 ** See also: addremove, extras, status
959 */
@@ -995,10 +998,12 @@
998 verilyFlag = allFileFlag = allDirFlag = 1;
999 emptyDirsFlag = 1;
1000 disableUndo = 1;
1001 scanFlags |= SCAN_ALL;
1002 zCleanFlag = 0;
1003 g.fNoDirSymlinks = 1; /* Forbid symlink directory traversal. */
1004 g.allowSymlinks = 1; /* Treat symlink files as content. */
1005 }
1006 if( zIgnoreFlag==0 && !verilyFlag ){
1007 zIgnoreFlag = db_get("ignore-glob", 0);
1008 }
1009 if( zKeepFlag==0 && !verilyFlag ){
@@ -1011,11 +1016,10 @@
1016 verify_all_options();
1017 pIgnore = glob_create(zIgnoreFlag);
1018 pKeep = glob_create(zKeepFlag);
1019 pClean = glob_create(zCleanFlag);
1020 nRoot = (int)strlen(g.zLocalRoot);
 
1021 if( !dirsOnlyFlag ){
1022 Stmt q;
1023 Blob repo;
1024 if( !dryRunFlag && !disableUndo ) undo_begin();
1025 locate_unmanaged_files(g.argc-2, g.argv+2, scanFlags, pIgnore);
@@ -2112,10 +2116,17 @@
2116 noSign = db_get_boolean("omitsign", 0)|noSign;
2117 if( db_get_boolean("clearsign", 0)==0 ){ noSign = 1; }
2118 useCksum = db_get_boolean("repo-cksum", 1);
2119 outputManifest = db_get_manifest_setting();
2120 verify_all_options();
2121
2122 /* Do not allow the creation of a new branch using an existing open
2123 ** branch name unless the --force flag is used */
2124 if( sCiInfo.zBranch!=0 && !forceFlag && branch_is_open(sCiInfo.zBranch) ){
2125 fossil_fatal("an open branch named \"%s\" already exists - use --force"
2126 " to override", sCiInfo.zBranch);
2127 }
2128
2129 /* Escape special characters in tags and put all tags in sorted order */
2130 if( nTag ){
2131 int i;
2132 for(i=0; i<nTag; i++) sCiInfo.azTag[i] = mprintf("%F", sCiInfo.azTag[i]);
2133
+18 -6
--- src/db.c
+++ src/db.c
@@ -1423,19 +1423,31 @@
14231423
return zRepo;
14241424
}
14251425
14261426
/*
14271427
** Returns non-zero if the default value for the "allow-symlinks" setting
1428
-** is "on".
1428
+** is "on". When on Windows, this always returns false.
14291429
*/
14301430
int db_allow_symlinks_by_default(void){
14311431
#if defined(_WIN32)
14321432
return 0;
14331433
#else
14341434
return 1;
14351435
#endif
14361436
}
1437
+
1438
+/*
1439
+** Returns non-zero if support for symlinks is currently enabled.
1440
+*/
1441
+int db_allow_symlinks(int traversal){
1442
+ if( traversal ){
1443
+ if( g.allowSymlinks ) return 1;
1444
+ return g.fNoDirSymlinks;
1445
+ }else{
1446
+ return g.allowSymlinks;
1447
+ }
1448
+}
14371449
14381450
/*
14391451
** Open the repository database given by zDbName. If zDbName==NULL then
14401452
** get the name from the already open local database.
14411453
*/
@@ -2263,15 +2275,15 @@
22632275
){
22642276
/* There's a versioned setting, and a non-versioned setting. Tell
22652277
** the user about the conflict */
22662278
fossil_warning(
22672279
"setting %s has both versioned and non-versioned values: using "
2268
- "versioned value from file .fossil-settings/%s (to silence this "
2269
- "warning, either create an empty file named "
2270
- ".fossil-settings/%s.no-warn in the check-out root, "
2271
- "or delete the non-versioned setting "
2272
- "with \"fossil unset %s\")", zName, zName, zName, zName
2280
+ "versioned value from file \"%/.fossil-settings/%s\" (to silence "
2281
+ "this warning, either create an empty file named "
2282
+ "\"%/.fossil-settings/%s.no-warn\" in the check-out root, or delete "
2283
+ "the non-versioned setting with \"fossil unset %s\")", zName,
2284
+ g.zLocalRoot, zName, g.zLocalRoot, zName, zName
22732285
);
22742286
}
22752287
/* Prefer the versioned setting */
22762288
return ( zVersionedSetting!=0 ) ? zVersionedSetting : zNonVersionedSetting;
22772289
}
22782290
--- src/db.c
+++ src/db.c
@@ -1423,19 +1423,31 @@
1423 return zRepo;
1424 }
1425
1426 /*
1427 ** Returns non-zero if the default value for the "allow-symlinks" setting
1428 ** is "on".
1429 */
1430 int db_allow_symlinks_by_default(void){
1431 #if defined(_WIN32)
1432 return 0;
1433 #else
1434 return 1;
1435 #endif
1436 }
 
 
 
 
 
 
 
 
 
 
 
 
1437
1438 /*
1439 ** Open the repository database given by zDbName. If zDbName==NULL then
1440 ** get the name from the already open local database.
1441 */
@@ -2263,15 +2275,15 @@
2263 ){
2264 /* There's a versioned setting, and a non-versioned setting. Tell
2265 ** the user about the conflict */
2266 fossil_warning(
2267 "setting %s has both versioned and non-versioned values: using "
2268 "versioned value from file .fossil-settings/%s (to silence this "
2269 "warning, either create an empty file named "
2270 ".fossil-settings/%s.no-warn in the check-out root, "
2271 "or delete the non-versioned setting "
2272 "with \"fossil unset %s\")", zName, zName, zName, zName
2273 );
2274 }
2275 /* Prefer the versioned setting */
2276 return ( zVersionedSetting!=0 ) ? zVersionedSetting : zNonVersionedSetting;
2277 }
2278
--- src/db.c
+++ src/db.c
@@ -1423,19 +1423,31 @@
1423 return zRepo;
1424 }
1425
1426 /*
1427 ** Returns non-zero if the default value for the "allow-symlinks" setting
1428 ** is "on". When on Windows, this always returns false.
1429 */
1430 int db_allow_symlinks_by_default(void){
1431 #if defined(_WIN32)
1432 return 0;
1433 #else
1434 return 1;
1435 #endif
1436 }
1437
1438 /*
1439 ** Returns non-zero if support for symlinks is currently enabled.
1440 */
1441 int db_allow_symlinks(int traversal){
1442 if( traversal ){
1443 if( g.allowSymlinks ) return 1;
1444 return g.fNoDirSymlinks;
1445 }else{
1446 return g.allowSymlinks;
1447 }
1448 }
1449
1450 /*
1451 ** Open the repository database given by zDbName. If zDbName==NULL then
1452 ** get the name from the already open local database.
1453 */
@@ -2263,15 +2275,15 @@
2275 ){
2276 /* There's a versioned setting, and a non-versioned setting. Tell
2277 ** the user about the conflict */
2278 fossil_warning(
2279 "setting %s has both versioned and non-versioned values: using "
2280 "versioned value from file \"%/.fossil-settings/%s\" (to silence "
2281 "this warning, either create an empty file named "
2282 "\"%/.fossil-settings/%s.no-warn\" in the check-out root, or delete "
2283 "the non-versioned setting with \"fossil unset %s\")", zName,
2284 g.zLocalRoot, zName, g.zLocalRoot, zName, zName
2285 );
2286 }
2287 /* Prefer the versioned setting */
2288 return ( zVersionedSetting!=0 ) ? zVersionedSetting : zNonVersionedSetting;
2289 }
2290
+7 -6
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -749,17 +749,18 @@
749749
/*
750750
** Returns non-zero if files that may be binary should be used with external
751751
** diff programs.
752752
*/
753753
int diff_include_binary_files(void){
754
- if( is_truth(find_option("diff-binary", 0, 1)) ){
755
- return 1;
754
+ const char* zArgIncludeBinary = find_option("diff-binary", 0, 1);
755
+
756
+ /* Command line argument have priority on settings */
757
+ if( zArgIncludeBinary ){
758
+ return is_truth(zArgIncludeBinary);
759
+ }else{
760
+ return db_get_boolean("diff-binary", 1);
756761
}
757
- if( db_get_boolean("diff-binary", 1) ){
758
- return 1;
759
- }
760
- return 0;
761762
}
762763
763764
/*
764765
** Returns the GLOB pattern for file names that should be treated as binary
765766
** by the diff subsystem, if any.
766767
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -749,17 +749,18 @@
749 /*
750 ** Returns non-zero if files that may be binary should be used with external
751 ** diff programs.
752 */
753 int diff_include_binary_files(void){
754 if( is_truth(find_option("diff-binary", 0, 1)) ){
755 return 1;
 
 
 
 
 
756 }
757 if( db_get_boolean("diff-binary", 1) ){
758 return 1;
759 }
760 return 0;
761 }
762
763 /*
764 ** Returns the GLOB pattern for file names that should be treated as binary
765 ** by the diff subsystem, if any.
766
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -749,17 +749,18 @@
749 /*
750 ** Returns non-zero if files that may be binary should be used with external
751 ** diff programs.
752 */
753 int diff_include_binary_files(void){
754 const char* zArgIncludeBinary = find_option("diff-binary", 0, 1);
755
756 /* Command line argument have priority on settings */
757 if( zArgIncludeBinary ){
758 return is_truth(zArgIncludeBinary);
759 }else{
760 return db_get_boolean("diff-binary", 1);
761 }
 
 
 
 
762 }
763
764 /*
765 ** Returns the GLOB pattern for file names that should be treated as binary
766 ** by the diff subsystem, if any.
767
+145 -25
--- src/file.c
+++ src/file.c
@@ -85,15 +85,20 @@
8585
/*
8686
** Fill stat buf with information received from stat() or lstat().
8787
** lstat() is called on Unix if isWd is TRUE and allow-symlinks setting is on.
8888
**
8989
*/
90
-static int fossil_stat(const char *zFilename, struct fossilStat *buf, int isWd){
90
+static int fossil_stat(
91
+ const char *zFilename, /* name of file or directory to inspect. */
92
+ struct fossilStat *buf, /* pointer to buffer where info should go. */
93
+ int isWd, /* non-zero to consider look at symlink itself. */
94
+ int forceWd /* non-zero to force look at symlink itself. */
95
+){
9196
int rc;
9297
void *zMbcs = fossil_utf8_to_path(zFilename, 0);
9398
#if !defined(_WIN32)
94
- if( isWd && g.allowSymlinks ){
99
+ if( isWd && (forceWd || db_allow_symlinks(0)) ){
95100
rc = lstat(zMbcs, buf);
96101
}else{
97102
rc = stat(zMbcs, buf);
98103
}
99104
#else
@@ -100,10 +105,18 @@
100105
rc = win32_stat(zMbcs, buf, isWd);
101106
#endif
102107
fossil_path_free(zMbcs);
103108
return rc;
104109
}
110
+
111
+/*
112
+** Clears the fileStat variable and its associated validity flag.
113
+*/
114
+static void resetStat(){
115
+ fileStatValid = 0;
116
+ memset(&fileStat, 0, sizeof(struct fossilStat));
117
+}
105118
106119
/*
107120
** Fill in the fileStat variable for the file named zFilename.
108121
** If zFilename==0, then use the previous value of fileStat if
109122
** there is a previous value.
@@ -115,11 +128,11 @@
115128
static int getStat(const char *zFilename, int isWd){
116129
int rc = 0;
117130
if( zFilename==0 ){
118131
if( fileStatValid==0 ) rc = 1;
119132
}else{
120
- if( fossil_stat(zFilename, &fileStat, isWd)!=0 ){
133
+ if( fossil_stat(zFilename, &fileStat, isWd, 0)!=0 ){
121134
fileStatValid = 0;
122135
rc = 1;
123136
}else{
124137
fileStatValid = 1;
125138
rc = 0;
@@ -157,10 +170,26 @@
157170
** Same as file_mtime(), but takes into account symlinks.
158171
*/
159172
i64 file_wd_mtime(const char *zFilename){
160173
return getStat(zFilename, 1) ? -1 : fileStat.st_mtime;
161174
}
175
+
176
+/*
177
+** Return the mode bits for a file. Return -1 if the file does not
178
+** exist. If zFilename is NULL return the size of the most recently
179
+** stat-ed file.
180
+*/
181
+int file_mode(const char *zFilename){
182
+ return getStat(zFilename, 0) ? -1 : fileStat.st_mode;
183
+}
184
+
185
+/*
186
+** Same as file_mode(), but takes into account symlinks.
187
+*/
188
+int file_wd_mode(const char *zFilename){
189
+ return getStat(zFilename, 1) ? -1 : fileStat.st_mode;
190
+}
162191
163192
/*
164193
** Return TRUE if the named file is an ordinary file or symlink
165194
** and symlinks are allowed.
166195
** Return false for directories, devices, fifos, etc.
@@ -191,11 +220,11 @@
191220
**
192221
** Arguments: target file (symlink will point to it), link file
193222
**/
194223
void symlink_create(const char *zTargetFile, const char *zLinkFile){
195224
#if !defined(_WIN32)
196
- if( g.allowSymlinks ){
225
+ if( db_allow_symlinks(0) ){
197226
int i, nName;
198227
char *zName, zBuf[1000];
199228
200229
nName = strlen(zLinkFile);
201230
if( nName>=sizeof(zBuf) ){
@@ -248,11 +277,11 @@
248277
int file_wd_perm(const char *zFilename){
249278
#if !defined(_WIN32)
250279
if( !getStat(zFilename, 1) ){
251280
if( S_ISREG(fileStat.st_mode) && ((S_IXUSR)&fileStat.st_mode)!=0 )
252281
return PERM_EXE;
253
- else if( g.allowSymlinks && S_ISLNK(fileStat.st_mode) )
282
+ else if( db_allow_symlinks(0) && S_ISLNK(fileStat.st_mode) )
254283
return PERM_LNK;
255284
}
256285
#endif
257286
return PERM_REG;
258287
}
@@ -301,19 +330,21 @@
301330
** but is something other than a directory.
302331
*/
303332
int file_wd_isdir(const char *zFilename){
304333
int rc;
305334
char *zFN;
335
+ struct fossilStat dirFileStat;
306336
307337
zFN = mprintf("%s", zFilename);
308338
file_simplify_name(zFN, -1, 0);
309
- rc = getStat(zFN, 1);
339
+ memset(&dirFileStat, 0, sizeof(struct fossilStat));
340
+ rc = fossil_stat(zFN, &dirFileStat, 1, 1);
310341
if( rc ){
311342
rc = 0; /* It does not exist at all. */
312
- }else if( S_ISDIR(fileStat.st_mode) ){
343
+ }else if( S_ISDIR(dirFileStat.st_mode) ){
313344
rc = 1; /* It exists and is a real directory. */
314
- }else if( S_ISLNK(fileStat.st_mode) ){
345
+ }else if( !db_allow_symlinks(1) && S_ISLNK(dirFileStat.st_mode) ){
315346
Blob content;
316347
blob_read_link(&content, zFN); /* It exists and is a link. */
317348
rc = file_wd_isdir(blob_str(&content)); /* Points to directory? */
318349
blob_reset(&content);
319350
}else{
@@ -480,11 +511,11 @@
480511
*/
481512
int file_wd_setexe(const char *zFilename, int onoff){
482513
int rc = 0;
483514
#if !defined(_WIN32)
484515
struct stat buf;
485
- if( fossil_stat(zFilename, &buf, 1)!=0 || S_ISLNK(buf.st_mode) ) return 0;
516
+ if( fossil_stat(zFilename, &buf, 1, 0)!=0 || S_ISLNK(buf.st_mode) ) return 0;
486517
if( onoff ){
487518
int targetMode = (buf.st_mode & 0444)>>2;
488519
if( (buf.st_mode & 0100)==0 ){
489520
chmod(zFilename, buf.st_mode | targetMode);
490521
rc = 1;
@@ -932,39 +963,123 @@
932963
}
933964
#endif
934965
blob_resize(pOut, file_simplify_name(blob_buffer(pOut),
935966
blob_size(pOut), slash));
936967
}
968
+
969
+/*
970
+** Emits the effective or raw stat() information for the specified
971
+** file or directory, optionally preserving the trailing slash and
972
+** resetting the cached stat() information.
973
+*/
974
+static void emitFileStat(
975
+ const char *zPath,
976
+ int raw,
977
+ int slash,
978
+ int reset
979
+){
980
+ char zBuf[100];
981
+ Blob x;
982
+ memset(zBuf, 0, sizeof(zBuf));
983
+ blob_zero(&x);
984
+ file_canonical_name(zPath, &x, slash);
985
+ fossil_print("%s[%s] -> [%s]\n", raw ? "RAW " : "", zPath, blob_buffer(&x));
986
+ blob_reset(&x);
987
+ if( raw ){
988
+ int rc;
989
+ struct fossilStat testFileStat;
990
+ memset(&testFileStat, 0, sizeof(struct fossilStat));
991
+ rc = fossil_stat(zPath, &testFileStat, 0, 0);
992
+ fossil_print(" stat_rc = %d\n", rc);
993
+ sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_size);
994
+ fossil_print(" stat_size = %s\n", zBuf);
995
+ sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_mtime);
996
+ fossil_print(" stat_mtime = %s\n", zBuf);
997
+ fossil_print(" stat_mode = %d\n", testFileStat.st_mode);
998
+ memset(&testFileStat, 0, sizeof(struct fossilStat));
999
+ rc = fossil_stat(zPath, &testFileStat, 1, 1);
1000
+ fossil_print(" l_stat_rc = %d\n", rc);
1001
+ sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_size);
1002
+ fossil_print(" l_stat_size = %s\n", zBuf);
1003
+ sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_mtime);
1004
+ fossil_print(" l_stat_mtime = %s\n", zBuf);
1005
+ fossil_print(" l_stat_mode = %d\n", testFileStat.st_mode);
1006
+ }else{
1007
+ if( reset ) resetStat();
1008
+ sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_wd_size(zPath));
1009
+ fossil_print(" file_size = %s\n", zBuf);
1010
+ sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_wd_mtime(zPath));
1011
+ fossil_print(" file_mtime = %s\n", zBuf);
1012
+ fossil_print(" file_mode = %d\n", file_wd_mode(zPath));
1013
+ fossil_print(" file_isfile = %d\n", file_wd_isfile(zPath));
1014
+ fossil_print(" file_isfile_or_link = %d\n", file_wd_isfile_or_link(zPath));
1015
+ fossil_print(" file_islink = %d\n", file_wd_islink(zPath));
1016
+ fossil_print(" file_isexe = %d\n", file_wd_isexe(zPath));
1017
+ fossil_print(" file_isdir = %d\n", file_wd_isdir(zPath));
1018
+ if( reset ) resetStat();
1019
+ }
1020
+}
1021
+
1022
+/*
1023
+** COMMAND: test-file-environment
1024
+**
1025
+** Usage: %fossil test-file-environment FILENAME...
1026
+**
1027
+** Display the effective file handling subsystem "settings" and then
1028
+** display file system information about the files specified, if any.
1029
+**
1030
+** Options:
1031
+**
1032
+** --open-config Open the configuration database first.
1033
+** --slash Trailing slashes, if any, are retained.
1034
+** --reset Reset cached stat() info for each file.
1035
+*/
1036
+void cmd_test_file_environment(void){
1037
+ int i;
1038
+ int slashFlag = find_option("slash",0,0)!=0;
1039
+ int resetFlag = find_option("reset",0,0)!=0;
1040
+ if( find_option("open-config", 0, 0)!=0 ){
1041
+ Th_OpenConfig(1);
1042
+ }
1043
+ fossil_print("Th_IsLocalOpen() = %d\n", Th_IsLocalOpen());
1044
+ fossil_print("Th_IsRepositoryOpen() = %d\n", Th_IsRepositoryOpen());
1045
+ fossil_print("Th_IsConfigOpen() = %d\n", Th_IsConfigOpen());
1046
+ fossil_print("filenames_are_case_sensitive() = %d\n",
1047
+ filenames_are_case_sensitive());
1048
+ fossil_print("db_allow_symlinks_by_default() = %d\n",
1049
+ db_allow_symlinks_by_default());
1050
+ fossil_print("db_allow_symlinks(0) = %d\n", db_allow_symlinks(0));
1051
+ fossil_print("db_allow_symlinks(1) = %d\n", db_allow_symlinks(1));
1052
+ for(i=2; i<g.argc; i++){
1053
+ emitFileStat(g.argv[i], 1, slashFlag, resetFlag);
1054
+ emitFileStat(g.argv[i], 0, slashFlag, resetFlag);
1055
+ }
1056
+}
9371057
9381058
/*
9391059
** COMMAND: test-canonical-name
9401060
**
9411061
** Usage: %fossil test-canonical-name FILENAME...
9421062
**
9431063
** Test the operation of the canonical name generator.
9441064
** Also test Fossil's ability to measure attributes of a file.
1065
+**
1066
+** Options:
1067
+**
1068
+** --open-config Open the configuration database first.
1069
+** --slash Trailing slashes, if any, are retained.
1070
+** --reset Reset cached stat() info for each file.
9451071
*/
9461072
void cmd_test_canonical_name(void){
9471073
int i;
948
- Blob x;
9491074
int slashFlag = find_option("slash",0,0)!=0;
950
- blob_zero(&x);
1075
+ int resetFlag = find_option("reset",0,0)!=0;
1076
+ if( find_option("open-config", 0, 0)!=0 ){
1077
+ Th_OpenConfig(1);
1078
+ }
9511079
for(i=2; i<g.argc; i++){
952
- char zBuf[100];
953
- const char *zName = g.argv[i];
954
- file_canonical_name(zName, &x, slashFlag);
955
- fossil_print("[%s] -> [%s]\n", zName, blob_buffer(&x));
956
- blob_reset(&x);
957
- sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_wd_size(zName));
958
- fossil_print(" file_size = %s\n", zBuf);
959
- sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_wd_mtime(zName));
960
- fossil_print(" file_mtime = %s\n", zBuf);
961
- fossil_print(" file_isfile = %d\n", file_wd_isfile(zName));
962
- fossil_print(" file_isfile_or_link = %d\n",file_wd_isfile_or_link(zName));
963
- fossil_print(" file_islink = %d\n", file_wd_islink(zName));
964
- fossil_print(" file_isexe = %d\n", file_wd_isexe(zName));
965
- fossil_print(" file_isdir = %d\n", file_wd_isdir(zName));
1080
+ emitFileStat(g.argv[i], 0, slashFlag, resetFlag);
9661081
}
9671082
}
9681083
9691084
/*
9701085
** Return TRUE if the given filename is canonical.
@@ -1075,10 +1190,14 @@
10751190
10761191
/*
10771192
** COMMAND: test-relative-name
10781193
**
10791194
** Test the operation of the relative name generator.
1195
+**
1196
+** Options:
1197
+**
1198
+** --slash Trailing slashes, if any, are retained.
10801199
*/
10811200
void cmd_test_relative_name(void){
10821201
int i;
10831202
Blob x;
10841203
int slashFlag = find_option("slash",0,0)!=0;
@@ -1194,10 +1313,11 @@
11941313
**
11951314
** Options:
11961315
** --absolute Return an absolute path instead of a relative one.
11971316
** --case-sensitive B Enable or disable case-sensitive filenames. B is
11981317
** a boolean: "yes", "no", "true", "false", etc.
1318
+** --no-dir-symlinks Disables support for directory symlinks.
11991319
*/
12001320
void cmd_test_tree_name(void){
12011321
int i;
12021322
Blob x;
12031323
int absoluteFlag = find_option("absolute",0,0)!=0;
12041324
--- src/file.c
+++ src/file.c
@@ -85,15 +85,20 @@
85 /*
86 ** Fill stat buf with information received from stat() or lstat().
87 ** lstat() is called on Unix if isWd is TRUE and allow-symlinks setting is on.
88 **
89 */
90 static int fossil_stat(const char *zFilename, struct fossilStat *buf, int isWd){
 
 
 
 
 
91 int rc;
92 void *zMbcs = fossil_utf8_to_path(zFilename, 0);
93 #if !defined(_WIN32)
94 if( isWd && g.allowSymlinks ){
95 rc = lstat(zMbcs, buf);
96 }else{
97 rc = stat(zMbcs, buf);
98 }
99 #else
@@ -100,10 +105,18 @@
100 rc = win32_stat(zMbcs, buf, isWd);
101 #endif
102 fossil_path_free(zMbcs);
103 return rc;
104 }
 
 
 
 
 
 
 
 
105
106 /*
107 ** Fill in the fileStat variable for the file named zFilename.
108 ** If zFilename==0, then use the previous value of fileStat if
109 ** there is a previous value.
@@ -115,11 +128,11 @@
115 static int getStat(const char *zFilename, int isWd){
116 int rc = 0;
117 if( zFilename==0 ){
118 if( fileStatValid==0 ) rc = 1;
119 }else{
120 if( fossil_stat(zFilename, &fileStat, isWd)!=0 ){
121 fileStatValid = 0;
122 rc = 1;
123 }else{
124 fileStatValid = 1;
125 rc = 0;
@@ -157,10 +170,26 @@
157 ** Same as file_mtime(), but takes into account symlinks.
158 */
159 i64 file_wd_mtime(const char *zFilename){
160 return getStat(zFilename, 1) ? -1 : fileStat.st_mtime;
161 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
163 /*
164 ** Return TRUE if the named file is an ordinary file or symlink
165 ** and symlinks are allowed.
166 ** Return false for directories, devices, fifos, etc.
@@ -191,11 +220,11 @@
191 **
192 ** Arguments: target file (symlink will point to it), link file
193 **/
194 void symlink_create(const char *zTargetFile, const char *zLinkFile){
195 #if !defined(_WIN32)
196 if( g.allowSymlinks ){
197 int i, nName;
198 char *zName, zBuf[1000];
199
200 nName = strlen(zLinkFile);
201 if( nName>=sizeof(zBuf) ){
@@ -248,11 +277,11 @@
248 int file_wd_perm(const char *zFilename){
249 #if !defined(_WIN32)
250 if( !getStat(zFilename, 1) ){
251 if( S_ISREG(fileStat.st_mode) && ((S_IXUSR)&fileStat.st_mode)!=0 )
252 return PERM_EXE;
253 else if( g.allowSymlinks && S_ISLNK(fileStat.st_mode) )
254 return PERM_LNK;
255 }
256 #endif
257 return PERM_REG;
258 }
@@ -301,19 +330,21 @@
301 ** but is something other than a directory.
302 */
303 int file_wd_isdir(const char *zFilename){
304 int rc;
305 char *zFN;
 
306
307 zFN = mprintf("%s", zFilename);
308 file_simplify_name(zFN, -1, 0);
309 rc = getStat(zFN, 1);
 
310 if( rc ){
311 rc = 0; /* It does not exist at all. */
312 }else if( S_ISDIR(fileStat.st_mode) ){
313 rc = 1; /* It exists and is a real directory. */
314 }else if( S_ISLNK(fileStat.st_mode) ){
315 Blob content;
316 blob_read_link(&content, zFN); /* It exists and is a link. */
317 rc = file_wd_isdir(blob_str(&content)); /* Points to directory? */
318 blob_reset(&content);
319 }else{
@@ -480,11 +511,11 @@
480 */
481 int file_wd_setexe(const char *zFilename, int onoff){
482 int rc = 0;
483 #if !defined(_WIN32)
484 struct stat buf;
485 if( fossil_stat(zFilename, &buf, 1)!=0 || S_ISLNK(buf.st_mode) ) return 0;
486 if( onoff ){
487 int targetMode = (buf.st_mode & 0444)>>2;
488 if( (buf.st_mode & 0100)==0 ){
489 chmod(zFilename, buf.st_mode | targetMode);
490 rc = 1;
@@ -932,39 +963,123 @@
932 }
933 #endif
934 blob_resize(pOut, file_simplify_name(blob_buffer(pOut),
935 blob_size(pOut), slash));
936 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
937
938 /*
939 ** COMMAND: test-canonical-name
940 **
941 ** Usage: %fossil test-canonical-name FILENAME...
942 **
943 ** Test the operation of the canonical name generator.
944 ** Also test Fossil's ability to measure attributes of a file.
 
 
 
 
 
 
945 */
946 void cmd_test_canonical_name(void){
947 int i;
948 Blob x;
949 int slashFlag = find_option("slash",0,0)!=0;
950 blob_zero(&x);
 
 
 
951 for(i=2; i<g.argc; i++){
952 char zBuf[100];
953 const char *zName = g.argv[i];
954 file_canonical_name(zName, &x, slashFlag);
955 fossil_print("[%s] -> [%s]\n", zName, blob_buffer(&x));
956 blob_reset(&x);
957 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_wd_size(zName));
958 fossil_print(" file_size = %s\n", zBuf);
959 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_wd_mtime(zName));
960 fossil_print(" file_mtime = %s\n", zBuf);
961 fossil_print(" file_isfile = %d\n", file_wd_isfile(zName));
962 fossil_print(" file_isfile_or_link = %d\n",file_wd_isfile_or_link(zName));
963 fossil_print(" file_islink = %d\n", file_wd_islink(zName));
964 fossil_print(" file_isexe = %d\n", file_wd_isexe(zName));
965 fossil_print(" file_isdir = %d\n", file_wd_isdir(zName));
966 }
967 }
968
969 /*
970 ** Return TRUE if the given filename is canonical.
@@ -1075,10 +1190,14 @@
1075
1076 /*
1077 ** COMMAND: test-relative-name
1078 **
1079 ** Test the operation of the relative name generator.
 
 
 
 
1080 */
1081 void cmd_test_relative_name(void){
1082 int i;
1083 Blob x;
1084 int slashFlag = find_option("slash",0,0)!=0;
@@ -1194,10 +1313,11 @@
1194 **
1195 ** Options:
1196 ** --absolute Return an absolute path instead of a relative one.
1197 ** --case-sensitive B Enable or disable case-sensitive filenames. B is
1198 ** a boolean: "yes", "no", "true", "false", etc.
 
1199 */
1200 void cmd_test_tree_name(void){
1201 int i;
1202 Blob x;
1203 int absoluteFlag = find_option("absolute",0,0)!=0;
1204
--- src/file.c
+++ src/file.c
@@ -85,15 +85,20 @@
85 /*
86 ** Fill stat buf with information received from stat() or lstat().
87 ** lstat() is called on Unix if isWd is TRUE and allow-symlinks setting is on.
88 **
89 */
90 static int fossil_stat(
91 const char *zFilename, /* name of file or directory to inspect. */
92 struct fossilStat *buf, /* pointer to buffer where info should go. */
93 int isWd, /* non-zero to consider look at symlink itself. */
94 int forceWd /* non-zero to force look at symlink itself. */
95 ){
96 int rc;
97 void *zMbcs = fossil_utf8_to_path(zFilename, 0);
98 #if !defined(_WIN32)
99 if( isWd && (forceWd || db_allow_symlinks(0)) ){
100 rc = lstat(zMbcs, buf);
101 }else{
102 rc = stat(zMbcs, buf);
103 }
104 #else
@@ -100,10 +105,18 @@
105 rc = win32_stat(zMbcs, buf, isWd);
106 #endif
107 fossil_path_free(zMbcs);
108 return rc;
109 }
110
111 /*
112 ** Clears the fileStat variable and its associated validity flag.
113 */
114 static void resetStat(){
115 fileStatValid = 0;
116 memset(&fileStat, 0, sizeof(struct fossilStat));
117 }
118
119 /*
120 ** Fill in the fileStat variable for the file named zFilename.
121 ** If zFilename==0, then use the previous value of fileStat if
122 ** there is a previous value.
@@ -115,11 +128,11 @@
128 static int getStat(const char *zFilename, int isWd){
129 int rc = 0;
130 if( zFilename==0 ){
131 if( fileStatValid==0 ) rc = 1;
132 }else{
133 if( fossil_stat(zFilename, &fileStat, isWd, 0)!=0 ){
134 fileStatValid = 0;
135 rc = 1;
136 }else{
137 fileStatValid = 1;
138 rc = 0;
@@ -157,10 +170,26 @@
170 ** Same as file_mtime(), but takes into account symlinks.
171 */
172 i64 file_wd_mtime(const char *zFilename){
173 return getStat(zFilename, 1) ? -1 : fileStat.st_mtime;
174 }
175
176 /*
177 ** Return the mode bits for a file. Return -1 if the file does not
178 ** exist. If zFilename is NULL return the size of the most recently
179 ** stat-ed file.
180 */
181 int file_mode(const char *zFilename){
182 return getStat(zFilename, 0) ? -1 : fileStat.st_mode;
183 }
184
185 /*
186 ** Same as file_mode(), but takes into account symlinks.
187 */
188 int file_wd_mode(const char *zFilename){
189 return getStat(zFilename, 1) ? -1 : fileStat.st_mode;
190 }
191
192 /*
193 ** Return TRUE if the named file is an ordinary file or symlink
194 ** and symlinks are allowed.
195 ** Return false for directories, devices, fifos, etc.
@@ -191,11 +220,11 @@
220 **
221 ** Arguments: target file (symlink will point to it), link file
222 **/
223 void symlink_create(const char *zTargetFile, const char *zLinkFile){
224 #if !defined(_WIN32)
225 if( db_allow_symlinks(0) ){
226 int i, nName;
227 char *zName, zBuf[1000];
228
229 nName = strlen(zLinkFile);
230 if( nName>=sizeof(zBuf) ){
@@ -248,11 +277,11 @@
277 int file_wd_perm(const char *zFilename){
278 #if !defined(_WIN32)
279 if( !getStat(zFilename, 1) ){
280 if( S_ISREG(fileStat.st_mode) && ((S_IXUSR)&fileStat.st_mode)!=0 )
281 return PERM_EXE;
282 else if( db_allow_symlinks(0) && S_ISLNK(fileStat.st_mode) )
283 return PERM_LNK;
284 }
285 #endif
286 return PERM_REG;
287 }
@@ -301,19 +330,21 @@
330 ** but is something other than a directory.
331 */
332 int file_wd_isdir(const char *zFilename){
333 int rc;
334 char *zFN;
335 struct fossilStat dirFileStat;
336
337 zFN = mprintf("%s", zFilename);
338 file_simplify_name(zFN, -1, 0);
339 memset(&dirFileStat, 0, sizeof(struct fossilStat));
340 rc = fossil_stat(zFN, &dirFileStat, 1, 1);
341 if( rc ){
342 rc = 0; /* It does not exist at all. */
343 }else if( S_ISDIR(dirFileStat.st_mode) ){
344 rc = 1; /* It exists and is a real directory. */
345 }else if( !db_allow_symlinks(1) && S_ISLNK(dirFileStat.st_mode) ){
346 Blob content;
347 blob_read_link(&content, zFN); /* It exists and is a link. */
348 rc = file_wd_isdir(blob_str(&content)); /* Points to directory? */
349 blob_reset(&content);
350 }else{
@@ -480,11 +511,11 @@
511 */
512 int file_wd_setexe(const char *zFilename, int onoff){
513 int rc = 0;
514 #if !defined(_WIN32)
515 struct stat buf;
516 if( fossil_stat(zFilename, &buf, 1, 0)!=0 || S_ISLNK(buf.st_mode) ) return 0;
517 if( onoff ){
518 int targetMode = (buf.st_mode & 0444)>>2;
519 if( (buf.st_mode & 0100)==0 ){
520 chmod(zFilename, buf.st_mode | targetMode);
521 rc = 1;
@@ -932,39 +963,123 @@
963 }
964 #endif
965 blob_resize(pOut, file_simplify_name(blob_buffer(pOut),
966 blob_size(pOut), slash));
967 }
968
969 /*
970 ** Emits the effective or raw stat() information for the specified
971 ** file or directory, optionally preserving the trailing slash and
972 ** resetting the cached stat() information.
973 */
974 static void emitFileStat(
975 const char *zPath,
976 int raw,
977 int slash,
978 int reset
979 ){
980 char zBuf[100];
981 Blob x;
982 memset(zBuf, 0, sizeof(zBuf));
983 blob_zero(&x);
984 file_canonical_name(zPath, &x, slash);
985 fossil_print("%s[%s] -> [%s]\n", raw ? "RAW " : "", zPath, blob_buffer(&x));
986 blob_reset(&x);
987 if( raw ){
988 int rc;
989 struct fossilStat testFileStat;
990 memset(&testFileStat, 0, sizeof(struct fossilStat));
991 rc = fossil_stat(zPath, &testFileStat, 0, 0);
992 fossil_print(" stat_rc = %d\n", rc);
993 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_size);
994 fossil_print(" stat_size = %s\n", zBuf);
995 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_mtime);
996 fossil_print(" stat_mtime = %s\n", zBuf);
997 fossil_print(" stat_mode = %d\n", testFileStat.st_mode);
998 memset(&testFileStat, 0, sizeof(struct fossilStat));
999 rc = fossil_stat(zPath, &testFileStat, 1, 1);
1000 fossil_print(" l_stat_rc = %d\n", rc);
1001 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_size);
1002 fossil_print(" l_stat_size = %s\n", zBuf);
1003 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", testFileStat.st_mtime);
1004 fossil_print(" l_stat_mtime = %s\n", zBuf);
1005 fossil_print(" l_stat_mode = %d\n", testFileStat.st_mode);
1006 }else{
1007 if( reset ) resetStat();
1008 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_wd_size(zPath));
1009 fossil_print(" file_size = %s\n", zBuf);
1010 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", file_wd_mtime(zPath));
1011 fossil_print(" file_mtime = %s\n", zBuf);
1012 fossil_print(" file_mode = %d\n", file_wd_mode(zPath));
1013 fossil_print(" file_isfile = %d\n", file_wd_isfile(zPath));
1014 fossil_print(" file_isfile_or_link = %d\n", file_wd_isfile_or_link(zPath));
1015 fossil_print(" file_islink = %d\n", file_wd_islink(zPath));
1016 fossil_print(" file_isexe = %d\n", file_wd_isexe(zPath));
1017 fossil_print(" file_isdir = %d\n", file_wd_isdir(zPath));
1018 if( reset ) resetStat();
1019 }
1020 }
1021
1022 /*
1023 ** COMMAND: test-file-environment
1024 **
1025 ** Usage: %fossil test-file-environment FILENAME...
1026 **
1027 ** Display the effective file handling subsystem "settings" and then
1028 ** display file system information about the files specified, if any.
1029 **
1030 ** Options:
1031 **
1032 ** --open-config Open the configuration database first.
1033 ** --slash Trailing slashes, if any, are retained.
1034 ** --reset Reset cached stat() info for each file.
1035 */
1036 void cmd_test_file_environment(void){
1037 int i;
1038 int slashFlag = find_option("slash",0,0)!=0;
1039 int resetFlag = find_option("reset",0,0)!=0;
1040 if( find_option("open-config", 0, 0)!=0 ){
1041 Th_OpenConfig(1);
1042 }
1043 fossil_print("Th_IsLocalOpen() = %d\n", Th_IsLocalOpen());
1044 fossil_print("Th_IsRepositoryOpen() = %d\n", Th_IsRepositoryOpen());
1045 fossil_print("Th_IsConfigOpen() = %d\n", Th_IsConfigOpen());
1046 fossil_print("filenames_are_case_sensitive() = %d\n",
1047 filenames_are_case_sensitive());
1048 fossil_print("db_allow_symlinks_by_default() = %d\n",
1049 db_allow_symlinks_by_default());
1050 fossil_print("db_allow_symlinks(0) = %d\n", db_allow_symlinks(0));
1051 fossil_print("db_allow_symlinks(1) = %d\n", db_allow_symlinks(1));
1052 for(i=2; i<g.argc; i++){
1053 emitFileStat(g.argv[i], 1, slashFlag, resetFlag);
1054 emitFileStat(g.argv[i], 0, slashFlag, resetFlag);
1055 }
1056 }
1057
1058 /*
1059 ** COMMAND: test-canonical-name
1060 **
1061 ** Usage: %fossil test-canonical-name FILENAME...
1062 **
1063 ** Test the operation of the canonical name generator.
1064 ** Also test Fossil's ability to measure attributes of a file.
1065 **
1066 ** Options:
1067 **
1068 ** --open-config Open the configuration database first.
1069 ** --slash Trailing slashes, if any, are retained.
1070 ** --reset Reset cached stat() info for each file.
1071 */
1072 void cmd_test_canonical_name(void){
1073 int i;
 
1074 int slashFlag = find_option("slash",0,0)!=0;
1075 int resetFlag = find_option("reset",0,0)!=0;
1076 if( find_option("open-config", 0, 0)!=0 ){
1077 Th_OpenConfig(1);
1078 }
1079 for(i=2; i<g.argc; i++){
1080 emitFileStat(g.argv[i], 0, slashFlag, resetFlag);
 
 
 
 
 
 
 
 
 
 
 
 
 
1081 }
1082 }
1083
1084 /*
1085 ** Return TRUE if the given filename is canonical.
@@ -1075,10 +1190,14 @@
1190
1191 /*
1192 ** COMMAND: test-relative-name
1193 **
1194 ** Test the operation of the relative name generator.
1195 **
1196 ** Options:
1197 **
1198 ** --slash Trailing slashes, if any, are retained.
1199 */
1200 void cmd_test_relative_name(void){
1201 int i;
1202 Blob x;
1203 int slashFlag = find_option("slash",0,0)!=0;
@@ -1194,10 +1313,11 @@
1313 **
1314 ** Options:
1315 ** --absolute Return an absolute path instead of a relative one.
1316 ** --case-sensitive B Enable or disable case-sensitive filenames. B is
1317 ** a boolean: "yes", "no", "true", "false", etc.
1318 ** --no-dir-symlinks Disables support for directory symlinks.
1319 */
1320 void cmd_test_tree_name(void){
1321 int i;
1322 Blob x;
1323 int absoluteFlag = find_option("absolute",0,0)!=0;
1324
--- src/finfo.c
+++ src/finfo.c
@@ -45,10 +45,11 @@
4545
** --case-sensitive B Enable or disable case-sensitive filenames. B is a
4646
** boolean: "yes", "no", "true", "false", etc.
4747
** -l|--log select log mode (the default)
4848
** -n|--limit N Display the first N changes (default unlimited).
4949
** N<=0 means no limit.
50
+** --no-dir-symlinks Disables support for directory symlinks.
5051
** --offset P skip P changes
5152
** -p|--print select print mode
5253
** -r|--revision R print the given revision (or ckout, if none is given)
5354
** to stdout (only in print mode)
5455
** -s|--status select status mode (print a status indicator for FILE)
5556
--- src/finfo.c
+++ src/finfo.c
@@ -45,10 +45,11 @@
45 ** --case-sensitive B Enable or disable case-sensitive filenames. B is a
46 ** boolean: "yes", "no", "true", "false", etc.
47 ** -l|--log select log mode (the default)
48 ** -n|--limit N Display the first N changes (default unlimited).
49 ** N<=0 means no limit.
 
50 ** --offset P skip P changes
51 ** -p|--print select print mode
52 ** -r|--revision R print the given revision (or ckout, if none is given)
53 ** to stdout (only in print mode)
54 ** -s|--status select status mode (print a status indicator for FILE)
55
--- src/finfo.c
+++ src/finfo.c
@@ -45,10 +45,11 @@
45 ** --case-sensitive B Enable or disable case-sensitive filenames. B is a
46 ** boolean: "yes", "no", "true", "false", etc.
47 ** -l|--log select log mode (the default)
48 ** -n|--limit N Display the first N changes (default unlimited).
49 ** N<=0 means no limit.
50 ** --no-dir-symlinks Disables support for directory symlinks.
51 ** --offset P skip P changes
52 ** -p|--print select print mode
53 ** -r|--revision R print the given revision (or ckout, if none is given)
54 ** to stdout (only in print mode)
55 ** -s|--status select status mode (print a status indicator for FILE)
56
+1
--- src/json.c
+++ src/json.c
@@ -1263,10 +1263,11 @@
12631263
INT(g, isConst);
12641264
CSTR(g, zConfigDbName);
12651265
INT(g, repositoryOpen);
12661266
INT(g, localOpen);
12671267
INT(g, minPrefix);
1268
+ INT(g, fNoDirSymlinks);
12681269
INT(g, fSqlTrace);
12691270
INT(g, fSqlStats);
12701271
INT(g, fSqlPrint);
12711272
INT(g, fQuiet);
12721273
INT(g, fHttpTrace);
12731274
--- src/json.c
+++ src/json.c
@@ -1263,10 +1263,11 @@
1263 INT(g, isConst);
1264 CSTR(g, zConfigDbName);
1265 INT(g, repositoryOpen);
1266 INT(g, localOpen);
1267 INT(g, minPrefix);
 
1268 INT(g, fSqlTrace);
1269 INT(g, fSqlStats);
1270 INT(g, fSqlPrint);
1271 INT(g, fQuiet);
1272 INT(g, fHttpTrace);
1273
--- src/json.c
+++ src/json.c
@@ -1263,10 +1263,11 @@
1263 INT(g, isConst);
1264 CSTR(g, zConfigDbName);
1265 INT(g, repositoryOpen);
1266 INT(g, localOpen);
1267 INT(g, minPrefix);
1268 INT(g, fNoDirSymlinks);
1269 INT(g, fSqlTrace);
1270 INT(g, fSqlStats);
1271 INT(g, fSqlPrint);
1272 INT(g, fQuiet);
1273 INT(g, fHttpTrace);
1274
+54 -44
--- src/login.c
+++ src/login.c
@@ -526,53 +526,63 @@
526526
527527
/* Deal with password-change requests */
528528
if( g.perm.Password && zPasswd
529529
&& (zNew1 = P("n1"))!=0 && (zNew2 = P("n2"))!=0
530530
){
531
- /* The user requests a password change */
532
- zSha1Pw = sha1_shared_secret(zPasswd, g.zLogin, 0);
533
- if( db_int(1, "SELECT 0 FROM user"
534
- " WHERE uid=%d"
535
- " AND (constant_time_cmp(pw,%Q)=0"
536
- " OR constant_time_cmp(pw,%Q)=0)",
537
- g.userUid, zSha1Pw, zPasswd) ){
538
- sleep(1);
539
- zErrMsg =
540
- @ <p><span class="loginError">
541
- @ You entered an incorrect old password while attempting to change
542
- @ your password. Your password is unchanged.
543
- @ </span></p>
544
- ;
545
- }else if( fossil_strcmp(zNew1,zNew2)!=0 ){
546
- zErrMsg =
547
- @ <p><span class="loginError">
548
- @ The two copies of your new passwords do not match.
549
- @ Your password is unchanged.
550
- @ </span></p>
551
- ;
552
- }else{
553
- char *zNewPw = sha1_shared_secret(zNew1, g.zLogin, 0);
554
- char *zChngPw;
555
- char *zErr;
556
- db_multi_exec(
557
- "UPDATE user SET pw=%Q WHERE uid=%d", zNewPw, g.userUid
558
- );
559
- fossil_free(zNewPw);
560
- zChngPw = mprintf(
561
- "UPDATE user"
562
- " SET pw=shared_secret(%Q,%Q,"
563
- " (SELECT value FROM config WHERE name='project-code'))"
564
- " WHERE login=%Q",
565
- zNew1, g.zLogin, g.zLogin
566
- );
567
- if( login_group_sql(zChngPw, "<p>", "</p>\n", &zErr) ){
568
- zErrMsg = mprintf("<span class=\"loginError\">%s</span>", zErr);
569
- fossil_free(zErr);
570
- }else{
571
- redirect_to_g();
572
- return;
573
- }
531
+ /* If there is not a "real" login, we cannot change any password. */
532
+ if( g.zLogin ){
533
+ /* The user requests a password change */
534
+ zSha1Pw = sha1_shared_secret(zPasswd, g.zLogin, 0);
535
+ if( db_int(1, "SELECT 0 FROM user"
536
+ " WHERE uid=%d"
537
+ " AND (constant_time_cmp(pw,%Q)=0"
538
+ " OR constant_time_cmp(pw,%Q)=0)",
539
+ g.userUid, zSha1Pw, zPasswd) ){
540
+ sleep(1);
541
+ zErrMsg =
542
+ @ <p><span class="loginError">
543
+ @ You entered an incorrect old password while attempting to change
544
+ @ your password. Your password is unchanged.
545
+ @ </span></p>
546
+ ;
547
+ }else if( fossil_strcmp(zNew1,zNew2)!=0 ){
548
+ zErrMsg =
549
+ @ <p><span class="loginError">
550
+ @ The two copies of your new passwords do not match.
551
+ @ Your password is unchanged.
552
+ @ </span></p>
553
+ ;
554
+ }else{
555
+ char *zNewPw = sha1_shared_secret(zNew1, g.zLogin, 0);
556
+ char *zChngPw;
557
+ char *zErr;
558
+ db_multi_exec(
559
+ "UPDATE user SET pw=%Q WHERE uid=%d", zNewPw, g.userUid
560
+ );
561
+ fossil_free(zNewPw);
562
+ zChngPw = mprintf(
563
+ "UPDATE user"
564
+ " SET pw=shared_secret(%Q,%Q,"
565
+ " (SELECT value FROM config WHERE name='project-code'))"
566
+ " WHERE login=%Q",
567
+ zNew1, g.zLogin, g.zLogin
568
+ );
569
+ if( login_group_sql(zChngPw, "<p>", "</p>\n", &zErr) ){
570
+ zErrMsg = mprintf("<span class=\"loginError\">%s</span>", zErr);
571
+ fossil_free(zErr);
572
+ }else{
573
+ redirect_to_g();
574
+ return;
575
+ }
576
+ }
577
+ }else{
578
+ zErrMsg =
579
+ @ <p><span class="loginError">
580
+ @ The password cannot be changed for this type of login.
581
+ @ The password is unchanged.
582
+ @ </span></p>
583
+ ;
574584
}
575585
}
576586
zIpAddr = PD("REMOTE_ADDR","nil"); /* Complete IP address for logging */
577587
zReferer = P("HTTP_REFERER");
578588
uid = login_is_valid_anonymous(zUsername, zPasswd, P("cs"));
@@ -699,11 +709,11 @@
699709
}
700710
@ </div>
701711
free(zCaptcha);
702712
}
703713
@ </form>
704
- if( g.perm.Password ){
714
+ if( g.zLogin && g.perm.Password ){
705715
@ <hr />
706716
@ <p>Change Password for user <b>%h(g.zLogin)</b>:</p>
707717
form_begin(0, "%R/login");
708718
@ <table>
709719
@ <tr><td class="login_out_label">Old Password:</td>
710720
--- src/login.c
+++ src/login.c
@@ -526,53 +526,63 @@
526
527 /* Deal with password-change requests */
528 if( g.perm.Password && zPasswd
529 && (zNew1 = P("n1"))!=0 && (zNew2 = P("n2"))!=0
530 ){
531 /* The user requests a password change */
532 zSha1Pw = sha1_shared_secret(zPasswd, g.zLogin, 0);
533 if( db_int(1, "SELECT 0 FROM user"
534 " WHERE uid=%d"
535 " AND (constant_time_cmp(pw,%Q)=0"
536 " OR constant_time_cmp(pw,%Q)=0)",
537 g.userUid, zSha1Pw, zPasswd) ){
538 sleep(1);
539 zErrMsg =
540 @ <p><span class="loginError">
541 @ You entered an incorrect old password while attempting to change
542 @ your password. Your password is unchanged.
543 @ </span></p>
544 ;
545 }else if( fossil_strcmp(zNew1,zNew2)!=0 ){
546 zErrMsg =
547 @ <p><span class="loginError">
548 @ The two copies of your new passwords do not match.
549 @ Your password is unchanged.
550 @ </span></p>
551 ;
552 }else{
553 char *zNewPw = sha1_shared_secret(zNew1, g.zLogin, 0);
554 char *zChngPw;
555 char *zErr;
556 db_multi_exec(
557 "UPDATE user SET pw=%Q WHERE uid=%d", zNewPw, g.userUid
558 );
559 fossil_free(zNewPw);
560 zChngPw = mprintf(
561 "UPDATE user"
562 " SET pw=shared_secret(%Q,%Q,"
563 " (SELECT value FROM config WHERE name='project-code'))"
564 " WHERE login=%Q",
565 zNew1, g.zLogin, g.zLogin
566 );
567 if( login_group_sql(zChngPw, "<p>", "</p>\n", &zErr) ){
568 zErrMsg = mprintf("<span class=\"loginError\">%s</span>", zErr);
569 fossil_free(zErr);
570 }else{
571 redirect_to_g();
572 return;
573 }
 
 
 
 
 
 
 
 
 
 
574 }
575 }
576 zIpAddr = PD("REMOTE_ADDR","nil"); /* Complete IP address for logging */
577 zReferer = P("HTTP_REFERER");
578 uid = login_is_valid_anonymous(zUsername, zPasswd, P("cs"));
@@ -699,11 +709,11 @@
699 }
700 @ </div>
701 free(zCaptcha);
702 }
703 @ </form>
704 if( g.perm.Password ){
705 @ <hr />
706 @ <p>Change Password for user <b>%h(g.zLogin)</b>:</p>
707 form_begin(0, "%R/login");
708 @ <table>
709 @ <tr><td class="login_out_label">Old Password:</td>
710
--- src/login.c
+++ src/login.c
@@ -526,53 +526,63 @@
526
527 /* Deal with password-change requests */
528 if( g.perm.Password && zPasswd
529 && (zNew1 = P("n1"))!=0 && (zNew2 = P("n2"))!=0
530 ){
531 /* If there is not a "real" login, we cannot change any password. */
532 if( g.zLogin ){
533 /* The user requests a password change */
534 zSha1Pw = sha1_shared_secret(zPasswd, g.zLogin, 0);
535 if( db_int(1, "SELECT 0 FROM user"
536 " WHERE uid=%d"
537 " AND (constant_time_cmp(pw,%Q)=0"
538 " OR constant_time_cmp(pw,%Q)=0)",
539 g.userUid, zSha1Pw, zPasswd) ){
540 sleep(1);
541 zErrMsg =
542 @ <p><span class="loginError">
543 @ You entered an incorrect old password while attempting to change
544 @ your password. Your password is unchanged.
545 @ </span></p>
546 ;
547 }else if( fossil_strcmp(zNew1,zNew2)!=0 ){
548 zErrMsg =
549 @ <p><span class="loginError">
550 @ The two copies of your new passwords do not match.
551 @ Your password is unchanged.
552 @ </span></p>
553 ;
554 }else{
555 char *zNewPw = sha1_shared_secret(zNew1, g.zLogin, 0);
556 char *zChngPw;
557 char *zErr;
558 db_multi_exec(
559 "UPDATE user SET pw=%Q WHERE uid=%d", zNewPw, g.userUid
560 );
561 fossil_free(zNewPw);
562 zChngPw = mprintf(
563 "UPDATE user"
564 " SET pw=shared_secret(%Q,%Q,"
565 " (SELECT value FROM config WHERE name='project-code'))"
566 " WHERE login=%Q",
567 zNew1, g.zLogin, g.zLogin
568 );
569 if( login_group_sql(zChngPw, "<p>", "</p>\n", &zErr) ){
570 zErrMsg = mprintf("<span class=\"loginError\">%s</span>", zErr);
571 fossil_free(zErr);
572 }else{
573 redirect_to_g();
574 return;
575 }
576 }
577 }else{
578 zErrMsg =
579 @ <p><span class="loginError">
580 @ The password cannot be changed for this type of login.
581 @ The password is unchanged.
582 @ </span></p>
583 ;
584 }
585 }
586 zIpAddr = PD("REMOTE_ADDR","nil"); /* Complete IP address for logging */
587 zReferer = P("HTTP_REFERER");
588 uid = login_is_valid_anonymous(zUsername, zPasswd, P("cs"));
@@ -699,11 +709,11 @@
709 }
710 @ </div>
711 free(zCaptcha);
712 }
713 @ </form>
714 if( g.zLogin && g.perm.Password ){
715 @ <hr />
716 @ <p>Change Password for user <b>%h(g.zLogin)</b>:</p>
717 form_begin(0, "%R/login");
718 @ <table>
719 @ <tr><td class="login_out_label">Old Password:</td>
720
+7 -3
--- src/main.c
+++ src/main.c
@@ -135,10 +135,11 @@
135135
char *zLocalDbName; /* Name of the local database file */
136136
char *zOpenRevision; /* Check-in version to use during database open */
137137
int localOpen; /* True if the local database is open */
138138
char *zLocalRoot; /* The directory holding the local database */
139139
int minPrefix; /* Number of digits needed for a distinct UUID */
140
+ int fNoDirSymlinks; /* True if --no-dir-symlinks flag is present */
140141
int fSqlTrace; /* True if --sqltrace flag is present */
141142
int fSqlStats; /* True if --sqltrace or --sqlstats are present */
142143
int fSqlPrint; /* True if -sqlprint flag is present */
143144
int fQuiet; /* True if -quiet flag is present */
144145
int fJail; /* True if running with a chroot jail */
@@ -613,10 +614,11 @@
613614
fossil_exit(1);
614615
}else{
615616
const char *zChdir = find_option("chdir",0,1);
616617
g.isHTTP = 0;
617618
g.rcvid = 0;
619
+ g.fNoDirSymlinks = find_option("no-dir-symlinks", 0, 0)!=0;
618620
g.fQuiet = find_option("quiet", 0, 0)!=0;
619621
g.fSqlTrace = find_option("sqltrace", 0, 0)!=0;
620622
g.fSqlStats = find_option("sqlstats", 0, 0)!=0;
621623
g.fSystemTrace = find_option("systemtrace", 0, 0)!=0;
622624
g.fSshTrace = find_option("sshtrace", 0, 0)!=0;
@@ -993,14 +995,16 @@
993995
#endif
994996
blob_appendf(pOut, "SQLite %s %.30s\n", sqlite3_libversion(),
995997
sqlite3_sourceid());
996998
if( g.db==0 ) sqlite3_open(":memory:", &g.db);
997999
db_prepare(&q,
998
- "SELECT compile_options FROM pragma_compile_options"
999
- " WHERE compile_options NOT LIKE 'COMPILER=%%'");
1000
+ "pragma compile_options");
10001001
while( db_step(&q)==SQLITE_ROW ){
1001
- blob_appendf(pOut, "SQLITE_%s\n", db_column_text(&q, 0));
1002
+ const char *text = db_column_text(&q, 0);
1003
+ if( strncmp(text, "COMPILER", 8) ){
1004
+ blob_appendf(pOut, "SQLITE_%s\n", text);
1005
+ }
10021006
}
10031007
db_finalize(&q);
10041008
}
10051009
10061010
/*
10071011
--- src/main.c
+++ src/main.c
@@ -135,10 +135,11 @@
135 char *zLocalDbName; /* Name of the local database file */
136 char *zOpenRevision; /* Check-in version to use during database open */
137 int localOpen; /* True if the local database is open */
138 char *zLocalRoot; /* The directory holding the local database */
139 int minPrefix; /* Number of digits needed for a distinct UUID */
 
140 int fSqlTrace; /* True if --sqltrace flag is present */
141 int fSqlStats; /* True if --sqltrace or --sqlstats are present */
142 int fSqlPrint; /* True if -sqlprint flag is present */
143 int fQuiet; /* True if -quiet flag is present */
144 int fJail; /* True if running with a chroot jail */
@@ -613,10 +614,11 @@
613 fossil_exit(1);
614 }else{
615 const char *zChdir = find_option("chdir",0,1);
616 g.isHTTP = 0;
617 g.rcvid = 0;
 
618 g.fQuiet = find_option("quiet", 0, 0)!=0;
619 g.fSqlTrace = find_option("sqltrace", 0, 0)!=0;
620 g.fSqlStats = find_option("sqlstats", 0, 0)!=0;
621 g.fSystemTrace = find_option("systemtrace", 0, 0)!=0;
622 g.fSshTrace = find_option("sshtrace", 0, 0)!=0;
@@ -993,14 +995,16 @@
993 #endif
994 blob_appendf(pOut, "SQLite %s %.30s\n", sqlite3_libversion(),
995 sqlite3_sourceid());
996 if( g.db==0 ) sqlite3_open(":memory:", &g.db);
997 db_prepare(&q,
998 "SELECT compile_options FROM pragma_compile_options"
999 " WHERE compile_options NOT LIKE 'COMPILER=%%'");
1000 while( db_step(&q)==SQLITE_ROW ){
1001 blob_appendf(pOut, "SQLITE_%s\n", db_column_text(&q, 0));
 
 
 
1002 }
1003 db_finalize(&q);
1004 }
1005
1006 /*
1007
--- src/main.c
+++ src/main.c
@@ -135,10 +135,11 @@
135 char *zLocalDbName; /* Name of the local database file */
136 char *zOpenRevision; /* Check-in version to use during database open */
137 int localOpen; /* True if the local database is open */
138 char *zLocalRoot; /* The directory holding the local database */
139 int minPrefix; /* Number of digits needed for a distinct UUID */
140 int fNoDirSymlinks; /* True if --no-dir-symlinks flag is present */
141 int fSqlTrace; /* True if --sqltrace flag is present */
142 int fSqlStats; /* True if --sqltrace or --sqlstats are present */
143 int fSqlPrint; /* True if -sqlprint flag is present */
144 int fQuiet; /* True if -quiet flag is present */
145 int fJail; /* True if running with a chroot jail */
@@ -613,10 +614,11 @@
614 fossil_exit(1);
615 }else{
616 const char *zChdir = find_option("chdir",0,1);
617 g.isHTTP = 0;
618 g.rcvid = 0;
619 g.fNoDirSymlinks = find_option("no-dir-symlinks", 0, 0)!=0;
620 g.fQuiet = find_option("quiet", 0, 0)!=0;
621 g.fSqlTrace = find_option("sqltrace", 0, 0)!=0;
622 g.fSqlStats = find_option("sqlstats", 0, 0)!=0;
623 g.fSystemTrace = find_option("systemtrace", 0, 0)!=0;
624 g.fSshTrace = find_option("sshtrace", 0, 0)!=0;
@@ -993,14 +995,16 @@
995 #endif
996 blob_appendf(pOut, "SQLite %s %.30s\n", sqlite3_libversion(),
997 sqlite3_sourceid());
998 if( g.db==0 ) sqlite3_open(":memory:", &g.db);
999 db_prepare(&q,
1000 "pragma compile_options");
 
1001 while( db_step(&q)==SQLITE_ROW ){
1002 const char *text = db_column_text(&q, 0);
1003 if( strncmp(text, "COMPILER", 8) ){
1004 blob_appendf(pOut, "SQLITE_%s\n", text);
1005 }
1006 }
1007 db_finalize(&q);
1008 }
1009
1010 /*
1011
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -670,11 +670,11 @@
670670
#### The directories where the OpenSSL include and library files are located.
671671
# The recommended usage here is to use the Sysinternals junction tool
672672
# to create a hard link between an "openssl-1.x" sub-directory of the
673673
# Fossil source code directory and the target OpenSSL source directory.
674674
#
675
-OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.1.0d
675
+OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.1.0e
676676
OPENSSLINCDIR = $(OPENSSLDIR)/include
677677
OPENSSLLIBDIR = $(OPENSSLDIR)
678678
679679
#### Either the directory where the Tcl library is installed or the Tcl
680680
# source code directory resides (depending on the value of the macro
@@ -1501,11 +1501,11 @@
15011501
!ifndef USE_SEE
15021502
USE_SEE = 0
15031503
!endif
15041504
15051505
!if $(FOSSIL_ENABLE_SSL)!=0
1506
-SSLDIR = $(B)\compat\openssl-1.1.0d
1506
+SSLDIR = $(B)\compat\openssl-1.1.0e
15071507
SSLINCDIR = $(SSLDIR)\inc32
15081508
!if $(FOSSIL_DYNAMIC_BUILD)!=0
15091509
SSLLIBDIR = $(SSLDIR)\out32dll
15101510
!else
15111511
SSLLIBDIR = $(SSLDIR)\out32
15121512
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -670,11 +670,11 @@
670 #### The directories where the OpenSSL include and library files are located.
671 # The recommended usage here is to use the Sysinternals junction tool
672 # to create a hard link between an "openssl-1.x" sub-directory of the
673 # Fossil source code directory and the target OpenSSL source directory.
674 #
675 OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.1.0d
676 OPENSSLINCDIR = $(OPENSSLDIR)/include
677 OPENSSLLIBDIR = $(OPENSSLDIR)
678
679 #### Either the directory where the Tcl library is installed or the Tcl
680 # source code directory resides (depending on the value of the macro
@@ -1501,11 +1501,11 @@
1501 !ifndef USE_SEE
1502 USE_SEE = 0
1503 !endif
1504
1505 !if $(FOSSIL_ENABLE_SSL)!=0
1506 SSLDIR = $(B)\compat\openssl-1.1.0d
1507 SSLINCDIR = $(SSLDIR)\inc32
1508 !if $(FOSSIL_DYNAMIC_BUILD)!=0
1509 SSLLIBDIR = $(SSLDIR)\out32dll
1510 !else
1511 SSLLIBDIR = $(SSLDIR)\out32
1512
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -670,11 +670,11 @@
670 #### The directories where the OpenSSL include and library files are located.
671 # The recommended usage here is to use the Sysinternals junction tool
672 # to create a hard link between an "openssl-1.x" sub-directory of the
673 # Fossil source code directory and the target OpenSSL source directory.
674 #
675 OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.1.0e
676 OPENSSLINCDIR = $(OPENSSLDIR)/include
677 OPENSSLLIBDIR = $(OPENSSLDIR)
678
679 #### Either the directory where the Tcl library is installed or the Tcl
680 # source code directory resides (depending on the value of the macro
@@ -1501,11 +1501,11 @@
1501 !ifndef USE_SEE
1502 USE_SEE = 0
1503 !endif
1504
1505 !if $(FOSSIL_ENABLE_SSL)!=0
1506 SSLDIR = $(B)\compat\openssl-1.1.0e
1507 SSLINCDIR = $(SSLDIR)\inc32
1508 !if $(FOSSIL_DYNAMIC_BUILD)!=0
1509 SSLLIBDIR = $(SSLDIR)\out32dll
1510 !else
1511 SSLLIBDIR = $(SSLDIR)\out32
1512
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -670,11 +670,11 @@
670670
#### The directories where the OpenSSL include and library files are located.
671671
# The recommended usage here is to use the Sysinternals junction tool
672672
# to create a hard link between an "openssl-1.x" sub-directory of the
673673
# Fossil source code directory and the target OpenSSL source directory.
674674
#
675
-OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.1.0d
675
+OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.1.0e
676676
OPENSSLINCDIR = $(OPENSSLDIR)/include
677677
OPENSSLLIBDIR = $(OPENSSLDIR)
678678
679679
#### Either the directory where the Tcl library is installed or the Tcl
680680
# source code directory resides (depending on the value of the macro
@@ -1501,11 +1501,11 @@
15011501
!ifndef USE_SEE
15021502
USE_SEE = 0
15031503
!endif
15041504
15051505
!if $(FOSSIL_ENABLE_SSL)!=0
1506
-SSLDIR = $(B)\compat\openssl-1.1.0d
1506
+SSLDIR = $(B)\compat\openssl-1.1.0e
15071507
SSLINCDIR = $(SSLDIR)\inc32
15081508
!if $(FOSSIL_DYNAMIC_BUILD)!=0
15091509
SSLLIBDIR = $(SSLDIR)\out32dll
15101510
!else
15111511
SSLLIBDIR = $(SSLDIR)\out32
15121512
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -670,11 +670,11 @@
670 #### The directories where the OpenSSL include and library files are located.
671 # The recommended usage here is to use the Sysinternals junction tool
672 # to create a hard link between an "openssl-1.x" sub-directory of the
673 # Fossil source code directory and the target OpenSSL source directory.
674 #
675 OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.1.0d
676 OPENSSLINCDIR = $(OPENSSLDIR)/include
677 OPENSSLLIBDIR = $(OPENSSLDIR)
678
679 #### Either the directory where the Tcl library is installed or the Tcl
680 # source code directory resides (depending on the value of the macro
@@ -1501,11 +1501,11 @@
1501 !ifndef USE_SEE
1502 USE_SEE = 0
1503 !endif
1504
1505 !if $(FOSSIL_ENABLE_SSL)!=0
1506 SSLDIR = $(B)\compat\openssl-1.1.0d
1507 SSLINCDIR = $(SSLDIR)\inc32
1508 !if $(FOSSIL_DYNAMIC_BUILD)!=0
1509 SSLLIBDIR = $(SSLDIR)\out32dll
1510 !else
1511 SSLLIBDIR = $(SSLDIR)\out32
1512
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -670,11 +670,11 @@
670 #### The directories where the OpenSSL include and library files are located.
671 # The recommended usage here is to use the Sysinternals junction tool
672 # to create a hard link between an "openssl-1.x" sub-directory of the
673 # Fossil source code directory and the target OpenSSL source directory.
674 #
675 OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.1.0e
676 OPENSSLINCDIR = $(OPENSSLDIR)/include
677 OPENSSLLIBDIR = $(OPENSSLDIR)
678
679 #### Either the directory where the Tcl library is installed or the Tcl
680 # source code directory resides (depending on the value of the macro
@@ -1501,11 +1501,11 @@
1501 !ifndef USE_SEE
1502 USE_SEE = 0
1503 !endif
1504
1505 !if $(FOSSIL_ENABLE_SSL)!=0
1506 SSLDIR = $(B)\compat\openssl-1.1.0e
1507 SSLINCDIR = $(SSLDIR)\inc32
1508 !if $(FOSSIL_DYNAMIC_BUILD)!=0
1509 SSLLIBDIR = $(SSLDIR)\out32dll
1510 !else
1511 SSLLIBDIR = $(SSLDIR)\out32
1512
--- src/merge.c
+++ src/merge.c
@@ -205,10 +205,12 @@
205205
** -f|--force Force the merge even if it would be a no-op.
206206
**
207207
** --force-missing Force the merge even if there is missing content.
208208
**
209209
** --integrate Merged branch will be closed when committing.
210
+**
211
+** --no-dir-symlinks Disables support for directory symlinks.
210212
**
211213
** -n|--dry-run If given, display instead of run actions
212214
**
213215
** -v|--verbose Show additional details of the merge
214216
*/
215217
--- src/merge.c
+++ src/merge.c
@@ -205,10 +205,12 @@
205 ** -f|--force Force the merge even if it would be a no-op.
206 **
207 ** --force-missing Force the merge even if there is missing content.
208 **
209 ** --integrate Merged branch will be closed when committing.
 
 
210 **
211 ** -n|--dry-run If given, display instead of run actions
212 **
213 ** -v|--verbose Show additional details of the merge
214 */
215
--- src/merge.c
+++ src/merge.c
@@ -205,10 +205,12 @@
205 ** -f|--force Force the merge even if it would be a no-op.
206 **
207 ** --force-missing Force the merge even if there is missing content.
208 **
209 ** --integrate Merged branch will be closed when committing.
210 **
211 ** --no-dir-symlinks Disables support for directory symlinks.
212 **
213 ** -n|--dry-run If given, display instead of run actions
214 **
215 ** -v|--verbose Show additional details of the merge
216 */
217
+6 -1
--- src/shell.c
+++ src/shell.c
@@ -4286,19 +4286,24 @@
42864286
const char *zMode = nArg>=2 ? azArg[1] : "";
42874287
int n2 = (int)strlen(zMode);
42884288
int c2 = zMode[0];
42894289
if( c2=='l' && n2>2 && strncmp(azArg[1],"lines",n2)==0 ){
42904290
p->mode = MODE_Line;
4291
+ sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
42914292
}else if( c2=='c' && strncmp(azArg[1],"columns",n2)==0 ){
42924293
p->mode = MODE_Column;
4294
+ sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
42934295
}else if( c2=='l' && n2>2 && strncmp(azArg[1],"list",n2)==0 ){
42944296
p->mode = MODE_List;
4297
+ sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Column);
4298
+ sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
42954299
}else if( c2=='h' && strncmp(azArg[1],"html",n2)==0 ){
42964300
p->mode = MODE_Html;
42974301
}else if( c2=='t' && strncmp(azArg[1],"tcl",n2)==0 ){
42984302
p->mode = MODE_Tcl;
42994303
sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Space);
4304
+ sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
43004305
}else if( c2=='c' && strncmp(azArg[1],"csv",n2)==0 ){
43014306
p->mode = MODE_Csv;
43024307
sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma);
43034308
sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_CrLf);
43044309
}else if( c2=='t' && strncmp(azArg[1],"tabs",n2)==0 ){
@@ -5295,11 +5300,11 @@
52955300
sqlite3_libversion(), sqlite3_sourceid());
52965301
}else
52975302
52985303
if( c=='v' && strncmp(azArg[0], "vfsinfo", n)==0 ){
52995304
const char *zDbName = nArg==2 ? azArg[1] : "main";
5300
- sqlite3_vfs *pVfs;
5305
+ sqlite3_vfs *pVfs = 0;
53015306
if( p->db ){
53025307
sqlite3_file_control(p->db, zDbName, SQLITE_FCNTL_VFS_POINTER, &pVfs);
53035308
if( pVfs ){
53045309
utf8_printf(p->out, "vfs.zName = \"%s\"\n", pVfs->zName);
53055310
raw_printf(p->out, "vfs.iVersion = %d\n", pVfs->iVersion);
53065311
--- src/shell.c
+++ src/shell.c
@@ -4286,19 +4286,24 @@
4286 const char *zMode = nArg>=2 ? azArg[1] : "";
4287 int n2 = (int)strlen(zMode);
4288 int c2 = zMode[0];
4289 if( c2=='l' && n2>2 && strncmp(azArg[1],"lines",n2)==0 ){
4290 p->mode = MODE_Line;
 
4291 }else if( c2=='c' && strncmp(azArg[1],"columns",n2)==0 ){
4292 p->mode = MODE_Column;
 
4293 }else if( c2=='l' && n2>2 && strncmp(azArg[1],"list",n2)==0 ){
4294 p->mode = MODE_List;
 
 
4295 }else if( c2=='h' && strncmp(azArg[1],"html",n2)==0 ){
4296 p->mode = MODE_Html;
4297 }else if( c2=='t' && strncmp(azArg[1],"tcl",n2)==0 ){
4298 p->mode = MODE_Tcl;
4299 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Space);
 
4300 }else if( c2=='c' && strncmp(azArg[1],"csv",n2)==0 ){
4301 p->mode = MODE_Csv;
4302 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma);
4303 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_CrLf);
4304 }else if( c2=='t' && strncmp(azArg[1],"tabs",n2)==0 ){
@@ -5295,11 +5300,11 @@
5295 sqlite3_libversion(), sqlite3_sourceid());
5296 }else
5297
5298 if( c=='v' && strncmp(azArg[0], "vfsinfo", n)==0 ){
5299 const char *zDbName = nArg==2 ? azArg[1] : "main";
5300 sqlite3_vfs *pVfs;
5301 if( p->db ){
5302 sqlite3_file_control(p->db, zDbName, SQLITE_FCNTL_VFS_POINTER, &pVfs);
5303 if( pVfs ){
5304 utf8_printf(p->out, "vfs.zName = \"%s\"\n", pVfs->zName);
5305 raw_printf(p->out, "vfs.iVersion = %d\n", pVfs->iVersion);
5306
--- src/shell.c
+++ src/shell.c
@@ -4286,19 +4286,24 @@
4286 const char *zMode = nArg>=2 ? azArg[1] : "";
4287 int n2 = (int)strlen(zMode);
4288 int c2 = zMode[0];
4289 if( c2=='l' && n2>2 && strncmp(azArg[1],"lines",n2)==0 ){
4290 p->mode = MODE_Line;
4291 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
4292 }else if( c2=='c' && strncmp(azArg[1],"columns",n2)==0 ){
4293 p->mode = MODE_Column;
4294 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
4295 }else if( c2=='l' && n2>2 && strncmp(azArg[1],"list",n2)==0 ){
4296 p->mode = MODE_List;
4297 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Column);
4298 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
4299 }else if( c2=='h' && strncmp(azArg[1],"html",n2)==0 ){
4300 p->mode = MODE_Html;
4301 }else if( c2=='t' && strncmp(azArg[1],"tcl",n2)==0 ){
4302 p->mode = MODE_Tcl;
4303 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Space);
4304 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row);
4305 }else if( c2=='c' && strncmp(azArg[1],"csv",n2)==0 ){
4306 p->mode = MODE_Csv;
4307 sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma);
4308 sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_CrLf);
4309 }else if( c2=='t' && strncmp(azArg[1],"tabs",n2)==0 ){
@@ -5295,11 +5300,11 @@
5300 sqlite3_libversion(), sqlite3_sourceid());
5301 }else
5302
5303 if( c=='v' && strncmp(azArg[0], "vfsinfo", n)==0 ){
5304 const char *zDbName = nArg==2 ? azArg[1] : "main";
5305 sqlite3_vfs *pVfs = 0;
5306 if( p->db ){
5307 sqlite3_file_control(p->db, zDbName, SQLITE_FCNTL_VFS_POINTER, &pVfs);
5308 if( pVfs ){
5309 utf8_printf(p->out, "vfs.zName = \"%s\"\n", pVfs->zName);
5310 raw_printf(p->out, "vfs.iVersion = %d\n", pVfs->iVersion);
5311
+1431 -760
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.16.2. By combining all the individual C code files into this
3
+** version 3.17.0. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -202,15 +202,32 @@
202202
# define _FILE_OFFSET_BITS 64
203203
# endif
204204
# define _LARGEFILE_SOURCE 1
205205
#endif
206206
207
-/* What version of GCC is being used. 0 means GCC is not being used */
208
-#ifdef __GNUC__
207
+/* The GCC_VERSION and MSVC_VERSION macros are used to
208
+** conditionally include optimizations for each of these compilers. A
209
+** value of 0 means that compiler is not being used. The
210
+** SQLITE_DISABLE_INTRINSIC macro means do not use any compiler-specific
211
+** optimizations, and hence set all compiler macros to 0
212
+**
213
+** There was once also a CLANG_VERSION macro. However, we learn that the
214
+** version numbers in clang are for "marketing" only and are inconsistent
215
+** and unreliable. Fortunately, all versions of clang also recognize the
216
+** gcc version numbers and have reasonable settings for gcc version numbers,
217
+** so the GCC_VERSION macro will be set to a correct non-zero value even
218
+** when compiling with clang.
219
+*/
220
+#if defined(__GNUC__) && !defined(SQLITE_DISABLE_INTRINSIC)
209221
# define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__)
210222
#else
211223
# define GCC_VERSION 0
224
+#endif
225
+#if defined(_MSC_VER) && !defined(SQLITE_DISABLE_INTRINSIC)
226
+# define MSVC_VERSION _MSC_VER
227
+#else
228
+# define MSVC_VERSION 0
212229
#endif
213230
214231
/* Needed for various definitions... */
215232
#if defined(__GNUC__) && !defined(_GNU_SOURCE)
216233
# define _GNU_SOURCE
@@ -379,13 +396,13 @@
379396
**
380397
** See also: [sqlite3_libversion()],
381398
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
382399
** [sqlite_version()] and [sqlite_source_id()].
383400
*/
384
-#define SQLITE_VERSION "3.16.2"
385
-#define SQLITE_VERSION_NUMBER 3016002
386
-#define SQLITE_SOURCE_ID "2017-01-06 16:32:41 a65a62893ca8319e89e48b8a38cf8a59c69a8209"
401
+#define SQLITE_VERSION "3.17.0"
402
+#define SQLITE_VERSION_NUMBER 3017000
403
+#define SQLITE_SOURCE_ID "2017-02-13 16:02:40 ada05cfa86ad7f5645450ac7a2a21c9aa6e57d2c"
387404
388405
/*
389406
** CAPI3REF: Run-Time Library Version Numbers
390407
** KEYWORDS: sqlite3_version sqlite3_sourceid
391408
**
@@ -517,11 +534,15 @@
517534
** sqlite3_uint64 and sqlite_uint64 types can store integer values
518535
** between 0 and +18446744073709551615 inclusive.
519536
*/
520537
#ifdef SQLITE_INT64_TYPE
521538
typedef SQLITE_INT64_TYPE sqlite_int64;
522
- typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
539
+# ifdef SQLITE_UINT64_TYPE
540
+ typedef SQLITE_UINT64_TYPE sqlite_uint64;
541
+# else
542
+ typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
543
+# endif
523544
#elif defined(_MSC_VER) || defined(__BORLANDC__)
524545
typedef __int64 sqlite_int64;
525546
typedef unsigned __int64 sqlite_uint64;
526547
#else
527548
typedef long long int sqlite_int64;
@@ -830,11 +851,11 @@
830851
** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
831852
** after reboot following a crash or power loss, the only bytes in a
832853
** file that were written at the application level might have changed
833854
** and that adjacent bytes, even bytes within the same sector are
834855
** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
835
-** flag indicate that a file cannot be deleted when open. The
856
+** flag indicates that a file cannot be deleted when open. The
836857
** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
837858
** read-only media and cannot be changed even by processes with
838859
** elevated privileges.
839860
*/
840861
#define SQLITE_IOCAP_ATOMIC 0x00000001
@@ -980,10 +1001,13 @@
9801001
** <li> [SQLITE_IOCAP_ATOMIC16K]
9811002
** <li> [SQLITE_IOCAP_ATOMIC32K]
9821003
** <li> [SQLITE_IOCAP_ATOMIC64K]
9831004
** <li> [SQLITE_IOCAP_SAFE_APPEND]
9841005
** <li> [SQLITE_IOCAP_SEQUENTIAL]
1006
+** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]
1007
+** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
1008
+** <li> [SQLITE_IOCAP_IMMUTABLE]
9851009
** </ul>
9861010
**
9871011
** The SQLITE_IOCAP_ATOMIC property means that all writes of
9881012
** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
9891013
** mean that writes of blocks that are nnn bytes in size and
@@ -5668,11 +5692,11 @@
56685692
** ^(The update hook is not invoked when internal system tables are
56695693
** modified (i.e. sqlite_master and sqlite_sequence).)^
56705694
** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
56715695
**
56725696
** ^In the current implementation, the update hook
5673
-** is not invoked when duplication rows are deleted because of an
5697
+** is not invoked when conflicting rows are deleted because of an
56745698
** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
56755699
** invoked when rows are deleted using the [truncate optimization].
56765700
** The exceptions defined in this paragraph might change in a future
56775701
** release of SQLite.
56785702
**
@@ -6450,10 +6474,16 @@
64506474
**
64516475
** ^Unless it returns SQLITE_MISUSE, this function sets the
64526476
** [database connection] error code and message accessible via
64536477
** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
64546478
**
6479
+** A BLOB referenced by sqlite3_blob_open() may be read using the
6480
+** [sqlite3_blob_read()] interface and modified by using
6481
+** [sqlite3_blob_write()]. The [BLOB handle] can be moved to a
6482
+** different row of the same table using the [sqlite3_blob_reopen()]
6483
+** interface. However, the column, table, or database of a [BLOB handle]
6484
+** cannot be changed after the [BLOB handle] is opened.
64556485
**
64566486
** ^(If the row that a BLOB handle points to is modified by an
64576487
** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
64586488
** then the BLOB handle is marked as "expired".
64596489
** This is true if any column of the row is changed, even a column
@@ -6473,10 +6503,14 @@
64736503
** and the built-in [zeroblob] SQL function may be used to create a
64746504
** zero-filled blob to read or write using the incremental-blob interface.
64756505
**
64766506
** To avoid a resource leak, every open [BLOB handle] should eventually
64776507
** be released by a call to [sqlite3_blob_close()].
6508
+**
6509
+** See also: [sqlite3_blob_close()],
6510
+** [sqlite3_blob_reopen()], [sqlite3_blob_read()],
6511
+** [sqlite3_blob_bytes()], [sqlite3_blob_write()].
64786512
*/
64796513
SQLITE_API int sqlite3_blob_open(
64806514
sqlite3*,
64816515
const char *zDb,
64826516
const char *zTable,
@@ -6488,15 +6522,15 @@
64886522
64896523
/*
64906524
** CAPI3REF: Move a BLOB Handle to a New Row
64916525
** METHOD: sqlite3_blob
64926526
**
6493
-** ^This function is used to move an existing blob handle so that it points
6527
+** ^This function is used to move an existing [BLOB handle] so that it points
64946528
** to a different row of the same database table. ^The new row is identified
64956529
** by the rowid value passed as the second argument. Only the row can be
64966530
** changed. ^The database, table and column on which the blob handle is open
6497
-** remain the same. Moving an existing blob handle to a new row can be
6531
+** remain the same. Moving an existing [BLOB handle] to a new row is
64986532
** faster than closing the existing handle and opening a new one.
64996533
**
65006534
** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] -
65016535
** it must exist and there must be either a blob or text value stored in
65026536
** the nominated column.)^ ^If the new row is not present in the table, or if
@@ -8421,22 +8455,22 @@
84218455
** ^These interfaces are only available if SQLite is compiled using the
84228456
** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option.
84238457
**
84248458
** ^The [sqlite3_preupdate_hook()] interface registers a callback function
84258459
** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation
8426
-** on a [rowid table].
8460
+** on a database table.
84278461
** ^At most one preupdate hook may be registered at a time on a single
84288462
** [database connection]; each call to [sqlite3_preupdate_hook()] overrides
84298463
** the previous setting.
84308464
** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()]
84318465
** with a NULL pointer as the second parameter.
84328466
** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as
84338467
** the first parameter to callbacks.
84348468
**
8435
-** ^The preupdate hook only fires for changes to [rowid tables]; the preupdate
8436
-** hook is not invoked for changes to [virtual tables] or [WITHOUT ROWID]
8437
-** tables.
8469
+** ^The preupdate hook only fires for changes to real database tables; the
8470
+** preupdate hook is not invoked for changes to [virtual tables] or to
8471
+** system tables like sqlite_master or sqlite_stat1.
84388472
**
84398473
** ^The second parameter to the preupdate callback is a pointer to
84408474
** the [database connection] that registered the preupdate hook.
84418475
** ^The third parameter to the preupdate callback is one of the constants
84428476
** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the
@@ -8446,16 +8480,20 @@
84468480
** will be "main" for the main database or "temp" for TEMP tables or
84478481
** the name given after the AS keyword in the [ATTACH] statement for attached
84488482
** databases.)^
84498483
** ^The fifth parameter to the preupdate callback is the name of the
84508484
** table that is being modified.
8451
-** ^The sixth parameter to the preupdate callback is the initial [rowid] of the
8452
-** row being changes for SQLITE_UPDATE and SQLITE_DELETE changes and is
8453
-** undefined for SQLITE_INSERT changes.
8454
-** ^The seventh parameter to the preupdate callback is the final [rowid] of
8455
-** the row being changed for SQLITE_UPDATE and SQLITE_INSERT changes and is
8456
-** undefined for SQLITE_DELETE changes.
8485
+**
8486
+** For an UPDATE or DELETE operation on a [rowid table], the sixth
8487
+** parameter passed to the preupdate callback is the initial [rowid] of the
8488
+** row being modified or deleted. For an INSERT operation on a rowid table,
8489
+** or any operation on a WITHOUT ROWID table, the value of the sixth
8490
+** parameter is undefined. For an INSERT or UPDATE on a rowid table the
8491
+** seventh parameter is the final rowid value of the row being inserted
8492
+** or updated. The value of the seventh parameter passed to the callback
8493
+** function is not defined for operations on WITHOUT ROWID tables, or for
8494
+** INSERT operations on rowid tables.
84578495
**
84588496
** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
84598497
** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
84608498
** provide additional information about a preupdate event. These routines
84618499
** may only be called from within a preupdate callback. Invoking any of
@@ -8887,11 +8925,11 @@
88878925
** The session object will be used to create changesets for tables in
88888926
** database zDb, where zDb is either "main", or "temp", or the name of an
88898927
** attached database. It is not an error if database zDb is not attached
88908928
** to the database when the session object is created.
88918929
*/
8892
-int sqlite3session_create(
8930
+SQLITE_API int sqlite3session_create(
88938931
sqlite3 *db, /* Database handle */
88948932
const char *zDb, /* Name of db (e.g. "main") */
88958933
sqlite3_session **ppSession /* OUT: New session object */
88968934
);
88978935
@@ -8905,11 +8943,11 @@
89058943
**
89068944
** Session objects must be deleted before the database handle to which they
89078945
** are attached is closed. Refer to the documentation for
89088946
** [sqlite3session_create()] for details.
89098947
*/
8910
-void sqlite3session_delete(sqlite3_session *pSession);
8948
+SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);
89118949
89128950
89138951
/*
89148952
** CAPI3REF: Enable Or Disable A Session Object
89158953
**
@@ -8925,11 +8963,11 @@
89258963
** no-op, and may be used to query the current state of the session.
89268964
**
89278965
** The return value indicates the final state of the session object: 0 if
89288966
** the session is disabled, or 1 if it is enabled.
89298967
*/
8930
-int sqlite3session_enable(sqlite3_session *pSession, int bEnable);
8968
+SQLITE_API int sqlite3session_enable(sqlite3_session *pSession, int bEnable);
89318969
89328970
/*
89338971
** CAPI3REF: Set Or Clear the Indirect Change Flag
89348972
**
89358973
** Each change recorded by a session object is marked as either direct or
@@ -8954,11 +8992,11 @@
89548992
** indirect flag for the specified session object.
89558993
**
89568994
** The return value indicates the final state of the indirect flag: 0 if
89578995
** it is clear, or 1 if it is set.
89588996
*/
8959
-int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect);
8997
+SQLITE_API int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect);
89608998
89618999
/*
89629000
** CAPI3REF: Attach A Table To A Session Object
89639001
**
89649002
** If argument zTab is not NULL, then it is the name of a table to attach
@@ -8984,11 +9022,11 @@
89849022
** in one or more of their PRIMARY KEY columns.
89859023
**
89869024
** SQLITE_OK is returned if the call completes without error. Or, if an error
89879025
** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
89889026
*/
8989
-int sqlite3session_attach(
9027
+SQLITE_API int sqlite3session_attach(
89909028
sqlite3_session *pSession, /* Session object */
89919029
const char *zTab /* Table name */
89929030
);
89939031
89949032
/*
@@ -8998,11 +9036,11 @@
89989036
** in tables that are not attached to the Session object, the filter is called
89999037
** to determine whether changes to the table's rows should be tracked or not.
90009038
** If xFilter returns 0, changes is not tracked. Note that once a table is
90019039
** attached, xFilter will not be called again.
90029040
*/
9003
-void sqlite3session_table_filter(
9041
+SQLITE_API void sqlite3session_table_filter(
90049042
sqlite3_session *pSession, /* Session object */
90059043
int(*xFilter)(
90069044
void *pCtx, /* Copy of third arg to _filter_table() */
90079045
const char *zTab /* Table name */
90089046
),
@@ -9111,11 +9149,11 @@
91119149
** changeset, even though the delete took place while the session was disabled.
91129150
** Or, if one field of a row is updated while a session is disabled, and
91139151
** another field of the same row is updated while the session is enabled, the
91149152
** resulting changeset will contain an UPDATE change that updates both fields.
91159153
*/
9116
-int sqlite3session_changeset(
9154
+SQLITE_API int sqlite3session_changeset(
91179155
sqlite3_session *pSession, /* Session object */
91189156
int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */
91199157
void **ppChangeset /* OUT: Buffer containing changeset */
91209158
);
91219159
@@ -9155,11 +9193,12 @@
91559193
**
91569194
** <li> For each row (primary key) that exists in the to-table but not in
91579195
** the from-table, a DELETE record is added to the session object.
91589196
**
91599197
** <li> For each row (primary key) that exists in both tables, but features
9160
-** different in each, an UPDATE record is added to the session.
9198
+** different non-PK values in each, an UPDATE record is added to the
9199
+** session.
91619200
** </ul>
91629201
**
91639202
** To clarify, if this function is called and then a changeset constructed
91649203
** using [sqlite3session_changeset()], then after applying that changeset to
91659204
** database zFrom the contents of the two compatible tables would be
@@ -9172,11 +9211,11 @@
91729211
** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
91739212
** may be set to point to a buffer containing an English language error
91749213
** message. It is the responsibility of the caller to free this buffer using
91759214
** sqlite3_free().
91769215
*/
9177
-int sqlite3session_diff(
9216
+SQLITE_API int sqlite3session_diff(
91789217
sqlite3_session *pSession,
91799218
const char *zFromDb,
91809219
const char *zTbl,
91819220
char **pzErrMsg
91829221
);
@@ -9208,11 +9247,11 @@
92089247
** Changes within a patchset are ordered in the same way as for changesets
92099248
** generated by the sqlite3session_changeset() function (i.e. all changes for
92109249
** a single table are grouped together, tables appear in the order in which
92119250
** they were attached to the session object).
92129251
*/
9213
-int sqlite3session_patchset(
9252
+SQLITE_API int sqlite3session_patchset(
92149253
sqlite3_session *pSession, /* Session object */
92159254
int *pnPatchset, /* OUT: Size of buffer at *ppChangeset */
92169255
void **ppPatchset /* OUT: Buffer containing changeset */
92179256
);
92189257
@@ -9229,11 +9268,11 @@
92299268
** an attached table is modified and then later on the original values
92309269
** are restored. However, if this function returns non-zero, then it is
92319270
** guaranteed that a call to sqlite3session_changeset() will return a
92329271
** changeset containing zero changes.
92339272
*/
9234
-int sqlite3session_isempty(sqlite3_session *pSession);
9273
+SQLITE_API int sqlite3session_isempty(sqlite3_session *pSession);
92359274
92369275
/*
92379276
** CAPI3REF: Create An Iterator To Traverse A Changeset
92389277
**
92399278
** Create an iterator used to iterate through the contents of a changeset.
@@ -9264,11 +9303,11 @@
92649303
** this function, all changes that relate to a single table are visited
92659304
** consecutively. There is no chance that the iterator will visit a change
92669305
** the applies to table X, then one for table Y, and then later on visit
92679306
** another change for table X.
92689307
*/
9269
-int sqlite3changeset_start(
9308
+SQLITE_API int sqlite3changeset_start(
92709309
sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */
92719310
int nChangeset, /* Size of changeset blob in bytes */
92729311
void *pChangeset /* Pointer to blob containing changeset */
92739312
);
92749313
@@ -9293,11 +9332,11 @@
92939332
**
92949333
** If an error occurs, an SQLite error code is returned. Possible error
92959334
** codes include SQLITE_CORRUPT (if the changeset buffer is corrupt) or
92969335
** SQLITE_NOMEM.
92979336
*/
9298
-int sqlite3changeset_next(sqlite3_changeset_iter *pIter);
9337
+SQLITE_API int sqlite3changeset_next(sqlite3_changeset_iter *pIter);
92999338
93009339
/*
93019340
** CAPI3REF: Obtain The Current Operation From A Changeset Iterator
93029341
**
93039342
** The pIter argument passed to this function may either be an iterator
@@ -9321,11 +9360,11 @@
93219360
**
93229361
** If no error occurs, SQLITE_OK is returned. If an error does occur, an
93239362
** SQLite error code is returned. The values of the output variables may not
93249363
** be trusted in this case.
93259364
*/
9326
-int sqlite3changeset_op(
9365
+SQLITE_API int sqlite3changeset_op(
93279366
sqlite3_changeset_iter *pIter, /* Iterator object */
93289367
const char **pzTab, /* OUT: Pointer to table name */
93299368
int *pnCol, /* OUT: Number of columns in table */
93309369
int *pOp, /* OUT: SQLITE_INSERT, DELETE or UPDATE */
93319370
int *pbIndirect /* OUT: True for an 'indirect' change */
@@ -9354,11 +9393,11 @@
93549393
** If this function is called when the iterator does not point to a valid
93559394
** entry, SQLITE_MISUSE is returned and the output variables zeroed. Otherwise,
93569395
** SQLITE_OK is returned and the output variables populated as described
93579396
** above.
93589397
*/
9359
-int sqlite3changeset_pk(
9398
+SQLITE_API int sqlite3changeset_pk(
93609399
sqlite3_changeset_iter *pIter, /* Iterator object */
93619400
unsigned char **pabPK, /* OUT: Array of boolean - true for PK cols */
93629401
int *pnCol /* OUT: Number of entries in output array */
93639402
);
93649403
@@ -9384,11 +9423,11 @@
93849423
** is similar to the "old.*" columns available to update or delete triggers.
93859424
**
93869425
** If some other error occurs (e.g. an OOM condition), an SQLite error code
93879426
** is returned and *ppValue is set to NULL.
93889427
*/
9389
-int sqlite3changeset_old(
9428
+SQLITE_API int sqlite3changeset_old(
93909429
sqlite3_changeset_iter *pIter, /* Changeset iterator */
93919430
int iVal, /* Column number */
93929431
sqlite3_value **ppValue /* OUT: Old value (or NULL pointer) */
93939432
);
93949433
@@ -9417,11 +9456,11 @@
94179456
** triggers.
94189457
**
94199458
** If some other error occurs (e.g. an OOM condition), an SQLite error code
94209459
** is returned and *ppValue is set to NULL.
94219460
*/
9422
-int sqlite3changeset_new(
9461
+SQLITE_API int sqlite3changeset_new(
94239462
sqlite3_changeset_iter *pIter, /* Changeset iterator */
94249463
int iVal, /* Column number */
94259464
sqlite3_value **ppValue /* OUT: New value (or NULL pointer) */
94269465
);
94279466
@@ -9444,11 +9483,11 @@
94449483
** and returns SQLITE_OK.
94459484
**
94469485
** If some other error occurs (e.g. an OOM condition), an SQLite error code
94479486
** is returned and *ppValue is set to NULL.
94489487
*/
9449
-int sqlite3changeset_conflict(
9488
+SQLITE_API int sqlite3changeset_conflict(
94509489
sqlite3_changeset_iter *pIter, /* Changeset iterator */
94519490
int iVal, /* Column number */
94529491
sqlite3_value **ppValue /* OUT: Value from conflicting row */
94539492
);
94549493
@@ -9460,11 +9499,11 @@
94609499
** it sets the output variable to the total number of known foreign key
94619500
** violations in the destination database and returns SQLITE_OK.
94629501
**
94639502
** In all other cases this function returns SQLITE_MISUSE.
94649503
*/
9465
-int sqlite3changeset_fk_conflicts(
9504
+SQLITE_API int sqlite3changeset_fk_conflicts(
94669505
sqlite3_changeset_iter *pIter, /* Changeset iterator */
94679506
int *pnOut /* OUT: Number of FK violations */
94689507
);
94699508
94709509
@@ -9493,11 +9532,11 @@
94939532
** rc = sqlite3changeset_finalize();
94949533
** if( rc!=SQLITE_OK ){
94959534
** // An error has occurred
94969535
** }
94979536
*/
9498
-int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter);
9537
+SQLITE_API int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter);
94999538
95009539
/*
95019540
** CAPI3REF: Invert A Changeset
95029541
**
95039542
** This function is used to "invert" a changeset object. Applying an inverted
@@ -9523,11 +9562,11 @@
95239562
** call to this function.
95249563
**
95259564
** WARNING/TODO: This function currently assumes that the input is a valid
95269565
** changeset. If it is not, the results are undefined.
95279566
*/
9528
-int sqlite3changeset_invert(
9567
+SQLITE_API int sqlite3changeset_invert(
95299568
int nIn, const void *pIn, /* Input changeset */
95309569
int *pnOut, void **ppOut /* OUT: Inverse of input */
95319570
);
95329571
95339572
/*
@@ -9552,11 +9591,11 @@
95529591
** *pnOut = 0;
95539592
** }
95549593
**
95559594
** Refer to the sqlite3_changegroup documentation below for details.
95569595
*/
9557
-int sqlite3changeset_concat(
9596
+SQLITE_API int sqlite3changeset_concat(
95589597
int nA, /* Number of bytes in buffer pA */
95599598
void *pA, /* Pointer to buffer containing changeset A */
95609599
int nB, /* Number of bytes in buffer pB */
95619600
void *pB, /* Pointer to buffer containing changeset B */
95629601
int *pnOut, /* OUT: Number of bytes in output changeset */
@@ -9740,11 +9779,11 @@
97409779
** considered compatible if all of the following are true:
97419780
**
97429781
** <ul>
97439782
** <li> The table has the same name as the name recorded in the
97449783
** changeset, and
9745
-** <li> The table has the same number of columns as recorded in the
9784
+** <li> The table has at least as many columns as recorded in the
97469785
** changeset, and
97479786
** <li> The table has primary key columns in the same position as
97489787
** recorded in the changeset.
97499788
** </ul>
97509789
**
@@ -9785,11 +9824,15 @@
97859824
** the changeset the row is deleted from the target database.
97869825
**
97879826
** If a row with matching primary key values is found, but one or more of
97889827
** the non-primary key fields contains a value different from the original
97899828
** row value stored in the changeset, the conflict-handler function is
9790
-** invoked with [SQLITE_CHANGESET_DATA] as the second argument.
9829
+** invoked with [SQLITE_CHANGESET_DATA] as the second argument. If the
9830
+** database table has more columns than are recorded in the changeset,
9831
+** only the values of those non-primary key fields are compared against
9832
+** the current database contents - any trailing database table columns
9833
+** are ignored.
97919834
**
97929835
** If no row with matching primary key values is found in the database,
97939836
** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
97949837
** passed as the second argument.
97959838
**
@@ -9800,11 +9843,13 @@
98009843
** operation is attempted because an earlier call to the conflict handler
98019844
** function returned [SQLITE_CHANGESET_REPLACE].
98029845
**
98039846
** <dt>INSERT Changes<dd>
98049847
** For each INSERT change, an attempt is made to insert the new row into
9805
-** the database.
9848
+** the database. If the changeset row contains fewer fields than the
9849
+** database table, the trailing fields are populated with their default
9850
+** values.
98069851
**
98079852
** If the attempt to insert the row fails because the database already
98089853
** contains a row with the same primary key values, the conflict handler
98099854
** function is invoked with the second argument set to
98109855
** [SQLITE_CHANGESET_CONFLICT].
@@ -9818,17 +9863,17 @@
98189863
**
98199864
** <dt>UPDATE Changes<dd>
98209865
** For each UPDATE change, this function checks if the target database
98219866
** contains a row with the same primary key value (or values) as the
98229867
** original row values stored in the changeset. If it does, and the values
9823
-** stored in all non-primary key columns also match the values stored in
9824
-** the changeset the row is updated within the target database.
9868
+** stored in all modified non-primary key columns also match the values
9869
+** stored in the changeset the row is updated within the target database.
98259870
**
98269871
** If a row with matching primary key values is found, but one or more of
9827
-** the non-primary key fields contains a value different from an original
9828
-** row value stored in the changeset, the conflict-handler function is
9829
-** invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since
9872
+** the modified non-primary key fields contains a value different from an
9873
+** original row value stored in the changeset, the conflict-handler function
9874
+** is invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since
98309875
** UPDATE changes only contain values for non-primary key fields that are
98319876
** to be modified, only those fields need to match the original values to
98329877
** avoid the SQLITE_CHANGESET_DATA conflict-handler callback.
98339878
**
98349879
** If no row with matching primary key values is found in the database,
@@ -9852,11 +9897,11 @@
98529897
** If any other error (aside from a constraint failure when attempting to
98539898
** write to the target database) occurs, then the savepoint transaction is
98549899
** rolled back, restoring the target database to its original state, and an
98559900
** SQLite error code returned.
98569901
*/
9857
-int sqlite3changeset_apply(
9902
+SQLITE_API int sqlite3changeset_apply(
98589903
sqlite3 *db, /* Apply change to "main" db of this handle */
98599904
int nChangeset, /* Size of changeset in bytes */
98609905
void *pChangeset, /* Changeset blob */
98619906
int(*xFilter)(
98629907
void *pCtx, /* Copy of sixth arg to _apply() */
@@ -10053,11 +10098,11 @@
1005310098
**
1005410099
** The sessions module never invokes an xOutput callback with the third
1005510100
** parameter set to a value less than or equal to zero. Other than this,
1005610101
** no guarantees are made as to the size of the chunks of data returned.
1005710102
*/
10058
-int sqlite3changeset_apply_strm(
10103
+SQLITE_API int sqlite3changeset_apply_strm(
1005910104
sqlite3 *db, /* Apply change to "main" db of this handle */
1006010105
int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
1006110106
void *pIn, /* First arg for xInput */
1006210107
int(*xFilter)(
1006310108
void *pCtx, /* Copy of sixth arg to _apply() */
@@ -10068,35 +10113,35 @@
1006810113
int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
1006910114
sqlite3_changeset_iter *p /* Handle describing change and conflict */
1007010115
),
1007110116
void *pCtx /* First argument passed to xConflict */
1007210117
);
10073
-int sqlite3changeset_concat_strm(
10118
+SQLITE_API int sqlite3changeset_concat_strm(
1007410119
int (*xInputA)(void *pIn, void *pData, int *pnData),
1007510120
void *pInA,
1007610121
int (*xInputB)(void *pIn, void *pData, int *pnData),
1007710122
void *pInB,
1007810123
int (*xOutput)(void *pOut, const void *pData, int nData),
1007910124
void *pOut
1008010125
);
10081
-int sqlite3changeset_invert_strm(
10126
+SQLITE_API int sqlite3changeset_invert_strm(
1008210127
int (*xInput)(void *pIn, void *pData, int *pnData),
1008310128
void *pIn,
1008410129
int (*xOutput)(void *pOut, const void *pData, int nData),
1008510130
void *pOut
1008610131
);
10087
-int sqlite3changeset_start_strm(
10132
+SQLITE_API int sqlite3changeset_start_strm(
1008810133
sqlite3_changeset_iter **pp,
1008910134
int (*xInput)(void *pIn, void *pData, int *pnData),
1009010135
void *pIn
1009110136
);
10092
-int sqlite3session_changeset_strm(
10137
+SQLITE_API int sqlite3session_changeset_strm(
1009310138
sqlite3_session *pSession,
1009410139
int (*xOutput)(void *pOut, const void *pData, int nData),
1009510140
void *pOut
1009610141
);
10097
-int sqlite3session_patchset_strm(
10142
+SQLITE_API int sqlite3session_patchset_strm(
1009810143
sqlite3_session *pSession,
1009910144
int (*xOutput)(void *pOut, const void *pData, int nData),
1010010145
void *pOut
1010110146
);
1010210147
int sqlite3changegroup_add_strm(sqlite3_changegroup*,
@@ -10999,10 +11044,11 @@
1099911044
# if defined(_MSC_VER) && _MSC_VER>=1400
1100011045
# if !defined(_WIN32_WCE)
1100111046
# include <intrin.h>
1100211047
# pragma intrinsic(_byteswap_ushort)
1100311048
# pragma intrinsic(_byteswap_ulong)
11049
+# pragma intrinsic(_byteswap_uint64)
1100411050
# pragma intrinsic(_ReadWriteBarrier)
1100511051
# else
1100611052
# include <cmnintrin.h>
1100711053
# endif
1100811054
# endif
@@ -11537,10 +11583,22 @@
1153711583
#include <stdlib.h>
1153811584
#include <string.h>
1153911585
#include <assert.h>
1154011586
#include <stddef.h>
1154111587
11588
+/*
11589
+** Use a macro to replace memcpy() if compiled with SQLITE_INLINE_MEMCPY.
11590
+** This allows better measurements of where memcpy() is used when running
11591
+** cachegrind. But this macro version of memcpy() is very slow so it
11592
+** should not be used in production. This is a performance measurement
11593
+** hack only.
11594
+*/
11595
+#ifdef SQLITE_INLINE_MEMCPY
11596
+# define memcpy(D,S,N) {char*xxd=(char*)(D);const char*xxs=(const char*)(S);\
11597
+ int xxn=(N);while(xxn-->0)*(xxd++)=*(xxs++);}
11598
+#endif
11599
+
1154211600
/*
1154311601
** If compiling for a processor that lacks floating point support,
1154411602
** substitute integer for floating-point
1154511603
*/
1154611604
#ifdef SQLITE_OMIT_FLOATING_POINT
@@ -11621,13 +11679,16 @@
1162111679
/*
1162211680
** The default initial allocation for the pagecache when using separate
1162311681
** pagecaches for each database connection. A positive number is the
1162411682
** number of pages. A negative number N translations means that a buffer
1162511683
** of -1024*N bytes is allocated and used for as many pages as it will hold.
11684
+**
11685
+** The default value of "20" was choosen to minimize the run-time of the
11686
+** speedtest1 test program with options: --shrink-memory --reprepare
1162611687
*/
1162711688
#ifndef SQLITE_DEFAULT_PCACHE_INITSZ
11628
-# define SQLITE_DEFAULT_PCACHE_INITSZ 100
11689
+# define SQLITE_DEFAULT_PCACHE_INITSZ 20
1162911690
#endif
1163011691
1163111692
/*
1163211693
** GCC does not define the offsetof() macro so we'll have to do it
1163311694
** ourselves.
@@ -11798,36 +11859,39 @@
1179811859
** Macros to determine whether the machine is big or little endian,
1179911860
** and whether or not that determination is run-time or compile-time.
1180011861
**
1180111862
** For best performance, an attempt is made to guess at the byte-order
1180211863
** using C-preprocessor macros. If that is unsuccessful, or if
11803
-** -DSQLITE_RUNTIME_BYTEORDER=1 is set, then byte-order is determined
11864
+** -DSQLITE_BYTEORDER=0 is set, then byte-order is determined
1180411865
** at run-time.
1180511866
*/
11806
-#if (defined(i386) || defined(__i386__) || defined(_M_IX86) || \
11867
+#ifndef SQLITE_BYTEORDER
11868
+# if defined(i386) || defined(__i386__) || defined(_M_IX86) || \
1180711869
defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \
1180811870
defined(_M_AMD64) || defined(_M_ARM) || defined(__x86) || \
11809
- defined(__arm__)) && !defined(SQLITE_RUNTIME_BYTEORDER)
11810
-# define SQLITE_BYTEORDER 1234
11811
-# define SQLITE_BIGENDIAN 0
11812
-# define SQLITE_LITTLEENDIAN 1
11813
-# define SQLITE_UTF16NATIVE SQLITE_UTF16LE
11871
+ defined(__arm__)
11872
+# define SQLITE_BYTEORDER 1234
11873
+# elif defined(sparc) || defined(__ppc__)
11874
+# define SQLITE_BYTEORDER 4321
11875
+# else
11876
+# define SQLITE_BYTEORDER 0
11877
+# endif
1181411878
#endif
11815
-#if (defined(sparc) || defined(__ppc__)) \
11816
- && !defined(SQLITE_RUNTIME_BYTEORDER)
11817
-# define SQLITE_BYTEORDER 4321
11879
+#if SQLITE_BYTEORDER==4321
1181811880
# define SQLITE_BIGENDIAN 1
1181911881
# define SQLITE_LITTLEENDIAN 0
1182011882
# define SQLITE_UTF16NATIVE SQLITE_UTF16BE
11821
-#endif
11822
-#if !defined(SQLITE_BYTEORDER)
11883
+#elif SQLITE_BYTEORDER==1234
11884
+# define SQLITE_BIGENDIAN 0
11885
+# define SQLITE_LITTLEENDIAN 1
11886
+# define SQLITE_UTF16NATIVE SQLITE_UTF16LE
11887
+#else
1182311888
# ifdef SQLITE_AMALGAMATION
1182411889
const int sqlite3one = 1;
1182511890
# else
1182611891
extern const int sqlite3one;
1182711892
# endif
11828
-# define SQLITE_BYTEORDER 0 /* 0 means "unknown at compile-time" */
1182911893
# define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0)
1183011894
# define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1)
1183111895
# define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE)
1183211896
#endif
1183311897
@@ -12346,13 +12410,14 @@
1234612410
);
1234712411
SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor*);
1234812412
SQLITE_PRIVATE int sqlite3BtreeCursorRestore(BtCursor*, int*);
1234912413
SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor*, u8 flags);
1235012414
12351
-/* Allowed flags for the 2nd argument to sqlite3BtreeDelete() */
12415
+/* Allowed flags for sqlite3BtreeDelete() and sqlite3BtreeInsert() */
1235212416
#define BTREE_SAVEPOSITION 0x02 /* Leave cursor pointing at NEXT or PREV */
1235312417
#define BTREE_AUXDELETE 0x04 /* not the primary delete operation */
12418
+#define BTREE_APPEND 0x08 /* Insert is likely an append */
1235412419
1235512420
/* An instance of the BtreePayload object describes the content of a single
1235612421
** entry in either an index or table btree.
1235712422
**
1235812423
** Index btrees (used for indexes and also WITHOUT ROWID tables) contain
@@ -12379,11 +12444,11 @@
1237912444
int nData; /* Size of pData. 0 if none. */
1238012445
int nZero; /* Extra zero data appended after pData,nData */
1238112446
};
1238212447
1238312448
SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload,
12384
- int bias, int seekResult);
12449
+ int flags, int seekResult);
1238512450
SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes);
1238612451
SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
1238712452
SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes);
1238812453
SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
1238912454
SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes);
@@ -12512,12 +12577,11 @@
1251212577
** as an instance of the following structure:
1251312578
*/
1251412579
struct VdbeOp {
1251512580
u8 opcode; /* What operation to perform */
1251612581
signed char p4type; /* One of the P4_xxx constants for p4 */
12517
- u8 notUsed1;
12518
- u8 p5; /* Fifth parameter is an unsigned character */
12582
+ u16 p5; /* Fifth parameter is an unsigned 16-bit integer */
1251912583
int p1; /* First operand */
1252012584
int p2; /* Second parameter (often the jump destination) */
1252112585
int p3; /* The third parameter */
1252212586
union p4union { /* fourth parameter */
1252312587
int i; /* Integer value if p4type==P4_INT32 */
@@ -12874,11 +12938,11 @@
1287412938
SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
1287512939
SQLITE_PRIVATE void sqlite3VdbeChangeOpcode(Vdbe*, u32 addr, u8);
1287612940
SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1);
1287712941
SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
1287812942
SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
12879
-SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
12943
+SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u16 P5);
1288012944
SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
1288112945
SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
1288212946
SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
1288312947
SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
1288412948
SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
@@ -13176,18 +13240,20 @@
1317613240
SQLITE_PRIVATE int sqlite3PagerCheckpoint(Pager *pPager, sqlite3*, int, int*, int*);
1317713241
SQLITE_PRIVATE int sqlite3PagerWalSupported(Pager *pPager);
1317813242
SQLITE_PRIVATE int sqlite3PagerWalCallback(Pager *pPager);
1317913243
SQLITE_PRIVATE int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen);
1318013244
SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager, sqlite3*);
13181
-SQLITE_PRIVATE int sqlite3PagerUseWal(Pager *pPager);
13245
+# ifdef SQLITE_DIRECT_OVERFLOW_READ
13246
+SQLITE_PRIVATE int sqlite3PagerUseWal(Pager *pPager, Pgno);
13247
+# endif
1318213248
# ifdef SQLITE_ENABLE_SNAPSHOT
1318313249
SQLITE_PRIVATE int sqlite3PagerSnapshotGet(Pager *pPager, sqlite3_snapshot **ppSnapshot);
1318413250
SQLITE_PRIVATE int sqlite3PagerSnapshotOpen(Pager *pPager, sqlite3_snapshot *pSnapshot);
1318513251
SQLITE_PRIVATE int sqlite3PagerSnapshotRecover(Pager *pPager);
1318613252
# endif
1318713253
#else
13188
-# define sqlite3PagerUseWal(x) 0
13254
+# define sqlite3PagerUseWal(x,y) 0
1318913255
#endif
1319013256
1319113257
#ifdef SQLITE_ENABLE_ZIPVFS
1319213258
SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager);
1319313259
#endif
@@ -14007,10 +14073,11 @@
1400714073
signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */
1400814074
u8 suppressErr; /* Do not issue error messages if true */
1400914075
u8 vtabOnConflict; /* Value to return for s3_vtab_on_conflict() */
1401014076
u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */
1401114077
u8 mTrace; /* zero or more SQLITE_TRACE flags */
14078
+ u8 skipBtreeMutex; /* True if no shared-cache backends */
1401214079
int nextPagesize; /* Pagesize after VACUUM if >0 */
1401314080
u32 magic; /* Magic number for detect library misuse */
1401414081
int nChange; /* Value returned by sqlite3_changes() */
1401514082
int nTotalChange; /* Value returned by sqlite3_total_changes() */
1401614083
int aLimit[SQLITE_N_LIMIT]; /* Limits */
@@ -14272,10 +14339,11 @@
1427214339
#define SQLITE_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */
1427314340
#define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */
1427414341
#define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */
1427514342
#define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a
1427614343
** single query - might change over time */
14344
+#define SQLITE_FUNC_AFFINITY 0x4000 /* Built-in affinity() function */
1427714345
1427814346
/*
1427914347
** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
1428014348
** used to create the initializers for the FuncDef structures.
1428114349
**
@@ -15278,11 +15346,11 @@
1527815346
#define WHERE_DISTINCTBY 0x0080 /* pOrderby is really a DISTINCT clause */
1527915347
#define WHERE_WANT_DISTINCT 0x0100 /* All output needs to be distinct */
1528015348
#define WHERE_SORTBYGROUP 0x0200 /* Support sqlite3WhereIsSorted() */
1528115349
#define WHERE_SEEK_TABLE 0x0400 /* Do not defer seeks on main table */
1528215350
#define WHERE_ORDERBY_LIMIT 0x0800 /* ORDERBY+LIMIT on the inner loop */
15283
- /* 0x1000 not currently used */
15351
+#define WHERE_SEEK_UNIQ_TABLE 0x1000 /* Do not defer seeks if unique */
1528415352
/* 0x2000 not currently used */
1528515353
#define WHERE_USE_LIMIT 0x4000 /* Use the LIMIT in cost estimates */
1528615354
/* 0x8000 not currently used */
1528715355
1528815356
/* Allowed return values from sqlite3WhereIsDistinct()
@@ -15739,25 +15807,23 @@
1573915807
** OPFLAG_AUXDELETE == BTREE_AUXDELETE
1574015808
*/
1574115809
#define OPFLAG_NCHANGE 0x01 /* OP_Insert: Set to update db->nChange */
1574215810
/* Also used in P2 (not P5) of OP_Delete */
1574315811
#define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */
15744
-#define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */
15812
+#define OPFLAG_LASTROWID 0x20 /* Set to update db->lastRowid */
1574515813
#define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */
1574615814
#define OPFLAG_APPEND 0x08 /* This is likely to be an append */
1574715815
#define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */
15748
-#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
1574915816
#define OPFLAG_ISNOOP 0x40 /* OP_Delete does pre-update-hook only */
15750
-#endif
1575115817
#define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */
1575215818
#define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */
1575315819
#define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */
1575415820
#define OPFLAG_SEEKEQ 0x02 /* OP_Open** cursor uses EQ seek only */
1575515821
#define OPFLAG_FORDELETE 0x08 /* OP_Open should use BTREE_FORDELETE */
1575615822
#define OPFLAG_P2ISREG 0x10 /* P2 to OP_Open** is a register number */
1575715823
#define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */
15758
-#define OPFLAG_SAVEPOSITION 0x02 /* OP_Delete: keep cursor position */
15824
+#define OPFLAG_SAVEPOSITION 0x02 /* OP_Delete/Insert: save cursor pos */
1575915825
#define OPFLAG_AUXDELETE 0x04 /* OP_Delete: index in a DELETE op */
1576015826
1576115827
/*
1576215828
* Each trigger present in the database schema is stored as an instance of
1576315829
* struct Trigger.
@@ -16414,11 +16480,11 @@
1641416480
SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*);
1641516481
SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
1641616482
SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int);
1641716483
SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, Expr*, int);
1641816484
SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
16419
-SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
16485
+SQLITE_PRIVATE int sqlite3ExprCodeAtInit(Parse*, Expr*, int);
1642016486
SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
1642116487
SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
1642216488
SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*, int);
1642316489
SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int, u8);
1642416490
#define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */
@@ -16476,10 +16542,15 @@
1647616542
SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*, int);
1647716543
SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,Index*,int);
1647816544
SQLITE_PRIVATE void sqlite3ResolvePartIdxLabel(Parse*,int);
1647916545
SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int,
1648016546
u8,u8,int,int*,int*);
16547
+#ifdef SQLITE_ENABLE_NULL_TRIM
16548
+SQLITE_PRIVATE void sqlite3SetMakeRecordP5(Vdbe*,Table*);
16549
+#else
16550
+# define sqlite3SetMakeRecordP5(A,B)
16551
+#endif
1648116552
SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int);
1648216553
SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, u8, int, u8*, int*, int*);
1648316554
SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse*, int, int);
1648416555
SQLITE_PRIVATE void sqlite3MultiWrite(Parse*);
1648516556
SQLITE_PRIVATE void sqlite3MayAbort(Parse*);
@@ -16754,12 +16825,14 @@
1675416825
#endif
1675516826
1675616827
/*
1675716828
** The interface to the LEMON-generated parser
1675816829
*/
16759
-SQLITE_PRIVATE void *sqlite3ParserAlloc(void*(*)(u64));
16760
-SQLITE_PRIVATE void sqlite3ParserFree(void*, void(*)(void*));
16830
+#ifndef SQLITE_AMALGAMATION
16831
+SQLITE_PRIVATE void *sqlite3ParserAlloc(void*(*)(u64));
16832
+SQLITE_PRIVATE void sqlite3ParserFree(void*, void(*)(void*));
16833
+#endif
1676116834
SQLITE_PRIVATE void sqlite3Parser(void*, int, Token, Parse*);
1676216835
#ifdef YYTRACKMAXSTACKDEPTH
1676316836
SQLITE_PRIVATE int sqlite3ParserStackPeak(void*);
1676416837
#endif
1676516838
@@ -16865,10 +16938,11 @@
1686516938
#define sqlite3FkActions(a,b,c,d,e,f)
1686616939
#define sqlite3FkCheck(a,b,c,d,e,f)
1686716940
#define sqlite3FkDropTable(a,b,c)
1686816941
#define sqlite3FkOldmask(a,b) 0
1686916942
#define sqlite3FkRequired(a,b,c,d) 0
16943
+ #define sqlite3FkReferences(a) 0
1687016944
#endif
1687116945
#ifndef SQLITE_OMIT_FOREIGN_KEY
1687216946
SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *, Table*);
1687316947
SQLITE_PRIVATE int sqlite3FkLocateIndex(Parse*,Table*,FKey*,Index**,int**);
1687416948
#else
@@ -17193,10 +17267,23 @@
1719317267
** setting.)
1719417268
*/
1719517269
#ifndef SQLITE_STMTJRNL_SPILL
1719617270
# define SQLITE_STMTJRNL_SPILL (64*1024)
1719717271
#endif
17272
+
17273
+/*
17274
+** The default lookaside-configuration, the format "SZ,N". SZ is the
17275
+** number of bytes in each lookaside slot (should be a multiple of 8)
17276
+** and N is the number of slots. The lookaside-configuration can be
17277
+** changed as start-time using sqlite3_config(SQLITE_CONFIG_LOOKASIDE)
17278
+** or at run-time for an individual database connection using
17279
+** sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE);
17280
+*/
17281
+#ifndef SQLITE_DEFAULT_LOOKASIDE
17282
+# define SQLITE_DEFAULT_LOOKASIDE 1200,100
17283
+#endif
17284
+
1719817285
1719917286
/*
1720017287
** The following singleton contains the global configuration for
1720117288
** the SQLite library.
1720217289
*/
@@ -17206,12 +17293,11 @@
1720617293
SQLITE_THREADSAFE==1, /* bFullMutex */
1720717294
SQLITE_USE_URI, /* bOpenUri */
1720817295
SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */
1720917296
0x7ffffffe, /* mxStrlen */
1721017297
0, /* neverCorrupt */
17211
- 512, /* szLookaside */
17212
- 125, /* nLookaside */
17298
+ SQLITE_DEFAULT_LOOKASIDE, /* szLookaside, nLookaside */
1721317299
SQLITE_STMTJRNL_SPILL, /* nStmtSpill */
1721417300
{0,0,0,0,0,0,0,0}, /* m */
1721517301
{0,0,0,0,0,0,0,0,0}, /* mutex */
1721617302
{0,0,0,0,0,0,0,0,0,0,0,0,0},/* pcache2 */
1721717303
(void*)0, /* pHeap */
@@ -18219,10 +18305,11 @@
1821918305
int iNewReg; /* Register for new.* values */
1822018306
i64 iKey1; /* First key value passed to hook */
1822118307
i64 iKey2; /* Second key value passed to hook */
1822218308
Mem *aNew; /* Array of new.* values */
1822318309
Table *pTab; /* Schema object being upated */
18310
+ Index *pPk; /* PK index if pTab is WITHOUT ROWID */
1822418311
};
1822518312
1822618313
/*
1822718314
** Function prototypes
1822818315
*/
@@ -20619,20 +20706,22 @@
2061920706
** cases of nByte<=0 will be intercepted and dealt with by higher level
2062020707
** routines.
2062120708
*/
2062220709
static void *sqlite3MemMalloc(int nByte){
2062320710
#ifdef SQLITE_MALLOCSIZE
20624
- void *p = SQLITE_MALLOC( nByte );
20711
+ void *p;
20712
+ testcase( ROUND8(nByte)==nByte );
20713
+ p = SQLITE_MALLOC( nByte );
2062520714
if( p==0 ){
2062620715
testcase( sqlite3GlobalConfig.xLog!=0 );
2062720716
sqlite3_log(SQLITE_NOMEM, "failed to allocate %u bytes of memory", nByte);
2062820717
}
2062920718
return p;
2063020719
#else
2063120720
sqlite3_int64 *p;
2063220721
assert( nByte>0 );
20633
- nByte = ROUND8(nByte);
20722
+ testcase( ROUND8(nByte)!=nByte );
2063420723
p = SQLITE_MALLOC( nByte+8 );
2063520724
if( p ){
2063620725
p[0] = nByte;
2063720726
p++;
2063820727
}else{
@@ -23750,12 +23839,11 @@
2375023839
SQLITE_PRIVATE void sqlite3MemoryBarrier(void){
2375123840
#if defined(SQLITE_MEMORY_BARRIER)
2375223841
SQLITE_MEMORY_BARRIER;
2375323842
#elif defined(__GNUC__)
2375423843
__sync_synchronize();
23755
-#elif !defined(SQLITE_DISABLE_INTRINSIC) && \
23756
- defined(_MSC_VER) && _MSC_VER>=1300
23844
+#elif MSVC_VERSION>=1300
2375723845
_ReadWriteBarrier();
2375823846
#elif defined(MemoryBarrier)
2375923847
MemoryBarrier();
2376023848
#endif
2376123849
}
@@ -24283,15 +24371,23 @@
2428324371
2428424372
/*
2428524373
** Do a memory allocation with statistics and alarms. Assume the
2428624374
** lock is already held.
2428724375
*/
24288
-static int mallocWithAlarm(int n, void **pp){
24289
- int nFull;
24376
+static void mallocWithAlarm(int n, void **pp){
2429024377
void *p;
24378
+ int nFull;
2429124379
assert( sqlite3_mutex_held(mem0.mutex) );
24380
+ assert( n>0 );
24381
+
24382
+ /* In Firefox (circa 2017-02-08), xRoundup() is remapped to an internal
24383
+ ** implementation of malloc_good_size(), which must be called in debug
24384
+ ** mode and specifically when the DMD "Dark Matter Detector" is enabled
24385
+ ** or else a crash results. Hence, do not attempt to optimize out the
24386
+ ** following xRoundup() call. */
2429224387
nFull = sqlite3GlobalConfig.m.xRoundup(n);
24388
+
2429324389
sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, n);
2429424390
if( mem0.alarmThreshold>0 ){
2429524391
sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
2429624392
if( nUsed >= mem0.alarmThreshold - nFull ){
2429724393
mem0.nearlyFull = 1;
@@ -24311,11 +24407,10 @@
2431124407
nFull = sqlite3MallocSize(p);
2431224408
sqlite3StatusUp(SQLITE_STATUS_MEMORY_USED, nFull);
2431324409
sqlite3StatusUp(SQLITE_STATUS_MALLOC_COUNT, 1);
2431424410
}
2431524411
*pp = p;
24316
- return nFull;
2431724412
}
2431824413
2431924414
/*
2432024415
** Allocate memory. This routine is like sqlite3_malloc() except that it
2432124416
** assumes the memory subsystem has already been initialized.
@@ -24951,11 +25046,10 @@
2495125046
2495225047
/*
2495325048
** Allowed values for et_info.flags
2495425049
*/
2495525050
#define FLAG_SIGNED 1 /* True if the value to convert is signed */
24956
-#define FLAG_INTERN 2 /* True if for internal use only */
2495725051
#define FLAG_STRING 4 /* Allow infinity precision */
2495825052
2495925053
2496025054
/*
2496125055
** The following table is searched linearly, so it is good to put the
@@ -24985,15 +25079,14 @@
2498525079
{ 'i', 10, 1, etRADIX, 0, 0 },
2498625080
{ 'n', 0, 0, etSIZE, 0, 0 },
2498725081
{ '%', 0, 0, etPERCENT, 0, 0 },
2498825082
{ 'p', 16, 0, etPOINTER, 0, 1 },
2498925083
24990
-/* All the rest have the FLAG_INTERN bit set and are thus for internal
24991
-** use only */
24992
- { 'T', 0, 2, etTOKEN, 0, 0 },
24993
- { 'S', 0, 2, etSRCLIST, 0, 0 },
24994
- { 'r', 10, 3, etORDINAL, 0, 0 },
25084
+ /* All the rest are undocumented and are for internal use only */
25085
+ { 'T', 0, 0, etTOKEN, 0, 0 },
25086
+ { 'S', 0, 0, etSRCLIST, 0, 0 },
25087
+ { 'r', 10, 1, etORDINAL, 0, 0 },
2499525088
};
2499625089
2499725090
/*
2499825091
** If SQLITE_OMIT_FLOATING_POINT is defined, then none of the floating point
2499925092
** conversions will work.
@@ -25083,11 +25176,10 @@
2508325176
etByte flag_long; /* True if "l" flag is present */
2508425177
etByte flag_longlong; /* True if the "ll" flag is present */
2508525178
etByte done; /* Loop termination flag */
2508625179
etByte xtype = etINVALID; /* Conversion paradigm */
2508725180
u8 bArgList; /* True for SQLITE_PRINTF_SQLFUNC */
25088
- u8 useIntern; /* Ok to use internal conversions (ex: %T) */
2508925181
char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
2509025182
sqlite_uint64 longvalue; /* Value for integer types */
2509125183
LONGDOUBLE_TYPE realvalue; /* Value for real types */
2509225184
const et_info *infop; /* Pointer to the appropriate info structure */
2509325185
char *zOut; /* Rendering buffer */
@@ -25102,17 +25194,15 @@
2510225194
#endif
2510325195
PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */
2510425196
char buf[etBUFSIZE]; /* Conversion buffer */
2510525197
2510625198
bufpt = 0;
25107
- if( pAccum->printfFlags ){
25108
- if( (bArgList = (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){
25109
- pArgList = va_arg(ap, PrintfArguments*);
25110
- }
25111
- useIntern = pAccum->printfFlags & SQLITE_PRINTF_INTERNAL;
25199
+ if( (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC)!=0 ){
25200
+ pArgList = va_arg(ap, PrintfArguments*);
25201
+ bArgList = 1;
2511225202
}else{
25113
- bArgList = useIntern = 0;
25203
+ bArgList = 0;
2511425204
}
2511525205
for(; (c=(*fmt))!=0; ++fmt){
2511625206
if( c!='%' ){
2511725207
bufpt = (char *)fmt;
2511825208
#if HAVE_STRCHRNUL
@@ -25220,15 +25310,11 @@
2522025310
infop = &fmtinfo[0];
2522125311
xtype = etINVALID;
2522225312
for(idx=0; idx<ArraySize(fmtinfo); idx++){
2522325313
if( c==fmtinfo[idx].fmttype ){
2522425314
infop = &fmtinfo[idx];
25225
- if( useIntern || (infop->flags & FLAG_INTERN)==0 ){
25226
- xtype = infop->type;
25227
- }else{
25228
- return;
25229
- }
25315
+ xtype = infop->type;
2523025316
break;
2523125317
}
2523225318
}
2523325319
2523425320
/*
@@ -25593,22 +25679,28 @@
2559325679
** consume, not the length of the output...
2559425680
** if( precision>=0 && precision<length ) length = precision; */
2559525681
break;
2559625682
}
2559725683
case etTOKEN: {
25598
- Token *pToken = va_arg(ap, Token*);
25684
+ Token *pToken;
25685
+ if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
25686
+ pToken = va_arg(ap, Token*);
2559925687
assert( bArgList==0 );
2560025688
if( pToken && pToken->n ){
2560125689
sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n);
2560225690
}
2560325691
length = width = 0;
2560425692
break;
2560525693
}
2560625694
case etSRCLIST: {
25607
- SrcList *pSrc = va_arg(ap, SrcList*);
25608
- int k = va_arg(ap, int);
25609
- struct SrcList_item *pItem = &pSrc->a[k];
25695
+ SrcList *pSrc;
25696
+ int k;
25697
+ struct SrcList_item *pItem;
25698
+ if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
25699
+ pSrc = va_arg(ap, SrcList*);
25700
+ k = va_arg(ap, int);
25701
+ pItem = &pSrc->a[k];
2561025702
assert( bArgList==0 );
2561125703
assert( k>=0 && k<pSrc->nSrc );
2561225704
if( pItem->zDatabase ){
2561325705
sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase);
2561425706
sqlite3StrAccumAppend(pAccum, ".", 1);
@@ -25626,13 +25718,17 @@
2562625718
** The text of the conversion is pointed to by "bufpt" and is
2562725719
** "length" characters long. The field width is "width". Do
2562825720
** the output.
2562925721
*/
2563025722
width -= length;
25631
- if( width>0 && !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
25632
- sqlite3StrAccumAppend(pAccum, bufpt, length);
25633
- if( width>0 && flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
25723
+ if( width>0 ){
25724
+ if( !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
25725
+ sqlite3StrAccumAppend(pAccum, bufpt, length);
25726
+ if( flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
25727
+ }else{
25728
+ sqlite3StrAccumAppend(pAccum, bufpt, length);
25729
+ }
2563425730
2563525731
if( zExtra ){
2563625732
sqlite3DbFree(pAccum->db, zExtra);
2563725733
zExtra = 0;
2563825734
}
@@ -28600,17 +28696,15 @@
2860028696
SQLITE_PRIVATE u32 sqlite3Get4byte(const u8 *p){
2860128697
#if SQLITE_BYTEORDER==4321
2860228698
u32 x;
2860328699
memcpy(&x,p,4);
2860428700
return x;
28605
-#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
28606
- && defined(__GNUC__) && GCC_VERSION>=4003000
28701
+#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
2860728702
u32 x;
2860828703
memcpy(&x,p,4);
2860928704
return __builtin_bswap32(x);
28610
-#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
28611
- && defined(_MSC_VER) && _MSC_VER>=1300
28705
+#elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
2861228706
u32 x;
2861328707
memcpy(&x,p,4);
2861428708
return _byteswap_ulong(x);
2861528709
#else
2861628710
testcase( p[0]&0x80 );
@@ -28618,16 +28712,14 @@
2861828712
#endif
2861928713
}
2862028714
SQLITE_PRIVATE void sqlite3Put4byte(unsigned char *p, u32 v){
2862128715
#if SQLITE_BYTEORDER==4321
2862228716
memcpy(p,&v,4);
28623
-#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
28624
- && defined(__GNUC__) && GCC_VERSION>=4003000
28717
+#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
2862528718
u32 x = __builtin_bswap32(v);
2862628719
memcpy(p,&x,4);
28627
-#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
28628
- && defined(_MSC_VER) && _MSC_VER>=1300
28720
+#elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
2862928721
u32 x = _byteswap_ulong(v);
2863028722
memcpy(p,&x,4);
2863128723
#else
2863228724
p[0] = (u8)(v>>24);
2863328725
p[1] = (u8)(v>>16);
@@ -28739,10 +28831,13 @@
2873928831
** the other 64-bit signed integer at *pA and store the result in *pA.
2874028832
** Return 0 on success. Or if the operation would have resulted in an
2874128833
** overflow, leave *pA unchanged and return 1.
2874228834
*/
2874328835
SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){
28836
+#if GCC_VERSION>=5004000
28837
+ return __builtin_add_overflow(*pA, iB, pA);
28838
+#else
2874428839
i64 iA = *pA;
2874528840
testcase( iA==0 ); testcase( iA==1 );
2874628841
testcase( iB==-1 ); testcase( iB==0 );
2874728842
if( iB>=0 ){
2874828843
testcase( iA>0 && LARGEST_INT64 - iA == iB );
@@ -28753,23 +28848,31 @@
2875328848
testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 2 );
2875428849
if( iA<0 && -(iA + LARGEST_INT64) > iB + 1 ) return 1;
2875528850
}
2875628851
*pA += iB;
2875728852
return 0;
28853
+#endif
2875828854
}
2875928855
SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){
28856
+#if GCC_VERSION>=5004000
28857
+ return __builtin_sub_overflow(*pA, iB, pA);
28858
+#else
2876028859
testcase( iB==SMALLEST_INT64+1 );
2876128860
if( iB==SMALLEST_INT64 ){
2876228861
testcase( (*pA)==(-1) ); testcase( (*pA)==0 );
2876328862
if( (*pA)>=0 ) return 1;
2876428863
*pA -= iB;
2876528864
return 0;
2876628865
}else{
2876728866
return sqlite3AddInt64(pA, -iB);
2876828867
}
28868
+#endif
2876928869
}
2877028870
SQLITE_PRIVATE int sqlite3MulInt64(i64 *pA, i64 iB){
28871
+#if GCC_VERSION>=5004000
28872
+ return __builtin_mul_overflow(*pA, iB, pA);
28873
+#else
2877128874
i64 iA = *pA;
2877228875
if( iB>0 ){
2877328876
if( iA>LARGEST_INT64/iB ) return 1;
2877428877
if( iA<SMALLEST_INT64/iB ) return 1;
2877528878
}else if( iB<0 ){
@@ -28781,10 +28884,11 @@
2878128884
if( -iA>LARGEST_INT64/-iB ) return 1;
2878228885
}
2878328886
}
2878428887
*pA = iA*iB;
2878528888
return 0;
28889
+#endif
2878628890
}
2878728891
2878828892
/*
2878928893
** Compute the absolute value of a 32-bit signed integer, of possible. Or
2879028894
** if the integer has a value of -2147483648, return +2147483647
@@ -47485,18 +47589,24 @@
4748547589
** if( pPager->jfd->pMethods ){ ...
4748647590
*/
4748747591
#define isOpen(pFd) ((pFd)->pMethods!=0)
4748847592
4748947593
/*
47490
-** Return true if this pager uses a write-ahead log instead of the usual
47491
-** rollback journal. Otherwise false.
47594
+** Return true if this pager uses a write-ahead log to read page pgno.
47595
+** Return false if the pager reads pgno directly from the database.
4749247596
*/
47597
+#if !defined(SQLITE_OMIT_WAL) && defined(SQLITE_DIRECT_OVERFLOW_READ)
47598
+SQLITE_PRIVATE int sqlite3PagerUseWal(Pager *pPager, Pgno pgno){
47599
+ u32 iRead = 0;
47600
+ int rc;
47601
+ if( pPager->pWal==0 ) return 0;
47602
+ rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iRead);
47603
+ return rc || iRead;
47604
+}
47605
+#endif
4749347606
#ifndef SQLITE_OMIT_WAL
47494
-SQLITE_PRIVATE int sqlite3PagerUseWal(Pager *pPager){
47495
- return (pPager->pWal!=0);
47496
-}
47497
-# define pagerUseWal(x) sqlite3PagerUseWal(x)
47607
+# define pagerUseWal(x) ((x)->pWal!=0)
4749847608
#else
4749947609
# define pagerUseWal(x) 0
4750047610
# define pagerRollbackWal(x) 0
4750147611
# define pagerWalFrames(v,w,x,y) 0
4750247612
# define pagerOpenWalIfPresent(z) SQLITE_OK
@@ -58445,15 +58555,13 @@
5844558555
** two-byte aligned address. get2bytea() is only used for accessing the
5844658556
** cell addresses in a btree header.
5844758557
*/
5844858558
#if SQLITE_BYTEORDER==4321
5844958559
# define get2byteAligned(x) (*(u16*)(x))
58450
-#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
58451
- && GCC_VERSION>=4008000
58560
+#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4008000
5845258561
# define get2byteAligned(x) __builtin_bswap16(*(u16*)(x))
58453
-#elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
58454
- && defined(_MSC_VER) && _MSC_VER>=1300
58562
+#elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
5845558563
# define get2byteAligned(x) _byteswap_ushort(*(u16*)(x))
5845658564
#else
5845758565
# define get2byteAligned(x) ((x)[0]<<8 | (x)[1])
5845858566
#endif
5845958567
@@ -58624,27 +58732,38 @@
5862458732
** Enter the mutexes in accending order by BtShared pointer address
5862558733
** to avoid the possibility of deadlock when two threads with
5862658734
** two or more btrees in common both try to lock all their btrees
5862758735
** at the same instant.
5862858736
*/
58629
-SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){
58737
+static void SQLITE_NOINLINE btreeEnterAll(sqlite3 *db){
5863058738
int i;
58739
+ int skipOk = 1;
5863158740
Btree *p;
5863258741
assert( sqlite3_mutex_held(db->mutex) );
5863358742
for(i=0; i<db->nDb; i++){
5863458743
p = db->aDb[i].pBt;
58635
- if( p ) sqlite3BtreeEnter(p);
58744
+ if( p && p->sharable ){
58745
+ sqlite3BtreeEnter(p);
58746
+ skipOk = 0;
58747
+ }
5863658748
}
58749
+ db->skipBtreeMutex = skipOk;
5863758750
}
58638
-SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3 *db){
58751
+SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){
58752
+ if( db->skipBtreeMutex==0 ) btreeEnterAll(db);
58753
+}
58754
+static void SQLITE_NOINLINE btreeLeaveAll(sqlite3 *db){
5863958755
int i;
5864058756
Btree *p;
5864158757
assert( sqlite3_mutex_held(db->mutex) );
5864258758
for(i=0; i<db->nDb; i++){
5864358759
p = db->aDb[i].pBt;
5864458760
if( p ) sqlite3BtreeLeave(p);
5864558761
}
58762
+}
58763
+SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3 *db){
58764
+ if( db->skipBtreeMutex==0 ) btreeLeaveAll(db);
5864658765
}
5864758766
5864858767
#ifndef NDEBUG
5864958768
/*
5865058769
** Return true if the current thread holds the database connection
@@ -62097,16 +62216,18 @@
6209762216
for(i=0; i<nCell; i++){
6209862217
u8 *pCell = findCell(pPage, i);
6209962218
if( eType==PTRMAP_OVERFLOW1 ){
6210062219
CellInfo info;
6210162220
pPage->xParseCell(pPage, pCell, &info);
62102
- if( info.nLocal<info.nPayload
62103
- && pCell+info.nSize-1<=pPage->aData+pPage->maskPage
62104
- && iFrom==get4byte(pCell+info.nSize-4)
62105
- ){
62106
- put4byte(pCell+info.nSize-4, iTo);
62107
- break;
62221
+ if( info.nLocal<info.nPayload ){
62222
+ if( pCell+info.nSize > pPage->aData+pPage->pBt->usableSize ){
62223
+ return SQLITE_CORRUPT_BKPT;
62224
+ }
62225
+ if( iFrom==get4byte(pCell+info.nSize-4) ){
62226
+ put4byte(pCell+info.nSize-4, iTo);
62227
+ break;
62228
+ }
6210862229
}
6210962230
}else{
6211062231
if( get4byte(pCell)==iFrom ){
6211162232
put4byte(pCell, iTo);
6211262233
break;
@@ -62777,11 +62898,16 @@
6277762898
if( p && p->inTrans==TRANS_WRITE ){
6277862899
BtShared *pBt = p->pBt;
6277962900
assert( op==SAVEPOINT_RELEASE || op==SAVEPOINT_ROLLBACK );
6278062901
assert( iSavepoint>=0 || (iSavepoint==-1 && op==SAVEPOINT_ROLLBACK) );
6278162902
sqlite3BtreeEnter(p);
62782
- rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint);
62903
+ if( op==SAVEPOINT_ROLLBACK ){
62904
+ rc = saveAllCursors(pBt, 0, 0);
62905
+ }
62906
+ if( rc==SQLITE_OK ){
62907
+ rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint);
62908
+ }
6278362909
if( rc==SQLITE_OK ){
6278462910
if( iSavepoint<0 && (pBt->btsFlags & BTS_INITIALLY_EMPTY)!=0 ){
6278562911
pBt->nPage = 0;
6278662912
}
6278762913
rc = newDatabase(pBt);
@@ -63163,25 +63289,24 @@
6316363289
** for the entry that the pCur cursor is pointing to. The eOp
6316463290
** argument is interpreted as follows:
6316563291
**
6316663292
** 0: The operation is a read. Populate the overflow cache.
6316763293
** 1: The operation is a write. Populate the overflow cache.
63168
-** 2: The operation is a read. Do not populate the overflow cache.
6316963294
**
6317063295
** A total of "amt" bytes are read or written beginning at "offset".
6317163296
** Data is read to or from the buffer pBuf.
6317263297
**
6317363298
** The content being read or written might appear on the main page
6317463299
** or be scattered out on multiple overflow pages.
6317563300
**
63176
-** If the current cursor entry uses one or more overflow pages and the
63177
-** eOp argument is not 2, this function may allocate space for and lazily
63178
-** populates the overflow page-list cache array (BtCursor.aOverflow).
63301
+** If the current cursor entry uses one or more overflow pages
63302
+** this function may allocate space for and lazily populate
63303
+** the overflow page-list cache array (BtCursor.aOverflow).
6317963304
** Subsequent calls use this cache to make seeking to the supplied offset
6318063305
** more efficient.
6318163306
**
63182
-** Once an overflow page-list cache has been allocated, it may be
63307
+** Once an overflow page-list cache has been allocated, it must be
6318363308
** invalidated if some other cursor writes to the same table, or if
6318463309
** the cursor is moved to a different row. Additionally, in auto-vacuum
6318563310
** mode, the following events may invalidate an overflow page-list cache.
6318663311
**
6318763312
** * An incremental vacuum,
@@ -63199,25 +63324,21 @@
6319963324
int rc = SQLITE_OK;
6320063325
int iIdx = 0;
6320163326
MemPage *pPage = pCur->apPage[pCur->iPage]; /* Btree page of current entry */
6320263327
BtShared *pBt = pCur->pBt; /* Btree this cursor belongs to */
6320363328
#ifdef SQLITE_DIRECT_OVERFLOW_READ
63204
- unsigned char * const pBufStart = pBuf;
63205
- int bEnd; /* True if reading to end of data */
63329
+ unsigned char * const pBufStart = pBuf; /* Start of original out buffer */
6320663330
#endif
6320763331
6320863332
assert( pPage );
63333
+ assert( eOp==0 || eOp==1 );
6320963334
assert( pCur->eState==CURSOR_VALID );
6321063335
assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
6321163336
assert( cursorHoldsMutex(pCur) );
63212
- assert( eOp!=2 || offset==0 ); /* Always start from beginning for eOp==2 */
6321363337
6321463338
getCellInfo(pCur);
6321563339
aPayload = pCur->info.pPayload;
63216
-#ifdef SQLITE_DIRECT_OVERFLOW_READ
63217
- bEnd = offset+amt==pCur->info.nPayload;
63218
-#endif
6321963340
assert( offset+amt <= pCur->info.nPayload );
6322063341
6322163342
assert( aPayload > pPage->aData );
6322263343
if( (uptr)(aPayload - pPage->aData) > (pBt->usableSize - pCur->info.nLocal) ){
6322363344
/* Trying to read or write past the end of the data is an error. The
@@ -63232,11 +63353,11 @@
6323263353
if( offset<pCur->info.nLocal ){
6323363354
int a = amt;
6323463355
if( a+offset>pCur->info.nLocal ){
6323563356
a = pCur->info.nLocal - offset;
6323663357
}
63237
- rc = copyPayload(&aPayload[offset], pBuf, a, (eOp & 0x01), pPage->pDbPage);
63358
+ rc = copyPayload(&aPayload[offset], pBuf, a, eOp, pPage->pDbPage);
6323863359
offset = 0;
6323963360
pBuf += a;
6324063361
amt -= a;
6324163362
}else{
6324263363
offset -= pCur->info.nLocal;
@@ -63248,69 +63369,58 @@
6324863369
Pgno nextPage;
6324963370
6325063371
nextPage = get4byte(&aPayload[pCur->info.nLocal]);
6325163372
6325263373
/* If the BtCursor.aOverflow[] has not been allocated, allocate it now.
63253
- ** Except, do not allocate aOverflow[] for eOp==2.
6325463374
**
6325563375
** The aOverflow[] array is sized at one entry for each overflow page
6325663376
** in the overflow chain. The page number of the first overflow page is
6325763377
** stored in aOverflow[0], etc. A value of 0 in the aOverflow[] array
6325863378
** means "not yet known" (the cache is lazily populated).
6325963379
*/
63260
- if( eOp!=2 && (pCur->curFlags & BTCF_ValidOvfl)==0 ){
63380
+ if( (pCur->curFlags & BTCF_ValidOvfl)==0 ){
6326163381
int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize;
6326263382
if( nOvfl>pCur->nOvflAlloc ){
6326363383
Pgno *aNew = (Pgno*)sqlite3Realloc(
6326463384
pCur->aOverflow, nOvfl*2*sizeof(Pgno)
6326563385
);
6326663386
if( aNew==0 ){
63267
- rc = SQLITE_NOMEM_BKPT;
63387
+ return SQLITE_NOMEM_BKPT;
6326863388
}else{
6326963389
pCur->nOvflAlloc = nOvfl*2;
6327063390
pCur->aOverflow = aNew;
6327163391
}
6327263392
}
63273
- if( rc==SQLITE_OK ){
63274
- memset(pCur->aOverflow, 0, nOvfl*sizeof(Pgno));
63275
- pCur->curFlags |= BTCF_ValidOvfl;
63393
+ memset(pCur->aOverflow, 0, nOvfl*sizeof(Pgno));
63394
+ pCur->curFlags |= BTCF_ValidOvfl;
63395
+ }else{
63396
+ /* If the overflow page-list cache has been allocated and the
63397
+ ** entry for the first required overflow page is valid, skip
63398
+ ** directly to it.
63399
+ */
63400
+ if( pCur->aOverflow[offset/ovflSize] ){
63401
+ iIdx = (offset/ovflSize);
63402
+ nextPage = pCur->aOverflow[iIdx];
63403
+ offset = (offset%ovflSize);
6327663404
}
6327763405
}
6327863406
63279
- /* If the overflow page-list cache has been allocated and the
63280
- ** entry for the first required overflow page is valid, skip
63281
- ** directly to it.
63282
- */
63283
- if( (pCur->curFlags & BTCF_ValidOvfl)!=0
63284
- && pCur->aOverflow[offset/ovflSize]
63285
- ){
63286
- iIdx = (offset/ovflSize);
63287
- nextPage = pCur->aOverflow[iIdx];
63288
- offset = (offset%ovflSize);
63289
- }
63290
-
63291
- for( ; rc==SQLITE_OK && amt>0 && nextPage; iIdx++){
63292
-
63407
+ assert( rc==SQLITE_OK && amt>0 );
63408
+ while( nextPage ){
6329363409
/* If required, populate the overflow page-list cache. */
63294
- if( (pCur->curFlags & BTCF_ValidOvfl)!=0 ){
63295
- assert( pCur->aOverflow[iIdx]==0
63296
- || pCur->aOverflow[iIdx]==nextPage
63297
- || CORRUPT_DB );
63298
- pCur->aOverflow[iIdx] = nextPage;
63299
- }
63410
+ assert( pCur->aOverflow[iIdx]==0
63411
+ || pCur->aOverflow[iIdx]==nextPage
63412
+ || CORRUPT_DB );
63413
+ pCur->aOverflow[iIdx] = nextPage;
6330063414
6330163415
if( offset>=ovflSize ){
6330263416
/* The only reason to read this page is to obtain the page
6330363417
** number for the next page in the overflow chain. The page
6330463418
** data is not required. So first try to lookup the overflow
6330563419
** page-list cache, if any, then fall back to the getOverflowPage()
6330663420
** function.
63307
- **
63308
- ** Note that the aOverflow[] array must be allocated because eOp!=2
63309
- ** here. If eOp==2, then offset==0 and this branch is never taken.
6331063421
*/
63311
- assert( eOp!=2 );
6331263422
assert( pCur->curFlags & BTCF_ValidOvfl );
6331363423
assert( pCur->pBtree->db==pBt->db );
6331463424
if( pCur->aOverflow[iIdx+1] ){
6331563425
nextPage = pCur->aOverflow[iIdx+1];
6331663426
}else{
@@ -63320,11 +63430,11 @@
6332063430
}else{
6332163431
/* Need to read this page properly. It contains some of the
6332263432
** range of data that is being read (eOp==0) or written (eOp!=0).
6332363433
*/
6332463434
#ifdef SQLITE_DIRECT_OVERFLOW_READ
63325
- sqlite3_file *fd;
63435
+ sqlite3_file *fd; /* File from which to do direct overflow read */
6332663436
#endif
6332763437
int a = amt;
6332863438
if( a + offset > ovflSize ){
6332963439
a = ovflSize - offset;
6333063440
}
@@ -63332,31 +63442,29 @@
6333263442
#ifdef SQLITE_DIRECT_OVERFLOW_READ
6333363443
/* If all the following are true:
6333463444
**
6333563445
** 1) this is a read operation, and
6333663446
** 2) data is required from the start of this overflow page, and
63337
- ** 3) the database is file-backed, and
63338
- ** 4) there is no open write-transaction, and
63339
- ** 5) the database is not a WAL database,
63340
- ** 6) all data from the page is being read.
63341
- ** 7) at least 4 bytes have already been read into the output buffer
63447
+ ** 3) there is no open write-transaction, and
63448
+ ** 4) the database is file-backed, and
63449
+ ** 5) the page is not in the WAL file
63450
+ ** 6) at least 4 bytes have already been read into the output buffer
6334263451
**
6334363452
** then data can be read directly from the database file into the
6334463453
** output buffer, bypassing the page-cache altogether. This speeds
6334563454
** up loading large records that span many overflow pages.
6334663455
*/
63347
- if( (eOp&0x01)==0 /* (1) */
63456
+ if( eOp==0 /* (1) */
6334863457
&& offset==0 /* (2) */
63349
- && (bEnd || a==ovflSize) /* (6) */
63350
- && pBt->inTransaction==TRANS_READ /* (4) */
63351
- && (fd = sqlite3PagerFile(pBt->pPager))->pMethods /* (3) */
63352
- && 0==sqlite3PagerUseWal(pBt->pPager) /* (5) */
63353
- && &pBuf[-4]>=pBufStart /* (7) */
63458
+ && pBt->inTransaction==TRANS_READ /* (3) */
63459
+ && (fd = sqlite3PagerFile(pBt->pPager))->pMethods /* (4) */
63460
+ && 0==sqlite3PagerUseWal(pBt->pPager, nextPage) /* (5) */
63461
+ && &pBuf[-4]>=pBufStart /* (6) */
6335463462
){
6335563463
u8 aSave[4];
6335663464
u8 *aWrite = &pBuf[-4];
63357
- assert( aWrite>=pBufStart ); /* hence (7) */
63465
+ assert( aWrite>=pBufStart ); /* due to (6) */
6335863466
memcpy(aSave, aWrite, 4);
6335963467
rc = sqlite3OsRead(fd, aWrite, a+4, (i64)pBt->pageSize*(nextPage-1));
6336063468
nextPage = get4byte(aWrite);
6336163469
memcpy(aWrite, aSave, 4);
6336263470
}else
@@ -63363,28 +63471,31 @@
6336363471
#endif
6336463472
6336563473
{
6336663474
DbPage *pDbPage;
6336763475
rc = sqlite3PagerGet(pBt->pPager, nextPage, &pDbPage,
63368
- ((eOp&0x01)==0 ? PAGER_GET_READONLY : 0)
63476
+ (eOp==0 ? PAGER_GET_READONLY : 0)
6336963477
);
6337063478
if( rc==SQLITE_OK ){
6337163479
aPayload = sqlite3PagerGetData(pDbPage);
6337263480
nextPage = get4byte(aPayload);
63373
- rc = copyPayload(&aPayload[offset+4], pBuf, a, (eOp&0x01), pDbPage);
63481
+ rc = copyPayload(&aPayload[offset+4], pBuf, a, eOp, pDbPage);
6337463482
sqlite3PagerUnref(pDbPage);
6337563483
offset = 0;
6337663484
}
6337763485
}
6337863486
amt -= a;
63487
+ if( amt==0 ) return rc;
6337963488
pBuf += a;
6338063489
}
63490
+ if( rc ) break;
63491
+ iIdx++;
6338163492
}
6338263493
}
6338363494
6338463495
if( rc==SQLITE_OK && amt>0 ){
63385
- return SQLITE_CORRUPT_BKPT;
63496
+ return SQLITE_CORRUPT_BKPT; /* Overflow chain ends prematurely */
6338663497
}
6338763498
return rc;
6338863499
}
6338963500
6339063501
/*
@@ -63409,25 +63520,38 @@
6340963520
assert( pCur->eState==CURSOR_VALID );
6341063521
assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
6341163522
assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
6341263523
return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
6341363524
}
63525
+
63526
+/*
63527
+** This variant of sqlite3BtreePayload() works even if the cursor has not
63528
+** in the CURSOR_VALID state. It is only used by the sqlite3_blob_read()
63529
+** interface.
63530
+*/
6341463531
#ifndef SQLITE_OMIT_INCRBLOB
63415
-SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
63532
+static SQLITE_NOINLINE int accessPayloadChecked(
63533
+ BtCursor *pCur,
63534
+ u32 offset,
63535
+ u32 amt,
63536
+ void *pBuf
63537
+){
6341663538
int rc;
6341763539
if ( pCur->eState==CURSOR_INVALID ){
6341863540
return SQLITE_ABORT;
6341963541
}
6342063542
assert( cursorOwnsBtShared(pCur) );
63421
- rc = restoreCursorPosition(pCur);
63422
- if( rc==SQLITE_OK ){
63423
- assert( pCur->eState==CURSOR_VALID );
63424
- assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
63425
- assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
63426
- rc = accessPayload(pCur, offset, amt, pBuf, 0);
63427
- }
63428
- return rc;
63543
+ rc = btreeRestoreCursorPosition(pCur);
63544
+ return rc ? rc : accessPayload(pCur, offset, amt, pBuf, 0);
63545
+}
63546
+SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
63547
+ if( pCur->eState==CURSOR_VALID ){
63548
+ assert( cursorOwnsBtShared(pCur) );
63549
+ return accessPayload(pCur, offset, amt, pBuf, 0);
63550
+ }else{
63551
+ return accessPayloadChecked(pCur, offset, amt, pBuf);
63552
+ }
6342963553
}
6343063554
#endif /* SQLITE_OMIT_INCRBLOB */
6343163555
6343263556
/*
6343363557
** Return a pointer to payload information from the entry that the
@@ -63829,13 +63953,30 @@
6382963953
){
6383063954
if( pCur->info.nKey==intKey ){
6383163955
*pRes = 0;
6383263956
return SQLITE_OK;
6383363957
}
63834
- if( (pCur->curFlags & BTCF_AtLast)!=0 && pCur->info.nKey<intKey ){
63835
- *pRes = -1;
63836
- return SQLITE_OK;
63958
+ if( pCur->info.nKey<intKey ){
63959
+ if( (pCur->curFlags & BTCF_AtLast)!=0 ){
63960
+ *pRes = -1;
63961
+ return SQLITE_OK;
63962
+ }
63963
+ /* If the requested key is one more than the previous key, then
63964
+ ** try to get there using sqlite3BtreeNext() rather than a full
63965
+ ** binary search. This is an optimization only. The correct answer
63966
+ ** is still obtained without this ase, only a little more slowely */
63967
+ if( pCur->info.nKey+1==intKey && !pCur->skipNext ){
63968
+ *pRes = 0;
63969
+ rc = sqlite3BtreeNext(pCur, pRes);
63970
+ if( rc ) return rc;
63971
+ if( *pRes==0 ){
63972
+ getCellInfo(pCur);
63973
+ if( pCur->info.nKey==intKey ){
63974
+ return SQLITE_OK;
63975
+ }
63976
+ }
63977
+ }
6383763978
}
6383863979
}
6383963980
6384063981
if( pIdxKey ){
6384163982
xRecordCompare = sqlite3VdbeFindCompare(pIdxKey);
@@ -63967,11 +64108,12 @@
6396764108
if( pCellKey==0 ){
6396864109
rc = SQLITE_NOMEM_BKPT;
6396964110
goto moveto_finish;
6397064111
}
6397164112
pCur->aiIdx[pCur->iPage] = (u16)idx;
63972
- rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 2);
64113
+ rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
64114
+ pCur->curFlags &= ~BTCF_ValidOvfl;
6397364115
if( rc ){
6397464116
sqlite3_free(pCellKey);
6397564117
goto moveto_finish;
6397664118
}
6397764119
c = xRecordCompare(nCell, pCellKey, pIdxKey);
@@ -66010,11 +66152,10 @@
6601066152
*/
6601166153
usableSpace = pBt->usableSize - 12 + leafCorrection;
6601266154
for(i=0; i<nOld; i++){
6601366155
MemPage *p = apOld[i];
6601466156
szNew[i] = usableSpace - p->nFree;
66015
- if( szNew[i]<0 ){ rc = SQLITE_CORRUPT_BKPT; goto balance_cleanup; }
6601666157
for(j=0; j<p->nOverflow; j++){
6601766158
szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]);
6601866159
}
6601966160
cntNew[i] = cntOld[i];
6602066161
}
@@ -66689,11 +66830,11 @@
6668966830
** to decode the key.
6669066831
*/
6669166832
SQLITE_PRIVATE int sqlite3BtreeInsert(
6669266833
BtCursor *pCur, /* Insert data into the table of this cursor */
6669366834
const BtreePayload *pX, /* Content of the row to be inserted */
66694
- int appendBias, /* True if this is likely an append */
66835
+ int flags, /* True if this is likely an append */
6669566836
int seekResult /* Result of prior MovetoUnpacked() call */
6669666837
){
6669766838
int rc;
6669866839
int loc = seekResult; /* -1: before desired location +1: after */
6669966840
int szNew = 0;
@@ -66701,10 +66842,12 @@
6670166842
MemPage *pPage;
6670266843
Btree *p = pCur->pBtree;
6670366844
BtShared *pBt = p->pBt;
6670466845
unsigned char *oldCell;
6670566846
unsigned char *newCell = 0;
66847
+
66848
+ assert( (flags & (BTREE_SAVEPOSITION|BTREE_APPEND))==flags );
6670666849
6670766850
if( pCur->eState==CURSOR_FAULT ){
6670866851
assert( pCur->skipNext!=SQLITE_OK );
6670966852
return pCur->skipNext;
6671066853
}
@@ -66742,23 +66885,28 @@
6674266885
assert( pX->pKey==0 );
6674366886
/* If this is an insert into a table b-tree, invalidate any incrblob
6674466887
** cursors open on the row being replaced */
6674566888
invalidateIncrblobCursors(p, pX->nKey, 0);
6674666889
66890
+ /* If BTREE_SAVEPOSITION is set, the cursor must already be pointing
66891
+ ** to a row with the same key as the new entry being inserted. */
66892
+ assert( (flags & BTREE_SAVEPOSITION)==0 ||
66893
+ ((pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey) );
66894
+
6674766895
/* If the cursor is currently on the last row and we are appending a
6674866896
** new row onto the end, set the "loc" to avoid an unnecessary
6674966897
** btreeMoveto() call */
6675066898
if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey ){
6675166899
loc = 0;
6675266900
}else if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey>0
6675366901
&& pCur->info.nKey==pX->nKey-1 ){
6675466902
loc = -1;
6675566903
}else if( loc==0 ){
66756
- rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, appendBias, &loc);
66904
+ rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, flags!=0, &loc);
6675766905
if( rc ) return rc;
6675866906
}
66759
- }else if( loc==0 ){
66907
+ }else if( loc==0 && (flags & BTREE_SAVEPOSITION)==0 ){
6676066908
if( pX->nMem ){
6676166909
UnpackedRecord r;
6676266910
r.pKeyInfo = pCur->pKeyInfo;
6676366911
r.aMem = pX->aMem;
6676466912
r.nField = pX->nMem;
@@ -66765,13 +66913,13 @@
6676566913
r.default_rc = 0;
6676666914
r.errCode = 0;
6676766915
r.r1 = 0;
6676866916
r.r2 = 0;
6676966917
r.eqSeen = 0;
66770
- rc = sqlite3BtreeMovetoUnpacked(pCur, &r, 0, appendBias, &loc);
66918
+ rc = sqlite3BtreeMovetoUnpacked(pCur, &r, 0, flags!=0, &loc);
6677166919
}else{
66772
- rc = btreeMoveto(pCur, pX->pKey, pX->nKey, appendBias, &loc);
66920
+ rc = btreeMoveto(pCur, pX->pKey, pX->nKey, flags!=0, &loc);
6677366921
}
6677466922
if( rc ) return rc;
6677566923
}
6677666924
assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );
6677766925
@@ -66855,10 +67003,24 @@
6685567003
** fails. Internal data structure corruption will result otherwise.
6685667004
** Also, set the cursor state to invalid. This stops saveCursorPosition()
6685767005
** from trying to save the current position of the cursor. */
6685867006
pCur->apPage[pCur->iPage]->nOverflow = 0;
6685967007
pCur->eState = CURSOR_INVALID;
67008
+ if( (flags & BTREE_SAVEPOSITION) && rc==SQLITE_OK ){
67009
+ rc = moveToRoot(pCur);
67010
+ if( pCur->pKeyInfo ){
67011
+ assert( pCur->pKey==0 );
67012
+ pCur->pKey = sqlite3Malloc( pX->nKey );
67013
+ if( pCur->pKey==0 ){
67014
+ rc = SQLITE_NOMEM;
67015
+ }else{
67016
+ memcpy(pCur->pKey, pX->pKey, pX->nKey);
67017
+ }
67018
+ }
67019
+ pCur->eState = CURSOR_REQUIRESEEK;
67020
+ pCur->nKey = pX->nKey;
67021
+ }
6686067022
}
6686167023
assert( pCur->apPage[pCur->iPage]->nOverflow==0 );
6686267024
6686367025
end_insert:
6686467026
return rc;
@@ -71765,11 +71927,11 @@
7176571927
sqlite3VdbeGetOp(p,addr)->p2 = val;
7176671928
}
7176771929
SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe *p, u32 addr, int val){
7176871930
sqlite3VdbeGetOp(p,addr)->p3 = val;
7176971931
}
71770
-SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe *p, u8 p5){
71932
+SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe *p, u16 p5){
7177171933
assert( p->nOp>0 || p->db->mallocFailed );
7177271934
if( p->nOp>0 ) p->aOp[p->nOp-1].p5 = p5;
7177371935
}
7177471936
7177571937
/*
@@ -73479,64 +73641,63 @@
7347973641
** statement transaction is committed.
7348073642
**
7348173643
** If an IO error occurs, an SQLITE_IOERR_XXX error code is returned.
7348273644
** Otherwise SQLITE_OK.
7348373645
*/
73484
-SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *p, int eOp){
73646
+static SQLITE_NOINLINE int vdbeCloseStatement(Vdbe *p, int eOp){
7348573647
sqlite3 *const db = p->db;
7348673648
int rc = SQLITE_OK;
73487
-
73488
- /* If p->iStatement is greater than zero, then this Vdbe opened a
73489
- ** statement transaction that should be closed here. The only exception
73490
- ** is that an IO error may have occurred, causing an emergency rollback.
73491
- ** In this case (db->nStatement==0), and there is nothing to do.
73492
- */
73493
- if( db->nStatement && p->iStatement ){
73494
- int i;
73495
- const int iSavepoint = p->iStatement-1;
73496
-
73497
- assert( eOp==SAVEPOINT_ROLLBACK || eOp==SAVEPOINT_RELEASE);
73498
- assert( db->nStatement>0 );
73499
- assert( p->iStatement==(db->nStatement+db->nSavepoint) );
73500
-
73501
- for(i=0; i<db->nDb; i++){
73502
- int rc2 = SQLITE_OK;
73503
- Btree *pBt = db->aDb[i].pBt;
73504
- if( pBt ){
73505
- if( eOp==SAVEPOINT_ROLLBACK ){
73506
- rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_ROLLBACK, iSavepoint);
73507
- }
73508
- if( rc2==SQLITE_OK ){
73509
- rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_RELEASE, iSavepoint);
73510
- }
73511
- if( rc==SQLITE_OK ){
73512
- rc = rc2;
73513
- }
73514
- }
73515
- }
73516
- db->nStatement--;
73517
- p->iStatement = 0;
73518
-
73519
- if( rc==SQLITE_OK ){
73520
- if( eOp==SAVEPOINT_ROLLBACK ){
73521
- rc = sqlite3VtabSavepoint(db, SAVEPOINT_ROLLBACK, iSavepoint);
73522
- }
73523
- if( rc==SQLITE_OK ){
73524
- rc = sqlite3VtabSavepoint(db, SAVEPOINT_RELEASE, iSavepoint);
73525
- }
73526
- }
73527
-
73528
- /* If the statement transaction is being rolled back, also restore the
73529
- ** database handles deferred constraint counter to the value it had when
73530
- ** the statement transaction was opened. */
73531
- if( eOp==SAVEPOINT_ROLLBACK ){
73532
- db->nDeferredCons = p->nStmtDefCons;
73533
- db->nDeferredImmCons = p->nStmtDefImmCons;
73534
- }
73535
- }
73536
- return rc;
73537
-}
73649
+ int i;
73650
+ const int iSavepoint = p->iStatement-1;
73651
+
73652
+ assert( eOp==SAVEPOINT_ROLLBACK || eOp==SAVEPOINT_RELEASE);
73653
+ assert( db->nStatement>0 );
73654
+ assert( p->iStatement==(db->nStatement+db->nSavepoint) );
73655
+
73656
+ for(i=0; i<db->nDb; i++){
73657
+ int rc2 = SQLITE_OK;
73658
+ Btree *pBt = db->aDb[i].pBt;
73659
+ if( pBt ){
73660
+ if( eOp==SAVEPOINT_ROLLBACK ){
73661
+ rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_ROLLBACK, iSavepoint);
73662
+ }
73663
+ if( rc2==SQLITE_OK ){
73664
+ rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_RELEASE, iSavepoint);
73665
+ }
73666
+ if( rc==SQLITE_OK ){
73667
+ rc = rc2;
73668
+ }
73669
+ }
73670
+ }
73671
+ db->nStatement--;
73672
+ p->iStatement = 0;
73673
+
73674
+ if( rc==SQLITE_OK ){
73675
+ if( eOp==SAVEPOINT_ROLLBACK ){
73676
+ rc = sqlite3VtabSavepoint(db, SAVEPOINT_ROLLBACK, iSavepoint);
73677
+ }
73678
+ if( rc==SQLITE_OK ){
73679
+ rc = sqlite3VtabSavepoint(db, SAVEPOINT_RELEASE, iSavepoint);
73680
+ }
73681
+ }
73682
+
73683
+ /* If the statement transaction is being rolled back, also restore the
73684
+ ** database handles deferred constraint counter to the value it had when
73685
+ ** the statement transaction was opened. */
73686
+ if( eOp==SAVEPOINT_ROLLBACK ){
73687
+ db->nDeferredCons = p->nStmtDefCons;
73688
+ db->nDeferredImmCons = p->nStmtDefImmCons;
73689
+ }
73690
+ return rc;
73691
+}
73692
+SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *p, int eOp){
73693
+ if( p->db->nStatement && p->iStatement ){
73694
+ return vdbeCloseStatement(p, eOp);
73695
+ }
73696
+ return SQLITE_OK;
73697
+}
73698
+
7353873699
7353973700
/*
7354073701
** This function is called when a transaction opened by the database
7354173702
** handle associated with the VM passed as an argument is about to be
7354273703
** committed. If there are outstanding deferred foreign key constraint
@@ -75567,14 +75728,14 @@
7556775728
** structure itself, using sqlite3DbFree().
7556875729
**
7556975730
** This function is used to free UnpackedRecord structures allocated by
7557075731
** the vdbeUnpackRecord() function found in vdbeapi.c.
7557175732
*/
75572
-static void vdbeFreeUnpacked(sqlite3 *db, UnpackedRecord *p){
75733
+static void vdbeFreeUnpacked(sqlite3 *db, int nField, UnpackedRecord *p){
7557375734
if( p ){
7557475735
int i;
75575
- for(i=0; i<p->nField; i++){
75736
+ for(i=0; i<nField; i++){
7557675737
Mem *pMem = &p->aMem[i];
7557775738
if( pMem->zMalloc ) sqlite3VdbeMemRelease(pMem);
7557875739
}
7557975740
sqlite3DbFree(db, p);
7558075741
}
@@ -75603,14 +75764,19 @@
7560375764
const char *zTbl = pTab->zName;
7560475765
static const u8 fakeSortOrder = 0;
7560575766
7560675767
assert( db->pPreUpdate==0 );
7560775768
memset(&preupdate, 0, sizeof(PreUpdate));
75608
- if( op==SQLITE_UPDATE ){
75609
- iKey2 = v->aMem[iReg].u.i;
75769
+ if( HasRowid(pTab)==0 ){
75770
+ iKey1 = iKey2 = 0;
75771
+ preupdate.pPk = sqlite3PrimaryKeyIndex(pTab);
7561075772
}else{
75611
- iKey2 = iKey1;
75773
+ if( op==SQLITE_UPDATE ){
75774
+ iKey2 = v->aMem[iReg].u.i;
75775
+ }else{
75776
+ iKey2 = iKey1;
75777
+ }
7561275778
}
7561375779
7561475780
assert( pCsr->nField==pTab->nCol
7561575781
|| (pCsr->nField==pTab->nCol+1 && op==SQLITE_DELETE && iReg==-1)
7561675782
);
@@ -75629,12 +75795,12 @@
7562975795
7563075796
db->pPreUpdate = &preupdate;
7563175797
db->xPreUpdateCallback(db->pPreUpdateArg, db, op, zDb, zTbl, iKey1, iKey2);
7563275798
db->pPreUpdate = 0;
7563375799
sqlite3DbFree(db, preupdate.aRecord);
75634
- vdbeFreeUnpacked(db, preupdate.pUnpacked);
75635
- vdbeFreeUnpacked(db, preupdate.pNewUnpacked);
75800
+ vdbeFreeUnpacked(db, preupdate.keyinfo.nField+1, preupdate.pUnpacked);
75801
+ vdbeFreeUnpacked(db, preupdate.keyinfo.nField+1, preupdate.pNewUnpacked);
7563675802
if( preupdate.aNew ){
7563775803
int i;
7563875804
for(i=0; i<pCsr->nField; i++){
7563975805
sqlite3VdbeMemRelease(&preupdate.aNew[i]);
7564075806
}
@@ -77305,18 +77471,22 @@
7730577471
** This function is called from within a pre-update callback to retrieve
7730677472
** a field of the row currently being updated or deleted.
7730777473
*/
7730877474
SQLITE_API int sqlite3_preupdate_old(sqlite3 *db, int iIdx, sqlite3_value **ppValue){
7730977475
PreUpdate *p = db->pPreUpdate;
77476
+ Mem *pMem;
7731077477
int rc = SQLITE_OK;
7731177478
7731277479
/* Test that this call is being made from within an SQLITE_DELETE or
7731377480
** SQLITE_UPDATE pre-update callback, and that iIdx is within range. */
7731477481
if( !p || p->op==SQLITE_INSERT ){
7731577482
rc = SQLITE_MISUSE_BKPT;
7731677483
goto preupdate_old_out;
7731777484
}
77485
+ if( p->pPk ){
77486
+ iIdx = sqlite3ColumnOfIndex(p->pPk, iIdx);
77487
+ }
7731877488
if( iIdx>=p->pCsr->nField || iIdx<0 ){
7731977489
rc = SQLITE_RANGE;
7732077490
goto preupdate_old_out;
7732177491
}
7732277492
@@ -77338,21 +77508,18 @@
7733877508
goto preupdate_old_out;
7733977509
}
7734077510
p->aRecord = aRec;
7734177511
}
7734277512
77343
- if( iIdx>=p->pUnpacked->nField ){
77513
+ pMem = *ppValue = &p->pUnpacked->aMem[iIdx];
77514
+ if( iIdx==p->pTab->iPKey ){
77515
+ sqlite3VdbeMemSetInt64(pMem, p->iKey1);
77516
+ }else if( iIdx>=p->pUnpacked->nField ){
7734477517
*ppValue = (sqlite3_value *)columnNullValue();
77345
- }else{
77346
- Mem *pMem = *ppValue = &p->pUnpacked->aMem[iIdx];
77347
- *ppValue = &p->pUnpacked->aMem[iIdx];
77348
- if( iIdx==p->pTab->iPKey ){
77349
- sqlite3VdbeMemSetInt64(pMem, p->iKey1);
77350
- }else if( p->pTab->aCol[iIdx].affinity==SQLITE_AFF_REAL ){
77351
- if( pMem->flags & MEM_Int ){
77352
- sqlite3VdbeMemRealify(pMem);
77353
- }
77518
+ }else if( p->pTab->aCol[iIdx].affinity==SQLITE_AFF_REAL ){
77519
+ if( pMem->flags & MEM_Int ){
77520
+ sqlite3VdbeMemRealify(pMem);
7735477521
}
7735577522
}
7735677523
7735777524
preupdate_old_out:
7735877525
sqlite3Error(db, rc);
@@ -77401,10 +77568,13 @@
7740177568
7740277569
if( !p || p->op==SQLITE_DELETE ){
7740377570
rc = SQLITE_MISUSE_BKPT;
7740477571
goto preupdate_new_out;
7740577572
}
77573
+ if( p->pPk && p->op!=SQLITE_UPDATE ){
77574
+ iIdx = sqlite3ColumnOfIndex(p->pPk, iIdx);
77575
+ }
7740677576
if( iIdx>=p->pCsr->nField || iIdx<0 ){
7740777577
rc = SQLITE_RANGE;
7740877578
goto preupdate_new_out;
7740977579
}
7741077580
@@ -77421,17 +77591,15 @@
7742177591
rc = SQLITE_NOMEM;
7742277592
goto preupdate_new_out;
7742377593
}
7742477594
p->pNewUnpacked = pUnpack;
7742577595
}
77426
- if( iIdx>=pUnpack->nField ){
77596
+ pMem = &pUnpack->aMem[iIdx];
77597
+ if( iIdx==p->pTab->iPKey ){
77598
+ sqlite3VdbeMemSetInt64(pMem, p->iKey2);
77599
+ }else if( iIdx>=pUnpack->nField ){
7742777600
pMem = (sqlite3_value *)columnNullValue();
77428
- }else{
77429
- pMem = &pUnpack->aMem[iIdx];
77430
- if( iIdx==p->pTab->iPKey ){
77431
- sqlite3VdbeMemSetInt64(pMem, p->iKey2);
77432
- }
7743377601
}
7743477602
}else{
7743577603
/* For an UPDATE, memory cell (p->iNewReg+1+iIdx) contains the required
7743677604
** value. Make a copy of the cell contents and return a pointer to it.
7743777605
** It is not safe to return a pointer to the memory cell itself as the
@@ -78404,12 +78572,10 @@
7840478572
Mem *aMem = p->aMem; /* Copy of p->aMem */
7840578573
Mem *pIn1 = 0; /* 1st input operand */
7840678574
Mem *pIn2 = 0; /* 2nd input operand */
7840778575
Mem *pIn3 = 0; /* 3rd input operand */
7840878576
Mem *pOut = 0; /* Output operand */
78409
- int *aPermute = 0; /* Permutation of columns for OP_Compare */
78410
- i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
7841178577
#ifdef VDBE_PROFILE
7841278578
u64 start; /* CPU clock count at start of opcode */
7841378579
#endif
7841478580
/*** INSERT STACK UNION HERE ***/
7841578581
@@ -78420,11 +78586,10 @@
7842078586
** sqlite3_column_text16() failed. */
7842178587
goto no_mem;
7842278588
}
7842378589
assert( p->rc==SQLITE_OK || (p->rc&0xff)==SQLITE_BUSY );
7842478590
assert( p->bIsReader || p->readOnly!=0 );
78425
- p->rc = SQLITE_OK;
7842678591
p->iCurrentTime = 0;
7842778592
assert( p->explain==0 );
7842878593
p->pResultSet = 0;
7842978594
db->busyHandler.nBusy = 0;
7843078595
if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
@@ -78781,11 +78946,10 @@
7878178946
pFrame = p->pFrame;
7878278947
p->pFrame = pFrame->pParent;
7878378948
p->nFrame--;
7878478949
sqlite3VdbeSetChanges(db, p->nChange);
7878578950
pcx = sqlite3VdbeFrameRestore(pFrame);
78786
- lastRowid = db->lastRowid;
7878778951
if( pOp->p2==OE_Ignore ){
7878878952
/* Instruction pcx is the OP_Program that invoked the sub-program
7878978953
** currently being halted. If the p2 instruction of this OP_Halt
7879078954
** instruction is set to OE_Ignore, then the sub-program is throwing
7879178955
** an IGNORE exception. In this case jump to the address specified
@@ -79016,11 +79180,11 @@
7901679180
assert( pOp->p4.z==0 || pOp->p4.z==sqlite3VListNumToName(p->pVList,pOp->p1) );
7901779181
pVar = &p->aVar[pOp->p1 - 1];
7901879182
if( sqlite3VdbeMemTooBig(pVar) ){
7901979183
goto too_big;
7902079184
}
79021
- pOut = out2Prerelease(p, pOp);
79185
+ pOut = &aMem[pOp->p2];
7902279186
sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static);
7902379187
UPDATE_MAX_BLOBSIZE(pOut);
7902479188
break;
7902579189
}
7902679190
@@ -79503,13 +79667,11 @@
7950379667
REGISTER_TRACE(pOp->p2+i, pCtx->argv[i]);
7950479668
}
7950579669
#endif
7950679670
MemSetTypeFlag(pCtx->pOut, MEM_Null);
7950779671
pCtx->fErrorOrAux = 0;
79508
- db->lastRowid = lastRowid;
7950979672
(*pCtx->pFunc->xSFunc)(pCtx, pCtx->argc, pCtx->argv);/* IMP: R-24505-23230 */
79510
- lastRowid = db->lastRowid; /* Remember rowid changes made by xSFunc */
7951179673
7951279674
/* If the function returned an error, throw an exception */
7951379675
if( pCtx->fErrorOrAux ){
7951479676
if( pCtx->isError ){
7951579677
sqlite3VdbeError(p, "%s", sqlite3_value_text(pCtx->pOut));
@@ -79961,12 +80123,12 @@
7996180123
}
7996280124
7996380125
7996480126
/* Opcode: Permutation * * * P4 *
7996580127
**
79966
-** Set the permutation used by the OP_Compare operator to be the array
79967
-** of integers in P4.
80128
+** Set the permutation used by the OP_Compare operator in the next
80129
+** instruction. The permutation is stored in the P4 operand.
7996880130
**
7996980131
** The permutation is only valid until the next OP_Compare that has
7997080132
** the OPFLAG_PERMUTE bit set in P5. Typically the OP_Permutation should
7997180133
** occur immediately prior to the OP_Compare.
7997280134
**
@@ -79974,11 +80136,12 @@
7997480136
** and does not become part of the permutation.
7997580137
*/
7997680138
case OP_Permutation: {
7997780139
assert( pOp->p4type==P4_INTARRAY );
7997880140
assert( pOp->p4.ai );
79979
- aPermute = pOp->p4.ai + 1;
80141
+ assert( pOp[1].opcode==OP_Compare );
80142
+ assert( pOp[1].p5 & OPFLAG_PERMUTE );
7998080143
break;
7998180144
}
7998280145
7998380146
/* Opcode: Compare P1 P2 P3 P4 P5
7998480147
** Synopsis: r[P1@P3] <-> r[P2@P3]
@@ -80007,12 +80170,21 @@
8000780170
int p2;
8000880171
const KeyInfo *pKeyInfo;
8000980172
int idx;
8001080173
CollSeq *pColl; /* Collating sequence to use on this term */
8001180174
int bRev; /* True for DESCENDING sort order */
80175
+ int *aPermute; /* The permutation */
8001280176
80013
- if( (pOp->p5 & OPFLAG_PERMUTE)==0 ) aPermute = 0;
80177
+ if( (pOp->p5 & OPFLAG_PERMUTE)==0 ){
80178
+ aPermute = 0;
80179
+ }else{
80180
+ assert( pOp>aOp );
80181
+ assert( pOp[-1].opcode==OP_Permutation );
80182
+ assert( pOp[-1].p4type==P4_INTARRAY );
80183
+ aPermute = pOp[-1].p4.ai + 1;
80184
+ assert( aPermute!=0 );
80185
+ }
8001480186
n = pOp->p3;
8001580187
pKeyInfo = pOp->p4.pKeyInfo;
8001680188
assert( n>0 );
8001780189
assert( pKeyInfo!=0 );
8001880190
p1 = pOp->p1;
@@ -80041,11 +80213,10 @@
8004180213
if( iCompare ){
8004280214
if( bRev ) iCompare = -iCompare;
8004380215
break;
8004480216
}
8004580217
}
80046
- aPermute = 0;
8004780218
break;
8004880219
}
8004980220
8005080221
/* Opcode: Jump P1 P2 P3 * *
8005180222
**
@@ -80597,10 +80768,24 @@
8059780768
do{
8059880769
applyAffinity(pRec++, *(zAffinity++), encoding);
8059980770
assert( zAffinity[0]==0 || pRec<=pLast );
8060080771
}while( zAffinity[0] );
8060180772
}
80773
+
80774
+#ifdef SQLITE_ENABLE_NULL_TRIM
80775
+ /* NULLs can be safely trimmed from the end of the record, as long as
80776
+ ** as the schema format is 2 or more and none of the omitted columns
80777
+ ** have a non-NULL default value. Also, the record must be left with
80778
+ ** at least one field. If P5>0 then it will be one more than the
80779
+ ** index of the right-most column with a non-NULL default value */
80780
+ if( pOp->p5 ){
80781
+ while( (pLast->flags & MEM_Null)!=0 && nField>pOp->p5 ){
80782
+ pLast--;
80783
+ nField--;
80784
+ }
80785
+ }
80786
+#endif
8060280787
8060380788
/* Loop through the elements that will make up the record to figure
8060480789
** out how much space is required for the new record.
8060580790
*/
8060680791
pRec = pLast;
@@ -82187,11 +82372,11 @@
8218782372
assert( memIsValid(pData) );
8218882373
pC = p->apCsr[pOp->p1];
8218982374
assert( pC!=0 );
8219082375
assert( pC->eCurType==CURTYPE_BTREE );
8219182376
assert( pC->uc.pCursor!=0 );
82192
- assert( pC->isTable );
82377
+ assert( (pOp->p5 & OPFLAG_ISNOOP) || pC->isTable );
8219382378
assert( pOp->p4type==P4_TABLE || pOp->p4type>=P4_STATIC );
8219482379
REGISTER_TRACE(pOp->p2, pData);
8219582380
8219682381
if( pOp->opcode==OP_Insert ){
8219782382
pKey = &aMem[pOp->p3];
@@ -82203,18 +82388,17 @@
8220382388
assert( pOp->opcode==OP_InsertInt );
8220482389
x.nKey = pOp->p3;
8220582390
}
8220682391
8220782392
if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
82208
- assert( pC->isTable );
8220982393
assert( pC->iDb>=0 );
8221082394
zDb = db->aDb[pC->iDb].zDbSName;
8221182395
pTab = pOp->p4.pTab;
82212
- assert( HasRowid(pTab) );
82396
+ assert( (pOp->p5 & OPFLAG_ISNOOP) || HasRowid(pTab) );
8221382397
op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT);
8221482398
}else{
82215
- pTab = 0; /* Not needed. Silence a comiler warning. */
82399
+ pTab = 0; /* Not needed. Silence a compiler warning. */
8221682400
zDb = 0; /* Not needed. Silence a compiler warning. */
8221782401
}
8221882402
8221982403
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
8222082404
/* Invoke the pre-update hook, if any */
@@ -82222,14 +82406,15 @@
8222282406
&& pOp->p4type==P4_TABLE
8222382407
&& !(pOp->p5 & OPFLAG_ISUPDATE)
8222482408
){
8222582409
sqlite3VdbePreUpdateHook(p, pC, SQLITE_INSERT, zDb, pTab, x.nKey, pOp->p2);
8222682410
}
82411
+ if( pOp->p5 & OPFLAG_ISNOOP ) break;
8222782412
#endif
8222882413
8222982414
if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
82230
- if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = x.nKey;
82415
+ if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = x.nKey;
8223182416
if( pData->flags & MEM_Null ){
8223282417
x.pData = 0;
8223382418
x.nData = 0;
8223482419
}else{
8223582420
assert( pData->flags & (MEM_Blob|MEM_Str) );
@@ -82242,11 +82427,11 @@
8224282427
}else{
8224382428
x.nZero = 0;
8224482429
}
8224582430
x.pKey = 0;
8224682431
rc = sqlite3BtreeInsert(pC->uc.pCursor, &x,
82247
- (pOp->p5 & OPFLAG_APPEND)!=0, seekResult
82432
+ (pOp->p5 & (OPFLAG_APPEND|OPFLAG_SAVEPOSITION)), seekResult
8224882433
);
8224982434
pC->deferredMoveto = 0;
8225082435
pC->cacheStatus = CACHE_STALE;
8225182436
8225282437
/* Invoke the update-hook if required. */
@@ -82334,12 +82519,15 @@
8233482519
pTab = 0; /* Not needed. Silence a compiler warning. */
8233582520
}
8233682521
8233782522
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
8233882523
/* Invoke the pre-update-hook if required. */
82339
- if( db->xPreUpdateCallback && pOp->p4.pTab && HasRowid(pTab) ){
82340
- assert( !(opflags & OPFLAG_ISUPDATE) || (aMem[pOp->p3].flags & MEM_Int) );
82524
+ if( db->xPreUpdateCallback && pOp->p4.pTab ){
82525
+ assert( !(opflags & OPFLAG_ISUPDATE)
82526
+ || HasRowid(pTab)==0
82527
+ || (aMem[pOp->p3].flags & MEM_Int)
82528
+ );
8234182529
sqlite3VdbePreUpdateHook(p, pC,
8234282530
(opflags & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_DELETE,
8234382531
zDb, pTab, pC->movetoTarget,
8234482532
pOp->p3
8234582533
);
@@ -82453,11 +82641,11 @@
8245382641
if( rc ) goto abort_due_to_error;
8245482642
p->apCsr[pOp->p3]->cacheStatus = CACHE_STALE;
8245582643
break;
8245682644
}
8245782645
82458
-/* Opcode: RowData P1 P2 * * *
82646
+/* Opcode: RowData P1 P2 P3 * *
8245982647
** Synopsis: r[P2]=data
8246082648
**
8246182649
** Write into register P2 the complete row content for the row at
8246282650
** which cursor P1 is currently pointing.
8246382651
** There is no interpretation of the data.
@@ -82467,18 +82655,30 @@
8246782655
** If cursor P1 is an index, then the content is the key of the row.
8246882656
** If cursor P2 is a table, then the content extracted is the data.
8246982657
**
8247082658
** If the P1 cursor must be pointing to a valid row (not a NULL row)
8247182659
** of a real table, not a pseudo-table.
82660
+**
82661
+** If P3!=0 then this opcode is allowed to make an ephermeral pointer
82662
+** into the database page. That means that the content of the output
82663
+** register will be invalidated as soon as the cursor moves - including
82664
+** moves caused by other cursors that "save" the the current cursors
82665
+** position in order that they can write to the same table. If P3==0
82666
+** then a copy of the data is made into memory. P3!=0 is faster, but
82667
+** P3==0 is safer.
82668
+**
82669
+** If P3!=0 then the content of the P2 register is unsuitable for use
82670
+** in OP_Result and any OP_Result will invalidate the P2 register content.
82671
+** The P2 register content is invalidated by opcodes like OP_Function or
82672
+** by any use of another cursor pointing to the same table.
8247282673
*/
8247382674
case OP_RowData: {
8247482675
VdbeCursor *pC;
8247582676
BtCursor *pCrsr;
8247682677
u32 n;
8247782678
82478
- pOut = &aMem[pOp->p2];
82479
- memAboutToChange(p, pOut);
82679
+ pOut = out2Prerelease(p, pOp);
8248082680
8248182681
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
8248282682
pC = p->apCsr[pOp->p1];
8248382683
assert( pC!=0 );
8248482684
assert( pC->eCurType==CURTYPE_BTREE );
@@ -82505,18 +82705,13 @@
8250582705
n = sqlite3BtreePayloadSize(pCrsr);
8250682706
if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
8250782707
goto too_big;
8250882708
}
8250982709
testcase( n==0 );
82510
- if( sqlite3VdbeMemClearAndResize(pOut, MAX(n,32)) ){
82511
- goto no_mem;
82512
- }
82513
- pOut->n = n;
82514
- MemSetTypeFlag(pOut, MEM_Blob);
82515
- rc = sqlite3BtreePayload(pCrsr, 0, n, pOut->z);
82710
+ rc = sqlite3VdbeMemFromBtree(pCrsr, 0, n, pOut);
8251682711
if( rc ) goto abort_due_to_error;
82517
- pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */
82712
+ if( !pOp->p3 ) Deephemeralize(pOut);
8251882713
UPDATE_MAX_BLOBSIZE(pOut);
8251982714
REGISTER_TRACE(pOp->p2, pOut);
8252082715
break;
8252182716
}
8252282717
@@ -82900,11 +83095,11 @@
8290083095
x.nKey = pIn2->n;
8290183096
x.pKey = pIn2->z;
8290283097
x.aMem = aMem + pOp->p3;
8290383098
x.nMem = (u16)pOp->p4.i;
8290483099
rc = sqlite3BtreeInsert(pC->uc.pCursor, &x,
82905
- (pOp->p5 & OPFLAG_APPEND)!=0,
83100
+ (pOp->p5 & (OPFLAG_APPEND|OPFLAG_SAVEPOSITION)),
8290683101
((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0)
8290783102
);
8290883103
assert( pC->deferredMoveto==0 );
8290983104
pC->cacheStatus = CACHE_STALE;
8291083105
}
@@ -83022,11 +83217,10 @@
8302283217
pTabCur->aAltMap = pOp->p4.ai;
8302383218
pTabCur->pAltCursor = pC;
8302483219
}else{
8302583220
pOut = out2Prerelease(p, pOp);
8302683221
pOut->u.i = rowid;
83027
- pOut->flags = MEM_Int;
8302883222
}
8302983223
}else{
8303083224
assert( pOp->opcode==OP_IdxRowid );
8303183225
sqlite3VdbeMemSetNull(&aMem[pOp->p2]);
8303283226
}
@@ -83664,11 +83858,11 @@
8366483858
assert( (int)(pOp - aOp)==pFrame->pc );
8366583859
}
8366683860
8366783861
p->nFrame++;
8366883862
pFrame->pParent = p->pFrame;
83669
- pFrame->lastRowid = lastRowid;
83863
+ pFrame->lastRowid = db->lastRowid;
8367083864
pFrame->nChange = p->nChange;
8367183865
pFrame->nDbChange = p->db->nChange;
8367283866
assert( pFrame->pAuxData==0 );
8367383867
pFrame->pAuxData = p->pAuxData;
8367483868
p->pAuxData = 0;
@@ -84605,11 +84799,11 @@
8460584799
rc = pModule->xUpdate(pVtab, nArg, apArg, &rowid);
8460684800
db->vtabOnConflict = vtabOnConflict;
8460784801
sqlite3VtabImportErrmsg(p, pVtab);
8460884802
if( rc==SQLITE_OK && pOp->p1 ){
8460984803
assert( nArg>1 && apArg[0] && (apArg[0]->flags&MEM_Null) );
84610
- db->lastRowid = lastRowid = rowid;
84804
+ db->lastRowid = rowid;
8461184805
}
8461284806
if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){
8461384807
if( pOp->p5==OE_Ignore ){
8461484808
rc = SQLITE_OK;
8461584809
}else{
@@ -84841,11 +85035,10 @@
8484185035
8484285036
/* This is the only way out of this procedure. We have to
8484385037
** release the mutexes on btrees that were acquired at the
8484485038
** top. */
8484585039
vdbe_return:
84846
- db->lastRowid = lastRowid;
8484785040
testcase( nVmStep>0 );
8484885041
p->aCounter[SQLITE_STMTSTATUS_VM_STEP] += (int)nVmStep;
8484985042
sqlite3VdbeLeave(p);
8485085043
assert( rc!=SQLITE_OK || nExtraDelete==0
8485185044
|| sqlite3_strlike("DELETE%",p->zSql,0)!=0
@@ -84905,14 +85098,13 @@
8490585098
/*
8490685099
** Valid sqlite3_blob* handles point to Incrblob structures.
8490785100
*/
8490885101
typedef struct Incrblob Incrblob;
8490985102
struct Incrblob {
84910
- int flags; /* Copy of "flags" passed to sqlite3_blob_open() */
8491185103
int nByte; /* Size of open blob, in bytes */
8491285104
int iOffset; /* Byte offset of blob in cursor data */
84913
- int iCol; /* Table column this handle is open on */
85105
+ u16 iCol; /* Table column this handle is open on */
8491485106
BtCursor *pCsr; /* Cursor pointing at blob row */
8491585107
sqlite3_stmt *pStmt; /* Statement holding cursor open */
8491685108
sqlite3 *db; /* The associated database */
8491785109
char *zDb; /* Database name */
8491885110
Table *pTab; /* Table object */
@@ -84939,21 +85131,31 @@
8493985131
static int blobSeekToRow(Incrblob *p, sqlite3_int64 iRow, char **pzErr){
8494085132
int rc; /* Error code */
8494185133
char *zErr = 0; /* Error message */
8494285134
Vdbe *v = (Vdbe *)p->pStmt;
8494385135
84944
- /* Set the value of the SQL statements only variable to integer iRow.
84945
- ** This is done directly instead of using sqlite3_bind_int64() to avoid
84946
- ** triggering asserts related to mutexes.
85136
+ /* Set the value of register r[1] in the SQL statement to integer iRow.
85137
+ ** This is done directly as a performance optimization
8494785138
*/
84948
- assert( v->aVar[0].flags&MEM_Int );
84949
- v->aVar[0].u.i = iRow;
85139
+ v->aMem[1].flags = MEM_Int;
85140
+ v->aMem[1].u.i = iRow;
8495085141
84951
- rc = sqlite3_step(p->pStmt);
85142
+ /* If the statement has been run before (and is paused at the OP_ResultRow)
85143
+ ** then back it up to the point where it does the OP_SeekRowid. This could
85144
+ ** have been down with an extra OP_Goto, but simply setting the program
85145
+ ** counter is faster. */
85146
+ if( v->pc>3 ){
85147
+ v->pc = 3;
85148
+ rc = sqlite3VdbeExec(v);
85149
+ }else{
85150
+ rc = sqlite3_step(p->pStmt);
85151
+ }
8495285152
if( rc==SQLITE_ROW ){
8495385153
VdbeCursor *pC = v->apCsr[0];
84954
- u32 type = pC->aType[p->iCol];
85154
+ u32 type = pC->nHdrParsed>p->iCol ? pC->aType[p->iCol] : 0;
85155
+ testcase( pC->nHdrParsed==p->iCol );
85156
+ testcase( pC->nHdrParsed==p->iCol+1 );
8495585157
if( type<12 ){
8495685158
zErr = sqlite3MPrintf(p->db, "cannot open value of type %s",
8495785159
type==0?"null": type==7?"real": "integer"
8495885160
);
8495985161
rc = SQLITE_ERROR;
@@ -84994,11 +85196,11 @@
8499485196
sqlite3* db, /* The database connection */
8499585197
const char *zDb, /* The attached database containing the blob */
8499685198
const char *zTable, /* The table containing the blob */
8499785199
const char *zColumn, /* The column containing the blob */
8499885200
sqlite_int64 iRow, /* The row containing the glob */
84999
- int flags, /* True -> read/write access, false -> read-only */
85201
+ int wrFlag, /* True -> read/write access, false -> read-only */
8500085202
sqlite3_blob **ppBlob /* Handle for accessing the blob returned here */
8500185203
){
8500285204
int nAttempt = 0;
8500385205
int iCol; /* Index of zColumn in row-record */
8500485206
int rc = SQLITE_OK;
@@ -85016,11 +85218,11 @@
8501685218
#ifdef SQLITE_ENABLE_API_ARMOR
8501785219
if( !sqlite3SafetyCheckOk(db) || zTable==0 ){
8501885220
return SQLITE_MISUSE_BKPT;
8501985221
}
8502085222
#endif
85021
- flags = !!flags; /* flags = (flags ? 1 : 0); */
85223
+ wrFlag = !!wrFlag; /* wrFlag = (wrFlag ? 1 : 0); */
8502285224
8502385225
sqlite3_mutex_enter(db->mutex);
8502485226
8502585227
pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
8502685228
if( !pBlob ) goto blob_open_out;
@@ -85076,13 +85278,12 @@
8507685278
goto blob_open_out;
8507785279
}
8507885280
8507985281
/* If the value is being opened for writing, check that the
8508085282
** column is not indexed, and that it is not part of a foreign key.
85081
- ** It is against the rules to open a column to which either of these
85082
- ** descriptions applies for writing. */
85083
- if( flags ){
85283
+ */
85284
+ if( wrFlag ){
8508485285
const char *zFault = 0;
8508585286
Index *pIdx;
8508685287
#ifndef SQLITE_OMIT_FOREIGN_KEY
8508785288
if( db->flags&SQLITE_ForeignKeys ){
8508885289
/* Check that the column is not part of an FK child key definition. It
@@ -85139,22 +85340,21 @@
8513985340
*/
8514085341
static const int iLn = VDBE_OFFSET_LINENO(2);
8514185342
static const VdbeOpList openBlob[] = {
8514285343
{OP_TableLock, 0, 0, 0}, /* 0: Acquire a read or write lock */
8514385344
{OP_OpenRead, 0, 0, 0}, /* 1: Open a cursor */
85144
- {OP_Variable, 1, 1, 0}, /* 2: Move ?1 into reg[1] */
85145
- {OP_NotExists, 0, 7, 1}, /* 3: Seek the cursor */
85146
- {OP_Column, 0, 0, 1}, /* 4 */
85147
- {OP_ResultRow, 1, 0, 0}, /* 5 */
85148
- {OP_Goto, 0, 2, 0}, /* 6 */
85149
- {OP_Halt, 0, 0, 0}, /* 7 */
85345
+ /* blobSeekToRow() will initialize r[1] to the desired rowid */
85346
+ {OP_NotExists, 0, 5, 1}, /* 2: Seek the cursor to rowid=r[1] */
85347
+ {OP_Column, 0, 0, 1}, /* 3 */
85348
+ {OP_ResultRow, 1, 0, 0}, /* 4 */
85349
+ {OP_Halt, 0, 0, 0}, /* 5 */
8515085350
};
8515185351
Vdbe *v = (Vdbe *)pBlob->pStmt;
8515285352
int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
8515385353
VdbeOp *aOp;
8515485354
85155
- sqlite3VdbeAddOp4Int(v, OP_Transaction, iDb, flags,
85355
+ sqlite3VdbeAddOp4Int(v, OP_Transaction, iDb, wrFlag,
8515685356
pTab->pSchema->schema_cookie,
8515785357
pTab->pSchema->iGeneration);
8515885358
sqlite3VdbeChangeP5(v, 1);
8515985359
aOp = sqlite3VdbeAddOpList(v, ArraySize(openBlob), openBlob, iLn);
8516085360
@@ -85167,19 +85367,19 @@
8516785367
#ifdef SQLITE_OMIT_SHARED_CACHE
8516885368
aOp[0].opcode = OP_Noop;
8516985369
#else
8517085370
aOp[0].p1 = iDb;
8517185371
aOp[0].p2 = pTab->tnum;
85172
- aOp[0].p3 = flags;
85372
+ aOp[0].p3 = wrFlag;
8517385373
sqlite3VdbeChangeP4(v, 1, pTab->zName, P4_TRANSIENT);
8517485374
}
8517585375
if( db->mallocFailed==0 ){
8517685376
#endif
8517785377
8517885378
/* Remove either the OP_OpenWrite or OpenRead. Set the P2
8517985379
** parameter of the other to pTab->tnum. */
85180
- if( flags ) aOp[1].opcode = OP_OpenWrite;
85380
+ if( wrFlag ) aOp[1].opcode = OP_OpenWrite;
8518185381
aOp[1].p2 = pTab->tnum;
8518285382
aOp[1].p3 = iDb;
8518385383
8518485384
/* Configure the number of columns. Configure the cursor to
8518585385
** think that the table has one more column than it really
@@ -85188,27 +85388,25 @@
8518885388
** we can invoke OP_Column to fill in the vdbe cursors type
8518985389
** and offset cache without causing any IO.
8519085390
*/
8519185391
aOp[1].p4type = P4_INT32;
8519285392
aOp[1].p4.i = pTab->nCol+1;
85193
- aOp[4].p2 = pTab->nCol;
85393
+ aOp[3].p2 = pTab->nCol;
8519485394
85195
- pParse->nVar = 1;
85395
+ pParse->nVar = 0;
8519685396
pParse->nMem = 1;
8519785397
pParse->nTab = 1;
8519885398
sqlite3VdbeMakeReady(v, pParse);
8519985399
}
8520085400
}
8520185401
85202
- pBlob->flags = flags;
8520385402
pBlob->iCol = iCol;
8520485403
pBlob->db = db;
8520585404
sqlite3BtreeLeaveAll(db);
8520685405
if( db->mallocFailed ){
8520785406
goto blob_open_out;
8520885407
}
85209
- sqlite3_bind_int64(pBlob->pStmt, 1, iRow);
8521085408
rc = blobSeekToRow(pBlob, iRow, &zErr);
8521185409
} while( (++nAttempt)<SQLITE_MAX_SCHEMA_RETRY && rc==SQLITE_SCHEMA );
8521285410
8521385411
blob_open_out:
8521485412
if( rc==SQLITE_OK && db->mallocFailed==0 ){
@@ -88741,12 +88939,10 @@
8874188939
** This file contains routines used for walking the parser tree and
8874288940
** resolve all identifiers by associating them with a particular
8874388941
** table and column.
8874488942
*/
8874588943
/* #include "sqliteInt.h" */
88746
-/* #include <stdlib.h> */
88747
-/* #include <string.h> */
8874888944
8874988945
/*
8875088946
** Walk the expression tree pExpr and increase the aggregate function
8875188947
** depth (the Expr.op2 field) by N on every TK_AGG_FUNCTION node.
8875288948
** This needs to occur when copying a TK_AGG_FUNCTION node from an
@@ -90501,11 +90697,11 @@
9050190697
aff = sqlite3ExprAffinity(pExpr->pLeft);
9050290698
if( pExpr->pRight ){
9050390699
aff = sqlite3CompareAffinity(pExpr->pRight, aff);
9050490700
}else if( ExprHasProperty(pExpr, EP_xIsSelect) ){
9050590701
aff = sqlite3CompareAffinity(pExpr->x.pSelect->pEList->a[0].pExpr, aff);
90506
- }else if( NEVER(aff==0) ){
90702
+ }else if( aff==0 ){
9050790703
aff = SQLITE_AFF_BLOB;
9050890704
}
9050990705
return aff;
9051090706
}
9051190707
@@ -91237,21 +91433,27 @@
9123791433
int doAdd = 0;
9123891434
if( z[0]=='?' ){
9123991435
/* Wildcard of the form "?nnn". Convert "nnn" to an integer and
9124091436
** use it as the variable number */
9124191437
i64 i;
91242
- int bOk = 0==sqlite3Atoi64(&z[1], &i, n-1, SQLITE_UTF8);
91243
- x = (ynVar)i;
91438
+ int bOk;
91439
+ if( n==2 ){ /*OPTIMIZATION-IF-TRUE*/
91440
+ i = z[1]-'0'; /* The common case of ?N for a single digit N */
91441
+ bOk = 1;
91442
+ }else{
91443
+ bOk = 0==sqlite3Atoi64(&z[1], &i, n-1, SQLITE_UTF8);
91444
+ }
9124491445
testcase( i==0 );
9124591446
testcase( i==1 );
9124691447
testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 );
9124791448
testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] );
9124891449
if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
9124991450
sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d",
9125091451
db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]);
9125191452
return;
9125291453
}
91454
+ x = (ynVar)i;
9125391455
if( x>pParse->nVar ){
9125491456
pParse->nVar = (int)x;
9125591457
doAdd = 1;
9125691458
}else if( sqlite3VListNumToName(pParse->pVList, x)==0 ){
9125791459
doAdd = 1;
@@ -91682,37 +91884,45 @@
9168291884
pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
9168391885
pNewItem->idx = pOldItem->idx;
9168491886
}
9168591887
return pNew;
9168691888
}
91687
-SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
91688
- Select *pNew, *pPrior;
91889
+SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *pDup, int flags){
91890
+ Select *pRet = 0;
91891
+ Select *pNext = 0;
91892
+ Select **pp = &pRet;
91893
+ Select *p;
91894
+
9168991895
assert( db!=0 );
91690
- if( p==0 ) return 0;
91691
- pNew = sqlite3DbMallocRawNN(db, sizeof(*p) );
91692
- if( pNew==0 ) return 0;
91693
- pNew->pEList = sqlite3ExprListDup(db, p->pEList, flags);
91694
- pNew->pSrc = sqlite3SrcListDup(db, p->pSrc, flags);
91695
- pNew->pWhere = sqlite3ExprDup(db, p->pWhere, flags);
91696
- pNew->pGroupBy = sqlite3ExprListDup(db, p->pGroupBy, flags);
91697
- pNew->pHaving = sqlite3ExprDup(db, p->pHaving, flags);
91698
- pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, flags);
91699
- pNew->op = p->op;
91700
- pNew->pPrior = pPrior = sqlite3SelectDup(db, p->pPrior, flags);
91701
- if( pPrior ) pPrior->pNext = pNew;
91702
- pNew->pNext = 0;
91703
- pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags);
91704
- pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags);
91705
- pNew->iLimit = 0;
91706
- pNew->iOffset = 0;
91707
- pNew->selFlags = p->selFlags & ~SF_UsesEphemeral;
91708
- pNew->addrOpenEphm[0] = -1;
91709
- pNew->addrOpenEphm[1] = -1;
91710
- pNew->nSelectRow = p->nSelectRow;
91711
- pNew->pWith = withDup(db, p->pWith);
91712
- sqlite3SelectSetName(pNew, p->zSelName);
91713
- return pNew;
91896
+ for(p=pDup; p; p=p->pPrior){
91897
+ Select *pNew = sqlite3DbMallocRawNN(db, sizeof(*p) );
91898
+ if( pNew==0 ) break;
91899
+ pNew->pEList = sqlite3ExprListDup(db, p->pEList, flags);
91900
+ pNew->pSrc = sqlite3SrcListDup(db, p->pSrc, flags);
91901
+ pNew->pWhere = sqlite3ExprDup(db, p->pWhere, flags);
91902
+ pNew->pGroupBy = sqlite3ExprListDup(db, p->pGroupBy, flags);
91903
+ pNew->pHaving = sqlite3ExprDup(db, p->pHaving, flags);
91904
+ pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, flags);
91905
+ pNew->op = p->op;
91906
+ pNew->pNext = pNext;
91907
+ pNew->pPrior = 0;
91908
+ pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags);
91909
+ pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags);
91910
+ pNew->iLimit = 0;
91911
+ pNew->iOffset = 0;
91912
+ pNew->selFlags = p->selFlags & ~SF_UsesEphemeral;
91913
+ pNew->addrOpenEphm[0] = -1;
91914
+ pNew->addrOpenEphm[1] = -1;
91915
+ pNew->nSelectRow = p->nSelectRow;
91916
+ pNew->pWith = withDup(db, p->pWith);
91917
+ sqlite3SelectSetName(pNew, p->zSelName);
91918
+ *pp = pNew;
91919
+ pp = &pNew->pPrior;
91920
+ pNext = pNew;
91921
+ }
91922
+
91923
+ return pRet;
9171491924
}
9171591925
#else
9171691926
SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
9171791927
assert( p==0 );
9171891928
return 0;
@@ -91773,11 +91983,11 @@
9177391983
**
9177491984
** (a,b,c) = (expr1,expr2,expr3)
9177591985
** Or: (a,b,c) = (SELECT x,y,z FROM ....)
9177691986
**
9177791987
** For each term of the vector assignment, append new entries to the
91778
-** expression list pList. In the case of a subquery on the LHS, append
91988
+** expression list pList. In the case of a subquery on the RHS, append
9177991989
** TK_SELECT_COLUMN expressions.
9178091990
*/
9178191991
SQLITE_PRIVATE ExprList *sqlite3ExprListAppendVector(
9178291992
Parse *pParse, /* Parsing context */
9178391993
ExprList *pList, /* List to which to append. Might be NULL */
@@ -93882,10 +94092,15 @@
9388294092
int i; /* Loop counter */
9388394093
sqlite3 *db = pParse->db; /* The database connection */
9388494094
u8 enc = ENC(db); /* The text encoding used by this database */
9388594095
CollSeq *pColl = 0; /* A collating sequence */
9388694096
94097
+ if( ConstFactorOk(pParse) && sqlite3ExprIsConstantNotJoin(pExpr) ){
94098
+ /* SQL functions can be expensive. So try to move constant functions
94099
+ ** out of the inner loop, even if that means an extra OP_Copy. */
94100
+ return sqlite3ExprCodeAtInit(pParse, pExpr, -1);
94101
+ }
9388794102
assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
9388894103
if( ExprHasProperty(pExpr, EP_TokenOnly) ){
9388994104
pFarg = 0;
9389094105
}else{
9389194106
pFarg = pExpr->x.pList;
@@ -93929,10 +94144,26 @@
9392994144
*/
9393094145
if( pDef->funcFlags & SQLITE_FUNC_UNLIKELY ){
9393194146
assert( nFarg>=1 );
9393294147
return sqlite3ExprCodeTarget(pParse, pFarg->a[0].pExpr, target);
9393394148
}
94149
+
94150
+#ifdef SQLITE_DEBUG
94151
+ /* The AFFINITY() function evaluates to a string that describes
94152
+ ** the type affinity of the argument. This is used for testing of
94153
+ ** the SQLite type logic.
94154
+ */
94155
+ if( pDef->funcFlags & SQLITE_FUNC_AFFINITY ){
94156
+ const char *azAff[] = { "blob", "text", "numeric", "integer", "real" };
94157
+ char aff;
94158
+ assert( nFarg==1 );
94159
+ aff = sqlite3ExprAffinity(pFarg->a[0].pExpr);
94160
+ sqlite3VdbeLoadString(v, target,
94161
+ aff ? azAff[aff-SQLITE_AFF_BLOB] : "none");
94162
+ return target;
94163
+ }
94164
+#endif
9393494165
9393594166
for(i=0; i<nFarg; i++){
9393694167
if( i<32 && sqlite3ExprIsConstant(pFarg->a[i].pExpr) ){
9393794168
testcase( i==31 );
9393894169
constMask |= MASKBIT32(i);
@@ -94246,28 +94477,44 @@
9424694477
return inReg;
9424794478
}
9424894479
9424994480
/*
9425094481
** Factor out the code of the given expression to initialization time.
94482
+**
94483
+** If regDest>=0 then the result is always stored in that register and the
94484
+** result is not reusable. If regDest<0 then this routine is free to
94485
+** store the value whereever it wants. The register where the expression
94486
+** is stored is returned. When regDest<0, two identical expressions will
94487
+** code to the same register.
9425194488
*/
94252
-SQLITE_PRIVATE void sqlite3ExprCodeAtInit(
94489
+SQLITE_PRIVATE int sqlite3ExprCodeAtInit(
9425394490
Parse *pParse, /* Parsing context */
9425494491
Expr *pExpr, /* The expression to code when the VDBE initializes */
94255
- int regDest, /* Store the value in this register */
94256
- u8 reusable /* True if this expression is reusable */
94492
+ int regDest /* Store the value in this register */
9425794493
){
9425894494
ExprList *p;
9425994495
assert( ConstFactorOk(pParse) );
9426094496
p = pParse->pConstExpr;
94497
+ if( regDest<0 && p ){
94498
+ struct ExprList_item *pItem;
94499
+ int i;
94500
+ for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
94501
+ if( pItem->reusable && sqlite3ExprCompare(pItem->pExpr,pExpr,-1)==0 ){
94502
+ return pItem->u.iConstExprReg;
94503
+ }
94504
+ }
94505
+ }
9426194506
pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
9426294507
p = sqlite3ExprListAppend(pParse, p, pExpr);
9426394508
if( p ){
9426494509
struct ExprList_item *pItem = &p->a[p->nExpr-1];
94510
+ pItem->reusable = regDest<0;
94511
+ if( regDest<0 ) regDest = ++pParse->nMem;
9426594512
pItem->u.iConstExprReg = regDest;
94266
- pItem->reusable = reusable;
9426794513
}
9426894514
pParse->pConstExpr = p;
94515
+ return regDest;
9426994516
}
9427094517
9427194518
/*
9427294519
** Generate code to evaluate an expression and store the results
9427394520
** into a register. Return the register number where the results
@@ -94286,23 +94533,12 @@
9428694533
pExpr = sqlite3ExprSkipCollate(pExpr);
9428794534
if( ConstFactorOk(pParse)
9428894535
&& pExpr->op!=TK_REGISTER
9428994536
&& sqlite3ExprIsConstantNotJoin(pExpr)
9429094537
){
94291
- ExprList *p = pParse->pConstExpr;
94292
- int i;
9429394538
*pReg = 0;
94294
- if( p ){
94295
- struct ExprList_item *pItem;
94296
- for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
94297
- if( pItem->reusable && sqlite3ExprCompare(pItem->pExpr,pExpr,-1)==0 ){
94298
- return pItem->u.iConstExprReg;
94299
- }
94300
- }
94301
- }
94302
- r2 = ++pParse->nMem;
94303
- sqlite3ExprCodeAtInit(pParse, pExpr, r2, 1);
94539
+ r2 = sqlite3ExprCodeAtInit(pParse, pExpr, -1);
9430494540
}else{
9430594541
int r1 = sqlite3GetTempReg(pParse);
9430694542
r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
9430794543
if( r2==r1 ){
9430894544
*pReg = r1;
@@ -94352,11 +94588,11 @@
9435294588
** in register target. If the expression is constant, then this routine
9435394589
** might choose to code the expression at initialization time.
9435494590
*/
9435594591
SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse *pParse, Expr *pExpr, int target){
9435694592
if( pParse->okConstFactor && sqlite3ExprIsConstant(pExpr) ){
94357
- sqlite3ExprCodeAtInit(pParse, pExpr, target, 0);
94593
+ sqlite3ExprCodeAtInit(pParse, pExpr, target);
9435894594
}else{
9435994595
sqlite3ExprCode(pParse, pExpr, target);
9436094596
}
9436194597
}
9436294598
@@ -94424,11 +94660,11 @@
9442494660
n--;
9442594661
}else{
9442694662
sqlite3VdbeAddOp2(v, copyOp, j+srcReg-1, target+i);
9442794663
}
9442894664
}else if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){
94429
- sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0);
94665
+ sqlite3ExprCodeAtInit(pParse, pExpr, target+i);
9443094666
}else{
9443194667
int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
9443294668
if( inReg!=target+i ){
9443394669
VdbeOp *pOp;
9443494670
if( copyOp==OP_Copy
@@ -96968,10 +97204,16 @@
9696897204
** used to query statistical information that has been gathered into
9696997205
** the Stat4Accum object by prior calls to stat_push(). The P parameter
9697097206
** has type BLOB but it is really just a pointer to the Stat4Accum object.
9697197207
** The content to returned is determined by the parameter J
9697297208
** which is one of the STAT_GET_xxxx values defined above.
97209
+**
97210
+** The stat_get(P,J) function is not available to generic SQL. It is
97211
+** inserted as part of a manually constructed bytecode program. (See
97212
+** the callStatGet() routine below.) It is guaranteed that the P
97213
+** parameter will always be a poiner to a Stat4Accum object, never a
97214
+** NULL.
9697397215
**
9697497216
** If neither STAT3 nor STAT4 are enabled, then J is always
9697597217
** STAT_GET_STAT1 and is hence omitted and this routine becomes
9697697218
** a one-parameter function, stat_get(P), that always returns the
9697797219
** stat1 table entry information.
@@ -97787,11 +98029,11 @@
9778798029
sumEq += aSample[i].anEq[iCol];
9778898030
nSum100 += 100;
9778998031
}
9779098032
}
9779198033
97792
- if( nDist100>nSum100 ){
98034
+ if( nDist100>nSum100 && sumEq<nRow ){
9779398035
avgEq = ((i64)100 * (nRow - sumEq))/(nDist100 - nSum100);
9779498036
}
9779598037
if( avgEq==0 ) avgEq = 1;
9779698038
pIdx->aAvgEq[iCol] = avgEq;
9779798039
}
@@ -98201,10 +98443,11 @@
9820198443
assert( pVfs );
9820298444
flags |= SQLITE_OPEN_MAIN_DB;
9820398445
rc = sqlite3BtreeOpen(pVfs, zPath, db, &aNew->pBt, 0, flags);
9820498446
sqlite3_free( zPath );
9820598447
db->nDb++;
98448
+ db->skipBtreeMutex = 0;
9820698449
if( rc==SQLITE_CONSTRAINT ){
9820798450
rc = SQLITE_ERROR;
9820898451
zErrDyn = sqlite3MPrintf(db, "database is already attached");
9820998452
}else if( rc==SQLITE_OK ){
9821098453
Pager *pPager;
@@ -104365,16 +104608,12 @@
104365104608
}
104366104609
}else
104367104610
#endif
104368104611
{
104369104612
int count = (pParse->nested==0); /* True to count changes */
104370
- int iIdxNoSeek = -1;
104371
- if( bComplex==0 && aiCurOnePass[1]!=iDataCur ){
104372
- iIdxNoSeek = aiCurOnePass[1];
104373
- }
104374104613
sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
104375
- iKey, nKey, count, OE_Default, eOnePass, iIdxNoSeek);
104614
+ iKey, nKey, count, OE_Default, eOnePass, aiCurOnePass[1]);
104376104615
}
104377104616
104378104617
/* End of the loop over all rowids/primary-keys. */
104379104618
if( eOnePass!=ONEPASS_OFF ){
104380104619
sqlite3VdbeResolveLabel(v, addrBypass);
@@ -104450,19 +104689,21 @@
104450104689
** then this function must seek iDataCur to the entry identified by iPk
104451104690
** and nPk before reading from it.
104452104691
**
104453104692
** If eMode is ONEPASS_MULTI, then this call is being made as part
104454104693
** of a ONEPASS delete that affects multiple rows. In this case, if
104455
-** iIdxNoSeek is a valid cursor number (>=0), then its position should
104456
-** be preserved following the delete operation. Or, if iIdxNoSeek is not
104457
-** a valid cursor number, the position of iDataCur should be preserved
104458
-** instead.
104694
+** iIdxNoSeek is a valid cursor number (>=0) and is not the same as
104695
+** iDataCur, then its position should be preserved following the delete
104696
+** operation. Or, if iIdxNoSeek is not a valid cursor number, the
104697
+** position of iDataCur should be preserved instead.
104459104698
**
104460104699
** iIdxNoSeek:
104461
-** If iIdxNoSeek is a valid cursor number (>=0), then it identifies an
104462
-** index cursor (from within array of cursors starting at iIdxCur) that
104463
-** already points to the index entry to be deleted.
104700
+** If iIdxNoSeek is a valid cursor number (>=0) not equal to iDataCur,
104701
+** then it identifies an index cursor (from within array of cursors
104702
+** starting at iIdxCur) that already points to the index entry to be deleted.
104703
+** Except, this optimization is disabled if there are BEFORE triggers since
104704
+** the trigger body might have moved the cursor.
104464104705
*/
104465104706
SQLITE_PRIVATE void sqlite3GenerateRowDelete(
104466104707
Parse *pParse, /* Parsing context */
104467104708
Table *pTab, /* Table containing the row to be deleted */
104468104709
Trigger *pTrigger, /* List of triggers to (potentially) fire */
@@ -104529,17 +104770,22 @@
104529104770
TK_DELETE, 0, TRIGGER_BEFORE, pTab, iOld, onconf, iLabel
104530104771
);
104531104772
104532104773
/* If any BEFORE triggers were coded, then seek the cursor to the
104533104774
** row to be deleted again. It may be that the BEFORE triggers moved
104534
- ** the cursor or of already deleted the row that the cursor was
104775
+ ** the cursor or already deleted the row that the cursor was
104535104776
** pointing to.
104777
+ **
104778
+ ** Also disable the iIdxNoSeek optimization since the BEFORE trigger
104779
+ ** may have moved that cursor.
104536104780
*/
104537104781
if( addrStart<sqlite3VdbeCurrentAddr(v) ){
104538104782
sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
104539104783
VdbeCoverageIf(v, opSeek==OP_NotExists);
104540104784
VdbeCoverageIf(v, opSeek==OP_NotFound);
104785
+ testcase( iIdxNoSeek>=0 );
104786
+ iIdxNoSeek = -1;
104541104787
}
104542104788
104543104789
/* Do FK processing. This call checks that any FK constraints that
104544104790
** refer to this table (i.e. constraints attached to other tables)
104545104791
** are not violated by deleting this row. */
@@ -104558,15 +104804,17 @@
104558104804
*/
104559104805
if( pTab->pSelect==0 ){
104560104806
u8 p5 = 0;
104561104807
sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek);
104562104808
sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
104563
- sqlite3VdbeAppendP4(v, (char*)pTab, P4_TABLE);
104809
+ if( pParse->nested==0 ){
104810
+ sqlite3VdbeAppendP4(v, (char*)pTab, P4_TABLE);
104811
+ }
104564104812
if( eMode!=ONEPASS_OFF ){
104565104813
sqlite3VdbeChangeP5(v, OPFLAG_AUXDELETE);
104566104814
}
104567
- if( iIdxNoSeek>=0 ){
104815
+ if( iIdxNoSeek>=0 && iIdxNoSeek!=iDataCur ){
104568104816
sqlite3VdbeAddOp1(v, OP_Delete, iIdxNoSeek);
104569104817
}
104570104818
if( eMode==ONEPASS_MULTI ) p5 |= OPFLAG_SAVEPOSITION;
104571104819
sqlite3VdbeChangeP5(v, p5);
104572104820
}
@@ -104716,10 +104964,14 @@
104716104964
** opcode if it is present */
104717104965
sqlite3VdbeDeletePriorOpcode(v, OP_RealAffinity);
104718104966
}
104719104967
if( regOut ){
104720104968
sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regOut);
104969
+ if( pIdx->pTable->pSelect ){
104970
+ const char *zAff = sqlite3IndexAffinityStr(pParse->db, pIdx);
104971
+ sqlite3VdbeChangeP4(v, -1, zAff, P4_TRANSIENT);
104972
+ }
104721104973
}
104722104974
sqlite3ReleaseTempRange(pParse, regBase, nCol);
104723104975
return regBase;
104724104976
}
104725104977
@@ -106512,10 +106764,13 @@
106512106764
DFUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ),
106513106765
#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
106514106766
FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
106515106767
FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
106516106768
FUNCTION2(likely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
106769
+#ifdef SQLITE_DEBUG
106770
+ FUNCTION2(affinity, 1, 0, 0, noopFunc, SQLITE_FUNC_AFFINITY),
106771
+#endif
106517106772
FUNCTION(ltrim, 1, 1, 0, trimFunc ),
106518106773
FUNCTION(ltrim, 2, 1, 0, trimFunc ),
106519106774
FUNCTION(rtrim, 1, 2, 0, trimFunc ),
106520106775
FUNCTION(rtrim, 2, 2, 0, trimFunc ),
106521106776
FUNCTION(trim, 1, 3, 0, trimFunc ),
@@ -109667,11 +109922,11 @@
109667109922
if( db->flags&SQLITE_RecTriggers ){
109668109923
pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
109669109924
}
109670109925
sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
109671109926
regR, nPkField, 0, OE_Replace,
109672
- (pIdx==pPk ? ONEPASS_SINGLE : ONEPASS_OFF), -1);
109927
+ (pIdx==pPk ? ONEPASS_SINGLE : ONEPASS_OFF), iThisCur);
109673109928
seenReplace = 1;
109674109929
break;
109675109930
}
109676109931
}
109677109932
sqlite3VdbeResolveLabel(v, addrUniqueOk);
@@ -109683,10 +109938,29 @@
109683109938
}
109684109939
109685109940
*pbMayReplace = seenReplace;
109686109941
VdbeModuleComment((v, "END: GenCnstCks(%d)", seenReplace));
109687109942
}
109943
+
109944
+#ifdef SQLITE_ENABLE_NULL_TRIM
109945
+/*
109946
+** Change the P5 operand on the last opcode (which should be an OP_MakeRecord)
109947
+** to be the number of columns in table pTab that must not be NULL-trimmed.
109948
+**
109949
+** Or if no columns of pTab may be NULL-trimmed, leave P5 at zero.
109950
+*/
109951
+SQLITE_PRIVATE void sqlite3SetMakeRecordP5(Vdbe *v, Table *pTab){
109952
+ u16 i;
109953
+
109954
+ /* Records with omitted columns are only allowed for schema format
109955
+ ** version 2 and later (SQLite version 3.1.4, 2005-02-20). */
109956
+ if( pTab->pSchema->file_format<2 ) return;
109957
+
109958
+ for(i=pTab->nCol; i>1 && pTab->aCol[i-1].pDflt==0; i--){}
109959
+ sqlite3VdbeChangeP5(v, i);
109960
+}
109961
+#endif
109688109962
109689109963
/*
109690109964
** This routine generates code to finish the INSERT or UPDATE operation
109691109965
** that was started by a prior call to sqlite3GenerateConstraintChecks.
109692109966
** A consecutive range of registers starting at regNewData contains the
@@ -109700,11 +109974,11 @@
109700109974
Table *pTab, /* the table into which we are inserting */
109701109975
int iDataCur, /* Cursor of the canonical data source */
109702109976
int iIdxCur, /* First index cursor */
109703109977
int regNewData, /* Range of content */
109704109978
int *aRegIdx, /* Register used by each index. 0 for unused indices */
109705
- int isUpdate, /* True for UPDATE, False for INSERT */
109979
+ int update_flags, /* True for UPDATE, False for INSERT */
109706109980
int appendBias, /* True if this is likely to be an append */
109707109981
int useSeekResult /* True to set the USESEEKRESULT flag on OP_[Idx]Insert */
109708109982
){
109709109983
Vdbe *v; /* Prepared statements under construction */
109710109984
Index *pIdx; /* An index being inserted or updated */
@@ -109711,10 +109985,15 @@
109711109985
u8 pik_flags; /* flag values passed to the btree insert */
109712109986
int regData; /* Content registers (after the rowid) */
109713109987
int regRec; /* Register holding assembled record for the table */
109714109988
int i; /* Loop counter */
109715109989
u8 bAffinityDone = 0; /* True if OP_Affinity has been run already */
109990
+
109991
+ assert( update_flags==0
109992
+ || update_flags==OPFLAG_ISUPDATE
109993
+ || update_flags==(OPFLAG_ISUPDATE|OPFLAG_SAVEPOSITION)
109994
+ );
109716109995
109717109996
v = sqlite3GetVdbe(pParse);
109718109997
assert( v!=0 );
109719109998
assert( pTab->pSelect==0 ); /* This table is not a VIEW */
109720109999
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
@@ -109722,34 +110001,43 @@
109722110001
bAffinityDone = 1;
109723110002
if( pIdx->pPartIdxWhere ){
109724110003
sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
109725110004
VdbeCoverage(v);
109726110005
}
109727
- sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i],
109728
- aRegIdx[i]+1,
109729
- pIdx->uniqNotNull ? pIdx->nKeyCol: pIdx->nColumn);
109730
- pik_flags = 0;
109731
- if( useSeekResult ) pik_flags = OPFLAG_USESEEKRESULT;
110006
+ pik_flags = (useSeekResult ? OPFLAG_USESEEKRESULT : 0);
109732110007
if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
109733110008
assert( pParse->nested==0 );
109734110009
pik_flags |= OPFLAG_NCHANGE;
110010
+ pik_flags |= (update_flags & OPFLAG_SAVEPOSITION);
110011
+#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
110012
+ if( update_flags==0 ){
110013
+ sqlite3VdbeAddOp4(v, OP_InsertInt,
110014
+ iIdxCur+i, aRegIdx[i], 0, (char*)pTab, P4_TABLE
110015
+ );
110016
+ sqlite3VdbeChangeP5(v, OPFLAG_ISNOOP);
110017
+ }
110018
+#endif
109735110019
}
110020
+ sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i],
110021
+ aRegIdx[i]+1,
110022
+ pIdx->uniqNotNull ? pIdx->nKeyCol: pIdx->nColumn);
109736110023
sqlite3VdbeChangeP5(v, pik_flags);
109737110024
}
109738110025
if( !HasRowid(pTab) ) return;
109739110026
regData = regNewData + 1;
109740110027
regRec = sqlite3GetTempReg(pParse);
109741110028
sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec);
110029
+ sqlite3SetMakeRecordP5(v, pTab);
109742110030
if( !bAffinityDone ){
109743110031
sqlite3TableAffinity(v, pTab, 0);
109744110032
sqlite3ExprCacheAffinityChange(pParse, regData, pTab->nCol);
109745110033
}
109746110034
if( pParse->nested ){
109747110035
pik_flags = 0;
109748110036
}else{
109749110037
pik_flags = OPFLAG_NCHANGE;
109750
- pik_flags |= (isUpdate?OPFLAG_ISUPDATE:OPFLAG_LASTROWID);
110038
+ pik_flags |= (update_flags?update_flags:OPFLAG_LASTROWID);
109751110039
}
109752110040
if( appendBias ){
109753110041
pik_flags |= OPFLAG_APPEND;
109754110042
}
109755110043
if( useSeekResult ){
@@ -110154,11 +110442,11 @@
110154110442
addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid);
110155110443
}else{
110156110444
addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
110157110445
assert( (pDest->tabFlags & TF_Autoincrement)==0 );
110158110446
}
110159
- sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData);
110447
+ sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1);
110160110448
if( db->flags & SQLITE_Vacuum ){
110161110449
sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1);
110162110450
insFlags = OPFLAG_NCHANGE|OPFLAG_LASTROWID|
110163110451
OPFLAG_APPEND|OPFLAG_USESEEKRESULT;
110164110452
}else{
@@ -110186,11 +110474,11 @@
110186110474
sqlite3VdbeAddOp3(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest);
110187110475
sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
110188110476
sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
110189110477
VdbeComment((v, "%s", pDestIdx->zName));
110190110478
addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
110191
- sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData);
110479
+ sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1);
110192110480
if( db->flags & SQLITE_Vacuum ){
110193110481
/* This INSERT command is part of a VACUUM operation, which guarantees
110194110482
** that the destination table is empty. If all indexed columns use
110195110483
** collation sequence BINARY, then it can also be assumed that the
110196110484
** index will be populated by inserting keys in strictly sorted
@@ -110971,11 +111259,10 @@
110971111259
#endif /* SQLITE3EXT_H */
110972111260
110973111261
/************** End of sqlite3ext.h ******************************************/
110974111262
/************** Continuing where we left off in loadext.c ********************/
110975111263
/* #include "sqliteInt.h" */
110976
-/* #include <string.h> */
110977111264
110978111265
#ifndef SQLITE_OMIT_LOAD_EXTENSION
110979111266
/*
110980111267
** Some API routines are omitted when various features are
110981111268
** excluded from a build of SQLite. Substitute a NULL pointer
@@ -112635,11 +112922,11 @@
112635112922
112636112923
/*
112637112924
** Locate a pragma in the aPragmaName[] array.
112638112925
*/
112639112926
static const PragmaName *pragmaLocate(const char *zName){
112640
- int upr, lwr, mid, rc;
112927
+ int upr, lwr, mid = 0, rc;
112641112928
lwr = 0;
112642112929
upr = ArraySize(aPragmaName)-1;
112643112930
while( lwr<=upr ){
112644112931
mid = (lwr+upr)/2;
112645112932
rc = sqlite3_stricmp(zName, aPragmaName[mid].zName);
@@ -116149,10 +116436,11 @@
116149116436
v = pParse->pVdbe;
116150116437
r1 = sqlite3GetTempReg(pParse);
116151116438
sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N); VdbeCoverage(v);
116152116439
sqlite3VdbeAddOp3(v, OP_MakeRecord, iMem, N, r1);
116153116440
sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r1, iMem, N);
116441
+ sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
116154116442
sqlite3ReleaseTempReg(pParse, r1);
116155116443
}
116156116444
116157116445
/*
116158116446
** This routine generates the code for the inside of the inner loop
@@ -119677,11 +119965,19 @@
119677119965
assert( pTab->nTabRef==1 || ((pSel->selFlags&SF_Recursive) && pTab->nTabRef==2 ));
119678119966
119679119967
pCte->zCteErr = "circular reference: %s";
119680119968
pSavedWith = pParse->pWith;
119681119969
pParse->pWith = pWith;
119682
- sqlite3WalkSelect(pWalker, bMayRecursive ? pSel->pPrior : pSel);
119970
+ if( bMayRecursive ){
119971
+ Select *pPrior = pSel->pPrior;
119972
+ assert( pPrior->pWith==0 );
119973
+ pPrior->pWith = pSel->pWith;
119974
+ sqlite3WalkSelect(pWalker, pPrior);
119975
+ pPrior->pWith = 0;
119976
+ }else{
119977
+ sqlite3WalkSelect(pWalker, pSel);
119978
+ }
119683119979
pParse->pWith = pWith;
119684119980
119685119981
for(pLeft=pSel; pLeft->pPrior; pLeft=pLeft->pPrior);
119686119982
pEList = pLeft->pEList;
119687119983
if( pCte->pCols ){
@@ -119721,14 +120017,16 @@
119721120017
** sqlite3SelectExpand() when walking a SELECT tree to resolve table
119722120018
** names and other FROM clause elements.
119723120019
*/
119724120020
static void selectPopWith(Walker *pWalker, Select *p){
119725120021
Parse *pParse = pWalker->pParse;
119726
- With *pWith = findRightmost(p)->pWith;
119727
- if( pWith!=0 ){
119728
- assert( pParse->pWith==pWith );
119729
- pParse->pWith = pWith->pOuter;
120022
+ if( pParse->pWith && p->pPrior==0 ){
120023
+ With *pWith = findRightmost(p)->pWith;
120024
+ if( pWith!=0 ){
120025
+ assert( pParse->pWith==pWith );
120026
+ pParse->pWith = pWith->pOuter;
120027
+ }
119730120028
}
119731120029
}
119732120030
#else
119733120031
#define selectPopWith 0
119734120032
#endif
@@ -119774,12 +120072,12 @@
119774120072
if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){
119775120073
return WRC_Prune;
119776120074
}
119777120075
pTabList = p->pSrc;
119778120076
pEList = p->pEList;
119779
- if( pWalker->xSelectCallback2==selectPopWith ){
119780
- sqlite3WithPush(pParse, findRightmost(p)->pWith, 0);
120077
+ if( p->pWith ){
120078
+ sqlite3WithPush(pParse, p->pWith, 0);
119781120079
}
119782120080
119783120081
/* Make sure cursor numbers have been assigned to all entries in
119784120082
** the FROM clause of the SELECT statement.
119785120083
*/
@@ -120062,13 +120360,11 @@
120062120360
if( pParse->hasCompound ){
120063120361
w.xSelectCallback = convertCompoundSelectToSubquery;
120064120362
sqlite3WalkSelect(&w, pSelect);
120065120363
}
120066120364
w.xSelectCallback = selectExpander;
120067
- if( (pSelect->selFlags & SF_MultiValue)==0 ){
120068
- w.xSelectCallback2 = selectPopWith;
120069
- }
120365
+ w.xSelectCallback2 = selectPopWith;
120070120366
sqlite3WalkSelect(&w, pSelect);
120071120367
}
120072120368
120073120369
120074120370
#ifndef SQLITE_OMIT_SUBQUERY
@@ -121143,11 +121439,11 @@
121143121439
/* This case runs if the aggregate has no GROUP BY clause. The
121144121440
** processing is much simpler since there is only a single row
121145121441
** of output.
121146121442
*/
121147121443
resetAccumulator(pParse, &sAggInfo);
121148
- pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMax,0,flag,0);
121444
+ pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMax, 0,flag,0);
121149121445
if( pWInfo==0 ){
121150121446
sqlite3ExprListDelete(db, pDel);
121151121447
goto select_end;
121152121448
}
121153121449
updateAccumulator(pParse, &sAggInfo);
@@ -121232,12 +121528,10 @@
121232121528
**
121233121529
** These routines are in a separate files so that they will not be linked
121234121530
** if they are not used.
121235121531
*/
121236121532
/* #include "sqliteInt.h" */
121237
-/* #include <stdlib.h> */
121238
-/* #include <string.h> */
121239121533
121240121534
#ifndef SQLITE_OMIT_GET_TABLE
121241121535
121242121536
/*
121243121537
** This structure is used to pass data from sqlite3_get_table() through
@@ -122591,16 +122885,16 @@
122591122885
sqlite3ValueFromExpr(sqlite3VdbeDb(v), pCol->pDflt, enc,
122592122886
pCol->affinity, &pValue);
122593122887
if( pValue ){
122594122888
sqlite3VdbeAppendP4(v, pValue, P4_MEM);
122595122889
}
122890
+ }
122596122891
#ifndef SQLITE_OMIT_FLOATING_POINT
122597
- if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){
122598
- sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg);
122599
- }
122892
+ if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){
122893
+ sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg);
122894
+ }
122600122895
#endif
122601
- }
122602122896
}
122603122897
122604122898
/*
122605122899
** Process an UPDATE statement.
122606122900
**
@@ -122625,11 +122919,11 @@
122625122919
int nIdx; /* Number of indices that need updating */
122626122920
int iBaseCur; /* Base cursor number */
122627122921
int iDataCur; /* Cursor for the canonical data btree */
122628122922
int iIdxCur; /* Cursor for the first index */
122629122923
sqlite3 *db; /* The database structure */
122630
- int *aRegIdx = 0; /* One register assigned to each index to be updated */
122924
+ int *aRegIdx = 0; /* First register in array assigned to each index */
122631122925
int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the
122632122926
** an expression for the i-th column of the table.
122633122927
** aXRef[i]==-1 if the i-th column is not changed. */
122634122928
u8 *aToOpen; /* 1 for tables and indices to be opened */
122635122929
u8 chngPk; /* PRIMARY KEY changed in a WITHOUT ROWID table */
@@ -122637,14 +122931,15 @@
122637122931
u8 chngKey; /* Either chngPk or chngRowid */
122638122932
Expr *pRowidExpr = 0; /* Expression defining the new record number */
122639122933
AuthContext sContext; /* The authorization context */
122640122934
NameContext sNC; /* The name-context to resolve expressions in */
122641122935
int iDb; /* Database containing the table being updated */
122642
- int okOnePass; /* True for one-pass algorithm without the FIFO */
122936
+ int eOnePass; /* ONEPASS_XXX value from where.c */
122643122937
int hasFK; /* True if foreign key processing is required */
122644122938
int labelBreak; /* Jump here to break out of UPDATE loop */
122645122939
int labelContinue; /* Jump here to continue next step of UPDATE loop */
122940
+ int flags; /* Flags for sqlite3WhereBegin() */
122646122941
122647122942
#ifndef SQLITE_OMIT_TRIGGER
122648122943
int isView; /* True when updating a view (INSTEAD OF trigger) */
122649122944
Trigger *pTrigger; /* List of triggers on pTab, if required */
122650122945
int tmask; /* Mask of TRIGGER_BEFORE|TRIGGER_AFTER */
@@ -122651,10 +122946,14 @@
122651122946
#endif
122652122947
int newmask; /* Mask of NEW.* columns accessed by BEFORE triggers */
122653122948
int iEph = 0; /* Ephemeral table holding all primary key values */
122654122949
int nKey = 0; /* Number of elements in regKey for WITHOUT ROWID */
122655122950
int aiCurOnePass[2]; /* The write cursors opened by WHERE_ONEPASS */
122951
+ int addrOpen = 0; /* Address of OP_OpenEphemeral */
122952
+ int iPk = 0; /* First of nPk cells holding PRIMARY KEY value */
122953
+ i16 nPk = 0; /* Number of components of the PRIMARY KEY */
122954
+ int bReplace = 0; /* True if REPLACE conflict resolution might happen */
122656122955
122657122956
/* Register Allocations */
122658122957
int regRowCount = 0; /* A count of rows changed */
122659122958
int regOldRowid = 0; /* The old rowid */
122660122959
int regNewRowid = 0; /* The new rowid */
@@ -122810,17 +123109,27 @@
122810123109
for(i=0; i<pIdx->nKeyCol; i++){
122811123110
i16 iIdxCol = pIdx->aiColumn[i];
122812123111
if( iIdxCol<0 || aXRef[iIdxCol]>=0 ){
122813123112
reg = ++pParse->nMem;
122814123113
pParse->nMem += pIdx->nColumn;
123114
+ if( (onError==OE_Replace)
123115
+ || (onError==OE_Default && pIdx->onError==OE_Replace)
123116
+ ){
123117
+ bReplace = 1;
123118
+ }
122815123119
break;
122816123120
}
122817123121
}
122818123122
}
122819123123
if( reg==0 ) aToOpen[j+1] = 0;
122820123124
aRegIdx[j] = reg;
122821123125
}
123126
+ if( bReplace ){
123127
+ /* If REPLACE conflict resolution might be invoked, open cursors on all
123128
+ ** indexes in case they are needed to delete records. */
123129
+ memset(aToOpen, 1, nIdx+1);
123130
+ }
122822123131
122823123132
/* Begin generating code. */
122824123133
v = sqlite3GetVdbe(pParse);
122825123134
if( v==0 ) goto update_cleanup;
122826123135
if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
@@ -122869,107 +123178,127 @@
122869123178
pWhere, onError);
122870123179
goto update_cleanup;
122871123180
}
122872123181
#endif
122873123182
122874
- /* Begin the database scan
122875
- */
123183
+ /* Initialize the count of updated rows */
123184
+ if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab ){
123185
+ regRowCount = ++pParse->nMem;
123186
+ sqlite3VdbeAddOp2(v, OP_Integer, 0, regRowCount);
123187
+ }
123188
+
122876123189
if( HasRowid(pTab) ){
122877123190
sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid);
122878
- pWInfo = sqlite3WhereBegin(
122879
- pParse, pTabList, pWhere, 0, 0,
122880
- WHERE_ONEPASS_DESIRED | WHERE_SEEK_TABLE, iIdxCur
122881
- );
122882
- if( pWInfo==0 ) goto update_cleanup;
122883
- okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
122884
-
122885
- /* Remember the rowid of every item to be updated.
122886
- */
122887
- sqlite3VdbeAddOp2(v, OP_Rowid, iDataCur, regOldRowid);
122888
- if( !okOnePass ){
122889
- sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, regOldRowid);
122890
- }
122891
-
122892
- /* End the database scan loop.
122893
- */
122894
- sqlite3WhereEnd(pWInfo);
122895123191
}else{
122896
- int iPk; /* First of nPk memory cells holding PRIMARY KEY value */
122897
- i16 nPk; /* Number of components of the PRIMARY KEY */
122898
- int addrOpen; /* Address of the OpenEphemeral instruction */
122899
-
122900123192
assert( pPk!=0 );
122901123193
nPk = pPk->nKeyCol;
122902123194
iPk = pParse->nMem+1;
122903123195
pParse->nMem += nPk;
122904123196
regKey = ++pParse->nMem;
122905123197
iEph = pParse->nTab++;
123198
+
122906123199
sqlite3VdbeAddOp2(v, OP_Null, 0, iPk);
122907123200
addrOpen = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEph, nPk);
122908123201
sqlite3VdbeSetP4KeyInfo(pParse, pPk);
122909
- pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0,
122910
- WHERE_ONEPASS_DESIRED, iIdxCur);
122911
- if( pWInfo==0 ) goto update_cleanup;
122912
- okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
123202
+ }
123203
+
123204
+ /* Begin the database scan.
123205
+ **
123206
+ ** Do not consider a single-pass strategy for a multi-row update if
123207
+ ** there are any triggers or foreign keys to process, or rows may
123208
+ ** be deleted as a result of REPLACE conflict handling. Any of these
123209
+ ** things might disturb a cursor being used to scan through the table
123210
+ ** or index, causing a single-pass approach to malfunction. */
123211
+ flags = WHERE_ONEPASS_DESIRED|WHERE_SEEK_UNIQ_TABLE;
123212
+ if( !pParse->nested && !pTrigger && !hasFK && !chngKey && !bReplace ){
123213
+ flags |= WHERE_ONEPASS_MULTIROW;
123214
+ }
123215
+ pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, flags, iIdxCur);
123216
+ if( pWInfo==0 ) goto update_cleanup;
123217
+
123218
+ /* A one-pass strategy that might update more than one row may not
123219
+ ** be used if any column of the index used for the scan is being
123220
+ ** updated. Otherwise, if there is an index on "b", statements like
123221
+ ** the following could create an infinite loop:
123222
+ **
123223
+ ** UPDATE t1 SET b=b+1 WHERE b>?
123224
+ **
123225
+ ** Fall back to ONEPASS_OFF if where.c has selected a ONEPASS_MULTI
123226
+ ** strategy that uses an index for which one or more columns are being
123227
+ ** updated. */
123228
+ eOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
123229
+ if( eOnePass==ONEPASS_MULTI ){
123230
+ int iCur = aiCurOnePass[1];
123231
+ if( iCur>=0 && iCur!=iDataCur && aToOpen[iCur-iBaseCur] ){
123232
+ eOnePass = ONEPASS_OFF;
123233
+ }
123234
+ assert( iCur!=iDataCur || !HasRowid(pTab) );
123235
+ }
123236
+
123237
+ if( HasRowid(pTab) ){
123238
+ /* Read the rowid of the current row of the WHERE scan. In ONEPASS_OFF
123239
+ ** mode, write the rowid into the FIFO. In either of the one-pass modes,
123240
+ ** leave it in register regOldRowid. */
123241
+ sqlite3VdbeAddOp2(v, OP_Rowid, iDataCur, regOldRowid);
123242
+ if( eOnePass==ONEPASS_OFF ){
123243
+ sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, regOldRowid);
123244
+ }
123245
+ }else{
123246
+ /* Read the PK of the current row into an array of registers. In
123247
+ ** ONEPASS_OFF mode, serialize the array into a record and store it in
123248
+ ** the ephemeral table. Or, in ONEPASS_SINGLE or MULTI mode, change
123249
+ ** the OP_OpenEphemeral instruction to a Noop (the ephemeral table
123250
+ ** is not required) and leave the PK fields in the array of registers. */
122913123251
for(i=0; i<nPk; i++){
122914123252
assert( pPk->aiColumn[i]>=0 );
122915
- sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pPk->aiColumn[i],
122916
- iPk+i);
123253
+ sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur,pPk->aiColumn[i],iPk+i);
122917123254
}
122918
- if( okOnePass ){
123255
+ if( eOnePass ){
122919123256
sqlite3VdbeChangeToNoop(v, addrOpen);
122920123257
nKey = nPk;
122921123258
regKey = iPk;
122922123259
}else{
122923123260
sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, regKey,
122924123261
sqlite3IndexAffinityStr(db, pPk), nPk);
122925123262
sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iEph, regKey, iPk, nPk);
122926123263
}
122927
- sqlite3WhereEnd(pWInfo);
122928123264
}
122929123265
122930
- /* Initialize the count of updated rows
122931
- */
122932
- if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab ){
122933
- regRowCount = ++pParse->nMem;
122934
- sqlite3VdbeAddOp2(v, OP_Integer, 0, regRowCount);
123266
+ if( eOnePass!=ONEPASS_MULTI ){
123267
+ sqlite3WhereEnd(pWInfo);
122935123268
}
122936123269
122937123270
labelBreak = sqlite3VdbeMakeLabel(v);
122938123271
if( !isView ){
122939
- /*
122940
- ** Open every index that needs updating. Note that if any
122941
- ** index could potentially invoke a REPLACE conflict resolution
122942
- ** action, then we need to open all indices because we might need
122943
- ** to be deleting some records.
122944
- */
122945
- if( onError==OE_Replace ){
122946
- memset(aToOpen, 1, nIdx+1);
122947
- }else{
122948
- for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
122949
- if( pIdx->onError==OE_Replace ){
122950
- memset(aToOpen, 1, nIdx+1);
122951
- break;
122952
- }
122953
- }
122954
- }
122955
- if( okOnePass ){
123272
+ int addrOnce = 0;
123273
+
123274
+ /* Open every index that needs updating. */
123275
+ if( eOnePass!=ONEPASS_OFF ){
122956123276
if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iBaseCur] = 0;
122957123277
if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iBaseCur] = 0;
122958123278
}
123279
+
123280
+ if( eOnePass==ONEPASS_MULTI && (nIdx-(aiCurOnePass[1]>=0))>0 ){
123281
+ addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
123282
+ }
122959123283
sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, 0, iBaseCur, aToOpen,
122960123284
0, 0);
123285
+ if( addrOnce ) sqlite3VdbeJumpHere(v, addrOnce);
122961123286
}
122962123287
122963123288
/* Top of the update loop */
122964
- if( okOnePass ){
122965
- if( aToOpen[iDataCur-iBaseCur] && !isView ){
123289
+ if( eOnePass!=ONEPASS_OFF ){
123290
+ if( !isView && aiCurOnePass[0]!=iDataCur && aiCurOnePass[1]!=iDataCur ){
122966123291
assert( pPk );
122967123292
sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey, nKey);
122968123293
VdbeCoverageNeverTaken(v);
122969123294
}
122970
- labelContinue = labelBreak;
123295
+ if( eOnePass==ONEPASS_SINGLE ){
123296
+ labelContinue = labelBreak;
123297
+ }else{
123298
+ labelContinue = sqlite3VdbeMakeLabel(v);
123299
+ }
122971123300
sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak);
122972123301
VdbeCoverageIf(v, pPk==0);
122973123302
VdbeCoverageIf(v, pPk!=0);
122974123303
}else if( pPk ){
122975123304
labelContinue = sqlite3VdbeMakeLabel(v);
@@ -123090,11 +123419,10 @@
123090123419
}
123091123420
}
123092123421
123093123422
if( !isView ){
123094123423
int addr1 = 0; /* Address of jump instruction */
123095
- int bReplace = 0; /* True if REPLACE conflict resolution might happen */
123096123424
123097123425
/* Do constraint checks. */
123098123426
assert( regOldRowid>0 );
123099123427
sqlite3GenerateConstraintChecks(pParse, pTab, aRegIdx, iDataCur, iIdxCur,
123100123428
regNewRowid, regOldRowid, chngKey, onError, labelContinue, &bReplace,
@@ -123126,18 +123454,22 @@
123126123454
** is the column index supplied by the user.
123127123455
*/
123128123456
assert( regNew==regNewRowid+1 );
123129123457
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
123130123458
sqlite3VdbeAddOp3(v, OP_Delete, iDataCur,
123131
- OPFLAG_ISUPDATE | ((hasFK || chngKey || pPk!=0) ? 0 : OPFLAG_ISNOOP),
123459
+ OPFLAG_ISUPDATE | ((hasFK || chngKey) ? 0 : OPFLAG_ISNOOP),
123132123460
regNewRowid
123133123461
);
123462
+ if( eOnePass==ONEPASS_MULTI ){
123463
+ assert( hasFK==0 && chngKey==0 );
123464
+ sqlite3VdbeChangeP5(v, OPFLAG_SAVEPOSITION);
123465
+ }
123134123466
if( !pParse->nested ){
123135123467
sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
123136123468
}
123137123469
#else
123138
- if( hasFK || chngKey || pPk!=0 ){
123470
+ if( hasFK || chngKey ){
123139123471
sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0);
123140123472
}
123141123473
#endif
123142123474
if( bReplace || chngKey ){
123143123475
sqlite3VdbeJumpHere(v, addr1);
@@ -123146,12 +123478,15 @@
123146123478
if( hasFK ){
123147123479
sqlite3FkCheck(pParse, pTab, 0, regNewRowid, aXRef, chngKey);
123148123480
}
123149123481
123150123482
/* Insert the new index entries and the new record. */
123151
- sqlite3CompleteInsertion(pParse, pTab, iDataCur, iIdxCur,
123152
- regNewRowid, aRegIdx, 1, 0, 0);
123483
+ sqlite3CompleteInsertion(
123484
+ pParse, pTab, iDataCur, iIdxCur, regNewRowid, aRegIdx,
123485
+ OPFLAG_ISUPDATE | (eOnePass==ONEPASS_MULTI ? OPFLAG_SAVEPOSITION : 0),
123486
+ 0, 0
123487
+ );
123153123488
123154123489
/* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
123155123490
** handle rows (possibly in other tables) that refer via a foreign key
123156123491
** to the row just updated. */
123157123492
if( hasFK ){
@@ -123169,12 +123504,15 @@
123169123504
TRIGGER_AFTER, pTab, regOldRowid, onError, labelContinue);
123170123505
123171123506
/* Repeat the above with the next record to be updated, until
123172123507
** all record selected by the WHERE clause have been updated.
123173123508
*/
123174
- if( okOnePass ){
123509
+ if( eOnePass==ONEPASS_SINGLE ){
123175123510
/* Nothing to do at end-of-loop for a single-pass */
123511
+ }else if( eOnePass==ONEPASS_MULTI ){
123512
+ sqlite3VdbeResolveLabel(v, labelContinue);
123513
+ sqlite3WhereEnd(pWInfo);
123176123514
}else if( pPk ){
123177123515
sqlite3VdbeResolveLabel(v, labelContinue);
123178123516
sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop); VdbeCoverage(v);
123179123517
}else{
123180123518
sqlite3VdbeGoto(v, labelContinue);
@@ -127090,11 +127428,14 @@
127090127428
127091127429
/* Seek the table cursor, if required */
127092127430
if( omitTable ){
127093127431
/* pIdx is a covering index. No need to access the main table. */
127094127432
}else if( HasRowid(pIdx->pTable) ){
127095
- if( (pWInfo->wctrlFlags & WHERE_SEEK_TABLE)!=0 ){
127433
+ if( (pWInfo->wctrlFlags & WHERE_SEEK_TABLE) || (
127434
+ (pWInfo->wctrlFlags & WHERE_SEEK_UNIQ_TABLE)
127435
+ && (pWInfo->eOnePass==ONEPASS_SINGLE)
127436
+ )){
127096127437
iRowidReg = ++pParse->nMem;
127097127438
sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
127098127439
sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
127099127440
sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, iRowidReg);
127100127441
VdbeCoverage(v);
@@ -128454,10 +128795,11 @@
128454128795
int noCase = 0; /* uppercase equivalent to lowercase */
128455128796
int op; /* Top-level operator. pExpr->op */
128456128797
Parse *pParse = pWInfo->pParse; /* Parsing context */
128457128798
sqlite3 *db = pParse->db; /* Database connection */
128458128799
unsigned char eOp2; /* op2 value for LIKE/REGEXP/GLOB */
128800
+ int nLeft; /* Number of elements on left side vector */
128459128801
128460128802
if( db->mallocFailed ){
128461128803
return;
128462128804
}
128463128805
pTerm = &pWC->a[idxTerm];
@@ -128483,10 +128825,14 @@
128483128825
if( ExprHasProperty(pExpr, EP_FromJoin) ){
128484128826
Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->iRightJoinTable);
128485128827
prereqAll |= x;
128486128828
extraRight = x-1; /* ON clause terms may not be used with an index
128487128829
** on left table of a LEFT JOIN. Ticket #3015 */
128830
+ if( (prereqAll>>1)>=x ){
128831
+ sqlite3ErrorMsg(pParse, "ON clause references tables to its right");
128832
+ return;
128833
+ }
128488128834
}
128489128835
pTerm->prereqAll = prereqAll;
128490128836
pTerm->leftCursor = -1;
128491128837
pTerm->iParent = -1;
128492128838
pTerm->eOperator = 0;
@@ -128725,17 +129071,16 @@
128725129071
**
128726129072
** This is only required if at least one side of the comparison operation
128727129073
** is not a sub-select. */
128728129074
if( pWC->op==TK_AND
128729129075
&& (pExpr->op==TK_EQ || pExpr->op==TK_IS)
128730
- && sqlite3ExprIsVector(pExpr->pLeft)
129076
+ && (nLeft = sqlite3ExprVectorSize(pExpr->pLeft))>1
129077
+ && sqlite3ExprVectorSize(pExpr->pRight)==nLeft
128731129078
&& ( (pExpr->pLeft->flags & EP_xIsSelect)==0
128732
- || (pExpr->pRight->flags & EP_xIsSelect)==0
128733
- )){
128734
- int nLeft = sqlite3ExprVectorSize(pExpr->pLeft);
129079
+ || (pExpr->pRight->flags & EP_xIsSelect)==0)
129080
+ ){
128735129081
int i;
128736
- assert( nLeft==sqlite3ExprVectorSize(pExpr->pRight) );
128737129082
for(i=0; i<nLeft; i++){
128738129083
int idxNew;
128739129084
Expr *pNew;
128740129085
Expr *pLeft = sqlite3ExprForVectorField(pParse, pExpr->pLeft, i);
128741129086
Expr *pRight = sqlite3ExprForVectorField(pParse, pExpr->pRight, i);
@@ -129293,10 +129638,11 @@
129293129638
if( pIdx ){
129294129639
int j = iColumn;
129295129640
iColumn = pIdx->aiColumn[j];
129296129641
if( iColumn==XN_EXPR ){
129297129642
pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr;
129643
+ pScan->zCollName = pIdx->azColl[j];
129298129644
}else if( iColumn==pIdx->pTable->iPKey ){
129299129645
iColumn = XN_ROWID;
129300129646
}else if( iColumn>=0 ){
129301129647
pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity;
129302129648
pScan->zCollName = pIdx->azColl[j];
@@ -133934,11 +134280,12 @@
133934134280
x = sqlite3ColumnOfIndex(pIdx, x);
133935134281
if( x>=0 ){
133936134282
pOp->p2 = x;
133937134283
pOp->p1 = pLevel->iIdxCur;
133938134284
}
133939
- assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0 );
134285
+ assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0
134286
+ || pWInfo->eOnePass );
133940134287
}else if( pOp->opcode==OP_Rowid ){
133941134288
pOp->p1 = pLevel->iIdxCur;
133942134289
pOp->opcode = OP_IdxRowid;
133943134290
}
133944134291
}
@@ -133998,10 +134345,23 @@
133998134345
** Indicate that sqlite3ParserFree() will never be called with a null
133999134346
** pointer.
134000134347
*/
134001134348
#define YYPARSEFREENEVERNULL 1
134002134349
134350
+/*
134351
+** In the amalgamation, the parse.c file generated by lemon and the
134352
+** tokenize.c file are concatenated. In that case, sqlite3RunParser()
134353
+** has access to the the size of the yyParser object and so the parser
134354
+** engine can be allocated from stack. In that case, only the
134355
+** sqlite3ParserInit() and sqlite3ParserFinalize() routines are invoked
134356
+** and the sqlite3ParserAlloc() and sqlite3ParserFree() routines can be
134357
+** omitted.
134358
+*/
134359
+#ifdef SQLITE_AMALGAMATION
134360
+# define sqlite3Parser_ENGINEALWAYSONSTACK 1
134361
+#endif
134362
+
134003134363
/*
134004134364
** Alternative datatype for the argument to the malloc() routine passed
134005134365
** into sqlite3ParserAlloc(). The default is size_t.
134006134366
*/
134007134367
#define YYMALLOCARGTYPE u64
@@ -135446,10 +135806,35 @@
135446135806
*/
135447135807
#ifndef YYMALLOCARGTYPE
135448135808
# define YYMALLOCARGTYPE size_t
135449135809
#endif
135450135810
135811
+/* Initialize a new parser that has already been allocated.
135812
+*/
135813
+SQLITE_PRIVATE void sqlite3ParserInit(void *yypParser){
135814
+ yyParser *pParser = (yyParser*)yypParser;
135815
+#ifdef YYTRACKMAXSTACKDEPTH
135816
+ pParser->yyhwm = 0;
135817
+#endif
135818
+#if YYSTACKDEPTH<=0
135819
+ pParser->yytos = NULL;
135820
+ pParser->yystack = NULL;
135821
+ pParser->yystksz = 0;
135822
+ if( yyGrowStack(pParser) ){
135823
+ pParser->yystack = &pParser->yystk0;
135824
+ pParser->yystksz = 1;
135825
+ }
135826
+#endif
135827
+#ifndef YYNOERRORRECOVERY
135828
+ pParser->yyerrcnt = -1;
135829
+#endif
135830
+ pParser->yytos = pParser->yystack;
135831
+ pParser->yystack[0].stateno = 0;
135832
+ pParser->yystack[0].major = 0;
135833
+}
135834
+
135835
+#ifndef sqlite3Parser_ENGINEALWAYSONSTACK
135451135836
/*
135452135837
** This function allocates a new parser.
135453135838
** The only argument is a pointer to a function which works like
135454135839
** malloc.
135455135840
**
@@ -135461,32 +135846,15 @@
135461135846
** to sqlite3Parser and sqlite3ParserFree.
135462135847
*/
135463135848
SQLITE_PRIVATE void *sqlite3ParserAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){
135464135849
yyParser *pParser;
135465135850
pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) );
135466
- if( pParser ){
135467
-#ifdef YYTRACKMAXSTACKDEPTH
135468
- pParser->yyhwm = 0;
135469
-#endif
135470
-#if YYSTACKDEPTH<=0
135471
- pParser->yytos = NULL;
135472
- pParser->yystack = NULL;
135473
- pParser->yystksz = 0;
135474
- if( yyGrowStack(pParser) ){
135475
- pParser->yystack = &pParser->yystk0;
135476
- pParser->yystksz = 1;
135477
- }
135478
-#endif
135479
-#ifndef YYNOERRORRECOVERY
135480
- pParser->yyerrcnt = -1;
135481
-#endif
135482
- pParser->yytos = pParser->yystack;
135483
- pParser->yystack[0].stateno = 0;
135484
- pParser->yystack[0].major = 0;
135485
- }
135851
+ if( pParser ) sqlite3ParserInit(pParser);
135486135852
return pParser;
135487135853
}
135854
+#endif /* sqlite3Parser_ENGINEALWAYSONSTACK */
135855
+
135488135856
135489135857
/* The following function deletes the "minor type" or semantic value
135490135858
** associated with a symbol. The symbol can be either a terminal
135491135859
** or nonterminal. "yymajor" is the symbol code, and "yypminor" is
135492135860
** a pointer to the value to be deleted. The code used to do the
@@ -135608,10 +135976,22 @@
135608135976
}
135609135977
#endif
135610135978
yy_destructor(pParser, yytos->major, &yytos->minor);
135611135979
}
135612135980
135981
+/*
135982
+** Clear all secondary memory allocations from the parser
135983
+*/
135984
+SQLITE_PRIVATE void sqlite3ParserFinalize(void *p){
135985
+ yyParser *pParser = (yyParser*)p;
135986
+ while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser);
135987
+#if YYSTACKDEPTH<=0
135988
+ if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack);
135989
+#endif
135990
+}
135991
+
135992
+#ifndef sqlite3Parser_ENGINEALWAYSONSTACK
135613135993
/*
135614135994
** Deallocate and destroy a parser. Destructors are called for
135615135995
** all stack elements before shutting the parser down.
135616135996
**
135617135997
** If the YYPARSEFREENEVERNULL macro exists (for example because it
@@ -135620,20 +136000,17 @@
135620136000
*/
135621136001
SQLITE_PRIVATE void sqlite3ParserFree(
135622136002
void *p, /* The parser to be deleted */
135623136003
void (*freeProc)(void*) /* Function used to reclaim memory */
135624136004
){
135625
- yyParser *pParser = (yyParser*)p;
135626136005
#ifndef YYPARSEFREENEVERNULL
135627
- if( pParser==0 ) return;
135628
-#endif
135629
- while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser);
135630
-#if YYSTACKDEPTH<=0
135631
- if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack);
135632
-#endif
135633
- (*freeProc)((void*)pParser);
135634
-}
136006
+ if( p==0 ) return;
136007
+#endif
136008
+ sqlite3ParserFinalize(p);
136009
+ (*freeProc)(p);
136010
+}
136011
+#endif /* sqlite3Parser_ENGINEALWAYSONSTACK */
135635136012
135636136013
/*
135637136014
** Return the peak depth of the stack for a parser.
135638136015
*/
135639136016
#ifdef YYTRACKMAXSTACKDEPTH
@@ -138483,10 +138860,13 @@
138483138860
void *pEngine; /* The LEMON-generated LALR(1) parser */
138484138861
int tokenType; /* type of the next token */
138485138862
int lastTokenParsed = -1; /* type of the previous token */
138486138863
sqlite3 *db = pParse->db; /* The database connection */
138487138864
int mxSqlLen; /* Max length of an SQL string */
138865
+#ifdef sqlite3Parser_ENGINEALWAYSONSTACK
138866
+ unsigned char zSpace[sizeof(yyParser)]; /* Space for parser engine object */
138867
+#endif
138488138868
138489138869
assert( zSql!=0 );
138490138870
mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
138491138871
if( db->nVdbeActive==0 ){
138492138872
db->u1.isInterrupted = 0;
@@ -138494,15 +138874,20 @@
138494138874
pParse->rc = SQLITE_OK;
138495138875
pParse->zTail = zSql;
138496138876
i = 0;
138497138877
assert( pzErrMsg!=0 );
138498138878
/* sqlite3ParserTrace(stdout, "parser: "); */
138879
+#ifdef sqlite3Parser_ENGINEALWAYSONSTACK
138880
+ pEngine = zSpace;
138881
+ sqlite3ParserInit(pEngine);
138882
+#else
138499138883
pEngine = sqlite3ParserAlloc(sqlite3Malloc);
138500138884
if( pEngine==0 ){
138501138885
sqlite3OomFault(db);
138502138886
return SQLITE_NOMEM_BKPT;
138503138887
}
138888
+#endif
138504138889
assert( pParse->pNewTable==0 );
138505138890
assert( pParse->pNewTrigger==0 );
138506138891
assert( pParse->nVar==0 );
138507138892
assert( pParse->pVList==0 );
138508138893
while( 1 ){
@@ -138550,11 +138935,15 @@
138550138935
sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK,
138551138936
sqlite3ParserStackPeak(pEngine)
138552138937
);
138553138938
sqlite3_mutex_leave(sqlite3MallocMutex());
138554138939
#endif /* YYDEBUG */
138940
+#ifdef sqlite3Parser_ENGINEALWAYSONSTACK
138941
+ sqlite3ParserFinalize(pEngine);
138942
+#else
138555138943
sqlite3ParserFree(pEngine, sqlite3_free);
138944
+#endif
138556138945
if( db->mallocFailed ){
138557138946
pParse->rc = SQLITE_NOMEM_BKPT;
138558138947
}
138559138948
if( pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE && pParse->zErrMsg==0 ){
138560138949
pParse->zErrMsg = sqlite3MPrintf(db, "%s", sqlite3ErrStr(pParse->rc));
@@ -144213,10 +144602,11 @@
144213144602
144214144603
/* Precompiled statements used by the implementation. Each of these
144215144604
** statements is run and reset within a single virtual table API call.
144216144605
*/
144217144606
sqlite3_stmt *aStmt[40];
144607
+ sqlite3_stmt *pSeekStmt; /* Cache for fts3CursorSeekStmt() */
144218144608
144219144609
char *zReadExprlist;
144220144610
char *zWriteExprlist;
144221144611
144222144612
int nNodeSize; /* Soft limit for node size */
@@ -144282,10 +144672,11 @@
144282144672
struct Fts3Cursor {
144283144673
sqlite3_vtab_cursor base; /* Base class used by SQLite core */
144284144674
i16 eSearch; /* Search strategy (see below) */
144285144675
u8 isEof; /* True if at End Of Results */
144286144676
u8 isRequireSeek; /* True if must seek pStmt to %_content row */
144677
+ u8 bSeekStmt; /* True if pStmt is a seek */
144287144678
sqlite3_stmt *pStmt; /* Prepared statement in use by the cursor */
144288144679
Fts3Expr *pExpr; /* Parsed MATCH query string */
144289144680
int iLangid; /* Language being queried for */
144290144681
int nPhrase; /* Number of matchable phrases in query */
144291144682
Fts3DeferredToken *pDeferred; /* Deferred search tokens, if any */
@@ -144804,10 +145195,11 @@
144804145195
144805145196
assert( p->nPendingData==0 );
144806145197
assert( p->pSegments==0 );
144807145198
144808145199
/* Free any prepared statements held */
145200
+ sqlite3_finalize(p->pSeekStmt);
144809145201
for(i=0; i<SizeofArray(p->aStmt); i++){
144810145202
sqlite3_finalize(p->aStmt[i]);
144811145203
}
144812145204
sqlite3_free(p->zSegmentsTbl);
144813145205
sqlite3_free(p->zReadExprlist);
@@ -145675,13 +146067,13 @@
145675146067
p->nPendingData = 0;
145676146068
p->azColumn = (char **)&p[1];
145677146069
p->pTokenizer = pTokenizer;
145678146070
p->nMaxPendingData = FTS3_MAX_PENDING_DATA;
145679146071
p->bHasDocsize = (isFts4 && bNoDocsize==0);
145680
- p->bHasStat = isFts4;
145681
- p->bFts4 = isFts4;
145682
- p->bDescIdx = bDescIdx;
146072
+ p->bHasStat = (u8)isFts4;
146073
+ p->bFts4 = (u8)isFts4;
146074
+ p->bDescIdx = (u8)bDescIdx;
145683146075
p->nAutoincrmerge = 0xff; /* 0xff means setting unknown */
145684146076
p->zContentTbl = zContent;
145685146077
p->zLanguageid = zLanguageid;
145686146078
zContent = 0;
145687146079
zLanguageid = 0;
@@ -145991,19 +146383,39 @@
145991146383
return SQLITE_NOMEM;
145992146384
}
145993146385
memset(pCsr, 0, sizeof(Fts3Cursor));
145994146386
return SQLITE_OK;
145995146387
}
146388
+
146389
+/*
146390
+** Finalize the statement handle at pCsr->pStmt.
146391
+**
146392
+** Or, if that statement handle is one created by fts3CursorSeekStmt(),
146393
+** and the Fts3Table.pSeekStmt slot is currently NULL, save the statement
146394
+** pointer there instead of finalizing it.
146395
+*/
146396
+static void fts3CursorFinalizeStmt(Fts3Cursor *pCsr){
146397
+ if( pCsr->bSeekStmt ){
146398
+ Fts3Table *p = (Fts3Table *)pCsr->base.pVtab;
146399
+ if( p->pSeekStmt==0 ){
146400
+ p->pSeekStmt = pCsr->pStmt;
146401
+ sqlite3_reset(pCsr->pStmt);
146402
+ pCsr->pStmt = 0;
146403
+ }
146404
+ pCsr->bSeekStmt = 0;
146405
+ }
146406
+ sqlite3_finalize(pCsr->pStmt);
146407
+}
145996146408
145997146409
/*
145998146410
** Close the cursor. For additional information see the documentation
145999146411
** on the xClose method of the virtual table interface.
146000146412
*/
146001146413
static int fts3CloseMethod(sqlite3_vtab_cursor *pCursor){
146002146414
Fts3Cursor *pCsr = (Fts3Cursor *)pCursor;
146003146415
assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
146004
- sqlite3_finalize(pCsr->pStmt);
146416
+ fts3CursorFinalizeStmt(pCsr);
146005146417
sqlite3Fts3ExprFree(pCsr->pExpr);
146006146418
sqlite3Fts3FreeDeferredTokens(pCsr);
146007146419
sqlite3_free(pCsr->aDoclist);
146008146420
sqlite3Fts3MIBufferFree(pCsr->pMIBuffer);
146009146421
assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
@@ -146017,24 +146429,27 @@
146017146429
**
146018146430
** "SELECT <columns> FROM %_content WHERE rowid = ?"
146019146431
**
146020146432
** (or the equivalent for a content=xxx table) and set pCsr->pStmt to
146021146433
** it. If an error occurs, return an SQLite error code.
146022
-**
146023
-** Otherwise, set *ppStmt to point to pCsr->pStmt and return SQLITE_OK.
146024146434
*/
146025
-static int fts3CursorSeekStmt(Fts3Cursor *pCsr, sqlite3_stmt **ppStmt){
146435
+static int fts3CursorSeekStmt(Fts3Cursor *pCsr){
146026146436
int rc = SQLITE_OK;
146027146437
if( pCsr->pStmt==0 ){
146028146438
Fts3Table *p = (Fts3Table *)pCsr->base.pVtab;
146029146439
char *zSql;
146030
- zSql = sqlite3_mprintf("SELECT %s WHERE rowid = ?", p->zReadExprlist);
146031
- if( !zSql ) return SQLITE_NOMEM;
146032
- rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0);
146033
- sqlite3_free(zSql);
146440
+ if( p->pSeekStmt ){
146441
+ pCsr->pStmt = p->pSeekStmt;
146442
+ p->pSeekStmt = 0;
146443
+ }else{
146444
+ zSql = sqlite3_mprintf("SELECT %s WHERE rowid = ?", p->zReadExprlist);
146445
+ if( !zSql ) return SQLITE_NOMEM;
146446
+ rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0);
146447
+ sqlite3_free(zSql);
146448
+ }
146449
+ if( rc==SQLITE_OK ) pCsr->bSeekStmt = 1;
146034146450
}
146035
- *ppStmt = pCsr->pStmt;
146036146451
return rc;
146037146452
}
146038146453
146039146454
/*
146040146455
** Position the pCsr->pStmt statement so that it is on the row
@@ -146042,13 +146457,11 @@
146042146457
** SQLITE_OK on success.
146043146458
*/
146044146459
static int fts3CursorSeek(sqlite3_context *pContext, Fts3Cursor *pCsr){
146045146460
int rc = SQLITE_OK;
146046146461
if( pCsr->isRequireSeek ){
146047
- sqlite3_stmt *pStmt = 0;
146048
-
146049
- rc = fts3CursorSeekStmt(pCsr, &pStmt);
146462
+ rc = fts3CursorSeekStmt(pCsr);
146050146463
if( rc==SQLITE_OK ){
146051146464
sqlite3_bind_int64(pCsr->pStmt, 1, pCsr->iPrevId);
146052146465
pCsr->isRequireSeek = 0;
146053146466
if( SQLITE_ROW==sqlite3_step(pCsr->pStmt) ){
146054146467
return SQLITE_OK;
@@ -147502,11 +147915,11 @@
147502147915
if( idxNum & FTS3_HAVE_DOCID_GE ) pDocidGe = apVal[iIdx++];
147503147916
if( idxNum & FTS3_HAVE_DOCID_LE ) pDocidLe = apVal[iIdx++];
147504147917
assert( iIdx==nVal );
147505147918
147506147919
/* In case the cursor has been used before, clear it now. */
147507
- sqlite3_finalize(pCsr->pStmt);
147920
+ fts3CursorFinalizeStmt(pCsr);
147508147921
sqlite3_free(pCsr->aDoclist);
147509147922
sqlite3Fts3MIBufferFree(pCsr->pMIBuffer);
147510147923
sqlite3Fts3ExprFree(pCsr->pExpr);
147511147924
memset(&pCursor[1], 0, sizeof(Fts3Cursor)-sizeof(sqlite3_vtab_cursor));
147512147925
@@ -147570,11 +147983,11 @@
147570147983
sqlite3_free(zSql);
147571147984
}else{
147572147985
rc = SQLITE_NOMEM;
147573147986
}
147574147987
}else if( eSearch==FTS3_DOCID_SEARCH ){
147575
- rc = fts3CursorSeekStmt(pCsr, &pCsr->pStmt);
147988
+ rc = fts3CursorSeekStmt(pCsr);
147576147989
if( rc==SQLITE_OK ){
147577147990
rc = sqlite3_bind_value(pCsr->pStmt, 1, pCons);
147578147991
}
147579147992
}
147580147993
if( rc!=SQLITE_OK ) return rc;
@@ -147734,11 +148147,11 @@
147734148147
sqlite3_stmt *pStmt = 0;
147735148148
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
147736148149
if( rc==SQLITE_OK ){
147737148150
int bHasStat = (sqlite3_step(pStmt)==SQLITE_ROW);
147738148151
rc = sqlite3_finalize(pStmt);
147739
- if( rc==SQLITE_OK ) p->bHasStat = bHasStat;
148152
+ if( rc==SQLITE_OK ) p->bHasStat = (u8)bHasStat;
147740148153
}
147741148154
sqlite3_free(zSql);
147742148155
}else{
147743148156
rc = SQLITE_NOMEM;
147744148157
}
@@ -162590,10 +163003,11 @@
162590163003
/* #include <stdio.h> */
162591163004
162592163005
#ifndef SQLITE_AMALGAMATION
162593163006
#include "sqlite3rtree.h"
162594163007
typedef sqlite3_int64 i64;
163008
+typedef sqlite3_uint64 u64;
162595163009
typedef unsigned char u8;
162596163010
typedef unsigned short u16;
162597163011
typedef unsigned int u32;
162598163012
#endif
162599163013
@@ -162638,28 +163052,33 @@
162638163052
struct Rtree {
162639163053
sqlite3_vtab base; /* Base class. Must be first */
162640163054
sqlite3 *db; /* Host database connection */
162641163055
int iNodeSize; /* Size in bytes of each node in the node table */
162642163056
u8 nDim; /* Number of dimensions */
163057
+ u8 nDim2; /* Twice the number of dimensions */
162643163058
u8 eCoordType; /* RTREE_COORD_REAL32 or RTREE_COORD_INT32 */
162644163059
u8 nBytesPerCell; /* Bytes consumed per cell */
163060
+ u8 inWrTrans; /* True if inside write transaction */
162645163061
int iDepth; /* Current depth of the r-tree structure */
162646163062
char *zDb; /* Name of database containing r-tree table */
162647163063
char *zName; /* Name of r-tree table */
162648
- int nBusy; /* Current number of users of this structure */
163064
+ u32 nBusy; /* Current number of users of this structure */
162649163065
i64 nRowEst; /* Estimated number of rows in this table */
163066
+ u32 nCursor; /* Number of open cursors */
162650163067
162651163068
/* List of nodes removed during a CondenseTree operation. List is
162652163069
** linked together via the pointer normally used for hash chains -
162653163070
** RtreeNode.pNext. RtreeNode.iNode stores the depth of the sub-tree
162654163071
** headed by the node (leaf nodes have RtreeNode.iNode==0).
162655163072
*/
162656163073
RtreeNode *pDeleted;
162657163074
int iReinsertHeight; /* Height of sub-trees Reinsert() has run on */
163075
+
163076
+ /* Blob I/O on xxx_node */
163077
+ sqlite3_blob *pNodeBlob;
162658163078
162659163079
/* Statements to read/write/delete a record from xxx_node */
162660
- sqlite3_stmt *pReadNode;
162661163080
sqlite3_stmt *pWriteNode;
162662163081
sqlite3_stmt *pDeleteNode;
162663163082
162664163083
/* Statements to read/write/delete a record from xxx_rowid */
162665163084
sqlite3_stmt *pReadRowid;
@@ -162884,26 +163303,100 @@
162884163303
#endif
162885163304
#ifndef MIN
162886163305
# define MIN(x,y) ((x) > (y) ? (y) : (x))
162887163306
#endif
162888163307
163308
+/* What version of GCC is being used. 0 means GCC is not being used .
163309
+** Note that the GCC_VERSION macro will also be set correctly when using
163310
+** clang, since clang works hard to be gcc compatible. So the gcc
163311
+** optimizations will also work when compiling with clang.
163312
+*/
163313
+#ifndef GCC_VERSION
163314
+#if defined(__GNUC__) && !defined(SQLITE_DISABLE_INTRINSIC)
163315
+# define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__)
163316
+#else
163317
+# define GCC_VERSION 0
163318
+#endif
163319
+#endif
163320
+
163321
+/* The testcase() macro should already be defined in the amalgamation. If
163322
+** it is not, make it a no-op.
163323
+*/
163324
+#ifndef SQLITE_AMALGAMATION
163325
+# define testcase(X)
163326
+#endif
163327
+
163328
+/*
163329
+** Macros to determine whether the machine is big or little endian,
163330
+** and whether or not that determination is run-time or compile-time.
163331
+**
163332
+** For best performance, an attempt is made to guess at the byte-order
163333
+** using C-preprocessor macros. If that is unsuccessful, or if
163334
+** -DSQLITE_RUNTIME_BYTEORDER=1 is set, then byte-order is determined
163335
+** at run-time.
163336
+*/
163337
+#ifndef SQLITE_BYTEORDER
163338
+#if defined(i386) || defined(__i386__) || defined(_M_IX86) || \
163339
+ defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \
163340
+ defined(_M_AMD64) || defined(_M_ARM) || defined(__x86) || \
163341
+ defined(__arm__)
163342
+# define SQLITE_BYTEORDER 1234
163343
+#elif defined(sparc) || defined(__ppc__)
163344
+# define SQLITE_BYTEORDER 4321
163345
+#else
163346
+# define SQLITE_BYTEORDER 0 /* 0 means "unknown at compile-time" */
163347
+#endif
163348
+#endif
163349
+
163350
+
163351
+/* What version of MSVC is being used. 0 means MSVC is not being used */
163352
+#ifndef MSVC_VERSION
163353
+#if defined(_MSC_VER) && !defined(SQLITE_DISABLE_INTRINSIC)
163354
+# define MSVC_VERSION _MSC_VER
163355
+#else
163356
+# define MSVC_VERSION 0
163357
+#endif
163358
+#endif
163359
+
162889163360
/*
162890163361
** Functions to deserialize a 16 bit integer, 32 bit real number and
162891163362
** 64 bit integer. The deserialized value is returned.
162892163363
*/
162893163364
static int readInt16(u8 *p){
162894163365
return (p[0]<<8) + p[1];
162895163366
}
162896163367
static void readCoord(u8 *p, RtreeCoord *pCoord){
163368
+ assert( ((((char*)p) - (char*)0)&3)==0 ); /* p is always 4-byte aligned */
163369
+#if SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
163370
+ pCoord->u = _byteswap_ulong(*(u32*)p);
163371
+#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
163372
+ pCoord->u = __builtin_bswap32(*(u32*)p);
163373
+#elif SQLITE_BYTEORDER==4321
163374
+ pCoord->u = *(u32*)p;
163375
+#else
162897163376
pCoord->u = (
162898163377
(((u32)p[0]) << 24) +
162899163378
(((u32)p[1]) << 16) +
162900163379
(((u32)p[2]) << 8) +
162901163380
(((u32)p[3]) << 0)
162902163381
);
163382
+#endif
162903163383
}
162904163384
static i64 readInt64(u8 *p){
163385
+#if SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
163386
+ u64 x;
163387
+ memcpy(&x, p, 8);
163388
+ return (i64)_byteswap_uint64(x);
163389
+#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
163390
+ u64 x;
163391
+ memcpy(&x, p, 8);
163392
+ return (i64)__builtin_bswap64(x);
163393
+#elif SQLITE_BYTEORDER==4321
163394
+ i64 x;
163395
+ memcpy(&x, p, 8);
163396
+ return x;
163397
+#else
162905163398
return (
162906163399
(((i64)p[0]) << 56) +
162907163400
(((i64)p[1]) << 48) +
162908163401
(((i64)p[2]) << 40) +
162909163402
(((i64)p[3]) << 32) +
@@ -162910,42 +163403,64 @@
162910163403
(((i64)p[4]) << 24) +
162911163404
(((i64)p[5]) << 16) +
162912163405
(((i64)p[6]) << 8) +
162913163406
(((i64)p[7]) << 0)
162914163407
);
163408
+#endif
162915163409
}
162916163410
162917163411
/*
162918163412
** Functions to serialize a 16 bit integer, 32 bit real number and
162919163413
** 64 bit integer. The value returned is the number of bytes written
162920163414
** to the argument buffer (always 2, 4 and 8 respectively).
162921163415
*/
162922
-static int writeInt16(u8 *p, int i){
163416
+static void writeInt16(u8 *p, int i){
162923163417
p[0] = (i>> 8)&0xFF;
162924163418
p[1] = (i>> 0)&0xFF;
162925
- return 2;
162926163419
}
162927163420
static int writeCoord(u8 *p, RtreeCoord *pCoord){
162928163421
u32 i;
163422
+ assert( ((((char*)p) - (char*)0)&3)==0 ); /* p is always 4-byte aligned */
162929163423
assert( sizeof(RtreeCoord)==4 );
162930163424
assert( sizeof(u32)==4 );
163425
+#if SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
163426
+ i = __builtin_bswap32(pCoord->u);
163427
+ memcpy(p, &i, 4);
163428
+#elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
163429
+ i = _byteswap_ulong(pCoord->u);
163430
+ memcpy(p, &i, 4);
163431
+#elif SQLITE_BYTEORDER==4321
163432
+ i = pCoord->u;
163433
+ memcpy(p, &i, 4);
163434
+#else
162931163435
i = pCoord->u;
162932163436
p[0] = (i>>24)&0xFF;
162933163437
p[1] = (i>>16)&0xFF;
162934163438
p[2] = (i>> 8)&0xFF;
162935163439
p[3] = (i>> 0)&0xFF;
163440
+#endif
162936163441
return 4;
162937163442
}
162938163443
static int writeInt64(u8 *p, i64 i){
163444
+#if SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
163445
+ i = (i64)__builtin_bswap64((u64)i);
163446
+ memcpy(p, &i, 8);
163447
+#elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
163448
+ i = (i64)_byteswap_uint64((u64)i);
163449
+ memcpy(p, &i, 8);
163450
+#elif SQLITE_BYTEORDER==4321
163451
+ memcpy(p, &i, 8);
163452
+#else
162939163453
p[0] = (i>>56)&0xFF;
162940163454
p[1] = (i>>48)&0xFF;
162941163455
p[2] = (i>>40)&0xFF;
162942163456
p[3] = (i>>32)&0xFF;
162943163457
p[4] = (i>>24)&0xFF;
162944163458
p[5] = (i>>16)&0xFF;
162945163459
p[6] = (i>> 8)&0xFF;
162946163460
p[7] = (i>> 0)&0xFF;
163461
+#endif
162947163462
return 8;
162948163463
}
162949163464
162950163465
/*
162951163466
** Increment the reference count of node p.
@@ -163023,10 +163538,21 @@
163023163538
pNode->isDirty = 1;
163024163539
nodeReference(pParent);
163025163540
}
163026163541
return pNode;
163027163542
}
163543
+
163544
+/*
163545
+** Clear the Rtree.pNodeBlob object
163546
+*/
163547
+static void nodeBlobReset(Rtree *pRtree){
163548
+ if( pRtree->pNodeBlob && pRtree->inWrTrans==0 && pRtree->nCursor==0 ){
163549
+ sqlite3_blob *pBlob = pRtree->pNodeBlob;
163550
+ pRtree->pNodeBlob = 0;
163551
+ sqlite3_blob_close(pBlob);
163552
+ }
163553
+}
163028163554
163029163555
/*
163030163556
** Obtain a reference to an r-tree node.
163031163557
*/
163032163558
static int nodeAcquire(
@@ -163033,13 +163559,12 @@
163033163559
Rtree *pRtree, /* R-tree structure */
163034163560
i64 iNode, /* Node number to load */
163035163561
RtreeNode *pParent, /* Either the parent node or NULL */
163036163562
RtreeNode **ppNode /* OUT: Acquired node */
163037163563
){
163038
- int rc;
163039
- int rc2 = SQLITE_OK;
163040
- RtreeNode *pNode;
163564
+ int rc = SQLITE_OK;
163565
+ RtreeNode *pNode = 0;
163041163566
163042163567
/* Check if the requested node is already in the hash table. If so,
163043163568
** increase its reference count and return it.
163044163569
*/
163045163570
if( (pNode = nodeHashLookup(pRtree, iNode)) ){
@@ -163051,32 +163576,49 @@
163051163576
pNode->nRef++;
163052163577
*ppNode = pNode;
163053163578
return SQLITE_OK;
163054163579
}
163055163580
163056
- sqlite3_bind_int64(pRtree->pReadNode, 1, iNode);
163057
- rc = sqlite3_step(pRtree->pReadNode);
163058
- if( rc==SQLITE_ROW ){
163059
- const u8 *zBlob = sqlite3_column_blob(pRtree->pReadNode, 0);
163060
- if( pRtree->iNodeSize==sqlite3_column_bytes(pRtree->pReadNode, 0) ){
163061
- pNode = (RtreeNode *)sqlite3_malloc(sizeof(RtreeNode)+pRtree->iNodeSize);
163062
- if( !pNode ){
163063
- rc2 = SQLITE_NOMEM;
163064
- }else{
163065
- pNode->pParent = pParent;
163066
- pNode->zData = (u8 *)&pNode[1];
163067
- pNode->nRef = 1;
163068
- pNode->iNode = iNode;
163069
- pNode->isDirty = 0;
163070
- pNode->pNext = 0;
163071
- memcpy(pNode->zData, zBlob, pRtree->iNodeSize);
163072
- nodeReference(pParent);
163073
- }
163074
- }
163075
- }
163076
- rc = sqlite3_reset(pRtree->pReadNode);
163077
- if( rc==SQLITE_OK ) rc = rc2;
163581
+ if( pRtree->pNodeBlob ){
163582
+ sqlite3_blob *pBlob = pRtree->pNodeBlob;
163583
+ pRtree->pNodeBlob = 0;
163584
+ rc = sqlite3_blob_reopen(pBlob, iNode);
163585
+ pRtree->pNodeBlob = pBlob;
163586
+ if( rc ){
163587
+ nodeBlobReset(pRtree);
163588
+ if( rc==SQLITE_NOMEM ) return SQLITE_NOMEM;
163589
+ }
163590
+ }
163591
+ if( pRtree->pNodeBlob==0 ){
163592
+ char *zTab = sqlite3_mprintf("%s_node", pRtree->zName);
163593
+ if( zTab==0 ) return SQLITE_NOMEM;
163594
+ rc = sqlite3_blob_open(pRtree->db, pRtree->zDb, zTab, "data", iNode, 0,
163595
+ &pRtree->pNodeBlob);
163596
+ sqlite3_free(zTab);
163597
+ }
163598
+ if( rc ){
163599
+ nodeBlobReset(pRtree);
163600
+ *ppNode = 0;
163601
+ /* If unable to open an sqlite3_blob on the desired row, that can only
163602
+ ** be because the shadow tables hold erroneous data. */
163603
+ if( rc==SQLITE_ERROR ) rc = SQLITE_CORRUPT_VTAB;
163604
+ }else if( pRtree->iNodeSize==sqlite3_blob_bytes(pRtree->pNodeBlob) ){
163605
+ pNode = (RtreeNode *)sqlite3_malloc(sizeof(RtreeNode)+pRtree->iNodeSize);
163606
+ if( !pNode ){
163607
+ rc = SQLITE_NOMEM;
163608
+ }else{
163609
+ pNode->pParent = pParent;
163610
+ pNode->zData = (u8 *)&pNode[1];
163611
+ pNode->nRef = 1;
163612
+ pNode->iNode = iNode;
163613
+ pNode->isDirty = 0;
163614
+ pNode->pNext = 0;
163615
+ rc = sqlite3_blob_read(pRtree->pNodeBlob, pNode->zData,
163616
+ pRtree->iNodeSize, 0);
163617
+ nodeReference(pParent);
163618
+ }
163619
+ }
163078163620
163079163621
/* If the root node was just loaded, set pRtree->iDepth to the height
163080163622
** of the r-tree structure. A height of zero means all data is stored on
163081163623
** the root node. A height of one means the children of the root node
163082163624
** are the leaves, and so on. If the depth as specified on the root node
@@ -163124,11 +163666,11 @@
163124163666
int iCell /* Index into pNode into which pCell is written */
163125163667
){
163126163668
int ii;
163127163669
u8 *p = &pNode->zData[4 + pRtree->nBytesPerCell*iCell];
163128163670
p += writeInt64(p, pCell->iRowid);
163129
- for(ii=0; ii<(pRtree->nDim*2); ii++){
163671
+ for(ii=0; ii<pRtree->nDim2; ii++){
163130163672
p += writeCoord(p, &pCell->aCoord[ii]);
163131163673
}
163132163674
pNode->isDirty = 1;
163133163675
}
163134163676
@@ -163258,17 +163800,20 @@
163258163800
int iCell, /* Index of the cell within the node */
163259163801
RtreeCell *pCell /* OUT: Write the cell contents here */
163260163802
){
163261163803
u8 *pData;
163262163804
RtreeCoord *pCoord;
163263
- int ii;
163805
+ int ii = 0;
163264163806
pCell->iRowid = nodeGetRowid(pRtree, pNode, iCell);
163265163807
pData = pNode->zData + (12 + pRtree->nBytesPerCell*iCell);
163266163808
pCoord = pCell->aCoord;
163267
- for(ii=0; ii<pRtree->nDim*2; ii++){
163268
- readCoord(&pData[ii*4], &pCoord[ii]);
163269
- }
163809
+ do{
163810
+ readCoord(pData, &pCoord[ii]);
163811
+ readCoord(pData+4, &pCoord[ii+1]);
163812
+ pData += 8;
163813
+ ii += 2;
163814
+ }while( ii<pRtree->nDim2 );
163270163815
}
163271163816
163272163817
163273163818
/* Forward declaration for the function that does the work of
163274163819
** the virtual table module xCreate() and xConnect() methods.
@@ -163315,11 +163860,13 @@
163315163860
** zero the structure is deleted.
163316163861
*/
163317163862
static void rtreeRelease(Rtree *pRtree){
163318163863
pRtree->nBusy--;
163319163864
if( pRtree->nBusy==0 ){
163320
- sqlite3_finalize(pRtree->pReadNode);
163865
+ pRtree->inWrTrans = 0;
163866
+ pRtree->nCursor = 0;
163867
+ nodeBlobReset(pRtree);
163321163868
sqlite3_finalize(pRtree->pWriteNode);
163322163869
sqlite3_finalize(pRtree->pDeleteNode);
163323163870
sqlite3_finalize(pRtree->pReadRowid);
163324163871
sqlite3_finalize(pRtree->pWriteRowid);
163325163872
sqlite3_finalize(pRtree->pDeleteRowid);
@@ -163353,10 +163900,11 @@
163353163900
pRtree->zDb, pRtree->zName
163354163901
);
163355163902
if( !zCreate ){
163356163903
rc = SQLITE_NOMEM;
163357163904
}else{
163905
+ nodeBlobReset(pRtree);
163358163906
rc = sqlite3_exec(pRtree->db, zCreate, 0, 0, 0);
163359163907
sqlite3_free(zCreate);
163360163908
}
163361163909
if( rc==SQLITE_OK ){
163362163910
rtreeRelease(pRtree);
@@ -163368,17 +163916,19 @@
163368163916
/*
163369163917
** Rtree virtual table module xOpen method.
163370163918
*/
163371163919
static int rtreeOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
163372163920
int rc = SQLITE_NOMEM;
163921
+ Rtree *pRtree = (Rtree *)pVTab;
163373163922
RtreeCursor *pCsr;
163374163923
163375163924
pCsr = (RtreeCursor *)sqlite3_malloc(sizeof(RtreeCursor));
163376163925
if( pCsr ){
163377163926
memset(pCsr, 0, sizeof(RtreeCursor));
163378163927
pCsr->base.pVtab = pVTab;
163379163928
rc = SQLITE_OK;
163929
+ pRtree->nCursor++;
163380163930
}
163381163931
*ppCursor = (sqlite3_vtab_cursor *)pCsr;
163382163932
163383163933
return rc;
163384163934
}
@@ -163407,14 +163957,17 @@
163407163957
*/
163408163958
static int rtreeClose(sqlite3_vtab_cursor *cur){
163409163959
Rtree *pRtree = (Rtree *)(cur->pVtab);
163410163960
int ii;
163411163961
RtreeCursor *pCsr = (RtreeCursor *)cur;
163962
+ assert( pRtree->nCursor>0 );
163412163963
freeCursorConstraints(pCsr);
163413163964
sqlite3_free(pCsr->aPoint);
163414163965
for(ii=0; ii<RTREE_CACHE_SZ; ii++) nodeRelease(pRtree, pCsr->aNode[ii]);
163415163966
sqlite3_free(pCsr);
163967
+ pRtree->nCursor--;
163968
+ nodeBlobReset(pRtree);
163416163969
return SQLITE_OK;
163417163970
}
163418163971
163419163972
/*
163420163973
** Rtree virtual table module xEof method.
@@ -163433,27 +163986,34 @@
163433163986
** endian platforms. The on-disk record stores integer coordinates if
163434163987
** eInt is true and it stores 32-bit floating point records if eInt is
163435163988
** false. a[] is the four bytes of the on-disk record to be decoded.
163436163989
** Store the results in "r".
163437163990
**
163438
-** There are three versions of this macro, one each for little-endian and
163439
-** big-endian processors and a third generic implementation. The endian-
163440
-** specific implementations are much faster and are preferred if the
163441
-** processor endianness is known at compile-time. The SQLITE_BYTEORDER
163442
-** macro is part of sqliteInt.h and hence the endian-specific
163443
-** implementation will only be used if this module is compiled as part
163444
-** of the amalgamation.
163991
+** There are five versions of this macro. The last one is generic. The
163992
+** other four are various architectures-specific optimizations.
163445163993
*/
163446
-#if defined(SQLITE_BYTEORDER) && SQLITE_BYTEORDER==1234
163994
+#if SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
163995
+#define RTREE_DECODE_COORD(eInt, a, r) { \
163996
+ RtreeCoord c; /* Coordinate decoded */ \
163997
+ c.u = _byteswap_ulong(*(u32*)a); \
163998
+ r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \
163999
+}
164000
+#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
164001
+#define RTREE_DECODE_COORD(eInt, a, r) { \
164002
+ RtreeCoord c; /* Coordinate decoded */ \
164003
+ c.u = __builtin_bswap32(*(u32*)a); \
164004
+ r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \
164005
+}
164006
+#elif SQLITE_BYTEORDER==1234
163447164007
#define RTREE_DECODE_COORD(eInt, a, r) { \
163448164008
RtreeCoord c; /* Coordinate decoded */ \
163449164009
memcpy(&c.u,a,4); \
163450164010
c.u = ((c.u>>24)&0xff)|((c.u>>8)&0xff00)| \
163451164011
((c.u&0xff)<<24)|((c.u&0xff00)<<8); \
163452164012
r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \
163453164013
}
163454
-#elif defined(SQLITE_BYTEORDER) && SQLITE_BYTEORDER==4321
164014
+#elif SQLITE_BYTEORDER==4321
163455164015
#define RTREE_DECODE_COORD(eInt, a, r) { \
163456164016
RtreeCoord c; /* Coordinate decoded */ \
163457164017
memcpy(&c.u,a,4); \
163458164018
r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \
163459164019
}
@@ -163476,30 +164036,58 @@
163476164036
u8 *pCellData, /* Raw cell content */
163477164037
RtreeSearchPoint *pSearch, /* Container of this cell */
163478164038
sqlite3_rtree_dbl *prScore, /* OUT: score for the cell */
163479164039
int *peWithin /* OUT: visibility of the cell */
163480164040
){
163481
- int i; /* Loop counter */
163482164041
sqlite3_rtree_query_info *pInfo = pConstraint->pInfo; /* Callback info */
163483164042
int nCoord = pInfo->nCoord; /* No. of coordinates */
163484164043
int rc; /* Callback return code */
164044
+ RtreeCoord c; /* Translator union */
163485164045
sqlite3_rtree_dbl aCoord[RTREE_MAX_DIMENSIONS*2]; /* Decoded coordinates */
163486164046
163487164047
assert( pConstraint->op==RTREE_MATCH || pConstraint->op==RTREE_QUERY );
163488164048
assert( nCoord==2 || nCoord==4 || nCoord==6 || nCoord==8 || nCoord==10 );
163489164049
163490164050
if( pConstraint->op==RTREE_QUERY && pSearch->iLevel==1 ){
163491164051
pInfo->iRowid = readInt64(pCellData);
163492164052
}
163493164053
pCellData += 8;
163494
- for(i=0; i<nCoord; i++, pCellData += 4){
163495
- RTREE_DECODE_COORD(eInt, pCellData, aCoord[i]);
164054
+#ifndef SQLITE_RTREE_INT_ONLY
164055
+ if( eInt==0 ){
164056
+ switch( nCoord ){
164057
+ case 10: readCoord(pCellData+36, &c); aCoord[9] = c.f;
164058
+ readCoord(pCellData+32, &c); aCoord[8] = c.f;
164059
+ case 8: readCoord(pCellData+28, &c); aCoord[7] = c.f;
164060
+ readCoord(pCellData+24, &c); aCoord[6] = c.f;
164061
+ case 6: readCoord(pCellData+20, &c); aCoord[5] = c.f;
164062
+ readCoord(pCellData+16, &c); aCoord[4] = c.f;
164063
+ case 4: readCoord(pCellData+12, &c); aCoord[3] = c.f;
164064
+ readCoord(pCellData+8, &c); aCoord[2] = c.f;
164065
+ default: readCoord(pCellData+4, &c); aCoord[1] = c.f;
164066
+ readCoord(pCellData, &c); aCoord[0] = c.f;
164067
+ }
164068
+ }else
164069
+#endif
164070
+ {
164071
+ switch( nCoord ){
164072
+ case 10: readCoord(pCellData+36, &c); aCoord[9] = c.i;
164073
+ readCoord(pCellData+32, &c); aCoord[8] = c.i;
164074
+ case 8: readCoord(pCellData+28, &c); aCoord[7] = c.i;
164075
+ readCoord(pCellData+24, &c); aCoord[6] = c.i;
164076
+ case 6: readCoord(pCellData+20, &c); aCoord[5] = c.i;
164077
+ readCoord(pCellData+16, &c); aCoord[4] = c.i;
164078
+ case 4: readCoord(pCellData+12, &c); aCoord[3] = c.i;
164079
+ readCoord(pCellData+8, &c); aCoord[2] = c.i;
164080
+ default: readCoord(pCellData+4, &c); aCoord[1] = c.i;
164081
+ readCoord(pCellData, &c); aCoord[0] = c.i;
164082
+ }
163496164083
}
163497164084
if( pConstraint->op==RTREE_MATCH ){
164085
+ int eWithin = 0;
163498164086
rc = pConstraint->u.xGeom((sqlite3_rtree_geometry*)pInfo,
163499
- nCoord, aCoord, &i);
163500
- if( i==0 ) *peWithin = NOT_WITHIN;
164087
+ nCoord, aCoord, &eWithin);
164088
+ if( eWithin==0 ) *peWithin = NOT_WITHIN;
163501164089
*prScore = RTREE_ZERO;
163502164090
}else{
163503164091
pInfo->aCoord = aCoord;
163504164092
pInfo->iLevel = pSearch->iLevel - 1;
163505164093
pInfo->rScore = pInfo->rParentScore = pSearch->rScore;
@@ -163531,10 +164119,11 @@
163531164119
*/
163532164120
pCellData += 8 + 4*(p->iCoord&0xfe);
163533164121
163534164122
assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
163535164123
|| p->op==RTREE_GT || p->op==RTREE_EQ );
164124
+ assert( ((((char*)pCellData) - (char*)0)&3)==0 ); /* 4-byte aligned */
163536164125
switch( p->op ){
163537164126
case RTREE_LE:
163538164127
case RTREE_LT:
163539164128
case RTREE_EQ:
163540164129
RTREE_DECODE_COORD(eInt, pCellData, val);
@@ -163571,10 +164160,11 @@
163571164160
RtreeDValue xN; /* Coordinate value converted to a double */
163572164161
163573164162
assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
163574164163
|| p->op==RTREE_GT || p->op==RTREE_EQ );
163575164164
pCellData += 8 + p->iCoord*4;
164165
+ assert( ((((char*)pCellData) - (char*)0)&3)==0 ); /* 4-byte aligned */
163576164166
RTREE_DECODE_COORD(eInt, pCellData, xN);
163577164167
switch( p->op ){
163578164168
case RTREE_LE: if( xN <= p->u.rValue ) return; break;
163579164169
case RTREE_LT: if( xN < p->u.rValue ) return; break;
163580164170
case RTREE_GE: if( xN >= p->u.rValue ) return; break;
@@ -163639,11 +164229,11 @@
163639164229
if( pA->iLevel>pB->iLevel ) return +1;
163640164230
return 0;
163641164231
}
163642164232
163643164233
/*
163644
-** Interchange to search points in a cursor.
164234
+** Interchange two search points in a cursor.
163645164235
*/
163646164236
static void rtreeSearchPointSwap(RtreeCursor *p, int i, int j){
163647164237
RtreeSearchPoint t = p->aPoint[i];
163648164238
assert( i<j );
163649164239
p->aPoint[i] = p->aPoint[j];
@@ -163887,11 +164477,11 @@
163887164477
rtreeSearchPointPop(pCur);
163888164478
}
163889164479
if( rScore<RTREE_ZERO ) rScore = RTREE_ZERO;
163890164480
p = rtreeSearchPointNew(pCur, rScore, x.iLevel);
163891164481
if( p==0 ) return SQLITE_NOMEM;
163892
- p->eWithin = eWithin;
164482
+ p->eWithin = (u8)eWithin;
163893164483
p->id = x.id;
163894164484
p->iCell = x.iCell;
163895164485
RTREE_QUEUE_TRACE(pCur, "PUSH-S:");
163896164486
break;
163897164487
}
@@ -163946,11 +164536,10 @@
163946164536
if( rc ) return rc;
163947164537
if( p==0 ) return SQLITE_OK;
163948164538
if( i==0 ){
163949164539
sqlite3_result_int64(ctx, nodeGetRowid(pRtree, pNode, p->iCell));
163950164540
}else{
163951
- if( rc ) return rc;
163952164541
nodeGetCoord(pRtree, pNode, p->iCell, i-1, &c);
163953164542
#ifndef SQLITE_RTREE_INT_ONLY
163954164543
if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
163955164544
sqlite3_result_double(ctx, c.f);
163956164545
}else
@@ -164075,11 +164664,11 @@
164075164664
assert( p!=0 ); /* Always returns pCsr->sPoint */
164076164665
pCsr->aNode[0] = pLeaf;
164077164666
p->id = iNode;
164078164667
p->eWithin = PARTLY_WITHIN;
164079164668
rc = nodeRowidIndex(pRtree, pLeaf, iRowid, &iCell);
164080
- p->iCell = iCell;
164669
+ p->iCell = (u8)iCell;
164081164670
RTREE_QUEUE_TRACE(pCsr, "PUSH-F1:");
164082164671
}else{
164083164672
pCsr->atEOF = 1;
164084164673
}
164085164674
}else{
@@ -164108,11 +164697,11 @@
164108164697
*/
164109164698
rc = deserializeGeometry(argv[ii], p);
164110164699
if( rc!=SQLITE_OK ){
164111164700
break;
164112164701
}
164113
- p->pInfo->nCoord = pRtree->nDim*2;
164702
+ p->pInfo->nCoord = pRtree->nDim2;
164114164703
p->pInfo->anQueue = pCsr->anQueue;
164115164704
p->pInfo->mxLevel = pRtree->iDepth + 1;
164116164705
}else{
164117164706
#ifdef SQLITE_RTREE_INT_ONLY
164118164707
p->u.rValue = sqlite3_value_int64(argv[ii]);
@@ -164123,11 +164712,11 @@
164123164712
}
164124164713
}
164125164714
}
164126164715
if( rc==SQLITE_OK ){
164127164716
RtreeSearchPoint *pNew;
164128
- pNew = rtreeSearchPointNew(pCsr, RTREE_ZERO, pRtree->iDepth+1);
164717
+ pNew = rtreeSearchPointNew(pCsr, RTREE_ZERO, (u8)(pRtree->iDepth+1));
164129164718
if( pNew==0 ) return SQLITE_NOMEM;
164130164719
pNew->id = 1;
164131164720
pNew->iCell = 0;
164132164721
pNew->eWithin = PARTLY_WITHIN;
164133164722
assert( pCsr->bPoint==1 );
@@ -164141,23 +164730,10 @@
164141164730
nodeRelease(pRtree, pRoot);
164142164731
rtreeRelease(pRtree);
164143164732
return rc;
164144164733
}
164145164734
164146
-/*
164147
-** Set the pIdxInfo->estimatedRows variable to nRow. Unless this
164148
-** extension is currently being used by a version of SQLite too old to
164149
-** support estimatedRows. In that case this function is a no-op.
164150
-*/
164151
-static void setEstimatedRows(sqlite3_index_info *pIdxInfo, i64 nRow){
164152
-#if SQLITE_VERSION_NUMBER>=3008002
164153
- if( sqlite3_libversion_number()>=3008002 ){
164154
- pIdxInfo->estimatedRows = nRow;
164155
- }
164156
-#endif
164157
-}
164158
-
164159164735
/*
164160164736
** Rtree virtual table module xBestIndex method. There are three
164161164737
** table scan strategies to choose from (in order from most to
164162164738
** least desirable):
164163164739
**
@@ -164233,11 +164809,11 @@
164233164809
** considered almost as quick as a direct rowid lookup (for which
164234164810
** sqlite uses an internal cost of 0.0). It is expected to return
164235164811
** a single row.
164236164812
*/
164237164813
pIdxInfo->estimatedCost = 30.0;
164238
- setEstimatedRows(pIdxInfo, 1);
164814
+ pIdxInfo->estimatedRows = 1;
164239164815
return SQLITE_OK;
164240164816
}
164241164817
164242164818
if( p->usable && (p->iColumn>0 || p->op==SQLITE_INDEX_CONSTRAINT_MATCH) ){
164243164819
u8 op;
@@ -164251,11 +164827,11 @@
164251164827
assert( p->op==SQLITE_INDEX_CONSTRAINT_MATCH );
164252164828
op = RTREE_MATCH;
164253164829
break;
164254164830
}
164255164831
zIdxStr[iIdx++] = op;
164256
- zIdxStr[iIdx++] = p->iColumn - 1 + '0';
164832
+ zIdxStr[iIdx++] = (char)(p->iColumn - 1 + '0');
164257164833
pIdxInfo->aConstraintUsage[ii].argvIndex = (iIdx/2);
164258164834
pIdxInfo->aConstraintUsage[ii].omit = 1;
164259164835
}
164260164836
}
164261164837
@@ -164265,55 +164841,75 @@
164265164841
return SQLITE_NOMEM;
164266164842
}
164267164843
164268164844
nRow = pRtree->nRowEst >> (iIdx/2);
164269164845
pIdxInfo->estimatedCost = (double)6.0 * (double)nRow;
164270
- setEstimatedRows(pIdxInfo, nRow);
164846
+ pIdxInfo->estimatedRows = nRow;
164271164847
164272164848
return rc;
164273164849
}
164274164850
164275164851
/*
164276164852
** Return the N-dimensional volumn of the cell stored in *p.
164277164853
*/
164278164854
static RtreeDValue cellArea(Rtree *pRtree, RtreeCell *p){
164279164855
RtreeDValue area = (RtreeDValue)1;
164280
- int ii;
164281
- for(ii=0; ii<(pRtree->nDim*2); ii+=2){
164282
- area = (area * (DCOORD(p->aCoord[ii+1]) - DCOORD(p->aCoord[ii])));
164856
+ assert( pRtree->nDim>=1 && pRtree->nDim<=5 );
164857
+#ifndef SQLITE_RTREE_INT_ONLY
164858
+ if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
164859
+ switch( pRtree->nDim ){
164860
+ case 5: area = p->aCoord[9].f - p->aCoord[8].f;
164861
+ case 4: area *= p->aCoord[7].f - p->aCoord[6].f;
164862
+ case 3: area *= p->aCoord[5].f - p->aCoord[4].f;
164863
+ case 2: area *= p->aCoord[3].f - p->aCoord[2].f;
164864
+ default: area *= p->aCoord[1].f - p->aCoord[0].f;
164865
+ }
164866
+ }else
164867
+#endif
164868
+ {
164869
+ switch( pRtree->nDim ){
164870
+ case 5: area = p->aCoord[9].i - p->aCoord[8].i;
164871
+ case 4: area *= p->aCoord[7].i - p->aCoord[6].i;
164872
+ case 3: area *= p->aCoord[5].i - p->aCoord[4].i;
164873
+ case 2: area *= p->aCoord[3].i - p->aCoord[2].i;
164874
+ default: area *= p->aCoord[1].i - p->aCoord[0].i;
164875
+ }
164283164876
}
164284164877
return area;
164285164878
}
164286164879
164287164880
/*
164288164881
** Return the margin length of cell p. The margin length is the sum
164289164882
** of the objects size in each dimension.
164290164883
*/
164291164884
static RtreeDValue cellMargin(Rtree *pRtree, RtreeCell *p){
164292
- RtreeDValue margin = (RtreeDValue)0;
164293
- int ii;
164294
- for(ii=0; ii<(pRtree->nDim*2); ii+=2){
164885
+ RtreeDValue margin = 0;
164886
+ int ii = pRtree->nDim2 - 2;
164887
+ do{
164295164888
margin += (DCOORD(p->aCoord[ii+1]) - DCOORD(p->aCoord[ii]));
164296
- }
164889
+ ii -= 2;
164890
+ }while( ii>=0 );
164297164891
return margin;
164298164892
}
164299164893
164300164894
/*
164301164895
** Store the union of cells p1 and p2 in p1.
164302164896
*/
164303164897
static void cellUnion(Rtree *pRtree, RtreeCell *p1, RtreeCell *p2){
164304
- int ii;
164898
+ int ii = 0;
164305164899
if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
164306
- for(ii=0; ii<(pRtree->nDim*2); ii+=2){
164900
+ do{
164307164901
p1->aCoord[ii].f = MIN(p1->aCoord[ii].f, p2->aCoord[ii].f);
164308164902
p1->aCoord[ii+1].f = MAX(p1->aCoord[ii+1].f, p2->aCoord[ii+1].f);
164309
- }
164903
+ ii += 2;
164904
+ }while( ii<pRtree->nDim2 );
164310164905
}else{
164311
- for(ii=0; ii<(pRtree->nDim*2); ii+=2){
164906
+ do{
164312164907
p1->aCoord[ii].i = MIN(p1->aCoord[ii].i, p2->aCoord[ii].i);
164313164908
p1->aCoord[ii+1].i = MAX(p1->aCoord[ii+1].i, p2->aCoord[ii+1].i);
164314
- }
164909
+ ii += 2;
164910
+ }while( ii<pRtree->nDim2 );
164315164911
}
164316164912
}
164317164913
164318164914
/*
164319164915
** Return true if the area covered by p2 is a subset of the area covered
@@ -164320,11 +164916,11 @@
164320164916
** by p1. False otherwise.
164321164917
*/
164322164918
static int cellContains(Rtree *pRtree, RtreeCell *p1, RtreeCell *p2){
164323164919
int ii;
164324164920
int isInt = (pRtree->eCoordType==RTREE_COORD_INT32);
164325
- for(ii=0; ii<(pRtree->nDim*2); ii+=2){
164921
+ for(ii=0; ii<pRtree->nDim2; ii+=2){
164326164922
RtreeCoord *a1 = &p1->aCoord[ii];
164327164923
RtreeCoord *a2 = &p2->aCoord[ii];
164328164924
if( (!isInt && (a2[0].f<a1[0].f || a2[1].f>a1[1].f))
164329164925
|| ( isInt && (a2[0].i<a1[0].i || a2[1].i>a1[1].i))
164330164926
){
@@ -164355,11 +164951,11 @@
164355164951
int ii;
164356164952
RtreeDValue overlap = RTREE_ZERO;
164357164953
for(ii=0; ii<nCell; ii++){
164358164954
int jj;
164359164955
RtreeDValue o = (RtreeDValue)1;
164360
- for(jj=0; jj<(pRtree->nDim*2); jj+=2){
164956
+ for(jj=0; jj<pRtree->nDim2; jj+=2){
164361164957
RtreeDValue x1, x2;
164362164958
x1 = MAX(DCOORD(p->aCoord[jj]), DCOORD(aCell[ii].aCoord[jj]));
164363164959
x2 = MIN(DCOORD(p->aCoord[jj+1]), DCOORD(aCell[ii].aCoord[jj+1]));
164364164960
if( x2<x1 ){
164365164961
o = (RtreeDValue)0;
@@ -165411,11 +166007,11 @@
165411166007
** with "column" that are interpreted as table constraints.
165412166008
** Example: CREATE VIRTUAL TABLE bad USING rtree(x,y,CHECK(y>5));
165413166009
** This problem was discovered after years of use, so we silently ignore
165414166010
** these kinds of misdeclared tables to avoid breaking any legacy.
165415166011
*/
165416
- assert( nData<=(pRtree->nDim*2 + 3) );
166012
+ assert( nData<=(pRtree->nDim2 + 3) );
165417166013
165418166014
#ifndef SQLITE_RTREE_INT_ONLY
165419166015
if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
165420166016
for(ii=0; ii<nData-4; ii+=2){
165421166017
cell.aCoord[ii].f = rtreeValueDown(azData[ii+3]);
@@ -165500,10 +166096,31 @@
165500166096
165501166097
constraint:
165502166098
rtreeRelease(pRtree);
165503166099
return rc;
165504166100
}
166101
+
166102
+/*
166103
+** Called when a transaction starts.
166104
+*/
166105
+static int rtreeBeginTransaction(sqlite3_vtab *pVtab){
166106
+ Rtree *pRtree = (Rtree *)pVtab;
166107
+ assert( pRtree->inWrTrans==0 );
166108
+ pRtree->inWrTrans++;
166109
+ return SQLITE_OK;
166110
+}
166111
+
166112
+/*
166113
+** Called when a transaction completes (either by COMMIT or ROLLBACK).
166114
+** The sqlite3_blob object should be released at this point.
166115
+*/
166116
+static int rtreeEndTransaction(sqlite3_vtab *pVtab){
166117
+ Rtree *pRtree = (Rtree *)pVtab;
166118
+ pRtree->inWrTrans = 0;
166119
+ nodeBlobReset(pRtree);
166120
+ return SQLITE_OK;
166121
+}
165505166122
165506166123
/*
165507166124
** The xRename method for rtree module virtual tables.
165508166125
*/
165509166126
static int rtreeRename(sqlite3_vtab *pVtab, const char *zNewName){
@@ -165521,10 +166138,11 @@
165521166138
rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
165522166139
sqlite3_free(zSql);
165523166140
}
165524166141
return rc;
165525166142
}
166143
+
165526166144
165527166145
/*
165528166146
** This function populates the pRtree->nRowEst variable with an estimate
165529166147
** of the number of rows in the virtual table. If possible, this is based
165530166148
** on sqlite_stat1 data. Otherwise, use RTREE_DEFAULT_ROWEST.
@@ -165581,19 +166199,19 @@
165581166199
rtreeNext, /* xNext - advance a cursor */
165582166200
rtreeEof, /* xEof */
165583166201
rtreeColumn, /* xColumn - read data */
165584166202
rtreeRowid, /* xRowid - read data */
165585166203
rtreeUpdate, /* xUpdate - write data */
165586
- 0, /* xBegin - begin transaction */
165587
- 0, /* xSync - sync transaction */
165588
- 0, /* xCommit - commit transaction */
165589
- 0, /* xRollback - rollback transaction */
166204
+ rtreeBeginTransaction, /* xBegin - begin transaction */
166205
+ rtreeEndTransaction, /* xSync - sync transaction */
166206
+ rtreeEndTransaction, /* xCommit - commit transaction */
166207
+ rtreeEndTransaction, /* xRollback - rollback transaction */
165590166208
0, /* xFindFunction - function overloading */
165591166209
rtreeRename, /* xRename - rename the table */
165592166210
0, /* xSavepoint */
165593166211
0, /* xRelease */
165594
- 0 /* xRollbackTo */
166212
+ 0, /* xRollbackTo */
165595166213
};
165596166214
165597166215
static int rtreeSqlInit(
165598166216
Rtree *pRtree,
165599166217
sqlite3 *db,
@@ -165601,14 +166219,13 @@
165601166219
const char *zPrefix,
165602166220
int isCreate
165603166221
){
165604166222
int rc = SQLITE_OK;
165605166223
165606
- #define N_STATEMENT 9
166224
+ #define N_STATEMENT 8
165607166225
static const char *azSql[N_STATEMENT] = {
165608
- /* Read and write the xxx_node table */
165609
- "SELECT data FROM '%q'.'%q_node' WHERE nodeno = :1",
166226
+ /* Write the xxx_node table */
165610166227
"INSERT OR REPLACE INTO '%q'.'%q_node' VALUES(:1, :2)",
165611166228
"DELETE FROM '%q'.'%q_node' WHERE nodeno = :1",
165612166229
165613166230
/* Read and write the xxx_rowid table */
165614166231
"SELECT nodeno FROM '%q'.'%q_rowid' WHERE rowid = :1",
@@ -165642,19 +166259,18 @@
165642166259
if( rc!=SQLITE_OK ){
165643166260
return rc;
165644166261
}
165645166262
}
165646166263
165647
- appStmt[0] = &pRtree->pReadNode;
165648
- appStmt[1] = &pRtree->pWriteNode;
165649
- appStmt[2] = &pRtree->pDeleteNode;
165650
- appStmt[3] = &pRtree->pReadRowid;
165651
- appStmt[4] = &pRtree->pWriteRowid;
165652
- appStmt[5] = &pRtree->pDeleteRowid;
165653
- appStmt[6] = &pRtree->pReadParent;
165654
- appStmt[7] = &pRtree->pWriteParent;
165655
- appStmt[8] = &pRtree->pDeleteParent;
166264
+ appStmt[0] = &pRtree->pWriteNode;
166265
+ appStmt[1] = &pRtree->pDeleteNode;
166266
+ appStmt[2] = &pRtree->pReadRowid;
166267
+ appStmt[3] = &pRtree->pWriteRowid;
166268
+ appStmt[4] = &pRtree->pDeleteRowid;
166269
+ appStmt[5] = &pRtree->pReadParent;
166270
+ appStmt[6] = &pRtree->pWriteParent;
166271
+ appStmt[7] = &pRtree->pDeleteParent;
165656166272
165657166273
rc = rtreeQueryStat1(db, pRtree);
165658166274
for(i=0; i<N_STATEMENT && rc==SQLITE_OK; i++){
165659166275
char *zSql = sqlite3_mprintf(azSql[i], zDb, zPrefix);
165660166276
if( zSql ){
@@ -165788,13 +166404,14 @@
165788166404
memset(pRtree, 0, sizeof(Rtree)+nDb+nName+2);
165789166405
pRtree->nBusy = 1;
165790166406
pRtree->base.pModule = &rtreeModule;
165791166407
pRtree->zDb = (char *)&pRtree[1];
165792166408
pRtree->zName = &pRtree->zDb[nDb+1];
165793
- pRtree->nDim = (argc-4)/2;
165794
- pRtree->nBytesPerCell = 8 + pRtree->nDim*4*2;
165795
- pRtree->eCoordType = eCoordType;
166409
+ pRtree->nDim = (u8)((argc-4)/2);
166410
+ pRtree->nDim2 = pRtree->nDim*2;
166411
+ pRtree->nBytesPerCell = 8 + pRtree->nDim2*4;
166412
+ pRtree->eCoordType = (u8)eCoordType;
165796166413
memcpy(pRtree->zDb, argv[1], nDb);
165797166414
memcpy(pRtree->zName, argv[2], nName);
165798166415
165799166416
/* Figure out the node size to use. */
165800166417
rc = getNodeSize(db, pRtree, isCreate, pzErr);
@@ -165863,11 +166480,12 @@
165863166480
int ii;
165864166481
165865166482
UNUSED_PARAMETER(nArg);
165866166483
memset(&node, 0, sizeof(RtreeNode));
165867166484
memset(&tree, 0, sizeof(Rtree));
165868
- tree.nDim = sqlite3_value_int(apArg[0]);
166485
+ tree.nDim = (u8)sqlite3_value_int(apArg[0]);
166486
+ tree.nDim2 = tree.nDim*2;
165869166487
tree.nBytesPerCell = 8 + 8 * tree.nDim;
165870166488
node.zData = (u8 *)sqlite3_value_blob(apArg[1]);
165871166489
165872166490
for(ii=0; ii<NCELL(&node); ii++){
165873166491
char zCell[512];
@@ -165876,11 +166494,11 @@
165876166494
int jj;
165877166495
165878166496
nodeGetCell(&tree, &node, ii, &cell);
165879166497
sqlite3_snprintf(512-nCell,&zCell[nCell],"%lld", cell.iRowid);
165880166498
nCell = (int)strlen(zCell);
165881
- for(jj=0; jj<tree.nDim*2; jj++){
166499
+ for(jj=0; jj<tree.nDim2; jj++){
165882166500
#ifndef SQLITE_RTREE_INT_ONLY
165883166501
sqlite3_snprintf(512-nCell,&zCell[nCell], " %g",
165884166502
(double)cell.aCoord[jj].f);
165885166503
#else
165886166504
sqlite3_snprintf(512-nCell,&zCell[nCell], " %d",
@@ -166584,42 +167202,40 @@
166584167202
166585167203
/*
166586167204
** Register the ICU extension functions with database db.
166587167205
*/
166588167206
SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db){
166589
- struct IcuScalar {
167207
+ static const struct IcuScalar {
166590167208
const char *zName; /* Function name */
166591
- int nArg; /* Number of arguments */
166592
- int enc; /* Optimal text encoding */
166593
- void *pContext; /* sqlite3_user_data() context */
167209
+ unsigned char nArg; /* Number of arguments */
167210
+ unsigned short enc; /* Optimal text encoding */
167211
+ unsigned char iContext; /* sqlite3_user_data() context */
166594167212
void (*xFunc)(sqlite3_context*,int,sqlite3_value**);
166595167213
} scalars[] = {
166596
- {"regexp", 2, SQLITE_ANY|SQLITE_DETERMINISTIC, 0, icuRegexpFunc},
166597
-
166598
- {"lower", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
166599
- {"lower", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
166600
- {"upper", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16},
166601
- {"upper", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16},
166602
-
166603
- {"lower", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
166604
- {"lower", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
166605
- {"upper", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16},
166606
- {"upper", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16},
166607
-
166608
- {"like", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc},
166609
- {"like", 3, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc},
166610
-
166611
- {"icu_load_collation", 2, SQLITE_UTF8, (void*)db, icuLoadCollation},
167214
+ {"icu_load_collation", 2, SQLITE_UTF8, 1, icuLoadCollation},
167215
+ {"regexp", 2, SQLITE_ANY|SQLITE_DETERMINISTIC, 0, icuRegexpFunc},
167216
+ {"lower", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
167217
+ {"lower", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
167218
+ {"upper", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, 1, icuCaseFunc16},
167219
+ {"upper", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, 1, icuCaseFunc16},
167220
+ {"lower", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
167221
+ {"lower", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
167222
+ {"upper", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, 1, icuCaseFunc16},
167223
+ {"upper", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 1, icuCaseFunc16},
167224
+ {"like", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc},
167225
+ {"like", 3, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc},
166612167226
};
166613
-
166614167227
int rc = SQLITE_OK;
166615167228
int i;
166616167229
167230
+
166617167231
for(i=0; rc==SQLITE_OK && i<(int)(sizeof(scalars)/sizeof(scalars[0])); i++){
166618
- struct IcuScalar *p = &scalars[i];
167232
+ const struct IcuScalar *p = &scalars[i];
166619167233
rc = sqlite3_create_function(
166620
- db, p->zName, p->nArg, p->enc, p->pContext, p->xFunc, 0, 0
167234
+ db, p->zName, p->nArg, p->enc,
167235
+ p->iContext ? (void*)db : (void*)0,
167236
+ p->xFunc, 0, 0
166621167237
);
166622167238
}
166623167239
166624167240
return rc;
166625167241
}
@@ -169823,11 +170439,11 @@
169823170439
169824170440
/*
169825170441
** Open the database handle and attach the RBU database as "rbu". If an
169826170442
** error occurs, leave an error code and message in the RBU handle.
169827170443
*/
169828
-static void rbuOpenDatabase(sqlite3rbu *p){
170444
+static void rbuOpenDatabase(sqlite3rbu *p, int *pbRetry){
169829170445
assert( p->rc || (p->dbMain==0 && p->dbRbu==0) );
169830170446
assert( p->rc || rbuIsVacuum(p) || p->zTarget!=0 );
169831170447
169832170448
/* Open the RBU database */
169833170449
p->dbRbu = rbuOpenDbhandle(p, p->zRbu, 1);
@@ -169898,11 +170514,11 @@
169898170514
if( p->eStage>=RBU_STAGE_MOVE ){
169899170515
bOpen = 1;
169900170516
}else{
169901170517
RbuState *pState = rbuLoadState(p);
169902170518
if( pState ){
169903
- bOpen = (pState->eStage>RBU_STAGE_MOVE);
170519
+ bOpen = (pState->eStage>=RBU_STAGE_MOVE);
169904170520
rbuFreeState(pState);
169905170521
}
169906170522
}
169907170523
if( bOpen ) p->dbMain = rbuOpenDbhandle(p, p->zRbu, p->nRbu<=1);
169908170524
}
@@ -169910,10 +170526,19 @@
169910170526
p->eStage = 0;
169911170527
if( p->rc==SQLITE_OK && p->dbMain==0 ){
169912170528
if( !rbuIsVacuum(p) ){
169913170529
p->dbMain = rbuOpenDbhandle(p, p->zTarget, 1);
169914170530
}else if( p->pRbuFd->pWalFd ){
170531
+ if( pbRetry ){
170532
+ p->pRbuFd->bNolock = 0;
170533
+ sqlite3_close(p->dbRbu);
170534
+ sqlite3_close(p->dbMain);
170535
+ p->dbMain = 0;
170536
+ p->dbRbu = 0;
170537
+ *pbRetry = 1;
170538
+ return;
170539
+ }
169915170540
p->rc = SQLITE_ERROR;
169916170541
p->zErrmsg = sqlite3_mprintf("cannot vacuum wal mode database");
169917170542
}else{
169918170543
char *zTarget;
169919170544
char *zExtra = 0;
@@ -170090,20 +170715,22 @@
170090170715
p->eStage = RBU_STAGE_CAPTURE;
170091170716
rc2 = sqlite3_exec(p->dbMain, "PRAGMA main.wal_checkpoint=restart", 0, 0,0);
170092170717
if( rc2!=SQLITE_INTERNAL ) p->rc = rc2;
170093170718
}
170094170719
170095
- if( p->rc==SQLITE_OK ){
170720
+ if( p->rc==SQLITE_OK && p->nFrame>0 ){
170096170721
p->eStage = RBU_STAGE_CKPT;
170097170722
p->nStep = (pState ? pState->nRow : 0);
170098170723
p->aBuf = rbuMalloc(p, p->pgsz);
170099170724
p->iWalCksum = rbuShmChecksum(p);
170100170725
}
170101170726
170102
- if( p->rc==SQLITE_OK && pState && pState->iWalCksum!=p->iWalCksum ){
170103
- p->rc = SQLITE_DONE;
170104
- p->eStage = RBU_STAGE_DONE;
170727
+ if( p->rc==SQLITE_OK ){
170728
+ if( p->nFrame==0 || (pState && pState->iWalCksum!=p->iWalCksum) ){
170729
+ p->rc = SQLITE_DONE;
170730
+ p->eStage = RBU_STAGE_DONE;
170731
+ }
170105170732
}
170106170733
}
170107170734
170108170735
/*
170109170736
** Called when iAmt bytes are read from offset iOff of the wal file while
@@ -170272,11 +170899,11 @@
170272170899
#else
170273170900
p->rc = rename(zOal, zWal) ? SQLITE_IOERR : SQLITE_OK;
170274170901
#endif
170275170902
170276170903
if( p->rc==SQLITE_OK ){
170277
- rbuOpenDatabase(p);
170904
+ rbuOpenDatabase(p, 0);
170278170905
rbuSetupCheckpoint(p, 0);
170279170906
}
170280170907
}
170281170908
}
170282170909
@@ -170983,10 +171610,11 @@
170983171610
rbuCreateVfs(p);
170984171611
170985171612
/* Open the target, RBU and state databases */
170986171613
if( p->rc==SQLITE_OK ){
170987171614
char *pCsr = (char*)&p[1];
171615
+ int bRetry = 0;
170988171616
if( zTarget ){
170989171617
p->zTarget = pCsr;
170990171618
memcpy(p->zTarget, zTarget, nTarget+1);
170991171619
pCsr += nTarget+1;
170992171620
}
@@ -170994,11 +171622,22 @@
170994171622
memcpy(p->zRbu, zRbu, nRbu+1);
170995171623
pCsr += nRbu+1;
170996171624
if( zState ){
170997171625
p->zState = rbuMPrintf(p, "%s", zState);
170998171626
}
170999
- rbuOpenDatabase(p);
171627
+
171628
+ /* If the first attempt to open the database file fails and the bRetry
171629
+ ** flag it set, this means that the db was not opened because it seemed
171630
+ ** to be a wal-mode db. But, this may have happened due to an earlier
171631
+ ** RBU vacuum operation leaving an old wal file in the directory.
171632
+ ** If this is the case, it will have been checkpointed and deleted
171633
+ ** when the handle was closed and a second attempt to open the
171634
+ ** database may succeed. */
171635
+ rbuOpenDatabase(p, &bRetry);
171636
+ if( bRetry ){
171637
+ rbuOpenDatabase(p, 0);
171638
+ }
171000171639
}
171001171640
171002171641
if( p->rc==SQLITE_OK ){
171003171642
pState = rbuLoadState(p);
171004171643
assert( pState || p->rc!=SQLITE_OK );
@@ -175957,11 +176596,11 @@
175957176596
sqlite3_value **ppValue /* OUT: Value from conflicting row */
175958176597
){
175959176598
if( !pIter->pConflict ){
175960176599
return SQLITE_MISUSE;
175961176600
}
175962
- if( iVal<0 || iVal>=sqlite3_column_count(pIter->pConflict) ){
176601
+ if( iVal<0 || iVal>=pIter->nCol ){
175963176602
return SQLITE_RANGE;
175964176603
}
175965176604
*ppValue = sqlite3_column_value(pIter->pConflict, iVal);
175966176605
return SQLITE_OK;
175967176606
}
@@ -176424,11 +177063,17 @@
176424177063
int i;
176425177064
SessionBuffer buf = {0, 0, 0};
176426177065
176427177066
sessionAppendStr(&buf, "INSERT INTO main.", &rc);
176428177067
sessionAppendIdent(&buf, zTab, &rc);
176429
- sessionAppendStr(&buf, " VALUES(?", &rc);
177068
+ sessionAppendStr(&buf, "(", &rc);
177069
+ for(i=0; i<p->nCol; i++){
177070
+ if( i!=0 ) sessionAppendStr(&buf, ", ", &rc);
177071
+ sessionAppendIdent(&buf, p->azCol[i], &rc);
177072
+ }
177073
+
177074
+ sessionAppendStr(&buf, ") VALUES(?", &rc);
176430177075
for(i=1; i<p->nCol; i++){
176431177076
sessionAppendStr(&buf, ", ?", &rc);
176432177077
}
176433177078
sessionAppendStr(&buf, ")", &rc);
176434177079
@@ -176970,42 +177615,51 @@
176970177615
break;
176971177616
}
176972177617
nTab = (int)strlen(zTab);
176973177618
sApply.azCol = (const char **)zTab;
176974177619
}else{
177620
+ int nMinCol = 0;
177621
+ int i;
177622
+
176975177623
sqlite3changeset_pk(pIter, &abPK, 0);
176976177624
rc = sessionTableInfo(
176977177625
db, "main", zNew, &sApply.nCol, &zTab, &sApply.azCol, &sApply.abPK
176978177626
);
176979177627
if( rc!=SQLITE_OK ) break;
177628
+ for(i=0; i<sApply.nCol; i++){
177629
+ if( sApply.abPK[i] ) nMinCol = i+1;
177630
+ }
176980177631
176981177632
if( sApply.nCol==0 ){
176982177633
schemaMismatch = 1;
176983177634
sqlite3_log(SQLITE_SCHEMA,
176984177635
"sqlite3changeset_apply(): no such table: %s", zTab
176985177636
);
176986177637
}
176987
- else if( sApply.nCol!=nCol ){
177638
+ else if( sApply.nCol<nCol ){
176988177639
schemaMismatch = 1;
176989177640
sqlite3_log(SQLITE_SCHEMA,
176990
- "sqlite3changeset_apply(): table %s has %d columns, expected %d",
177641
+ "sqlite3changeset_apply(): table %s has %d columns, "
177642
+ "expected %d or more",
176991177643
zTab, sApply.nCol, nCol
176992177644
);
176993177645
}
176994
- else if( memcmp(sApply.abPK, abPK, nCol)!=0 ){
177646
+ else if( nCol<nMinCol || memcmp(sApply.abPK, abPK, nCol)!=0 ){
176995177647
schemaMismatch = 1;
176996177648
sqlite3_log(SQLITE_SCHEMA, "sqlite3changeset_apply(): "
176997177649
"primary key mismatch for table %s", zTab
176998177650
);
176999177651
}
177000
- else if(
177001
- (rc = sessionSelectRow(db, zTab, &sApply))
177002
- || (rc = sessionUpdateRow(db, zTab, &sApply))
177003
- || (rc = sessionDeleteRow(db, zTab, &sApply))
177004
- || (rc = sessionInsertRow(db, zTab, &sApply))
177005
- ){
177006
- break;
177652
+ else{
177653
+ sApply.nCol = nCol;
177654
+ if((rc = sessionSelectRow(db, zTab, &sApply))
177655
+ || (rc = sessionUpdateRow(db, zTab, &sApply))
177656
+ || (rc = sessionDeleteRow(db, zTab, &sApply))
177657
+ || (rc = sessionInsertRow(db, zTab, &sApply))
177658
+ ){
177659
+ break;
177660
+ }
177007177661
}
177008177662
nTab = sqlite3Strlen30(zTab);
177009177663
}
177010177664
}
177011177665
@@ -177593,11 +178247,11 @@
177593178247
** a BLOB, but there is no support for JSONB in the current implementation.
177594178248
** This implementation parses JSON text at 250 MB/s, so it is hard to see
177595178249
** how JSONB might improve on that.)
177596178250
*/
177597178251
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_JSON1)
177598
-#if !defined(_SQLITEINT_H_)
178252
+#if !defined(SQLITEINT_H)
177599178253
/* #include "sqlite3ext.h" */
177600178254
#endif
177601178255
SQLITE_EXTENSION_INIT1
177602178256
/* #include <assert.h> */
177603178257
/* #include <string.h> */
@@ -181644,10 +182298,35 @@
181644182298
*/
181645182299
#ifndef fts5YYMALLOCARGTYPE
181646182300
# define fts5YYMALLOCARGTYPE size_t
181647182301
#endif
181648182302
182303
+/* Initialize a new parser that has already been allocated.
182304
+*/
182305
+static void sqlite3Fts5ParserInit(void *fts5yypParser){
182306
+ fts5yyParser *pParser = (fts5yyParser*)fts5yypParser;
182307
+#ifdef fts5YYTRACKMAXSTACKDEPTH
182308
+ pParser->fts5yyhwm = 0;
182309
+#endif
182310
+#if fts5YYSTACKDEPTH<=0
182311
+ pParser->fts5yytos = NULL;
182312
+ pParser->fts5yystack = NULL;
182313
+ pParser->fts5yystksz = 0;
182314
+ if( fts5yyGrowStack(pParser) ){
182315
+ pParser->fts5yystack = &pParser->fts5yystk0;
182316
+ pParser->fts5yystksz = 1;
182317
+ }
182318
+#endif
182319
+#ifndef fts5YYNOERRORRECOVERY
182320
+ pParser->fts5yyerrcnt = -1;
182321
+#endif
182322
+ pParser->fts5yytos = pParser->fts5yystack;
182323
+ pParser->fts5yystack[0].stateno = 0;
182324
+ pParser->fts5yystack[0].major = 0;
182325
+}
182326
+
182327
+#ifndef sqlite3Fts5Parser_ENGINEALWAYSONSTACK
181649182328
/*
181650182329
** This function allocates a new parser.
181651182330
** The only argument is a pointer to a function which works like
181652182331
** malloc.
181653182332
**
@@ -181659,32 +182338,15 @@
181659182338
** to sqlite3Fts5Parser and sqlite3Fts5ParserFree.
181660182339
*/
181661182340
static void *sqlite3Fts5ParserAlloc(void *(*mallocProc)(fts5YYMALLOCARGTYPE)){
181662182341
fts5yyParser *pParser;
181663182342
pParser = (fts5yyParser*)(*mallocProc)( (fts5YYMALLOCARGTYPE)sizeof(fts5yyParser) );
181664
- if( pParser ){
181665
-#ifdef fts5YYTRACKMAXSTACKDEPTH
181666
- pParser->fts5yyhwm = 0;
181667
-#endif
181668
-#if fts5YYSTACKDEPTH<=0
181669
- pParser->fts5yytos = NULL;
181670
- pParser->fts5yystack = NULL;
181671
- pParser->fts5yystksz = 0;
181672
- if( fts5yyGrowStack(pParser) ){
181673
- pParser->fts5yystack = &pParser->fts5yystk0;
181674
- pParser->fts5yystksz = 1;
181675
- }
181676
-#endif
181677
-#ifndef fts5YYNOERRORRECOVERY
181678
- pParser->fts5yyerrcnt = -1;
181679
-#endif
181680
- pParser->fts5yytos = pParser->fts5yystack;
181681
- pParser->fts5yystack[0].stateno = 0;
181682
- pParser->fts5yystack[0].major = 0;
181683
- }
182343
+ if( pParser ) sqlite3Fts5ParserInit(pParser);
181684182344
return pParser;
181685182345
}
182346
+#endif /* sqlite3Fts5Parser_ENGINEALWAYSONSTACK */
182347
+
181686182348
181687182349
/* The following function deletes the "minor type" or semantic value
181688182350
** associated with a symbol. The symbol can be either a terminal
181689182351
** or nonterminal. "fts5yymajor" is the symbol code, and "fts5yypminor" is
181690182352
** a pointer to the value to be deleted. The code used to do the
@@ -181762,10 +182424,22 @@
181762182424
}
181763182425
#endif
181764182426
fts5yy_destructor(pParser, fts5yytos->major, &fts5yytos->minor);
181765182427
}
181766182428
182429
+/*
182430
+** Clear all secondary memory allocations from the parser
182431
+*/
182432
+static void sqlite3Fts5ParserFinalize(void *p){
182433
+ fts5yyParser *pParser = (fts5yyParser*)p;
182434
+ while( pParser->fts5yytos>pParser->fts5yystack ) fts5yy_pop_parser_stack(pParser);
182435
+#if fts5YYSTACKDEPTH<=0
182436
+ if( pParser->fts5yystack!=&pParser->fts5yystk0 ) free(pParser->fts5yystack);
182437
+#endif
182438
+}
182439
+
182440
+#ifndef sqlite3Fts5Parser_ENGINEALWAYSONSTACK
181767182441
/*
181768182442
** Deallocate and destroy a parser. Destructors are called for
181769182443
** all stack elements before shutting the parser down.
181770182444
**
181771182445
** If the fts5YYPARSEFREENEVERNULL macro exists (for example because it
@@ -181774,20 +182448,17 @@
181774182448
*/
181775182449
static void sqlite3Fts5ParserFree(
181776182450
void *p, /* The parser to be deleted */
181777182451
void (*freeProc)(void*) /* Function used to reclaim memory */
181778182452
){
181779
- fts5yyParser *pParser = (fts5yyParser*)p;
181780182453
#ifndef fts5YYPARSEFREENEVERNULL
181781
- if( pParser==0 ) return;
181782
-#endif
181783
- while( pParser->fts5yytos>pParser->fts5yystack ) fts5yy_pop_parser_stack(pParser);
181784
-#if fts5YYSTACKDEPTH<=0
181785
- if( pParser->fts5yystack!=&pParser->fts5yystk0 ) free(pParser->fts5yystack);
181786
-#endif
181787
- (*freeProc)((void*)pParser);
181788
-}
182454
+ if( p==0 ) return;
182455
+#endif
182456
+ sqlite3Fts5ParserFinalize(p);
182457
+ (*freeProc)(p);
182458
+}
182459
+#endif /* sqlite3Fts5Parser_ENGINEALWAYSONSTACK */
181789182460
181790182461
/*
181791182462
** Return the peak depth of the stack for a parser.
181792182463
*/
181793182464
#ifdef fts5YYTRACKMAXSTACKDEPTH
@@ -186122,11 +186793,11 @@
186122186793
memset(&sCtx, 0, sizeof(TokenCtx));
186123186794
sCtx.pPhrase = pAppend;
186124186795
186125186796
rc = fts5ParseStringFromToken(pToken, &z);
186126186797
if( rc==SQLITE_OK ){
186127
- int flags = FTS5_TOKENIZE_QUERY | (bPrefix ? FTS5_TOKENIZE_QUERY : 0);
186798
+ int flags = FTS5_TOKENIZE_QUERY | (bPrefix ? FTS5_TOKENIZE_PREFIX : 0);
186128186799
int n;
186129186800
sqlite3Fts5Dequote(z);
186130186801
n = (int)strlen(z);
186131186802
rc = sqlite3Fts5Tokenize(pConfig, flags, z, n, &sCtx, fts5ParseTokenize);
186132186803
}
@@ -196863,11 +197534,11 @@
196863197534
int nArg, /* Number of args */
196864197535
sqlite3_value **apUnused /* Function arguments */
196865197536
){
196866197537
assert( nArg==0 );
196867197538
UNUSED_PARAM2(nArg, apUnused);
196868
- sqlite3_result_text(pCtx, "fts5: 2017-01-06 16:32:41 a65a62893ca8319e89e48b8a38cf8a59c69a8209", -1, SQLITE_TRANSIENT);
197539
+ sqlite3_result_text(pCtx, "fts5: 2017-02-13 16:02:40 ada05cfa86ad7f5645450ac7a2a21c9aa6e57d2c", -1, SQLITE_TRANSIENT);
196869197540
}
196870197541
196871197542
static int fts5Init(sqlite3 *db){
196872197543
static const sqlite3_module fts5Mod = {
196873197544
/* iVersion */ 2,
196874197545
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.16.2. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -202,15 +202,32 @@
202 # define _FILE_OFFSET_BITS 64
203 # endif
204 # define _LARGEFILE_SOURCE 1
205 #endif
206
207 /* What version of GCC is being used. 0 means GCC is not being used */
208 #ifdef __GNUC__
 
 
 
 
 
 
 
 
 
 
 
 
209 # define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__)
210 #else
211 # define GCC_VERSION 0
 
 
 
 
 
212 #endif
213
214 /* Needed for various definitions... */
215 #if defined(__GNUC__) && !defined(_GNU_SOURCE)
216 # define _GNU_SOURCE
@@ -379,13 +396,13 @@
379 **
380 ** See also: [sqlite3_libversion()],
381 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
382 ** [sqlite_version()] and [sqlite_source_id()].
383 */
384 #define SQLITE_VERSION "3.16.2"
385 #define SQLITE_VERSION_NUMBER 3016002
386 #define SQLITE_SOURCE_ID "2017-01-06 16:32:41 a65a62893ca8319e89e48b8a38cf8a59c69a8209"
387
388 /*
389 ** CAPI3REF: Run-Time Library Version Numbers
390 ** KEYWORDS: sqlite3_version sqlite3_sourceid
391 **
@@ -517,11 +534,15 @@
517 ** sqlite3_uint64 and sqlite_uint64 types can store integer values
518 ** between 0 and +18446744073709551615 inclusive.
519 */
520 #ifdef SQLITE_INT64_TYPE
521 typedef SQLITE_INT64_TYPE sqlite_int64;
522 typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
 
 
 
 
523 #elif defined(_MSC_VER) || defined(__BORLANDC__)
524 typedef __int64 sqlite_int64;
525 typedef unsigned __int64 sqlite_uint64;
526 #else
527 typedef long long int sqlite_int64;
@@ -830,11 +851,11 @@
830 ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
831 ** after reboot following a crash or power loss, the only bytes in a
832 ** file that were written at the application level might have changed
833 ** and that adjacent bytes, even bytes within the same sector are
834 ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
835 ** flag indicate that a file cannot be deleted when open. The
836 ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
837 ** read-only media and cannot be changed even by processes with
838 ** elevated privileges.
839 */
840 #define SQLITE_IOCAP_ATOMIC 0x00000001
@@ -980,10 +1001,13 @@
980 ** <li> [SQLITE_IOCAP_ATOMIC16K]
981 ** <li> [SQLITE_IOCAP_ATOMIC32K]
982 ** <li> [SQLITE_IOCAP_ATOMIC64K]
983 ** <li> [SQLITE_IOCAP_SAFE_APPEND]
984 ** <li> [SQLITE_IOCAP_SEQUENTIAL]
 
 
 
985 ** </ul>
986 **
987 ** The SQLITE_IOCAP_ATOMIC property means that all writes of
988 ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
989 ** mean that writes of blocks that are nnn bytes in size and
@@ -5668,11 +5692,11 @@
5668 ** ^(The update hook is not invoked when internal system tables are
5669 ** modified (i.e. sqlite_master and sqlite_sequence).)^
5670 ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
5671 **
5672 ** ^In the current implementation, the update hook
5673 ** is not invoked when duplication rows are deleted because of an
5674 ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
5675 ** invoked when rows are deleted using the [truncate optimization].
5676 ** The exceptions defined in this paragraph might change in a future
5677 ** release of SQLite.
5678 **
@@ -6450,10 +6474,16 @@
6450 **
6451 ** ^Unless it returns SQLITE_MISUSE, this function sets the
6452 ** [database connection] error code and message accessible via
6453 ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
6454 **
 
 
 
 
 
 
6455 **
6456 ** ^(If the row that a BLOB handle points to is modified by an
6457 ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
6458 ** then the BLOB handle is marked as "expired".
6459 ** This is true if any column of the row is changed, even a column
@@ -6473,10 +6503,14 @@
6473 ** and the built-in [zeroblob] SQL function may be used to create a
6474 ** zero-filled blob to read or write using the incremental-blob interface.
6475 **
6476 ** To avoid a resource leak, every open [BLOB handle] should eventually
6477 ** be released by a call to [sqlite3_blob_close()].
 
 
 
 
6478 */
6479 SQLITE_API int sqlite3_blob_open(
6480 sqlite3*,
6481 const char *zDb,
6482 const char *zTable,
@@ -6488,15 +6522,15 @@
6488
6489 /*
6490 ** CAPI3REF: Move a BLOB Handle to a New Row
6491 ** METHOD: sqlite3_blob
6492 **
6493 ** ^This function is used to move an existing blob handle so that it points
6494 ** to a different row of the same database table. ^The new row is identified
6495 ** by the rowid value passed as the second argument. Only the row can be
6496 ** changed. ^The database, table and column on which the blob handle is open
6497 ** remain the same. Moving an existing blob handle to a new row can be
6498 ** faster than closing the existing handle and opening a new one.
6499 **
6500 ** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] -
6501 ** it must exist and there must be either a blob or text value stored in
6502 ** the nominated column.)^ ^If the new row is not present in the table, or if
@@ -8421,22 +8455,22 @@
8421 ** ^These interfaces are only available if SQLite is compiled using the
8422 ** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option.
8423 **
8424 ** ^The [sqlite3_preupdate_hook()] interface registers a callback function
8425 ** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation
8426 ** on a [rowid table].
8427 ** ^At most one preupdate hook may be registered at a time on a single
8428 ** [database connection]; each call to [sqlite3_preupdate_hook()] overrides
8429 ** the previous setting.
8430 ** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()]
8431 ** with a NULL pointer as the second parameter.
8432 ** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as
8433 ** the first parameter to callbacks.
8434 **
8435 ** ^The preupdate hook only fires for changes to [rowid tables]; the preupdate
8436 ** hook is not invoked for changes to [virtual tables] or [WITHOUT ROWID]
8437 ** tables.
8438 **
8439 ** ^The second parameter to the preupdate callback is a pointer to
8440 ** the [database connection] that registered the preupdate hook.
8441 ** ^The third parameter to the preupdate callback is one of the constants
8442 ** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the
@@ -8446,16 +8480,20 @@
8446 ** will be "main" for the main database or "temp" for TEMP tables or
8447 ** the name given after the AS keyword in the [ATTACH] statement for attached
8448 ** databases.)^
8449 ** ^The fifth parameter to the preupdate callback is the name of the
8450 ** table that is being modified.
8451 ** ^The sixth parameter to the preupdate callback is the initial [rowid] of the
8452 ** row being changes for SQLITE_UPDATE and SQLITE_DELETE changes and is
8453 ** undefined for SQLITE_INSERT changes.
8454 ** ^The seventh parameter to the preupdate callback is the final [rowid] of
8455 ** the row being changed for SQLITE_UPDATE and SQLITE_INSERT changes and is
8456 ** undefined for SQLITE_DELETE changes.
 
 
 
 
8457 **
8458 ** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
8459 ** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
8460 ** provide additional information about a preupdate event. These routines
8461 ** may only be called from within a preupdate callback. Invoking any of
@@ -8887,11 +8925,11 @@
8887 ** The session object will be used to create changesets for tables in
8888 ** database zDb, where zDb is either "main", or "temp", or the name of an
8889 ** attached database. It is not an error if database zDb is not attached
8890 ** to the database when the session object is created.
8891 */
8892 int sqlite3session_create(
8893 sqlite3 *db, /* Database handle */
8894 const char *zDb, /* Name of db (e.g. "main") */
8895 sqlite3_session **ppSession /* OUT: New session object */
8896 );
8897
@@ -8905,11 +8943,11 @@
8905 **
8906 ** Session objects must be deleted before the database handle to which they
8907 ** are attached is closed. Refer to the documentation for
8908 ** [sqlite3session_create()] for details.
8909 */
8910 void sqlite3session_delete(sqlite3_session *pSession);
8911
8912
8913 /*
8914 ** CAPI3REF: Enable Or Disable A Session Object
8915 **
@@ -8925,11 +8963,11 @@
8925 ** no-op, and may be used to query the current state of the session.
8926 **
8927 ** The return value indicates the final state of the session object: 0 if
8928 ** the session is disabled, or 1 if it is enabled.
8929 */
8930 int sqlite3session_enable(sqlite3_session *pSession, int bEnable);
8931
8932 /*
8933 ** CAPI3REF: Set Or Clear the Indirect Change Flag
8934 **
8935 ** Each change recorded by a session object is marked as either direct or
@@ -8954,11 +8992,11 @@
8954 ** indirect flag for the specified session object.
8955 **
8956 ** The return value indicates the final state of the indirect flag: 0 if
8957 ** it is clear, or 1 if it is set.
8958 */
8959 int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect);
8960
8961 /*
8962 ** CAPI3REF: Attach A Table To A Session Object
8963 **
8964 ** If argument zTab is not NULL, then it is the name of a table to attach
@@ -8984,11 +9022,11 @@
8984 ** in one or more of their PRIMARY KEY columns.
8985 **
8986 ** SQLITE_OK is returned if the call completes without error. Or, if an error
8987 ** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
8988 */
8989 int sqlite3session_attach(
8990 sqlite3_session *pSession, /* Session object */
8991 const char *zTab /* Table name */
8992 );
8993
8994 /*
@@ -8998,11 +9036,11 @@
8998 ** in tables that are not attached to the Session object, the filter is called
8999 ** to determine whether changes to the table's rows should be tracked or not.
9000 ** If xFilter returns 0, changes is not tracked. Note that once a table is
9001 ** attached, xFilter will not be called again.
9002 */
9003 void sqlite3session_table_filter(
9004 sqlite3_session *pSession, /* Session object */
9005 int(*xFilter)(
9006 void *pCtx, /* Copy of third arg to _filter_table() */
9007 const char *zTab /* Table name */
9008 ),
@@ -9111,11 +9149,11 @@
9111 ** changeset, even though the delete took place while the session was disabled.
9112 ** Or, if one field of a row is updated while a session is disabled, and
9113 ** another field of the same row is updated while the session is enabled, the
9114 ** resulting changeset will contain an UPDATE change that updates both fields.
9115 */
9116 int sqlite3session_changeset(
9117 sqlite3_session *pSession, /* Session object */
9118 int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */
9119 void **ppChangeset /* OUT: Buffer containing changeset */
9120 );
9121
@@ -9155,11 +9193,12 @@
9155 **
9156 ** <li> For each row (primary key) that exists in the to-table but not in
9157 ** the from-table, a DELETE record is added to the session object.
9158 **
9159 ** <li> For each row (primary key) that exists in both tables, but features
9160 ** different in each, an UPDATE record is added to the session.
 
9161 ** </ul>
9162 **
9163 ** To clarify, if this function is called and then a changeset constructed
9164 ** using [sqlite3session_changeset()], then after applying that changeset to
9165 ** database zFrom the contents of the two compatible tables would be
@@ -9172,11 +9211,11 @@
9172 ** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
9173 ** may be set to point to a buffer containing an English language error
9174 ** message. It is the responsibility of the caller to free this buffer using
9175 ** sqlite3_free().
9176 */
9177 int sqlite3session_diff(
9178 sqlite3_session *pSession,
9179 const char *zFromDb,
9180 const char *zTbl,
9181 char **pzErrMsg
9182 );
@@ -9208,11 +9247,11 @@
9208 ** Changes within a patchset are ordered in the same way as for changesets
9209 ** generated by the sqlite3session_changeset() function (i.e. all changes for
9210 ** a single table are grouped together, tables appear in the order in which
9211 ** they were attached to the session object).
9212 */
9213 int sqlite3session_patchset(
9214 sqlite3_session *pSession, /* Session object */
9215 int *pnPatchset, /* OUT: Size of buffer at *ppChangeset */
9216 void **ppPatchset /* OUT: Buffer containing changeset */
9217 );
9218
@@ -9229,11 +9268,11 @@
9229 ** an attached table is modified and then later on the original values
9230 ** are restored. However, if this function returns non-zero, then it is
9231 ** guaranteed that a call to sqlite3session_changeset() will return a
9232 ** changeset containing zero changes.
9233 */
9234 int sqlite3session_isempty(sqlite3_session *pSession);
9235
9236 /*
9237 ** CAPI3REF: Create An Iterator To Traverse A Changeset
9238 **
9239 ** Create an iterator used to iterate through the contents of a changeset.
@@ -9264,11 +9303,11 @@
9264 ** this function, all changes that relate to a single table are visited
9265 ** consecutively. There is no chance that the iterator will visit a change
9266 ** the applies to table X, then one for table Y, and then later on visit
9267 ** another change for table X.
9268 */
9269 int sqlite3changeset_start(
9270 sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */
9271 int nChangeset, /* Size of changeset blob in bytes */
9272 void *pChangeset /* Pointer to blob containing changeset */
9273 );
9274
@@ -9293,11 +9332,11 @@
9293 **
9294 ** If an error occurs, an SQLite error code is returned. Possible error
9295 ** codes include SQLITE_CORRUPT (if the changeset buffer is corrupt) or
9296 ** SQLITE_NOMEM.
9297 */
9298 int sqlite3changeset_next(sqlite3_changeset_iter *pIter);
9299
9300 /*
9301 ** CAPI3REF: Obtain The Current Operation From A Changeset Iterator
9302 **
9303 ** The pIter argument passed to this function may either be an iterator
@@ -9321,11 +9360,11 @@
9321 **
9322 ** If no error occurs, SQLITE_OK is returned. If an error does occur, an
9323 ** SQLite error code is returned. The values of the output variables may not
9324 ** be trusted in this case.
9325 */
9326 int sqlite3changeset_op(
9327 sqlite3_changeset_iter *pIter, /* Iterator object */
9328 const char **pzTab, /* OUT: Pointer to table name */
9329 int *pnCol, /* OUT: Number of columns in table */
9330 int *pOp, /* OUT: SQLITE_INSERT, DELETE or UPDATE */
9331 int *pbIndirect /* OUT: True for an 'indirect' change */
@@ -9354,11 +9393,11 @@
9354 ** If this function is called when the iterator does not point to a valid
9355 ** entry, SQLITE_MISUSE is returned and the output variables zeroed. Otherwise,
9356 ** SQLITE_OK is returned and the output variables populated as described
9357 ** above.
9358 */
9359 int sqlite3changeset_pk(
9360 sqlite3_changeset_iter *pIter, /* Iterator object */
9361 unsigned char **pabPK, /* OUT: Array of boolean - true for PK cols */
9362 int *pnCol /* OUT: Number of entries in output array */
9363 );
9364
@@ -9384,11 +9423,11 @@
9384 ** is similar to the "old.*" columns available to update or delete triggers.
9385 **
9386 ** If some other error occurs (e.g. an OOM condition), an SQLite error code
9387 ** is returned and *ppValue is set to NULL.
9388 */
9389 int sqlite3changeset_old(
9390 sqlite3_changeset_iter *pIter, /* Changeset iterator */
9391 int iVal, /* Column number */
9392 sqlite3_value **ppValue /* OUT: Old value (or NULL pointer) */
9393 );
9394
@@ -9417,11 +9456,11 @@
9417 ** triggers.
9418 **
9419 ** If some other error occurs (e.g. an OOM condition), an SQLite error code
9420 ** is returned and *ppValue is set to NULL.
9421 */
9422 int sqlite3changeset_new(
9423 sqlite3_changeset_iter *pIter, /* Changeset iterator */
9424 int iVal, /* Column number */
9425 sqlite3_value **ppValue /* OUT: New value (or NULL pointer) */
9426 );
9427
@@ -9444,11 +9483,11 @@
9444 ** and returns SQLITE_OK.
9445 **
9446 ** If some other error occurs (e.g. an OOM condition), an SQLite error code
9447 ** is returned and *ppValue is set to NULL.
9448 */
9449 int sqlite3changeset_conflict(
9450 sqlite3_changeset_iter *pIter, /* Changeset iterator */
9451 int iVal, /* Column number */
9452 sqlite3_value **ppValue /* OUT: Value from conflicting row */
9453 );
9454
@@ -9460,11 +9499,11 @@
9460 ** it sets the output variable to the total number of known foreign key
9461 ** violations in the destination database and returns SQLITE_OK.
9462 **
9463 ** In all other cases this function returns SQLITE_MISUSE.
9464 */
9465 int sqlite3changeset_fk_conflicts(
9466 sqlite3_changeset_iter *pIter, /* Changeset iterator */
9467 int *pnOut /* OUT: Number of FK violations */
9468 );
9469
9470
@@ -9493,11 +9532,11 @@
9493 ** rc = sqlite3changeset_finalize();
9494 ** if( rc!=SQLITE_OK ){
9495 ** // An error has occurred
9496 ** }
9497 */
9498 int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter);
9499
9500 /*
9501 ** CAPI3REF: Invert A Changeset
9502 **
9503 ** This function is used to "invert" a changeset object. Applying an inverted
@@ -9523,11 +9562,11 @@
9523 ** call to this function.
9524 **
9525 ** WARNING/TODO: This function currently assumes that the input is a valid
9526 ** changeset. If it is not, the results are undefined.
9527 */
9528 int sqlite3changeset_invert(
9529 int nIn, const void *pIn, /* Input changeset */
9530 int *pnOut, void **ppOut /* OUT: Inverse of input */
9531 );
9532
9533 /*
@@ -9552,11 +9591,11 @@
9552 ** *pnOut = 0;
9553 ** }
9554 **
9555 ** Refer to the sqlite3_changegroup documentation below for details.
9556 */
9557 int sqlite3changeset_concat(
9558 int nA, /* Number of bytes in buffer pA */
9559 void *pA, /* Pointer to buffer containing changeset A */
9560 int nB, /* Number of bytes in buffer pB */
9561 void *pB, /* Pointer to buffer containing changeset B */
9562 int *pnOut, /* OUT: Number of bytes in output changeset */
@@ -9740,11 +9779,11 @@
9740 ** considered compatible if all of the following are true:
9741 **
9742 ** <ul>
9743 ** <li> The table has the same name as the name recorded in the
9744 ** changeset, and
9745 ** <li> The table has the same number of columns as recorded in the
9746 ** changeset, and
9747 ** <li> The table has primary key columns in the same position as
9748 ** recorded in the changeset.
9749 ** </ul>
9750 **
@@ -9785,11 +9824,15 @@
9785 ** the changeset the row is deleted from the target database.
9786 **
9787 ** If a row with matching primary key values is found, but one or more of
9788 ** the non-primary key fields contains a value different from the original
9789 ** row value stored in the changeset, the conflict-handler function is
9790 ** invoked with [SQLITE_CHANGESET_DATA] as the second argument.
 
 
 
 
9791 **
9792 ** If no row with matching primary key values is found in the database,
9793 ** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
9794 ** passed as the second argument.
9795 **
@@ -9800,11 +9843,13 @@
9800 ** operation is attempted because an earlier call to the conflict handler
9801 ** function returned [SQLITE_CHANGESET_REPLACE].
9802 **
9803 ** <dt>INSERT Changes<dd>
9804 ** For each INSERT change, an attempt is made to insert the new row into
9805 ** the database.
 
 
9806 **
9807 ** If the attempt to insert the row fails because the database already
9808 ** contains a row with the same primary key values, the conflict handler
9809 ** function is invoked with the second argument set to
9810 ** [SQLITE_CHANGESET_CONFLICT].
@@ -9818,17 +9863,17 @@
9818 **
9819 ** <dt>UPDATE Changes<dd>
9820 ** For each UPDATE change, this function checks if the target database
9821 ** contains a row with the same primary key value (or values) as the
9822 ** original row values stored in the changeset. If it does, and the values
9823 ** stored in all non-primary key columns also match the values stored in
9824 ** the changeset the row is updated within the target database.
9825 **
9826 ** If a row with matching primary key values is found, but one or more of
9827 ** the non-primary key fields contains a value different from an original
9828 ** row value stored in the changeset, the conflict-handler function is
9829 ** invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since
9830 ** UPDATE changes only contain values for non-primary key fields that are
9831 ** to be modified, only those fields need to match the original values to
9832 ** avoid the SQLITE_CHANGESET_DATA conflict-handler callback.
9833 **
9834 ** If no row with matching primary key values is found in the database,
@@ -9852,11 +9897,11 @@
9852 ** If any other error (aside from a constraint failure when attempting to
9853 ** write to the target database) occurs, then the savepoint transaction is
9854 ** rolled back, restoring the target database to its original state, and an
9855 ** SQLite error code returned.
9856 */
9857 int sqlite3changeset_apply(
9858 sqlite3 *db, /* Apply change to "main" db of this handle */
9859 int nChangeset, /* Size of changeset in bytes */
9860 void *pChangeset, /* Changeset blob */
9861 int(*xFilter)(
9862 void *pCtx, /* Copy of sixth arg to _apply() */
@@ -10053,11 +10098,11 @@
10053 **
10054 ** The sessions module never invokes an xOutput callback with the third
10055 ** parameter set to a value less than or equal to zero. Other than this,
10056 ** no guarantees are made as to the size of the chunks of data returned.
10057 */
10058 int sqlite3changeset_apply_strm(
10059 sqlite3 *db, /* Apply change to "main" db of this handle */
10060 int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
10061 void *pIn, /* First arg for xInput */
10062 int(*xFilter)(
10063 void *pCtx, /* Copy of sixth arg to _apply() */
@@ -10068,35 +10113,35 @@
10068 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
10069 sqlite3_changeset_iter *p /* Handle describing change and conflict */
10070 ),
10071 void *pCtx /* First argument passed to xConflict */
10072 );
10073 int sqlite3changeset_concat_strm(
10074 int (*xInputA)(void *pIn, void *pData, int *pnData),
10075 void *pInA,
10076 int (*xInputB)(void *pIn, void *pData, int *pnData),
10077 void *pInB,
10078 int (*xOutput)(void *pOut, const void *pData, int nData),
10079 void *pOut
10080 );
10081 int sqlite3changeset_invert_strm(
10082 int (*xInput)(void *pIn, void *pData, int *pnData),
10083 void *pIn,
10084 int (*xOutput)(void *pOut, const void *pData, int nData),
10085 void *pOut
10086 );
10087 int sqlite3changeset_start_strm(
10088 sqlite3_changeset_iter **pp,
10089 int (*xInput)(void *pIn, void *pData, int *pnData),
10090 void *pIn
10091 );
10092 int sqlite3session_changeset_strm(
10093 sqlite3_session *pSession,
10094 int (*xOutput)(void *pOut, const void *pData, int nData),
10095 void *pOut
10096 );
10097 int sqlite3session_patchset_strm(
10098 sqlite3_session *pSession,
10099 int (*xOutput)(void *pOut, const void *pData, int nData),
10100 void *pOut
10101 );
10102 int sqlite3changegroup_add_strm(sqlite3_changegroup*,
@@ -10999,10 +11044,11 @@
10999 # if defined(_MSC_VER) && _MSC_VER>=1400
11000 # if !defined(_WIN32_WCE)
11001 # include <intrin.h>
11002 # pragma intrinsic(_byteswap_ushort)
11003 # pragma intrinsic(_byteswap_ulong)
 
11004 # pragma intrinsic(_ReadWriteBarrier)
11005 # else
11006 # include <cmnintrin.h>
11007 # endif
11008 # endif
@@ -11537,10 +11583,22 @@
11537 #include <stdlib.h>
11538 #include <string.h>
11539 #include <assert.h>
11540 #include <stddef.h>
11541
 
 
 
 
 
 
 
 
 
 
 
 
11542 /*
11543 ** If compiling for a processor that lacks floating point support,
11544 ** substitute integer for floating-point
11545 */
11546 #ifdef SQLITE_OMIT_FLOATING_POINT
@@ -11621,13 +11679,16 @@
11621 /*
11622 ** The default initial allocation for the pagecache when using separate
11623 ** pagecaches for each database connection. A positive number is the
11624 ** number of pages. A negative number N translations means that a buffer
11625 ** of -1024*N bytes is allocated and used for as many pages as it will hold.
 
 
 
11626 */
11627 #ifndef SQLITE_DEFAULT_PCACHE_INITSZ
11628 # define SQLITE_DEFAULT_PCACHE_INITSZ 100
11629 #endif
11630
11631 /*
11632 ** GCC does not define the offsetof() macro so we'll have to do it
11633 ** ourselves.
@@ -11798,36 +11859,39 @@
11798 ** Macros to determine whether the machine is big or little endian,
11799 ** and whether or not that determination is run-time or compile-time.
11800 **
11801 ** For best performance, an attempt is made to guess at the byte-order
11802 ** using C-preprocessor macros. If that is unsuccessful, or if
11803 ** -DSQLITE_RUNTIME_BYTEORDER=1 is set, then byte-order is determined
11804 ** at run-time.
11805 */
11806 #if (defined(i386) || defined(__i386__) || defined(_M_IX86) || \
 
11807 defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \
11808 defined(_M_AMD64) || defined(_M_ARM) || defined(__x86) || \
11809 defined(__arm__)) && !defined(SQLITE_RUNTIME_BYTEORDER)
11810 # define SQLITE_BYTEORDER 1234
11811 # define SQLITE_BIGENDIAN 0
11812 # define SQLITE_LITTLEENDIAN 1
11813 # define SQLITE_UTF16NATIVE SQLITE_UTF16LE
 
 
11814 #endif
11815 #if (defined(sparc) || defined(__ppc__)) \
11816 && !defined(SQLITE_RUNTIME_BYTEORDER)
11817 # define SQLITE_BYTEORDER 4321
11818 # define SQLITE_BIGENDIAN 1
11819 # define SQLITE_LITTLEENDIAN 0
11820 # define SQLITE_UTF16NATIVE SQLITE_UTF16BE
11821 #endif
11822 #if !defined(SQLITE_BYTEORDER)
 
 
 
11823 # ifdef SQLITE_AMALGAMATION
11824 const int sqlite3one = 1;
11825 # else
11826 extern const int sqlite3one;
11827 # endif
11828 # define SQLITE_BYTEORDER 0 /* 0 means "unknown at compile-time" */
11829 # define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0)
11830 # define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1)
11831 # define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE)
11832 #endif
11833
@@ -12346,13 +12410,14 @@
12346 );
12347 SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor*);
12348 SQLITE_PRIVATE int sqlite3BtreeCursorRestore(BtCursor*, int*);
12349 SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor*, u8 flags);
12350
12351 /* Allowed flags for the 2nd argument to sqlite3BtreeDelete() */
12352 #define BTREE_SAVEPOSITION 0x02 /* Leave cursor pointing at NEXT or PREV */
12353 #define BTREE_AUXDELETE 0x04 /* not the primary delete operation */
 
12354
12355 /* An instance of the BtreePayload object describes the content of a single
12356 ** entry in either an index or table btree.
12357 **
12358 ** Index btrees (used for indexes and also WITHOUT ROWID tables) contain
@@ -12379,11 +12444,11 @@
12379 int nData; /* Size of pData. 0 if none. */
12380 int nZero; /* Extra zero data appended after pData,nData */
12381 };
12382
12383 SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload,
12384 int bias, int seekResult);
12385 SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes);
12386 SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
12387 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes);
12388 SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
12389 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes);
@@ -12512,12 +12577,11 @@
12512 ** as an instance of the following structure:
12513 */
12514 struct VdbeOp {
12515 u8 opcode; /* What operation to perform */
12516 signed char p4type; /* One of the P4_xxx constants for p4 */
12517 u8 notUsed1;
12518 u8 p5; /* Fifth parameter is an unsigned character */
12519 int p1; /* First operand */
12520 int p2; /* Second parameter (often the jump destination) */
12521 int p3; /* The third parameter */
12522 union p4union { /* fourth parameter */
12523 int i; /* Integer value if p4type==P4_INT32 */
@@ -12874,11 +12938,11 @@
12874 SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
12875 SQLITE_PRIVATE void sqlite3VdbeChangeOpcode(Vdbe*, u32 addr, u8);
12876 SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1);
12877 SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
12878 SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
12879 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
12880 SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
12881 SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
12882 SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
12883 SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
12884 SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
@@ -13176,18 +13240,20 @@
13176 SQLITE_PRIVATE int sqlite3PagerCheckpoint(Pager *pPager, sqlite3*, int, int*, int*);
13177 SQLITE_PRIVATE int sqlite3PagerWalSupported(Pager *pPager);
13178 SQLITE_PRIVATE int sqlite3PagerWalCallback(Pager *pPager);
13179 SQLITE_PRIVATE int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen);
13180 SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager, sqlite3*);
13181 SQLITE_PRIVATE int sqlite3PagerUseWal(Pager *pPager);
 
 
13182 # ifdef SQLITE_ENABLE_SNAPSHOT
13183 SQLITE_PRIVATE int sqlite3PagerSnapshotGet(Pager *pPager, sqlite3_snapshot **ppSnapshot);
13184 SQLITE_PRIVATE int sqlite3PagerSnapshotOpen(Pager *pPager, sqlite3_snapshot *pSnapshot);
13185 SQLITE_PRIVATE int sqlite3PagerSnapshotRecover(Pager *pPager);
13186 # endif
13187 #else
13188 # define sqlite3PagerUseWal(x) 0
13189 #endif
13190
13191 #ifdef SQLITE_ENABLE_ZIPVFS
13192 SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager);
13193 #endif
@@ -14007,10 +14073,11 @@
14007 signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */
14008 u8 suppressErr; /* Do not issue error messages if true */
14009 u8 vtabOnConflict; /* Value to return for s3_vtab_on_conflict() */
14010 u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */
14011 u8 mTrace; /* zero or more SQLITE_TRACE flags */
 
14012 int nextPagesize; /* Pagesize after VACUUM if >0 */
14013 u32 magic; /* Magic number for detect library misuse */
14014 int nChange; /* Value returned by sqlite3_changes() */
14015 int nTotalChange; /* Value returned by sqlite3_total_changes() */
14016 int aLimit[SQLITE_N_LIMIT]; /* Limits */
@@ -14272,10 +14339,11 @@
14272 #define SQLITE_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */
14273 #define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */
14274 #define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */
14275 #define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a
14276 ** single query - might change over time */
 
14277
14278 /*
14279 ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
14280 ** used to create the initializers for the FuncDef structures.
14281 **
@@ -15278,11 +15346,11 @@
15278 #define WHERE_DISTINCTBY 0x0080 /* pOrderby is really a DISTINCT clause */
15279 #define WHERE_WANT_DISTINCT 0x0100 /* All output needs to be distinct */
15280 #define WHERE_SORTBYGROUP 0x0200 /* Support sqlite3WhereIsSorted() */
15281 #define WHERE_SEEK_TABLE 0x0400 /* Do not defer seeks on main table */
15282 #define WHERE_ORDERBY_LIMIT 0x0800 /* ORDERBY+LIMIT on the inner loop */
15283 /* 0x1000 not currently used */
15284 /* 0x2000 not currently used */
15285 #define WHERE_USE_LIMIT 0x4000 /* Use the LIMIT in cost estimates */
15286 /* 0x8000 not currently used */
15287
15288 /* Allowed return values from sqlite3WhereIsDistinct()
@@ -15739,25 +15807,23 @@
15739 ** OPFLAG_AUXDELETE == BTREE_AUXDELETE
15740 */
15741 #define OPFLAG_NCHANGE 0x01 /* OP_Insert: Set to update db->nChange */
15742 /* Also used in P2 (not P5) of OP_Delete */
15743 #define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */
15744 #define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */
15745 #define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */
15746 #define OPFLAG_APPEND 0x08 /* This is likely to be an append */
15747 #define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */
15748 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
15749 #define OPFLAG_ISNOOP 0x40 /* OP_Delete does pre-update-hook only */
15750 #endif
15751 #define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */
15752 #define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */
15753 #define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */
15754 #define OPFLAG_SEEKEQ 0x02 /* OP_Open** cursor uses EQ seek only */
15755 #define OPFLAG_FORDELETE 0x08 /* OP_Open should use BTREE_FORDELETE */
15756 #define OPFLAG_P2ISREG 0x10 /* P2 to OP_Open** is a register number */
15757 #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */
15758 #define OPFLAG_SAVEPOSITION 0x02 /* OP_Delete: keep cursor position */
15759 #define OPFLAG_AUXDELETE 0x04 /* OP_Delete: index in a DELETE op */
15760
15761 /*
15762 * Each trigger present in the database schema is stored as an instance of
15763 * struct Trigger.
@@ -16414,11 +16480,11 @@
16414 SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*);
16415 SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
16416 SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int);
16417 SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, Expr*, int);
16418 SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
16419 SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
16420 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
16421 SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
16422 SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*, int);
16423 SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int, u8);
16424 #define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */
@@ -16476,10 +16542,15 @@
16476 SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*, int);
16477 SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,Index*,int);
16478 SQLITE_PRIVATE void sqlite3ResolvePartIdxLabel(Parse*,int);
16479 SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int,
16480 u8,u8,int,int*,int*);
 
 
 
 
 
16481 SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int);
16482 SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, u8, int, u8*, int*, int*);
16483 SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse*, int, int);
16484 SQLITE_PRIVATE void sqlite3MultiWrite(Parse*);
16485 SQLITE_PRIVATE void sqlite3MayAbort(Parse*);
@@ -16754,12 +16825,14 @@
16754 #endif
16755
16756 /*
16757 ** The interface to the LEMON-generated parser
16758 */
16759 SQLITE_PRIVATE void *sqlite3ParserAlloc(void*(*)(u64));
16760 SQLITE_PRIVATE void sqlite3ParserFree(void*, void(*)(void*));
 
 
16761 SQLITE_PRIVATE void sqlite3Parser(void*, int, Token, Parse*);
16762 #ifdef YYTRACKMAXSTACKDEPTH
16763 SQLITE_PRIVATE int sqlite3ParserStackPeak(void*);
16764 #endif
16765
@@ -16865,10 +16938,11 @@
16865 #define sqlite3FkActions(a,b,c,d,e,f)
16866 #define sqlite3FkCheck(a,b,c,d,e,f)
16867 #define sqlite3FkDropTable(a,b,c)
16868 #define sqlite3FkOldmask(a,b) 0
16869 #define sqlite3FkRequired(a,b,c,d) 0
 
16870 #endif
16871 #ifndef SQLITE_OMIT_FOREIGN_KEY
16872 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *, Table*);
16873 SQLITE_PRIVATE int sqlite3FkLocateIndex(Parse*,Table*,FKey*,Index**,int**);
16874 #else
@@ -17193,10 +17267,23 @@
17193 ** setting.)
17194 */
17195 #ifndef SQLITE_STMTJRNL_SPILL
17196 # define SQLITE_STMTJRNL_SPILL (64*1024)
17197 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
17198
17199 /*
17200 ** The following singleton contains the global configuration for
17201 ** the SQLite library.
17202 */
@@ -17206,12 +17293,11 @@
17206 SQLITE_THREADSAFE==1, /* bFullMutex */
17207 SQLITE_USE_URI, /* bOpenUri */
17208 SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */
17209 0x7ffffffe, /* mxStrlen */
17210 0, /* neverCorrupt */
17211 512, /* szLookaside */
17212 125, /* nLookaside */
17213 SQLITE_STMTJRNL_SPILL, /* nStmtSpill */
17214 {0,0,0,0,0,0,0,0}, /* m */
17215 {0,0,0,0,0,0,0,0,0}, /* mutex */
17216 {0,0,0,0,0,0,0,0,0,0,0,0,0},/* pcache2 */
17217 (void*)0, /* pHeap */
@@ -18219,10 +18305,11 @@
18219 int iNewReg; /* Register for new.* values */
18220 i64 iKey1; /* First key value passed to hook */
18221 i64 iKey2; /* Second key value passed to hook */
18222 Mem *aNew; /* Array of new.* values */
18223 Table *pTab; /* Schema object being upated */
 
18224 };
18225
18226 /*
18227 ** Function prototypes
18228 */
@@ -20619,20 +20706,22 @@
20619 ** cases of nByte<=0 will be intercepted and dealt with by higher level
20620 ** routines.
20621 */
20622 static void *sqlite3MemMalloc(int nByte){
20623 #ifdef SQLITE_MALLOCSIZE
20624 void *p = SQLITE_MALLOC( nByte );
 
 
20625 if( p==0 ){
20626 testcase( sqlite3GlobalConfig.xLog!=0 );
20627 sqlite3_log(SQLITE_NOMEM, "failed to allocate %u bytes of memory", nByte);
20628 }
20629 return p;
20630 #else
20631 sqlite3_int64 *p;
20632 assert( nByte>0 );
20633 nByte = ROUND8(nByte);
20634 p = SQLITE_MALLOC( nByte+8 );
20635 if( p ){
20636 p[0] = nByte;
20637 p++;
20638 }else{
@@ -23750,12 +23839,11 @@
23750 SQLITE_PRIVATE void sqlite3MemoryBarrier(void){
23751 #if defined(SQLITE_MEMORY_BARRIER)
23752 SQLITE_MEMORY_BARRIER;
23753 #elif defined(__GNUC__)
23754 __sync_synchronize();
23755 #elif !defined(SQLITE_DISABLE_INTRINSIC) && \
23756 defined(_MSC_VER) && _MSC_VER>=1300
23757 _ReadWriteBarrier();
23758 #elif defined(MemoryBarrier)
23759 MemoryBarrier();
23760 #endif
23761 }
@@ -24283,15 +24371,23 @@
24283
24284 /*
24285 ** Do a memory allocation with statistics and alarms. Assume the
24286 ** lock is already held.
24287 */
24288 static int mallocWithAlarm(int n, void **pp){
24289 int nFull;
24290 void *p;
 
24291 assert( sqlite3_mutex_held(mem0.mutex) );
 
 
 
 
 
 
 
24292 nFull = sqlite3GlobalConfig.m.xRoundup(n);
 
24293 sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, n);
24294 if( mem0.alarmThreshold>0 ){
24295 sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
24296 if( nUsed >= mem0.alarmThreshold - nFull ){
24297 mem0.nearlyFull = 1;
@@ -24311,11 +24407,10 @@
24311 nFull = sqlite3MallocSize(p);
24312 sqlite3StatusUp(SQLITE_STATUS_MEMORY_USED, nFull);
24313 sqlite3StatusUp(SQLITE_STATUS_MALLOC_COUNT, 1);
24314 }
24315 *pp = p;
24316 return nFull;
24317 }
24318
24319 /*
24320 ** Allocate memory. This routine is like sqlite3_malloc() except that it
24321 ** assumes the memory subsystem has already been initialized.
@@ -24951,11 +25046,10 @@
24951
24952 /*
24953 ** Allowed values for et_info.flags
24954 */
24955 #define FLAG_SIGNED 1 /* True if the value to convert is signed */
24956 #define FLAG_INTERN 2 /* True if for internal use only */
24957 #define FLAG_STRING 4 /* Allow infinity precision */
24958
24959
24960 /*
24961 ** The following table is searched linearly, so it is good to put the
@@ -24985,15 +25079,14 @@
24985 { 'i', 10, 1, etRADIX, 0, 0 },
24986 { 'n', 0, 0, etSIZE, 0, 0 },
24987 { '%', 0, 0, etPERCENT, 0, 0 },
24988 { 'p', 16, 0, etPOINTER, 0, 1 },
24989
24990 /* All the rest have the FLAG_INTERN bit set and are thus for internal
24991 ** use only */
24992 { 'T', 0, 2, etTOKEN, 0, 0 },
24993 { 'S', 0, 2, etSRCLIST, 0, 0 },
24994 { 'r', 10, 3, etORDINAL, 0, 0 },
24995 };
24996
24997 /*
24998 ** If SQLITE_OMIT_FLOATING_POINT is defined, then none of the floating point
24999 ** conversions will work.
@@ -25083,11 +25176,10 @@
25083 etByte flag_long; /* True if "l" flag is present */
25084 etByte flag_longlong; /* True if the "ll" flag is present */
25085 etByte done; /* Loop termination flag */
25086 etByte xtype = etINVALID; /* Conversion paradigm */
25087 u8 bArgList; /* True for SQLITE_PRINTF_SQLFUNC */
25088 u8 useIntern; /* Ok to use internal conversions (ex: %T) */
25089 char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
25090 sqlite_uint64 longvalue; /* Value for integer types */
25091 LONGDOUBLE_TYPE realvalue; /* Value for real types */
25092 const et_info *infop; /* Pointer to the appropriate info structure */
25093 char *zOut; /* Rendering buffer */
@@ -25102,17 +25194,15 @@
25102 #endif
25103 PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */
25104 char buf[etBUFSIZE]; /* Conversion buffer */
25105
25106 bufpt = 0;
25107 if( pAccum->printfFlags ){
25108 if( (bArgList = (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){
25109 pArgList = va_arg(ap, PrintfArguments*);
25110 }
25111 useIntern = pAccum->printfFlags & SQLITE_PRINTF_INTERNAL;
25112 }else{
25113 bArgList = useIntern = 0;
25114 }
25115 for(; (c=(*fmt))!=0; ++fmt){
25116 if( c!='%' ){
25117 bufpt = (char *)fmt;
25118 #if HAVE_STRCHRNUL
@@ -25220,15 +25310,11 @@
25220 infop = &fmtinfo[0];
25221 xtype = etINVALID;
25222 for(idx=0; idx<ArraySize(fmtinfo); idx++){
25223 if( c==fmtinfo[idx].fmttype ){
25224 infop = &fmtinfo[idx];
25225 if( useIntern || (infop->flags & FLAG_INTERN)==0 ){
25226 xtype = infop->type;
25227 }else{
25228 return;
25229 }
25230 break;
25231 }
25232 }
25233
25234 /*
@@ -25593,22 +25679,28 @@
25593 ** consume, not the length of the output...
25594 ** if( precision>=0 && precision<length ) length = precision; */
25595 break;
25596 }
25597 case etTOKEN: {
25598 Token *pToken = va_arg(ap, Token*);
 
 
25599 assert( bArgList==0 );
25600 if( pToken && pToken->n ){
25601 sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n);
25602 }
25603 length = width = 0;
25604 break;
25605 }
25606 case etSRCLIST: {
25607 SrcList *pSrc = va_arg(ap, SrcList*);
25608 int k = va_arg(ap, int);
25609 struct SrcList_item *pItem = &pSrc->a[k];
 
 
 
 
25610 assert( bArgList==0 );
25611 assert( k>=0 && k<pSrc->nSrc );
25612 if( pItem->zDatabase ){
25613 sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase);
25614 sqlite3StrAccumAppend(pAccum, ".", 1);
@@ -25626,13 +25718,17 @@
25626 ** The text of the conversion is pointed to by "bufpt" and is
25627 ** "length" characters long. The field width is "width". Do
25628 ** the output.
25629 */
25630 width -= length;
25631 if( width>0 && !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
25632 sqlite3StrAccumAppend(pAccum, bufpt, length);
25633 if( width>0 && flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
 
 
 
 
25634
25635 if( zExtra ){
25636 sqlite3DbFree(pAccum->db, zExtra);
25637 zExtra = 0;
25638 }
@@ -28600,17 +28696,15 @@
28600 SQLITE_PRIVATE u32 sqlite3Get4byte(const u8 *p){
28601 #if SQLITE_BYTEORDER==4321
28602 u32 x;
28603 memcpy(&x,p,4);
28604 return x;
28605 #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
28606 && defined(__GNUC__) && GCC_VERSION>=4003000
28607 u32 x;
28608 memcpy(&x,p,4);
28609 return __builtin_bswap32(x);
28610 #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
28611 && defined(_MSC_VER) && _MSC_VER>=1300
28612 u32 x;
28613 memcpy(&x,p,4);
28614 return _byteswap_ulong(x);
28615 #else
28616 testcase( p[0]&0x80 );
@@ -28618,16 +28712,14 @@
28618 #endif
28619 }
28620 SQLITE_PRIVATE void sqlite3Put4byte(unsigned char *p, u32 v){
28621 #if SQLITE_BYTEORDER==4321
28622 memcpy(p,&v,4);
28623 #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
28624 && defined(__GNUC__) && GCC_VERSION>=4003000
28625 u32 x = __builtin_bswap32(v);
28626 memcpy(p,&x,4);
28627 #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
28628 && defined(_MSC_VER) && _MSC_VER>=1300
28629 u32 x = _byteswap_ulong(v);
28630 memcpy(p,&x,4);
28631 #else
28632 p[0] = (u8)(v>>24);
28633 p[1] = (u8)(v>>16);
@@ -28739,10 +28831,13 @@
28739 ** the other 64-bit signed integer at *pA and store the result in *pA.
28740 ** Return 0 on success. Or if the operation would have resulted in an
28741 ** overflow, leave *pA unchanged and return 1.
28742 */
28743 SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){
 
 
 
28744 i64 iA = *pA;
28745 testcase( iA==0 ); testcase( iA==1 );
28746 testcase( iB==-1 ); testcase( iB==0 );
28747 if( iB>=0 ){
28748 testcase( iA>0 && LARGEST_INT64 - iA == iB );
@@ -28753,23 +28848,31 @@
28753 testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 2 );
28754 if( iA<0 && -(iA + LARGEST_INT64) > iB + 1 ) return 1;
28755 }
28756 *pA += iB;
28757 return 0;
 
28758 }
28759 SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){
 
 
 
28760 testcase( iB==SMALLEST_INT64+1 );
28761 if( iB==SMALLEST_INT64 ){
28762 testcase( (*pA)==(-1) ); testcase( (*pA)==0 );
28763 if( (*pA)>=0 ) return 1;
28764 *pA -= iB;
28765 return 0;
28766 }else{
28767 return sqlite3AddInt64(pA, -iB);
28768 }
 
28769 }
28770 SQLITE_PRIVATE int sqlite3MulInt64(i64 *pA, i64 iB){
 
 
 
28771 i64 iA = *pA;
28772 if( iB>0 ){
28773 if( iA>LARGEST_INT64/iB ) return 1;
28774 if( iA<SMALLEST_INT64/iB ) return 1;
28775 }else if( iB<0 ){
@@ -28781,10 +28884,11 @@
28781 if( -iA>LARGEST_INT64/-iB ) return 1;
28782 }
28783 }
28784 *pA = iA*iB;
28785 return 0;
 
28786 }
28787
28788 /*
28789 ** Compute the absolute value of a 32-bit signed integer, of possible. Or
28790 ** if the integer has a value of -2147483648, return +2147483647
@@ -47485,18 +47589,24 @@
47485 ** if( pPager->jfd->pMethods ){ ...
47486 */
47487 #define isOpen(pFd) ((pFd)->pMethods!=0)
47488
47489 /*
47490 ** Return true if this pager uses a write-ahead log instead of the usual
47491 ** rollback journal. Otherwise false.
47492 */
 
 
 
 
 
 
 
 
 
47493 #ifndef SQLITE_OMIT_WAL
47494 SQLITE_PRIVATE int sqlite3PagerUseWal(Pager *pPager){
47495 return (pPager->pWal!=0);
47496 }
47497 # define pagerUseWal(x) sqlite3PagerUseWal(x)
47498 #else
47499 # define pagerUseWal(x) 0
47500 # define pagerRollbackWal(x) 0
47501 # define pagerWalFrames(v,w,x,y) 0
47502 # define pagerOpenWalIfPresent(z) SQLITE_OK
@@ -58445,15 +58555,13 @@
58445 ** two-byte aligned address. get2bytea() is only used for accessing the
58446 ** cell addresses in a btree header.
58447 */
58448 #if SQLITE_BYTEORDER==4321
58449 # define get2byteAligned(x) (*(u16*)(x))
58450 #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
58451 && GCC_VERSION>=4008000
58452 # define get2byteAligned(x) __builtin_bswap16(*(u16*)(x))
58453 #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \
58454 && defined(_MSC_VER) && _MSC_VER>=1300
58455 # define get2byteAligned(x) _byteswap_ushort(*(u16*)(x))
58456 #else
58457 # define get2byteAligned(x) ((x)[0]<<8 | (x)[1])
58458 #endif
58459
@@ -58624,27 +58732,38 @@
58624 ** Enter the mutexes in accending order by BtShared pointer address
58625 ** to avoid the possibility of deadlock when two threads with
58626 ** two or more btrees in common both try to lock all their btrees
58627 ** at the same instant.
58628 */
58629 SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){
58630 int i;
 
58631 Btree *p;
58632 assert( sqlite3_mutex_held(db->mutex) );
58633 for(i=0; i<db->nDb; i++){
58634 p = db->aDb[i].pBt;
58635 if( p ) sqlite3BtreeEnter(p);
 
 
 
58636 }
 
58637 }
58638 SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3 *db){
 
 
 
58639 int i;
58640 Btree *p;
58641 assert( sqlite3_mutex_held(db->mutex) );
58642 for(i=0; i<db->nDb; i++){
58643 p = db->aDb[i].pBt;
58644 if( p ) sqlite3BtreeLeave(p);
58645 }
 
 
 
58646 }
58647
58648 #ifndef NDEBUG
58649 /*
58650 ** Return true if the current thread holds the database connection
@@ -62097,16 +62216,18 @@
62097 for(i=0; i<nCell; i++){
62098 u8 *pCell = findCell(pPage, i);
62099 if( eType==PTRMAP_OVERFLOW1 ){
62100 CellInfo info;
62101 pPage->xParseCell(pPage, pCell, &info);
62102 if( info.nLocal<info.nPayload
62103 && pCell+info.nSize-1<=pPage->aData+pPage->maskPage
62104 && iFrom==get4byte(pCell+info.nSize-4)
62105 ){
62106 put4byte(pCell+info.nSize-4, iTo);
62107 break;
 
 
62108 }
62109 }else{
62110 if( get4byte(pCell)==iFrom ){
62111 put4byte(pCell, iTo);
62112 break;
@@ -62777,11 +62898,16 @@
62777 if( p && p->inTrans==TRANS_WRITE ){
62778 BtShared *pBt = p->pBt;
62779 assert( op==SAVEPOINT_RELEASE || op==SAVEPOINT_ROLLBACK );
62780 assert( iSavepoint>=0 || (iSavepoint==-1 && op==SAVEPOINT_ROLLBACK) );
62781 sqlite3BtreeEnter(p);
62782 rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint);
 
 
 
 
 
62783 if( rc==SQLITE_OK ){
62784 if( iSavepoint<0 && (pBt->btsFlags & BTS_INITIALLY_EMPTY)!=0 ){
62785 pBt->nPage = 0;
62786 }
62787 rc = newDatabase(pBt);
@@ -63163,25 +63289,24 @@
63163 ** for the entry that the pCur cursor is pointing to. The eOp
63164 ** argument is interpreted as follows:
63165 **
63166 ** 0: The operation is a read. Populate the overflow cache.
63167 ** 1: The operation is a write. Populate the overflow cache.
63168 ** 2: The operation is a read. Do not populate the overflow cache.
63169 **
63170 ** A total of "amt" bytes are read or written beginning at "offset".
63171 ** Data is read to or from the buffer pBuf.
63172 **
63173 ** The content being read or written might appear on the main page
63174 ** or be scattered out on multiple overflow pages.
63175 **
63176 ** If the current cursor entry uses one or more overflow pages and the
63177 ** eOp argument is not 2, this function may allocate space for and lazily
63178 ** populates the overflow page-list cache array (BtCursor.aOverflow).
63179 ** Subsequent calls use this cache to make seeking to the supplied offset
63180 ** more efficient.
63181 **
63182 ** Once an overflow page-list cache has been allocated, it may be
63183 ** invalidated if some other cursor writes to the same table, or if
63184 ** the cursor is moved to a different row. Additionally, in auto-vacuum
63185 ** mode, the following events may invalidate an overflow page-list cache.
63186 **
63187 ** * An incremental vacuum,
@@ -63199,25 +63324,21 @@
63199 int rc = SQLITE_OK;
63200 int iIdx = 0;
63201 MemPage *pPage = pCur->apPage[pCur->iPage]; /* Btree page of current entry */
63202 BtShared *pBt = pCur->pBt; /* Btree this cursor belongs to */
63203 #ifdef SQLITE_DIRECT_OVERFLOW_READ
63204 unsigned char * const pBufStart = pBuf;
63205 int bEnd; /* True if reading to end of data */
63206 #endif
63207
63208 assert( pPage );
 
63209 assert( pCur->eState==CURSOR_VALID );
63210 assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
63211 assert( cursorHoldsMutex(pCur) );
63212 assert( eOp!=2 || offset==0 ); /* Always start from beginning for eOp==2 */
63213
63214 getCellInfo(pCur);
63215 aPayload = pCur->info.pPayload;
63216 #ifdef SQLITE_DIRECT_OVERFLOW_READ
63217 bEnd = offset+amt==pCur->info.nPayload;
63218 #endif
63219 assert( offset+amt <= pCur->info.nPayload );
63220
63221 assert( aPayload > pPage->aData );
63222 if( (uptr)(aPayload - pPage->aData) > (pBt->usableSize - pCur->info.nLocal) ){
63223 /* Trying to read or write past the end of the data is an error. The
@@ -63232,11 +63353,11 @@
63232 if( offset<pCur->info.nLocal ){
63233 int a = amt;
63234 if( a+offset>pCur->info.nLocal ){
63235 a = pCur->info.nLocal - offset;
63236 }
63237 rc = copyPayload(&aPayload[offset], pBuf, a, (eOp & 0x01), pPage->pDbPage);
63238 offset = 0;
63239 pBuf += a;
63240 amt -= a;
63241 }else{
63242 offset -= pCur->info.nLocal;
@@ -63248,69 +63369,58 @@
63248 Pgno nextPage;
63249
63250 nextPage = get4byte(&aPayload[pCur->info.nLocal]);
63251
63252 /* If the BtCursor.aOverflow[] has not been allocated, allocate it now.
63253 ** Except, do not allocate aOverflow[] for eOp==2.
63254 **
63255 ** The aOverflow[] array is sized at one entry for each overflow page
63256 ** in the overflow chain. The page number of the first overflow page is
63257 ** stored in aOverflow[0], etc. A value of 0 in the aOverflow[] array
63258 ** means "not yet known" (the cache is lazily populated).
63259 */
63260 if( eOp!=2 && (pCur->curFlags & BTCF_ValidOvfl)==0 ){
63261 int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize;
63262 if( nOvfl>pCur->nOvflAlloc ){
63263 Pgno *aNew = (Pgno*)sqlite3Realloc(
63264 pCur->aOverflow, nOvfl*2*sizeof(Pgno)
63265 );
63266 if( aNew==0 ){
63267 rc = SQLITE_NOMEM_BKPT;
63268 }else{
63269 pCur->nOvflAlloc = nOvfl*2;
63270 pCur->aOverflow = aNew;
63271 }
63272 }
63273 if( rc==SQLITE_OK ){
63274 memset(pCur->aOverflow, 0, nOvfl*sizeof(Pgno));
63275 pCur->curFlags |= BTCF_ValidOvfl;
 
 
 
 
 
 
 
 
63276 }
63277 }
63278
63279 /* If the overflow page-list cache has been allocated and the
63280 ** entry for the first required overflow page is valid, skip
63281 ** directly to it.
63282 */
63283 if( (pCur->curFlags & BTCF_ValidOvfl)!=0
63284 && pCur->aOverflow[offset/ovflSize]
63285 ){
63286 iIdx = (offset/ovflSize);
63287 nextPage = pCur->aOverflow[iIdx];
63288 offset = (offset%ovflSize);
63289 }
63290
63291 for( ; rc==SQLITE_OK && amt>0 && nextPage; iIdx++){
63292
63293 /* If required, populate the overflow page-list cache. */
63294 if( (pCur->curFlags & BTCF_ValidOvfl)!=0 ){
63295 assert( pCur->aOverflow[iIdx]==0
63296 || pCur->aOverflow[iIdx]==nextPage
63297 || CORRUPT_DB );
63298 pCur->aOverflow[iIdx] = nextPage;
63299 }
63300
63301 if( offset>=ovflSize ){
63302 /* The only reason to read this page is to obtain the page
63303 ** number for the next page in the overflow chain. The page
63304 ** data is not required. So first try to lookup the overflow
63305 ** page-list cache, if any, then fall back to the getOverflowPage()
63306 ** function.
63307 **
63308 ** Note that the aOverflow[] array must be allocated because eOp!=2
63309 ** here. If eOp==2, then offset==0 and this branch is never taken.
63310 */
63311 assert( eOp!=2 );
63312 assert( pCur->curFlags & BTCF_ValidOvfl );
63313 assert( pCur->pBtree->db==pBt->db );
63314 if( pCur->aOverflow[iIdx+1] ){
63315 nextPage = pCur->aOverflow[iIdx+1];
63316 }else{
@@ -63320,11 +63430,11 @@
63320 }else{
63321 /* Need to read this page properly. It contains some of the
63322 ** range of data that is being read (eOp==0) or written (eOp!=0).
63323 */
63324 #ifdef SQLITE_DIRECT_OVERFLOW_READ
63325 sqlite3_file *fd;
63326 #endif
63327 int a = amt;
63328 if( a + offset > ovflSize ){
63329 a = ovflSize - offset;
63330 }
@@ -63332,31 +63442,29 @@
63332 #ifdef SQLITE_DIRECT_OVERFLOW_READ
63333 /* If all the following are true:
63334 **
63335 ** 1) this is a read operation, and
63336 ** 2) data is required from the start of this overflow page, and
63337 ** 3) the database is file-backed, and
63338 ** 4) there is no open write-transaction, and
63339 ** 5) the database is not a WAL database,
63340 ** 6) all data from the page is being read.
63341 ** 7) at least 4 bytes have already been read into the output buffer
63342 **
63343 ** then data can be read directly from the database file into the
63344 ** output buffer, bypassing the page-cache altogether. This speeds
63345 ** up loading large records that span many overflow pages.
63346 */
63347 if( (eOp&0x01)==0 /* (1) */
63348 && offset==0 /* (2) */
63349 && (bEnd || a==ovflSize) /* (6) */
63350 && pBt->inTransaction==TRANS_READ /* (4) */
63351 && (fd = sqlite3PagerFile(pBt->pPager))->pMethods /* (3) */
63352 && 0==sqlite3PagerUseWal(pBt->pPager) /* (5) */
63353 && &pBuf[-4]>=pBufStart /* (7) */
63354 ){
63355 u8 aSave[4];
63356 u8 *aWrite = &pBuf[-4];
63357 assert( aWrite>=pBufStart ); /* hence (7) */
63358 memcpy(aSave, aWrite, 4);
63359 rc = sqlite3OsRead(fd, aWrite, a+4, (i64)pBt->pageSize*(nextPage-1));
63360 nextPage = get4byte(aWrite);
63361 memcpy(aWrite, aSave, 4);
63362 }else
@@ -63363,28 +63471,31 @@
63363 #endif
63364
63365 {
63366 DbPage *pDbPage;
63367 rc = sqlite3PagerGet(pBt->pPager, nextPage, &pDbPage,
63368 ((eOp&0x01)==0 ? PAGER_GET_READONLY : 0)
63369 );
63370 if( rc==SQLITE_OK ){
63371 aPayload = sqlite3PagerGetData(pDbPage);
63372 nextPage = get4byte(aPayload);
63373 rc = copyPayload(&aPayload[offset+4], pBuf, a, (eOp&0x01), pDbPage);
63374 sqlite3PagerUnref(pDbPage);
63375 offset = 0;
63376 }
63377 }
63378 amt -= a;
 
63379 pBuf += a;
63380 }
 
 
63381 }
63382 }
63383
63384 if( rc==SQLITE_OK && amt>0 ){
63385 return SQLITE_CORRUPT_BKPT;
63386 }
63387 return rc;
63388 }
63389
63390 /*
@@ -63409,25 +63520,38 @@
63409 assert( pCur->eState==CURSOR_VALID );
63410 assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
63411 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
63412 return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
63413 }
 
 
 
 
 
 
63414 #ifndef SQLITE_OMIT_INCRBLOB
63415 SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
 
 
 
 
 
63416 int rc;
63417 if ( pCur->eState==CURSOR_INVALID ){
63418 return SQLITE_ABORT;
63419 }
63420 assert( cursorOwnsBtShared(pCur) );
63421 rc = restoreCursorPosition(pCur);
63422 if( rc==SQLITE_OK ){
63423 assert( pCur->eState==CURSOR_VALID );
63424 assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
63425 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
63426 rc = accessPayload(pCur, offset, amt, pBuf, 0);
63427 }
63428 return rc;
 
 
63429 }
63430 #endif /* SQLITE_OMIT_INCRBLOB */
63431
63432 /*
63433 ** Return a pointer to payload information from the entry that the
@@ -63829,13 +63953,30 @@
63829 ){
63830 if( pCur->info.nKey==intKey ){
63831 *pRes = 0;
63832 return SQLITE_OK;
63833 }
63834 if( (pCur->curFlags & BTCF_AtLast)!=0 && pCur->info.nKey<intKey ){
63835 *pRes = -1;
63836 return SQLITE_OK;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63837 }
63838 }
63839
63840 if( pIdxKey ){
63841 xRecordCompare = sqlite3VdbeFindCompare(pIdxKey);
@@ -63967,11 +64108,12 @@
63967 if( pCellKey==0 ){
63968 rc = SQLITE_NOMEM_BKPT;
63969 goto moveto_finish;
63970 }
63971 pCur->aiIdx[pCur->iPage] = (u16)idx;
63972 rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 2);
 
63973 if( rc ){
63974 sqlite3_free(pCellKey);
63975 goto moveto_finish;
63976 }
63977 c = xRecordCompare(nCell, pCellKey, pIdxKey);
@@ -66010,11 +66152,10 @@
66010 */
66011 usableSpace = pBt->usableSize - 12 + leafCorrection;
66012 for(i=0; i<nOld; i++){
66013 MemPage *p = apOld[i];
66014 szNew[i] = usableSpace - p->nFree;
66015 if( szNew[i]<0 ){ rc = SQLITE_CORRUPT_BKPT; goto balance_cleanup; }
66016 for(j=0; j<p->nOverflow; j++){
66017 szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]);
66018 }
66019 cntNew[i] = cntOld[i];
66020 }
@@ -66689,11 +66830,11 @@
66689 ** to decode the key.
66690 */
66691 SQLITE_PRIVATE int sqlite3BtreeInsert(
66692 BtCursor *pCur, /* Insert data into the table of this cursor */
66693 const BtreePayload *pX, /* Content of the row to be inserted */
66694 int appendBias, /* True if this is likely an append */
66695 int seekResult /* Result of prior MovetoUnpacked() call */
66696 ){
66697 int rc;
66698 int loc = seekResult; /* -1: before desired location +1: after */
66699 int szNew = 0;
@@ -66701,10 +66842,12 @@
66701 MemPage *pPage;
66702 Btree *p = pCur->pBtree;
66703 BtShared *pBt = p->pBt;
66704 unsigned char *oldCell;
66705 unsigned char *newCell = 0;
 
 
66706
66707 if( pCur->eState==CURSOR_FAULT ){
66708 assert( pCur->skipNext!=SQLITE_OK );
66709 return pCur->skipNext;
66710 }
@@ -66742,23 +66885,28 @@
66742 assert( pX->pKey==0 );
66743 /* If this is an insert into a table b-tree, invalidate any incrblob
66744 ** cursors open on the row being replaced */
66745 invalidateIncrblobCursors(p, pX->nKey, 0);
66746
 
 
 
 
 
66747 /* If the cursor is currently on the last row and we are appending a
66748 ** new row onto the end, set the "loc" to avoid an unnecessary
66749 ** btreeMoveto() call */
66750 if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey ){
66751 loc = 0;
66752 }else if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey>0
66753 && pCur->info.nKey==pX->nKey-1 ){
66754 loc = -1;
66755 }else if( loc==0 ){
66756 rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, appendBias, &loc);
66757 if( rc ) return rc;
66758 }
66759 }else if( loc==0 ){
66760 if( pX->nMem ){
66761 UnpackedRecord r;
66762 r.pKeyInfo = pCur->pKeyInfo;
66763 r.aMem = pX->aMem;
66764 r.nField = pX->nMem;
@@ -66765,13 +66913,13 @@
66765 r.default_rc = 0;
66766 r.errCode = 0;
66767 r.r1 = 0;
66768 r.r2 = 0;
66769 r.eqSeen = 0;
66770 rc = sqlite3BtreeMovetoUnpacked(pCur, &r, 0, appendBias, &loc);
66771 }else{
66772 rc = btreeMoveto(pCur, pX->pKey, pX->nKey, appendBias, &loc);
66773 }
66774 if( rc ) return rc;
66775 }
66776 assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );
66777
@@ -66855,10 +67003,24 @@
66855 ** fails. Internal data structure corruption will result otherwise.
66856 ** Also, set the cursor state to invalid. This stops saveCursorPosition()
66857 ** from trying to save the current position of the cursor. */
66858 pCur->apPage[pCur->iPage]->nOverflow = 0;
66859 pCur->eState = CURSOR_INVALID;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66860 }
66861 assert( pCur->apPage[pCur->iPage]->nOverflow==0 );
66862
66863 end_insert:
66864 return rc;
@@ -71765,11 +71927,11 @@
71765 sqlite3VdbeGetOp(p,addr)->p2 = val;
71766 }
71767 SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe *p, u32 addr, int val){
71768 sqlite3VdbeGetOp(p,addr)->p3 = val;
71769 }
71770 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe *p, u8 p5){
71771 assert( p->nOp>0 || p->db->mallocFailed );
71772 if( p->nOp>0 ) p->aOp[p->nOp-1].p5 = p5;
71773 }
71774
71775 /*
@@ -73479,64 +73641,63 @@
73479 ** statement transaction is committed.
73480 **
73481 ** If an IO error occurs, an SQLITE_IOERR_XXX error code is returned.
73482 ** Otherwise SQLITE_OK.
73483 */
73484 SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *p, int eOp){
73485 sqlite3 *const db = p->db;
73486 int rc = SQLITE_OK;
73487
73488 /* If p->iStatement is greater than zero, then this Vdbe opened a
73489 ** statement transaction that should be closed here. The only exception
73490 ** is that an IO error may have occurred, causing an emergency rollback.
73491 ** In this case (db->nStatement==0), and there is nothing to do.
73492 */
73493 if( db->nStatement && p->iStatement ){
73494 int i;
73495 const int iSavepoint = p->iStatement-1;
73496
73497 assert( eOp==SAVEPOINT_ROLLBACK || eOp==SAVEPOINT_RELEASE);
73498 assert( db->nStatement>0 );
73499 assert( p->iStatement==(db->nStatement+db->nSavepoint) );
73500
73501 for(i=0; i<db->nDb; i++){
73502 int rc2 = SQLITE_OK;
73503 Btree *pBt = db->aDb[i].pBt;
73504 if( pBt ){
73505 if( eOp==SAVEPOINT_ROLLBACK ){
73506 rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_ROLLBACK, iSavepoint);
73507 }
73508 if( rc2==SQLITE_OK ){
73509 rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_RELEASE, iSavepoint);
73510 }
73511 if( rc==SQLITE_OK ){
73512 rc = rc2;
73513 }
73514 }
73515 }
73516 db->nStatement--;
73517 p->iStatement = 0;
73518
73519 if( rc==SQLITE_OK ){
73520 if( eOp==SAVEPOINT_ROLLBACK ){
73521 rc = sqlite3VtabSavepoint(db, SAVEPOINT_ROLLBACK, iSavepoint);
73522 }
73523 if( rc==SQLITE_OK ){
73524 rc = sqlite3VtabSavepoint(db, SAVEPOINT_RELEASE, iSavepoint);
73525 }
73526 }
73527
73528 /* If the statement transaction is being rolled back, also restore the
73529 ** database handles deferred constraint counter to the value it had when
73530 ** the statement transaction was opened. */
73531 if( eOp==SAVEPOINT_ROLLBACK ){
73532 db->nDeferredCons = p->nStmtDefCons;
73533 db->nDeferredImmCons = p->nStmtDefImmCons;
73534 }
73535 }
73536 return rc;
73537 }
73538
73539 /*
73540 ** This function is called when a transaction opened by the database
73541 ** handle associated with the VM passed as an argument is about to be
73542 ** committed. If there are outstanding deferred foreign key constraint
@@ -75567,14 +75728,14 @@
75567 ** structure itself, using sqlite3DbFree().
75568 **
75569 ** This function is used to free UnpackedRecord structures allocated by
75570 ** the vdbeUnpackRecord() function found in vdbeapi.c.
75571 */
75572 static void vdbeFreeUnpacked(sqlite3 *db, UnpackedRecord *p){
75573 if( p ){
75574 int i;
75575 for(i=0; i<p->nField; i++){
75576 Mem *pMem = &p->aMem[i];
75577 if( pMem->zMalloc ) sqlite3VdbeMemRelease(pMem);
75578 }
75579 sqlite3DbFree(db, p);
75580 }
@@ -75603,14 +75764,19 @@
75603 const char *zTbl = pTab->zName;
75604 static const u8 fakeSortOrder = 0;
75605
75606 assert( db->pPreUpdate==0 );
75607 memset(&preupdate, 0, sizeof(PreUpdate));
75608 if( op==SQLITE_UPDATE ){
75609 iKey2 = v->aMem[iReg].u.i;
 
75610 }else{
75611 iKey2 = iKey1;
 
 
 
 
75612 }
75613
75614 assert( pCsr->nField==pTab->nCol
75615 || (pCsr->nField==pTab->nCol+1 && op==SQLITE_DELETE && iReg==-1)
75616 );
@@ -75629,12 +75795,12 @@
75629
75630 db->pPreUpdate = &preupdate;
75631 db->xPreUpdateCallback(db->pPreUpdateArg, db, op, zDb, zTbl, iKey1, iKey2);
75632 db->pPreUpdate = 0;
75633 sqlite3DbFree(db, preupdate.aRecord);
75634 vdbeFreeUnpacked(db, preupdate.pUnpacked);
75635 vdbeFreeUnpacked(db, preupdate.pNewUnpacked);
75636 if( preupdate.aNew ){
75637 int i;
75638 for(i=0; i<pCsr->nField; i++){
75639 sqlite3VdbeMemRelease(&preupdate.aNew[i]);
75640 }
@@ -77305,18 +77471,22 @@
77305 ** This function is called from within a pre-update callback to retrieve
77306 ** a field of the row currently being updated or deleted.
77307 */
77308 SQLITE_API int sqlite3_preupdate_old(sqlite3 *db, int iIdx, sqlite3_value **ppValue){
77309 PreUpdate *p = db->pPreUpdate;
 
77310 int rc = SQLITE_OK;
77311
77312 /* Test that this call is being made from within an SQLITE_DELETE or
77313 ** SQLITE_UPDATE pre-update callback, and that iIdx is within range. */
77314 if( !p || p->op==SQLITE_INSERT ){
77315 rc = SQLITE_MISUSE_BKPT;
77316 goto preupdate_old_out;
77317 }
 
 
 
77318 if( iIdx>=p->pCsr->nField || iIdx<0 ){
77319 rc = SQLITE_RANGE;
77320 goto preupdate_old_out;
77321 }
77322
@@ -77338,21 +77508,18 @@
77338 goto preupdate_old_out;
77339 }
77340 p->aRecord = aRec;
77341 }
77342
77343 if( iIdx>=p->pUnpacked->nField ){
 
 
 
77344 *ppValue = (sqlite3_value *)columnNullValue();
77345 }else{
77346 Mem *pMem = *ppValue = &p->pUnpacked->aMem[iIdx];
77347 *ppValue = &p->pUnpacked->aMem[iIdx];
77348 if( iIdx==p->pTab->iPKey ){
77349 sqlite3VdbeMemSetInt64(pMem, p->iKey1);
77350 }else if( p->pTab->aCol[iIdx].affinity==SQLITE_AFF_REAL ){
77351 if( pMem->flags & MEM_Int ){
77352 sqlite3VdbeMemRealify(pMem);
77353 }
77354 }
77355 }
77356
77357 preupdate_old_out:
77358 sqlite3Error(db, rc);
@@ -77401,10 +77568,13 @@
77401
77402 if( !p || p->op==SQLITE_DELETE ){
77403 rc = SQLITE_MISUSE_BKPT;
77404 goto preupdate_new_out;
77405 }
 
 
 
77406 if( iIdx>=p->pCsr->nField || iIdx<0 ){
77407 rc = SQLITE_RANGE;
77408 goto preupdate_new_out;
77409 }
77410
@@ -77421,17 +77591,15 @@
77421 rc = SQLITE_NOMEM;
77422 goto preupdate_new_out;
77423 }
77424 p->pNewUnpacked = pUnpack;
77425 }
77426 if( iIdx>=pUnpack->nField ){
 
 
 
77427 pMem = (sqlite3_value *)columnNullValue();
77428 }else{
77429 pMem = &pUnpack->aMem[iIdx];
77430 if( iIdx==p->pTab->iPKey ){
77431 sqlite3VdbeMemSetInt64(pMem, p->iKey2);
77432 }
77433 }
77434 }else{
77435 /* For an UPDATE, memory cell (p->iNewReg+1+iIdx) contains the required
77436 ** value. Make a copy of the cell contents and return a pointer to it.
77437 ** It is not safe to return a pointer to the memory cell itself as the
@@ -78404,12 +78572,10 @@
78404 Mem *aMem = p->aMem; /* Copy of p->aMem */
78405 Mem *pIn1 = 0; /* 1st input operand */
78406 Mem *pIn2 = 0; /* 2nd input operand */
78407 Mem *pIn3 = 0; /* 3rd input operand */
78408 Mem *pOut = 0; /* Output operand */
78409 int *aPermute = 0; /* Permutation of columns for OP_Compare */
78410 i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
78411 #ifdef VDBE_PROFILE
78412 u64 start; /* CPU clock count at start of opcode */
78413 #endif
78414 /*** INSERT STACK UNION HERE ***/
78415
@@ -78420,11 +78586,10 @@
78420 ** sqlite3_column_text16() failed. */
78421 goto no_mem;
78422 }
78423 assert( p->rc==SQLITE_OK || (p->rc&0xff)==SQLITE_BUSY );
78424 assert( p->bIsReader || p->readOnly!=0 );
78425 p->rc = SQLITE_OK;
78426 p->iCurrentTime = 0;
78427 assert( p->explain==0 );
78428 p->pResultSet = 0;
78429 db->busyHandler.nBusy = 0;
78430 if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
@@ -78781,11 +78946,10 @@
78781 pFrame = p->pFrame;
78782 p->pFrame = pFrame->pParent;
78783 p->nFrame--;
78784 sqlite3VdbeSetChanges(db, p->nChange);
78785 pcx = sqlite3VdbeFrameRestore(pFrame);
78786 lastRowid = db->lastRowid;
78787 if( pOp->p2==OE_Ignore ){
78788 /* Instruction pcx is the OP_Program that invoked the sub-program
78789 ** currently being halted. If the p2 instruction of this OP_Halt
78790 ** instruction is set to OE_Ignore, then the sub-program is throwing
78791 ** an IGNORE exception. In this case jump to the address specified
@@ -79016,11 +79180,11 @@
79016 assert( pOp->p4.z==0 || pOp->p4.z==sqlite3VListNumToName(p->pVList,pOp->p1) );
79017 pVar = &p->aVar[pOp->p1 - 1];
79018 if( sqlite3VdbeMemTooBig(pVar) ){
79019 goto too_big;
79020 }
79021 pOut = out2Prerelease(p, pOp);
79022 sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static);
79023 UPDATE_MAX_BLOBSIZE(pOut);
79024 break;
79025 }
79026
@@ -79503,13 +79667,11 @@
79503 REGISTER_TRACE(pOp->p2+i, pCtx->argv[i]);
79504 }
79505 #endif
79506 MemSetTypeFlag(pCtx->pOut, MEM_Null);
79507 pCtx->fErrorOrAux = 0;
79508 db->lastRowid = lastRowid;
79509 (*pCtx->pFunc->xSFunc)(pCtx, pCtx->argc, pCtx->argv);/* IMP: R-24505-23230 */
79510 lastRowid = db->lastRowid; /* Remember rowid changes made by xSFunc */
79511
79512 /* If the function returned an error, throw an exception */
79513 if( pCtx->fErrorOrAux ){
79514 if( pCtx->isError ){
79515 sqlite3VdbeError(p, "%s", sqlite3_value_text(pCtx->pOut));
@@ -79961,12 +80123,12 @@
79961 }
79962
79963
79964 /* Opcode: Permutation * * * P4 *
79965 **
79966 ** Set the permutation used by the OP_Compare operator to be the array
79967 ** of integers in P4.
79968 **
79969 ** The permutation is only valid until the next OP_Compare that has
79970 ** the OPFLAG_PERMUTE bit set in P5. Typically the OP_Permutation should
79971 ** occur immediately prior to the OP_Compare.
79972 **
@@ -79974,11 +80136,12 @@
79974 ** and does not become part of the permutation.
79975 */
79976 case OP_Permutation: {
79977 assert( pOp->p4type==P4_INTARRAY );
79978 assert( pOp->p4.ai );
79979 aPermute = pOp->p4.ai + 1;
 
79980 break;
79981 }
79982
79983 /* Opcode: Compare P1 P2 P3 P4 P5
79984 ** Synopsis: r[P1@P3] <-> r[P2@P3]
@@ -80007,12 +80170,21 @@
80007 int p2;
80008 const KeyInfo *pKeyInfo;
80009 int idx;
80010 CollSeq *pColl; /* Collating sequence to use on this term */
80011 int bRev; /* True for DESCENDING sort order */
 
80012
80013 if( (pOp->p5 & OPFLAG_PERMUTE)==0 ) aPermute = 0;
 
 
 
 
 
 
 
 
80014 n = pOp->p3;
80015 pKeyInfo = pOp->p4.pKeyInfo;
80016 assert( n>0 );
80017 assert( pKeyInfo!=0 );
80018 p1 = pOp->p1;
@@ -80041,11 +80213,10 @@
80041 if( iCompare ){
80042 if( bRev ) iCompare = -iCompare;
80043 break;
80044 }
80045 }
80046 aPermute = 0;
80047 break;
80048 }
80049
80050 /* Opcode: Jump P1 P2 P3 * *
80051 **
@@ -80597,10 +80768,24 @@
80597 do{
80598 applyAffinity(pRec++, *(zAffinity++), encoding);
80599 assert( zAffinity[0]==0 || pRec<=pLast );
80600 }while( zAffinity[0] );
80601 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80602
80603 /* Loop through the elements that will make up the record to figure
80604 ** out how much space is required for the new record.
80605 */
80606 pRec = pLast;
@@ -82187,11 +82372,11 @@
82187 assert( memIsValid(pData) );
82188 pC = p->apCsr[pOp->p1];
82189 assert( pC!=0 );
82190 assert( pC->eCurType==CURTYPE_BTREE );
82191 assert( pC->uc.pCursor!=0 );
82192 assert( pC->isTable );
82193 assert( pOp->p4type==P4_TABLE || pOp->p4type>=P4_STATIC );
82194 REGISTER_TRACE(pOp->p2, pData);
82195
82196 if( pOp->opcode==OP_Insert ){
82197 pKey = &aMem[pOp->p3];
@@ -82203,18 +82388,17 @@
82203 assert( pOp->opcode==OP_InsertInt );
82204 x.nKey = pOp->p3;
82205 }
82206
82207 if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
82208 assert( pC->isTable );
82209 assert( pC->iDb>=0 );
82210 zDb = db->aDb[pC->iDb].zDbSName;
82211 pTab = pOp->p4.pTab;
82212 assert( HasRowid(pTab) );
82213 op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT);
82214 }else{
82215 pTab = 0; /* Not needed. Silence a comiler warning. */
82216 zDb = 0; /* Not needed. Silence a compiler warning. */
82217 }
82218
82219 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
82220 /* Invoke the pre-update hook, if any */
@@ -82222,14 +82406,15 @@
82222 && pOp->p4type==P4_TABLE
82223 && !(pOp->p5 & OPFLAG_ISUPDATE)
82224 ){
82225 sqlite3VdbePreUpdateHook(p, pC, SQLITE_INSERT, zDb, pTab, x.nKey, pOp->p2);
82226 }
 
82227 #endif
82228
82229 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
82230 if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = x.nKey;
82231 if( pData->flags & MEM_Null ){
82232 x.pData = 0;
82233 x.nData = 0;
82234 }else{
82235 assert( pData->flags & (MEM_Blob|MEM_Str) );
@@ -82242,11 +82427,11 @@
82242 }else{
82243 x.nZero = 0;
82244 }
82245 x.pKey = 0;
82246 rc = sqlite3BtreeInsert(pC->uc.pCursor, &x,
82247 (pOp->p5 & OPFLAG_APPEND)!=0, seekResult
82248 );
82249 pC->deferredMoveto = 0;
82250 pC->cacheStatus = CACHE_STALE;
82251
82252 /* Invoke the update-hook if required. */
@@ -82334,12 +82519,15 @@
82334 pTab = 0; /* Not needed. Silence a compiler warning. */
82335 }
82336
82337 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
82338 /* Invoke the pre-update-hook if required. */
82339 if( db->xPreUpdateCallback && pOp->p4.pTab && HasRowid(pTab) ){
82340 assert( !(opflags & OPFLAG_ISUPDATE) || (aMem[pOp->p3].flags & MEM_Int) );
 
 
 
82341 sqlite3VdbePreUpdateHook(p, pC,
82342 (opflags & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_DELETE,
82343 zDb, pTab, pC->movetoTarget,
82344 pOp->p3
82345 );
@@ -82453,11 +82641,11 @@
82453 if( rc ) goto abort_due_to_error;
82454 p->apCsr[pOp->p3]->cacheStatus = CACHE_STALE;
82455 break;
82456 }
82457
82458 /* Opcode: RowData P1 P2 * * *
82459 ** Synopsis: r[P2]=data
82460 **
82461 ** Write into register P2 the complete row content for the row at
82462 ** which cursor P1 is currently pointing.
82463 ** There is no interpretation of the data.
@@ -82467,18 +82655,30 @@
82467 ** If cursor P1 is an index, then the content is the key of the row.
82468 ** If cursor P2 is a table, then the content extracted is the data.
82469 **
82470 ** If the P1 cursor must be pointing to a valid row (not a NULL row)
82471 ** of a real table, not a pseudo-table.
 
 
 
 
 
 
 
 
 
 
 
 
 
82472 */
82473 case OP_RowData: {
82474 VdbeCursor *pC;
82475 BtCursor *pCrsr;
82476 u32 n;
82477
82478 pOut = &aMem[pOp->p2];
82479 memAboutToChange(p, pOut);
82480
82481 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
82482 pC = p->apCsr[pOp->p1];
82483 assert( pC!=0 );
82484 assert( pC->eCurType==CURTYPE_BTREE );
@@ -82505,18 +82705,13 @@
82505 n = sqlite3BtreePayloadSize(pCrsr);
82506 if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
82507 goto too_big;
82508 }
82509 testcase( n==0 );
82510 if( sqlite3VdbeMemClearAndResize(pOut, MAX(n,32)) ){
82511 goto no_mem;
82512 }
82513 pOut->n = n;
82514 MemSetTypeFlag(pOut, MEM_Blob);
82515 rc = sqlite3BtreePayload(pCrsr, 0, n, pOut->z);
82516 if( rc ) goto abort_due_to_error;
82517 pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */
82518 UPDATE_MAX_BLOBSIZE(pOut);
82519 REGISTER_TRACE(pOp->p2, pOut);
82520 break;
82521 }
82522
@@ -82900,11 +83095,11 @@
82900 x.nKey = pIn2->n;
82901 x.pKey = pIn2->z;
82902 x.aMem = aMem + pOp->p3;
82903 x.nMem = (u16)pOp->p4.i;
82904 rc = sqlite3BtreeInsert(pC->uc.pCursor, &x,
82905 (pOp->p5 & OPFLAG_APPEND)!=0,
82906 ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0)
82907 );
82908 assert( pC->deferredMoveto==0 );
82909 pC->cacheStatus = CACHE_STALE;
82910 }
@@ -83022,11 +83217,10 @@
83022 pTabCur->aAltMap = pOp->p4.ai;
83023 pTabCur->pAltCursor = pC;
83024 }else{
83025 pOut = out2Prerelease(p, pOp);
83026 pOut->u.i = rowid;
83027 pOut->flags = MEM_Int;
83028 }
83029 }else{
83030 assert( pOp->opcode==OP_IdxRowid );
83031 sqlite3VdbeMemSetNull(&aMem[pOp->p2]);
83032 }
@@ -83664,11 +83858,11 @@
83664 assert( (int)(pOp - aOp)==pFrame->pc );
83665 }
83666
83667 p->nFrame++;
83668 pFrame->pParent = p->pFrame;
83669 pFrame->lastRowid = lastRowid;
83670 pFrame->nChange = p->nChange;
83671 pFrame->nDbChange = p->db->nChange;
83672 assert( pFrame->pAuxData==0 );
83673 pFrame->pAuxData = p->pAuxData;
83674 p->pAuxData = 0;
@@ -84605,11 +84799,11 @@
84605 rc = pModule->xUpdate(pVtab, nArg, apArg, &rowid);
84606 db->vtabOnConflict = vtabOnConflict;
84607 sqlite3VtabImportErrmsg(p, pVtab);
84608 if( rc==SQLITE_OK && pOp->p1 ){
84609 assert( nArg>1 && apArg[0] && (apArg[0]->flags&MEM_Null) );
84610 db->lastRowid = lastRowid = rowid;
84611 }
84612 if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){
84613 if( pOp->p5==OE_Ignore ){
84614 rc = SQLITE_OK;
84615 }else{
@@ -84841,11 +85035,10 @@
84841
84842 /* This is the only way out of this procedure. We have to
84843 ** release the mutexes on btrees that were acquired at the
84844 ** top. */
84845 vdbe_return:
84846 db->lastRowid = lastRowid;
84847 testcase( nVmStep>0 );
84848 p->aCounter[SQLITE_STMTSTATUS_VM_STEP] += (int)nVmStep;
84849 sqlite3VdbeLeave(p);
84850 assert( rc!=SQLITE_OK || nExtraDelete==0
84851 || sqlite3_strlike("DELETE%",p->zSql,0)!=0
@@ -84905,14 +85098,13 @@
84905 /*
84906 ** Valid sqlite3_blob* handles point to Incrblob structures.
84907 */
84908 typedef struct Incrblob Incrblob;
84909 struct Incrblob {
84910 int flags; /* Copy of "flags" passed to sqlite3_blob_open() */
84911 int nByte; /* Size of open blob, in bytes */
84912 int iOffset; /* Byte offset of blob in cursor data */
84913 int iCol; /* Table column this handle is open on */
84914 BtCursor *pCsr; /* Cursor pointing at blob row */
84915 sqlite3_stmt *pStmt; /* Statement holding cursor open */
84916 sqlite3 *db; /* The associated database */
84917 char *zDb; /* Database name */
84918 Table *pTab; /* Table object */
@@ -84939,21 +85131,31 @@
84939 static int blobSeekToRow(Incrblob *p, sqlite3_int64 iRow, char **pzErr){
84940 int rc; /* Error code */
84941 char *zErr = 0; /* Error message */
84942 Vdbe *v = (Vdbe *)p->pStmt;
84943
84944 /* Set the value of the SQL statements only variable to integer iRow.
84945 ** This is done directly instead of using sqlite3_bind_int64() to avoid
84946 ** triggering asserts related to mutexes.
84947 */
84948 assert( v->aVar[0].flags&MEM_Int );
84949 v->aVar[0].u.i = iRow;
84950
84951 rc = sqlite3_step(p->pStmt);
 
 
 
 
 
 
 
 
 
84952 if( rc==SQLITE_ROW ){
84953 VdbeCursor *pC = v->apCsr[0];
84954 u32 type = pC->aType[p->iCol];
 
 
84955 if( type<12 ){
84956 zErr = sqlite3MPrintf(p->db, "cannot open value of type %s",
84957 type==0?"null": type==7?"real": "integer"
84958 );
84959 rc = SQLITE_ERROR;
@@ -84994,11 +85196,11 @@
84994 sqlite3* db, /* The database connection */
84995 const char *zDb, /* The attached database containing the blob */
84996 const char *zTable, /* The table containing the blob */
84997 const char *zColumn, /* The column containing the blob */
84998 sqlite_int64 iRow, /* The row containing the glob */
84999 int flags, /* True -> read/write access, false -> read-only */
85000 sqlite3_blob **ppBlob /* Handle for accessing the blob returned here */
85001 ){
85002 int nAttempt = 0;
85003 int iCol; /* Index of zColumn in row-record */
85004 int rc = SQLITE_OK;
@@ -85016,11 +85218,11 @@
85016 #ifdef SQLITE_ENABLE_API_ARMOR
85017 if( !sqlite3SafetyCheckOk(db) || zTable==0 ){
85018 return SQLITE_MISUSE_BKPT;
85019 }
85020 #endif
85021 flags = !!flags; /* flags = (flags ? 1 : 0); */
85022
85023 sqlite3_mutex_enter(db->mutex);
85024
85025 pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
85026 if( !pBlob ) goto blob_open_out;
@@ -85076,13 +85278,12 @@
85076 goto blob_open_out;
85077 }
85078
85079 /* If the value is being opened for writing, check that the
85080 ** column is not indexed, and that it is not part of a foreign key.
85081 ** It is against the rules to open a column to which either of these
85082 ** descriptions applies for writing. */
85083 if( flags ){
85084 const char *zFault = 0;
85085 Index *pIdx;
85086 #ifndef SQLITE_OMIT_FOREIGN_KEY
85087 if( db->flags&SQLITE_ForeignKeys ){
85088 /* Check that the column is not part of an FK child key definition. It
@@ -85139,22 +85340,21 @@
85139 */
85140 static const int iLn = VDBE_OFFSET_LINENO(2);
85141 static const VdbeOpList openBlob[] = {
85142 {OP_TableLock, 0, 0, 0}, /* 0: Acquire a read or write lock */
85143 {OP_OpenRead, 0, 0, 0}, /* 1: Open a cursor */
85144 {OP_Variable, 1, 1, 0}, /* 2: Move ?1 into reg[1] */
85145 {OP_NotExists, 0, 7, 1}, /* 3: Seek the cursor */
85146 {OP_Column, 0, 0, 1}, /* 4 */
85147 {OP_ResultRow, 1, 0, 0}, /* 5 */
85148 {OP_Goto, 0, 2, 0}, /* 6 */
85149 {OP_Halt, 0, 0, 0}, /* 7 */
85150 };
85151 Vdbe *v = (Vdbe *)pBlob->pStmt;
85152 int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
85153 VdbeOp *aOp;
85154
85155 sqlite3VdbeAddOp4Int(v, OP_Transaction, iDb, flags,
85156 pTab->pSchema->schema_cookie,
85157 pTab->pSchema->iGeneration);
85158 sqlite3VdbeChangeP5(v, 1);
85159 aOp = sqlite3VdbeAddOpList(v, ArraySize(openBlob), openBlob, iLn);
85160
@@ -85167,19 +85367,19 @@
85167 #ifdef SQLITE_OMIT_SHARED_CACHE
85168 aOp[0].opcode = OP_Noop;
85169 #else
85170 aOp[0].p1 = iDb;
85171 aOp[0].p2 = pTab->tnum;
85172 aOp[0].p3 = flags;
85173 sqlite3VdbeChangeP4(v, 1, pTab->zName, P4_TRANSIENT);
85174 }
85175 if( db->mallocFailed==0 ){
85176 #endif
85177
85178 /* Remove either the OP_OpenWrite or OpenRead. Set the P2
85179 ** parameter of the other to pTab->tnum. */
85180 if( flags ) aOp[1].opcode = OP_OpenWrite;
85181 aOp[1].p2 = pTab->tnum;
85182 aOp[1].p3 = iDb;
85183
85184 /* Configure the number of columns. Configure the cursor to
85185 ** think that the table has one more column than it really
@@ -85188,27 +85388,25 @@
85188 ** we can invoke OP_Column to fill in the vdbe cursors type
85189 ** and offset cache without causing any IO.
85190 */
85191 aOp[1].p4type = P4_INT32;
85192 aOp[1].p4.i = pTab->nCol+1;
85193 aOp[4].p2 = pTab->nCol;
85194
85195 pParse->nVar = 1;
85196 pParse->nMem = 1;
85197 pParse->nTab = 1;
85198 sqlite3VdbeMakeReady(v, pParse);
85199 }
85200 }
85201
85202 pBlob->flags = flags;
85203 pBlob->iCol = iCol;
85204 pBlob->db = db;
85205 sqlite3BtreeLeaveAll(db);
85206 if( db->mallocFailed ){
85207 goto blob_open_out;
85208 }
85209 sqlite3_bind_int64(pBlob->pStmt, 1, iRow);
85210 rc = blobSeekToRow(pBlob, iRow, &zErr);
85211 } while( (++nAttempt)<SQLITE_MAX_SCHEMA_RETRY && rc==SQLITE_SCHEMA );
85212
85213 blob_open_out:
85214 if( rc==SQLITE_OK && db->mallocFailed==0 ){
@@ -88741,12 +88939,10 @@
88741 ** This file contains routines used for walking the parser tree and
88742 ** resolve all identifiers by associating them with a particular
88743 ** table and column.
88744 */
88745 /* #include "sqliteInt.h" */
88746 /* #include <stdlib.h> */
88747 /* #include <string.h> */
88748
88749 /*
88750 ** Walk the expression tree pExpr and increase the aggregate function
88751 ** depth (the Expr.op2 field) by N on every TK_AGG_FUNCTION node.
88752 ** This needs to occur when copying a TK_AGG_FUNCTION node from an
@@ -90501,11 +90697,11 @@
90501 aff = sqlite3ExprAffinity(pExpr->pLeft);
90502 if( pExpr->pRight ){
90503 aff = sqlite3CompareAffinity(pExpr->pRight, aff);
90504 }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){
90505 aff = sqlite3CompareAffinity(pExpr->x.pSelect->pEList->a[0].pExpr, aff);
90506 }else if( NEVER(aff==0) ){
90507 aff = SQLITE_AFF_BLOB;
90508 }
90509 return aff;
90510 }
90511
@@ -91237,21 +91433,27 @@
91237 int doAdd = 0;
91238 if( z[0]=='?' ){
91239 /* Wildcard of the form "?nnn". Convert "nnn" to an integer and
91240 ** use it as the variable number */
91241 i64 i;
91242 int bOk = 0==sqlite3Atoi64(&z[1], &i, n-1, SQLITE_UTF8);
91243 x = (ynVar)i;
 
 
 
 
 
91244 testcase( i==0 );
91245 testcase( i==1 );
91246 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 );
91247 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] );
91248 if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
91249 sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d",
91250 db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]);
91251 return;
91252 }
 
91253 if( x>pParse->nVar ){
91254 pParse->nVar = (int)x;
91255 doAdd = 1;
91256 }else if( sqlite3VListNumToName(pParse->pVList, x)==0 ){
91257 doAdd = 1;
@@ -91682,37 +91884,45 @@
91682 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
91683 pNewItem->idx = pOldItem->idx;
91684 }
91685 return pNew;
91686 }
91687 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
91688 Select *pNew, *pPrior;
 
 
 
 
91689 assert( db!=0 );
91690 if( p==0 ) return 0;
91691 pNew = sqlite3DbMallocRawNN(db, sizeof(*p) );
91692 if( pNew==0 ) return 0;
91693 pNew->pEList = sqlite3ExprListDup(db, p->pEList, flags);
91694 pNew->pSrc = sqlite3SrcListDup(db, p->pSrc, flags);
91695 pNew->pWhere = sqlite3ExprDup(db, p->pWhere, flags);
91696 pNew->pGroupBy = sqlite3ExprListDup(db, p->pGroupBy, flags);
91697 pNew->pHaving = sqlite3ExprDup(db, p->pHaving, flags);
91698 pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, flags);
91699 pNew->op = p->op;
91700 pNew->pPrior = pPrior = sqlite3SelectDup(db, p->pPrior, flags);
91701 if( pPrior ) pPrior->pNext = pNew;
91702 pNew->pNext = 0;
91703 pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags);
91704 pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags);
91705 pNew->iLimit = 0;
91706 pNew->iOffset = 0;
91707 pNew->selFlags = p->selFlags & ~SF_UsesEphemeral;
91708 pNew->addrOpenEphm[0] = -1;
91709 pNew->addrOpenEphm[1] = -1;
91710 pNew->nSelectRow = p->nSelectRow;
91711 pNew->pWith = withDup(db, p->pWith);
91712 sqlite3SelectSetName(pNew, p->zSelName);
91713 return pNew;
 
 
 
 
91714 }
91715 #else
91716 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
91717 assert( p==0 );
91718 return 0;
@@ -91773,11 +91983,11 @@
91773 **
91774 ** (a,b,c) = (expr1,expr2,expr3)
91775 ** Or: (a,b,c) = (SELECT x,y,z FROM ....)
91776 **
91777 ** For each term of the vector assignment, append new entries to the
91778 ** expression list pList. In the case of a subquery on the LHS, append
91779 ** TK_SELECT_COLUMN expressions.
91780 */
91781 SQLITE_PRIVATE ExprList *sqlite3ExprListAppendVector(
91782 Parse *pParse, /* Parsing context */
91783 ExprList *pList, /* List to which to append. Might be NULL */
@@ -93882,10 +94092,15 @@
93882 int i; /* Loop counter */
93883 sqlite3 *db = pParse->db; /* The database connection */
93884 u8 enc = ENC(db); /* The text encoding used by this database */
93885 CollSeq *pColl = 0; /* A collating sequence */
93886
 
 
 
 
 
93887 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
93888 if( ExprHasProperty(pExpr, EP_TokenOnly) ){
93889 pFarg = 0;
93890 }else{
93891 pFarg = pExpr->x.pList;
@@ -93929,10 +94144,26 @@
93929 */
93930 if( pDef->funcFlags & SQLITE_FUNC_UNLIKELY ){
93931 assert( nFarg>=1 );
93932 return sqlite3ExprCodeTarget(pParse, pFarg->a[0].pExpr, target);
93933 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93934
93935 for(i=0; i<nFarg; i++){
93936 if( i<32 && sqlite3ExprIsConstant(pFarg->a[i].pExpr) ){
93937 testcase( i==31 );
93938 constMask |= MASKBIT32(i);
@@ -94246,28 +94477,44 @@
94246 return inReg;
94247 }
94248
94249 /*
94250 ** Factor out the code of the given expression to initialization time.
 
 
 
 
 
 
94251 */
94252 SQLITE_PRIVATE void sqlite3ExprCodeAtInit(
94253 Parse *pParse, /* Parsing context */
94254 Expr *pExpr, /* The expression to code when the VDBE initializes */
94255 int regDest, /* Store the value in this register */
94256 u8 reusable /* True if this expression is reusable */
94257 ){
94258 ExprList *p;
94259 assert( ConstFactorOk(pParse) );
94260 p = pParse->pConstExpr;
 
 
 
 
 
 
 
 
 
94261 pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
94262 p = sqlite3ExprListAppend(pParse, p, pExpr);
94263 if( p ){
94264 struct ExprList_item *pItem = &p->a[p->nExpr-1];
 
 
94265 pItem->u.iConstExprReg = regDest;
94266 pItem->reusable = reusable;
94267 }
94268 pParse->pConstExpr = p;
 
94269 }
94270
94271 /*
94272 ** Generate code to evaluate an expression and store the results
94273 ** into a register. Return the register number where the results
@@ -94286,23 +94533,12 @@
94286 pExpr = sqlite3ExprSkipCollate(pExpr);
94287 if( ConstFactorOk(pParse)
94288 && pExpr->op!=TK_REGISTER
94289 && sqlite3ExprIsConstantNotJoin(pExpr)
94290 ){
94291 ExprList *p = pParse->pConstExpr;
94292 int i;
94293 *pReg = 0;
94294 if( p ){
94295 struct ExprList_item *pItem;
94296 for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
94297 if( pItem->reusable && sqlite3ExprCompare(pItem->pExpr,pExpr,-1)==0 ){
94298 return pItem->u.iConstExprReg;
94299 }
94300 }
94301 }
94302 r2 = ++pParse->nMem;
94303 sqlite3ExprCodeAtInit(pParse, pExpr, r2, 1);
94304 }else{
94305 int r1 = sqlite3GetTempReg(pParse);
94306 r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
94307 if( r2==r1 ){
94308 *pReg = r1;
@@ -94352,11 +94588,11 @@
94352 ** in register target. If the expression is constant, then this routine
94353 ** might choose to code the expression at initialization time.
94354 */
94355 SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse *pParse, Expr *pExpr, int target){
94356 if( pParse->okConstFactor && sqlite3ExprIsConstant(pExpr) ){
94357 sqlite3ExprCodeAtInit(pParse, pExpr, target, 0);
94358 }else{
94359 sqlite3ExprCode(pParse, pExpr, target);
94360 }
94361 }
94362
@@ -94424,11 +94660,11 @@
94424 n--;
94425 }else{
94426 sqlite3VdbeAddOp2(v, copyOp, j+srcReg-1, target+i);
94427 }
94428 }else if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){
94429 sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0);
94430 }else{
94431 int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
94432 if( inReg!=target+i ){
94433 VdbeOp *pOp;
94434 if( copyOp==OP_Copy
@@ -96968,10 +97204,16 @@
96968 ** used to query statistical information that has been gathered into
96969 ** the Stat4Accum object by prior calls to stat_push(). The P parameter
96970 ** has type BLOB but it is really just a pointer to the Stat4Accum object.
96971 ** The content to returned is determined by the parameter J
96972 ** which is one of the STAT_GET_xxxx values defined above.
 
 
 
 
 
 
96973 **
96974 ** If neither STAT3 nor STAT4 are enabled, then J is always
96975 ** STAT_GET_STAT1 and is hence omitted and this routine becomes
96976 ** a one-parameter function, stat_get(P), that always returns the
96977 ** stat1 table entry information.
@@ -97787,11 +98029,11 @@
97787 sumEq += aSample[i].anEq[iCol];
97788 nSum100 += 100;
97789 }
97790 }
97791
97792 if( nDist100>nSum100 ){
97793 avgEq = ((i64)100 * (nRow - sumEq))/(nDist100 - nSum100);
97794 }
97795 if( avgEq==0 ) avgEq = 1;
97796 pIdx->aAvgEq[iCol] = avgEq;
97797 }
@@ -98201,10 +98443,11 @@
98201 assert( pVfs );
98202 flags |= SQLITE_OPEN_MAIN_DB;
98203 rc = sqlite3BtreeOpen(pVfs, zPath, db, &aNew->pBt, 0, flags);
98204 sqlite3_free( zPath );
98205 db->nDb++;
 
98206 if( rc==SQLITE_CONSTRAINT ){
98207 rc = SQLITE_ERROR;
98208 zErrDyn = sqlite3MPrintf(db, "database is already attached");
98209 }else if( rc==SQLITE_OK ){
98210 Pager *pPager;
@@ -104365,16 +104608,12 @@
104365 }
104366 }else
104367 #endif
104368 {
104369 int count = (pParse->nested==0); /* True to count changes */
104370 int iIdxNoSeek = -1;
104371 if( bComplex==0 && aiCurOnePass[1]!=iDataCur ){
104372 iIdxNoSeek = aiCurOnePass[1];
104373 }
104374 sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
104375 iKey, nKey, count, OE_Default, eOnePass, iIdxNoSeek);
104376 }
104377
104378 /* End of the loop over all rowids/primary-keys. */
104379 if( eOnePass!=ONEPASS_OFF ){
104380 sqlite3VdbeResolveLabel(v, addrBypass);
@@ -104450,19 +104689,21 @@
104450 ** then this function must seek iDataCur to the entry identified by iPk
104451 ** and nPk before reading from it.
104452 **
104453 ** If eMode is ONEPASS_MULTI, then this call is being made as part
104454 ** of a ONEPASS delete that affects multiple rows. In this case, if
104455 ** iIdxNoSeek is a valid cursor number (>=0), then its position should
104456 ** be preserved following the delete operation. Or, if iIdxNoSeek is not
104457 ** a valid cursor number, the position of iDataCur should be preserved
104458 ** instead.
104459 **
104460 ** iIdxNoSeek:
104461 ** If iIdxNoSeek is a valid cursor number (>=0), then it identifies an
104462 ** index cursor (from within array of cursors starting at iIdxCur) that
104463 ** already points to the index entry to be deleted.
 
 
104464 */
104465 SQLITE_PRIVATE void sqlite3GenerateRowDelete(
104466 Parse *pParse, /* Parsing context */
104467 Table *pTab, /* Table containing the row to be deleted */
104468 Trigger *pTrigger, /* List of triggers to (potentially) fire */
@@ -104529,17 +104770,22 @@
104529 TK_DELETE, 0, TRIGGER_BEFORE, pTab, iOld, onconf, iLabel
104530 );
104531
104532 /* If any BEFORE triggers were coded, then seek the cursor to the
104533 ** row to be deleted again. It may be that the BEFORE triggers moved
104534 ** the cursor or of already deleted the row that the cursor was
104535 ** pointing to.
 
 
 
104536 */
104537 if( addrStart<sqlite3VdbeCurrentAddr(v) ){
104538 sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
104539 VdbeCoverageIf(v, opSeek==OP_NotExists);
104540 VdbeCoverageIf(v, opSeek==OP_NotFound);
 
 
104541 }
104542
104543 /* Do FK processing. This call checks that any FK constraints that
104544 ** refer to this table (i.e. constraints attached to other tables)
104545 ** are not violated by deleting this row. */
@@ -104558,15 +104804,17 @@
104558 */
104559 if( pTab->pSelect==0 ){
104560 u8 p5 = 0;
104561 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek);
104562 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
104563 sqlite3VdbeAppendP4(v, (char*)pTab, P4_TABLE);
 
 
104564 if( eMode!=ONEPASS_OFF ){
104565 sqlite3VdbeChangeP5(v, OPFLAG_AUXDELETE);
104566 }
104567 if( iIdxNoSeek>=0 ){
104568 sqlite3VdbeAddOp1(v, OP_Delete, iIdxNoSeek);
104569 }
104570 if( eMode==ONEPASS_MULTI ) p5 |= OPFLAG_SAVEPOSITION;
104571 sqlite3VdbeChangeP5(v, p5);
104572 }
@@ -104716,10 +104964,14 @@
104716 ** opcode if it is present */
104717 sqlite3VdbeDeletePriorOpcode(v, OP_RealAffinity);
104718 }
104719 if( regOut ){
104720 sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regOut);
 
 
 
 
104721 }
104722 sqlite3ReleaseTempRange(pParse, regBase, nCol);
104723 return regBase;
104724 }
104725
@@ -106512,10 +106764,13 @@
106512 DFUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ),
106513 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
106514 FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
106515 FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
106516 FUNCTION2(likely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
 
 
 
106517 FUNCTION(ltrim, 1, 1, 0, trimFunc ),
106518 FUNCTION(ltrim, 2, 1, 0, trimFunc ),
106519 FUNCTION(rtrim, 1, 2, 0, trimFunc ),
106520 FUNCTION(rtrim, 2, 2, 0, trimFunc ),
106521 FUNCTION(trim, 1, 3, 0, trimFunc ),
@@ -109667,11 +109922,11 @@
109667 if( db->flags&SQLITE_RecTriggers ){
109668 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
109669 }
109670 sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
109671 regR, nPkField, 0, OE_Replace,
109672 (pIdx==pPk ? ONEPASS_SINGLE : ONEPASS_OFF), -1);
109673 seenReplace = 1;
109674 break;
109675 }
109676 }
109677 sqlite3VdbeResolveLabel(v, addrUniqueOk);
@@ -109683,10 +109938,29 @@
109683 }
109684
109685 *pbMayReplace = seenReplace;
109686 VdbeModuleComment((v, "END: GenCnstCks(%d)", seenReplace));
109687 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109688
109689 /*
109690 ** This routine generates code to finish the INSERT or UPDATE operation
109691 ** that was started by a prior call to sqlite3GenerateConstraintChecks.
109692 ** A consecutive range of registers starting at regNewData contains the
@@ -109700,11 +109974,11 @@
109700 Table *pTab, /* the table into which we are inserting */
109701 int iDataCur, /* Cursor of the canonical data source */
109702 int iIdxCur, /* First index cursor */
109703 int regNewData, /* Range of content */
109704 int *aRegIdx, /* Register used by each index. 0 for unused indices */
109705 int isUpdate, /* True for UPDATE, False for INSERT */
109706 int appendBias, /* True if this is likely to be an append */
109707 int useSeekResult /* True to set the USESEEKRESULT flag on OP_[Idx]Insert */
109708 ){
109709 Vdbe *v; /* Prepared statements under construction */
109710 Index *pIdx; /* An index being inserted or updated */
@@ -109711,10 +109985,15 @@
109711 u8 pik_flags; /* flag values passed to the btree insert */
109712 int regData; /* Content registers (after the rowid) */
109713 int regRec; /* Register holding assembled record for the table */
109714 int i; /* Loop counter */
109715 u8 bAffinityDone = 0; /* True if OP_Affinity has been run already */
 
 
 
 
 
109716
109717 v = sqlite3GetVdbe(pParse);
109718 assert( v!=0 );
109719 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
109720 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
@@ -109722,34 +110001,43 @@
109722 bAffinityDone = 1;
109723 if( pIdx->pPartIdxWhere ){
109724 sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
109725 VdbeCoverage(v);
109726 }
109727 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i],
109728 aRegIdx[i]+1,
109729 pIdx->uniqNotNull ? pIdx->nKeyCol: pIdx->nColumn);
109730 pik_flags = 0;
109731 if( useSeekResult ) pik_flags = OPFLAG_USESEEKRESULT;
109732 if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
109733 assert( pParse->nested==0 );
109734 pik_flags |= OPFLAG_NCHANGE;
 
 
 
 
 
 
 
 
 
109735 }
 
 
 
109736 sqlite3VdbeChangeP5(v, pik_flags);
109737 }
109738 if( !HasRowid(pTab) ) return;
109739 regData = regNewData + 1;
109740 regRec = sqlite3GetTempReg(pParse);
109741 sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec);
 
109742 if( !bAffinityDone ){
109743 sqlite3TableAffinity(v, pTab, 0);
109744 sqlite3ExprCacheAffinityChange(pParse, regData, pTab->nCol);
109745 }
109746 if( pParse->nested ){
109747 pik_flags = 0;
109748 }else{
109749 pik_flags = OPFLAG_NCHANGE;
109750 pik_flags |= (isUpdate?OPFLAG_ISUPDATE:OPFLAG_LASTROWID);
109751 }
109752 if( appendBias ){
109753 pik_flags |= OPFLAG_APPEND;
109754 }
109755 if( useSeekResult ){
@@ -110154,11 +110442,11 @@
110154 addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid);
110155 }else{
110156 addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
110157 assert( (pDest->tabFlags & TF_Autoincrement)==0 );
110158 }
110159 sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData);
110160 if( db->flags & SQLITE_Vacuum ){
110161 sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1);
110162 insFlags = OPFLAG_NCHANGE|OPFLAG_LASTROWID|
110163 OPFLAG_APPEND|OPFLAG_USESEEKRESULT;
110164 }else{
@@ -110186,11 +110474,11 @@
110186 sqlite3VdbeAddOp3(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest);
110187 sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
110188 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
110189 VdbeComment((v, "%s", pDestIdx->zName));
110190 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
110191 sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData);
110192 if( db->flags & SQLITE_Vacuum ){
110193 /* This INSERT command is part of a VACUUM operation, which guarantees
110194 ** that the destination table is empty. If all indexed columns use
110195 ** collation sequence BINARY, then it can also be assumed that the
110196 ** index will be populated by inserting keys in strictly sorted
@@ -110971,11 +111259,10 @@
110971 #endif /* SQLITE3EXT_H */
110972
110973 /************** End of sqlite3ext.h ******************************************/
110974 /************** Continuing where we left off in loadext.c ********************/
110975 /* #include "sqliteInt.h" */
110976 /* #include <string.h> */
110977
110978 #ifndef SQLITE_OMIT_LOAD_EXTENSION
110979 /*
110980 ** Some API routines are omitted when various features are
110981 ** excluded from a build of SQLite. Substitute a NULL pointer
@@ -112635,11 +112922,11 @@
112635
112636 /*
112637 ** Locate a pragma in the aPragmaName[] array.
112638 */
112639 static const PragmaName *pragmaLocate(const char *zName){
112640 int upr, lwr, mid, rc;
112641 lwr = 0;
112642 upr = ArraySize(aPragmaName)-1;
112643 while( lwr<=upr ){
112644 mid = (lwr+upr)/2;
112645 rc = sqlite3_stricmp(zName, aPragmaName[mid].zName);
@@ -116149,10 +116436,11 @@
116149 v = pParse->pVdbe;
116150 r1 = sqlite3GetTempReg(pParse);
116151 sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N); VdbeCoverage(v);
116152 sqlite3VdbeAddOp3(v, OP_MakeRecord, iMem, N, r1);
116153 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r1, iMem, N);
 
116154 sqlite3ReleaseTempReg(pParse, r1);
116155 }
116156
116157 /*
116158 ** This routine generates the code for the inside of the inner loop
@@ -119677,11 +119965,19 @@
119677 assert( pTab->nTabRef==1 || ((pSel->selFlags&SF_Recursive) && pTab->nTabRef==2 ));
119678
119679 pCte->zCteErr = "circular reference: %s";
119680 pSavedWith = pParse->pWith;
119681 pParse->pWith = pWith;
119682 sqlite3WalkSelect(pWalker, bMayRecursive ? pSel->pPrior : pSel);
 
 
 
 
 
 
 
 
119683 pParse->pWith = pWith;
119684
119685 for(pLeft=pSel; pLeft->pPrior; pLeft=pLeft->pPrior);
119686 pEList = pLeft->pEList;
119687 if( pCte->pCols ){
@@ -119721,14 +120017,16 @@
119721 ** sqlite3SelectExpand() when walking a SELECT tree to resolve table
119722 ** names and other FROM clause elements.
119723 */
119724 static void selectPopWith(Walker *pWalker, Select *p){
119725 Parse *pParse = pWalker->pParse;
119726 With *pWith = findRightmost(p)->pWith;
119727 if( pWith!=0 ){
119728 assert( pParse->pWith==pWith );
119729 pParse->pWith = pWith->pOuter;
 
 
119730 }
119731 }
119732 #else
119733 #define selectPopWith 0
119734 #endif
@@ -119774,12 +120072,12 @@
119774 if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){
119775 return WRC_Prune;
119776 }
119777 pTabList = p->pSrc;
119778 pEList = p->pEList;
119779 if( pWalker->xSelectCallback2==selectPopWith ){
119780 sqlite3WithPush(pParse, findRightmost(p)->pWith, 0);
119781 }
119782
119783 /* Make sure cursor numbers have been assigned to all entries in
119784 ** the FROM clause of the SELECT statement.
119785 */
@@ -120062,13 +120360,11 @@
120062 if( pParse->hasCompound ){
120063 w.xSelectCallback = convertCompoundSelectToSubquery;
120064 sqlite3WalkSelect(&w, pSelect);
120065 }
120066 w.xSelectCallback = selectExpander;
120067 if( (pSelect->selFlags & SF_MultiValue)==0 ){
120068 w.xSelectCallback2 = selectPopWith;
120069 }
120070 sqlite3WalkSelect(&w, pSelect);
120071 }
120072
120073
120074 #ifndef SQLITE_OMIT_SUBQUERY
@@ -121143,11 +121439,11 @@
121143 /* This case runs if the aggregate has no GROUP BY clause. The
121144 ** processing is much simpler since there is only a single row
121145 ** of output.
121146 */
121147 resetAccumulator(pParse, &sAggInfo);
121148 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMax,0,flag,0);
121149 if( pWInfo==0 ){
121150 sqlite3ExprListDelete(db, pDel);
121151 goto select_end;
121152 }
121153 updateAccumulator(pParse, &sAggInfo);
@@ -121232,12 +121528,10 @@
121232 **
121233 ** These routines are in a separate files so that they will not be linked
121234 ** if they are not used.
121235 */
121236 /* #include "sqliteInt.h" */
121237 /* #include <stdlib.h> */
121238 /* #include <string.h> */
121239
121240 #ifndef SQLITE_OMIT_GET_TABLE
121241
121242 /*
121243 ** This structure is used to pass data from sqlite3_get_table() through
@@ -122591,16 +122885,16 @@
122591 sqlite3ValueFromExpr(sqlite3VdbeDb(v), pCol->pDflt, enc,
122592 pCol->affinity, &pValue);
122593 if( pValue ){
122594 sqlite3VdbeAppendP4(v, pValue, P4_MEM);
122595 }
 
122596 #ifndef SQLITE_OMIT_FLOATING_POINT
122597 if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){
122598 sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg);
122599 }
122600 #endif
122601 }
122602 }
122603
122604 /*
122605 ** Process an UPDATE statement.
122606 **
@@ -122625,11 +122919,11 @@
122625 int nIdx; /* Number of indices that need updating */
122626 int iBaseCur; /* Base cursor number */
122627 int iDataCur; /* Cursor for the canonical data btree */
122628 int iIdxCur; /* Cursor for the first index */
122629 sqlite3 *db; /* The database structure */
122630 int *aRegIdx = 0; /* One register assigned to each index to be updated */
122631 int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the
122632 ** an expression for the i-th column of the table.
122633 ** aXRef[i]==-1 if the i-th column is not changed. */
122634 u8 *aToOpen; /* 1 for tables and indices to be opened */
122635 u8 chngPk; /* PRIMARY KEY changed in a WITHOUT ROWID table */
@@ -122637,14 +122931,15 @@
122637 u8 chngKey; /* Either chngPk or chngRowid */
122638 Expr *pRowidExpr = 0; /* Expression defining the new record number */
122639 AuthContext sContext; /* The authorization context */
122640 NameContext sNC; /* The name-context to resolve expressions in */
122641 int iDb; /* Database containing the table being updated */
122642 int okOnePass; /* True for one-pass algorithm without the FIFO */
122643 int hasFK; /* True if foreign key processing is required */
122644 int labelBreak; /* Jump here to break out of UPDATE loop */
122645 int labelContinue; /* Jump here to continue next step of UPDATE loop */
 
122646
122647 #ifndef SQLITE_OMIT_TRIGGER
122648 int isView; /* True when updating a view (INSTEAD OF trigger) */
122649 Trigger *pTrigger; /* List of triggers on pTab, if required */
122650 int tmask; /* Mask of TRIGGER_BEFORE|TRIGGER_AFTER */
@@ -122651,10 +122946,14 @@
122651 #endif
122652 int newmask; /* Mask of NEW.* columns accessed by BEFORE triggers */
122653 int iEph = 0; /* Ephemeral table holding all primary key values */
122654 int nKey = 0; /* Number of elements in regKey for WITHOUT ROWID */
122655 int aiCurOnePass[2]; /* The write cursors opened by WHERE_ONEPASS */
 
 
 
 
122656
122657 /* Register Allocations */
122658 int regRowCount = 0; /* A count of rows changed */
122659 int regOldRowid = 0; /* The old rowid */
122660 int regNewRowid = 0; /* The new rowid */
@@ -122810,17 +123109,27 @@
122810 for(i=0; i<pIdx->nKeyCol; i++){
122811 i16 iIdxCol = pIdx->aiColumn[i];
122812 if( iIdxCol<0 || aXRef[iIdxCol]>=0 ){
122813 reg = ++pParse->nMem;
122814 pParse->nMem += pIdx->nColumn;
 
 
 
 
 
122815 break;
122816 }
122817 }
122818 }
122819 if( reg==0 ) aToOpen[j+1] = 0;
122820 aRegIdx[j] = reg;
122821 }
 
 
 
 
 
122822
122823 /* Begin generating code. */
122824 v = sqlite3GetVdbe(pParse);
122825 if( v==0 ) goto update_cleanup;
122826 if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
@@ -122869,107 +123178,127 @@
122869 pWhere, onError);
122870 goto update_cleanup;
122871 }
122872 #endif
122873
122874 /* Begin the database scan
122875 */
 
 
 
 
122876 if( HasRowid(pTab) ){
122877 sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid);
122878 pWInfo = sqlite3WhereBegin(
122879 pParse, pTabList, pWhere, 0, 0,
122880 WHERE_ONEPASS_DESIRED | WHERE_SEEK_TABLE, iIdxCur
122881 );
122882 if( pWInfo==0 ) goto update_cleanup;
122883 okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
122884
122885 /* Remember the rowid of every item to be updated.
122886 */
122887 sqlite3VdbeAddOp2(v, OP_Rowid, iDataCur, regOldRowid);
122888 if( !okOnePass ){
122889 sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, regOldRowid);
122890 }
122891
122892 /* End the database scan loop.
122893 */
122894 sqlite3WhereEnd(pWInfo);
122895 }else{
122896 int iPk; /* First of nPk memory cells holding PRIMARY KEY value */
122897 i16 nPk; /* Number of components of the PRIMARY KEY */
122898 int addrOpen; /* Address of the OpenEphemeral instruction */
122899
122900 assert( pPk!=0 );
122901 nPk = pPk->nKeyCol;
122902 iPk = pParse->nMem+1;
122903 pParse->nMem += nPk;
122904 regKey = ++pParse->nMem;
122905 iEph = pParse->nTab++;
 
122906 sqlite3VdbeAddOp2(v, OP_Null, 0, iPk);
122907 addrOpen = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEph, nPk);
122908 sqlite3VdbeSetP4KeyInfo(pParse, pPk);
122909 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0,
122910 WHERE_ONEPASS_DESIRED, iIdxCur);
122911 if( pWInfo==0 ) goto update_cleanup;
122912 okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122913 for(i=0; i<nPk; i++){
122914 assert( pPk->aiColumn[i]>=0 );
122915 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pPk->aiColumn[i],
122916 iPk+i);
122917 }
122918 if( okOnePass ){
122919 sqlite3VdbeChangeToNoop(v, addrOpen);
122920 nKey = nPk;
122921 regKey = iPk;
122922 }else{
122923 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, regKey,
122924 sqlite3IndexAffinityStr(db, pPk), nPk);
122925 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iEph, regKey, iPk, nPk);
122926 }
122927 sqlite3WhereEnd(pWInfo);
122928 }
122929
122930 /* Initialize the count of updated rows
122931 */
122932 if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab ){
122933 regRowCount = ++pParse->nMem;
122934 sqlite3VdbeAddOp2(v, OP_Integer, 0, regRowCount);
122935 }
122936
122937 labelBreak = sqlite3VdbeMakeLabel(v);
122938 if( !isView ){
122939 /*
122940 ** Open every index that needs updating. Note that if any
122941 ** index could potentially invoke a REPLACE conflict resolution
122942 ** action, then we need to open all indices because we might need
122943 ** to be deleting some records.
122944 */
122945 if( onError==OE_Replace ){
122946 memset(aToOpen, 1, nIdx+1);
122947 }else{
122948 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
122949 if( pIdx->onError==OE_Replace ){
122950 memset(aToOpen, 1, nIdx+1);
122951 break;
122952 }
122953 }
122954 }
122955 if( okOnePass ){
122956 if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iBaseCur] = 0;
122957 if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iBaseCur] = 0;
122958 }
 
 
 
 
122959 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, 0, iBaseCur, aToOpen,
122960 0, 0);
 
122961 }
122962
122963 /* Top of the update loop */
122964 if( okOnePass ){
122965 if( aToOpen[iDataCur-iBaseCur] && !isView ){
122966 assert( pPk );
122967 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey, nKey);
122968 VdbeCoverageNeverTaken(v);
122969 }
122970 labelContinue = labelBreak;
 
 
 
 
122971 sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak);
122972 VdbeCoverageIf(v, pPk==0);
122973 VdbeCoverageIf(v, pPk!=0);
122974 }else if( pPk ){
122975 labelContinue = sqlite3VdbeMakeLabel(v);
@@ -123090,11 +123419,10 @@
123090 }
123091 }
123092
123093 if( !isView ){
123094 int addr1 = 0; /* Address of jump instruction */
123095 int bReplace = 0; /* True if REPLACE conflict resolution might happen */
123096
123097 /* Do constraint checks. */
123098 assert( regOldRowid>0 );
123099 sqlite3GenerateConstraintChecks(pParse, pTab, aRegIdx, iDataCur, iIdxCur,
123100 regNewRowid, regOldRowid, chngKey, onError, labelContinue, &bReplace,
@@ -123126,18 +123454,22 @@
123126 ** is the column index supplied by the user.
123127 */
123128 assert( regNew==regNewRowid+1 );
123129 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
123130 sqlite3VdbeAddOp3(v, OP_Delete, iDataCur,
123131 OPFLAG_ISUPDATE | ((hasFK || chngKey || pPk!=0) ? 0 : OPFLAG_ISNOOP),
123132 regNewRowid
123133 );
 
 
 
 
123134 if( !pParse->nested ){
123135 sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
123136 }
123137 #else
123138 if( hasFK || chngKey || pPk!=0 ){
123139 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0);
123140 }
123141 #endif
123142 if( bReplace || chngKey ){
123143 sqlite3VdbeJumpHere(v, addr1);
@@ -123146,12 +123478,15 @@
123146 if( hasFK ){
123147 sqlite3FkCheck(pParse, pTab, 0, regNewRowid, aXRef, chngKey);
123148 }
123149
123150 /* Insert the new index entries and the new record. */
123151 sqlite3CompleteInsertion(pParse, pTab, iDataCur, iIdxCur,
123152 regNewRowid, aRegIdx, 1, 0, 0);
 
 
 
123153
123154 /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
123155 ** handle rows (possibly in other tables) that refer via a foreign key
123156 ** to the row just updated. */
123157 if( hasFK ){
@@ -123169,12 +123504,15 @@
123169 TRIGGER_AFTER, pTab, regOldRowid, onError, labelContinue);
123170
123171 /* Repeat the above with the next record to be updated, until
123172 ** all record selected by the WHERE clause have been updated.
123173 */
123174 if( okOnePass ){
123175 /* Nothing to do at end-of-loop for a single-pass */
 
 
 
123176 }else if( pPk ){
123177 sqlite3VdbeResolveLabel(v, labelContinue);
123178 sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop); VdbeCoverage(v);
123179 }else{
123180 sqlite3VdbeGoto(v, labelContinue);
@@ -127090,11 +127428,14 @@
127090
127091 /* Seek the table cursor, if required */
127092 if( omitTable ){
127093 /* pIdx is a covering index. No need to access the main table. */
127094 }else if( HasRowid(pIdx->pTable) ){
127095 if( (pWInfo->wctrlFlags & WHERE_SEEK_TABLE)!=0 ){
 
 
 
127096 iRowidReg = ++pParse->nMem;
127097 sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
127098 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
127099 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, iRowidReg);
127100 VdbeCoverage(v);
@@ -128454,10 +128795,11 @@
128454 int noCase = 0; /* uppercase equivalent to lowercase */
128455 int op; /* Top-level operator. pExpr->op */
128456 Parse *pParse = pWInfo->pParse; /* Parsing context */
128457 sqlite3 *db = pParse->db; /* Database connection */
128458 unsigned char eOp2; /* op2 value for LIKE/REGEXP/GLOB */
 
128459
128460 if( db->mallocFailed ){
128461 return;
128462 }
128463 pTerm = &pWC->a[idxTerm];
@@ -128483,10 +128825,14 @@
128483 if( ExprHasProperty(pExpr, EP_FromJoin) ){
128484 Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->iRightJoinTable);
128485 prereqAll |= x;
128486 extraRight = x-1; /* ON clause terms may not be used with an index
128487 ** on left table of a LEFT JOIN. Ticket #3015 */
 
 
 
 
128488 }
128489 pTerm->prereqAll = prereqAll;
128490 pTerm->leftCursor = -1;
128491 pTerm->iParent = -1;
128492 pTerm->eOperator = 0;
@@ -128725,17 +129071,16 @@
128725 **
128726 ** This is only required if at least one side of the comparison operation
128727 ** is not a sub-select. */
128728 if( pWC->op==TK_AND
128729 && (pExpr->op==TK_EQ || pExpr->op==TK_IS)
128730 && sqlite3ExprIsVector(pExpr->pLeft)
 
128731 && ( (pExpr->pLeft->flags & EP_xIsSelect)==0
128732 || (pExpr->pRight->flags & EP_xIsSelect)==0
128733 )){
128734 int nLeft = sqlite3ExprVectorSize(pExpr->pLeft);
128735 int i;
128736 assert( nLeft==sqlite3ExprVectorSize(pExpr->pRight) );
128737 for(i=0; i<nLeft; i++){
128738 int idxNew;
128739 Expr *pNew;
128740 Expr *pLeft = sqlite3ExprForVectorField(pParse, pExpr->pLeft, i);
128741 Expr *pRight = sqlite3ExprForVectorField(pParse, pExpr->pRight, i);
@@ -129293,10 +129638,11 @@
129293 if( pIdx ){
129294 int j = iColumn;
129295 iColumn = pIdx->aiColumn[j];
129296 if( iColumn==XN_EXPR ){
129297 pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr;
 
129298 }else if( iColumn==pIdx->pTable->iPKey ){
129299 iColumn = XN_ROWID;
129300 }else if( iColumn>=0 ){
129301 pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity;
129302 pScan->zCollName = pIdx->azColl[j];
@@ -133934,11 +134280,12 @@
133934 x = sqlite3ColumnOfIndex(pIdx, x);
133935 if( x>=0 ){
133936 pOp->p2 = x;
133937 pOp->p1 = pLevel->iIdxCur;
133938 }
133939 assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0 );
 
133940 }else if( pOp->opcode==OP_Rowid ){
133941 pOp->p1 = pLevel->iIdxCur;
133942 pOp->opcode = OP_IdxRowid;
133943 }
133944 }
@@ -133998,10 +134345,23 @@
133998 ** Indicate that sqlite3ParserFree() will never be called with a null
133999 ** pointer.
134000 */
134001 #define YYPARSEFREENEVERNULL 1
134002
 
 
 
 
 
 
 
 
 
 
 
 
 
134003 /*
134004 ** Alternative datatype for the argument to the malloc() routine passed
134005 ** into sqlite3ParserAlloc(). The default is size_t.
134006 */
134007 #define YYMALLOCARGTYPE u64
@@ -135446,10 +135806,35 @@
135446 */
135447 #ifndef YYMALLOCARGTYPE
135448 # define YYMALLOCARGTYPE size_t
135449 #endif
135450
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135451 /*
135452 ** This function allocates a new parser.
135453 ** The only argument is a pointer to a function which works like
135454 ** malloc.
135455 **
@@ -135461,32 +135846,15 @@
135461 ** to sqlite3Parser and sqlite3ParserFree.
135462 */
135463 SQLITE_PRIVATE void *sqlite3ParserAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){
135464 yyParser *pParser;
135465 pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) );
135466 if( pParser ){
135467 #ifdef YYTRACKMAXSTACKDEPTH
135468 pParser->yyhwm = 0;
135469 #endif
135470 #if YYSTACKDEPTH<=0
135471 pParser->yytos = NULL;
135472 pParser->yystack = NULL;
135473 pParser->yystksz = 0;
135474 if( yyGrowStack(pParser) ){
135475 pParser->yystack = &pParser->yystk0;
135476 pParser->yystksz = 1;
135477 }
135478 #endif
135479 #ifndef YYNOERRORRECOVERY
135480 pParser->yyerrcnt = -1;
135481 #endif
135482 pParser->yytos = pParser->yystack;
135483 pParser->yystack[0].stateno = 0;
135484 pParser->yystack[0].major = 0;
135485 }
135486 return pParser;
135487 }
 
 
135488
135489 /* The following function deletes the "minor type" or semantic value
135490 ** associated with a symbol. The symbol can be either a terminal
135491 ** or nonterminal. "yymajor" is the symbol code, and "yypminor" is
135492 ** a pointer to the value to be deleted. The code used to do the
@@ -135608,10 +135976,22 @@
135608 }
135609 #endif
135610 yy_destructor(pParser, yytos->major, &yytos->minor);
135611 }
135612
 
 
 
 
 
 
 
 
 
 
 
 
135613 /*
135614 ** Deallocate and destroy a parser. Destructors are called for
135615 ** all stack elements before shutting the parser down.
135616 **
135617 ** If the YYPARSEFREENEVERNULL macro exists (for example because it
@@ -135620,20 +136000,17 @@
135620 */
135621 SQLITE_PRIVATE void sqlite3ParserFree(
135622 void *p, /* The parser to be deleted */
135623 void (*freeProc)(void*) /* Function used to reclaim memory */
135624 ){
135625 yyParser *pParser = (yyParser*)p;
135626 #ifndef YYPARSEFREENEVERNULL
135627 if( pParser==0 ) return;
135628 #endif
135629 while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser);
135630 #if YYSTACKDEPTH<=0
135631 if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack);
135632 #endif
135633 (*freeProc)((void*)pParser);
135634 }
135635
135636 /*
135637 ** Return the peak depth of the stack for a parser.
135638 */
135639 #ifdef YYTRACKMAXSTACKDEPTH
@@ -138483,10 +138860,13 @@
138483 void *pEngine; /* The LEMON-generated LALR(1) parser */
138484 int tokenType; /* type of the next token */
138485 int lastTokenParsed = -1; /* type of the previous token */
138486 sqlite3 *db = pParse->db; /* The database connection */
138487 int mxSqlLen; /* Max length of an SQL string */
 
 
 
138488
138489 assert( zSql!=0 );
138490 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
138491 if( db->nVdbeActive==0 ){
138492 db->u1.isInterrupted = 0;
@@ -138494,15 +138874,20 @@
138494 pParse->rc = SQLITE_OK;
138495 pParse->zTail = zSql;
138496 i = 0;
138497 assert( pzErrMsg!=0 );
138498 /* sqlite3ParserTrace(stdout, "parser: "); */
 
 
 
 
138499 pEngine = sqlite3ParserAlloc(sqlite3Malloc);
138500 if( pEngine==0 ){
138501 sqlite3OomFault(db);
138502 return SQLITE_NOMEM_BKPT;
138503 }
 
138504 assert( pParse->pNewTable==0 );
138505 assert( pParse->pNewTrigger==0 );
138506 assert( pParse->nVar==0 );
138507 assert( pParse->pVList==0 );
138508 while( 1 ){
@@ -138550,11 +138935,15 @@
138550 sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK,
138551 sqlite3ParserStackPeak(pEngine)
138552 );
138553 sqlite3_mutex_leave(sqlite3MallocMutex());
138554 #endif /* YYDEBUG */
 
 
 
138555 sqlite3ParserFree(pEngine, sqlite3_free);
 
138556 if( db->mallocFailed ){
138557 pParse->rc = SQLITE_NOMEM_BKPT;
138558 }
138559 if( pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE && pParse->zErrMsg==0 ){
138560 pParse->zErrMsg = sqlite3MPrintf(db, "%s", sqlite3ErrStr(pParse->rc));
@@ -144213,10 +144602,11 @@
144213
144214 /* Precompiled statements used by the implementation. Each of these
144215 ** statements is run and reset within a single virtual table API call.
144216 */
144217 sqlite3_stmt *aStmt[40];
 
144218
144219 char *zReadExprlist;
144220 char *zWriteExprlist;
144221
144222 int nNodeSize; /* Soft limit for node size */
@@ -144282,10 +144672,11 @@
144282 struct Fts3Cursor {
144283 sqlite3_vtab_cursor base; /* Base class used by SQLite core */
144284 i16 eSearch; /* Search strategy (see below) */
144285 u8 isEof; /* True if at End Of Results */
144286 u8 isRequireSeek; /* True if must seek pStmt to %_content row */
 
144287 sqlite3_stmt *pStmt; /* Prepared statement in use by the cursor */
144288 Fts3Expr *pExpr; /* Parsed MATCH query string */
144289 int iLangid; /* Language being queried for */
144290 int nPhrase; /* Number of matchable phrases in query */
144291 Fts3DeferredToken *pDeferred; /* Deferred search tokens, if any */
@@ -144804,10 +145195,11 @@
144804
144805 assert( p->nPendingData==0 );
144806 assert( p->pSegments==0 );
144807
144808 /* Free any prepared statements held */
 
144809 for(i=0; i<SizeofArray(p->aStmt); i++){
144810 sqlite3_finalize(p->aStmt[i]);
144811 }
144812 sqlite3_free(p->zSegmentsTbl);
144813 sqlite3_free(p->zReadExprlist);
@@ -145675,13 +146067,13 @@
145675 p->nPendingData = 0;
145676 p->azColumn = (char **)&p[1];
145677 p->pTokenizer = pTokenizer;
145678 p->nMaxPendingData = FTS3_MAX_PENDING_DATA;
145679 p->bHasDocsize = (isFts4 && bNoDocsize==0);
145680 p->bHasStat = isFts4;
145681 p->bFts4 = isFts4;
145682 p->bDescIdx = bDescIdx;
145683 p->nAutoincrmerge = 0xff; /* 0xff means setting unknown */
145684 p->zContentTbl = zContent;
145685 p->zLanguageid = zLanguageid;
145686 zContent = 0;
145687 zLanguageid = 0;
@@ -145991,19 +146383,39 @@
145991 return SQLITE_NOMEM;
145992 }
145993 memset(pCsr, 0, sizeof(Fts3Cursor));
145994 return SQLITE_OK;
145995 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145996
145997 /*
145998 ** Close the cursor. For additional information see the documentation
145999 ** on the xClose method of the virtual table interface.
146000 */
146001 static int fts3CloseMethod(sqlite3_vtab_cursor *pCursor){
146002 Fts3Cursor *pCsr = (Fts3Cursor *)pCursor;
146003 assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
146004 sqlite3_finalize(pCsr->pStmt);
146005 sqlite3Fts3ExprFree(pCsr->pExpr);
146006 sqlite3Fts3FreeDeferredTokens(pCsr);
146007 sqlite3_free(pCsr->aDoclist);
146008 sqlite3Fts3MIBufferFree(pCsr->pMIBuffer);
146009 assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
@@ -146017,24 +146429,27 @@
146017 **
146018 ** "SELECT <columns> FROM %_content WHERE rowid = ?"
146019 **
146020 ** (or the equivalent for a content=xxx table) and set pCsr->pStmt to
146021 ** it. If an error occurs, return an SQLite error code.
146022 **
146023 ** Otherwise, set *ppStmt to point to pCsr->pStmt and return SQLITE_OK.
146024 */
146025 static int fts3CursorSeekStmt(Fts3Cursor *pCsr, sqlite3_stmt **ppStmt){
146026 int rc = SQLITE_OK;
146027 if( pCsr->pStmt==0 ){
146028 Fts3Table *p = (Fts3Table *)pCsr->base.pVtab;
146029 char *zSql;
146030 zSql = sqlite3_mprintf("SELECT %s WHERE rowid = ?", p->zReadExprlist);
146031 if( !zSql ) return SQLITE_NOMEM;
146032 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0);
146033 sqlite3_free(zSql);
 
 
 
 
 
 
146034 }
146035 *ppStmt = pCsr->pStmt;
146036 return rc;
146037 }
146038
146039 /*
146040 ** Position the pCsr->pStmt statement so that it is on the row
@@ -146042,13 +146457,11 @@
146042 ** SQLITE_OK on success.
146043 */
146044 static int fts3CursorSeek(sqlite3_context *pContext, Fts3Cursor *pCsr){
146045 int rc = SQLITE_OK;
146046 if( pCsr->isRequireSeek ){
146047 sqlite3_stmt *pStmt = 0;
146048
146049 rc = fts3CursorSeekStmt(pCsr, &pStmt);
146050 if( rc==SQLITE_OK ){
146051 sqlite3_bind_int64(pCsr->pStmt, 1, pCsr->iPrevId);
146052 pCsr->isRequireSeek = 0;
146053 if( SQLITE_ROW==sqlite3_step(pCsr->pStmt) ){
146054 return SQLITE_OK;
@@ -147502,11 +147915,11 @@
147502 if( idxNum & FTS3_HAVE_DOCID_GE ) pDocidGe = apVal[iIdx++];
147503 if( idxNum & FTS3_HAVE_DOCID_LE ) pDocidLe = apVal[iIdx++];
147504 assert( iIdx==nVal );
147505
147506 /* In case the cursor has been used before, clear it now. */
147507 sqlite3_finalize(pCsr->pStmt);
147508 sqlite3_free(pCsr->aDoclist);
147509 sqlite3Fts3MIBufferFree(pCsr->pMIBuffer);
147510 sqlite3Fts3ExprFree(pCsr->pExpr);
147511 memset(&pCursor[1], 0, sizeof(Fts3Cursor)-sizeof(sqlite3_vtab_cursor));
147512
@@ -147570,11 +147983,11 @@
147570 sqlite3_free(zSql);
147571 }else{
147572 rc = SQLITE_NOMEM;
147573 }
147574 }else if( eSearch==FTS3_DOCID_SEARCH ){
147575 rc = fts3CursorSeekStmt(pCsr, &pCsr->pStmt);
147576 if( rc==SQLITE_OK ){
147577 rc = sqlite3_bind_value(pCsr->pStmt, 1, pCons);
147578 }
147579 }
147580 if( rc!=SQLITE_OK ) return rc;
@@ -147734,11 +148147,11 @@
147734 sqlite3_stmt *pStmt = 0;
147735 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
147736 if( rc==SQLITE_OK ){
147737 int bHasStat = (sqlite3_step(pStmt)==SQLITE_ROW);
147738 rc = sqlite3_finalize(pStmt);
147739 if( rc==SQLITE_OK ) p->bHasStat = bHasStat;
147740 }
147741 sqlite3_free(zSql);
147742 }else{
147743 rc = SQLITE_NOMEM;
147744 }
@@ -162590,10 +163003,11 @@
162590 /* #include <stdio.h> */
162591
162592 #ifndef SQLITE_AMALGAMATION
162593 #include "sqlite3rtree.h"
162594 typedef sqlite3_int64 i64;
 
162595 typedef unsigned char u8;
162596 typedef unsigned short u16;
162597 typedef unsigned int u32;
162598 #endif
162599
@@ -162638,28 +163052,33 @@
162638 struct Rtree {
162639 sqlite3_vtab base; /* Base class. Must be first */
162640 sqlite3 *db; /* Host database connection */
162641 int iNodeSize; /* Size in bytes of each node in the node table */
162642 u8 nDim; /* Number of dimensions */
 
162643 u8 eCoordType; /* RTREE_COORD_REAL32 or RTREE_COORD_INT32 */
162644 u8 nBytesPerCell; /* Bytes consumed per cell */
 
162645 int iDepth; /* Current depth of the r-tree structure */
162646 char *zDb; /* Name of database containing r-tree table */
162647 char *zName; /* Name of r-tree table */
162648 int nBusy; /* Current number of users of this structure */
162649 i64 nRowEst; /* Estimated number of rows in this table */
 
162650
162651 /* List of nodes removed during a CondenseTree operation. List is
162652 ** linked together via the pointer normally used for hash chains -
162653 ** RtreeNode.pNext. RtreeNode.iNode stores the depth of the sub-tree
162654 ** headed by the node (leaf nodes have RtreeNode.iNode==0).
162655 */
162656 RtreeNode *pDeleted;
162657 int iReinsertHeight; /* Height of sub-trees Reinsert() has run on */
 
 
 
162658
162659 /* Statements to read/write/delete a record from xxx_node */
162660 sqlite3_stmt *pReadNode;
162661 sqlite3_stmt *pWriteNode;
162662 sqlite3_stmt *pDeleteNode;
162663
162664 /* Statements to read/write/delete a record from xxx_rowid */
162665 sqlite3_stmt *pReadRowid;
@@ -162884,26 +163303,100 @@
162884 #endif
162885 #ifndef MIN
162886 # define MIN(x,y) ((x) > (y) ? (y) : (x))
162887 #endif
162888
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162889 /*
162890 ** Functions to deserialize a 16 bit integer, 32 bit real number and
162891 ** 64 bit integer. The deserialized value is returned.
162892 */
162893 static int readInt16(u8 *p){
162894 return (p[0]<<8) + p[1];
162895 }
162896 static void readCoord(u8 *p, RtreeCoord *pCoord){
 
 
 
 
 
 
 
 
162897 pCoord->u = (
162898 (((u32)p[0]) << 24) +
162899 (((u32)p[1]) << 16) +
162900 (((u32)p[2]) << 8) +
162901 (((u32)p[3]) << 0)
162902 );
 
162903 }
162904 static i64 readInt64(u8 *p){
 
 
 
 
 
 
 
 
 
 
 
 
 
162905 return (
162906 (((i64)p[0]) << 56) +
162907 (((i64)p[1]) << 48) +
162908 (((i64)p[2]) << 40) +
162909 (((i64)p[3]) << 32) +
@@ -162910,42 +163403,64 @@
162910 (((i64)p[4]) << 24) +
162911 (((i64)p[5]) << 16) +
162912 (((i64)p[6]) << 8) +
162913 (((i64)p[7]) << 0)
162914 );
 
162915 }
162916
162917 /*
162918 ** Functions to serialize a 16 bit integer, 32 bit real number and
162919 ** 64 bit integer. The value returned is the number of bytes written
162920 ** to the argument buffer (always 2, 4 and 8 respectively).
162921 */
162922 static int writeInt16(u8 *p, int i){
162923 p[0] = (i>> 8)&0xFF;
162924 p[1] = (i>> 0)&0xFF;
162925 return 2;
162926 }
162927 static int writeCoord(u8 *p, RtreeCoord *pCoord){
162928 u32 i;
 
162929 assert( sizeof(RtreeCoord)==4 );
162930 assert( sizeof(u32)==4 );
 
 
 
 
 
 
 
 
 
 
162931 i = pCoord->u;
162932 p[0] = (i>>24)&0xFF;
162933 p[1] = (i>>16)&0xFF;
162934 p[2] = (i>> 8)&0xFF;
162935 p[3] = (i>> 0)&0xFF;
 
162936 return 4;
162937 }
162938 static int writeInt64(u8 *p, i64 i){
 
 
 
 
 
 
 
 
 
162939 p[0] = (i>>56)&0xFF;
162940 p[1] = (i>>48)&0xFF;
162941 p[2] = (i>>40)&0xFF;
162942 p[3] = (i>>32)&0xFF;
162943 p[4] = (i>>24)&0xFF;
162944 p[5] = (i>>16)&0xFF;
162945 p[6] = (i>> 8)&0xFF;
162946 p[7] = (i>> 0)&0xFF;
 
162947 return 8;
162948 }
162949
162950 /*
162951 ** Increment the reference count of node p.
@@ -163023,10 +163538,21 @@
163023 pNode->isDirty = 1;
163024 nodeReference(pParent);
163025 }
163026 return pNode;
163027 }
 
 
 
 
 
 
 
 
 
 
 
163028
163029 /*
163030 ** Obtain a reference to an r-tree node.
163031 */
163032 static int nodeAcquire(
@@ -163033,13 +163559,12 @@
163033 Rtree *pRtree, /* R-tree structure */
163034 i64 iNode, /* Node number to load */
163035 RtreeNode *pParent, /* Either the parent node or NULL */
163036 RtreeNode **ppNode /* OUT: Acquired node */
163037 ){
163038 int rc;
163039 int rc2 = SQLITE_OK;
163040 RtreeNode *pNode;
163041
163042 /* Check if the requested node is already in the hash table. If so,
163043 ** increase its reference count and return it.
163044 */
163045 if( (pNode = nodeHashLookup(pRtree, iNode)) ){
@@ -163051,32 +163576,49 @@
163051 pNode->nRef++;
163052 *ppNode = pNode;
163053 return SQLITE_OK;
163054 }
163055
163056 sqlite3_bind_int64(pRtree->pReadNode, 1, iNode);
163057 rc = sqlite3_step(pRtree->pReadNode);
163058 if( rc==SQLITE_ROW ){
163059 const u8 *zBlob = sqlite3_column_blob(pRtree->pReadNode, 0);
163060 if( pRtree->iNodeSize==sqlite3_column_bytes(pRtree->pReadNode, 0) ){
163061 pNode = (RtreeNode *)sqlite3_malloc(sizeof(RtreeNode)+pRtree->iNodeSize);
163062 if( !pNode ){
163063 rc2 = SQLITE_NOMEM;
163064 }else{
163065 pNode->pParent = pParent;
163066 pNode->zData = (u8 *)&pNode[1];
163067 pNode->nRef = 1;
163068 pNode->iNode = iNode;
163069 pNode->isDirty = 0;
163070 pNode->pNext = 0;
163071 memcpy(pNode->zData, zBlob, pRtree->iNodeSize);
163072 nodeReference(pParent);
163073 }
163074 }
163075 }
163076 rc = sqlite3_reset(pRtree->pReadNode);
163077 if( rc==SQLITE_OK ) rc = rc2;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163078
163079 /* If the root node was just loaded, set pRtree->iDepth to the height
163080 ** of the r-tree structure. A height of zero means all data is stored on
163081 ** the root node. A height of one means the children of the root node
163082 ** are the leaves, and so on. If the depth as specified on the root node
@@ -163124,11 +163666,11 @@
163124 int iCell /* Index into pNode into which pCell is written */
163125 ){
163126 int ii;
163127 u8 *p = &pNode->zData[4 + pRtree->nBytesPerCell*iCell];
163128 p += writeInt64(p, pCell->iRowid);
163129 for(ii=0; ii<(pRtree->nDim*2); ii++){
163130 p += writeCoord(p, &pCell->aCoord[ii]);
163131 }
163132 pNode->isDirty = 1;
163133 }
163134
@@ -163258,17 +163800,20 @@
163258 int iCell, /* Index of the cell within the node */
163259 RtreeCell *pCell /* OUT: Write the cell contents here */
163260 ){
163261 u8 *pData;
163262 RtreeCoord *pCoord;
163263 int ii;
163264 pCell->iRowid = nodeGetRowid(pRtree, pNode, iCell);
163265 pData = pNode->zData + (12 + pRtree->nBytesPerCell*iCell);
163266 pCoord = pCell->aCoord;
163267 for(ii=0; ii<pRtree->nDim*2; ii++){
163268 readCoord(&pData[ii*4], &pCoord[ii]);
163269 }
 
 
 
163270 }
163271
163272
163273 /* Forward declaration for the function that does the work of
163274 ** the virtual table module xCreate() and xConnect() methods.
@@ -163315,11 +163860,13 @@
163315 ** zero the structure is deleted.
163316 */
163317 static void rtreeRelease(Rtree *pRtree){
163318 pRtree->nBusy--;
163319 if( pRtree->nBusy==0 ){
163320 sqlite3_finalize(pRtree->pReadNode);
 
 
163321 sqlite3_finalize(pRtree->pWriteNode);
163322 sqlite3_finalize(pRtree->pDeleteNode);
163323 sqlite3_finalize(pRtree->pReadRowid);
163324 sqlite3_finalize(pRtree->pWriteRowid);
163325 sqlite3_finalize(pRtree->pDeleteRowid);
@@ -163353,10 +163900,11 @@
163353 pRtree->zDb, pRtree->zName
163354 );
163355 if( !zCreate ){
163356 rc = SQLITE_NOMEM;
163357 }else{
 
163358 rc = sqlite3_exec(pRtree->db, zCreate, 0, 0, 0);
163359 sqlite3_free(zCreate);
163360 }
163361 if( rc==SQLITE_OK ){
163362 rtreeRelease(pRtree);
@@ -163368,17 +163916,19 @@
163368 /*
163369 ** Rtree virtual table module xOpen method.
163370 */
163371 static int rtreeOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
163372 int rc = SQLITE_NOMEM;
 
163373 RtreeCursor *pCsr;
163374
163375 pCsr = (RtreeCursor *)sqlite3_malloc(sizeof(RtreeCursor));
163376 if( pCsr ){
163377 memset(pCsr, 0, sizeof(RtreeCursor));
163378 pCsr->base.pVtab = pVTab;
163379 rc = SQLITE_OK;
 
163380 }
163381 *ppCursor = (sqlite3_vtab_cursor *)pCsr;
163382
163383 return rc;
163384 }
@@ -163407,14 +163957,17 @@
163407 */
163408 static int rtreeClose(sqlite3_vtab_cursor *cur){
163409 Rtree *pRtree = (Rtree *)(cur->pVtab);
163410 int ii;
163411 RtreeCursor *pCsr = (RtreeCursor *)cur;
 
163412 freeCursorConstraints(pCsr);
163413 sqlite3_free(pCsr->aPoint);
163414 for(ii=0; ii<RTREE_CACHE_SZ; ii++) nodeRelease(pRtree, pCsr->aNode[ii]);
163415 sqlite3_free(pCsr);
 
 
163416 return SQLITE_OK;
163417 }
163418
163419 /*
163420 ** Rtree virtual table module xEof method.
@@ -163433,27 +163986,34 @@
163433 ** endian platforms. The on-disk record stores integer coordinates if
163434 ** eInt is true and it stores 32-bit floating point records if eInt is
163435 ** false. a[] is the four bytes of the on-disk record to be decoded.
163436 ** Store the results in "r".
163437 **
163438 ** There are three versions of this macro, one each for little-endian and
163439 ** big-endian processors and a third generic implementation. The endian-
163440 ** specific implementations are much faster and are preferred if the
163441 ** processor endianness is known at compile-time. The SQLITE_BYTEORDER
163442 ** macro is part of sqliteInt.h and hence the endian-specific
163443 ** implementation will only be used if this module is compiled as part
163444 ** of the amalgamation.
163445 */
163446 #if defined(SQLITE_BYTEORDER) && SQLITE_BYTEORDER==1234
 
 
 
 
 
 
 
 
 
 
 
 
163447 #define RTREE_DECODE_COORD(eInt, a, r) { \
163448 RtreeCoord c; /* Coordinate decoded */ \
163449 memcpy(&c.u,a,4); \
163450 c.u = ((c.u>>24)&0xff)|((c.u>>8)&0xff00)| \
163451 ((c.u&0xff)<<24)|((c.u&0xff00)<<8); \
163452 r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \
163453 }
163454 #elif defined(SQLITE_BYTEORDER) && SQLITE_BYTEORDER==4321
163455 #define RTREE_DECODE_COORD(eInt, a, r) { \
163456 RtreeCoord c; /* Coordinate decoded */ \
163457 memcpy(&c.u,a,4); \
163458 r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \
163459 }
@@ -163476,30 +164036,58 @@
163476 u8 *pCellData, /* Raw cell content */
163477 RtreeSearchPoint *pSearch, /* Container of this cell */
163478 sqlite3_rtree_dbl *prScore, /* OUT: score for the cell */
163479 int *peWithin /* OUT: visibility of the cell */
163480 ){
163481 int i; /* Loop counter */
163482 sqlite3_rtree_query_info *pInfo = pConstraint->pInfo; /* Callback info */
163483 int nCoord = pInfo->nCoord; /* No. of coordinates */
163484 int rc; /* Callback return code */
 
163485 sqlite3_rtree_dbl aCoord[RTREE_MAX_DIMENSIONS*2]; /* Decoded coordinates */
163486
163487 assert( pConstraint->op==RTREE_MATCH || pConstraint->op==RTREE_QUERY );
163488 assert( nCoord==2 || nCoord==4 || nCoord==6 || nCoord==8 || nCoord==10 );
163489
163490 if( pConstraint->op==RTREE_QUERY && pSearch->iLevel==1 ){
163491 pInfo->iRowid = readInt64(pCellData);
163492 }
163493 pCellData += 8;
163494 for(i=0; i<nCoord; i++, pCellData += 4){
163495 RTREE_DECODE_COORD(eInt, pCellData, aCoord[i]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163496 }
163497 if( pConstraint->op==RTREE_MATCH ){
 
163498 rc = pConstraint->u.xGeom((sqlite3_rtree_geometry*)pInfo,
163499 nCoord, aCoord, &i);
163500 if( i==0 ) *peWithin = NOT_WITHIN;
163501 *prScore = RTREE_ZERO;
163502 }else{
163503 pInfo->aCoord = aCoord;
163504 pInfo->iLevel = pSearch->iLevel - 1;
163505 pInfo->rScore = pInfo->rParentScore = pSearch->rScore;
@@ -163531,10 +164119,11 @@
163531 */
163532 pCellData += 8 + 4*(p->iCoord&0xfe);
163533
163534 assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
163535 || p->op==RTREE_GT || p->op==RTREE_EQ );
 
163536 switch( p->op ){
163537 case RTREE_LE:
163538 case RTREE_LT:
163539 case RTREE_EQ:
163540 RTREE_DECODE_COORD(eInt, pCellData, val);
@@ -163571,10 +164160,11 @@
163571 RtreeDValue xN; /* Coordinate value converted to a double */
163572
163573 assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
163574 || p->op==RTREE_GT || p->op==RTREE_EQ );
163575 pCellData += 8 + p->iCoord*4;
 
163576 RTREE_DECODE_COORD(eInt, pCellData, xN);
163577 switch( p->op ){
163578 case RTREE_LE: if( xN <= p->u.rValue ) return; break;
163579 case RTREE_LT: if( xN < p->u.rValue ) return; break;
163580 case RTREE_GE: if( xN >= p->u.rValue ) return; break;
@@ -163639,11 +164229,11 @@
163639 if( pA->iLevel>pB->iLevel ) return +1;
163640 return 0;
163641 }
163642
163643 /*
163644 ** Interchange to search points in a cursor.
163645 */
163646 static void rtreeSearchPointSwap(RtreeCursor *p, int i, int j){
163647 RtreeSearchPoint t = p->aPoint[i];
163648 assert( i<j );
163649 p->aPoint[i] = p->aPoint[j];
@@ -163887,11 +164477,11 @@
163887 rtreeSearchPointPop(pCur);
163888 }
163889 if( rScore<RTREE_ZERO ) rScore = RTREE_ZERO;
163890 p = rtreeSearchPointNew(pCur, rScore, x.iLevel);
163891 if( p==0 ) return SQLITE_NOMEM;
163892 p->eWithin = eWithin;
163893 p->id = x.id;
163894 p->iCell = x.iCell;
163895 RTREE_QUEUE_TRACE(pCur, "PUSH-S:");
163896 break;
163897 }
@@ -163946,11 +164536,10 @@
163946 if( rc ) return rc;
163947 if( p==0 ) return SQLITE_OK;
163948 if( i==0 ){
163949 sqlite3_result_int64(ctx, nodeGetRowid(pRtree, pNode, p->iCell));
163950 }else{
163951 if( rc ) return rc;
163952 nodeGetCoord(pRtree, pNode, p->iCell, i-1, &c);
163953 #ifndef SQLITE_RTREE_INT_ONLY
163954 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
163955 sqlite3_result_double(ctx, c.f);
163956 }else
@@ -164075,11 +164664,11 @@
164075 assert( p!=0 ); /* Always returns pCsr->sPoint */
164076 pCsr->aNode[0] = pLeaf;
164077 p->id = iNode;
164078 p->eWithin = PARTLY_WITHIN;
164079 rc = nodeRowidIndex(pRtree, pLeaf, iRowid, &iCell);
164080 p->iCell = iCell;
164081 RTREE_QUEUE_TRACE(pCsr, "PUSH-F1:");
164082 }else{
164083 pCsr->atEOF = 1;
164084 }
164085 }else{
@@ -164108,11 +164697,11 @@
164108 */
164109 rc = deserializeGeometry(argv[ii], p);
164110 if( rc!=SQLITE_OK ){
164111 break;
164112 }
164113 p->pInfo->nCoord = pRtree->nDim*2;
164114 p->pInfo->anQueue = pCsr->anQueue;
164115 p->pInfo->mxLevel = pRtree->iDepth + 1;
164116 }else{
164117 #ifdef SQLITE_RTREE_INT_ONLY
164118 p->u.rValue = sqlite3_value_int64(argv[ii]);
@@ -164123,11 +164712,11 @@
164123 }
164124 }
164125 }
164126 if( rc==SQLITE_OK ){
164127 RtreeSearchPoint *pNew;
164128 pNew = rtreeSearchPointNew(pCsr, RTREE_ZERO, pRtree->iDepth+1);
164129 if( pNew==0 ) return SQLITE_NOMEM;
164130 pNew->id = 1;
164131 pNew->iCell = 0;
164132 pNew->eWithin = PARTLY_WITHIN;
164133 assert( pCsr->bPoint==1 );
@@ -164141,23 +164730,10 @@
164141 nodeRelease(pRtree, pRoot);
164142 rtreeRelease(pRtree);
164143 return rc;
164144 }
164145
164146 /*
164147 ** Set the pIdxInfo->estimatedRows variable to nRow. Unless this
164148 ** extension is currently being used by a version of SQLite too old to
164149 ** support estimatedRows. In that case this function is a no-op.
164150 */
164151 static void setEstimatedRows(sqlite3_index_info *pIdxInfo, i64 nRow){
164152 #if SQLITE_VERSION_NUMBER>=3008002
164153 if( sqlite3_libversion_number()>=3008002 ){
164154 pIdxInfo->estimatedRows = nRow;
164155 }
164156 #endif
164157 }
164158
164159 /*
164160 ** Rtree virtual table module xBestIndex method. There are three
164161 ** table scan strategies to choose from (in order from most to
164162 ** least desirable):
164163 **
@@ -164233,11 +164809,11 @@
164233 ** considered almost as quick as a direct rowid lookup (for which
164234 ** sqlite uses an internal cost of 0.0). It is expected to return
164235 ** a single row.
164236 */
164237 pIdxInfo->estimatedCost = 30.0;
164238 setEstimatedRows(pIdxInfo, 1);
164239 return SQLITE_OK;
164240 }
164241
164242 if( p->usable && (p->iColumn>0 || p->op==SQLITE_INDEX_CONSTRAINT_MATCH) ){
164243 u8 op;
@@ -164251,11 +164827,11 @@
164251 assert( p->op==SQLITE_INDEX_CONSTRAINT_MATCH );
164252 op = RTREE_MATCH;
164253 break;
164254 }
164255 zIdxStr[iIdx++] = op;
164256 zIdxStr[iIdx++] = p->iColumn - 1 + '0';
164257 pIdxInfo->aConstraintUsage[ii].argvIndex = (iIdx/2);
164258 pIdxInfo->aConstraintUsage[ii].omit = 1;
164259 }
164260 }
164261
@@ -164265,55 +164841,75 @@
164265 return SQLITE_NOMEM;
164266 }
164267
164268 nRow = pRtree->nRowEst >> (iIdx/2);
164269 pIdxInfo->estimatedCost = (double)6.0 * (double)nRow;
164270 setEstimatedRows(pIdxInfo, nRow);
164271
164272 return rc;
164273 }
164274
164275 /*
164276 ** Return the N-dimensional volumn of the cell stored in *p.
164277 */
164278 static RtreeDValue cellArea(Rtree *pRtree, RtreeCell *p){
164279 RtreeDValue area = (RtreeDValue)1;
164280 int ii;
164281 for(ii=0; ii<(pRtree->nDim*2); ii+=2){
164282 area = (area * (DCOORD(p->aCoord[ii+1]) - DCOORD(p->aCoord[ii])));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164283 }
164284 return area;
164285 }
164286
164287 /*
164288 ** Return the margin length of cell p. The margin length is the sum
164289 ** of the objects size in each dimension.
164290 */
164291 static RtreeDValue cellMargin(Rtree *pRtree, RtreeCell *p){
164292 RtreeDValue margin = (RtreeDValue)0;
164293 int ii;
164294 for(ii=0; ii<(pRtree->nDim*2); ii+=2){
164295 margin += (DCOORD(p->aCoord[ii+1]) - DCOORD(p->aCoord[ii]));
164296 }
 
164297 return margin;
164298 }
164299
164300 /*
164301 ** Store the union of cells p1 and p2 in p1.
164302 */
164303 static void cellUnion(Rtree *pRtree, RtreeCell *p1, RtreeCell *p2){
164304 int ii;
164305 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
164306 for(ii=0; ii<(pRtree->nDim*2); ii+=2){
164307 p1->aCoord[ii].f = MIN(p1->aCoord[ii].f, p2->aCoord[ii].f);
164308 p1->aCoord[ii+1].f = MAX(p1->aCoord[ii+1].f, p2->aCoord[ii+1].f);
164309 }
 
164310 }else{
164311 for(ii=0; ii<(pRtree->nDim*2); ii+=2){
164312 p1->aCoord[ii].i = MIN(p1->aCoord[ii].i, p2->aCoord[ii].i);
164313 p1->aCoord[ii+1].i = MAX(p1->aCoord[ii+1].i, p2->aCoord[ii+1].i);
164314 }
 
164315 }
164316 }
164317
164318 /*
164319 ** Return true if the area covered by p2 is a subset of the area covered
@@ -164320,11 +164916,11 @@
164320 ** by p1. False otherwise.
164321 */
164322 static int cellContains(Rtree *pRtree, RtreeCell *p1, RtreeCell *p2){
164323 int ii;
164324 int isInt = (pRtree->eCoordType==RTREE_COORD_INT32);
164325 for(ii=0; ii<(pRtree->nDim*2); ii+=2){
164326 RtreeCoord *a1 = &p1->aCoord[ii];
164327 RtreeCoord *a2 = &p2->aCoord[ii];
164328 if( (!isInt && (a2[0].f<a1[0].f || a2[1].f>a1[1].f))
164329 || ( isInt && (a2[0].i<a1[0].i || a2[1].i>a1[1].i))
164330 ){
@@ -164355,11 +164951,11 @@
164355 int ii;
164356 RtreeDValue overlap = RTREE_ZERO;
164357 for(ii=0; ii<nCell; ii++){
164358 int jj;
164359 RtreeDValue o = (RtreeDValue)1;
164360 for(jj=0; jj<(pRtree->nDim*2); jj+=2){
164361 RtreeDValue x1, x2;
164362 x1 = MAX(DCOORD(p->aCoord[jj]), DCOORD(aCell[ii].aCoord[jj]));
164363 x2 = MIN(DCOORD(p->aCoord[jj+1]), DCOORD(aCell[ii].aCoord[jj+1]));
164364 if( x2<x1 ){
164365 o = (RtreeDValue)0;
@@ -165411,11 +166007,11 @@
165411 ** with "column" that are interpreted as table constraints.
165412 ** Example: CREATE VIRTUAL TABLE bad USING rtree(x,y,CHECK(y>5));
165413 ** This problem was discovered after years of use, so we silently ignore
165414 ** these kinds of misdeclared tables to avoid breaking any legacy.
165415 */
165416 assert( nData<=(pRtree->nDim*2 + 3) );
165417
165418 #ifndef SQLITE_RTREE_INT_ONLY
165419 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
165420 for(ii=0; ii<nData-4; ii+=2){
165421 cell.aCoord[ii].f = rtreeValueDown(azData[ii+3]);
@@ -165500,10 +166096,31 @@
165500
165501 constraint:
165502 rtreeRelease(pRtree);
165503 return rc;
165504 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165505
165506 /*
165507 ** The xRename method for rtree module virtual tables.
165508 */
165509 static int rtreeRename(sqlite3_vtab *pVtab, const char *zNewName){
@@ -165521,10 +166138,11 @@
165521 rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
165522 sqlite3_free(zSql);
165523 }
165524 return rc;
165525 }
 
165526
165527 /*
165528 ** This function populates the pRtree->nRowEst variable with an estimate
165529 ** of the number of rows in the virtual table. If possible, this is based
165530 ** on sqlite_stat1 data. Otherwise, use RTREE_DEFAULT_ROWEST.
@@ -165581,19 +166199,19 @@
165581 rtreeNext, /* xNext - advance a cursor */
165582 rtreeEof, /* xEof */
165583 rtreeColumn, /* xColumn - read data */
165584 rtreeRowid, /* xRowid - read data */
165585 rtreeUpdate, /* xUpdate - write data */
165586 0, /* xBegin - begin transaction */
165587 0, /* xSync - sync transaction */
165588 0, /* xCommit - commit transaction */
165589 0, /* xRollback - rollback transaction */
165590 0, /* xFindFunction - function overloading */
165591 rtreeRename, /* xRename - rename the table */
165592 0, /* xSavepoint */
165593 0, /* xRelease */
165594 0 /* xRollbackTo */
165595 };
165596
165597 static int rtreeSqlInit(
165598 Rtree *pRtree,
165599 sqlite3 *db,
@@ -165601,14 +166219,13 @@
165601 const char *zPrefix,
165602 int isCreate
165603 ){
165604 int rc = SQLITE_OK;
165605
165606 #define N_STATEMENT 9
165607 static const char *azSql[N_STATEMENT] = {
165608 /* Read and write the xxx_node table */
165609 "SELECT data FROM '%q'.'%q_node' WHERE nodeno = :1",
165610 "INSERT OR REPLACE INTO '%q'.'%q_node' VALUES(:1, :2)",
165611 "DELETE FROM '%q'.'%q_node' WHERE nodeno = :1",
165612
165613 /* Read and write the xxx_rowid table */
165614 "SELECT nodeno FROM '%q'.'%q_rowid' WHERE rowid = :1",
@@ -165642,19 +166259,18 @@
165642 if( rc!=SQLITE_OK ){
165643 return rc;
165644 }
165645 }
165646
165647 appStmt[0] = &pRtree->pReadNode;
165648 appStmt[1] = &pRtree->pWriteNode;
165649 appStmt[2] = &pRtree->pDeleteNode;
165650 appStmt[3] = &pRtree->pReadRowid;
165651 appStmt[4] = &pRtree->pWriteRowid;
165652 appStmt[5] = &pRtree->pDeleteRowid;
165653 appStmt[6] = &pRtree->pReadParent;
165654 appStmt[7] = &pRtree->pWriteParent;
165655 appStmt[8] = &pRtree->pDeleteParent;
165656
165657 rc = rtreeQueryStat1(db, pRtree);
165658 for(i=0; i<N_STATEMENT && rc==SQLITE_OK; i++){
165659 char *zSql = sqlite3_mprintf(azSql[i], zDb, zPrefix);
165660 if( zSql ){
@@ -165788,13 +166404,14 @@
165788 memset(pRtree, 0, sizeof(Rtree)+nDb+nName+2);
165789 pRtree->nBusy = 1;
165790 pRtree->base.pModule = &rtreeModule;
165791 pRtree->zDb = (char *)&pRtree[1];
165792 pRtree->zName = &pRtree->zDb[nDb+1];
165793 pRtree->nDim = (argc-4)/2;
165794 pRtree->nBytesPerCell = 8 + pRtree->nDim*4*2;
165795 pRtree->eCoordType = eCoordType;
 
165796 memcpy(pRtree->zDb, argv[1], nDb);
165797 memcpy(pRtree->zName, argv[2], nName);
165798
165799 /* Figure out the node size to use. */
165800 rc = getNodeSize(db, pRtree, isCreate, pzErr);
@@ -165863,11 +166480,12 @@
165863 int ii;
165864
165865 UNUSED_PARAMETER(nArg);
165866 memset(&node, 0, sizeof(RtreeNode));
165867 memset(&tree, 0, sizeof(Rtree));
165868 tree.nDim = sqlite3_value_int(apArg[0]);
 
165869 tree.nBytesPerCell = 8 + 8 * tree.nDim;
165870 node.zData = (u8 *)sqlite3_value_blob(apArg[1]);
165871
165872 for(ii=0; ii<NCELL(&node); ii++){
165873 char zCell[512];
@@ -165876,11 +166494,11 @@
165876 int jj;
165877
165878 nodeGetCell(&tree, &node, ii, &cell);
165879 sqlite3_snprintf(512-nCell,&zCell[nCell],"%lld", cell.iRowid);
165880 nCell = (int)strlen(zCell);
165881 for(jj=0; jj<tree.nDim*2; jj++){
165882 #ifndef SQLITE_RTREE_INT_ONLY
165883 sqlite3_snprintf(512-nCell,&zCell[nCell], " %g",
165884 (double)cell.aCoord[jj].f);
165885 #else
165886 sqlite3_snprintf(512-nCell,&zCell[nCell], " %d",
@@ -166584,42 +167202,40 @@
166584
166585 /*
166586 ** Register the ICU extension functions with database db.
166587 */
166588 SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db){
166589 struct IcuScalar {
166590 const char *zName; /* Function name */
166591 int nArg; /* Number of arguments */
166592 int enc; /* Optimal text encoding */
166593 void *pContext; /* sqlite3_user_data() context */
166594 void (*xFunc)(sqlite3_context*,int,sqlite3_value**);
166595 } scalars[] = {
166596 {"regexp", 2, SQLITE_ANY|SQLITE_DETERMINISTIC, 0, icuRegexpFunc},
166597
166598 {"lower", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
166599 {"lower", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
166600 {"upper", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16},
166601 {"upper", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16},
166602
166603 {"lower", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
166604 {"lower", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
166605 {"upper", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16},
166606 {"upper", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16},
166607
166608 {"like", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc},
166609 {"like", 3, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc},
166610
166611 {"icu_load_collation", 2, SQLITE_UTF8, (void*)db, icuLoadCollation},
166612 };
166613
166614 int rc = SQLITE_OK;
166615 int i;
166616
 
166617 for(i=0; rc==SQLITE_OK && i<(int)(sizeof(scalars)/sizeof(scalars[0])); i++){
166618 struct IcuScalar *p = &scalars[i];
166619 rc = sqlite3_create_function(
166620 db, p->zName, p->nArg, p->enc, p->pContext, p->xFunc, 0, 0
 
 
166621 );
166622 }
166623
166624 return rc;
166625 }
@@ -169823,11 +170439,11 @@
169823
169824 /*
169825 ** Open the database handle and attach the RBU database as "rbu". If an
169826 ** error occurs, leave an error code and message in the RBU handle.
169827 */
169828 static void rbuOpenDatabase(sqlite3rbu *p){
169829 assert( p->rc || (p->dbMain==0 && p->dbRbu==0) );
169830 assert( p->rc || rbuIsVacuum(p) || p->zTarget!=0 );
169831
169832 /* Open the RBU database */
169833 p->dbRbu = rbuOpenDbhandle(p, p->zRbu, 1);
@@ -169898,11 +170514,11 @@
169898 if( p->eStage>=RBU_STAGE_MOVE ){
169899 bOpen = 1;
169900 }else{
169901 RbuState *pState = rbuLoadState(p);
169902 if( pState ){
169903 bOpen = (pState->eStage>RBU_STAGE_MOVE);
169904 rbuFreeState(pState);
169905 }
169906 }
169907 if( bOpen ) p->dbMain = rbuOpenDbhandle(p, p->zRbu, p->nRbu<=1);
169908 }
@@ -169910,10 +170526,19 @@
169910 p->eStage = 0;
169911 if( p->rc==SQLITE_OK && p->dbMain==0 ){
169912 if( !rbuIsVacuum(p) ){
169913 p->dbMain = rbuOpenDbhandle(p, p->zTarget, 1);
169914 }else if( p->pRbuFd->pWalFd ){
 
 
 
 
 
 
 
 
 
169915 p->rc = SQLITE_ERROR;
169916 p->zErrmsg = sqlite3_mprintf("cannot vacuum wal mode database");
169917 }else{
169918 char *zTarget;
169919 char *zExtra = 0;
@@ -170090,20 +170715,22 @@
170090 p->eStage = RBU_STAGE_CAPTURE;
170091 rc2 = sqlite3_exec(p->dbMain, "PRAGMA main.wal_checkpoint=restart", 0, 0,0);
170092 if( rc2!=SQLITE_INTERNAL ) p->rc = rc2;
170093 }
170094
170095 if( p->rc==SQLITE_OK ){
170096 p->eStage = RBU_STAGE_CKPT;
170097 p->nStep = (pState ? pState->nRow : 0);
170098 p->aBuf = rbuMalloc(p, p->pgsz);
170099 p->iWalCksum = rbuShmChecksum(p);
170100 }
170101
170102 if( p->rc==SQLITE_OK && pState && pState->iWalCksum!=p->iWalCksum ){
170103 p->rc = SQLITE_DONE;
170104 p->eStage = RBU_STAGE_DONE;
 
 
170105 }
170106 }
170107
170108 /*
170109 ** Called when iAmt bytes are read from offset iOff of the wal file while
@@ -170272,11 +170899,11 @@
170272 #else
170273 p->rc = rename(zOal, zWal) ? SQLITE_IOERR : SQLITE_OK;
170274 #endif
170275
170276 if( p->rc==SQLITE_OK ){
170277 rbuOpenDatabase(p);
170278 rbuSetupCheckpoint(p, 0);
170279 }
170280 }
170281 }
170282
@@ -170983,10 +171610,11 @@
170983 rbuCreateVfs(p);
170984
170985 /* Open the target, RBU and state databases */
170986 if( p->rc==SQLITE_OK ){
170987 char *pCsr = (char*)&p[1];
 
170988 if( zTarget ){
170989 p->zTarget = pCsr;
170990 memcpy(p->zTarget, zTarget, nTarget+1);
170991 pCsr += nTarget+1;
170992 }
@@ -170994,11 +171622,22 @@
170994 memcpy(p->zRbu, zRbu, nRbu+1);
170995 pCsr += nRbu+1;
170996 if( zState ){
170997 p->zState = rbuMPrintf(p, "%s", zState);
170998 }
170999 rbuOpenDatabase(p);
 
 
 
 
 
 
 
 
 
 
 
171000 }
171001
171002 if( p->rc==SQLITE_OK ){
171003 pState = rbuLoadState(p);
171004 assert( pState || p->rc!=SQLITE_OK );
@@ -175957,11 +176596,11 @@
175957 sqlite3_value **ppValue /* OUT: Value from conflicting row */
175958 ){
175959 if( !pIter->pConflict ){
175960 return SQLITE_MISUSE;
175961 }
175962 if( iVal<0 || iVal>=sqlite3_column_count(pIter->pConflict) ){
175963 return SQLITE_RANGE;
175964 }
175965 *ppValue = sqlite3_column_value(pIter->pConflict, iVal);
175966 return SQLITE_OK;
175967 }
@@ -176424,11 +177063,17 @@
176424 int i;
176425 SessionBuffer buf = {0, 0, 0};
176426
176427 sessionAppendStr(&buf, "INSERT INTO main.", &rc);
176428 sessionAppendIdent(&buf, zTab, &rc);
176429 sessionAppendStr(&buf, " VALUES(?", &rc);
 
 
 
 
 
 
176430 for(i=1; i<p->nCol; i++){
176431 sessionAppendStr(&buf, ", ?", &rc);
176432 }
176433 sessionAppendStr(&buf, ")", &rc);
176434
@@ -176970,42 +177615,51 @@
176970 break;
176971 }
176972 nTab = (int)strlen(zTab);
176973 sApply.azCol = (const char **)zTab;
176974 }else{
 
 
 
176975 sqlite3changeset_pk(pIter, &abPK, 0);
176976 rc = sessionTableInfo(
176977 db, "main", zNew, &sApply.nCol, &zTab, &sApply.azCol, &sApply.abPK
176978 );
176979 if( rc!=SQLITE_OK ) break;
 
 
 
176980
176981 if( sApply.nCol==0 ){
176982 schemaMismatch = 1;
176983 sqlite3_log(SQLITE_SCHEMA,
176984 "sqlite3changeset_apply(): no such table: %s", zTab
176985 );
176986 }
176987 else if( sApply.nCol!=nCol ){
176988 schemaMismatch = 1;
176989 sqlite3_log(SQLITE_SCHEMA,
176990 "sqlite3changeset_apply(): table %s has %d columns, expected %d",
 
176991 zTab, sApply.nCol, nCol
176992 );
176993 }
176994 else if( memcmp(sApply.abPK, abPK, nCol)!=0 ){
176995 schemaMismatch = 1;
176996 sqlite3_log(SQLITE_SCHEMA, "sqlite3changeset_apply(): "
176997 "primary key mismatch for table %s", zTab
176998 );
176999 }
177000 else if(
177001 (rc = sessionSelectRow(db, zTab, &sApply))
177002 || (rc = sessionUpdateRow(db, zTab, &sApply))
177003 || (rc = sessionDeleteRow(db, zTab, &sApply))
177004 || (rc = sessionInsertRow(db, zTab, &sApply))
177005 ){
177006 break;
 
 
177007 }
177008 nTab = sqlite3Strlen30(zTab);
177009 }
177010 }
177011
@@ -177593,11 +178247,11 @@
177593 ** a BLOB, but there is no support for JSONB in the current implementation.
177594 ** This implementation parses JSON text at 250 MB/s, so it is hard to see
177595 ** how JSONB might improve on that.)
177596 */
177597 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_JSON1)
177598 #if !defined(_SQLITEINT_H_)
177599 /* #include "sqlite3ext.h" */
177600 #endif
177601 SQLITE_EXTENSION_INIT1
177602 /* #include <assert.h> */
177603 /* #include <string.h> */
@@ -181644,10 +182298,35 @@
181644 */
181645 #ifndef fts5YYMALLOCARGTYPE
181646 # define fts5YYMALLOCARGTYPE size_t
181647 #endif
181648
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181649 /*
181650 ** This function allocates a new parser.
181651 ** The only argument is a pointer to a function which works like
181652 ** malloc.
181653 **
@@ -181659,32 +182338,15 @@
181659 ** to sqlite3Fts5Parser and sqlite3Fts5ParserFree.
181660 */
181661 static void *sqlite3Fts5ParserAlloc(void *(*mallocProc)(fts5YYMALLOCARGTYPE)){
181662 fts5yyParser *pParser;
181663 pParser = (fts5yyParser*)(*mallocProc)( (fts5YYMALLOCARGTYPE)sizeof(fts5yyParser) );
181664 if( pParser ){
181665 #ifdef fts5YYTRACKMAXSTACKDEPTH
181666 pParser->fts5yyhwm = 0;
181667 #endif
181668 #if fts5YYSTACKDEPTH<=0
181669 pParser->fts5yytos = NULL;
181670 pParser->fts5yystack = NULL;
181671 pParser->fts5yystksz = 0;
181672 if( fts5yyGrowStack(pParser) ){
181673 pParser->fts5yystack = &pParser->fts5yystk0;
181674 pParser->fts5yystksz = 1;
181675 }
181676 #endif
181677 #ifndef fts5YYNOERRORRECOVERY
181678 pParser->fts5yyerrcnt = -1;
181679 #endif
181680 pParser->fts5yytos = pParser->fts5yystack;
181681 pParser->fts5yystack[0].stateno = 0;
181682 pParser->fts5yystack[0].major = 0;
181683 }
181684 return pParser;
181685 }
 
 
181686
181687 /* The following function deletes the "minor type" or semantic value
181688 ** associated with a symbol. The symbol can be either a terminal
181689 ** or nonterminal. "fts5yymajor" is the symbol code, and "fts5yypminor" is
181690 ** a pointer to the value to be deleted. The code used to do the
@@ -181762,10 +182424,22 @@
181762 }
181763 #endif
181764 fts5yy_destructor(pParser, fts5yytos->major, &fts5yytos->minor);
181765 }
181766
 
 
 
 
 
 
 
 
 
 
 
 
181767 /*
181768 ** Deallocate and destroy a parser. Destructors are called for
181769 ** all stack elements before shutting the parser down.
181770 **
181771 ** If the fts5YYPARSEFREENEVERNULL macro exists (for example because it
@@ -181774,20 +182448,17 @@
181774 */
181775 static void sqlite3Fts5ParserFree(
181776 void *p, /* The parser to be deleted */
181777 void (*freeProc)(void*) /* Function used to reclaim memory */
181778 ){
181779 fts5yyParser *pParser = (fts5yyParser*)p;
181780 #ifndef fts5YYPARSEFREENEVERNULL
181781 if( pParser==0 ) return;
181782 #endif
181783 while( pParser->fts5yytos>pParser->fts5yystack ) fts5yy_pop_parser_stack(pParser);
181784 #if fts5YYSTACKDEPTH<=0
181785 if( pParser->fts5yystack!=&pParser->fts5yystk0 ) free(pParser->fts5yystack);
181786 #endif
181787 (*freeProc)((void*)pParser);
181788 }
181789
181790 /*
181791 ** Return the peak depth of the stack for a parser.
181792 */
181793 #ifdef fts5YYTRACKMAXSTACKDEPTH
@@ -186122,11 +186793,11 @@
186122 memset(&sCtx, 0, sizeof(TokenCtx));
186123 sCtx.pPhrase = pAppend;
186124
186125 rc = fts5ParseStringFromToken(pToken, &z);
186126 if( rc==SQLITE_OK ){
186127 int flags = FTS5_TOKENIZE_QUERY | (bPrefix ? FTS5_TOKENIZE_QUERY : 0);
186128 int n;
186129 sqlite3Fts5Dequote(z);
186130 n = (int)strlen(z);
186131 rc = sqlite3Fts5Tokenize(pConfig, flags, z, n, &sCtx, fts5ParseTokenize);
186132 }
@@ -196863,11 +197534,11 @@
196863 int nArg, /* Number of args */
196864 sqlite3_value **apUnused /* Function arguments */
196865 ){
196866 assert( nArg==0 );
196867 UNUSED_PARAM2(nArg, apUnused);
196868 sqlite3_result_text(pCtx, "fts5: 2017-01-06 16:32:41 a65a62893ca8319e89e48b8a38cf8a59c69a8209", -1, SQLITE_TRANSIENT);
196869 }
196870
196871 static int fts5Init(sqlite3 *db){
196872 static const sqlite3_module fts5Mod = {
196873 /* iVersion */ 2,
196874
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.17.0. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -202,15 +202,32 @@
202 # define _FILE_OFFSET_BITS 64
203 # endif
204 # define _LARGEFILE_SOURCE 1
205 #endif
206
207 /* The GCC_VERSION and MSVC_VERSION macros are used to
208 ** conditionally include optimizations for each of these compilers. A
209 ** value of 0 means that compiler is not being used. The
210 ** SQLITE_DISABLE_INTRINSIC macro means do not use any compiler-specific
211 ** optimizations, and hence set all compiler macros to 0
212 **
213 ** There was once also a CLANG_VERSION macro. However, we learn that the
214 ** version numbers in clang are for "marketing" only and are inconsistent
215 ** and unreliable. Fortunately, all versions of clang also recognize the
216 ** gcc version numbers and have reasonable settings for gcc version numbers,
217 ** so the GCC_VERSION macro will be set to a correct non-zero value even
218 ** when compiling with clang.
219 */
220 #if defined(__GNUC__) && !defined(SQLITE_DISABLE_INTRINSIC)
221 # define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__)
222 #else
223 # define GCC_VERSION 0
224 #endif
225 #if defined(_MSC_VER) && !defined(SQLITE_DISABLE_INTRINSIC)
226 # define MSVC_VERSION _MSC_VER
227 #else
228 # define MSVC_VERSION 0
229 #endif
230
231 /* Needed for various definitions... */
232 #if defined(__GNUC__) && !defined(_GNU_SOURCE)
233 # define _GNU_SOURCE
@@ -379,13 +396,13 @@
396 **
397 ** See also: [sqlite3_libversion()],
398 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
399 ** [sqlite_version()] and [sqlite_source_id()].
400 */
401 #define SQLITE_VERSION "3.17.0"
402 #define SQLITE_VERSION_NUMBER 3017000
403 #define SQLITE_SOURCE_ID "2017-02-13 16:02:40 ada05cfa86ad7f5645450ac7a2a21c9aa6e57d2c"
404
405 /*
406 ** CAPI3REF: Run-Time Library Version Numbers
407 ** KEYWORDS: sqlite3_version sqlite3_sourceid
408 **
@@ -517,11 +534,15 @@
534 ** sqlite3_uint64 and sqlite_uint64 types can store integer values
535 ** between 0 and +18446744073709551615 inclusive.
536 */
537 #ifdef SQLITE_INT64_TYPE
538 typedef SQLITE_INT64_TYPE sqlite_int64;
539 # ifdef SQLITE_UINT64_TYPE
540 typedef SQLITE_UINT64_TYPE sqlite_uint64;
541 # else
542 typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
543 # endif
544 #elif defined(_MSC_VER) || defined(__BORLANDC__)
545 typedef __int64 sqlite_int64;
546 typedef unsigned __int64 sqlite_uint64;
547 #else
548 typedef long long int sqlite_int64;
@@ -830,11 +851,11 @@
851 ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
852 ** after reboot following a crash or power loss, the only bytes in a
853 ** file that were written at the application level might have changed
854 ** and that adjacent bytes, even bytes within the same sector are
855 ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
856 ** flag indicates that a file cannot be deleted when open. The
857 ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
858 ** read-only media and cannot be changed even by processes with
859 ** elevated privileges.
860 */
861 #define SQLITE_IOCAP_ATOMIC 0x00000001
@@ -980,10 +1001,13 @@
1001 ** <li> [SQLITE_IOCAP_ATOMIC16K]
1002 ** <li> [SQLITE_IOCAP_ATOMIC32K]
1003 ** <li> [SQLITE_IOCAP_ATOMIC64K]
1004 ** <li> [SQLITE_IOCAP_SAFE_APPEND]
1005 ** <li> [SQLITE_IOCAP_SEQUENTIAL]
1006 ** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]
1007 ** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
1008 ** <li> [SQLITE_IOCAP_IMMUTABLE]
1009 ** </ul>
1010 **
1011 ** The SQLITE_IOCAP_ATOMIC property means that all writes of
1012 ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
1013 ** mean that writes of blocks that are nnn bytes in size and
@@ -5668,11 +5692,11 @@
5692 ** ^(The update hook is not invoked when internal system tables are
5693 ** modified (i.e. sqlite_master and sqlite_sequence).)^
5694 ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
5695 **
5696 ** ^In the current implementation, the update hook
5697 ** is not invoked when conflicting rows are deleted because of an
5698 ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
5699 ** invoked when rows are deleted using the [truncate optimization].
5700 ** The exceptions defined in this paragraph might change in a future
5701 ** release of SQLite.
5702 **
@@ -6450,10 +6474,16 @@
6474 **
6475 ** ^Unless it returns SQLITE_MISUSE, this function sets the
6476 ** [database connection] error code and message accessible via
6477 ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
6478 **
6479 ** A BLOB referenced by sqlite3_blob_open() may be read using the
6480 ** [sqlite3_blob_read()] interface and modified by using
6481 ** [sqlite3_blob_write()]. The [BLOB handle] can be moved to a
6482 ** different row of the same table using the [sqlite3_blob_reopen()]
6483 ** interface. However, the column, table, or database of a [BLOB handle]
6484 ** cannot be changed after the [BLOB handle] is opened.
6485 **
6486 ** ^(If the row that a BLOB handle points to is modified by an
6487 ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
6488 ** then the BLOB handle is marked as "expired".
6489 ** This is true if any column of the row is changed, even a column
@@ -6473,10 +6503,14 @@
6503 ** and the built-in [zeroblob] SQL function may be used to create a
6504 ** zero-filled blob to read or write using the incremental-blob interface.
6505 **
6506 ** To avoid a resource leak, every open [BLOB handle] should eventually
6507 ** be released by a call to [sqlite3_blob_close()].
6508 **
6509 ** See also: [sqlite3_blob_close()],
6510 ** [sqlite3_blob_reopen()], [sqlite3_blob_read()],
6511 ** [sqlite3_blob_bytes()], [sqlite3_blob_write()].
6512 */
6513 SQLITE_API int sqlite3_blob_open(
6514 sqlite3*,
6515 const char *zDb,
6516 const char *zTable,
@@ -6488,15 +6522,15 @@
6522
6523 /*
6524 ** CAPI3REF: Move a BLOB Handle to a New Row
6525 ** METHOD: sqlite3_blob
6526 **
6527 ** ^This function is used to move an existing [BLOB handle] so that it points
6528 ** to a different row of the same database table. ^The new row is identified
6529 ** by the rowid value passed as the second argument. Only the row can be
6530 ** changed. ^The database, table and column on which the blob handle is open
6531 ** remain the same. Moving an existing [BLOB handle] to a new row is
6532 ** faster than closing the existing handle and opening a new one.
6533 **
6534 ** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] -
6535 ** it must exist and there must be either a blob or text value stored in
6536 ** the nominated column.)^ ^If the new row is not present in the table, or if
@@ -8421,22 +8455,22 @@
8455 ** ^These interfaces are only available if SQLite is compiled using the
8456 ** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option.
8457 **
8458 ** ^The [sqlite3_preupdate_hook()] interface registers a callback function
8459 ** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation
8460 ** on a database table.
8461 ** ^At most one preupdate hook may be registered at a time on a single
8462 ** [database connection]; each call to [sqlite3_preupdate_hook()] overrides
8463 ** the previous setting.
8464 ** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()]
8465 ** with a NULL pointer as the second parameter.
8466 ** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as
8467 ** the first parameter to callbacks.
8468 **
8469 ** ^The preupdate hook only fires for changes to real database tables; the
8470 ** preupdate hook is not invoked for changes to [virtual tables] or to
8471 ** system tables like sqlite_master or sqlite_stat1.
8472 **
8473 ** ^The second parameter to the preupdate callback is a pointer to
8474 ** the [database connection] that registered the preupdate hook.
8475 ** ^The third parameter to the preupdate callback is one of the constants
8476 ** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the
@@ -8446,16 +8480,20 @@
8480 ** will be "main" for the main database or "temp" for TEMP tables or
8481 ** the name given after the AS keyword in the [ATTACH] statement for attached
8482 ** databases.)^
8483 ** ^The fifth parameter to the preupdate callback is the name of the
8484 ** table that is being modified.
8485 **
8486 ** For an UPDATE or DELETE operation on a [rowid table], the sixth
8487 ** parameter passed to the preupdate callback is the initial [rowid] of the
8488 ** row being modified or deleted. For an INSERT operation on a rowid table,
8489 ** or any operation on a WITHOUT ROWID table, the value of the sixth
8490 ** parameter is undefined. For an INSERT or UPDATE on a rowid table the
8491 ** seventh parameter is the final rowid value of the row being inserted
8492 ** or updated. The value of the seventh parameter passed to the callback
8493 ** function is not defined for operations on WITHOUT ROWID tables, or for
8494 ** INSERT operations on rowid tables.
8495 **
8496 ** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
8497 ** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
8498 ** provide additional information about a preupdate event. These routines
8499 ** may only be called from within a preupdate callback. Invoking any of
@@ -8887,11 +8925,11 @@
8925 ** The session object will be used to create changesets for tables in
8926 ** database zDb, where zDb is either "main", or "temp", or the name of an
8927 ** attached database. It is not an error if database zDb is not attached
8928 ** to the database when the session object is created.
8929 */
8930 SQLITE_API int sqlite3session_create(
8931 sqlite3 *db, /* Database handle */
8932 const char *zDb, /* Name of db (e.g. "main") */
8933 sqlite3_session **ppSession /* OUT: New session object */
8934 );
8935
@@ -8905,11 +8943,11 @@
8943 **
8944 ** Session objects must be deleted before the database handle to which they
8945 ** are attached is closed. Refer to the documentation for
8946 ** [sqlite3session_create()] for details.
8947 */
8948 SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);
8949
8950
8951 /*
8952 ** CAPI3REF: Enable Or Disable A Session Object
8953 **
@@ -8925,11 +8963,11 @@
8963 ** no-op, and may be used to query the current state of the session.
8964 **
8965 ** The return value indicates the final state of the session object: 0 if
8966 ** the session is disabled, or 1 if it is enabled.
8967 */
8968 SQLITE_API int sqlite3session_enable(sqlite3_session *pSession, int bEnable);
8969
8970 /*
8971 ** CAPI3REF: Set Or Clear the Indirect Change Flag
8972 **
8973 ** Each change recorded by a session object is marked as either direct or
@@ -8954,11 +8992,11 @@
8992 ** indirect flag for the specified session object.
8993 **
8994 ** The return value indicates the final state of the indirect flag: 0 if
8995 ** it is clear, or 1 if it is set.
8996 */
8997 SQLITE_API int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect);
8998
8999 /*
9000 ** CAPI3REF: Attach A Table To A Session Object
9001 **
9002 ** If argument zTab is not NULL, then it is the name of a table to attach
@@ -8984,11 +9022,11 @@
9022 ** in one or more of their PRIMARY KEY columns.
9023 **
9024 ** SQLITE_OK is returned if the call completes without error. Or, if an error
9025 ** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
9026 */
9027 SQLITE_API int sqlite3session_attach(
9028 sqlite3_session *pSession, /* Session object */
9029 const char *zTab /* Table name */
9030 );
9031
9032 /*
@@ -8998,11 +9036,11 @@
9036 ** in tables that are not attached to the Session object, the filter is called
9037 ** to determine whether changes to the table's rows should be tracked or not.
9038 ** If xFilter returns 0, changes is not tracked. Note that once a table is
9039 ** attached, xFilter will not be called again.
9040 */
9041 SQLITE_API void sqlite3session_table_filter(
9042 sqlite3_session *pSession, /* Session object */
9043 int(*xFilter)(
9044 void *pCtx, /* Copy of third arg to _filter_table() */
9045 const char *zTab /* Table name */
9046 ),
@@ -9111,11 +9149,11 @@
9149 ** changeset, even though the delete took place while the session was disabled.
9150 ** Or, if one field of a row is updated while a session is disabled, and
9151 ** another field of the same row is updated while the session is enabled, the
9152 ** resulting changeset will contain an UPDATE change that updates both fields.
9153 */
9154 SQLITE_API int sqlite3session_changeset(
9155 sqlite3_session *pSession, /* Session object */
9156 int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */
9157 void **ppChangeset /* OUT: Buffer containing changeset */
9158 );
9159
@@ -9155,11 +9193,12 @@
9193 **
9194 ** <li> For each row (primary key) that exists in the to-table but not in
9195 ** the from-table, a DELETE record is added to the session object.
9196 **
9197 ** <li> For each row (primary key) that exists in both tables, but features
9198 ** different non-PK values in each, an UPDATE record is added to the
9199 ** session.
9200 ** </ul>
9201 **
9202 ** To clarify, if this function is called and then a changeset constructed
9203 ** using [sqlite3session_changeset()], then after applying that changeset to
9204 ** database zFrom the contents of the two compatible tables would be
@@ -9172,11 +9211,11 @@
9211 ** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
9212 ** may be set to point to a buffer containing an English language error
9213 ** message. It is the responsibility of the caller to free this buffer using
9214 ** sqlite3_free().
9215 */
9216 SQLITE_API int sqlite3session_diff(
9217 sqlite3_session *pSession,
9218 const char *zFromDb,
9219 const char *zTbl,
9220 char **pzErrMsg
9221 );
@@ -9208,11 +9247,11 @@
9247 ** Changes within a patchset are ordered in the same way as for changesets
9248 ** generated by the sqlite3session_changeset() function (i.e. all changes for
9249 ** a single table are grouped together, tables appear in the order in which
9250 ** they were attached to the session object).
9251 */
9252 SQLITE_API int sqlite3session_patchset(
9253 sqlite3_session *pSession, /* Session object */
9254 int *pnPatchset, /* OUT: Size of buffer at *ppChangeset */
9255 void **ppPatchset /* OUT: Buffer containing changeset */
9256 );
9257
@@ -9229,11 +9268,11 @@
9268 ** an attached table is modified and then later on the original values
9269 ** are restored. However, if this function returns non-zero, then it is
9270 ** guaranteed that a call to sqlite3session_changeset() will return a
9271 ** changeset containing zero changes.
9272 */
9273 SQLITE_API int sqlite3session_isempty(sqlite3_session *pSession);
9274
9275 /*
9276 ** CAPI3REF: Create An Iterator To Traverse A Changeset
9277 **
9278 ** Create an iterator used to iterate through the contents of a changeset.
@@ -9264,11 +9303,11 @@
9303 ** this function, all changes that relate to a single table are visited
9304 ** consecutively. There is no chance that the iterator will visit a change
9305 ** the applies to table X, then one for table Y, and then later on visit
9306 ** another change for table X.
9307 */
9308 SQLITE_API int sqlite3changeset_start(
9309 sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */
9310 int nChangeset, /* Size of changeset blob in bytes */
9311 void *pChangeset /* Pointer to blob containing changeset */
9312 );
9313
@@ -9293,11 +9332,11 @@
9332 **
9333 ** If an error occurs, an SQLite error code is returned. Possible error
9334 ** codes include SQLITE_CORRUPT (if the changeset buffer is corrupt) or
9335 ** SQLITE_NOMEM.
9336 */
9337 SQLITE_API int sqlite3changeset_next(sqlite3_changeset_iter *pIter);
9338
9339 /*
9340 ** CAPI3REF: Obtain The Current Operation From A Changeset Iterator
9341 **
9342 ** The pIter argument passed to this function may either be an iterator
@@ -9321,11 +9360,11 @@
9360 **
9361 ** If no error occurs, SQLITE_OK is returned. If an error does occur, an
9362 ** SQLite error code is returned. The values of the output variables may not
9363 ** be trusted in this case.
9364 */
9365 SQLITE_API int sqlite3changeset_op(
9366 sqlite3_changeset_iter *pIter, /* Iterator object */
9367 const char **pzTab, /* OUT: Pointer to table name */
9368 int *pnCol, /* OUT: Number of columns in table */
9369 int *pOp, /* OUT: SQLITE_INSERT, DELETE or UPDATE */
9370 int *pbIndirect /* OUT: True for an 'indirect' change */
@@ -9354,11 +9393,11 @@
9393 ** If this function is called when the iterator does not point to a valid
9394 ** entry, SQLITE_MISUSE is returned and the output variables zeroed. Otherwise,
9395 ** SQLITE_OK is returned and the output variables populated as described
9396 ** above.
9397 */
9398 SQLITE_API int sqlite3changeset_pk(
9399 sqlite3_changeset_iter *pIter, /* Iterator object */
9400 unsigned char **pabPK, /* OUT: Array of boolean - true for PK cols */
9401 int *pnCol /* OUT: Number of entries in output array */
9402 );
9403
@@ -9384,11 +9423,11 @@
9423 ** is similar to the "old.*" columns available to update or delete triggers.
9424 **
9425 ** If some other error occurs (e.g. an OOM condition), an SQLite error code
9426 ** is returned and *ppValue is set to NULL.
9427 */
9428 SQLITE_API int sqlite3changeset_old(
9429 sqlite3_changeset_iter *pIter, /* Changeset iterator */
9430 int iVal, /* Column number */
9431 sqlite3_value **ppValue /* OUT: Old value (or NULL pointer) */
9432 );
9433
@@ -9417,11 +9456,11 @@
9456 ** triggers.
9457 **
9458 ** If some other error occurs (e.g. an OOM condition), an SQLite error code
9459 ** is returned and *ppValue is set to NULL.
9460 */
9461 SQLITE_API int sqlite3changeset_new(
9462 sqlite3_changeset_iter *pIter, /* Changeset iterator */
9463 int iVal, /* Column number */
9464 sqlite3_value **ppValue /* OUT: New value (or NULL pointer) */
9465 );
9466
@@ -9444,11 +9483,11 @@
9483 ** and returns SQLITE_OK.
9484 **
9485 ** If some other error occurs (e.g. an OOM condition), an SQLite error code
9486 ** is returned and *ppValue is set to NULL.
9487 */
9488 SQLITE_API int sqlite3changeset_conflict(
9489 sqlite3_changeset_iter *pIter, /* Changeset iterator */
9490 int iVal, /* Column number */
9491 sqlite3_value **ppValue /* OUT: Value from conflicting row */
9492 );
9493
@@ -9460,11 +9499,11 @@
9499 ** it sets the output variable to the total number of known foreign key
9500 ** violations in the destination database and returns SQLITE_OK.
9501 **
9502 ** In all other cases this function returns SQLITE_MISUSE.
9503 */
9504 SQLITE_API int sqlite3changeset_fk_conflicts(
9505 sqlite3_changeset_iter *pIter, /* Changeset iterator */
9506 int *pnOut /* OUT: Number of FK violations */
9507 );
9508
9509
@@ -9493,11 +9532,11 @@
9532 ** rc = sqlite3changeset_finalize();
9533 ** if( rc!=SQLITE_OK ){
9534 ** // An error has occurred
9535 ** }
9536 */
9537 SQLITE_API int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter);
9538
9539 /*
9540 ** CAPI3REF: Invert A Changeset
9541 **
9542 ** This function is used to "invert" a changeset object. Applying an inverted
@@ -9523,11 +9562,11 @@
9562 ** call to this function.
9563 **
9564 ** WARNING/TODO: This function currently assumes that the input is a valid
9565 ** changeset. If it is not, the results are undefined.
9566 */
9567 SQLITE_API int sqlite3changeset_invert(
9568 int nIn, const void *pIn, /* Input changeset */
9569 int *pnOut, void **ppOut /* OUT: Inverse of input */
9570 );
9571
9572 /*
@@ -9552,11 +9591,11 @@
9591 ** *pnOut = 0;
9592 ** }
9593 **
9594 ** Refer to the sqlite3_changegroup documentation below for details.
9595 */
9596 SQLITE_API int sqlite3changeset_concat(
9597 int nA, /* Number of bytes in buffer pA */
9598 void *pA, /* Pointer to buffer containing changeset A */
9599 int nB, /* Number of bytes in buffer pB */
9600 void *pB, /* Pointer to buffer containing changeset B */
9601 int *pnOut, /* OUT: Number of bytes in output changeset */
@@ -9740,11 +9779,11 @@
9779 ** considered compatible if all of the following are true:
9780 **
9781 ** <ul>
9782 ** <li> The table has the same name as the name recorded in the
9783 ** changeset, and
9784 ** <li> The table has at least as many columns as recorded in the
9785 ** changeset, and
9786 ** <li> The table has primary key columns in the same position as
9787 ** recorded in the changeset.
9788 ** </ul>
9789 **
@@ -9785,11 +9824,15 @@
9824 ** the changeset the row is deleted from the target database.
9825 **
9826 ** If a row with matching primary key values is found, but one or more of
9827 ** the non-primary key fields contains a value different from the original
9828 ** row value stored in the changeset, the conflict-handler function is
9829 ** invoked with [SQLITE_CHANGESET_DATA] as the second argument. If the
9830 ** database table has more columns than are recorded in the changeset,
9831 ** only the values of those non-primary key fields are compared against
9832 ** the current database contents - any trailing database table columns
9833 ** are ignored.
9834 **
9835 ** If no row with matching primary key values is found in the database,
9836 ** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
9837 ** passed as the second argument.
9838 **
@@ -9800,11 +9843,13 @@
9843 ** operation is attempted because an earlier call to the conflict handler
9844 ** function returned [SQLITE_CHANGESET_REPLACE].
9845 **
9846 ** <dt>INSERT Changes<dd>
9847 ** For each INSERT change, an attempt is made to insert the new row into
9848 ** the database. If the changeset row contains fewer fields than the
9849 ** database table, the trailing fields are populated with their default
9850 ** values.
9851 **
9852 ** If the attempt to insert the row fails because the database already
9853 ** contains a row with the same primary key values, the conflict handler
9854 ** function is invoked with the second argument set to
9855 ** [SQLITE_CHANGESET_CONFLICT].
@@ -9818,17 +9863,17 @@
9863 **
9864 ** <dt>UPDATE Changes<dd>
9865 ** For each UPDATE change, this function checks if the target database
9866 ** contains a row with the same primary key value (or values) as the
9867 ** original row values stored in the changeset. If it does, and the values
9868 ** stored in all modified non-primary key columns also match the values
9869 ** stored in the changeset the row is updated within the target database.
9870 **
9871 ** If a row with matching primary key values is found, but one or more of
9872 ** the modified non-primary key fields contains a value different from an
9873 ** original row value stored in the changeset, the conflict-handler function
9874 ** is invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since
9875 ** UPDATE changes only contain values for non-primary key fields that are
9876 ** to be modified, only those fields need to match the original values to
9877 ** avoid the SQLITE_CHANGESET_DATA conflict-handler callback.
9878 **
9879 ** If no row with matching primary key values is found in the database,
@@ -9852,11 +9897,11 @@
9897 ** If any other error (aside from a constraint failure when attempting to
9898 ** write to the target database) occurs, then the savepoint transaction is
9899 ** rolled back, restoring the target database to its original state, and an
9900 ** SQLite error code returned.
9901 */
9902 SQLITE_API int sqlite3changeset_apply(
9903 sqlite3 *db, /* Apply change to "main" db of this handle */
9904 int nChangeset, /* Size of changeset in bytes */
9905 void *pChangeset, /* Changeset blob */
9906 int(*xFilter)(
9907 void *pCtx, /* Copy of sixth arg to _apply() */
@@ -10053,11 +10098,11 @@
10098 **
10099 ** The sessions module never invokes an xOutput callback with the third
10100 ** parameter set to a value less than or equal to zero. Other than this,
10101 ** no guarantees are made as to the size of the chunks of data returned.
10102 */
10103 SQLITE_API int sqlite3changeset_apply_strm(
10104 sqlite3 *db, /* Apply change to "main" db of this handle */
10105 int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
10106 void *pIn, /* First arg for xInput */
10107 int(*xFilter)(
10108 void *pCtx, /* Copy of sixth arg to _apply() */
@@ -10068,35 +10113,35 @@
10113 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
10114 sqlite3_changeset_iter *p /* Handle describing change and conflict */
10115 ),
10116 void *pCtx /* First argument passed to xConflict */
10117 );
10118 SQLITE_API int sqlite3changeset_concat_strm(
10119 int (*xInputA)(void *pIn, void *pData, int *pnData),
10120 void *pInA,
10121 int (*xInputB)(void *pIn, void *pData, int *pnData),
10122 void *pInB,
10123 int (*xOutput)(void *pOut, const void *pData, int nData),
10124 void *pOut
10125 );
10126 SQLITE_API int sqlite3changeset_invert_strm(
10127 int (*xInput)(void *pIn, void *pData, int *pnData),
10128 void *pIn,
10129 int (*xOutput)(void *pOut, const void *pData, int nData),
10130 void *pOut
10131 );
10132 SQLITE_API int sqlite3changeset_start_strm(
10133 sqlite3_changeset_iter **pp,
10134 int (*xInput)(void *pIn, void *pData, int *pnData),
10135 void *pIn
10136 );
10137 SQLITE_API int sqlite3session_changeset_strm(
10138 sqlite3_session *pSession,
10139 int (*xOutput)(void *pOut, const void *pData, int nData),
10140 void *pOut
10141 );
10142 SQLITE_API int sqlite3session_patchset_strm(
10143 sqlite3_session *pSession,
10144 int (*xOutput)(void *pOut, const void *pData, int nData),
10145 void *pOut
10146 );
10147 int sqlite3changegroup_add_strm(sqlite3_changegroup*,
@@ -10999,10 +11044,11 @@
11044 # if defined(_MSC_VER) && _MSC_VER>=1400
11045 # if !defined(_WIN32_WCE)
11046 # include <intrin.h>
11047 # pragma intrinsic(_byteswap_ushort)
11048 # pragma intrinsic(_byteswap_ulong)
11049 # pragma intrinsic(_byteswap_uint64)
11050 # pragma intrinsic(_ReadWriteBarrier)
11051 # else
11052 # include <cmnintrin.h>
11053 # endif
11054 # endif
@@ -11537,10 +11583,22 @@
11583 #include <stdlib.h>
11584 #include <string.h>
11585 #include <assert.h>
11586 #include <stddef.h>
11587
11588 /*
11589 ** Use a macro to replace memcpy() if compiled with SQLITE_INLINE_MEMCPY.
11590 ** This allows better measurements of where memcpy() is used when running
11591 ** cachegrind. But this macro version of memcpy() is very slow so it
11592 ** should not be used in production. This is a performance measurement
11593 ** hack only.
11594 */
11595 #ifdef SQLITE_INLINE_MEMCPY
11596 # define memcpy(D,S,N) {char*xxd=(char*)(D);const char*xxs=(const char*)(S);\
11597 int xxn=(N);while(xxn-->0)*(xxd++)=*(xxs++);}
11598 #endif
11599
11600 /*
11601 ** If compiling for a processor that lacks floating point support,
11602 ** substitute integer for floating-point
11603 */
11604 #ifdef SQLITE_OMIT_FLOATING_POINT
@@ -11621,13 +11679,16 @@
11679 /*
11680 ** The default initial allocation for the pagecache when using separate
11681 ** pagecaches for each database connection. A positive number is the
11682 ** number of pages. A negative number N translations means that a buffer
11683 ** of -1024*N bytes is allocated and used for as many pages as it will hold.
11684 **
11685 ** The default value of "20" was choosen to minimize the run-time of the
11686 ** speedtest1 test program with options: --shrink-memory --reprepare
11687 */
11688 #ifndef SQLITE_DEFAULT_PCACHE_INITSZ
11689 # define SQLITE_DEFAULT_PCACHE_INITSZ 20
11690 #endif
11691
11692 /*
11693 ** GCC does not define the offsetof() macro so we'll have to do it
11694 ** ourselves.
@@ -11798,36 +11859,39 @@
11859 ** Macros to determine whether the machine is big or little endian,
11860 ** and whether or not that determination is run-time or compile-time.
11861 **
11862 ** For best performance, an attempt is made to guess at the byte-order
11863 ** using C-preprocessor macros. If that is unsuccessful, or if
11864 ** -DSQLITE_BYTEORDER=0 is set, then byte-order is determined
11865 ** at run-time.
11866 */
11867 #ifndef SQLITE_BYTEORDER
11868 # if defined(i386) || defined(__i386__) || defined(_M_IX86) || \
11869 defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \
11870 defined(_M_AMD64) || defined(_M_ARM) || defined(__x86) || \
11871 defined(__arm__)
11872 # define SQLITE_BYTEORDER 1234
11873 # elif defined(sparc) || defined(__ppc__)
11874 # define SQLITE_BYTEORDER 4321
11875 # else
11876 # define SQLITE_BYTEORDER 0
11877 # endif
11878 #endif
11879 #if SQLITE_BYTEORDER==4321
 
 
11880 # define SQLITE_BIGENDIAN 1
11881 # define SQLITE_LITTLEENDIAN 0
11882 # define SQLITE_UTF16NATIVE SQLITE_UTF16BE
11883 #elif SQLITE_BYTEORDER==1234
11884 # define SQLITE_BIGENDIAN 0
11885 # define SQLITE_LITTLEENDIAN 1
11886 # define SQLITE_UTF16NATIVE SQLITE_UTF16LE
11887 #else
11888 # ifdef SQLITE_AMALGAMATION
11889 const int sqlite3one = 1;
11890 # else
11891 extern const int sqlite3one;
11892 # endif
 
11893 # define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0)
11894 # define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1)
11895 # define SQLITE_UTF16NATIVE (SQLITE_BIGENDIAN?SQLITE_UTF16BE:SQLITE_UTF16LE)
11896 #endif
11897
@@ -12346,13 +12410,14 @@
12410 );
12411 SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor*);
12412 SQLITE_PRIVATE int sqlite3BtreeCursorRestore(BtCursor*, int*);
12413 SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor*, u8 flags);
12414
12415 /* Allowed flags for sqlite3BtreeDelete() and sqlite3BtreeInsert() */
12416 #define BTREE_SAVEPOSITION 0x02 /* Leave cursor pointing at NEXT or PREV */
12417 #define BTREE_AUXDELETE 0x04 /* not the primary delete operation */
12418 #define BTREE_APPEND 0x08 /* Insert is likely an append */
12419
12420 /* An instance of the BtreePayload object describes the content of a single
12421 ** entry in either an index or table btree.
12422 **
12423 ** Index btrees (used for indexes and also WITHOUT ROWID tables) contain
@@ -12379,11 +12444,11 @@
12444 int nData; /* Size of pData. 0 if none. */
12445 int nZero; /* Extra zero data appended after pData,nData */
12446 };
12447
12448 SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload,
12449 int flags, int seekResult);
12450 SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes);
12451 SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
12452 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes);
12453 SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
12454 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes);
@@ -12512,12 +12577,11 @@
12577 ** as an instance of the following structure:
12578 */
12579 struct VdbeOp {
12580 u8 opcode; /* What operation to perform */
12581 signed char p4type; /* One of the P4_xxx constants for p4 */
12582 u16 p5; /* Fifth parameter is an unsigned 16-bit integer */
 
12583 int p1; /* First operand */
12584 int p2; /* Second parameter (often the jump destination) */
12585 int p3; /* The third parameter */
12586 union p4union { /* fourth parameter */
12587 int i; /* Integer value if p4type==P4_INT32 */
@@ -12874,11 +12938,11 @@
12938 SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
12939 SQLITE_PRIVATE void sqlite3VdbeChangeOpcode(Vdbe*, u32 addr, u8);
12940 SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1);
12941 SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
12942 SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
12943 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u16 P5);
12944 SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr);
12945 SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
12946 SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
12947 SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
12948 SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
@@ -13176,18 +13240,20 @@
13240 SQLITE_PRIVATE int sqlite3PagerCheckpoint(Pager *pPager, sqlite3*, int, int*, int*);
13241 SQLITE_PRIVATE int sqlite3PagerWalSupported(Pager *pPager);
13242 SQLITE_PRIVATE int sqlite3PagerWalCallback(Pager *pPager);
13243 SQLITE_PRIVATE int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen);
13244 SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager, sqlite3*);
13245 # ifdef SQLITE_DIRECT_OVERFLOW_READ
13246 SQLITE_PRIVATE int sqlite3PagerUseWal(Pager *pPager, Pgno);
13247 # endif
13248 # ifdef SQLITE_ENABLE_SNAPSHOT
13249 SQLITE_PRIVATE int sqlite3PagerSnapshotGet(Pager *pPager, sqlite3_snapshot **ppSnapshot);
13250 SQLITE_PRIVATE int sqlite3PagerSnapshotOpen(Pager *pPager, sqlite3_snapshot *pSnapshot);
13251 SQLITE_PRIVATE int sqlite3PagerSnapshotRecover(Pager *pPager);
13252 # endif
13253 #else
13254 # define sqlite3PagerUseWal(x,y) 0
13255 #endif
13256
13257 #ifdef SQLITE_ENABLE_ZIPVFS
13258 SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager);
13259 #endif
@@ -14007,10 +14073,11 @@
14073 signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */
14074 u8 suppressErr; /* Do not issue error messages if true */
14075 u8 vtabOnConflict; /* Value to return for s3_vtab_on_conflict() */
14076 u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */
14077 u8 mTrace; /* zero or more SQLITE_TRACE flags */
14078 u8 skipBtreeMutex; /* True if no shared-cache backends */
14079 int nextPagesize; /* Pagesize after VACUUM if >0 */
14080 u32 magic; /* Magic number for detect library misuse */
14081 int nChange; /* Value returned by sqlite3_changes() */
14082 int nTotalChange; /* Value returned by sqlite3_total_changes() */
14083 int aLimit[SQLITE_N_LIMIT]; /* Limits */
@@ -14272,10 +14339,11 @@
14339 #define SQLITE_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */
14340 #define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */
14341 #define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */
14342 #define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a
14343 ** single query - might change over time */
14344 #define SQLITE_FUNC_AFFINITY 0x4000 /* Built-in affinity() function */
14345
14346 /*
14347 ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
14348 ** used to create the initializers for the FuncDef structures.
14349 **
@@ -15278,11 +15346,11 @@
15346 #define WHERE_DISTINCTBY 0x0080 /* pOrderby is really a DISTINCT clause */
15347 #define WHERE_WANT_DISTINCT 0x0100 /* All output needs to be distinct */
15348 #define WHERE_SORTBYGROUP 0x0200 /* Support sqlite3WhereIsSorted() */
15349 #define WHERE_SEEK_TABLE 0x0400 /* Do not defer seeks on main table */
15350 #define WHERE_ORDERBY_LIMIT 0x0800 /* ORDERBY+LIMIT on the inner loop */
15351 #define WHERE_SEEK_UNIQ_TABLE 0x1000 /* Do not defer seeks if unique */
15352 /* 0x2000 not currently used */
15353 #define WHERE_USE_LIMIT 0x4000 /* Use the LIMIT in cost estimates */
15354 /* 0x8000 not currently used */
15355
15356 /* Allowed return values from sqlite3WhereIsDistinct()
@@ -15739,25 +15807,23 @@
15807 ** OPFLAG_AUXDELETE == BTREE_AUXDELETE
15808 */
15809 #define OPFLAG_NCHANGE 0x01 /* OP_Insert: Set to update db->nChange */
15810 /* Also used in P2 (not P5) of OP_Delete */
15811 #define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */
15812 #define OPFLAG_LASTROWID 0x20 /* Set to update db->lastRowid */
15813 #define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */
15814 #define OPFLAG_APPEND 0x08 /* This is likely to be an append */
15815 #define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */
 
15816 #define OPFLAG_ISNOOP 0x40 /* OP_Delete does pre-update-hook only */
 
15817 #define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */
15818 #define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */
15819 #define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */
15820 #define OPFLAG_SEEKEQ 0x02 /* OP_Open** cursor uses EQ seek only */
15821 #define OPFLAG_FORDELETE 0x08 /* OP_Open should use BTREE_FORDELETE */
15822 #define OPFLAG_P2ISREG 0x10 /* P2 to OP_Open** is a register number */
15823 #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */
15824 #define OPFLAG_SAVEPOSITION 0x02 /* OP_Delete/Insert: save cursor pos */
15825 #define OPFLAG_AUXDELETE 0x04 /* OP_Delete: index in a DELETE op */
15826
15827 /*
15828 * Each trigger present in the database schema is stored as an instance of
15829 * struct Trigger.
@@ -16414,11 +16480,11 @@
16480 SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*);
16481 SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
16482 SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int);
16483 SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, Expr*, int);
16484 SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
16485 SQLITE_PRIVATE int sqlite3ExprCodeAtInit(Parse*, Expr*, int);
16486 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
16487 SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
16488 SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*, int);
16489 SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int, u8);
16490 #define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */
@@ -16476,10 +16542,15 @@
16542 SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*, int);
16543 SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,Index*,int);
16544 SQLITE_PRIVATE void sqlite3ResolvePartIdxLabel(Parse*,int);
16545 SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int,
16546 u8,u8,int,int*,int*);
16547 #ifdef SQLITE_ENABLE_NULL_TRIM
16548 SQLITE_PRIVATE void sqlite3SetMakeRecordP5(Vdbe*,Table*);
16549 #else
16550 # define sqlite3SetMakeRecordP5(A,B)
16551 #endif
16552 SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int);
16553 SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, u8, int, u8*, int*, int*);
16554 SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse*, int, int);
16555 SQLITE_PRIVATE void sqlite3MultiWrite(Parse*);
16556 SQLITE_PRIVATE void sqlite3MayAbort(Parse*);
@@ -16754,12 +16825,14 @@
16825 #endif
16826
16827 /*
16828 ** The interface to the LEMON-generated parser
16829 */
16830 #ifndef SQLITE_AMALGAMATION
16831 SQLITE_PRIVATE void *sqlite3ParserAlloc(void*(*)(u64));
16832 SQLITE_PRIVATE void sqlite3ParserFree(void*, void(*)(void*));
16833 #endif
16834 SQLITE_PRIVATE void sqlite3Parser(void*, int, Token, Parse*);
16835 #ifdef YYTRACKMAXSTACKDEPTH
16836 SQLITE_PRIVATE int sqlite3ParserStackPeak(void*);
16837 #endif
16838
@@ -16865,10 +16938,11 @@
16938 #define sqlite3FkActions(a,b,c,d,e,f)
16939 #define sqlite3FkCheck(a,b,c,d,e,f)
16940 #define sqlite3FkDropTable(a,b,c)
16941 #define sqlite3FkOldmask(a,b) 0
16942 #define sqlite3FkRequired(a,b,c,d) 0
16943 #define sqlite3FkReferences(a) 0
16944 #endif
16945 #ifndef SQLITE_OMIT_FOREIGN_KEY
16946 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *, Table*);
16947 SQLITE_PRIVATE int sqlite3FkLocateIndex(Parse*,Table*,FKey*,Index**,int**);
16948 #else
@@ -17193,10 +17267,23 @@
17267 ** setting.)
17268 */
17269 #ifndef SQLITE_STMTJRNL_SPILL
17270 # define SQLITE_STMTJRNL_SPILL (64*1024)
17271 #endif
17272
17273 /*
17274 ** The default lookaside-configuration, the format "SZ,N". SZ is the
17275 ** number of bytes in each lookaside slot (should be a multiple of 8)
17276 ** and N is the number of slots. The lookaside-configuration can be
17277 ** changed as start-time using sqlite3_config(SQLITE_CONFIG_LOOKASIDE)
17278 ** or at run-time for an individual database connection using
17279 ** sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE);
17280 */
17281 #ifndef SQLITE_DEFAULT_LOOKASIDE
17282 # define SQLITE_DEFAULT_LOOKASIDE 1200,100
17283 #endif
17284
17285
17286 /*
17287 ** The following singleton contains the global configuration for
17288 ** the SQLite library.
17289 */
@@ -17206,12 +17293,11 @@
17293 SQLITE_THREADSAFE==1, /* bFullMutex */
17294 SQLITE_USE_URI, /* bOpenUri */
17295 SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */
17296 0x7ffffffe, /* mxStrlen */
17297 0, /* neverCorrupt */
17298 SQLITE_DEFAULT_LOOKASIDE, /* szLookaside, nLookaside */
 
17299 SQLITE_STMTJRNL_SPILL, /* nStmtSpill */
17300 {0,0,0,0,0,0,0,0}, /* m */
17301 {0,0,0,0,0,0,0,0,0}, /* mutex */
17302 {0,0,0,0,0,0,0,0,0,0,0,0,0},/* pcache2 */
17303 (void*)0, /* pHeap */
@@ -18219,10 +18305,11 @@
18305 int iNewReg; /* Register for new.* values */
18306 i64 iKey1; /* First key value passed to hook */
18307 i64 iKey2; /* Second key value passed to hook */
18308 Mem *aNew; /* Array of new.* values */
18309 Table *pTab; /* Schema object being upated */
18310 Index *pPk; /* PK index if pTab is WITHOUT ROWID */
18311 };
18312
18313 /*
18314 ** Function prototypes
18315 */
@@ -20619,20 +20706,22 @@
20706 ** cases of nByte<=0 will be intercepted and dealt with by higher level
20707 ** routines.
20708 */
20709 static void *sqlite3MemMalloc(int nByte){
20710 #ifdef SQLITE_MALLOCSIZE
20711 void *p;
20712 testcase( ROUND8(nByte)==nByte );
20713 p = SQLITE_MALLOC( nByte );
20714 if( p==0 ){
20715 testcase( sqlite3GlobalConfig.xLog!=0 );
20716 sqlite3_log(SQLITE_NOMEM, "failed to allocate %u bytes of memory", nByte);
20717 }
20718 return p;
20719 #else
20720 sqlite3_int64 *p;
20721 assert( nByte>0 );
20722 testcase( ROUND8(nByte)!=nByte );
20723 p = SQLITE_MALLOC( nByte+8 );
20724 if( p ){
20725 p[0] = nByte;
20726 p++;
20727 }else{
@@ -23750,12 +23839,11 @@
23839 SQLITE_PRIVATE void sqlite3MemoryBarrier(void){
23840 #if defined(SQLITE_MEMORY_BARRIER)
23841 SQLITE_MEMORY_BARRIER;
23842 #elif defined(__GNUC__)
23843 __sync_synchronize();
23844 #elif MSVC_VERSION>=1300
 
23845 _ReadWriteBarrier();
23846 #elif defined(MemoryBarrier)
23847 MemoryBarrier();
23848 #endif
23849 }
@@ -24283,15 +24371,23 @@
24371
24372 /*
24373 ** Do a memory allocation with statistics and alarms. Assume the
24374 ** lock is already held.
24375 */
24376 static void mallocWithAlarm(int n, void **pp){
 
24377 void *p;
24378 int nFull;
24379 assert( sqlite3_mutex_held(mem0.mutex) );
24380 assert( n>0 );
24381
24382 /* In Firefox (circa 2017-02-08), xRoundup() is remapped to an internal
24383 ** implementation of malloc_good_size(), which must be called in debug
24384 ** mode and specifically when the DMD "Dark Matter Detector" is enabled
24385 ** or else a crash results. Hence, do not attempt to optimize out the
24386 ** following xRoundup() call. */
24387 nFull = sqlite3GlobalConfig.m.xRoundup(n);
24388
24389 sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, n);
24390 if( mem0.alarmThreshold>0 ){
24391 sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
24392 if( nUsed >= mem0.alarmThreshold - nFull ){
24393 mem0.nearlyFull = 1;
@@ -24311,11 +24407,10 @@
24407 nFull = sqlite3MallocSize(p);
24408 sqlite3StatusUp(SQLITE_STATUS_MEMORY_USED, nFull);
24409 sqlite3StatusUp(SQLITE_STATUS_MALLOC_COUNT, 1);
24410 }
24411 *pp = p;
 
24412 }
24413
24414 /*
24415 ** Allocate memory. This routine is like sqlite3_malloc() except that it
24416 ** assumes the memory subsystem has already been initialized.
@@ -24951,11 +25046,10 @@
25046
25047 /*
25048 ** Allowed values for et_info.flags
25049 */
25050 #define FLAG_SIGNED 1 /* True if the value to convert is signed */
 
25051 #define FLAG_STRING 4 /* Allow infinity precision */
25052
25053
25054 /*
25055 ** The following table is searched linearly, so it is good to put the
@@ -24985,15 +25079,14 @@
25079 { 'i', 10, 1, etRADIX, 0, 0 },
25080 { 'n', 0, 0, etSIZE, 0, 0 },
25081 { '%', 0, 0, etPERCENT, 0, 0 },
25082 { 'p', 16, 0, etPOINTER, 0, 1 },
25083
25084 /* All the rest are undocumented and are for internal use only */
25085 { 'T', 0, 0, etTOKEN, 0, 0 },
25086 { 'S', 0, 0, etSRCLIST, 0, 0 },
25087 { 'r', 10, 1, etORDINAL, 0, 0 },
 
25088 };
25089
25090 /*
25091 ** If SQLITE_OMIT_FLOATING_POINT is defined, then none of the floating point
25092 ** conversions will work.
@@ -25083,11 +25176,10 @@
25176 etByte flag_long; /* True if "l" flag is present */
25177 etByte flag_longlong; /* True if the "ll" flag is present */
25178 etByte done; /* Loop termination flag */
25179 etByte xtype = etINVALID; /* Conversion paradigm */
25180 u8 bArgList; /* True for SQLITE_PRINTF_SQLFUNC */
 
25181 char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
25182 sqlite_uint64 longvalue; /* Value for integer types */
25183 LONGDOUBLE_TYPE realvalue; /* Value for real types */
25184 const et_info *infop; /* Pointer to the appropriate info structure */
25185 char *zOut; /* Rendering buffer */
@@ -25102,17 +25194,15 @@
25194 #endif
25195 PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */
25196 char buf[etBUFSIZE]; /* Conversion buffer */
25197
25198 bufpt = 0;
25199 if( (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC)!=0 ){
25200 pArgList = va_arg(ap, PrintfArguments*);
25201 bArgList = 1;
 
 
25202 }else{
25203 bArgList = 0;
25204 }
25205 for(; (c=(*fmt))!=0; ++fmt){
25206 if( c!='%' ){
25207 bufpt = (char *)fmt;
25208 #if HAVE_STRCHRNUL
@@ -25220,15 +25310,11 @@
25310 infop = &fmtinfo[0];
25311 xtype = etINVALID;
25312 for(idx=0; idx<ArraySize(fmtinfo); idx++){
25313 if( c==fmtinfo[idx].fmttype ){
25314 infop = &fmtinfo[idx];
25315 xtype = infop->type;
 
 
 
 
25316 break;
25317 }
25318 }
25319
25320 /*
@@ -25593,22 +25679,28 @@
25679 ** consume, not the length of the output...
25680 ** if( precision>=0 && precision<length ) length = precision; */
25681 break;
25682 }
25683 case etTOKEN: {
25684 Token *pToken;
25685 if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
25686 pToken = va_arg(ap, Token*);
25687 assert( bArgList==0 );
25688 if( pToken && pToken->n ){
25689 sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n);
25690 }
25691 length = width = 0;
25692 break;
25693 }
25694 case etSRCLIST: {
25695 SrcList *pSrc;
25696 int k;
25697 struct SrcList_item *pItem;
25698 if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
25699 pSrc = va_arg(ap, SrcList*);
25700 k = va_arg(ap, int);
25701 pItem = &pSrc->a[k];
25702 assert( bArgList==0 );
25703 assert( k>=0 && k<pSrc->nSrc );
25704 if( pItem->zDatabase ){
25705 sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase);
25706 sqlite3StrAccumAppend(pAccum, ".", 1);
@@ -25626,13 +25718,17 @@
25718 ** The text of the conversion is pointed to by "bufpt" and is
25719 ** "length" characters long. The field width is "width". Do
25720 ** the output.
25721 */
25722 width -= length;
25723 if( width>0 ){
25724 if( !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
25725 sqlite3StrAccumAppend(pAccum, bufpt, length);
25726 if( flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
25727 }else{
25728 sqlite3StrAccumAppend(pAccum, bufpt, length);
25729 }
25730
25731 if( zExtra ){
25732 sqlite3DbFree(pAccum->db, zExtra);
25733 zExtra = 0;
25734 }
@@ -28600,17 +28696,15 @@
28696 SQLITE_PRIVATE u32 sqlite3Get4byte(const u8 *p){
28697 #if SQLITE_BYTEORDER==4321
28698 u32 x;
28699 memcpy(&x,p,4);
28700 return x;
28701 #elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
 
28702 u32 x;
28703 memcpy(&x,p,4);
28704 return __builtin_bswap32(x);
28705 #elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
 
28706 u32 x;
28707 memcpy(&x,p,4);
28708 return _byteswap_ulong(x);
28709 #else
28710 testcase( p[0]&0x80 );
@@ -28618,16 +28712,14 @@
28712 #endif
28713 }
28714 SQLITE_PRIVATE void sqlite3Put4byte(unsigned char *p, u32 v){
28715 #if SQLITE_BYTEORDER==4321
28716 memcpy(p,&v,4);
28717 #elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
 
28718 u32 x = __builtin_bswap32(v);
28719 memcpy(p,&x,4);
28720 #elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
 
28721 u32 x = _byteswap_ulong(v);
28722 memcpy(p,&x,4);
28723 #else
28724 p[0] = (u8)(v>>24);
28725 p[1] = (u8)(v>>16);
@@ -28739,10 +28831,13 @@
28831 ** the other 64-bit signed integer at *pA and store the result in *pA.
28832 ** Return 0 on success. Or if the operation would have resulted in an
28833 ** overflow, leave *pA unchanged and return 1.
28834 */
28835 SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){
28836 #if GCC_VERSION>=5004000
28837 return __builtin_add_overflow(*pA, iB, pA);
28838 #else
28839 i64 iA = *pA;
28840 testcase( iA==0 ); testcase( iA==1 );
28841 testcase( iB==-1 ); testcase( iB==0 );
28842 if( iB>=0 ){
28843 testcase( iA>0 && LARGEST_INT64 - iA == iB );
@@ -28753,23 +28848,31 @@
28848 testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 2 );
28849 if( iA<0 && -(iA + LARGEST_INT64) > iB + 1 ) return 1;
28850 }
28851 *pA += iB;
28852 return 0;
28853 #endif
28854 }
28855 SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){
28856 #if GCC_VERSION>=5004000
28857 return __builtin_sub_overflow(*pA, iB, pA);
28858 #else
28859 testcase( iB==SMALLEST_INT64+1 );
28860 if( iB==SMALLEST_INT64 ){
28861 testcase( (*pA)==(-1) ); testcase( (*pA)==0 );
28862 if( (*pA)>=0 ) return 1;
28863 *pA -= iB;
28864 return 0;
28865 }else{
28866 return sqlite3AddInt64(pA, -iB);
28867 }
28868 #endif
28869 }
28870 SQLITE_PRIVATE int sqlite3MulInt64(i64 *pA, i64 iB){
28871 #if GCC_VERSION>=5004000
28872 return __builtin_mul_overflow(*pA, iB, pA);
28873 #else
28874 i64 iA = *pA;
28875 if( iB>0 ){
28876 if( iA>LARGEST_INT64/iB ) return 1;
28877 if( iA<SMALLEST_INT64/iB ) return 1;
28878 }else if( iB<0 ){
@@ -28781,10 +28884,11 @@
28884 if( -iA>LARGEST_INT64/-iB ) return 1;
28885 }
28886 }
28887 *pA = iA*iB;
28888 return 0;
28889 #endif
28890 }
28891
28892 /*
28893 ** Compute the absolute value of a 32-bit signed integer, of possible. Or
28894 ** if the integer has a value of -2147483648, return +2147483647
@@ -47485,18 +47589,24 @@
47589 ** if( pPager->jfd->pMethods ){ ...
47590 */
47591 #define isOpen(pFd) ((pFd)->pMethods!=0)
47592
47593 /*
47594 ** Return true if this pager uses a write-ahead log to read page pgno.
47595 ** Return false if the pager reads pgno directly from the database.
47596 */
47597 #if !defined(SQLITE_OMIT_WAL) && defined(SQLITE_DIRECT_OVERFLOW_READ)
47598 SQLITE_PRIVATE int sqlite3PagerUseWal(Pager *pPager, Pgno pgno){
47599 u32 iRead = 0;
47600 int rc;
47601 if( pPager->pWal==0 ) return 0;
47602 rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iRead);
47603 return rc || iRead;
47604 }
47605 #endif
47606 #ifndef SQLITE_OMIT_WAL
47607 # define pagerUseWal(x) ((x)->pWal!=0)
 
 
 
47608 #else
47609 # define pagerUseWal(x) 0
47610 # define pagerRollbackWal(x) 0
47611 # define pagerWalFrames(v,w,x,y) 0
47612 # define pagerOpenWalIfPresent(z) SQLITE_OK
@@ -58445,15 +58555,13 @@
58555 ** two-byte aligned address. get2bytea() is only used for accessing the
58556 ** cell addresses in a btree header.
58557 */
58558 #if SQLITE_BYTEORDER==4321
58559 # define get2byteAligned(x) (*(u16*)(x))
58560 #elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4008000
 
58561 # define get2byteAligned(x) __builtin_bswap16(*(u16*)(x))
58562 #elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
 
58563 # define get2byteAligned(x) _byteswap_ushort(*(u16*)(x))
58564 #else
58565 # define get2byteAligned(x) ((x)[0]<<8 | (x)[1])
58566 #endif
58567
@@ -58624,27 +58732,38 @@
58732 ** Enter the mutexes in accending order by BtShared pointer address
58733 ** to avoid the possibility of deadlock when two threads with
58734 ** two or more btrees in common both try to lock all their btrees
58735 ** at the same instant.
58736 */
58737 static void SQLITE_NOINLINE btreeEnterAll(sqlite3 *db){
58738 int i;
58739 int skipOk = 1;
58740 Btree *p;
58741 assert( sqlite3_mutex_held(db->mutex) );
58742 for(i=0; i<db->nDb; i++){
58743 p = db->aDb[i].pBt;
58744 if( p && p->sharable ){
58745 sqlite3BtreeEnter(p);
58746 skipOk = 0;
58747 }
58748 }
58749 db->skipBtreeMutex = skipOk;
58750 }
58751 SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){
58752 if( db->skipBtreeMutex==0 ) btreeEnterAll(db);
58753 }
58754 static void SQLITE_NOINLINE btreeLeaveAll(sqlite3 *db){
58755 int i;
58756 Btree *p;
58757 assert( sqlite3_mutex_held(db->mutex) );
58758 for(i=0; i<db->nDb; i++){
58759 p = db->aDb[i].pBt;
58760 if( p ) sqlite3BtreeLeave(p);
58761 }
58762 }
58763 SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3 *db){
58764 if( db->skipBtreeMutex==0 ) btreeLeaveAll(db);
58765 }
58766
58767 #ifndef NDEBUG
58768 /*
58769 ** Return true if the current thread holds the database connection
@@ -62097,16 +62216,18 @@
62216 for(i=0; i<nCell; i++){
62217 u8 *pCell = findCell(pPage, i);
62218 if( eType==PTRMAP_OVERFLOW1 ){
62219 CellInfo info;
62220 pPage->xParseCell(pPage, pCell, &info);
62221 if( info.nLocal<info.nPayload ){
62222 if( pCell+info.nSize > pPage->aData+pPage->pBt->usableSize ){
62223 return SQLITE_CORRUPT_BKPT;
62224 }
62225 if( iFrom==get4byte(pCell+info.nSize-4) ){
62226 put4byte(pCell+info.nSize-4, iTo);
62227 break;
62228 }
62229 }
62230 }else{
62231 if( get4byte(pCell)==iFrom ){
62232 put4byte(pCell, iTo);
62233 break;
@@ -62777,11 +62898,16 @@
62898 if( p && p->inTrans==TRANS_WRITE ){
62899 BtShared *pBt = p->pBt;
62900 assert( op==SAVEPOINT_RELEASE || op==SAVEPOINT_ROLLBACK );
62901 assert( iSavepoint>=0 || (iSavepoint==-1 && op==SAVEPOINT_ROLLBACK) );
62902 sqlite3BtreeEnter(p);
62903 if( op==SAVEPOINT_ROLLBACK ){
62904 rc = saveAllCursors(pBt, 0, 0);
62905 }
62906 if( rc==SQLITE_OK ){
62907 rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint);
62908 }
62909 if( rc==SQLITE_OK ){
62910 if( iSavepoint<0 && (pBt->btsFlags & BTS_INITIALLY_EMPTY)!=0 ){
62911 pBt->nPage = 0;
62912 }
62913 rc = newDatabase(pBt);
@@ -63163,25 +63289,24 @@
63289 ** for the entry that the pCur cursor is pointing to. The eOp
63290 ** argument is interpreted as follows:
63291 **
63292 ** 0: The operation is a read. Populate the overflow cache.
63293 ** 1: The operation is a write. Populate the overflow cache.
 
63294 **
63295 ** A total of "amt" bytes are read or written beginning at "offset".
63296 ** Data is read to or from the buffer pBuf.
63297 **
63298 ** The content being read or written might appear on the main page
63299 ** or be scattered out on multiple overflow pages.
63300 **
63301 ** If the current cursor entry uses one or more overflow pages
63302 ** this function may allocate space for and lazily populate
63303 ** the overflow page-list cache array (BtCursor.aOverflow).
63304 ** Subsequent calls use this cache to make seeking to the supplied offset
63305 ** more efficient.
63306 **
63307 ** Once an overflow page-list cache has been allocated, it must be
63308 ** invalidated if some other cursor writes to the same table, or if
63309 ** the cursor is moved to a different row. Additionally, in auto-vacuum
63310 ** mode, the following events may invalidate an overflow page-list cache.
63311 **
63312 ** * An incremental vacuum,
@@ -63199,25 +63324,21 @@
63324 int rc = SQLITE_OK;
63325 int iIdx = 0;
63326 MemPage *pPage = pCur->apPage[pCur->iPage]; /* Btree page of current entry */
63327 BtShared *pBt = pCur->pBt; /* Btree this cursor belongs to */
63328 #ifdef SQLITE_DIRECT_OVERFLOW_READ
63329 unsigned char * const pBufStart = pBuf; /* Start of original out buffer */
 
63330 #endif
63331
63332 assert( pPage );
63333 assert( eOp==0 || eOp==1 );
63334 assert( pCur->eState==CURSOR_VALID );
63335 assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
63336 assert( cursorHoldsMutex(pCur) );
 
63337
63338 getCellInfo(pCur);
63339 aPayload = pCur->info.pPayload;
 
 
 
63340 assert( offset+amt <= pCur->info.nPayload );
63341
63342 assert( aPayload > pPage->aData );
63343 if( (uptr)(aPayload - pPage->aData) > (pBt->usableSize - pCur->info.nLocal) ){
63344 /* Trying to read or write past the end of the data is an error. The
@@ -63232,11 +63353,11 @@
63353 if( offset<pCur->info.nLocal ){
63354 int a = amt;
63355 if( a+offset>pCur->info.nLocal ){
63356 a = pCur->info.nLocal - offset;
63357 }
63358 rc = copyPayload(&aPayload[offset], pBuf, a, eOp, pPage->pDbPage);
63359 offset = 0;
63360 pBuf += a;
63361 amt -= a;
63362 }else{
63363 offset -= pCur->info.nLocal;
@@ -63248,69 +63369,58 @@
63369 Pgno nextPage;
63370
63371 nextPage = get4byte(&aPayload[pCur->info.nLocal]);
63372
63373 /* If the BtCursor.aOverflow[] has not been allocated, allocate it now.
 
63374 **
63375 ** The aOverflow[] array is sized at one entry for each overflow page
63376 ** in the overflow chain. The page number of the first overflow page is
63377 ** stored in aOverflow[0], etc. A value of 0 in the aOverflow[] array
63378 ** means "not yet known" (the cache is lazily populated).
63379 */
63380 if( (pCur->curFlags & BTCF_ValidOvfl)==0 ){
63381 int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize;
63382 if( nOvfl>pCur->nOvflAlloc ){
63383 Pgno *aNew = (Pgno*)sqlite3Realloc(
63384 pCur->aOverflow, nOvfl*2*sizeof(Pgno)
63385 );
63386 if( aNew==0 ){
63387 return SQLITE_NOMEM_BKPT;
63388 }else{
63389 pCur->nOvflAlloc = nOvfl*2;
63390 pCur->aOverflow = aNew;
63391 }
63392 }
63393 memset(pCur->aOverflow, 0, nOvfl*sizeof(Pgno));
63394 pCur->curFlags |= BTCF_ValidOvfl;
63395 }else{
63396 /* If the overflow page-list cache has been allocated and the
63397 ** entry for the first required overflow page is valid, skip
63398 ** directly to it.
63399 */
63400 if( pCur->aOverflow[offset/ovflSize] ){
63401 iIdx = (offset/ovflSize);
63402 nextPage = pCur->aOverflow[iIdx];
63403 offset = (offset%ovflSize);
63404 }
63405 }
63406
63407 assert( rc==SQLITE_OK && amt>0 );
63408 while( nextPage ){
 
 
 
 
 
 
 
 
 
 
 
 
63409 /* If required, populate the overflow page-list cache. */
63410 assert( pCur->aOverflow[iIdx]==0
63411 || pCur->aOverflow[iIdx]==nextPage
63412 || CORRUPT_DB );
63413 pCur->aOverflow[iIdx] = nextPage;
 
 
63414
63415 if( offset>=ovflSize ){
63416 /* The only reason to read this page is to obtain the page
63417 ** number for the next page in the overflow chain. The page
63418 ** data is not required. So first try to lookup the overflow
63419 ** page-list cache, if any, then fall back to the getOverflowPage()
63420 ** function.
 
 
 
63421 */
 
63422 assert( pCur->curFlags & BTCF_ValidOvfl );
63423 assert( pCur->pBtree->db==pBt->db );
63424 if( pCur->aOverflow[iIdx+1] ){
63425 nextPage = pCur->aOverflow[iIdx+1];
63426 }else{
@@ -63320,11 +63430,11 @@
63430 }else{
63431 /* Need to read this page properly. It contains some of the
63432 ** range of data that is being read (eOp==0) or written (eOp!=0).
63433 */
63434 #ifdef SQLITE_DIRECT_OVERFLOW_READ
63435 sqlite3_file *fd; /* File from which to do direct overflow read */
63436 #endif
63437 int a = amt;
63438 if( a + offset > ovflSize ){
63439 a = ovflSize - offset;
63440 }
@@ -63332,31 +63442,29 @@
63442 #ifdef SQLITE_DIRECT_OVERFLOW_READ
63443 /* If all the following are true:
63444 **
63445 ** 1) this is a read operation, and
63446 ** 2) data is required from the start of this overflow page, and
63447 ** 3) there is no open write-transaction, and
63448 ** 4) the database is file-backed, and
63449 ** 5) the page is not in the WAL file
63450 ** 6) at least 4 bytes have already been read into the output buffer
 
63451 **
63452 ** then data can be read directly from the database file into the
63453 ** output buffer, bypassing the page-cache altogether. This speeds
63454 ** up loading large records that span many overflow pages.
63455 */
63456 if( eOp==0 /* (1) */
63457 && offset==0 /* (2) */
63458 && pBt->inTransaction==TRANS_READ /* (3) */
63459 && (fd = sqlite3PagerFile(pBt->pPager))->pMethods /* (4) */
63460 && 0==sqlite3PagerUseWal(pBt->pPager, nextPage) /* (5) */
63461 && &pBuf[-4]>=pBufStart /* (6) */
 
63462 ){
63463 u8 aSave[4];
63464 u8 *aWrite = &pBuf[-4];
63465 assert( aWrite>=pBufStart ); /* due to (6) */
63466 memcpy(aSave, aWrite, 4);
63467 rc = sqlite3OsRead(fd, aWrite, a+4, (i64)pBt->pageSize*(nextPage-1));
63468 nextPage = get4byte(aWrite);
63469 memcpy(aWrite, aSave, 4);
63470 }else
@@ -63363,28 +63471,31 @@
63471 #endif
63472
63473 {
63474 DbPage *pDbPage;
63475 rc = sqlite3PagerGet(pBt->pPager, nextPage, &pDbPage,
63476 (eOp==0 ? PAGER_GET_READONLY : 0)
63477 );
63478 if( rc==SQLITE_OK ){
63479 aPayload = sqlite3PagerGetData(pDbPage);
63480 nextPage = get4byte(aPayload);
63481 rc = copyPayload(&aPayload[offset+4], pBuf, a, eOp, pDbPage);
63482 sqlite3PagerUnref(pDbPage);
63483 offset = 0;
63484 }
63485 }
63486 amt -= a;
63487 if( amt==0 ) return rc;
63488 pBuf += a;
63489 }
63490 if( rc ) break;
63491 iIdx++;
63492 }
63493 }
63494
63495 if( rc==SQLITE_OK && amt>0 ){
63496 return SQLITE_CORRUPT_BKPT; /* Overflow chain ends prematurely */
63497 }
63498 return rc;
63499 }
63500
63501 /*
@@ -63409,25 +63520,38 @@
63520 assert( pCur->eState==CURSOR_VALID );
63521 assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
63522 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
63523 return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
63524 }
63525
63526 /*
63527 ** This variant of sqlite3BtreePayload() works even if the cursor has not
63528 ** in the CURSOR_VALID state. It is only used by the sqlite3_blob_read()
63529 ** interface.
63530 */
63531 #ifndef SQLITE_OMIT_INCRBLOB
63532 static SQLITE_NOINLINE int accessPayloadChecked(
63533 BtCursor *pCur,
63534 u32 offset,
63535 u32 amt,
63536 void *pBuf
63537 ){
63538 int rc;
63539 if ( pCur->eState==CURSOR_INVALID ){
63540 return SQLITE_ABORT;
63541 }
63542 assert( cursorOwnsBtShared(pCur) );
63543 rc = btreeRestoreCursorPosition(pCur);
63544 return rc ? rc : accessPayload(pCur, offset, amt, pBuf, 0);
63545 }
63546 SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
63547 if( pCur->eState==CURSOR_VALID ){
63548 assert( cursorOwnsBtShared(pCur) );
63549 return accessPayload(pCur, offset, amt, pBuf, 0);
63550 }else{
63551 return accessPayloadChecked(pCur, offset, amt, pBuf);
63552 }
63553 }
63554 #endif /* SQLITE_OMIT_INCRBLOB */
63555
63556 /*
63557 ** Return a pointer to payload information from the entry that the
@@ -63829,13 +63953,30 @@
63953 ){
63954 if( pCur->info.nKey==intKey ){
63955 *pRes = 0;
63956 return SQLITE_OK;
63957 }
63958 if( pCur->info.nKey<intKey ){
63959 if( (pCur->curFlags & BTCF_AtLast)!=0 ){
63960 *pRes = -1;
63961 return SQLITE_OK;
63962 }
63963 /* If the requested key is one more than the previous key, then
63964 ** try to get there using sqlite3BtreeNext() rather than a full
63965 ** binary search. This is an optimization only. The correct answer
63966 ** is still obtained without this ase, only a little more slowely */
63967 if( pCur->info.nKey+1==intKey && !pCur->skipNext ){
63968 *pRes = 0;
63969 rc = sqlite3BtreeNext(pCur, pRes);
63970 if( rc ) return rc;
63971 if( *pRes==0 ){
63972 getCellInfo(pCur);
63973 if( pCur->info.nKey==intKey ){
63974 return SQLITE_OK;
63975 }
63976 }
63977 }
63978 }
63979 }
63980
63981 if( pIdxKey ){
63982 xRecordCompare = sqlite3VdbeFindCompare(pIdxKey);
@@ -63967,11 +64108,12 @@
64108 if( pCellKey==0 ){
64109 rc = SQLITE_NOMEM_BKPT;
64110 goto moveto_finish;
64111 }
64112 pCur->aiIdx[pCur->iPage] = (u16)idx;
64113 rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
64114 pCur->curFlags &= ~BTCF_ValidOvfl;
64115 if( rc ){
64116 sqlite3_free(pCellKey);
64117 goto moveto_finish;
64118 }
64119 c = xRecordCompare(nCell, pCellKey, pIdxKey);
@@ -66010,11 +66152,10 @@
66152 */
66153 usableSpace = pBt->usableSize - 12 + leafCorrection;
66154 for(i=0; i<nOld; i++){
66155 MemPage *p = apOld[i];
66156 szNew[i] = usableSpace - p->nFree;
 
66157 for(j=0; j<p->nOverflow; j++){
66158 szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]);
66159 }
66160 cntNew[i] = cntOld[i];
66161 }
@@ -66689,11 +66830,11 @@
66830 ** to decode the key.
66831 */
66832 SQLITE_PRIVATE int sqlite3BtreeInsert(
66833 BtCursor *pCur, /* Insert data into the table of this cursor */
66834 const BtreePayload *pX, /* Content of the row to be inserted */
66835 int flags, /* True if this is likely an append */
66836 int seekResult /* Result of prior MovetoUnpacked() call */
66837 ){
66838 int rc;
66839 int loc = seekResult; /* -1: before desired location +1: after */
66840 int szNew = 0;
@@ -66701,10 +66842,12 @@
66842 MemPage *pPage;
66843 Btree *p = pCur->pBtree;
66844 BtShared *pBt = p->pBt;
66845 unsigned char *oldCell;
66846 unsigned char *newCell = 0;
66847
66848 assert( (flags & (BTREE_SAVEPOSITION|BTREE_APPEND))==flags );
66849
66850 if( pCur->eState==CURSOR_FAULT ){
66851 assert( pCur->skipNext!=SQLITE_OK );
66852 return pCur->skipNext;
66853 }
@@ -66742,23 +66885,28 @@
66885 assert( pX->pKey==0 );
66886 /* If this is an insert into a table b-tree, invalidate any incrblob
66887 ** cursors open on the row being replaced */
66888 invalidateIncrblobCursors(p, pX->nKey, 0);
66889
66890 /* If BTREE_SAVEPOSITION is set, the cursor must already be pointing
66891 ** to a row with the same key as the new entry being inserted. */
66892 assert( (flags & BTREE_SAVEPOSITION)==0 ||
66893 ((pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey) );
66894
66895 /* If the cursor is currently on the last row and we are appending a
66896 ** new row onto the end, set the "loc" to avoid an unnecessary
66897 ** btreeMoveto() call */
66898 if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey ){
66899 loc = 0;
66900 }else if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey>0
66901 && pCur->info.nKey==pX->nKey-1 ){
66902 loc = -1;
66903 }else if( loc==0 ){
66904 rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, flags!=0, &loc);
66905 if( rc ) return rc;
66906 }
66907 }else if( loc==0 && (flags & BTREE_SAVEPOSITION)==0 ){
66908 if( pX->nMem ){
66909 UnpackedRecord r;
66910 r.pKeyInfo = pCur->pKeyInfo;
66911 r.aMem = pX->aMem;
66912 r.nField = pX->nMem;
@@ -66765,13 +66913,13 @@
66913 r.default_rc = 0;
66914 r.errCode = 0;
66915 r.r1 = 0;
66916 r.r2 = 0;
66917 r.eqSeen = 0;
66918 rc = sqlite3BtreeMovetoUnpacked(pCur, &r, 0, flags!=0, &loc);
66919 }else{
66920 rc = btreeMoveto(pCur, pX->pKey, pX->nKey, flags!=0, &loc);
66921 }
66922 if( rc ) return rc;
66923 }
66924 assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );
66925
@@ -66855,10 +67003,24 @@
67003 ** fails. Internal data structure corruption will result otherwise.
67004 ** Also, set the cursor state to invalid. This stops saveCursorPosition()
67005 ** from trying to save the current position of the cursor. */
67006 pCur->apPage[pCur->iPage]->nOverflow = 0;
67007 pCur->eState = CURSOR_INVALID;
67008 if( (flags & BTREE_SAVEPOSITION) && rc==SQLITE_OK ){
67009 rc = moveToRoot(pCur);
67010 if( pCur->pKeyInfo ){
67011 assert( pCur->pKey==0 );
67012 pCur->pKey = sqlite3Malloc( pX->nKey );
67013 if( pCur->pKey==0 ){
67014 rc = SQLITE_NOMEM;
67015 }else{
67016 memcpy(pCur->pKey, pX->pKey, pX->nKey);
67017 }
67018 }
67019 pCur->eState = CURSOR_REQUIRESEEK;
67020 pCur->nKey = pX->nKey;
67021 }
67022 }
67023 assert( pCur->apPage[pCur->iPage]->nOverflow==0 );
67024
67025 end_insert:
67026 return rc;
@@ -71765,11 +71927,11 @@
71927 sqlite3VdbeGetOp(p,addr)->p2 = val;
71928 }
71929 SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe *p, u32 addr, int val){
71930 sqlite3VdbeGetOp(p,addr)->p3 = val;
71931 }
71932 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe *p, u16 p5){
71933 assert( p->nOp>0 || p->db->mallocFailed );
71934 if( p->nOp>0 ) p->aOp[p->nOp-1].p5 = p5;
71935 }
71936
71937 /*
@@ -73479,64 +73641,63 @@
73641 ** statement transaction is committed.
73642 **
73643 ** If an IO error occurs, an SQLITE_IOERR_XXX error code is returned.
73644 ** Otherwise SQLITE_OK.
73645 */
73646 static SQLITE_NOINLINE int vdbeCloseStatement(Vdbe *p, int eOp){
73647 sqlite3 *const db = p->db;
73648 int rc = SQLITE_OK;
73649 int i;
73650 const int iSavepoint = p->iStatement-1;
73651
73652 assert( eOp==SAVEPOINT_ROLLBACK || eOp==SAVEPOINT_RELEASE);
73653 assert( db->nStatement>0 );
73654 assert( p->iStatement==(db->nStatement+db->nSavepoint) );
73655
73656 for(i=0; i<db->nDb; i++){
73657 int rc2 = SQLITE_OK;
73658 Btree *pBt = db->aDb[i].pBt;
73659 if( pBt ){
73660 if( eOp==SAVEPOINT_ROLLBACK ){
73661 rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_ROLLBACK, iSavepoint);
73662 }
73663 if( rc2==SQLITE_OK ){
73664 rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_RELEASE, iSavepoint);
73665 }
73666 if( rc==SQLITE_OK ){
73667 rc = rc2;
73668 }
73669 }
73670 }
73671 db->nStatement--;
73672 p->iStatement = 0;
73673
73674 if( rc==SQLITE_OK ){
73675 if( eOp==SAVEPOINT_ROLLBACK ){
73676 rc = sqlite3VtabSavepoint(db, SAVEPOINT_ROLLBACK, iSavepoint);
73677 }
73678 if( rc==SQLITE_OK ){
73679 rc = sqlite3VtabSavepoint(db, SAVEPOINT_RELEASE, iSavepoint);
73680 }
73681 }
73682
73683 /* If the statement transaction is being rolled back, also restore the
73684 ** database handles deferred constraint counter to the value it had when
73685 ** the statement transaction was opened. */
73686 if( eOp==SAVEPOINT_ROLLBACK ){
73687 db->nDeferredCons = p->nStmtDefCons;
73688 db->nDeferredImmCons = p->nStmtDefImmCons;
73689 }
73690 return rc;
73691 }
73692 SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *p, int eOp){
73693 if( p->db->nStatement && p->iStatement ){
73694 return vdbeCloseStatement(p, eOp);
73695 }
73696 return SQLITE_OK;
73697 }
73698
 
73699
73700 /*
73701 ** This function is called when a transaction opened by the database
73702 ** handle associated with the VM passed as an argument is about to be
73703 ** committed. If there are outstanding deferred foreign key constraint
@@ -75567,14 +75728,14 @@
75728 ** structure itself, using sqlite3DbFree().
75729 **
75730 ** This function is used to free UnpackedRecord structures allocated by
75731 ** the vdbeUnpackRecord() function found in vdbeapi.c.
75732 */
75733 static void vdbeFreeUnpacked(sqlite3 *db, int nField, UnpackedRecord *p){
75734 if( p ){
75735 int i;
75736 for(i=0; i<nField; i++){
75737 Mem *pMem = &p->aMem[i];
75738 if( pMem->zMalloc ) sqlite3VdbeMemRelease(pMem);
75739 }
75740 sqlite3DbFree(db, p);
75741 }
@@ -75603,14 +75764,19 @@
75764 const char *zTbl = pTab->zName;
75765 static const u8 fakeSortOrder = 0;
75766
75767 assert( db->pPreUpdate==0 );
75768 memset(&preupdate, 0, sizeof(PreUpdate));
75769 if( HasRowid(pTab)==0 ){
75770 iKey1 = iKey2 = 0;
75771 preupdate.pPk = sqlite3PrimaryKeyIndex(pTab);
75772 }else{
75773 if( op==SQLITE_UPDATE ){
75774 iKey2 = v->aMem[iReg].u.i;
75775 }else{
75776 iKey2 = iKey1;
75777 }
75778 }
75779
75780 assert( pCsr->nField==pTab->nCol
75781 || (pCsr->nField==pTab->nCol+1 && op==SQLITE_DELETE && iReg==-1)
75782 );
@@ -75629,12 +75795,12 @@
75795
75796 db->pPreUpdate = &preupdate;
75797 db->xPreUpdateCallback(db->pPreUpdateArg, db, op, zDb, zTbl, iKey1, iKey2);
75798 db->pPreUpdate = 0;
75799 sqlite3DbFree(db, preupdate.aRecord);
75800 vdbeFreeUnpacked(db, preupdate.keyinfo.nField+1, preupdate.pUnpacked);
75801 vdbeFreeUnpacked(db, preupdate.keyinfo.nField+1, preupdate.pNewUnpacked);
75802 if( preupdate.aNew ){
75803 int i;
75804 for(i=0; i<pCsr->nField; i++){
75805 sqlite3VdbeMemRelease(&preupdate.aNew[i]);
75806 }
@@ -77305,18 +77471,22 @@
77471 ** This function is called from within a pre-update callback to retrieve
77472 ** a field of the row currently being updated or deleted.
77473 */
77474 SQLITE_API int sqlite3_preupdate_old(sqlite3 *db, int iIdx, sqlite3_value **ppValue){
77475 PreUpdate *p = db->pPreUpdate;
77476 Mem *pMem;
77477 int rc = SQLITE_OK;
77478
77479 /* Test that this call is being made from within an SQLITE_DELETE or
77480 ** SQLITE_UPDATE pre-update callback, and that iIdx is within range. */
77481 if( !p || p->op==SQLITE_INSERT ){
77482 rc = SQLITE_MISUSE_BKPT;
77483 goto preupdate_old_out;
77484 }
77485 if( p->pPk ){
77486 iIdx = sqlite3ColumnOfIndex(p->pPk, iIdx);
77487 }
77488 if( iIdx>=p->pCsr->nField || iIdx<0 ){
77489 rc = SQLITE_RANGE;
77490 goto preupdate_old_out;
77491 }
77492
@@ -77338,21 +77508,18 @@
77508 goto preupdate_old_out;
77509 }
77510 p->aRecord = aRec;
77511 }
77512
77513 pMem = *ppValue = &p->pUnpacked->aMem[iIdx];
77514 if( iIdx==p->pTab->iPKey ){
77515 sqlite3VdbeMemSetInt64(pMem, p->iKey1);
77516 }else if( iIdx>=p->pUnpacked->nField ){
77517 *ppValue = (sqlite3_value *)columnNullValue();
77518 }else if( p->pTab->aCol[iIdx].affinity==SQLITE_AFF_REAL ){
77519 if( pMem->flags & MEM_Int ){
77520 sqlite3VdbeMemRealify(pMem);
 
 
 
 
 
 
77521 }
77522 }
77523
77524 preupdate_old_out:
77525 sqlite3Error(db, rc);
@@ -77401,10 +77568,13 @@
77568
77569 if( !p || p->op==SQLITE_DELETE ){
77570 rc = SQLITE_MISUSE_BKPT;
77571 goto preupdate_new_out;
77572 }
77573 if( p->pPk && p->op!=SQLITE_UPDATE ){
77574 iIdx = sqlite3ColumnOfIndex(p->pPk, iIdx);
77575 }
77576 if( iIdx>=p->pCsr->nField || iIdx<0 ){
77577 rc = SQLITE_RANGE;
77578 goto preupdate_new_out;
77579 }
77580
@@ -77421,17 +77591,15 @@
77591 rc = SQLITE_NOMEM;
77592 goto preupdate_new_out;
77593 }
77594 p->pNewUnpacked = pUnpack;
77595 }
77596 pMem = &pUnpack->aMem[iIdx];
77597 if( iIdx==p->pTab->iPKey ){
77598 sqlite3VdbeMemSetInt64(pMem, p->iKey2);
77599 }else if( iIdx>=pUnpack->nField ){
77600 pMem = (sqlite3_value *)columnNullValue();
 
 
 
 
 
77601 }
77602 }else{
77603 /* For an UPDATE, memory cell (p->iNewReg+1+iIdx) contains the required
77604 ** value. Make a copy of the cell contents and return a pointer to it.
77605 ** It is not safe to return a pointer to the memory cell itself as the
@@ -78404,12 +78572,10 @@
78572 Mem *aMem = p->aMem; /* Copy of p->aMem */
78573 Mem *pIn1 = 0; /* 1st input operand */
78574 Mem *pIn2 = 0; /* 2nd input operand */
78575 Mem *pIn3 = 0; /* 3rd input operand */
78576 Mem *pOut = 0; /* Output operand */
 
 
78577 #ifdef VDBE_PROFILE
78578 u64 start; /* CPU clock count at start of opcode */
78579 #endif
78580 /*** INSERT STACK UNION HERE ***/
78581
@@ -78420,11 +78586,10 @@
78586 ** sqlite3_column_text16() failed. */
78587 goto no_mem;
78588 }
78589 assert( p->rc==SQLITE_OK || (p->rc&0xff)==SQLITE_BUSY );
78590 assert( p->bIsReader || p->readOnly!=0 );
 
78591 p->iCurrentTime = 0;
78592 assert( p->explain==0 );
78593 p->pResultSet = 0;
78594 db->busyHandler.nBusy = 0;
78595 if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
@@ -78781,11 +78946,10 @@
78946 pFrame = p->pFrame;
78947 p->pFrame = pFrame->pParent;
78948 p->nFrame--;
78949 sqlite3VdbeSetChanges(db, p->nChange);
78950 pcx = sqlite3VdbeFrameRestore(pFrame);
 
78951 if( pOp->p2==OE_Ignore ){
78952 /* Instruction pcx is the OP_Program that invoked the sub-program
78953 ** currently being halted. If the p2 instruction of this OP_Halt
78954 ** instruction is set to OE_Ignore, then the sub-program is throwing
78955 ** an IGNORE exception. In this case jump to the address specified
@@ -79016,11 +79180,11 @@
79180 assert( pOp->p4.z==0 || pOp->p4.z==sqlite3VListNumToName(p->pVList,pOp->p1) );
79181 pVar = &p->aVar[pOp->p1 - 1];
79182 if( sqlite3VdbeMemTooBig(pVar) ){
79183 goto too_big;
79184 }
79185 pOut = &aMem[pOp->p2];
79186 sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static);
79187 UPDATE_MAX_BLOBSIZE(pOut);
79188 break;
79189 }
79190
@@ -79503,13 +79667,11 @@
79667 REGISTER_TRACE(pOp->p2+i, pCtx->argv[i]);
79668 }
79669 #endif
79670 MemSetTypeFlag(pCtx->pOut, MEM_Null);
79671 pCtx->fErrorOrAux = 0;
 
79672 (*pCtx->pFunc->xSFunc)(pCtx, pCtx->argc, pCtx->argv);/* IMP: R-24505-23230 */
 
79673
79674 /* If the function returned an error, throw an exception */
79675 if( pCtx->fErrorOrAux ){
79676 if( pCtx->isError ){
79677 sqlite3VdbeError(p, "%s", sqlite3_value_text(pCtx->pOut));
@@ -79961,12 +80123,12 @@
80123 }
80124
80125
80126 /* Opcode: Permutation * * * P4 *
80127 **
80128 ** Set the permutation used by the OP_Compare operator in the next
80129 ** instruction. The permutation is stored in the P4 operand.
80130 **
80131 ** The permutation is only valid until the next OP_Compare that has
80132 ** the OPFLAG_PERMUTE bit set in P5. Typically the OP_Permutation should
80133 ** occur immediately prior to the OP_Compare.
80134 **
@@ -79974,11 +80136,12 @@
80136 ** and does not become part of the permutation.
80137 */
80138 case OP_Permutation: {
80139 assert( pOp->p4type==P4_INTARRAY );
80140 assert( pOp->p4.ai );
80141 assert( pOp[1].opcode==OP_Compare );
80142 assert( pOp[1].p5 & OPFLAG_PERMUTE );
80143 break;
80144 }
80145
80146 /* Opcode: Compare P1 P2 P3 P4 P5
80147 ** Synopsis: r[P1@P3] <-> r[P2@P3]
@@ -80007,12 +80170,21 @@
80170 int p2;
80171 const KeyInfo *pKeyInfo;
80172 int idx;
80173 CollSeq *pColl; /* Collating sequence to use on this term */
80174 int bRev; /* True for DESCENDING sort order */
80175 int *aPermute; /* The permutation */
80176
80177 if( (pOp->p5 & OPFLAG_PERMUTE)==0 ){
80178 aPermute = 0;
80179 }else{
80180 assert( pOp>aOp );
80181 assert( pOp[-1].opcode==OP_Permutation );
80182 assert( pOp[-1].p4type==P4_INTARRAY );
80183 aPermute = pOp[-1].p4.ai + 1;
80184 assert( aPermute!=0 );
80185 }
80186 n = pOp->p3;
80187 pKeyInfo = pOp->p4.pKeyInfo;
80188 assert( n>0 );
80189 assert( pKeyInfo!=0 );
80190 p1 = pOp->p1;
@@ -80041,11 +80213,10 @@
80213 if( iCompare ){
80214 if( bRev ) iCompare = -iCompare;
80215 break;
80216 }
80217 }
 
80218 break;
80219 }
80220
80221 /* Opcode: Jump P1 P2 P3 * *
80222 **
@@ -80597,10 +80768,24 @@
80768 do{
80769 applyAffinity(pRec++, *(zAffinity++), encoding);
80770 assert( zAffinity[0]==0 || pRec<=pLast );
80771 }while( zAffinity[0] );
80772 }
80773
80774 #ifdef SQLITE_ENABLE_NULL_TRIM
80775 /* NULLs can be safely trimmed from the end of the record, as long as
80776 ** as the schema format is 2 or more and none of the omitted columns
80777 ** have a non-NULL default value. Also, the record must be left with
80778 ** at least one field. If P5>0 then it will be one more than the
80779 ** index of the right-most column with a non-NULL default value */
80780 if( pOp->p5 ){
80781 while( (pLast->flags & MEM_Null)!=0 && nField>pOp->p5 ){
80782 pLast--;
80783 nField--;
80784 }
80785 }
80786 #endif
80787
80788 /* Loop through the elements that will make up the record to figure
80789 ** out how much space is required for the new record.
80790 */
80791 pRec = pLast;
@@ -82187,11 +82372,11 @@
82372 assert( memIsValid(pData) );
82373 pC = p->apCsr[pOp->p1];
82374 assert( pC!=0 );
82375 assert( pC->eCurType==CURTYPE_BTREE );
82376 assert( pC->uc.pCursor!=0 );
82377 assert( (pOp->p5 & OPFLAG_ISNOOP) || pC->isTable );
82378 assert( pOp->p4type==P4_TABLE || pOp->p4type>=P4_STATIC );
82379 REGISTER_TRACE(pOp->p2, pData);
82380
82381 if( pOp->opcode==OP_Insert ){
82382 pKey = &aMem[pOp->p3];
@@ -82203,18 +82388,17 @@
82388 assert( pOp->opcode==OP_InsertInt );
82389 x.nKey = pOp->p3;
82390 }
82391
82392 if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){
 
82393 assert( pC->iDb>=0 );
82394 zDb = db->aDb[pC->iDb].zDbSName;
82395 pTab = pOp->p4.pTab;
82396 assert( (pOp->p5 & OPFLAG_ISNOOP) || HasRowid(pTab) );
82397 op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT);
82398 }else{
82399 pTab = 0; /* Not needed. Silence a compiler warning. */
82400 zDb = 0; /* Not needed. Silence a compiler warning. */
82401 }
82402
82403 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
82404 /* Invoke the pre-update hook, if any */
@@ -82222,14 +82406,15 @@
82406 && pOp->p4type==P4_TABLE
82407 && !(pOp->p5 & OPFLAG_ISUPDATE)
82408 ){
82409 sqlite3VdbePreUpdateHook(p, pC, SQLITE_INSERT, zDb, pTab, x.nKey, pOp->p2);
82410 }
82411 if( pOp->p5 & OPFLAG_ISNOOP ) break;
82412 #endif
82413
82414 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
82415 if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = x.nKey;
82416 if( pData->flags & MEM_Null ){
82417 x.pData = 0;
82418 x.nData = 0;
82419 }else{
82420 assert( pData->flags & (MEM_Blob|MEM_Str) );
@@ -82242,11 +82427,11 @@
82427 }else{
82428 x.nZero = 0;
82429 }
82430 x.pKey = 0;
82431 rc = sqlite3BtreeInsert(pC->uc.pCursor, &x,
82432 (pOp->p5 & (OPFLAG_APPEND|OPFLAG_SAVEPOSITION)), seekResult
82433 );
82434 pC->deferredMoveto = 0;
82435 pC->cacheStatus = CACHE_STALE;
82436
82437 /* Invoke the update-hook if required. */
@@ -82334,12 +82519,15 @@
82519 pTab = 0; /* Not needed. Silence a compiler warning. */
82520 }
82521
82522 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
82523 /* Invoke the pre-update-hook if required. */
82524 if( db->xPreUpdateCallback && pOp->p4.pTab ){
82525 assert( !(opflags & OPFLAG_ISUPDATE)
82526 || HasRowid(pTab)==0
82527 || (aMem[pOp->p3].flags & MEM_Int)
82528 );
82529 sqlite3VdbePreUpdateHook(p, pC,
82530 (opflags & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_DELETE,
82531 zDb, pTab, pC->movetoTarget,
82532 pOp->p3
82533 );
@@ -82453,11 +82641,11 @@
82641 if( rc ) goto abort_due_to_error;
82642 p->apCsr[pOp->p3]->cacheStatus = CACHE_STALE;
82643 break;
82644 }
82645
82646 /* Opcode: RowData P1 P2 P3 * *
82647 ** Synopsis: r[P2]=data
82648 **
82649 ** Write into register P2 the complete row content for the row at
82650 ** which cursor P1 is currently pointing.
82651 ** There is no interpretation of the data.
@@ -82467,18 +82655,30 @@
82655 ** If cursor P1 is an index, then the content is the key of the row.
82656 ** If cursor P2 is a table, then the content extracted is the data.
82657 **
82658 ** If the P1 cursor must be pointing to a valid row (not a NULL row)
82659 ** of a real table, not a pseudo-table.
82660 **
82661 ** If P3!=0 then this opcode is allowed to make an ephermeral pointer
82662 ** into the database page. That means that the content of the output
82663 ** register will be invalidated as soon as the cursor moves - including
82664 ** moves caused by other cursors that "save" the the current cursors
82665 ** position in order that they can write to the same table. If P3==0
82666 ** then a copy of the data is made into memory. P3!=0 is faster, but
82667 ** P3==0 is safer.
82668 **
82669 ** If P3!=0 then the content of the P2 register is unsuitable for use
82670 ** in OP_Result and any OP_Result will invalidate the P2 register content.
82671 ** The P2 register content is invalidated by opcodes like OP_Function or
82672 ** by any use of another cursor pointing to the same table.
82673 */
82674 case OP_RowData: {
82675 VdbeCursor *pC;
82676 BtCursor *pCrsr;
82677 u32 n;
82678
82679 pOut = out2Prerelease(p, pOp);
 
82680
82681 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
82682 pC = p->apCsr[pOp->p1];
82683 assert( pC!=0 );
82684 assert( pC->eCurType==CURTYPE_BTREE );
@@ -82505,18 +82705,13 @@
82705 n = sqlite3BtreePayloadSize(pCrsr);
82706 if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
82707 goto too_big;
82708 }
82709 testcase( n==0 );
82710 rc = sqlite3VdbeMemFromBtree(pCrsr, 0, n, pOut);
 
 
 
 
 
82711 if( rc ) goto abort_due_to_error;
82712 if( !pOp->p3 ) Deephemeralize(pOut);
82713 UPDATE_MAX_BLOBSIZE(pOut);
82714 REGISTER_TRACE(pOp->p2, pOut);
82715 break;
82716 }
82717
@@ -82900,11 +83095,11 @@
83095 x.nKey = pIn2->n;
83096 x.pKey = pIn2->z;
83097 x.aMem = aMem + pOp->p3;
83098 x.nMem = (u16)pOp->p4.i;
83099 rc = sqlite3BtreeInsert(pC->uc.pCursor, &x,
83100 (pOp->p5 & (OPFLAG_APPEND|OPFLAG_SAVEPOSITION)),
83101 ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0)
83102 );
83103 assert( pC->deferredMoveto==0 );
83104 pC->cacheStatus = CACHE_STALE;
83105 }
@@ -83022,11 +83217,10 @@
83217 pTabCur->aAltMap = pOp->p4.ai;
83218 pTabCur->pAltCursor = pC;
83219 }else{
83220 pOut = out2Prerelease(p, pOp);
83221 pOut->u.i = rowid;
 
83222 }
83223 }else{
83224 assert( pOp->opcode==OP_IdxRowid );
83225 sqlite3VdbeMemSetNull(&aMem[pOp->p2]);
83226 }
@@ -83664,11 +83858,11 @@
83858 assert( (int)(pOp - aOp)==pFrame->pc );
83859 }
83860
83861 p->nFrame++;
83862 pFrame->pParent = p->pFrame;
83863 pFrame->lastRowid = db->lastRowid;
83864 pFrame->nChange = p->nChange;
83865 pFrame->nDbChange = p->db->nChange;
83866 assert( pFrame->pAuxData==0 );
83867 pFrame->pAuxData = p->pAuxData;
83868 p->pAuxData = 0;
@@ -84605,11 +84799,11 @@
84799 rc = pModule->xUpdate(pVtab, nArg, apArg, &rowid);
84800 db->vtabOnConflict = vtabOnConflict;
84801 sqlite3VtabImportErrmsg(p, pVtab);
84802 if( rc==SQLITE_OK && pOp->p1 ){
84803 assert( nArg>1 && apArg[0] && (apArg[0]->flags&MEM_Null) );
84804 db->lastRowid = rowid;
84805 }
84806 if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){
84807 if( pOp->p5==OE_Ignore ){
84808 rc = SQLITE_OK;
84809 }else{
@@ -84841,11 +85035,10 @@
85035
85036 /* This is the only way out of this procedure. We have to
85037 ** release the mutexes on btrees that were acquired at the
85038 ** top. */
85039 vdbe_return:
 
85040 testcase( nVmStep>0 );
85041 p->aCounter[SQLITE_STMTSTATUS_VM_STEP] += (int)nVmStep;
85042 sqlite3VdbeLeave(p);
85043 assert( rc!=SQLITE_OK || nExtraDelete==0
85044 || sqlite3_strlike("DELETE%",p->zSql,0)!=0
@@ -84905,14 +85098,13 @@
85098 /*
85099 ** Valid sqlite3_blob* handles point to Incrblob structures.
85100 */
85101 typedef struct Incrblob Incrblob;
85102 struct Incrblob {
 
85103 int nByte; /* Size of open blob, in bytes */
85104 int iOffset; /* Byte offset of blob in cursor data */
85105 u16 iCol; /* Table column this handle is open on */
85106 BtCursor *pCsr; /* Cursor pointing at blob row */
85107 sqlite3_stmt *pStmt; /* Statement holding cursor open */
85108 sqlite3 *db; /* The associated database */
85109 char *zDb; /* Database name */
85110 Table *pTab; /* Table object */
@@ -84939,21 +85131,31 @@
85131 static int blobSeekToRow(Incrblob *p, sqlite3_int64 iRow, char **pzErr){
85132 int rc; /* Error code */
85133 char *zErr = 0; /* Error message */
85134 Vdbe *v = (Vdbe *)p->pStmt;
85135
85136 /* Set the value of register r[1] in the SQL statement to integer iRow.
85137 ** This is done directly as a performance optimization
 
85138 */
85139 v->aMem[1].flags = MEM_Int;
85140 v->aMem[1].u.i = iRow;
85141
85142 /* If the statement has been run before (and is paused at the OP_ResultRow)
85143 ** then back it up to the point where it does the OP_SeekRowid. This could
85144 ** have been down with an extra OP_Goto, but simply setting the program
85145 ** counter is faster. */
85146 if( v->pc>3 ){
85147 v->pc = 3;
85148 rc = sqlite3VdbeExec(v);
85149 }else{
85150 rc = sqlite3_step(p->pStmt);
85151 }
85152 if( rc==SQLITE_ROW ){
85153 VdbeCursor *pC = v->apCsr[0];
85154 u32 type = pC->nHdrParsed>p->iCol ? pC->aType[p->iCol] : 0;
85155 testcase( pC->nHdrParsed==p->iCol );
85156 testcase( pC->nHdrParsed==p->iCol+1 );
85157 if( type<12 ){
85158 zErr = sqlite3MPrintf(p->db, "cannot open value of type %s",
85159 type==0?"null": type==7?"real": "integer"
85160 );
85161 rc = SQLITE_ERROR;
@@ -84994,11 +85196,11 @@
85196 sqlite3* db, /* The database connection */
85197 const char *zDb, /* The attached database containing the blob */
85198 const char *zTable, /* The table containing the blob */
85199 const char *zColumn, /* The column containing the blob */
85200 sqlite_int64 iRow, /* The row containing the glob */
85201 int wrFlag, /* True -> read/write access, false -> read-only */
85202 sqlite3_blob **ppBlob /* Handle for accessing the blob returned here */
85203 ){
85204 int nAttempt = 0;
85205 int iCol; /* Index of zColumn in row-record */
85206 int rc = SQLITE_OK;
@@ -85016,11 +85218,11 @@
85218 #ifdef SQLITE_ENABLE_API_ARMOR
85219 if( !sqlite3SafetyCheckOk(db) || zTable==0 ){
85220 return SQLITE_MISUSE_BKPT;
85221 }
85222 #endif
85223 wrFlag = !!wrFlag; /* wrFlag = (wrFlag ? 1 : 0); */
85224
85225 sqlite3_mutex_enter(db->mutex);
85226
85227 pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
85228 if( !pBlob ) goto blob_open_out;
@@ -85076,13 +85278,12 @@
85278 goto blob_open_out;
85279 }
85280
85281 /* If the value is being opened for writing, check that the
85282 ** column is not indexed, and that it is not part of a foreign key.
85283 */
85284 if( wrFlag ){
 
85285 const char *zFault = 0;
85286 Index *pIdx;
85287 #ifndef SQLITE_OMIT_FOREIGN_KEY
85288 if( db->flags&SQLITE_ForeignKeys ){
85289 /* Check that the column is not part of an FK child key definition. It
@@ -85139,22 +85340,21 @@
85340 */
85341 static const int iLn = VDBE_OFFSET_LINENO(2);
85342 static const VdbeOpList openBlob[] = {
85343 {OP_TableLock, 0, 0, 0}, /* 0: Acquire a read or write lock */
85344 {OP_OpenRead, 0, 0, 0}, /* 1: Open a cursor */
85345 /* blobSeekToRow() will initialize r[1] to the desired rowid */
85346 {OP_NotExists, 0, 5, 1}, /* 2: Seek the cursor to rowid=r[1] */
85347 {OP_Column, 0, 0, 1}, /* 3 */
85348 {OP_ResultRow, 1, 0, 0}, /* 4 */
85349 {OP_Halt, 0, 0, 0}, /* 5 */
 
85350 };
85351 Vdbe *v = (Vdbe *)pBlob->pStmt;
85352 int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
85353 VdbeOp *aOp;
85354
85355 sqlite3VdbeAddOp4Int(v, OP_Transaction, iDb, wrFlag,
85356 pTab->pSchema->schema_cookie,
85357 pTab->pSchema->iGeneration);
85358 sqlite3VdbeChangeP5(v, 1);
85359 aOp = sqlite3VdbeAddOpList(v, ArraySize(openBlob), openBlob, iLn);
85360
@@ -85167,19 +85367,19 @@
85367 #ifdef SQLITE_OMIT_SHARED_CACHE
85368 aOp[0].opcode = OP_Noop;
85369 #else
85370 aOp[0].p1 = iDb;
85371 aOp[0].p2 = pTab->tnum;
85372 aOp[0].p3 = wrFlag;
85373 sqlite3VdbeChangeP4(v, 1, pTab->zName, P4_TRANSIENT);
85374 }
85375 if( db->mallocFailed==0 ){
85376 #endif
85377
85378 /* Remove either the OP_OpenWrite or OpenRead. Set the P2
85379 ** parameter of the other to pTab->tnum. */
85380 if( wrFlag ) aOp[1].opcode = OP_OpenWrite;
85381 aOp[1].p2 = pTab->tnum;
85382 aOp[1].p3 = iDb;
85383
85384 /* Configure the number of columns. Configure the cursor to
85385 ** think that the table has one more column than it really
@@ -85188,27 +85388,25 @@
85388 ** we can invoke OP_Column to fill in the vdbe cursors type
85389 ** and offset cache without causing any IO.
85390 */
85391 aOp[1].p4type = P4_INT32;
85392 aOp[1].p4.i = pTab->nCol+1;
85393 aOp[3].p2 = pTab->nCol;
85394
85395 pParse->nVar = 0;
85396 pParse->nMem = 1;
85397 pParse->nTab = 1;
85398 sqlite3VdbeMakeReady(v, pParse);
85399 }
85400 }
85401
 
85402 pBlob->iCol = iCol;
85403 pBlob->db = db;
85404 sqlite3BtreeLeaveAll(db);
85405 if( db->mallocFailed ){
85406 goto blob_open_out;
85407 }
 
85408 rc = blobSeekToRow(pBlob, iRow, &zErr);
85409 } while( (++nAttempt)<SQLITE_MAX_SCHEMA_RETRY && rc==SQLITE_SCHEMA );
85410
85411 blob_open_out:
85412 if( rc==SQLITE_OK && db->mallocFailed==0 ){
@@ -88741,12 +88939,10 @@
88939 ** This file contains routines used for walking the parser tree and
88940 ** resolve all identifiers by associating them with a particular
88941 ** table and column.
88942 */
88943 /* #include "sqliteInt.h" */
 
 
88944
88945 /*
88946 ** Walk the expression tree pExpr and increase the aggregate function
88947 ** depth (the Expr.op2 field) by N on every TK_AGG_FUNCTION node.
88948 ** This needs to occur when copying a TK_AGG_FUNCTION node from an
@@ -90501,11 +90697,11 @@
90697 aff = sqlite3ExprAffinity(pExpr->pLeft);
90698 if( pExpr->pRight ){
90699 aff = sqlite3CompareAffinity(pExpr->pRight, aff);
90700 }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){
90701 aff = sqlite3CompareAffinity(pExpr->x.pSelect->pEList->a[0].pExpr, aff);
90702 }else if( aff==0 ){
90703 aff = SQLITE_AFF_BLOB;
90704 }
90705 return aff;
90706 }
90707
@@ -91237,21 +91433,27 @@
91433 int doAdd = 0;
91434 if( z[0]=='?' ){
91435 /* Wildcard of the form "?nnn". Convert "nnn" to an integer and
91436 ** use it as the variable number */
91437 i64 i;
91438 int bOk;
91439 if( n==2 ){ /*OPTIMIZATION-IF-TRUE*/
91440 i = z[1]-'0'; /* The common case of ?N for a single digit N */
91441 bOk = 1;
91442 }else{
91443 bOk = 0==sqlite3Atoi64(&z[1], &i, n-1, SQLITE_UTF8);
91444 }
91445 testcase( i==0 );
91446 testcase( i==1 );
91447 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 );
91448 testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] );
91449 if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
91450 sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d",
91451 db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]);
91452 return;
91453 }
91454 x = (ynVar)i;
91455 if( x>pParse->nVar ){
91456 pParse->nVar = (int)x;
91457 doAdd = 1;
91458 }else if( sqlite3VListNumToName(pParse->pVList, x)==0 ){
91459 doAdd = 1;
@@ -91682,37 +91884,45 @@
91884 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
91885 pNewItem->idx = pOldItem->idx;
91886 }
91887 return pNew;
91888 }
91889 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *pDup, int flags){
91890 Select *pRet = 0;
91891 Select *pNext = 0;
91892 Select **pp = &pRet;
91893 Select *p;
91894
91895 assert( db!=0 );
91896 for(p=pDup; p; p=p->pPrior){
91897 Select *pNew = sqlite3DbMallocRawNN(db, sizeof(*p) );
91898 if( pNew==0 ) break;
91899 pNew->pEList = sqlite3ExprListDup(db, p->pEList, flags);
91900 pNew->pSrc = sqlite3SrcListDup(db, p->pSrc, flags);
91901 pNew->pWhere = sqlite3ExprDup(db, p->pWhere, flags);
91902 pNew->pGroupBy = sqlite3ExprListDup(db, p->pGroupBy, flags);
91903 pNew->pHaving = sqlite3ExprDup(db, p->pHaving, flags);
91904 pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, flags);
91905 pNew->op = p->op;
91906 pNew->pNext = pNext;
91907 pNew->pPrior = 0;
91908 pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags);
91909 pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags);
91910 pNew->iLimit = 0;
91911 pNew->iOffset = 0;
91912 pNew->selFlags = p->selFlags & ~SF_UsesEphemeral;
91913 pNew->addrOpenEphm[0] = -1;
91914 pNew->addrOpenEphm[1] = -1;
91915 pNew->nSelectRow = p->nSelectRow;
91916 pNew->pWith = withDup(db, p->pWith);
91917 sqlite3SelectSetName(pNew, p->zSelName);
91918 *pp = pNew;
91919 pp = &pNew->pPrior;
91920 pNext = pNew;
91921 }
91922
91923 return pRet;
91924 }
91925 #else
91926 SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
91927 assert( p==0 );
91928 return 0;
@@ -91773,11 +91983,11 @@
91983 **
91984 ** (a,b,c) = (expr1,expr2,expr3)
91985 ** Or: (a,b,c) = (SELECT x,y,z FROM ....)
91986 **
91987 ** For each term of the vector assignment, append new entries to the
91988 ** expression list pList. In the case of a subquery on the RHS, append
91989 ** TK_SELECT_COLUMN expressions.
91990 */
91991 SQLITE_PRIVATE ExprList *sqlite3ExprListAppendVector(
91992 Parse *pParse, /* Parsing context */
91993 ExprList *pList, /* List to which to append. Might be NULL */
@@ -93882,10 +94092,15 @@
94092 int i; /* Loop counter */
94093 sqlite3 *db = pParse->db; /* The database connection */
94094 u8 enc = ENC(db); /* The text encoding used by this database */
94095 CollSeq *pColl = 0; /* A collating sequence */
94096
94097 if( ConstFactorOk(pParse) && sqlite3ExprIsConstantNotJoin(pExpr) ){
94098 /* SQL functions can be expensive. So try to move constant functions
94099 ** out of the inner loop, even if that means an extra OP_Copy. */
94100 return sqlite3ExprCodeAtInit(pParse, pExpr, -1);
94101 }
94102 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
94103 if( ExprHasProperty(pExpr, EP_TokenOnly) ){
94104 pFarg = 0;
94105 }else{
94106 pFarg = pExpr->x.pList;
@@ -93929,10 +94144,26 @@
94144 */
94145 if( pDef->funcFlags & SQLITE_FUNC_UNLIKELY ){
94146 assert( nFarg>=1 );
94147 return sqlite3ExprCodeTarget(pParse, pFarg->a[0].pExpr, target);
94148 }
94149
94150 #ifdef SQLITE_DEBUG
94151 /* The AFFINITY() function evaluates to a string that describes
94152 ** the type affinity of the argument. This is used for testing of
94153 ** the SQLite type logic.
94154 */
94155 if( pDef->funcFlags & SQLITE_FUNC_AFFINITY ){
94156 const char *azAff[] = { "blob", "text", "numeric", "integer", "real" };
94157 char aff;
94158 assert( nFarg==1 );
94159 aff = sqlite3ExprAffinity(pFarg->a[0].pExpr);
94160 sqlite3VdbeLoadString(v, target,
94161 aff ? azAff[aff-SQLITE_AFF_BLOB] : "none");
94162 return target;
94163 }
94164 #endif
94165
94166 for(i=0; i<nFarg; i++){
94167 if( i<32 && sqlite3ExprIsConstant(pFarg->a[i].pExpr) ){
94168 testcase( i==31 );
94169 constMask |= MASKBIT32(i);
@@ -94246,28 +94477,44 @@
94477 return inReg;
94478 }
94479
94480 /*
94481 ** Factor out the code of the given expression to initialization time.
94482 **
94483 ** If regDest>=0 then the result is always stored in that register and the
94484 ** result is not reusable. If regDest<0 then this routine is free to
94485 ** store the value whereever it wants. The register where the expression
94486 ** is stored is returned. When regDest<0, two identical expressions will
94487 ** code to the same register.
94488 */
94489 SQLITE_PRIVATE int sqlite3ExprCodeAtInit(
94490 Parse *pParse, /* Parsing context */
94491 Expr *pExpr, /* The expression to code when the VDBE initializes */
94492 int regDest /* Store the value in this register */
 
94493 ){
94494 ExprList *p;
94495 assert( ConstFactorOk(pParse) );
94496 p = pParse->pConstExpr;
94497 if( regDest<0 && p ){
94498 struct ExprList_item *pItem;
94499 int i;
94500 for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
94501 if( pItem->reusable && sqlite3ExprCompare(pItem->pExpr,pExpr,-1)==0 ){
94502 return pItem->u.iConstExprReg;
94503 }
94504 }
94505 }
94506 pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
94507 p = sqlite3ExprListAppend(pParse, p, pExpr);
94508 if( p ){
94509 struct ExprList_item *pItem = &p->a[p->nExpr-1];
94510 pItem->reusable = regDest<0;
94511 if( regDest<0 ) regDest = ++pParse->nMem;
94512 pItem->u.iConstExprReg = regDest;
 
94513 }
94514 pParse->pConstExpr = p;
94515 return regDest;
94516 }
94517
94518 /*
94519 ** Generate code to evaluate an expression and store the results
94520 ** into a register. Return the register number where the results
@@ -94286,23 +94533,12 @@
94533 pExpr = sqlite3ExprSkipCollate(pExpr);
94534 if( ConstFactorOk(pParse)
94535 && pExpr->op!=TK_REGISTER
94536 && sqlite3ExprIsConstantNotJoin(pExpr)
94537 ){
 
 
94538 *pReg = 0;
94539 r2 = sqlite3ExprCodeAtInit(pParse, pExpr, -1);
 
 
 
 
 
 
 
 
 
94540 }else{
94541 int r1 = sqlite3GetTempReg(pParse);
94542 r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
94543 if( r2==r1 ){
94544 *pReg = r1;
@@ -94352,11 +94588,11 @@
94588 ** in register target. If the expression is constant, then this routine
94589 ** might choose to code the expression at initialization time.
94590 */
94591 SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse *pParse, Expr *pExpr, int target){
94592 if( pParse->okConstFactor && sqlite3ExprIsConstant(pExpr) ){
94593 sqlite3ExprCodeAtInit(pParse, pExpr, target);
94594 }else{
94595 sqlite3ExprCode(pParse, pExpr, target);
94596 }
94597 }
94598
@@ -94424,11 +94660,11 @@
94660 n--;
94661 }else{
94662 sqlite3VdbeAddOp2(v, copyOp, j+srcReg-1, target+i);
94663 }
94664 }else if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){
94665 sqlite3ExprCodeAtInit(pParse, pExpr, target+i);
94666 }else{
94667 int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
94668 if( inReg!=target+i ){
94669 VdbeOp *pOp;
94670 if( copyOp==OP_Copy
@@ -96968,10 +97204,16 @@
97204 ** used to query statistical information that has been gathered into
97205 ** the Stat4Accum object by prior calls to stat_push(). The P parameter
97206 ** has type BLOB but it is really just a pointer to the Stat4Accum object.
97207 ** The content to returned is determined by the parameter J
97208 ** which is one of the STAT_GET_xxxx values defined above.
97209 **
97210 ** The stat_get(P,J) function is not available to generic SQL. It is
97211 ** inserted as part of a manually constructed bytecode program. (See
97212 ** the callStatGet() routine below.) It is guaranteed that the P
97213 ** parameter will always be a poiner to a Stat4Accum object, never a
97214 ** NULL.
97215 **
97216 ** If neither STAT3 nor STAT4 are enabled, then J is always
97217 ** STAT_GET_STAT1 and is hence omitted and this routine becomes
97218 ** a one-parameter function, stat_get(P), that always returns the
97219 ** stat1 table entry information.
@@ -97787,11 +98029,11 @@
98029 sumEq += aSample[i].anEq[iCol];
98030 nSum100 += 100;
98031 }
98032 }
98033
98034 if( nDist100>nSum100 && sumEq<nRow ){
98035 avgEq = ((i64)100 * (nRow - sumEq))/(nDist100 - nSum100);
98036 }
98037 if( avgEq==0 ) avgEq = 1;
98038 pIdx->aAvgEq[iCol] = avgEq;
98039 }
@@ -98201,10 +98443,11 @@
98443 assert( pVfs );
98444 flags |= SQLITE_OPEN_MAIN_DB;
98445 rc = sqlite3BtreeOpen(pVfs, zPath, db, &aNew->pBt, 0, flags);
98446 sqlite3_free( zPath );
98447 db->nDb++;
98448 db->skipBtreeMutex = 0;
98449 if( rc==SQLITE_CONSTRAINT ){
98450 rc = SQLITE_ERROR;
98451 zErrDyn = sqlite3MPrintf(db, "database is already attached");
98452 }else if( rc==SQLITE_OK ){
98453 Pager *pPager;
@@ -104365,16 +104608,12 @@
104608 }
104609 }else
104610 #endif
104611 {
104612 int count = (pParse->nested==0); /* True to count changes */
 
 
 
 
104613 sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
104614 iKey, nKey, count, OE_Default, eOnePass, aiCurOnePass[1]);
104615 }
104616
104617 /* End of the loop over all rowids/primary-keys. */
104618 if( eOnePass!=ONEPASS_OFF ){
104619 sqlite3VdbeResolveLabel(v, addrBypass);
@@ -104450,19 +104689,21 @@
104689 ** then this function must seek iDataCur to the entry identified by iPk
104690 ** and nPk before reading from it.
104691 **
104692 ** If eMode is ONEPASS_MULTI, then this call is being made as part
104693 ** of a ONEPASS delete that affects multiple rows. In this case, if
104694 ** iIdxNoSeek is a valid cursor number (>=0) and is not the same as
104695 ** iDataCur, then its position should be preserved following the delete
104696 ** operation. Or, if iIdxNoSeek is not a valid cursor number, the
104697 ** position of iDataCur should be preserved instead.
104698 **
104699 ** iIdxNoSeek:
104700 ** If iIdxNoSeek is a valid cursor number (>=0) not equal to iDataCur,
104701 ** then it identifies an index cursor (from within array of cursors
104702 ** starting at iIdxCur) that already points to the index entry to be deleted.
104703 ** Except, this optimization is disabled if there are BEFORE triggers since
104704 ** the trigger body might have moved the cursor.
104705 */
104706 SQLITE_PRIVATE void sqlite3GenerateRowDelete(
104707 Parse *pParse, /* Parsing context */
104708 Table *pTab, /* Table containing the row to be deleted */
104709 Trigger *pTrigger, /* List of triggers to (potentially) fire */
@@ -104529,17 +104770,22 @@
104770 TK_DELETE, 0, TRIGGER_BEFORE, pTab, iOld, onconf, iLabel
104771 );
104772
104773 /* If any BEFORE triggers were coded, then seek the cursor to the
104774 ** row to be deleted again. It may be that the BEFORE triggers moved
104775 ** the cursor or already deleted the row that the cursor was
104776 ** pointing to.
104777 **
104778 ** Also disable the iIdxNoSeek optimization since the BEFORE trigger
104779 ** may have moved that cursor.
104780 */
104781 if( addrStart<sqlite3VdbeCurrentAddr(v) ){
104782 sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
104783 VdbeCoverageIf(v, opSeek==OP_NotExists);
104784 VdbeCoverageIf(v, opSeek==OP_NotFound);
104785 testcase( iIdxNoSeek>=0 );
104786 iIdxNoSeek = -1;
104787 }
104788
104789 /* Do FK processing. This call checks that any FK constraints that
104790 ** refer to this table (i.e. constraints attached to other tables)
104791 ** are not violated by deleting this row. */
@@ -104558,15 +104804,17 @@
104804 */
104805 if( pTab->pSelect==0 ){
104806 u8 p5 = 0;
104807 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek);
104808 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
104809 if( pParse->nested==0 ){
104810 sqlite3VdbeAppendP4(v, (char*)pTab, P4_TABLE);
104811 }
104812 if( eMode!=ONEPASS_OFF ){
104813 sqlite3VdbeChangeP5(v, OPFLAG_AUXDELETE);
104814 }
104815 if( iIdxNoSeek>=0 && iIdxNoSeek!=iDataCur ){
104816 sqlite3VdbeAddOp1(v, OP_Delete, iIdxNoSeek);
104817 }
104818 if( eMode==ONEPASS_MULTI ) p5 |= OPFLAG_SAVEPOSITION;
104819 sqlite3VdbeChangeP5(v, p5);
104820 }
@@ -104716,10 +104964,14 @@
104964 ** opcode if it is present */
104965 sqlite3VdbeDeletePriorOpcode(v, OP_RealAffinity);
104966 }
104967 if( regOut ){
104968 sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regOut);
104969 if( pIdx->pTable->pSelect ){
104970 const char *zAff = sqlite3IndexAffinityStr(pParse->db, pIdx);
104971 sqlite3VdbeChangeP4(v, -1, zAff, P4_TRANSIENT);
104972 }
104973 }
104974 sqlite3ReleaseTempRange(pParse, regBase, nCol);
104975 return regBase;
104976 }
104977
@@ -106512,10 +106764,13 @@
106764 DFUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ),
106765 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
106766 FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
106767 FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
106768 FUNCTION2(likely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
106769 #ifdef SQLITE_DEBUG
106770 FUNCTION2(affinity, 1, 0, 0, noopFunc, SQLITE_FUNC_AFFINITY),
106771 #endif
106772 FUNCTION(ltrim, 1, 1, 0, trimFunc ),
106773 FUNCTION(ltrim, 2, 1, 0, trimFunc ),
106774 FUNCTION(rtrim, 1, 2, 0, trimFunc ),
106775 FUNCTION(rtrim, 2, 2, 0, trimFunc ),
106776 FUNCTION(trim, 1, 3, 0, trimFunc ),
@@ -109667,11 +109922,11 @@
109922 if( db->flags&SQLITE_RecTriggers ){
109923 pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0);
109924 }
109925 sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur,
109926 regR, nPkField, 0, OE_Replace,
109927 (pIdx==pPk ? ONEPASS_SINGLE : ONEPASS_OFF), iThisCur);
109928 seenReplace = 1;
109929 break;
109930 }
109931 }
109932 sqlite3VdbeResolveLabel(v, addrUniqueOk);
@@ -109683,10 +109938,29 @@
109938 }
109939
109940 *pbMayReplace = seenReplace;
109941 VdbeModuleComment((v, "END: GenCnstCks(%d)", seenReplace));
109942 }
109943
109944 #ifdef SQLITE_ENABLE_NULL_TRIM
109945 /*
109946 ** Change the P5 operand on the last opcode (which should be an OP_MakeRecord)
109947 ** to be the number of columns in table pTab that must not be NULL-trimmed.
109948 **
109949 ** Or if no columns of pTab may be NULL-trimmed, leave P5 at zero.
109950 */
109951 SQLITE_PRIVATE void sqlite3SetMakeRecordP5(Vdbe *v, Table *pTab){
109952 u16 i;
109953
109954 /* Records with omitted columns are only allowed for schema format
109955 ** version 2 and later (SQLite version 3.1.4, 2005-02-20). */
109956 if( pTab->pSchema->file_format<2 ) return;
109957
109958 for(i=pTab->nCol; i>1 && pTab->aCol[i-1].pDflt==0; i--){}
109959 sqlite3VdbeChangeP5(v, i);
109960 }
109961 #endif
109962
109963 /*
109964 ** This routine generates code to finish the INSERT or UPDATE operation
109965 ** that was started by a prior call to sqlite3GenerateConstraintChecks.
109966 ** A consecutive range of registers starting at regNewData contains the
@@ -109700,11 +109974,11 @@
109974 Table *pTab, /* the table into which we are inserting */
109975 int iDataCur, /* Cursor of the canonical data source */
109976 int iIdxCur, /* First index cursor */
109977 int regNewData, /* Range of content */
109978 int *aRegIdx, /* Register used by each index. 0 for unused indices */
109979 int update_flags, /* True for UPDATE, False for INSERT */
109980 int appendBias, /* True if this is likely to be an append */
109981 int useSeekResult /* True to set the USESEEKRESULT flag on OP_[Idx]Insert */
109982 ){
109983 Vdbe *v; /* Prepared statements under construction */
109984 Index *pIdx; /* An index being inserted or updated */
@@ -109711,10 +109985,15 @@
109985 u8 pik_flags; /* flag values passed to the btree insert */
109986 int regData; /* Content registers (after the rowid) */
109987 int regRec; /* Register holding assembled record for the table */
109988 int i; /* Loop counter */
109989 u8 bAffinityDone = 0; /* True if OP_Affinity has been run already */
109990
109991 assert( update_flags==0
109992 || update_flags==OPFLAG_ISUPDATE
109993 || update_flags==(OPFLAG_ISUPDATE|OPFLAG_SAVEPOSITION)
109994 );
109995
109996 v = sqlite3GetVdbe(pParse);
109997 assert( v!=0 );
109998 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
109999 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
@@ -109722,34 +110001,43 @@
110001 bAffinityDone = 1;
110002 if( pIdx->pPartIdxWhere ){
110003 sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
110004 VdbeCoverage(v);
110005 }
110006 pik_flags = (useSeekResult ? OPFLAG_USESEEKRESULT : 0);
 
 
 
 
110007 if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
110008 assert( pParse->nested==0 );
110009 pik_flags |= OPFLAG_NCHANGE;
110010 pik_flags |= (update_flags & OPFLAG_SAVEPOSITION);
110011 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
110012 if( update_flags==0 ){
110013 sqlite3VdbeAddOp4(v, OP_InsertInt,
110014 iIdxCur+i, aRegIdx[i], 0, (char*)pTab, P4_TABLE
110015 );
110016 sqlite3VdbeChangeP5(v, OPFLAG_ISNOOP);
110017 }
110018 #endif
110019 }
110020 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i],
110021 aRegIdx[i]+1,
110022 pIdx->uniqNotNull ? pIdx->nKeyCol: pIdx->nColumn);
110023 sqlite3VdbeChangeP5(v, pik_flags);
110024 }
110025 if( !HasRowid(pTab) ) return;
110026 regData = regNewData + 1;
110027 regRec = sqlite3GetTempReg(pParse);
110028 sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec);
110029 sqlite3SetMakeRecordP5(v, pTab);
110030 if( !bAffinityDone ){
110031 sqlite3TableAffinity(v, pTab, 0);
110032 sqlite3ExprCacheAffinityChange(pParse, regData, pTab->nCol);
110033 }
110034 if( pParse->nested ){
110035 pik_flags = 0;
110036 }else{
110037 pik_flags = OPFLAG_NCHANGE;
110038 pik_flags |= (update_flags?update_flags:OPFLAG_LASTROWID);
110039 }
110040 if( appendBias ){
110041 pik_flags |= OPFLAG_APPEND;
110042 }
110043 if( useSeekResult ){
@@ -110154,11 +110442,11 @@
110442 addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid);
110443 }else{
110444 addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
110445 assert( (pDest->tabFlags & TF_Autoincrement)==0 );
110446 }
110447 sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1);
110448 if( db->flags & SQLITE_Vacuum ){
110449 sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1);
110450 insFlags = OPFLAG_NCHANGE|OPFLAG_LASTROWID|
110451 OPFLAG_APPEND|OPFLAG_USESEEKRESULT;
110452 }else{
@@ -110186,11 +110474,11 @@
110474 sqlite3VdbeAddOp3(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest);
110475 sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
110476 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
110477 VdbeComment((v, "%s", pDestIdx->zName));
110478 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
110479 sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1);
110480 if( db->flags & SQLITE_Vacuum ){
110481 /* This INSERT command is part of a VACUUM operation, which guarantees
110482 ** that the destination table is empty. If all indexed columns use
110483 ** collation sequence BINARY, then it can also be assumed that the
110484 ** index will be populated by inserting keys in strictly sorted
@@ -110971,11 +111259,10 @@
111259 #endif /* SQLITE3EXT_H */
111260
111261 /************** End of sqlite3ext.h ******************************************/
111262 /************** Continuing where we left off in loadext.c ********************/
111263 /* #include "sqliteInt.h" */
 
111264
111265 #ifndef SQLITE_OMIT_LOAD_EXTENSION
111266 /*
111267 ** Some API routines are omitted when various features are
111268 ** excluded from a build of SQLite. Substitute a NULL pointer
@@ -112635,11 +112922,11 @@
112922
112923 /*
112924 ** Locate a pragma in the aPragmaName[] array.
112925 */
112926 static const PragmaName *pragmaLocate(const char *zName){
112927 int upr, lwr, mid = 0, rc;
112928 lwr = 0;
112929 upr = ArraySize(aPragmaName)-1;
112930 while( lwr<=upr ){
112931 mid = (lwr+upr)/2;
112932 rc = sqlite3_stricmp(zName, aPragmaName[mid].zName);
@@ -116149,10 +116436,11 @@
116436 v = pParse->pVdbe;
116437 r1 = sqlite3GetTempReg(pParse);
116438 sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N); VdbeCoverage(v);
116439 sqlite3VdbeAddOp3(v, OP_MakeRecord, iMem, N, r1);
116440 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r1, iMem, N);
116441 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
116442 sqlite3ReleaseTempReg(pParse, r1);
116443 }
116444
116445 /*
116446 ** This routine generates the code for the inside of the inner loop
@@ -119677,11 +119965,19 @@
119965 assert( pTab->nTabRef==1 || ((pSel->selFlags&SF_Recursive) && pTab->nTabRef==2 ));
119966
119967 pCte->zCteErr = "circular reference: %s";
119968 pSavedWith = pParse->pWith;
119969 pParse->pWith = pWith;
119970 if( bMayRecursive ){
119971 Select *pPrior = pSel->pPrior;
119972 assert( pPrior->pWith==0 );
119973 pPrior->pWith = pSel->pWith;
119974 sqlite3WalkSelect(pWalker, pPrior);
119975 pPrior->pWith = 0;
119976 }else{
119977 sqlite3WalkSelect(pWalker, pSel);
119978 }
119979 pParse->pWith = pWith;
119980
119981 for(pLeft=pSel; pLeft->pPrior; pLeft=pLeft->pPrior);
119982 pEList = pLeft->pEList;
119983 if( pCte->pCols ){
@@ -119721,14 +120017,16 @@
120017 ** sqlite3SelectExpand() when walking a SELECT tree to resolve table
120018 ** names and other FROM clause elements.
120019 */
120020 static void selectPopWith(Walker *pWalker, Select *p){
120021 Parse *pParse = pWalker->pParse;
120022 if( pParse->pWith && p->pPrior==0 ){
120023 With *pWith = findRightmost(p)->pWith;
120024 if( pWith!=0 ){
120025 assert( pParse->pWith==pWith );
120026 pParse->pWith = pWith->pOuter;
120027 }
120028 }
120029 }
120030 #else
120031 #define selectPopWith 0
120032 #endif
@@ -119774,12 +120072,12 @@
120072 if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){
120073 return WRC_Prune;
120074 }
120075 pTabList = p->pSrc;
120076 pEList = p->pEList;
120077 if( p->pWith ){
120078 sqlite3WithPush(pParse, p->pWith, 0);
120079 }
120080
120081 /* Make sure cursor numbers have been assigned to all entries in
120082 ** the FROM clause of the SELECT statement.
120083 */
@@ -120062,13 +120360,11 @@
120360 if( pParse->hasCompound ){
120361 w.xSelectCallback = convertCompoundSelectToSubquery;
120362 sqlite3WalkSelect(&w, pSelect);
120363 }
120364 w.xSelectCallback = selectExpander;
120365 w.xSelectCallback2 = selectPopWith;
 
 
120366 sqlite3WalkSelect(&w, pSelect);
120367 }
120368
120369
120370 #ifndef SQLITE_OMIT_SUBQUERY
@@ -121143,11 +121439,11 @@
121439 /* This case runs if the aggregate has no GROUP BY clause. The
121440 ** processing is much simpler since there is only a single row
121441 ** of output.
121442 */
121443 resetAccumulator(pParse, &sAggInfo);
121444 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMax, 0,flag,0);
121445 if( pWInfo==0 ){
121446 sqlite3ExprListDelete(db, pDel);
121447 goto select_end;
121448 }
121449 updateAccumulator(pParse, &sAggInfo);
@@ -121232,12 +121528,10 @@
121528 **
121529 ** These routines are in a separate files so that they will not be linked
121530 ** if they are not used.
121531 */
121532 /* #include "sqliteInt.h" */
 
 
121533
121534 #ifndef SQLITE_OMIT_GET_TABLE
121535
121536 /*
121537 ** This structure is used to pass data from sqlite3_get_table() through
@@ -122591,16 +122885,16 @@
122885 sqlite3ValueFromExpr(sqlite3VdbeDb(v), pCol->pDflt, enc,
122886 pCol->affinity, &pValue);
122887 if( pValue ){
122888 sqlite3VdbeAppendP4(v, pValue, P4_MEM);
122889 }
122890 }
122891 #ifndef SQLITE_OMIT_FLOATING_POINT
122892 if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){
122893 sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg);
122894 }
122895 #endif
 
122896 }
122897
122898 /*
122899 ** Process an UPDATE statement.
122900 **
@@ -122625,11 +122919,11 @@
122919 int nIdx; /* Number of indices that need updating */
122920 int iBaseCur; /* Base cursor number */
122921 int iDataCur; /* Cursor for the canonical data btree */
122922 int iIdxCur; /* Cursor for the first index */
122923 sqlite3 *db; /* The database structure */
122924 int *aRegIdx = 0; /* First register in array assigned to each index */
122925 int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the
122926 ** an expression for the i-th column of the table.
122927 ** aXRef[i]==-1 if the i-th column is not changed. */
122928 u8 *aToOpen; /* 1 for tables and indices to be opened */
122929 u8 chngPk; /* PRIMARY KEY changed in a WITHOUT ROWID table */
@@ -122637,14 +122931,15 @@
122931 u8 chngKey; /* Either chngPk or chngRowid */
122932 Expr *pRowidExpr = 0; /* Expression defining the new record number */
122933 AuthContext sContext; /* The authorization context */
122934 NameContext sNC; /* The name-context to resolve expressions in */
122935 int iDb; /* Database containing the table being updated */
122936 int eOnePass; /* ONEPASS_XXX value from where.c */
122937 int hasFK; /* True if foreign key processing is required */
122938 int labelBreak; /* Jump here to break out of UPDATE loop */
122939 int labelContinue; /* Jump here to continue next step of UPDATE loop */
122940 int flags; /* Flags for sqlite3WhereBegin() */
122941
122942 #ifndef SQLITE_OMIT_TRIGGER
122943 int isView; /* True when updating a view (INSTEAD OF trigger) */
122944 Trigger *pTrigger; /* List of triggers on pTab, if required */
122945 int tmask; /* Mask of TRIGGER_BEFORE|TRIGGER_AFTER */
@@ -122651,10 +122946,14 @@
122946 #endif
122947 int newmask; /* Mask of NEW.* columns accessed by BEFORE triggers */
122948 int iEph = 0; /* Ephemeral table holding all primary key values */
122949 int nKey = 0; /* Number of elements in regKey for WITHOUT ROWID */
122950 int aiCurOnePass[2]; /* The write cursors opened by WHERE_ONEPASS */
122951 int addrOpen = 0; /* Address of OP_OpenEphemeral */
122952 int iPk = 0; /* First of nPk cells holding PRIMARY KEY value */
122953 i16 nPk = 0; /* Number of components of the PRIMARY KEY */
122954 int bReplace = 0; /* True if REPLACE conflict resolution might happen */
122955
122956 /* Register Allocations */
122957 int regRowCount = 0; /* A count of rows changed */
122958 int regOldRowid = 0; /* The old rowid */
122959 int regNewRowid = 0; /* The new rowid */
@@ -122810,17 +123109,27 @@
123109 for(i=0; i<pIdx->nKeyCol; i++){
123110 i16 iIdxCol = pIdx->aiColumn[i];
123111 if( iIdxCol<0 || aXRef[iIdxCol]>=0 ){
123112 reg = ++pParse->nMem;
123113 pParse->nMem += pIdx->nColumn;
123114 if( (onError==OE_Replace)
123115 || (onError==OE_Default && pIdx->onError==OE_Replace)
123116 ){
123117 bReplace = 1;
123118 }
123119 break;
123120 }
123121 }
123122 }
123123 if( reg==0 ) aToOpen[j+1] = 0;
123124 aRegIdx[j] = reg;
123125 }
123126 if( bReplace ){
123127 /* If REPLACE conflict resolution might be invoked, open cursors on all
123128 ** indexes in case they are needed to delete records. */
123129 memset(aToOpen, 1, nIdx+1);
123130 }
123131
123132 /* Begin generating code. */
123133 v = sqlite3GetVdbe(pParse);
123134 if( v==0 ) goto update_cleanup;
123135 if( pParse->nested==0 ) sqlite3VdbeCountChanges(v);
@@ -122869,107 +123178,127 @@
123178 pWhere, onError);
123179 goto update_cleanup;
123180 }
123181 #endif
123182
123183 /* Initialize the count of updated rows */
123184 if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab ){
123185 regRowCount = ++pParse->nMem;
123186 sqlite3VdbeAddOp2(v, OP_Integer, 0, regRowCount);
123187 }
123188
123189 if( HasRowid(pTab) ){
123190 sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123191 }else{
 
 
 
 
123192 assert( pPk!=0 );
123193 nPk = pPk->nKeyCol;
123194 iPk = pParse->nMem+1;
123195 pParse->nMem += nPk;
123196 regKey = ++pParse->nMem;
123197 iEph = pParse->nTab++;
123198
123199 sqlite3VdbeAddOp2(v, OP_Null, 0, iPk);
123200 addrOpen = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEph, nPk);
123201 sqlite3VdbeSetP4KeyInfo(pParse, pPk);
123202 }
123203
123204 /* Begin the database scan.
123205 **
123206 ** Do not consider a single-pass strategy for a multi-row update if
123207 ** there are any triggers or foreign keys to process, or rows may
123208 ** be deleted as a result of REPLACE conflict handling. Any of these
123209 ** things might disturb a cursor being used to scan through the table
123210 ** or index, causing a single-pass approach to malfunction. */
123211 flags = WHERE_ONEPASS_DESIRED|WHERE_SEEK_UNIQ_TABLE;
123212 if( !pParse->nested && !pTrigger && !hasFK && !chngKey && !bReplace ){
123213 flags |= WHERE_ONEPASS_MULTIROW;
123214 }
123215 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, flags, iIdxCur);
123216 if( pWInfo==0 ) goto update_cleanup;
123217
123218 /* A one-pass strategy that might update more than one row may not
123219 ** be used if any column of the index used for the scan is being
123220 ** updated. Otherwise, if there is an index on "b", statements like
123221 ** the following could create an infinite loop:
123222 **
123223 ** UPDATE t1 SET b=b+1 WHERE b>?
123224 **
123225 ** Fall back to ONEPASS_OFF if where.c has selected a ONEPASS_MULTI
123226 ** strategy that uses an index for which one or more columns are being
123227 ** updated. */
123228 eOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
123229 if( eOnePass==ONEPASS_MULTI ){
123230 int iCur = aiCurOnePass[1];
123231 if( iCur>=0 && iCur!=iDataCur && aToOpen[iCur-iBaseCur] ){
123232 eOnePass = ONEPASS_OFF;
123233 }
123234 assert( iCur!=iDataCur || !HasRowid(pTab) );
123235 }
123236
123237 if( HasRowid(pTab) ){
123238 /* Read the rowid of the current row of the WHERE scan. In ONEPASS_OFF
123239 ** mode, write the rowid into the FIFO. In either of the one-pass modes,
123240 ** leave it in register regOldRowid. */
123241 sqlite3VdbeAddOp2(v, OP_Rowid, iDataCur, regOldRowid);
123242 if( eOnePass==ONEPASS_OFF ){
123243 sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, regOldRowid);
123244 }
123245 }else{
123246 /* Read the PK of the current row into an array of registers. In
123247 ** ONEPASS_OFF mode, serialize the array into a record and store it in
123248 ** the ephemeral table. Or, in ONEPASS_SINGLE or MULTI mode, change
123249 ** the OP_OpenEphemeral instruction to a Noop (the ephemeral table
123250 ** is not required) and leave the PK fields in the array of registers. */
123251 for(i=0; i<nPk; i++){
123252 assert( pPk->aiColumn[i]>=0 );
123253 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur,pPk->aiColumn[i],iPk+i);
 
123254 }
123255 if( eOnePass ){
123256 sqlite3VdbeChangeToNoop(v, addrOpen);
123257 nKey = nPk;
123258 regKey = iPk;
123259 }else{
123260 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, regKey,
123261 sqlite3IndexAffinityStr(db, pPk), nPk);
123262 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iEph, regKey, iPk, nPk);
123263 }
 
123264 }
123265
123266 if( eOnePass!=ONEPASS_MULTI ){
123267 sqlite3WhereEnd(pWInfo);
 
 
 
123268 }
123269
123270 labelBreak = sqlite3VdbeMakeLabel(v);
123271 if( !isView ){
123272 int addrOnce = 0;
123273
123274 /* Open every index that needs updating. */
123275 if( eOnePass!=ONEPASS_OFF ){
 
 
 
 
 
 
 
 
 
 
 
 
 
123276 if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iBaseCur] = 0;
123277 if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iBaseCur] = 0;
123278 }
123279
123280 if( eOnePass==ONEPASS_MULTI && (nIdx-(aiCurOnePass[1]>=0))>0 ){
123281 addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
123282 }
123283 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, 0, iBaseCur, aToOpen,
123284 0, 0);
123285 if( addrOnce ) sqlite3VdbeJumpHere(v, addrOnce);
123286 }
123287
123288 /* Top of the update loop */
123289 if( eOnePass!=ONEPASS_OFF ){
123290 if( !isView && aiCurOnePass[0]!=iDataCur && aiCurOnePass[1]!=iDataCur ){
123291 assert( pPk );
123292 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey, nKey);
123293 VdbeCoverageNeverTaken(v);
123294 }
123295 if( eOnePass==ONEPASS_SINGLE ){
123296 labelContinue = labelBreak;
123297 }else{
123298 labelContinue = sqlite3VdbeMakeLabel(v);
123299 }
123300 sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak);
123301 VdbeCoverageIf(v, pPk==0);
123302 VdbeCoverageIf(v, pPk!=0);
123303 }else if( pPk ){
123304 labelContinue = sqlite3VdbeMakeLabel(v);
@@ -123090,11 +123419,10 @@
123419 }
123420 }
123421
123422 if( !isView ){
123423 int addr1 = 0; /* Address of jump instruction */
 
123424
123425 /* Do constraint checks. */
123426 assert( regOldRowid>0 );
123427 sqlite3GenerateConstraintChecks(pParse, pTab, aRegIdx, iDataCur, iIdxCur,
123428 regNewRowid, regOldRowid, chngKey, onError, labelContinue, &bReplace,
@@ -123126,18 +123454,22 @@
123454 ** is the column index supplied by the user.
123455 */
123456 assert( regNew==regNewRowid+1 );
123457 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
123458 sqlite3VdbeAddOp3(v, OP_Delete, iDataCur,
123459 OPFLAG_ISUPDATE | ((hasFK || chngKey) ? 0 : OPFLAG_ISNOOP),
123460 regNewRowid
123461 );
123462 if( eOnePass==ONEPASS_MULTI ){
123463 assert( hasFK==0 && chngKey==0 );
123464 sqlite3VdbeChangeP5(v, OPFLAG_SAVEPOSITION);
123465 }
123466 if( !pParse->nested ){
123467 sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
123468 }
123469 #else
123470 if( hasFK || chngKey ){
123471 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0);
123472 }
123473 #endif
123474 if( bReplace || chngKey ){
123475 sqlite3VdbeJumpHere(v, addr1);
@@ -123146,12 +123478,15 @@
123478 if( hasFK ){
123479 sqlite3FkCheck(pParse, pTab, 0, regNewRowid, aXRef, chngKey);
123480 }
123481
123482 /* Insert the new index entries and the new record. */
123483 sqlite3CompleteInsertion(
123484 pParse, pTab, iDataCur, iIdxCur, regNewRowid, aRegIdx,
123485 OPFLAG_ISUPDATE | (eOnePass==ONEPASS_MULTI ? OPFLAG_SAVEPOSITION : 0),
123486 0, 0
123487 );
123488
123489 /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
123490 ** handle rows (possibly in other tables) that refer via a foreign key
123491 ** to the row just updated. */
123492 if( hasFK ){
@@ -123169,12 +123504,15 @@
123504 TRIGGER_AFTER, pTab, regOldRowid, onError, labelContinue);
123505
123506 /* Repeat the above with the next record to be updated, until
123507 ** all record selected by the WHERE clause have been updated.
123508 */
123509 if( eOnePass==ONEPASS_SINGLE ){
123510 /* Nothing to do at end-of-loop for a single-pass */
123511 }else if( eOnePass==ONEPASS_MULTI ){
123512 sqlite3VdbeResolveLabel(v, labelContinue);
123513 sqlite3WhereEnd(pWInfo);
123514 }else if( pPk ){
123515 sqlite3VdbeResolveLabel(v, labelContinue);
123516 sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop); VdbeCoverage(v);
123517 }else{
123518 sqlite3VdbeGoto(v, labelContinue);
@@ -127090,11 +127428,14 @@
127428
127429 /* Seek the table cursor, if required */
127430 if( omitTable ){
127431 /* pIdx is a covering index. No need to access the main table. */
127432 }else if( HasRowid(pIdx->pTable) ){
127433 if( (pWInfo->wctrlFlags & WHERE_SEEK_TABLE) || (
127434 (pWInfo->wctrlFlags & WHERE_SEEK_UNIQ_TABLE)
127435 && (pWInfo->eOnePass==ONEPASS_SINGLE)
127436 )){
127437 iRowidReg = ++pParse->nMem;
127438 sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
127439 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
127440 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, iRowidReg);
127441 VdbeCoverage(v);
@@ -128454,10 +128795,11 @@
128795 int noCase = 0; /* uppercase equivalent to lowercase */
128796 int op; /* Top-level operator. pExpr->op */
128797 Parse *pParse = pWInfo->pParse; /* Parsing context */
128798 sqlite3 *db = pParse->db; /* Database connection */
128799 unsigned char eOp2; /* op2 value for LIKE/REGEXP/GLOB */
128800 int nLeft; /* Number of elements on left side vector */
128801
128802 if( db->mallocFailed ){
128803 return;
128804 }
128805 pTerm = &pWC->a[idxTerm];
@@ -128483,10 +128825,14 @@
128825 if( ExprHasProperty(pExpr, EP_FromJoin) ){
128826 Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->iRightJoinTable);
128827 prereqAll |= x;
128828 extraRight = x-1; /* ON clause terms may not be used with an index
128829 ** on left table of a LEFT JOIN. Ticket #3015 */
128830 if( (prereqAll>>1)>=x ){
128831 sqlite3ErrorMsg(pParse, "ON clause references tables to its right");
128832 return;
128833 }
128834 }
128835 pTerm->prereqAll = prereqAll;
128836 pTerm->leftCursor = -1;
128837 pTerm->iParent = -1;
128838 pTerm->eOperator = 0;
@@ -128725,17 +129071,16 @@
129071 **
129072 ** This is only required if at least one side of the comparison operation
129073 ** is not a sub-select. */
129074 if( pWC->op==TK_AND
129075 && (pExpr->op==TK_EQ || pExpr->op==TK_IS)
129076 && (nLeft = sqlite3ExprVectorSize(pExpr->pLeft))>1
129077 && sqlite3ExprVectorSize(pExpr->pRight)==nLeft
129078 && ( (pExpr->pLeft->flags & EP_xIsSelect)==0
129079 || (pExpr->pRight->flags & EP_xIsSelect)==0)
129080 ){
 
129081 int i;
 
129082 for(i=0; i<nLeft; i++){
129083 int idxNew;
129084 Expr *pNew;
129085 Expr *pLeft = sqlite3ExprForVectorField(pParse, pExpr->pLeft, i);
129086 Expr *pRight = sqlite3ExprForVectorField(pParse, pExpr->pRight, i);
@@ -129293,10 +129638,11 @@
129638 if( pIdx ){
129639 int j = iColumn;
129640 iColumn = pIdx->aiColumn[j];
129641 if( iColumn==XN_EXPR ){
129642 pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr;
129643 pScan->zCollName = pIdx->azColl[j];
129644 }else if( iColumn==pIdx->pTable->iPKey ){
129645 iColumn = XN_ROWID;
129646 }else if( iColumn>=0 ){
129647 pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity;
129648 pScan->zCollName = pIdx->azColl[j];
@@ -133934,11 +134280,12 @@
134280 x = sqlite3ColumnOfIndex(pIdx, x);
134281 if( x>=0 ){
134282 pOp->p2 = x;
134283 pOp->p1 = pLevel->iIdxCur;
134284 }
134285 assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0
134286 || pWInfo->eOnePass );
134287 }else if( pOp->opcode==OP_Rowid ){
134288 pOp->p1 = pLevel->iIdxCur;
134289 pOp->opcode = OP_IdxRowid;
134290 }
134291 }
@@ -133998,10 +134345,23 @@
134345 ** Indicate that sqlite3ParserFree() will never be called with a null
134346 ** pointer.
134347 */
134348 #define YYPARSEFREENEVERNULL 1
134349
134350 /*
134351 ** In the amalgamation, the parse.c file generated by lemon and the
134352 ** tokenize.c file are concatenated. In that case, sqlite3RunParser()
134353 ** has access to the the size of the yyParser object and so the parser
134354 ** engine can be allocated from stack. In that case, only the
134355 ** sqlite3ParserInit() and sqlite3ParserFinalize() routines are invoked
134356 ** and the sqlite3ParserAlloc() and sqlite3ParserFree() routines can be
134357 ** omitted.
134358 */
134359 #ifdef SQLITE_AMALGAMATION
134360 # define sqlite3Parser_ENGINEALWAYSONSTACK 1
134361 #endif
134362
134363 /*
134364 ** Alternative datatype for the argument to the malloc() routine passed
134365 ** into sqlite3ParserAlloc(). The default is size_t.
134366 */
134367 #define YYMALLOCARGTYPE u64
@@ -135446,10 +135806,35 @@
135806 */
135807 #ifndef YYMALLOCARGTYPE
135808 # define YYMALLOCARGTYPE size_t
135809 #endif
135810
135811 /* Initialize a new parser that has already been allocated.
135812 */
135813 SQLITE_PRIVATE void sqlite3ParserInit(void *yypParser){
135814 yyParser *pParser = (yyParser*)yypParser;
135815 #ifdef YYTRACKMAXSTACKDEPTH
135816 pParser->yyhwm = 0;
135817 #endif
135818 #if YYSTACKDEPTH<=0
135819 pParser->yytos = NULL;
135820 pParser->yystack = NULL;
135821 pParser->yystksz = 0;
135822 if( yyGrowStack(pParser) ){
135823 pParser->yystack = &pParser->yystk0;
135824 pParser->yystksz = 1;
135825 }
135826 #endif
135827 #ifndef YYNOERRORRECOVERY
135828 pParser->yyerrcnt = -1;
135829 #endif
135830 pParser->yytos = pParser->yystack;
135831 pParser->yystack[0].stateno = 0;
135832 pParser->yystack[0].major = 0;
135833 }
135834
135835 #ifndef sqlite3Parser_ENGINEALWAYSONSTACK
135836 /*
135837 ** This function allocates a new parser.
135838 ** The only argument is a pointer to a function which works like
135839 ** malloc.
135840 **
@@ -135461,32 +135846,15 @@
135846 ** to sqlite3Parser and sqlite3ParserFree.
135847 */
135848 SQLITE_PRIVATE void *sqlite3ParserAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){
135849 yyParser *pParser;
135850 pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) );
135851 if( pParser ) sqlite3ParserInit(pParser);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135852 return pParser;
135853 }
135854 #endif /* sqlite3Parser_ENGINEALWAYSONSTACK */
135855
135856
135857 /* The following function deletes the "minor type" or semantic value
135858 ** associated with a symbol. The symbol can be either a terminal
135859 ** or nonterminal. "yymajor" is the symbol code, and "yypminor" is
135860 ** a pointer to the value to be deleted. The code used to do the
@@ -135608,10 +135976,22 @@
135976 }
135977 #endif
135978 yy_destructor(pParser, yytos->major, &yytos->minor);
135979 }
135980
135981 /*
135982 ** Clear all secondary memory allocations from the parser
135983 */
135984 SQLITE_PRIVATE void sqlite3ParserFinalize(void *p){
135985 yyParser *pParser = (yyParser*)p;
135986 while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser);
135987 #if YYSTACKDEPTH<=0
135988 if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack);
135989 #endif
135990 }
135991
135992 #ifndef sqlite3Parser_ENGINEALWAYSONSTACK
135993 /*
135994 ** Deallocate and destroy a parser. Destructors are called for
135995 ** all stack elements before shutting the parser down.
135996 **
135997 ** If the YYPARSEFREENEVERNULL macro exists (for example because it
@@ -135620,20 +136000,17 @@
136000 */
136001 SQLITE_PRIVATE void sqlite3ParserFree(
136002 void *p, /* The parser to be deleted */
136003 void (*freeProc)(void*) /* Function used to reclaim memory */
136004 ){
 
136005 #ifndef YYPARSEFREENEVERNULL
136006 if( p==0 ) return;
136007 #endif
136008 sqlite3ParserFinalize(p);
136009 (*freeProc)(p);
136010 }
136011 #endif /* sqlite3Parser_ENGINEALWAYSONSTACK */
 
 
136012
136013 /*
136014 ** Return the peak depth of the stack for a parser.
136015 */
136016 #ifdef YYTRACKMAXSTACKDEPTH
@@ -138483,10 +138860,13 @@
138860 void *pEngine; /* The LEMON-generated LALR(1) parser */
138861 int tokenType; /* type of the next token */
138862 int lastTokenParsed = -1; /* type of the previous token */
138863 sqlite3 *db = pParse->db; /* The database connection */
138864 int mxSqlLen; /* Max length of an SQL string */
138865 #ifdef sqlite3Parser_ENGINEALWAYSONSTACK
138866 unsigned char zSpace[sizeof(yyParser)]; /* Space for parser engine object */
138867 #endif
138868
138869 assert( zSql!=0 );
138870 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
138871 if( db->nVdbeActive==0 ){
138872 db->u1.isInterrupted = 0;
@@ -138494,15 +138874,20 @@
138874 pParse->rc = SQLITE_OK;
138875 pParse->zTail = zSql;
138876 i = 0;
138877 assert( pzErrMsg!=0 );
138878 /* sqlite3ParserTrace(stdout, "parser: "); */
138879 #ifdef sqlite3Parser_ENGINEALWAYSONSTACK
138880 pEngine = zSpace;
138881 sqlite3ParserInit(pEngine);
138882 #else
138883 pEngine = sqlite3ParserAlloc(sqlite3Malloc);
138884 if( pEngine==0 ){
138885 sqlite3OomFault(db);
138886 return SQLITE_NOMEM_BKPT;
138887 }
138888 #endif
138889 assert( pParse->pNewTable==0 );
138890 assert( pParse->pNewTrigger==0 );
138891 assert( pParse->nVar==0 );
138892 assert( pParse->pVList==0 );
138893 while( 1 ){
@@ -138550,11 +138935,15 @@
138935 sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK,
138936 sqlite3ParserStackPeak(pEngine)
138937 );
138938 sqlite3_mutex_leave(sqlite3MallocMutex());
138939 #endif /* YYDEBUG */
138940 #ifdef sqlite3Parser_ENGINEALWAYSONSTACK
138941 sqlite3ParserFinalize(pEngine);
138942 #else
138943 sqlite3ParserFree(pEngine, sqlite3_free);
138944 #endif
138945 if( db->mallocFailed ){
138946 pParse->rc = SQLITE_NOMEM_BKPT;
138947 }
138948 if( pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE && pParse->zErrMsg==0 ){
138949 pParse->zErrMsg = sqlite3MPrintf(db, "%s", sqlite3ErrStr(pParse->rc));
@@ -144213,10 +144602,11 @@
144602
144603 /* Precompiled statements used by the implementation. Each of these
144604 ** statements is run and reset within a single virtual table API call.
144605 */
144606 sqlite3_stmt *aStmt[40];
144607 sqlite3_stmt *pSeekStmt; /* Cache for fts3CursorSeekStmt() */
144608
144609 char *zReadExprlist;
144610 char *zWriteExprlist;
144611
144612 int nNodeSize; /* Soft limit for node size */
@@ -144282,10 +144672,11 @@
144672 struct Fts3Cursor {
144673 sqlite3_vtab_cursor base; /* Base class used by SQLite core */
144674 i16 eSearch; /* Search strategy (see below) */
144675 u8 isEof; /* True if at End Of Results */
144676 u8 isRequireSeek; /* True if must seek pStmt to %_content row */
144677 u8 bSeekStmt; /* True if pStmt is a seek */
144678 sqlite3_stmt *pStmt; /* Prepared statement in use by the cursor */
144679 Fts3Expr *pExpr; /* Parsed MATCH query string */
144680 int iLangid; /* Language being queried for */
144681 int nPhrase; /* Number of matchable phrases in query */
144682 Fts3DeferredToken *pDeferred; /* Deferred search tokens, if any */
@@ -144804,10 +145195,11 @@
145195
145196 assert( p->nPendingData==0 );
145197 assert( p->pSegments==0 );
145198
145199 /* Free any prepared statements held */
145200 sqlite3_finalize(p->pSeekStmt);
145201 for(i=0; i<SizeofArray(p->aStmt); i++){
145202 sqlite3_finalize(p->aStmt[i]);
145203 }
145204 sqlite3_free(p->zSegmentsTbl);
145205 sqlite3_free(p->zReadExprlist);
@@ -145675,13 +146067,13 @@
146067 p->nPendingData = 0;
146068 p->azColumn = (char **)&p[1];
146069 p->pTokenizer = pTokenizer;
146070 p->nMaxPendingData = FTS3_MAX_PENDING_DATA;
146071 p->bHasDocsize = (isFts4 && bNoDocsize==0);
146072 p->bHasStat = (u8)isFts4;
146073 p->bFts4 = (u8)isFts4;
146074 p->bDescIdx = (u8)bDescIdx;
146075 p->nAutoincrmerge = 0xff; /* 0xff means setting unknown */
146076 p->zContentTbl = zContent;
146077 p->zLanguageid = zLanguageid;
146078 zContent = 0;
146079 zLanguageid = 0;
@@ -145991,19 +146383,39 @@
146383 return SQLITE_NOMEM;
146384 }
146385 memset(pCsr, 0, sizeof(Fts3Cursor));
146386 return SQLITE_OK;
146387 }
146388
146389 /*
146390 ** Finalize the statement handle at pCsr->pStmt.
146391 **
146392 ** Or, if that statement handle is one created by fts3CursorSeekStmt(),
146393 ** and the Fts3Table.pSeekStmt slot is currently NULL, save the statement
146394 ** pointer there instead of finalizing it.
146395 */
146396 static void fts3CursorFinalizeStmt(Fts3Cursor *pCsr){
146397 if( pCsr->bSeekStmt ){
146398 Fts3Table *p = (Fts3Table *)pCsr->base.pVtab;
146399 if( p->pSeekStmt==0 ){
146400 p->pSeekStmt = pCsr->pStmt;
146401 sqlite3_reset(pCsr->pStmt);
146402 pCsr->pStmt = 0;
146403 }
146404 pCsr->bSeekStmt = 0;
146405 }
146406 sqlite3_finalize(pCsr->pStmt);
146407 }
146408
146409 /*
146410 ** Close the cursor. For additional information see the documentation
146411 ** on the xClose method of the virtual table interface.
146412 */
146413 static int fts3CloseMethod(sqlite3_vtab_cursor *pCursor){
146414 Fts3Cursor *pCsr = (Fts3Cursor *)pCursor;
146415 assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
146416 fts3CursorFinalizeStmt(pCsr);
146417 sqlite3Fts3ExprFree(pCsr->pExpr);
146418 sqlite3Fts3FreeDeferredTokens(pCsr);
146419 sqlite3_free(pCsr->aDoclist);
146420 sqlite3Fts3MIBufferFree(pCsr->pMIBuffer);
146421 assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
@@ -146017,24 +146429,27 @@
146429 **
146430 ** "SELECT <columns> FROM %_content WHERE rowid = ?"
146431 **
146432 ** (or the equivalent for a content=xxx table) and set pCsr->pStmt to
146433 ** it. If an error occurs, return an SQLite error code.
 
 
146434 */
146435 static int fts3CursorSeekStmt(Fts3Cursor *pCsr){
146436 int rc = SQLITE_OK;
146437 if( pCsr->pStmt==0 ){
146438 Fts3Table *p = (Fts3Table *)pCsr->base.pVtab;
146439 char *zSql;
146440 if( p->pSeekStmt ){
146441 pCsr->pStmt = p->pSeekStmt;
146442 p->pSeekStmt = 0;
146443 }else{
146444 zSql = sqlite3_mprintf("SELECT %s WHERE rowid = ?", p->zReadExprlist);
146445 if( !zSql ) return SQLITE_NOMEM;
146446 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0);
146447 sqlite3_free(zSql);
146448 }
146449 if( rc==SQLITE_OK ) pCsr->bSeekStmt = 1;
146450 }
 
146451 return rc;
146452 }
146453
146454 /*
146455 ** Position the pCsr->pStmt statement so that it is on the row
@@ -146042,13 +146457,11 @@
146457 ** SQLITE_OK on success.
146458 */
146459 static int fts3CursorSeek(sqlite3_context *pContext, Fts3Cursor *pCsr){
146460 int rc = SQLITE_OK;
146461 if( pCsr->isRequireSeek ){
146462 rc = fts3CursorSeekStmt(pCsr);
 
 
146463 if( rc==SQLITE_OK ){
146464 sqlite3_bind_int64(pCsr->pStmt, 1, pCsr->iPrevId);
146465 pCsr->isRequireSeek = 0;
146466 if( SQLITE_ROW==sqlite3_step(pCsr->pStmt) ){
146467 return SQLITE_OK;
@@ -147502,11 +147915,11 @@
147915 if( idxNum & FTS3_HAVE_DOCID_GE ) pDocidGe = apVal[iIdx++];
147916 if( idxNum & FTS3_HAVE_DOCID_LE ) pDocidLe = apVal[iIdx++];
147917 assert( iIdx==nVal );
147918
147919 /* In case the cursor has been used before, clear it now. */
147920 fts3CursorFinalizeStmt(pCsr);
147921 sqlite3_free(pCsr->aDoclist);
147922 sqlite3Fts3MIBufferFree(pCsr->pMIBuffer);
147923 sqlite3Fts3ExprFree(pCsr->pExpr);
147924 memset(&pCursor[1], 0, sizeof(Fts3Cursor)-sizeof(sqlite3_vtab_cursor));
147925
@@ -147570,11 +147983,11 @@
147983 sqlite3_free(zSql);
147984 }else{
147985 rc = SQLITE_NOMEM;
147986 }
147987 }else if( eSearch==FTS3_DOCID_SEARCH ){
147988 rc = fts3CursorSeekStmt(pCsr);
147989 if( rc==SQLITE_OK ){
147990 rc = sqlite3_bind_value(pCsr->pStmt, 1, pCons);
147991 }
147992 }
147993 if( rc!=SQLITE_OK ) return rc;
@@ -147734,11 +148147,11 @@
148147 sqlite3_stmt *pStmt = 0;
148148 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
148149 if( rc==SQLITE_OK ){
148150 int bHasStat = (sqlite3_step(pStmt)==SQLITE_ROW);
148151 rc = sqlite3_finalize(pStmt);
148152 if( rc==SQLITE_OK ) p->bHasStat = (u8)bHasStat;
148153 }
148154 sqlite3_free(zSql);
148155 }else{
148156 rc = SQLITE_NOMEM;
148157 }
@@ -162590,10 +163003,11 @@
163003 /* #include <stdio.h> */
163004
163005 #ifndef SQLITE_AMALGAMATION
163006 #include "sqlite3rtree.h"
163007 typedef sqlite3_int64 i64;
163008 typedef sqlite3_uint64 u64;
163009 typedef unsigned char u8;
163010 typedef unsigned short u16;
163011 typedef unsigned int u32;
163012 #endif
163013
@@ -162638,28 +163052,33 @@
163052 struct Rtree {
163053 sqlite3_vtab base; /* Base class. Must be first */
163054 sqlite3 *db; /* Host database connection */
163055 int iNodeSize; /* Size in bytes of each node in the node table */
163056 u8 nDim; /* Number of dimensions */
163057 u8 nDim2; /* Twice the number of dimensions */
163058 u8 eCoordType; /* RTREE_COORD_REAL32 or RTREE_COORD_INT32 */
163059 u8 nBytesPerCell; /* Bytes consumed per cell */
163060 u8 inWrTrans; /* True if inside write transaction */
163061 int iDepth; /* Current depth of the r-tree structure */
163062 char *zDb; /* Name of database containing r-tree table */
163063 char *zName; /* Name of r-tree table */
163064 u32 nBusy; /* Current number of users of this structure */
163065 i64 nRowEst; /* Estimated number of rows in this table */
163066 u32 nCursor; /* Number of open cursors */
163067
163068 /* List of nodes removed during a CondenseTree operation. List is
163069 ** linked together via the pointer normally used for hash chains -
163070 ** RtreeNode.pNext. RtreeNode.iNode stores the depth of the sub-tree
163071 ** headed by the node (leaf nodes have RtreeNode.iNode==0).
163072 */
163073 RtreeNode *pDeleted;
163074 int iReinsertHeight; /* Height of sub-trees Reinsert() has run on */
163075
163076 /* Blob I/O on xxx_node */
163077 sqlite3_blob *pNodeBlob;
163078
163079 /* Statements to read/write/delete a record from xxx_node */
 
163080 sqlite3_stmt *pWriteNode;
163081 sqlite3_stmt *pDeleteNode;
163082
163083 /* Statements to read/write/delete a record from xxx_rowid */
163084 sqlite3_stmt *pReadRowid;
@@ -162884,26 +163303,100 @@
163303 #endif
163304 #ifndef MIN
163305 # define MIN(x,y) ((x) > (y) ? (y) : (x))
163306 #endif
163307
163308 /* What version of GCC is being used. 0 means GCC is not being used .
163309 ** Note that the GCC_VERSION macro will also be set correctly when using
163310 ** clang, since clang works hard to be gcc compatible. So the gcc
163311 ** optimizations will also work when compiling with clang.
163312 */
163313 #ifndef GCC_VERSION
163314 #if defined(__GNUC__) && !defined(SQLITE_DISABLE_INTRINSIC)
163315 # define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__)
163316 #else
163317 # define GCC_VERSION 0
163318 #endif
163319 #endif
163320
163321 /* The testcase() macro should already be defined in the amalgamation. If
163322 ** it is not, make it a no-op.
163323 */
163324 #ifndef SQLITE_AMALGAMATION
163325 # define testcase(X)
163326 #endif
163327
163328 /*
163329 ** Macros to determine whether the machine is big or little endian,
163330 ** and whether or not that determination is run-time or compile-time.
163331 **
163332 ** For best performance, an attempt is made to guess at the byte-order
163333 ** using C-preprocessor macros. If that is unsuccessful, or if
163334 ** -DSQLITE_RUNTIME_BYTEORDER=1 is set, then byte-order is determined
163335 ** at run-time.
163336 */
163337 #ifndef SQLITE_BYTEORDER
163338 #if defined(i386) || defined(__i386__) || defined(_M_IX86) || \
163339 defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \
163340 defined(_M_AMD64) || defined(_M_ARM) || defined(__x86) || \
163341 defined(__arm__)
163342 # define SQLITE_BYTEORDER 1234
163343 #elif defined(sparc) || defined(__ppc__)
163344 # define SQLITE_BYTEORDER 4321
163345 #else
163346 # define SQLITE_BYTEORDER 0 /* 0 means "unknown at compile-time" */
163347 #endif
163348 #endif
163349
163350
163351 /* What version of MSVC is being used. 0 means MSVC is not being used */
163352 #ifndef MSVC_VERSION
163353 #if defined(_MSC_VER) && !defined(SQLITE_DISABLE_INTRINSIC)
163354 # define MSVC_VERSION _MSC_VER
163355 #else
163356 # define MSVC_VERSION 0
163357 #endif
163358 #endif
163359
163360 /*
163361 ** Functions to deserialize a 16 bit integer, 32 bit real number and
163362 ** 64 bit integer. The deserialized value is returned.
163363 */
163364 static int readInt16(u8 *p){
163365 return (p[0]<<8) + p[1];
163366 }
163367 static void readCoord(u8 *p, RtreeCoord *pCoord){
163368 assert( ((((char*)p) - (char*)0)&3)==0 ); /* p is always 4-byte aligned */
163369 #if SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
163370 pCoord->u = _byteswap_ulong(*(u32*)p);
163371 #elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
163372 pCoord->u = __builtin_bswap32(*(u32*)p);
163373 #elif SQLITE_BYTEORDER==4321
163374 pCoord->u = *(u32*)p;
163375 #else
163376 pCoord->u = (
163377 (((u32)p[0]) << 24) +
163378 (((u32)p[1]) << 16) +
163379 (((u32)p[2]) << 8) +
163380 (((u32)p[3]) << 0)
163381 );
163382 #endif
163383 }
163384 static i64 readInt64(u8 *p){
163385 #if SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
163386 u64 x;
163387 memcpy(&x, p, 8);
163388 return (i64)_byteswap_uint64(x);
163389 #elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
163390 u64 x;
163391 memcpy(&x, p, 8);
163392 return (i64)__builtin_bswap64(x);
163393 #elif SQLITE_BYTEORDER==4321
163394 i64 x;
163395 memcpy(&x, p, 8);
163396 return x;
163397 #else
163398 return (
163399 (((i64)p[0]) << 56) +
163400 (((i64)p[1]) << 48) +
163401 (((i64)p[2]) << 40) +
163402 (((i64)p[3]) << 32) +
@@ -162910,42 +163403,64 @@
163403 (((i64)p[4]) << 24) +
163404 (((i64)p[5]) << 16) +
163405 (((i64)p[6]) << 8) +
163406 (((i64)p[7]) << 0)
163407 );
163408 #endif
163409 }
163410
163411 /*
163412 ** Functions to serialize a 16 bit integer, 32 bit real number and
163413 ** 64 bit integer. The value returned is the number of bytes written
163414 ** to the argument buffer (always 2, 4 and 8 respectively).
163415 */
163416 static void writeInt16(u8 *p, int i){
163417 p[0] = (i>> 8)&0xFF;
163418 p[1] = (i>> 0)&0xFF;
 
163419 }
163420 static int writeCoord(u8 *p, RtreeCoord *pCoord){
163421 u32 i;
163422 assert( ((((char*)p) - (char*)0)&3)==0 ); /* p is always 4-byte aligned */
163423 assert( sizeof(RtreeCoord)==4 );
163424 assert( sizeof(u32)==4 );
163425 #if SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
163426 i = __builtin_bswap32(pCoord->u);
163427 memcpy(p, &i, 4);
163428 #elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
163429 i = _byteswap_ulong(pCoord->u);
163430 memcpy(p, &i, 4);
163431 #elif SQLITE_BYTEORDER==4321
163432 i = pCoord->u;
163433 memcpy(p, &i, 4);
163434 #else
163435 i = pCoord->u;
163436 p[0] = (i>>24)&0xFF;
163437 p[1] = (i>>16)&0xFF;
163438 p[2] = (i>> 8)&0xFF;
163439 p[3] = (i>> 0)&0xFF;
163440 #endif
163441 return 4;
163442 }
163443 static int writeInt64(u8 *p, i64 i){
163444 #if SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
163445 i = (i64)__builtin_bswap64((u64)i);
163446 memcpy(p, &i, 8);
163447 #elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
163448 i = (i64)_byteswap_uint64((u64)i);
163449 memcpy(p, &i, 8);
163450 #elif SQLITE_BYTEORDER==4321
163451 memcpy(p, &i, 8);
163452 #else
163453 p[0] = (i>>56)&0xFF;
163454 p[1] = (i>>48)&0xFF;
163455 p[2] = (i>>40)&0xFF;
163456 p[3] = (i>>32)&0xFF;
163457 p[4] = (i>>24)&0xFF;
163458 p[5] = (i>>16)&0xFF;
163459 p[6] = (i>> 8)&0xFF;
163460 p[7] = (i>> 0)&0xFF;
163461 #endif
163462 return 8;
163463 }
163464
163465 /*
163466 ** Increment the reference count of node p.
@@ -163023,10 +163538,21 @@
163538 pNode->isDirty = 1;
163539 nodeReference(pParent);
163540 }
163541 return pNode;
163542 }
163543
163544 /*
163545 ** Clear the Rtree.pNodeBlob object
163546 */
163547 static void nodeBlobReset(Rtree *pRtree){
163548 if( pRtree->pNodeBlob && pRtree->inWrTrans==0 && pRtree->nCursor==0 ){
163549 sqlite3_blob *pBlob = pRtree->pNodeBlob;
163550 pRtree->pNodeBlob = 0;
163551 sqlite3_blob_close(pBlob);
163552 }
163553 }
163554
163555 /*
163556 ** Obtain a reference to an r-tree node.
163557 */
163558 static int nodeAcquire(
@@ -163033,13 +163559,12 @@
163559 Rtree *pRtree, /* R-tree structure */
163560 i64 iNode, /* Node number to load */
163561 RtreeNode *pParent, /* Either the parent node or NULL */
163562 RtreeNode **ppNode /* OUT: Acquired node */
163563 ){
163564 int rc = SQLITE_OK;
163565 RtreeNode *pNode = 0;
 
163566
163567 /* Check if the requested node is already in the hash table. If so,
163568 ** increase its reference count and return it.
163569 */
163570 if( (pNode = nodeHashLookup(pRtree, iNode)) ){
@@ -163051,32 +163576,49 @@
163576 pNode->nRef++;
163577 *ppNode = pNode;
163578 return SQLITE_OK;
163579 }
163580
163581 if( pRtree->pNodeBlob ){
163582 sqlite3_blob *pBlob = pRtree->pNodeBlob;
163583 pRtree->pNodeBlob = 0;
163584 rc = sqlite3_blob_reopen(pBlob, iNode);
163585 pRtree->pNodeBlob = pBlob;
163586 if( rc ){
163587 nodeBlobReset(pRtree);
163588 if( rc==SQLITE_NOMEM ) return SQLITE_NOMEM;
163589 }
163590 }
163591 if( pRtree->pNodeBlob==0 ){
163592 char *zTab = sqlite3_mprintf("%s_node", pRtree->zName);
163593 if( zTab==0 ) return SQLITE_NOMEM;
163594 rc = sqlite3_blob_open(pRtree->db, pRtree->zDb, zTab, "data", iNode, 0,
163595 &pRtree->pNodeBlob);
163596 sqlite3_free(zTab);
163597 }
163598 if( rc ){
163599 nodeBlobReset(pRtree);
163600 *ppNode = 0;
163601 /* If unable to open an sqlite3_blob on the desired row, that can only
163602 ** be because the shadow tables hold erroneous data. */
163603 if( rc==SQLITE_ERROR ) rc = SQLITE_CORRUPT_VTAB;
163604 }else if( pRtree->iNodeSize==sqlite3_blob_bytes(pRtree->pNodeBlob) ){
163605 pNode = (RtreeNode *)sqlite3_malloc(sizeof(RtreeNode)+pRtree->iNodeSize);
163606 if( !pNode ){
163607 rc = SQLITE_NOMEM;
163608 }else{
163609 pNode->pParent = pParent;
163610 pNode->zData = (u8 *)&pNode[1];
163611 pNode->nRef = 1;
163612 pNode->iNode = iNode;
163613 pNode->isDirty = 0;
163614 pNode->pNext = 0;
163615 rc = sqlite3_blob_read(pRtree->pNodeBlob, pNode->zData,
163616 pRtree->iNodeSize, 0);
163617 nodeReference(pParent);
163618 }
163619 }
163620
163621 /* If the root node was just loaded, set pRtree->iDepth to the height
163622 ** of the r-tree structure. A height of zero means all data is stored on
163623 ** the root node. A height of one means the children of the root node
163624 ** are the leaves, and so on. If the depth as specified on the root node
@@ -163124,11 +163666,11 @@
163666 int iCell /* Index into pNode into which pCell is written */
163667 ){
163668 int ii;
163669 u8 *p = &pNode->zData[4 + pRtree->nBytesPerCell*iCell];
163670 p += writeInt64(p, pCell->iRowid);
163671 for(ii=0; ii<pRtree->nDim2; ii++){
163672 p += writeCoord(p, &pCell->aCoord[ii]);
163673 }
163674 pNode->isDirty = 1;
163675 }
163676
@@ -163258,17 +163800,20 @@
163800 int iCell, /* Index of the cell within the node */
163801 RtreeCell *pCell /* OUT: Write the cell contents here */
163802 ){
163803 u8 *pData;
163804 RtreeCoord *pCoord;
163805 int ii = 0;
163806 pCell->iRowid = nodeGetRowid(pRtree, pNode, iCell);
163807 pData = pNode->zData + (12 + pRtree->nBytesPerCell*iCell);
163808 pCoord = pCell->aCoord;
163809 do{
163810 readCoord(pData, &pCoord[ii]);
163811 readCoord(pData+4, &pCoord[ii+1]);
163812 pData += 8;
163813 ii += 2;
163814 }while( ii<pRtree->nDim2 );
163815 }
163816
163817
163818 /* Forward declaration for the function that does the work of
163819 ** the virtual table module xCreate() and xConnect() methods.
@@ -163315,11 +163860,13 @@
163860 ** zero the structure is deleted.
163861 */
163862 static void rtreeRelease(Rtree *pRtree){
163863 pRtree->nBusy--;
163864 if( pRtree->nBusy==0 ){
163865 pRtree->inWrTrans = 0;
163866 pRtree->nCursor = 0;
163867 nodeBlobReset(pRtree);
163868 sqlite3_finalize(pRtree->pWriteNode);
163869 sqlite3_finalize(pRtree->pDeleteNode);
163870 sqlite3_finalize(pRtree->pReadRowid);
163871 sqlite3_finalize(pRtree->pWriteRowid);
163872 sqlite3_finalize(pRtree->pDeleteRowid);
@@ -163353,10 +163900,11 @@
163900 pRtree->zDb, pRtree->zName
163901 );
163902 if( !zCreate ){
163903 rc = SQLITE_NOMEM;
163904 }else{
163905 nodeBlobReset(pRtree);
163906 rc = sqlite3_exec(pRtree->db, zCreate, 0, 0, 0);
163907 sqlite3_free(zCreate);
163908 }
163909 if( rc==SQLITE_OK ){
163910 rtreeRelease(pRtree);
@@ -163368,17 +163916,19 @@
163916 /*
163917 ** Rtree virtual table module xOpen method.
163918 */
163919 static int rtreeOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
163920 int rc = SQLITE_NOMEM;
163921 Rtree *pRtree = (Rtree *)pVTab;
163922 RtreeCursor *pCsr;
163923
163924 pCsr = (RtreeCursor *)sqlite3_malloc(sizeof(RtreeCursor));
163925 if( pCsr ){
163926 memset(pCsr, 0, sizeof(RtreeCursor));
163927 pCsr->base.pVtab = pVTab;
163928 rc = SQLITE_OK;
163929 pRtree->nCursor++;
163930 }
163931 *ppCursor = (sqlite3_vtab_cursor *)pCsr;
163932
163933 return rc;
163934 }
@@ -163407,14 +163957,17 @@
163957 */
163958 static int rtreeClose(sqlite3_vtab_cursor *cur){
163959 Rtree *pRtree = (Rtree *)(cur->pVtab);
163960 int ii;
163961 RtreeCursor *pCsr = (RtreeCursor *)cur;
163962 assert( pRtree->nCursor>0 );
163963 freeCursorConstraints(pCsr);
163964 sqlite3_free(pCsr->aPoint);
163965 for(ii=0; ii<RTREE_CACHE_SZ; ii++) nodeRelease(pRtree, pCsr->aNode[ii]);
163966 sqlite3_free(pCsr);
163967 pRtree->nCursor--;
163968 nodeBlobReset(pRtree);
163969 return SQLITE_OK;
163970 }
163971
163972 /*
163973 ** Rtree virtual table module xEof method.
@@ -163433,27 +163986,34 @@
163986 ** endian platforms. The on-disk record stores integer coordinates if
163987 ** eInt is true and it stores 32-bit floating point records if eInt is
163988 ** false. a[] is the four bytes of the on-disk record to be decoded.
163989 ** Store the results in "r".
163990 **
163991 ** There are five versions of this macro. The last one is generic. The
163992 ** other four are various architectures-specific optimizations.
 
 
 
 
 
163993 */
163994 #if SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
163995 #define RTREE_DECODE_COORD(eInt, a, r) { \
163996 RtreeCoord c; /* Coordinate decoded */ \
163997 c.u = _byteswap_ulong(*(u32*)a); \
163998 r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \
163999 }
164000 #elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
164001 #define RTREE_DECODE_COORD(eInt, a, r) { \
164002 RtreeCoord c; /* Coordinate decoded */ \
164003 c.u = __builtin_bswap32(*(u32*)a); \
164004 r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \
164005 }
164006 #elif SQLITE_BYTEORDER==1234
164007 #define RTREE_DECODE_COORD(eInt, a, r) { \
164008 RtreeCoord c; /* Coordinate decoded */ \
164009 memcpy(&c.u,a,4); \
164010 c.u = ((c.u>>24)&0xff)|((c.u>>8)&0xff00)| \
164011 ((c.u&0xff)<<24)|((c.u&0xff00)<<8); \
164012 r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \
164013 }
164014 #elif SQLITE_BYTEORDER==4321
164015 #define RTREE_DECODE_COORD(eInt, a, r) { \
164016 RtreeCoord c; /* Coordinate decoded */ \
164017 memcpy(&c.u,a,4); \
164018 r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \
164019 }
@@ -163476,30 +164036,58 @@
164036 u8 *pCellData, /* Raw cell content */
164037 RtreeSearchPoint *pSearch, /* Container of this cell */
164038 sqlite3_rtree_dbl *prScore, /* OUT: score for the cell */
164039 int *peWithin /* OUT: visibility of the cell */
164040 ){
 
164041 sqlite3_rtree_query_info *pInfo = pConstraint->pInfo; /* Callback info */
164042 int nCoord = pInfo->nCoord; /* No. of coordinates */
164043 int rc; /* Callback return code */
164044 RtreeCoord c; /* Translator union */
164045 sqlite3_rtree_dbl aCoord[RTREE_MAX_DIMENSIONS*2]; /* Decoded coordinates */
164046
164047 assert( pConstraint->op==RTREE_MATCH || pConstraint->op==RTREE_QUERY );
164048 assert( nCoord==2 || nCoord==4 || nCoord==6 || nCoord==8 || nCoord==10 );
164049
164050 if( pConstraint->op==RTREE_QUERY && pSearch->iLevel==1 ){
164051 pInfo->iRowid = readInt64(pCellData);
164052 }
164053 pCellData += 8;
164054 #ifndef SQLITE_RTREE_INT_ONLY
164055 if( eInt==0 ){
164056 switch( nCoord ){
164057 case 10: readCoord(pCellData+36, &c); aCoord[9] = c.f;
164058 readCoord(pCellData+32, &c); aCoord[8] = c.f;
164059 case 8: readCoord(pCellData+28, &c); aCoord[7] = c.f;
164060 readCoord(pCellData+24, &c); aCoord[6] = c.f;
164061 case 6: readCoord(pCellData+20, &c); aCoord[5] = c.f;
164062 readCoord(pCellData+16, &c); aCoord[4] = c.f;
164063 case 4: readCoord(pCellData+12, &c); aCoord[3] = c.f;
164064 readCoord(pCellData+8, &c); aCoord[2] = c.f;
164065 default: readCoord(pCellData+4, &c); aCoord[1] = c.f;
164066 readCoord(pCellData, &c); aCoord[0] = c.f;
164067 }
164068 }else
164069 #endif
164070 {
164071 switch( nCoord ){
164072 case 10: readCoord(pCellData+36, &c); aCoord[9] = c.i;
164073 readCoord(pCellData+32, &c); aCoord[8] = c.i;
164074 case 8: readCoord(pCellData+28, &c); aCoord[7] = c.i;
164075 readCoord(pCellData+24, &c); aCoord[6] = c.i;
164076 case 6: readCoord(pCellData+20, &c); aCoord[5] = c.i;
164077 readCoord(pCellData+16, &c); aCoord[4] = c.i;
164078 case 4: readCoord(pCellData+12, &c); aCoord[3] = c.i;
164079 readCoord(pCellData+8, &c); aCoord[2] = c.i;
164080 default: readCoord(pCellData+4, &c); aCoord[1] = c.i;
164081 readCoord(pCellData, &c); aCoord[0] = c.i;
164082 }
164083 }
164084 if( pConstraint->op==RTREE_MATCH ){
164085 int eWithin = 0;
164086 rc = pConstraint->u.xGeom((sqlite3_rtree_geometry*)pInfo,
164087 nCoord, aCoord, &eWithin);
164088 if( eWithin==0 ) *peWithin = NOT_WITHIN;
164089 *prScore = RTREE_ZERO;
164090 }else{
164091 pInfo->aCoord = aCoord;
164092 pInfo->iLevel = pSearch->iLevel - 1;
164093 pInfo->rScore = pInfo->rParentScore = pSearch->rScore;
@@ -163531,10 +164119,11 @@
164119 */
164120 pCellData += 8 + 4*(p->iCoord&0xfe);
164121
164122 assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
164123 || p->op==RTREE_GT || p->op==RTREE_EQ );
164124 assert( ((((char*)pCellData) - (char*)0)&3)==0 ); /* 4-byte aligned */
164125 switch( p->op ){
164126 case RTREE_LE:
164127 case RTREE_LT:
164128 case RTREE_EQ:
164129 RTREE_DECODE_COORD(eInt, pCellData, val);
@@ -163571,10 +164160,11 @@
164160 RtreeDValue xN; /* Coordinate value converted to a double */
164161
164162 assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
164163 || p->op==RTREE_GT || p->op==RTREE_EQ );
164164 pCellData += 8 + p->iCoord*4;
164165 assert( ((((char*)pCellData) - (char*)0)&3)==0 ); /* 4-byte aligned */
164166 RTREE_DECODE_COORD(eInt, pCellData, xN);
164167 switch( p->op ){
164168 case RTREE_LE: if( xN <= p->u.rValue ) return; break;
164169 case RTREE_LT: if( xN < p->u.rValue ) return; break;
164170 case RTREE_GE: if( xN >= p->u.rValue ) return; break;
@@ -163639,11 +164229,11 @@
164229 if( pA->iLevel>pB->iLevel ) return +1;
164230 return 0;
164231 }
164232
164233 /*
164234 ** Interchange two search points in a cursor.
164235 */
164236 static void rtreeSearchPointSwap(RtreeCursor *p, int i, int j){
164237 RtreeSearchPoint t = p->aPoint[i];
164238 assert( i<j );
164239 p->aPoint[i] = p->aPoint[j];
@@ -163887,11 +164477,11 @@
164477 rtreeSearchPointPop(pCur);
164478 }
164479 if( rScore<RTREE_ZERO ) rScore = RTREE_ZERO;
164480 p = rtreeSearchPointNew(pCur, rScore, x.iLevel);
164481 if( p==0 ) return SQLITE_NOMEM;
164482 p->eWithin = (u8)eWithin;
164483 p->id = x.id;
164484 p->iCell = x.iCell;
164485 RTREE_QUEUE_TRACE(pCur, "PUSH-S:");
164486 break;
164487 }
@@ -163946,11 +164536,10 @@
164536 if( rc ) return rc;
164537 if( p==0 ) return SQLITE_OK;
164538 if( i==0 ){
164539 sqlite3_result_int64(ctx, nodeGetRowid(pRtree, pNode, p->iCell));
164540 }else{
 
164541 nodeGetCoord(pRtree, pNode, p->iCell, i-1, &c);
164542 #ifndef SQLITE_RTREE_INT_ONLY
164543 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
164544 sqlite3_result_double(ctx, c.f);
164545 }else
@@ -164075,11 +164664,11 @@
164664 assert( p!=0 ); /* Always returns pCsr->sPoint */
164665 pCsr->aNode[0] = pLeaf;
164666 p->id = iNode;
164667 p->eWithin = PARTLY_WITHIN;
164668 rc = nodeRowidIndex(pRtree, pLeaf, iRowid, &iCell);
164669 p->iCell = (u8)iCell;
164670 RTREE_QUEUE_TRACE(pCsr, "PUSH-F1:");
164671 }else{
164672 pCsr->atEOF = 1;
164673 }
164674 }else{
@@ -164108,11 +164697,11 @@
164697 */
164698 rc = deserializeGeometry(argv[ii], p);
164699 if( rc!=SQLITE_OK ){
164700 break;
164701 }
164702 p->pInfo->nCoord = pRtree->nDim2;
164703 p->pInfo->anQueue = pCsr->anQueue;
164704 p->pInfo->mxLevel = pRtree->iDepth + 1;
164705 }else{
164706 #ifdef SQLITE_RTREE_INT_ONLY
164707 p->u.rValue = sqlite3_value_int64(argv[ii]);
@@ -164123,11 +164712,11 @@
164712 }
164713 }
164714 }
164715 if( rc==SQLITE_OK ){
164716 RtreeSearchPoint *pNew;
164717 pNew = rtreeSearchPointNew(pCsr, RTREE_ZERO, (u8)(pRtree->iDepth+1));
164718 if( pNew==0 ) return SQLITE_NOMEM;
164719 pNew->id = 1;
164720 pNew->iCell = 0;
164721 pNew->eWithin = PARTLY_WITHIN;
164722 assert( pCsr->bPoint==1 );
@@ -164141,23 +164730,10 @@
164730 nodeRelease(pRtree, pRoot);
164731 rtreeRelease(pRtree);
164732 return rc;
164733 }
164734
 
 
 
 
 
 
 
 
 
 
 
 
 
164735 /*
164736 ** Rtree virtual table module xBestIndex method. There are three
164737 ** table scan strategies to choose from (in order from most to
164738 ** least desirable):
164739 **
@@ -164233,11 +164809,11 @@
164809 ** considered almost as quick as a direct rowid lookup (for which
164810 ** sqlite uses an internal cost of 0.0). It is expected to return
164811 ** a single row.
164812 */
164813 pIdxInfo->estimatedCost = 30.0;
164814 pIdxInfo->estimatedRows = 1;
164815 return SQLITE_OK;
164816 }
164817
164818 if( p->usable && (p->iColumn>0 || p->op==SQLITE_INDEX_CONSTRAINT_MATCH) ){
164819 u8 op;
@@ -164251,11 +164827,11 @@
164827 assert( p->op==SQLITE_INDEX_CONSTRAINT_MATCH );
164828 op = RTREE_MATCH;
164829 break;
164830 }
164831 zIdxStr[iIdx++] = op;
164832 zIdxStr[iIdx++] = (char)(p->iColumn - 1 + '0');
164833 pIdxInfo->aConstraintUsage[ii].argvIndex = (iIdx/2);
164834 pIdxInfo->aConstraintUsage[ii].omit = 1;
164835 }
164836 }
164837
@@ -164265,55 +164841,75 @@
164841 return SQLITE_NOMEM;
164842 }
164843
164844 nRow = pRtree->nRowEst >> (iIdx/2);
164845 pIdxInfo->estimatedCost = (double)6.0 * (double)nRow;
164846 pIdxInfo->estimatedRows = nRow;
164847
164848 return rc;
164849 }
164850
164851 /*
164852 ** Return the N-dimensional volumn of the cell stored in *p.
164853 */
164854 static RtreeDValue cellArea(Rtree *pRtree, RtreeCell *p){
164855 RtreeDValue area = (RtreeDValue)1;
164856 assert( pRtree->nDim>=1 && pRtree->nDim<=5 );
164857 #ifndef SQLITE_RTREE_INT_ONLY
164858 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
164859 switch( pRtree->nDim ){
164860 case 5: area = p->aCoord[9].f - p->aCoord[8].f;
164861 case 4: area *= p->aCoord[7].f - p->aCoord[6].f;
164862 case 3: area *= p->aCoord[5].f - p->aCoord[4].f;
164863 case 2: area *= p->aCoord[3].f - p->aCoord[2].f;
164864 default: area *= p->aCoord[1].f - p->aCoord[0].f;
164865 }
164866 }else
164867 #endif
164868 {
164869 switch( pRtree->nDim ){
164870 case 5: area = p->aCoord[9].i - p->aCoord[8].i;
164871 case 4: area *= p->aCoord[7].i - p->aCoord[6].i;
164872 case 3: area *= p->aCoord[5].i - p->aCoord[4].i;
164873 case 2: area *= p->aCoord[3].i - p->aCoord[2].i;
164874 default: area *= p->aCoord[1].i - p->aCoord[0].i;
164875 }
164876 }
164877 return area;
164878 }
164879
164880 /*
164881 ** Return the margin length of cell p. The margin length is the sum
164882 ** of the objects size in each dimension.
164883 */
164884 static RtreeDValue cellMargin(Rtree *pRtree, RtreeCell *p){
164885 RtreeDValue margin = 0;
164886 int ii = pRtree->nDim2 - 2;
164887 do{
164888 margin += (DCOORD(p->aCoord[ii+1]) - DCOORD(p->aCoord[ii]));
164889 ii -= 2;
164890 }while( ii>=0 );
164891 return margin;
164892 }
164893
164894 /*
164895 ** Store the union of cells p1 and p2 in p1.
164896 */
164897 static void cellUnion(Rtree *pRtree, RtreeCell *p1, RtreeCell *p2){
164898 int ii = 0;
164899 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
164900 do{
164901 p1->aCoord[ii].f = MIN(p1->aCoord[ii].f, p2->aCoord[ii].f);
164902 p1->aCoord[ii+1].f = MAX(p1->aCoord[ii+1].f, p2->aCoord[ii+1].f);
164903 ii += 2;
164904 }while( ii<pRtree->nDim2 );
164905 }else{
164906 do{
164907 p1->aCoord[ii].i = MIN(p1->aCoord[ii].i, p2->aCoord[ii].i);
164908 p1->aCoord[ii+1].i = MAX(p1->aCoord[ii+1].i, p2->aCoord[ii+1].i);
164909 ii += 2;
164910 }while( ii<pRtree->nDim2 );
164911 }
164912 }
164913
164914 /*
164915 ** Return true if the area covered by p2 is a subset of the area covered
@@ -164320,11 +164916,11 @@
164916 ** by p1. False otherwise.
164917 */
164918 static int cellContains(Rtree *pRtree, RtreeCell *p1, RtreeCell *p2){
164919 int ii;
164920 int isInt = (pRtree->eCoordType==RTREE_COORD_INT32);
164921 for(ii=0; ii<pRtree->nDim2; ii+=2){
164922 RtreeCoord *a1 = &p1->aCoord[ii];
164923 RtreeCoord *a2 = &p2->aCoord[ii];
164924 if( (!isInt && (a2[0].f<a1[0].f || a2[1].f>a1[1].f))
164925 || ( isInt && (a2[0].i<a1[0].i || a2[1].i>a1[1].i))
164926 ){
@@ -164355,11 +164951,11 @@
164951 int ii;
164952 RtreeDValue overlap = RTREE_ZERO;
164953 for(ii=0; ii<nCell; ii++){
164954 int jj;
164955 RtreeDValue o = (RtreeDValue)1;
164956 for(jj=0; jj<pRtree->nDim2; jj+=2){
164957 RtreeDValue x1, x2;
164958 x1 = MAX(DCOORD(p->aCoord[jj]), DCOORD(aCell[ii].aCoord[jj]));
164959 x2 = MIN(DCOORD(p->aCoord[jj+1]), DCOORD(aCell[ii].aCoord[jj+1]));
164960 if( x2<x1 ){
164961 o = (RtreeDValue)0;
@@ -165411,11 +166007,11 @@
166007 ** with "column" that are interpreted as table constraints.
166008 ** Example: CREATE VIRTUAL TABLE bad USING rtree(x,y,CHECK(y>5));
166009 ** This problem was discovered after years of use, so we silently ignore
166010 ** these kinds of misdeclared tables to avoid breaking any legacy.
166011 */
166012 assert( nData<=(pRtree->nDim2 + 3) );
166013
166014 #ifndef SQLITE_RTREE_INT_ONLY
166015 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
166016 for(ii=0; ii<nData-4; ii+=2){
166017 cell.aCoord[ii].f = rtreeValueDown(azData[ii+3]);
@@ -165500,10 +166096,31 @@
166096
166097 constraint:
166098 rtreeRelease(pRtree);
166099 return rc;
166100 }
166101
166102 /*
166103 ** Called when a transaction starts.
166104 */
166105 static int rtreeBeginTransaction(sqlite3_vtab *pVtab){
166106 Rtree *pRtree = (Rtree *)pVtab;
166107 assert( pRtree->inWrTrans==0 );
166108 pRtree->inWrTrans++;
166109 return SQLITE_OK;
166110 }
166111
166112 /*
166113 ** Called when a transaction completes (either by COMMIT or ROLLBACK).
166114 ** The sqlite3_blob object should be released at this point.
166115 */
166116 static int rtreeEndTransaction(sqlite3_vtab *pVtab){
166117 Rtree *pRtree = (Rtree *)pVtab;
166118 pRtree->inWrTrans = 0;
166119 nodeBlobReset(pRtree);
166120 return SQLITE_OK;
166121 }
166122
166123 /*
166124 ** The xRename method for rtree module virtual tables.
166125 */
166126 static int rtreeRename(sqlite3_vtab *pVtab, const char *zNewName){
@@ -165521,10 +166138,11 @@
166138 rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
166139 sqlite3_free(zSql);
166140 }
166141 return rc;
166142 }
166143
166144
166145 /*
166146 ** This function populates the pRtree->nRowEst variable with an estimate
166147 ** of the number of rows in the virtual table. If possible, this is based
166148 ** on sqlite_stat1 data. Otherwise, use RTREE_DEFAULT_ROWEST.
@@ -165581,19 +166199,19 @@
166199 rtreeNext, /* xNext - advance a cursor */
166200 rtreeEof, /* xEof */
166201 rtreeColumn, /* xColumn - read data */
166202 rtreeRowid, /* xRowid - read data */
166203 rtreeUpdate, /* xUpdate - write data */
166204 rtreeBeginTransaction, /* xBegin - begin transaction */
166205 rtreeEndTransaction, /* xSync - sync transaction */
166206 rtreeEndTransaction, /* xCommit - commit transaction */
166207 rtreeEndTransaction, /* xRollback - rollback transaction */
166208 0, /* xFindFunction - function overloading */
166209 rtreeRename, /* xRename - rename the table */
166210 0, /* xSavepoint */
166211 0, /* xRelease */
166212 0, /* xRollbackTo */
166213 };
166214
166215 static int rtreeSqlInit(
166216 Rtree *pRtree,
166217 sqlite3 *db,
@@ -165601,14 +166219,13 @@
166219 const char *zPrefix,
166220 int isCreate
166221 ){
166222 int rc = SQLITE_OK;
166223
166224 #define N_STATEMENT 8
166225 static const char *azSql[N_STATEMENT] = {
166226 /* Write the xxx_node table */
 
166227 "INSERT OR REPLACE INTO '%q'.'%q_node' VALUES(:1, :2)",
166228 "DELETE FROM '%q'.'%q_node' WHERE nodeno = :1",
166229
166230 /* Read and write the xxx_rowid table */
166231 "SELECT nodeno FROM '%q'.'%q_rowid' WHERE rowid = :1",
@@ -165642,19 +166259,18 @@
166259 if( rc!=SQLITE_OK ){
166260 return rc;
166261 }
166262 }
166263
166264 appStmt[0] = &pRtree->pWriteNode;
166265 appStmt[1] = &pRtree->pDeleteNode;
166266 appStmt[2] = &pRtree->pReadRowid;
166267 appStmt[3] = &pRtree->pWriteRowid;
166268 appStmt[4] = &pRtree->pDeleteRowid;
166269 appStmt[5] = &pRtree->pReadParent;
166270 appStmt[6] = &pRtree->pWriteParent;
166271 appStmt[7] = &pRtree->pDeleteParent;
 
166272
166273 rc = rtreeQueryStat1(db, pRtree);
166274 for(i=0; i<N_STATEMENT && rc==SQLITE_OK; i++){
166275 char *zSql = sqlite3_mprintf(azSql[i], zDb, zPrefix);
166276 if( zSql ){
@@ -165788,13 +166404,14 @@
166404 memset(pRtree, 0, sizeof(Rtree)+nDb+nName+2);
166405 pRtree->nBusy = 1;
166406 pRtree->base.pModule = &rtreeModule;
166407 pRtree->zDb = (char *)&pRtree[1];
166408 pRtree->zName = &pRtree->zDb[nDb+1];
166409 pRtree->nDim = (u8)((argc-4)/2);
166410 pRtree->nDim2 = pRtree->nDim*2;
166411 pRtree->nBytesPerCell = 8 + pRtree->nDim2*4;
166412 pRtree->eCoordType = (u8)eCoordType;
166413 memcpy(pRtree->zDb, argv[1], nDb);
166414 memcpy(pRtree->zName, argv[2], nName);
166415
166416 /* Figure out the node size to use. */
166417 rc = getNodeSize(db, pRtree, isCreate, pzErr);
@@ -165863,11 +166480,12 @@
166480 int ii;
166481
166482 UNUSED_PARAMETER(nArg);
166483 memset(&node, 0, sizeof(RtreeNode));
166484 memset(&tree, 0, sizeof(Rtree));
166485 tree.nDim = (u8)sqlite3_value_int(apArg[0]);
166486 tree.nDim2 = tree.nDim*2;
166487 tree.nBytesPerCell = 8 + 8 * tree.nDim;
166488 node.zData = (u8 *)sqlite3_value_blob(apArg[1]);
166489
166490 for(ii=0; ii<NCELL(&node); ii++){
166491 char zCell[512];
@@ -165876,11 +166494,11 @@
166494 int jj;
166495
166496 nodeGetCell(&tree, &node, ii, &cell);
166497 sqlite3_snprintf(512-nCell,&zCell[nCell],"%lld", cell.iRowid);
166498 nCell = (int)strlen(zCell);
166499 for(jj=0; jj<tree.nDim2; jj++){
166500 #ifndef SQLITE_RTREE_INT_ONLY
166501 sqlite3_snprintf(512-nCell,&zCell[nCell], " %g",
166502 (double)cell.aCoord[jj].f);
166503 #else
166504 sqlite3_snprintf(512-nCell,&zCell[nCell], " %d",
@@ -166584,42 +167202,40 @@
167202
167203 /*
167204 ** Register the ICU extension functions with database db.
167205 */
167206 SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db){
167207 static const struct IcuScalar {
167208 const char *zName; /* Function name */
167209 unsigned char nArg; /* Number of arguments */
167210 unsigned short enc; /* Optimal text encoding */
167211 unsigned char iContext; /* sqlite3_user_data() context */
167212 void (*xFunc)(sqlite3_context*,int,sqlite3_value**);
167213 } scalars[] = {
167214 {"icu_load_collation", 2, SQLITE_UTF8, 1, icuLoadCollation},
167215 {"regexp", 2, SQLITE_ANY|SQLITE_DETERMINISTIC, 0, icuRegexpFunc},
167216 {"lower", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
167217 {"lower", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
167218 {"upper", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, 1, icuCaseFunc16},
167219 {"upper", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, 1, icuCaseFunc16},
167220 {"lower", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
167221 {"lower", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
167222 {"upper", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, 1, icuCaseFunc16},
167223 {"upper", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 1, icuCaseFunc16},
167224 {"like", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc},
167225 {"like", 3, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc},
 
 
 
 
167226 };
 
167227 int rc = SQLITE_OK;
167228 int i;
167229
167230
167231 for(i=0; rc==SQLITE_OK && i<(int)(sizeof(scalars)/sizeof(scalars[0])); i++){
167232 const struct IcuScalar *p = &scalars[i];
167233 rc = sqlite3_create_function(
167234 db, p->zName, p->nArg, p->enc,
167235 p->iContext ? (void*)db : (void*)0,
167236 p->xFunc, 0, 0
167237 );
167238 }
167239
167240 return rc;
167241 }
@@ -169823,11 +170439,11 @@
170439
170440 /*
170441 ** Open the database handle and attach the RBU database as "rbu". If an
170442 ** error occurs, leave an error code and message in the RBU handle.
170443 */
170444 static void rbuOpenDatabase(sqlite3rbu *p, int *pbRetry){
170445 assert( p->rc || (p->dbMain==0 && p->dbRbu==0) );
170446 assert( p->rc || rbuIsVacuum(p) || p->zTarget!=0 );
170447
170448 /* Open the RBU database */
170449 p->dbRbu = rbuOpenDbhandle(p, p->zRbu, 1);
@@ -169898,11 +170514,11 @@
170514 if( p->eStage>=RBU_STAGE_MOVE ){
170515 bOpen = 1;
170516 }else{
170517 RbuState *pState = rbuLoadState(p);
170518 if( pState ){
170519 bOpen = (pState->eStage>=RBU_STAGE_MOVE);
170520 rbuFreeState(pState);
170521 }
170522 }
170523 if( bOpen ) p->dbMain = rbuOpenDbhandle(p, p->zRbu, p->nRbu<=1);
170524 }
@@ -169910,10 +170526,19 @@
170526 p->eStage = 0;
170527 if( p->rc==SQLITE_OK && p->dbMain==0 ){
170528 if( !rbuIsVacuum(p) ){
170529 p->dbMain = rbuOpenDbhandle(p, p->zTarget, 1);
170530 }else if( p->pRbuFd->pWalFd ){
170531 if( pbRetry ){
170532 p->pRbuFd->bNolock = 0;
170533 sqlite3_close(p->dbRbu);
170534 sqlite3_close(p->dbMain);
170535 p->dbMain = 0;
170536 p->dbRbu = 0;
170537 *pbRetry = 1;
170538 return;
170539 }
170540 p->rc = SQLITE_ERROR;
170541 p->zErrmsg = sqlite3_mprintf("cannot vacuum wal mode database");
170542 }else{
170543 char *zTarget;
170544 char *zExtra = 0;
@@ -170090,20 +170715,22 @@
170715 p->eStage = RBU_STAGE_CAPTURE;
170716 rc2 = sqlite3_exec(p->dbMain, "PRAGMA main.wal_checkpoint=restart", 0, 0,0);
170717 if( rc2!=SQLITE_INTERNAL ) p->rc = rc2;
170718 }
170719
170720 if( p->rc==SQLITE_OK && p->nFrame>0 ){
170721 p->eStage = RBU_STAGE_CKPT;
170722 p->nStep = (pState ? pState->nRow : 0);
170723 p->aBuf = rbuMalloc(p, p->pgsz);
170724 p->iWalCksum = rbuShmChecksum(p);
170725 }
170726
170727 if( p->rc==SQLITE_OK ){
170728 if( p->nFrame==0 || (pState && pState->iWalCksum!=p->iWalCksum) ){
170729 p->rc = SQLITE_DONE;
170730 p->eStage = RBU_STAGE_DONE;
170731 }
170732 }
170733 }
170734
170735 /*
170736 ** Called when iAmt bytes are read from offset iOff of the wal file while
@@ -170272,11 +170899,11 @@
170899 #else
170900 p->rc = rename(zOal, zWal) ? SQLITE_IOERR : SQLITE_OK;
170901 #endif
170902
170903 if( p->rc==SQLITE_OK ){
170904 rbuOpenDatabase(p, 0);
170905 rbuSetupCheckpoint(p, 0);
170906 }
170907 }
170908 }
170909
@@ -170983,10 +171610,11 @@
171610 rbuCreateVfs(p);
171611
171612 /* Open the target, RBU and state databases */
171613 if( p->rc==SQLITE_OK ){
171614 char *pCsr = (char*)&p[1];
171615 int bRetry = 0;
171616 if( zTarget ){
171617 p->zTarget = pCsr;
171618 memcpy(p->zTarget, zTarget, nTarget+1);
171619 pCsr += nTarget+1;
171620 }
@@ -170994,11 +171622,22 @@
171622 memcpy(p->zRbu, zRbu, nRbu+1);
171623 pCsr += nRbu+1;
171624 if( zState ){
171625 p->zState = rbuMPrintf(p, "%s", zState);
171626 }
171627
171628 /* If the first attempt to open the database file fails and the bRetry
171629 ** flag it set, this means that the db was not opened because it seemed
171630 ** to be a wal-mode db. But, this may have happened due to an earlier
171631 ** RBU vacuum operation leaving an old wal file in the directory.
171632 ** If this is the case, it will have been checkpointed and deleted
171633 ** when the handle was closed and a second attempt to open the
171634 ** database may succeed. */
171635 rbuOpenDatabase(p, &bRetry);
171636 if( bRetry ){
171637 rbuOpenDatabase(p, 0);
171638 }
171639 }
171640
171641 if( p->rc==SQLITE_OK ){
171642 pState = rbuLoadState(p);
171643 assert( pState || p->rc!=SQLITE_OK );
@@ -175957,11 +176596,11 @@
176596 sqlite3_value **ppValue /* OUT: Value from conflicting row */
176597 ){
176598 if( !pIter->pConflict ){
176599 return SQLITE_MISUSE;
176600 }
176601 if( iVal<0 || iVal>=pIter->nCol ){
176602 return SQLITE_RANGE;
176603 }
176604 *ppValue = sqlite3_column_value(pIter->pConflict, iVal);
176605 return SQLITE_OK;
176606 }
@@ -176424,11 +177063,17 @@
177063 int i;
177064 SessionBuffer buf = {0, 0, 0};
177065
177066 sessionAppendStr(&buf, "INSERT INTO main.", &rc);
177067 sessionAppendIdent(&buf, zTab, &rc);
177068 sessionAppendStr(&buf, "(", &rc);
177069 for(i=0; i<p->nCol; i++){
177070 if( i!=0 ) sessionAppendStr(&buf, ", ", &rc);
177071 sessionAppendIdent(&buf, p->azCol[i], &rc);
177072 }
177073
177074 sessionAppendStr(&buf, ") VALUES(?", &rc);
177075 for(i=1; i<p->nCol; i++){
177076 sessionAppendStr(&buf, ", ?", &rc);
177077 }
177078 sessionAppendStr(&buf, ")", &rc);
177079
@@ -176970,42 +177615,51 @@
177615 break;
177616 }
177617 nTab = (int)strlen(zTab);
177618 sApply.azCol = (const char **)zTab;
177619 }else{
177620 int nMinCol = 0;
177621 int i;
177622
177623 sqlite3changeset_pk(pIter, &abPK, 0);
177624 rc = sessionTableInfo(
177625 db, "main", zNew, &sApply.nCol, &zTab, &sApply.azCol, &sApply.abPK
177626 );
177627 if( rc!=SQLITE_OK ) break;
177628 for(i=0; i<sApply.nCol; i++){
177629 if( sApply.abPK[i] ) nMinCol = i+1;
177630 }
177631
177632 if( sApply.nCol==0 ){
177633 schemaMismatch = 1;
177634 sqlite3_log(SQLITE_SCHEMA,
177635 "sqlite3changeset_apply(): no such table: %s", zTab
177636 );
177637 }
177638 else if( sApply.nCol<nCol ){
177639 schemaMismatch = 1;
177640 sqlite3_log(SQLITE_SCHEMA,
177641 "sqlite3changeset_apply(): table %s has %d columns, "
177642 "expected %d or more",
177643 zTab, sApply.nCol, nCol
177644 );
177645 }
177646 else if( nCol<nMinCol || memcmp(sApply.abPK, abPK, nCol)!=0 ){
177647 schemaMismatch = 1;
177648 sqlite3_log(SQLITE_SCHEMA, "sqlite3changeset_apply(): "
177649 "primary key mismatch for table %s", zTab
177650 );
177651 }
177652 else{
177653 sApply.nCol = nCol;
177654 if((rc = sessionSelectRow(db, zTab, &sApply))
177655 || (rc = sessionUpdateRow(db, zTab, &sApply))
177656 || (rc = sessionDeleteRow(db, zTab, &sApply))
177657 || (rc = sessionInsertRow(db, zTab, &sApply))
177658 ){
177659 break;
177660 }
177661 }
177662 nTab = sqlite3Strlen30(zTab);
177663 }
177664 }
177665
@@ -177593,11 +178247,11 @@
178247 ** a BLOB, but there is no support for JSONB in the current implementation.
178248 ** This implementation parses JSON text at 250 MB/s, so it is hard to see
178249 ** how JSONB might improve on that.)
178250 */
178251 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_JSON1)
178252 #if !defined(SQLITEINT_H)
178253 /* #include "sqlite3ext.h" */
178254 #endif
178255 SQLITE_EXTENSION_INIT1
178256 /* #include <assert.h> */
178257 /* #include <string.h> */
@@ -181644,10 +182298,35 @@
182298 */
182299 #ifndef fts5YYMALLOCARGTYPE
182300 # define fts5YYMALLOCARGTYPE size_t
182301 #endif
182302
182303 /* Initialize a new parser that has already been allocated.
182304 */
182305 static void sqlite3Fts5ParserInit(void *fts5yypParser){
182306 fts5yyParser *pParser = (fts5yyParser*)fts5yypParser;
182307 #ifdef fts5YYTRACKMAXSTACKDEPTH
182308 pParser->fts5yyhwm = 0;
182309 #endif
182310 #if fts5YYSTACKDEPTH<=0
182311 pParser->fts5yytos = NULL;
182312 pParser->fts5yystack = NULL;
182313 pParser->fts5yystksz = 0;
182314 if( fts5yyGrowStack(pParser) ){
182315 pParser->fts5yystack = &pParser->fts5yystk0;
182316 pParser->fts5yystksz = 1;
182317 }
182318 #endif
182319 #ifndef fts5YYNOERRORRECOVERY
182320 pParser->fts5yyerrcnt = -1;
182321 #endif
182322 pParser->fts5yytos = pParser->fts5yystack;
182323 pParser->fts5yystack[0].stateno = 0;
182324 pParser->fts5yystack[0].major = 0;
182325 }
182326
182327 #ifndef sqlite3Fts5Parser_ENGINEALWAYSONSTACK
182328 /*
182329 ** This function allocates a new parser.
182330 ** The only argument is a pointer to a function which works like
182331 ** malloc.
182332 **
@@ -181659,32 +182338,15 @@
182338 ** to sqlite3Fts5Parser and sqlite3Fts5ParserFree.
182339 */
182340 static void *sqlite3Fts5ParserAlloc(void *(*mallocProc)(fts5YYMALLOCARGTYPE)){
182341 fts5yyParser *pParser;
182342 pParser = (fts5yyParser*)(*mallocProc)( (fts5YYMALLOCARGTYPE)sizeof(fts5yyParser) );
182343 if( pParser ) sqlite3Fts5ParserInit(pParser);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182344 return pParser;
182345 }
182346 #endif /* sqlite3Fts5Parser_ENGINEALWAYSONSTACK */
182347
182348
182349 /* The following function deletes the "minor type" or semantic value
182350 ** associated with a symbol. The symbol can be either a terminal
182351 ** or nonterminal. "fts5yymajor" is the symbol code, and "fts5yypminor" is
182352 ** a pointer to the value to be deleted. The code used to do the
@@ -181762,10 +182424,22 @@
182424 }
182425 #endif
182426 fts5yy_destructor(pParser, fts5yytos->major, &fts5yytos->minor);
182427 }
182428
182429 /*
182430 ** Clear all secondary memory allocations from the parser
182431 */
182432 static void sqlite3Fts5ParserFinalize(void *p){
182433 fts5yyParser *pParser = (fts5yyParser*)p;
182434 while( pParser->fts5yytos>pParser->fts5yystack ) fts5yy_pop_parser_stack(pParser);
182435 #if fts5YYSTACKDEPTH<=0
182436 if( pParser->fts5yystack!=&pParser->fts5yystk0 ) free(pParser->fts5yystack);
182437 #endif
182438 }
182439
182440 #ifndef sqlite3Fts5Parser_ENGINEALWAYSONSTACK
182441 /*
182442 ** Deallocate and destroy a parser. Destructors are called for
182443 ** all stack elements before shutting the parser down.
182444 **
182445 ** If the fts5YYPARSEFREENEVERNULL macro exists (for example because it
@@ -181774,20 +182448,17 @@
182448 */
182449 static void sqlite3Fts5ParserFree(
182450 void *p, /* The parser to be deleted */
182451 void (*freeProc)(void*) /* Function used to reclaim memory */
182452 ){
 
182453 #ifndef fts5YYPARSEFREENEVERNULL
182454 if( p==0 ) return;
182455 #endif
182456 sqlite3Fts5ParserFinalize(p);
182457 (*freeProc)(p);
182458 }
182459 #endif /* sqlite3Fts5Parser_ENGINEALWAYSONSTACK */
 
 
182460
182461 /*
182462 ** Return the peak depth of the stack for a parser.
182463 */
182464 #ifdef fts5YYTRACKMAXSTACKDEPTH
@@ -186122,11 +186793,11 @@
186793 memset(&sCtx, 0, sizeof(TokenCtx));
186794 sCtx.pPhrase = pAppend;
186795
186796 rc = fts5ParseStringFromToken(pToken, &z);
186797 if( rc==SQLITE_OK ){
186798 int flags = FTS5_TOKENIZE_QUERY | (bPrefix ? FTS5_TOKENIZE_PREFIX : 0);
186799 int n;
186800 sqlite3Fts5Dequote(z);
186801 n = (int)strlen(z);
186802 rc = sqlite3Fts5Tokenize(pConfig, flags, z, n, &sCtx, fts5ParseTokenize);
186803 }
@@ -196863,11 +197534,11 @@
197534 int nArg, /* Number of args */
197535 sqlite3_value **apUnused /* Function arguments */
197536 ){
197537 assert( nArg==0 );
197538 UNUSED_PARAM2(nArg, apUnused);
197539 sqlite3_result_text(pCtx, "fts5: 2017-02-13 16:02:40 ada05cfa86ad7f5645450ac7a2a21c9aa6e57d2c", -1, SQLITE_TRANSIENT);
197540 }
197541
197542 static int fts5Init(sqlite3 *db){
197543 static const sqlite3_module fts5Mod = {
197544 /* iVersion */ 2,
197545
+83 -55
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -119,13 +119,13 @@
119119
**
120120
** See also: [sqlite3_libversion()],
121121
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122122
** [sqlite_version()] and [sqlite_source_id()].
123123
*/
124
-#define SQLITE_VERSION "3.16.2"
125
-#define SQLITE_VERSION_NUMBER 3016002
126
-#define SQLITE_SOURCE_ID "2017-01-06 16:32:41 a65a62893ca8319e89e48b8a38cf8a59c69a8209"
124
+#define SQLITE_VERSION "3.17.0"
125
+#define SQLITE_VERSION_NUMBER 3017000
126
+#define SQLITE_SOURCE_ID "2017-02-13 16:02:40 ada05cfa86ad7f5645450ac7a2a21c9aa6e57d2c"
127127
128128
/*
129129
** CAPI3REF: Run-Time Library Version Numbers
130130
** KEYWORDS: sqlite3_version sqlite3_sourceid
131131
**
@@ -257,11 +257,15 @@
257257
** sqlite3_uint64 and sqlite_uint64 types can store integer values
258258
** between 0 and +18446744073709551615 inclusive.
259259
*/
260260
#ifdef SQLITE_INT64_TYPE
261261
typedef SQLITE_INT64_TYPE sqlite_int64;
262
- typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
262
+# ifdef SQLITE_UINT64_TYPE
263
+ typedef SQLITE_UINT64_TYPE sqlite_uint64;
264
+# else
265
+ typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
266
+# endif
263267
#elif defined(_MSC_VER) || defined(__BORLANDC__)
264268
typedef __int64 sqlite_int64;
265269
typedef unsigned __int64 sqlite_uint64;
266270
#else
267271
typedef long long int sqlite_int64;
@@ -570,11 +574,11 @@
570574
** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
571575
** after reboot following a crash or power loss, the only bytes in a
572576
** file that were written at the application level might have changed
573577
** and that adjacent bytes, even bytes within the same sector are
574578
** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
575
-** flag indicate that a file cannot be deleted when open. The
579
+** flag indicates that a file cannot be deleted when open. The
576580
** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
577581
** read-only media and cannot be changed even by processes with
578582
** elevated privileges.
579583
*/
580584
#define SQLITE_IOCAP_ATOMIC 0x00000001
@@ -720,10 +724,13 @@
720724
** <li> [SQLITE_IOCAP_ATOMIC16K]
721725
** <li> [SQLITE_IOCAP_ATOMIC32K]
722726
** <li> [SQLITE_IOCAP_ATOMIC64K]
723727
** <li> [SQLITE_IOCAP_SAFE_APPEND]
724728
** <li> [SQLITE_IOCAP_SEQUENTIAL]
729
+** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]
730
+** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
731
+** <li> [SQLITE_IOCAP_IMMUTABLE]
725732
** </ul>
726733
**
727734
** The SQLITE_IOCAP_ATOMIC property means that all writes of
728735
** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
729736
** mean that writes of blocks that are nnn bytes in size and
@@ -5408,11 +5415,11 @@
54085415
** ^(The update hook is not invoked when internal system tables are
54095416
** modified (i.e. sqlite_master and sqlite_sequence).)^
54105417
** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
54115418
**
54125419
** ^In the current implementation, the update hook
5413
-** is not invoked when duplication rows are deleted because of an
5420
+** is not invoked when conflicting rows are deleted because of an
54145421
** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
54155422
** invoked when rows are deleted using the [truncate optimization].
54165423
** The exceptions defined in this paragraph might change in a future
54175424
** release of SQLite.
54185425
**
@@ -6190,10 +6197,16 @@
61906197
**
61916198
** ^Unless it returns SQLITE_MISUSE, this function sets the
61926199
** [database connection] error code and message accessible via
61936200
** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
61946201
**
6202
+** A BLOB referenced by sqlite3_blob_open() may be read using the
6203
+** [sqlite3_blob_read()] interface and modified by using
6204
+** [sqlite3_blob_write()]. The [BLOB handle] can be moved to a
6205
+** different row of the same table using the [sqlite3_blob_reopen()]
6206
+** interface. However, the column, table, or database of a [BLOB handle]
6207
+** cannot be changed after the [BLOB handle] is opened.
61956208
**
61966209
** ^(If the row that a BLOB handle points to is modified by an
61976210
** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
61986211
** then the BLOB handle is marked as "expired".
61996212
** This is true if any column of the row is changed, even a column
@@ -6213,10 +6226,14 @@
62136226
** and the built-in [zeroblob] SQL function may be used to create a
62146227
** zero-filled blob to read or write using the incremental-blob interface.
62156228
**
62166229
** To avoid a resource leak, every open [BLOB handle] should eventually
62176230
** be released by a call to [sqlite3_blob_close()].
6231
+**
6232
+** See also: [sqlite3_blob_close()],
6233
+** [sqlite3_blob_reopen()], [sqlite3_blob_read()],
6234
+** [sqlite3_blob_bytes()], [sqlite3_blob_write()].
62186235
*/
62196236
SQLITE_API int sqlite3_blob_open(
62206237
sqlite3*,
62216238
const char *zDb,
62226239
const char *zTable,
@@ -6228,15 +6245,15 @@
62286245
62296246
/*
62306247
** CAPI3REF: Move a BLOB Handle to a New Row
62316248
** METHOD: sqlite3_blob
62326249
**
6233
-** ^This function is used to move an existing blob handle so that it points
6250
+** ^This function is used to move an existing [BLOB handle] so that it points
62346251
** to a different row of the same database table. ^The new row is identified
62356252
** by the rowid value passed as the second argument. Only the row can be
62366253
** changed. ^The database, table and column on which the blob handle is open
6237
-** remain the same. Moving an existing blob handle to a new row can be
6254
+** remain the same. Moving an existing [BLOB handle] to a new row is
62386255
** faster than closing the existing handle and opening a new one.
62396256
**
62406257
** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] -
62416258
** it must exist and there must be either a blob or text value stored in
62426259
** the nominated column.)^ ^If the new row is not present in the table, or if
@@ -8161,22 +8178,22 @@
81618178
** ^These interfaces are only available if SQLite is compiled using the
81628179
** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option.
81638180
**
81648181
** ^The [sqlite3_preupdate_hook()] interface registers a callback function
81658182
** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation
8166
-** on a [rowid table].
8183
+** on a database table.
81678184
** ^At most one preupdate hook may be registered at a time on a single
81688185
** [database connection]; each call to [sqlite3_preupdate_hook()] overrides
81698186
** the previous setting.
81708187
** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()]
81718188
** with a NULL pointer as the second parameter.
81728189
** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as
81738190
** the first parameter to callbacks.
81748191
**
8175
-** ^The preupdate hook only fires for changes to [rowid tables]; the preupdate
8176
-** hook is not invoked for changes to [virtual tables] or [WITHOUT ROWID]
8177
-** tables.
8192
+** ^The preupdate hook only fires for changes to real database tables; the
8193
+** preupdate hook is not invoked for changes to [virtual tables] or to
8194
+** system tables like sqlite_master or sqlite_stat1.
81788195
**
81798196
** ^The second parameter to the preupdate callback is a pointer to
81808197
** the [database connection] that registered the preupdate hook.
81818198
** ^The third parameter to the preupdate callback is one of the constants
81828199
** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the
@@ -8186,16 +8203,20 @@
81868203
** will be "main" for the main database or "temp" for TEMP tables or
81878204
** the name given after the AS keyword in the [ATTACH] statement for attached
81888205
** databases.)^
81898206
** ^The fifth parameter to the preupdate callback is the name of the
81908207
** table that is being modified.
8191
-** ^The sixth parameter to the preupdate callback is the initial [rowid] of the
8192
-** row being changes for SQLITE_UPDATE and SQLITE_DELETE changes and is
8193
-** undefined for SQLITE_INSERT changes.
8194
-** ^The seventh parameter to the preupdate callback is the final [rowid] of
8195
-** the row being changed for SQLITE_UPDATE and SQLITE_INSERT changes and is
8196
-** undefined for SQLITE_DELETE changes.
8208
+**
8209
+** For an UPDATE or DELETE operation on a [rowid table], the sixth
8210
+** parameter passed to the preupdate callback is the initial [rowid] of the
8211
+** row being modified or deleted. For an INSERT operation on a rowid table,
8212
+** or any operation on a WITHOUT ROWID table, the value of the sixth
8213
+** parameter is undefined. For an INSERT or UPDATE on a rowid table the
8214
+** seventh parameter is the final rowid value of the row being inserted
8215
+** or updated. The value of the seventh parameter passed to the callback
8216
+** function is not defined for operations on WITHOUT ROWID tables, or for
8217
+** INSERT operations on rowid tables.
81978218
**
81988219
** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
81998220
** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
82008221
** provide additional information about a preupdate event. These routines
82018222
** may only be called from within a preupdate callback. Invoking any of
@@ -8627,11 +8648,11 @@
86278648
** The session object will be used to create changesets for tables in
86288649
** database zDb, where zDb is either "main", or "temp", or the name of an
86298650
** attached database. It is not an error if database zDb is not attached
86308651
** to the database when the session object is created.
86318652
*/
8632
-int sqlite3session_create(
8653
+SQLITE_API int sqlite3session_create(
86338654
sqlite3 *db, /* Database handle */
86348655
const char *zDb, /* Name of db (e.g. "main") */
86358656
sqlite3_session **ppSession /* OUT: New session object */
86368657
);
86378658
@@ -8645,11 +8666,11 @@
86458666
**
86468667
** Session objects must be deleted before the database handle to which they
86478668
** are attached is closed. Refer to the documentation for
86488669
** [sqlite3session_create()] for details.
86498670
*/
8650
-void sqlite3session_delete(sqlite3_session *pSession);
8671
+SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);
86518672
86528673
86538674
/*
86548675
** CAPI3REF: Enable Or Disable A Session Object
86558676
**
@@ -8665,11 +8686,11 @@
86658686
** no-op, and may be used to query the current state of the session.
86668687
**
86678688
** The return value indicates the final state of the session object: 0 if
86688689
** the session is disabled, or 1 if it is enabled.
86698690
*/
8670
-int sqlite3session_enable(sqlite3_session *pSession, int bEnable);
8691
+SQLITE_API int sqlite3session_enable(sqlite3_session *pSession, int bEnable);
86718692
86728693
/*
86738694
** CAPI3REF: Set Or Clear the Indirect Change Flag
86748695
**
86758696
** Each change recorded by a session object is marked as either direct or
@@ -8694,11 +8715,11 @@
86948715
** indirect flag for the specified session object.
86958716
**
86968717
** The return value indicates the final state of the indirect flag: 0 if
86978718
** it is clear, or 1 if it is set.
86988719
*/
8699
-int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect);
8720
+SQLITE_API int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect);
87008721
87018722
/*
87028723
** CAPI3REF: Attach A Table To A Session Object
87038724
**
87048725
** If argument zTab is not NULL, then it is the name of a table to attach
@@ -8724,11 +8745,11 @@
87248745
** in one or more of their PRIMARY KEY columns.
87258746
**
87268747
** SQLITE_OK is returned if the call completes without error. Or, if an error
87278748
** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
87288749
*/
8729
-int sqlite3session_attach(
8750
+SQLITE_API int sqlite3session_attach(
87308751
sqlite3_session *pSession, /* Session object */
87318752
const char *zTab /* Table name */
87328753
);
87338754
87348755
/*
@@ -8738,11 +8759,11 @@
87388759
** in tables that are not attached to the Session object, the filter is called
87398760
** to determine whether changes to the table's rows should be tracked or not.
87408761
** If xFilter returns 0, changes is not tracked. Note that once a table is
87418762
** attached, xFilter will not be called again.
87428763
*/
8743
-void sqlite3session_table_filter(
8764
+SQLITE_API void sqlite3session_table_filter(
87448765
sqlite3_session *pSession, /* Session object */
87458766
int(*xFilter)(
87468767
void *pCtx, /* Copy of third arg to _filter_table() */
87478768
const char *zTab /* Table name */
87488769
),
@@ -8851,11 +8872,11 @@
88518872
** changeset, even though the delete took place while the session was disabled.
88528873
** Or, if one field of a row is updated while a session is disabled, and
88538874
** another field of the same row is updated while the session is enabled, the
88548875
** resulting changeset will contain an UPDATE change that updates both fields.
88558876
*/
8856
-int sqlite3session_changeset(
8877
+SQLITE_API int sqlite3session_changeset(
88578878
sqlite3_session *pSession, /* Session object */
88588879
int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */
88598880
void **ppChangeset /* OUT: Buffer containing changeset */
88608881
);
88618882
@@ -8895,11 +8916,12 @@
88958916
**
88968917
** <li> For each row (primary key) that exists in the to-table but not in
88978918
** the from-table, a DELETE record is added to the session object.
88988919
**
88998920
** <li> For each row (primary key) that exists in both tables, but features
8900
-** different in each, an UPDATE record is added to the session.
8921
+** different non-PK values in each, an UPDATE record is added to the
8922
+** session.
89018923
** </ul>
89028924
**
89038925
** To clarify, if this function is called and then a changeset constructed
89048926
** using [sqlite3session_changeset()], then after applying that changeset to
89058927
** database zFrom the contents of the two compatible tables would be
@@ -8912,11 +8934,11 @@
89128934
** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
89138935
** may be set to point to a buffer containing an English language error
89148936
** message. It is the responsibility of the caller to free this buffer using
89158937
** sqlite3_free().
89168938
*/
8917
-int sqlite3session_diff(
8939
+SQLITE_API int sqlite3session_diff(
89188940
sqlite3_session *pSession,
89198941
const char *zFromDb,
89208942
const char *zTbl,
89218943
char **pzErrMsg
89228944
);
@@ -8948,11 +8970,11 @@
89488970
** Changes within a patchset are ordered in the same way as for changesets
89498971
** generated by the sqlite3session_changeset() function (i.e. all changes for
89508972
** a single table are grouped together, tables appear in the order in which
89518973
** they were attached to the session object).
89528974
*/
8953
-int sqlite3session_patchset(
8975
+SQLITE_API int sqlite3session_patchset(
89548976
sqlite3_session *pSession, /* Session object */
89558977
int *pnPatchset, /* OUT: Size of buffer at *ppChangeset */
89568978
void **ppPatchset /* OUT: Buffer containing changeset */
89578979
);
89588980
@@ -8969,11 +8991,11 @@
89698991
** an attached table is modified and then later on the original values
89708992
** are restored. However, if this function returns non-zero, then it is
89718993
** guaranteed that a call to sqlite3session_changeset() will return a
89728994
** changeset containing zero changes.
89738995
*/
8974
-int sqlite3session_isempty(sqlite3_session *pSession);
8996
+SQLITE_API int sqlite3session_isempty(sqlite3_session *pSession);
89758997
89768998
/*
89778999
** CAPI3REF: Create An Iterator To Traverse A Changeset
89789000
**
89799001
** Create an iterator used to iterate through the contents of a changeset.
@@ -9004,11 +9026,11 @@
90049026
** this function, all changes that relate to a single table are visited
90059027
** consecutively. There is no chance that the iterator will visit a change
90069028
** the applies to table X, then one for table Y, and then later on visit
90079029
** another change for table X.
90089030
*/
9009
-int sqlite3changeset_start(
9031
+SQLITE_API int sqlite3changeset_start(
90109032
sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */
90119033
int nChangeset, /* Size of changeset blob in bytes */
90129034
void *pChangeset /* Pointer to blob containing changeset */
90139035
);
90149036
@@ -9033,11 +9055,11 @@
90339055
**
90349056
** If an error occurs, an SQLite error code is returned. Possible error
90359057
** codes include SQLITE_CORRUPT (if the changeset buffer is corrupt) or
90369058
** SQLITE_NOMEM.
90379059
*/
9038
-int sqlite3changeset_next(sqlite3_changeset_iter *pIter);
9060
+SQLITE_API int sqlite3changeset_next(sqlite3_changeset_iter *pIter);
90399061
90409062
/*
90419063
** CAPI3REF: Obtain The Current Operation From A Changeset Iterator
90429064
**
90439065
** The pIter argument passed to this function may either be an iterator
@@ -9061,11 +9083,11 @@
90619083
**
90629084
** If no error occurs, SQLITE_OK is returned. If an error does occur, an
90639085
** SQLite error code is returned. The values of the output variables may not
90649086
** be trusted in this case.
90659087
*/
9066
-int sqlite3changeset_op(
9088
+SQLITE_API int sqlite3changeset_op(
90679089
sqlite3_changeset_iter *pIter, /* Iterator object */
90689090
const char **pzTab, /* OUT: Pointer to table name */
90699091
int *pnCol, /* OUT: Number of columns in table */
90709092
int *pOp, /* OUT: SQLITE_INSERT, DELETE or UPDATE */
90719093
int *pbIndirect /* OUT: True for an 'indirect' change */
@@ -9094,11 +9116,11 @@
90949116
** If this function is called when the iterator does not point to a valid
90959117
** entry, SQLITE_MISUSE is returned and the output variables zeroed. Otherwise,
90969118
** SQLITE_OK is returned and the output variables populated as described
90979119
** above.
90989120
*/
9099
-int sqlite3changeset_pk(
9121
+SQLITE_API int sqlite3changeset_pk(
91009122
sqlite3_changeset_iter *pIter, /* Iterator object */
91019123
unsigned char **pabPK, /* OUT: Array of boolean - true for PK cols */
91029124
int *pnCol /* OUT: Number of entries in output array */
91039125
);
91049126
@@ -9124,11 +9146,11 @@
91249146
** is similar to the "old.*" columns available to update or delete triggers.
91259147
**
91269148
** If some other error occurs (e.g. an OOM condition), an SQLite error code
91279149
** is returned and *ppValue is set to NULL.
91289150
*/
9129
-int sqlite3changeset_old(
9151
+SQLITE_API int sqlite3changeset_old(
91309152
sqlite3_changeset_iter *pIter, /* Changeset iterator */
91319153
int iVal, /* Column number */
91329154
sqlite3_value **ppValue /* OUT: Old value (or NULL pointer) */
91339155
);
91349156
@@ -9157,11 +9179,11 @@
91579179
** triggers.
91589180
**
91599181
** If some other error occurs (e.g. an OOM condition), an SQLite error code
91609182
** is returned and *ppValue is set to NULL.
91619183
*/
9162
-int sqlite3changeset_new(
9184
+SQLITE_API int sqlite3changeset_new(
91639185
sqlite3_changeset_iter *pIter, /* Changeset iterator */
91649186
int iVal, /* Column number */
91659187
sqlite3_value **ppValue /* OUT: New value (or NULL pointer) */
91669188
);
91679189
@@ -9184,11 +9206,11 @@
91849206
** and returns SQLITE_OK.
91859207
**
91869208
** If some other error occurs (e.g. an OOM condition), an SQLite error code
91879209
** is returned and *ppValue is set to NULL.
91889210
*/
9189
-int sqlite3changeset_conflict(
9211
+SQLITE_API int sqlite3changeset_conflict(
91909212
sqlite3_changeset_iter *pIter, /* Changeset iterator */
91919213
int iVal, /* Column number */
91929214
sqlite3_value **ppValue /* OUT: Value from conflicting row */
91939215
);
91949216
@@ -9200,11 +9222,11 @@
92009222
** it sets the output variable to the total number of known foreign key
92019223
** violations in the destination database and returns SQLITE_OK.
92029224
**
92039225
** In all other cases this function returns SQLITE_MISUSE.
92049226
*/
9205
-int sqlite3changeset_fk_conflicts(
9227
+SQLITE_API int sqlite3changeset_fk_conflicts(
92069228
sqlite3_changeset_iter *pIter, /* Changeset iterator */
92079229
int *pnOut /* OUT: Number of FK violations */
92089230
);
92099231
92109232
@@ -9233,11 +9255,11 @@
92339255
** rc = sqlite3changeset_finalize();
92349256
** if( rc!=SQLITE_OK ){
92359257
** // An error has occurred
92369258
** }
92379259
*/
9238
-int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter);
9260
+SQLITE_API int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter);
92399261
92409262
/*
92419263
** CAPI3REF: Invert A Changeset
92429264
**
92439265
** This function is used to "invert" a changeset object. Applying an inverted
@@ -9263,11 +9285,11 @@
92639285
** call to this function.
92649286
**
92659287
** WARNING/TODO: This function currently assumes that the input is a valid
92669288
** changeset. If it is not, the results are undefined.
92679289
*/
9268
-int sqlite3changeset_invert(
9290
+SQLITE_API int sqlite3changeset_invert(
92699291
int nIn, const void *pIn, /* Input changeset */
92709292
int *pnOut, void **ppOut /* OUT: Inverse of input */
92719293
);
92729294
92739295
/*
@@ -9292,11 +9314,11 @@
92929314
** *pnOut = 0;
92939315
** }
92949316
**
92959317
** Refer to the sqlite3_changegroup documentation below for details.
92969318
*/
9297
-int sqlite3changeset_concat(
9319
+SQLITE_API int sqlite3changeset_concat(
92989320
int nA, /* Number of bytes in buffer pA */
92999321
void *pA, /* Pointer to buffer containing changeset A */
93009322
int nB, /* Number of bytes in buffer pB */
93019323
void *pB, /* Pointer to buffer containing changeset B */
93029324
int *pnOut, /* OUT: Number of bytes in output changeset */
@@ -9480,11 +9502,11 @@
94809502
** considered compatible if all of the following are true:
94819503
**
94829504
** <ul>
94839505
** <li> The table has the same name as the name recorded in the
94849506
** changeset, and
9485
-** <li> The table has the same number of columns as recorded in the
9507
+** <li> The table has at least as many columns as recorded in the
94869508
** changeset, and
94879509
** <li> The table has primary key columns in the same position as
94889510
** recorded in the changeset.
94899511
** </ul>
94909512
**
@@ -9525,11 +9547,15 @@
95259547
** the changeset the row is deleted from the target database.
95269548
**
95279549
** If a row with matching primary key values is found, but one or more of
95289550
** the non-primary key fields contains a value different from the original
95299551
** row value stored in the changeset, the conflict-handler function is
9530
-** invoked with [SQLITE_CHANGESET_DATA] as the second argument.
9552
+** invoked with [SQLITE_CHANGESET_DATA] as the second argument. If the
9553
+** database table has more columns than are recorded in the changeset,
9554
+** only the values of those non-primary key fields are compared against
9555
+** the current database contents - any trailing database table columns
9556
+** are ignored.
95319557
**
95329558
** If no row with matching primary key values is found in the database,
95339559
** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
95349560
** passed as the second argument.
95359561
**
@@ -9540,11 +9566,13 @@
95409566
** operation is attempted because an earlier call to the conflict handler
95419567
** function returned [SQLITE_CHANGESET_REPLACE].
95429568
**
95439569
** <dt>INSERT Changes<dd>
95449570
** For each INSERT change, an attempt is made to insert the new row into
9545
-** the database.
9571
+** the database. If the changeset row contains fewer fields than the
9572
+** database table, the trailing fields are populated with their default
9573
+** values.
95469574
**
95479575
** If the attempt to insert the row fails because the database already
95489576
** contains a row with the same primary key values, the conflict handler
95499577
** function is invoked with the second argument set to
95509578
** [SQLITE_CHANGESET_CONFLICT].
@@ -9558,17 +9586,17 @@
95589586
**
95599587
** <dt>UPDATE Changes<dd>
95609588
** For each UPDATE change, this function checks if the target database
95619589
** contains a row with the same primary key value (or values) as the
95629590
** original row values stored in the changeset. If it does, and the values
9563
-** stored in all non-primary key columns also match the values stored in
9564
-** the changeset the row is updated within the target database.
9591
+** stored in all modified non-primary key columns also match the values
9592
+** stored in the changeset the row is updated within the target database.
95659593
**
95669594
** If a row with matching primary key values is found, but one or more of
9567
-** the non-primary key fields contains a value different from an original
9568
-** row value stored in the changeset, the conflict-handler function is
9569
-** invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since
9595
+** the modified non-primary key fields contains a value different from an
9596
+** original row value stored in the changeset, the conflict-handler function
9597
+** is invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since
95709598
** UPDATE changes only contain values for non-primary key fields that are
95719599
** to be modified, only those fields need to match the original values to
95729600
** avoid the SQLITE_CHANGESET_DATA conflict-handler callback.
95739601
**
95749602
** If no row with matching primary key values is found in the database,
@@ -9592,11 +9620,11 @@
95929620
** If any other error (aside from a constraint failure when attempting to
95939621
** write to the target database) occurs, then the savepoint transaction is
95949622
** rolled back, restoring the target database to its original state, and an
95959623
** SQLite error code returned.
95969624
*/
9597
-int sqlite3changeset_apply(
9625
+SQLITE_API int sqlite3changeset_apply(
95989626
sqlite3 *db, /* Apply change to "main" db of this handle */
95999627
int nChangeset, /* Size of changeset in bytes */
96009628
void *pChangeset, /* Changeset blob */
96019629
int(*xFilter)(
96029630
void *pCtx, /* Copy of sixth arg to _apply() */
@@ -9793,11 +9821,11 @@
97939821
**
97949822
** The sessions module never invokes an xOutput callback with the third
97959823
** parameter set to a value less than or equal to zero. Other than this,
97969824
** no guarantees are made as to the size of the chunks of data returned.
97979825
*/
9798
-int sqlite3changeset_apply_strm(
9826
+SQLITE_API int sqlite3changeset_apply_strm(
97999827
sqlite3 *db, /* Apply change to "main" db of this handle */
98009828
int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
98019829
void *pIn, /* First arg for xInput */
98029830
int(*xFilter)(
98039831
void *pCtx, /* Copy of sixth arg to _apply() */
@@ -9808,35 +9836,35 @@
98089836
int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
98099837
sqlite3_changeset_iter *p /* Handle describing change and conflict */
98109838
),
98119839
void *pCtx /* First argument passed to xConflict */
98129840
);
9813
-int sqlite3changeset_concat_strm(
9841
+SQLITE_API int sqlite3changeset_concat_strm(
98149842
int (*xInputA)(void *pIn, void *pData, int *pnData),
98159843
void *pInA,
98169844
int (*xInputB)(void *pIn, void *pData, int *pnData),
98179845
void *pInB,
98189846
int (*xOutput)(void *pOut, const void *pData, int nData),
98199847
void *pOut
98209848
);
9821
-int sqlite3changeset_invert_strm(
9849
+SQLITE_API int sqlite3changeset_invert_strm(
98229850
int (*xInput)(void *pIn, void *pData, int *pnData),
98239851
void *pIn,
98249852
int (*xOutput)(void *pOut, const void *pData, int nData),
98259853
void *pOut
98269854
);
9827
-int sqlite3changeset_start_strm(
9855
+SQLITE_API int sqlite3changeset_start_strm(
98289856
sqlite3_changeset_iter **pp,
98299857
int (*xInput)(void *pIn, void *pData, int *pnData),
98309858
void *pIn
98319859
);
9832
-int sqlite3session_changeset_strm(
9860
+SQLITE_API int sqlite3session_changeset_strm(
98339861
sqlite3_session *pSession,
98349862
int (*xOutput)(void *pOut, const void *pData, int nData),
98359863
void *pOut
98369864
);
9837
-int sqlite3session_patchset_strm(
9865
+SQLITE_API int sqlite3session_patchset_strm(
98389866
sqlite3_session *pSession,
98399867
int (*xOutput)(void *pOut, const void *pData, int nData),
98409868
void *pOut
98419869
);
98429870
int sqlite3changegroup_add_strm(sqlite3_changegroup*,
98439871
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -119,13 +119,13 @@
119 **
120 ** See also: [sqlite3_libversion()],
121 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122 ** [sqlite_version()] and [sqlite_source_id()].
123 */
124 #define SQLITE_VERSION "3.16.2"
125 #define SQLITE_VERSION_NUMBER 3016002
126 #define SQLITE_SOURCE_ID "2017-01-06 16:32:41 a65a62893ca8319e89e48b8a38cf8a59c69a8209"
127
128 /*
129 ** CAPI3REF: Run-Time Library Version Numbers
130 ** KEYWORDS: sqlite3_version sqlite3_sourceid
131 **
@@ -257,11 +257,15 @@
257 ** sqlite3_uint64 and sqlite_uint64 types can store integer values
258 ** between 0 and +18446744073709551615 inclusive.
259 */
260 #ifdef SQLITE_INT64_TYPE
261 typedef SQLITE_INT64_TYPE sqlite_int64;
262 typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
 
 
 
 
263 #elif defined(_MSC_VER) || defined(__BORLANDC__)
264 typedef __int64 sqlite_int64;
265 typedef unsigned __int64 sqlite_uint64;
266 #else
267 typedef long long int sqlite_int64;
@@ -570,11 +574,11 @@
570 ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
571 ** after reboot following a crash or power loss, the only bytes in a
572 ** file that were written at the application level might have changed
573 ** and that adjacent bytes, even bytes within the same sector are
574 ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
575 ** flag indicate that a file cannot be deleted when open. The
576 ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
577 ** read-only media and cannot be changed even by processes with
578 ** elevated privileges.
579 */
580 #define SQLITE_IOCAP_ATOMIC 0x00000001
@@ -720,10 +724,13 @@
720 ** <li> [SQLITE_IOCAP_ATOMIC16K]
721 ** <li> [SQLITE_IOCAP_ATOMIC32K]
722 ** <li> [SQLITE_IOCAP_ATOMIC64K]
723 ** <li> [SQLITE_IOCAP_SAFE_APPEND]
724 ** <li> [SQLITE_IOCAP_SEQUENTIAL]
 
 
 
725 ** </ul>
726 **
727 ** The SQLITE_IOCAP_ATOMIC property means that all writes of
728 ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
729 ** mean that writes of blocks that are nnn bytes in size and
@@ -5408,11 +5415,11 @@
5408 ** ^(The update hook is not invoked when internal system tables are
5409 ** modified (i.e. sqlite_master and sqlite_sequence).)^
5410 ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
5411 **
5412 ** ^In the current implementation, the update hook
5413 ** is not invoked when duplication rows are deleted because of an
5414 ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
5415 ** invoked when rows are deleted using the [truncate optimization].
5416 ** The exceptions defined in this paragraph might change in a future
5417 ** release of SQLite.
5418 **
@@ -6190,10 +6197,16 @@
6190 **
6191 ** ^Unless it returns SQLITE_MISUSE, this function sets the
6192 ** [database connection] error code and message accessible via
6193 ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
6194 **
 
 
 
 
 
 
6195 **
6196 ** ^(If the row that a BLOB handle points to is modified by an
6197 ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
6198 ** then the BLOB handle is marked as "expired".
6199 ** This is true if any column of the row is changed, even a column
@@ -6213,10 +6226,14 @@
6213 ** and the built-in [zeroblob] SQL function may be used to create a
6214 ** zero-filled blob to read or write using the incremental-blob interface.
6215 **
6216 ** To avoid a resource leak, every open [BLOB handle] should eventually
6217 ** be released by a call to [sqlite3_blob_close()].
 
 
 
 
6218 */
6219 SQLITE_API int sqlite3_blob_open(
6220 sqlite3*,
6221 const char *zDb,
6222 const char *zTable,
@@ -6228,15 +6245,15 @@
6228
6229 /*
6230 ** CAPI3REF: Move a BLOB Handle to a New Row
6231 ** METHOD: sqlite3_blob
6232 **
6233 ** ^This function is used to move an existing blob handle so that it points
6234 ** to a different row of the same database table. ^The new row is identified
6235 ** by the rowid value passed as the second argument. Only the row can be
6236 ** changed. ^The database, table and column on which the blob handle is open
6237 ** remain the same. Moving an existing blob handle to a new row can be
6238 ** faster than closing the existing handle and opening a new one.
6239 **
6240 ** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] -
6241 ** it must exist and there must be either a blob or text value stored in
6242 ** the nominated column.)^ ^If the new row is not present in the table, or if
@@ -8161,22 +8178,22 @@
8161 ** ^These interfaces are only available if SQLite is compiled using the
8162 ** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option.
8163 **
8164 ** ^The [sqlite3_preupdate_hook()] interface registers a callback function
8165 ** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation
8166 ** on a [rowid table].
8167 ** ^At most one preupdate hook may be registered at a time on a single
8168 ** [database connection]; each call to [sqlite3_preupdate_hook()] overrides
8169 ** the previous setting.
8170 ** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()]
8171 ** with a NULL pointer as the second parameter.
8172 ** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as
8173 ** the first parameter to callbacks.
8174 **
8175 ** ^The preupdate hook only fires for changes to [rowid tables]; the preupdate
8176 ** hook is not invoked for changes to [virtual tables] or [WITHOUT ROWID]
8177 ** tables.
8178 **
8179 ** ^The second parameter to the preupdate callback is a pointer to
8180 ** the [database connection] that registered the preupdate hook.
8181 ** ^The third parameter to the preupdate callback is one of the constants
8182 ** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the
@@ -8186,16 +8203,20 @@
8186 ** will be "main" for the main database or "temp" for TEMP tables or
8187 ** the name given after the AS keyword in the [ATTACH] statement for attached
8188 ** databases.)^
8189 ** ^The fifth parameter to the preupdate callback is the name of the
8190 ** table that is being modified.
8191 ** ^The sixth parameter to the preupdate callback is the initial [rowid] of the
8192 ** row being changes for SQLITE_UPDATE and SQLITE_DELETE changes and is
8193 ** undefined for SQLITE_INSERT changes.
8194 ** ^The seventh parameter to the preupdate callback is the final [rowid] of
8195 ** the row being changed for SQLITE_UPDATE and SQLITE_INSERT changes and is
8196 ** undefined for SQLITE_DELETE changes.
 
 
 
 
8197 **
8198 ** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
8199 ** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
8200 ** provide additional information about a preupdate event. These routines
8201 ** may only be called from within a preupdate callback. Invoking any of
@@ -8627,11 +8648,11 @@
8627 ** The session object will be used to create changesets for tables in
8628 ** database zDb, where zDb is either "main", or "temp", or the name of an
8629 ** attached database. It is not an error if database zDb is not attached
8630 ** to the database when the session object is created.
8631 */
8632 int sqlite3session_create(
8633 sqlite3 *db, /* Database handle */
8634 const char *zDb, /* Name of db (e.g. "main") */
8635 sqlite3_session **ppSession /* OUT: New session object */
8636 );
8637
@@ -8645,11 +8666,11 @@
8645 **
8646 ** Session objects must be deleted before the database handle to which they
8647 ** are attached is closed. Refer to the documentation for
8648 ** [sqlite3session_create()] for details.
8649 */
8650 void sqlite3session_delete(sqlite3_session *pSession);
8651
8652
8653 /*
8654 ** CAPI3REF: Enable Or Disable A Session Object
8655 **
@@ -8665,11 +8686,11 @@
8665 ** no-op, and may be used to query the current state of the session.
8666 **
8667 ** The return value indicates the final state of the session object: 0 if
8668 ** the session is disabled, or 1 if it is enabled.
8669 */
8670 int sqlite3session_enable(sqlite3_session *pSession, int bEnable);
8671
8672 /*
8673 ** CAPI3REF: Set Or Clear the Indirect Change Flag
8674 **
8675 ** Each change recorded by a session object is marked as either direct or
@@ -8694,11 +8715,11 @@
8694 ** indirect flag for the specified session object.
8695 **
8696 ** The return value indicates the final state of the indirect flag: 0 if
8697 ** it is clear, or 1 if it is set.
8698 */
8699 int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect);
8700
8701 /*
8702 ** CAPI3REF: Attach A Table To A Session Object
8703 **
8704 ** If argument zTab is not NULL, then it is the name of a table to attach
@@ -8724,11 +8745,11 @@
8724 ** in one or more of their PRIMARY KEY columns.
8725 **
8726 ** SQLITE_OK is returned if the call completes without error. Or, if an error
8727 ** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
8728 */
8729 int sqlite3session_attach(
8730 sqlite3_session *pSession, /* Session object */
8731 const char *zTab /* Table name */
8732 );
8733
8734 /*
@@ -8738,11 +8759,11 @@
8738 ** in tables that are not attached to the Session object, the filter is called
8739 ** to determine whether changes to the table's rows should be tracked or not.
8740 ** If xFilter returns 0, changes is not tracked. Note that once a table is
8741 ** attached, xFilter will not be called again.
8742 */
8743 void sqlite3session_table_filter(
8744 sqlite3_session *pSession, /* Session object */
8745 int(*xFilter)(
8746 void *pCtx, /* Copy of third arg to _filter_table() */
8747 const char *zTab /* Table name */
8748 ),
@@ -8851,11 +8872,11 @@
8851 ** changeset, even though the delete took place while the session was disabled.
8852 ** Or, if one field of a row is updated while a session is disabled, and
8853 ** another field of the same row is updated while the session is enabled, the
8854 ** resulting changeset will contain an UPDATE change that updates both fields.
8855 */
8856 int sqlite3session_changeset(
8857 sqlite3_session *pSession, /* Session object */
8858 int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */
8859 void **ppChangeset /* OUT: Buffer containing changeset */
8860 );
8861
@@ -8895,11 +8916,12 @@
8895 **
8896 ** <li> For each row (primary key) that exists in the to-table but not in
8897 ** the from-table, a DELETE record is added to the session object.
8898 **
8899 ** <li> For each row (primary key) that exists in both tables, but features
8900 ** different in each, an UPDATE record is added to the session.
 
8901 ** </ul>
8902 **
8903 ** To clarify, if this function is called and then a changeset constructed
8904 ** using [sqlite3session_changeset()], then after applying that changeset to
8905 ** database zFrom the contents of the two compatible tables would be
@@ -8912,11 +8934,11 @@
8912 ** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
8913 ** may be set to point to a buffer containing an English language error
8914 ** message. It is the responsibility of the caller to free this buffer using
8915 ** sqlite3_free().
8916 */
8917 int sqlite3session_diff(
8918 sqlite3_session *pSession,
8919 const char *zFromDb,
8920 const char *zTbl,
8921 char **pzErrMsg
8922 );
@@ -8948,11 +8970,11 @@
8948 ** Changes within a patchset are ordered in the same way as for changesets
8949 ** generated by the sqlite3session_changeset() function (i.e. all changes for
8950 ** a single table are grouped together, tables appear in the order in which
8951 ** they were attached to the session object).
8952 */
8953 int sqlite3session_patchset(
8954 sqlite3_session *pSession, /* Session object */
8955 int *pnPatchset, /* OUT: Size of buffer at *ppChangeset */
8956 void **ppPatchset /* OUT: Buffer containing changeset */
8957 );
8958
@@ -8969,11 +8991,11 @@
8969 ** an attached table is modified and then later on the original values
8970 ** are restored. However, if this function returns non-zero, then it is
8971 ** guaranteed that a call to sqlite3session_changeset() will return a
8972 ** changeset containing zero changes.
8973 */
8974 int sqlite3session_isempty(sqlite3_session *pSession);
8975
8976 /*
8977 ** CAPI3REF: Create An Iterator To Traverse A Changeset
8978 **
8979 ** Create an iterator used to iterate through the contents of a changeset.
@@ -9004,11 +9026,11 @@
9004 ** this function, all changes that relate to a single table are visited
9005 ** consecutively. There is no chance that the iterator will visit a change
9006 ** the applies to table X, then one for table Y, and then later on visit
9007 ** another change for table X.
9008 */
9009 int sqlite3changeset_start(
9010 sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */
9011 int nChangeset, /* Size of changeset blob in bytes */
9012 void *pChangeset /* Pointer to blob containing changeset */
9013 );
9014
@@ -9033,11 +9055,11 @@
9033 **
9034 ** If an error occurs, an SQLite error code is returned. Possible error
9035 ** codes include SQLITE_CORRUPT (if the changeset buffer is corrupt) or
9036 ** SQLITE_NOMEM.
9037 */
9038 int sqlite3changeset_next(sqlite3_changeset_iter *pIter);
9039
9040 /*
9041 ** CAPI3REF: Obtain The Current Operation From A Changeset Iterator
9042 **
9043 ** The pIter argument passed to this function may either be an iterator
@@ -9061,11 +9083,11 @@
9061 **
9062 ** If no error occurs, SQLITE_OK is returned. If an error does occur, an
9063 ** SQLite error code is returned. The values of the output variables may not
9064 ** be trusted in this case.
9065 */
9066 int sqlite3changeset_op(
9067 sqlite3_changeset_iter *pIter, /* Iterator object */
9068 const char **pzTab, /* OUT: Pointer to table name */
9069 int *pnCol, /* OUT: Number of columns in table */
9070 int *pOp, /* OUT: SQLITE_INSERT, DELETE or UPDATE */
9071 int *pbIndirect /* OUT: True for an 'indirect' change */
@@ -9094,11 +9116,11 @@
9094 ** If this function is called when the iterator does not point to a valid
9095 ** entry, SQLITE_MISUSE is returned and the output variables zeroed. Otherwise,
9096 ** SQLITE_OK is returned and the output variables populated as described
9097 ** above.
9098 */
9099 int sqlite3changeset_pk(
9100 sqlite3_changeset_iter *pIter, /* Iterator object */
9101 unsigned char **pabPK, /* OUT: Array of boolean - true for PK cols */
9102 int *pnCol /* OUT: Number of entries in output array */
9103 );
9104
@@ -9124,11 +9146,11 @@
9124 ** is similar to the "old.*" columns available to update or delete triggers.
9125 **
9126 ** If some other error occurs (e.g. an OOM condition), an SQLite error code
9127 ** is returned and *ppValue is set to NULL.
9128 */
9129 int sqlite3changeset_old(
9130 sqlite3_changeset_iter *pIter, /* Changeset iterator */
9131 int iVal, /* Column number */
9132 sqlite3_value **ppValue /* OUT: Old value (or NULL pointer) */
9133 );
9134
@@ -9157,11 +9179,11 @@
9157 ** triggers.
9158 **
9159 ** If some other error occurs (e.g. an OOM condition), an SQLite error code
9160 ** is returned and *ppValue is set to NULL.
9161 */
9162 int sqlite3changeset_new(
9163 sqlite3_changeset_iter *pIter, /* Changeset iterator */
9164 int iVal, /* Column number */
9165 sqlite3_value **ppValue /* OUT: New value (or NULL pointer) */
9166 );
9167
@@ -9184,11 +9206,11 @@
9184 ** and returns SQLITE_OK.
9185 **
9186 ** If some other error occurs (e.g. an OOM condition), an SQLite error code
9187 ** is returned and *ppValue is set to NULL.
9188 */
9189 int sqlite3changeset_conflict(
9190 sqlite3_changeset_iter *pIter, /* Changeset iterator */
9191 int iVal, /* Column number */
9192 sqlite3_value **ppValue /* OUT: Value from conflicting row */
9193 );
9194
@@ -9200,11 +9222,11 @@
9200 ** it sets the output variable to the total number of known foreign key
9201 ** violations in the destination database and returns SQLITE_OK.
9202 **
9203 ** In all other cases this function returns SQLITE_MISUSE.
9204 */
9205 int sqlite3changeset_fk_conflicts(
9206 sqlite3_changeset_iter *pIter, /* Changeset iterator */
9207 int *pnOut /* OUT: Number of FK violations */
9208 );
9209
9210
@@ -9233,11 +9255,11 @@
9233 ** rc = sqlite3changeset_finalize();
9234 ** if( rc!=SQLITE_OK ){
9235 ** // An error has occurred
9236 ** }
9237 */
9238 int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter);
9239
9240 /*
9241 ** CAPI3REF: Invert A Changeset
9242 **
9243 ** This function is used to "invert" a changeset object. Applying an inverted
@@ -9263,11 +9285,11 @@
9263 ** call to this function.
9264 **
9265 ** WARNING/TODO: This function currently assumes that the input is a valid
9266 ** changeset. If it is not, the results are undefined.
9267 */
9268 int sqlite3changeset_invert(
9269 int nIn, const void *pIn, /* Input changeset */
9270 int *pnOut, void **ppOut /* OUT: Inverse of input */
9271 );
9272
9273 /*
@@ -9292,11 +9314,11 @@
9292 ** *pnOut = 0;
9293 ** }
9294 **
9295 ** Refer to the sqlite3_changegroup documentation below for details.
9296 */
9297 int sqlite3changeset_concat(
9298 int nA, /* Number of bytes in buffer pA */
9299 void *pA, /* Pointer to buffer containing changeset A */
9300 int nB, /* Number of bytes in buffer pB */
9301 void *pB, /* Pointer to buffer containing changeset B */
9302 int *pnOut, /* OUT: Number of bytes in output changeset */
@@ -9480,11 +9502,11 @@
9480 ** considered compatible if all of the following are true:
9481 **
9482 ** <ul>
9483 ** <li> The table has the same name as the name recorded in the
9484 ** changeset, and
9485 ** <li> The table has the same number of columns as recorded in the
9486 ** changeset, and
9487 ** <li> The table has primary key columns in the same position as
9488 ** recorded in the changeset.
9489 ** </ul>
9490 **
@@ -9525,11 +9547,15 @@
9525 ** the changeset the row is deleted from the target database.
9526 **
9527 ** If a row with matching primary key values is found, but one or more of
9528 ** the non-primary key fields contains a value different from the original
9529 ** row value stored in the changeset, the conflict-handler function is
9530 ** invoked with [SQLITE_CHANGESET_DATA] as the second argument.
 
 
 
 
9531 **
9532 ** If no row with matching primary key values is found in the database,
9533 ** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
9534 ** passed as the second argument.
9535 **
@@ -9540,11 +9566,13 @@
9540 ** operation is attempted because an earlier call to the conflict handler
9541 ** function returned [SQLITE_CHANGESET_REPLACE].
9542 **
9543 ** <dt>INSERT Changes<dd>
9544 ** For each INSERT change, an attempt is made to insert the new row into
9545 ** the database.
 
 
9546 **
9547 ** If the attempt to insert the row fails because the database already
9548 ** contains a row with the same primary key values, the conflict handler
9549 ** function is invoked with the second argument set to
9550 ** [SQLITE_CHANGESET_CONFLICT].
@@ -9558,17 +9586,17 @@
9558 **
9559 ** <dt>UPDATE Changes<dd>
9560 ** For each UPDATE change, this function checks if the target database
9561 ** contains a row with the same primary key value (or values) as the
9562 ** original row values stored in the changeset. If it does, and the values
9563 ** stored in all non-primary key columns also match the values stored in
9564 ** the changeset the row is updated within the target database.
9565 **
9566 ** If a row with matching primary key values is found, but one or more of
9567 ** the non-primary key fields contains a value different from an original
9568 ** row value stored in the changeset, the conflict-handler function is
9569 ** invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since
9570 ** UPDATE changes only contain values for non-primary key fields that are
9571 ** to be modified, only those fields need to match the original values to
9572 ** avoid the SQLITE_CHANGESET_DATA conflict-handler callback.
9573 **
9574 ** If no row with matching primary key values is found in the database,
@@ -9592,11 +9620,11 @@
9592 ** If any other error (aside from a constraint failure when attempting to
9593 ** write to the target database) occurs, then the savepoint transaction is
9594 ** rolled back, restoring the target database to its original state, and an
9595 ** SQLite error code returned.
9596 */
9597 int sqlite3changeset_apply(
9598 sqlite3 *db, /* Apply change to "main" db of this handle */
9599 int nChangeset, /* Size of changeset in bytes */
9600 void *pChangeset, /* Changeset blob */
9601 int(*xFilter)(
9602 void *pCtx, /* Copy of sixth arg to _apply() */
@@ -9793,11 +9821,11 @@
9793 **
9794 ** The sessions module never invokes an xOutput callback with the third
9795 ** parameter set to a value less than or equal to zero. Other than this,
9796 ** no guarantees are made as to the size of the chunks of data returned.
9797 */
9798 int sqlite3changeset_apply_strm(
9799 sqlite3 *db, /* Apply change to "main" db of this handle */
9800 int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
9801 void *pIn, /* First arg for xInput */
9802 int(*xFilter)(
9803 void *pCtx, /* Copy of sixth arg to _apply() */
@@ -9808,35 +9836,35 @@
9808 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
9809 sqlite3_changeset_iter *p /* Handle describing change and conflict */
9810 ),
9811 void *pCtx /* First argument passed to xConflict */
9812 );
9813 int sqlite3changeset_concat_strm(
9814 int (*xInputA)(void *pIn, void *pData, int *pnData),
9815 void *pInA,
9816 int (*xInputB)(void *pIn, void *pData, int *pnData),
9817 void *pInB,
9818 int (*xOutput)(void *pOut, const void *pData, int nData),
9819 void *pOut
9820 );
9821 int sqlite3changeset_invert_strm(
9822 int (*xInput)(void *pIn, void *pData, int *pnData),
9823 void *pIn,
9824 int (*xOutput)(void *pOut, const void *pData, int nData),
9825 void *pOut
9826 );
9827 int sqlite3changeset_start_strm(
9828 sqlite3_changeset_iter **pp,
9829 int (*xInput)(void *pIn, void *pData, int *pnData),
9830 void *pIn
9831 );
9832 int sqlite3session_changeset_strm(
9833 sqlite3_session *pSession,
9834 int (*xOutput)(void *pOut, const void *pData, int nData),
9835 void *pOut
9836 );
9837 int sqlite3session_patchset_strm(
9838 sqlite3_session *pSession,
9839 int (*xOutput)(void *pOut, const void *pData, int nData),
9840 void *pOut
9841 );
9842 int sqlite3changegroup_add_strm(sqlite3_changegroup*,
9843
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -119,13 +119,13 @@
119 **
120 ** See also: [sqlite3_libversion()],
121 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122 ** [sqlite_version()] and [sqlite_source_id()].
123 */
124 #define SQLITE_VERSION "3.17.0"
125 #define SQLITE_VERSION_NUMBER 3017000
126 #define SQLITE_SOURCE_ID "2017-02-13 16:02:40 ada05cfa86ad7f5645450ac7a2a21c9aa6e57d2c"
127
128 /*
129 ** CAPI3REF: Run-Time Library Version Numbers
130 ** KEYWORDS: sqlite3_version sqlite3_sourceid
131 **
@@ -257,11 +257,15 @@
257 ** sqlite3_uint64 and sqlite_uint64 types can store integer values
258 ** between 0 and +18446744073709551615 inclusive.
259 */
260 #ifdef SQLITE_INT64_TYPE
261 typedef SQLITE_INT64_TYPE sqlite_int64;
262 # ifdef SQLITE_UINT64_TYPE
263 typedef SQLITE_UINT64_TYPE sqlite_uint64;
264 # else
265 typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
266 # endif
267 #elif defined(_MSC_VER) || defined(__BORLANDC__)
268 typedef __int64 sqlite_int64;
269 typedef unsigned __int64 sqlite_uint64;
270 #else
271 typedef long long int sqlite_int64;
@@ -570,11 +574,11 @@
574 ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
575 ** after reboot following a crash or power loss, the only bytes in a
576 ** file that were written at the application level might have changed
577 ** and that adjacent bytes, even bytes within the same sector are
578 ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
579 ** flag indicates that a file cannot be deleted when open. The
580 ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
581 ** read-only media and cannot be changed even by processes with
582 ** elevated privileges.
583 */
584 #define SQLITE_IOCAP_ATOMIC 0x00000001
@@ -720,10 +724,13 @@
724 ** <li> [SQLITE_IOCAP_ATOMIC16K]
725 ** <li> [SQLITE_IOCAP_ATOMIC32K]
726 ** <li> [SQLITE_IOCAP_ATOMIC64K]
727 ** <li> [SQLITE_IOCAP_SAFE_APPEND]
728 ** <li> [SQLITE_IOCAP_SEQUENTIAL]
729 ** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]
730 ** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
731 ** <li> [SQLITE_IOCAP_IMMUTABLE]
732 ** </ul>
733 **
734 ** The SQLITE_IOCAP_ATOMIC property means that all writes of
735 ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
736 ** mean that writes of blocks that are nnn bytes in size and
@@ -5408,11 +5415,11 @@
5415 ** ^(The update hook is not invoked when internal system tables are
5416 ** modified (i.e. sqlite_master and sqlite_sequence).)^
5417 ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
5418 **
5419 ** ^In the current implementation, the update hook
5420 ** is not invoked when conflicting rows are deleted because of an
5421 ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
5422 ** invoked when rows are deleted using the [truncate optimization].
5423 ** The exceptions defined in this paragraph might change in a future
5424 ** release of SQLite.
5425 **
@@ -6190,10 +6197,16 @@
6197 **
6198 ** ^Unless it returns SQLITE_MISUSE, this function sets the
6199 ** [database connection] error code and message accessible via
6200 ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
6201 **
6202 ** A BLOB referenced by sqlite3_blob_open() may be read using the
6203 ** [sqlite3_blob_read()] interface and modified by using
6204 ** [sqlite3_blob_write()]. The [BLOB handle] can be moved to a
6205 ** different row of the same table using the [sqlite3_blob_reopen()]
6206 ** interface. However, the column, table, or database of a [BLOB handle]
6207 ** cannot be changed after the [BLOB handle] is opened.
6208 **
6209 ** ^(If the row that a BLOB handle points to is modified by an
6210 ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
6211 ** then the BLOB handle is marked as "expired".
6212 ** This is true if any column of the row is changed, even a column
@@ -6213,10 +6226,14 @@
6226 ** and the built-in [zeroblob] SQL function may be used to create a
6227 ** zero-filled blob to read or write using the incremental-blob interface.
6228 **
6229 ** To avoid a resource leak, every open [BLOB handle] should eventually
6230 ** be released by a call to [sqlite3_blob_close()].
6231 **
6232 ** See also: [sqlite3_blob_close()],
6233 ** [sqlite3_blob_reopen()], [sqlite3_blob_read()],
6234 ** [sqlite3_blob_bytes()], [sqlite3_blob_write()].
6235 */
6236 SQLITE_API int sqlite3_blob_open(
6237 sqlite3*,
6238 const char *zDb,
6239 const char *zTable,
@@ -6228,15 +6245,15 @@
6245
6246 /*
6247 ** CAPI3REF: Move a BLOB Handle to a New Row
6248 ** METHOD: sqlite3_blob
6249 **
6250 ** ^This function is used to move an existing [BLOB handle] so that it points
6251 ** to a different row of the same database table. ^The new row is identified
6252 ** by the rowid value passed as the second argument. Only the row can be
6253 ** changed. ^The database, table and column on which the blob handle is open
6254 ** remain the same. Moving an existing [BLOB handle] to a new row is
6255 ** faster than closing the existing handle and opening a new one.
6256 **
6257 ** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] -
6258 ** it must exist and there must be either a blob or text value stored in
6259 ** the nominated column.)^ ^If the new row is not present in the table, or if
@@ -8161,22 +8178,22 @@
8178 ** ^These interfaces are only available if SQLite is compiled using the
8179 ** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option.
8180 **
8181 ** ^The [sqlite3_preupdate_hook()] interface registers a callback function
8182 ** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation
8183 ** on a database table.
8184 ** ^At most one preupdate hook may be registered at a time on a single
8185 ** [database connection]; each call to [sqlite3_preupdate_hook()] overrides
8186 ** the previous setting.
8187 ** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()]
8188 ** with a NULL pointer as the second parameter.
8189 ** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as
8190 ** the first parameter to callbacks.
8191 **
8192 ** ^The preupdate hook only fires for changes to real database tables; the
8193 ** preupdate hook is not invoked for changes to [virtual tables] or to
8194 ** system tables like sqlite_master or sqlite_stat1.
8195 **
8196 ** ^The second parameter to the preupdate callback is a pointer to
8197 ** the [database connection] that registered the preupdate hook.
8198 ** ^The third parameter to the preupdate callback is one of the constants
8199 ** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the
@@ -8186,16 +8203,20 @@
8203 ** will be "main" for the main database or "temp" for TEMP tables or
8204 ** the name given after the AS keyword in the [ATTACH] statement for attached
8205 ** databases.)^
8206 ** ^The fifth parameter to the preupdate callback is the name of the
8207 ** table that is being modified.
8208 **
8209 ** For an UPDATE or DELETE operation on a [rowid table], the sixth
8210 ** parameter passed to the preupdate callback is the initial [rowid] of the
8211 ** row being modified or deleted. For an INSERT operation on a rowid table,
8212 ** or any operation on a WITHOUT ROWID table, the value of the sixth
8213 ** parameter is undefined. For an INSERT or UPDATE on a rowid table the
8214 ** seventh parameter is the final rowid value of the row being inserted
8215 ** or updated. The value of the seventh parameter passed to the callback
8216 ** function is not defined for operations on WITHOUT ROWID tables, or for
8217 ** INSERT operations on rowid tables.
8218 **
8219 ** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
8220 ** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
8221 ** provide additional information about a preupdate event. These routines
8222 ** may only be called from within a preupdate callback. Invoking any of
@@ -8627,11 +8648,11 @@
8648 ** The session object will be used to create changesets for tables in
8649 ** database zDb, where zDb is either "main", or "temp", or the name of an
8650 ** attached database. It is not an error if database zDb is not attached
8651 ** to the database when the session object is created.
8652 */
8653 SQLITE_API int sqlite3session_create(
8654 sqlite3 *db, /* Database handle */
8655 const char *zDb, /* Name of db (e.g. "main") */
8656 sqlite3_session **ppSession /* OUT: New session object */
8657 );
8658
@@ -8645,11 +8666,11 @@
8666 **
8667 ** Session objects must be deleted before the database handle to which they
8668 ** are attached is closed. Refer to the documentation for
8669 ** [sqlite3session_create()] for details.
8670 */
8671 SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);
8672
8673
8674 /*
8675 ** CAPI3REF: Enable Or Disable A Session Object
8676 **
@@ -8665,11 +8686,11 @@
8686 ** no-op, and may be used to query the current state of the session.
8687 **
8688 ** The return value indicates the final state of the session object: 0 if
8689 ** the session is disabled, or 1 if it is enabled.
8690 */
8691 SQLITE_API int sqlite3session_enable(sqlite3_session *pSession, int bEnable);
8692
8693 /*
8694 ** CAPI3REF: Set Or Clear the Indirect Change Flag
8695 **
8696 ** Each change recorded by a session object is marked as either direct or
@@ -8694,11 +8715,11 @@
8715 ** indirect flag for the specified session object.
8716 **
8717 ** The return value indicates the final state of the indirect flag: 0 if
8718 ** it is clear, or 1 if it is set.
8719 */
8720 SQLITE_API int sqlite3session_indirect(sqlite3_session *pSession, int bIndirect);
8721
8722 /*
8723 ** CAPI3REF: Attach A Table To A Session Object
8724 **
8725 ** If argument zTab is not NULL, then it is the name of a table to attach
@@ -8724,11 +8745,11 @@
8745 ** in one or more of their PRIMARY KEY columns.
8746 **
8747 ** SQLITE_OK is returned if the call completes without error. Or, if an error
8748 ** occurs, an SQLite error code (e.g. SQLITE_NOMEM) is returned.
8749 */
8750 SQLITE_API int sqlite3session_attach(
8751 sqlite3_session *pSession, /* Session object */
8752 const char *zTab /* Table name */
8753 );
8754
8755 /*
@@ -8738,11 +8759,11 @@
8759 ** in tables that are not attached to the Session object, the filter is called
8760 ** to determine whether changes to the table's rows should be tracked or not.
8761 ** If xFilter returns 0, changes is not tracked. Note that once a table is
8762 ** attached, xFilter will not be called again.
8763 */
8764 SQLITE_API void sqlite3session_table_filter(
8765 sqlite3_session *pSession, /* Session object */
8766 int(*xFilter)(
8767 void *pCtx, /* Copy of third arg to _filter_table() */
8768 const char *zTab /* Table name */
8769 ),
@@ -8851,11 +8872,11 @@
8872 ** changeset, even though the delete took place while the session was disabled.
8873 ** Or, if one field of a row is updated while a session is disabled, and
8874 ** another field of the same row is updated while the session is enabled, the
8875 ** resulting changeset will contain an UPDATE change that updates both fields.
8876 */
8877 SQLITE_API int sqlite3session_changeset(
8878 sqlite3_session *pSession, /* Session object */
8879 int *pnChangeset, /* OUT: Size of buffer at *ppChangeset */
8880 void **ppChangeset /* OUT: Buffer containing changeset */
8881 );
8882
@@ -8895,11 +8916,12 @@
8916 **
8917 ** <li> For each row (primary key) that exists in the to-table but not in
8918 ** the from-table, a DELETE record is added to the session object.
8919 **
8920 ** <li> For each row (primary key) that exists in both tables, but features
8921 ** different non-PK values in each, an UPDATE record is added to the
8922 ** session.
8923 ** </ul>
8924 **
8925 ** To clarify, if this function is called and then a changeset constructed
8926 ** using [sqlite3session_changeset()], then after applying that changeset to
8927 ** database zFrom the contents of the two compatible tables would be
@@ -8912,11 +8934,11 @@
8934 ** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
8935 ** may be set to point to a buffer containing an English language error
8936 ** message. It is the responsibility of the caller to free this buffer using
8937 ** sqlite3_free().
8938 */
8939 SQLITE_API int sqlite3session_diff(
8940 sqlite3_session *pSession,
8941 const char *zFromDb,
8942 const char *zTbl,
8943 char **pzErrMsg
8944 );
@@ -8948,11 +8970,11 @@
8970 ** Changes within a patchset are ordered in the same way as for changesets
8971 ** generated by the sqlite3session_changeset() function (i.e. all changes for
8972 ** a single table are grouped together, tables appear in the order in which
8973 ** they were attached to the session object).
8974 */
8975 SQLITE_API int sqlite3session_patchset(
8976 sqlite3_session *pSession, /* Session object */
8977 int *pnPatchset, /* OUT: Size of buffer at *ppChangeset */
8978 void **ppPatchset /* OUT: Buffer containing changeset */
8979 );
8980
@@ -8969,11 +8991,11 @@
8991 ** an attached table is modified and then later on the original values
8992 ** are restored. However, if this function returns non-zero, then it is
8993 ** guaranteed that a call to sqlite3session_changeset() will return a
8994 ** changeset containing zero changes.
8995 */
8996 SQLITE_API int sqlite3session_isempty(sqlite3_session *pSession);
8997
8998 /*
8999 ** CAPI3REF: Create An Iterator To Traverse A Changeset
9000 **
9001 ** Create an iterator used to iterate through the contents of a changeset.
@@ -9004,11 +9026,11 @@
9026 ** this function, all changes that relate to a single table are visited
9027 ** consecutively. There is no chance that the iterator will visit a change
9028 ** the applies to table X, then one for table Y, and then later on visit
9029 ** another change for table X.
9030 */
9031 SQLITE_API int sqlite3changeset_start(
9032 sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */
9033 int nChangeset, /* Size of changeset blob in bytes */
9034 void *pChangeset /* Pointer to blob containing changeset */
9035 );
9036
@@ -9033,11 +9055,11 @@
9055 **
9056 ** If an error occurs, an SQLite error code is returned. Possible error
9057 ** codes include SQLITE_CORRUPT (if the changeset buffer is corrupt) or
9058 ** SQLITE_NOMEM.
9059 */
9060 SQLITE_API int sqlite3changeset_next(sqlite3_changeset_iter *pIter);
9061
9062 /*
9063 ** CAPI3REF: Obtain The Current Operation From A Changeset Iterator
9064 **
9065 ** The pIter argument passed to this function may either be an iterator
@@ -9061,11 +9083,11 @@
9083 **
9084 ** If no error occurs, SQLITE_OK is returned. If an error does occur, an
9085 ** SQLite error code is returned. The values of the output variables may not
9086 ** be trusted in this case.
9087 */
9088 SQLITE_API int sqlite3changeset_op(
9089 sqlite3_changeset_iter *pIter, /* Iterator object */
9090 const char **pzTab, /* OUT: Pointer to table name */
9091 int *pnCol, /* OUT: Number of columns in table */
9092 int *pOp, /* OUT: SQLITE_INSERT, DELETE or UPDATE */
9093 int *pbIndirect /* OUT: True for an 'indirect' change */
@@ -9094,11 +9116,11 @@
9116 ** If this function is called when the iterator does not point to a valid
9117 ** entry, SQLITE_MISUSE is returned and the output variables zeroed. Otherwise,
9118 ** SQLITE_OK is returned and the output variables populated as described
9119 ** above.
9120 */
9121 SQLITE_API int sqlite3changeset_pk(
9122 sqlite3_changeset_iter *pIter, /* Iterator object */
9123 unsigned char **pabPK, /* OUT: Array of boolean - true for PK cols */
9124 int *pnCol /* OUT: Number of entries in output array */
9125 );
9126
@@ -9124,11 +9146,11 @@
9146 ** is similar to the "old.*" columns available to update or delete triggers.
9147 **
9148 ** If some other error occurs (e.g. an OOM condition), an SQLite error code
9149 ** is returned and *ppValue is set to NULL.
9150 */
9151 SQLITE_API int sqlite3changeset_old(
9152 sqlite3_changeset_iter *pIter, /* Changeset iterator */
9153 int iVal, /* Column number */
9154 sqlite3_value **ppValue /* OUT: Old value (or NULL pointer) */
9155 );
9156
@@ -9157,11 +9179,11 @@
9179 ** triggers.
9180 **
9181 ** If some other error occurs (e.g. an OOM condition), an SQLite error code
9182 ** is returned and *ppValue is set to NULL.
9183 */
9184 SQLITE_API int sqlite3changeset_new(
9185 sqlite3_changeset_iter *pIter, /* Changeset iterator */
9186 int iVal, /* Column number */
9187 sqlite3_value **ppValue /* OUT: New value (or NULL pointer) */
9188 );
9189
@@ -9184,11 +9206,11 @@
9206 ** and returns SQLITE_OK.
9207 **
9208 ** If some other error occurs (e.g. an OOM condition), an SQLite error code
9209 ** is returned and *ppValue is set to NULL.
9210 */
9211 SQLITE_API int sqlite3changeset_conflict(
9212 sqlite3_changeset_iter *pIter, /* Changeset iterator */
9213 int iVal, /* Column number */
9214 sqlite3_value **ppValue /* OUT: Value from conflicting row */
9215 );
9216
@@ -9200,11 +9222,11 @@
9222 ** it sets the output variable to the total number of known foreign key
9223 ** violations in the destination database and returns SQLITE_OK.
9224 **
9225 ** In all other cases this function returns SQLITE_MISUSE.
9226 */
9227 SQLITE_API int sqlite3changeset_fk_conflicts(
9228 sqlite3_changeset_iter *pIter, /* Changeset iterator */
9229 int *pnOut /* OUT: Number of FK violations */
9230 );
9231
9232
@@ -9233,11 +9255,11 @@
9255 ** rc = sqlite3changeset_finalize();
9256 ** if( rc!=SQLITE_OK ){
9257 ** // An error has occurred
9258 ** }
9259 */
9260 SQLITE_API int sqlite3changeset_finalize(sqlite3_changeset_iter *pIter);
9261
9262 /*
9263 ** CAPI3REF: Invert A Changeset
9264 **
9265 ** This function is used to "invert" a changeset object. Applying an inverted
@@ -9263,11 +9285,11 @@
9285 ** call to this function.
9286 **
9287 ** WARNING/TODO: This function currently assumes that the input is a valid
9288 ** changeset. If it is not, the results are undefined.
9289 */
9290 SQLITE_API int sqlite3changeset_invert(
9291 int nIn, const void *pIn, /* Input changeset */
9292 int *pnOut, void **ppOut /* OUT: Inverse of input */
9293 );
9294
9295 /*
@@ -9292,11 +9314,11 @@
9314 ** *pnOut = 0;
9315 ** }
9316 **
9317 ** Refer to the sqlite3_changegroup documentation below for details.
9318 */
9319 SQLITE_API int sqlite3changeset_concat(
9320 int nA, /* Number of bytes in buffer pA */
9321 void *pA, /* Pointer to buffer containing changeset A */
9322 int nB, /* Number of bytes in buffer pB */
9323 void *pB, /* Pointer to buffer containing changeset B */
9324 int *pnOut, /* OUT: Number of bytes in output changeset */
@@ -9480,11 +9502,11 @@
9502 ** considered compatible if all of the following are true:
9503 **
9504 ** <ul>
9505 ** <li> The table has the same name as the name recorded in the
9506 ** changeset, and
9507 ** <li> The table has at least as many columns as recorded in the
9508 ** changeset, and
9509 ** <li> The table has primary key columns in the same position as
9510 ** recorded in the changeset.
9511 ** </ul>
9512 **
@@ -9525,11 +9547,15 @@
9547 ** the changeset the row is deleted from the target database.
9548 **
9549 ** If a row with matching primary key values is found, but one or more of
9550 ** the non-primary key fields contains a value different from the original
9551 ** row value stored in the changeset, the conflict-handler function is
9552 ** invoked with [SQLITE_CHANGESET_DATA] as the second argument. If the
9553 ** database table has more columns than are recorded in the changeset,
9554 ** only the values of those non-primary key fields are compared against
9555 ** the current database contents - any trailing database table columns
9556 ** are ignored.
9557 **
9558 ** If no row with matching primary key values is found in the database,
9559 ** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND]
9560 ** passed as the second argument.
9561 **
@@ -9540,11 +9566,13 @@
9566 ** operation is attempted because an earlier call to the conflict handler
9567 ** function returned [SQLITE_CHANGESET_REPLACE].
9568 **
9569 ** <dt>INSERT Changes<dd>
9570 ** For each INSERT change, an attempt is made to insert the new row into
9571 ** the database. If the changeset row contains fewer fields than the
9572 ** database table, the trailing fields are populated with their default
9573 ** values.
9574 **
9575 ** If the attempt to insert the row fails because the database already
9576 ** contains a row with the same primary key values, the conflict handler
9577 ** function is invoked with the second argument set to
9578 ** [SQLITE_CHANGESET_CONFLICT].
@@ -9558,17 +9586,17 @@
9586 **
9587 ** <dt>UPDATE Changes<dd>
9588 ** For each UPDATE change, this function checks if the target database
9589 ** contains a row with the same primary key value (or values) as the
9590 ** original row values stored in the changeset. If it does, and the values
9591 ** stored in all modified non-primary key columns also match the values
9592 ** stored in the changeset the row is updated within the target database.
9593 **
9594 ** If a row with matching primary key values is found, but one or more of
9595 ** the modified non-primary key fields contains a value different from an
9596 ** original row value stored in the changeset, the conflict-handler function
9597 ** is invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since
9598 ** UPDATE changes only contain values for non-primary key fields that are
9599 ** to be modified, only those fields need to match the original values to
9600 ** avoid the SQLITE_CHANGESET_DATA conflict-handler callback.
9601 **
9602 ** If no row with matching primary key values is found in the database,
@@ -9592,11 +9620,11 @@
9620 ** If any other error (aside from a constraint failure when attempting to
9621 ** write to the target database) occurs, then the savepoint transaction is
9622 ** rolled back, restoring the target database to its original state, and an
9623 ** SQLite error code returned.
9624 */
9625 SQLITE_API int sqlite3changeset_apply(
9626 sqlite3 *db, /* Apply change to "main" db of this handle */
9627 int nChangeset, /* Size of changeset in bytes */
9628 void *pChangeset, /* Changeset blob */
9629 int(*xFilter)(
9630 void *pCtx, /* Copy of sixth arg to _apply() */
@@ -9793,11 +9821,11 @@
9821 **
9822 ** The sessions module never invokes an xOutput callback with the third
9823 ** parameter set to a value less than or equal to zero. Other than this,
9824 ** no guarantees are made as to the size of the chunks of data returned.
9825 */
9826 SQLITE_API int sqlite3changeset_apply_strm(
9827 sqlite3 *db, /* Apply change to "main" db of this handle */
9828 int (*xInput)(void *pIn, void *pData, int *pnData), /* Input function */
9829 void *pIn, /* First arg for xInput */
9830 int(*xFilter)(
9831 void *pCtx, /* Copy of sixth arg to _apply() */
@@ -9808,35 +9836,35 @@
9836 int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */
9837 sqlite3_changeset_iter *p /* Handle describing change and conflict */
9838 ),
9839 void *pCtx /* First argument passed to xConflict */
9840 );
9841 SQLITE_API int sqlite3changeset_concat_strm(
9842 int (*xInputA)(void *pIn, void *pData, int *pnData),
9843 void *pInA,
9844 int (*xInputB)(void *pIn, void *pData, int *pnData),
9845 void *pInB,
9846 int (*xOutput)(void *pOut, const void *pData, int nData),
9847 void *pOut
9848 );
9849 SQLITE_API int sqlite3changeset_invert_strm(
9850 int (*xInput)(void *pIn, void *pData, int *pnData),
9851 void *pIn,
9852 int (*xOutput)(void *pOut, const void *pData, int nData),
9853 void *pOut
9854 );
9855 SQLITE_API int sqlite3changeset_start_strm(
9856 sqlite3_changeset_iter **pp,
9857 int (*xInput)(void *pIn, void *pData, int *pnData),
9858 void *pIn
9859 );
9860 SQLITE_API int sqlite3session_changeset_strm(
9861 sqlite3_session *pSession,
9862 int (*xOutput)(void *pOut, const void *pData, int nData),
9863 void *pOut
9864 );
9865 SQLITE_API int sqlite3session_patchset_strm(
9866 sqlite3_session *pSession,
9867 int (*xOutput)(void *pOut, const void *pData, int nData),
9868 void *pOut
9869 );
9870 int sqlite3changegroup_add_strm(sqlite3_changegroup*,
9871
+3 -3
--- src/sync.c
+++ src/sync.c
@@ -213,11 +213,11 @@
213213
** --from-parent-project Pull content from the parent project
214214
** --ipv4 Use only IPv4, not IPv6
215215
** --once Do not remember URL for subsequent syncs
216216
** --proxy PROXY Use the specified HTTP proxy
217217
** --private Pull private branches too
218
-** -R|--repository REPO Repository to pull into
218
+** -R|--repository REPO Local repository to pull into
219219
** --ssl-identity FILE Local SSL credentials, if requested by remote
220220
** --ssh-command SSH Use SSH as the "ssh" command
221221
** -v|--verbose Additional (debugging) output
222222
** --verily Exchange extra information with the remote
223223
** to ensure no content is overlooked
@@ -258,11 +258,11 @@
258258
** if required by the remote website
259259
** --ipv4 Use only IPv4, not IPv6
260260
** --once Do not remember URL for subsequent syncs
261261
** --proxy PROXY Use the specified HTTP proxy
262262
** --private Push private branches too
263
-** -R|--repository REPO Repository to pull into
263
+** -R|--repository REPO Local repository to push from
264264
** --ssl-identity FILE Local SSL credentials, if requested by remote
265265
** --ssh-command SSH Use SSH as the "ssh" command
266266
** -v|--verbose Additional (debugging) output
267267
** --verily Exchange extra information with the remote
268268
** to ensure no content is overlooked
@@ -303,11 +303,11 @@
303303
** if required by the remote website
304304
** --ipv4 Use only IPv4, not IPv6
305305
** --once Do not remember URL for subsequent syncs
306306
** --proxy PROXY Use the specified HTTP proxy
307307
** --private Sync private branches too
308
-** -R|--repository REPO Repository to pull into
308
+** -R|--repository REPO Local repository to sync with
309309
** --ssl-identity FILE Local SSL credentials, if requested by remote
310310
** --ssh-command SSH Use SSH as the "ssh" command
311311
** -u|--unversioned Also sync unversioned content
312312
** -v|--verbose Additional (debugging) output
313313
** --verily Exchange extra information with the remote
314314
--- src/sync.c
+++ src/sync.c
@@ -213,11 +213,11 @@
213 ** --from-parent-project Pull content from the parent project
214 ** --ipv4 Use only IPv4, not IPv6
215 ** --once Do not remember URL for subsequent syncs
216 ** --proxy PROXY Use the specified HTTP proxy
217 ** --private Pull private branches too
218 ** -R|--repository REPO Repository to pull into
219 ** --ssl-identity FILE Local SSL credentials, if requested by remote
220 ** --ssh-command SSH Use SSH as the "ssh" command
221 ** -v|--verbose Additional (debugging) output
222 ** --verily Exchange extra information with the remote
223 ** to ensure no content is overlooked
@@ -258,11 +258,11 @@
258 ** if required by the remote website
259 ** --ipv4 Use only IPv4, not IPv6
260 ** --once Do not remember URL for subsequent syncs
261 ** --proxy PROXY Use the specified HTTP proxy
262 ** --private Push private branches too
263 ** -R|--repository REPO Repository to pull into
264 ** --ssl-identity FILE Local SSL credentials, if requested by remote
265 ** --ssh-command SSH Use SSH as the "ssh" command
266 ** -v|--verbose Additional (debugging) output
267 ** --verily Exchange extra information with the remote
268 ** to ensure no content is overlooked
@@ -303,11 +303,11 @@
303 ** if required by the remote website
304 ** --ipv4 Use only IPv4, not IPv6
305 ** --once Do not remember URL for subsequent syncs
306 ** --proxy PROXY Use the specified HTTP proxy
307 ** --private Sync private branches too
308 ** -R|--repository REPO Repository to pull into
309 ** --ssl-identity FILE Local SSL credentials, if requested by remote
310 ** --ssh-command SSH Use SSH as the "ssh" command
311 ** -u|--unversioned Also sync unversioned content
312 ** -v|--verbose Additional (debugging) output
313 ** --verily Exchange extra information with the remote
314
--- src/sync.c
+++ src/sync.c
@@ -213,11 +213,11 @@
213 ** --from-parent-project Pull content from the parent project
214 ** --ipv4 Use only IPv4, not IPv6
215 ** --once Do not remember URL for subsequent syncs
216 ** --proxy PROXY Use the specified HTTP proxy
217 ** --private Pull private branches too
218 ** -R|--repository REPO Local repository to pull into
219 ** --ssl-identity FILE Local SSL credentials, if requested by remote
220 ** --ssh-command SSH Use SSH as the "ssh" command
221 ** -v|--verbose Additional (debugging) output
222 ** --verily Exchange extra information with the remote
223 ** to ensure no content is overlooked
@@ -258,11 +258,11 @@
258 ** if required by the remote website
259 ** --ipv4 Use only IPv4, not IPv6
260 ** --once Do not remember URL for subsequent syncs
261 ** --proxy PROXY Use the specified HTTP proxy
262 ** --private Push private branches too
263 ** -R|--repository REPO Local repository to push from
264 ** --ssl-identity FILE Local SSL credentials, if requested by remote
265 ** --ssh-command SSH Use SSH as the "ssh" command
266 ** -v|--verbose Additional (debugging) output
267 ** --verily Exchange extra information with the remote
268 ** to ensure no content is overlooked
@@ -303,11 +303,11 @@
303 ** if required by the remote website
304 ** --ipv4 Use only IPv4, not IPv6
305 ** --once Do not remember URL for subsequent syncs
306 ** --proxy PROXY Use the specified HTTP proxy
307 ** --private Sync private branches too
308 ** -R|--repository REPO Local repository to sync with
309 ** --ssl-identity FILE Local SSL credentials, if requested by remote
310 ** --ssh-command SSH Use SSH as the "ssh" command
311 ** -u|--unversioned Also sync unversioned content
312 ** -v|--verbose Additional (debugging) output
313 ** --verily Exchange extra information with the remote
314
+8 -7
--- src/th_main.c
+++ src/th_main.c
@@ -21,10 +21,18 @@
2121
#include "config.h"
2222
#include "th_main.h"
2323
#include "sqlite3.h"
2424
2525
#if INTERFACE
26
+/*
27
+** These macros are used within this file to detect if the repository and
28
+** configuration ("user") database are currently open.
29
+*/
30
+#define Th_IsLocalOpen() (g.localOpen)
31
+#define Th_IsRepositoryOpen() (g.repositoryOpen)
32
+#define Th_IsConfigOpen() (g.zConfigDbName!=0)
33
+
2634
/*
2735
** Flag parameters to the Th_FossilInit() routine used to control the
2836
** interpreter creation and initialization process.
2937
*/
3038
#define TH_INIT_NONE ((u32)0x00000000) /* No flags. */
@@ -59,17 +67,10 @@
5967
*/
6068
#define NO_COMMAND_HOOK_ERROR "no such command: command_hook"
6169
#define NO_WEBPAGE_HOOK_ERROR "no such command: webpage_hook"
6270
#endif
6371
64
-/*
65
-** These macros are used within this file to detect if the repository and
66
-** configuration ("user") database are currently open.
67
-*/
68
-#define Th_IsRepositoryOpen() (g.repositoryOpen)
69
-#define Th_IsConfigOpen() (g.zConfigDbName!=0)
70
-
7172
/*
7273
** Global variable counting the number of outstanding calls to malloc()
7374
** made by the th1 implementation. This is used to catch memory leaks
7475
** in the interpreter. Obviously, it also means th1 is not threadsafe.
7576
*/
7677
--- src/th_main.c
+++ src/th_main.c
@@ -21,10 +21,18 @@
21 #include "config.h"
22 #include "th_main.h"
23 #include "sqlite3.h"
24
25 #if INTERFACE
 
 
 
 
 
 
 
 
26 /*
27 ** Flag parameters to the Th_FossilInit() routine used to control the
28 ** interpreter creation and initialization process.
29 */
30 #define TH_INIT_NONE ((u32)0x00000000) /* No flags. */
@@ -59,17 +67,10 @@
59 */
60 #define NO_COMMAND_HOOK_ERROR "no such command: command_hook"
61 #define NO_WEBPAGE_HOOK_ERROR "no such command: webpage_hook"
62 #endif
63
64 /*
65 ** These macros are used within this file to detect if the repository and
66 ** configuration ("user") database are currently open.
67 */
68 #define Th_IsRepositoryOpen() (g.repositoryOpen)
69 #define Th_IsConfigOpen() (g.zConfigDbName!=0)
70
71 /*
72 ** Global variable counting the number of outstanding calls to malloc()
73 ** made by the th1 implementation. This is used to catch memory leaks
74 ** in the interpreter. Obviously, it also means th1 is not threadsafe.
75 */
76
--- src/th_main.c
+++ src/th_main.c
@@ -21,10 +21,18 @@
21 #include "config.h"
22 #include "th_main.h"
23 #include "sqlite3.h"
24
25 #if INTERFACE
26 /*
27 ** These macros are used within this file to detect if the repository and
28 ** configuration ("user") database are currently open.
29 */
30 #define Th_IsLocalOpen() (g.localOpen)
31 #define Th_IsRepositoryOpen() (g.repositoryOpen)
32 #define Th_IsConfigOpen() (g.zConfigDbName!=0)
33
34 /*
35 ** Flag parameters to the Th_FossilInit() routine used to control the
36 ** interpreter creation and initialization process.
37 */
38 #define TH_INIT_NONE ((u32)0x00000000) /* No flags. */
@@ -59,17 +67,10 @@
67 */
68 #define NO_COMMAND_HOOK_ERROR "no such command: command_hook"
69 #define NO_WEBPAGE_HOOK_ERROR "no such command: webpage_hook"
70 #endif
71
 
 
 
 
 
 
 
72 /*
73 ** Global variable counting the number of outstanding calls to malloc()
74 ** made by the th1 implementation. This is used to catch memory leaks
75 ** in the interpreter. Obviously, it also means th1 is not threadsafe.
76 */
77
+4 -2
--- src/timeline.c
+++ src/timeline.c
@@ -2485,16 +2485,18 @@
24852485
blob_append_sql(&sql, "\n AND event.mtime %s %s",
24862486
( mode==TIMELINE_MODE_BEFORE ||
24872487
mode==TIMELINE_MODE_PARENTS ) ? "<=" : ">=", zDate /*safe-for-%s*/
24882488
);
24892489
2490
+ /* When zFilePattern is specified, compute complete ancestry;
2491
+ * limit later at print_timeline() */
24902492
if( mode==TIMELINE_MODE_CHILDREN || mode==TIMELINE_MODE_PARENTS ){
24912493
db_multi_exec("CREATE TEMP TABLE ok(rid INTEGER PRIMARY KEY)");
24922494
if( mode==TIMELINE_MODE_CHILDREN ){
2493
- compute_descendants(objid, n);
2495
+ compute_descendants(objid, (zFilePattern ? 0 : n));
24942496
}else{
2495
- compute_ancestors(objid, n, 0);
2497
+ compute_ancestors(objid, (zFilePattern ? 0 : n), 0);
24962498
}
24972499
blob_append_sql(&sql, "\n AND blob.rid IN ok");
24982500
}
24992501
if( zType && (zType[0]!='a') ){
25002502
blob_append_sql(&sql, "\n AND event.type=%Q ", zType);
25012503
--- src/timeline.c
+++ src/timeline.c
@@ -2485,16 +2485,18 @@
2485 blob_append_sql(&sql, "\n AND event.mtime %s %s",
2486 ( mode==TIMELINE_MODE_BEFORE ||
2487 mode==TIMELINE_MODE_PARENTS ) ? "<=" : ">=", zDate /*safe-for-%s*/
2488 );
2489
 
 
2490 if( mode==TIMELINE_MODE_CHILDREN || mode==TIMELINE_MODE_PARENTS ){
2491 db_multi_exec("CREATE TEMP TABLE ok(rid INTEGER PRIMARY KEY)");
2492 if( mode==TIMELINE_MODE_CHILDREN ){
2493 compute_descendants(objid, n);
2494 }else{
2495 compute_ancestors(objid, n, 0);
2496 }
2497 blob_append_sql(&sql, "\n AND blob.rid IN ok");
2498 }
2499 if( zType && (zType[0]!='a') ){
2500 blob_append_sql(&sql, "\n AND event.type=%Q ", zType);
2501
--- src/timeline.c
+++ src/timeline.c
@@ -2485,16 +2485,18 @@
2485 blob_append_sql(&sql, "\n AND event.mtime %s %s",
2486 ( mode==TIMELINE_MODE_BEFORE ||
2487 mode==TIMELINE_MODE_PARENTS ) ? "<=" : ">=", zDate /*safe-for-%s*/
2488 );
2489
2490 /* When zFilePattern is specified, compute complete ancestry;
2491 * limit later at print_timeline() */
2492 if( mode==TIMELINE_MODE_CHILDREN || mode==TIMELINE_MODE_PARENTS ){
2493 db_multi_exec("CREATE TEMP TABLE ok(rid INTEGER PRIMARY KEY)");
2494 if( mode==TIMELINE_MODE_CHILDREN ){
2495 compute_descendants(objid, (zFilePattern ? 0 : n));
2496 }else{
2497 compute_ancestors(objid, (zFilePattern ? 0 : n), 0);
2498 }
2499 blob_append_sql(&sql, "\n AND blob.rid IN ok");
2500 }
2501 if( zType && (zType[0]!='a') ){
2502 blob_append_sql(&sql, "\n AND event.type=%Q ", zType);
2503
--- src/update.c
+++ src/update.c
@@ -95,10 +95,11 @@
9595
** Options:
9696
** --case-sensitive <BOOL> override case-sensitive setting
9797
** --debug print debug information on stdout
9898
** --latest acceptable in place of VERSION, update to latest version
9999
** --force-missing force update if missing content after sync
100
+** --no-dir-symlinks Disables support for directory symlinks.
100101
** -n|--dry-run If given, display instead of run actions
101102
** -v|--verbose print status information about all files
102103
** -W|--width <num> Width of lines (default is to auto-detect). Must be >20
103104
** or 0 (= no limit, resulting in a single line per entry).
104105
**
105106
--- src/update.c
+++ src/update.c
@@ -95,10 +95,11 @@
95 ** Options:
96 ** --case-sensitive <BOOL> override case-sensitive setting
97 ** --debug print debug information on stdout
98 ** --latest acceptable in place of VERSION, update to latest version
99 ** --force-missing force update if missing content after sync
 
100 ** -n|--dry-run If given, display instead of run actions
101 ** -v|--verbose print status information about all files
102 ** -W|--width <num> Width of lines (default is to auto-detect). Must be >20
103 ** or 0 (= no limit, resulting in a single line per entry).
104 **
105
--- src/update.c
+++ src/update.c
@@ -95,10 +95,11 @@
95 ** Options:
96 ** --case-sensitive <BOOL> override case-sensitive setting
97 ** --debug print debug information on stdout
98 ** --latest acceptable in place of VERSION, update to latest version
99 ** --force-missing force update if missing content after sync
100 ** --no-dir-symlinks Disables support for directory symlinks.
101 ** -n|--dry-run If given, display instead of run actions
102 ** -v|--verbose print status information about all files
103 ** -W|--width <num> Width of lines (default is to auto-detect). Must be >20
104 ** or 0 (= no limit, resulting in a single line per entry).
105 **
106
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -170,11 +170,11 @@
170170
#### The directories where the OpenSSL include and library files are located.
171171
# The recommended usage here is to use the Sysinternals junction tool
172172
# to create a hard link between an "openssl-1.x" sub-directory of the
173173
# Fossil source code directory and the target OpenSSL source directory.
174174
#
175
-OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.1.0d
175
+OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.1.0e
176176
OPENSSLINCDIR = $(OPENSSLDIR)/include
177177
OPENSSLLIBDIR = $(OPENSSLDIR)
178178
179179
#### Either the directory where the Tcl library is installed or the Tcl
180180
# source code directory resides (depending on the value of the macro
181181
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -170,11 +170,11 @@
170 #### The directories where the OpenSSL include and library files are located.
171 # The recommended usage here is to use the Sysinternals junction tool
172 # to create a hard link between an "openssl-1.x" sub-directory of the
173 # Fossil source code directory and the target OpenSSL source directory.
174 #
175 OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.1.0d
176 OPENSSLINCDIR = $(OPENSSLDIR)/include
177 OPENSSLLIBDIR = $(OPENSSLDIR)
178
179 #### Either the directory where the Tcl library is installed or the Tcl
180 # source code directory resides (depending on the value of the macro
181
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -170,11 +170,11 @@
170 #### The directories where the OpenSSL include and library files are located.
171 # The recommended usage here is to use the Sysinternals junction tool
172 # to create a hard link between an "openssl-1.x" sub-directory of the
173 # Fossil source code directory and the target OpenSSL source directory.
174 #
175 OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.1.0e
176 OPENSSLINCDIR = $(OPENSSLDIR)/include
177 OPENSSLLIBDIR = $(OPENSSLDIR)
178
179 #### Either the directory where the Tcl library is installed or the Tcl
180 # source code directory resides (depending on the value of the macro
181
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -170,11 +170,11 @@
170170
#### The directories where the OpenSSL include and library files are located.
171171
# The recommended usage here is to use the Sysinternals junction tool
172172
# to create a hard link between an "openssl-1.x" sub-directory of the
173173
# Fossil source code directory and the target OpenSSL source directory.
174174
#
175
-OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.1.0d
175
+OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.1.0e
176176
OPENSSLINCDIR = $(OPENSSLDIR)/include
177177
OPENSSLLIBDIR = $(OPENSSLDIR)
178178
179179
#### Either the directory where the Tcl library is installed or the Tcl
180180
# source code directory resides (depending on the value of the macro
181181
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -170,11 +170,11 @@
170 #### The directories where the OpenSSL include and library files are located.
171 # The recommended usage here is to use the Sysinternals junction tool
172 # to create a hard link between an "openssl-1.x" sub-directory of the
173 # Fossil source code directory and the target OpenSSL source directory.
174 #
175 OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.1.0d
176 OPENSSLINCDIR = $(OPENSSLDIR)/include
177 OPENSSLLIBDIR = $(OPENSSLDIR)
178
179 #### Either the directory where the Tcl library is installed or the Tcl
180 # source code directory resides (depending on the value of the macro
181
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -170,11 +170,11 @@
170 #### The directories where the OpenSSL include and library files are located.
171 # The recommended usage here is to use the Sysinternals junction tool
172 # to create a hard link between an "openssl-1.x" sub-directory of the
173 # Fossil source code directory and the target OpenSSL source directory.
174 #
175 OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.1.0e
176 OPENSSLINCDIR = $(OPENSSLDIR)/include
177 OPENSSLLIBDIR = $(OPENSSLDIR)
178
179 #### Either the directory where the Tcl library is installed or the Tcl
180 # source code directory resides (depending on the value of the macro
181
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -170,11 +170,11 @@
170170
#### The directories where the OpenSSL include and library files are located.
171171
# The recommended usage here is to use the Sysinternals junction tool
172172
# to create a hard link between an "openssl-1.x" sub-directory of the
173173
# Fossil source code directory and the target OpenSSL source directory.
174174
#
175
-OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.1.0d
175
+OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.1.0e
176176
OPENSSLINCDIR = $(OPENSSLDIR)/include
177177
OPENSSLLIBDIR = $(OPENSSLDIR)
178178
179179
#### Either the directory where the Tcl library is installed or the Tcl
180180
# source code directory resides (depending on the value of the macro
181181
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -170,11 +170,11 @@
170 #### The directories where the OpenSSL include and library files are located.
171 # The recommended usage here is to use the Sysinternals junction tool
172 # to create a hard link between an "openssl-1.x" sub-directory of the
173 # Fossil source code directory and the target OpenSSL source directory.
174 #
175 OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.1.0d
176 OPENSSLINCDIR = $(OPENSSLDIR)/include
177 OPENSSLLIBDIR = $(OPENSSLDIR)
178
179 #### Either the directory where the Tcl library is installed or the Tcl
180 # source code directory resides (depending on the value of the macro
181
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -170,11 +170,11 @@
170 #### The directories where the OpenSSL include and library files are located.
171 # The recommended usage here is to use the Sysinternals junction tool
172 # to create a hard link between an "openssl-1.x" sub-directory of the
173 # Fossil source code directory and the target OpenSSL source directory.
174 #
175 OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.1.0e
176 OPENSSLINCDIR = $(OPENSSLDIR)/include
177 OPENSSLLIBDIR = $(OPENSSLDIR)
178
179 #### Either the directory where the Tcl library is installed or the Tcl
180 # source code directory resides (depending on the value of the macro
181
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -170,11 +170,11 @@
170170
#### The directories where the OpenSSL include and library files are located.
171171
# The recommended usage here is to use the Sysinternals junction tool
172172
# to create a hard link between an "openssl-1.x" sub-directory of the
173173
# Fossil source code directory and the target OpenSSL source directory.
174174
#
175
-OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.1.0d
175
+OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.1.0e
176176
OPENSSLINCDIR = $(OPENSSLDIR)/include
177177
OPENSSLLIBDIR = $(OPENSSLDIR)
178178
179179
#### Either the directory where the Tcl library is installed or the Tcl
180180
# source code directory resides (depending on the value of the macro
181181
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -170,11 +170,11 @@
170 #### The directories where the OpenSSL include and library files are located.
171 # The recommended usage here is to use the Sysinternals junction tool
172 # to create a hard link between an "openssl-1.x" sub-directory of the
173 # Fossil source code directory and the target OpenSSL source directory.
174 #
175 OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.1.0d
176 OPENSSLINCDIR = $(OPENSSLDIR)/include
177 OPENSSLLIBDIR = $(OPENSSLDIR)
178
179 #### Either the directory where the Tcl library is installed or the Tcl
180 # source code directory resides (depending on the value of the macro
181
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -170,11 +170,11 @@
170 #### The directories where the OpenSSL include and library files are located.
171 # The recommended usage here is to use the Sysinternals junction tool
172 # to create a hard link between an "openssl-1.x" sub-directory of the
173 # Fossil source code directory and the target OpenSSL source directory.
174 #
175 OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.1.0e
176 OPENSSLINCDIR = $(OPENSSLDIR)/include
177 OPENSSLLIBDIR = $(OPENSSLDIR)
178
179 #### Either the directory where the Tcl library is installed or the Tcl
180 # source code directory resides (depending on the value of the macro
181
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -98,11 +98,11 @@
9898
!ifndef USE_SEE
9999
USE_SEE = 0
100100
!endif
101101
102102
!if $(FOSSIL_ENABLE_SSL)!=0
103
-SSLDIR = $(B)\compat\openssl-1.1.0d
103
+SSLDIR = $(B)\compat\openssl-1.1.0e
104104
SSLINCDIR = $(SSLDIR)\inc32
105105
!if $(FOSSIL_DYNAMIC_BUILD)!=0
106106
SSLLIBDIR = $(SSLDIR)\out32dll
107107
!else
108108
SSLLIBDIR = $(SSLDIR)\out32
109109
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -98,11 +98,11 @@
98 !ifndef USE_SEE
99 USE_SEE = 0
100 !endif
101
102 !if $(FOSSIL_ENABLE_SSL)!=0
103 SSLDIR = $(B)\compat\openssl-1.1.0d
104 SSLINCDIR = $(SSLDIR)\inc32
105 !if $(FOSSIL_DYNAMIC_BUILD)!=0
106 SSLLIBDIR = $(SSLDIR)\out32dll
107 !else
108 SSLLIBDIR = $(SSLDIR)\out32
109
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -98,11 +98,11 @@
98 !ifndef USE_SEE
99 USE_SEE = 0
100 !endif
101
102 !if $(FOSSIL_ENABLE_SSL)!=0
103 SSLDIR = $(B)\compat\openssl-1.1.0e
104 SSLINCDIR = $(SSLDIR)\inc32
105 !if $(FOSSIL_DYNAMIC_BUILD)!=0
106 SSLLIBDIR = $(SSLDIR)\out32dll
107 !else
108 SSLLIBDIR = $(SSLDIR)\out32
109
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -98,11 +98,11 @@
9898
!ifndef USE_SEE
9999
USE_SEE = 0
100100
!endif
101101
102102
!if $(FOSSIL_ENABLE_SSL)!=0
103
-SSLDIR = $(B)\compat\openssl-1.1.0d
103
+SSLDIR = $(B)\compat\openssl-1.1.0e
104104
SSLINCDIR = $(SSLDIR)\inc32
105105
!if $(FOSSIL_DYNAMIC_BUILD)!=0
106106
SSLLIBDIR = $(SSLDIR)\out32dll
107107
!else
108108
SSLLIBDIR = $(SSLDIR)\out32
109109
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -98,11 +98,11 @@
98 !ifndef USE_SEE
99 USE_SEE = 0
100 !endif
101
102 !if $(FOSSIL_ENABLE_SSL)!=0
103 SSLDIR = $(B)\compat\openssl-1.1.0d
104 SSLINCDIR = $(SSLDIR)\inc32
105 !if $(FOSSIL_DYNAMIC_BUILD)!=0
106 SSLLIBDIR = $(SSLDIR)\out32dll
107 !else
108 SSLLIBDIR = $(SSLDIR)\out32
109
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -98,11 +98,11 @@
98 !ifndef USE_SEE
99 USE_SEE = 0
100 !endif
101
102 !if $(FOSSIL_ENABLE_SSL)!=0
103 SSLDIR = $(B)\compat\openssl-1.1.0e
104 SSLINCDIR = $(SSLDIR)\inc32
105 !if $(FOSSIL_DYNAMIC_BUILD)!=0
106 SSLLIBDIR = $(SSLDIR)\out32dll
107 !else
108 SSLLIBDIR = $(SSLDIR)\out32
109
+1 -1
--- www/build.wiki
+++ www/build.wiki
@@ -141,11 +141,11 @@
141141
the optional <a href="https://www.openssl.org/">OpenSSL</a> support,
142142
first <a href="https://www.openssl.org/source/">download the official
143143
source code for OpenSSL</a> and extract it to an appropriately named
144144
"<b>openssl-X.Y.ZA</b>" subdirectory within the local
145145
[/tree?ci=trunk&name=compat | compat] directory (e.g.
146
-"<b>compat/openssl-1.1.0d</b>"), then make sure that some recent
146
+"<b>compat/openssl-1.1.0e</b>"), then make sure that some recent
147147
<a href="http://www.perl.org/">Perl</a> binaries are installed locally,
148148
and finally run one of the following commands:
149149
<blockquote><pre>
150150
nmake /f Makefile.msc FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
151151
</pre></blockquote>
152152
--- www/build.wiki
+++ www/build.wiki
@@ -141,11 +141,11 @@
141 the optional <a href="https://www.openssl.org/">OpenSSL</a> support,
142 first <a href="https://www.openssl.org/source/">download the official
143 source code for OpenSSL</a> and extract it to an appropriately named
144 "<b>openssl-X.Y.ZA</b>" subdirectory within the local
145 [/tree?ci=trunk&name=compat | compat] directory (e.g.
146 "<b>compat/openssl-1.1.0d</b>"), then make sure that some recent
147 <a href="http://www.perl.org/">Perl</a> binaries are installed locally,
148 and finally run one of the following commands:
149 <blockquote><pre>
150 nmake /f Makefile.msc FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
151 </pre></blockquote>
152
--- www/build.wiki
+++ www/build.wiki
@@ -141,11 +141,11 @@
141 the optional <a href="https://www.openssl.org/">OpenSSL</a> support,
142 first <a href="https://www.openssl.org/source/">download the official
143 source code for OpenSSL</a> and extract it to an appropriately named
144 "<b>openssl-X.Y.ZA</b>" subdirectory within the local
145 [/tree?ci=trunk&name=compat | compat] directory (e.g.
146 "<b>compat/openssl-1.1.0e</b>"), then make sure that some recent
147 <a href="http://www.perl.org/">Perl</a> binaries are installed locally,
148 and finally run one of the following commands:
149 <blockquote><pre>
150 nmake /f Makefile.msc FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
151 </pre></blockquote>
152
+1 -1
--- www/build.wiki
+++ www/build.wiki
@@ -141,11 +141,11 @@
141141
the optional <a href="https://www.openssl.org/">OpenSSL</a> support,
142142
first <a href="https://www.openssl.org/source/">download the official
143143
source code for OpenSSL</a> and extract it to an appropriately named
144144
"<b>openssl-X.Y.ZA</b>" subdirectory within the local
145145
[/tree?ci=trunk&name=compat | compat] directory (e.g.
146
-"<b>compat/openssl-1.1.0d</b>"), then make sure that some recent
146
+"<b>compat/openssl-1.1.0e</b>"), then make sure that some recent
147147
<a href="http://www.perl.org/">Perl</a> binaries are installed locally,
148148
and finally run one of the following commands:
149149
<blockquote><pre>
150150
nmake /f Makefile.msc FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
151151
</pre></blockquote>
152152
--- www/build.wiki
+++ www/build.wiki
@@ -141,11 +141,11 @@
141 the optional <a href="https://www.openssl.org/">OpenSSL</a> support,
142 first <a href="https://www.openssl.org/source/">download the official
143 source code for OpenSSL</a> and extract it to an appropriately named
144 "<b>openssl-X.Y.ZA</b>" subdirectory within the local
145 [/tree?ci=trunk&name=compat | compat] directory (e.g.
146 "<b>compat/openssl-1.1.0d</b>"), then make sure that some recent
147 <a href="http://www.perl.org/">Perl</a> binaries are installed locally,
148 and finally run one of the following commands:
149 <blockquote><pre>
150 nmake /f Makefile.msc FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
151 </pre></blockquote>
152
--- www/build.wiki
+++ www/build.wiki
@@ -141,11 +141,11 @@
141 the optional <a href="https://www.openssl.org/">OpenSSL</a> support,
142 first <a href="https://www.openssl.org/source/">download the official
143 source code for OpenSSL</a> and extract it to an appropriately named
144 "<b>openssl-X.Y.ZA</b>" subdirectory within the local
145 [/tree?ci=trunk&name=compat | compat] directory (e.g.
146 "<b>compat/openssl-1.1.0e</b>"), then make sure that some recent
147 <a href="http://www.perl.org/">Perl</a> binaries are installed locally,
148 and finally run one of the following commands:
149 <blockquote><pre>
150 nmake /f Makefile.msc FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
151 </pre></blockquote>
152
--- www/changes.wiki
+++ www/changes.wiki
@@ -1,7 +1,12 @@
11
<title>Change Log</title>
22
3
+<a name='v1_38'></a>
4
+<h2>Changes for Version 1.38 (2017-??-??)</h2>
5
+
6
+ * Update the built-in SQLite to version 3.17.0.
7
+
38
<a name='v1_37'></a>
49
<h2>Changes for Version 1.37 (2017-01-16)</h2>
510
611
* Add checkbox widgets to various web pages. See [/technote/8d18bf27e9|
712
this technote] for more information. To get the checkboxes to look as
813
--- www/changes.wiki
+++ www/changes.wiki
@@ -1,7 +1,12 @@
1 <title>Change Log</title>
2
 
 
 
 
 
3 <a name='v1_37'></a>
4 <h2>Changes for Version 1.37 (2017-01-16)</h2>
5
6 * Add checkbox widgets to various web pages. See [/technote/8d18bf27e9|
7 this technote] for more information. To get the checkboxes to look as
8
--- www/changes.wiki
+++ www/changes.wiki
@@ -1,7 +1,12 @@
1 <title>Change Log</title>
2
3 <a name='v1_38'></a>
4 <h2>Changes for Version 1.38 (2017-??-??)</h2>
5
6 * Update the built-in SQLite to version 3.17.0.
7
8 <a name='v1_37'></a>
9 <h2>Changes for Version 1.37 (2017-01-16)</h2>
10
11 * Add checkbox widgets to various web pages. See [/technote/8d18bf27e9|
12 this technote] for more information. To get the checkboxes to look as
13
--- www/env-opts.md
+++ www/env-opts.md
@@ -72,10 +72,13 @@
7272
`--localtime`: Override the `timeline-utc` option to explicitly use
7373
local time.
7474
7575
`--nocgi`: Prevent fossil from acting as a CGI by default even if the
7676
`GATEWAY_INTERFACE` environment variable is set.
77
+
78
+`--no-dir-symlinks`: Disables support for directory symlinks, thus
79
+preventing them from being traversed into.
7780
7881
`--no-th-hook`: (Sets `g.fNoThHook`.) Override the `th1-hooks` setting
7982
and prevent any TH1 hooks from being executed.
8083
8184
`--quiet`: (Sets `g.fQuiet`.) Cause fossil to suppress various messages and progress
8285
--- www/env-opts.md
+++ www/env-opts.md
@@ -72,10 +72,13 @@
72 `--localtime`: Override the `timeline-utc` option to explicitly use
73 local time.
74
75 `--nocgi`: Prevent fossil from acting as a CGI by default even if the
76 `GATEWAY_INTERFACE` environment variable is set.
 
 
 
77
78 `--no-th-hook`: (Sets `g.fNoThHook`.) Override the `th1-hooks` setting
79 and prevent any TH1 hooks from being executed.
80
81 `--quiet`: (Sets `g.fQuiet`.) Cause fossil to suppress various messages and progress
82
--- www/env-opts.md
+++ www/env-opts.md
@@ -72,10 +72,13 @@
72 `--localtime`: Override the `timeline-utc` option to explicitly use
73 local time.
74
75 `--nocgi`: Prevent fossil from acting as a CGI by default even if the
76 `GATEWAY_INTERFACE` environment variable is set.
77
78 `--no-dir-symlinks`: Disables support for directory symlinks, thus
79 preventing them from being traversed into.
80
81 `--no-th-hook`: (Sets `g.fNoThHook`.) Override the `th1-hooks` setting
82 and prevent any TH1 hooks from being executed.
83
84 `--quiet`: (Sets `g.fQuiet`.) Cause fossil to suppress various messages and progress
85
--- www/quickstart.wiki
+++ www/quickstart.wiki
@@ -268,11 +268,11 @@
268268
before you start editing, if you want, but most people just wait
269269
until they are ready to commit.
270270
271271
To merge two branches back together, first
272272
[/help/update | update] to the branch you want to merge into.
273
- Then do a [/help/merge|merge] another branch that you want to incorporate
273
+ Then do a [/help/merge|merge] of the other branch that you want to incorporate
274274
the changes from. For example, to merge "featureX" changes into "trunk"
275275
do this:</p>
276276
277277
<blockquote>
278278
<b>fossil [/help/update|update] trunk</b><br>
279279
--- www/quickstart.wiki
+++ www/quickstart.wiki
@@ -268,11 +268,11 @@
268 before you start editing, if you want, but most people just wait
269 until they are ready to commit.
270
271 To merge two branches back together, first
272 [/help/update | update] to the branch you want to merge into.
273 Then do a [/help/merge|merge] another branch that you want to incorporate
274 the changes from. For example, to merge "featureX" changes into "trunk"
275 do this:</p>
276
277 <blockquote>
278 <b>fossil [/help/update|update] trunk</b><br>
279
--- www/quickstart.wiki
+++ www/quickstart.wiki
@@ -268,11 +268,11 @@
268 before you start editing, if you want, but most people just wait
269 until they are ready to commit.
270
271 To merge two branches back together, first
272 [/help/update | update] to the branch you want to merge into.
273 Then do a [/help/merge|merge] of the other branch that you want to incorporate
274 the changes from. For example, to merge "featureX" changes into "trunk"
275 do this:</p>
276
277 <blockquote>
278 <b>fossil [/help/update|update] trunk</b><br>
279

Keyboard Shortcuts

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