Fossil SCM

Merged in trunk.

stephan 2022-06-11 12:34 UTC markdown-tagrefs merge
Commit fd14e7ec623d7c570d249f412b3a1b0cad1b78c6a0d01fc638b60ad2bc817063
69 files changed +11 +36 +108 +2 -1 +42 +2632 -2368 +2122 -1656 +23 -1 +1 -2 +3 -1 +20 -1 +19 -5 +19 -5 +9 -2 +4 -5 +58 -12 +12 -4 +14 -6 -19 +8 -1 +5 -3 +44 -11 +44 -11 +9 -1 +24 +1 -1 +14 +1 -1 +10 -8 +3 -2 +10 +3 -2 +2 -1 +2 -1 +2 -1 +10 -4 +10 +146 -9 +1 -1 +12 +2 -2 +3 -1 +1 +8 -4 +55 -11 +163 +9 -3 +1 -1 +4 -3 +90 -35 +1 +12 -4 +3 -1 +17 -1 +71 -66 +71 -66 +65 +14 -1 +6 -1 +12 -2 +148 -3 +6 -6 +6 -3 +17 +5 -3 +1 -1
+11
--- Makefile.in
+++ Makefile.in
@@ -72,10 +72,21 @@
7272
USE_SEE = @USE_SEE@
7373
APPNAME = fossil
7474
#
7575
# APPNAME = fossil-fuzz
7676
# may be more appropriate for fuzzing.
77
+
78
+#### Emscripten stuff for optionally doing in-tree builds
79
+# of any WASM components. We store precompiled WASM in the the SCM, so
80
+# this is only useful for people who actively work on WASM
81
+# components. EMSDK_ENV refers to the "environment" script which comes
82
+# with the Emscripten SDK package:
83
+# https://emscripten.org/docs/getting_started/downloads.html
84
+EMSDK_HOME = @EMSDK_HOME@
85
+EMSDK_ENV = @EMSDK_ENV@
86
+EMCC_OPT = @EMCC_OPT@
87
+EMCC_WRAPPER = $(SRCDIR_tools)/emcc.sh
7788
7889
.PHONY: all tags
7990
8091
include $(SRCDIR)/main.mk
8192
8293
--- Makefile.in
+++ Makefile.in
@@ -72,10 +72,21 @@
72 USE_SEE = @USE_SEE@
73 APPNAME = fossil
74 #
75 # APPNAME = fossil-fuzz
76 # may be more appropriate for fuzzing.
 
 
 
 
 
 
 
 
 
 
 
77
78 .PHONY: all tags
79
80 include $(SRCDIR)/main.mk
81
82
--- Makefile.in
+++ Makefile.in
@@ -72,10 +72,21 @@
72 USE_SEE = @USE_SEE@
73 APPNAME = fossil
74 #
75 # APPNAME = fossil-fuzz
76 # may be more appropriate for fuzzing.
77
78 #### Emscripten stuff for optionally doing in-tree builds
79 # of any WASM components. We store precompiled WASM in the the SCM, so
80 # this is only useful for people who actively work on WASM
81 # components. EMSDK_ENV refers to the "environment" script which comes
82 # with the Emscripten SDK package:
83 # https://emscripten.org/docs/getting_started/downloads.html
84 EMSDK_HOME = @EMSDK_HOME@
85 EMSDK_ENV = @EMSDK_ENV@
86 EMCC_OPT = @EMCC_OPT@
87 EMCC_WRAPPER = $(SRCDIR_tools)/emcc.sh
88
89 .PHONY: all tags
90
91 include $(SRCDIR)/main.mk
92
93
+36
--- auto.def
+++ auto.def
@@ -28,10 +28,11 @@
2828
static=0 => {Link a static executable}
2929
fusefs=1 => {Disable the Fuse Filesystem}
3030
fossil-debug=0 => {Build with fossil debugging enabled}
3131
no-opt=0 => {Build without optimization}
3232
json=0 => {Build with fossil JSON API enabled}
33
+ with-emsdk:path => {Directory containing the Emscripten SDK}
3334
}
3435
3536
# Update the minimum required SQLite version number here, and also
3637
# in src/main.c near the sqlite3_libversion_number() call. Take care
3738
# that both places agree!
@@ -632,10 +633,37 @@
632633
set tclconfig(TCL_LD_FLAGS) [string map [list -ldl ""] \
633634
$tclconfig(TCL_LD_FLAGS)]
634635
define-append EXTRA_LDFLAGS $tclconfig(TCL_LD_FLAGS)
635636
define FOSSIL_ENABLE_TCL
636637
}
638
+
639
+# Emscripten is a purely optional component used only for doing
640
+# in-tree builds of WASM stuff, as opposed to WASM binaries we import
641
+# from other places. This is only set up for Unix-style OSes and is
642
+# untested anywhere but Linux.
643
+set emsdkHome [opt-val with-emsdk]
644
+define EMSDK_HOME ""
645
+define EMSDK_ENV ""
646
+define EMCC_OPT "-Oz"
647
+if {$emsdkHome eq "" && [info exists ::env(EMSDK)]} {
648
+ # Fall back to checking the environment. $EMSDK gets set
649
+ # by sourcing emsdk_env.sh.
650
+ set emsdkHome $::env(EMSDK)
651
+}
652
+if {$emsdkHome ne ""} {
653
+ define EMSDK_HOME $emsdkHome
654
+ set emsdkEnv "$emsdkHome/emsdk_env.sh"
655
+ if {[file exists $emsdkEnv]} {
656
+ puts "Using Emscripten SDK environment from $emsdkEnv."
657
+ define EMSDK_ENV $emsdkEnv
658
+ if {[info exists ::env(EMCC_OPT)]} {
659
+ define EMCC_OPT $::env(EMCC_OPT)
660
+ }
661
+ } else {
662
+ puts "emsdk_env.sh not found. Assuming emcc is in the PATH."
663
+ }
664
+}
637665
638666
# Network functions require libraries on some systems
639667
cc-check-function-in-lib gethostbyname nsl
640668
if {![cc-check-function-in-lib socket {socket network}]} {
641669
# Last resort, may be Windows
@@ -726,8 +754,16 @@
726754
# Linux can only infer the dependency on pthread from OpenSSL when
727755
# doing dynamic linkage.
728756
define-append LIBS -lpthread
729757
}
730758
759
+if {[get-define EMSDK_HOME] ne ""} {
760
+ define EMCC_WRAPPER $::autosetup(dir)/../tools/emcc.sh
761
+ make-template tools/emcc.sh.in
762
+ catch {exec chmod u+x tools/emcc.sh}
763
+} else {
764
+ define EMCC_WRAPPER ""
765
+ catch {exec rm -f tools/emcc.sh}
766
+}
731767
732768
make-template Makefile.in
733769
make-config-header autoconfig.h -auto {USE_* FOSSIL_*}
734770
735771
ADDED extsrc/pikchr-worker.js
--- auto.def
+++ auto.def
@@ -28,10 +28,11 @@
28 static=0 => {Link a static executable}
29 fusefs=1 => {Disable the Fuse Filesystem}
30 fossil-debug=0 => {Build with fossil debugging enabled}
31 no-opt=0 => {Build without optimization}
32 json=0 => {Build with fossil JSON API enabled}
 
33 }
34
35 # Update the minimum required SQLite version number here, and also
36 # in src/main.c near the sqlite3_libversion_number() call. Take care
37 # that both places agree!
@@ -632,10 +633,37 @@
632 set tclconfig(TCL_LD_FLAGS) [string map [list -ldl ""] \
633 $tclconfig(TCL_LD_FLAGS)]
634 define-append EXTRA_LDFLAGS $tclconfig(TCL_LD_FLAGS)
635 define FOSSIL_ENABLE_TCL
636 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
637
638 # Network functions require libraries on some systems
639 cc-check-function-in-lib gethostbyname nsl
640 if {![cc-check-function-in-lib socket {socket network}]} {
641 # Last resort, may be Windows
@@ -726,8 +754,16 @@
726 # Linux can only infer the dependency on pthread from OpenSSL when
727 # doing dynamic linkage.
728 define-append LIBS -lpthread
729 }
730
 
 
 
 
 
 
 
 
731
732 make-template Makefile.in
733 make-config-header autoconfig.h -auto {USE_* FOSSIL_*}
734
735 DDED extsrc/pikchr-worker.js
--- auto.def
+++ auto.def
@@ -28,10 +28,11 @@
28 static=0 => {Link a static executable}
29 fusefs=1 => {Disable the Fuse Filesystem}
30 fossil-debug=0 => {Build with fossil debugging enabled}
31 no-opt=0 => {Build without optimization}
32 json=0 => {Build with fossil JSON API enabled}
33 with-emsdk:path => {Directory containing the Emscripten SDK}
34 }
35
36 # Update the minimum required SQLite version number here, and also
37 # in src/main.c near the sqlite3_libversion_number() call. Take care
38 # that both places agree!
@@ -632,10 +633,37 @@
633 set tclconfig(TCL_LD_FLAGS) [string map [list -ldl ""] \
634 $tclconfig(TCL_LD_FLAGS)]
635 define-append EXTRA_LDFLAGS $tclconfig(TCL_LD_FLAGS)
636 define FOSSIL_ENABLE_TCL
637 }
638
639 # Emscripten is a purely optional component used only for doing
640 # in-tree builds of WASM stuff, as opposed to WASM binaries we import
641 # from other places. This is only set up for Unix-style OSes and is
642 # untested anywhere but Linux.
643 set emsdkHome [opt-val with-emsdk]
644 define EMSDK_HOME ""
645 define EMSDK_ENV ""
646 define EMCC_OPT "-Oz"
647 if {$emsdkHome eq "" && [info exists ::env(EMSDK)]} {
648 # Fall back to checking the environment. $EMSDK gets set
649 # by sourcing emsdk_env.sh.
650 set emsdkHome $::env(EMSDK)
651 }
652 if {$emsdkHome ne ""} {
653 define EMSDK_HOME $emsdkHome
654 set emsdkEnv "$emsdkHome/emsdk_env.sh"
655 if {[file exists $emsdkEnv]} {
656 puts "Using Emscripten SDK environment from $emsdkEnv."
657 define EMSDK_ENV $emsdkEnv
658 if {[info exists ::env(EMCC_OPT)]} {
659 define EMCC_OPT $::env(EMCC_OPT)
660 }
661 } else {
662 puts "emsdk_env.sh not found. Assuming emcc is in the PATH."
663 }
664 }
665
666 # Network functions require libraries on some systems
667 cc-check-function-in-lib gethostbyname nsl
668 if {![cc-check-function-in-lib socket {socket network}]} {
669 # Last resort, may be Windows
@@ -726,8 +754,16 @@
754 # Linux can only infer the dependency on pthread from OpenSSL when
755 # doing dynamic linkage.
756 define-append LIBS -lpthread
757 }
758
759 if {[get-define EMSDK_HOME] ne ""} {
760 define EMCC_WRAPPER $::autosetup(dir)/../tools/emcc.sh
761 make-template tools/emcc.sh.in
762 catch {exec chmod u+x tools/emcc.sh}
763 } else {
764 define EMCC_WRAPPER ""
765 catch {exec rm -f tools/emcc.sh}
766 }
767
768 make-template Makefile.in
769 make-config-header autoconfig.h -auto {USE_* FOSSIL_*}
770
771 DDED extsrc/pikchr-worker.js
--- a/extsrc/pikchr-worker.js
+++ b/extsrc/pikchr-worker.js
@@ -0,0 +1,108 @@
1
+/*
2
+ 2022-05-20
3
+
4
+ The author disresult like with DOM elements,
5
+ we have to define a lower-level message API. Messages abstractly
6
+ look like:
7
+
8
+ { type: string, data: type-specific value }
9
+
10
+ Where 'type' is used for dispatching and 'data' is a
11
+ 'type'-dependent value.
12
+
13
+ The 'type' values expected by each side of the main/worker
14
+ connection vary. The types are described below but subject to
15
+ change at any time as this experiment evolves.
16
+
17
+ Main-to-Worker message types:
18
+
19
+ - pikchr: data=pikchr-format text to render or an object:
20
+
21
+ {
22
+ pikchr: source code for the pikchr,
23
+ darkMode: boolean true to adjust colors for a dark color scheme,
24
+ cssClass: CSS class name to add to the typeshe author disclaims copyright to this source code. In place of a
25
+ legal notice, here is a blessing:
26
+
27
+ * May you do good and not evil.
28
+ * May you find forgiveness for yourself and forgive others.
29
+ * May you share freely, never taking more than you give.
30
+
31
+ ***********************************************************************
32
+
33
+ This is a JS Worker file for use with the pikchr wasm build. It
34
+ loads the pikchr wasm module and offers access to it via the Worker
35
+ message-passing interface.
36
+
37
+ Because we can have only a single message handler, as opposed to an
38
+ arbitrary n/* messages come in the form
39
+
40
+ {type:'module', data:{
41
+ type:'status',
42
+ data: {text:string|null, step:1-based-integer}
43
+ }
44
+
45
+ with an incrementing step value for each subsequent message. When
46
+ the module loading is complete, a message with a text value of
47
+ n ull is posted.
48
+
49
+ - pikchr:
50
+
51
+ {type: 'pikchr',
52
+ data:{
53
+ pikchr: input text,
54
+ result: rendered result (SVG on success, HTML on error),
55
+ isError: bool, true if .pikchr holds an error report,
56
+ flags: integer: flags used to configure the pikchr rendering,
57
+ width: if !isError, width (integer pixels) of the SVG,
58
+ height: if !isError, height (integer pixels) of the SVG
59
+ }
60
+ }
61
+
62
+*/
63
+
64
+"use strict";
65
+(function(){
66
+ /**
67
+ Posts a message in the form {type,data} unless passed more than
68
+ 2 args, in which case it posts {type, data:[arg1...argN]}.
69
+ */
70
+ const wMsg = function(type,data){
71
+ postMessage({
72
+ type,
73
+ data: arguments.length<3
74
+ ? data
75
+ : Array.prototype.slice.call(arguments,1)
76
+ });
77
+ };
78
+
79
+ const stderr = function(){wMsg('stderr', Array.prototype.slice.call(arguments));};
80
+
81
+ self.onerror = function(/*message, source, lineno, colno, error*/) {
82
+ const err = arguments[4];
83
+ if(err && 'ExitStatus'==err.name){
84
+ /* This "cannot happen" for this wasm binding, but just in
85
+ case... */
86
+ pikchrModule.isDead = true;
87
+ stderr("FATAL ERROR:", err.message);
88
+ stderr("Restarting the app requires reloading the page.");
89
+ wMsg('error', err);
90
+ }
91
+ pikchrModule.setStatus('Exception thrown, see JavaScript console: '+err);
92
+ };
93
+
94
+ self.onmessage = function f(ev){
95
+ ev = ev.data;
96
+ switch(ev.type){
97
+ /**
98
+ Runs the given text through pikchr and emits a 'pikchr'
99
+ message result (output format documented above).
100
+
101
+ Fires a working/start event before it starts and
102
+ working/end event when it finishes.
103
+ */
104
+ case 'pikchr':
105
+ if(pikchrModule.isDead){
106
+ stderr( show-ready');
107
+ });
108
+})();
--- a/extsrc/pikchr-worker.js
+++ b/extsrc/pikchr-worker.js
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/extsrc/pikchr-worker.js
+++ b/extsrc/pikchr-worker.js
@@ -0,0 +1,108 @@
1 /*
2 2022-05-20
3
4 The author disresult like with DOM elements,
5 we have to define a lower-level message API. Messages abstractly
6 look like:
7
8 { type: string, data: type-specific value }
9
10 Where 'type' is used for dispatching and 'data' is a
11 'type'-dependent value.
12
13 The 'type' values expected by each side of the main/worker
14 connection vary. The types are described below but subject to
15 change at any time as this experiment evolves.
16
17 Main-to-Worker message types:
18
19 - pikchr: data=pikchr-format text to render or an object:
20
21 {
22 pikchr: source code for the pikchr,
23 darkMode: boolean true to adjust colors for a dark color scheme,
24 cssClass: CSS class name to add to the typeshe author disclaims copyright to this source code. In place of a
25 legal notice, here is a blessing:
26
27 * May you do good and not evil.
28 * May you find forgiveness for yourself and forgive others.
29 * May you share freely, never taking more than you give.
30
31 ***********************************************************************
32
33 This is a JS Worker file for use with the pikchr wasm build. It
34 loads the pikchr wasm module and offers access to it via the Worker
35 message-passing interface.
36
37 Because we can have only a single message handler, as opposed to an
38 arbitrary n/* messages come in the form
39
40 {type:'module', data:{
41 type:'status',
42 data: {text:string|null, step:1-based-integer}
43 }
44
45 with an incrementing step value for each subsequent message. When
46 the module loading is complete, a message with a text value of
47 n ull is posted.
48
49 - pikchr:
50
51 {type: 'pikchr',
52 data:{
53 pikchr: input text,
54 result: rendered result (SVG on success, HTML on error),
55 isError: bool, true if .pikchr holds an error report,
56 flags: integer: flags used to configure the pikchr rendering,
57 width: if !isError, width (integer pixels) of the SVG,
58 height: if !isError, height (integer pixels) of the SVG
59 }
60 }
61
62 */
63
64 "use strict";
65 (function(){
66 /**
67 Posts a message in the form {type,data} unless passed more than
68 2 args, in which case it posts {type, data:[arg1...argN]}.
69 */
70 const wMsg = function(type,data){
71 postMessage({
72 type,
73 data: arguments.length<3
74 ? data
75 : Array.prototype.slice.call(arguments,1)
76 });
77 };
78
79 const stderr = function(){wMsg('stderr', Array.prototype.slice.call(arguments));};
80
81 self.onerror = function(/*message, source, lineno, colno, error*/) {
82 const err = arguments[4];
83 if(err && 'ExitStatus'==err.name){
84 /* This "cannot happen" for this wasm binding, but just in
85 case... */
86 pikchrModule.isDead = true;
87 stderr("FATAL ERROR:", err.message);
88 stderr("Restarting the app requires reloading the page.");
89 wMsg('error', err);
90 }
91 pikchrModule.setStatus('Exception thrown, see JavaScript console: '+err);
92 };
93
94 self.onmessage = function f(ev){
95 ev = ev.data;
96 switch(ev.type){
97 /**
98 Runs the given text through pikchr and emits a 'pikchr'
99 message result (output format documented above).
100
101 Fires a working/start event before it starts and
102 working/end event when it finishes.
103 */
104 case 'pikchr':
105 if(pikchrModule.isDead){
106 stderr( show-ready');
107 });
108 })();
+2 -1
--- extsrc/pikchr.c
+++ extsrc/pikchr.c
@@ -3807,10 +3807,11 @@
38073807
}
38083808
static void circleNumProp(Pik *p, PObj *pObj, PToken *pId){
38093809
/* For a circle, the width must equal the height and both must
38103810
** be twice the radius. Enforce those constraints. */
38113811
switch( pId->eType ){
3812
+ case T_DIAMETER:
38123813
case T_RADIUS:
38133814
pObj->w = pObj->h = 2.0*pObj->rad;
38143815
break;
38153816
case T_WIDTH:
38163817
pObj->h = pObj->w;
@@ -8095,6 +8096,6 @@
80958096
80968097
80978098
#endif /* PIKCHR_TCL */
80988099
80998100
8100
-#line 8125 "pikchr.c"
8101
+#line 8126 "pikchr.c"
81018102
81028103
ADDED extsrc/pikchr.js
81038104
ADDED extsrc/pikchr.wasm
--- extsrc/pikchr.c
+++ extsrc/pikchr.c
@@ -3807,10 +3807,11 @@
3807 }
3808 static void circleNumProp(Pik *p, PObj *pObj, PToken *pId){
3809 /* For a circle, the width must equal the height and both must
3810 ** be twice the radius. Enforce those constraints. */
3811 switch( pId->eType ){
 
3812 case T_RADIUS:
3813 pObj->w = pObj->h = 2.0*pObj->rad;
3814 break;
3815 case T_WIDTH:
3816 pObj->h = pObj->w;
@@ -8095,6 +8096,6 @@
8095
8096
8097 #endif /* PIKCHR_TCL */
8098
8099
8100 #line 8125 "pikchr.c"
8101
8102 DDED extsrc/pikchr.js
8103 DDED extsrc/pikchr.wasm
--- extsrc/pikchr.c
+++ extsrc/pikchr.c
@@ -3807,10 +3807,11 @@
3807 }
3808 static void circleNumProp(Pik *p, PObj *pObj, PToken *pId){
3809 /* For a circle, the width must equal the height and both must
3810 ** be twice the radius. Enforce those constraints. */
3811 switch( pId->eType ){
3812 case T_DIAMETER:
3813 case T_RADIUS:
3814 pObj->w = pObj->h = 2.0*pObj->rad;
3815 break;
3816 case T_WIDTH:
3817 pObj->h = pObj->w;
@@ -8095,6 +8096,6 @@
8096
8097
8098 #endif /* PIKCHR_TCL */
8099
8100
8101 #line 8126 "pikchr.c"
8102
8103 DDED extsrc/pikchr.js
8104 DDED extsrc/pikchr.wasm
--- a/extsrc/pikchr.js
+++ b/extsrc/pikchr.js
@@ -0,0 +1,42 @@
1
+) {
2
+ r initPikchrModuDi
3
+var initPikchrMod || {};e["ready"] = new Promise(fhis by
4
+// setting the ENVIRONMENT// setting the ENVIRONMENT settingow) => {
5
+ throw toT(resolve, reject) =>e present at the end iffunction(resolve, reject) end if `scriptDirectory` is lice"";
6
+
7
+function locateFile(path) {
8
+ if (Module["locaeFile"]) {
9
+ retut they can
10
+// refer to Module (if they choose; th// Sometimes an exivartory` is lice"";
11
+
12
+fnse = awaitirectory + path;
13
+}
14
+
15
+
16
+
17
+/aitirectory + path;
18
+}
19
+
20
+
21
+
22
+// Ho);nt runtime environments.}
23
+var initPikchrModule = (() => {
24
+ vchrModule var initPikchrModule =, setWindowTitle;
25
+ed in the code, and you
26
+//d in the code, and yORKER) {
27
+iseResvar readomiseResolve = resolveft());
28
+ }
29
+ }
30
+ // = reject;
31
+});
32
+
33
+// Determine nvironment we are in}
34
+ if (_scriptDir) {
35
+iseResvar readyPromi_scriptDir;
36
+ }
37
+Throw) => {
38
+ throw tindexOf("blob:") !== 0) {
39
+iseResvar readyPromiscriptDirectory.substr(0, ) => {
40
+ thrvar runtimeKeepavar buffer,aliveCounter = 0 || runtimeKeepaliveCounter > 0binaryFilevar initPikchrModuDir = typGlobalBufferAn ENVIRONME.src : undefined;
41
+ nresponse =>b() =>var function(str)function(arr)function(type) {
42
+ r
--- a/extsrc/pikchr.js
+++ b/extsrc/pikchr.js
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/extsrc/pikchr.js
+++ b/extsrc/pikchr.js
@@ -0,0 +1,42 @@
1 ) {
2 r initPikchrModuDi
3 var initPikchrMod || {};e["ready"] = new Promise(fhis by
4 // setting the ENVIRONMENT// setting the ENVIRONMENT settingow) => {
5 throw toT(resolve, reject) =>e present at the end iffunction(resolve, reject) end if `scriptDirectory` is lice"";
6
7 function locateFile(path) {
8 if (Module["locaeFile"]) {
9 retut they can
10 // refer to Module (if they choose; th// Sometimes an exivartory` is lice"";
11
12 fnse = awaitirectory + path;
13 }
14
15
16
17 /aitirectory + path;
18 }
19
20
21
22 // Ho);nt runtime environments.}
23 var initPikchrModule = (() => {
24 vchrModule var initPikchrModule =, setWindowTitle;
25 ed in the code, and you
26 //d in the code, and yORKER) {
27 iseResvar readomiseResolve = resolveft());
28 }
29 }
30 // = reject;
31 });
32
33 // Determine nvironment we are in}
34 if (_scriptDir) {
35 iseResvar readyPromi_scriptDir;
36 }
37 Throw) => {
38 throw tindexOf("blob:") !== 0) {
39 iseResvar readyPromiscriptDirectory.substr(0, ) => {
40 thrvar runtimeKeepavar buffer,aliveCounter = 0 || runtimeKeepaliveCounter > 0binaryFilevar initPikchrModuDir = typGlobalBufferAn ENVIRONME.src : undefined;
41 nresponse =>b() =>var function(str)function(arr)function(type) {
42 r

Binary file

+2632 -2368
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -245,10 +245,20 @@
245245
#else
246246
# define setBinaryMode(X,Y)
247247
# define setTextMode(X,Y)
248248
#endif
249249
250
+/*
251
+** When compiling with emcc (a.k.a. emscripten), we're building a
252
+** WebAssembly (WASM) bundle and need to disable and rewire a few
253
+** things.
254
+*/
255
+#ifdef __EMSCRIPTEN__
256
+#define SQLITE_SHELL_WASM_MODE
257
+#else
258
+#undef SQLITE_SHELL_WASM_MODE
259
+#endif
250260
251261
/* True if the timer is enabled */
252262
static int enableTimer = 0;
253263
254264
/* Return the current wall-clock time */
@@ -707,10 +717,11 @@
707717
**
708718
** The result is stored in space obtained from malloc() and must either
709719
** be freed by the caller or else passed back into this routine via the
710720
** zPrior argument for reuse.
711721
*/
722
+#ifndef SQLITE_SHELL_WASM_MODE
712723
static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
713724
char *zPrompt;
714725
char *zResult;
715726
if( in!=0 ){
716727
zResult = local_getline(zPrior, in);
@@ -726,11 +737,11 @@
726737
if( zResult && *zResult ) shell_add_history(zResult);
727738
#endif
728739
}
729740
return zResult;
730741
}
731
-
742
+#endif /* !SQLITE_SHELL_WASM_MODE */
732743
733744
/*
734745
** Return the value of a hexadecimal digit. Return -1 if the input
735746
** is not a hex digit.
736747
*/
@@ -814,11 +825,11 @@
814825
** zIn, if it was not NULL, is freed.
815826
**
816827
** If the third argument, quote, is not '\0', then it is used as a
817828
** quote character for zAppend.
818829
*/
819
-static void appendText(ShellText *p, char const *zAppend, char quote){
830
+static void appendText(ShellText *p, const char *zAppend, char quote){
820831
int len;
821832
int i;
822833
int nAppend = strlen30(zAppend);
823834
824835
len = nAppend+p->n+1;
@@ -1379,10 +1390,121 @@
13791390
#endif /* defined(WIN32) && defined(_MSC_VER) */
13801391
13811392
/************************* End test_windirent.c ********************/
13821393
#define dirent DIRENT
13831394
#endif
1395
+/************************* Begin ../ext/misc/memtrace.c ******************/
1396
+/*
1397
+** 2019-01-21
1398
+**
1399
+** The author disclaims copyright to this source code. In place of
1400
+** a legal notice, here is a blessing:
1401
+**
1402
+** May you do good and not evil.
1403
+** May you find forgiveness for yourself and forgive others.
1404
+** May you share freely, never taking more than you give.
1405
+**
1406
+*************************************************************************
1407
+**
1408
+** This file implements an extension that uses the SQLITE_CONFIG_MALLOC
1409
+** mechanism to add a tracing layer on top of SQLite. If this extension
1410
+** is registered prior to sqlite3_initialize(), it will cause all memory
1411
+** allocation activities to be logged on standard output, or to some other
1412
+** FILE specified by the initializer.
1413
+**
1414
+** This file needs to be compiled into the application that uses it.
1415
+**
1416
+** This extension is used to implement the --memtrace option of the
1417
+** command-line shell.
1418
+*/
1419
+#include <assert.h>
1420
+#include <string.h>
1421
+#include <stdio.h>
1422
+
1423
+/* The original memory allocation routines */
1424
+static sqlite3_mem_methods memtraceBase;
1425
+static FILE *memtraceOut;
1426
+
1427
+/* Methods that trace memory allocations */
1428
+static void *memtraceMalloc(int n){
1429
+ if( memtraceOut ){
1430
+ fprintf(memtraceOut, "MEMTRACE: allocate %d bytes\n",
1431
+ memtraceBase.xRoundup(n));
1432
+ }
1433
+ return memtraceBase.xMalloc(n);
1434
+}
1435
+static void memtraceFree(void *p){
1436
+ if( p==0 ) return;
1437
+ if( memtraceOut ){
1438
+ fprintf(memtraceOut, "MEMTRACE: free %d bytes\n", memtraceBase.xSize(p));
1439
+ }
1440
+ memtraceBase.xFree(p);
1441
+}
1442
+static void *memtraceRealloc(void *p, int n){
1443
+ if( p==0 ) return memtraceMalloc(n);
1444
+ if( n==0 ){
1445
+ memtraceFree(p);
1446
+ return 0;
1447
+ }
1448
+ if( memtraceOut ){
1449
+ fprintf(memtraceOut, "MEMTRACE: resize %d -> %d bytes\n",
1450
+ memtraceBase.xSize(p), memtraceBase.xRoundup(n));
1451
+ }
1452
+ return memtraceBase.xRealloc(p, n);
1453
+}
1454
+static int memtraceSize(void *p){
1455
+ return memtraceBase.xSize(p);
1456
+}
1457
+static int memtraceRoundup(int n){
1458
+ return memtraceBase.xRoundup(n);
1459
+}
1460
+static int memtraceInit(void *p){
1461
+ return memtraceBase.xInit(p);
1462
+}
1463
+static void memtraceShutdown(void *p){
1464
+ memtraceBase.xShutdown(p);
1465
+}
1466
+
1467
+/* The substitute memory allocator */
1468
+static sqlite3_mem_methods ersaztMethods = {
1469
+ memtraceMalloc,
1470
+ memtraceFree,
1471
+ memtraceRealloc,
1472
+ memtraceSize,
1473
+ memtraceRoundup,
1474
+ memtraceInit,
1475
+ memtraceShutdown,
1476
+ 0
1477
+};
1478
+
1479
+/* Begin tracing memory allocations to out. */
1480
+int sqlite3MemTraceActivate(FILE *out){
1481
+ int rc = SQLITE_OK;
1482
+ if( memtraceBase.xMalloc==0 ){
1483
+ rc = sqlite3_config(SQLITE_CONFIG_GETMALLOC, &memtraceBase);
1484
+ if( rc==SQLITE_OK ){
1485
+ rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &ersaztMethods);
1486
+ }
1487
+ }
1488
+ memtraceOut = out;
1489
+ return rc;
1490
+}
1491
+
1492
+/* Deactivate memory tracing */
1493
+int sqlite3MemTraceDeactivate(void){
1494
+ int rc = SQLITE_OK;
1495
+ if( memtraceBase.xMalloc!=0 ){
1496
+ rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &memtraceBase);
1497
+ if( rc==SQLITE_OK ){
1498
+ memset(&memtraceBase, 0, sizeof(memtraceBase));
1499
+ }
1500
+ }
1501
+ memtraceOut = 0;
1502
+ return rc;
1503
+}
1504
+
1505
+/************************* End ../ext/misc/memtrace.c ********************/
13841506
/************************* Begin ../ext/misc/shathree.c ******************/
13851507
/*
13861508
** 2017-03-08
13871509
**
13881510
** The author disclaims copyright to this source code. In place of
@@ -2106,2333 +2228,10 @@
21062228
}
21072229
return rc;
21082230
}
21092231
21102232
/************************* End ../ext/misc/shathree.c ********************/
2111
-/************************* Begin ../ext/misc/fileio.c ******************/
2112
-/*
2113
-** 2014-06-13
2114
-**
2115
-** The author disclaims copyright to this source code. In place of
2116
-** a legal notice, here is a blessing:
2117
-**
2118
-** May you do good and not evil.
2119
-** May you find forgiveness for yourself and forgive others.
2120
-** May you share freely, never taking more than you give.
2121
-**
2122
-******************************************************************************
2123
-**
2124
-** This SQLite extension implements SQL functions readfile() and
2125
-** writefile(), and eponymous virtual type "fsdir".
2126
-**
2127
-** WRITEFILE(FILE, DATA [, MODE [, MTIME]]):
2128
-**
2129
-** If neither of the optional arguments is present, then this UDF
2130
-** function writes blob DATA to file FILE. If successful, the number
2131
-** of bytes written is returned. If an error occurs, NULL is returned.
2132
-**
2133
-** If the first option argument - MODE - is present, then it must
2134
-** be passed an integer value that corresponds to a POSIX mode
2135
-** value (file type + permissions, as returned in the stat.st_mode
2136
-** field by the stat() system call). Three types of files may
2137
-** be written/created:
2138
-**
2139
-** regular files: (mode & 0170000)==0100000
2140
-** symbolic links: (mode & 0170000)==0120000
2141
-** directories: (mode & 0170000)==0040000
2142
-**
2143
-** For a directory, the DATA is ignored. For a symbolic link, it is
2144
-** interpreted as text and used as the target of the link. For a
2145
-** regular file, it is interpreted as a blob and written into the
2146
-** named file. Regardless of the type of file, its permissions are
2147
-** set to (mode & 0777) before returning.
2148
-**
2149
-** If the optional MTIME argument is present, then it is interpreted
2150
-** as an integer - the number of seconds since the unix epoch. The
2151
-** modification-time of the target file is set to this value before
2152
-** returning.
2153
-**
2154
-** If three or more arguments are passed to this function and an
2155
-** error is encountered, an exception is raised.
2156
-**
2157
-** READFILE(FILE):
2158
-**
2159
-** Read and return the contents of file FILE (type blob) from disk.
2160
-**
2161
-** FSDIR:
2162
-**
2163
-** Used as follows:
2164
-**
2165
-** SELECT * FROM fsdir($path [, $dir]);
2166
-**
2167
-** Parameter $path is an absolute or relative pathname. If the file that it
2168
-** refers to does not exist, it is an error. If the path refers to a regular
2169
-** file or symbolic link, it returns a single row. Or, if the path refers
2170
-** to a directory, it returns one row for the directory, and one row for each
2171
-** file within the hierarchy rooted at $path.
2172
-**
2173
-** Each row has the following columns:
2174
-**
2175
-** name: Path to file or directory (text value).
2176
-** mode: Value of stat.st_mode for directory entry (an integer).
2177
-** mtime: Value of stat.st_mtime for directory entry (an integer).
2178
-** data: For a regular file, a blob containing the file data. For a
2179
-** symlink, a text value containing the text of the link. For a
2180
-** directory, NULL.
2181
-**
2182
-** If a non-NULL value is specified for the optional $dir parameter and
2183
-** $path is a relative path, then $path is interpreted relative to $dir.
2184
-** And the paths returned in the "name" column of the table are also
2185
-** relative to directory $dir.
2186
-**
2187
-** Notes on building this extension for Windows:
2188
-** Unless linked statically with the SQLite library, a preprocessor
2189
-** symbol, FILEIO_WIN32_DLL, must be #define'd to create a stand-alone
2190
-** DLL form of this extension for WIN32. See its use below for details.
2191
-*/
2192
-/* #include "sqlite3ext.h" */
2193
-SQLITE_EXTENSION_INIT1
2194
-#include <stdio.h>
2195
-#include <string.h>
2196
-#include <assert.h>
2197
-
2198
-#include <sys/types.h>
2199
-#include <sys/stat.h>
2200
-#include <fcntl.h>
2201
-#if !defined(_WIN32) && !defined(WIN32)
2202
-# include <unistd.h>
2203
-# include <dirent.h>
2204
-# include <utime.h>
2205
-# include <sys/time.h>
2206
-#else
2207
-# include "windows.h"
2208
-# include <io.h>
2209
-# include <direct.h>
2210
-/* # include "test_windirent.h" */
2211
-# define dirent DIRENT
2212
-# ifndef chmod
2213
-# define chmod _chmod
2214
-# endif
2215
-# ifndef stat
2216
-# define stat _stat
2217
-# endif
2218
-# define mkdir(path,mode) _mkdir(path)
2219
-# define lstat(path,buf) stat(path,buf)
2220
-#endif
2221
-#include <time.h>
2222
-#include <errno.h>
2223
-
2224
-
2225
-/*
2226
-** Structure of the fsdir() table-valued function
2227
-*/
2228
- /* 0 1 2 3 4 5 */
2229
-#define FSDIR_SCHEMA "(name,mode,mtime,data,path HIDDEN,dir HIDDEN)"
2230
-#define FSDIR_COLUMN_NAME 0 /* Name of the file */
2231
-#define FSDIR_COLUMN_MODE 1 /* Access mode */
2232
-#define FSDIR_COLUMN_MTIME 2 /* Last modification time */
2233
-#define FSDIR_COLUMN_DATA 3 /* File content */
2234
-#define FSDIR_COLUMN_PATH 4 /* Path to top of search */
2235
-#define FSDIR_COLUMN_DIR 5 /* Path is relative to this directory */
2236
-
2237
-
2238
-/*
2239
-** Set the result stored by context ctx to a blob containing the
2240
-** contents of file zName. Or, leave the result unchanged (NULL)
2241
-** if the file does not exist or is unreadable.
2242
-**
2243
-** If the file exceeds the SQLite blob size limit, through an
2244
-** SQLITE_TOOBIG error.
2245
-**
2246
-** Throw an SQLITE_IOERR if there are difficulties pulling the file
2247
-** off of disk.
2248
-*/
2249
-static void readFileContents(sqlite3_context *ctx, const char *zName){
2250
- FILE *in;
2251
- sqlite3_int64 nIn;
2252
- void *pBuf;
2253
- sqlite3 *db;
2254
- int mxBlob;
2255
-
2256
- in = fopen(zName, "rb");
2257
- if( in==0 ){
2258
- /* File does not exist or is unreadable. Leave the result set to NULL. */
2259
- return;
2260
- }
2261
- fseek(in, 0, SEEK_END);
2262
- nIn = ftell(in);
2263
- rewind(in);
2264
- db = sqlite3_context_db_handle(ctx);
2265
- mxBlob = sqlite3_limit(db, SQLITE_LIMIT_LENGTH, -1);
2266
- if( nIn>mxBlob ){
2267
- sqlite3_result_error_code(ctx, SQLITE_TOOBIG);
2268
- fclose(in);
2269
- return;
2270
- }
2271
- pBuf = sqlite3_malloc64( nIn ? nIn : 1 );
2272
- if( pBuf==0 ){
2273
- sqlite3_result_error_nomem(ctx);
2274
- fclose(in);
2275
- return;
2276
- }
2277
- if( nIn==(sqlite3_int64)fread(pBuf, 1, (size_t)nIn, in) ){
2278
- sqlite3_result_blob64(ctx, pBuf, nIn, sqlite3_free);
2279
- }else{
2280
- sqlite3_result_error_code(ctx, SQLITE_IOERR);
2281
- sqlite3_free(pBuf);
2282
- }
2283
- fclose(in);
2284
-}
2285
-
2286
-/*
2287
-** Implementation of the "readfile(X)" SQL function. The entire content
2288
-** of the file named X is read and returned as a BLOB. NULL is returned
2289
-** if the file does not exist or is unreadable.
2290
-*/
2291
-static void readfileFunc(
2292
- sqlite3_context *context,
2293
- int argc,
2294
- sqlite3_value **argv
2295
-){
2296
- const char *zName;
2297
- (void)(argc); /* Unused parameter */
2298
- zName = (const char*)sqlite3_value_text(argv[0]);
2299
- if( zName==0 ) return;
2300
- readFileContents(context, zName);
2301
-}
2302
-
2303
-/*
2304
-** Set the error message contained in context ctx to the results of
2305
-** vprintf(zFmt, ...).
2306
-*/
2307
-static void ctxErrorMsg(sqlite3_context *ctx, const char *zFmt, ...){
2308
- char *zMsg = 0;
2309
- va_list ap;
2310
- va_start(ap, zFmt);
2311
- zMsg = sqlite3_vmprintf(zFmt, ap);
2312
- sqlite3_result_error(ctx, zMsg, -1);
2313
- sqlite3_free(zMsg);
2314
- va_end(ap);
2315
-}
2316
-
2317
-#if defined(_WIN32)
2318
-/*
2319
-** This function is designed to convert a Win32 FILETIME structure into the
2320
-** number of seconds since the Unix Epoch (1970-01-01 00:00:00 UTC).
2321
-*/
2322
-static sqlite3_uint64 fileTimeToUnixTime(
2323
- LPFILETIME pFileTime
2324
-){
2325
- SYSTEMTIME epochSystemTime;
2326
- ULARGE_INTEGER epochIntervals;
2327
- FILETIME epochFileTime;
2328
- ULARGE_INTEGER fileIntervals;
2329
-
2330
- memset(&epochSystemTime, 0, sizeof(SYSTEMTIME));
2331
- epochSystemTime.wYear = 1970;
2332
- epochSystemTime.wMonth = 1;
2333
- epochSystemTime.wDay = 1;
2334
- SystemTimeToFileTime(&epochSystemTime, &epochFileTime);
2335
- epochIntervals.LowPart = epochFileTime.dwLowDateTime;
2336
- epochIntervals.HighPart = epochFileTime.dwHighDateTime;
2337
-
2338
- fileIntervals.LowPart = pFileTime->dwLowDateTime;
2339
- fileIntervals.HighPart = pFileTime->dwHighDateTime;
2340
-
2341
- return (fileIntervals.QuadPart - epochIntervals.QuadPart) / 10000000;
2342
-}
2343
-
2344
-
2345
-#if defined(FILEIO_WIN32_DLL) && (defined(_WIN32) || defined(WIN32))
2346
-# /* To allow a standalone DLL, use this next replacement function: */
2347
-# undef sqlite3_win32_utf8_to_unicode
2348
-# define sqlite3_win32_utf8_to_unicode utf8_to_utf16
2349
-#
2350
-LPWSTR utf8_to_utf16(const char *z){
2351
- int nAllot = MultiByteToWideChar(CP_UTF8, 0, z, -1, NULL, 0);
2352
- LPWSTR rv = sqlite3_malloc(nAllot * sizeof(WCHAR));
2353
- if( rv!=0 && 0 < MultiByteToWideChar(CP_UTF8, 0, z, -1, rv, nAllot) )
2354
- return rv;
2355
- sqlite3_free(rv);
2356
- return 0;
2357
-}
2358
-#endif
2359
-
2360
-/*
2361
-** This function attempts to normalize the time values found in the stat()
2362
-** buffer to UTC. This is necessary on Win32, where the runtime library
2363
-** appears to return these values as local times.
2364
-*/
2365
-static void statTimesToUtc(
2366
- const char *zPath,
2367
- struct stat *pStatBuf
2368
-){
2369
- HANDLE hFindFile;
2370
- WIN32_FIND_DATAW fd;
2371
- LPWSTR zUnicodeName;
2372
- extern LPWSTR sqlite3_win32_utf8_to_unicode(const char*);
2373
- zUnicodeName = sqlite3_win32_utf8_to_unicode(zPath);
2374
- if( zUnicodeName ){
2375
- memset(&fd, 0, sizeof(WIN32_FIND_DATAW));
2376
- hFindFile = FindFirstFileW(zUnicodeName, &fd);
2377
- if( hFindFile!=NULL ){
2378
- pStatBuf->st_ctime = (time_t)fileTimeToUnixTime(&fd.ftCreationTime);
2379
- pStatBuf->st_atime = (time_t)fileTimeToUnixTime(&fd.ftLastAccessTime);
2380
- pStatBuf->st_mtime = (time_t)fileTimeToUnixTime(&fd.ftLastWriteTime);
2381
- FindClose(hFindFile);
2382
- }
2383
- sqlite3_free(zUnicodeName);
2384
- }
2385
-}
2386
-#endif
2387
-
2388
-/*
2389
-** This function is used in place of stat(). On Windows, special handling
2390
-** is required in order for the included time to be returned as UTC. On all
2391
-** other systems, this function simply calls stat().
2392
-*/
2393
-static int fileStat(
2394
- const char *zPath,
2395
- struct stat *pStatBuf
2396
-){
2397
-#if defined(_WIN32)
2398
- int rc = stat(zPath, pStatBuf);
2399
- if( rc==0 ) statTimesToUtc(zPath, pStatBuf);
2400
- return rc;
2401
-#else
2402
- return stat(zPath, pStatBuf);
2403
-#endif
2404
-}
2405
-
2406
-/*
2407
-** This function is used in place of lstat(). On Windows, special handling
2408
-** is required in order for the included time to be returned as UTC. On all
2409
-** other systems, this function simply calls lstat().
2410
-*/
2411
-static int fileLinkStat(
2412
- const char *zPath,
2413
- struct stat *pStatBuf
2414
-){
2415
-#if defined(_WIN32)
2416
- int rc = lstat(zPath, pStatBuf);
2417
- if( rc==0 ) statTimesToUtc(zPath, pStatBuf);
2418
- return rc;
2419
-#else
2420
- return lstat(zPath, pStatBuf);
2421
-#endif
2422
-}
2423
-
2424
-/*
2425
-** Argument zFile is the name of a file that will be created and/or written
2426
-** by SQL function writefile(). This function ensures that the directory
2427
-** zFile will be written to exists, creating it if required. The permissions
2428
-** for any path components created by this function are set in accordance
2429
-** with the current umask.
2430
-**
2431
-** If an OOM condition is encountered, SQLITE_NOMEM is returned. Otherwise,
2432
-** SQLITE_OK is returned if the directory is successfully created, or
2433
-** SQLITE_ERROR otherwise.
2434
-*/
2435
-static int makeDirectory(
2436
- const char *zFile
2437
-){
2438
- char *zCopy = sqlite3_mprintf("%s", zFile);
2439
- int rc = SQLITE_OK;
2440
-
2441
- if( zCopy==0 ){
2442
- rc = SQLITE_NOMEM;
2443
- }else{
2444
- int nCopy = (int)strlen(zCopy);
2445
- int i = 1;
2446
-
2447
- while( rc==SQLITE_OK ){
2448
- struct stat sStat;
2449
- int rc2;
2450
-
2451
- for(; zCopy[i]!='/' && i<nCopy; i++);
2452
- if( i==nCopy ) break;
2453
- zCopy[i] = '\0';
2454
-
2455
- rc2 = fileStat(zCopy, &sStat);
2456
- if( rc2!=0 ){
2457
- if( mkdir(zCopy, 0777) ) rc = SQLITE_ERROR;
2458
- }else{
2459
- if( !S_ISDIR(sStat.st_mode) ) rc = SQLITE_ERROR;
2460
- }
2461
- zCopy[i] = '/';
2462
- i++;
2463
- }
2464
-
2465
- sqlite3_free(zCopy);
2466
- }
2467
-
2468
- return rc;
2469
-}
2470
-
2471
-/*
2472
-** This function does the work for the writefile() UDF. Refer to
2473
-** header comments at the top of this file for details.
2474
-*/
2475
-static int writeFile(
2476
- sqlite3_context *pCtx, /* Context to return bytes written in */
2477
- const char *zFile, /* File to write */
2478
- sqlite3_value *pData, /* Data to write */
2479
- mode_t mode, /* MODE parameter passed to writefile() */
2480
- sqlite3_int64 mtime /* MTIME parameter (or -1 to not set time) */
2481
-){
2482
- if( zFile==0 ) return 1;
2483
-#if !defined(_WIN32) && !defined(WIN32)
2484
- if( S_ISLNK(mode) ){
2485
- const char *zTo = (const char*)sqlite3_value_text(pData);
2486
- if( zTo==0 || symlink(zTo, zFile)<0 ) return 1;
2487
- }else
2488
-#endif
2489
- {
2490
- if( S_ISDIR(mode) ){
2491
- if( mkdir(zFile, mode) ){
2492
- /* The mkdir() call to create the directory failed. This might not
2493
- ** be an error though - if there is already a directory at the same
2494
- ** path and either the permissions already match or can be changed
2495
- ** to do so using chmod(), it is not an error. */
2496
- struct stat sStat;
2497
- if( errno!=EEXIST
2498
- || 0!=fileStat(zFile, &sStat)
2499
- || !S_ISDIR(sStat.st_mode)
2500
- || ((sStat.st_mode&0777)!=(mode&0777) && 0!=chmod(zFile, mode&0777))
2501
- ){
2502
- return 1;
2503
- }
2504
- }
2505
- }else{
2506
- sqlite3_int64 nWrite = 0;
2507
- const char *z;
2508
- int rc = 0;
2509
- FILE *out = fopen(zFile, "wb");
2510
- if( out==0 ) return 1;
2511
- z = (const char*)sqlite3_value_blob(pData);
2512
- if( z ){
2513
- sqlite3_int64 n = fwrite(z, 1, sqlite3_value_bytes(pData), out);
2514
- nWrite = sqlite3_value_bytes(pData);
2515
- if( nWrite!=n ){
2516
- rc = 1;
2517
- }
2518
- }
2519
- fclose(out);
2520
- if( rc==0 && mode && chmod(zFile, mode & 0777) ){
2521
- rc = 1;
2522
- }
2523
- if( rc ) return 2;
2524
- sqlite3_result_int64(pCtx, nWrite);
2525
- }
2526
- }
2527
-
2528
- if( mtime>=0 ){
2529
-#if defined(_WIN32)
2530
-#if !SQLITE_OS_WINRT
2531
- /* Windows */
2532
- FILETIME lastAccess;
2533
- FILETIME lastWrite;
2534
- SYSTEMTIME currentTime;
2535
- LONGLONG intervals;
2536
- HANDLE hFile;
2537
- LPWSTR zUnicodeName;
2538
- extern LPWSTR sqlite3_win32_utf8_to_unicode(const char*);
2539
-
2540
- GetSystemTime(&currentTime);
2541
- SystemTimeToFileTime(&currentTime, &lastAccess);
2542
- intervals = Int32x32To64(mtime, 10000000) + 116444736000000000;
2543
- lastWrite.dwLowDateTime = (DWORD)intervals;
2544
- lastWrite.dwHighDateTime = intervals >> 32;
2545
- zUnicodeName = sqlite3_win32_utf8_to_unicode(zFile);
2546
- if( zUnicodeName==0 ){
2547
- return 1;
2548
- }
2549
- hFile = CreateFileW(
2550
- zUnicodeName, FILE_WRITE_ATTRIBUTES, 0, NULL, OPEN_EXISTING,
2551
- FILE_FLAG_BACKUP_SEMANTICS, NULL
2552
- );
2553
- sqlite3_free(zUnicodeName);
2554
- if( hFile!=INVALID_HANDLE_VALUE ){
2555
- BOOL bResult = SetFileTime(hFile, NULL, &lastAccess, &lastWrite);
2556
- CloseHandle(hFile);
2557
- return !bResult;
2558
- }else{
2559
- return 1;
2560
- }
2561
-#endif
2562
-#elif defined(AT_FDCWD) && 0 /* utimensat() is not universally available */
2563
- /* Recent unix */
2564
- struct timespec times[2];
2565
- times[0].tv_nsec = times[1].tv_nsec = 0;
2566
- times[0].tv_sec = time(0);
2567
- times[1].tv_sec = mtime;
2568
- if( utimensat(AT_FDCWD, zFile, times, AT_SYMLINK_NOFOLLOW) ){
2569
- return 1;
2570
- }
2571
-#else
2572
- /* Legacy unix */
2573
- struct timeval times[2];
2574
- times[0].tv_usec = times[1].tv_usec = 0;
2575
- times[0].tv_sec = time(0);
2576
- times[1].tv_sec = mtime;
2577
- if( utimes(zFile, times) ){
2578
- return 1;
2579
- }
2580
-#endif
2581
- }
2582
-
2583
- return 0;
2584
-}
2585
-
2586
-/*
2587
-** Implementation of the "writefile(W,X[,Y[,Z]]])" SQL function.
2588
-** Refer to header comments at the top of this file for details.
2589
-*/
2590
-static void writefileFunc(
2591
- sqlite3_context *context,
2592
- int argc,
2593
- sqlite3_value **argv
2594
-){
2595
- const char *zFile;
2596
- mode_t mode = 0;
2597
- int res;
2598
- sqlite3_int64 mtime = -1;
2599
-
2600
- if( argc<2 || argc>4 ){
2601
- sqlite3_result_error(context,
2602
- "wrong number of arguments to function writefile()", -1
2603
- );
2604
- return;
2605
- }
2606
-
2607
- zFile = (const char*)sqlite3_value_text(argv[0]);
2608
- if( zFile==0 ) return;
2609
- if( argc>=3 ){
2610
- mode = (mode_t)sqlite3_value_int(argv[2]);
2611
- }
2612
- if( argc==4 ){
2613
- mtime = sqlite3_value_int64(argv[3]);
2614
- }
2615
-
2616
- res = writeFile(context, zFile, argv[1], mode, mtime);
2617
- if( res==1 && errno==ENOENT ){
2618
- if( makeDirectory(zFile)==SQLITE_OK ){
2619
- res = writeFile(context, zFile, argv[1], mode, mtime);
2620
- }
2621
- }
2622
-
2623
- if( argc>2 && res!=0 ){
2624
- if( S_ISLNK(mode) ){
2625
- ctxErrorMsg(context, "failed to create symlink: %s", zFile);
2626
- }else if( S_ISDIR(mode) ){
2627
- ctxErrorMsg(context, "failed to create directory: %s", zFile);
2628
- }else{
2629
- ctxErrorMsg(context, "failed to write file: %s", zFile);
2630
- }
2631
- }
2632
-}
2633
-
2634
-/*
2635
-** SQL function: lsmode(MODE)
2636
-**
2637
-** Given a numberic st_mode from stat(), convert it into a human-readable
2638
-** text string in the style of "ls -l".
2639
-*/
2640
-static void lsModeFunc(
2641
- sqlite3_context *context,
2642
- int argc,
2643
- sqlite3_value **argv
2644
-){
2645
- int i;
2646
- int iMode = sqlite3_value_int(argv[0]);
2647
- char z[16];
2648
- (void)argc;
2649
- if( S_ISLNK(iMode) ){
2650
- z[0] = 'l';
2651
- }else if( S_ISREG(iMode) ){
2652
- z[0] = '-';
2653
- }else if( S_ISDIR(iMode) ){
2654
- z[0] = 'd';
2655
- }else{
2656
- z[0] = '?';
2657
- }
2658
- for(i=0; i<3; i++){
2659
- int m = (iMode >> ((2-i)*3));
2660
- char *a = &z[1 + i*3];
2661
- a[0] = (m & 0x4) ? 'r' : '-';
2662
- a[1] = (m & 0x2) ? 'w' : '-';
2663
- a[2] = (m & 0x1) ? 'x' : '-';
2664
- }
2665
- z[10] = '\0';
2666
- sqlite3_result_text(context, z, -1, SQLITE_TRANSIENT);
2667
-}
2668
-
2669
-#ifndef SQLITE_OMIT_VIRTUALTABLE
2670
-
2671
-/*
2672
-** Cursor type for recursively iterating through a directory structure.
2673
-*/
2674
-typedef struct fsdir_cursor fsdir_cursor;
2675
-typedef struct FsdirLevel FsdirLevel;
2676
-
2677
-struct FsdirLevel {
2678
- DIR *pDir; /* From opendir() */
2679
- char *zDir; /* Name of directory (nul-terminated) */
2680
-};
2681
-
2682
-struct fsdir_cursor {
2683
- sqlite3_vtab_cursor base; /* Base class - must be first */
2684
-
2685
- int nLvl; /* Number of entries in aLvl[] array */
2686
- int iLvl; /* Index of current entry */
2687
- FsdirLevel *aLvl; /* Hierarchy of directories being traversed */
2688
-
2689
- const char *zBase;
2690
- int nBase;
2691
-
2692
- struct stat sStat; /* Current lstat() results */
2693
- char *zPath; /* Path to current entry */
2694
- sqlite3_int64 iRowid; /* Current rowid */
2695
-};
2696
-
2697
-typedef struct fsdir_tab fsdir_tab;
2698
-struct fsdir_tab {
2699
- sqlite3_vtab base; /* Base class - must be first */
2700
-};
2701
-
2702
-/*
2703
-** Construct a new fsdir virtual table object.
2704
-*/
2705
-static int fsdirConnect(
2706
- sqlite3 *db,
2707
- void *pAux,
2708
- int argc, const char *const*argv,
2709
- sqlite3_vtab **ppVtab,
2710
- char **pzErr
2711
-){
2712
- fsdir_tab *pNew = 0;
2713
- int rc;
2714
- (void)pAux;
2715
- (void)argc;
2716
- (void)argv;
2717
- (void)pzErr;
2718
- rc = sqlite3_declare_vtab(db, "CREATE TABLE x" FSDIR_SCHEMA);
2719
- if( rc==SQLITE_OK ){
2720
- pNew = (fsdir_tab*)sqlite3_malloc( sizeof(*pNew) );
2721
- if( pNew==0 ) return SQLITE_NOMEM;
2722
- memset(pNew, 0, sizeof(*pNew));
2723
- sqlite3_vtab_config(db, SQLITE_VTAB_DIRECTONLY);
2724
- }
2725
- *ppVtab = (sqlite3_vtab*)pNew;
2726
- return rc;
2727
-}
2728
-
2729
-/*
2730
-** This method is the destructor for fsdir vtab objects.
2731
-*/
2732
-static int fsdirDisconnect(sqlite3_vtab *pVtab){
2733
- sqlite3_free(pVtab);
2734
- return SQLITE_OK;
2735
-}
2736
-
2737
-/*
2738
-** Constructor for a new fsdir_cursor object.
2739
-*/
2740
-static int fsdirOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
2741
- fsdir_cursor *pCur;
2742
- (void)p;
2743
- pCur = sqlite3_malloc( sizeof(*pCur) );
2744
- if( pCur==0 ) return SQLITE_NOMEM;
2745
- memset(pCur, 0, sizeof(*pCur));
2746
- pCur->iLvl = -1;
2747
- *ppCursor = &pCur->base;
2748
- return SQLITE_OK;
2749
-}
2750
-
2751
-/*
2752
-** Reset a cursor back to the state it was in when first returned
2753
-** by fsdirOpen().
2754
-*/
2755
-static void fsdirResetCursor(fsdir_cursor *pCur){
2756
- int i;
2757
- for(i=0; i<=pCur->iLvl; i++){
2758
- FsdirLevel *pLvl = &pCur->aLvl[i];
2759
- if( pLvl->pDir ) closedir(pLvl->pDir);
2760
- sqlite3_free(pLvl->zDir);
2761
- }
2762
- sqlite3_free(pCur->zPath);
2763
- sqlite3_free(pCur->aLvl);
2764
- pCur->aLvl = 0;
2765
- pCur->zPath = 0;
2766
- pCur->zBase = 0;
2767
- pCur->nBase = 0;
2768
- pCur->nLvl = 0;
2769
- pCur->iLvl = -1;
2770
- pCur->iRowid = 1;
2771
-}
2772
-
2773
-/*
2774
-** Destructor for an fsdir_cursor.
2775
-*/
2776
-static int fsdirClose(sqlite3_vtab_cursor *cur){
2777
- fsdir_cursor *pCur = (fsdir_cursor*)cur;
2778
-
2779
- fsdirResetCursor(pCur);
2780
- sqlite3_free(pCur);
2781
- return SQLITE_OK;
2782
-}
2783
-
2784
-/*
2785
-** Set the error message for the virtual table associated with cursor
2786
-** pCur to the results of vprintf(zFmt, ...).
2787
-*/
2788
-static void fsdirSetErrmsg(fsdir_cursor *pCur, const char *zFmt, ...){
2789
- va_list ap;
2790
- va_start(ap, zFmt);
2791
- pCur->base.pVtab->zErrMsg = sqlite3_vmprintf(zFmt, ap);
2792
- va_end(ap);
2793
-}
2794
-
2795
-
2796
-/*
2797
-** Advance an fsdir_cursor to its next row of output.
2798
-*/
2799
-static int fsdirNext(sqlite3_vtab_cursor *cur){
2800
- fsdir_cursor *pCur = (fsdir_cursor*)cur;
2801
- mode_t m = pCur->sStat.st_mode;
2802
-
2803
- pCur->iRowid++;
2804
- if( S_ISDIR(m) ){
2805
- /* Descend into this directory */
2806
- int iNew = pCur->iLvl + 1;
2807
- FsdirLevel *pLvl;
2808
- if( iNew>=pCur->nLvl ){
2809
- int nNew = iNew+1;
2810
- sqlite3_int64 nByte = nNew*sizeof(FsdirLevel);
2811
- FsdirLevel *aNew = (FsdirLevel*)sqlite3_realloc64(pCur->aLvl, nByte);
2812
- if( aNew==0 ) return SQLITE_NOMEM;
2813
- memset(&aNew[pCur->nLvl], 0, sizeof(FsdirLevel)*(nNew-pCur->nLvl));
2814
- pCur->aLvl = aNew;
2815
- pCur->nLvl = nNew;
2816
- }
2817
- pCur->iLvl = iNew;
2818
- pLvl = &pCur->aLvl[iNew];
2819
-
2820
- pLvl->zDir = pCur->zPath;
2821
- pCur->zPath = 0;
2822
- pLvl->pDir = opendir(pLvl->zDir);
2823
- if( pLvl->pDir==0 ){
2824
- fsdirSetErrmsg(pCur, "cannot read directory: %s", pCur->zPath);
2825
- return SQLITE_ERROR;
2826
- }
2827
- }
2828
-
2829
- while( pCur->iLvl>=0 ){
2830
- FsdirLevel *pLvl = &pCur->aLvl[pCur->iLvl];
2831
- struct dirent *pEntry = readdir(pLvl->pDir);
2832
- if( pEntry ){
2833
- if( pEntry->d_name[0]=='.' ){
2834
- if( pEntry->d_name[1]=='.' && pEntry->d_name[2]=='\0' ) continue;
2835
- if( pEntry->d_name[1]=='\0' ) continue;
2836
- }
2837
- sqlite3_free(pCur->zPath);
2838
- pCur->zPath = sqlite3_mprintf("%s/%s", pLvl->zDir, pEntry->d_name);
2839
- if( pCur->zPath==0 ) return SQLITE_NOMEM;
2840
- if( fileLinkStat(pCur->zPath, &pCur->sStat) ){
2841
- fsdirSetErrmsg(pCur, "cannot stat file: %s", pCur->zPath);
2842
- return SQLITE_ERROR;
2843
- }
2844
- return SQLITE_OK;
2845
- }
2846
- closedir(pLvl->pDir);
2847
- sqlite3_free(pLvl->zDir);
2848
- pLvl->pDir = 0;
2849
- pLvl->zDir = 0;
2850
- pCur->iLvl--;
2851
- }
2852
-
2853
- /* EOF */
2854
- sqlite3_free(pCur->zPath);
2855
- pCur->zPath = 0;
2856
- return SQLITE_OK;
2857
-}
2858
-
2859
-/*
2860
-** Return values of columns for the row at which the series_cursor
2861
-** is currently pointing.
2862
-*/
2863
-static int fsdirColumn(
2864
- sqlite3_vtab_cursor *cur, /* The cursor */
2865
- sqlite3_context *ctx, /* First argument to sqlite3_result_...() */
2866
- int i /* Which column to return */
2867
-){
2868
- fsdir_cursor *pCur = (fsdir_cursor*)cur;
2869
- switch( i ){
2870
- case FSDIR_COLUMN_NAME: {
2871
- sqlite3_result_text(ctx, &pCur->zPath[pCur->nBase], -1, SQLITE_TRANSIENT);
2872
- break;
2873
- }
2874
-
2875
- case FSDIR_COLUMN_MODE:
2876
- sqlite3_result_int64(ctx, pCur->sStat.st_mode);
2877
- break;
2878
-
2879
- case FSDIR_COLUMN_MTIME:
2880
- sqlite3_result_int64(ctx, pCur->sStat.st_mtime);
2881
- break;
2882
-
2883
- case FSDIR_COLUMN_DATA: {
2884
- mode_t m = pCur->sStat.st_mode;
2885
- if( S_ISDIR(m) ){
2886
- sqlite3_result_null(ctx);
2887
-#if !defined(_WIN32) && !defined(WIN32)
2888
- }else if( S_ISLNK(m) ){
2889
- char aStatic[64];
2890
- char *aBuf = aStatic;
2891
- sqlite3_int64 nBuf = 64;
2892
- int n;
2893
-
2894
- while( 1 ){
2895
- n = readlink(pCur->zPath, aBuf, nBuf);
2896
- if( n<nBuf ) break;
2897
- if( aBuf!=aStatic ) sqlite3_free(aBuf);
2898
- nBuf = nBuf*2;
2899
- aBuf = sqlite3_malloc64(nBuf);
2900
- if( aBuf==0 ){
2901
- sqlite3_result_error_nomem(ctx);
2902
- return SQLITE_NOMEM;
2903
- }
2904
- }
2905
-
2906
- sqlite3_result_text(ctx, aBuf, n, SQLITE_TRANSIENT);
2907
- if( aBuf!=aStatic ) sqlite3_free(aBuf);
2908
-#endif
2909
- }else{
2910
- readFileContents(ctx, pCur->zPath);
2911
- }
2912
- }
2913
- case FSDIR_COLUMN_PATH:
2914
- default: {
2915
- /* The FSDIR_COLUMN_PATH and FSDIR_COLUMN_DIR are input parameters.
2916
- ** always return their values as NULL */
2917
- break;
2918
- }
2919
- }
2920
- return SQLITE_OK;
2921
-}
2922
-
2923
-/*
2924
-** Return the rowid for the current row. In this implementation, the
2925
-** first row returned is assigned rowid value 1, and each subsequent
2926
-** row a value 1 more than that of the previous.
2927
-*/
2928
-static int fsdirRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
2929
- fsdir_cursor *pCur = (fsdir_cursor*)cur;
2930
- *pRowid = pCur->iRowid;
2931
- return SQLITE_OK;
2932
-}
2933
-
2934
-/*
2935
-** Return TRUE if the cursor has been moved off of the last
2936
-** row of output.
2937
-*/
2938
-static int fsdirEof(sqlite3_vtab_cursor *cur){
2939
- fsdir_cursor *pCur = (fsdir_cursor*)cur;
2940
- return (pCur->zPath==0);
2941
-}
2942
-
2943
-/*
2944
-** xFilter callback.
2945
-**
2946
-** idxNum==1 PATH parameter only
2947
-** idxNum==2 Both PATH and DIR supplied
2948
-*/
2949
-static int fsdirFilter(
2950
- sqlite3_vtab_cursor *cur,
2951
- int idxNum, const char *idxStr,
2952
- int argc, sqlite3_value **argv
2953
-){
2954
- const char *zDir = 0;
2955
- fsdir_cursor *pCur = (fsdir_cursor*)cur;
2956
- (void)idxStr;
2957
- fsdirResetCursor(pCur);
2958
-
2959
- if( idxNum==0 ){
2960
- fsdirSetErrmsg(pCur, "table function fsdir requires an argument");
2961
- return SQLITE_ERROR;
2962
- }
2963
-
2964
- assert( argc==idxNum && (argc==1 || argc==2) );
2965
- zDir = (const char*)sqlite3_value_text(argv[0]);
2966
- if( zDir==0 ){
2967
- fsdirSetErrmsg(pCur, "table function fsdir requires a non-NULL argument");
2968
- return SQLITE_ERROR;
2969
- }
2970
- if( argc==2 ){
2971
- pCur->zBase = (const char*)sqlite3_value_text(argv[1]);
2972
- }
2973
- if( pCur->zBase ){
2974
- pCur->nBase = (int)strlen(pCur->zBase)+1;
2975
- pCur->zPath = sqlite3_mprintf("%s/%s", pCur->zBase, zDir);
2976
- }else{
2977
- pCur->zPath = sqlite3_mprintf("%s", zDir);
2978
- }
2979
-
2980
- if( pCur->zPath==0 ){
2981
- return SQLITE_NOMEM;
2982
- }
2983
- if( fileLinkStat(pCur->zPath, &pCur->sStat) ){
2984
- fsdirSetErrmsg(pCur, "cannot stat file: %s", pCur->zPath);
2985
- return SQLITE_ERROR;
2986
- }
2987
-
2988
- return SQLITE_OK;
2989
-}
2990
-
2991
-/*
2992
-** SQLite will invoke this method one or more times while planning a query
2993
-** that uses the generate_series virtual table. This routine needs to create
2994
-** a query plan for each invocation and compute an estimated cost for that
2995
-** plan.
2996
-**
2997
-** In this implementation idxNum is used to represent the
2998
-** query plan. idxStr is unused.
2999
-**
3000
-** The query plan is represented by values of idxNum:
3001
-**
3002
-** (1) The path value is supplied by argv[0]
3003
-** (2) Path is in argv[0] and dir is in argv[1]
3004
-*/
3005
-static int fsdirBestIndex(
3006
- sqlite3_vtab *tab,
3007
- sqlite3_index_info *pIdxInfo
3008
-){
3009
- int i; /* Loop over constraints */
3010
- int idxPath = -1; /* Index in pIdxInfo->aConstraint of PATH= */
3011
- int idxDir = -1; /* Index in pIdxInfo->aConstraint of DIR= */
3012
- int seenPath = 0; /* True if an unusable PATH= constraint is seen */
3013
- int seenDir = 0; /* True if an unusable DIR= constraint is seen */
3014
- const struct sqlite3_index_constraint *pConstraint;
3015
-
3016
- (void)tab;
3017
- pConstraint = pIdxInfo->aConstraint;
3018
- for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
3019
- if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
3020
- switch( pConstraint->iColumn ){
3021
- case FSDIR_COLUMN_PATH: {
3022
- if( pConstraint->usable ){
3023
- idxPath = i;
3024
- seenPath = 0;
3025
- }else if( idxPath<0 ){
3026
- seenPath = 1;
3027
- }
3028
- break;
3029
- }
3030
- case FSDIR_COLUMN_DIR: {
3031
- if( pConstraint->usable ){
3032
- idxDir = i;
3033
- seenDir = 0;
3034
- }else if( idxDir<0 ){
3035
- seenDir = 1;
3036
- }
3037
- break;
3038
- }
3039
- }
3040
- }
3041
- if( seenPath || seenDir ){
3042
- /* If input parameters are unusable, disallow this plan */
3043
- return SQLITE_CONSTRAINT;
3044
- }
3045
-
3046
- if( idxPath<0 ){
3047
- pIdxInfo->idxNum = 0;
3048
- /* The pIdxInfo->estimatedCost should have been initialized to a huge
3049
- ** number. Leave it unchanged. */
3050
- pIdxInfo->estimatedRows = 0x7fffffff;
3051
- }else{
3052
- pIdxInfo->aConstraintUsage[idxPath].omit = 1;
3053
- pIdxInfo->aConstraintUsage[idxPath].argvIndex = 1;
3054
- if( idxDir>=0 ){
3055
- pIdxInfo->aConstraintUsage[idxDir].omit = 1;
3056
- pIdxInfo->aConstraintUsage[idxDir].argvIndex = 2;
3057
- pIdxInfo->idxNum = 2;
3058
- pIdxInfo->estimatedCost = 10.0;
3059
- }else{
3060
- pIdxInfo->idxNum = 1;
3061
- pIdxInfo->estimatedCost = 100.0;
3062
- }
3063
- }
3064
-
3065
- return SQLITE_OK;
3066
-}
3067
-
3068
-/*
3069
-** Register the "fsdir" virtual table.
3070
-*/
3071
-static int fsdirRegister(sqlite3 *db){
3072
- static sqlite3_module fsdirModule = {
3073
- 0, /* iVersion */
3074
- 0, /* xCreate */
3075
- fsdirConnect, /* xConnect */
3076
- fsdirBestIndex, /* xBestIndex */
3077
- fsdirDisconnect, /* xDisconnect */
3078
- 0, /* xDestroy */
3079
- fsdirOpen, /* xOpen - open a cursor */
3080
- fsdirClose, /* xClose - close a cursor */
3081
- fsdirFilter, /* xFilter - configure scan constraints */
3082
- fsdirNext, /* xNext - advance a cursor */
3083
- fsdirEof, /* xEof - check for end of scan */
3084
- fsdirColumn, /* xColumn - read data */
3085
- fsdirRowid, /* xRowid - read data */
3086
- 0, /* xUpdate */
3087
- 0, /* xBegin */
3088
- 0, /* xSync */
3089
- 0, /* xCommit */
3090
- 0, /* xRollback */
3091
- 0, /* xFindMethod */
3092
- 0, /* xRename */
3093
- 0, /* xSavepoint */
3094
- 0, /* xRelease */
3095
- 0, /* xRollbackTo */
3096
- 0, /* xShadowName */
3097
- };
3098
-
3099
- int rc = sqlite3_create_module(db, "fsdir", &fsdirModule, 0);
3100
- return rc;
3101
-}
3102
-#else /* SQLITE_OMIT_VIRTUALTABLE */
3103
-# define fsdirRegister(x) SQLITE_OK
3104
-#endif
3105
-
3106
-#ifdef _WIN32
3107
-
3108
-#endif
3109
-int sqlite3_fileio_init(
3110
- sqlite3 *db,
3111
- char **pzErrMsg,
3112
- const sqlite3_api_routines *pApi
3113
-){
3114
- int rc = SQLITE_OK;
3115
- SQLITE_EXTENSION_INIT2(pApi);
3116
- (void)pzErrMsg; /* Unused parameter */
3117
- rc = sqlite3_create_function(db, "readfile", 1,
3118
- SQLITE_UTF8|SQLITE_DIRECTONLY, 0,
3119
- readfileFunc, 0, 0);
3120
- if( rc==SQLITE_OK ){
3121
- rc = sqlite3_create_function(db, "writefile", -1,
3122
- SQLITE_UTF8|SQLITE_DIRECTONLY, 0,
3123
- writefileFunc, 0, 0);
3124
- }
3125
- if( rc==SQLITE_OK ){
3126
- rc = sqlite3_create_function(db, "lsmode", 1, SQLITE_UTF8, 0,
3127
- lsModeFunc, 0, 0);
3128
- }
3129
- if( rc==SQLITE_OK ){
3130
- rc = fsdirRegister(db);
3131
- }
3132
- return rc;
3133
-}
3134
-
3135
-#if defined(FILEIO_WIN32_DLL) && (defined(_WIN32) || defined(WIN32))
3136
-/* To allow a standalone DLL, make test_windirent.c use the same
3137
- * redefined SQLite API calls as the above extension code does.
3138
- * Just pull in this .c to accomplish this. As a beneficial side
3139
- * effect, this extension becomes a single translation unit. */
3140
-# include "test_windirent.c"
3141
-#endif
3142
-
3143
-/************************* End ../ext/misc/fileio.c ********************/
3144
-/************************* Begin ../ext/misc/completion.c ******************/
3145
-/*
3146
-** 2017-07-10
3147
-**
3148
-** The author disclaims copyright to this source code. In place of
3149
-** a legal notice, here is a blessing:
3150
-**
3151
-** May you do good and not evil.
3152
-** May you find forgiveness for yourself and forgive others.
3153
-** May you share freely, never taking more than you give.
3154
-**
3155
-*************************************************************************
3156
-**
3157
-** This file implements an eponymous virtual table that returns suggested
3158
-** completions for a partial SQL input.
3159
-**
3160
-** Suggested usage:
3161
-**
3162
-** SELECT DISTINCT candidate COLLATE nocase
3163
-** FROM completion($prefix,$wholeline)
3164
-** ORDER BY 1;
3165
-**
3166
-** The two query parameters are optional. $prefix is the text of the
3167
-** current word being typed and that is to be completed. $wholeline is
3168
-** the complete input line, used for context.
3169
-**
3170
-** The raw completion() table might return the same candidate multiple
3171
-** times, for example if the same column name is used to two or more
3172
-** tables. And the candidates are returned in an arbitrary order. Hence,
3173
-** the DISTINCT and ORDER BY are recommended.
3174
-**
3175
-** This virtual table operates at the speed of human typing, and so there
3176
-** is no attempt to make it fast. Even a slow implementation will be much
3177
-** faster than any human can type.
3178
-**
3179
-*/
3180
-/* #include "sqlite3ext.h" */
3181
-SQLITE_EXTENSION_INIT1
3182
-#include <assert.h>
3183
-#include <string.h>
3184
-#include <ctype.h>
3185
-
3186
-#ifndef SQLITE_OMIT_VIRTUALTABLE
3187
-
3188
-/* completion_vtab is a subclass of sqlite3_vtab which will
3189
-** serve as the underlying representation of a completion virtual table
3190
-*/
3191
-typedef struct completion_vtab completion_vtab;
3192
-struct completion_vtab {
3193
- sqlite3_vtab base; /* Base class - must be first */
3194
- sqlite3 *db; /* Database connection for this completion vtab */
3195
-};
3196
-
3197
-/* completion_cursor is a subclass of sqlite3_vtab_cursor which will
3198
-** serve as the underlying representation of a cursor that scans
3199
-** over rows of the result
3200
-*/
3201
-typedef struct completion_cursor completion_cursor;
3202
-struct completion_cursor {
3203
- sqlite3_vtab_cursor base; /* Base class - must be first */
3204
- sqlite3 *db; /* Database connection for this cursor */
3205
- int nPrefix, nLine; /* Number of bytes in zPrefix and zLine */
3206
- char *zPrefix; /* The prefix for the word we want to complete */
3207
- char *zLine; /* The whole that we want to complete */
3208
- const char *zCurrentRow; /* Current output row */
3209
- int szRow; /* Length of the zCurrentRow string */
3210
- sqlite3_stmt *pStmt; /* Current statement */
3211
- sqlite3_int64 iRowid; /* The rowid */
3212
- int ePhase; /* Current phase */
3213
- int j; /* inter-phase counter */
3214
-};
3215
-
3216
-/* Values for ePhase:
3217
-*/
3218
-#define COMPLETION_FIRST_PHASE 1
3219
-#define COMPLETION_KEYWORDS 1
3220
-#define COMPLETION_PRAGMAS 2
3221
-#define COMPLETION_FUNCTIONS 3
3222
-#define COMPLETION_COLLATIONS 4
3223
-#define COMPLETION_INDEXES 5
3224
-#define COMPLETION_TRIGGERS 6
3225
-#define COMPLETION_DATABASES 7
3226
-#define COMPLETION_TABLES 8 /* Also VIEWs and TRIGGERs */
3227
-#define COMPLETION_COLUMNS 9
3228
-#define COMPLETION_MODULES 10
3229
-#define COMPLETION_EOF 11
3230
-
3231
-/*
3232
-** The completionConnect() method is invoked to create a new
3233
-** completion_vtab that describes the completion virtual table.
3234
-**
3235
-** Think of this routine as the constructor for completion_vtab objects.
3236
-**
3237
-** All this routine needs to do is:
3238
-**
3239
-** (1) Allocate the completion_vtab object and initialize all fields.
3240
-**
3241
-** (2) Tell SQLite (via the sqlite3_declare_vtab() interface) what the
3242
-** result set of queries against completion will look like.
3243
-*/
3244
-static int completionConnect(
3245
- sqlite3 *db,
3246
- void *pAux,
3247
- int argc, const char *const*argv,
3248
- sqlite3_vtab **ppVtab,
3249
- char **pzErr
3250
-){
3251
- completion_vtab *pNew;
3252
- int rc;
3253
-
3254
- (void)(pAux); /* Unused parameter */
3255
- (void)(argc); /* Unused parameter */
3256
- (void)(argv); /* Unused parameter */
3257
- (void)(pzErr); /* Unused parameter */
3258
-
3259
-/* Column numbers */
3260
-#define COMPLETION_COLUMN_CANDIDATE 0 /* Suggested completion of the input */
3261
-#define COMPLETION_COLUMN_PREFIX 1 /* Prefix of the word to be completed */
3262
-#define COMPLETION_COLUMN_WHOLELINE 2 /* Entire line seen so far */
3263
-#define COMPLETION_COLUMN_PHASE 3 /* ePhase - used for debugging only */
3264
-
3265
- sqlite3_vtab_config(db, SQLITE_VTAB_INNOCUOUS);
3266
- rc = sqlite3_declare_vtab(db,
3267
- "CREATE TABLE x("
3268
- " candidate TEXT,"
3269
- " prefix TEXT HIDDEN,"
3270
- " wholeline TEXT HIDDEN,"
3271
- " phase INT HIDDEN" /* Used for debugging only */
3272
- ")");
3273
- if( rc==SQLITE_OK ){
3274
- pNew = sqlite3_malloc( sizeof(*pNew) );
3275
- *ppVtab = (sqlite3_vtab*)pNew;
3276
- if( pNew==0 ) return SQLITE_NOMEM;
3277
- memset(pNew, 0, sizeof(*pNew));
3278
- pNew->db = db;
3279
- }
3280
- return rc;
3281
-}
3282
-
3283
-/*
3284
-** This method is the destructor for completion_cursor objects.
3285
-*/
3286
-static int completionDisconnect(sqlite3_vtab *pVtab){
3287
- sqlite3_free(pVtab);
3288
- return SQLITE_OK;
3289
-}
3290
-
3291
-/*
3292
-** Constructor for a new completion_cursor object.
3293
-*/
3294
-static int completionOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
3295
- completion_cursor *pCur;
3296
- pCur = sqlite3_malloc( sizeof(*pCur) );
3297
- if( pCur==0 ) return SQLITE_NOMEM;
3298
- memset(pCur, 0, sizeof(*pCur));
3299
- pCur->db = ((completion_vtab*)p)->db;
3300
- *ppCursor = &pCur->base;
3301
- return SQLITE_OK;
3302
-}
3303
-
3304
-/*
3305
-** Reset the completion_cursor.
3306
-*/
3307
-static void completionCursorReset(completion_cursor *pCur){
3308
- sqlite3_free(pCur->zPrefix); pCur->zPrefix = 0; pCur->nPrefix = 0;
3309
- sqlite3_free(pCur->zLine); pCur->zLine = 0; pCur->nLine = 0;
3310
- sqlite3_finalize(pCur->pStmt); pCur->pStmt = 0;
3311
- pCur->j = 0;
3312
-}
3313
-
3314
-/*
3315
-** Destructor for a completion_cursor.
3316
-*/
3317
-static int completionClose(sqlite3_vtab_cursor *cur){
3318
- completionCursorReset((completion_cursor*)cur);
3319
- sqlite3_free(cur);
3320
- return SQLITE_OK;
3321
-}
3322
-
3323
-/*
3324
-** Advance a completion_cursor to its next row of output.
3325
-**
3326
-** The ->ePhase, ->j, and ->pStmt fields of the completion_cursor object
3327
-** record the current state of the scan. This routine sets ->zCurrentRow
3328
-** to the current row of output and then returns. If no more rows remain,
3329
-** then ->ePhase is set to COMPLETION_EOF which will signal the virtual
3330
-** table that has reached the end of its scan.
3331
-**
3332
-** The current implementation just lists potential identifiers and
3333
-** keywords and filters them by zPrefix. Future enhancements should
3334
-** take zLine into account to try to restrict the set of identifiers and
3335
-** keywords based on what would be legal at the current point of input.
3336
-*/
3337
-static int completionNext(sqlite3_vtab_cursor *cur){
3338
- completion_cursor *pCur = (completion_cursor*)cur;
3339
- int eNextPhase = 0; /* Next phase to try if current phase reaches end */
3340
- int iCol = -1; /* If >=0, step pCur->pStmt and use the i-th column */
3341
- pCur->iRowid++;
3342
- while( pCur->ePhase!=COMPLETION_EOF ){
3343
- switch( pCur->ePhase ){
3344
- case COMPLETION_KEYWORDS: {
3345
- if( pCur->j >= sqlite3_keyword_count() ){
3346
- pCur->zCurrentRow = 0;
3347
- pCur->ePhase = COMPLETION_DATABASES;
3348
- }else{
3349
- sqlite3_keyword_name(pCur->j++, &pCur->zCurrentRow, &pCur->szRow);
3350
- }
3351
- iCol = -1;
3352
- break;
3353
- }
3354
- case COMPLETION_DATABASES: {
3355
- if( pCur->pStmt==0 ){
3356
- sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1,
3357
- &pCur->pStmt, 0);
3358
- }
3359
- iCol = 1;
3360
- eNextPhase = COMPLETION_TABLES;
3361
- break;
3362
- }
3363
- case COMPLETION_TABLES: {
3364
- if( pCur->pStmt==0 ){
3365
- sqlite3_stmt *pS2;
3366
- char *zSql = 0;
3367
- const char *zSep = "";
3368
- sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, &pS2, 0);
3369
- while( sqlite3_step(pS2)==SQLITE_ROW ){
3370
- const char *zDb = (const char*)sqlite3_column_text(pS2, 1);
3371
- zSql = sqlite3_mprintf(
3372
- "%z%s"
3373
- "SELECT name FROM \"%w\".sqlite_schema",
3374
- zSql, zSep, zDb
3375
- );
3376
- if( zSql==0 ) return SQLITE_NOMEM;
3377
- zSep = " UNION ";
3378
- }
3379
- sqlite3_finalize(pS2);
3380
- sqlite3_prepare_v2(pCur->db, zSql, -1, &pCur->pStmt, 0);
3381
- sqlite3_free(zSql);
3382
- }
3383
- iCol = 0;
3384
- eNextPhase = COMPLETION_COLUMNS;
3385
- break;
3386
- }
3387
- case COMPLETION_COLUMNS: {
3388
- if( pCur->pStmt==0 ){
3389
- sqlite3_stmt *pS2;
3390
- char *zSql = 0;
3391
- const char *zSep = "";
3392
- sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, &pS2, 0);
3393
- while( sqlite3_step(pS2)==SQLITE_ROW ){
3394
- const char *zDb = (const char*)sqlite3_column_text(pS2, 1);
3395
- zSql = sqlite3_mprintf(
3396
- "%z%s"
3397
- "SELECT pti.name FROM \"%w\".sqlite_schema AS sm"
3398
- " JOIN pragma_table_info(sm.name,%Q) AS pti"
3399
- " WHERE sm.type='table'",
3400
- zSql, zSep, zDb, zDb
3401
- );
3402
- if( zSql==0 ) return SQLITE_NOMEM;
3403
- zSep = " UNION ";
3404
- }
3405
- sqlite3_finalize(pS2);
3406
- sqlite3_prepare_v2(pCur->db, zSql, -1, &pCur->pStmt, 0);
3407
- sqlite3_free(zSql);
3408
- }
3409
- iCol = 0;
3410
- eNextPhase = COMPLETION_EOF;
3411
- break;
3412
- }
3413
- }
3414
- if( iCol<0 ){
3415
- /* This case is when the phase presets zCurrentRow */
3416
- if( pCur->zCurrentRow==0 ) continue;
3417
- }else{
3418
- if( sqlite3_step(pCur->pStmt)==SQLITE_ROW ){
3419
- /* Extract the next row of content */
3420
- pCur->zCurrentRow = (const char*)sqlite3_column_text(pCur->pStmt, iCol);
3421
- pCur->szRow = sqlite3_column_bytes(pCur->pStmt, iCol);
3422
- }else{
3423
- /* When all rows are finished, advance to the next phase */
3424
- sqlite3_finalize(pCur->pStmt);
3425
- pCur->pStmt = 0;
3426
- pCur->ePhase = eNextPhase;
3427
- continue;
3428
- }
3429
- }
3430
- if( pCur->nPrefix==0 ) break;
3431
- if( pCur->nPrefix<=pCur->szRow
3432
- && sqlite3_strnicmp(pCur->zPrefix, pCur->zCurrentRow, pCur->nPrefix)==0
3433
- ){
3434
- break;
3435
- }
3436
- }
3437
-
3438
- return SQLITE_OK;
3439
-}
3440
-
3441
-/*
3442
-** Return values of columns for the row at which the completion_cursor
3443
-** is currently pointing.
3444
-*/
3445
-static int completionColumn(
3446
- sqlite3_vtab_cursor *cur, /* The cursor */
3447
- sqlite3_context *ctx, /* First argument to sqlite3_result_...() */
3448
- int i /* Which column to return */
3449
-){
3450
- completion_cursor *pCur = (completion_cursor*)cur;
3451
- switch( i ){
3452
- case COMPLETION_COLUMN_CANDIDATE: {
3453
- sqlite3_result_text(ctx, pCur->zCurrentRow, pCur->szRow,SQLITE_TRANSIENT);
3454
- break;
3455
- }
3456
- case COMPLETION_COLUMN_PREFIX: {
3457
- sqlite3_result_text(ctx, pCur->zPrefix, -1, SQLITE_TRANSIENT);
3458
- break;
3459
- }
3460
- case COMPLETION_COLUMN_WHOLELINE: {
3461
- sqlite3_result_text(ctx, pCur->zLine, -1, SQLITE_TRANSIENT);
3462
- break;
3463
- }
3464
- case COMPLETION_COLUMN_PHASE: {
3465
- sqlite3_result_int(ctx, pCur->ePhase);
3466
- break;
3467
- }
3468
- }
3469
- return SQLITE_OK;
3470
-}
3471
-
3472
-/*
3473
-** Return the rowid for the current row. In this implementation, the
3474
-** rowid is the same as the output value.
3475
-*/
3476
-static int completionRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
3477
- completion_cursor *pCur = (completion_cursor*)cur;
3478
- *pRowid = pCur->iRowid;
3479
- return SQLITE_OK;
3480
-}
3481
-
3482
-/*
3483
-** Return TRUE if the cursor has been moved off of the last
3484
-** row of output.
3485
-*/
3486
-static int completionEof(sqlite3_vtab_cursor *cur){
3487
- completion_cursor *pCur = (completion_cursor*)cur;
3488
- return pCur->ePhase >= COMPLETION_EOF;
3489
-}
3490
-
3491
-/*
3492
-** This method is called to "rewind" the completion_cursor object back
3493
-** to the first row of output. This method is always called at least
3494
-** once prior to any call to completionColumn() or completionRowid() or
3495
-** completionEof().
3496
-*/
3497
-static int completionFilter(
3498
- sqlite3_vtab_cursor *pVtabCursor,
3499
- int idxNum, const char *idxStr,
3500
- int argc, sqlite3_value **argv
3501
-){
3502
- completion_cursor *pCur = (completion_cursor *)pVtabCursor;
3503
- int iArg = 0;
3504
- (void)(idxStr); /* Unused parameter */
3505
- (void)(argc); /* Unused parameter */
3506
- completionCursorReset(pCur);
3507
- if( idxNum & 1 ){
3508
- pCur->nPrefix = sqlite3_value_bytes(argv[iArg]);
3509
- if( pCur->nPrefix>0 ){
3510
- pCur->zPrefix = sqlite3_mprintf("%s", sqlite3_value_text(argv[iArg]));
3511
- if( pCur->zPrefix==0 ) return SQLITE_NOMEM;
3512
- }
3513
- iArg = 1;
3514
- }
3515
- if( idxNum & 2 ){
3516
- pCur->nLine = sqlite3_value_bytes(argv[iArg]);
3517
- if( pCur->nLine>0 ){
3518
- pCur->zLine = sqlite3_mprintf("%s", sqlite3_value_text(argv[iArg]));
3519
- if( pCur->zLine==0 ) return SQLITE_NOMEM;
3520
- }
3521
- }
3522
- if( pCur->zLine!=0 && pCur->zPrefix==0 ){
3523
- int i = pCur->nLine;
3524
- while( i>0 && (isalnum(pCur->zLine[i-1]) || pCur->zLine[i-1]=='_') ){
3525
- i--;
3526
- }
3527
- pCur->nPrefix = pCur->nLine - i;
3528
- if( pCur->nPrefix>0 ){
3529
- pCur->zPrefix = sqlite3_mprintf("%.*s", pCur->nPrefix, pCur->zLine + i);
3530
- if( pCur->zPrefix==0 ) return SQLITE_NOMEM;
3531
- }
3532
- }
3533
- pCur->iRowid = 0;
3534
- pCur->ePhase = COMPLETION_FIRST_PHASE;
3535
- return completionNext(pVtabCursor);
3536
-}
3537
-
3538
-/*
3539
-** SQLite will invoke this method one or more times while planning a query
3540
-** that uses the completion virtual table. This routine needs to create
3541
-** a query plan for each invocation and compute an estimated cost for that
3542
-** plan.
3543
-**
3544
-** There are two hidden parameters that act as arguments to the table-valued
3545
-** function: "prefix" and "wholeline". Bit 0 of idxNum is set if "prefix"
3546
-** is available and bit 1 is set if "wholeline" is available.
3547
-*/
3548
-static int completionBestIndex(
3549
- sqlite3_vtab *tab,
3550
- sqlite3_index_info *pIdxInfo
3551
-){
3552
- int i; /* Loop over constraints */
3553
- int idxNum = 0; /* The query plan bitmask */
3554
- int prefixIdx = -1; /* Index of the start= constraint, or -1 if none */
3555
- int wholelineIdx = -1; /* Index of the stop= constraint, or -1 if none */
3556
- int nArg = 0; /* Number of arguments that completeFilter() expects */
3557
- const struct sqlite3_index_constraint *pConstraint;
3558
-
3559
- (void)(tab); /* Unused parameter */
3560
- pConstraint = pIdxInfo->aConstraint;
3561
- for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
3562
- if( pConstraint->usable==0 ) continue;
3563
- if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
3564
- switch( pConstraint->iColumn ){
3565
- case COMPLETION_COLUMN_PREFIX:
3566
- prefixIdx = i;
3567
- idxNum |= 1;
3568
- break;
3569
- case COMPLETION_COLUMN_WHOLELINE:
3570
- wholelineIdx = i;
3571
- idxNum |= 2;
3572
- break;
3573
- }
3574
- }
3575
- if( prefixIdx>=0 ){
3576
- pIdxInfo->aConstraintUsage[prefixIdx].argvIndex = ++nArg;
3577
- pIdxInfo->aConstraintUsage[prefixIdx].omit = 1;
3578
- }
3579
- if( wholelineIdx>=0 ){
3580
- pIdxInfo->aConstraintUsage[wholelineIdx].argvIndex = ++nArg;
3581
- pIdxInfo->aConstraintUsage[wholelineIdx].omit = 1;
3582
- }
3583
- pIdxInfo->idxNum = idxNum;
3584
- pIdxInfo->estimatedCost = (double)5000 - 1000*nArg;
3585
- pIdxInfo->estimatedRows = 500 - 100*nArg;
3586
- return SQLITE_OK;
3587
-}
3588
-
3589
-/*
3590
-** This following structure defines all the methods for the
3591
-** completion virtual table.
3592
-*/
3593
-static sqlite3_module completionModule = {
3594
- 0, /* iVersion */
3595
- 0, /* xCreate */
3596
- completionConnect, /* xConnect */
3597
- completionBestIndex, /* xBestIndex */
3598
- completionDisconnect, /* xDisconnect */
3599
- 0, /* xDestroy */
3600
- completionOpen, /* xOpen - open a cursor */
3601
- completionClose, /* xClose - close a cursor */
3602
- completionFilter, /* xFilter - configure scan constraints */
3603
- completionNext, /* xNext - advance a cursor */
3604
- completionEof, /* xEof - check for end of scan */
3605
- completionColumn, /* xColumn - read data */
3606
- completionRowid, /* xRowid - read data */
3607
- 0, /* xUpdate */
3608
- 0, /* xBegin */
3609
- 0, /* xSync */
3610
- 0, /* xCommit */
3611
- 0, /* xRollback */
3612
- 0, /* xFindMethod */
3613
- 0, /* xRename */
3614
- 0, /* xSavepoint */
3615
- 0, /* xRelease */
3616
- 0, /* xRollbackTo */
3617
- 0 /* xShadowName */
3618
-};
3619
-
3620
-#endif /* SQLITE_OMIT_VIRTUALTABLE */
3621
-
3622
-int sqlite3CompletionVtabInit(sqlite3 *db){
3623
- int rc = SQLITE_OK;
3624
-#ifndef SQLITE_OMIT_VIRTUALTABLE
3625
- rc = sqlite3_create_module(db, "completion", &completionModule, 0);
3626
-#endif
3627
- return rc;
3628
-}
3629
-
3630
-#ifdef _WIN32
3631
-
3632
-#endif
3633
-int sqlite3_completion_init(
3634
- sqlite3 *db,
3635
- char **pzErrMsg,
3636
- const sqlite3_api_routines *pApi
3637
-){
3638
- int rc = SQLITE_OK;
3639
- SQLITE_EXTENSION_INIT2(pApi);
3640
- (void)(pzErrMsg); /* Unused parameter */
3641
-#ifndef SQLITE_OMIT_VIRTUALTABLE
3642
- rc = sqlite3CompletionVtabInit(db);
3643
-#endif
3644
- return rc;
3645
-}
3646
-
3647
-/************************* End ../ext/misc/completion.c ********************/
3648
-/************************* Begin ../ext/misc/appendvfs.c ******************/
3649
-/*
3650
-** 2017-10-20
3651
-**
3652
-** The author disclaims copyright to this source code. In place of
3653
-** a legal notice, here is a blessing:
3654
-**
3655
-** May you do good and not evil.
3656
-** May you find forgiveness for yourself and forgive others.
3657
-** May you share freely, never taking more than you give.
3658
-**
3659
-******************************************************************************
3660
-**
3661
-** This file implements a VFS shim that allows an SQLite database to be
3662
-** appended onto the end of some other file, such as an executable.
3663
-**
3664
-** A special record must appear at the end of the file that identifies the
3665
-** file as an appended database and provides the offset to the first page
3666
-** of the exposed content. (Or, it is the length of the content prefix.)
3667
-** For best performance page 1 should be located at a disk page boundary,
3668
-** though that is not required.
3669
-**
3670
-** When opening a database using this VFS, the connection might treat
3671
-** the file as an ordinary SQLite database, or it might treat it as a
3672
-** database appended onto some other file. The decision is made by
3673
-** applying the following rules in order:
3674
-**
3675
-** (1) An empty file is an ordinary database.
3676
-**
3677
-** (2) If the file ends with the appendvfs trailer string
3678
-** "Start-Of-SQLite3-NNNNNNNN" that file is an appended database.
3679
-**
3680
-** (3) If the file begins with the standard SQLite prefix string
3681
-** "SQLite format 3", that file is an ordinary database.
3682
-**
3683
-** (4) If none of the above apply and the SQLITE_OPEN_CREATE flag is
3684
-** set, then a new database is appended to the already existing file.
3685
-**
3686
-** (5) Otherwise, SQLITE_CANTOPEN is returned.
3687
-**
3688
-** To avoid unnecessary complications with the PENDING_BYTE, the size of
3689
-** the file containing the database is limited to 1GiB. (1073741824 bytes)
3690
-** This VFS will not read or write past the 1GiB mark. This restriction
3691
-** might be lifted in future versions. For now, if you need a larger
3692
-** database, then keep it in a separate file.
3693
-**
3694
-** If the file being opened is a plain database (not an appended one), then
3695
-** this shim is a pass-through into the default underlying VFS. (rule 3)
3696
-**/
3697
-/* #include "sqlite3ext.h" */
3698
-SQLITE_EXTENSION_INIT1
3699
-#include <string.h>
3700
-#include <assert.h>
3701
-
3702
-/* The append mark at the end of the database is:
3703
-**
3704
-** Start-Of-SQLite3-NNNNNNNN
3705
-** 123456789 123456789 12345
3706
-**
3707
-** The NNNNNNNN represents a 64-bit big-endian unsigned integer which is
3708
-** the offset to page 1, and also the length of the prefix content.
3709
-*/
3710
-#define APND_MARK_PREFIX "Start-Of-SQLite3-"
3711
-#define APND_MARK_PREFIX_SZ 17
3712
-#define APND_MARK_FOS_SZ 8
3713
-#define APND_MARK_SIZE (APND_MARK_PREFIX_SZ+APND_MARK_FOS_SZ)
3714
-
3715
-/*
3716
-** Maximum size of the combined prefix + database + append-mark. This
3717
-** must be less than 0x40000000 to avoid locking issues on Windows.
3718
-*/
3719
-#define APND_MAX_SIZE (0x40000000)
3720
-
3721
-/*
3722
-** Try to align the database to an even multiple of APND_ROUNDUP bytes.
3723
-*/
3724
-#ifndef APND_ROUNDUP
3725
-#define APND_ROUNDUP 4096
3726
-#endif
3727
-#define APND_ALIGN_MASK ((sqlite3_int64)(APND_ROUNDUP-1))
3728
-#define APND_START_ROUNDUP(fsz) (((fsz)+APND_ALIGN_MASK) & ~APND_ALIGN_MASK)
3729
-
3730
-/*
3731
-** Forward declaration of objects used by this utility
3732
-*/
3733
-typedef struct sqlite3_vfs ApndVfs;
3734
-typedef struct ApndFile ApndFile;
3735
-
3736
-/* Access to a lower-level VFS that (might) implement dynamic loading,
3737
-** access to randomness, etc.
3738
-*/
3739
-#define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData))
3740
-#define ORIGFILE(p) ((sqlite3_file*)(((ApndFile*)(p))+1))
3741
-
3742
-/* An open appendvfs file
3743
-**
3744
-** An instance of this structure describes the appended database file.
3745
-** A separate sqlite3_file object is always appended. The appended
3746
-** sqlite3_file object (which can be accessed using ORIGFILE()) describes
3747
-** the entire file, including the prefix, the database, and the
3748
-** append-mark.
3749
-**
3750
-** The structure of an AppendVFS database is like this:
3751
-**
3752
-** +-------------+---------+----------+-------------+
3753
-** | prefix-file | padding | database | append-mark |
3754
-** +-------------+---------+----------+-------------+
3755
-** ^ ^
3756
-** | |
3757
-** iPgOne iMark
3758
-**
3759
-**
3760
-** "prefix file" - file onto which the database has been appended.
3761
-** "padding" - zero or more bytes inserted so that "database"
3762
-** starts on an APND_ROUNDUP boundary
3763
-** "database" - The SQLite database file
3764
-** "append-mark" - The 25-byte "Start-Of-SQLite3-NNNNNNNN" that indicates
3765
-** the offset from the start of prefix-file to the start
3766
-** of "database".
3767
-**
3768
-** The size of the database is iMark - iPgOne.
3769
-**
3770
-** The NNNNNNNN in the "Start-Of-SQLite3-NNNNNNNN" suffix is the value
3771
-** of iPgOne stored as a big-ending 64-bit integer.
3772
-**
3773
-** iMark will be the size of the underlying file minus 25 (APND_MARKSIZE).
3774
-** Or, iMark is -1 to indicate that it has not yet been written.
3775
-*/
3776
-struct ApndFile {
3777
- sqlite3_file base; /* Subclass. MUST BE FIRST! */
3778
- sqlite3_int64 iPgOne; /* Offset to the start of the database */
3779
- sqlite3_int64 iMark; /* Offset of the append mark. -1 if unwritten */
3780
- /* Always followed by another sqlite3_file that describes the whole file */
3781
-};
3782
-
3783
-/*
3784
-** Methods for ApndFile
3785
-*/
3786
-static int apndClose(sqlite3_file*);
3787
-static int apndRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
3788
-static int apndWrite(sqlite3_file*,const void*,int iAmt, sqlite3_int64 iOfst);
3789
-static int apndTruncate(sqlite3_file*, sqlite3_int64 size);
3790
-static int apndSync(sqlite3_file*, int flags);
3791
-static int apndFileSize(sqlite3_file*, sqlite3_int64 *pSize);
3792
-static int apndLock(sqlite3_file*, int);
3793
-static int apndUnlock(sqlite3_file*, int);
3794
-static int apndCheckReservedLock(sqlite3_file*, int *pResOut);
3795
-static int apndFileControl(sqlite3_file*, int op, void *pArg);
3796
-static int apndSectorSize(sqlite3_file*);
3797
-static int apndDeviceCharacteristics(sqlite3_file*);
3798
-static int apndShmMap(sqlite3_file*, int iPg, int pgsz, int, void volatile**);
3799
-static int apndShmLock(sqlite3_file*, int offset, int n, int flags);
3800
-static void apndShmBarrier(sqlite3_file*);
3801
-static int apndShmUnmap(sqlite3_file*, int deleteFlag);
3802
-static int apndFetch(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp);
3803
-static int apndUnfetch(sqlite3_file*, sqlite3_int64 iOfst, void *p);
3804
-
3805
-/*
3806
-** Methods for ApndVfs
3807
-*/
3808
-static int apndOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *);
3809
-static int apndDelete(sqlite3_vfs*, const char *zName, int syncDir);
3810
-static int apndAccess(sqlite3_vfs*, const char *zName, int flags, int *);
3811
-static int apndFullPathname(sqlite3_vfs*, const char *zName, int, char *zOut);
3812
-static void *apndDlOpen(sqlite3_vfs*, const char *zFilename);
3813
-static void apndDlError(sqlite3_vfs*, int nByte, char *zErrMsg);
3814
-static void (*apndDlSym(sqlite3_vfs *pVfs, void *p, const char*zSym))(void);
3815
-static void apndDlClose(sqlite3_vfs*, void*);
3816
-static int apndRandomness(sqlite3_vfs*, int nByte, char *zOut);
3817
-static int apndSleep(sqlite3_vfs*, int microseconds);
3818
-static int apndCurrentTime(sqlite3_vfs*, double*);
3819
-static int apndGetLastError(sqlite3_vfs*, int, char *);
3820
-static int apndCurrentTimeInt64(sqlite3_vfs*, sqlite3_int64*);
3821
-static int apndSetSystemCall(sqlite3_vfs*, const char*,sqlite3_syscall_ptr);
3822
-static sqlite3_syscall_ptr apndGetSystemCall(sqlite3_vfs*, const char *z);
3823
-static const char *apndNextSystemCall(sqlite3_vfs*, const char *zName);
3824
-
3825
-static sqlite3_vfs apnd_vfs = {
3826
- 3, /* iVersion (set when registered) */
3827
- 0, /* szOsFile (set when registered) */
3828
- 1024, /* mxPathname */
3829
- 0, /* pNext */
3830
- "apndvfs", /* zName */
3831
- 0, /* pAppData (set when registered) */
3832
- apndOpen, /* xOpen */
3833
- apndDelete, /* xDelete */
3834
- apndAccess, /* xAccess */
3835
- apndFullPathname, /* xFullPathname */
3836
- apndDlOpen, /* xDlOpen */
3837
- apndDlError, /* xDlError */
3838
- apndDlSym, /* xDlSym */
3839
- apndDlClose, /* xDlClose */
3840
- apndRandomness, /* xRandomness */
3841
- apndSleep, /* xSleep */
3842
- apndCurrentTime, /* xCurrentTime */
3843
- apndGetLastError, /* xGetLastError */
3844
- apndCurrentTimeInt64, /* xCurrentTimeInt64 */
3845
- apndSetSystemCall, /* xSetSystemCall */
3846
- apndGetSystemCall, /* xGetSystemCall */
3847
- apndNextSystemCall /* xNextSystemCall */
3848
-};
3849
-
3850
-static const sqlite3_io_methods apnd_io_methods = {
3851
- 3, /* iVersion */
3852
- apndClose, /* xClose */
3853
- apndRead, /* xRead */
3854
- apndWrite, /* xWrite */
3855
- apndTruncate, /* xTruncate */
3856
- apndSync, /* xSync */
3857
- apndFileSize, /* xFileSize */
3858
- apndLock, /* xLock */
3859
- apndUnlock, /* xUnlock */
3860
- apndCheckReservedLock, /* xCheckReservedLock */
3861
- apndFileControl, /* xFileControl */
3862
- apndSectorSize, /* xSectorSize */
3863
- apndDeviceCharacteristics, /* xDeviceCharacteristics */
3864
- apndShmMap, /* xShmMap */
3865
- apndShmLock, /* xShmLock */
3866
- apndShmBarrier, /* xShmBarrier */
3867
- apndShmUnmap, /* xShmUnmap */
3868
- apndFetch, /* xFetch */
3869
- apndUnfetch /* xUnfetch */
3870
-};
3871
-
3872
-/*
3873
-** Close an apnd-file.
3874
-*/
3875
-static int apndClose(sqlite3_file *pFile){
3876
- pFile = ORIGFILE(pFile);
3877
- return pFile->pMethods->xClose(pFile);
3878
-}
3879
-
3880
-/*
3881
-** Read data from an apnd-file.
3882
-*/
3883
-static int apndRead(
3884
- sqlite3_file *pFile,
3885
- void *zBuf,
3886
- int iAmt,
3887
- sqlite_int64 iOfst
3888
-){
3889
- ApndFile *paf = (ApndFile *)pFile;
3890
- pFile = ORIGFILE(pFile);
3891
- return pFile->pMethods->xRead(pFile, zBuf, iAmt, paf->iPgOne+iOfst);
3892
-}
3893
-
3894
-/*
3895
-** Add the append-mark onto what should become the end of the file.
3896
-* If and only if this succeeds, internal ApndFile.iMark is updated.
3897
-* Parameter iWriteEnd is the appendvfs-relative offset of the new mark.
3898
-*/
3899
-static int apndWriteMark(
3900
- ApndFile *paf,
3901
- sqlite3_file *pFile,
3902
- sqlite_int64 iWriteEnd
3903
-){
3904
- sqlite_int64 iPgOne = paf->iPgOne;
3905
- unsigned char a[APND_MARK_SIZE];
3906
- int i = APND_MARK_FOS_SZ;
3907
- int rc;
3908
- assert(pFile == ORIGFILE(paf));
3909
- memcpy(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ);
3910
- while( --i >= 0 ){
3911
- a[APND_MARK_PREFIX_SZ+i] = (unsigned char)(iPgOne & 0xff);
3912
- iPgOne >>= 8;
3913
- }
3914
- iWriteEnd += paf->iPgOne;
3915
- if( SQLITE_OK==(rc = pFile->pMethods->xWrite
3916
- (pFile, a, APND_MARK_SIZE, iWriteEnd)) ){
3917
- paf->iMark = iWriteEnd;
3918
- }
3919
- return rc;
3920
-}
3921
-
3922
-/*
3923
-** Write data to an apnd-file.
3924
-*/
3925
-static int apndWrite(
3926
- sqlite3_file *pFile,
3927
- const void *zBuf,
3928
- int iAmt,
3929
- sqlite_int64 iOfst
3930
-){
3931
- ApndFile *paf = (ApndFile *)pFile;
3932
- sqlite_int64 iWriteEnd = iOfst + iAmt;
3933
- if( iWriteEnd>=APND_MAX_SIZE ) return SQLITE_FULL;
3934
- pFile = ORIGFILE(pFile);
3935
- /* If append-mark is absent or will be overwritten, write it. */
3936
- if( paf->iMark < 0 || paf->iPgOne + iWriteEnd > paf->iMark ){
3937
- int rc = apndWriteMark(paf, pFile, iWriteEnd);
3938
- if( SQLITE_OK!=rc ) return rc;
3939
- }
3940
- return pFile->pMethods->xWrite(pFile, zBuf, iAmt, paf->iPgOne+iOfst);
3941
-}
3942
-
3943
-/*
3944
-** Truncate an apnd-file.
3945
-*/
3946
-static int apndTruncate(sqlite3_file *pFile, sqlite_int64 size){
3947
- ApndFile *paf = (ApndFile *)pFile;
3948
- pFile = ORIGFILE(pFile);
3949
- /* The append mark goes out first so truncate failure does not lose it. */
3950
- if( SQLITE_OK!=apndWriteMark(paf, pFile, size) ) return SQLITE_IOERR;
3951
- /* Truncate underlying file just past append mark */
3952
- return pFile->pMethods->xTruncate(pFile, paf->iMark+APND_MARK_SIZE);
3953
-}
3954
-
3955
-/*
3956
-** Sync an apnd-file.
3957
-*/
3958
-static int apndSync(sqlite3_file *pFile, int flags){
3959
- pFile = ORIGFILE(pFile);
3960
- return pFile->pMethods->xSync(pFile, flags);
3961
-}
3962
-
3963
-/*
3964
-** Return the current file-size of an apnd-file.
3965
-** If the append mark is not yet there, the file-size is 0.
3966
-*/
3967
-static int apndFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
3968
- ApndFile *paf = (ApndFile *)pFile;
3969
- *pSize = ( paf->iMark >= 0 )? (paf->iMark - paf->iPgOne) : 0;
3970
- return SQLITE_OK;
3971
-}
3972
-
3973
-/*
3974
-** Lock an apnd-file.
3975
-*/
3976
-static int apndLock(sqlite3_file *pFile, int eLock){
3977
- pFile = ORIGFILE(pFile);
3978
- return pFile->pMethods->xLock(pFile, eLock);
3979
-}
3980
-
3981
-/*
3982
-** Unlock an apnd-file.
3983
-*/
3984
-static int apndUnlock(sqlite3_file *pFile, int eLock){
3985
- pFile = ORIGFILE(pFile);
3986
- return pFile->pMethods->xUnlock(pFile, eLock);
3987
-}
3988
-
3989
-/*
3990
-** Check if another file-handle holds a RESERVED lock on an apnd-file.
3991
-*/
3992
-static int apndCheckReservedLock(sqlite3_file *pFile, int *pResOut){
3993
- pFile = ORIGFILE(pFile);
3994
- return pFile->pMethods->xCheckReservedLock(pFile, pResOut);
3995
-}
3996
-
3997
-/*
3998
-** File control method. For custom operations on an apnd-file.
3999
-*/
4000
-static int apndFileControl(sqlite3_file *pFile, int op, void *pArg){
4001
- ApndFile *paf = (ApndFile *)pFile;
4002
- int rc;
4003
- pFile = ORIGFILE(pFile);
4004
- if( op==SQLITE_FCNTL_SIZE_HINT ) *(sqlite3_int64*)pArg += paf->iPgOne;
4005
- rc = pFile->pMethods->xFileControl(pFile, op, pArg);
4006
- if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
4007
- *(char**)pArg = sqlite3_mprintf("apnd(%lld)/%z", paf->iPgOne,*(char**)pArg);
4008
- }
4009
- return rc;
4010
-}
4011
-
4012
-/*
4013
-** Return the sector-size in bytes for an apnd-file.
4014
-*/
4015
-static int apndSectorSize(sqlite3_file *pFile){
4016
- pFile = ORIGFILE(pFile);
4017
- return pFile->pMethods->xSectorSize(pFile);
4018
-}
4019
-
4020
-/*
4021
-** Return the device characteristic flags supported by an apnd-file.
4022
-*/
4023
-static int apndDeviceCharacteristics(sqlite3_file *pFile){
4024
- pFile = ORIGFILE(pFile);
4025
- return pFile->pMethods->xDeviceCharacteristics(pFile);
4026
-}
4027
-
4028
-/* Create a shared memory file mapping */
4029
-static int apndShmMap(
4030
- sqlite3_file *pFile,
4031
- int iPg,
4032
- int pgsz,
4033
- int bExtend,
4034
- void volatile **pp
4035
-){
4036
- pFile = ORIGFILE(pFile);
4037
- return pFile->pMethods->xShmMap(pFile,iPg,pgsz,bExtend,pp);
4038
-}
4039
-
4040
-/* Perform locking on a shared-memory segment */
4041
-static int apndShmLock(sqlite3_file *pFile, int offset, int n, int flags){
4042
- pFile = ORIGFILE(pFile);
4043
- return pFile->pMethods->xShmLock(pFile,offset,n,flags);
4044
-}
4045
-
4046
-/* Memory barrier operation on shared memory */
4047
-static void apndShmBarrier(sqlite3_file *pFile){
4048
- pFile = ORIGFILE(pFile);
4049
- pFile->pMethods->xShmBarrier(pFile);
4050
-}
4051
-
4052
-/* Unmap a shared memory segment */
4053
-static int apndShmUnmap(sqlite3_file *pFile, int deleteFlag){
4054
- pFile = ORIGFILE(pFile);
4055
- return pFile->pMethods->xShmUnmap(pFile,deleteFlag);
4056
-}
4057
-
4058
-/* Fetch a page of a memory-mapped file */
4059
-static int apndFetch(
4060
- sqlite3_file *pFile,
4061
- sqlite3_int64 iOfst,
4062
- int iAmt,
4063
- void **pp
4064
-){
4065
- ApndFile *p = (ApndFile *)pFile;
4066
- if( p->iMark < 0 || iOfst+iAmt > p->iMark ){
4067
- return SQLITE_IOERR; /* Cannot read what is not yet there. */
4068
- }
4069
- pFile = ORIGFILE(pFile);
4070
- return pFile->pMethods->xFetch(pFile, iOfst+p->iPgOne, iAmt, pp);
4071
-}
4072
-
4073
-/* Release a memory-mapped page */
4074
-static int apndUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){
4075
- ApndFile *p = (ApndFile *)pFile;
4076
- pFile = ORIGFILE(pFile);
4077
- return pFile->pMethods->xUnfetch(pFile, iOfst+p->iPgOne, pPage);
4078
-}
4079
-
4080
-/*
4081
-** Try to read the append-mark off the end of a file. Return the
4082
-** start of the appended database if the append-mark is present.
4083
-** If there is no valid append-mark, return -1;
4084
-**
4085
-** An append-mark is only valid if the NNNNNNNN start-of-database offset
4086
-** indicates that the appended database contains at least one page. The
4087
-** start-of-database value must be a multiple of 512.
4088
-*/
4089
-static sqlite3_int64 apndReadMark(sqlite3_int64 sz, sqlite3_file *pFile){
4090
- int rc, i;
4091
- sqlite3_int64 iMark;
4092
- int msbs = 8 * (APND_MARK_FOS_SZ-1);
4093
- unsigned char a[APND_MARK_SIZE];
4094
-
4095
- if( APND_MARK_SIZE!=(sz & 0x1ff) ) return -1;
4096
- rc = pFile->pMethods->xRead(pFile, a, APND_MARK_SIZE, sz-APND_MARK_SIZE);
4097
- if( rc ) return -1;
4098
- if( memcmp(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ)!=0 ) return -1;
4099
- iMark = ((sqlite3_int64)(a[APND_MARK_PREFIX_SZ] & 0x7f)) << msbs;
4100
- for(i=1; i<8; i++){
4101
- msbs -= 8;
4102
- iMark |= (sqlite3_int64)a[APND_MARK_PREFIX_SZ+i]<<msbs;
4103
- }
4104
- if( iMark > (sz - APND_MARK_SIZE - 512) ) return -1;
4105
- if( iMark & 0x1ff ) return -1;
4106
- return iMark;
4107
-}
4108
-
4109
-static const char apvfsSqliteHdr[] = "SQLite format 3";
4110
-/*
4111
-** Check to see if the file is an appendvfs SQLite database file.
4112
-** Return true iff it is such. Parameter sz is the file's size.
4113
-*/
4114
-static int apndIsAppendvfsDatabase(sqlite3_int64 sz, sqlite3_file *pFile){
4115
- int rc;
4116
- char zHdr[16];
4117
- sqlite3_int64 iMark = apndReadMark(sz, pFile);
4118
- if( iMark>=0 ){
4119
- /* If file has the correct end-marker, the expected odd size, and the
4120
- ** SQLite DB type marker where the end-marker puts it, then it
4121
- ** is an appendvfs database.
4122
- */
4123
- rc = pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), iMark);
4124
- if( SQLITE_OK==rc
4125
- && memcmp(zHdr, apvfsSqliteHdr, sizeof(zHdr))==0
4126
- && (sz & 0x1ff) == APND_MARK_SIZE
4127
- && sz>=512+APND_MARK_SIZE
4128
- ){
4129
- return 1; /* It's an appendvfs database */
4130
- }
4131
- }
4132
- return 0;
4133
-}
4134
-
4135
-/*
4136
-** Check to see if the file is an ordinary SQLite database file.
4137
-** Return true iff so. Parameter sz is the file's size.
4138
-*/
4139
-static int apndIsOrdinaryDatabaseFile(sqlite3_int64 sz, sqlite3_file *pFile){
4140
- char zHdr[16];
4141
- if( apndIsAppendvfsDatabase(sz, pFile) /* rule 2 */
4142
- || (sz & 0x1ff) != 0
4143
- || SQLITE_OK!=pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), 0)
4144
- || memcmp(zHdr, apvfsSqliteHdr, sizeof(zHdr))!=0
4145
- ){
4146
- return 0;
4147
- }else{
4148
- return 1;
4149
- }
4150
-}
4151
-
4152
-/*
4153
-** Open an apnd file handle.
4154
-*/
4155
-static int apndOpen(
4156
- sqlite3_vfs *pApndVfs,
4157
- const char *zName,
4158
- sqlite3_file *pFile,
4159
- int flags,
4160
- int *pOutFlags
4161
-){
4162
- ApndFile *pApndFile = (ApndFile*)pFile;
4163
- sqlite3_file *pBaseFile = ORIGFILE(pFile);
4164
- sqlite3_vfs *pBaseVfs = ORIGVFS(pApndVfs);
4165
- int rc;
4166
- sqlite3_int64 sz = 0;
4167
- if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
4168
- /* The appendvfs is not to be used for transient or temporary databases.
4169
- ** Just use the base VFS open to initialize the given file object and
4170
- ** open the underlying file. (Appendvfs is then unused for this file.)
4171
- */
4172
- return pBaseVfs->xOpen(pBaseVfs, zName, pFile, flags, pOutFlags);
4173
- }
4174
- memset(pApndFile, 0, sizeof(ApndFile));
4175
- pFile->pMethods = &apnd_io_methods;
4176
- pApndFile->iMark = -1; /* Append mark not yet written */
4177
-
4178
- rc = pBaseVfs->xOpen(pBaseVfs, zName, pBaseFile, flags, pOutFlags);
4179
- if( rc==SQLITE_OK ){
4180
- rc = pBaseFile->pMethods->xFileSize(pBaseFile, &sz);
4181
- if( rc ){
4182
- pBaseFile->pMethods->xClose(pBaseFile);
4183
- }
4184
- }
4185
- if( rc ){
4186
- pFile->pMethods = 0;
4187
- return rc;
4188
- }
4189
- if( apndIsOrdinaryDatabaseFile(sz, pBaseFile) ){
4190
- /* The file being opened appears to be just an ordinary DB. Copy
4191
- ** the base dispatch-table so this instance mimics the base VFS.
4192
- */
4193
- memmove(pApndFile, pBaseFile, pBaseVfs->szOsFile);
4194
- return SQLITE_OK;
4195
- }
4196
- pApndFile->iPgOne = apndReadMark(sz, pFile);
4197
- if( pApndFile->iPgOne>=0 ){
4198
- pApndFile->iMark = sz - APND_MARK_SIZE; /* Append mark found */
4199
- return SQLITE_OK;
4200
- }
4201
- if( (flags & SQLITE_OPEN_CREATE)==0 ){
4202
- pBaseFile->pMethods->xClose(pBaseFile);
4203
- rc = SQLITE_CANTOPEN;
4204
- pFile->pMethods = 0;
4205
- }else{
4206
- /* Round newly added appendvfs location to #define'd page boundary.
4207
- ** Note that nothing has yet been written to the underlying file.
4208
- ** The append mark will be written along with first content write.
4209
- ** Until then, paf->iMark value indicates it is not yet written.
4210
- */
4211
- pApndFile->iPgOne = APND_START_ROUNDUP(sz);
4212
- }
4213
- return rc;
4214
-}
4215
-
4216
-/*
4217
-** Delete an apnd file.
4218
-** For an appendvfs, this could mean delete the appendvfs portion,
4219
-** leaving the appendee as it was before it gained an appendvfs.
4220
-** For now, this code deletes the underlying file too.
4221
-*/
4222
-static int apndDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
4223
- return ORIGVFS(pVfs)->xDelete(ORIGVFS(pVfs), zPath, dirSync);
4224
-}
4225
-
4226
-/*
4227
-** All other VFS methods are pass-thrus.
4228
-*/
4229
-static int apndAccess(
4230
- sqlite3_vfs *pVfs,
4231
- const char *zPath,
4232
- int flags,
4233
- int *pResOut
4234
-){
4235
- return ORIGVFS(pVfs)->xAccess(ORIGVFS(pVfs), zPath, flags, pResOut);
4236
-}
4237
-static int apndFullPathname(
4238
- sqlite3_vfs *pVfs,
4239
- const char *zPath,
4240
- int nOut,
4241
- char *zOut
4242
-){
4243
- return ORIGVFS(pVfs)->xFullPathname(ORIGVFS(pVfs),zPath,nOut,zOut);
4244
-}
4245
-static void *apndDlOpen(sqlite3_vfs *pVfs, const char *zPath){
4246
- return ORIGVFS(pVfs)->xDlOpen(ORIGVFS(pVfs), zPath);
4247
-}
4248
-static void apndDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){
4249
- ORIGVFS(pVfs)->xDlError(ORIGVFS(pVfs), nByte, zErrMsg);
4250
-}
4251
-static void (*apndDlSym(sqlite3_vfs *pVfs, void *p, const char *zSym))(void){
4252
- return ORIGVFS(pVfs)->xDlSym(ORIGVFS(pVfs), p, zSym);
4253
-}
4254
-static void apndDlClose(sqlite3_vfs *pVfs, void *pHandle){
4255
- ORIGVFS(pVfs)->xDlClose(ORIGVFS(pVfs), pHandle);
4256
-}
4257
-static int apndRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
4258
- return ORIGVFS(pVfs)->xRandomness(ORIGVFS(pVfs), nByte, zBufOut);
4259
-}
4260
-static int apndSleep(sqlite3_vfs *pVfs, int nMicro){
4261
- return ORIGVFS(pVfs)->xSleep(ORIGVFS(pVfs), nMicro);
4262
-}
4263
-static int apndCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
4264
- return ORIGVFS(pVfs)->xCurrentTime(ORIGVFS(pVfs), pTimeOut);
4265
-}
4266
-static int apndGetLastError(sqlite3_vfs *pVfs, int a, char *b){
4267
- return ORIGVFS(pVfs)->xGetLastError(ORIGVFS(pVfs), a, b);
4268
-}
4269
-static int apndCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *p){
4270
- return ORIGVFS(pVfs)->xCurrentTimeInt64(ORIGVFS(pVfs), p);
4271
-}
4272
-static int apndSetSystemCall(
4273
- sqlite3_vfs *pVfs,
4274
- const char *zName,
4275
- sqlite3_syscall_ptr pCall
4276
-){
4277
- return ORIGVFS(pVfs)->xSetSystemCall(ORIGVFS(pVfs),zName,pCall);
4278
-}
4279
-static sqlite3_syscall_ptr apndGetSystemCall(
4280
- sqlite3_vfs *pVfs,
4281
- const char *zName
4282
-){
4283
- return ORIGVFS(pVfs)->xGetSystemCall(ORIGVFS(pVfs),zName);
4284
-}
4285
-static const char *apndNextSystemCall(sqlite3_vfs *pVfs, const char *zName){
4286
- return ORIGVFS(pVfs)->xNextSystemCall(ORIGVFS(pVfs), zName);
4287
-}
4288
-
4289
-
4290
-#ifdef _WIN32
4291
-
4292
-#endif
4293
-/*
4294
-** This routine is called when the extension is loaded.
4295
-** Register the new VFS.
4296
-*/
4297
-int sqlite3_appendvfs_init(
4298
- sqlite3 *db,
4299
- char **pzErrMsg,
4300
- const sqlite3_api_routines *pApi
4301
-){
4302
- int rc = SQLITE_OK;
4303
- sqlite3_vfs *pOrig;
4304
- SQLITE_EXTENSION_INIT2(pApi);
4305
- (void)pzErrMsg;
4306
- (void)db;
4307
- pOrig = sqlite3_vfs_find(0);
4308
- if( pOrig==0 ) return SQLITE_ERROR;
4309
- apnd_vfs.iVersion = pOrig->iVersion;
4310
- apnd_vfs.pAppData = pOrig;
4311
- apnd_vfs.szOsFile = pOrig->szOsFile + sizeof(ApndFile);
4312
- rc = sqlite3_vfs_register(&apnd_vfs, 0);
4313
-#ifdef APPENDVFS_TEST
4314
- if( rc==SQLITE_OK ){
4315
- rc = sqlite3_auto_extension((void(*)(void))apndvfsRegister);
4316
- }
4317
-#endif
4318
- if( rc==SQLITE_OK ) rc = SQLITE_OK_LOAD_PERMANENTLY;
4319
- return rc;
4320
-}
4321
-
4322
-/************************* End ../ext/misc/appendvfs.c ********************/
4323
-/************************* Begin ../ext/misc/memtrace.c ******************/
4324
-/*
4325
-** 2019-01-21
4326
-**
4327
-** The author disclaims copyright to this source code. In place of
4328
-** a legal notice, here is a blessing:
4329
-**
4330
-** May you do good and not evil.
4331
-** May you find forgiveness for yourself and forgive others.
4332
-** May you share freely, never taking more than you give.
4333
-**
4334
-*************************************************************************
4335
-**
4336
-** This file implements an extension that uses the SQLITE_CONFIG_MALLOC
4337
-** mechanism to add a tracing layer on top of SQLite. If this extension
4338
-** is registered prior to sqlite3_initialize(), it will cause all memory
4339
-** allocation activities to be logged on standard output, or to some other
4340
-** FILE specified by the initializer.
4341
-**
4342
-** This file needs to be compiled into the application that uses it.
4343
-**
4344
-** This extension is used to implement the --memtrace option of the
4345
-** command-line shell.
4346
-*/
4347
-#include <assert.h>
4348
-#include <string.h>
4349
-#include <stdio.h>
4350
-
4351
-/* The original memory allocation routines */
4352
-static sqlite3_mem_methods memtraceBase;
4353
-static FILE *memtraceOut;
4354
-
4355
-/* Methods that trace memory allocations */
4356
-static void *memtraceMalloc(int n){
4357
- if( memtraceOut ){
4358
- fprintf(memtraceOut, "MEMTRACE: allocate %d bytes\n",
4359
- memtraceBase.xRoundup(n));
4360
- }
4361
- return memtraceBase.xMalloc(n);
4362
-}
4363
-static void memtraceFree(void *p){
4364
- if( p==0 ) return;
4365
- if( memtraceOut ){
4366
- fprintf(memtraceOut, "MEMTRACE: free %d bytes\n", memtraceBase.xSize(p));
4367
- }
4368
- memtraceBase.xFree(p);
4369
-}
4370
-static void *memtraceRealloc(void *p, int n){
4371
- if( p==0 ) return memtraceMalloc(n);
4372
- if( n==0 ){
4373
- memtraceFree(p);
4374
- return 0;
4375
- }
4376
- if( memtraceOut ){
4377
- fprintf(memtraceOut, "MEMTRACE: resize %d -> %d bytes\n",
4378
- memtraceBase.xSize(p), memtraceBase.xRoundup(n));
4379
- }
4380
- return memtraceBase.xRealloc(p, n);
4381
-}
4382
-static int memtraceSize(void *p){
4383
- return memtraceBase.xSize(p);
4384
-}
4385
-static int memtraceRoundup(int n){
4386
- return memtraceBase.xRoundup(n);
4387
-}
4388
-static int memtraceInit(void *p){
4389
- return memtraceBase.xInit(p);
4390
-}
4391
-static void memtraceShutdown(void *p){
4392
- memtraceBase.xShutdown(p);
4393
-}
4394
-
4395
-/* The substitute memory allocator */
4396
-static sqlite3_mem_methods ersaztMethods = {
4397
- memtraceMalloc,
4398
- memtraceFree,
4399
- memtraceRealloc,
4400
- memtraceSize,
4401
- memtraceRoundup,
4402
- memtraceInit,
4403
- memtraceShutdown,
4404
- 0
4405
-};
4406
-
4407
-/* Begin tracing memory allocations to out. */
4408
-int sqlite3MemTraceActivate(FILE *out){
4409
- int rc = SQLITE_OK;
4410
- if( memtraceBase.xMalloc==0 ){
4411
- rc = sqlite3_config(SQLITE_CONFIG_GETMALLOC, &memtraceBase);
4412
- if( rc==SQLITE_OK ){
4413
- rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &ersaztMethods);
4414
- }
4415
- }
4416
- memtraceOut = out;
4417
- return rc;
4418
-}
4419
-
4420
-/* Deactivate memory tracing */
4421
-int sqlite3MemTraceDeactivate(void){
4422
- int rc = SQLITE_OK;
4423
- if( memtraceBase.xMalloc!=0 ){
4424
- rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &memtraceBase);
4425
- if( rc==SQLITE_OK ){
4426
- memset(&memtraceBase, 0, sizeof(memtraceBase));
4427
- }
4428
- }
4429
- memtraceOut = 0;
4430
- return rc;
4431
-}
4432
-
4433
-/************************* End ../ext/misc/memtrace.c ********************/
44342233
/************************* Begin ../ext/misc/uint.c ******************/
44352234
/*
44362235
** 2020-04-14
44372236
**
44382237
** The author disclaims copyright to this source code. In place of
@@ -6696,10 +4495,2224 @@
66964495
}
66974496
return rc;
66984497
}
66994498
67004499
/************************* End ../ext/misc/regexp.c ********************/
4500
+#ifndef SQLITE_SHELL_WASM_MODE
4501
+/************************* Begin ../ext/misc/fileio.c ******************/
4502
+/*
4503
+** 2014-06-13
4504
+**
4505
+** The author disclaims copyright to this source code. In place of
4506
+** a legal notice, here is a blessing:
4507
+**
4508
+** May you do good and not evil.
4509
+** May you find forgiveness for yourself and forgive others.
4510
+** May you share freely, never taking more than you give.
4511
+**
4512
+******************************************************************************
4513
+**
4514
+** This SQLite extension implements SQL functions readfile() and
4515
+** writefile(), and eponymous virtual type "fsdir".
4516
+**
4517
+** WRITEFILE(FILE, DATA [, MODE [, MTIME]]):
4518
+**
4519
+** If neither of the optional arguments is present, then this UDF
4520
+** function writes blob DATA to file FILE. If successful, the number
4521
+** of bytes written is returned. If an error occurs, NULL is returned.
4522
+**
4523
+** If the first option argument - MODE - is present, then it must
4524
+** be passed an integer value that corresponds to a POSIX mode
4525
+** value (file type + permissions, as returned in the stat.st_mode
4526
+** field by the stat() system call). Three types of files may
4527
+** be written/created:
4528
+**
4529
+** regular files: (mode & 0170000)==0100000
4530
+** symbolic links: (mode & 0170000)==0120000
4531
+** directories: (mode & 0170000)==0040000
4532
+**
4533
+** For a directory, the DATA is ignored. For a symbolic link, it is
4534
+** interpreted as text and used as the target of the link. For a
4535
+** regular file, it is interpreted as a blob and written into the
4536
+** named file. Regardless of the type of file, its permissions are
4537
+** set to (mode & 0777) before returning.
4538
+**
4539
+** If the optional MTIME argument is present, then it is interpreted
4540
+** as an integer - the number of seconds since the unix epoch. The
4541
+** modification-time of the target file is set to this value before
4542
+** returning.
4543
+**
4544
+** If three or more arguments are passed to this function and an
4545
+** error is encountered, an exception is raised.
4546
+**
4547
+** READFILE(FILE):
4548
+**
4549
+** Read and return the contents of file FILE (type blob) from disk.
4550
+**
4551
+** FSDIR:
4552
+**
4553
+** Used as follows:
4554
+**
4555
+** SELECT * FROM fsdir($path [, $dir]);
4556
+**
4557
+** Parameter $path is an absolute or relative pathname. If the file that it
4558
+** refers to does not exist, it is an error. If the path refers to a regular
4559
+** file or symbolic link, it returns a single row. Or, if the path refers
4560
+** to a directory, it returns one row for the directory, and one row for each
4561
+** file within the hierarchy rooted at $path.
4562
+**
4563
+** Each row has the following columns:
4564
+**
4565
+** name: Path to file or directory (text value).
4566
+** mode: Value of stat.st_mode for directory entry (an integer).
4567
+** mtime: Value of stat.st_mtime for directory entry (an integer).
4568
+** data: For a regular file, a blob containing the file data. For a
4569
+** symlink, a text value containing the text of the link. For a
4570
+** directory, NULL.
4571
+**
4572
+** If a non-NULL value is specified for the optional $dir parameter and
4573
+** $path is a relative path, then $path is interpreted relative to $dir.
4574
+** And the paths returned in the "name" column of the table are also
4575
+** relative to directory $dir.
4576
+**
4577
+** Notes on building this extension for Windows:
4578
+** Unless linked statically with the SQLite library, a preprocessor
4579
+** symbol, FILEIO_WIN32_DLL, must be #define'd to create a stand-alone
4580
+** DLL form of this extension for WIN32. See its use below for details.
4581
+*/
4582
+/* #include "sqlite3ext.h" */
4583
+SQLITE_EXTENSION_INIT1
4584
+#include <stdio.h>
4585
+#include <string.h>
4586
+#include <assert.h>
4587
+
4588
+#include <sys/types.h>
4589
+#include <sys/stat.h>
4590
+#include <fcntl.h>
4591
+#if !defined(_WIN32) && !defined(WIN32)
4592
+# include <unistd.h>
4593
+# include <dirent.h>
4594
+# include <utime.h>
4595
+# include <sys/time.h>
4596
+#else
4597
+# include "windows.h"
4598
+# include <io.h>
4599
+# include <direct.h>
4600
+/* # include "test_windirent.h" */
4601
+# define dirent DIRENT
4602
+# ifndef chmod
4603
+# define chmod _chmod
4604
+# endif
4605
+# ifndef stat
4606
+# define stat _stat
4607
+# endif
4608
+# define mkdir(path,mode) _mkdir(path)
4609
+# define lstat(path,buf) stat(path,buf)
4610
+#endif
4611
+#include <time.h>
4612
+#include <errno.h>
4613
+
4614
+
4615
+/*
4616
+** Structure of the fsdir() table-valued function
4617
+*/
4618
+ /* 0 1 2 3 4 5 */
4619
+#define FSDIR_SCHEMA "(name,mode,mtime,data,path HIDDEN,dir HIDDEN)"
4620
+#define FSDIR_COLUMN_NAME 0 /* Name of the file */
4621
+#define FSDIR_COLUMN_MODE 1 /* Access mode */
4622
+#define FSDIR_COLUMN_MTIME 2 /* Last modification time */
4623
+#define FSDIR_COLUMN_DATA 3 /* File content */
4624
+#define FSDIR_COLUMN_PATH 4 /* Path to top of search */
4625
+#define FSDIR_COLUMN_DIR 5 /* Path is relative to this directory */
4626
+
4627
+
4628
+/*
4629
+** Set the result stored by context ctx to a blob containing the
4630
+** contents of file zName. Or, leave the result unchanged (NULL)
4631
+** if the file does not exist or is unreadable.
4632
+**
4633
+** If the file exceeds the SQLite blob size limit, through an
4634
+** SQLITE_TOOBIG error.
4635
+**
4636
+** Throw an SQLITE_IOERR if there are difficulties pulling the file
4637
+** off of disk.
4638
+*/
4639
+static void readFileContents(sqlite3_context *ctx, const char *zName){
4640
+ FILE *in;
4641
+ sqlite3_int64 nIn;
4642
+ void *pBuf;
4643
+ sqlite3 *db;
4644
+ int mxBlob;
4645
+
4646
+ in = fopen(zName, "rb");
4647
+ if( in==0 ){
4648
+ /* File does not exist or is unreadable. Leave the result set to NULL. */
4649
+ return;
4650
+ }
4651
+ fseek(in, 0, SEEK_END);
4652
+ nIn = ftell(in);
4653
+ rewind(in);
4654
+ db = sqlite3_context_db_handle(ctx);
4655
+ mxBlob = sqlite3_limit(db, SQLITE_LIMIT_LENGTH, -1);
4656
+ if( nIn>mxBlob ){
4657
+ sqlite3_result_error_code(ctx, SQLITE_TOOBIG);
4658
+ fclose(in);
4659
+ return;
4660
+ }
4661
+ pBuf = sqlite3_malloc64( nIn ? nIn : 1 );
4662
+ if( pBuf==0 ){
4663
+ sqlite3_result_error_nomem(ctx);
4664
+ fclose(in);
4665
+ return;
4666
+ }
4667
+ if( nIn==(sqlite3_int64)fread(pBuf, 1, (size_t)nIn, in) ){
4668
+ sqlite3_result_blob64(ctx, pBuf, nIn, sqlite3_free);
4669
+ }else{
4670
+ sqlite3_result_error_code(ctx, SQLITE_IOERR);
4671
+ sqlite3_free(pBuf);
4672
+ }
4673
+ fclose(in);
4674
+}
4675
+
4676
+/*
4677
+** Implementation of the "readfile(X)" SQL function. The entire content
4678
+** of the file named X is read and returned as a BLOB. NULL is returned
4679
+** if the file does not exist or is unreadable.
4680
+*/
4681
+static void readfileFunc(
4682
+ sqlite3_context *context,
4683
+ int argc,
4684
+ sqlite3_value **argv
4685
+){
4686
+ const char *zName;
4687
+ (void)(argc); /* Unused parameter */
4688
+ zName = (const char*)sqlite3_value_text(argv[0]);
4689
+ if( zName==0 ) return;
4690
+ readFileContents(context, zName);
4691
+}
4692
+
4693
+/*
4694
+** Set the error message contained in context ctx to the results of
4695
+** vprintf(zFmt, ...).
4696
+*/
4697
+static void ctxErrorMsg(sqlite3_context *ctx, const char *zFmt, ...){
4698
+ char *zMsg = 0;
4699
+ va_list ap;
4700
+ va_start(ap, zFmt);
4701
+ zMsg = sqlite3_vmprintf(zFmt, ap);
4702
+ sqlite3_result_error(ctx, zMsg, -1);
4703
+ sqlite3_free(zMsg);
4704
+ va_end(ap);
4705
+}
4706
+
4707
+#if defined(_WIN32)
4708
+/*
4709
+** This function is designed to convert a Win32 FILETIME structure into the
4710
+** number of seconds since the Unix Epoch (1970-01-01 00:00:00 UTC).
4711
+*/
4712
+static sqlite3_uint64 fileTimeToUnixTime(
4713
+ LPFILETIME pFileTime
4714
+){
4715
+ SYSTEMTIME epochSystemTime;
4716
+ ULARGE_INTEGER epochIntervals;
4717
+ FILETIME epochFileTime;
4718
+ ULARGE_INTEGER fileIntervals;
4719
+
4720
+ memset(&epochSystemTime, 0, sizeof(SYSTEMTIME));
4721
+ epochSystemTime.wYear = 1970;
4722
+ epochSystemTime.wMonth = 1;
4723
+ epochSystemTime.wDay = 1;
4724
+ SystemTimeToFileTime(&epochSystemTime, &epochFileTime);
4725
+ epochIntervals.LowPart = epochFileTime.dwLowDateTime;
4726
+ epochIntervals.HighPart = epochFileTime.dwHighDateTime;
4727
+
4728
+ fileIntervals.LowPart = pFileTime->dwLowDateTime;
4729
+ fileIntervals.HighPart = pFileTime->dwHighDateTime;
4730
+
4731
+ return (fileIntervals.QuadPart - epochIntervals.QuadPart) / 10000000;
4732
+}
4733
+
4734
+
4735
+#if defined(FILEIO_WIN32_DLL) && (defined(_WIN32) || defined(WIN32))
4736
+# /* To allow a standalone DLL, use this next replacement function: */
4737
+# undef sqlite3_win32_utf8_to_unicode
4738
+# define sqlite3_win32_utf8_to_unicode utf8_to_utf16
4739
+#
4740
+LPWSTR utf8_to_utf16(const char *z){
4741
+ int nAllot = MultiByteToWideChar(CP_UTF8, 0, z, -1, NULL, 0);
4742
+ LPWSTR rv = sqlite3_malloc(nAllot * sizeof(WCHAR));
4743
+ if( rv!=0 && 0 < MultiByteToWideChar(CP_UTF8, 0, z, -1, rv, nAllot) )
4744
+ return rv;
4745
+ sqlite3_free(rv);
4746
+ return 0;
4747
+}
4748
+#endif
4749
+
4750
+/*
4751
+** This function attempts to normalize the time values found in the stat()
4752
+** buffer to UTC. This is necessary on Win32, where the runtime library
4753
+** appears to return these values as local times.
4754
+*/
4755
+static void statTimesToUtc(
4756
+ const char *zPath,
4757
+ struct stat *pStatBuf
4758
+){
4759
+ HANDLE hFindFile;
4760
+ WIN32_FIND_DATAW fd;
4761
+ LPWSTR zUnicodeName;
4762
+ extern LPWSTR sqlite3_win32_utf8_to_unicode(const char*);
4763
+ zUnicodeName = sqlite3_win32_utf8_to_unicode(zPath);
4764
+ if( zUnicodeName ){
4765
+ memset(&fd, 0, sizeof(WIN32_FIND_DATAW));
4766
+ hFindFile = FindFirstFileW(zUnicodeName, &fd);
4767
+ if( hFindFile!=NULL ){
4768
+ pStatBuf->st_ctime = (time_t)fileTimeToUnixTime(&fd.ftCreationTime);
4769
+ pStatBuf->st_atime = (time_t)fileTimeToUnixTime(&fd.ftLastAccessTime);
4770
+ pStatBuf->st_mtime = (time_t)fileTimeToUnixTime(&fd.ftLastWriteTime);
4771
+ FindClose(hFindFile);
4772
+ }
4773
+ sqlite3_free(zUnicodeName);
4774
+ }
4775
+}
4776
+#endif
4777
+
4778
+/*
4779
+** This function is used in place of stat(). On Windows, special handling
4780
+** is required in order for the included time to be returned as UTC. On all
4781
+** other systems, this function simply calls stat().
4782
+*/
4783
+static int fileStat(
4784
+ const char *zPath,
4785
+ struct stat *pStatBuf
4786
+){
4787
+#if defined(_WIN32)
4788
+ int rc = stat(zPath, pStatBuf);
4789
+ if( rc==0 ) statTimesToUtc(zPath, pStatBuf);
4790
+ return rc;
4791
+#else
4792
+ return stat(zPath, pStatBuf);
4793
+#endif
4794
+}
4795
+
4796
+/*
4797
+** This function is used in place of lstat(). On Windows, special handling
4798
+** is required in order for the included time to be returned as UTC. On all
4799
+** other systems, this function simply calls lstat().
4800
+*/
4801
+static int fileLinkStat(
4802
+ const char *zPath,
4803
+ struct stat *pStatBuf
4804
+){
4805
+#if defined(_WIN32)
4806
+ int rc = lstat(zPath, pStatBuf);
4807
+ if( rc==0 ) statTimesToUtc(zPath, pStatBuf);
4808
+ return rc;
4809
+#else
4810
+ return lstat(zPath, pStatBuf);
4811
+#endif
4812
+}
4813
+
4814
+/*
4815
+** Argument zFile is the name of a file that will be created and/or written
4816
+** by SQL function writefile(). This function ensures that the directory
4817
+** zFile will be written to exists, creating it if required. The permissions
4818
+** for any path components created by this function are set in accordance
4819
+** with the current umask.
4820
+**
4821
+** If an OOM condition is encountered, SQLITE_NOMEM is returned. Otherwise,
4822
+** SQLITE_OK is returned if the directory is successfully created, or
4823
+** SQLITE_ERROR otherwise.
4824
+*/
4825
+static int makeDirectory(
4826
+ const char *zFile
4827
+){
4828
+ char *zCopy = sqlite3_mprintf("%s", zFile);
4829
+ int rc = SQLITE_OK;
4830
+
4831
+ if( zCopy==0 ){
4832
+ rc = SQLITE_NOMEM;
4833
+ }else{
4834
+ int nCopy = (int)strlen(zCopy);
4835
+ int i = 1;
4836
+
4837
+ while( rc==SQLITE_OK ){
4838
+ struct stat sStat;
4839
+ int rc2;
4840
+
4841
+ for(; zCopy[i]!='/' && i<nCopy; i++);
4842
+ if( i==nCopy ) break;
4843
+ zCopy[i] = '\0';
4844
+
4845
+ rc2 = fileStat(zCopy, &sStat);
4846
+ if( rc2!=0 ){
4847
+ if( mkdir(zCopy, 0777) ) rc = SQLITE_ERROR;
4848
+ }else{
4849
+ if( !S_ISDIR(sStat.st_mode) ) rc = SQLITE_ERROR;
4850
+ }
4851
+ zCopy[i] = '/';
4852
+ i++;
4853
+ }
4854
+
4855
+ sqlite3_free(zCopy);
4856
+ }
4857
+
4858
+ return rc;
4859
+}
4860
+
4861
+/*
4862
+** This function does the work for the writefile() UDF. Refer to
4863
+** header comments at the top of this file for details.
4864
+*/
4865
+static int writeFile(
4866
+ sqlite3_context *pCtx, /* Context to return bytes written in */
4867
+ const char *zFile, /* File to write */
4868
+ sqlite3_value *pData, /* Data to write */
4869
+ mode_t mode, /* MODE parameter passed to writefile() */
4870
+ sqlite3_int64 mtime /* MTIME parameter (or -1 to not set time) */
4871
+){
4872
+ if( zFile==0 ) return 1;
4873
+#if !defined(_WIN32) && !defined(WIN32)
4874
+ if( S_ISLNK(mode) ){
4875
+ const char *zTo = (const char*)sqlite3_value_text(pData);
4876
+ if( zTo==0 || symlink(zTo, zFile)<0 ) return 1;
4877
+ }else
4878
+#endif
4879
+ {
4880
+ if( S_ISDIR(mode) ){
4881
+ if( mkdir(zFile, mode) ){
4882
+ /* The mkdir() call to create the directory failed. This might not
4883
+ ** be an error though - if there is already a directory at the same
4884
+ ** path and either the permissions already match or can be changed
4885
+ ** to do so using chmod(), it is not an error. */
4886
+ struct stat sStat;
4887
+ if( errno!=EEXIST
4888
+ || 0!=fileStat(zFile, &sStat)
4889
+ || !S_ISDIR(sStat.st_mode)
4890
+ || ((sStat.st_mode&0777)!=(mode&0777) && 0!=chmod(zFile, mode&0777))
4891
+ ){
4892
+ return 1;
4893
+ }
4894
+ }
4895
+ }else{
4896
+ sqlite3_int64 nWrite = 0;
4897
+ const char *z;
4898
+ int rc = 0;
4899
+ FILE *out = fopen(zFile, "wb");
4900
+ if( out==0 ) return 1;
4901
+ z = (const char*)sqlite3_value_blob(pData);
4902
+ if( z ){
4903
+ sqlite3_int64 n = fwrite(z, 1, sqlite3_value_bytes(pData), out);
4904
+ nWrite = sqlite3_value_bytes(pData);
4905
+ if( nWrite!=n ){
4906
+ rc = 1;
4907
+ }
4908
+ }
4909
+ fclose(out);
4910
+ if( rc==0 && mode && chmod(zFile, mode & 0777) ){
4911
+ rc = 1;
4912
+ }
4913
+ if( rc ) return 2;
4914
+ sqlite3_result_int64(pCtx, nWrite);
4915
+ }
4916
+ }
4917
+
4918
+ if( mtime>=0 ){
4919
+#if defined(_WIN32)
4920
+#if !SQLITE_OS_WINRT
4921
+ /* Windows */
4922
+ FILETIME lastAccess;
4923
+ FILETIME lastWrite;
4924
+ SYSTEMTIME currentTime;
4925
+ LONGLONG intervals;
4926
+ HANDLE hFile;
4927
+ LPWSTR zUnicodeName;
4928
+ extern LPWSTR sqlite3_win32_utf8_to_unicode(const char*);
4929
+
4930
+ GetSystemTime(&currentTime);
4931
+ SystemTimeToFileTime(&currentTime, &lastAccess);
4932
+ intervals = Int32x32To64(mtime, 10000000) + 116444736000000000;
4933
+ lastWrite.dwLowDateTime = (DWORD)intervals;
4934
+ lastWrite.dwHighDateTime = intervals >> 32;
4935
+ zUnicodeName = sqlite3_win32_utf8_to_unicode(zFile);
4936
+ if( zUnicodeName==0 ){
4937
+ return 1;
4938
+ }
4939
+ hFile = CreateFileW(
4940
+ zUnicodeName, FILE_WRITE_ATTRIBUTES, 0, NULL, OPEN_EXISTING,
4941
+ FILE_FLAG_BACKUP_SEMANTICS, NULL
4942
+ );
4943
+ sqlite3_free(zUnicodeName);
4944
+ if( hFile!=INVALID_HANDLE_VALUE ){
4945
+ BOOL bResult = SetFileTime(hFile, NULL, &lastAccess, &lastWrite);
4946
+ CloseHandle(hFile);
4947
+ return !bResult;
4948
+ }else{
4949
+ return 1;
4950
+ }
4951
+#endif
4952
+#elif defined(AT_FDCWD) && 0 /* utimensat() is not universally available */
4953
+ /* Recent unix */
4954
+ struct timespec times[2];
4955
+ times[0].tv_nsec = times[1].tv_nsec = 0;
4956
+ times[0].tv_sec = time(0);
4957
+ times[1].tv_sec = mtime;
4958
+ if( utimensat(AT_FDCWD, zFile, times, AT_SYMLINK_NOFOLLOW) ){
4959
+ return 1;
4960
+ }
4961
+#else
4962
+ /* Legacy unix */
4963
+ struct timeval times[2];
4964
+ times[0].tv_usec = times[1].tv_usec = 0;
4965
+ times[0].tv_sec = time(0);
4966
+ times[1].tv_sec = mtime;
4967
+ if( utimes(zFile, times) ){
4968
+ return 1;
4969
+ }
4970
+#endif
4971
+ }
4972
+
4973
+ return 0;
4974
+}
4975
+
4976
+/*
4977
+** Implementation of the "writefile(W,X[,Y[,Z]]])" SQL function.
4978
+** Refer to header comments at the top of this file for details.
4979
+*/
4980
+static void writefileFunc(
4981
+ sqlite3_context *context,
4982
+ int argc,
4983
+ sqlite3_value **argv
4984
+){
4985
+ const char *zFile;
4986
+ mode_t mode = 0;
4987
+ int res;
4988
+ sqlite3_int64 mtime = -1;
4989
+
4990
+ if( argc<2 || argc>4 ){
4991
+ sqlite3_result_error(context,
4992
+ "wrong number of arguments to function writefile()", -1
4993
+ );
4994
+ return;
4995
+ }
4996
+
4997
+ zFile = (const char*)sqlite3_value_text(argv[0]);
4998
+ if( zFile==0 ) return;
4999
+ if( argc>=3 ){
5000
+ mode = (mode_t)sqlite3_value_int(argv[2]);
5001
+ }
5002
+ if( argc==4 ){
5003
+ mtime = sqlite3_value_int64(argv[3]);
5004
+ }
5005
+
5006
+ res = writeFile(context, zFile, argv[1], mode, mtime);
5007
+ if( res==1 && errno==ENOENT ){
5008
+ if( makeDirectory(zFile)==SQLITE_OK ){
5009
+ res = writeFile(context, zFile, argv[1], mode, mtime);
5010
+ }
5011
+ }
5012
+
5013
+ if( argc>2 && res!=0 ){
5014
+ if( S_ISLNK(mode) ){
5015
+ ctxErrorMsg(context, "failed to create symlink: %s", zFile);
5016
+ }else if( S_ISDIR(mode) ){
5017
+ ctxErrorMsg(context, "failed to create directory: %s", zFile);
5018
+ }else{
5019
+ ctxErrorMsg(context, "failed to write file: %s", zFile);
5020
+ }
5021
+ }
5022
+}
5023
+
5024
+/*
5025
+** SQL function: lsmode(MODE)
5026
+**
5027
+** Given a numberic st_mode from stat(), convert it into a human-readable
5028
+** text string in the style of "ls -l".
5029
+*/
5030
+static void lsModeFunc(
5031
+ sqlite3_context *context,
5032
+ int argc,
5033
+ sqlite3_value **argv
5034
+){
5035
+ int i;
5036
+ int iMode = sqlite3_value_int(argv[0]);
5037
+ char z[16];
5038
+ (void)argc;
5039
+ if( S_ISLNK(iMode) ){
5040
+ z[0] = 'l';
5041
+ }else if( S_ISREG(iMode) ){
5042
+ z[0] = '-';
5043
+ }else if( S_ISDIR(iMode) ){
5044
+ z[0] = 'd';
5045
+ }else{
5046
+ z[0] = '?';
5047
+ }
5048
+ for(i=0; i<3; i++){
5049
+ int m = (iMode >> ((2-i)*3));
5050
+ char *a = &z[1 + i*3];
5051
+ a[0] = (m & 0x4) ? 'r' : '-';
5052
+ a[1] = (m & 0x2) ? 'w' : '-';
5053
+ a[2] = (m & 0x1) ? 'x' : '-';
5054
+ }
5055
+ z[10] = '\0';
5056
+ sqlite3_result_text(context, z, -1, SQLITE_TRANSIENT);
5057
+}
5058
+
5059
+#ifndef SQLITE_OMIT_VIRTUALTABLE
5060
+
5061
+/*
5062
+** Cursor type for recursively iterating through a directory structure.
5063
+*/
5064
+typedef struct fsdir_cursor fsdir_cursor;
5065
+typedef struct FsdirLevel FsdirLevel;
5066
+
5067
+struct FsdirLevel {
5068
+ DIR *pDir; /* From opendir() */
5069
+ char *zDir; /* Name of directory (nul-terminated) */
5070
+};
5071
+
5072
+struct fsdir_cursor {
5073
+ sqlite3_vtab_cursor base; /* Base class - must be first */
5074
+
5075
+ int nLvl; /* Number of entries in aLvl[] array */
5076
+ int iLvl; /* Index of current entry */
5077
+ FsdirLevel *aLvl; /* Hierarchy of directories being traversed */
5078
+
5079
+ const char *zBase;
5080
+ int nBase;
5081
+
5082
+ struct stat sStat; /* Current lstat() results */
5083
+ char *zPath; /* Path to current entry */
5084
+ sqlite3_int64 iRowid; /* Current rowid */
5085
+};
5086
+
5087
+typedef struct fsdir_tab fsdir_tab;
5088
+struct fsdir_tab {
5089
+ sqlite3_vtab base; /* Base class - must be first */
5090
+};
5091
+
5092
+/*
5093
+** Construct a new fsdir virtual table object.
5094
+*/
5095
+static int fsdirConnect(
5096
+ sqlite3 *db,
5097
+ void *pAux,
5098
+ int argc, const char *const*argv,
5099
+ sqlite3_vtab **ppVtab,
5100
+ char **pzErr
5101
+){
5102
+ fsdir_tab *pNew = 0;
5103
+ int rc;
5104
+ (void)pAux;
5105
+ (void)argc;
5106
+ (void)argv;
5107
+ (void)pzErr;
5108
+ rc = sqlite3_declare_vtab(db, "CREATE TABLE x" FSDIR_SCHEMA);
5109
+ if( rc==SQLITE_OK ){
5110
+ pNew = (fsdir_tab*)sqlite3_malloc( sizeof(*pNew) );
5111
+ if( pNew==0 ) return SQLITE_NOMEM;
5112
+ memset(pNew, 0, sizeof(*pNew));
5113
+ sqlite3_vtab_config(db, SQLITE_VTAB_DIRECTONLY);
5114
+ }
5115
+ *ppVtab = (sqlite3_vtab*)pNew;
5116
+ return rc;
5117
+}
5118
+
5119
+/*
5120
+** This method is the destructor for fsdir vtab objects.
5121
+*/
5122
+static int fsdirDisconnect(sqlite3_vtab *pVtab){
5123
+ sqlite3_free(pVtab);
5124
+ return SQLITE_OK;
5125
+}
5126
+
5127
+/*
5128
+** Constructor for a new fsdir_cursor object.
5129
+*/
5130
+static int fsdirOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
5131
+ fsdir_cursor *pCur;
5132
+ (void)p;
5133
+ pCur = sqlite3_malloc( sizeof(*pCur) );
5134
+ if( pCur==0 ) return SQLITE_NOMEM;
5135
+ memset(pCur, 0, sizeof(*pCur));
5136
+ pCur->iLvl = -1;
5137
+ *ppCursor = &pCur->base;
5138
+ return SQLITE_OK;
5139
+}
5140
+
5141
+/*
5142
+** Reset a cursor back to the state it was in when first returned
5143
+** by fsdirOpen().
5144
+*/
5145
+static void fsdirResetCursor(fsdir_cursor *pCur){
5146
+ int i;
5147
+ for(i=0; i<=pCur->iLvl; i++){
5148
+ FsdirLevel *pLvl = &pCur->aLvl[i];
5149
+ if( pLvl->pDir ) closedir(pLvl->pDir);
5150
+ sqlite3_free(pLvl->zDir);
5151
+ }
5152
+ sqlite3_free(pCur->zPath);
5153
+ sqlite3_free(pCur->aLvl);
5154
+ pCur->aLvl = 0;
5155
+ pCur->zPath = 0;
5156
+ pCur->zBase = 0;
5157
+ pCur->nBase = 0;
5158
+ pCur->nLvl = 0;
5159
+ pCur->iLvl = -1;
5160
+ pCur->iRowid = 1;
5161
+}
5162
+
5163
+/*
5164
+** Destructor for an fsdir_cursor.
5165
+*/
5166
+static int fsdirClose(sqlite3_vtab_cursor *cur){
5167
+ fsdir_cursor *pCur = (fsdir_cursor*)cur;
5168
+
5169
+ fsdirResetCursor(pCur);
5170
+ sqlite3_free(pCur);
5171
+ return SQLITE_OK;
5172
+}
5173
+
5174
+/*
5175
+** Set the error message for the virtual table associated with cursor
5176
+** pCur to the results of vprintf(zFmt, ...).
5177
+*/
5178
+static void fsdirSetErrmsg(fsdir_cursor *pCur, const char *zFmt, ...){
5179
+ va_list ap;
5180
+ va_start(ap, zFmt);
5181
+ pCur->base.pVtab->zErrMsg = sqlite3_vmprintf(zFmt, ap);
5182
+ va_end(ap);
5183
+}
5184
+
5185
+
5186
+/*
5187
+** Advance an fsdir_cursor to its next row of output.
5188
+*/
5189
+static int fsdirNext(sqlite3_vtab_cursor *cur){
5190
+ fsdir_cursor *pCur = (fsdir_cursor*)cur;
5191
+ mode_t m = pCur->sStat.st_mode;
5192
+
5193
+ pCur->iRowid++;
5194
+ if( S_ISDIR(m) ){
5195
+ /* Descend into this directory */
5196
+ int iNew = pCur->iLvl + 1;
5197
+ FsdirLevel *pLvl;
5198
+ if( iNew>=pCur->nLvl ){
5199
+ int nNew = iNew+1;
5200
+ sqlite3_int64 nByte = nNew*sizeof(FsdirLevel);
5201
+ FsdirLevel *aNew = (FsdirLevel*)sqlite3_realloc64(pCur->aLvl, nByte);
5202
+ if( aNew==0 ) return SQLITE_NOMEM;
5203
+ memset(&aNew[pCur->nLvl], 0, sizeof(FsdirLevel)*(nNew-pCur->nLvl));
5204
+ pCur->aLvl = aNew;
5205
+ pCur->nLvl = nNew;
5206
+ }
5207
+ pCur->iLvl = iNew;
5208
+ pLvl = &pCur->aLvl[iNew];
5209
+
5210
+ pLvl->zDir = pCur->zPath;
5211
+ pCur->zPath = 0;
5212
+ pLvl->pDir = opendir(pLvl->zDir);
5213
+ if( pLvl->pDir==0 ){
5214
+ fsdirSetErrmsg(pCur, "cannot read directory: %s", pCur->zPath);
5215
+ return SQLITE_ERROR;
5216
+ }
5217
+ }
5218
+
5219
+ while( pCur->iLvl>=0 ){
5220
+ FsdirLevel *pLvl = &pCur->aLvl[pCur->iLvl];
5221
+ struct dirent *pEntry = readdir(pLvl->pDir);
5222
+ if( pEntry ){
5223
+ if( pEntry->d_name[0]=='.' ){
5224
+ if( pEntry->d_name[1]=='.' && pEntry->d_name[2]=='\0' ) continue;
5225
+ if( pEntry->d_name[1]=='\0' ) continue;
5226
+ }
5227
+ sqlite3_free(pCur->zPath);
5228
+ pCur->zPath = sqlite3_mprintf("%s/%s", pLvl->zDir, pEntry->d_name);
5229
+ if( pCur->zPath==0 ) return SQLITE_NOMEM;
5230
+ if( fileLinkStat(pCur->zPath, &pCur->sStat) ){
5231
+ fsdirSetErrmsg(pCur, "cannot stat file: %s", pCur->zPath);
5232
+ return SQLITE_ERROR;
5233
+ }
5234
+ return SQLITE_OK;
5235
+ }
5236
+ closedir(pLvl->pDir);
5237
+ sqlite3_free(pLvl->zDir);
5238
+ pLvl->pDir = 0;
5239
+ pLvl->zDir = 0;
5240
+ pCur->iLvl--;
5241
+ }
5242
+
5243
+ /* EOF */
5244
+ sqlite3_free(pCur->zPath);
5245
+ pCur->zPath = 0;
5246
+ return SQLITE_OK;
5247
+}
5248
+
5249
+/*
5250
+** Return values of columns for the row at which the series_cursor
5251
+** is currently pointing.
5252
+*/
5253
+static int fsdirColumn(
5254
+ sqlite3_vtab_cursor *cur, /* The cursor */
5255
+ sqlite3_context *ctx, /* First argument to sqlite3_result_...() */
5256
+ int i /* Which column to return */
5257
+){
5258
+ fsdir_cursor *pCur = (fsdir_cursor*)cur;
5259
+ switch( i ){
5260
+ case FSDIR_COLUMN_NAME: {
5261
+ sqlite3_result_text(ctx, &pCur->zPath[pCur->nBase], -1, SQLITE_TRANSIENT);
5262
+ break;
5263
+ }
5264
+
5265
+ case FSDIR_COLUMN_MODE:
5266
+ sqlite3_result_int64(ctx, pCur->sStat.st_mode);
5267
+ break;
5268
+
5269
+ case FSDIR_COLUMN_MTIME:
5270
+ sqlite3_result_int64(ctx, pCur->sStat.st_mtime);
5271
+ break;
5272
+
5273
+ case FSDIR_COLUMN_DATA: {
5274
+ mode_t m = pCur->sStat.st_mode;
5275
+ if( S_ISDIR(m) ){
5276
+ sqlite3_result_null(ctx);
5277
+#if !defined(_WIN32) && !defined(WIN32)
5278
+ }else if( S_ISLNK(m) ){
5279
+ char aStatic[64];
5280
+ char *aBuf = aStatic;
5281
+ sqlite3_int64 nBuf = 64;
5282
+ int n;
5283
+
5284
+ while( 1 ){
5285
+ n = readlink(pCur->zPath, aBuf, nBuf);
5286
+ if( n<nBuf ) break;
5287
+ if( aBuf!=aStatic ) sqlite3_free(aBuf);
5288
+ nBuf = nBuf*2;
5289
+ aBuf = sqlite3_malloc64(nBuf);
5290
+ if( aBuf==0 ){
5291
+ sqlite3_result_error_nomem(ctx);
5292
+ return SQLITE_NOMEM;
5293
+ }
5294
+ }
5295
+
5296
+ sqlite3_result_text(ctx, aBuf, n, SQLITE_TRANSIENT);
5297
+ if( aBuf!=aStatic ) sqlite3_free(aBuf);
5298
+#endif
5299
+ }else{
5300
+ readFileContents(ctx, pCur->zPath);
5301
+ }
5302
+ }
5303
+ case FSDIR_COLUMN_PATH:
5304
+ default: {
5305
+ /* The FSDIR_COLUMN_PATH and FSDIR_COLUMN_DIR are input parameters.
5306
+ ** always return their values as NULL */
5307
+ break;
5308
+ }
5309
+ }
5310
+ return SQLITE_OK;
5311
+}
5312
+
5313
+/*
5314
+** Return the rowid for the current row. In this implementation, the
5315
+** first row returned is assigned rowid value 1, and each subsequent
5316
+** row a value 1 more than that of the previous.
5317
+*/
5318
+static int fsdirRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
5319
+ fsdir_cursor *pCur = (fsdir_cursor*)cur;
5320
+ *pRowid = pCur->iRowid;
5321
+ return SQLITE_OK;
5322
+}
5323
+
5324
+/*
5325
+** Return TRUE if the cursor has been moved off of the last
5326
+** row of output.
5327
+*/
5328
+static int fsdirEof(sqlite3_vtab_cursor *cur){
5329
+ fsdir_cursor *pCur = (fsdir_cursor*)cur;
5330
+ return (pCur->zPath==0);
5331
+}
5332
+
5333
+/*
5334
+** xFilter callback.
5335
+**
5336
+** idxNum==1 PATH parameter only
5337
+** idxNum==2 Both PATH and DIR supplied
5338
+*/
5339
+static int fsdirFilter(
5340
+ sqlite3_vtab_cursor *cur,
5341
+ int idxNum, const char *idxStr,
5342
+ int argc, sqlite3_value **argv
5343
+){
5344
+ const char *zDir = 0;
5345
+ fsdir_cursor *pCur = (fsdir_cursor*)cur;
5346
+ (void)idxStr;
5347
+ fsdirResetCursor(pCur);
5348
+
5349
+ if( idxNum==0 ){
5350
+ fsdirSetErrmsg(pCur, "table function fsdir requires an argument");
5351
+ return SQLITE_ERROR;
5352
+ }
5353
+
5354
+ assert( argc==idxNum && (argc==1 || argc==2) );
5355
+ zDir = (const char*)sqlite3_value_text(argv[0]);
5356
+ if( zDir==0 ){
5357
+ fsdirSetErrmsg(pCur, "table function fsdir requires a non-NULL argument");
5358
+ return SQLITE_ERROR;
5359
+ }
5360
+ if( argc==2 ){
5361
+ pCur->zBase = (const char*)sqlite3_value_text(argv[1]);
5362
+ }
5363
+ if( pCur->zBase ){
5364
+ pCur->nBase = (int)strlen(pCur->zBase)+1;
5365
+ pCur->zPath = sqlite3_mprintf("%s/%s", pCur->zBase, zDir);
5366
+ }else{
5367
+ pCur->zPath = sqlite3_mprintf("%s", zDir);
5368
+ }
5369
+
5370
+ if( pCur->zPath==0 ){
5371
+ return SQLITE_NOMEM;
5372
+ }
5373
+ if( fileLinkStat(pCur->zPath, &pCur->sStat) ){
5374
+ fsdirSetErrmsg(pCur, "cannot stat file: %s", pCur->zPath);
5375
+ return SQLITE_ERROR;
5376
+ }
5377
+
5378
+ return SQLITE_OK;
5379
+}
5380
+
5381
+/*
5382
+** SQLite will invoke this method one or more times while planning a query
5383
+** that uses the generate_series virtual table. This routine needs to create
5384
+** a query plan for each invocation and compute an estimated cost for that
5385
+** plan.
5386
+**
5387
+** In this implementation idxNum is used to represent the
5388
+** query plan. idxStr is unused.
5389
+**
5390
+** The query plan is represented by values of idxNum:
5391
+**
5392
+** (1) The path value is supplied by argv[0]
5393
+** (2) Path is in argv[0] and dir is in argv[1]
5394
+*/
5395
+static int fsdirBestIndex(
5396
+ sqlite3_vtab *tab,
5397
+ sqlite3_index_info *pIdxInfo
5398
+){
5399
+ int i; /* Loop over constraints */
5400
+ int idxPath = -1; /* Index in pIdxInfo->aConstraint of PATH= */
5401
+ int idxDir = -1; /* Index in pIdxInfo->aConstraint of DIR= */
5402
+ int seenPath = 0; /* True if an unusable PATH= constraint is seen */
5403
+ int seenDir = 0; /* True if an unusable DIR= constraint is seen */
5404
+ const struct sqlite3_index_constraint *pConstraint;
5405
+
5406
+ (void)tab;
5407
+ pConstraint = pIdxInfo->aConstraint;
5408
+ for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
5409
+ if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
5410
+ switch( pConstraint->iColumn ){
5411
+ case FSDIR_COLUMN_PATH: {
5412
+ if( pConstraint->usable ){
5413
+ idxPath = i;
5414
+ seenPath = 0;
5415
+ }else if( idxPath<0 ){
5416
+ seenPath = 1;
5417
+ }
5418
+ break;
5419
+ }
5420
+ case FSDIR_COLUMN_DIR: {
5421
+ if( pConstraint->usable ){
5422
+ idxDir = i;
5423
+ seenDir = 0;
5424
+ }else if( idxDir<0 ){
5425
+ seenDir = 1;
5426
+ }
5427
+ break;
5428
+ }
5429
+ }
5430
+ }
5431
+ if( seenPath || seenDir ){
5432
+ /* If input parameters are unusable, disallow this plan */
5433
+ return SQLITE_CONSTRAINT;
5434
+ }
5435
+
5436
+ if( idxPath<0 ){
5437
+ pIdxInfo->idxNum = 0;
5438
+ /* The pIdxInfo->estimatedCost should have been initialized to a huge
5439
+ ** number. Leave it unchanged. */
5440
+ pIdxInfo->estimatedRows = 0x7fffffff;
5441
+ }else{
5442
+ pIdxInfo->aConstraintUsage[idxPath].omit = 1;
5443
+ pIdxInfo->aConstraintUsage[idxPath].argvIndex = 1;
5444
+ if( idxDir>=0 ){
5445
+ pIdxInfo->aConstraintUsage[idxDir].omit = 1;
5446
+ pIdxInfo->aConstraintUsage[idxDir].argvIndex = 2;
5447
+ pIdxInfo->idxNum = 2;
5448
+ pIdxInfo->estimatedCost = 10.0;
5449
+ }else{
5450
+ pIdxInfo->idxNum = 1;
5451
+ pIdxInfo->estimatedCost = 100.0;
5452
+ }
5453
+ }
5454
+
5455
+ return SQLITE_OK;
5456
+}
5457
+
5458
+/*
5459
+** Register the "fsdir" virtual table.
5460
+*/
5461
+static int fsdirRegister(sqlite3 *db){
5462
+ static sqlite3_module fsdirModule = {
5463
+ 0, /* iVersion */
5464
+ 0, /* xCreate */
5465
+ fsdirConnect, /* xConnect */
5466
+ fsdirBestIndex, /* xBestIndex */
5467
+ fsdirDisconnect, /* xDisconnect */
5468
+ 0, /* xDestroy */
5469
+ fsdirOpen, /* xOpen - open a cursor */
5470
+ fsdirClose, /* xClose - close a cursor */
5471
+ fsdirFilter, /* xFilter - configure scan constraints */
5472
+ fsdirNext, /* xNext - advance a cursor */
5473
+ fsdirEof, /* xEof - check for end of scan */
5474
+ fsdirColumn, /* xColumn - read data */
5475
+ fsdirRowid, /* xRowid - read data */
5476
+ 0, /* xUpdate */
5477
+ 0, /* xBegin */
5478
+ 0, /* xSync */
5479
+ 0, /* xCommit */
5480
+ 0, /* xRollback */
5481
+ 0, /* xFindMethod */
5482
+ 0, /* xRename */
5483
+ 0, /* xSavepoint */
5484
+ 0, /* xRelease */
5485
+ 0, /* xRollbackTo */
5486
+ 0, /* xShadowName */
5487
+ };
5488
+
5489
+ int rc = sqlite3_create_module(db, "fsdir", &fsdirModule, 0);
5490
+ return rc;
5491
+}
5492
+#else /* SQLITE_OMIT_VIRTUALTABLE */
5493
+# define fsdirRegister(x) SQLITE_OK
5494
+#endif
5495
+
5496
+#ifdef _WIN32
5497
+
5498
+#endif
5499
+int sqlite3_fileio_init(
5500
+ sqlite3 *db,
5501
+ char **pzErrMsg,
5502
+ const sqlite3_api_routines *pApi
5503
+){
5504
+ int rc = SQLITE_OK;
5505
+ SQLITE_EXTENSION_INIT2(pApi);
5506
+ (void)pzErrMsg; /* Unused parameter */
5507
+ rc = sqlite3_create_function(db, "readfile", 1,
5508
+ SQLITE_UTF8|SQLITE_DIRECTONLY, 0,
5509
+ readfileFunc, 0, 0);
5510
+ if( rc==SQLITE_OK ){
5511
+ rc = sqlite3_create_function(db, "writefile", -1,
5512
+ SQLITE_UTF8|SQLITE_DIRECTONLY, 0,
5513
+ writefileFunc, 0, 0);
5514
+ }
5515
+ if( rc==SQLITE_OK ){
5516
+ rc = sqlite3_create_function(db, "lsmode", 1, SQLITE_UTF8, 0,
5517
+ lsModeFunc, 0, 0);
5518
+ }
5519
+ if( rc==SQLITE_OK ){
5520
+ rc = fsdirRegister(db);
5521
+ }
5522
+ return rc;
5523
+}
5524
+
5525
+#if defined(FILEIO_WIN32_DLL) && (defined(_WIN32) || defined(WIN32))
5526
+/* To allow a standalone DLL, make test_windirent.c use the same
5527
+ * redefined SQLite API calls as the above extension code does.
5528
+ * Just pull in this .c to accomplish this. As a beneficial side
5529
+ * effect, this extension becomes a single translation unit. */
5530
+# include "test_windirent.c"
5531
+#endif
5532
+
5533
+/************************* End ../ext/misc/fileio.c ********************/
5534
+/************************* Begin ../ext/misc/completion.c ******************/
5535
+/*
5536
+** 2017-07-10
5537
+**
5538
+** The author disclaims copyright to this source code. In place of
5539
+** a legal notice, here is a blessing:
5540
+**
5541
+** May you do good and not evil.
5542
+** May you find forgiveness for yourself and forgive others.
5543
+** May you share freely, never taking more than you give.
5544
+**
5545
+*************************************************************************
5546
+**
5547
+** This file implements an eponymous virtual table that returns suggested
5548
+** completions for a partial SQL input.
5549
+**
5550
+** Suggested usage:
5551
+**
5552
+** SELECT DISTINCT candidate COLLATE nocase
5553
+** FROM completion($prefix,$wholeline)
5554
+** ORDER BY 1;
5555
+**
5556
+** The two query parameters are optional. $prefix is the text of the
5557
+** current word being typed and that is to be completed. $wholeline is
5558
+** the complete input line, used for context.
5559
+**
5560
+** The raw completion() table might return the same candidate multiple
5561
+** times, for example if the same column name is used to two or more
5562
+** tables. And the candidates are returned in an arbitrary order. Hence,
5563
+** the DISTINCT and ORDER BY are recommended.
5564
+**
5565
+** This virtual table operates at the speed of human typing, and so there
5566
+** is no attempt to make it fast. Even a slow implementation will be much
5567
+** faster than any human can type.
5568
+**
5569
+*/
5570
+/* #include "sqlite3ext.h" */
5571
+SQLITE_EXTENSION_INIT1
5572
+#include <assert.h>
5573
+#include <string.h>
5574
+#include <ctype.h>
5575
+
5576
+#ifndef SQLITE_OMIT_VIRTUALTABLE
5577
+
5578
+/* completion_vtab is a subclass of sqlite3_vtab which will
5579
+** serve as the underlying representation of a completion virtual table
5580
+*/
5581
+typedef struct completion_vtab completion_vtab;
5582
+struct completion_vtab {
5583
+ sqlite3_vtab base; /* Base class - must be first */
5584
+ sqlite3 *db; /* Database connection for this completion vtab */
5585
+};
5586
+
5587
+/* completion_cursor is a subclass of sqlite3_vtab_cursor which will
5588
+** serve as the underlying representation of a cursor that scans
5589
+** over rows of the result
5590
+*/
5591
+typedef struct completion_cursor completion_cursor;
5592
+struct completion_cursor {
5593
+ sqlite3_vtab_cursor base; /* Base class - must be first */
5594
+ sqlite3 *db; /* Database connection for this cursor */
5595
+ int nPrefix, nLine; /* Number of bytes in zPrefix and zLine */
5596
+ char *zPrefix; /* The prefix for the word we want to complete */
5597
+ char *zLine; /* The whole that we want to complete */
5598
+ const char *zCurrentRow; /* Current output row */
5599
+ int szRow; /* Length of the zCurrentRow string */
5600
+ sqlite3_stmt *pStmt; /* Current statement */
5601
+ sqlite3_int64 iRowid; /* The rowid */
5602
+ int ePhase; /* Current phase */
5603
+ int j; /* inter-phase counter */
5604
+};
5605
+
5606
+/* Values for ePhase:
5607
+*/
5608
+#define COMPLETION_FIRST_PHASE 1
5609
+#define COMPLETION_KEYWORDS 1
5610
+#define COMPLETION_PRAGMAS 2
5611
+#define COMPLETION_FUNCTIONS 3
5612
+#define COMPLETION_COLLATIONS 4
5613
+#define COMPLETION_INDEXES 5
5614
+#define COMPLETION_TRIGGERS 6
5615
+#define COMPLETION_DATABASES 7
5616
+#define COMPLETION_TABLES 8 /* Also VIEWs and TRIGGERs */
5617
+#define COMPLETION_COLUMNS 9
5618
+#define COMPLETION_MODULES 10
5619
+#define COMPLETION_EOF 11
5620
+
5621
+/*
5622
+** The completionConnect() method is invoked to create a new
5623
+** completion_vtab that describes the completion virtual table.
5624
+**
5625
+** Think of this routine as the constructor for completion_vtab objects.
5626
+**
5627
+** All this routine needs to do is:
5628
+**
5629
+** (1) Allocate the completion_vtab object and initialize all fields.
5630
+**
5631
+** (2) Tell SQLite (via the sqlite3_declare_vtab() interface) what the
5632
+** result set of queries against completion will look like.
5633
+*/
5634
+static int completionConnect(
5635
+ sqlite3 *db,
5636
+ void *pAux,
5637
+ int argc, const char *const*argv,
5638
+ sqlite3_vtab **ppVtab,
5639
+ char **pzErr
5640
+){
5641
+ completion_vtab *pNew;
5642
+ int rc;
5643
+
5644
+ (void)(pAux); /* Unused parameter */
5645
+ (void)(argc); /* Unused parameter */
5646
+ (void)(argv); /* Unused parameter */
5647
+ (void)(pzErr); /* Unused parameter */
5648
+
5649
+/* Column numbers */
5650
+#define COMPLETION_COLUMN_CANDIDATE 0 /* Suggested completion of the input */
5651
+#define COMPLETION_COLUMN_PREFIX 1 /* Prefix of the word to be completed */
5652
+#define COMPLETION_COLUMN_WHOLELINE 2 /* Entire line seen so far */
5653
+#define COMPLETION_COLUMN_PHASE 3 /* ePhase - used for debugging only */
5654
+
5655
+ sqlite3_vtab_config(db, SQLITE_VTAB_INNOCUOUS);
5656
+ rc = sqlite3_declare_vtab(db,
5657
+ "CREATE TABLE x("
5658
+ " candidate TEXT,"
5659
+ " prefix TEXT HIDDEN,"
5660
+ " wholeline TEXT HIDDEN,"
5661
+ " phase INT HIDDEN" /* Used for debugging only */
5662
+ ")");
5663
+ if( rc==SQLITE_OK ){
5664
+ pNew = sqlite3_malloc( sizeof(*pNew) );
5665
+ *ppVtab = (sqlite3_vtab*)pNew;
5666
+ if( pNew==0 ) return SQLITE_NOMEM;
5667
+ memset(pNew, 0, sizeof(*pNew));
5668
+ pNew->db = db;
5669
+ }
5670
+ return rc;
5671
+}
5672
+
5673
+/*
5674
+** This method is the destructor for completion_cursor objects.
5675
+*/
5676
+static int completionDisconnect(sqlite3_vtab *pVtab){
5677
+ sqlite3_free(pVtab);
5678
+ return SQLITE_OK;
5679
+}
5680
+
5681
+/*
5682
+** Constructor for a new completion_cursor object.
5683
+*/
5684
+static int completionOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
5685
+ completion_cursor *pCur;
5686
+ pCur = sqlite3_malloc( sizeof(*pCur) );
5687
+ if( pCur==0 ) return SQLITE_NOMEM;
5688
+ memset(pCur, 0, sizeof(*pCur));
5689
+ pCur->db = ((completion_vtab*)p)->db;
5690
+ *ppCursor = &pCur->base;
5691
+ return SQLITE_OK;
5692
+}
5693
+
5694
+/*
5695
+** Reset the completion_cursor.
5696
+*/
5697
+static void completionCursorReset(completion_cursor *pCur){
5698
+ sqlite3_free(pCur->zPrefix); pCur->zPrefix = 0; pCur->nPrefix = 0;
5699
+ sqlite3_free(pCur->zLine); pCur->zLine = 0; pCur->nLine = 0;
5700
+ sqlite3_finalize(pCur->pStmt); pCur->pStmt = 0;
5701
+ pCur->j = 0;
5702
+}
5703
+
5704
+/*
5705
+** Destructor for a completion_cursor.
5706
+*/
5707
+static int completionClose(sqlite3_vtab_cursor *cur){
5708
+ completionCursorReset((completion_cursor*)cur);
5709
+ sqlite3_free(cur);
5710
+ return SQLITE_OK;
5711
+}
5712
+
5713
+/*
5714
+** Advance a completion_cursor to its next row of output.
5715
+**
5716
+** The ->ePhase, ->j, and ->pStmt fields of the completion_cursor object
5717
+** record the current state of the scan. This routine sets ->zCurrentRow
5718
+** to the current row of output and then returns. If no more rows remain,
5719
+** then ->ePhase is set to COMPLETION_EOF which will signal the virtual
5720
+** table that has reached the end of its scan.
5721
+**
5722
+** The current implementation just lists potential identifiers and
5723
+** keywords and filters them by zPrefix. Future enhancements should
5724
+** take zLine into account to try to restrict the set of identifiers and
5725
+** keywords based on what would be legal at the current point of input.
5726
+*/
5727
+static int completionNext(sqlite3_vtab_cursor *cur){
5728
+ completion_cursor *pCur = (completion_cursor*)cur;
5729
+ int eNextPhase = 0; /* Next phase to try if current phase reaches end */
5730
+ int iCol = -1; /* If >=0, step pCur->pStmt and use the i-th column */
5731
+ pCur->iRowid++;
5732
+ while( pCur->ePhase!=COMPLETION_EOF ){
5733
+ switch( pCur->ePhase ){
5734
+ case COMPLETION_KEYWORDS: {
5735
+ if( pCur->j >= sqlite3_keyword_count() ){
5736
+ pCur->zCurrentRow = 0;
5737
+ pCur->ePhase = COMPLETION_DATABASES;
5738
+ }else{
5739
+ sqlite3_keyword_name(pCur->j++, &pCur->zCurrentRow, &pCur->szRow);
5740
+ }
5741
+ iCol = -1;
5742
+ break;
5743
+ }
5744
+ case COMPLETION_DATABASES: {
5745
+ if( pCur->pStmt==0 ){
5746
+ sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1,
5747
+ &pCur->pStmt, 0);
5748
+ }
5749
+ iCol = 1;
5750
+ eNextPhase = COMPLETION_TABLES;
5751
+ break;
5752
+ }
5753
+ case COMPLETION_TABLES: {
5754
+ if( pCur->pStmt==0 ){
5755
+ sqlite3_stmt *pS2;
5756
+ char *zSql = 0;
5757
+ const char *zSep = "";
5758
+ sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, &pS2, 0);
5759
+ while( sqlite3_step(pS2)==SQLITE_ROW ){
5760
+ const char *zDb = (const char*)sqlite3_column_text(pS2, 1);
5761
+ zSql = sqlite3_mprintf(
5762
+ "%z%s"
5763
+ "SELECT name FROM \"%w\".sqlite_schema",
5764
+ zSql, zSep, zDb
5765
+ );
5766
+ if( zSql==0 ) return SQLITE_NOMEM;
5767
+ zSep = " UNION ";
5768
+ }
5769
+ sqlite3_finalize(pS2);
5770
+ sqlite3_prepare_v2(pCur->db, zSql, -1, &pCur->pStmt, 0);
5771
+ sqlite3_free(zSql);
5772
+ }
5773
+ iCol = 0;
5774
+ eNextPhase = COMPLETION_COLUMNS;
5775
+ break;
5776
+ }
5777
+ case COMPLETION_COLUMNS: {
5778
+ if( pCur->pStmt==0 ){
5779
+ sqlite3_stmt *pS2;
5780
+ char *zSql = 0;
5781
+ const char *zSep = "";
5782
+ sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, &pS2, 0);
5783
+ while( sqlite3_step(pS2)==SQLITE_ROW ){
5784
+ const char *zDb = (const char*)sqlite3_column_text(pS2, 1);
5785
+ zSql = sqlite3_mprintf(
5786
+ "%z%s"
5787
+ "SELECT pti.name FROM \"%w\".sqlite_schema AS sm"
5788
+ " JOIN pragma_table_info(sm.name,%Q) AS pti"
5789
+ " WHERE sm.type='table'",
5790
+ zSql, zSep, zDb, zDb
5791
+ );
5792
+ if( zSql==0 ) return SQLITE_NOMEM;
5793
+ zSep = " UNION ";
5794
+ }
5795
+ sqlite3_finalize(pS2);
5796
+ sqlite3_prepare_v2(pCur->db, zSql, -1, &pCur->pStmt, 0);
5797
+ sqlite3_free(zSql);
5798
+ }
5799
+ iCol = 0;
5800
+ eNextPhase = COMPLETION_EOF;
5801
+ break;
5802
+ }
5803
+ }
5804
+ if( iCol<0 ){
5805
+ /* This case is when the phase presets zCurrentRow */
5806
+ if( pCur->zCurrentRow==0 ) continue;
5807
+ }else{
5808
+ if( sqlite3_step(pCur->pStmt)==SQLITE_ROW ){
5809
+ /* Extract the next row of content */
5810
+ pCur->zCurrentRow = (const char*)sqlite3_column_text(pCur->pStmt, iCol);
5811
+ pCur->szRow = sqlite3_column_bytes(pCur->pStmt, iCol);
5812
+ }else{
5813
+ /* When all rows are finished, advance to the next phase */
5814
+ sqlite3_finalize(pCur->pStmt);
5815
+ pCur->pStmt = 0;
5816
+ pCur->ePhase = eNextPhase;
5817
+ continue;
5818
+ }
5819
+ }
5820
+ if( pCur->nPrefix==0 ) break;
5821
+ if( pCur->nPrefix<=pCur->szRow
5822
+ && sqlite3_strnicmp(pCur->zPrefix, pCur->zCurrentRow, pCur->nPrefix)==0
5823
+ ){
5824
+ break;
5825
+ }
5826
+ }
5827
+
5828
+ return SQLITE_OK;
5829
+}
5830
+
5831
+/*
5832
+** Return values of columns for the row at which the completion_cursor
5833
+** is currently pointing.
5834
+*/
5835
+static int completionColumn(
5836
+ sqlite3_vtab_cursor *cur, /* The cursor */
5837
+ sqlite3_context *ctx, /* First argument to sqlite3_result_...() */
5838
+ int i /* Which column to return */
5839
+){
5840
+ completion_cursor *pCur = (completion_cursor*)cur;
5841
+ switch( i ){
5842
+ case COMPLETION_COLUMN_CANDIDATE: {
5843
+ sqlite3_result_text(ctx, pCur->zCurrentRow, pCur->szRow,SQLITE_TRANSIENT);
5844
+ break;
5845
+ }
5846
+ case COMPLETION_COLUMN_PREFIX: {
5847
+ sqlite3_result_text(ctx, pCur->zPrefix, -1, SQLITE_TRANSIENT);
5848
+ break;
5849
+ }
5850
+ case COMPLETION_COLUMN_WHOLELINE: {
5851
+ sqlite3_result_text(ctx, pCur->zLine, -1, SQLITE_TRANSIENT);
5852
+ break;
5853
+ }
5854
+ case COMPLETION_COLUMN_PHASE: {
5855
+ sqlite3_result_int(ctx, pCur->ePhase);
5856
+ break;
5857
+ }
5858
+ }
5859
+ return SQLITE_OK;
5860
+}
5861
+
5862
+/*
5863
+** Return the rowid for the current row. In this implementation, the
5864
+** rowid is the same as the output value.
5865
+*/
5866
+static int completionRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
5867
+ completion_cursor *pCur = (completion_cursor*)cur;
5868
+ *pRowid = pCur->iRowid;
5869
+ return SQLITE_OK;
5870
+}
5871
+
5872
+/*
5873
+** Return TRUE if the cursor has been moved off of the last
5874
+** row of output.
5875
+*/
5876
+static int completionEof(sqlite3_vtab_cursor *cur){
5877
+ completion_cursor *pCur = (completion_cursor*)cur;
5878
+ return pCur->ePhase >= COMPLETION_EOF;
5879
+}
5880
+
5881
+/*
5882
+** This method is called to "rewind" the completion_cursor object back
5883
+** to the first row of output. This method is always called at least
5884
+** once prior to any call to completionColumn() or completionRowid() or
5885
+** completionEof().
5886
+*/
5887
+static int completionFilter(
5888
+ sqlite3_vtab_cursor *pVtabCursor,
5889
+ int idxNum, const char *idxStr,
5890
+ int argc, sqlite3_value **argv
5891
+){
5892
+ completion_cursor *pCur = (completion_cursor *)pVtabCursor;
5893
+ int iArg = 0;
5894
+ (void)(idxStr); /* Unused parameter */
5895
+ (void)(argc); /* Unused parameter */
5896
+ completionCursorReset(pCur);
5897
+ if( idxNum & 1 ){
5898
+ pCur->nPrefix = sqlite3_value_bytes(argv[iArg]);
5899
+ if( pCur->nPrefix>0 ){
5900
+ pCur->zPrefix = sqlite3_mprintf("%s", sqlite3_value_text(argv[iArg]));
5901
+ if( pCur->zPrefix==0 ) return SQLITE_NOMEM;
5902
+ }
5903
+ iArg = 1;
5904
+ }
5905
+ if( idxNum & 2 ){
5906
+ pCur->nLine = sqlite3_value_bytes(argv[iArg]);
5907
+ if( pCur->nLine>0 ){
5908
+ pCur->zLine = sqlite3_mprintf("%s", sqlite3_value_text(argv[iArg]));
5909
+ if( pCur->zLine==0 ) return SQLITE_NOMEM;
5910
+ }
5911
+ }
5912
+ if( pCur->zLine!=0 && pCur->zPrefix==0 ){
5913
+ int i = pCur->nLine;
5914
+ while( i>0 && (isalnum(pCur->zLine[i-1]) || pCur->zLine[i-1]=='_') ){
5915
+ i--;
5916
+ }
5917
+ pCur->nPrefix = pCur->nLine - i;
5918
+ if( pCur->nPrefix>0 ){
5919
+ pCur->zPrefix = sqlite3_mprintf("%.*s", pCur->nPrefix, pCur->zLine + i);
5920
+ if( pCur->zPrefix==0 ) return SQLITE_NOMEM;
5921
+ }
5922
+ }
5923
+ pCur->iRowid = 0;
5924
+ pCur->ePhase = COMPLETION_FIRST_PHASE;
5925
+ return completionNext(pVtabCursor);
5926
+}
5927
+
5928
+/*
5929
+** SQLite will invoke this method one or more times while planning a query
5930
+** that uses the completion virtual table. This routine needs to create
5931
+** a query plan for each invocation and compute an estimated cost for that
5932
+** plan.
5933
+**
5934
+** There are two hidden parameters that act as arguments to the table-valued
5935
+** function: "prefix" and "wholeline". Bit 0 of idxNum is set if "prefix"
5936
+** is available and bit 1 is set if "wholeline" is available.
5937
+*/
5938
+static int completionBestIndex(
5939
+ sqlite3_vtab *tab,
5940
+ sqlite3_index_info *pIdxInfo
5941
+){
5942
+ int i; /* Loop over constraints */
5943
+ int idxNum = 0; /* The query plan bitmask */
5944
+ int prefixIdx = -1; /* Index of the start= constraint, or -1 if none */
5945
+ int wholelineIdx = -1; /* Index of the stop= constraint, or -1 if none */
5946
+ int nArg = 0; /* Number of arguments that completeFilter() expects */
5947
+ const struct sqlite3_index_constraint *pConstraint;
5948
+
5949
+ (void)(tab); /* Unused parameter */
5950
+ pConstraint = pIdxInfo->aConstraint;
5951
+ for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
5952
+ if( pConstraint->usable==0 ) continue;
5953
+ if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
5954
+ switch( pConstraint->iColumn ){
5955
+ case COMPLETION_COLUMN_PREFIX:
5956
+ prefixIdx = i;
5957
+ idxNum |= 1;
5958
+ break;
5959
+ case COMPLETION_COLUMN_WHOLELINE:
5960
+ wholelineIdx = i;
5961
+ idxNum |= 2;
5962
+ break;
5963
+ }
5964
+ }
5965
+ if( prefixIdx>=0 ){
5966
+ pIdxInfo->aConstraintUsage[prefixIdx].argvIndex = ++nArg;
5967
+ pIdxInfo->aConstraintUsage[prefixIdx].omit = 1;
5968
+ }
5969
+ if( wholelineIdx>=0 ){
5970
+ pIdxInfo->aConstraintUsage[wholelineIdx].argvIndex = ++nArg;
5971
+ pIdxInfo->aConstraintUsage[wholelineIdx].omit = 1;
5972
+ }
5973
+ pIdxInfo->idxNum = idxNum;
5974
+ pIdxInfo->estimatedCost = (double)5000 - 1000*nArg;
5975
+ pIdxInfo->estimatedRows = 500 - 100*nArg;
5976
+ return SQLITE_OK;
5977
+}
5978
+
5979
+/*
5980
+** This following structure defines all the methods for the
5981
+** completion virtual table.
5982
+*/
5983
+static sqlite3_module completionModule = {
5984
+ 0, /* iVersion */
5985
+ 0, /* xCreate */
5986
+ completionConnect, /* xConnect */
5987
+ completionBestIndex, /* xBestIndex */
5988
+ completionDisconnect, /* xDisconnect */
5989
+ 0, /* xDestroy */
5990
+ completionOpen, /* xOpen - open a cursor */
5991
+ completionClose, /* xClose - close a cursor */
5992
+ completionFilter, /* xFilter - configure scan constraints */
5993
+ completionNext, /* xNext - advance a cursor */
5994
+ completionEof, /* xEof - check for end of scan */
5995
+ completionColumn, /* xColumn - read data */
5996
+ completionRowid, /* xRowid - read data */
5997
+ 0, /* xUpdate */
5998
+ 0, /* xBegin */
5999
+ 0, /* xSync */
6000
+ 0, /* xCommit */
6001
+ 0, /* xRollback */
6002
+ 0, /* xFindMethod */
6003
+ 0, /* xRename */
6004
+ 0, /* xSavepoint */
6005
+ 0, /* xRelease */
6006
+ 0, /* xRollbackTo */
6007
+ 0 /* xShadowName */
6008
+};
6009
+
6010
+#endif /* SQLITE_OMIT_VIRTUALTABLE */
6011
+
6012
+int sqlite3CompletionVtabInit(sqlite3 *db){
6013
+ int rc = SQLITE_OK;
6014
+#ifndef SQLITE_OMIT_VIRTUALTABLE
6015
+ rc = sqlite3_create_module(db, "completion", &completionModule, 0);
6016
+#endif
6017
+ return rc;
6018
+}
6019
+
6020
+#ifdef _WIN32
6021
+
6022
+#endif
6023
+int sqlite3_completion_init(
6024
+ sqlite3 *db,
6025
+ char **pzErrMsg,
6026
+ const sqlite3_api_routines *pApi
6027
+){
6028
+ int rc = SQLITE_OK;
6029
+ SQLITE_EXTENSION_INIT2(pApi);
6030
+ (void)(pzErrMsg); /* Unused parameter */
6031
+#ifndef SQLITE_OMIT_VIRTUALTABLE
6032
+ rc = sqlite3CompletionVtabInit(db);
6033
+#endif
6034
+ return rc;
6035
+}
6036
+
6037
+/************************* End ../ext/misc/completion.c ********************/
6038
+/************************* Begin ../ext/misc/appendvfs.c ******************/
6039
+/*
6040
+** 2017-10-20
6041
+**
6042
+** The author disclaims copyright to this source code. In place of
6043
+** a legal notice, here is a blessing:
6044
+**
6045
+** May you do good and not evil.
6046
+** May you find forgiveness for yourself and forgive others.
6047
+** May you share freely, never taking more than you give.
6048
+**
6049
+******************************************************************************
6050
+**
6051
+** This file implements a VFS shim that allows an SQLite database to be
6052
+** appended onto the end of some other file, such as an executable.
6053
+**
6054
+** A special record must appear at the end of the file that identifies the
6055
+** file as an appended database and provides the offset to the first page
6056
+** of the exposed content. (Or, it is the length of the content prefix.)
6057
+** For best performance page 1 should be located at a disk page boundary,
6058
+** though that is not required.
6059
+**
6060
+** When opening a database using this VFS, the connection might treat
6061
+** the file as an ordinary SQLite database, or it might treat it as a
6062
+** database appended onto some other file. The decision is made by
6063
+** applying the following rules in order:
6064
+**
6065
+** (1) An empty file is an ordinary database.
6066
+**
6067
+** (2) If the file ends with the appendvfs trailer string
6068
+** "Start-Of-SQLite3-NNNNNNNN" that file is an appended database.
6069
+**
6070
+** (3) If the file begins with the standard SQLite prefix string
6071
+** "SQLite format 3", that file is an ordinary database.
6072
+**
6073
+** (4) If none of the above apply and the SQLITE_OPEN_CREATE flag is
6074
+** set, then a new database is appended to the already existing file.
6075
+**
6076
+** (5) Otherwise, SQLITE_CANTOPEN is returned.
6077
+**
6078
+** To avoid unnecessary complications with the PENDING_BYTE, the size of
6079
+** the file containing the database is limited to 1GiB. (1073741824 bytes)
6080
+** This VFS will not read or write past the 1GiB mark. This restriction
6081
+** might be lifted in future versions. For now, if you need a larger
6082
+** database, then keep it in a separate file.
6083
+**
6084
+** If the file being opened is a plain database (not an appended one), then
6085
+** this shim is a pass-through into the default underlying VFS. (rule 3)
6086
+**/
6087
+/* #include "sqlite3ext.h" */
6088
+SQLITE_EXTENSION_INIT1
6089
+#include <string.h>
6090
+#include <assert.h>
6091
+
6092
+/* The append mark at the end of the database is:
6093
+**
6094
+** Start-Of-SQLite3-NNNNNNNN
6095
+** 123456789 123456789 12345
6096
+**
6097
+** The NNNNNNNN represents a 64-bit big-endian unsigned integer which is
6098
+** the offset to page 1, and also the length of the prefix content.
6099
+*/
6100
+#define APND_MARK_PREFIX "Start-Of-SQLite3-"
6101
+#define APND_MARK_PREFIX_SZ 17
6102
+#define APND_MARK_FOS_SZ 8
6103
+#define APND_MARK_SIZE (APND_MARK_PREFIX_SZ+APND_MARK_FOS_SZ)
6104
+
6105
+/*
6106
+** Maximum size of the combined prefix + database + append-mark. This
6107
+** must be less than 0x40000000 to avoid locking issues on Windows.
6108
+*/
6109
+#define APND_MAX_SIZE (0x40000000)
6110
+
6111
+/*
6112
+** Try to align the database to an even multiple of APND_ROUNDUP bytes.
6113
+*/
6114
+#ifndef APND_ROUNDUP
6115
+#define APND_ROUNDUP 4096
6116
+#endif
6117
+#define APND_ALIGN_MASK ((sqlite3_int64)(APND_ROUNDUP-1))
6118
+#define APND_START_ROUNDUP(fsz) (((fsz)+APND_ALIGN_MASK) & ~APND_ALIGN_MASK)
6119
+
6120
+/*
6121
+** Forward declaration of objects used by this utility
6122
+*/
6123
+typedef struct sqlite3_vfs ApndVfs;
6124
+typedef struct ApndFile ApndFile;
6125
+
6126
+/* Access to a lower-level VFS that (might) implement dynamic loading,
6127
+** access to randomness, etc.
6128
+*/
6129
+#define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData))
6130
+#define ORIGFILE(p) ((sqlite3_file*)(((ApndFile*)(p))+1))
6131
+
6132
+/* An open appendvfs file
6133
+**
6134
+** An instance of this structure describes the appended database file.
6135
+** A separate sqlite3_file object is always appended. The appended
6136
+** sqlite3_file object (which can be accessed using ORIGFILE()) describes
6137
+** the entire file, including the prefix, the database, and the
6138
+** append-mark.
6139
+**
6140
+** The structure of an AppendVFS database is like this:
6141
+**
6142
+** +-------------+---------+----------+-------------+
6143
+** | prefix-file | padding | database | append-mark |
6144
+** +-------------+---------+----------+-------------+
6145
+** ^ ^
6146
+** | |
6147
+** iPgOne iMark
6148
+**
6149
+**
6150
+** "prefix file" - file onto which the database has been appended.
6151
+** "padding" - zero or more bytes inserted so that "database"
6152
+** starts on an APND_ROUNDUP boundary
6153
+** "database" - The SQLite database file
6154
+** "append-mark" - The 25-byte "Start-Of-SQLite3-NNNNNNNN" that indicates
6155
+** the offset from the start of prefix-file to the start
6156
+** of "database".
6157
+**
6158
+** The size of the database is iMark - iPgOne.
6159
+**
6160
+** The NNNNNNNN in the "Start-Of-SQLite3-NNNNNNNN" suffix is the value
6161
+** of iPgOne stored as a big-ending 64-bit integer.
6162
+**
6163
+** iMark will be the size of the underlying file minus 25 (APND_MARKSIZE).
6164
+** Or, iMark is -1 to indicate that it has not yet been written.
6165
+*/
6166
+struct ApndFile {
6167
+ sqlite3_file base; /* Subclass. MUST BE FIRST! */
6168
+ sqlite3_int64 iPgOne; /* Offset to the start of the database */
6169
+ sqlite3_int64 iMark; /* Offset of the append mark. -1 if unwritten */
6170
+ /* Always followed by another sqlite3_file that describes the whole file */
6171
+};
6172
+
6173
+/*
6174
+** Methods for ApndFile
6175
+*/
6176
+static int apndClose(sqlite3_file*);
6177
+static int apndRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
6178
+static int apndWrite(sqlite3_file*,const void*,int iAmt, sqlite3_int64 iOfst);
6179
+static int apndTruncate(sqlite3_file*, sqlite3_int64 size);
6180
+static int apndSync(sqlite3_file*, int flags);
6181
+static int apndFileSize(sqlite3_file*, sqlite3_int64 *pSize);
6182
+static int apndLock(sqlite3_file*, int);
6183
+static int apndUnlock(sqlite3_file*, int);
6184
+static int apndCheckReservedLock(sqlite3_file*, int *pResOut);
6185
+static int apndFileControl(sqlite3_file*, int op, void *pArg);
6186
+static int apndSectorSize(sqlite3_file*);
6187
+static int apndDeviceCharacteristics(sqlite3_file*);
6188
+static int apndShmMap(sqlite3_file*, int iPg, int pgsz, int, void volatile**);
6189
+static int apndShmLock(sqlite3_file*, int offset, int n, int flags);
6190
+static void apndShmBarrier(sqlite3_file*);
6191
+static int apndShmUnmap(sqlite3_file*, int deleteFlag);
6192
+static int apndFetch(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp);
6193
+static int apndUnfetch(sqlite3_file*, sqlite3_int64 iOfst, void *p);
6194
+
6195
+/*
6196
+** Methods for ApndVfs
6197
+*/
6198
+static int apndOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *);
6199
+static int apndDelete(sqlite3_vfs*, const char *zName, int syncDir);
6200
+static int apndAccess(sqlite3_vfs*, const char *zName, int flags, int *);
6201
+static int apndFullPathname(sqlite3_vfs*, const char *zName, int, char *zOut);
6202
+static void *apndDlOpen(sqlite3_vfs*, const char *zFilename);
6203
+static void apndDlError(sqlite3_vfs*, int nByte, char *zErrMsg);
6204
+static void (*apndDlSym(sqlite3_vfs *pVfs, void *p, const char*zSym))(void);
6205
+static void apndDlClose(sqlite3_vfs*, void*);
6206
+static int apndRandomness(sqlite3_vfs*, int nByte, char *zOut);
6207
+static int apndSleep(sqlite3_vfs*, int microseconds);
6208
+static int apndCurrentTime(sqlite3_vfs*, double*);
6209
+static int apndGetLastError(sqlite3_vfs*, int, char *);
6210
+static int apndCurrentTimeInt64(sqlite3_vfs*, sqlite3_int64*);
6211
+static int apndSetSystemCall(sqlite3_vfs*, const char*,sqlite3_syscall_ptr);
6212
+static sqlite3_syscall_ptr apndGetSystemCall(sqlite3_vfs*, const char *z);
6213
+static const char *apndNextSystemCall(sqlite3_vfs*, const char *zName);
6214
+
6215
+static sqlite3_vfs apnd_vfs = {
6216
+ 3, /* iVersion (set when registered) */
6217
+ 0, /* szOsFile (set when registered) */
6218
+ 1024, /* mxPathname */
6219
+ 0, /* pNext */
6220
+ "apndvfs", /* zName */
6221
+ 0, /* pAppData (set when registered) */
6222
+ apndOpen, /* xOpen */
6223
+ apndDelete, /* xDelete */
6224
+ apndAccess, /* xAccess */
6225
+ apndFullPathname, /* xFullPathname */
6226
+ apndDlOpen, /* xDlOpen */
6227
+ apndDlError, /* xDlError */
6228
+ apndDlSym, /* xDlSym */
6229
+ apndDlClose, /* xDlClose */
6230
+ apndRandomness, /* xRandomness */
6231
+ apndSleep, /* xSleep */
6232
+ apndCurrentTime, /* xCurrentTime */
6233
+ apndGetLastError, /* xGetLastError */
6234
+ apndCurrentTimeInt64, /* xCurrentTimeInt64 */
6235
+ apndSetSystemCall, /* xSetSystemCall */
6236
+ apndGetSystemCall, /* xGetSystemCall */
6237
+ apndNextSystemCall /* xNextSystemCall */
6238
+};
6239
+
6240
+static const sqlite3_io_methods apnd_io_methods = {
6241
+ 3, /* iVersion */
6242
+ apndClose, /* xClose */
6243
+ apndRead, /* xRead */
6244
+ apndWrite, /* xWrite */
6245
+ apndTruncate, /* xTruncate */
6246
+ apndSync, /* xSync */
6247
+ apndFileSize, /* xFileSize */
6248
+ apndLock, /* xLock */
6249
+ apndUnlock, /* xUnlock */
6250
+ apndCheckReservedLock, /* xCheckReservedLock */
6251
+ apndFileControl, /* xFileControl */
6252
+ apndSectorSize, /* xSectorSize */
6253
+ apndDeviceCharacteristics, /* xDeviceCharacteristics */
6254
+ apndShmMap, /* xShmMap */
6255
+ apndShmLock, /* xShmLock */
6256
+ apndShmBarrier, /* xShmBarrier */
6257
+ apndShmUnmap, /* xShmUnmap */
6258
+ apndFetch, /* xFetch */
6259
+ apndUnfetch /* xUnfetch */
6260
+};
6261
+
6262
+/*
6263
+** Close an apnd-file.
6264
+*/
6265
+static int apndClose(sqlite3_file *pFile){
6266
+ pFile = ORIGFILE(pFile);
6267
+ return pFile->pMethods->xClose(pFile);
6268
+}
6269
+
6270
+/*
6271
+** Read data from an apnd-file.
6272
+*/
6273
+static int apndRead(
6274
+ sqlite3_file *pFile,
6275
+ void *zBuf,
6276
+ int iAmt,
6277
+ sqlite_int64 iOfst
6278
+){
6279
+ ApndFile *paf = (ApndFile *)pFile;
6280
+ pFile = ORIGFILE(pFile);
6281
+ return pFile->pMethods->xRead(pFile, zBuf, iAmt, paf->iPgOne+iOfst);
6282
+}
6283
+
6284
+/*
6285
+** Add the append-mark onto what should become the end of the file.
6286
+* If and only if this succeeds, internal ApndFile.iMark is updated.
6287
+* Parameter iWriteEnd is the appendvfs-relative offset of the new mark.
6288
+*/
6289
+static int apndWriteMark(
6290
+ ApndFile *paf,
6291
+ sqlite3_file *pFile,
6292
+ sqlite_int64 iWriteEnd
6293
+){
6294
+ sqlite_int64 iPgOne = paf->iPgOne;
6295
+ unsigned char a[APND_MARK_SIZE];
6296
+ int i = APND_MARK_FOS_SZ;
6297
+ int rc;
6298
+ assert(pFile == ORIGFILE(paf));
6299
+ memcpy(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ);
6300
+ while( --i >= 0 ){
6301
+ a[APND_MARK_PREFIX_SZ+i] = (unsigned char)(iPgOne & 0xff);
6302
+ iPgOne >>= 8;
6303
+ }
6304
+ iWriteEnd += paf->iPgOne;
6305
+ if( SQLITE_OK==(rc = pFile->pMethods->xWrite
6306
+ (pFile, a, APND_MARK_SIZE, iWriteEnd)) ){
6307
+ paf->iMark = iWriteEnd;
6308
+ }
6309
+ return rc;
6310
+}
6311
+
6312
+/*
6313
+** Write data to an apnd-file.
6314
+*/
6315
+static int apndWrite(
6316
+ sqlite3_file *pFile,
6317
+ const void *zBuf,
6318
+ int iAmt,
6319
+ sqlite_int64 iOfst
6320
+){
6321
+ ApndFile *paf = (ApndFile *)pFile;
6322
+ sqlite_int64 iWriteEnd = iOfst + iAmt;
6323
+ if( iWriteEnd>=APND_MAX_SIZE ) return SQLITE_FULL;
6324
+ pFile = ORIGFILE(pFile);
6325
+ /* If append-mark is absent or will be overwritten, write it. */
6326
+ if( paf->iMark < 0 || paf->iPgOne + iWriteEnd > paf->iMark ){
6327
+ int rc = apndWriteMark(paf, pFile, iWriteEnd);
6328
+ if( SQLITE_OK!=rc ) return rc;
6329
+ }
6330
+ return pFile->pMethods->xWrite(pFile, zBuf, iAmt, paf->iPgOne+iOfst);
6331
+}
6332
+
6333
+/*
6334
+** Truncate an apnd-file.
6335
+*/
6336
+static int apndTruncate(sqlite3_file *pFile, sqlite_int64 size){
6337
+ ApndFile *paf = (ApndFile *)pFile;
6338
+ pFile = ORIGFILE(pFile);
6339
+ /* The append mark goes out first so truncate failure does not lose it. */
6340
+ if( SQLITE_OK!=apndWriteMark(paf, pFile, size) ) return SQLITE_IOERR;
6341
+ /* Truncate underlying file just past append mark */
6342
+ return pFile->pMethods->xTruncate(pFile, paf->iMark+APND_MARK_SIZE);
6343
+}
6344
+
6345
+/*
6346
+** Sync an apnd-file.
6347
+*/
6348
+static int apndSync(sqlite3_file *pFile, int flags){
6349
+ pFile = ORIGFILE(pFile);
6350
+ return pFile->pMethods->xSync(pFile, flags);
6351
+}
6352
+
6353
+/*
6354
+** Return the current file-size of an apnd-file.
6355
+** If the append mark is not yet there, the file-size is 0.
6356
+*/
6357
+static int apndFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
6358
+ ApndFile *paf = (ApndFile *)pFile;
6359
+ *pSize = ( paf->iMark >= 0 )? (paf->iMark - paf->iPgOne) : 0;
6360
+ return SQLITE_OK;
6361
+}
6362
+
6363
+/*
6364
+** Lock an apnd-file.
6365
+*/
6366
+static int apndLock(sqlite3_file *pFile, int eLock){
6367
+ pFile = ORIGFILE(pFile);
6368
+ return pFile->pMethods->xLock(pFile, eLock);
6369
+}
6370
+
6371
+/*
6372
+** Unlock an apnd-file.
6373
+*/
6374
+static int apndUnlock(sqlite3_file *pFile, int eLock){
6375
+ pFile = ORIGFILE(pFile);
6376
+ return pFile->pMethods->xUnlock(pFile, eLock);
6377
+}
6378
+
6379
+/*
6380
+** Check if another file-handle holds a RESERVED lock on an apnd-file.
6381
+*/
6382
+static int apndCheckReservedLock(sqlite3_file *pFile, int *pResOut){
6383
+ pFile = ORIGFILE(pFile);
6384
+ return pFile->pMethods->xCheckReservedLock(pFile, pResOut);
6385
+}
6386
+
6387
+/*
6388
+** File control method. For custom operations on an apnd-file.
6389
+*/
6390
+static int apndFileControl(sqlite3_file *pFile, int op, void *pArg){
6391
+ ApndFile *paf = (ApndFile *)pFile;
6392
+ int rc;
6393
+ pFile = ORIGFILE(pFile);
6394
+ if( op==SQLITE_FCNTL_SIZE_HINT ) *(sqlite3_int64*)pArg += paf->iPgOne;
6395
+ rc = pFile->pMethods->xFileControl(pFile, op, pArg);
6396
+ if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
6397
+ *(char**)pArg = sqlite3_mprintf("apnd(%lld)/%z", paf->iPgOne,*(char**)pArg);
6398
+ }
6399
+ return rc;
6400
+}
6401
+
6402
+/*
6403
+** Return the sector-size in bytes for an apnd-file.
6404
+*/
6405
+static int apndSectorSize(sqlite3_file *pFile){
6406
+ pFile = ORIGFILE(pFile);
6407
+ return pFile->pMethods->xSectorSize(pFile);
6408
+}
6409
+
6410
+/*
6411
+** Return the device characteristic flags supported by an apnd-file.
6412
+*/
6413
+static int apndDeviceCharacteristics(sqlite3_file *pFile){
6414
+ pFile = ORIGFILE(pFile);
6415
+ return pFile->pMethods->xDeviceCharacteristics(pFile);
6416
+}
6417
+
6418
+/* Create a shared memory file mapping */
6419
+static int apndShmMap(
6420
+ sqlite3_file *pFile,
6421
+ int iPg,
6422
+ int pgsz,
6423
+ int bExtend,
6424
+ void volatile **pp
6425
+){
6426
+ pFile = ORIGFILE(pFile);
6427
+ return pFile->pMethods->xShmMap(pFile,iPg,pgsz,bExtend,pp);
6428
+}
6429
+
6430
+/* Perform locking on a shared-memory segment */
6431
+static int apndShmLock(sqlite3_file *pFile, int offset, int n, int flags){
6432
+ pFile = ORIGFILE(pFile);
6433
+ return pFile->pMethods->xShmLock(pFile,offset,n,flags);
6434
+}
6435
+
6436
+/* Memory barrier operation on shared memory */
6437
+static void apndShmBarrier(sqlite3_file *pFile){
6438
+ pFile = ORIGFILE(pFile);
6439
+ pFile->pMethods->xShmBarrier(pFile);
6440
+}
6441
+
6442
+/* Unmap a shared memory segment */
6443
+static int apndShmUnmap(sqlite3_file *pFile, int deleteFlag){
6444
+ pFile = ORIGFILE(pFile);
6445
+ return pFile->pMethods->xShmUnmap(pFile,deleteFlag);
6446
+}
6447
+
6448
+/* Fetch a page of a memory-mapped file */
6449
+static int apndFetch(
6450
+ sqlite3_file *pFile,
6451
+ sqlite3_int64 iOfst,
6452
+ int iAmt,
6453
+ void **pp
6454
+){
6455
+ ApndFile *p = (ApndFile *)pFile;
6456
+ if( p->iMark < 0 || iOfst+iAmt > p->iMark ){
6457
+ return SQLITE_IOERR; /* Cannot read what is not yet there. */
6458
+ }
6459
+ pFile = ORIGFILE(pFile);
6460
+ return pFile->pMethods->xFetch(pFile, iOfst+p->iPgOne, iAmt, pp);
6461
+}
6462
+
6463
+/* Release a memory-mapped page */
6464
+static int apndUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){
6465
+ ApndFile *p = (ApndFile *)pFile;
6466
+ pFile = ORIGFILE(pFile);
6467
+ return pFile->pMethods->xUnfetch(pFile, iOfst+p->iPgOne, pPage);
6468
+}
6469
+
6470
+/*
6471
+** Try to read the append-mark off the end of a file. Return the
6472
+** start of the appended database if the append-mark is present.
6473
+** If there is no valid append-mark, return -1;
6474
+**
6475
+** An append-mark is only valid if the NNNNNNNN start-of-database offset
6476
+** indicates that the appended database contains at least one page. The
6477
+** start-of-database value must be a multiple of 512.
6478
+*/
6479
+static sqlite3_int64 apndReadMark(sqlite3_int64 sz, sqlite3_file *pFile){
6480
+ int rc, i;
6481
+ sqlite3_int64 iMark;
6482
+ int msbs = 8 * (APND_MARK_FOS_SZ-1);
6483
+ unsigned char a[APND_MARK_SIZE];
6484
+
6485
+ if( APND_MARK_SIZE!=(sz & 0x1ff) ) return -1;
6486
+ rc = pFile->pMethods->xRead(pFile, a, APND_MARK_SIZE, sz-APND_MARK_SIZE);
6487
+ if( rc ) return -1;
6488
+ if( memcmp(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ)!=0 ) return -1;
6489
+ iMark = ((sqlite3_int64)(a[APND_MARK_PREFIX_SZ] & 0x7f)) << msbs;
6490
+ for(i=1; i<8; i++){
6491
+ msbs -= 8;
6492
+ iMark |= (sqlite3_int64)a[APND_MARK_PREFIX_SZ+i]<<msbs;
6493
+ }
6494
+ if( iMark > (sz - APND_MARK_SIZE - 512) ) return -1;
6495
+ if( iMark & 0x1ff ) return -1;
6496
+ return iMark;
6497
+}
6498
+
6499
+static const char apvfsSqliteHdr[] = "SQLite format 3";
6500
+/*
6501
+** Check to see if the file is an appendvfs SQLite database file.
6502
+** Return true iff it is such. Parameter sz is the file's size.
6503
+*/
6504
+static int apndIsAppendvfsDatabase(sqlite3_int64 sz, sqlite3_file *pFile){
6505
+ int rc;
6506
+ char zHdr[16];
6507
+ sqlite3_int64 iMark = apndReadMark(sz, pFile);
6508
+ if( iMark>=0 ){
6509
+ /* If file has the correct end-marker, the expected odd size, and the
6510
+ ** SQLite DB type marker where the end-marker puts it, then it
6511
+ ** is an appendvfs database.
6512
+ */
6513
+ rc = pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), iMark);
6514
+ if( SQLITE_OK==rc
6515
+ && memcmp(zHdr, apvfsSqliteHdr, sizeof(zHdr))==0
6516
+ && (sz & 0x1ff) == APND_MARK_SIZE
6517
+ && sz>=512+APND_MARK_SIZE
6518
+ ){
6519
+ return 1; /* It's an appendvfs database */
6520
+ }
6521
+ }
6522
+ return 0;
6523
+}
6524
+
6525
+/*
6526
+** Check to see if the file is an ordinary SQLite database file.
6527
+** Return true iff so. Parameter sz is the file's size.
6528
+*/
6529
+static int apndIsOrdinaryDatabaseFile(sqlite3_int64 sz, sqlite3_file *pFile){
6530
+ char zHdr[16];
6531
+ if( apndIsAppendvfsDatabase(sz, pFile) /* rule 2 */
6532
+ || (sz & 0x1ff) != 0
6533
+ || SQLITE_OK!=pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), 0)
6534
+ || memcmp(zHdr, apvfsSqliteHdr, sizeof(zHdr))!=0
6535
+ ){
6536
+ return 0;
6537
+ }else{
6538
+ return 1;
6539
+ }
6540
+}
6541
+
6542
+/*
6543
+** Open an apnd file handle.
6544
+*/
6545
+static int apndOpen(
6546
+ sqlite3_vfs *pApndVfs,
6547
+ const char *zName,
6548
+ sqlite3_file *pFile,
6549
+ int flags,
6550
+ int *pOutFlags
6551
+){
6552
+ ApndFile *pApndFile = (ApndFile*)pFile;
6553
+ sqlite3_file *pBaseFile = ORIGFILE(pFile);
6554
+ sqlite3_vfs *pBaseVfs = ORIGVFS(pApndVfs);
6555
+ int rc;
6556
+ sqlite3_int64 sz = 0;
6557
+ if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
6558
+ /* The appendvfs is not to be used for transient or temporary databases.
6559
+ ** Just use the base VFS open to initialize the given file object and
6560
+ ** open the underlying file. (Appendvfs is then unused for this file.)
6561
+ */
6562
+ return pBaseVfs->xOpen(pBaseVfs, zName, pFile, flags, pOutFlags);
6563
+ }
6564
+ memset(pApndFile, 0, sizeof(ApndFile));
6565
+ pFile->pMethods = &apnd_io_methods;
6566
+ pApndFile->iMark = -1; /* Append mark not yet written */
6567
+
6568
+ rc = pBaseVfs->xOpen(pBaseVfs, zName, pBaseFile, flags, pOutFlags);
6569
+ if( rc==SQLITE_OK ){
6570
+ rc = pBaseFile->pMethods->xFileSize(pBaseFile, &sz);
6571
+ if( rc ){
6572
+ pBaseFile->pMethods->xClose(pBaseFile);
6573
+ }
6574
+ }
6575
+ if( rc ){
6576
+ pFile->pMethods = 0;
6577
+ return rc;
6578
+ }
6579
+ if( apndIsOrdinaryDatabaseFile(sz, pBaseFile) ){
6580
+ /* The file being opened appears to be just an ordinary DB. Copy
6581
+ ** the base dispatch-table so this instance mimics the base VFS.
6582
+ */
6583
+ memmove(pApndFile, pBaseFile, pBaseVfs->szOsFile);
6584
+ return SQLITE_OK;
6585
+ }
6586
+ pApndFile->iPgOne = apndReadMark(sz, pFile);
6587
+ if( pApndFile->iPgOne>=0 ){
6588
+ pApndFile->iMark = sz - APND_MARK_SIZE; /* Append mark found */
6589
+ return SQLITE_OK;
6590
+ }
6591
+ if( (flags & SQLITE_OPEN_CREATE)==0 ){
6592
+ pBaseFile->pMethods->xClose(pBaseFile);
6593
+ rc = SQLITE_CANTOPEN;
6594
+ pFile->pMethods = 0;
6595
+ }else{
6596
+ /* Round newly added appendvfs location to #define'd page boundary.
6597
+ ** Note that nothing has yet been written to the underlying file.
6598
+ ** The append mark will be written along with first content write.
6599
+ ** Until then, paf->iMark value indicates it is not yet written.
6600
+ */
6601
+ pApndFile->iPgOne = APND_START_ROUNDUP(sz);
6602
+ }
6603
+ return rc;
6604
+}
6605
+
6606
+/*
6607
+** Delete an apnd file.
6608
+** For an appendvfs, this could mean delete the appendvfs portion,
6609
+** leaving the appendee as it was before it gained an appendvfs.
6610
+** For now, this code deletes the underlying file too.
6611
+*/
6612
+static int apndDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
6613
+ return ORIGVFS(pVfs)->xDelete(ORIGVFS(pVfs), zPath, dirSync);
6614
+}
6615
+
6616
+/*
6617
+** All other VFS methods are pass-thrus.
6618
+*/
6619
+static int apndAccess(
6620
+ sqlite3_vfs *pVfs,
6621
+ const char *zPath,
6622
+ int flags,
6623
+ int *pResOut
6624
+){
6625
+ return ORIGVFS(pVfs)->xAccess(ORIGVFS(pVfs), zPath, flags, pResOut);
6626
+}
6627
+static int apndFullPathname(
6628
+ sqlite3_vfs *pVfs,
6629
+ const char *zPath,
6630
+ int nOut,
6631
+ char *zOut
6632
+){
6633
+ return ORIGVFS(pVfs)->xFullPathname(ORIGVFS(pVfs),zPath,nOut,zOut);
6634
+}
6635
+static void *apndDlOpen(sqlite3_vfs *pVfs, const char *zPath){
6636
+ return ORIGVFS(pVfs)->xDlOpen(ORIGVFS(pVfs), zPath);
6637
+}
6638
+static void apndDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){
6639
+ ORIGVFS(pVfs)->xDlError(ORIGVFS(pVfs), nByte, zErrMsg);
6640
+}
6641
+static void (*apndDlSym(sqlite3_vfs *pVfs, void *p, const char *zSym))(void){
6642
+ return ORIGVFS(pVfs)->xDlSym(ORIGVFS(pVfs), p, zSym);
6643
+}
6644
+static void apndDlClose(sqlite3_vfs *pVfs, void *pHandle){
6645
+ ORIGVFS(pVfs)->xDlClose(ORIGVFS(pVfs), pHandle);
6646
+}
6647
+static int apndRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
6648
+ return ORIGVFS(pVfs)->xRandomness(ORIGVFS(pVfs), nByte, zBufOut);
6649
+}
6650
+static int apndSleep(sqlite3_vfs *pVfs, int nMicro){
6651
+ return ORIGVFS(pVfs)->xSleep(ORIGVFS(pVfs), nMicro);
6652
+}
6653
+static int apndCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
6654
+ return ORIGVFS(pVfs)->xCurrentTime(ORIGVFS(pVfs), pTimeOut);
6655
+}
6656
+static int apndGetLastError(sqlite3_vfs *pVfs, int a, char *b){
6657
+ return ORIGVFS(pVfs)->xGetLastError(ORIGVFS(pVfs), a, b);
6658
+}
6659
+static int apndCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *p){
6660
+ return ORIGVFS(pVfs)->xCurrentTimeInt64(ORIGVFS(pVfs), p);
6661
+}
6662
+static int apndSetSystemCall(
6663
+ sqlite3_vfs *pVfs,
6664
+ const char *zName,
6665
+ sqlite3_syscall_ptr pCall
6666
+){
6667
+ return ORIGVFS(pVfs)->xSetSystemCall(ORIGVFS(pVfs),zName,pCall);
6668
+}
6669
+static sqlite3_syscall_ptr apndGetSystemCall(
6670
+ sqlite3_vfs *pVfs,
6671
+ const char *zName
6672
+){
6673
+ return ORIGVFS(pVfs)->xGetSystemCall(ORIGVFS(pVfs),zName);
6674
+}
6675
+static const char *apndNextSystemCall(sqlite3_vfs *pVfs, const char *zName){
6676
+ return ORIGVFS(pVfs)->xNextSystemCall(ORIGVFS(pVfs), zName);
6677
+}
6678
+
6679
+
6680
+#ifdef _WIN32
6681
+
6682
+#endif
6683
+/*
6684
+** This routine is called when the extension is loaded.
6685
+** Register the new VFS.
6686
+*/
6687
+int sqlite3_appendvfs_init(
6688
+ sqlite3 *db,
6689
+ char **pzErrMsg,
6690
+ const sqlite3_api_routines *pApi
6691
+){
6692
+ int rc = SQLITE_OK;
6693
+ sqlite3_vfs *pOrig;
6694
+ SQLITE_EXTENSION_INIT2(pApi);
6695
+ (void)pzErrMsg;
6696
+ (void)db;
6697
+ pOrig = sqlite3_vfs_find(0);
6698
+ if( pOrig==0 ) return SQLITE_ERROR;
6699
+ apnd_vfs.iVersion = pOrig->iVersion;
6700
+ apnd_vfs.pAppData = pOrig;
6701
+ apnd_vfs.szOsFile = pOrig->szOsFile + sizeof(ApndFile);
6702
+ rc = sqlite3_vfs_register(&apnd_vfs, 0);
6703
+#ifdef APPENDVFS_TEST
6704
+ if( rc==SQLITE_OK ){
6705
+ rc = sqlite3_auto_extension((void(*)(void))apndvfsRegister);
6706
+ }
6707
+#endif
6708
+ if( rc==SQLITE_OK ) rc = SQLITE_OK_LOAD_PERMANENTLY;
6709
+ return rc;
6710
+}
6711
+
6712
+/************************* End ../ext/misc/appendvfs.c ********************/
6713
+#endif
67016714
#ifdef SQLITE_HAVE_ZLIB
67026715
/************************* Begin ../ext/misc/zipfile.c ******************/
67036716
/*
67046717
** 2017-12-26
67056718
**
@@ -12235,11 +12248,21 @@
1223512248
int nIndent; /* Size of array aiIndent[] */
1223612249
int iIndent; /* Index of current op in aiIndent[] */
1223712250
char *zNonce; /* Nonce for temporary safe-mode excapes */
1223812251
EQPGraph sGraph; /* Information for the graphical EXPLAIN QUERY PLAN */
1223912252
ExpertInfo expert; /* Valid if previous command was ".expert OPT..." */
12253
+#ifdef SQLITE_SHELL_WASM_MODE
12254
+ struct {
12255
+ const char * zInput; /* Input string from wasm/JS proxy */
12256
+ const char * zPos; /* Cursor pos into zInput */
12257
+ } wasm;
12258
+#endif
1224012259
};
12260
+
12261
+#ifdef SQLITE_SHELL_WASM_MODE
12262
+static ShellState shellState;
12263
+#endif
1224112264
1224212265
1224312266
/* Allowed values for ShellState.autoEQP
1224412267
*/
1224512268
#define AUTOEQP_off 0 /* Automatic EXPLAIN QUERY PLAN is off */
@@ -12277,11 +12300,11 @@
1227712300
#define SHFLG_Lookaside 0x00000002 /* Lookaside memory is used */
1227812301
#define SHFLG_Backslash 0x00000004 /* The --backslash option is used */
1227912302
#define SHFLG_PreserveRowid 0x00000008 /* .dump preserves rowid values */
1228012303
#define SHFLG_Newlines 0x00000010 /* .dump --newline flag */
1228112304
#define SHFLG_CountChanges 0x00000020 /* .changes setting */
12282
-#define SHFLG_Echo 0x00000040 /* .echo or --echo setting */
12305
+#define SHFLG_Echo 0x00000040 /* .echo on/off, or --echo setting */
1228312306
#define SHFLG_HeaderSet 0x00000080 /* showHeader has been specified */
1228412307
#define SHFLG_DumpDataOnly 0x00000100 /* .dump show data only */
1228512308
#define SHFLG_DumpNoSys 0x00000200 /* .dump omits system tables */
1228612309
1228712310
/*
@@ -14906,15 +14929,10 @@
1490614929
if( pArg ){
1490714930
pArg->pStmt = pStmt;
1490814931
pArg->cnt = 0;
1490914932
}
1491014933
14911
- /* echo the sql statement if echo on */
14912
- if( pArg && ShellHasFlag(pArg, SHFLG_Echo) ){
14913
- utf8_printf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
14914
- }
14915
-
1491614934
/* Show the EXPLAIN QUERY PLAN if .eqp is on */
1491714935
if( pArg && pArg->autoEQP && sqlite3_stmt_isexplain(pStmt)==0 ){
1491814936
sqlite3_stmt *pExplain;
1491914937
char *zEQP;
1492014938
int triggerEQP = 0;
@@ -15309,17 +15327,18 @@
1530915327
1531015328
/*
1531115329
** Text of help messages.
1531215330
**
1531315331
** The help text for each individual command begins with a line that starts
15314
-** with ".". Subsequent lines are supplimental information.
15332
+** with ".". Subsequent lines are supplemental information.
1531515333
**
1531615334
** There must be two or more spaces between the end of the command and the
1531715335
** start of the description of what that command does.
1531815336
*/
1531915337
static const char *(azHelp[]) = {
15320
-#if defined(SQLITE_HAVE_ZLIB) && !defined(SQLITE_OMIT_VIRTUALTABLE)
15338
+#if defined(SQLITE_HAVE_ZLIB) && !defined(SQLITE_OMIT_VIRTUALTABLE) \
15339
+ && !defined(SQLITE_SHELL_WASM_MODE)
1532115340
".archive ... Manage SQL archives",
1532215341
" Each command must have exactly one of the following options:",
1532315342
" -c, --create Create a new archive",
1532415343
" -u, --update Add or update files with changed mtime",
1532515344
" -i, --insert Like -u but always add even if unchanged",
@@ -15341,20 +15360,26 @@
1534115360
" http://sqlite.org/cli.html#sqlite_archive_support",
1534215361
#endif
1534315362
#ifndef SQLITE_OMIT_AUTHORIZATION
1534415363
".auth ON|OFF Show authorizer callbacks",
1534515364
#endif
15365
+#ifndef SQLITE_SHELL_WASM_MODE
1534615366
".backup ?DB? FILE Backup DB (default \"main\") to FILE",
1534715367
" Options:",
1534815368
" --append Use the appendvfs",
1534915369
" --async Write to FILE without journal and fsync()",
15370
+#endif
1535015371
".bail on|off Stop after hitting an error. Default OFF",
1535115372
".binary on|off Turn binary output on or off. Default OFF",
15373
+#ifndef SQLITE_SHELL_WASM_MODE
1535215374
".cd DIRECTORY Change the working directory to DIRECTORY",
15375
+#endif
1535315376
".changes on|off Show number of rows changed by SQL",
15377
+#ifndef SQLITE_SHELL_WASM_MODE
1535415378
".check GLOB Fail if output since .testcase does not match",
1535515379
".clone NEWDB Clone data into NEWDB from the existing database",
15380
+#endif
1535615381
".connection [close] [#] Open or close an auxiliary database connection",
1535715382
".databases List names and files of attached databases",
1535815383
".dbconfig ?op? ?val? List or change sqlite3_db_config() options",
1535915384
".dbinfo ?DB? Show status information about the database",
1536015385
".dump ?OBJECTS? Render database content as SQL",
@@ -15371,21 +15396,26 @@
1537115396
#ifdef SQLITE_DEBUG
1537215397
" test Show raw EXPLAIN QUERY PLAN output",
1537315398
" trace Like \"full\" but enable \"PRAGMA vdbe_trace\"",
1537415399
#endif
1537515400
" trigger Like \"full\" but also show trigger bytecode",
15401
+#ifndef SQLITE_SHELL_WASM_MODE
1537615402
".excel Display the output of next command in spreadsheet",
1537715403
" --bom Put a UTF8 byte-order mark on intermediate file",
15404
+#endif
15405
+#ifndef SQLITE_SHELL_WASM_MODE
1537815406
".exit ?CODE? Exit this program with return-code CODE",
15407
+#endif
1537915408
".expert EXPERIMENTAL. Suggest indexes for queries",
1538015409
".explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto",
1538115410
".filectrl CMD ... Run various sqlite3_file_control() operations",
1538215411
" --schema SCHEMA Use SCHEMA instead of \"main\"",
1538315412
" --help Show CMD details",
1538415413
".fullschema ?--indent? Show schema and the content of sqlite_stat tables",
1538515414
".headers on|off Turn display of headers on or off",
1538615415
".help ?-all? ?PATTERN? Show help text for PATTERN",
15416
+#ifndef SQLITE_SHELL_WASM_MODE
1538715417
".import FILE TABLE Import data from FILE into TABLE",
1538815418
" Options:",
1538915419
" --ascii Use \\037 and \\036 as column and row separators",
1539015420
" --csv Use , and \\n as column and row separators",
1539115421
" --skip N Skip the first N rows of input",
@@ -15396,10 +15426,11 @@
1539615426
" determines the column names.",
1539715427
" * If neither --csv or --ascii are used, the input mode is derived",
1539815428
" from the \".mode\" output mode",
1539915429
" * If FILE begins with \"|\" then it is a command that generates the",
1540015430
" input text.",
15431
+#endif
1540115432
#ifndef SQLITE_OMIT_TEST_CONTROL
1540215433
".imposter INDEX TABLE Create imposter table TABLE on index INDEX",
1540315434
#endif
1540415435
".indexes ?TABLE? Show names of indexes",
1540515436
" If TABLE is specified, only show indexes for",
@@ -15409,14 +15440,16 @@
1540915440
#endif
1541015441
".limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT",
1541115442
".lint OPTIONS Report potential schema issues.",
1541215443
" Options:",
1541315444
" fkey-indexes Find missing foreign key indexes",
15414
-#ifndef SQLITE_OMIT_LOAD_EXTENSION
15445
+#if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_WASM_MODE)
1541515446
".load FILE ?ENTRY? Load an extension library",
1541615447
#endif
15448
+#ifndef SQLITE_SHELL_WASM_MODE
1541715449
".log FILE|off Turn logging on or off. FILE can be stderr/stdout",
15450
+#endif
1541815451
".mode MODE ?OPTIONS? Set output mode",
1541915452
" MODE is one of:",
1542015453
" ascii Columns/rows delimited by 0x1F and 0x1E",
1542115454
" box Tables using unicode box-drawing characters",
1542215455
" csv Comma-separated values",
@@ -15437,35 +15470,44 @@
1543715470
" --wordwrap B Wrap or not at word boundaries per B (on/off)",
1543815471
" --ww Shorthand for \"--wordwrap 1\"",
1543915472
" --quote Quote output text as SQL literals",
1544015473
" --noquote Do not quote output text",
1544115474
" TABLE The name of SQL table used for \"insert\" mode",
15475
+#ifndef SQLITE_SHELL_WASM_MODE
1544215476
".nonce STRING Suspend safe mode for one command if nonce matches",
15477
+#endif
1544315478
".nullvalue STRING Use STRING in place of NULL values",
15479
+#ifndef SQLITE_SHELL_WASM_MODE
1544415480
".once ?OPTIONS? ?FILE? Output for the next SQL command only to FILE",
1544515481
" If FILE begins with '|' then open as a pipe",
1544615482
" --bom Put a UTF8 byte-order mark at the beginning",
1544715483
" -e Send output to the system text editor",
1544815484
" -x Send output as CSV to a spreadsheet (same as \".excel\")",
15485
+ /* Note that .open is (partially) available in WASM builds but is
15486
+ ** currently only intended to be used by the fiddle tool, not
15487
+ ** end users, so is "undocumented." */
1544915488
".open ?OPTIONS? ?FILE? Close existing database and reopen FILE",
1545015489
" Options:",
1545115490
" --append Use appendvfs to append database to the end of FILE",
15491
+#endif
1545215492
#ifndef SQLITE_OMIT_DESERIALIZE
1545315493
" --deserialize Load into memory using sqlite3_deserialize()",
1545415494
" --hexdb Load the output of \"dbtotxt\" as an in-memory db",
1545515495
" --maxsize N Maximum size for --hexdb or --deserialized database",
1545615496
#endif
1545715497
" --new Initialize FILE to an empty database",
1545815498
" --nofollow Do not follow symbolic links",
1545915499
" --readonly Open FILE readonly",
1546015500
" --zip FILE is a ZIP archive",
15501
+#ifndef SQLITE_SHELL_WASM_MODE
1546115502
".output ?FILE? Send output to FILE or stdout if FILE is omitted",
1546215503
" If FILE begins with '|' then open it as a pipe.",
1546315504
" Options:",
1546415505
" --bom Prefix output with a UTF8 byte-order mark",
1546515506
" -e Send output to the system text editor",
1546615507
" -x Send output as CSV to a spreadsheet",
15508
+#endif
1546715509
".parameter CMD ... Manage SQL parameter bindings",
1546815510
" clear Erase all bindings",
1546915511
" init Initialize the TEMP table that holds bindings",
1547015512
" list List the current parameter bindings",
1547115513
" set PARAMETER VALUE Given SQL parameter PARAMETER a value of VALUE",
@@ -15478,23 +15520,27 @@
1547815520
" --once Do no more than one progress interrupt",
1547915521
" --quiet|-q No output except at interrupts",
1548015522
" --reset Reset the count for each input and interrupt",
1548115523
#endif
1548215524
".prompt MAIN CONTINUE Replace the standard prompts",
15525
+#ifndef SQLITE_SHELL_WASM_MODE
1548315526
".quit Exit this program",
1548415527
".read FILE Read input from FILE or command output",
1548515528
" If FILE begins with \"|\", it is a command that generates the input.",
15529
+#endif
1548615530
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
1548715531
".recover Recover as much data as possible from corrupt db.",
1548815532
" --freelist-corrupt Assume the freelist is corrupt",
1548915533
" --recovery-db NAME Store recovery metadata in database file NAME",
1549015534
" --lost-and-found TABLE Alternative name for the lost-and-found table",
1549115535
" --no-rowids Do not attempt to recover rowid values",
1549215536
" that are not also INTEGER PRIMARY KEYs",
1549315537
#endif
15538
+#ifndef SQLITE_SHELL_WASM_MODE
1549415539
".restore ?DB? FILE Restore content of DB (default \"main\") from FILE",
1549515540
".save ?OPTIONS? FILE Write database to FILE (an alias for .backup ...)",
15541
+#endif
1549615542
".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off",
1549715543
".schema ?PATTERN? Show the CREATE statements matching PATTERN",
1549815544
" Options:",
1549915545
" --indent Try to pretty-print the schema",
1550015546
" --nosys Omit objects whose names start with \"sqlite_\"",
@@ -15524,24 +15570,26 @@
1552415570
" --sha3-224 Use the sha3-224 algorithm",
1552515571
" --sha3-256 Use the sha3-256 algorithm (default)",
1552615572
" --sha3-384 Use the sha3-384 algorithm",
1552715573
" --sha3-512 Use the sha3-512 algorithm",
1552815574
" Any other argument is a LIKE pattern for tables to hash",
15529
-#ifndef SQLITE_NOHAVE_SYSTEM
15575
+#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE)
1553015576
".shell CMD ARGS... Run CMD ARGS... in a system shell",
1553115577
#endif
1553215578
".show Show the current values for various settings",
1553315579
".stats ?ARG? Show stats or turn stats on or off",
1553415580
" off Turn off automatic stat display",
1553515581
" on Turn on automatic stat display",
1553615582
" stmt Show statement stats",
1553715583
" vmstep Show the virtual machine step count only",
15538
-#ifndef SQLITE_NOHAVE_SYSTEM
15584
+#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE)
1553915585
".system CMD ARGS... Run CMD ARGS... in a system shell",
1554015586
#endif
1554115587
".tables ?TABLE? List names of tables matching LIKE pattern TABLE",
15588
+#ifndef SQLITE_SHELL_WASM_MODE
1554215589
".testcase NAME Begin redirecting output to 'testcase-out.txt'",
15590
+#endif
1554315591
".testctrl CMD ... Run various sqlite3_test_control() operations",
1554415592
" Run \".testctrl\" with no arguments for details",
1554515593
".timeout MS Try opening locked tables for MS milliseconds",
1554615594
".timer on|off Turn SQL timer on or off",
1554715595
#ifndef SQLITE_OMIT_TRACE
@@ -16082,18 +16130,20 @@
1608216130
exit(1);
1608316131
}
1608416132
#ifndef SQLITE_OMIT_LOAD_EXTENSION
1608516133
sqlite3_enable_load_extension(p->db, 1);
1608616134
#endif
16087
- sqlite3_fileio_init(p->db, 0, 0);
1608816135
sqlite3_shathree_init(p->db, 0, 0);
16089
- sqlite3_completion_init(p->db, 0, 0);
1609016136
sqlite3_uint_init(p->db, 0, 0);
1609116137
sqlite3_decimal_init(p->db, 0, 0);
1609216138
sqlite3_regexp_init(p->db, 0, 0);
1609316139
sqlite3_ieee_init(p->db, 0, 0);
1609416140
sqlite3_series_init(p->db, 0, 0);
16141
+#ifndef SQLITE_SHELL_WASM_MODE
16142
+ sqlite3_fileio_init(p->db, 0, 0);
16143
+ sqlite3_completion_init(p->db, 0, 0);
16144
+#endif
1609516145
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
1609616146
sqlite3_dbdata_init(p->db, 0, 0);
1609716147
#endif
1609816148
#ifdef SQLITE_HAVE_ZLIB
1609916149
if( !p->bSafeModePersist ){
@@ -19212,18 +19262,20 @@
1921219262
sqlite3_set_authorizer(p->db, 0, 0);
1921319263
}
1921419264
}else
1921519265
#endif
1921619266
19217
-#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB)
19267
+#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB) \
19268
+ && !defined(SQLITE_SHELL_WASM_MODE)
1921819269
if( c=='a' && strncmp(azArg[0], "archive", n)==0 ){
1921919270
open_db(p, 0);
1922019271
failIfSafeMode(p, "cannot run .archive in safe mode");
1922119272
rc = arDotCommand(p, 0, azArg, nArg);
1922219273
}else
1922319274
#endif
1922419275
19276
+#ifndef SQLITE_SHELL_WASM_MODE
1922519277
if( (c=='b' && n>=3 && strncmp(azArg[0], "backup", n)==0)
1922619278
|| (c=='s' && n>=3 && strncmp(azArg[0], "save", n)==0)
1922719279
){
1922819280
const char *zDestFile = 0;
1922919281
const char *zDb = 0;
@@ -19288,10 +19340,11 @@
1928819340
utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
1928919341
rc = 1;
1929019342
}
1929119343
close_db(pDest);
1929219344
}else
19345
+#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
1929319346
1929419347
if( c=='b' && n>=3 && strncmp(azArg[0], "bail", n)==0 ){
1929519348
if( nArg==2 ){
1929619349
bail_on_error = booleanValue(azArg[1]);
1929719350
}else{
@@ -19318,10 +19371,11 @@
1931819371
*/
1931919372
if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
1932019373
test_breakpoint();
1932119374
}else
1932219375
19376
+#ifndef SQLITE_SHELL_WASM_MODE
1932319377
if( c=='c' && strcmp(azArg[0],"cd")==0 ){
1932419378
failIfSafeMode(p, "cannot run .cd in safe mode");
1932519379
if( nArg==2 ){
1932619380
#if defined(_WIN32) || defined(WIN32)
1932719381
wchar_t *z = sqlite3_win32_utf8_to_unicode(azArg[1]);
@@ -19337,10 +19391,11 @@
1933719391
}else{
1933819392
raw_printf(stderr, "Usage: .cd DIRECTORY\n");
1933919393
rc = 1;
1934019394
}
1934119395
}else
19396
+#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
1934219397
1934319398
if( c=='c' && n>=3 && strncmp(azArg[0], "changes", n)==0 ){
1934419399
if( nArg==2 ){
1934519400
setOrClearFlag(p, SHFLG_CountChanges, azArg[1]);
1934619401
}else{
@@ -19347,10 +19402,11 @@
1934719402
raw_printf(stderr, "Usage: .changes on|off\n");
1934819403
rc = 1;
1934919404
}
1935019405
}else
1935119406
19407
+#ifndef SQLITE_SHELL_WASM_MODE
1935219408
/* Cancel output redirection, if it is currently set (by .testcase)
1935319409
** Then read the content of the testcase-out.txt file and compare against
1935419410
** azArg[1]. If there are differences, report an error and exit.
1935519411
*/
1935619412
if( c=='c' && n>=3 && strncmp(azArg[0], "check", n)==0 ){
@@ -19371,20 +19427,23 @@
1937119427
utf8_printf(stdout, "testcase-%s ok\n", p->zTestcase);
1937219428
p->nCheck++;
1937319429
}
1937419430
sqlite3_free(zRes);
1937519431
}else
19432
+#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
1937619433
19434
+#ifndef SQLITE_SHELL_WASM_MODE
1937719435
if( c=='c' && strncmp(azArg[0], "clone", n)==0 ){
1937819436
failIfSafeMode(p, "cannot run .clone in safe mode");
1937919437
if( nArg==2 ){
1938019438
tryToClone(p, azArg[1]);
1938119439
}else{
1938219440
raw_printf(stderr, "Usage: .clone FILENAME\n");
1938319441
rc = 1;
1938419442
}
1938519443
}else
19444
+#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
1938619445
1938719446
if( c=='c' && strncmp(azArg[0], "connection", n)==0 ){
1938819447
if( nArg==1 ){
1938919448
/* List available connections */
1939019449
int i;
@@ -19523,11 +19582,11 @@
1952319582
char *zLike = 0;
1952419583
char *zSql;
1952519584
int i;
1952619585
int savedShowHeader = p->showHeader;
1952719586
int savedShellFlags = p->shellFlgs;
19528
- ShellClearFlag(p,
19587
+ ShellClearFlag(p,
1952919588
SHFLG_PreserveRowid|SHFLG_Newlines|SHFLG_Echo
1953019589
|SHFLG_DumpDataOnly|SHFLG_DumpNoSys);
1953119590
for(i=1; i<nArg; i++){
1953219591
if( azArg[i][0]=='-' ){
1953319592
const char *z = azArg[i]+1;
@@ -19669,14 +19728,16 @@
1966919728
raw_printf(stderr, "Usage: .eqp off|on|trace|trigger|full\n");
1967019729
rc = 1;
1967119730
}
1967219731
}else
1967319732
19733
+#ifndef SQLITE_SHELL_WASM_MODE
1967419734
if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
1967519735
if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
1967619736
rc = 2;
1967719737
}else
19738
+#endif
1967819739
1967919740
/* The ".explain" command is automatic now. It is largely pointless. It
1968019741
** retained purely for backwards compatibility */
1968119742
if( c=='e' && strncmp(azArg[0], "explain", n)==0 ){
1968219743
int val = 1;
@@ -19927,10 +19988,11 @@
1992719988
}else{
1992819989
showHelp(p->out, 0);
1992919990
}
1993019991
}else
1993119992
19993
+#ifndef SQLITE_SHELL_WASM_MODE
1993219994
if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
1993319995
char *zTable = 0; /* Insert data into this table */
1993419996
char *zSchema = 0; /* within this schema (may default to "main") */
1993519997
char *zFile = 0; /* Name of file to extra content from */
1993619998
sqlite3_stmt *pStmt = NULL; /* A statement */
@@ -19948,20 +20010,16 @@
1994820010
int useOutputMode = 1; /* Use output mode to determine separators */
1994920011
char *zCreate = 0; /* CREATE TABLE statement text */
1995020012
1995120013
failIfSafeMode(p, "cannot run .import in safe mode");
1995220014
memset(&sCtx, 0, sizeof(sCtx));
19953
- sCtx.z = sqlite3_malloc64(120);
19954
- if( sCtx.z==0 ){
19955
- import_cleanup(&sCtx);
19956
- shell_out_of_memory();
19957
- }
1995820015
if( p->mode==MODE_Ascii ){
1995920016
xRead = ascii_read_one_field;
1996020017
}else{
1996120018
xRead = csv_read_one_field;
1996220019
}
20020
+ rc = 1;
1996320021
for(i=1; i<nArg; i++){
1996420022
char *z = azArg[i];
1996520023
if( z[0]=='-' && z[1]=='-' ) z++;
1996620024
if( z[0]!='-' ){
1996720025
if( zFile==0 ){
@@ -19969,11 +20027,10 @@
1996920027
}else if( zTable==0 ){
1997020028
zTable = z;
1997120029
}else{
1997220030
utf8_printf(p->out, "ERROR: extra argument: \"%s\". Usage:\n", z);
1997320031
showHelp(p->out, "import");
19974
- rc = 1;
1997520032
goto meta_command_exit;
1997620033
}
1997720034
}else if( strcmp(z,"-v")==0 ){
1997820035
eVerbose++;
1997920036
}else if( strcmp(z,"-schema")==0 && i<nArg-1 ){
@@ -19991,19 +20048,17 @@
1999120048
xRead = csv_read_one_field;
1999220049
useOutputMode = 0;
1999320050
}else{
1999420051
utf8_printf(p->out, "ERROR: unknown option: \"%s\". Usage:\n", z);
1999520052
showHelp(p->out, "import");
19996
- rc = 1;
1999720053
goto meta_command_exit;
1999820054
}
1999920055
}
2000020056
if( zTable==0 ){
2000120057
utf8_printf(p->out, "ERROR: missing %s argument. Usage:\n",
2000220058
zFile==0 ? "FILE" : "TABLE");
2000320059
showHelp(p->out, "import");
20004
- rc = 1;
2000520060
goto meta_command_exit;
2000620061
}
2000720062
seenInterrupt = 0;
2000820063
open_db(p, 0);
2000920064
if( useOutputMode ){
@@ -20011,25 +20066,22 @@
2001120066
** the column and row separator characters from the output mode. */
2001220067
nSep = strlen30(p->colSeparator);
2001320068
if( nSep==0 ){
2001420069
raw_printf(stderr,
2001520070
"Error: non-null column separator required for import\n");
20016
- rc = 1;
2001720071
goto meta_command_exit;
2001820072
}
2001920073
if( nSep>1 ){
20020
- raw_printf(stderr,
20074
+ raw_printf(stderr,
2002120075
"Error: multi-character column separators not allowed"
2002220076
" for import\n");
20023
- rc = 1;
2002420077
goto meta_command_exit;
2002520078
}
2002620079
nSep = strlen30(p->rowSeparator);
2002720080
if( nSep==0 ){
2002820081
raw_printf(stderr,
2002920082
"Error: non-null row separator required for import\n");
20030
- rc = 1;
2003120083
goto meta_command_exit;
2003220084
}
2003320085
if( nSep==2 && p->mode==MODE_Csv && strcmp(p->rowSeparator,SEP_CrLf)==0 ){
2003420086
/* When importing CSV (only), if the row separator is set to the
2003520087
** default output row separator, change it to the default input
@@ -20039,11 +20091,10 @@
2003920091
nSep = strlen30(p->rowSeparator);
2004020092
}
2004120093
if( nSep>1 ){
2004220094
raw_printf(stderr, "Error: multi-character row separators not allowed"
2004320095
" for import\n");
20044
- rc = 1;
2004520096
goto meta_command_exit;
2004620097
}
2004720098
sCtx.cColSep = p->colSeparator[0];
2004820099
sCtx.cRowSep = p->rowSeparator[0];
2004920100
}
@@ -20050,11 +20101,10 @@
2005020101
sCtx.zFile = zFile;
2005120102
sCtx.nLine = 1;
2005220103
if( sCtx.zFile[0]=='|' ){
2005320104
#ifdef SQLITE_OMIT_POPEN
2005420105
raw_printf(stderr, "Error: pipes are not supported in this OS\n");
20055
- rc = 1;
2005620106
goto meta_command_exit;
2005720107
#else
2005820108
sCtx.in = popen(sCtx.zFile+1, "r");
2005920109
sCtx.zFile = "<pipe>";
2006020110
sCtx.xCloser = pclose;
@@ -20063,12 +20113,10 @@
2006320113
sCtx.in = fopen(sCtx.zFile, "rb");
2006420114
sCtx.xCloser = fclose;
2006520115
}
2006620116
if( sCtx.in==0 ){
2006720117
utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
20068
- rc = 1;
20069
- import_cleanup(&sCtx);
2007020118
goto meta_command_exit;
2007120119
}
2007220120
if( eVerbose>=2 || (eVerbose>=1 && useOutputMode) ){
2007320121
char zSep[2];
2007420122
zSep[1] = 0;
@@ -20077,10 +20125,15 @@
2007720125
output_c_string(p->out, zSep);
2007820126
utf8_printf(p->out, ", row separator ");
2007920127
zSep[0] = sCtx.cRowSep;
2008020128
output_c_string(p->out, zSep);
2008120129
utf8_printf(p->out, "\n");
20130
+ }
20131
+ sCtx.z = sqlite3_malloc64(120);
20132
+ if( sCtx.z==0 ){
20133
+ import_cleanup(&sCtx);
20134
+ shell_out_of_memory();
2008220135
}
2008320136
/* Below, resources must be freed before exit. */
2008420137
while( (nSkip--)>0 ){
2008520138
while( xRead(&sCtx) && sCtx.cTerm==sCtx.cColSep ){}
2008620139
}
@@ -20226,10 +20279,11 @@
2022620279
utf8_printf(p->out,
2022720280
"Added %d rows with %d errors using %d lines of input\n",
2022820281
sCtx.nRow, sCtx.nErr, sCtx.nLine-1);
2022920282
}
2023020283
}else
20284
+#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
2023120285
2023220286
#ifndef SQLITE_UNTESTABLE
2023320287
if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
2023420288
char *zSql;
2023520289
char *zCollist = 0;
@@ -20415,11 +20469,11 @@
2041520469
if( c=='l' && n>2 && strncmp(azArg[0], "lint", n)==0 ){
2041620470
open_db(p, 0);
2041720471
lintDotCommand(p, azArg, nArg);
2041820472
}else
2041920473
20420
-#ifndef SQLITE_OMIT_LOAD_EXTENSION
20474
+#if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_WASM_MODE)
2042120475
if( c=='l' && strncmp(azArg[0], "load", n)==0 ){
2042220476
const char *zFile, *zProc;
2042320477
char *zErrMsg = 0;
2042420478
failIfSafeMode(p, "cannot run .load in safe mode");
2042520479
if( nArg<2 ){
@@ -20437,10 +20491,11 @@
2043720491
rc = 1;
2043820492
}
2043920493
}else
2044020494
#endif
2044120495
20496
+#ifndef SQLITE_SHELL_WASM_MODE
2044220497
if( c=='l' && strncmp(azArg[0], "log", n)==0 ){
2044320498
failIfSafeMode(p, "cannot run .log in safe mode");
2044420499
if( nArg!=2 ){
2044520500
raw_printf(stderr, "Usage: .log FILENAME\n");
2044620501
rc = 1;
@@ -20448,10 +20503,11 @@
2044820503
const char *zFile = azArg[1];
2044920504
output_file_close(p->pLog);
2045020505
p->pLog = output_file_open(zFile, 0);
2045120506
}
2045220507
}else
20508
+#endif
2045320509
2045420510
if( c=='m' && strncmp(azArg[0], "mode", n)==0 ){
2045520511
const char *zMode = 0;
2045620512
const char *zTabname = 0;
2045720513
int i, n2;
@@ -20572,10 +20628,11 @@
2057220628
rc = 1;
2057320629
}
2057420630
p->cMode = p->mode;
2057520631
}else
2057620632
20633
+#ifndef SQLITE_SHELL_WASM_MODE
2057720634
if( c=='n' && strcmp(azArg[0], "nonce")==0 ){
2057820635
if( nArg!=2 ){
2057920636
raw_printf(stderr, "Usage: .nonce NONCE\n");
2058020637
rc = 1;
2058120638
}else if( p->zNonce==0 || strcmp(azArg[1],p->zNonce)!=0 ){
@@ -20586,10 +20643,11 @@
2058620643
p->bSafeMode = 0;
2058720644
return 0; /* Return immediately to bypass the safe mode reset
2058820645
** at the end of this procedure */
2058920646
}
2059020647
}else
20648
+#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
2059120649
2059220650
if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 ){
2059320651
if( nArg==2 ){
2059420652
sqlite3_snprintf(sizeof(p->nullValue), p->nullValue,
2059520653
"%.*s", (int)ArraySize(p->nullValue)-1, azArg[1]);
@@ -20607,10 +20665,11 @@
2060720665
int openMode = SHELL_OPEN_UNSPEC;
2060820666
2060920667
/* Check for command-line arguments */
2061020668
for(iName=1; iName<nArg; iName++){
2061120669
const char *z = azArg[iName];
20670
+#ifndef SQLITE_SHELL_WASM_MODE
2061220671
if( optionMatch(z,"new") ){
2061320672
newFlag = 1;
2061420673
#ifdef SQLITE_HAVE_ZLIB
2061520674
}else if( optionMatch(z, "zip") ){
2061620675
openMode = SHELL_OPEN_ZIPFILE;
@@ -20627,11 +20686,13 @@
2062720686
}else if( optionMatch(z, "hexdb") ){
2062820687
openMode = SHELL_OPEN_HEXDB;
2062920688
}else if( optionMatch(z, "maxsize") && iName+1<nArg ){
2063020689
p->szMax = integerValue(azArg[++iName]);
2063120690
#endif /* SQLITE_OMIT_DESERIALIZE */
20632
- }else if( z[0]=='-' ){
20691
+ }else
20692
+#endif /* !SQLITE_SHELL_WASM_MODE */
20693
+ if( z[0]=='-' ){
2063320694
utf8_printf(stderr, "unknown option: %s\n", z);
2063420695
rc = 1;
2063520696
goto meta_command_exit;
2063620697
}else if( zFN ){
2063720698
utf8_printf(stderr, "extra argument: \"%s\"\n", z);
@@ -20654,17 +20715,21 @@
2065420715
p->szMax = 0;
2065520716
2065620717
/* If a filename is specified, try to open it first */
2065720718
if( zFN || p->openMode==SHELL_OPEN_HEXDB ){
2065820719
if( newFlag && zFN && !p->bSafeMode ) shellDeleteFile(zFN);
20720
+#ifndef SQLITE_SHELL_WASM_MODE
2065920721
if( p->bSafeMode
2066020722
&& p->openMode!=SHELL_OPEN_HEXDB
2066120723
&& zFN
2066220724
&& strcmp(zFN,":memory:")!=0
2066320725
){
2066420726
failIfSafeMode(p, "cannot open disk-based database files in safe mode");
2066520727
}
20728
+#else
20729
+ /* WASM mode has its own sandboxed pseudo-filesystem. */
20730
+#endif
2066620731
if( zFN ){
2066720732
zNewFilename = sqlite3_mprintf("%s", zFN);
2066820733
shell_check_oom(zNewFilename);
2066920734
}else{
2067020735
zNewFilename = 0;
@@ -20683,10 +20748,11 @@
2068320748
p->pAuxDb->zDbFilename = 0;
2068420749
open_db(p, 0);
2068520750
}
2068620751
}else
2068720752
20753
+#ifndef SQLITE_SHELL_WASM_MODE
2068820754
if( (c=='o'
2068920755
&& (strncmp(azArg[0], "output", n)==0||strncmp(azArg[0], "once", n)==0))
2069020756
|| (c=='e' && n==5 && strcmp(azArg[0],"excel")==0)
2069120757
){
2069220758
char *zFile = 0;
@@ -20798,10 +20864,11 @@
2079820864
sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
2079920865
}
2080020866
}
2080120867
sqlite3_free(zFile);
2080220868
}else
20869
+#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
2080320870
2080420871
if( c=='p' && n>=3 && strncmp(azArg[0], "parameter", n)==0 ){
2080520872
open_db(p,0);
2080620873
if( nArg<=1 ) goto parameter_syntax_error;
2080720874
@@ -20967,14 +21034,17 @@
2096721034
if( nArg >= 3) {
2096821035
strncpy(continuePrompt,azArg[2],(int)ArraySize(continuePrompt)-1);
2096921036
}
2097021037
}else
2097121038
21039
+#ifndef SQLITE_SHELL_WASM_MODE
2097221040
if( c=='q' && strncmp(azArg[0], "quit", n)==0 ){
2097321041
rc = 2;
2097421042
}else
21043
+#endif
2097521044
21045
+#ifndef SQLITE_SHELL_WASM_MODE
2097621046
if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 ){
2097721047
FILE *inSaved = p->in;
2097821048
int savedLineno = p->lineno;
2097921049
failIfSafeMode(p, "cannot run .read in safe mode");
2098021050
if( nArg!=2 ){
@@ -21005,11 +21075,13 @@
2100521075
fclose(p->in);
2100621076
}
2100721077
p->in = inSaved;
2100821078
p->lineno = savedLineno;
2100921079
}else
21080
+#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
2101021081
21082
+#ifndef SQLITE_SHELL_WASM_MODE
2101121083
if( c=='r' && n>=3 && strncmp(azArg[0], "restore", n)==0 ){
2101221084
const char *zSrcFile;
2101321085
const char *zDb;
2101421086
sqlite3 *pSrc;
2101521087
sqlite3_backup *pBackup;
@@ -21057,10 +21129,11 @@
2105721129
utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
2105821130
rc = 1;
2105921131
}
2106021132
close_db(pSrc);
2106121133
}else
21134
+#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
2106221135
2106321136
if( c=='s' && strncmp(azArg[0], "scanstats", n)==0 ){
2106421137
if( nArg==2 ){
2106521138
p->scanstatsOn = (u8)booleanValue(azArg[1]);
2106621139
#ifndef SQLITE_ENABLE_STMT_SCANSTATUS
@@ -21682,11 +21755,11 @@
2168221755
shell_exec(p, zSql, 0);
2168321756
}
2168421757
sqlite3_free(zSql);
2168521758
}else
2168621759
21687
-#ifndef SQLITE_NOHAVE_SYSTEM
21760
+#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE)
2168821761
if( c=='s'
2168921762
&& (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
2169021763
){
2169121764
char *zCmd;
2169221765
int i, x;
@@ -21703,11 +21776,11 @@
2170321776
}
2170421777
x = zCmd!=0 ? system(zCmd) : 1;
2170521778
sqlite3_free(zCmd);
2170621779
if( x ) raw_printf(stderr, "System command returns %d\n", x);
2170721780
}else
21708
-#endif /* !defined(SQLITE_NOHAVE_SYSTEM) */
21781
+#endif /* !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE) */
2170921782
2171021783
if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
2171121784
static const char *azBool[] = { "off", "on", "trigger", "full"};
2171221785
const char *zOut;
2171321786
int i;
@@ -21715,11 +21788,11 @@
2171521788
raw_printf(stderr, "Usage: .show\n");
2171621789
rc = 1;
2171721790
goto meta_command_exit;
2171821791
}
2171921792
utf8_printf(p->out, "%12.12s: %s\n","echo",
21720
- azBool[ShellHasFlag(p, SHFLG_Echo)]);
21793
+ azBool[ShellHasFlag(p, SHFLG_Echo)]);
2172121794
utf8_printf(p->out, "%12.12s: %s\n","eqp", azBool[p->autoEQP&3]);
2172221795
utf8_printf(p->out, "%12.12s: %s\n","explain",
2172321796
p->mode==MODE_Explain ? "on" : p->autoExplain ? "auto" : "off");
2172421797
utf8_printf(p->out,"%12.12s: %s\n","headers", azBool[p->showHeader!=0]);
2172521798
if( p->mode==MODE_Column
@@ -21883,10 +21956,11 @@
2188321956
2188421957
for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
2188521958
sqlite3_free(azResult);
2188621959
}else
2188721960
21961
+#ifndef SQLITE_SHELL_WASM_MODE
2188821962
/* Begin redirecting output to the file "testcase-out.txt" */
2188921963
if( c=='t' && strcmp(azArg[0],"testcase")==0 ){
2189021964
output_reset(p);
2189121965
p->out = output_file_open("testcase-out.txt", 0);
2189221966
if( p->out==0 ){
@@ -21896,10 +21970,11 @@
2189621970
sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
2189721971
}else{
2189821972
sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?");
2189921973
}
2190021974
}else
21975
+#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
2190121976
2190221977
#ifndef SQLITE_UNTESTABLE
2190321978
if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 ){
2190421979
static const struct {
2190521980
const char *zCtrlName; /* Name of a test-control option */
@@ -22465,11 +22540,11 @@
2246522540
/* fall thru */
2246622541
case ']':
2246722542
cWait = 0;
2246822543
qss = QSS_SETV(qss, 0);
2246922544
goto PlainScan;
22470
- default: assert(0);
22545
+ default: assert(0);
2247122546
}
2247222547
}
2247322548
}
2247422549
}
2247522550
return qss;
@@ -22486,11 +22561,11 @@
2248622561
zLine += 1; /* Oracle */
2248722562
else if ( ToLower(zLine[0])=='g' && ToLower(zLine[1])=='o' )
2248822563
zLine += 2; /* SQL Server */
2248922564
else
2249022565
return 0;
22491
- return quickscan(zLine,QSS_Start)==QSS_Start;
22566
+ return quickscan(zLine, QSS_Start)==QSS_Start;
2249222567
}
2249322568
2249422569
/*
2249522570
** We need a default sqlite3_complete() implementation to use in case
2249622571
** the shell is compiled with SQLITE_OMIT_COMPLETE. The default assumes
@@ -22563,10 +22638,46 @@
2256322638
raw_printf(p->out, "%s\n", zLineBuf);
2256422639
}
2256522640
return 0;
2256622641
}
2256722642
22643
+static void echo_group_input(ShellState *p, const char *zDo){
22644
+ if( ShellHasFlag(p, SHFLG_Echo) ) utf8_printf(p->out, "%s\n", zDo);
22645
+}
22646
+
22647
+#ifdef SQLITE_SHELL_WASM_MODE
22648
+/*
22649
+** Alternate one_input_line() impl for wasm mode. This is not in the primary impl
22650
+** because we need the global shellState and cannot access it from that function
22651
+** without moving lots of code around (creating a larger/messier diff).
22652
+*/
22653
+static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
22654
+ /* Parse the next line from shellState.wasm.zInput. */
22655
+ const char *zBegin = shellState.wasm.zPos;
22656
+ const char *z = zBegin;
22657
+ char *zLine = 0;
22658
+ int nZ = 0;
22659
+
22660
+ UNUSED_PARAMETER(in);
22661
+ UNUSED_PARAMETER(isContinuation);
22662
+ if(!z || !*z){
22663
+ return 0;
22664
+ }
22665
+ while(*z && isspace(*z)) ++z;
22666
+ zBegin = z;
22667
+ for(; *z && '\n'!=*z; ++nZ, ++z){}
22668
+ if(nZ>0 && '\r'==zBegin[nZ-1]){
22669
+ --nZ;
22670
+ }
22671
+ shellState.wasm.zPos = z;
22672
+ zLine = realloc(zPrior, nZ+1);
22673
+ shell_check_oom(zLine);
22674
+ memcpy(zLine, zBegin, (size_t)nZ);
22675
+ zLine[nZ] = 0;
22676
+ return zLine;
22677
+}
22678
+#endif /* SQLITE_SHELL_WASM_MODE */
2256822679
2256922680
/*
2257022681
** Read input from *in and process it. If *in==0 then input
2257122682
** is interactive - the user is typing it it. Otherwise, input
2257222683
** is coming from a file or device. A prompt is issued and history
@@ -22612,18 +22723,17 @@
2261222723
&& line_is_complete(zSql, nSql) ){
2261322724
memcpy(zLine,";",2);
2261422725
}
2261522726
qss = quickscan(zLine, qss);
2261622727
if( QSS_PLAINWHITE(qss) && nSql==0 ){
22617
- if( ShellHasFlag(p, SHFLG_Echo) )
22618
- printf("%s\n", zLine);
2261922728
/* Just swallow single-line whitespace */
22729
+ echo_group_input(p, zLine);
2262022730
qss = QSS_Start;
2262122731
continue;
2262222732
}
2262322733
if( zLine && (zLine[0]=='.' || zLine[0]=='#') && nSql==0 ){
22624
- if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zLine);
22734
+ echo_group_input(p, zLine);
2262522735
if( zLine[0]=='.' ){
2262622736
rc = do_meta_command(zLine, p);
2262722737
if( rc==2 ){ /* exit requested */
2262822738
break;
2262922739
}else if( rc ){
@@ -22652,10 +22762,11 @@
2265222762
zSql[nSql++] = '\n';
2265322763
memcpy(zSql+nSql, zLine, nLine+1);
2265422764
nSql += nLine;
2265522765
}
2265622766
if( nSql && QSS_SEMITERM(qss) && sqlite3_complete(zSql) ){
22767
+ echo_group_input(p, zSql);
2265722768
errCnt += runOneSqlLine(p, zSql, p->in, startline);
2265822769
nSql = 0;
2265922770
if( p->outCount ){
2266022771
output_reset(p);
2266122772
p->outCount = 0;
@@ -22663,17 +22774,18 @@
2266322774
clearTempFile(p);
2266422775
}
2266522776
p->bSafeMode = p->bSafeModePersist;
2266622777
qss = QSS_Start;
2266722778
}else if( nSql && QSS_PLAINWHITE(qss) ){
22668
- if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zSql);
22779
+ echo_group_input(p, zSql);
2266922780
nSql = 0;
2267022781
qss = QSS_Start;
2267122782
}
2267222783
}
2267322784
if( nSql ){
2267422785
/* This may be incomplete. Let the SQL parser deal with that. */
22786
+ echo_group_input(p, zSql);
2267522787
errCnt += runOneSqlLine(p, zSql, p->in, startline);
2267622788
}
2267722789
free(zSql);
2267822790
free(zLine);
2267922791
--p->inputNesting;
@@ -22808,11 +22920,11 @@
2280822920
" -cmd COMMAND run \"COMMAND\" before reading stdin\n"
2280922921
" -csv set output mode to 'csv'\n"
2281022922
#if !defined(SQLITE_OMIT_DESERIALIZE)
2281122923
" -deserialize open the database using sqlite3_deserialize()\n"
2281222924
#endif
22813
- " -echo print commands before execution\n"
22925
+ " -echo print inputs before execution\n"
2281422926
" -init FILENAME read/process named file\n"
2281522927
" -[no]header turn headers on or off\n"
2281622928
#if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
2281722929
" -heap SIZE Size of heap for memsys3 or memsys5\n"
2281822930
#endif
@@ -22943,19 +23055,30 @@
2294323055
# define SQLITE_SHELL_IS_UTF8 (0)
2294423056
# else
2294523057
# define SQLITE_SHELL_IS_UTF8 (1)
2294623058
# endif
2294723059
#endif
23060
+
23061
+#ifdef SQLITE_SHELL_WASM_MODE
23062
+# define main fiddle_main
23063
+#endif
2294823064
2294923065
#if SQLITE_SHELL_IS_UTF8
2295023066
int SQLITE_CDECL main(int argc, char **argv){
2295123067
#else
2295223068
int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
2295323069
char **argv;
2295423070
#endif
23071
+#ifdef SQLITE_DEBUG
23072
+ sqlite3_uint64 mem_main_enter = sqlite3_memory_used();
23073
+#endif
2295523074
char *zErrMsg = 0;
23075
+#ifdef SQLITE_SHELL_WASM_MODE
23076
+# define data shellState
23077
+#else
2295623078
ShellState data;
23079
+#endif
2295723080
const char *zInitFile = 0;
2295823081
int i;
2295923082
int rc = 0;
2296023083
int warnInmemoryDb = 0;
2296123084
int readStdin = 1;
@@ -22967,12 +23090,17 @@
2296723090
int argcToFree = 0;
2296823091
#endif
2296923092
2297023093
setBinaryMode(stdin, 0);
2297123094
setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
23095
+#ifdef SQLITE_SHELL_WASM_MODE
23096
+ stdin_is_interactive = 0;
23097
+ stdout_is_console = 1;
23098
+#else
2297223099
stdin_is_interactive = isatty(0);
2297323100
stdout_is_console = isatty(1);
23101
+#endif
2297423102
2297523103
#if !defined(_WIN32_WCE)
2297623104
if( getenv("SQLITE_DEBUG_BREAK") ){
2297723105
if( isatty(0) && isatty(2) ){
2297823106
fprintf(stderr,
@@ -23224,11 +23352,13 @@
2322423352
utf8_printf(stderr,"%s: Error: no database filename specified\n", Argv0);
2322523353
return 1;
2322623354
#endif
2322723355
}
2322823356
data.out = stdout;
23357
+#ifndef SQLITE_SHELL_WASM_MODE
2322923358
sqlite3_appendvfs_init(0,0,0);
23359
+#endif
2323023360
2323123361
/* Go ahead and open the database file if it already exists. If the
2323223362
** file does not exist, delay opening it. This prevents empty database
2323323363
** files from being created if a user mistypes the database name argument
2323423364
** to the sqlite command-line tool.
@@ -23490,10 +23620,13 @@
2349023620
}else{
2349123621
data.in = stdin;
2349223622
rc = process_input(&data);
2349323623
}
2349423624
}
23625
+#ifndef SQLITE_SHELL_WASM_MODE
23626
+ /* In WASM mode we have to leave the db state in place so that
23627
+ ** client code can "push" SQL into it after this call returns. */
2349523628
free(azCmd);
2349623629
set_table_name(&data, 0);
2349723630
if( data.db ){
2349823631
session_close_all(&data, -1);
2349923632
close_db(data.db);
@@ -23516,7 +23649,138 @@
2351623649
free(data.colWidth);
2351723650
free(data.zNonce);
2351823651
/* Clear the global data structure so that valgrind will detect memory
2351923652
** leaks */
2352023653
memset(&data, 0, sizeof(data));
23654
+#ifdef SQLITE_DEBUG
23655
+ if( sqlite3_memory_used()>mem_main_enter ){
23656
+ utf8_printf(stderr, "Memory leaked: %u bytes\n",
23657
+ (unsigned int)(sqlite3_memory_used()-mem_main_enter));
23658
+ }
23659
+#endif
23660
+#endif /* !SQLITE_SHELL_WASM_MODE */
2352123661
return rc;
2352223662
}
23663
+
23664
+
23665
+#ifdef SQLITE_SHELL_WASM_MODE
23666
+/* Only for emcc experimentation purposes. */
23667
+int fiddle_experiment(int a,int b){
23668
+ return a + b;
23669
+}
23670
+
23671
+/* Only for emcc experimentation purposes.
23672
+
23673
+ Define this function in JS using:
23674
+
23675
+ emcc ... --js-library somefile.js
23676
+
23677
+ containing:
23678
+
23679
+mergeInto(LibraryManager.library, {
23680
+ my_foo: function(){
23681
+ console.debug("my_foo()",arguments);
23682
+ }
23683
+});
23684
+*/
23685
+/*extern void my_foo(sqlite3 *);*/
23686
+/* Only for emcc experimentation purposes. */
23687
+sqlite3 * fiddle_the_db(){
23688
+ printf("fiddle_the_db(%p)\n", (const void*)globalDb);
23689
+ /*my_foo(globalDb);*/
23690
+ return globalDb;
23691
+}
23692
+/* Only for emcc experimentation purposes. */
23693
+sqlite3 * fiddle_db_arg(sqlite3 *arg){
23694
+ printf("fiddle_db_arg(%p)\n", (const void*)arg);
23695
+ return arg;
23696
+}
23697
+
23698
+/*
23699
+** Intended to be called via a SharedWorker() while a separate
23700
+** SharedWorker() (which manages the wasm module) is performing work
23701
+** which should be interrupted. Unfortunately, SharedWorker is not
23702
+** portable enough to make real use of.
23703
+*/
23704
+void fiddle_interrupt(void){
23705
+ if(globalDb) sqlite3_interrupt(globalDb);
23706
+}
23707
+
23708
+/*
23709
+** Returns the filename of the given db name, assuming "main" if
23710
+** zDbName is NULL. Returns NULL if globalDb is not opened.
23711
+*/
23712
+const char * fiddle_db_filename(const char * zDbName){
23713
+ return globalDb
23714
+ ? sqlite3_db_filename(globalDb, zDbName ? zDbName : "main")
23715
+ : NULL;
23716
+}
23717
+
23718
+/*
23719
+** Closes, unlinks, and reopens the db using its current filename (or
23720
+** the default if the db is currently closed). It is assumed, for
23721
+** purposes of the fiddle build, that the file is in a transient
23722
+** virtual filesystem within the browser.
23723
+*/
23724
+void fiddle_reset_db(void){
23725
+ char *zFilename = 0;
23726
+ if(0==globalDb){
23727
+ shellState.pAuxDb->zDbFilename = "/fiddle.sqlite3";
23728
+ }else{
23729
+ zFilename =
23730
+ sqlite3_mprintf("%s", sqlite3_db_filename(globalDb, "main"));
23731
+ shell_check_oom(zFilename);
23732
+ close_db(globalDb);
23733
+ shellDeleteFile(zFilename);
23734
+ shellState.db = 0;
23735
+ shellState.pAuxDb->zDbFilename = zFilename;
23736
+ }
23737
+ open_db(&shellState, 0);
23738
+ sqlite3_free(zFilename);
23739
+}
23740
+
23741
+/*
23742
+** Trivial exportable function for emscripten. Needs to be exported using:
23743
+**
23744
+** emcc ..flags... -sEXPORTED_FUNCTIONS=_fiddle_exec -sEXPORTED_RUNTIME_METHODS=ccall,cwrap
23745
+**
23746
+** (Note the underscore before the function name.) It processes zSql
23747
+** as if it were input to the sqlite3 shell and redirects all output
23748
+** to the wasm binding.
23749
+*/
23750
+void fiddle_exec(const char * zSql){
23751
+ static int once = 0;
23752
+ int rc = 0;
23753
+ if(!once){
23754
+ /* Simulate an argv array for main() */
23755
+ static char * argv[] = {"fiddle",
23756
+ "-bail",
23757
+ "-safe"};
23758
+ rc = fiddle_main((int)(sizeof(argv)/sizeof(argv[0])), argv);
23759
+ once = rc ? -1 : 1;
23760
+ memset(&shellState.wasm, 0, sizeof(shellState.wasm));
23761
+ printf(
23762
+ "SQLite version %s %.19s\n" /*extra-version-info*/,
23763
+ sqlite3_libversion(), sqlite3_sourceid()
23764
+ );
23765
+ puts("WASM shell");
23766
+ puts("Enter \".help\" for usage hints.");
23767
+ if(once>0){
23768
+ fiddle_reset_db();
23769
+ }
23770
+ if(shellState.db){
23771
+ printf("Connected to %s.\n", fiddle_db_filename(NULL));
23772
+ }else{
23773
+ fprintf(stderr,"ERROR initializing db!\n");
23774
+ return;
23775
+ }
23776
+ }
23777
+ if(once<0){
23778
+ puts("DB init failed. Not executing SQL.");
23779
+ }else if(zSql && *zSql){
23780
+ shellState.wasm.zInput = zSql;
23781
+ shellState.wasm.zPos = zSql;
23782
+ process_input(&shellState);
23783
+ memset(&shellState.wasm, 0, sizeof(shellState.wasm));
23784
+ }
23785
+}
23786
+#endif /* SQLITE_SHELL_WASM_MODE */
2352323787
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -245,10 +245,20 @@
245 #else
246 # define setBinaryMode(X,Y)
247 # define setTextMode(X,Y)
248 #endif
249
 
 
 
 
 
 
 
 
 
 
250
251 /* True if the timer is enabled */
252 static int enableTimer = 0;
253
254 /* Return the current wall-clock time */
@@ -707,10 +717,11 @@
707 **
708 ** The result is stored in space obtained from malloc() and must either
709 ** be freed by the caller or else passed back into this routine via the
710 ** zPrior argument for reuse.
711 */
 
712 static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
713 char *zPrompt;
714 char *zResult;
715 if( in!=0 ){
716 zResult = local_getline(zPrior, in);
@@ -726,11 +737,11 @@
726 if( zResult && *zResult ) shell_add_history(zResult);
727 #endif
728 }
729 return zResult;
730 }
731
732
733 /*
734 ** Return the value of a hexadecimal digit. Return -1 if the input
735 ** is not a hex digit.
736 */
@@ -814,11 +825,11 @@
814 ** zIn, if it was not NULL, is freed.
815 **
816 ** If the third argument, quote, is not '\0', then it is used as a
817 ** quote character for zAppend.
818 */
819 static void appendText(ShellText *p, char const *zAppend, char quote){
820 int len;
821 int i;
822 int nAppend = strlen30(zAppend);
823
824 len = nAppend+p->n+1;
@@ -1379,10 +1390,121 @@
1379 #endif /* defined(WIN32) && defined(_MSC_VER) */
1380
1381 /************************* End test_windirent.c ********************/
1382 #define dirent DIRENT
1383 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1384 /************************* Begin ../ext/misc/shathree.c ******************/
1385 /*
1386 ** 2017-03-08
1387 **
1388 ** The author disclaims copyright to this source code. In place of
@@ -2106,2333 +2228,10 @@
2106 }
2107 return rc;
2108 }
2109
2110 /************************* End ../ext/misc/shathree.c ********************/
2111 /************************* Begin ../ext/misc/fileio.c ******************/
2112 /*
2113 ** 2014-06-13
2114 **
2115 ** The author disclaims copyright to this source code. In place of
2116 ** a legal notice, here is a blessing:
2117 **
2118 ** May you do good and not evil.
2119 ** May you find forgiveness for yourself and forgive others.
2120 ** May you share freely, never taking more than you give.
2121 **
2122 ******************************************************************************
2123 **
2124 ** This SQLite extension implements SQL functions readfile() and
2125 ** writefile(), and eponymous virtual type "fsdir".
2126 **
2127 ** WRITEFILE(FILE, DATA [, MODE [, MTIME]]):
2128 **
2129 ** If neither of the optional arguments is present, then this UDF
2130 ** function writes blob DATA to file FILE. If successful, the number
2131 ** of bytes written is returned. If an error occurs, NULL is returned.
2132 **
2133 ** If the first option argument - MODE - is present, then it must
2134 ** be passed an integer value that corresponds to a POSIX mode
2135 ** value (file type + permissions, as returned in the stat.st_mode
2136 ** field by the stat() system call). Three types of files may
2137 ** be written/created:
2138 **
2139 ** regular files: (mode & 0170000)==0100000
2140 ** symbolic links: (mode & 0170000)==0120000
2141 ** directories: (mode & 0170000)==0040000
2142 **
2143 ** For a directory, the DATA is ignored. For a symbolic link, it is
2144 ** interpreted as text and used as the target of the link. For a
2145 ** regular file, it is interpreted as a blob and written into the
2146 ** named file. Regardless of the type of file, its permissions are
2147 ** set to (mode & 0777) before returning.
2148 **
2149 ** If the optional MTIME argument is present, then it is interpreted
2150 ** as an integer - the number of seconds since the unix epoch. The
2151 ** modification-time of the target file is set to this value before
2152 ** returning.
2153 **
2154 ** If three or more arguments are passed to this function and an
2155 ** error is encountered, an exception is raised.
2156 **
2157 ** READFILE(FILE):
2158 **
2159 ** Read and return the contents of file FILE (type blob) from disk.
2160 **
2161 ** FSDIR:
2162 **
2163 ** Used as follows:
2164 **
2165 ** SELECT * FROM fsdir($path [, $dir]);
2166 **
2167 ** Parameter $path is an absolute or relative pathname. If the file that it
2168 ** refers to does not exist, it is an error. If the path refers to a regular
2169 ** file or symbolic link, it returns a single row. Or, if the path refers
2170 ** to a directory, it returns one row for the directory, and one row for each
2171 ** file within the hierarchy rooted at $path.
2172 **
2173 ** Each row has the following columns:
2174 **
2175 ** name: Path to file or directory (text value).
2176 ** mode: Value of stat.st_mode for directory entry (an integer).
2177 ** mtime: Value of stat.st_mtime for directory entry (an integer).
2178 ** data: For a regular file, a blob containing the file data. For a
2179 ** symlink, a text value containing the text of the link. For a
2180 ** directory, NULL.
2181 **
2182 ** If a non-NULL value is specified for the optional $dir parameter and
2183 ** $path is a relative path, then $path is interpreted relative to $dir.
2184 ** And the paths returned in the "name" column of the table are also
2185 ** relative to directory $dir.
2186 **
2187 ** Notes on building this extension for Windows:
2188 ** Unless linked statically with the SQLite library, a preprocessor
2189 ** symbol, FILEIO_WIN32_DLL, must be #define'd to create a stand-alone
2190 ** DLL form of this extension for WIN32. See its use below for details.
2191 */
2192 /* #include "sqlite3ext.h" */
2193 SQLITE_EXTENSION_INIT1
2194 #include <stdio.h>
2195 #include <string.h>
2196 #include <assert.h>
2197
2198 #include <sys/types.h>
2199 #include <sys/stat.h>
2200 #include <fcntl.h>
2201 #if !defined(_WIN32) && !defined(WIN32)
2202 # include <unistd.h>
2203 # include <dirent.h>
2204 # include <utime.h>
2205 # include <sys/time.h>
2206 #else
2207 # include "windows.h"
2208 # include <io.h>
2209 # include <direct.h>
2210 /* # include "test_windirent.h" */
2211 # define dirent DIRENT
2212 # ifndef chmod
2213 # define chmod _chmod
2214 # endif
2215 # ifndef stat
2216 # define stat _stat
2217 # endif
2218 # define mkdir(path,mode) _mkdir(path)
2219 # define lstat(path,buf) stat(path,buf)
2220 #endif
2221 #include <time.h>
2222 #include <errno.h>
2223
2224
2225 /*
2226 ** Structure of the fsdir() table-valued function
2227 */
2228 /* 0 1 2 3 4 5 */
2229 #define FSDIR_SCHEMA "(name,mode,mtime,data,path HIDDEN,dir HIDDEN)"
2230 #define FSDIR_COLUMN_NAME 0 /* Name of the file */
2231 #define FSDIR_COLUMN_MODE 1 /* Access mode */
2232 #define FSDIR_COLUMN_MTIME 2 /* Last modification time */
2233 #define FSDIR_COLUMN_DATA 3 /* File content */
2234 #define FSDIR_COLUMN_PATH 4 /* Path to top of search */
2235 #define FSDIR_COLUMN_DIR 5 /* Path is relative to this directory */
2236
2237
2238 /*
2239 ** Set the result stored by context ctx to a blob containing the
2240 ** contents of file zName. Or, leave the result unchanged (NULL)
2241 ** if the file does not exist or is unreadable.
2242 **
2243 ** If the file exceeds the SQLite blob size limit, through an
2244 ** SQLITE_TOOBIG error.
2245 **
2246 ** Throw an SQLITE_IOERR if there are difficulties pulling the file
2247 ** off of disk.
2248 */
2249 static void readFileContents(sqlite3_context *ctx, const char *zName){
2250 FILE *in;
2251 sqlite3_int64 nIn;
2252 void *pBuf;
2253 sqlite3 *db;
2254 int mxBlob;
2255
2256 in = fopen(zName, "rb");
2257 if( in==0 ){
2258 /* File does not exist or is unreadable. Leave the result set to NULL. */
2259 return;
2260 }
2261 fseek(in, 0, SEEK_END);
2262 nIn = ftell(in);
2263 rewind(in);
2264 db = sqlite3_context_db_handle(ctx);
2265 mxBlob = sqlite3_limit(db, SQLITE_LIMIT_LENGTH, -1);
2266 if( nIn>mxBlob ){
2267 sqlite3_result_error_code(ctx, SQLITE_TOOBIG);
2268 fclose(in);
2269 return;
2270 }
2271 pBuf = sqlite3_malloc64( nIn ? nIn : 1 );
2272 if( pBuf==0 ){
2273 sqlite3_result_error_nomem(ctx);
2274 fclose(in);
2275 return;
2276 }
2277 if( nIn==(sqlite3_int64)fread(pBuf, 1, (size_t)nIn, in) ){
2278 sqlite3_result_blob64(ctx, pBuf, nIn, sqlite3_free);
2279 }else{
2280 sqlite3_result_error_code(ctx, SQLITE_IOERR);
2281 sqlite3_free(pBuf);
2282 }
2283 fclose(in);
2284 }
2285
2286 /*
2287 ** Implementation of the "readfile(X)" SQL function. The entire content
2288 ** of the file named X is read and returned as a BLOB. NULL is returned
2289 ** if the file does not exist or is unreadable.
2290 */
2291 static void readfileFunc(
2292 sqlite3_context *context,
2293 int argc,
2294 sqlite3_value **argv
2295 ){
2296 const char *zName;
2297 (void)(argc); /* Unused parameter */
2298 zName = (const char*)sqlite3_value_text(argv[0]);
2299 if( zName==0 ) return;
2300 readFileContents(context, zName);
2301 }
2302
2303 /*
2304 ** Set the error message contained in context ctx to the results of
2305 ** vprintf(zFmt, ...).
2306 */
2307 static void ctxErrorMsg(sqlite3_context *ctx, const char *zFmt, ...){
2308 char *zMsg = 0;
2309 va_list ap;
2310 va_start(ap, zFmt);
2311 zMsg = sqlite3_vmprintf(zFmt, ap);
2312 sqlite3_result_error(ctx, zMsg, -1);
2313 sqlite3_free(zMsg);
2314 va_end(ap);
2315 }
2316
2317 #if defined(_WIN32)
2318 /*
2319 ** This function is designed to convert a Win32 FILETIME structure into the
2320 ** number of seconds since the Unix Epoch (1970-01-01 00:00:00 UTC).
2321 */
2322 static sqlite3_uint64 fileTimeToUnixTime(
2323 LPFILETIME pFileTime
2324 ){
2325 SYSTEMTIME epochSystemTime;
2326 ULARGE_INTEGER epochIntervals;
2327 FILETIME epochFileTime;
2328 ULARGE_INTEGER fileIntervals;
2329
2330 memset(&epochSystemTime, 0, sizeof(SYSTEMTIME));
2331 epochSystemTime.wYear = 1970;
2332 epochSystemTime.wMonth = 1;
2333 epochSystemTime.wDay = 1;
2334 SystemTimeToFileTime(&epochSystemTime, &epochFileTime);
2335 epochIntervals.LowPart = epochFileTime.dwLowDateTime;
2336 epochIntervals.HighPart = epochFileTime.dwHighDateTime;
2337
2338 fileIntervals.LowPart = pFileTime->dwLowDateTime;
2339 fileIntervals.HighPart = pFileTime->dwHighDateTime;
2340
2341 return (fileIntervals.QuadPart - epochIntervals.QuadPart) / 10000000;
2342 }
2343
2344
2345 #if defined(FILEIO_WIN32_DLL) && (defined(_WIN32) || defined(WIN32))
2346 # /* To allow a standalone DLL, use this next replacement function: */
2347 # undef sqlite3_win32_utf8_to_unicode
2348 # define sqlite3_win32_utf8_to_unicode utf8_to_utf16
2349 #
2350 LPWSTR utf8_to_utf16(const char *z){
2351 int nAllot = MultiByteToWideChar(CP_UTF8, 0, z, -1, NULL, 0);
2352 LPWSTR rv = sqlite3_malloc(nAllot * sizeof(WCHAR));
2353 if( rv!=0 && 0 < MultiByteToWideChar(CP_UTF8, 0, z, -1, rv, nAllot) )
2354 return rv;
2355 sqlite3_free(rv);
2356 return 0;
2357 }
2358 #endif
2359
2360 /*
2361 ** This function attempts to normalize the time values found in the stat()
2362 ** buffer to UTC. This is necessary on Win32, where the runtime library
2363 ** appears to return these values as local times.
2364 */
2365 static void statTimesToUtc(
2366 const char *zPath,
2367 struct stat *pStatBuf
2368 ){
2369 HANDLE hFindFile;
2370 WIN32_FIND_DATAW fd;
2371 LPWSTR zUnicodeName;
2372 extern LPWSTR sqlite3_win32_utf8_to_unicode(const char*);
2373 zUnicodeName = sqlite3_win32_utf8_to_unicode(zPath);
2374 if( zUnicodeName ){
2375 memset(&fd, 0, sizeof(WIN32_FIND_DATAW));
2376 hFindFile = FindFirstFileW(zUnicodeName, &fd);
2377 if( hFindFile!=NULL ){
2378 pStatBuf->st_ctime = (time_t)fileTimeToUnixTime(&fd.ftCreationTime);
2379 pStatBuf->st_atime = (time_t)fileTimeToUnixTime(&fd.ftLastAccessTime);
2380 pStatBuf->st_mtime = (time_t)fileTimeToUnixTime(&fd.ftLastWriteTime);
2381 FindClose(hFindFile);
2382 }
2383 sqlite3_free(zUnicodeName);
2384 }
2385 }
2386 #endif
2387
2388 /*
2389 ** This function is used in place of stat(). On Windows, special handling
2390 ** is required in order for the included time to be returned as UTC. On all
2391 ** other systems, this function simply calls stat().
2392 */
2393 static int fileStat(
2394 const char *zPath,
2395 struct stat *pStatBuf
2396 ){
2397 #if defined(_WIN32)
2398 int rc = stat(zPath, pStatBuf);
2399 if( rc==0 ) statTimesToUtc(zPath, pStatBuf);
2400 return rc;
2401 #else
2402 return stat(zPath, pStatBuf);
2403 #endif
2404 }
2405
2406 /*
2407 ** This function is used in place of lstat(). On Windows, special handling
2408 ** is required in order for the included time to be returned as UTC. On all
2409 ** other systems, this function simply calls lstat().
2410 */
2411 static int fileLinkStat(
2412 const char *zPath,
2413 struct stat *pStatBuf
2414 ){
2415 #if defined(_WIN32)
2416 int rc = lstat(zPath, pStatBuf);
2417 if( rc==0 ) statTimesToUtc(zPath, pStatBuf);
2418 return rc;
2419 #else
2420 return lstat(zPath, pStatBuf);
2421 #endif
2422 }
2423
2424 /*
2425 ** Argument zFile is the name of a file that will be created and/or written
2426 ** by SQL function writefile(). This function ensures that the directory
2427 ** zFile will be written to exists, creating it if required. The permissions
2428 ** for any path components created by this function are set in accordance
2429 ** with the current umask.
2430 **
2431 ** If an OOM condition is encountered, SQLITE_NOMEM is returned. Otherwise,
2432 ** SQLITE_OK is returned if the directory is successfully created, or
2433 ** SQLITE_ERROR otherwise.
2434 */
2435 static int makeDirectory(
2436 const char *zFile
2437 ){
2438 char *zCopy = sqlite3_mprintf("%s", zFile);
2439 int rc = SQLITE_OK;
2440
2441 if( zCopy==0 ){
2442 rc = SQLITE_NOMEM;
2443 }else{
2444 int nCopy = (int)strlen(zCopy);
2445 int i = 1;
2446
2447 while( rc==SQLITE_OK ){
2448 struct stat sStat;
2449 int rc2;
2450
2451 for(; zCopy[i]!='/' && i<nCopy; i++);
2452 if( i==nCopy ) break;
2453 zCopy[i] = '\0';
2454
2455 rc2 = fileStat(zCopy, &sStat);
2456 if( rc2!=0 ){
2457 if( mkdir(zCopy, 0777) ) rc = SQLITE_ERROR;
2458 }else{
2459 if( !S_ISDIR(sStat.st_mode) ) rc = SQLITE_ERROR;
2460 }
2461 zCopy[i] = '/';
2462 i++;
2463 }
2464
2465 sqlite3_free(zCopy);
2466 }
2467
2468 return rc;
2469 }
2470
2471 /*
2472 ** This function does the work for the writefile() UDF. Refer to
2473 ** header comments at the top of this file for details.
2474 */
2475 static int writeFile(
2476 sqlite3_context *pCtx, /* Context to return bytes written in */
2477 const char *zFile, /* File to write */
2478 sqlite3_value *pData, /* Data to write */
2479 mode_t mode, /* MODE parameter passed to writefile() */
2480 sqlite3_int64 mtime /* MTIME parameter (or -1 to not set time) */
2481 ){
2482 if( zFile==0 ) return 1;
2483 #if !defined(_WIN32) && !defined(WIN32)
2484 if( S_ISLNK(mode) ){
2485 const char *zTo = (const char*)sqlite3_value_text(pData);
2486 if( zTo==0 || symlink(zTo, zFile)<0 ) return 1;
2487 }else
2488 #endif
2489 {
2490 if( S_ISDIR(mode) ){
2491 if( mkdir(zFile, mode) ){
2492 /* The mkdir() call to create the directory failed. This might not
2493 ** be an error though - if there is already a directory at the same
2494 ** path and either the permissions already match or can be changed
2495 ** to do so using chmod(), it is not an error. */
2496 struct stat sStat;
2497 if( errno!=EEXIST
2498 || 0!=fileStat(zFile, &sStat)
2499 || !S_ISDIR(sStat.st_mode)
2500 || ((sStat.st_mode&0777)!=(mode&0777) && 0!=chmod(zFile, mode&0777))
2501 ){
2502 return 1;
2503 }
2504 }
2505 }else{
2506 sqlite3_int64 nWrite = 0;
2507 const char *z;
2508 int rc = 0;
2509 FILE *out = fopen(zFile, "wb");
2510 if( out==0 ) return 1;
2511 z = (const char*)sqlite3_value_blob(pData);
2512 if( z ){
2513 sqlite3_int64 n = fwrite(z, 1, sqlite3_value_bytes(pData), out);
2514 nWrite = sqlite3_value_bytes(pData);
2515 if( nWrite!=n ){
2516 rc = 1;
2517 }
2518 }
2519 fclose(out);
2520 if( rc==0 && mode && chmod(zFile, mode & 0777) ){
2521 rc = 1;
2522 }
2523 if( rc ) return 2;
2524 sqlite3_result_int64(pCtx, nWrite);
2525 }
2526 }
2527
2528 if( mtime>=0 ){
2529 #if defined(_WIN32)
2530 #if !SQLITE_OS_WINRT
2531 /* Windows */
2532 FILETIME lastAccess;
2533 FILETIME lastWrite;
2534 SYSTEMTIME currentTime;
2535 LONGLONG intervals;
2536 HANDLE hFile;
2537 LPWSTR zUnicodeName;
2538 extern LPWSTR sqlite3_win32_utf8_to_unicode(const char*);
2539
2540 GetSystemTime(&currentTime);
2541 SystemTimeToFileTime(&currentTime, &lastAccess);
2542 intervals = Int32x32To64(mtime, 10000000) + 116444736000000000;
2543 lastWrite.dwLowDateTime = (DWORD)intervals;
2544 lastWrite.dwHighDateTime = intervals >> 32;
2545 zUnicodeName = sqlite3_win32_utf8_to_unicode(zFile);
2546 if( zUnicodeName==0 ){
2547 return 1;
2548 }
2549 hFile = CreateFileW(
2550 zUnicodeName, FILE_WRITE_ATTRIBUTES, 0, NULL, OPEN_EXISTING,
2551 FILE_FLAG_BACKUP_SEMANTICS, NULL
2552 );
2553 sqlite3_free(zUnicodeName);
2554 if( hFile!=INVALID_HANDLE_VALUE ){
2555 BOOL bResult = SetFileTime(hFile, NULL, &lastAccess, &lastWrite);
2556 CloseHandle(hFile);
2557 return !bResult;
2558 }else{
2559 return 1;
2560 }
2561 #endif
2562 #elif defined(AT_FDCWD) && 0 /* utimensat() is not universally available */
2563 /* Recent unix */
2564 struct timespec times[2];
2565 times[0].tv_nsec = times[1].tv_nsec = 0;
2566 times[0].tv_sec = time(0);
2567 times[1].tv_sec = mtime;
2568 if( utimensat(AT_FDCWD, zFile, times, AT_SYMLINK_NOFOLLOW) ){
2569 return 1;
2570 }
2571 #else
2572 /* Legacy unix */
2573 struct timeval times[2];
2574 times[0].tv_usec = times[1].tv_usec = 0;
2575 times[0].tv_sec = time(0);
2576 times[1].tv_sec = mtime;
2577 if( utimes(zFile, times) ){
2578 return 1;
2579 }
2580 #endif
2581 }
2582
2583 return 0;
2584 }
2585
2586 /*
2587 ** Implementation of the "writefile(W,X[,Y[,Z]]])" SQL function.
2588 ** Refer to header comments at the top of this file for details.
2589 */
2590 static void writefileFunc(
2591 sqlite3_context *context,
2592 int argc,
2593 sqlite3_value **argv
2594 ){
2595 const char *zFile;
2596 mode_t mode = 0;
2597 int res;
2598 sqlite3_int64 mtime = -1;
2599
2600 if( argc<2 || argc>4 ){
2601 sqlite3_result_error(context,
2602 "wrong number of arguments to function writefile()", -1
2603 );
2604 return;
2605 }
2606
2607 zFile = (const char*)sqlite3_value_text(argv[0]);
2608 if( zFile==0 ) return;
2609 if( argc>=3 ){
2610 mode = (mode_t)sqlite3_value_int(argv[2]);
2611 }
2612 if( argc==4 ){
2613 mtime = sqlite3_value_int64(argv[3]);
2614 }
2615
2616 res = writeFile(context, zFile, argv[1], mode, mtime);
2617 if( res==1 && errno==ENOENT ){
2618 if( makeDirectory(zFile)==SQLITE_OK ){
2619 res = writeFile(context, zFile, argv[1], mode, mtime);
2620 }
2621 }
2622
2623 if( argc>2 && res!=0 ){
2624 if( S_ISLNK(mode) ){
2625 ctxErrorMsg(context, "failed to create symlink: %s", zFile);
2626 }else if( S_ISDIR(mode) ){
2627 ctxErrorMsg(context, "failed to create directory: %s", zFile);
2628 }else{
2629 ctxErrorMsg(context, "failed to write file: %s", zFile);
2630 }
2631 }
2632 }
2633
2634 /*
2635 ** SQL function: lsmode(MODE)
2636 **
2637 ** Given a numberic st_mode from stat(), convert it into a human-readable
2638 ** text string in the style of "ls -l".
2639 */
2640 static void lsModeFunc(
2641 sqlite3_context *context,
2642 int argc,
2643 sqlite3_value **argv
2644 ){
2645 int i;
2646 int iMode = sqlite3_value_int(argv[0]);
2647 char z[16];
2648 (void)argc;
2649 if( S_ISLNK(iMode) ){
2650 z[0] = 'l';
2651 }else if( S_ISREG(iMode) ){
2652 z[0] = '-';
2653 }else if( S_ISDIR(iMode) ){
2654 z[0] = 'd';
2655 }else{
2656 z[0] = '?';
2657 }
2658 for(i=0; i<3; i++){
2659 int m = (iMode >> ((2-i)*3));
2660 char *a = &z[1 + i*3];
2661 a[0] = (m & 0x4) ? 'r' : '-';
2662 a[1] = (m & 0x2) ? 'w' : '-';
2663 a[2] = (m & 0x1) ? 'x' : '-';
2664 }
2665 z[10] = '\0';
2666 sqlite3_result_text(context, z, -1, SQLITE_TRANSIENT);
2667 }
2668
2669 #ifndef SQLITE_OMIT_VIRTUALTABLE
2670
2671 /*
2672 ** Cursor type for recursively iterating through a directory structure.
2673 */
2674 typedef struct fsdir_cursor fsdir_cursor;
2675 typedef struct FsdirLevel FsdirLevel;
2676
2677 struct FsdirLevel {
2678 DIR *pDir; /* From opendir() */
2679 char *zDir; /* Name of directory (nul-terminated) */
2680 };
2681
2682 struct fsdir_cursor {
2683 sqlite3_vtab_cursor base; /* Base class - must be first */
2684
2685 int nLvl; /* Number of entries in aLvl[] array */
2686 int iLvl; /* Index of current entry */
2687 FsdirLevel *aLvl; /* Hierarchy of directories being traversed */
2688
2689 const char *zBase;
2690 int nBase;
2691
2692 struct stat sStat; /* Current lstat() results */
2693 char *zPath; /* Path to current entry */
2694 sqlite3_int64 iRowid; /* Current rowid */
2695 };
2696
2697 typedef struct fsdir_tab fsdir_tab;
2698 struct fsdir_tab {
2699 sqlite3_vtab base; /* Base class - must be first */
2700 };
2701
2702 /*
2703 ** Construct a new fsdir virtual table object.
2704 */
2705 static int fsdirConnect(
2706 sqlite3 *db,
2707 void *pAux,
2708 int argc, const char *const*argv,
2709 sqlite3_vtab **ppVtab,
2710 char **pzErr
2711 ){
2712 fsdir_tab *pNew = 0;
2713 int rc;
2714 (void)pAux;
2715 (void)argc;
2716 (void)argv;
2717 (void)pzErr;
2718 rc = sqlite3_declare_vtab(db, "CREATE TABLE x" FSDIR_SCHEMA);
2719 if( rc==SQLITE_OK ){
2720 pNew = (fsdir_tab*)sqlite3_malloc( sizeof(*pNew) );
2721 if( pNew==0 ) return SQLITE_NOMEM;
2722 memset(pNew, 0, sizeof(*pNew));
2723 sqlite3_vtab_config(db, SQLITE_VTAB_DIRECTONLY);
2724 }
2725 *ppVtab = (sqlite3_vtab*)pNew;
2726 return rc;
2727 }
2728
2729 /*
2730 ** This method is the destructor for fsdir vtab objects.
2731 */
2732 static int fsdirDisconnect(sqlite3_vtab *pVtab){
2733 sqlite3_free(pVtab);
2734 return SQLITE_OK;
2735 }
2736
2737 /*
2738 ** Constructor for a new fsdir_cursor object.
2739 */
2740 static int fsdirOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
2741 fsdir_cursor *pCur;
2742 (void)p;
2743 pCur = sqlite3_malloc( sizeof(*pCur) );
2744 if( pCur==0 ) return SQLITE_NOMEM;
2745 memset(pCur, 0, sizeof(*pCur));
2746 pCur->iLvl = -1;
2747 *ppCursor = &pCur->base;
2748 return SQLITE_OK;
2749 }
2750
2751 /*
2752 ** Reset a cursor back to the state it was in when first returned
2753 ** by fsdirOpen().
2754 */
2755 static void fsdirResetCursor(fsdir_cursor *pCur){
2756 int i;
2757 for(i=0; i<=pCur->iLvl; i++){
2758 FsdirLevel *pLvl = &pCur->aLvl[i];
2759 if( pLvl->pDir ) closedir(pLvl->pDir);
2760 sqlite3_free(pLvl->zDir);
2761 }
2762 sqlite3_free(pCur->zPath);
2763 sqlite3_free(pCur->aLvl);
2764 pCur->aLvl = 0;
2765 pCur->zPath = 0;
2766 pCur->zBase = 0;
2767 pCur->nBase = 0;
2768 pCur->nLvl = 0;
2769 pCur->iLvl = -1;
2770 pCur->iRowid = 1;
2771 }
2772
2773 /*
2774 ** Destructor for an fsdir_cursor.
2775 */
2776 static int fsdirClose(sqlite3_vtab_cursor *cur){
2777 fsdir_cursor *pCur = (fsdir_cursor*)cur;
2778
2779 fsdirResetCursor(pCur);
2780 sqlite3_free(pCur);
2781 return SQLITE_OK;
2782 }
2783
2784 /*
2785 ** Set the error message for the virtual table associated with cursor
2786 ** pCur to the results of vprintf(zFmt, ...).
2787 */
2788 static void fsdirSetErrmsg(fsdir_cursor *pCur, const char *zFmt, ...){
2789 va_list ap;
2790 va_start(ap, zFmt);
2791 pCur->base.pVtab->zErrMsg = sqlite3_vmprintf(zFmt, ap);
2792 va_end(ap);
2793 }
2794
2795
2796 /*
2797 ** Advance an fsdir_cursor to its next row of output.
2798 */
2799 static int fsdirNext(sqlite3_vtab_cursor *cur){
2800 fsdir_cursor *pCur = (fsdir_cursor*)cur;
2801 mode_t m = pCur->sStat.st_mode;
2802
2803 pCur->iRowid++;
2804 if( S_ISDIR(m) ){
2805 /* Descend into this directory */
2806 int iNew = pCur->iLvl + 1;
2807 FsdirLevel *pLvl;
2808 if( iNew>=pCur->nLvl ){
2809 int nNew = iNew+1;
2810 sqlite3_int64 nByte = nNew*sizeof(FsdirLevel);
2811 FsdirLevel *aNew = (FsdirLevel*)sqlite3_realloc64(pCur->aLvl, nByte);
2812 if( aNew==0 ) return SQLITE_NOMEM;
2813 memset(&aNew[pCur->nLvl], 0, sizeof(FsdirLevel)*(nNew-pCur->nLvl));
2814 pCur->aLvl = aNew;
2815 pCur->nLvl = nNew;
2816 }
2817 pCur->iLvl = iNew;
2818 pLvl = &pCur->aLvl[iNew];
2819
2820 pLvl->zDir = pCur->zPath;
2821 pCur->zPath = 0;
2822 pLvl->pDir = opendir(pLvl->zDir);
2823 if( pLvl->pDir==0 ){
2824 fsdirSetErrmsg(pCur, "cannot read directory: %s", pCur->zPath);
2825 return SQLITE_ERROR;
2826 }
2827 }
2828
2829 while( pCur->iLvl>=0 ){
2830 FsdirLevel *pLvl = &pCur->aLvl[pCur->iLvl];
2831 struct dirent *pEntry = readdir(pLvl->pDir);
2832 if( pEntry ){
2833 if( pEntry->d_name[0]=='.' ){
2834 if( pEntry->d_name[1]=='.' && pEntry->d_name[2]=='\0' ) continue;
2835 if( pEntry->d_name[1]=='\0' ) continue;
2836 }
2837 sqlite3_free(pCur->zPath);
2838 pCur->zPath = sqlite3_mprintf("%s/%s", pLvl->zDir, pEntry->d_name);
2839 if( pCur->zPath==0 ) return SQLITE_NOMEM;
2840 if( fileLinkStat(pCur->zPath, &pCur->sStat) ){
2841 fsdirSetErrmsg(pCur, "cannot stat file: %s", pCur->zPath);
2842 return SQLITE_ERROR;
2843 }
2844 return SQLITE_OK;
2845 }
2846 closedir(pLvl->pDir);
2847 sqlite3_free(pLvl->zDir);
2848 pLvl->pDir = 0;
2849 pLvl->zDir = 0;
2850 pCur->iLvl--;
2851 }
2852
2853 /* EOF */
2854 sqlite3_free(pCur->zPath);
2855 pCur->zPath = 0;
2856 return SQLITE_OK;
2857 }
2858
2859 /*
2860 ** Return values of columns for the row at which the series_cursor
2861 ** is currently pointing.
2862 */
2863 static int fsdirColumn(
2864 sqlite3_vtab_cursor *cur, /* The cursor */
2865 sqlite3_context *ctx, /* First argument to sqlite3_result_...() */
2866 int i /* Which column to return */
2867 ){
2868 fsdir_cursor *pCur = (fsdir_cursor*)cur;
2869 switch( i ){
2870 case FSDIR_COLUMN_NAME: {
2871 sqlite3_result_text(ctx, &pCur->zPath[pCur->nBase], -1, SQLITE_TRANSIENT);
2872 break;
2873 }
2874
2875 case FSDIR_COLUMN_MODE:
2876 sqlite3_result_int64(ctx, pCur->sStat.st_mode);
2877 break;
2878
2879 case FSDIR_COLUMN_MTIME:
2880 sqlite3_result_int64(ctx, pCur->sStat.st_mtime);
2881 break;
2882
2883 case FSDIR_COLUMN_DATA: {
2884 mode_t m = pCur->sStat.st_mode;
2885 if( S_ISDIR(m) ){
2886 sqlite3_result_null(ctx);
2887 #if !defined(_WIN32) && !defined(WIN32)
2888 }else if( S_ISLNK(m) ){
2889 char aStatic[64];
2890 char *aBuf = aStatic;
2891 sqlite3_int64 nBuf = 64;
2892 int n;
2893
2894 while( 1 ){
2895 n = readlink(pCur->zPath, aBuf, nBuf);
2896 if( n<nBuf ) break;
2897 if( aBuf!=aStatic ) sqlite3_free(aBuf);
2898 nBuf = nBuf*2;
2899 aBuf = sqlite3_malloc64(nBuf);
2900 if( aBuf==0 ){
2901 sqlite3_result_error_nomem(ctx);
2902 return SQLITE_NOMEM;
2903 }
2904 }
2905
2906 sqlite3_result_text(ctx, aBuf, n, SQLITE_TRANSIENT);
2907 if( aBuf!=aStatic ) sqlite3_free(aBuf);
2908 #endif
2909 }else{
2910 readFileContents(ctx, pCur->zPath);
2911 }
2912 }
2913 case FSDIR_COLUMN_PATH:
2914 default: {
2915 /* The FSDIR_COLUMN_PATH and FSDIR_COLUMN_DIR are input parameters.
2916 ** always return their values as NULL */
2917 break;
2918 }
2919 }
2920 return SQLITE_OK;
2921 }
2922
2923 /*
2924 ** Return the rowid for the current row. In this implementation, the
2925 ** first row returned is assigned rowid value 1, and each subsequent
2926 ** row a value 1 more than that of the previous.
2927 */
2928 static int fsdirRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
2929 fsdir_cursor *pCur = (fsdir_cursor*)cur;
2930 *pRowid = pCur->iRowid;
2931 return SQLITE_OK;
2932 }
2933
2934 /*
2935 ** Return TRUE if the cursor has been moved off of the last
2936 ** row of output.
2937 */
2938 static int fsdirEof(sqlite3_vtab_cursor *cur){
2939 fsdir_cursor *pCur = (fsdir_cursor*)cur;
2940 return (pCur->zPath==0);
2941 }
2942
2943 /*
2944 ** xFilter callback.
2945 **
2946 ** idxNum==1 PATH parameter only
2947 ** idxNum==2 Both PATH and DIR supplied
2948 */
2949 static int fsdirFilter(
2950 sqlite3_vtab_cursor *cur,
2951 int idxNum, const char *idxStr,
2952 int argc, sqlite3_value **argv
2953 ){
2954 const char *zDir = 0;
2955 fsdir_cursor *pCur = (fsdir_cursor*)cur;
2956 (void)idxStr;
2957 fsdirResetCursor(pCur);
2958
2959 if( idxNum==0 ){
2960 fsdirSetErrmsg(pCur, "table function fsdir requires an argument");
2961 return SQLITE_ERROR;
2962 }
2963
2964 assert( argc==idxNum && (argc==1 || argc==2) );
2965 zDir = (const char*)sqlite3_value_text(argv[0]);
2966 if( zDir==0 ){
2967 fsdirSetErrmsg(pCur, "table function fsdir requires a non-NULL argument");
2968 return SQLITE_ERROR;
2969 }
2970 if( argc==2 ){
2971 pCur->zBase = (const char*)sqlite3_value_text(argv[1]);
2972 }
2973 if( pCur->zBase ){
2974 pCur->nBase = (int)strlen(pCur->zBase)+1;
2975 pCur->zPath = sqlite3_mprintf("%s/%s", pCur->zBase, zDir);
2976 }else{
2977 pCur->zPath = sqlite3_mprintf("%s", zDir);
2978 }
2979
2980 if( pCur->zPath==0 ){
2981 return SQLITE_NOMEM;
2982 }
2983 if( fileLinkStat(pCur->zPath, &pCur->sStat) ){
2984 fsdirSetErrmsg(pCur, "cannot stat file: %s", pCur->zPath);
2985 return SQLITE_ERROR;
2986 }
2987
2988 return SQLITE_OK;
2989 }
2990
2991 /*
2992 ** SQLite will invoke this method one or more times while planning a query
2993 ** that uses the generate_series virtual table. This routine needs to create
2994 ** a query plan for each invocation and compute an estimated cost for that
2995 ** plan.
2996 **
2997 ** In this implementation idxNum is used to represent the
2998 ** query plan. idxStr is unused.
2999 **
3000 ** The query plan is represented by values of idxNum:
3001 **
3002 ** (1) The path value is supplied by argv[0]
3003 ** (2) Path is in argv[0] and dir is in argv[1]
3004 */
3005 static int fsdirBestIndex(
3006 sqlite3_vtab *tab,
3007 sqlite3_index_info *pIdxInfo
3008 ){
3009 int i; /* Loop over constraints */
3010 int idxPath = -1; /* Index in pIdxInfo->aConstraint of PATH= */
3011 int idxDir = -1; /* Index in pIdxInfo->aConstraint of DIR= */
3012 int seenPath = 0; /* True if an unusable PATH= constraint is seen */
3013 int seenDir = 0; /* True if an unusable DIR= constraint is seen */
3014 const struct sqlite3_index_constraint *pConstraint;
3015
3016 (void)tab;
3017 pConstraint = pIdxInfo->aConstraint;
3018 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
3019 if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
3020 switch( pConstraint->iColumn ){
3021 case FSDIR_COLUMN_PATH: {
3022 if( pConstraint->usable ){
3023 idxPath = i;
3024 seenPath = 0;
3025 }else if( idxPath<0 ){
3026 seenPath = 1;
3027 }
3028 break;
3029 }
3030 case FSDIR_COLUMN_DIR: {
3031 if( pConstraint->usable ){
3032 idxDir = i;
3033 seenDir = 0;
3034 }else if( idxDir<0 ){
3035 seenDir = 1;
3036 }
3037 break;
3038 }
3039 }
3040 }
3041 if( seenPath || seenDir ){
3042 /* If input parameters are unusable, disallow this plan */
3043 return SQLITE_CONSTRAINT;
3044 }
3045
3046 if( idxPath<0 ){
3047 pIdxInfo->idxNum = 0;
3048 /* The pIdxInfo->estimatedCost should have been initialized to a huge
3049 ** number. Leave it unchanged. */
3050 pIdxInfo->estimatedRows = 0x7fffffff;
3051 }else{
3052 pIdxInfo->aConstraintUsage[idxPath].omit = 1;
3053 pIdxInfo->aConstraintUsage[idxPath].argvIndex = 1;
3054 if( idxDir>=0 ){
3055 pIdxInfo->aConstraintUsage[idxDir].omit = 1;
3056 pIdxInfo->aConstraintUsage[idxDir].argvIndex = 2;
3057 pIdxInfo->idxNum = 2;
3058 pIdxInfo->estimatedCost = 10.0;
3059 }else{
3060 pIdxInfo->idxNum = 1;
3061 pIdxInfo->estimatedCost = 100.0;
3062 }
3063 }
3064
3065 return SQLITE_OK;
3066 }
3067
3068 /*
3069 ** Register the "fsdir" virtual table.
3070 */
3071 static int fsdirRegister(sqlite3 *db){
3072 static sqlite3_module fsdirModule = {
3073 0, /* iVersion */
3074 0, /* xCreate */
3075 fsdirConnect, /* xConnect */
3076 fsdirBestIndex, /* xBestIndex */
3077 fsdirDisconnect, /* xDisconnect */
3078 0, /* xDestroy */
3079 fsdirOpen, /* xOpen - open a cursor */
3080 fsdirClose, /* xClose - close a cursor */
3081 fsdirFilter, /* xFilter - configure scan constraints */
3082 fsdirNext, /* xNext - advance a cursor */
3083 fsdirEof, /* xEof - check for end of scan */
3084 fsdirColumn, /* xColumn - read data */
3085 fsdirRowid, /* xRowid - read data */
3086 0, /* xUpdate */
3087 0, /* xBegin */
3088 0, /* xSync */
3089 0, /* xCommit */
3090 0, /* xRollback */
3091 0, /* xFindMethod */
3092 0, /* xRename */
3093 0, /* xSavepoint */
3094 0, /* xRelease */
3095 0, /* xRollbackTo */
3096 0, /* xShadowName */
3097 };
3098
3099 int rc = sqlite3_create_module(db, "fsdir", &fsdirModule, 0);
3100 return rc;
3101 }
3102 #else /* SQLITE_OMIT_VIRTUALTABLE */
3103 # define fsdirRegister(x) SQLITE_OK
3104 #endif
3105
3106 #ifdef _WIN32
3107
3108 #endif
3109 int sqlite3_fileio_init(
3110 sqlite3 *db,
3111 char **pzErrMsg,
3112 const sqlite3_api_routines *pApi
3113 ){
3114 int rc = SQLITE_OK;
3115 SQLITE_EXTENSION_INIT2(pApi);
3116 (void)pzErrMsg; /* Unused parameter */
3117 rc = sqlite3_create_function(db, "readfile", 1,
3118 SQLITE_UTF8|SQLITE_DIRECTONLY, 0,
3119 readfileFunc, 0, 0);
3120 if( rc==SQLITE_OK ){
3121 rc = sqlite3_create_function(db, "writefile", -1,
3122 SQLITE_UTF8|SQLITE_DIRECTONLY, 0,
3123 writefileFunc, 0, 0);
3124 }
3125 if( rc==SQLITE_OK ){
3126 rc = sqlite3_create_function(db, "lsmode", 1, SQLITE_UTF8, 0,
3127 lsModeFunc, 0, 0);
3128 }
3129 if( rc==SQLITE_OK ){
3130 rc = fsdirRegister(db);
3131 }
3132 return rc;
3133 }
3134
3135 #if defined(FILEIO_WIN32_DLL) && (defined(_WIN32) || defined(WIN32))
3136 /* To allow a standalone DLL, make test_windirent.c use the same
3137 * redefined SQLite API calls as the above extension code does.
3138 * Just pull in this .c to accomplish this. As a beneficial side
3139 * effect, this extension becomes a single translation unit. */
3140 # include "test_windirent.c"
3141 #endif
3142
3143 /************************* End ../ext/misc/fileio.c ********************/
3144 /************************* Begin ../ext/misc/completion.c ******************/
3145 /*
3146 ** 2017-07-10
3147 **
3148 ** The author disclaims copyright to this source code. In place of
3149 ** a legal notice, here is a blessing:
3150 **
3151 ** May you do good and not evil.
3152 ** May you find forgiveness for yourself and forgive others.
3153 ** May you share freely, never taking more than you give.
3154 **
3155 *************************************************************************
3156 **
3157 ** This file implements an eponymous virtual table that returns suggested
3158 ** completions for a partial SQL input.
3159 **
3160 ** Suggested usage:
3161 **
3162 ** SELECT DISTINCT candidate COLLATE nocase
3163 ** FROM completion($prefix,$wholeline)
3164 ** ORDER BY 1;
3165 **
3166 ** The two query parameters are optional. $prefix is the text of the
3167 ** current word being typed and that is to be completed. $wholeline is
3168 ** the complete input line, used for context.
3169 **
3170 ** The raw completion() table might return the same candidate multiple
3171 ** times, for example if the same column name is used to two or more
3172 ** tables. And the candidates are returned in an arbitrary order. Hence,
3173 ** the DISTINCT and ORDER BY are recommended.
3174 **
3175 ** This virtual table operates at the speed of human typing, and so there
3176 ** is no attempt to make it fast. Even a slow implementation will be much
3177 ** faster than any human can type.
3178 **
3179 */
3180 /* #include "sqlite3ext.h" */
3181 SQLITE_EXTENSION_INIT1
3182 #include <assert.h>
3183 #include <string.h>
3184 #include <ctype.h>
3185
3186 #ifndef SQLITE_OMIT_VIRTUALTABLE
3187
3188 /* completion_vtab is a subclass of sqlite3_vtab which will
3189 ** serve as the underlying representation of a completion virtual table
3190 */
3191 typedef struct completion_vtab completion_vtab;
3192 struct completion_vtab {
3193 sqlite3_vtab base; /* Base class - must be first */
3194 sqlite3 *db; /* Database connection for this completion vtab */
3195 };
3196
3197 /* completion_cursor is a subclass of sqlite3_vtab_cursor which will
3198 ** serve as the underlying representation of a cursor that scans
3199 ** over rows of the result
3200 */
3201 typedef struct completion_cursor completion_cursor;
3202 struct completion_cursor {
3203 sqlite3_vtab_cursor base; /* Base class - must be first */
3204 sqlite3 *db; /* Database connection for this cursor */
3205 int nPrefix, nLine; /* Number of bytes in zPrefix and zLine */
3206 char *zPrefix; /* The prefix for the word we want to complete */
3207 char *zLine; /* The whole that we want to complete */
3208 const char *zCurrentRow; /* Current output row */
3209 int szRow; /* Length of the zCurrentRow string */
3210 sqlite3_stmt *pStmt; /* Current statement */
3211 sqlite3_int64 iRowid; /* The rowid */
3212 int ePhase; /* Current phase */
3213 int j; /* inter-phase counter */
3214 };
3215
3216 /* Values for ePhase:
3217 */
3218 #define COMPLETION_FIRST_PHASE 1
3219 #define COMPLETION_KEYWORDS 1
3220 #define COMPLETION_PRAGMAS 2
3221 #define COMPLETION_FUNCTIONS 3
3222 #define COMPLETION_COLLATIONS 4
3223 #define COMPLETION_INDEXES 5
3224 #define COMPLETION_TRIGGERS 6
3225 #define COMPLETION_DATABASES 7
3226 #define COMPLETION_TABLES 8 /* Also VIEWs and TRIGGERs */
3227 #define COMPLETION_COLUMNS 9
3228 #define COMPLETION_MODULES 10
3229 #define COMPLETION_EOF 11
3230
3231 /*
3232 ** The completionConnect() method is invoked to create a new
3233 ** completion_vtab that describes the completion virtual table.
3234 **
3235 ** Think of this routine as the constructor for completion_vtab objects.
3236 **
3237 ** All this routine needs to do is:
3238 **
3239 ** (1) Allocate the completion_vtab object and initialize all fields.
3240 **
3241 ** (2) Tell SQLite (via the sqlite3_declare_vtab() interface) what the
3242 ** result set of queries against completion will look like.
3243 */
3244 static int completionConnect(
3245 sqlite3 *db,
3246 void *pAux,
3247 int argc, const char *const*argv,
3248 sqlite3_vtab **ppVtab,
3249 char **pzErr
3250 ){
3251 completion_vtab *pNew;
3252 int rc;
3253
3254 (void)(pAux); /* Unused parameter */
3255 (void)(argc); /* Unused parameter */
3256 (void)(argv); /* Unused parameter */
3257 (void)(pzErr); /* Unused parameter */
3258
3259 /* Column numbers */
3260 #define COMPLETION_COLUMN_CANDIDATE 0 /* Suggested completion of the input */
3261 #define COMPLETION_COLUMN_PREFIX 1 /* Prefix of the word to be completed */
3262 #define COMPLETION_COLUMN_WHOLELINE 2 /* Entire line seen so far */
3263 #define COMPLETION_COLUMN_PHASE 3 /* ePhase - used for debugging only */
3264
3265 sqlite3_vtab_config(db, SQLITE_VTAB_INNOCUOUS);
3266 rc = sqlite3_declare_vtab(db,
3267 "CREATE TABLE x("
3268 " candidate TEXT,"
3269 " prefix TEXT HIDDEN,"
3270 " wholeline TEXT HIDDEN,"
3271 " phase INT HIDDEN" /* Used for debugging only */
3272 ")");
3273 if( rc==SQLITE_OK ){
3274 pNew = sqlite3_malloc( sizeof(*pNew) );
3275 *ppVtab = (sqlite3_vtab*)pNew;
3276 if( pNew==0 ) return SQLITE_NOMEM;
3277 memset(pNew, 0, sizeof(*pNew));
3278 pNew->db = db;
3279 }
3280 return rc;
3281 }
3282
3283 /*
3284 ** This method is the destructor for completion_cursor objects.
3285 */
3286 static int completionDisconnect(sqlite3_vtab *pVtab){
3287 sqlite3_free(pVtab);
3288 return SQLITE_OK;
3289 }
3290
3291 /*
3292 ** Constructor for a new completion_cursor object.
3293 */
3294 static int completionOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
3295 completion_cursor *pCur;
3296 pCur = sqlite3_malloc( sizeof(*pCur) );
3297 if( pCur==0 ) return SQLITE_NOMEM;
3298 memset(pCur, 0, sizeof(*pCur));
3299 pCur->db = ((completion_vtab*)p)->db;
3300 *ppCursor = &pCur->base;
3301 return SQLITE_OK;
3302 }
3303
3304 /*
3305 ** Reset the completion_cursor.
3306 */
3307 static void completionCursorReset(completion_cursor *pCur){
3308 sqlite3_free(pCur->zPrefix); pCur->zPrefix = 0; pCur->nPrefix = 0;
3309 sqlite3_free(pCur->zLine); pCur->zLine = 0; pCur->nLine = 0;
3310 sqlite3_finalize(pCur->pStmt); pCur->pStmt = 0;
3311 pCur->j = 0;
3312 }
3313
3314 /*
3315 ** Destructor for a completion_cursor.
3316 */
3317 static int completionClose(sqlite3_vtab_cursor *cur){
3318 completionCursorReset((completion_cursor*)cur);
3319 sqlite3_free(cur);
3320 return SQLITE_OK;
3321 }
3322
3323 /*
3324 ** Advance a completion_cursor to its next row of output.
3325 **
3326 ** The ->ePhase, ->j, and ->pStmt fields of the completion_cursor object
3327 ** record the current state of the scan. This routine sets ->zCurrentRow
3328 ** to the current row of output and then returns. If no more rows remain,
3329 ** then ->ePhase is set to COMPLETION_EOF which will signal the virtual
3330 ** table that has reached the end of its scan.
3331 **
3332 ** The current implementation just lists potential identifiers and
3333 ** keywords and filters them by zPrefix. Future enhancements should
3334 ** take zLine into account to try to restrict the set of identifiers and
3335 ** keywords based on what would be legal at the current point of input.
3336 */
3337 static int completionNext(sqlite3_vtab_cursor *cur){
3338 completion_cursor *pCur = (completion_cursor*)cur;
3339 int eNextPhase = 0; /* Next phase to try if current phase reaches end */
3340 int iCol = -1; /* If >=0, step pCur->pStmt and use the i-th column */
3341 pCur->iRowid++;
3342 while( pCur->ePhase!=COMPLETION_EOF ){
3343 switch( pCur->ePhase ){
3344 case COMPLETION_KEYWORDS: {
3345 if( pCur->j >= sqlite3_keyword_count() ){
3346 pCur->zCurrentRow = 0;
3347 pCur->ePhase = COMPLETION_DATABASES;
3348 }else{
3349 sqlite3_keyword_name(pCur->j++, &pCur->zCurrentRow, &pCur->szRow);
3350 }
3351 iCol = -1;
3352 break;
3353 }
3354 case COMPLETION_DATABASES: {
3355 if( pCur->pStmt==0 ){
3356 sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1,
3357 &pCur->pStmt, 0);
3358 }
3359 iCol = 1;
3360 eNextPhase = COMPLETION_TABLES;
3361 break;
3362 }
3363 case COMPLETION_TABLES: {
3364 if( pCur->pStmt==0 ){
3365 sqlite3_stmt *pS2;
3366 char *zSql = 0;
3367 const char *zSep = "";
3368 sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, &pS2, 0);
3369 while( sqlite3_step(pS2)==SQLITE_ROW ){
3370 const char *zDb = (const char*)sqlite3_column_text(pS2, 1);
3371 zSql = sqlite3_mprintf(
3372 "%z%s"
3373 "SELECT name FROM \"%w\".sqlite_schema",
3374 zSql, zSep, zDb
3375 );
3376 if( zSql==0 ) return SQLITE_NOMEM;
3377 zSep = " UNION ";
3378 }
3379 sqlite3_finalize(pS2);
3380 sqlite3_prepare_v2(pCur->db, zSql, -1, &pCur->pStmt, 0);
3381 sqlite3_free(zSql);
3382 }
3383 iCol = 0;
3384 eNextPhase = COMPLETION_COLUMNS;
3385 break;
3386 }
3387 case COMPLETION_COLUMNS: {
3388 if( pCur->pStmt==0 ){
3389 sqlite3_stmt *pS2;
3390 char *zSql = 0;
3391 const char *zSep = "";
3392 sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, &pS2, 0);
3393 while( sqlite3_step(pS2)==SQLITE_ROW ){
3394 const char *zDb = (const char*)sqlite3_column_text(pS2, 1);
3395 zSql = sqlite3_mprintf(
3396 "%z%s"
3397 "SELECT pti.name FROM \"%w\".sqlite_schema AS sm"
3398 " JOIN pragma_table_info(sm.name,%Q) AS pti"
3399 " WHERE sm.type='table'",
3400 zSql, zSep, zDb, zDb
3401 );
3402 if( zSql==0 ) return SQLITE_NOMEM;
3403 zSep = " UNION ";
3404 }
3405 sqlite3_finalize(pS2);
3406 sqlite3_prepare_v2(pCur->db, zSql, -1, &pCur->pStmt, 0);
3407 sqlite3_free(zSql);
3408 }
3409 iCol = 0;
3410 eNextPhase = COMPLETION_EOF;
3411 break;
3412 }
3413 }
3414 if( iCol<0 ){
3415 /* This case is when the phase presets zCurrentRow */
3416 if( pCur->zCurrentRow==0 ) continue;
3417 }else{
3418 if( sqlite3_step(pCur->pStmt)==SQLITE_ROW ){
3419 /* Extract the next row of content */
3420 pCur->zCurrentRow = (const char*)sqlite3_column_text(pCur->pStmt, iCol);
3421 pCur->szRow = sqlite3_column_bytes(pCur->pStmt, iCol);
3422 }else{
3423 /* When all rows are finished, advance to the next phase */
3424 sqlite3_finalize(pCur->pStmt);
3425 pCur->pStmt = 0;
3426 pCur->ePhase = eNextPhase;
3427 continue;
3428 }
3429 }
3430 if( pCur->nPrefix==0 ) break;
3431 if( pCur->nPrefix<=pCur->szRow
3432 && sqlite3_strnicmp(pCur->zPrefix, pCur->zCurrentRow, pCur->nPrefix)==0
3433 ){
3434 break;
3435 }
3436 }
3437
3438 return SQLITE_OK;
3439 }
3440
3441 /*
3442 ** Return values of columns for the row at which the completion_cursor
3443 ** is currently pointing.
3444 */
3445 static int completionColumn(
3446 sqlite3_vtab_cursor *cur, /* The cursor */
3447 sqlite3_context *ctx, /* First argument to sqlite3_result_...() */
3448 int i /* Which column to return */
3449 ){
3450 completion_cursor *pCur = (completion_cursor*)cur;
3451 switch( i ){
3452 case COMPLETION_COLUMN_CANDIDATE: {
3453 sqlite3_result_text(ctx, pCur->zCurrentRow, pCur->szRow,SQLITE_TRANSIENT);
3454 break;
3455 }
3456 case COMPLETION_COLUMN_PREFIX: {
3457 sqlite3_result_text(ctx, pCur->zPrefix, -1, SQLITE_TRANSIENT);
3458 break;
3459 }
3460 case COMPLETION_COLUMN_WHOLELINE: {
3461 sqlite3_result_text(ctx, pCur->zLine, -1, SQLITE_TRANSIENT);
3462 break;
3463 }
3464 case COMPLETION_COLUMN_PHASE: {
3465 sqlite3_result_int(ctx, pCur->ePhase);
3466 break;
3467 }
3468 }
3469 return SQLITE_OK;
3470 }
3471
3472 /*
3473 ** Return the rowid for the current row. In this implementation, the
3474 ** rowid is the same as the output value.
3475 */
3476 static int completionRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
3477 completion_cursor *pCur = (completion_cursor*)cur;
3478 *pRowid = pCur->iRowid;
3479 return SQLITE_OK;
3480 }
3481
3482 /*
3483 ** Return TRUE if the cursor has been moved off of the last
3484 ** row of output.
3485 */
3486 static int completionEof(sqlite3_vtab_cursor *cur){
3487 completion_cursor *pCur = (completion_cursor*)cur;
3488 return pCur->ePhase >= COMPLETION_EOF;
3489 }
3490
3491 /*
3492 ** This method is called to "rewind" the completion_cursor object back
3493 ** to the first row of output. This method is always called at least
3494 ** once prior to any call to completionColumn() or completionRowid() or
3495 ** completionEof().
3496 */
3497 static int completionFilter(
3498 sqlite3_vtab_cursor *pVtabCursor,
3499 int idxNum, const char *idxStr,
3500 int argc, sqlite3_value **argv
3501 ){
3502 completion_cursor *pCur = (completion_cursor *)pVtabCursor;
3503 int iArg = 0;
3504 (void)(idxStr); /* Unused parameter */
3505 (void)(argc); /* Unused parameter */
3506 completionCursorReset(pCur);
3507 if( idxNum & 1 ){
3508 pCur->nPrefix = sqlite3_value_bytes(argv[iArg]);
3509 if( pCur->nPrefix>0 ){
3510 pCur->zPrefix = sqlite3_mprintf("%s", sqlite3_value_text(argv[iArg]));
3511 if( pCur->zPrefix==0 ) return SQLITE_NOMEM;
3512 }
3513 iArg = 1;
3514 }
3515 if( idxNum & 2 ){
3516 pCur->nLine = sqlite3_value_bytes(argv[iArg]);
3517 if( pCur->nLine>0 ){
3518 pCur->zLine = sqlite3_mprintf("%s", sqlite3_value_text(argv[iArg]));
3519 if( pCur->zLine==0 ) return SQLITE_NOMEM;
3520 }
3521 }
3522 if( pCur->zLine!=0 && pCur->zPrefix==0 ){
3523 int i = pCur->nLine;
3524 while( i>0 && (isalnum(pCur->zLine[i-1]) || pCur->zLine[i-1]=='_') ){
3525 i--;
3526 }
3527 pCur->nPrefix = pCur->nLine - i;
3528 if( pCur->nPrefix>0 ){
3529 pCur->zPrefix = sqlite3_mprintf("%.*s", pCur->nPrefix, pCur->zLine + i);
3530 if( pCur->zPrefix==0 ) return SQLITE_NOMEM;
3531 }
3532 }
3533 pCur->iRowid = 0;
3534 pCur->ePhase = COMPLETION_FIRST_PHASE;
3535 return completionNext(pVtabCursor);
3536 }
3537
3538 /*
3539 ** SQLite will invoke this method one or more times while planning a query
3540 ** that uses the completion virtual table. This routine needs to create
3541 ** a query plan for each invocation and compute an estimated cost for that
3542 ** plan.
3543 **
3544 ** There are two hidden parameters that act as arguments to the table-valued
3545 ** function: "prefix" and "wholeline". Bit 0 of idxNum is set if "prefix"
3546 ** is available and bit 1 is set if "wholeline" is available.
3547 */
3548 static int completionBestIndex(
3549 sqlite3_vtab *tab,
3550 sqlite3_index_info *pIdxInfo
3551 ){
3552 int i; /* Loop over constraints */
3553 int idxNum = 0; /* The query plan bitmask */
3554 int prefixIdx = -1; /* Index of the start= constraint, or -1 if none */
3555 int wholelineIdx = -1; /* Index of the stop= constraint, or -1 if none */
3556 int nArg = 0; /* Number of arguments that completeFilter() expects */
3557 const struct sqlite3_index_constraint *pConstraint;
3558
3559 (void)(tab); /* Unused parameter */
3560 pConstraint = pIdxInfo->aConstraint;
3561 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
3562 if( pConstraint->usable==0 ) continue;
3563 if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
3564 switch( pConstraint->iColumn ){
3565 case COMPLETION_COLUMN_PREFIX:
3566 prefixIdx = i;
3567 idxNum |= 1;
3568 break;
3569 case COMPLETION_COLUMN_WHOLELINE:
3570 wholelineIdx = i;
3571 idxNum |= 2;
3572 break;
3573 }
3574 }
3575 if( prefixIdx>=0 ){
3576 pIdxInfo->aConstraintUsage[prefixIdx].argvIndex = ++nArg;
3577 pIdxInfo->aConstraintUsage[prefixIdx].omit = 1;
3578 }
3579 if( wholelineIdx>=0 ){
3580 pIdxInfo->aConstraintUsage[wholelineIdx].argvIndex = ++nArg;
3581 pIdxInfo->aConstraintUsage[wholelineIdx].omit = 1;
3582 }
3583 pIdxInfo->idxNum = idxNum;
3584 pIdxInfo->estimatedCost = (double)5000 - 1000*nArg;
3585 pIdxInfo->estimatedRows = 500 - 100*nArg;
3586 return SQLITE_OK;
3587 }
3588
3589 /*
3590 ** This following structure defines all the methods for the
3591 ** completion virtual table.
3592 */
3593 static sqlite3_module completionModule = {
3594 0, /* iVersion */
3595 0, /* xCreate */
3596 completionConnect, /* xConnect */
3597 completionBestIndex, /* xBestIndex */
3598 completionDisconnect, /* xDisconnect */
3599 0, /* xDestroy */
3600 completionOpen, /* xOpen - open a cursor */
3601 completionClose, /* xClose - close a cursor */
3602 completionFilter, /* xFilter - configure scan constraints */
3603 completionNext, /* xNext - advance a cursor */
3604 completionEof, /* xEof - check for end of scan */
3605 completionColumn, /* xColumn - read data */
3606 completionRowid, /* xRowid - read data */
3607 0, /* xUpdate */
3608 0, /* xBegin */
3609 0, /* xSync */
3610 0, /* xCommit */
3611 0, /* xRollback */
3612 0, /* xFindMethod */
3613 0, /* xRename */
3614 0, /* xSavepoint */
3615 0, /* xRelease */
3616 0, /* xRollbackTo */
3617 0 /* xShadowName */
3618 };
3619
3620 #endif /* SQLITE_OMIT_VIRTUALTABLE */
3621
3622 int sqlite3CompletionVtabInit(sqlite3 *db){
3623 int rc = SQLITE_OK;
3624 #ifndef SQLITE_OMIT_VIRTUALTABLE
3625 rc = sqlite3_create_module(db, "completion", &completionModule, 0);
3626 #endif
3627 return rc;
3628 }
3629
3630 #ifdef _WIN32
3631
3632 #endif
3633 int sqlite3_completion_init(
3634 sqlite3 *db,
3635 char **pzErrMsg,
3636 const sqlite3_api_routines *pApi
3637 ){
3638 int rc = SQLITE_OK;
3639 SQLITE_EXTENSION_INIT2(pApi);
3640 (void)(pzErrMsg); /* Unused parameter */
3641 #ifndef SQLITE_OMIT_VIRTUALTABLE
3642 rc = sqlite3CompletionVtabInit(db);
3643 #endif
3644 return rc;
3645 }
3646
3647 /************************* End ../ext/misc/completion.c ********************/
3648 /************************* Begin ../ext/misc/appendvfs.c ******************/
3649 /*
3650 ** 2017-10-20
3651 **
3652 ** The author disclaims copyright to this source code. In place of
3653 ** a legal notice, here is a blessing:
3654 **
3655 ** May you do good and not evil.
3656 ** May you find forgiveness for yourself and forgive others.
3657 ** May you share freely, never taking more than you give.
3658 **
3659 ******************************************************************************
3660 **
3661 ** This file implements a VFS shim that allows an SQLite database to be
3662 ** appended onto the end of some other file, such as an executable.
3663 **
3664 ** A special record must appear at the end of the file that identifies the
3665 ** file as an appended database and provides the offset to the first page
3666 ** of the exposed content. (Or, it is the length of the content prefix.)
3667 ** For best performance page 1 should be located at a disk page boundary,
3668 ** though that is not required.
3669 **
3670 ** When opening a database using this VFS, the connection might treat
3671 ** the file as an ordinary SQLite database, or it might treat it as a
3672 ** database appended onto some other file. The decision is made by
3673 ** applying the following rules in order:
3674 **
3675 ** (1) An empty file is an ordinary database.
3676 **
3677 ** (2) If the file ends with the appendvfs trailer string
3678 ** "Start-Of-SQLite3-NNNNNNNN" that file is an appended database.
3679 **
3680 ** (3) If the file begins with the standard SQLite prefix string
3681 ** "SQLite format 3", that file is an ordinary database.
3682 **
3683 ** (4) If none of the above apply and the SQLITE_OPEN_CREATE flag is
3684 ** set, then a new database is appended to the already existing file.
3685 **
3686 ** (5) Otherwise, SQLITE_CANTOPEN is returned.
3687 **
3688 ** To avoid unnecessary complications with the PENDING_BYTE, the size of
3689 ** the file containing the database is limited to 1GiB. (1073741824 bytes)
3690 ** This VFS will not read or write past the 1GiB mark. This restriction
3691 ** might be lifted in future versions. For now, if you need a larger
3692 ** database, then keep it in a separate file.
3693 **
3694 ** If the file being opened is a plain database (not an appended one), then
3695 ** this shim is a pass-through into the default underlying VFS. (rule 3)
3696 **/
3697 /* #include "sqlite3ext.h" */
3698 SQLITE_EXTENSION_INIT1
3699 #include <string.h>
3700 #include <assert.h>
3701
3702 /* The append mark at the end of the database is:
3703 **
3704 ** Start-Of-SQLite3-NNNNNNNN
3705 ** 123456789 123456789 12345
3706 **
3707 ** The NNNNNNNN represents a 64-bit big-endian unsigned integer which is
3708 ** the offset to page 1, and also the length of the prefix content.
3709 */
3710 #define APND_MARK_PREFIX "Start-Of-SQLite3-"
3711 #define APND_MARK_PREFIX_SZ 17
3712 #define APND_MARK_FOS_SZ 8
3713 #define APND_MARK_SIZE (APND_MARK_PREFIX_SZ+APND_MARK_FOS_SZ)
3714
3715 /*
3716 ** Maximum size of the combined prefix + database + append-mark. This
3717 ** must be less than 0x40000000 to avoid locking issues on Windows.
3718 */
3719 #define APND_MAX_SIZE (0x40000000)
3720
3721 /*
3722 ** Try to align the database to an even multiple of APND_ROUNDUP bytes.
3723 */
3724 #ifndef APND_ROUNDUP
3725 #define APND_ROUNDUP 4096
3726 #endif
3727 #define APND_ALIGN_MASK ((sqlite3_int64)(APND_ROUNDUP-1))
3728 #define APND_START_ROUNDUP(fsz) (((fsz)+APND_ALIGN_MASK) & ~APND_ALIGN_MASK)
3729
3730 /*
3731 ** Forward declaration of objects used by this utility
3732 */
3733 typedef struct sqlite3_vfs ApndVfs;
3734 typedef struct ApndFile ApndFile;
3735
3736 /* Access to a lower-level VFS that (might) implement dynamic loading,
3737 ** access to randomness, etc.
3738 */
3739 #define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData))
3740 #define ORIGFILE(p) ((sqlite3_file*)(((ApndFile*)(p))+1))
3741
3742 /* An open appendvfs file
3743 **
3744 ** An instance of this structure describes the appended database file.
3745 ** A separate sqlite3_file object is always appended. The appended
3746 ** sqlite3_file object (which can be accessed using ORIGFILE()) describes
3747 ** the entire file, including the prefix, the database, and the
3748 ** append-mark.
3749 **
3750 ** The structure of an AppendVFS database is like this:
3751 **
3752 ** +-------------+---------+----------+-------------+
3753 ** | prefix-file | padding | database | append-mark |
3754 ** +-------------+---------+----------+-------------+
3755 ** ^ ^
3756 ** | |
3757 ** iPgOne iMark
3758 **
3759 **
3760 ** "prefix file" - file onto which the database has been appended.
3761 ** "padding" - zero or more bytes inserted so that "database"
3762 ** starts on an APND_ROUNDUP boundary
3763 ** "database" - The SQLite database file
3764 ** "append-mark" - The 25-byte "Start-Of-SQLite3-NNNNNNNN" that indicates
3765 ** the offset from the start of prefix-file to the start
3766 ** of "database".
3767 **
3768 ** The size of the database is iMark - iPgOne.
3769 **
3770 ** The NNNNNNNN in the "Start-Of-SQLite3-NNNNNNNN" suffix is the value
3771 ** of iPgOne stored as a big-ending 64-bit integer.
3772 **
3773 ** iMark will be the size of the underlying file minus 25 (APND_MARKSIZE).
3774 ** Or, iMark is -1 to indicate that it has not yet been written.
3775 */
3776 struct ApndFile {
3777 sqlite3_file base; /* Subclass. MUST BE FIRST! */
3778 sqlite3_int64 iPgOne; /* Offset to the start of the database */
3779 sqlite3_int64 iMark; /* Offset of the append mark. -1 if unwritten */
3780 /* Always followed by another sqlite3_file that describes the whole file */
3781 };
3782
3783 /*
3784 ** Methods for ApndFile
3785 */
3786 static int apndClose(sqlite3_file*);
3787 static int apndRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
3788 static int apndWrite(sqlite3_file*,const void*,int iAmt, sqlite3_int64 iOfst);
3789 static int apndTruncate(sqlite3_file*, sqlite3_int64 size);
3790 static int apndSync(sqlite3_file*, int flags);
3791 static int apndFileSize(sqlite3_file*, sqlite3_int64 *pSize);
3792 static int apndLock(sqlite3_file*, int);
3793 static int apndUnlock(sqlite3_file*, int);
3794 static int apndCheckReservedLock(sqlite3_file*, int *pResOut);
3795 static int apndFileControl(sqlite3_file*, int op, void *pArg);
3796 static int apndSectorSize(sqlite3_file*);
3797 static int apndDeviceCharacteristics(sqlite3_file*);
3798 static int apndShmMap(sqlite3_file*, int iPg, int pgsz, int, void volatile**);
3799 static int apndShmLock(sqlite3_file*, int offset, int n, int flags);
3800 static void apndShmBarrier(sqlite3_file*);
3801 static int apndShmUnmap(sqlite3_file*, int deleteFlag);
3802 static int apndFetch(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp);
3803 static int apndUnfetch(sqlite3_file*, sqlite3_int64 iOfst, void *p);
3804
3805 /*
3806 ** Methods for ApndVfs
3807 */
3808 static int apndOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *);
3809 static int apndDelete(sqlite3_vfs*, const char *zName, int syncDir);
3810 static int apndAccess(sqlite3_vfs*, const char *zName, int flags, int *);
3811 static int apndFullPathname(sqlite3_vfs*, const char *zName, int, char *zOut);
3812 static void *apndDlOpen(sqlite3_vfs*, const char *zFilename);
3813 static void apndDlError(sqlite3_vfs*, int nByte, char *zErrMsg);
3814 static void (*apndDlSym(sqlite3_vfs *pVfs, void *p, const char*zSym))(void);
3815 static void apndDlClose(sqlite3_vfs*, void*);
3816 static int apndRandomness(sqlite3_vfs*, int nByte, char *zOut);
3817 static int apndSleep(sqlite3_vfs*, int microseconds);
3818 static int apndCurrentTime(sqlite3_vfs*, double*);
3819 static int apndGetLastError(sqlite3_vfs*, int, char *);
3820 static int apndCurrentTimeInt64(sqlite3_vfs*, sqlite3_int64*);
3821 static int apndSetSystemCall(sqlite3_vfs*, const char*,sqlite3_syscall_ptr);
3822 static sqlite3_syscall_ptr apndGetSystemCall(sqlite3_vfs*, const char *z);
3823 static const char *apndNextSystemCall(sqlite3_vfs*, const char *zName);
3824
3825 static sqlite3_vfs apnd_vfs = {
3826 3, /* iVersion (set when registered) */
3827 0, /* szOsFile (set when registered) */
3828 1024, /* mxPathname */
3829 0, /* pNext */
3830 "apndvfs", /* zName */
3831 0, /* pAppData (set when registered) */
3832 apndOpen, /* xOpen */
3833 apndDelete, /* xDelete */
3834 apndAccess, /* xAccess */
3835 apndFullPathname, /* xFullPathname */
3836 apndDlOpen, /* xDlOpen */
3837 apndDlError, /* xDlError */
3838 apndDlSym, /* xDlSym */
3839 apndDlClose, /* xDlClose */
3840 apndRandomness, /* xRandomness */
3841 apndSleep, /* xSleep */
3842 apndCurrentTime, /* xCurrentTime */
3843 apndGetLastError, /* xGetLastError */
3844 apndCurrentTimeInt64, /* xCurrentTimeInt64 */
3845 apndSetSystemCall, /* xSetSystemCall */
3846 apndGetSystemCall, /* xGetSystemCall */
3847 apndNextSystemCall /* xNextSystemCall */
3848 };
3849
3850 static const sqlite3_io_methods apnd_io_methods = {
3851 3, /* iVersion */
3852 apndClose, /* xClose */
3853 apndRead, /* xRead */
3854 apndWrite, /* xWrite */
3855 apndTruncate, /* xTruncate */
3856 apndSync, /* xSync */
3857 apndFileSize, /* xFileSize */
3858 apndLock, /* xLock */
3859 apndUnlock, /* xUnlock */
3860 apndCheckReservedLock, /* xCheckReservedLock */
3861 apndFileControl, /* xFileControl */
3862 apndSectorSize, /* xSectorSize */
3863 apndDeviceCharacteristics, /* xDeviceCharacteristics */
3864 apndShmMap, /* xShmMap */
3865 apndShmLock, /* xShmLock */
3866 apndShmBarrier, /* xShmBarrier */
3867 apndShmUnmap, /* xShmUnmap */
3868 apndFetch, /* xFetch */
3869 apndUnfetch /* xUnfetch */
3870 };
3871
3872 /*
3873 ** Close an apnd-file.
3874 */
3875 static int apndClose(sqlite3_file *pFile){
3876 pFile = ORIGFILE(pFile);
3877 return pFile->pMethods->xClose(pFile);
3878 }
3879
3880 /*
3881 ** Read data from an apnd-file.
3882 */
3883 static int apndRead(
3884 sqlite3_file *pFile,
3885 void *zBuf,
3886 int iAmt,
3887 sqlite_int64 iOfst
3888 ){
3889 ApndFile *paf = (ApndFile *)pFile;
3890 pFile = ORIGFILE(pFile);
3891 return pFile->pMethods->xRead(pFile, zBuf, iAmt, paf->iPgOne+iOfst);
3892 }
3893
3894 /*
3895 ** Add the append-mark onto what should become the end of the file.
3896 * If and only if this succeeds, internal ApndFile.iMark is updated.
3897 * Parameter iWriteEnd is the appendvfs-relative offset of the new mark.
3898 */
3899 static int apndWriteMark(
3900 ApndFile *paf,
3901 sqlite3_file *pFile,
3902 sqlite_int64 iWriteEnd
3903 ){
3904 sqlite_int64 iPgOne = paf->iPgOne;
3905 unsigned char a[APND_MARK_SIZE];
3906 int i = APND_MARK_FOS_SZ;
3907 int rc;
3908 assert(pFile == ORIGFILE(paf));
3909 memcpy(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ);
3910 while( --i >= 0 ){
3911 a[APND_MARK_PREFIX_SZ+i] = (unsigned char)(iPgOne & 0xff);
3912 iPgOne >>= 8;
3913 }
3914 iWriteEnd += paf->iPgOne;
3915 if( SQLITE_OK==(rc = pFile->pMethods->xWrite
3916 (pFile, a, APND_MARK_SIZE, iWriteEnd)) ){
3917 paf->iMark = iWriteEnd;
3918 }
3919 return rc;
3920 }
3921
3922 /*
3923 ** Write data to an apnd-file.
3924 */
3925 static int apndWrite(
3926 sqlite3_file *pFile,
3927 const void *zBuf,
3928 int iAmt,
3929 sqlite_int64 iOfst
3930 ){
3931 ApndFile *paf = (ApndFile *)pFile;
3932 sqlite_int64 iWriteEnd = iOfst + iAmt;
3933 if( iWriteEnd>=APND_MAX_SIZE ) return SQLITE_FULL;
3934 pFile = ORIGFILE(pFile);
3935 /* If append-mark is absent or will be overwritten, write it. */
3936 if( paf->iMark < 0 || paf->iPgOne + iWriteEnd > paf->iMark ){
3937 int rc = apndWriteMark(paf, pFile, iWriteEnd);
3938 if( SQLITE_OK!=rc ) return rc;
3939 }
3940 return pFile->pMethods->xWrite(pFile, zBuf, iAmt, paf->iPgOne+iOfst);
3941 }
3942
3943 /*
3944 ** Truncate an apnd-file.
3945 */
3946 static int apndTruncate(sqlite3_file *pFile, sqlite_int64 size){
3947 ApndFile *paf = (ApndFile *)pFile;
3948 pFile = ORIGFILE(pFile);
3949 /* The append mark goes out first so truncate failure does not lose it. */
3950 if( SQLITE_OK!=apndWriteMark(paf, pFile, size) ) return SQLITE_IOERR;
3951 /* Truncate underlying file just past append mark */
3952 return pFile->pMethods->xTruncate(pFile, paf->iMark+APND_MARK_SIZE);
3953 }
3954
3955 /*
3956 ** Sync an apnd-file.
3957 */
3958 static int apndSync(sqlite3_file *pFile, int flags){
3959 pFile = ORIGFILE(pFile);
3960 return pFile->pMethods->xSync(pFile, flags);
3961 }
3962
3963 /*
3964 ** Return the current file-size of an apnd-file.
3965 ** If the append mark is not yet there, the file-size is 0.
3966 */
3967 static int apndFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
3968 ApndFile *paf = (ApndFile *)pFile;
3969 *pSize = ( paf->iMark >= 0 )? (paf->iMark - paf->iPgOne) : 0;
3970 return SQLITE_OK;
3971 }
3972
3973 /*
3974 ** Lock an apnd-file.
3975 */
3976 static int apndLock(sqlite3_file *pFile, int eLock){
3977 pFile = ORIGFILE(pFile);
3978 return pFile->pMethods->xLock(pFile, eLock);
3979 }
3980
3981 /*
3982 ** Unlock an apnd-file.
3983 */
3984 static int apndUnlock(sqlite3_file *pFile, int eLock){
3985 pFile = ORIGFILE(pFile);
3986 return pFile->pMethods->xUnlock(pFile, eLock);
3987 }
3988
3989 /*
3990 ** Check if another file-handle holds a RESERVED lock on an apnd-file.
3991 */
3992 static int apndCheckReservedLock(sqlite3_file *pFile, int *pResOut){
3993 pFile = ORIGFILE(pFile);
3994 return pFile->pMethods->xCheckReservedLock(pFile, pResOut);
3995 }
3996
3997 /*
3998 ** File control method. For custom operations on an apnd-file.
3999 */
4000 static int apndFileControl(sqlite3_file *pFile, int op, void *pArg){
4001 ApndFile *paf = (ApndFile *)pFile;
4002 int rc;
4003 pFile = ORIGFILE(pFile);
4004 if( op==SQLITE_FCNTL_SIZE_HINT ) *(sqlite3_int64*)pArg += paf->iPgOne;
4005 rc = pFile->pMethods->xFileControl(pFile, op, pArg);
4006 if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
4007 *(char**)pArg = sqlite3_mprintf("apnd(%lld)/%z", paf->iPgOne,*(char**)pArg);
4008 }
4009 return rc;
4010 }
4011
4012 /*
4013 ** Return the sector-size in bytes for an apnd-file.
4014 */
4015 static int apndSectorSize(sqlite3_file *pFile){
4016 pFile = ORIGFILE(pFile);
4017 return pFile->pMethods->xSectorSize(pFile);
4018 }
4019
4020 /*
4021 ** Return the device characteristic flags supported by an apnd-file.
4022 */
4023 static int apndDeviceCharacteristics(sqlite3_file *pFile){
4024 pFile = ORIGFILE(pFile);
4025 return pFile->pMethods->xDeviceCharacteristics(pFile);
4026 }
4027
4028 /* Create a shared memory file mapping */
4029 static int apndShmMap(
4030 sqlite3_file *pFile,
4031 int iPg,
4032 int pgsz,
4033 int bExtend,
4034 void volatile **pp
4035 ){
4036 pFile = ORIGFILE(pFile);
4037 return pFile->pMethods->xShmMap(pFile,iPg,pgsz,bExtend,pp);
4038 }
4039
4040 /* Perform locking on a shared-memory segment */
4041 static int apndShmLock(sqlite3_file *pFile, int offset, int n, int flags){
4042 pFile = ORIGFILE(pFile);
4043 return pFile->pMethods->xShmLock(pFile,offset,n,flags);
4044 }
4045
4046 /* Memory barrier operation on shared memory */
4047 static void apndShmBarrier(sqlite3_file *pFile){
4048 pFile = ORIGFILE(pFile);
4049 pFile->pMethods->xShmBarrier(pFile);
4050 }
4051
4052 /* Unmap a shared memory segment */
4053 static int apndShmUnmap(sqlite3_file *pFile, int deleteFlag){
4054 pFile = ORIGFILE(pFile);
4055 return pFile->pMethods->xShmUnmap(pFile,deleteFlag);
4056 }
4057
4058 /* Fetch a page of a memory-mapped file */
4059 static int apndFetch(
4060 sqlite3_file *pFile,
4061 sqlite3_int64 iOfst,
4062 int iAmt,
4063 void **pp
4064 ){
4065 ApndFile *p = (ApndFile *)pFile;
4066 if( p->iMark < 0 || iOfst+iAmt > p->iMark ){
4067 return SQLITE_IOERR; /* Cannot read what is not yet there. */
4068 }
4069 pFile = ORIGFILE(pFile);
4070 return pFile->pMethods->xFetch(pFile, iOfst+p->iPgOne, iAmt, pp);
4071 }
4072
4073 /* Release a memory-mapped page */
4074 static int apndUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){
4075 ApndFile *p = (ApndFile *)pFile;
4076 pFile = ORIGFILE(pFile);
4077 return pFile->pMethods->xUnfetch(pFile, iOfst+p->iPgOne, pPage);
4078 }
4079
4080 /*
4081 ** Try to read the append-mark off the end of a file. Return the
4082 ** start of the appended database if the append-mark is present.
4083 ** If there is no valid append-mark, return -1;
4084 **
4085 ** An append-mark is only valid if the NNNNNNNN start-of-database offset
4086 ** indicates that the appended database contains at least one page. The
4087 ** start-of-database value must be a multiple of 512.
4088 */
4089 static sqlite3_int64 apndReadMark(sqlite3_int64 sz, sqlite3_file *pFile){
4090 int rc, i;
4091 sqlite3_int64 iMark;
4092 int msbs = 8 * (APND_MARK_FOS_SZ-1);
4093 unsigned char a[APND_MARK_SIZE];
4094
4095 if( APND_MARK_SIZE!=(sz & 0x1ff) ) return -1;
4096 rc = pFile->pMethods->xRead(pFile, a, APND_MARK_SIZE, sz-APND_MARK_SIZE);
4097 if( rc ) return -1;
4098 if( memcmp(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ)!=0 ) return -1;
4099 iMark = ((sqlite3_int64)(a[APND_MARK_PREFIX_SZ] & 0x7f)) << msbs;
4100 for(i=1; i<8; i++){
4101 msbs -= 8;
4102 iMark |= (sqlite3_int64)a[APND_MARK_PREFIX_SZ+i]<<msbs;
4103 }
4104 if( iMark > (sz - APND_MARK_SIZE - 512) ) return -1;
4105 if( iMark & 0x1ff ) return -1;
4106 return iMark;
4107 }
4108
4109 static const char apvfsSqliteHdr[] = "SQLite format 3";
4110 /*
4111 ** Check to see if the file is an appendvfs SQLite database file.
4112 ** Return true iff it is such. Parameter sz is the file's size.
4113 */
4114 static int apndIsAppendvfsDatabase(sqlite3_int64 sz, sqlite3_file *pFile){
4115 int rc;
4116 char zHdr[16];
4117 sqlite3_int64 iMark = apndReadMark(sz, pFile);
4118 if( iMark>=0 ){
4119 /* If file has the correct end-marker, the expected odd size, and the
4120 ** SQLite DB type marker where the end-marker puts it, then it
4121 ** is an appendvfs database.
4122 */
4123 rc = pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), iMark);
4124 if( SQLITE_OK==rc
4125 && memcmp(zHdr, apvfsSqliteHdr, sizeof(zHdr))==0
4126 && (sz & 0x1ff) == APND_MARK_SIZE
4127 && sz>=512+APND_MARK_SIZE
4128 ){
4129 return 1; /* It's an appendvfs database */
4130 }
4131 }
4132 return 0;
4133 }
4134
4135 /*
4136 ** Check to see if the file is an ordinary SQLite database file.
4137 ** Return true iff so. Parameter sz is the file's size.
4138 */
4139 static int apndIsOrdinaryDatabaseFile(sqlite3_int64 sz, sqlite3_file *pFile){
4140 char zHdr[16];
4141 if( apndIsAppendvfsDatabase(sz, pFile) /* rule 2 */
4142 || (sz & 0x1ff) != 0
4143 || SQLITE_OK!=pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), 0)
4144 || memcmp(zHdr, apvfsSqliteHdr, sizeof(zHdr))!=0
4145 ){
4146 return 0;
4147 }else{
4148 return 1;
4149 }
4150 }
4151
4152 /*
4153 ** Open an apnd file handle.
4154 */
4155 static int apndOpen(
4156 sqlite3_vfs *pApndVfs,
4157 const char *zName,
4158 sqlite3_file *pFile,
4159 int flags,
4160 int *pOutFlags
4161 ){
4162 ApndFile *pApndFile = (ApndFile*)pFile;
4163 sqlite3_file *pBaseFile = ORIGFILE(pFile);
4164 sqlite3_vfs *pBaseVfs = ORIGVFS(pApndVfs);
4165 int rc;
4166 sqlite3_int64 sz = 0;
4167 if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
4168 /* The appendvfs is not to be used for transient or temporary databases.
4169 ** Just use the base VFS open to initialize the given file object and
4170 ** open the underlying file. (Appendvfs is then unused for this file.)
4171 */
4172 return pBaseVfs->xOpen(pBaseVfs, zName, pFile, flags, pOutFlags);
4173 }
4174 memset(pApndFile, 0, sizeof(ApndFile));
4175 pFile->pMethods = &apnd_io_methods;
4176 pApndFile->iMark = -1; /* Append mark not yet written */
4177
4178 rc = pBaseVfs->xOpen(pBaseVfs, zName, pBaseFile, flags, pOutFlags);
4179 if( rc==SQLITE_OK ){
4180 rc = pBaseFile->pMethods->xFileSize(pBaseFile, &sz);
4181 if( rc ){
4182 pBaseFile->pMethods->xClose(pBaseFile);
4183 }
4184 }
4185 if( rc ){
4186 pFile->pMethods = 0;
4187 return rc;
4188 }
4189 if( apndIsOrdinaryDatabaseFile(sz, pBaseFile) ){
4190 /* The file being opened appears to be just an ordinary DB. Copy
4191 ** the base dispatch-table so this instance mimics the base VFS.
4192 */
4193 memmove(pApndFile, pBaseFile, pBaseVfs->szOsFile);
4194 return SQLITE_OK;
4195 }
4196 pApndFile->iPgOne = apndReadMark(sz, pFile);
4197 if( pApndFile->iPgOne>=0 ){
4198 pApndFile->iMark = sz - APND_MARK_SIZE; /* Append mark found */
4199 return SQLITE_OK;
4200 }
4201 if( (flags & SQLITE_OPEN_CREATE)==0 ){
4202 pBaseFile->pMethods->xClose(pBaseFile);
4203 rc = SQLITE_CANTOPEN;
4204 pFile->pMethods = 0;
4205 }else{
4206 /* Round newly added appendvfs location to #define'd page boundary.
4207 ** Note that nothing has yet been written to the underlying file.
4208 ** The append mark will be written along with first content write.
4209 ** Until then, paf->iMark value indicates it is not yet written.
4210 */
4211 pApndFile->iPgOne = APND_START_ROUNDUP(sz);
4212 }
4213 return rc;
4214 }
4215
4216 /*
4217 ** Delete an apnd file.
4218 ** For an appendvfs, this could mean delete the appendvfs portion,
4219 ** leaving the appendee as it was before it gained an appendvfs.
4220 ** For now, this code deletes the underlying file too.
4221 */
4222 static int apndDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
4223 return ORIGVFS(pVfs)->xDelete(ORIGVFS(pVfs), zPath, dirSync);
4224 }
4225
4226 /*
4227 ** All other VFS methods are pass-thrus.
4228 */
4229 static int apndAccess(
4230 sqlite3_vfs *pVfs,
4231 const char *zPath,
4232 int flags,
4233 int *pResOut
4234 ){
4235 return ORIGVFS(pVfs)->xAccess(ORIGVFS(pVfs), zPath, flags, pResOut);
4236 }
4237 static int apndFullPathname(
4238 sqlite3_vfs *pVfs,
4239 const char *zPath,
4240 int nOut,
4241 char *zOut
4242 ){
4243 return ORIGVFS(pVfs)->xFullPathname(ORIGVFS(pVfs),zPath,nOut,zOut);
4244 }
4245 static void *apndDlOpen(sqlite3_vfs *pVfs, const char *zPath){
4246 return ORIGVFS(pVfs)->xDlOpen(ORIGVFS(pVfs), zPath);
4247 }
4248 static void apndDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){
4249 ORIGVFS(pVfs)->xDlError(ORIGVFS(pVfs), nByte, zErrMsg);
4250 }
4251 static void (*apndDlSym(sqlite3_vfs *pVfs, void *p, const char *zSym))(void){
4252 return ORIGVFS(pVfs)->xDlSym(ORIGVFS(pVfs), p, zSym);
4253 }
4254 static void apndDlClose(sqlite3_vfs *pVfs, void *pHandle){
4255 ORIGVFS(pVfs)->xDlClose(ORIGVFS(pVfs), pHandle);
4256 }
4257 static int apndRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
4258 return ORIGVFS(pVfs)->xRandomness(ORIGVFS(pVfs), nByte, zBufOut);
4259 }
4260 static int apndSleep(sqlite3_vfs *pVfs, int nMicro){
4261 return ORIGVFS(pVfs)->xSleep(ORIGVFS(pVfs), nMicro);
4262 }
4263 static int apndCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
4264 return ORIGVFS(pVfs)->xCurrentTime(ORIGVFS(pVfs), pTimeOut);
4265 }
4266 static int apndGetLastError(sqlite3_vfs *pVfs, int a, char *b){
4267 return ORIGVFS(pVfs)->xGetLastError(ORIGVFS(pVfs), a, b);
4268 }
4269 static int apndCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *p){
4270 return ORIGVFS(pVfs)->xCurrentTimeInt64(ORIGVFS(pVfs), p);
4271 }
4272 static int apndSetSystemCall(
4273 sqlite3_vfs *pVfs,
4274 const char *zName,
4275 sqlite3_syscall_ptr pCall
4276 ){
4277 return ORIGVFS(pVfs)->xSetSystemCall(ORIGVFS(pVfs),zName,pCall);
4278 }
4279 static sqlite3_syscall_ptr apndGetSystemCall(
4280 sqlite3_vfs *pVfs,
4281 const char *zName
4282 ){
4283 return ORIGVFS(pVfs)->xGetSystemCall(ORIGVFS(pVfs),zName);
4284 }
4285 static const char *apndNextSystemCall(sqlite3_vfs *pVfs, const char *zName){
4286 return ORIGVFS(pVfs)->xNextSystemCall(ORIGVFS(pVfs), zName);
4287 }
4288
4289
4290 #ifdef _WIN32
4291
4292 #endif
4293 /*
4294 ** This routine is called when the extension is loaded.
4295 ** Register the new VFS.
4296 */
4297 int sqlite3_appendvfs_init(
4298 sqlite3 *db,
4299 char **pzErrMsg,
4300 const sqlite3_api_routines *pApi
4301 ){
4302 int rc = SQLITE_OK;
4303 sqlite3_vfs *pOrig;
4304 SQLITE_EXTENSION_INIT2(pApi);
4305 (void)pzErrMsg;
4306 (void)db;
4307 pOrig = sqlite3_vfs_find(0);
4308 if( pOrig==0 ) return SQLITE_ERROR;
4309 apnd_vfs.iVersion = pOrig->iVersion;
4310 apnd_vfs.pAppData = pOrig;
4311 apnd_vfs.szOsFile = pOrig->szOsFile + sizeof(ApndFile);
4312 rc = sqlite3_vfs_register(&apnd_vfs, 0);
4313 #ifdef APPENDVFS_TEST
4314 if( rc==SQLITE_OK ){
4315 rc = sqlite3_auto_extension((void(*)(void))apndvfsRegister);
4316 }
4317 #endif
4318 if( rc==SQLITE_OK ) rc = SQLITE_OK_LOAD_PERMANENTLY;
4319 return rc;
4320 }
4321
4322 /************************* End ../ext/misc/appendvfs.c ********************/
4323 /************************* Begin ../ext/misc/memtrace.c ******************/
4324 /*
4325 ** 2019-01-21
4326 **
4327 ** The author disclaims copyright to this source code. In place of
4328 ** a legal notice, here is a blessing:
4329 **
4330 ** May you do good and not evil.
4331 ** May you find forgiveness for yourself and forgive others.
4332 ** May you share freely, never taking more than you give.
4333 **
4334 *************************************************************************
4335 **
4336 ** This file implements an extension that uses the SQLITE_CONFIG_MALLOC
4337 ** mechanism to add a tracing layer on top of SQLite. If this extension
4338 ** is registered prior to sqlite3_initialize(), it will cause all memory
4339 ** allocation activities to be logged on standard output, or to some other
4340 ** FILE specified by the initializer.
4341 **
4342 ** This file needs to be compiled into the application that uses it.
4343 **
4344 ** This extension is used to implement the --memtrace option of the
4345 ** command-line shell.
4346 */
4347 #include <assert.h>
4348 #include <string.h>
4349 #include <stdio.h>
4350
4351 /* The original memory allocation routines */
4352 static sqlite3_mem_methods memtraceBase;
4353 static FILE *memtraceOut;
4354
4355 /* Methods that trace memory allocations */
4356 static void *memtraceMalloc(int n){
4357 if( memtraceOut ){
4358 fprintf(memtraceOut, "MEMTRACE: allocate %d bytes\n",
4359 memtraceBase.xRoundup(n));
4360 }
4361 return memtraceBase.xMalloc(n);
4362 }
4363 static void memtraceFree(void *p){
4364 if( p==0 ) return;
4365 if( memtraceOut ){
4366 fprintf(memtraceOut, "MEMTRACE: free %d bytes\n", memtraceBase.xSize(p));
4367 }
4368 memtraceBase.xFree(p);
4369 }
4370 static void *memtraceRealloc(void *p, int n){
4371 if( p==0 ) return memtraceMalloc(n);
4372 if( n==0 ){
4373 memtraceFree(p);
4374 return 0;
4375 }
4376 if( memtraceOut ){
4377 fprintf(memtraceOut, "MEMTRACE: resize %d -> %d bytes\n",
4378 memtraceBase.xSize(p), memtraceBase.xRoundup(n));
4379 }
4380 return memtraceBase.xRealloc(p, n);
4381 }
4382 static int memtraceSize(void *p){
4383 return memtraceBase.xSize(p);
4384 }
4385 static int memtraceRoundup(int n){
4386 return memtraceBase.xRoundup(n);
4387 }
4388 static int memtraceInit(void *p){
4389 return memtraceBase.xInit(p);
4390 }
4391 static void memtraceShutdown(void *p){
4392 memtraceBase.xShutdown(p);
4393 }
4394
4395 /* The substitute memory allocator */
4396 static sqlite3_mem_methods ersaztMethods = {
4397 memtraceMalloc,
4398 memtraceFree,
4399 memtraceRealloc,
4400 memtraceSize,
4401 memtraceRoundup,
4402 memtraceInit,
4403 memtraceShutdown,
4404 0
4405 };
4406
4407 /* Begin tracing memory allocations to out. */
4408 int sqlite3MemTraceActivate(FILE *out){
4409 int rc = SQLITE_OK;
4410 if( memtraceBase.xMalloc==0 ){
4411 rc = sqlite3_config(SQLITE_CONFIG_GETMALLOC, &memtraceBase);
4412 if( rc==SQLITE_OK ){
4413 rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &ersaztMethods);
4414 }
4415 }
4416 memtraceOut = out;
4417 return rc;
4418 }
4419
4420 /* Deactivate memory tracing */
4421 int sqlite3MemTraceDeactivate(void){
4422 int rc = SQLITE_OK;
4423 if( memtraceBase.xMalloc!=0 ){
4424 rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &memtraceBase);
4425 if( rc==SQLITE_OK ){
4426 memset(&memtraceBase, 0, sizeof(memtraceBase));
4427 }
4428 }
4429 memtraceOut = 0;
4430 return rc;
4431 }
4432
4433 /************************* End ../ext/misc/memtrace.c ********************/
4434 /************************* Begin ../ext/misc/uint.c ******************/
4435 /*
4436 ** 2020-04-14
4437 **
4438 ** The author disclaims copyright to this source code. In place of
@@ -6696,10 +4495,2224 @@
6696 }
6697 return rc;
6698 }
6699
6700 /************************* End ../ext/misc/regexp.c ********************/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6701 #ifdef SQLITE_HAVE_ZLIB
6702 /************************* Begin ../ext/misc/zipfile.c ******************/
6703 /*
6704 ** 2017-12-26
6705 **
@@ -12235,11 +12248,21 @@
12235 int nIndent; /* Size of array aiIndent[] */
12236 int iIndent; /* Index of current op in aiIndent[] */
12237 char *zNonce; /* Nonce for temporary safe-mode excapes */
12238 EQPGraph sGraph; /* Information for the graphical EXPLAIN QUERY PLAN */
12239 ExpertInfo expert; /* Valid if previous command was ".expert OPT..." */
 
 
 
 
 
 
12240 };
 
 
 
 
12241
12242
12243 /* Allowed values for ShellState.autoEQP
12244 */
12245 #define AUTOEQP_off 0 /* Automatic EXPLAIN QUERY PLAN is off */
@@ -12277,11 +12300,11 @@
12277 #define SHFLG_Lookaside 0x00000002 /* Lookaside memory is used */
12278 #define SHFLG_Backslash 0x00000004 /* The --backslash option is used */
12279 #define SHFLG_PreserveRowid 0x00000008 /* .dump preserves rowid values */
12280 #define SHFLG_Newlines 0x00000010 /* .dump --newline flag */
12281 #define SHFLG_CountChanges 0x00000020 /* .changes setting */
12282 #define SHFLG_Echo 0x00000040 /* .echo or --echo setting */
12283 #define SHFLG_HeaderSet 0x00000080 /* showHeader has been specified */
12284 #define SHFLG_DumpDataOnly 0x00000100 /* .dump show data only */
12285 #define SHFLG_DumpNoSys 0x00000200 /* .dump omits system tables */
12286
12287 /*
@@ -14906,15 +14929,10 @@
14906 if( pArg ){
14907 pArg->pStmt = pStmt;
14908 pArg->cnt = 0;
14909 }
14910
14911 /* echo the sql statement if echo on */
14912 if( pArg && ShellHasFlag(pArg, SHFLG_Echo) ){
14913 utf8_printf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
14914 }
14915
14916 /* Show the EXPLAIN QUERY PLAN if .eqp is on */
14917 if( pArg && pArg->autoEQP && sqlite3_stmt_isexplain(pStmt)==0 ){
14918 sqlite3_stmt *pExplain;
14919 char *zEQP;
14920 int triggerEQP = 0;
@@ -15309,17 +15327,18 @@
15309
15310 /*
15311 ** Text of help messages.
15312 **
15313 ** The help text for each individual command begins with a line that starts
15314 ** with ".". Subsequent lines are supplimental information.
15315 **
15316 ** There must be two or more spaces between the end of the command and the
15317 ** start of the description of what that command does.
15318 */
15319 static const char *(azHelp[]) = {
15320 #if defined(SQLITE_HAVE_ZLIB) && !defined(SQLITE_OMIT_VIRTUALTABLE)
 
15321 ".archive ... Manage SQL archives",
15322 " Each command must have exactly one of the following options:",
15323 " -c, --create Create a new archive",
15324 " -u, --update Add or update files with changed mtime",
15325 " -i, --insert Like -u but always add even if unchanged",
@@ -15341,20 +15360,26 @@
15341 " http://sqlite.org/cli.html#sqlite_archive_support",
15342 #endif
15343 #ifndef SQLITE_OMIT_AUTHORIZATION
15344 ".auth ON|OFF Show authorizer callbacks",
15345 #endif
 
15346 ".backup ?DB? FILE Backup DB (default \"main\") to FILE",
15347 " Options:",
15348 " --append Use the appendvfs",
15349 " --async Write to FILE without journal and fsync()",
 
15350 ".bail on|off Stop after hitting an error. Default OFF",
15351 ".binary on|off Turn binary output on or off. Default OFF",
 
15352 ".cd DIRECTORY Change the working directory to DIRECTORY",
 
15353 ".changes on|off Show number of rows changed by SQL",
 
15354 ".check GLOB Fail if output since .testcase does not match",
15355 ".clone NEWDB Clone data into NEWDB from the existing database",
 
15356 ".connection [close] [#] Open or close an auxiliary database connection",
15357 ".databases List names and files of attached databases",
15358 ".dbconfig ?op? ?val? List or change sqlite3_db_config() options",
15359 ".dbinfo ?DB? Show status information about the database",
15360 ".dump ?OBJECTS? Render database content as SQL",
@@ -15371,21 +15396,26 @@
15371 #ifdef SQLITE_DEBUG
15372 " test Show raw EXPLAIN QUERY PLAN output",
15373 " trace Like \"full\" but enable \"PRAGMA vdbe_trace\"",
15374 #endif
15375 " trigger Like \"full\" but also show trigger bytecode",
 
15376 ".excel Display the output of next command in spreadsheet",
15377 " --bom Put a UTF8 byte-order mark on intermediate file",
 
 
15378 ".exit ?CODE? Exit this program with return-code CODE",
 
15379 ".expert EXPERIMENTAL. Suggest indexes for queries",
15380 ".explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto",
15381 ".filectrl CMD ... Run various sqlite3_file_control() operations",
15382 " --schema SCHEMA Use SCHEMA instead of \"main\"",
15383 " --help Show CMD details",
15384 ".fullschema ?--indent? Show schema and the content of sqlite_stat tables",
15385 ".headers on|off Turn display of headers on or off",
15386 ".help ?-all? ?PATTERN? Show help text for PATTERN",
 
15387 ".import FILE TABLE Import data from FILE into TABLE",
15388 " Options:",
15389 " --ascii Use \\037 and \\036 as column and row separators",
15390 " --csv Use , and \\n as column and row separators",
15391 " --skip N Skip the first N rows of input",
@@ -15396,10 +15426,11 @@
15396 " determines the column names.",
15397 " * If neither --csv or --ascii are used, the input mode is derived",
15398 " from the \".mode\" output mode",
15399 " * If FILE begins with \"|\" then it is a command that generates the",
15400 " input text.",
 
15401 #ifndef SQLITE_OMIT_TEST_CONTROL
15402 ".imposter INDEX TABLE Create imposter table TABLE on index INDEX",
15403 #endif
15404 ".indexes ?TABLE? Show names of indexes",
15405 " If TABLE is specified, only show indexes for",
@@ -15409,14 +15440,16 @@
15409 #endif
15410 ".limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT",
15411 ".lint OPTIONS Report potential schema issues.",
15412 " Options:",
15413 " fkey-indexes Find missing foreign key indexes",
15414 #ifndef SQLITE_OMIT_LOAD_EXTENSION
15415 ".load FILE ?ENTRY? Load an extension library",
15416 #endif
 
15417 ".log FILE|off Turn logging on or off. FILE can be stderr/stdout",
 
15418 ".mode MODE ?OPTIONS? Set output mode",
15419 " MODE is one of:",
15420 " ascii Columns/rows delimited by 0x1F and 0x1E",
15421 " box Tables using unicode box-drawing characters",
15422 " csv Comma-separated values",
@@ -15437,35 +15470,44 @@
15437 " --wordwrap B Wrap or not at word boundaries per B (on/off)",
15438 " --ww Shorthand for \"--wordwrap 1\"",
15439 " --quote Quote output text as SQL literals",
15440 " --noquote Do not quote output text",
15441 " TABLE The name of SQL table used for \"insert\" mode",
 
15442 ".nonce STRING Suspend safe mode for one command if nonce matches",
 
15443 ".nullvalue STRING Use STRING in place of NULL values",
 
15444 ".once ?OPTIONS? ?FILE? Output for the next SQL command only to FILE",
15445 " If FILE begins with '|' then open as a pipe",
15446 " --bom Put a UTF8 byte-order mark at the beginning",
15447 " -e Send output to the system text editor",
15448 " -x Send output as CSV to a spreadsheet (same as \".excel\")",
 
 
 
15449 ".open ?OPTIONS? ?FILE? Close existing database and reopen FILE",
15450 " Options:",
15451 " --append Use appendvfs to append database to the end of FILE",
 
15452 #ifndef SQLITE_OMIT_DESERIALIZE
15453 " --deserialize Load into memory using sqlite3_deserialize()",
15454 " --hexdb Load the output of \"dbtotxt\" as an in-memory db",
15455 " --maxsize N Maximum size for --hexdb or --deserialized database",
15456 #endif
15457 " --new Initialize FILE to an empty database",
15458 " --nofollow Do not follow symbolic links",
15459 " --readonly Open FILE readonly",
15460 " --zip FILE is a ZIP archive",
 
15461 ".output ?FILE? Send output to FILE or stdout if FILE is omitted",
15462 " If FILE begins with '|' then open it as a pipe.",
15463 " Options:",
15464 " --bom Prefix output with a UTF8 byte-order mark",
15465 " -e Send output to the system text editor",
15466 " -x Send output as CSV to a spreadsheet",
 
15467 ".parameter CMD ... Manage SQL parameter bindings",
15468 " clear Erase all bindings",
15469 " init Initialize the TEMP table that holds bindings",
15470 " list List the current parameter bindings",
15471 " set PARAMETER VALUE Given SQL parameter PARAMETER a value of VALUE",
@@ -15478,23 +15520,27 @@
15478 " --once Do no more than one progress interrupt",
15479 " --quiet|-q No output except at interrupts",
15480 " --reset Reset the count for each input and interrupt",
15481 #endif
15482 ".prompt MAIN CONTINUE Replace the standard prompts",
 
15483 ".quit Exit this program",
15484 ".read FILE Read input from FILE or command output",
15485 " If FILE begins with \"|\", it is a command that generates the input.",
 
15486 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
15487 ".recover Recover as much data as possible from corrupt db.",
15488 " --freelist-corrupt Assume the freelist is corrupt",
15489 " --recovery-db NAME Store recovery metadata in database file NAME",
15490 " --lost-and-found TABLE Alternative name for the lost-and-found table",
15491 " --no-rowids Do not attempt to recover rowid values",
15492 " that are not also INTEGER PRIMARY KEYs",
15493 #endif
 
15494 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE",
15495 ".save ?OPTIONS? FILE Write database to FILE (an alias for .backup ...)",
 
15496 ".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off",
15497 ".schema ?PATTERN? Show the CREATE statements matching PATTERN",
15498 " Options:",
15499 " --indent Try to pretty-print the schema",
15500 " --nosys Omit objects whose names start with \"sqlite_\"",
@@ -15524,24 +15570,26 @@
15524 " --sha3-224 Use the sha3-224 algorithm",
15525 " --sha3-256 Use the sha3-256 algorithm (default)",
15526 " --sha3-384 Use the sha3-384 algorithm",
15527 " --sha3-512 Use the sha3-512 algorithm",
15528 " Any other argument is a LIKE pattern for tables to hash",
15529 #ifndef SQLITE_NOHAVE_SYSTEM
15530 ".shell CMD ARGS... Run CMD ARGS... in a system shell",
15531 #endif
15532 ".show Show the current values for various settings",
15533 ".stats ?ARG? Show stats or turn stats on or off",
15534 " off Turn off automatic stat display",
15535 " on Turn on automatic stat display",
15536 " stmt Show statement stats",
15537 " vmstep Show the virtual machine step count only",
15538 #ifndef SQLITE_NOHAVE_SYSTEM
15539 ".system CMD ARGS... Run CMD ARGS... in a system shell",
15540 #endif
15541 ".tables ?TABLE? List names of tables matching LIKE pattern TABLE",
 
15542 ".testcase NAME Begin redirecting output to 'testcase-out.txt'",
 
15543 ".testctrl CMD ... Run various sqlite3_test_control() operations",
15544 " Run \".testctrl\" with no arguments for details",
15545 ".timeout MS Try opening locked tables for MS milliseconds",
15546 ".timer on|off Turn SQL timer on or off",
15547 #ifndef SQLITE_OMIT_TRACE
@@ -16082,18 +16130,20 @@
16082 exit(1);
16083 }
16084 #ifndef SQLITE_OMIT_LOAD_EXTENSION
16085 sqlite3_enable_load_extension(p->db, 1);
16086 #endif
16087 sqlite3_fileio_init(p->db, 0, 0);
16088 sqlite3_shathree_init(p->db, 0, 0);
16089 sqlite3_completion_init(p->db, 0, 0);
16090 sqlite3_uint_init(p->db, 0, 0);
16091 sqlite3_decimal_init(p->db, 0, 0);
16092 sqlite3_regexp_init(p->db, 0, 0);
16093 sqlite3_ieee_init(p->db, 0, 0);
16094 sqlite3_series_init(p->db, 0, 0);
 
 
 
 
16095 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
16096 sqlite3_dbdata_init(p->db, 0, 0);
16097 #endif
16098 #ifdef SQLITE_HAVE_ZLIB
16099 if( !p->bSafeModePersist ){
@@ -19212,18 +19262,20 @@
19212 sqlite3_set_authorizer(p->db, 0, 0);
19213 }
19214 }else
19215 #endif
19216
19217 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB)
 
19218 if( c=='a' && strncmp(azArg[0], "archive", n)==0 ){
19219 open_db(p, 0);
19220 failIfSafeMode(p, "cannot run .archive in safe mode");
19221 rc = arDotCommand(p, 0, azArg, nArg);
19222 }else
19223 #endif
19224
 
19225 if( (c=='b' && n>=3 && strncmp(azArg[0], "backup", n)==0)
19226 || (c=='s' && n>=3 && strncmp(azArg[0], "save", n)==0)
19227 ){
19228 const char *zDestFile = 0;
19229 const char *zDb = 0;
@@ -19288,10 +19340,11 @@
19288 utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
19289 rc = 1;
19290 }
19291 close_db(pDest);
19292 }else
 
19293
19294 if( c=='b' && n>=3 && strncmp(azArg[0], "bail", n)==0 ){
19295 if( nArg==2 ){
19296 bail_on_error = booleanValue(azArg[1]);
19297 }else{
@@ -19318,10 +19371,11 @@
19318 */
19319 if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
19320 test_breakpoint();
19321 }else
19322
 
19323 if( c=='c' && strcmp(azArg[0],"cd")==0 ){
19324 failIfSafeMode(p, "cannot run .cd in safe mode");
19325 if( nArg==2 ){
19326 #if defined(_WIN32) || defined(WIN32)
19327 wchar_t *z = sqlite3_win32_utf8_to_unicode(azArg[1]);
@@ -19337,10 +19391,11 @@
19337 }else{
19338 raw_printf(stderr, "Usage: .cd DIRECTORY\n");
19339 rc = 1;
19340 }
19341 }else
 
19342
19343 if( c=='c' && n>=3 && strncmp(azArg[0], "changes", n)==0 ){
19344 if( nArg==2 ){
19345 setOrClearFlag(p, SHFLG_CountChanges, azArg[1]);
19346 }else{
@@ -19347,10 +19402,11 @@
19347 raw_printf(stderr, "Usage: .changes on|off\n");
19348 rc = 1;
19349 }
19350 }else
19351
 
19352 /* Cancel output redirection, if it is currently set (by .testcase)
19353 ** Then read the content of the testcase-out.txt file and compare against
19354 ** azArg[1]. If there are differences, report an error and exit.
19355 */
19356 if( c=='c' && n>=3 && strncmp(azArg[0], "check", n)==0 ){
@@ -19371,20 +19427,23 @@
19371 utf8_printf(stdout, "testcase-%s ok\n", p->zTestcase);
19372 p->nCheck++;
19373 }
19374 sqlite3_free(zRes);
19375 }else
 
19376
 
19377 if( c=='c' && strncmp(azArg[0], "clone", n)==0 ){
19378 failIfSafeMode(p, "cannot run .clone in safe mode");
19379 if( nArg==2 ){
19380 tryToClone(p, azArg[1]);
19381 }else{
19382 raw_printf(stderr, "Usage: .clone FILENAME\n");
19383 rc = 1;
19384 }
19385 }else
 
19386
19387 if( c=='c' && strncmp(azArg[0], "connection", n)==0 ){
19388 if( nArg==1 ){
19389 /* List available connections */
19390 int i;
@@ -19523,11 +19582,11 @@
19523 char *zLike = 0;
19524 char *zSql;
19525 int i;
19526 int savedShowHeader = p->showHeader;
19527 int savedShellFlags = p->shellFlgs;
19528 ShellClearFlag(p,
19529 SHFLG_PreserveRowid|SHFLG_Newlines|SHFLG_Echo
19530 |SHFLG_DumpDataOnly|SHFLG_DumpNoSys);
19531 for(i=1; i<nArg; i++){
19532 if( azArg[i][0]=='-' ){
19533 const char *z = azArg[i]+1;
@@ -19669,14 +19728,16 @@
19669 raw_printf(stderr, "Usage: .eqp off|on|trace|trigger|full\n");
19670 rc = 1;
19671 }
19672 }else
19673
 
19674 if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
19675 if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
19676 rc = 2;
19677 }else
 
19678
19679 /* The ".explain" command is automatic now. It is largely pointless. It
19680 ** retained purely for backwards compatibility */
19681 if( c=='e' && strncmp(azArg[0], "explain", n)==0 ){
19682 int val = 1;
@@ -19927,10 +19988,11 @@
19927 }else{
19928 showHelp(p->out, 0);
19929 }
19930 }else
19931
 
19932 if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
19933 char *zTable = 0; /* Insert data into this table */
19934 char *zSchema = 0; /* within this schema (may default to "main") */
19935 char *zFile = 0; /* Name of file to extra content from */
19936 sqlite3_stmt *pStmt = NULL; /* A statement */
@@ -19948,20 +20010,16 @@
19948 int useOutputMode = 1; /* Use output mode to determine separators */
19949 char *zCreate = 0; /* CREATE TABLE statement text */
19950
19951 failIfSafeMode(p, "cannot run .import in safe mode");
19952 memset(&sCtx, 0, sizeof(sCtx));
19953 sCtx.z = sqlite3_malloc64(120);
19954 if( sCtx.z==0 ){
19955 import_cleanup(&sCtx);
19956 shell_out_of_memory();
19957 }
19958 if( p->mode==MODE_Ascii ){
19959 xRead = ascii_read_one_field;
19960 }else{
19961 xRead = csv_read_one_field;
19962 }
 
19963 for(i=1; i<nArg; i++){
19964 char *z = azArg[i];
19965 if( z[0]=='-' && z[1]=='-' ) z++;
19966 if( z[0]!='-' ){
19967 if( zFile==0 ){
@@ -19969,11 +20027,10 @@
19969 }else if( zTable==0 ){
19970 zTable = z;
19971 }else{
19972 utf8_printf(p->out, "ERROR: extra argument: \"%s\". Usage:\n", z);
19973 showHelp(p->out, "import");
19974 rc = 1;
19975 goto meta_command_exit;
19976 }
19977 }else if( strcmp(z,"-v")==0 ){
19978 eVerbose++;
19979 }else if( strcmp(z,"-schema")==0 && i<nArg-1 ){
@@ -19991,19 +20048,17 @@
19991 xRead = csv_read_one_field;
19992 useOutputMode = 0;
19993 }else{
19994 utf8_printf(p->out, "ERROR: unknown option: \"%s\". Usage:\n", z);
19995 showHelp(p->out, "import");
19996 rc = 1;
19997 goto meta_command_exit;
19998 }
19999 }
20000 if( zTable==0 ){
20001 utf8_printf(p->out, "ERROR: missing %s argument. Usage:\n",
20002 zFile==0 ? "FILE" : "TABLE");
20003 showHelp(p->out, "import");
20004 rc = 1;
20005 goto meta_command_exit;
20006 }
20007 seenInterrupt = 0;
20008 open_db(p, 0);
20009 if( useOutputMode ){
@@ -20011,25 +20066,22 @@
20011 ** the column and row separator characters from the output mode. */
20012 nSep = strlen30(p->colSeparator);
20013 if( nSep==0 ){
20014 raw_printf(stderr,
20015 "Error: non-null column separator required for import\n");
20016 rc = 1;
20017 goto meta_command_exit;
20018 }
20019 if( nSep>1 ){
20020 raw_printf(stderr,
20021 "Error: multi-character column separators not allowed"
20022 " for import\n");
20023 rc = 1;
20024 goto meta_command_exit;
20025 }
20026 nSep = strlen30(p->rowSeparator);
20027 if( nSep==0 ){
20028 raw_printf(stderr,
20029 "Error: non-null row separator required for import\n");
20030 rc = 1;
20031 goto meta_command_exit;
20032 }
20033 if( nSep==2 && p->mode==MODE_Csv && strcmp(p->rowSeparator,SEP_CrLf)==0 ){
20034 /* When importing CSV (only), if the row separator is set to the
20035 ** default output row separator, change it to the default input
@@ -20039,11 +20091,10 @@
20039 nSep = strlen30(p->rowSeparator);
20040 }
20041 if( nSep>1 ){
20042 raw_printf(stderr, "Error: multi-character row separators not allowed"
20043 " for import\n");
20044 rc = 1;
20045 goto meta_command_exit;
20046 }
20047 sCtx.cColSep = p->colSeparator[0];
20048 sCtx.cRowSep = p->rowSeparator[0];
20049 }
@@ -20050,11 +20101,10 @@
20050 sCtx.zFile = zFile;
20051 sCtx.nLine = 1;
20052 if( sCtx.zFile[0]=='|' ){
20053 #ifdef SQLITE_OMIT_POPEN
20054 raw_printf(stderr, "Error: pipes are not supported in this OS\n");
20055 rc = 1;
20056 goto meta_command_exit;
20057 #else
20058 sCtx.in = popen(sCtx.zFile+1, "r");
20059 sCtx.zFile = "<pipe>";
20060 sCtx.xCloser = pclose;
@@ -20063,12 +20113,10 @@
20063 sCtx.in = fopen(sCtx.zFile, "rb");
20064 sCtx.xCloser = fclose;
20065 }
20066 if( sCtx.in==0 ){
20067 utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
20068 rc = 1;
20069 import_cleanup(&sCtx);
20070 goto meta_command_exit;
20071 }
20072 if( eVerbose>=2 || (eVerbose>=1 && useOutputMode) ){
20073 char zSep[2];
20074 zSep[1] = 0;
@@ -20077,10 +20125,15 @@
20077 output_c_string(p->out, zSep);
20078 utf8_printf(p->out, ", row separator ");
20079 zSep[0] = sCtx.cRowSep;
20080 output_c_string(p->out, zSep);
20081 utf8_printf(p->out, "\n");
 
 
 
 
 
20082 }
20083 /* Below, resources must be freed before exit. */
20084 while( (nSkip--)>0 ){
20085 while( xRead(&sCtx) && sCtx.cTerm==sCtx.cColSep ){}
20086 }
@@ -20226,10 +20279,11 @@
20226 utf8_printf(p->out,
20227 "Added %d rows with %d errors using %d lines of input\n",
20228 sCtx.nRow, sCtx.nErr, sCtx.nLine-1);
20229 }
20230 }else
 
20231
20232 #ifndef SQLITE_UNTESTABLE
20233 if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
20234 char *zSql;
20235 char *zCollist = 0;
@@ -20415,11 +20469,11 @@
20415 if( c=='l' && n>2 && strncmp(azArg[0], "lint", n)==0 ){
20416 open_db(p, 0);
20417 lintDotCommand(p, azArg, nArg);
20418 }else
20419
20420 #ifndef SQLITE_OMIT_LOAD_EXTENSION
20421 if( c=='l' && strncmp(azArg[0], "load", n)==0 ){
20422 const char *zFile, *zProc;
20423 char *zErrMsg = 0;
20424 failIfSafeMode(p, "cannot run .load in safe mode");
20425 if( nArg<2 ){
@@ -20437,10 +20491,11 @@
20437 rc = 1;
20438 }
20439 }else
20440 #endif
20441
 
20442 if( c=='l' && strncmp(azArg[0], "log", n)==0 ){
20443 failIfSafeMode(p, "cannot run .log in safe mode");
20444 if( nArg!=2 ){
20445 raw_printf(stderr, "Usage: .log FILENAME\n");
20446 rc = 1;
@@ -20448,10 +20503,11 @@
20448 const char *zFile = azArg[1];
20449 output_file_close(p->pLog);
20450 p->pLog = output_file_open(zFile, 0);
20451 }
20452 }else
 
20453
20454 if( c=='m' && strncmp(azArg[0], "mode", n)==0 ){
20455 const char *zMode = 0;
20456 const char *zTabname = 0;
20457 int i, n2;
@@ -20572,10 +20628,11 @@
20572 rc = 1;
20573 }
20574 p->cMode = p->mode;
20575 }else
20576
 
20577 if( c=='n' && strcmp(azArg[0], "nonce")==0 ){
20578 if( nArg!=2 ){
20579 raw_printf(stderr, "Usage: .nonce NONCE\n");
20580 rc = 1;
20581 }else if( p->zNonce==0 || strcmp(azArg[1],p->zNonce)!=0 ){
@@ -20586,10 +20643,11 @@
20586 p->bSafeMode = 0;
20587 return 0; /* Return immediately to bypass the safe mode reset
20588 ** at the end of this procedure */
20589 }
20590 }else
 
20591
20592 if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 ){
20593 if( nArg==2 ){
20594 sqlite3_snprintf(sizeof(p->nullValue), p->nullValue,
20595 "%.*s", (int)ArraySize(p->nullValue)-1, azArg[1]);
@@ -20607,10 +20665,11 @@
20607 int openMode = SHELL_OPEN_UNSPEC;
20608
20609 /* Check for command-line arguments */
20610 for(iName=1; iName<nArg; iName++){
20611 const char *z = azArg[iName];
 
20612 if( optionMatch(z,"new") ){
20613 newFlag = 1;
20614 #ifdef SQLITE_HAVE_ZLIB
20615 }else if( optionMatch(z, "zip") ){
20616 openMode = SHELL_OPEN_ZIPFILE;
@@ -20627,11 +20686,13 @@
20627 }else if( optionMatch(z, "hexdb") ){
20628 openMode = SHELL_OPEN_HEXDB;
20629 }else if( optionMatch(z, "maxsize") && iName+1<nArg ){
20630 p->szMax = integerValue(azArg[++iName]);
20631 #endif /* SQLITE_OMIT_DESERIALIZE */
20632 }else if( z[0]=='-' ){
 
 
20633 utf8_printf(stderr, "unknown option: %s\n", z);
20634 rc = 1;
20635 goto meta_command_exit;
20636 }else if( zFN ){
20637 utf8_printf(stderr, "extra argument: \"%s\"\n", z);
@@ -20654,17 +20715,21 @@
20654 p->szMax = 0;
20655
20656 /* If a filename is specified, try to open it first */
20657 if( zFN || p->openMode==SHELL_OPEN_HEXDB ){
20658 if( newFlag && zFN && !p->bSafeMode ) shellDeleteFile(zFN);
 
20659 if( p->bSafeMode
20660 && p->openMode!=SHELL_OPEN_HEXDB
20661 && zFN
20662 && strcmp(zFN,":memory:")!=0
20663 ){
20664 failIfSafeMode(p, "cannot open disk-based database files in safe mode");
20665 }
 
 
 
20666 if( zFN ){
20667 zNewFilename = sqlite3_mprintf("%s", zFN);
20668 shell_check_oom(zNewFilename);
20669 }else{
20670 zNewFilename = 0;
@@ -20683,10 +20748,11 @@
20683 p->pAuxDb->zDbFilename = 0;
20684 open_db(p, 0);
20685 }
20686 }else
20687
 
20688 if( (c=='o'
20689 && (strncmp(azArg[0], "output", n)==0||strncmp(azArg[0], "once", n)==0))
20690 || (c=='e' && n==5 && strcmp(azArg[0],"excel")==0)
20691 ){
20692 char *zFile = 0;
@@ -20798,10 +20864,11 @@
20798 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
20799 }
20800 }
20801 sqlite3_free(zFile);
20802 }else
 
20803
20804 if( c=='p' && n>=3 && strncmp(azArg[0], "parameter", n)==0 ){
20805 open_db(p,0);
20806 if( nArg<=1 ) goto parameter_syntax_error;
20807
@@ -20967,14 +21034,17 @@
20967 if( nArg >= 3) {
20968 strncpy(continuePrompt,azArg[2],(int)ArraySize(continuePrompt)-1);
20969 }
20970 }else
20971
 
20972 if( c=='q' && strncmp(azArg[0], "quit", n)==0 ){
20973 rc = 2;
20974 }else
 
20975
 
20976 if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 ){
20977 FILE *inSaved = p->in;
20978 int savedLineno = p->lineno;
20979 failIfSafeMode(p, "cannot run .read in safe mode");
20980 if( nArg!=2 ){
@@ -21005,11 +21075,13 @@
21005 fclose(p->in);
21006 }
21007 p->in = inSaved;
21008 p->lineno = savedLineno;
21009 }else
 
21010
 
21011 if( c=='r' && n>=3 && strncmp(azArg[0], "restore", n)==0 ){
21012 const char *zSrcFile;
21013 const char *zDb;
21014 sqlite3 *pSrc;
21015 sqlite3_backup *pBackup;
@@ -21057,10 +21129,11 @@
21057 utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
21058 rc = 1;
21059 }
21060 close_db(pSrc);
21061 }else
 
21062
21063 if( c=='s' && strncmp(azArg[0], "scanstats", n)==0 ){
21064 if( nArg==2 ){
21065 p->scanstatsOn = (u8)booleanValue(azArg[1]);
21066 #ifndef SQLITE_ENABLE_STMT_SCANSTATUS
@@ -21682,11 +21755,11 @@
21682 shell_exec(p, zSql, 0);
21683 }
21684 sqlite3_free(zSql);
21685 }else
21686
21687 #ifndef SQLITE_NOHAVE_SYSTEM
21688 if( c=='s'
21689 && (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
21690 ){
21691 char *zCmd;
21692 int i, x;
@@ -21703,11 +21776,11 @@
21703 }
21704 x = zCmd!=0 ? system(zCmd) : 1;
21705 sqlite3_free(zCmd);
21706 if( x ) raw_printf(stderr, "System command returns %d\n", x);
21707 }else
21708 #endif /* !defined(SQLITE_NOHAVE_SYSTEM) */
21709
21710 if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
21711 static const char *azBool[] = { "off", "on", "trigger", "full"};
21712 const char *zOut;
21713 int i;
@@ -21715,11 +21788,11 @@
21715 raw_printf(stderr, "Usage: .show\n");
21716 rc = 1;
21717 goto meta_command_exit;
21718 }
21719 utf8_printf(p->out, "%12.12s: %s\n","echo",
21720 azBool[ShellHasFlag(p, SHFLG_Echo)]);
21721 utf8_printf(p->out, "%12.12s: %s\n","eqp", azBool[p->autoEQP&3]);
21722 utf8_printf(p->out, "%12.12s: %s\n","explain",
21723 p->mode==MODE_Explain ? "on" : p->autoExplain ? "auto" : "off");
21724 utf8_printf(p->out,"%12.12s: %s\n","headers", azBool[p->showHeader!=0]);
21725 if( p->mode==MODE_Column
@@ -21883,10 +21956,11 @@
21883
21884 for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
21885 sqlite3_free(azResult);
21886 }else
21887
 
21888 /* Begin redirecting output to the file "testcase-out.txt" */
21889 if( c=='t' && strcmp(azArg[0],"testcase")==0 ){
21890 output_reset(p);
21891 p->out = output_file_open("testcase-out.txt", 0);
21892 if( p->out==0 ){
@@ -21896,10 +21970,11 @@
21896 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
21897 }else{
21898 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?");
21899 }
21900 }else
 
21901
21902 #ifndef SQLITE_UNTESTABLE
21903 if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 ){
21904 static const struct {
21905 const char *zCtrlName; /* Name of a test-control option */
@@ -22465,11 +22540,11 @@
22465 /* fall thru */
22466 case ']':
22467 cWait = 0;
22468 qss = QSS_SETV(qss, 0);
22469 goto PlainScan;
22470 default: assert(0);
22471 }
22472 }
22473 }
22474 }
22475 return qss;
@@ -22486,11 +22561,11 @@
22486 zLine += 1; /* Oracle */
22487 else if ( ToLower(zLine[0])=='g' && ToLower(zLine[1])=='o' )
22488 zLine += 2; /* SQL Server */
22489 else
22490 return 0;
22491 return quickscan(zLine,QSS_Start)==QSS_Start;
22492 }
22493
22494 /*
22495 ** We need a default sqlite3_complete() implementation to use in case
22496 ** the shell is compiled with SQLITE_OMIT_COMPLETE. The default assumes
@@ -22563,10 +22638,46 @@
22563 raw_printf(p->out, "%s\n", zLineBuf);
22564 }
22565 return 0;
22566 }
22567
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22568
22569 /*
22570 ** Read input from *in and process it. If *in==0 then input
22571 ** is interactive - the user is typing it it. Otherwise, input
22572 ** is coming from a file or device. A prompt is issued and history
@@ -22612,18 +22723,17 @@
22612 && line_is_complete(zSql, nSql) ){
22613 memcpy(zLine,";",2);
22614 }
22615 qss = quickscan(zLine, qss);
22616 if( QSS_PLAINWHITE(qss) && nSql==0 ){
22617 if( ShellHasFlag(p, SHFLG_Echo) )
22618 printf("%s\n", zLine);
22619 /* Just swallow single-line whitespace */
 
22620 qss = QSS_Start;
22621 continue;
22622 }
22623 if( zLine && (zLine[0]=='.' || zLine[0]=='#') && nSql==0 ){
22624 if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zLine);
22625 if( zLine[0]=='.' ){
22626 rc = do_meta_command(zLine, p);
22627 if( rc==2 ){ /* exit requested */
22628 break;
22629 }else if( rc ){
@@ -22652,10 +22762,11 @@
22652 zSql[nSql++] = '\n';
22653 memcpy(zSql+nSql, zLine, nLine+1);
22654 nSql += nLine;
22655 }
22656 if( nSql && QSS_SEMITERM(qss) && sqlite3_complete(zSql) ){
 
22657 errCnt += runOneSqlLine(p, zSql, p->in, startline);
22658 nSql = 0;
22659 if( p->outCount ){
22660 output_reset(p);
22661 p->outCount = 0;
@@ -22663,17 +22774,18 @@
22663 clearTempFile(p);
22664 }
22665 p->bSafeMode = p->bSafeModePersist;
22666 qss = QSS_Start;
22667 }else if( nSql && QSS_PLAINWHITE(qss) ){
22668 if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zSql);
22669 nSql = 0;
22670 qss = QSS_Start;
22671 }
22672 }
22673 if( nSql ){
22674 /* This may be incomplete. Let the SQL parser deal with that. */
 
22675 errCnt += runOneSqlLine(p, zSql, p->in, startline);
22676 }
22677 free(zSql);
22678 free(zLine);
22679 --p->inputNesting;
@@ -22808,11 +22920,11 @@
22808 " -cmd COMMAND run \"COMMAND\" before reading stdin\n"
22809 " -csv set output mode to 'csv'\n"
22810 #if !defined(SQLITE_OMIT_DESERIALIZE)
22811 " -deserialize open the database using sqlite3_deserialize()\n"
22812 #endif
22813 " -echo print commands before execution\n"
22814 " -init FILENAME read/process named file\n"
22815 " -[no]header turn headers on or off\n"
22816 #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
22817 " -heap SIZE Size of heap for memsys3 or memsys5\n"
22818 #endif
@@ -22943,19 +23055,30 @@
22943 # define SQLITE_SHELL_IS_UTF8 (0)
22944 # else
22945 # define SQLITE_SHELL_IS_UTF8 (1)
22946 # endif
22947 #endif
 
 
 
 
22948
22949 #if SQLITE_SHELL_IS_UTF8
22950 int SQLITE_CDECL main(int argc, char **argv){
22951 #else
22952 int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
22953 char **argv;
22954 #endif
 
 
 
22955 char *zErrMsg = 0;
 
 
 
22956 ShellState data;
 
22957 const char *zInitFile = 0;
22958 int i;
22959 int rc = 0;
22960 int warnInmemoryDb = 0;
22961 int readStdin = 1;
@@ -22967,12 +23090,17 @@
22967 int argcToFree = 0;
22968 #endif
22969
22970 setBinaryMode(stdin, 0);
22971 setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
 
 
 
 
22972 stdin_is_interactive = isatty(0);
22973 stdout_is_console = isatty(1);
 
22974
22975 #if !defined(_WIN32_WCE)
22976 if( getenv("SQLITE_DEBUG_BREAK") ){
22977 if( isatty(0) && isatty(2) ){
22978 fprintf(stderr,
@@ -23224,11 +23352,13 @@
23224 utf8_printf(stderr,"%s: Error: no database filename specified\n", Argv0);
23225 return 1;
23226 #endif
23227 }
23228 data.out = stdout;
 
23229 sqlite3_appendvfs_init(0,0,0);
 
23230
23231 /* Go ahead and open the database file if it already exists. If the
23232 ** file does not exist, delay opening it. This prevents empty database
23233 ** files from being created if a user mistypes the database name argument
23234 ** to the sqlite command-line tool.
@@ -23490,10 +23620,13 @@
23490 }else{
23491 data.in = stdin;
23492 rc = process_input(&data);
23493 }
23494 }
 
 
 
23495 free(azCmd);
23496 set_table_name(&data, 0);
23497 if( data.db ){
23498 session_close_all(&data, -1);
23499 close_db(data.db);
@@ -23516,7 +23649,138 @@
23516 free(data.colWidth);
23517 free(data.zNonce);
23518 /* Clear the global data structure so that valgrind will detect memory
23519 ** leaks */
23520 memset(&data, 0, sizeof(data));
 
 
 
 
 
 
 
23521 return rc;
23522 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23523
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -245,10 +245,20 @@
245 #else
246 # define setBinaryMode(X,Y)
247 # define setTextMode(X,Y)
248 #endif
249
250 /*
251 ** When compiling with emcc (a.k.a. emscripten), we're building a
252 ** WebAssembly (WASM) bundle and need to disable and rewire a few
253 ** things.
254 */
255 #ifdef __EMSCRIPTEN__
256 #define SQLITE_SHELL_WASM_MODE
257 #else
258 #undef SQLITE_SHELL_WASM_MODE
259 #endif
260
261 /* True if the timer is enabled */
262 static int enableTimer = 0;
263
264 /* Return the current wall-clock time */
@@ -707,10 +717,11 @@
717 **
718 ** The result is stored in space obtained from malloc() and must either
719 ** be freed by the caller or else passed back into this routine via the
720 ** zPrior argument for reuse.
721 */
722 #ifndef SQLITE_SHELL_WASM_MODE
723 static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
724 char *zPrompt;
725 char *zResult;
726 if( in!=0 ){
727 zResult = local_getline(zPrior, in);
@@ -726,11 +737,11 @@
737 if( zResult && *zResult ) shell_add_history(zResult);
738 #endif
739 }
740 return zResult;
741 }
742 #endif /* !SQLITE_SHELL_WASM_MODE */
743
744 /*
745 ** Return the value of a hexadecimal digit. Return -1 if the input
746 ** is not a hex digit.
747 */
@@ -814,11 +825,11 @@
825 ** zIn, if it was not NULL, is freed.
826 **
827 ** If the third argument, quote, is not '\0', then it is used as a
828 ** quote character for zAppend.
829 */
830 static void appendText(ShellText *p, const char *zAppend, char quote){
831 int len;
832 int i;
833 int nAppend = strlen30(zAppend);
834
835 len = nAppend+p->n+1;
@@ -1379,10 +1390,121 @@
1390 #endif /* defined(WIN32) && defined(_MSC_VER) */
1391
1392 /************************* End test_windirent.c ********************/
1393 #define dirent DIRENT
1394 #endif
1395 /************************* Begin ../ext/misc/memtrace.c ******************/
1396 /*
1397 ** 2019-01-21
1398 **
1399 ** The author disclaims copyright to this source code. In place of
1400 ** a legal notice, here is a blessing:
1401 **
1402 ** May you do good and not evil.
1403 ** May you find forgiveness for yourself and forgive others.
1404 ** May you share freely, never taking more than you give.
1405 **
1406 *************************************************************************
1407 **
1408 ** This file implements an extension that uses the SQLITE_CONFIG_MALLOC
1409 ** mechanism to add a tracing layer on top of SQLite. If this extension
1410 ** is registered prior to sqlite3_initialize(), it will cause all memory
1411 ** allocation activities to be logged on standard output, or to some other
1412 ** FILE specified by the initializer.
1413 **
1414 ** This file needs to be compiled into the application that uses it.
1415 **
1416 ** This extension is used to implement the --memtrace option of the
1417 ** command-line shell.
1418 */
1419 #include <assert.h>
1420 #include <string.h>
1421 #include <stdio.h>
1422
1423 /* The original memory allocation routines */
1424 static sqlite3_mem_methods memtraceBase;
1425 static FILE *memtraceOut;
1426
1427 /* Methods that trace memory allocations */
1428 static void *memtraceMalloc(int n){
1429 if( memtraceOut ){
1430 fprintf(memtraceOut, "MEMTRACE: allocate %d bytes\n",
1431 memtraceBase.xRoundup(n));
1432 }
1433 return memtraceBase.xMalloc(n);
1434 }
1435 static void memtraceFree(void *p){
1436 if( p==0 ) return;
1437 if( memtraceOut ){
1438 fprintf(memtraceOut, "MEMTRACE: free %d bytes\n", memtraceBase.xSize(p));
1439 }
1440 memtraceBase.xFree(p);
1441 }
1442 static void *memtraceRealloc(void *p, int n){
1443 if( p==0 ) return memtraceMalloc(n);
1444 if( n==0 ){
1445 memtraceFree(p);
1446 return 0;
1447 }
1448 if( memtraceOut ){
1449 fprintf(memtraceOut, "MEMTRACE: resize %d -> %d bytes\n",
1450 memtraceBase.xSize(p), memtraceBase.xRoundup(n));
1451 }
1452 return memtraceBase.xRealloc(p, n);
1453 }
1454 static int memtraceSize(void *p){
1455 return memtraceBase.xSize(p);
1456 }
1457 static int memtraceRoundup(int n){
1458 return memtraceBase.xRoundup(n);
1459 }
1460 static int memtraceInit(void *p){
1461 return memtraceBase.xInit(p);
1462 }
1463 static void memtraceShutdown(void *p){
1464 memtraceBase.xShutdown(p);
1465 }
1466
1467 /* The substitute memory allocator */
1468 static sqlite3_mem_methods ersaztMethods = {
1469 memtraceMalloc,
1470 memtraceFree,
1471 memtraceRealloc,
1472 memtraceSize,
1473 memtraceRoundup,
1474 memtraceInit,
1475 memtraceShutdown,
1476 0
1477 };
1478
1479 /* Begin tracing memory allocations to out. */
1480 int sqlite3MemTraceActivate(FILE *out){
1481 int rc = SQLITE_OK;
1482 if( memtraceBase.xMalloc==0 ){
1483 rc = sqlite3_config(SQLITE_CONFIG_GETMALLOC, &memtraceBase);
1484 if( rc==SQLITE_OK ){
1485 rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &ersaztMethods);
1486 }
1487 }
1488 memtraceOut = out;
1489 return rc;
1490 }
1491
1492 /* Deactivate memory tracing */
1493 int sqlite3MemTraceDeactivate(void){
1494 int rc = SQLITE_OK;
1495 if( memtraceBase.xMalloc!=0 ){
1496 rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &memtraceBase);
1497 if( rc==SQLITE_OK ){
1498 memset(&memtraceBase, 0, sizeof(memtraceBase));
1499 }
1500 }
1501 memtraceOut = 0;
1502 return rc;
1503 }
1504
1505 /************************* End ../ext/misc/memtrace.c ********************/
1506 /************************* Begin ../ext/misc/shathree.c ******************/
1507 /*
1508 ** 2017-03-08
1509 **
1510 ** The author disclaims copyright to this source code. In place of
@@ -2106,2333 +2228,10 @@
2228 }
2229 return rc;
2230 }
2231
2232 /************************* End ../ext/misc/shathree.c ********************/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2233 /************************* Begin ../ext/misc/uint.c ******************/
2234 /*
2235 ** 2020-04-14
2236 **
2237 ** The author disclaims copyright to this source code. In place of
@@ -6696,10 +4495,2224 @@
4495 }
4496 return rc;
4497 }
4498
4499 /************************* End ../ext/misc/regexp.c ********************/
4500 #ifndef SQLITE_SHELL_WASM_MODE
4501 /************************* Begin ../ext/misc/fileio.c ******************/
4502 /*
4503 ** 2014-06-13
4504 **
4505 ** The author disclaims copyright to this source code. In place of
4506 ** a legal notice, here is a blessing:
4507 **
4508 ** May you do good and not evil.
4509 ** May you find forgiveness for yourself and forgive others.
4510 ** May you share freely, never taking more than you give.
4511 **
4512 ******************************************************************************
4513 **
4514 ** This SQLite extension implements SQL functions readfile() and
4515 ** writefile(), and eponymous virtual type "fsdir".
4516 **
4517 ** WRITEFILE(FILE, DATA [, MODE [, MTIME]]):
4518 **
4519 ** If neither of the optional arguments is present, then this UDF
4520 ** function writes blob DATA to file FILE. If successful, the number
4521 ** of bytes written is returned. If an error occurs, NULL is returned.
4522 **
4523 ** If the first option argument - MODE - is present, then it must
4524 ** be passed an integer value that corresponds to a POSIX mode
4525 ** value (file type + permissions, as returned in the stat.st_mode
4526 ** field by the stat() system call). Three types of files may
4527 ** be written/created:
4528 **
4529 ** regular files: (mode & 0170000)==0100000
4530 ** symbolic links: (mode & 0170000)==0120000
4531 ** directories: (mode & 0170000)==0040000
4532 **
4533 ** For a directory, the DATA is ignored. For a symbolic link, it is
4534 ** interpreted as text and used as the target of the link. For a
4535 ** regular file, it is interpreted as a blob and written into the
4536 ** named file. Regardless of the type of file, its permissions are
4537 ** set to (mode & 0777) before returning.
4538 **
4539 ** If the optional MTIME argument is present, then it is interpreted
4540 ** as an integer - the number of seconds since the unix epoch. The
4541 ** modification-time of the target file is set to this value before
4542 ** returning.
4543 **
4544 ** If three or more arguments are passed to this function and an
4545 ** error is encountered, an exception is raised.
4546 **
4547 ** READFILE(FILE):
4548 **
4549 ** Read and return the contents of file FILE (type blob) from disk.
4550 **
4551 ** FSDIR:
4552 **
4553 ** Used as follows:
4554 **
4555 ** SELECT * FROM fsdir($path [, $dir]);
4556 **
4557 ** Parameter $path is an absolute or relative pathname. If the file that it
4558 ** refers to does not exist, it is an error. If the path refers to a regular
4559 ** file or symbolic link, it returns a single row. Or, if the path refers
4560 ** to a directory, it returns one row for the directory, and one row for each
4561 ** file within the hierarchy rooted at $path.
4562 **
4563 ** Each row has the following columns:
4564 **
4565 ** name: Path to file or directory (text value).
4566 ** mode: Value of stat.st_mode for directory entry (an integer).
4567 ** mtime: Value of stat.st_mtime for directory entry (an integer).
4568 ** data: For a regular file, a blob containing the file data. For a
4569 ** symlink, a text value containing the text of the link. For a
4570 ** directory, NULL.
4571 **
4572 ** If a non-NULL value is specified for the optional $dir parameter and
4573 ** $path is a relative path, then $path is interpreted relative to $dir.
4574 ** And the paths returned in the "name" column of the table are also
4575 ** relative to directory $dir.
4576 **
4577 ** Notes on building this extension for Windows:
4578 ** Unless linked statically with the SQLite library, a preprocessor
4579 ** symbol, FILEIO_WIN32_DLL, must be #define'd to create a stand-alone
4580 ** DLL form of this extension for WIN32. See its use below for details.
4581 */
4582 /* #include "sqlite3ext.h" */
4583 SQLITE_EXTENSION_INIT1
4584 #include <stdio.h>
4585 #include <string.h>
4586 #include <assert.h>
4587
4588 #include <sys/types.h>
4589 #include <sys/stat.h>
4590 #include <fcntl.h>
4591 #if !defined(_WIN32) && !defined(WIN32)
4592 # include <unistd.h>
4593 # include <dirent.h>
4594 # include <utime.h>
4595 # include <sys/time.h>
4596 #else
4597 # include "windows.h"
4598 # include <io.h>
4599 # include <direct.h>
4600 /* # include "test_windirent.h" */
4601 # define dirent DIRENT
4602 # ifndef chmod
4603 # define chmod _chmod
4604 # endif
4605 # ifndef stat
4606 # define stat _stat
4607 # endif
4608 # define mkdir(path,mode) _mkdir(path)
4609 # define lstat(path,buf) stat(path,buf)
4610 #endif
4611 #include <time.h>
4612 #include <errno.h>
4613
4614
4615 /*
4616 ** Structure of the fsdir() table-valued function
4617 */
4618 /* 0 1 2 3 4 5 */
4619 #define FSDIR_SCHEMA "(name,mode,mtime,data,path HIDDEN,dir HIDDEN)"
4620 #define FSDIR_COLUMN_NAME 0 /* Name of the file */
4621 #define FSDIR_COLUMN_MODE 1 /* Access mode */
4622 #define FSDIR_COLUMN_MTIME 2 /* Last modification time */
4623 #define FSDIR_COLUMN_DATA 3 /* File content */
4624 #define FSDIR_COLUMN_PATH 4 /* Path to top of search */
4625 #define FSDIR_COLUMN_DIR 5 /* Path is relative to this directory */
4626
4627
4628 /*
4629 ** Set the result stored by context ctx to a blob containing the
4630 ** contents of file zName. Or, leave the result unchanged (NULL)
4631 ** if the file does not exist or is unreadable.
4632 **
4633 ** If the file exceeds the SQLite blob size limit, through an
4634 ** SQLITE_TOOBIG error.
4635 **
4636 ** Throw an SQLITE_IOERR if there are difficulties pulling the file
4637 ** off of disk.
4638 */
4639 static void readFileContents(sqlite3_context *ctx, const char *zName){
4640 FILE *in;
4641 sqlite3_int64 nIn;
4642 void *pBuf;
4643 sqlite3 *db;
4644 int mxBlob;
4645
4646 in = fopen(zName, "rb");
4647 if( in==0 ){
4648 /* File does not exist or is unreadable. Leave the result set to NULL. */
4649 return;
4650 }
4651 fseek(in, 0, SEEK_END);
4652 nIn = ftell(in);
4653 rewind(in);
4654 db = sqlite3_context_db_handle(ctx);
4655 mxBlob = sqlite3_limit(db, SQLITE_LIMIT_LENGTH, -1);
4656 if( nIn>mxBlob ){
4657 sqlite3_result_error_code(ctx, SQLITE_TOOBIG);
4658 fclose(in);
4659 return;
4660 }
4661 pBuf = sqlite3_malloc64( nIn ? nIn : 1 );
4662 if( pBuf==0 ){
4663 sqlite3_result_error_nomem(ctx);
4664 fclose(in);
4665 return;
4666 }
4667 if( nIn==(sqlite3_int64)fread(pBuf, 1, (size_t)nIn, in) ){
4668 sqlite3_result_blob64(ctx, pBuf, nIn, sqlite3_free);
4669 }else{
4670 sqlite3_result_error_code(ctx, SQLITE_IOERR);
4671 sqlite3_free(pBuf);
4672 }
4673 fclose(in);
4674 }
4675
4676 /*
4677 ** Implementation of the "readfile(X)" SQL function. The entire content
4678 ** of the file named X is read and returned as a BLOB. NULL is returned
4679 ** if the file does not exist or is unreadable.
4680 */
4681 static void readfileFunc(
4682 sqlite3_context *context,
4683 int argc,
4684 sqlite3_value **argv
4685 ){
4686 const char *zName;
4687 (void)(argc); /* Unused parameter */
4688 zName = (const char*)sqlite3_value_text(argv[0]);
4689 if( zName==0 ) return;
4690 readFileContents(context, zName);
4691 }
4692
4693 /*
4694 ** Set the error message contained in context ctx to the results of
4695 ** vprintf(zFmt, ...).
4696 */
4697 static void ctxErrorMsg(sqlite3_context *ctx, const char *zFmt, ...){
4698 char *zMsg = 0;
4699 va_list ap;
4700 va_start(ap, zFmt);
4701 zMsg = sqlite3_vmprintf(zFmt, ap);
4702 sqlite3_result_error(ctx, zMsg, -1);
4703 sqlite3_free(zMsg);
4704 va_end(ap);
4705 }
4706
4707 #if defined(_WIN32)
4708 /*
4709 ** This function is designed to convert a Win32 FILETIME structure into the
4710 ** number of seconds since the Unix Epoch (1970-01-01 00:00:00 UTC).
4711 */
4712 static sqlite3_uint64 fileTimeToUnixTime(
4713 LPFILETIME pFileTime
4714 ){
4715 SYSTEMTIME epochSystemTime;
4716 ULARGE_INTEGER epochIntervals;
4717 FILETIME epochFileTime;
4718 ULARGE_INTEGER fileIntervals;
4719
4720 memset(&epochSystemTime, 0, sizeof(SYSTEMTIME));
4721 epochSystemTime.wYear = 1970;
4722 epochSystemTime.wMonth = 1;
4723 epochSystemTime.wDay = 1;
4724 SystemTimeToFileTime(&epochSystemTime, &epochFileTime);
4725 epochIntervals.LowPart = epochFileTime.dwLowDateTime;
4726 epochIntervals.HighPart = epochFileTime.dwHighDateTime;
4727
4728 fileIntervals.LowPart = pFileTime->dwLowDateTime;
4729 fileIntervals.HighPart = pFileTime->dwHighDateTime;
4730
4731 return (fileIntervals.QuadPart - epochIntervals.QuadPart) / 10000000;
4732 }
4733
4734
4735 #if defined(FILEIO_WIN32_DLL) && (defined(_WIN32) || defined(WIN32))
4736 # /* To allow a standalone DLL, use this next replacement function: */
4737 # undef sqlite3_win32_utf8_to_unicode
4738 # define sqlite3_win32_utf8_to_unicode utf8_to_utf16
4739 #
4740 LPWSTR utf8_to_utf16(const char *z){
4741 int nAllot = MultiByteToWideChar(CP_UTF8, 0, z, -1, NULL, 0);
4742 LPWSTR rv = sqlite3_malloc(nAllot * sizeof(WCHAR));
4743 if( rv!=0 && 0 < MultiByteToWideChar(CP_UTF8, 0, z, -1, rv, nAllot) )
4744 return rv;
4745 sqlite3_free(rv);
4746 return 0;
4747 }
4748 #endif
4749
4750 /*
4751 ** This function attempts to normalize the time values found in the stat()
4752 ** buffer to UTC. This is necessary on Win32, where the runtime library
4753 ** appears to return these values as local times.
4754 */
4755 static void statTimesToUtc(
4756 const char *zPath,
4757 struct stat *pStatBuf
4758 ){
4759 HANDLE hFindFile;
4760 WIN32_FIND_DATAW fd;
4761 LPWSTR zUnicodeName;
4762 extern LPWSTR sqlite3_win32_utf8_to_unicode(const char*);
4763 zUnicodeName = sqlite3_win32_utf8_to_unicode(zPath);
4764 if( zUnicodeName ){
4765 memset(&fd, 0, sizeof(WIN32_FIND_DATAW));
4766 hFindFile = FindFirstFileW(zUnicodeName, &fd);
4767 if( hFindFile!=NULL ){
4768 pStatBuf->st_ctime = (time_t)fileTimeToUnixTime(&fd.ftCreationTime);
4769 pStatBuf->st_atime = (time_t)fileTimeToUnixTime(&fd.ftLastAccessTime);
4770 pStatBuf->st_mtime = (time_t)fileTimeToUnixTime(&fd.ftLastWriteTime);
4771 FindClose(hFindFile);
4772 }
4773 sqlite3_free(zUnicodeName);
4774 }
4775 }
4776 #endif
4777
4778 /*
4779 ** This function is used in place of stat(). On Windows, special handling
4780 ** is required in order for the included time to be returned as UTC. On all
4781 ** other systems, this function simply calls stat().
4782 */
4783 static int fileStat(
4784 const char *zPath,
4785 struct stat *pStatBuf
4786 ){
4787 #if defined(_WIN32)
4788 int rc = stat(zPath, pStatBuf);
4789 if( rc==0 ) statTimesToUtc(zPath, pStatBuf);
4790 return rc;
4791 #else
4792 return stat(zPath, pStatBuf);
4793 #endif
4794 }
4795
4796 /*
4797 ** This function is used in place of lstat(). On Windows, special handling
4798 ** is required in order for the included time to be returned as UTC. On all
4799 ** other systems, this function simply calls lstat().
4800 */
4801 static int fileLinkStat(
4802 const char *zPath,
4803 struct stat *pStatBuf
4804 ){
4805 #if defined(_WIN32)
4806 int rc = lstat(zPath, pStatBuf);
4807 if( rc==0 ) statTimesToUtc(zPath, pStatBuf);
4808 return rc;
4809 #else
4810 return lstat(zPath, pStatBuf);
4811 #endif
4812 }
4813
4814 /*
4815 ** Argument zFile is the name of a file that will be created and/or written
4816 ** by SQL function writefile(). This function ensures that the directory
4817 ** zFile will be written to exists, creating it if required. The permissions
4818 ** for any path components created by this function are set in accordance
4819 ** with the current umask.
4820 **
4821 ** If an OOM condition is encountered, SQLITE_NOMEM is returned. Otherwise,
4822 ** SQLITE_OK is returned if the directory is successfully created, or
4823 ** SQLITE_ERROR otherwise.
4824 */
4825 static int makeDirectory(
4826 const char *zFile
4827 ){
4828 char *zCopy = sqlite3_mprintf("%s", zFile);
4829 int rc = SQLITE_OK;
4830
4831 if( zCopy==0 ){
4832 rc = SQLITE_NOMEM;
4833 }else{
4834 int nCopy = (int)strlen(zCopy);
4835 int i = 1;
4836
4837 while( rc==SQLITE_OK ){
4838 struct stat sStat;
4839 int rc2;
4840
4841 for(; zCopy[i]!='/' && i<nCopy; i++);
4842 if( i==nCopy ) break;
4843 zCopy[i] = '\0';
4844
4845 rc2 = fileStat(zCopy, &sStat);
4846 if( rc2!=0 ){
4847 if( mkdir(zCopy, 0777) ) rc = SQLITE_ERROR;
4848 }else{
4849 if( !S_ISDIR(sStat.st_mode) ) rc = SQLITE_ERROR;
4850 }
4851 zCopy[i] = '/';
4852 i++;
4853 }
4854
4855 sqlite3_free(zCopy);
4856 }
4857
4858 return rc;
4859 }
4860
4861 /*
4862 ** This function does the work for the writefile() UDF. Refer to
4863 ** header comments at the top of this file for details.
4864 */
4865 static int writeFile(
4866 sqlite3_context *pCtx, /* Context to return bytes written in */
4867 const char *zFile, /* File to write */
4868 sqlite3_value *pData, /* Data to write */
4869 mode_t mode, /* MODE parameter passed to writefile() */
4870 sqlite3_int64 mtime /* MTIME parameter (or -1 to not set time) */
4871 ){
4872 if( zFile==0 ) return 1;
4873 #if !defined(_WIN32) && !defined(WIN32)
4874 if( S_ISLNK(mode) ){
4875 const char *zTo = (const char*)sqlite3_value_text(pData);
4876 if( zTo==0 || symlink(zTo, zFile)<0 ) return 1;
4877 }else
4878 #endif
4879 {
4880 if( S_ISDIR(mode) ){
4881 if( mkdir(zFile, mode) ){
4882 /* The mkdir() call to create the directory failed. This might not
4883 ** be an error though - if there is already a directory at the same
4884 ** path and either the permissions already match or can be changed
4885 ** to do so using chmod(), it is not an error. */
4886 struct stat sStat;
4887 if( errno!=EEXIST
4888 || 0!=fileStat(zFile, &sStat)
4889 || !S_ISDIR(sStat.st_mode)
4890 || ((sStat.st_mode&0777)!=(mode&0777) && 0!=chmod(zFile, mode&0777))
4891 ){
4892 return 1;
4893 }
4894 }
4895 }else{
4896 sqlite3_int64 nWrite = 0;
4897 const char *z;
4898 int rc = 0;
4899 FILE *out = fopen(zFile, "wb");
4900 if( out==0 ) return 1;
4901 z = (const char*)sqlite3_value_blob(pData);
4902 if( z ){
4903 sqlite3_int64 n = fwrite(z, 1, sqlite3_value_bytes(pData), out);
4904 nWrite = sqlite3_value_bytes(pData);
4905 if( nWrite!=n ){
4906 rc = 1;
4907 }
4908 }
4909 fclose(out);
4910 if( rc==0 && mode && chmod(zFile, mode & 0777) ){
4911 rc = 1;
4912 }
4913 if( rc ) return 2;
4914 sqlite3_result_int64(pCtx, nWrite);
4915 }
4916 }
4917
4918 if( mtime>=0 ){
4919 #if defined(_WIN32)
4920 #if !SQLITE_OS_WINRT
4921 /* Windows */
4922 FILETIME lastAccess;
4923 FILETIME lastWrite;
4924 SYSTEMTIME currentTime;
4925 LONGLONG intervals;
4926 HANDLE hFile;
4927 LPWSTR zUnicodeName;
4928 extern LPWSTR sqlite3_win32_utf8_to_unicode(const char*);
4929
4930 GetSystemTime(&currentTime);
4931 SystemTimeToFileTime(&currentTime, &lastAccess);
4932 intervals = Int32x32To64(mtime, 10000000) + 116444736000000000;
4933 lastWrite.dwLowDateTime = (DWORD)intervals;
4934 lastWrite.dwHighDateTime = intervals >> 32;
4935 zUnicodeName = sqlite3_win32_utf8_to_unicode(zFile);
4936 if( zUnicodeName==0 ){
4937 return 1;
4938 }
4939 hFile = CreateFileW(
4940 zUnicodeName, FILE_WRITE_ATTRIBUTES, 0, NULL, OPEN_EXISTING,
4941 FILE_FLAG_BACKUP_SEMANTICS, NULL
4942 );
4943 sqlite3_free(zUnicodeName);
4944 if( hFile!=INVALID_HANDLE_VALUE ){
4945 BOOL bResult = SetFileTime(hFile, NULL, &lastAccess, &lastWrite);
4946 CloseHandle(hFile);
4947 return !bResult;
4948 }else{
4949 return 1;
4950 }
4951 #endif
4952 #elif defined(AT_FDCWD) && 0 /* utimensat() is not universally available */
4953 /* Recent unix */
4954 struct timespec times[2];
4955 times[0].tv_nsec = times[1].tv_nsec = 0;
4956 times[0].tv_sec = time(0);
4957 times[1].tv_sec = mtime;
4958 if( utimensat(AT_FDCWD, zFile, times, AT_SYMLINK_NOFOLLOW) ){
4959 return 1;
4960 }
4961 #else
4962 /* Legacy unix */
4963 struct timeval times[2];
4964 times[0].tv_usec = times[1].tv_usec = 0;
4965 times[0].tv_sec = time(0);
4966 times[1].tv_sec = mtime;
4967 if( utimes(zFile, times) ){
4968 return 1;
4969 }
4970 #endif
4971 }
4972
4973 return 0;
4974 }
4975
4976 /*
4977 ** Implementation of the "writefile(W,X[,Y[,Z]]])" SQL function.
4978 ** Refer to header comments at the top of this file for details.
4979 */
4980 static void writefileFunc(
4981 sqlite3_context *context,
4982 int argc,
4983 sqlite3_value **argv
4984 ){
4985 const char *zFile;
4986 mode_t mode = 0;
4987 int res;
4988 sqlite3_int64 mtime = -1;
4989
4990 if( argc<2 || argc>4 ){
4991 sqlite3_result_error(context,
4992 "wrong number of arguments to function writefile()", -1
4993 );
4994 return;
4995 }
4996
4997 zFile = (const char*)sqlite3_value_text(argv[0]);
4998 if( zFile==0 ) return;
4999 if( argc>=3 ){
5000 mode = (mode_t)sqlite3_value_int(argv[2]);
5001 }
5002 if( argc==4 ){
5003 mtime = sqlite3_value_int64(argv[3]);
5004 }
5005
5006 res = writeFile(context, zFile, argv[1], mode, mtime);
5007 if( res==1 && errno==ENOENT ){
5008 if( makeDirectory(zFile)==SQLITE_OK ){
5009 res = writeFile(context, zFile, argv[1], mode, mtime);
5010 }
5011 }
5012
5013 if( argc>2 && res!=0 ){
5014 if( S_ISLNK(mode) ){
5015 ctxErrorMsg(context, "failed to create symlink: %s", zFile);
5016 }else if( S_ISDIR(mode) ){
5017 ctxErrorMsg(context, "failed to create directory: %s", zFile);
5018 }else{
5019 ctxErrorMsg(context, "failed to write file: %s", zFile);
5020 }
5021 }
5022 }
5023
5024 /*
5025 ** SQL function: lsmode(MODE)
5026 **
5027 ** Given a numberic st_mode from stat(), convert it into a human-readable
5028 ** text string in the style of "ls -l".
5029 */
5030 static void lsModeFunc(
5031 sqlite3_context *context,
5032 int argc,
5033 sqlite3_value **argv
5034 ){
5035 int i;
5036 int iMode = sqlite3_value_int(argv[0]);
5037 char z[16];
5038 (void)argc;
5039 if( S_ISLNK(iMode) ){
5040 z[0] = 'l';
5041 }else if( S_ISREG(iMode) ){
5042 z[0] = '-';
5043 }else if( S_ISDIR(iMode) ){
5044 z[0] = 'd';
5045 }else{
5046 z[0] = '?';
5047 }
5048 for(i=0; i<3; i++){
5049 int m = (iMode >> ((2-i)*3));
5050 char *a = &z[1 + i*3];
5051 a[0] = (m & 0x4) ? 'r' : '-';
5052 a[1] = (m & 0x2) ? 'w' : '-';
5053 a[2] = (m & 0x1) ? 'x' : '-';
5054 }
5055 z[10] = '\0';
5056 sqlite3_result_text(context, z, -1, SQLITE_TRANSIENT);
5057 }
5058
5059 #ifndef SQLITE_OMIT_VIRTUALTABLE
5060
5061 /*
5062 ** Cursor type for recursively iterating through a directory structure.
5063 */
5064 typedef struct fsdir_cursor fsdir_cursor;
5065 typedef struct FsdirLevel FsdirLevel;
5066
5067 struct FsdirLevel {
5068 DIR *pDir; /* From opendir() */
5069 char *zDir; /* Name of directory (nul-terminated) */
5070 };
5071
5072 struct fsdir_cursor {
5073 sqlite3_vtab_cursor base; /* Base class - must be first */
5074
5075 int nLvl; /* Number of entries in aLvl[] array */
5076 int iLvl; /* Index of current entry */
5077 FsdirLevel *aLvl; /* Hierarchy of directories being traversed */
5078
5079 const char *zBase;
5080 int nBase;
5081
5082 struct stat sStat; /* Current lstat() results */
5083 char *zPath; /* Path to current entry */
5084 sqlite3_int64 iRowid; /* Current rowid */
5085 };
5086
5087 typedef struct fsdir_tab fsdir_tab;
5088 struct fsdir_tab {
5089 sqlite3_vtab base; /* Base class - must be first */
5090 };
5091
5092 /*
5093 ** Construct a new fsdir virtual table object.
5094 */
5095 static int fsdirConnect(
5096 sqlite3 *db,
5097 void *pAux,
5098 int argc, const char *const*argv,
5099 sqlite3_vtab **ppVtab,
5100 char **pzErr
5101 ){
5102 fsdir_tab *pNew = 0;
5103 int rc;
5104 (void)pAux;
5105 (void)argc;
5106 (void)argv;
5107 (void)pzErr;
5108 rc = sqlite3_declare_vtab(db, "CREATE TABLE x" FSDIR_SCHEMA);
5109 if( rc==SQLITE_OK ){
5110 pNew = (fsdir_tab*)sqlite3_malloc( sizeof(*pNew) );
5111 if( pNew==0 ) return SQLITE_NOMEM;
5112 memset(pNew, 0, sizeof(*pNew));
5113 sqlite3_vtab_config(db, SQLITE_VTAB_DIRECTONLY);
5114 }
5115 *ppVtab = (sqlite3_vtab*)pNew;
5116 return rc;
5117 }
5118
5119 /*
5120 ** This method is the destructor for fsdir vtab objects.
5121 */
5122 static int fsdirDisconnect(sqlite3_vtab *pVtab){
5123 sqlite3_free(pVtab);
5124 return SQLITE_OK;
5125 }
5126
5127 /*
5128 ** Constructor for a new fsdir_cursor object.
5129 */
5130 static int fsdirOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
5131 fsdir_cursor *pCur;
5132 (void)p;
5133 pCur = sqlite3_malloc( sizeof(*pCur) );
5134 if( pCur==0 ) return SQLITE_NOMEM;
5135 memset(pCur, 0, sizeof(*pCur));
5136 pCur->iLvl = -1;
5137 *ppCursor = &pCur->base;
5138 return SQLITE_OK;
5139 }
5140
5141 /*
5142 ** Reset a cursor back to the state it was in when first returned
5143 ** by fsdirOpen().
5144 */
5145 static void fsdirResetCursor(fsdir_cursor *pCur){
5146 int i;
5147 for(i=0; i<=pCur->iLvl; i++){
5148 FsdirLevel *pLvl = &pCur->aLvl[i];
5149 if( pLvl->pDir ) closedir(pLvl->pDir);
5150 sqlite3_free(pLvl->zDir);
5151 }
5152 sqlite3_free(pCur->zPath);
5153 sqlite3_free(pCur->aLvl);
5154 pCur->aLvl = 0;
5155 pCur->zPath = 0;
5156 pCur->zBase = 0;
5157 pCur->nBase = 0;
5158 pCur->nLvl = 0;
5159 pCur->iLvl = -1;
5160 pCur->iRowid = 1;
5161 }
5162
5163 /*
5164 ** Destructor for an fsdir_cursor.
5165 */
5166 static int fsdirClose(sqlite3_vtab_cursor *cur){
5167 fsdir_cursor *pCur = (fsdir_cursor*)cur;
5168
5169 fsdirResetCursor(pCur);
5170 sqlite3_free(pCur);
5171 return SQLITE_OK;
5172 }
5173
5174 /*
5175 ** Set the error message for the virtual table associated with cursor
5176 ** pCur to the results of vprintf(zFmt, ...).
5177 */
5178 static void fsdirSetErrmsg(fsdir_cursor *pCur, const char *zFmt, ...){
5179 va_list ap;
5180 va_start(ap, zFmt);
5181 pCur->base.pVtab->zErrMsg = sqlite3_vmprintf(zFmt, ap);
5182 va_end(ap);
5183 }
5184
5185
5186 /*
5187 ** Advance an fsdir_cursor to its next row of output.
5188 */
5189 static int fsdirNext(sqlite3_vtab_cursor *cur){
5190 fsdir_cursor *pCur = (fsdir_cursor*)cur;
5191 mode_t m = pCur->sStat.st_mode;
5192
5193 pCur->iRowid++;
5194 if( S_ISDIR(m) ){
5195 /* Descend into this directory */
5196 int iNew = pCur->iLvl + 1;
5197 FsdirLevel *pLvl;
5198 if( iNew>=pCur->nLvl ){
5199 int nNew = iNew+1;
5200 sqlite3_int64 nByte = nNew*sizeof(FsdirLevel);
5201 FsdirLevel *aNew = (FsdirLevel*)sqlite3_realloc64(pCur->aLvl, nByte);
5202 if( aNew==0 ) return SQLITE_NOMEM;
5203 memset(&aNew[pCur->nLvl], 0, sizeof(FsdirLevel)*(nNew-pCur->nLvl));
5204 pCur->aLvl = aNew;
5205 pCur->nLvl = nNew;
5206 }
5207 pCur->iLvl = iNew;
5208 pLvl = &pCur->aLvl[iNew];
5209
5210 pLvl->zDir = pCur->zPath;
5211 pCur->zPath = 0;
5212 pLvl->pDir = opendir(pLvl->zDir);
5213 if( pLvl->pDir==0 ){
5214 fsdirSetErrmsg(pCur, "cannot read directory: %s", pCur->zPath);
5215 return SQLITE_ERROR;
5216 }
5217 }
5218
5219 while( pCur->iLvl>=0 ){
5220 FsdirLevel *pLvl = &pCur->aLvl[pCur->iLvl];
5221 struct dirent *pEntry = readdir(pLvl->pDir);
5222 if( pEntry ){
5223 if( pEntry->d_name[0]=='.' ){
5224 if( pEntry->d_name[1]=='.' && pEntry->d_name[2]=='\0' ) continue;
5225 if( pEntry->d_name[1]=='\0' ) continue;
5226 }
5227 sqlite3_free(pCur->zPath);
5228 pCur->zPath = sqlite3_mprintf("%s/%s", pLvl->zDir, pEntry->d_name);
5229 if( pCur->zPath==0 ) return SQLITE_NOMEM;
5230 if( fileLinkStat(pCur->zPath, &pCur->sStat) ){
5231 fsdirSetErrmsg(pCur, "cannot stat file: %s", pCur->zPath);
5232 return SQLITE_ERROR;
5233 }
5234 return SQLITE_OK;
5235 }
5236 closedir(pLvl->pDir);
5237 sqlite3_free(pLvl->zDir);
5238 pLvl->pDir = 0;
5239 pLvl->zDir = 0;
5240 pCur->iLvl--;
5241 }
5242
5243 /* EOF */
5244 sqlite3_free(pCur->zPath);
5245 pCur->zPath = 0;
5246 return SQLITE_OK;
5247 }
5248
5249 /*
5250 ** Return values of columns for the row at which the series_cursor
5251 ** is currently pointing.
5252 */
5253 static int fsdirColumn(
5254 sqlite3_vtab_cursor *cur, /* The cursor */
5255 sqlite3_context *ctx, /* First argument to sqlite3_result_...() */
5256 int i /* Which column to return */
5257 ){
5258 fsdir_cursor *pCur = (fsdir_cursor*)cur;
5259 switch( i ){
5260 case FSDIR_COLUMN_NAME: {
5261 sqlite3_result_text(ctx, &pCur->zPath[pCur->nBase], -1, SQLITE_TRANSIENT);
5262 break;
5263 }
5264
5265 case FSDIR_COLUMN_MODE:
5266 sqlite3_result_int64(ctx, pCur->sStat.st_mode);
5267 break;
5268
5269 case FSDIR_COLUMN_MTIME:
5270 sqlite3_result_int64(ctx, pCur->sStat.st_mtime);
5271 break;
5272
5273 case FSDIR_COLUMN_DATA: {
5274 mode_t m = pCur->sStat.st_mode;
5275 if( S_ISDIR(m) ){
5276 sqlite3_result_null(ctx);
5277 #if !defined(_WIN32) && !defined(WIN32)
5278 }else if( S_ISLNK(m) ){
5279 char aStatic[64];
5280 char *aBuf = aStatic;
5281 sqlite3_int64 nBuf = 64;
5282 int n;
5283
5284 while( 1 ){
5285 n = readlink(pCur->zPath, aBuf, nBuf);
5286 if( n<nBuf ) break;
5287 if( aBuf!=aStatic ) sqlite3_free(aBuf);
5288 nBuf = nBuf*2;
5289 aBuf = sqlite3_malloc64(nBuf);
5290 if( aBuf==0 ){
5291 sqlite3_result_error_nomem(ctx);
5292 return SQLITE_NOMEM;
5293 }
5294 }
5295
5296 sqlite3_result_text(ctx, aBuf, n, SQLITE_TRANSIENT);
5297 if( aBuf!=aStatic ) sqlite3_free(aBuf);
5298 #endif
5299 }else{
5300 readFileContents(ctx, pCur->zPath);
5301 }
5302 }
5303 case FSDIR_COLUMN_PATH:
5304 default: {
5305 /* The FSDIR_COLUMN_PATH and FSDIR_COLUMN_DIR are input parameters.
5306 ** always return their values as NULL */
5307 break;
5308 }
5309 }
5310 return SQLITE_OK;
5311 }
5312
5313 /*
5314 ** Return the rowid for the current row. In this implementation, the
5315 ** first row returned is assigned rowid value 1, and each subsequent
5316 ** row a value 1 more than that of the previous.
5317 */
5318 static int fsdirRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
5319 fsdir_cursor *pCur = (fsdir_cursor*)cur;
5320 *pRowid = pCur->iRowid;
5321 return SQLITE_OK;
5322 }
5323
5324 /*
5325 ** Return TRUE if the cursor has been moved off of the last
5326 ** row of output.
5327 */
5328 static int fsdirEof(sqlite3_vtab_cursor *cur){
5329 fsdir_cursor *pCur = (fsdir_cursor*)cur;
5330 return (pCur->zPath==0);
5331 }
5332
5333 /*
5334 ** xFilter callback.
5335 **
5336 ** idxNum==1 PATH parameter only
5337 ** idxNum==2 Both PATH and DIR supplied
5338 */
5339 static int fsdirFilter(
5340 sqlite3_vtab_cursor *cur,
5341 int idxNum, const char *idxStr,
5342 int argc, sqlite3_value **argv
5343 ){
5344 const char *zDir = 0;
5345 fsdir_cursor *pCur = (fsdir_cursor*)cur;
5346 (void)idxStr;
5347 fsdirResetCursor(pCur);
5348
5349 if( idxNum==0 ){
5350 fsdirSetErrmsg(pCur, "table function fsdir requires an argument");
5351 return SQLITE_ERROR;
5352 }
5353
5354 assert( argc==idxNum && (argc==1 || argc==2) );
5355 zDir = (const char*)sqlite3_value_text(argv[0]);
5356 if( zDir==0 ){
5357 fsdirSetErrmsg(pCur, "table function fsdir requires a non-NULL argument");
5358 return SQLITE_ERROR;
5359 }
5360 if( argc==2 ){
5361 pCur->zBase = (const char*)sqlite3_value_text(argv[1]);
5362 }
5363 if( pCur->zBase ){
5364 pCur->nBase = (int)strlen(pCur->zBase)+1;
5365 pCur->zPath = sqlite3_mprintf("%s/%s", pCur->zBase, zDir);
5366 }else{
5367 pCur->zPath = sqlite3_mprintf("%s", zDir);
5368 }
5369
5370 if( pCur->zPath==0 ){
5371 return SQLITE_NOMEM;
5372 }
5373 if( fileLinkStat(pCur->zPath, &pCur->sStat) ){
5374 fsdirSetErrmsg(pCur, "cannot stat file: %s", pCur->zPath);
5375 return SQLITE_ERROR;
5376 }
5377
5378 return SQLITE_OK;
5379 }
5380
5381 /*
5382 ** SQLite will invoke this method one or more times while planning a query
5383 ** that uses the generate_series virtual table. This routine needs to create
5384 ** a query plan for each invocation and compute an estimated cost for that
5385 ** plan.
5386 **
5387 ** In this implementation idxNum is used to represent the
5388 ** query plan. idxStr is unused.
5389 **
5390 ** The query plan is represented by values of idxNum:
5391 **
5392 ** (1) The path value is supplied by argv[0]
5393 ** (2) Path is in argv[0] and dir is in argv[1]
5394 */
5395 static int fsdirBestIndex(
5396 sqlite3_vtab *tab,
5397 sqlite3_index_info *pIdxInfo
5398 ){
5399 int i; /* Loop over constraints */
5400 int idxPath = -1; /* Index in pIdxInfo->aConstraint of PATH= */
5401 int idxDir = -1; /* Index in pIdxInfo->aConstraint of DIR= */
5402 int seenPath = 0; /* True if an unusable PATH= constraint is seen */
5403 int seenDir = 0; /* True if an unusable DIR= constraint is seen */
5404 const struct sqlite3_index_constraint *pConstraint;
5405
5406 (void)tab;
5407 pConstraint = pIdxInfo->aConstraint;
5408 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
5409 if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
5410 switch( pConstraint->iColumn ){
5411 case FSDIR_COLUMN_PATH: {
5412 if( pConstraint->usable ){
5413 idxPath = i;
5414 seenPath = 0;
5415 }else if( idxPath<0 ){
5416 seenPath = 1;
5417 }
5418 break;
5419 }
5420 case FSDIR_COLUMN_DIR: {
5421 if( pConstraint->usable ){
5422 idxDir = i;
5423 seenDir = 0;
5424 }else if( idxDir<0 ){
5425 seenDir = 1;
5426 }
5427 break;
5428 }
5429 }
5430 }
5431 if( seenPath || seenDir ){
5432 /* If input parameters are unusable, disallow this plan */
5433 return SQLITE_CONSTRAINT;
5434 }
5435
5436 if( idxPath<0 ){
5437 pIdxInfo->idxNum = 0;
5438 /* The pIdxInfo->estimatedCost should have been initialized to a huge
5439 ** number. Leave it unchanged. */
5440 pIdxInfo->estimatedRows = 0x7fffffff;
5441 }else{
5442 pIdxInfo->aConstraintUsage[idxPath].omit = 1;
5443 pIdxInfo->aConstraintUsage[idxPath].argvIndex = 1;
5444 if( idxDir>=0 ){
5445 pIdxInfo->aConstraintUsage[idxDir].omit = 1;
5446 pIdxInfo->aConstraintUsage[idxDir].argvIndex = 2;
5447 pIdxInfo->idxNum = 2;
5448 pIdxInfo->estimatedCost = 10.0;
5449 }else{
5450 pIdxInfo->idxNum = 1;
5451 pIdxInfo->estimatedCost = 100.0;
5452 }
5453 }
5454
5455 return SQLITE_OK;
5456 }
5457
5458 /*
5459 ** Register the "fsdir" virtual table.
5460 */
5461 static int fsdirRegister(sqlite3 *db){
5462 static sqlite3_module fsdirModule = {
5463 0, /* iVersion */
5464 0, /* xCreate */
5465 fsdirConnect, /* xConnect */
5466 fsdirBestIndex, /* xBestIndex */
5467 fsdirDisconnect, /* xDisconnect */
5468 0, /* xDestroy */
5469 fsdirOpen, /* xOpen - open a cursor */
5470 fsdirClose, /* xClose - close a cursor */
5471 fsdirFilter, /* xFilter - configure scan constraints */
5472 fsdirNext, /* xNext - advance a cursor */
5473 fsdirEof, /* xEof - check for end of scan */
5474 fsdirColumn, /* xColumn - read data */
5475 fsdirRowid, /* xRowid - read data */
5476 0, /* xUpdate */
5477 0, /* xBegin */
5478 0, /* xSync */
5479 0, /* xCommit */
5480 0, /* xRollback */
5481 0, /* xFindMethod */
5482 0, /* xRename */
5483 0, /* xSavepoint */
5484 0, /* xRelease */
5485 0, /* xRollbackTo */
5486 0, /* xShadowName */
5487 };
5488
5489 int rc = sqlite3_create_module(db, "fsdir", &fsdirModule, 0);
5490 return rc;
5491 }
5492 #else /* SQLITE_OMIT_VIRTUALTABLE */
5493 # define fsdirRegister(x) SQLITE_OK
5494 #endif
5495
5496 #ifdef _WIN32
5497
5498 #endif
5499 int sqlite3_fileio_init(
5500 sqlite3 *db,
5501 char **pzErrMsg,
5502 const sqlite3_api_routines *pApi
5503 ){
5504 int rc = SQLITE_OK;
5505 SQLITE_EXTENSION_INIT2(pApi);
5506 (void)pzErrMsg; /* Unused parameter */
5507 rc = sqlite3_create_function(db, "readfile", 1,
5508 SQLITE_UTF8|SQLITE_DIRECTONLY, 0,
5509 readfileFunc, 0, 0);
5510 if( rc==SQLITE_OK ){
5511 rc = sqlite3_create_function(db, "writefile", -1,
5512 SQLITE_UTF8|SQLITE_DIRECTONLY, 0,
5513 writefileFunc, 0, 0);
5514 }
5515 if( rc==SQLITE_OK ){
5516 rc = sqlite3_create_function(db, "lsmode", 1, SQLITE_UTF8, 0,
5517 lsModeFunc, 0, 0);
5518 }
5519 if( rc==SQLITE_OK ){
5520 rc = fsdirRegister(db);
5521 }
5522 return rc;
5523 }
5524
5525 #if defined(FILEIO_WIN32_DLL) && (defined(_WIN32) || defined(WIN32))
5526 /* To allow a standalone DLL, make test_windirent.c use the same
5527 * redefined SQLite API calls as the above extension code does.
5528 * Just pull in this .c to accomplish this. As a beneficial side
5529 * effect, this extension becomes a single translation unit. */
5530 # include "test_windirent.c"
5531 #endif
5532
5533 /************************* End ../ext/misc/fileio.c ********************/
5534 /************************* Begin ../ext/misc/completion.c ******************/
5535 /*
5536 ** 2017-07-10
5537 **
5538 ** The author disclaims copyright to this source code. In place of
5539 ** a legal notice, here is a blessing:
5540 **
5541 ** May you do good and not evil.
5542 ** May you find forgiveness for yourself and forgive others.
5543 ** May you share freely, never taking more than you give.
5544 **
5545 *************************************************************************
5546 **
5547 ** This file implements an eponymous virtual table that returns suggested
5548 ** completions for a partial SQL input.
5549 **
5550 ** Suggested usage:
5551 **
5552 ** SELECT DISTINCT candidate COLLATE nocase
5553 ** FROM completion($prefix,$wholeline)
5554 ** ORDER BY 1;
5555 **
5556 ** The two query parameters are optional. $prefix is the text of the
5557 ** current word being typed and that is to be completed. $wholeline is
5558 ** the complete input line, used for context.
5559 **
5560 ** The raw completion() table might return the same candidate multiple
5561 ** times, for example if the same column name is used to two or more
5562 ** tables. And the candidates are returned in an arbitrary order. Hence,
5563 ** the DISTINCT and ORDER BY are recommended.
5564 **
5565 ** This virtual table operates at the speed of human typing, and so there
5566 ** is no attempt to make it fast. Even a slow implementation will be much
5567 ** faster than any human can type.
5568 **
5569 */
5570 /* #include "sqlite3ext.h" */
5571 SQLITE_EXTENSION_INIT1
5572 #include <assert.h>
5573 #include <string.h>
5574 #include <ctype.h>
5575
5576 #ifndef SQLITE_OMIT_VIRTUALTABLE
5577
5578 /* completion_vtab is a subclass of sqlite3_vtab which will
5579 ** serve as the underlying representation of a completion virtual table
5580 */
5581 typedef struct completion_vtab completion_vtab;
5582 struct completion_vtab {
5583 sqlite3_vtab base; /* Base class - must be first */
5584 sqlite3 *db; /* Database connection for this completion vtab */
5585 };
5586
5587 /* completion_cursor is a subclass of sqlite3_vtab_cursor which will
5588 ** serve as the underlying representation of a cursor that scans
5589 ** over rows of the result
5590 */
5591 typedef struct completion_cursor completion_cursor;
5592 struct completion_cursor {
5593 sqlite3_vtab_cursor base; /* Base class - must be first */
5594 sqlite3 *db; /* Database connection for this cursor */
5595 int nPrefix, nLine; /* Number of bytes in zPrefix and zLine */
5596 char *zPrefix; /* The prefix for the word we want to complete */
5597 char *zLine; /* The whole that we want to complete */
5598 const char *zCurrentRow; /* Current output row */
5599 int szRow; /* Length of the zCurrentRow string */
5600 sqlite3_stmt *pStmt; /* Current statement */
5601 sqlite3_int64 iRowid; /* The rowid */
5602 int ePhase; /* Current phase */
5603 int j; /* inter-phase counter */
5604 };
5605
5606 /* Values for ePhase:
5607 */
5608 #define COMPLETION_FIRST_PHASE 1
5609 #define COMPLETION_KEYWORDS 1
5610 #define COMPLETION_PRAGMAS 2
5611 #define COMPLETION_FUNCTIONS 3
5612 #define COMPLETION_COLLATIONS 4
5613 #define COMPLETION_INDEXES 5
5614 #define COMPLETION_TRIGGERS 6
5615 #define COMPLETION_DATABASES 7
5616 #define COMPLETION_TABLES 8 /* Also VIEWs and TRIGGERs */
5617 #define COMPLETION_COLUMNS 9
5618 #define COMPLETION_MODULES 10
5619 #define COMPLETION_EOF 11
5620
5621 /*
5622 ** The completionConnect() method is invoked to create a new
5623 ** completion_vtab that describes the completion virtual table.
5624 **
5625 ** Think of this routine as the constructor for completion_vtab objects.
5626 **
5627 ** All this routine needs to do is:
5628 **
5629 ** (1) Allocate the completion_vtab object and initialize all fields.
5630 **
5631 ** (2) Tell SQLite (via the sqlite3_declare_vtab() interface) what the
5632 ** result set of queries against completion will look like.
5633 */
5634 static int completionConnect(
5635 sqlite3 *db,
5636 void *pAux,
5637 int argc, const char *const*argv,
5638 sqlite3_vtab **ppVtab,
5639 char **pzErr
5640 ){
5641 completion_vtab *pNew;
5642 int rc;
5643
5644 (void)(pAux); /* Unused parameter */
5645 (void)(argc); /* Unused parameter */
5646 (void)(argv); /* Unused parameter */
5647 (void)(pzErr); /* Unused parameter */
5648
5649 /* Column numbers */
5650 #define COMPLETION_COLUMN_CANDIDATE 0 /* Suggested completion of the input */
5651 #define COMPLETION_COLUMN_PREFIX 1 /* Prefix of the word to be completed */
5652 #define COMPLETION_COLUMN_WHOLELINE 2 /* Entire line seen so far */
5653 #define COMPLETION_COLUMN_PHASE 3 /* ePhase - used for debugging only */
5654
5655 sqlite3_vtab_config(db, SQLITE_VTAB_INNOCUOUS);
5656 rc = sqlite3_declare_vtab(db,
5657 "CREATE TABLE x("
5658 " candidate TEXT,"
5659 " prefix TEXT HIDDEN,"
5660 " wholeline TEXT HIDDEN,"
5661 " phase INT HIDDEN" /* Used for debugging only */
5662 ")");
5663 if( rc==SQLITE_OK ){
5664 pNew = sqlite3_malloc( sizeof(*pNew) );
5665 *ppVtab = (sqlite3_vtab*)pNew;
5666 if( pNew==0 ) return SQLITE_NOMEM;
5667 memset(pNew, 0, sizeof(*pNew));
5668 pNew->db = db;
5669 }
5670 return rc;
5671 }
5672
5673 /*
5674 ** This method is the destructor for completion_cursor objects.
5675 */
5676 static int completionDisconnect(sqlite3_vtab *pVtab){
5677 sqlite3_free(pVtab);
5678 return SQLITE_OK;
5679 }
5680
5681 /*
5682 ** Constructor for a new completion_cursor object.
5683 */
5684 static int completionOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
5685 completion_cursor *pCur;
5686 pCur = sqlite3_malloc( sizeof(*pCur) );
5687 if( pCur==0 ) return SQLITE_NOMEM;
5688 memset(pCur, 0, sizeof(*pCur));
5689 pCur->db = ((completion_vtab*)p)->db;
5690 *ppCursor = &pCur->base;
5691 return SQLITE_OK;
5692 }
5693
5694 /*
5695 ** Reset the completion_cursor.
5696 */
5697 static void completionCursorReset(completion_cursor *pCur){
5698 sqlite3_free(pCur->zPrefix); pCur->zPrefix = 0; pCur->nPrefix = 0;
5699 sqlite3_free(pCur->zLine); pCur->zLine = 0; pCur->nLine = 0;
5700 sqlite3_finalize(pCur->pStmt); pCur->pStmt = 0;
5701 pCur->j = 0;
5702 }
5703
5704 /*
5705 ** Destructor for a completion_cursor.
5706 */
5707 static int completionClose(sqlite3_vtab_cursor *cur){
5708 completionCursorReset((completion_cursor*)cur);
5709 sqlite3_free(cur);
5710 return SQLITE_OK;
5711 }
5712
5713 /*
5714 ** Advance a completion_cursor to its next row of output.
5715 **
5716 ** The ->ePhase, ->j, and ->pStmt fields of the completion_cursor object
5717 ** record the current state of the scan. This routine sets ->zCurrentRow
5718 ** to the current row of output and then returns. If no more rows remain,
5719 ** then ->ePhase is set to COMPLETION_EOF which will signal the virtual
5720 ** table that has reached the end of its scan.
5721 **
5722 ** The current implementation just lists potential identifiers and
5723 ** keywords and filters them by zPrefix. Future enhancements should
5724 ** take zLine into account to try to restrict the set of identifiers and
5725 ** keywords based on what would be legal at the current point of input.
5726 */
5727 static int completionNext(sqlite3_vtab_cursor *cur){
5728 completion_cursor *pCur = (completion_cursor*)cur;
5729 int eNextPhase = 0; /* Next phase to try if current phase reaches end */
5730 int iCol = -1; /* If >=0, step pCur->pStmt and use the i-th column */
5731 pCur->iRowid++;
5732 while( pCur->ePhase!=COMPLETION_EOF ){
5733 switch( pCur->ePhase ){
5734 case COMPLETION_KEYWORDS: {
5735 if( pCur->j >= sqlite3_keyword_count() ){
5736 pCur->zCurrentRow = 0;
5737 pCur->ePhase = COMPLETION_DATABASES;
5738 }else{
5739 sqlite3_keyword_name(pCur->j++, &pCur->zCurrentRow, &pCur->szRow);
5740 }
5741 iCol = -1;
5742 break;
5743 }
5744 case COMPLETION_DATABASES: {
5745 if( pCur->pStmt==0 ){
5746 sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1,
5747 &pCur->pStmt, 0);
5748 }
5749 iCol = 1;
5750 eNextPhase = COMPLETION_TABLES;
5751 break;
5752 }
5753 case COMPLETION_TABLES: {
5754 if( pCur->pStmt==0 ){
5755 sqlite3_stmt *pS2;
5756 char *zSql = 0;
5757 const char *zSep = "";
5758 sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, &pS2, 0);
5759 while( sqlite3_step(pS2)==SQLITE_ROW ){
5760 const char *zDb = (const char*)sqlite3_column_text(pS2, 1);
5761 zSql = sqlite3_mprintf(
5762 "%z%s"
5763 "SELECT name FROM \"%w\".sqlite_schema",
5764 zSql, zSep, zDb
5765 );
5766 if( zSql==0 ) return SQLITE_NOMEM;
5767 zSep = " UNION ";
5768 }
5769 sqlite3_finalize(pS2);
5770 sqlite3_prepare_v2(pCur->db, zSql, -1, &pCur->pStmt, 0);
5771 sqlite3_free(zSql);
5772 }
5773 iCol = 0;
5774 eNextPhase = COMPLETION_COLUMNS;
5775 break;
5776 }
5777 case COMPLETION_COLUMNS: {
5778 if( pCur->pStmt==0 ){
5779 sqlite3_stmt *pS2;
5780 char *zSql = 0;
5781 const char *zSep = "";
5782 sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, &pS2, 0);
5783 while( sqlite3_step(pS2)==SQLITE_ROW ){
5784 const char *zDb = (const char*)sqlite3_column_text(pS2, 1);
5785 zSql = sqlite3_mprintf(
5786 "%z%s"
5787 "SELECT pti.name FROM \"%w\".sqlite_schema AS sm"
5788 " JOIN pragma_table_info(sm.name,%Q) AS pti"
5789 " WHERE sm.type='table'",
5790 zSql, zSep, zDb, zDb
5791 );
5792 if( zSql==0 ) return SQLITE_NOMEM;
5793 zSep = " UNION ";
5794 }
5795 sqlite3_finalize(pS2);
5796 sqlite3_prepare_v2(pCur->db, zSql, -1, &pCur->pStmt, 0);
5797 sqlite3_free(zSql);
5798 }
5799 iCol = 0;
5800 eNextPhase = COMPLETION_EOF;
5801 break;
5802 }
5803 }
5804 if( iCol<0 ){
5805 /* This case is when the phase presets zCurrentRow */
5806 if( pCur->zCurrentRow==0 ) continue;
5807 }else{
5808 if( sqlite3_step(pCur->pStmt)==SQLITE_ROW ){
5809 /* Extract the next row of content */
5810 pCur->zCurrentRow = (const char*)sqlite3_column_text(pCur->pStmt, iCol);
5811 pCur->szRow = sqlite3_column_bytes(pCur->pStmt, iCol);
5812 }else{
5813 /* When all rows are finished, advance to the next phase */
5814 sqlite3_finalize(pCur->pStmt);
5815 pCur->pStmt = 0;
5816 pCur->ePhase = eNextPhase;
5817 continue;
5818 }
5819 }
5820 if( pCur->nPrefix==0 ) break;
5821 if( pCur->nPrefix<=pCur->szRow
5822 && sqlite3_strnicmp(pCur->zPrefix, pCur->zCurrentRow, pCur->nPrefix)==0
5823 ){
5824 break;
5825 }
5826 }
5827
5828 return SQLITE_OK;
5829 }
5830
5831 /*
5832 ** Return values of columns for the row at which the completion_cursor
5833 ** is currently pointing.
5834 */
5835 static int completionColumn(
5836 sqlite3_vtab_cursor *cur, /* The cursor */
5837 sqlite3_context *ctx, /* First argument to sqlite3_result_...() */
5838 int i /* Which column to return */
5839 ){
5840 completion_cursor *pCur = (completion_cursor*)cur;
5841 switch( i ){
5842 case COMPLETION_COLUMN_CANDIDATE: {
5843 sqlite3_result_text(ctx, pCur->zCurrentRow, pCur->szRow,SQLITE_TRANSIENT);
5844 break;
5845 }
5846 case COMPLETION_COLUMN_PREFIX: {
5847 sqlite3_result_text(ctx, pCur->zPrefix, -1, SQLITE_TRANSIENT);
5848 break;
5849 }
5850 case COMPLETION_COLUMN_WHOLELINE: {
5851 sqlite3_result_text(ctx, pCur->zLine, -1, SQLITE_TRANSIENT);
5852 break;
5853 }
5854 case COMPLETION_COLUMN_PHASE: {
5855 sqlite3_result_int(ctx, pCur->ePhase);
5856 break;
5857 }
5858 }
5859 return SQLITE_OK;
5860 }
5861
5862 /*
5863 ** Return the rowid for the current row. In this implementation, the
5864 ** rowid is the same as the output value.
5865 */
5866 static int completionRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
5867 completion_cursor *pCur = (completion_cursor*)cur;
5868 *pRowid = pCur->iRowid;
5869 return SQLITE_OK;
5870 }
5871
5872 /*
5873 ** Return TRUE if the cursor has been moved off of the last
5874 ** row of output.
5875 */
5876 static int completionEof(sqlite3_vtab_cursor *cur){
5877 completion_cursor *pCur = (completion_cursor*)cur;
5878 return pCur->ePhase >= COMPLETION_EOF;
5879 }
5880
5881 /*
5882 ** This method is called to "rewind" the completion_cursor object back
5883 ** to the first row of output. This method is always called at least
5884 ** once prior to any call to completionColumn() or completionRowid() or
5885 ** completionEof().
5886 */
5887 static int completionFilter(
5888 sqlite3_vtab_cursor *pVtabCursor,
5889 int idxNum, const char *idxStr,
5890 int argc, sqlite3_value **argv
5891 ){
5892 completion_cursor *pCur = (completion_cursor *)pVtabCursor;
5893 int iArg = 0;
5894 (void)(idxStr); /* Unused parameter */
5895 (void)(argc); /* Unused parameter */
5896 completionCursorReset(pCur);
5897 if( idxNum & 1 ){
5898 pCur->nPrefix = sqlite3_value_bytes(argv[iArg]);
5899 if( pCur->nPrefix>0 ){
5900 pCur->zPrefix = sqlite3_mprintf("%s", sqlite3_value_text(argv[iArg]));
5901 if( pCur->zPrefix==0 ) return SQLITE_NOMEM;
5902 }
5903 iArg = 1;
5904 }
5905 if( idxNum & 2 ){
5906 pCur->nLine = sqlite3_value_bytes(argv[iArg]);
5907 if( pCur->nLine>0 ){
5908 pCur->zLine = sqlite3_mprintf("%s", sqlite3_value_text(argv[iArg]));
5909 if( pCur->zLine==0 ) return SQLITE_NOMEM;
5910 }
5911 }
5912 if( pCur->zLine!=0 && pCur->zPrefix==0 ){
5913 int i = pCur->nLine;
5914 while( i>0 && (isalnum(pCur->zLine[i-1]) || pCur->zLine[i-1]=='_') ){
5915 i--;
5916 }
5917 pCur->nPrefix = pCur->nLine - i;
5918 if( pCur->nPrefix>0 ){
5919 pCur->zPrefix = sqlite3_mprintf("%.*s", pCur->nPrefix, pCur->zLine + i);
5920 if( pCur->zPrefix==0 ) return SQLITE_NOMEM;
5921 }
5922 }
5923 pCur->iRowid = 0;
5924 pCur->ePhase = COMPLETION_FIRST_PHASE;
5925 return completionNext(pVtabCursor);
5926 }
5927
5928 /*
5929 ** SQLite will invoke this method one or more times while planning a query
5930 ** that uses the completion virtual table. This routine needs to create
5931 ** a query plan for each invocation and compute an estimated cost for that
5932 ** plan.
5933 **
5934 ** There are two hidden parameters that act as arguments to the table-valued
5935 ** function: "prefix" and "wholeline". Bit 0 of idxNum is set if "prefix"
5936 ** is available and bit 1 is set if "wholeline" is available.
5937 */
5938 static int completionBestIndex(
5939 sqlite3_vtab *tab,
5940 sqlite3_index_info *pIdxInfo
5941 ){
5942 int i; /* Loop over constraints */
5943 int idxNum = 0; /* The query plan bitmask */
5944 int prefixIdx = -1; /* Index of the start= constraint, or -1 if none */
5945 int wholelineIdx = -1; /* Index of the stop= constraint, or -1 if none */
5946 int nArg = 0; /* Number of arguments that completeFilter() expects */
5947 const struct sqlite3_index_constraint *pConstraint;
5948
5949 (void)(tab); /* Unused parameter */
5950 pConstraint = pIdxInfo->aConstraint;
5951 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
5952 if( pConstraint->usable==0 ) continue;
5953 if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
5954 switch( pConstraint->iColumn ){
5955 case COMPLETION_COLUMN_PREFIX:
5956 prefixIdx = i;
5957 idxNum |= 1;
5958 break;
5959 case COMPLETION_COLUMN_WHOLELINE:
5960 wholelineIdx = i;
5961 idxNum |= 2;
5962 break;
5963 }
5964 }
5965 if( prefixIdx>=0 ){
5966 pIdxInfo->aConstraintUsage[prefixIdx].argvIndex = ++nArg;
5967 pIdxInfo->aConstraintUsage[prefixIdx].omit = 1;
5968 }
5969 if( wholelineIdx>=0 ){
5970 pIdxInfo->aConstraintUsage[wholelineIdx].argvIndex = ++nArg;
5971 pIdxInfo->aConstraintUsage[wholelineIdx].omit = 1;
5972 }
5973 pIdxInfo->idxNum = idxNum;
5974 pIdxInfo->estimatedCost = (double)5000 - 1000*nArg;
5975 pIdxInfo->estimatedRows = 500 - 100*nArg;
5976 return SQLITE_OK;
5977 }
5978
5979 /*
5980 ** This following structure defines all the methods for the
5981 ** completion virtual table.
5982 */
5983 static sqlite3_module completionModule = {
5984 0, /* iVersion */
5985 0, /* xCreate */
5986 completionConnect, /* xConnect */
5987 completionBestIndex, /* xBestIndex */
5988 completionDisconnect, /* xDisconnect */
5989 0, /* xDestroy */
5990 completionOpen, /* xOpen - open a cursor */
5991 completionClose, /* xClose - close a cursor */
5992 completionFilter, /* xFilter - configure scan constraints */
5993 completionNext, /* xNext - advance a cursor */
5994 completionEof, /* xEof - check for end of scan */
5995 completionColumn, /* xColumn - read data */
5996 completionRowid, /* xRowid - read data */
5997 0, /* xUpdate */
5998 0, /* xBegin */
5999 0, /* xSync */
6000 0, /* xCommit */
6001 0, /* xRollback */
6002 0, /* xFindMethod */
6003 0, /* xRename */
6004 0, /* xSavepoint */
6005 0, /* xRelease */
6006 0, /* xRollbackTo */
6007 0 /* xShadowName */
6008 };
6009
6010 #endif /* SQLITE_OMIT_VIRTUALTABLE */
6011
6012 int sqlite3CompletionVtabInit(sqlite3 *db){
6013 int rc = SQLITE_OK;
6014 #ifndef SQLITE_OMIT_VIRTUALTABLE
6015 rc = sqlite3_create_module(db, "completion", &completionModule, 0);
6016 #endif
6017 return rc;
6018 }
6019
6020 #ifdef _WIN32
6021
6022 #endif
6023 int sqlite3_completion_init(
6024 sqlite3 *db,
6025 char **pzErrMsg,
6026 const sqlite3_api_routines *pApi
6027 ){
6028 int rc = SQLITE_OK;
6029 SQLITE_EXTENSION_INIT2(pApi);
6030 (void)(pzErrMsg); /* Unused parameter */
6031 #ifndef SQLITE_OMIT_VIRTUALTABLE
6032 rc = sqlite3CompletionVtabInit(db);
6033 #endif
6034 return rc;
6035 }
6036
6037 /************************* End ../ext/misc/completion.c ********************/
6038 /************************* Begin ../ext/misc/appendvfs.c ******************/
6039 /*
6040 ** 2017-10-20
6041 **
6042 ** The author disclaims copyright to this source code. In place of
6043 ** a legal notice, here is a blessing:
6044 **
6045 ** May you do good and not evil.
6046 ** May you find forgiveness for yourself and forgive others.
6047 ** May you share freely, never taking more than you give.
6048 **
6049 ******************************************************************************
6050 **
6051 ** This file implements a VFS shim that allows an SQLite database to be
6052 ** appended onto the end of some other file, such as an executable.
6053 **
6054 ** A special record must appear at the end of the file that identifies the
6055 ** file as an appended database and provides the offset to the first page
6056 ** of the exposed content. (Or, it is the length of the content prefix.)
6057 ** For best performance page 1 should be located at a disk page boundary,
6058 ** though that is not required.
6059 **
6060 ** When opening a database using this VFS, the connection might treat
6061 ** the file as an ordinary SQLite database, or it might treat it as a
6062 ** database appended onto some other file. The decision is made by
6063 ** applying the following rules in order:
6064 **
6065 ** (1) An empty file is an ordinary database.
6066 **
6067 ** (2) If the file ends with the appendvfs trailer string
6068 ** "Start-Of-SQLite3-NNNNNNNN" that file is an appended database.
6069 **
6070 ** (3) If the file begins with the standard SQLite prefix string
6071 ** "SQLite format 3", that file is an ordinary database.
6072 **
6073 ** (4) If none of the above apply and the SQLITE_OPEN_CREATE flag is
6074 ** set, then a new database is appended to the already existing file.
6075 **
6076 ** (5) Otherwise, SQLITE_CANTOPEN is returned.
6077 **
6078 ** To avoid unnecessary complications with the PENDING_BYTE, the size of
6079 ** the file containing the database is limited to 1GiB. (1073741824 bytes)
6080 ** This VFS will not read or write past the 1GiB mark. This restriction
6081 ** might be lifted in future versions. For now, if you need a larger
6082 ** database, then keep it in a separate file.
6083 **
6084 ** If the file being opened is a plain database (not an appended one), then
6085 ** this shim is a pass-through into the default underlying VFS. (rule 3)
6086 **/
6087 /* #include "sqlite3ext.h" */
6088 SQLITE_EXTENSION_INIT1
6089 #include <string.h>
6090 #include <assert.h>
6091
6092 /* The append mark at the end of the database is:
6093 **
6094 ** Start-Of-SQLite3-NNNNNNNN
6095 ** 123456789 123456789 12345
6096 **
6097 ** The NNNNNNNN represents a 64-bit big-endian unsigned integer which is
6098 ** the offset to page 1, and also the length of the prefix content.
6099 */
6100 #define APND_MARK_PREFIX "Start-Of-SQLite3-"
6101 #define APND_MARK_PREFIX_SZ 17
6102 #define APND_MARK_FOS_SZ 8
6103 #define APND_MARK_SIZE (APND_MARK_PREFIX_SZ+APND_MARK_FOS_SZ)
6104
6105 /*
6106 ** Maximum size of the combined prefix + database + append-mark. This
6107 ** must be less than 0x40000000 to avoid locking issues on Windows.
6108 */
6109 #define APND_MAX_SIZE (0x40000000)
6110
6111 /*
6112 ** Try to align the database to an even multiple of APND_ROUNDUP bytes.
6113 */
6114 #ifndef APND_ROUNDUP
6115 #define APND_ROUNDUP 4096
6116 #endif
6117 #define APND_ALIGN_MASK ((sqlite3_int64)(APND_ROUNDUP-1))
6118 #define APND_START_ROUNDUP(fsz) (((fsz)+APND_ALIGN_MASK) & ~APND_ALIGN_MASK)
6119
6120 /*
6121 ** Forward declaration of objects used by this utility
6122 */
6123 typedef struct sqlite3_vfs ApndVfs;
6124 typedef struct ApndFile ApndFile;
6125
6126 /* Access to a lower-level VFS that (might) implement dynamic loading,
6127 ** access to randomness, etc.
6128 */
6129 #define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData))
6130 #define ORIGFILE(p) ((sqlite3_file*)(((ApndFile*)(p))+1))
6131
6132 /* An open appendvfs file
6133 **
6134 ** An instance of this structure describes the appended database file.
6135 ** A separate sqlite3_file object is always appended. The appended
6136 ** sqlite3_file object (which can be accessed using ORIGFILE()) describes
6137 ** the entire file, including the prefix, the database, and the
6138 ** append-mark.
6139 **
6140 ** The structure of an AppendVFS database is like this:
6141 **
6142 ** +-------------+---------+----------+-------------+
6143 ** | prefix-file | padding | database | append-mark |
6144 ** +-------------+---------+----------+-------------+
6145 ** ^ ^
6146 ** | |
6147 ** iPgOne iMark
6148 **
6149 **
6150 ** "prefix file" - file onto which the database has been appended.
6151 ** "padding" - zero or more bytes inserted so that "database"
6152 ** starts on an APND_ROUNDUP boundary
6153 ** "database" - The SQLite database file
6154 ** "append-mark" - The 25-byte "Start-Of-SQLite3-NNNNNNNN" that indicates
6155 ** the offset from the start of prefix-file to the start
6156 ** of "database".
6157 **
6158 ** The size of the database is iMark - iPgOne.
6159 **
6160 ** The NNNNNNNN in the "Start-Of-SQLite3-NNNNNNNN" suffix is the value
6161 ** of iPgOne stored as a big-ending 64-bit integer.
6162 **
6163 ** iMark will be the size of the underlying file minus 25 (APND_MARKSIZE).
6164 ** Or, iMark is -1 to indicate that it has not yet been written.
6165 */
6166 struct ApndFile {
6167 sqlite3_file base; /* Subclass. MUST BE FIRST! */
6168 sqlite3_int64 iPgOne; /* Offset to the start of the database */
6169 sqlite3_int64 iMark; /* Offset of the append mark. -1 if unwritten */
6170 /* Always followed by another sqlite3_file that describes the whole file */
6171 };
6172
6173 /*
6174 ** Methods for ApndFile
6175 */
6176 static int apndClose(sqlite3_file*);
6177 static int apndRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
6178 static int apndWrite(sqlite3_file*,const void*,int iAmt, sqlite3_int64 iOfst);
6179 static int apndTruncate(sqlite3_file*, sqlite3_int64 size);
6180 static int apndSync(sqlite3_file*, int flags);
6181 static int apndFileSize(sqlite3_file*, sqlite3_int64 *pSize);
6182 static int apndLock(sqlite3_file*, int);
6183 static int apndUnlock(sqlite3_file*, int);
6184 static int apndCheckReservedLock(sqlite3_file*, int *pResOut);
6185 static int apndFileControl(sqlite3_file*, int op, void *pArg);
6186 static int apndSectorSize(sqlite3_file*);
6187 static int apndDeviceCharacteristics(sqlite3_file*);
6188 static int apndShmMap(sqlite3_file*, int iPg, int pgsz, int, void volatile**);
6189 static int apndShmLock(sqlite3_file*, int offset, int n, int flags);
6190 static void apndShmBarrier(sqlite3_file*);
6191 static int apndShmUnmap(sqlite3_file*, int deleteFlag);
6192 static int apndFetch(sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp);
6193 static int apndUnfetch(sqlite3_file*, sqlite3_int64 iOfst, void *p);
6194
6195 /*
6196 ** Methods for ApndVfs
6197 */
6198 static int apndOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *);
6199 static int apndDelete(sqlite3_vfs*, const char *zName, int syncDir);
6200 static int apndAccess(sqlite3_vfs*, const char *zName, int flags, int *);
6201 static int apndFullPathname(sqlite3_vfs*, const char *zName, int, char *zOut);
6202 static void *apndDlOpen(sqlite3_vfs*, const char *zFilename);
6203 static void apndDlError(sqlite3_vfs*, int nByte, char *zErrMsg);
6204 static void (*apndDlSym(sqlite3_vfs *pVfs, void *p, const char*zSym))(void);
6205 static void apndDlClose(sqlite3_vfs*, void*);
6206 static int apndRandomness(sqlite3_vfs*, int nByte, char *zOut);
6207 static int apndSleep(sqlite3_vfs*, int microseconds);
6208 static int apndCurrentTime(sqlite3_vfs*, double*);
6209 static int apndGetLastError(sqlite3_vfs*, int, char *);
6210 static int apndCurrentTimeInt64(sqlite3_vfs*, sqlite3_int64*);
6211 static int apndSetSystemCall(sqlite3_vfs*, const char*,sqlite3_syscall_ptr);
6212 static sqlite3_syscall_ptr apndGetSystemCall(sqlite3_vfs*, const char *z);
6213 static const char *apndNextSystemCall(sqlite3_vfs*, const char *zName);
6214
6215 static sqlite3_vfs apnd_vfs = {
6216 3, /* iVersion (set when registered) */
6217 0, /* szOsFile (set when registered) */
6218 1024, /* mxPathname */
6219 0, /* pNext */
6220 "apndvfs", /* zName */
6221 0, /* pAppData (set when registered) */
6222 apndOpen, /* xOpen */
6223 apndDelete, /* xDelete */
6224 apndAccess, /* xAccess */
6225 apndFullPathname, /* xFullPathname */
6226 apndDlOpen, /* xDlOpen */
6227 apndDlError, /* xDlError */
6228 apndDlSym, /* xDlSym */
6229 apndDlClose, /* xDlClose */
6230 apndRandomness, /* xRandomness */
6231 apndSleep, /* xSleep */
6232 apndCurrentTime, /* xCurrentTime */
6233 apndGetLastError, /* xGetLastError */
6234 apndCurrentTimeInt64, /* xCurrentTimeInt64 */
6235 apndSetSystemCall, /* xSetSystemCall */
6236 apndGetSystemCall, /* xGetSystemCall */
6237 apndNextSystemCall /* xNextSystemCall */
6238 };
6239
6240 static const sqlite3_io_methods apnd_io_methods = {
6241 3, /* iVersion */
6242 apndClose, /* xClose */
6243 apndRead, /* xRead */
6244 apndWrite, /* xWrite */
6245 apndTruncate, /* xTruncate */
6246 apndSync, /* xSync */
6247 apndFileSize, /* xFileSize */
6248 apndLock, /* xLock */
6249 apndUnlock, /* xUnlock */
6250 apndCheckReservedLock, /* xCheckReservedLock */
6251 apndFileControl, /* xFileControl */
6252 apndSectorSize, /* xSectorSize */
6253 apndDeviceCharacteristics, /* xDeviceCharacteristics */
6254 apndShmMap, /* xShmMap */
6255 apndShmLock, /* xShmLock */
6256 apndShmBarrier, /* xShmBarrier */
6257 apndShmUnmap, /* xShmUnmap */
6258 apndFetch, /* xFetch */
6259 apndUnfetch /* xUnfetch */
6260 };
6261
6262 /*
6263 ** Close an apnd-file.
6264 */
6265 static int apndClose(sqlite3_file *pFile){
6266 pFile = ORIGFILE(pFile);
6267 return pFile->pMethods->xClose(pFile);
6268 }
6269
6270 /*
6271 ** Read data from an apnd-file.
6272 */
6273 static int apndRead(
6274 sqlite3_file *pFile,
6275 void *zBuf,
6276 int iAmt,
6277 sqlite_int64 iOfst
6278 ){
6279 ApndFile *paf = (ApndFile *)pFile;
6280 pFile = ORIGFILE(pFile);
6281 return pFile->pMethods->xRead(pFile, zBuf, iAmt, paf->iPgOne+iOfst);
6282 }
6283
6284 /*
6285 ** Add the append-mark onto what should become the end of the file.
6286 * If and only if this succeeds, internal ApndFile.iMark is updated.
6287 * Parameter iWriteEnd is the appendvfs-relative offset of the new mark.
6288 */
6289 static int apndWriteMark(
6290 ApndFile *paf,
6291 sqlite3_file *pFile,
6292 sqlite_int64 iWriteEnd
6293 ){
6294 sqlite_int64 iPgOne = paf->iPgOne;
6295 unsigned char a[APND_MARK_SIZE];
6296 int i = APND_MARK_FOS_SZ;
6297 int rc;
6298 assert(pFile == ORIGFILE(paf));
6299 memcpy(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ);
6300 while( --i >= 0 ){
6301 a[APND_MARK_PREFIX_SZ+i] = (unsigned char)(iPgOne & 0xff);
6302 iPgOne >>= 8;
6303 }
6304 iWriteEnd += paf->iPgOne;
6305 if( SQLITE_OK==(rc = pFile->pMethods->xWrite
6306 (pFile, a, APND_MARK_SIZE, iWriteEnd)) ){
6307 paf->iMark = iWriteEnd;
6308 }
6309 return rc;
6310 }
6311
6312 /*
6313 ** Write data to an apnd-file.
6314 */
6315 static int apndWrite(
6316 sqlite3_file *pFile,
6317 const void *zBuf,
6318 int iAmt,
6319 sqlite_int64 iOfst
6320 ){
6321 ApndFile *paf = (ApndFile *)pFile;
6322 sqlite_int64 iWriteEnd = iOfst + iAmt;
6323 if( iWriteEnd>=APND_MAX_SIZE ) return SQLITE_FULL;
6324 pFile = ORIGFILE(pFile);
6325 /* If append-mark is absent or will be overwritten, write it. */
6326 if( paf->iMark < 0 || paf->iPgOne + iWriteEnd > paf->iMark ){
6327 int rc = apndWriteMark(paf, pFile, iWriteEnd);
6328 if( SQLITE_OK!=rc ) return rc;
6329 }
6330 return pFile->pMethods->xWrite(pFile, zBuf, iAmt, paf->iPgOne+iOfst);
6331 }
6332
6333 /*
6334 ** Truncate an apnd-file.
6335 */
6336 static int apndTruncate(sqlite3_file *pFile, sqlite_int64 size){
6337 ApndFile *paf = (ApndFile *)pFile;
6338 pFile = ORIGFILE(pFile);
6339 /* The append mark goes out first so truncate failure does not lose it. */
6340 if( SQLITE_OK!=apndWriteMark(paf, pFile, size) ) return SQLITE_IOERR;
6341 /* Truncate underlying file just past append mark */
6342 return pFile->pMethods->xTruncate(pFile, paf->iMark+APND_MARK_SIZE);
6343 }
6344
6345 /*
6346 ** Sync an apnd-file.
6347 */
6348 static int apndSync(sqlite3_file *pFile, int flags){
6349 pFile = ORIGFILE(pFile);
6350 return pFile->pMethods->xSync(pFile, flags);
6351 }
6352
6353 /*
6354 ** Return the current file-size of an apnd-file.
6355 ** If the append mark is not yet there, the file-size is 0.
6356 */
6357 static int apndFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
6358 ApndFile *paf = (ApndFile *)pFile;
6359 *pSize = ( paf->iMark >= 0 )? (paf->iMark - paf->iPgOne) : 0;
6360 return SQLITE_OK;
6361 }
6362
6363 /*
6364 ** Lock an apnd-file.
6365 */
6366 static int apndLock(sqlite3_file *pFile, int eLock){
6367 pFile = ORIGFILE(pFile);
6368 return pFile->pMethods->xLock(pFile, eLock);
6369 }
6370
6371 /*
6372 ** Unlock an apnd-file.
6373 */
6374 static int apndUnlock(sqlite3_file *pFile, int eLock){
6375 pFile = ORIGFILE(pFile);
6376 return pFile->pMethods->xUnlock(pFile, eLock);
6377 }
6378
6379 /*
6380 ** Check if another file-handle holds a RESERVED lock on an apnd-file.
6381 */
6382 static int apndCheckReservedLock(sqlite3_file *pFile, int *pResOut){
6383 pFile = ORIGFILE(pFile);
6384 return pFile->pMethods->xCheckReservedLock(pFile, pResOut);
6385 }
6386
6387 /*
6388 ** File control method. For custom operations on an apnd-file.
6389 */
6390 static int apndFileControl(sqlite3_file *pFile, int op, void *pArg){
6391 ApndFile *paf = (ApndFile *)pFile;
6392 int rc;
6393 pFile = ORIGFILE(pFile);
6394 if( op==SQLITE_FCNTL_SIZE_HINT ) *(sqlite3_int64*)pArg += paf->iPgOne;
6395 rc = pFile->pMethods->xFileControl(pFile, op, pArg);
6396 if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
6397 *(char**)pArg = sqlite3_mprintf("apnd(%lld)/%z", paf->iPgOne,*(char**)pArg);
6398 }
6399 return rc;
6400 }
6401
6402 /*
6403 ** Return the sector-size in bytes for an apnd-file.
6404 */
6405 static int apndSectorSize(sqlite3_file *pFile){
6406 pFile = ORIGFILE(pFile);
6407 return pFile->pMethods->xSectorSize(pFile);
6408 }
6409
6410 /*
6411 ** Return the device characteristic flags supported by an apnd-file.
6412 */
6413 static int apndDeviceCharacteristics(sqlite3_file *pFile){
6414 pFile = ORIGFILE(pFile);
6415 return pFile->pMethods->xDeviceCharacteristics(pFile);
6416 }
6417
6418 /* Create a shared memory file mapping */
6419 static int apndShmMap(
6420 sqlite3_file *pFile,
6421 int iPg,
6422 int pgsz,
6423 int bExtend,
6424 void volatile **pp
6425 ){
6426 pFile = ORIGFILE(pFile);
6427 return pFile->pMethods->xShmMap(pFile,iPg,pgsz,bExtend,pp);
6428 }
6429
6430 /* Perform locking on a shared-memory segment */
6431 static int apndShmLock(sqlite3_file *pFile, int offset, int n, int flags){
6432 pFile = ORIGFILE(pFile);
6433 return pFile->pMethods->xShmLock(pFile,offset,n,flags);
6434 }
6435
6436 /* Memory barrier operation on shared memory */
6437 static void apndShmBarrier(sqlite3_file *pFile){
6438 pFile = ORIGFILE(pFile);
6439 pFile->pMethods->xShmBarrier(pFile);
6440 }
6441
6442 /* Unmap a shared memory segment */
6443 static int apndShmUnmap(sqlite3_file *pFile, int deleteFlag){
6444 pFile = ORIGFILE(pFile);
6445 return pFile->pMethods->xShmUnmap(pFile,deleteFlag);
6446 }
6447
6448 /* Fetch a page of a memory-mapped file */
6449 static int apndFetch(
6450 sqlite3_file *pFile,
6451 sqlite3_int64 iOfst,
6452 int iAmt,
6453 void **pp
6454 ){
6455 ApndFile *p = (ApndFile *)pFile;
6456 if( p->iMark < 0 || iOfst+iAmt > p->iMark ){
6457 return SQLITE_IOERR; /* Cannot read what is not yet there. */
6458 }
6459 pFile = ORIGFILE(pFile);
6460 return pFile->pMethods->xFetch(pFile, iOfst+p->iPgOne, iAmt, pp);
6461 }
6462
6463 /* Release a memory-mapped page */
6464 static int apndUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){
6465 ApndFile *p = (ApndFile *)pFile;
6466 pFile = ORIGFILE(pFile);
6467 return pFile->pMethods->xUnfetch(pFile, iOfst+p->iPgOne, pPage);
6468 }
6469
6470 /*
6471 ** Try to read the append-mark off the end of a file. Return the
6472 ** start of the appended database if the append-mark is present.
6473 ** If there is no valid append-mark, return -1;
6474 **
6475 ** An append-mark is only valid if the NNNNNNNN start-of-database offset
6476 ** indicates that the appended database contains at least one page. The
6477 ** start-of-database value must be a multiple of 512.
6478 */
6479 static sqlite3_int64 apndReadMark(sqlite3_int64 sz, sqlite3_file *pFile){
6480 int rc, i;
6481 sqlite3_int64 iMark;
6482 int msbs = 8 * (APND_MARK_FOS_SZ-1);
6483 unsigned char a[APND_MARK_SIZE];
6484
6485 if( APND_MARK_SIZE!=(sz & 0x1ff) ) return -1;
6486 rc = pFile->pMethods->xRead(pFile, a, APND_MARK_SIZE, sz-APND_MARK_SIZE);
6487 if( rc ) return -1;
6488 if( memcmp(a, APND_MARK_PREFIX, APND_MARK_PREFIX_SZ)!=0 ) return -1;
6489 iMark = ((sqlite3_int64)(a[APND_MARK_PREFIX_SZ] & 0x7f)) << msbs;
6490 for(i=1; i<8; i++){
6491 msbs -= 8;
6492 iMark |= (sqlite3_int64)a[APND_MARK_PREFIX_SZ+i]<<msbs;
6493 }
6494 if( iMark > (sz - APND_MARK_SIZE - 512) ) return -1;
6495 if( iMark & 0x1ff ) return -1;
6496 return iMark;
6497 }
6498
6499 static const char apvfsSqliteHdr[] = "SQLite format 3";
6500 /*
6501 ** Check to see if the file is an appendvfs SQLite database file.
6502 ** Return true iff it is such. Parameter sz is the file's size.
6503 */
6504 static int apndIsAppendvfsDatabase(sqlite3_int64 sz, sqlite3_file *pFile){
6505 int rc;
6506 char zHdr[16];
6507 sqlite3_int64 iMark = apndReadMark(sz, pFile);
6508 if( iMark>=0 ){
6509 /* If file has the correct end-marker, the expected odd size, and the
6510 ** SQLite DB type marker where the end-marker puts it, then it
6511 ** is an appendvfs database.
6512 */
6513 rc = pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), iMark);
6514 if( SQLITE_OK==rc
6515 && memcmp(zHdr, apvfsSqliteHdr, sizeof(zHdr))==0
6516 && (sz & 0x1ff) == APND_MARK_SIZE
6517 && sz>=512+APND_MARK_SIZE
6518 ){
6519 return 1; /* It's an appendvfs database */
6520 }
6521 }
6522 return 0;
6523 }
6524
6525 /*
6526 ** Check to see if the file is an ordinary SQLite database file.
6527 ** Return true iff so. Parameter sz is the file's size.
6528 */
6529 static int apndIsOrdinaryDatabaseFile(sqlite3_int64 sz, sqlite3_file *pFile){
6530 char zHdr[16];
6531 if( apndIsAppendvfsDatabase(sz, pFile) /* rule 2 */
6532 || (sz & 0x1ff) != 0
6533 || SQLITE_OK!=pFile->pMethods->xRead(pFile, zHdr, sizeof(zHdr), 0)
6534 || memcmp(zHdr, apvfsSqliteHdr, sizeof(zHdr))!=0
6535 ){
6536 return 0;
6537 }else{
6538 return 1;
6539 }
6540 }
6541
6542 /*
6543 ** Open an apnd file handle.
6544 */
6545 static int apndOpen(
6546 sqlite3_vfs *pApndVfs,
6547 const char *zName,
6548 sqlite3_file *pFile,
6549 int flags,
6550 int *pOutFlags
6551 ){
6552 ApndFile *pApndFile = (ApndFile*)pFile;
6553 sqlite3_file *pBaseFile = ORIGFILE(pFile);
6554 sqlite3_vfs *pBaseVfs = ORIGVFS(pApndVfs);
6555 int rc;
6556 sqlite3_int64 sz = 0;
6557 if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
6558 /* The appendvfs is not to be used for transient or temporary databases.
6559 ** Just use the base VFS open to initialize the given file object and
6560 ** open the underlying file. (Appendvfs is then unused for this file.)
6561 */
6562 return pBaseVfs->xOpen(pBaseVfs, zName, pFile, flags, pOutFlags);
6563 }
6564 memset(pApndFile, 0, sizeof(ApndFile));
6565 pFile->pMethods = &apnd_io_methods;
6566 pApndFile->iMark = -1; /* Append mark not yet written */
6567
6568 rc = pBaseVfs->xOpen(pBaseVfs, zName, pBaseFile, flags, pOutFlags);
6569 if( rc==SQLITE_OK ){
6570 rc = pBaseFile->pMethods->xFileSize(pBaseFile, &sz);
6571 if( rc ){
6572 pBaseFile->pMethods->xClose(pBaseFile);
6573 }
6574 }
6575 if( rc ){
6576 pFile->pMethods = 0;
6577 return rc;
6578 }
6579 if( apndIsOrdinaryDatabaseFile(sz, pBaseFile) ){
6580 /* The file being opened appears to be just an ordinary DB. Copy
6581 ** the base dispatch-table so this instance mimics the base VFS.
6582 */
6583 memmove(pApndFile, pBaseFile, pBaseVfs->szOsFile);
6584 return SQLITE_OK;
6585 }
6586 pApndFile->iPgOne = apndReadMark(sz, pFile);
6587 if( pApndFile->iPgOne>=0 ){
6588 pApndFile->iMark = sz - APND_MARK_SIZE; /* Append mark found */
6589 return SQLITE_OK;
6590 }
6591 if( (flags & SQLITE_OPEN_CREATE)==0 ){
6592 pBaseFile->pMethods->xClose(pBaseFile);
6593 rc = SQLITE_CANTOPEN;
6594 pFile->pMethods = 0;
6595 }else{
6596 /* Round newly added appendvfs location to #define'd page boundary.
6597 ** Note that nothing has yet been written to the underlying file.
6598 ** The append mark will be written along with first content write.
6599 ** Until then, paf->iMark value indicates it is not yet written.
6600 */
6601 pApndFile->iPgOne = APND_START_ROUNDUP(sz);
6602 }
6603 return rc;
6604 }
6605
6606 /*
6607 ** Delete an apnd file.
6608 ** For an appendvfs, this could mean delete the appendvfs portion,
6609 ** leaving the appendee as it was before it gained an appendvfs.
6610 ** For now, this code deletes the underlying file too.
6611 */
6612 static int apndDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
6613 return ORIGVFS(pVfs)->xDelete(ORIGVFS(pVfs), zPath, dirSync);
6614 }
6615
6616 /*
6617 ** All other VFS methods are pass-thrus.
6618 */
6619 static int apndAccess(
6620 sqlite3_vfs *pVfs,
6621 const char *zPath,
6622 int flags,
6623 int *pResOut
6624 ){
6625 return ORIGVFS(pVfs)->xAccess(ORIGVFS(pVfs), zPath, flags, pResOut);
6626 }
6627 static int apndFullPathname(
6628 sqlite3_vfs *pVfs,
6629 const char *zPath,
6630 int nOut,
6631 char *zOut
6632 ){
6633 return ORIGVFS(pVfs)->xFullPathname(ORIGVFS(pVfs),zPath,nOut,zOut);
6634 }
6635 static void *apndDlOpen(sqlite3_vfs *pVfs, const char *zPath){
6636 return ORIGVFS(pVfs)->xDlOpen(ORIGVFS(pVfs), zPath);
6637 }
6638 static void apndDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){
6639 ORIGVFS(pVfs)->xDlError(ORIGVFS(pVfs), nByte, zErrMsg);
6640 }
6641 static void (*apndDlSym(sqlite3_vfs *pVfs, void *p, const char *zSym))(void){
6642 return ORIGVFS(pVfs)->xDlSym(ORIGVFS(pVfs), p, zSym);
6643 }
6644 static void apndDlClose(sqlite3_vfs *pVfs, void *pHandle){
6645 ORIGVFS(pVfs)->xDlClose(ORIGVFS(pVfs), pHandle);
6646 }
6647 static int apndRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
6648 return ORIGVFS(pVfs)->xRandomness(ORIGVFS(pVfs), nByte, zBufOut);
6649 }
6650 static int apndSleep(sqlite3_vfs *pVfs, int nMicro){
6651 return ORIGVFS(pVfs)->xSleep(ORIGVFS(pVfs), nMicro);
6652 }
6653 static int apndCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
6654 return ORIGVFS(pVfs)->xCurrentTime(ORIGVFS(pVfs), pTimeOut);
6655 }
6656 static int apndGetLastError(sqlite3_vfs *pVfs, int a, char *b){
6657 return ORIGVFS(pVfs)->xGetLastError(ORIGVFS(pVfs), a, b);
6658 }
6659 static int apndCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *p){
6660 return ORIGVFS(pVfs)->xCurrentTimeInt64(ORIGVFS(pVfs), p);
6661 }
6662 static int apndSetSystemCall(
6663 sqlite3_vfs *pVfs,
6664 const char *zName,
6665 sqlite3_syscall_ptr pCall
6666 ){
6667 return ORIGVFS(pVfs)->xSetSystemCall(ORIGVFS(pVfs),zName,pCall);
6668 }
6669 static sqlite3_syscall_ptr apndGetSystemCall(
6670 sqlite3_vfs *pVfs,
6671 const char *zName
6672 ){
6673 return ORIGVFS(pVfs)->xGetSystemCall(ORIGVFS(pVfs),zName);
6674 }
6675 static const char *apndNextSystemCall(sqlite3_vfs *pVfs, const char *zName){
6676 return ORIGVFS(pVfs)->xNextSystemCall(ORIGVFS(pVfs), zName);
6677 }
6678
6679
6680 #ifdef _WIN32
6681
6682 #endif
6683 /*
6684 ** This routine is called when the extension is loaded.
6685 ** Register the new VFS.
6686 */
6687 int sqlite3_appendvfs_init(
6688 sqlite3 *db,
6689 char **pzErrMsg,
6690 const sqlite3_api_routines *pApi
6691 ){
6692 int rc = SQLITE_OK;
6693 sqlite3_vfs *pOrig;
6694 SQLITE_EXTENSION_INIT2(pApi);
6695 (void)pzErrMsg;
6696 (void)db;
6697 pOrig = sqlite3_vfs_find(0);
6698 if( pOrig==0 ) return SQLITE_ERROR;
6699 apnd_vfs.iVersion = pOrig->iVersion;
6700 apnd_vfs.pAppData = pOrig;
6701 apnd_vfs.szOsFile = pOrig->szOsFile + sizeof(ApndFile);
6702 rc = sqlite3_vfs_register(&apnd_vfs, 0);
6703 #ifdef APPENDVFS_TEST
6704 if( rc==SQLITE_OK ){
6705 rc = sqlite3_auto_extension((void(*)(void))apndvfsRegister);
6706 }
6707 #endif
6708 if( rc==SQLITE_OK ) rc = SQLITE_OK_LOAD_PERMANENTLY;
6709 return rc;
6710 }
6711
6712 /************************* End ../ext/misc/appendvfs.c ********************/
6713 #endif
6714 #ifdef SQLITE_HAVE_ZLIB
6715 /************************* Begin ../ext/misc/zipfile.c ******************/
6716 /*
6717 ** 2017-12-26
6718 **
@@ -12235,11 +12248,21 @@
12248 int nIndent; /* Size of array aiIndent[] */
12249 int iIndent; /* Index of current op in aiIndent[] */
12250 char *zNonce; /* Nonce for temporary safe-mode excapes */
12251 EQPGraph sGraph; /* Information for the graphical EXPLAIN QUERY PLAN */
12252 ExpertInfo expert; /* Valid if previous command was ".expert OPT..." */
12253 #ifdef SQLITE_SHELL_WASM_MODE
12254 struct {
12255 const char * zInput; /* Input string from wasm/JS proxy */
12256 const char * zPos; /* Cursor pos into zInput */
12257 } wasm;
12258 #endif
12259 };
12260
12261 #ifdef SQLITE_SHELL_WASM_MODE
12262 static ShellState shellState;
12263 #endif
12264
12265
12266 /* Allowed values for ShellState.autoEQP
12267 */
12268 #define AUTOEQP_off 0 /* Automatic EXPLAIN QUERY PLAN is off */
@@ -12277,11 +12300,11 @@
12300 #define SHFLG_Lookaside 0x00000002 /* Lookaside memory is used */
12301 #define SHFLG_Backslash 0x00000004 /* The --backslash option is used */
12302 #define SHFLG_PreserveRowid 0x00000008 /* .dump preserves rowid values */
12303 #define SHFLG_Newlines 0x00000010 /* .dump --newline flag */
12304 #define SHFLG_CountChanges 0x00000020 /* .changes setting */
12305 #define SHFLG_Echo 0x00000040 /* .echo on/off, or --echo setting */
12306 #define SHFLG_HeaderSet 0x00000080 /* showHeader has been specified */
12307 #define SHFLG_DumpDataOnly 0x00000100 /* .dump show data only */
12308 #define SHFLG_DumpNoSys 0x00000200 /* .dump omits system tables */
12309
12310 /*
@@ -14906,15 +14929,10 @@
14929 if( pArg ){
14930 pArg->pStmt = pStmt;
14931 pArg->cnt = 0;
14932 }
14933
 
 
 
 
 
14934 /* Show the EXPLAIN QUERY PLAN if .eqp is on */
14935 if( pArg && pArg->autoEQP && sqlite3_stmt_isexplain(pStmt)==0 ){
14936 sqlite3_stmt *pExplain;
14937 char *zEQP;
14938 int triggerEQP = 0;
@@ -15309,17 +15327,18 @@
15327
15328 /*
15329 ** Text of help messages.
15330 **
15331 ** The help text for each individual command begins with a line that starts
15332 ** with ".". Subsequent lines are supplemental information.
15333 **
15334 ** There must be two or more spaces between the end of the command and the
15335 ** start of the description of what that command does.
15336 */
15337 static const char *(azHelp[]) = {
15338 #if defined(SQLITE_HAVE_ZLIB) && !defined(SQLITE_OMIT_VIRTUALTABLE) \
15339 && !defined(SQLITE_SHELL_WASM_MODE)
15340 ".archive ... Manage SQL archives",
15341 " Each command must have exactly one of the following options:",
15342 " -c, --create Create a new archive",
15343 " -u, --update Add or update files with changed mtime",
15344 " -i, --insert Like -u but always add even if unchanged",
@@ -15341,20 +15360,26 @@
15360 " http://sqlite.org/cli.html#sqlite_archive_support",
15361 #endif
15362 #ifndef SQLITE_OMIT_AUTHORIZATION
15363 ".auth ON|OFF Show authorizer callbacks",
15364 #endif
15365 #ifndef SQLITE_SHELL_WASM_MODE
15366 ".backup ?DB? FILE Backup DB (default \"main\") to FILE",
15367 " Options:",
15368 " --append Use the appendvfs",
15369 " --async Write to FILE without journal and fsync()",
15370 #endif
15371 ".bail on|off Stop after hitting an error. Default OFF",
15372 ".binary on|off Turn binary output on or off. Default OFF",
15373 #ifndef SQLITE_SHELL_WASM_MODE
15374 ".cd DIRECTORY Change the working directory to DIRECTORY",
15375 #endif
15376 ".changes on|off Show number of rows changed by SQL",
15377 #ifndef SQLITE_SHELL_WASM_MODE
15378 ".check GLOB Fail if output since .testcase does not match",
15379 ".clone NEWDB Clone data into NEWDB from the existing database",
15380 #endif
15381 ".connection [close] [#] Open or close an auxiliary database connection",
15382 ".databases List names and files of attached databases",
15383 ".dbconfig ?op? ?val? List or change sqlite3_db_config() options",
15384 ".dbinfo ?DB? Show status information about the database",
15385 ".dump ?OBJECTS? Render database content as SQL",
@@ -15371,21 +15396,26 @@
15396 #ifdef SQLITE_DEBUG
15397 " test Show raw EXPLAIN QUERY PLAN output",
15398 " trace Like \"full\" but enable \"PRAGMA vdbe_trace\"",
15399 #endif
15400 " trigger Like \"full\" but also show trigger bytecode",
15401 #ifndef SQLITE_SHELL_WASM_MODE
15402 ".excel Display the output of next command in spreadsheet",
15403 " --bom Put a UTF8 byte-order mark on intermediate file",
15404 #endif
15405 #ifndef SQLITE_SHELL_WASM_MODE
15406 ".exit ?CODE? Exit this program with return-code CODE",
15407 #endif
15408 ".expert EXPERIMENTAL. Suggest indexes for queries",
15409 ".explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto",
15410 ".filectrl CMD ... Run various sqlite3_file_control() operations",
15411 " --schema SCHEMA Use SCHEMA instead of \"main\"",
15412 " --help Show CMD details",
15413 ".fullschema ?--indent? Show schema and the content of sqlite_stat tables",
15414 ".headers on|off Turn display of headers on or off",
15415 ".help ?-all? ?PATTERN? Show help text for PATTERN",
15416 #ifndef SQLITE_SHELL_WASM_MODE
15417 ".import FILE TABLE Import data from FILE into TABLE",
15418 " Options:",
15419 " --ascii Use \\037 and \\036 as column and row separators",
15420 " --csv Use , and \\n as column and row separators",
15421 " --skip N Skip the first N rows of input",
@@ -15396,10 +15426,11 @@
15426 " determines the column names.",
15427 " * If neither --csv or --ascii are used, the input mode is derived",
15428 " from the \".mode\" output mode",
15429 " * If FILE begins with \"|\" then it is a command that generates the",
15430 " input text.",
15431 #endif
15432 #ifndef SQLITE_OMIT_TEST_CONTROL
15433 ".imposter INDEX TABLE Create imposter table TABLE on index INDEX",
15434 #endif
15435 ".indexes ?TABLE? Show names of indexes",
15436 " If TABLE is specified, only show indexes for",
@@ -15409,14 +15440,16 @@
15440 #endif
15441 ".limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT",
15442 ".lint OPTIONS Report potential schema issues.",
15443 " Options:",
15444 " fkey-indexes Find missing foreign key indexes",
15445 #if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_WASM_MODE)
15446 ".load FILE ?ENTRY? Load an extension library",
15447 #endif
15448 #ifndef SQLITE_SHELL_WASM_MODE
15449 ".log FILE|off Turn logging on or off. FILE can be stderr/stdout",
15450 #endif
15451 ".mode MODE ?OPTIONS? Set output mode",
15452 " MODE is one of:",
15453 " ascii Columns/rows delimited by 0x1F and 0x1E",
15454 " box Tables using unicode box-drawing characters",
15455 " csv Comma-separated values",
@@ -15437,35 +15470,44 @@
15470 " --wordwrap B Wrap or not at word boundaries per B (on/off)",
15471 " --ww Shorthand for \"--wordwrap 1\"",
15472 " --quote Quote output text as SQL literals",
15473 " --noquote Do not quote output text",
15474 " TABLE The name of SQL table used for \"insert\" mode",
15475 #ifndef SQLITE_SHELL_WASM_MODE
15476 ".nonce STRING Suspend safe mode for one command if nonce matches",
15477 #endif
15478 ".nullvalue STRING Use STRING in place of NULL values",
15479 #ifndef SQLITE_SHELL_WASM_MODE
15480 ".once ?OPTIONS? ?FILE? Output for the next SQL command only to FILE",
15481 " If FILE begins with '|' then open as a pipe",
15482 " --bom Put a UTF8 byte-order mark at the beginning",
15483 " -e Send output to the system text editor",
15484 " -x Send output as CSV to a spreadsheet (same as \".excel\")",
15485 /* Note that .open is (partially) available in WASM builds but is
15486 ** currently only intended to be used by the fiddle tool, not
15487 ** end users, so is "undocumented." */
15488 ".open ?OPTIONS? ?FILE? Close existing database and reopen FILE",
15489 " Options:",
15490 " --append Use appendvfs to append database to the end of FILE",
15491 #endif
15492 #ifndef SQLITE_OMIT_DESERIALIZE
15493 " --deserialize Load into memory using sqlite3_deserialize()",
15494 " --hexdb Load the output of \"dbtotxt\" as an in-memory db",
15495 " --maxsize N Maximum size for --hexdb or --deserialized database",
15496 #endif
15497 " --new Initialize FILE to an empty database",
15498 " --nofollow Do not follow symbolic links",
15499 " --readonly Open FILE readonly",
15500 " --zip FILE is a ZIP archive",
15501 #ifndef SQLITE_SHELL_WASM_MODE
15502 ".output ?FILE? Send output to FILE or stdout if FILE is omitted",
15503 " If FILE begins with '|' then open it as a pipe.",
15504 " Options:",
15505 " --bom Prefix output with a UTF8 byte-order mark",
15506 " -e Send output to the system text editor",
15507 " -x Send output as CSV to a spreadsheet",
15508 #endif
15509 ".parameter CMD ... Manage SQL parameter bindings",
15510 " clear Erase all bindings",
15511 " init Initialize the TEMP table that holds bindings",
15512 " list List the current parameter bindings",
15513 " set PARAMETER VALUE Given SQL parameter PARAMETER a value of VALUE",
@@ -15478,23 +15520,27 @@
15520 " --once Do no more than one progress interrupt",
15521 " --quiet|-q No output except at interrupts",
15522 " --reset Reset the count for each input and interrupt",
15523 #endif
15524 ".prompt MAIN CONTINUE Replace the standard prompts",
15525 #ifndef SQLITE_SHELL_WASM_MODE
15526 ".quit Exit this program",
15527 ".read FILE Read input from FILE or command output",
15528 " If FILE begins with \"|\", it is a command that generates the input.",
15529 #endif
15530 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
15531 ".recover Recover as much data as possible from corrupt db.",
15532 " --freelist-corrupt Assume the freelist is corrupt",
15533 " --recovery-db NAME Store recovery metadata in database file NAME",
15534 " --lost-and-found TABLE Alternative name for the lost-and-found table",
15535 " --no-rowids Do not attempt to recover rowid values",
15536 " that are not also INTEGER PRIMARY KEYs",
15537 #endif
15538 #ifndef SQLITE_SHELL_WASM_MODE
15539 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE",
15540 ".save ?OPTIONS? FILE Write database to FILE (an alias for .backup ...)",
15541 #endif
15542 ".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off",
15543 ".schema ?PATTERN? Show the CREATE statements matching PATTERN",
15544 " Options:",
15545 " --indent Try to pretty-print the schema",
15546 " --nosys Omit objects whose names start with \"sqlite_\"",
@@ -15524,24 +15570,26 @@
15570 " --sha3-224 Use the sha3-224 algorithm",
15571 " --sha3-256 Use the sha3-256 algorithm (default)",
15572 " --sha3-384 Use the sha3-384 algorithm",
15573 " --sha3-512 Use the sha3-512 algorithm",
15574 " Any other argument is a LIKE pattern for tables to hash",
15575 #if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE)
15576 ".shell CMD ARGS... Run CMD ARGS... in a system shell",
15577 #endif
15578 ".show Show the current values for various settings",
15579 ".stats ?ARG? Show stats or turn stats on or off",
15580 " off Turn off automatic stat display",
15581 " on Turn on automatic stat display",
15582 " stmt Show statement stats",
15583 " vmstep Show the virtual machine step count only",
15584 #if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE)
15585 ".system CMD ARGS... Run CMD ARGS... in a system shell",
15586 #endif
15587 ".tables ?TABLE? List names of tables matching LIKE pattern TABLE",
15588 #ifndef SQLITE_SHELL_WASM_MODE
15589 ".testcase NAME Begin redirecting output to 'testcase-out.txt'",
15590 #endif
15591 ".testctrl CMD ... Run various sqlite3_test_control() operations",
15592 " Run \".testctrl\" with no arguments for details",
15593 ".timeout MS Try opening locked tables for MS milliseconds",
15594 ".timer on|off Turn SQL timer on or off",
15595 #ifndef SQLITE_OMIT_TRACE
@@ -16082,18 +16130,20 @@
16130 exit(1);
16131 }
16132 #ifndef SQLITE_OMIT_LOAD_EXTENSION
16133 sqlite3_enable_load_extension(p->db, 1);
16134 #endif
 
16135 sqlite3_shathree_init(p->db, 0, 0);
 
16136 sqlite3_uint_init(p->db, 0, 0);
16137 sqlite3_decimal_init(p->db, 0, 0);
16138 sqlite3_regexp_init(p->db, 0, 0);
16139 sqlite3_ieee_init(p->db, 0, 0);
16140 sqlite3_series_init(p->db, 0, 0);
16141 #ifndef SQLITE_SHELL_WASM_MODE
16142 sqlite3_fileio_init(p->db, 0, 0);
16143 sqlite3_completion_init(p->db, 0, 0);
16144 #endif
16145 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
16146 sqlite3_dbdata_init(p->db, 0, 0);
16147 #endif
16148 #ifdef SQLITE_HAVE_ZLIB
16149 if( !p->bSafeModePersist ){
@@ -19212,18 +19262,20 @@
19262 sqlite3_set_authorizer(p->db, 0, 0);
19263 }
19264 }else
19265 #endif
19266
19267 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB) \
19268 && !defined(SQLITE_SHELL_WASM_MODE)
19269 if( c=='a' && strncmp(azArg[0], "archive", n)==0 ){
19270 open_db(p, 0);
19271 failIfSafeMode(p, "cannot run .archive in safe mode");
19272 rc = arDotCommand(p, 0, azArg, nArg);
19273 }else
19274 #endif
19275
19276 #ifndef SQLITE_SHELL_WASM_MODE
19277 if( (c=='b' && n>=3 && strncmp(azArg[0], "backup", n)==0)
19278 || (c=='s' && n>=3 && strncmp(azArg[0], "save", n)==0)
19279 ){
19280 const char *zDestFile = 0;
19281 const char *zDb = 0;
@@ -19288,10 +19340,11 @@
19340 utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
19341 rc = 1;
19342 }
19343 close_db(pDest);
19344 }else
19345 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
19346
19347 if( c=='b' && n>=3 && strncmp(azArg[0], "bail", n)==0 ){
19348 if( nArg==2 ){
19349 bail_on_error = booleanValue(azArg[1]);
19350 }else{
@@ -19318,10 +19371,11 @@
19371 */
19372 if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
19373 test_breakpoint();
19374 }else
19375
19376 #ifndef SQLITE_SHELL_WASM_MODE
19377 if( c=='c' && strcmp(azArg[0],"cd")==0 ){
19378 failIfSafeMode(p, "cannot run .cd in safe mode");
19379 if( nArg==2 ){
19380 #if defined(_WIN32) || defined(WIN32)
19381 wchar_t *z = sqlite3_win32_utf8_to_unicode(azArg[1]);
@@ -19337,10 +19391,11 @@
19391 }else{
19392 raw_printf(stderr, "Usage: .cd DIRECTORY\n");
19393 rc = 1;
19394 }
19395 }else
19396 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
19397
19398 if( c=='c' && n>=3 && strncmp(azArg[0], "changes", n)==0 ){
19399 if( nArg==2 ){
19400 setOrClearFlag(p, SHFLG_CountChanges, azArg[1]);
19401 }else{
@@ -19347,10 +19402,11 @@
19402 raw_printf(stderr, "Usage: .changes on|off\n");
19403 rc = 1;
19404 }
19405 }else
19406
19407 #ifndef SQLITE_SHELL_WASM_MODE
19408 /* Cancel output redirection, if it is currently set (by .testcase)
19409 ** Then read the content of the testcase-out.txt file and compare against
19410 ** azArg[1]. If there are differences, report an error and exit.
19411 */
19412 if( c=='c' && n>=3 && strncmp(azArg[0], "check", n)==0 ){
@@ -19371,20 +19427,23 @@
19427 utf8_printf(stdout, "testcase-%s ok\n", p->zTestcase);
19428 p->nCheck++;
19429 }
19430 sqlite3_free(zRes);
19431 }else
19432 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
19433
19434 #ifndef SQLITE_SHELL_WASM_MODE
19435 if( c=='c' && strncmp(azArg[0], "clone", n)==0 ){
19436 failIfSafeMode(p, "cannot run .clone in safe mode");
19437 if( nArg==2 ){
19438 tryToClone(p, azArg[1]);
19439 }else{
19440 raw_printf(stderr, "Usage: .clone FILENAME\n");
19441 rc = 1;
19442 }
19443 }else
19444 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
19445
19446 if( c=='c' && strncmp(azArg[0], "connection", n)==0 ){
19447 if( nArg==1 ){
19448 /* List available connections */
19449 int i;
@@ -19523,11 +19582,11 @@
19582 char *zLike = 0;
19583 char *zSql;
19584 int i;
19585 int savedShowHeader = p->showHeader;
19586 int savedShellFlags = p->shellFlgs;
19587 ShellClearFlag(p,
19588 SHFLG_PreserveRowid|SHFLG_Newlines|SHFLG_Echo
19589 |SHFLG_DumpDataOnly|SHFLG_DumpNoSys);
19590 for(i=1; i<nArg; i++){
19591 if( azArg[i][0]=='-' ){
19592 const char *z = azArg[i]+1;
@@ -19669,14 +19728,16 @@
19728 raw_printf(stderr, "Usage: .eqp off|on|trace|trigger|full\n");
19729 rc = 1;
19730 }
19731 }else
19732
19733 #ifndef SQLITE_SHELL_WASM_MODE
19734 if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
19735 if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
19736 rc = 2;
19737 }else
19738 #endif
19739
19740 /* The ".explain" command is automatic now. It is largely pointless. It
19741 ** retained purely for backwards compatibility */
19742 if( c=='e' && strncmp(azArg[0], "explain", n)==0 ){
19743 int val = 1;
@@ -19927,10 +19988,11 @@
19988 }else{
19989 showHelp(p->out, 0);
19990 }
19991 }else
19992
19993 #ifndef SQLITE_SHELL_WASM_MODE
19994 if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
19995 char *zTable = 0; /* Insert data into this table */
19996 char *zSchema = 0; /* within this schema (may default to "main") */
19997 char *zFile = 0; /* Name of file to extra content from */
19998 sqlite3_stmt *pStmt = NULL; /* A statement */
@@ -19948,20 +20010,16 @@
20010 int useOutputMode = 1; /* Use output mode to determine separators */
20011 char *zCreate = 0; /* CREATE TABLE statement text */
20012
20013 failIfSafeMode(p, "cannot run .import in safe mode");
20014 memset(&sCtx, 0, sizeof(sCtx));
 
 
 
 
 
20015 if( p->mode==MODE_Ascii ){
20016 xRead = ascii_read_one_field;
20017 }else{
20018 xRead = csv_read_one_field;
20019 }
20020 rc = 1;
20021 for(i=1; i<nArg; i++){
20022 char *z = azArg[i];
20023 if( z[0]=='-' && z[1]=='-' ) z++;
20024 if( z[0]!='-' ){
20025 if( zFile==0 ){
@@ -19969,11 +20027,10 @@
20027 }else if( zTable==0 ){
20028 zTable = z;
20029 }else{
20030 utf8_printf(p->out, "ERROR: extra argument: \"%s\". Usage:\n", z);
20031 showHelp(p->out, "import");
 
20032 goto meta_command_exit;
20033 }
20034 }else if( strcmp(z,"-v")==0 ){
20035 eVerbose++;
20036 }else if( strcmp(z,"-schema")==0 && i<nArg-1 ){
@@ -19991,19 +20048,17 @@
20048 xRead = csv_read_one_field;
20049 useOutputMode = 0;
20050 }else{
20051 utf8_printf(p->out, "ERROR: unknown option: \"%s\". Usage:\n", z);
20052 showHelp(p->out, "import");
 
20053 goto meta_command_exit;
20054 }
20055 }
20056 if( zTable==0 ){
20057 utf8_printf(p->out, "ERROR: missing %s argument. Usage:\n",
20058 zFile==0 ? "FILE" : "TABLE");
20059 showHelp(p->out, "import");
 
20060 goto meta_command_exit;
20061 }
20062 seenInterrupt = 0;
20063 open_db(p, 0);
20064 if( useOutputMode ){
@@ -20011,25 +20066,22 @@
20066 ** the column and row separator characters from the output mode. */
20067 nSep = strlen30(p->colSeparator);
20068 if( nSep==0 ){
20069 raw_printf(stderr,
20070 "Error: non-null column separator required for import\n");
 
20071 goto meta_command_exit;
20072 }
20073 if( nSep>1 ){
20074 raw_printf(stderr,
20075 "Error: multi-character column separators not allowed"
20076 " for import\n");
 
20077 goto meta_command_exit;
20078 }
20079 nSep = strlen30(p->rowSeparator);
20080 if( nSep==0 ){
20081 raw_printf(stderr,
20082 "Error: non-null row separator required for import\n");
 
20083 goto meta_command_exit;
20084 }
20085 if( nSep==2 && p->mode==MODE_Csv && strcmp(p->rowSeparator,SEP_CrLf)==0 ){
20086 /* When importing CSV (only), if the row separator is set to the
20087 ** default output row separator, change it to the default input
@@ -20039,11 +20091,10 @@
20091 nSep = strlen30(p->rowSeparator);
20092 }
20093 if( nSep>1 ){
20094 raw_printf(stderr, "Error: multi-character row separators not allowed"
20095 " for import\n");
 
20096 goto meta_command_exit;
20097 }
20098 sCtx.cColSep = p->colSeparator[0];
20099 sCtx.cRowSep = p->rowSeparator[0];
20100 }
@@ -20050,11 +20101,10 @@
20101 sCtx.zFile = zFile;
20102 sCtx.nLine = 1;
20103 if( sCtx.zFile[0]=='|' ){
20104 #ifdef SQLITE_OMIT_POPEN
20105 raw_printf(stderr, "Error: pipes are not supported in this OS\n");
 
20106 goto meta_command_exit;
20107 #else
20108 sCtx.in = popen(sCtx.zFile+1, "r");
20109 sCtx.zFile = "<pipe>";
20110 sCtx.xCloser = pclose;
@@ -20063,12 +20113,10 @@
20113 sCtx.in = fopen(sCtx.zFile, "rb");
20114 sCtx.xCloser = fclose;
20115 }
20116 if( sCtx.in==0 ){
20117 utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
 
 
20118 goto meta_command_exit;
20119 }
20120 if( eVerbose>=2 || (eVerbose>=1 && useOutputMode) ){
20121 char zSep[2];
20122 zSep[1] = 0;
@@ -20077,10 +20125,15 @@
20125 output_c_string(p->out, zSep);
20126 utf8_printf(p->out, ", row separator ");
20127 zSep[0] = sCtx.cRowSep;
20128 output_c_string(p->out, zSep);
20129 utf8_printf(p->out, "\n");
20130 }
20131 sCtx.z = sqlite3_malloc64(120);
20132 if( sCtx.z==0 ){
20133 import_cleanup(&sCtx);
20134 shell_out_of_memory();
20135 }
20136 /* Below, resources must be freed before exit. */
20137 while( (nSkip--)>0 ){
20138 while( xRead(&sCtx) && sCtx.cTerm==sCtx.cColSep ){}
20139 }
@@ -20226,10 +20279,11 @@
20279 utf8_printf(p->out,
20280 "Added %d rows with %d errors using %d lines of input\n",
20281 sCtx.nRow, sCtx.nErr, sCtx.nLine-1);
20282 }
20283 }else
20284 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
20285
20286 #ifndef SQLITE_UNTESTABLE
20287 if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
20288 char *zSql;
20289 char *zCollist = 0;
@@ -20415,11 +20469,11 @@
20469 if( c=='l' && n>2 && strncmp(azArg[0], "lint", n)==0 ){
20470 open_db(p, 0);
20471 lintDotCommand(p, azArg, nArg);
20472 }else
20473
20474 #if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_WASM_MODE)
20475 if( c=='l' && strncmp(azArg[0], "load", n)==0 ){
20476 const char *zFile, *zProc;
20477 char *zErrMsg = 0;
20478 failIfSafeMode(p, "cannot run .load in safe mode");
20479 if( nArg<2 ){
@@ -20437,10 +20491,11 @@
20491 rc = 1;
20492 }
20493 }else
20494 #endif
20495
20496 #ifndef SQLITE_SHELL_WASM_MODE
20497 if( c=='l' && strncmp(azArg[0], "log", n)==0 ){
20498 failIfSafeMode(p, "cannot run .log in safe mode");
20499 if( nArg!=2 ){
20500 raw_printf(stderr, "Usage: .log FILENAME\n");
20501 rc = 1;
@@ -20448,10 +20503,11 @@
20503 const char *zFile = azArg[1];
20504 output_file_close(p->pLog);
20505 p->pLog = output_file_open(zFile, 0);
20506 }
20507 }else
20508 #endif
20509
20510 if( c=='m' && strncmp(azArg[0], "mode", n)==0 ){
20511 const char *zMode = 0;
20512 const char *zTabname = 0;
20513 int i, n2;
@@ -20572,10 +20628,11 @@
20628 rc = 1;
20629 }
20630 p->cMode = p->mode;
20631 }else
20632
20633 #ifndef SQLITE_SHELL_WASM_MODE
20634 if( c=='n' && strcmp(azArg[0], "nonce")==0 ){
20635 if( nArg!=2 ){
20636 raw_printf(stderr, "Usage: .nonce NONCE\n");
20637 rc = 1;
20638 }else if( p->zNonce==0 || strcmp(azArg[1],p->zNonce)!=0 ){
@@ -20586,10 +20643,11 @@
20643 p->bSafeMode = 0;
20644 return 0; /* Return immediately to bypass the safe mode reset
20645 ** at the end of this procedure */
20646 }
20647 }else
20648 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
20649
20650 if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 ){
20651 if( nArg==2 ){
20652 sqlite3_snprintf(sizeof(p->nullValue), p->nullValue,
20653 "%.*s", (int)ArraySize(p->nullValue)-1, azArg[1]);
@@ -20607,10 +20665,11 @@
20665 int openMode = SHELL_OPEN_UNSPEC;
20666
20667 /* Check for command-line arguments */
20668 for(iName=1; iName<nArg; iName++){
20669 const char *z = azArg[iName];
20670 #ifndef SQLITE_SHELL_WASM_MODE
20671 if( optionMatch(z,"new") ){
20672 newFlag = 1;
20673 #ifdef SQLITE_HAVE_ZLIB
20674 }else if( optionMatch(z, "zip") ){
20675 openMode = SHELL_OPEN_ZIPFILE;
@@ -20627,11 +20686,13 @@
20686 }else if( optionMatch(z, "hexdb") ){
20687 openMode = SHELL_OPEN_HEXDB;
20688 }else if( optionMatch(z, "maxsize") && iName+1<nArg ){
20689 p->szMax = integerValue(azArg[++iName]);
20690 #endif /* SQLITE_OMIT_DESERIALIZE */
20691 }else
20692 #endif /* !SQLITE_SHELL_WASM_MODE */
20693 if( z[0]=='-' ){
20694 utf8_printf(stderr, "unknown option: %s\n", z);
20695 rc = 1;
20696 goto meta_command_exit;
20697 }else if( zFN ){
20698 utf8_printf(stderr, "extra argument: \"%s\"\n", z);
@@ -20654,17 +20715,21 @@
20715 p->szMax = 0;
20716
20717 /* If a filename is specified, try to open it first */
20718 if( zFN || p->openMode==SHELL_OPEN_HEXDB ){
20719 if( newFlag && zFN && !p->bSafeMode ) shellDeleteFile(zFN);
20720 #ifndef SQLITE_SHELL_WASM_MODE
20721 if( p->bSafeMode
20722 && p->openMode!=SHELL_OPEN_HEXDB
20723 && zFN
20724 && strcmp(zFN,":memory:")!=0
20725 ){
20726 failIfSafeMode(p, "cannot open disk-based database files in safe mode");
20727 }
20728 #else
20729 /* WASM mode has its own sandboxed pseudo-filesystem. */
20730 #endif
20731 if( zFN ){
20732 zNewFilename = sqlite3_mprintf("%s", zFN);
20733 shell_check_oom(zNewFilename);
20734 }else{
20735 zNewFilename = 0;
@@ -20683,10 +20748,11 @@
20748 p->pAuxDb->zDbFilename = 0;
20749 open_db(p, 0);
20750 }
20751 }else
20752
20753 #ifndef SQLITE_SHELL_WASM_MODE
20754 if( (c=='o'
20755 && (strncmp(azArg[0], "output", n)==0||strncmp(azArg[0], "once", n)==0))
20756 || (c=='e' && n==5 && strcmp(azArg[0],"excel")==0)
20757 ){
20758 char *zFile = 0;
@@ -20798,10 +20864,11 @@
20864 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
20865 }
20866 }
20867 sqlite3_free(zFile);
20868 }else
20869 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
20870
20871 if( c=='p' && n>=3 && strncmp(azArg[0], "parameter", n)==0 ){
20872 open_db(p,0);
20873 if( nArg<=1 ) goto parameter_syntax_error;
20874
@@ -20967,14 +21034,17 @@
21034 if( nArg >= 3) {
21035 strncpy(continuePrompt,azArg[2],(int)ArraySize(continuePrompt)-1);
21036 }
21037 }else
21038
21039 #ifndef SQLITE_SHELL_WASM_MODE
21040 if( c=='q' && strncmp(azArg[0], "quit", n)==0 ){
21041 rc = 2;
21042 }else
21043 #endif
21044
21045 #ifndef SQLITE_SHELL_WASM_MODE
21046 if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 ){
21047 FILE *inSaved = p->in;
21048 int savedLineno = p->lineno;
21049 failIfSafeMode(p, "cannot run .read in safe mode");
21050 if( nArg!=2 ){
@@ -21005,11 +21075,13 @@
21075 fclose(p->in);
21076 }
21077 p->in = inSaved;
21078 p->lineno = savedLineno;
21079 }else
21080 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
21081
21082 #ifndef SQLITE_SHELL_WASM_MODE
21083 if( c=='r' && n>=3 && strncmp(azArg[0], "restore", n)==0 ){
21084 const char *zSrcFile;
21085 const char *zDb;
21086 sqlite3 *pSrc;
21087 sqlite3_backup *pBackup;
@@ -21057,10 +21129,11 @@
21129 utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
21130 rc = 1;
21131 }
21132 close_db(pSrc);
21133 }else
21134 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
21135
21136 if( c=='s' && strncmp(azArg[0], "scanstats", n)==0 ){
21137 if( nArg==2 ){
21138 p->scanstatsOn = (u8)booleanValue(azArg[1]);
21139 #ifndef SQLITE_ENABLE_STMT_SCANSTATUS
@@ -21682,11 +21755,11 @@
21755 shell_exec(p, zSql, 0);
21756 }
21757 sqlite3_free(zSql);
21758 }else
21759
21760 #if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE)
21761 if( c=='s'
21762 && (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
21763 ){
21764 char *zCmd;
21765 int i, x;
@@ -21703,11 +21776,11 @@
21776 }
21777 x = zCmd!=0 ? system(zCmd) : 1;
21778 sqlite3_free(zCmd);
21779 if( x ) raw_printf(stderr, "System command returns %d\n", x);
21780 }else
21781 #endif /* !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE) */
21782
21783 if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
21784 static const char *azBool[] = { "off", "on", "trigger", "full"};
21785 const char *zOut;
21786 int i;
@@ -21715,11 +21788,11 @@
21788 raw_printf(stderr, "Usage: .show\n");
21789 rc = 1;
21790 goto meta_command_exit;
21791 }
21792 utf8_printf(p->out, "%12.12s: %s\n","echo",
21793 azBool[ShellHasFlag(p, SHFLG_Echo)]);
21794 utf8_printf(p->out, "%12.12s: %s\n","eqp", azBool[p->autoEQP&3]);
21795 utf8_printf(p->out, "%12.12s: %s\n","explain",
21796 p->mode==MODE_Explain ? "on" : p->autoExplain ? "auto" : "off");
21797 utf8_printf(p->out,"%12.12s: %s\n","headers", azBool[p->showHeader!=0]);
21798 if( p->mode==MODE_Column
@@ -21883,10 +21956,11 @@
21956
21957 for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
21958 sqlite3_free(azResult);
21959 }else
21960
21961 #ifndef SQLITE_SHELL_WASM_MODE
21962 /* Begin redirecting output to the file "testcase-out.txt" */
21963 if( c=='t' && strcmp(azArg[0],"testcase")==0 ){
21964 output_reset(p);
21965 p->out = output_file_open("testcase-out.txt", 0);
21966 if( p->out==0 ){
@@ -21896,10 +21970,11 @@
21970 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
21971 }else{
21972 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?");
21973 }
21974 }else
21975 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
21976
21977 #ifndef SQLITE_UNTESTABLE
21978 if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 ){
21979 static const struct {
21980 const char *zCtrlName; /* Name of a test-control option */
@@ -22465,11 +22540,11 @@
22540 /* fall thru */
22541 case ']':
22542 cWait = 0;
22543 qss = QSS_SETV(qss, 0);
22544 goto PlainScan;
22545 default: assert(0);
22546 }
22547 }
22548 }
22549 }
22550 return qss;
@@ -22486,11 +22561,11 @@
22561 zLine += 1; /* Oracle */
22562 else if ( ToLower(zLine[0])=='g' && ToLower(zLine[1])=='o' )
22563 zLine += 2; /* SQL Server */
22564 else
22565 return 0;
22566 return quickscan(zLine, QSS_Start)==QSS_Start;
22567 }
22568
22569 /*
22570 ** We need a default sqlite3_complete() implementation to use in case
22571 ** the shell is compiled with SQLITE_OMIT_COMPLETE. The default assumes
@@ -22563,10 +22638,46 @@
22638 raw_printf(p->out, "%s\n", zLineBuf);
22639 }
22640 return 0;
22641 }
22642
22643 static void echo_group_input(ShellState *p, const char *zDo){
22644 if( ShellHasFlag(p, SHFLG_Echo) ) utf8_printf(p->out, "%s\n", zDo);
22645 }
22646
22647 #ifdef SQLITE_SHELL_WASM_MODE
22648 /*
22649 ** Alternate one_input_line() impl for wasm mode. This is not in the primary impl
22650 ** because we need the global shellState and cannot access it from that function
22651 ** without moving lots of code around (creating a larger/messier diff).
22652 */
22653 static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
22654 /* Parse the next line from shellState.wasm.zInput. */
22655 const char *zBegin = shellState.wasm.zPos;
22656 const char *z = zBegin;
22657 char *zLine = 0;
22658 int nZ = 0;
22659
22660 UNUSED_PARAMETER(in);
22661 UNUSED_PARAMETER(isContinuation);
22662 if(!z || !*z){
22663 return 0;
22664 }
22665 while(*z && isspace(*z)) ++z;
22666 zBegin = z;
22667 for(; *z && '\n'!=*z; ++nZ, ++z){}
22668 if(nZ>0 && '\r'==zBegin[nZ-1]){
22669 --nZ;
22670 }
22671 shellState.wasm.zPos = z;
22672 zLine = realloc(zPrior, nZ+1);
22673 shell_check_oom(zLine);
22674 memcpy(zLine, zBegin, (size_t)nZ);
22675 zLine[nZ] = 0;
22676 return zLine;
22677 }
22678 #endif /* SQLITE_SHELL_WASM_MODE */
22679
22680 /*
22681 ** Read input from *in and process it. If *in==0 then input
22682 ** is interactive - the user is typing it it. Otherwise, input
22683 ** is coming from a file or device. A prompt is issued and history
@@ -22612,18 +22723,17 @@
22723 && line_is_complete(zSql, nSql) ){
22724 memcpy(zLine,";",2);
22725 }
22726 qss = quickscan(zLine, qss);
22727 if( QSS_PLAINWHITE(qss) && nSql==0 ){
 
 
22728 /* Just swallow single-line whitespace */
22729 echo_group_input(p, zLine);
22730 qss = QSS_Start;
22731 continue;
22732 }
22733 if( zLine && (zLine[0]=='.' || zLine[0]=='#') && nSql==0 ){
22734 echo_group_input(p, zLine);
22735 if( zLine[0]=='.' ){
22736 rc = do_meta_command(zLine, p);
22737 if( rc==2 ){ /* exit requested */
22738 break;
22739 }else if( rc ){
@@ -22652,10 +22762,11 @@
22762 zSql[nSql++] = '\n';
22763 memcpy(zSql+nSql, zLine, nLine+1);
22764 nSql += nLine;
22765 }
22766 if( nSql && QSS_SEMITERM(qss) && sqlite3_complete(zSql) ){
22767 echo_group_input(p, zSql);
22768 errCnt += runOneSqlLine(p, zSql, p->in, startline);
22769 nSql = 0;
22770 if( p->outCount ){
22771 output_reset(p);
22772 p->outCount = 0;
@@ -22663,17 +22774,18 @@
22774 clearTempFile(p);
22775 }
22776 p->bSafeMode = p->bSafeModePersist;
22777 qss = QSS_Start;
22778 }else if( nSql && QSS_PLAINWHITE(qss) ){
22779 echo_group_input(p, zSql);
22780 nSql = 0;
22781 qss = QSS_Start;
22782 }
22783 }
22784 if( nSql ){
22785 /* This may be incomplete. Let the SQL parser deal with that. */
22786 echo_group_input(p, zSql);
22787 errCnt += runOneSqlLine(p, zSql, p->in, startline);
22788 }
22789 free(zSql);
22790 free(zLine);
22791 --p->inputNesting;
@@ -22808,11 +22920,11 @@
22920 " -cmd COMMAND run \"COMMAND\" before reading stdin\n"
22921 " -csv set output mode to 'csv'\n"
22922 #if !defined(SQLITE_OMIT_DESERIALIZE)
22923 " -deserialize open the database using sqlite3_deserialize()\n"
22924 #endif
22925 " -echo print inputs before execution\n"
22926 " -init FILENAME read/process named file\n"
22927 " -[no]header turn headers on or off\n"
22928 #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
22929 " -heap SIZE Size of heap for memsys3 or memsys5\n"
22930 #endif
@@ -22943,19 +23055,30 @@
23055 # define SQLITE_SHELL_IS_UTF8 (0)
23056 # else
23057 # define SQLITE_SHELL_IS_UTF8 (1)
23058 # endif
23059 #endif
23060
23061 #ifdef SQLITE_SHELL_WASM_MODE
23062 # define main fiddle_main
23063 #endif
23064
23065 #if SQLITE_SHELL_IS_UTF8
23066 int SQLITE_CDECL main(int argc, char **argv){
23067 #else
23068 int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
23069 char **argv;
23070 #endif
23071 #ifdef SQLITE_DEBUG
23072 sqlite3_uint64 mem_main_enter = sqlite3_memory_used();
23073 #endif
23074 char *zErrMsg = 0;
23075 #ifdef SQLITE_SHELL_WASM_MODE
23076 # define data shellState
23077 #else
23078 ShellState data;
23079 #endif
23080 const char *zInitFile = 0;
23081 int i;
23082 int rc = 0;
23083 int warnInmemoryDb = 0;
23084 int readStdin = 1;
@@ -22967,12 +23090,17 @@
23090 int argcToFree = 0;
23091 #endif
23092
23093 setBinaryMode(stdin, 0);
23094 setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
23095 #ifdef SQLITE_SHELL_WASM_MODE
23096 stdin_is_interactive = 0;
23097 stdout_is_console = 1;
23098 #else
23099 stdin_is_interactive = isatty(0);
23100 stdout_is_console = isatty(1);
23101 #endif
23102
23103 #if !defined(_WIN32_WCE)
23104 if( getenv("SQLITE_DEBUG_BREAK") ){
23105 if( isatty(0) && isatty(2) ){
23106 fprintf(stderr,
@@ -23224,11 +23352,13 @@
23352 utf8_printf(stderr,"%s: Error: no database filename specified\n", Argv0);
23353 return 1;
23354 #endif
23355 }
23356 data.out = stdout;
23357 #ifndef SQLITE_SHELL_WASM_MODE
23358 sqlite3_appendvfs_init(0,0,0);
23359 #endif
23360
23361 /* Go ahead and open the database file if it already exists. If the
23362 ** file does not exist, delay opening it. This prevents empty database
23363 ** files from being created if a user mistypes the database name argument
23364 ** to the sqlite command-line tool.
@@ -23490,10 +23620,13 @@
23620 }else{
23621 data.in = stdin;
23622 rc = process_input(&data);
23623 }
23624 }
23625 #ifndef SQLITE_SHELL_WASM_MODE
23626 /* In WASM mode we have to leave the db state in place so that
23627 ** client code can "push" SQL into it after this call returns. */
23628 free(azCmd);
23629 set_table_name(&data, 0);
23630 if( data.db ){
23631 session_close_all(&data, -1);
23632 close_db(data.db);
@@ -23516,7 +23649,138 @@
23649 free(data.colWidth);
23650 free(data.zNonce);
23651 /* Clear the global data structure so that valgrind will detect memory
23652 ** leaks */
23653 memset(&data, 0, sizeof(data));
23654 #ifdef SQLITE_DEBUG
23655 if( sqlite3_memory_used()>mem_main_enter ){
23656 utf8_printf(stderr, "Memory leaked: %u bytes\n",
23657 (unsigned int)(sqlite3_memory_used()-mem_main_enter));
23658 }
23659 #endif
23660 #endif /* !SQLITE_SHELL_WASM_MODE */
23661 return rc;
23662 }
23663
23664
23665 #ifdef SQLITE_SHELL_WASM_MODE
23666 /* Only for emcc experimentation purposes. */
23667 int fiddle_experiment(int a,int b){
23668 return a + b;
23669 }
23670
23671 /* Only for emcc experimentation purposes.
23672
23673 Define this function in JS using:
23674
23675 emcc ... --js-library somefile.js
23676
23677 containing:
23678
23679 mergeInto(LibraryManager.library, {
23680 my_foo: function(){
23681 console.debug("my_foo()",arguments);
23682 }
23683 });
23684 */
23685 /*extern void my_foo(sqlite3 *);*/
23686 /* Only for emcc experimentation purposes. */
23687 sqlite3 * fiddle_the_db(){
23688 printf("fiddle_the_db(%p)\n", (const void*)globalDb);
23689 /*my_foo(globalDb);*/
23690 return globalDb;
23691 }
23692 /* Only for emcc experimentation purposes. */
23693 sqlite3 * fiddle_db_arg(sqlite3 *arg){
23694 printf("fiddle_db_arg(%p)\n", (const void*)arg);
23695 return arg;
23696 }
23697
23698 /*
23699 ** Intended to be called via a SharedWorker() while a separate
23700 ** SharedWorker() (which manages the wasm module) is performing work
23701 ** which should be interrupted. Unfortunately, SharedWorker is not
23702 ** portable enough to make real use of.
23703 */
23704 void fiddle_interrupt(void){
23705 if(globalDb) sqlite3_interrupt(globalDb);
23706 }
23707
23708 /*
23709 ** Returns the filename of the given db name, assuming "main" if
23710 ** zDbName is NULL. Returns NULL if globalDb is not opened.
23711 */
23712 const char * fiddle_db_filename(const char * zDbName){
23713 return globalDb
23714 ? sqlite3_db_filename(globalDb, zDbName ? zDbName : "main")
23715 : NULL;
23716 }
23717
23718 /*
23719 ** Closes, unlinks, and reopens the db using its current filename (or
23720 ** the default if the db is currently closed). It is assumed, for
23721 ** purposes of the fiddle build, that the file is in a transient
23722 ** virtual filesystem within the browser.
23723 */
23724 void fiddle_reset_db(void){
23725 char *zFilename = 0;
23726 if(0==globalDb){
23727 shellState.pAuxDb->zDbFilename = "/fiddle.sqlite3";
23728 }else{
23729 zFilename =
23730 sqlite3_mprintf("%s", sqlite3_db_filename(globalDb, "main"));
23731 shell_check_oom(zFilename);
23732 close_db(globalDb);
23733 shellDeleteFile(zFilename);
23734 shellState.db = 0;
23735 shellState.pAuxDb->zDbFilename = zFilename;
23736 }
23737 open_db(&shellState, 0);
23738 sqlite3_free(zFilename);
23739 }
23740
23741 /*
23742 ** Trivial exportable function for emscripten. Needs to be exported using:
23743 **
23744 ** emcc ..flags... -sEXPORTED_FUNCTIONS=_fiddle_exec -sEXPORTED_RUNTIME_METHODS=ccall,cwrap
23745 **
23746 ** (Note the underscore before the function name.) It processes zSql
23747 ** as if it were input to the sqlite3 shell and redirects all output
23748 ** to the wasm binding.
23749 */
23750 void fiddle_exec(const char * zSql){
23751 static int once = 0;
23752 int rc = 0;
23753 if(!once){
23754 /* Simulate an argv array for main() */
23755 static char * argv[] = {"fiddle",
23756 "-bail",
23757 "-safe"};
23758 rc = fiddle_main((int)(sizeof(argv)/sizeof(argv[0])), argv);
23759 once = rc ? -1 : 1;
23760 memset(&shellState.wasm, 0, sizeof(shellState.wasm));
23761 printf(
23762 "SQLite version %s %.19s\n" /*extra-version-info*/,
23763 sqlite3_libversion(), sqlite3_sourceid()
23764 );
23765 puts("WASM shell");
23766 puts("Enter \".help\" for usage hints.");
23767 if(once>0){
23768 fiddle_reset_db();
23769 }
23770 if(shellState.db){
23771 printf("Connected to %s.\n", fiddle_db_filename(NULL));
23772 }else{
23773 fprintf(stderr,"ERROR initializing db!\n");
23774 return;
23775 }
23776 }
23777 if(once<0){
23778 puts("DB init failed. Not executing SQL.");
23779 }else if(zSql && *zSql){
23780 shellState.wasm.zInput = zSql;
23781 shellState.wasm.zPos = zSql;
23782 process_input(&shellState);
23783 memset(&shellState.wasm, 0, sizeof(shellState.wasm));
23784 }
23785 }
23786 #endif /* SQLITE_SHELL_WASM_MODE */
23787
+2122 -1656
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452452
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453
** [sqlite_version()] and [sqlite_source_id()].
454454
*/
455455
#define SQLITE_VERSION "3.39.0"
456456
#define SQLITE_VERSION_NUMBER 3039000
457
-#define SQLITE_SOURCE_ID "2022-04-21 19:38:17 f766dff012af0ea3c28a8ce4db850cd0205729a8283bce1e442992aded7c734b"
457
+#define SQLITE_SOURCE_ID "2022-06-03 14:08:40 d18818afc6021a32989499c26ab38fa442e5a55e662e39bb06e5c0daa9c65e25"
458458
459459
/*
460460
** CAPI3REF: Run-Time Library Version Numbers
461461
** KEYWORDS: sqlite3_version sqlite3_sourceid
462462
**
@@ -6580,10 +6580,32 @@
65806580
** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
65816581
** create the statement in the first place.
65826582
*/
65836583
SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
65846584
6585
+/*
6586
+** CAPI3REF: Return The Schema Name For A Database Connection
6587
+** METHOD: sqlite3
6588
+**
6589
+** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name
6590
+** for the N-th database on database connection D, or a NULL pointer of N is
6591
+** out of range. An N alue of 0 means the main database file. An N of 1 is
6592
+** the "temp" schema. Larger values of N correspond to various ATTACH-ed
6593
+** databases.
6594
+**
6595
+** Space to hold the string that is returned by sqlite3_db_name() is managed
6596
+** by SQLite itself. The string might be deallocated by any operation that
6597
+** changes the schema, including [ATTACH] or [DETACH] or calls to
6598
+** [sqlite3_serialize()] or [sqlite3_deserialize()], even operations that
6599
+** occur on a different thread. Applications that need to
6600
+** remember the string long-term should make their own copy. Applications that
6601
+** are accessing the same database connection simultaneously on multiple
6602
+** threads should mutex-protect calls to this API and should make their own
6603
+** private copy of the result prior to releasing the mutex.
6604
+*/
6605
+SQLITE_API const char *sqlite3_db_name(sqlite3 *db, int N);
6606
+
65856607
/*
65866608
** CAPI3REF: Return The Filename For A Database Connection
65876609
** METHOD: sqlite3
65886610
**
65896611
** ^The sqlite3_db_filename(D,N) interface returns a pointer to the filename
@@ -15790,12 +15812,14 @@
1579015812
# define sqlite3VdbeVerifyNoMallocRequired(A,B)
1579115813
# define sqlite3VdbeVerifyNoResultRow(A)
1579215814
#endif
1579315815
#if defined(SQLITE_DEBUG)
1579415816
SQLITE_PRIVATE void sqlite3VdbeVerifyAbortable(Vdbe *p, int);
15817
+SQLITE_PRIVATE void sqlite3VdbeNoJumpsOutsideSubrtn(Vdbe*,int,int,int);
1579515818
#else
1579615819
# define sqlite3VdbeVerifyAbortable(A,B)
15820
+# define sqlite3VdbeNoJumpsOutsideSubrtn(A,B,C,D)
1579715821
#endif
1579815822
SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp,int iLineno);
1579915823
#ifndef SQLITE_OMIT_EXPLAIN
1580015824
SQLITE_PRIVATE void sqlite3VdbeExplain(Parse*,u8,const char*,...);
1580115825
SQLITE_PRIVATE void sqlite3VdbeExplainPop(Parse*);
@@ -16283,10 +16307,17 @@
1628316307
/* Maximum pathname length. Note: FILENAME_MAX defined by stdio.h
1628416308
*/
1628516309
#ifndef SQLITE_MAX_PATHLEN
1628616310
# define SQLITE_MAX_PATHLEN FILENAME_MAX
1628716311
#endif
16312
+
16313
+/* Maximum number of symlinks that will be resolved while trying to
16314
+** expand a filename in xFullPathname() in the VFS.
16315
+*/
16316
+#ifndef SQLITE_MAX_SYMLINK
16317
+# define SQLITE_MAX_SYMLINK 200
16318
+#endif
1628816319
1628916320
/*
1629016321
** The default size of a disk sector
1629116322
*/
1629216323
#ifndef SQLITE_DEFAULT_SECTOR_SIZE
@@ -17051,10 +17082,12 @@
1705117082
/* TH3 expects this value ^^^^^^^^^^ to be 0x40000. Coordinate any change */
1705217083
#define SQLITE_BloomFilter 0x00080000 /* Use a Bloom filter on searches */
1705317084
#define SQLITE_BloomPulldown 0x00100000 /* Run Bloom filters early */
1705417085
#define SQLITE_BalancedMerge 0x00200000 /* Balance multi-way merges */
1705517086
#define SQLITE_ReleaseReg 0x00400000 /* Use OP_ReleaseReg for testing */
17087
+#define SQLITE_FlttnUnionAll 0x00800000 /* Disable the UNION ALL flattener */
17088
+ /* TH3 expects this value ^^^^^^^^^^ See flatten04.test */
1705617089
#define SQLITE_AllOpts 0xffffffff /* All optimizations */
1705717090
1705817091
/*
1705917092
** Macros for testing whether or not optimizations are enabled or disabled.
1706017093
*/
@@ -17153,11 +17186,11 @@
1715317186
#define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */
1715417187
#define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */
1715517188
#define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a
1715617189
** single query - might change over time */
1715717190
#define SQLITE_FUNC_TEST 0x4000 /* Built-in testing functions */
17158
-#define SQLITE_FUNC_OFFSET 0x8000 /* Built-in sqlite_offset() function */
17191
+/* 0x8000 -- available for reuse */
1715917192
#define SQLITE_FUNC_WINDOW 0x00010000 /* Built-in window-only function */
1716017193
#define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */
1716117194
#define SQLITE_FUNC_DIRECT 0x00080000 /* Not for use in TRIGGERs or VIEWs */
1716217195
#define SQLITE_FUNC_SUBTYPE 0x00100000 /* Result likely to have sub-type */
1716317196
#define SQLITE_FUNC_UNSAFE 0x00200000 /* Function has side effects */
@@ -17170,10 +17203,11 @@
1717017203
#define INLINEFUNC_implies_nonnull_row 1
1717117204
#define INLINEFUNC_expr_implies_expr 2
1717217205
#define INLINEFUNC_expr_compare 3
1717317206
#define INLINEFUNC_affinity 4
1717417207
#define INLINEFUNC_iif 5
17208
+#define INLINEFUNC_sqlite_offset 6
1717517209
#define INLINEFUNC_unlikely 99 /* Default case */
1717617210
1717717211
/*
1717817212
** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
1717917213
** used to create the initializers for the FuncDef structures.
@@ -17396,10 +17430,11 @@
1739617430
#define COLFLAG_VIRTUAL 0x0020 /* GENERATED ALWAYS AS ... VIRTUAL */
1739717431
#define COLFLAG_STORED 0x0040 /* GENERATED ALWAYS AS ... STORED */
1739817432
#define COLFLAG_NOTAVAIL 0x0080 /* STORED column not yet calculated */
1739917433
#define COLFLAG_BUSY 0x0100 /* Blocks recursion on GENERATED columns */
1740017434
#define COLFLAG_HASCOLL 0x0200 /* Has collating sequence name in zCnName */
17435
+#define COLFLAG_NOEXPAND 0x0400 /* Omit this column when expanding "*" */
1740117436
#define COLFLAG_GENERATED 0x0060 /* Combo: _STORED, _VIRTUAL */
1740217437
#define COLFLAG_NOINSERT 0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */
1740317438
1740417439
/*
1740517440
** A "Collating Sequence" is defined by an instance of the following
@@ -18115,11 +18150,11 @@
1811518150
ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
1811618151
** TK_VARIABLE: variable number (always >= 1).
1811718152
** TK_SELECT_COLUMN: column of the result vector */
1811818153
i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
1811918154
union {
18120
- int iJoin; /* If EP_FromJoin, the right table of the join */
18155
+ int iJoin; /* If EP_OuterON or EP_InnerON, the right table */
1812118156
int iOfst; /* else: start of token from start of statement */
1812218157
} w;
1812318158
AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
1812418159
union {
1812518160
Table *pTab; /* TK_COLUMN: Table containing column. Can be NULL
@@ -18136,33 +18171,33 @@
1813618171
** Value restrictions:
1813718172
**
1813818173
** EP_Agg == NC_HasAgg == SF_HasAgg
1813918174
** EP_Win == NC_HasWin
1814018175
*/
18141
-#define EP_FromJoin 0x000001 /* Originates in ON/USING clause of outer join */
18142
-#define EP_Distinct 0x000002 /* Aggregate function with DISTINCT keyword */
18143
-#define EP_HasFunc 0x000004 /* Contains one or more functions of any kind */
18144
-#define EP_FixedCol 0x000008 /* TK_Column with a known fixed value */
18176
+#define EP_OuterON 0x000001 /* Originates in ON/USING clause of outer join */
18177
+#define EP_InnerON 0x000002 /* Originates in ON/USING of an inner join */
18178
+#define EP_Distinct 0x000004 /* Aggregate function with DISTINCT keyword */
18179
+#define EP_HasFunc 0x000008 /* Contains one or more functions of any kind */
1814518180
#define EP_Agg 0x000010 /* Contains one or more aggregate functions */
18146
-#define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */
18147
-#define EP_DblQuoted 0x000040 /* token.z was originally in "..." */
18148
-#define EP_InfixFunc 0x000080 /* True for an infix function: LIKE, GLOB, etc */
18149
-#define EP_Collate 0x000100 /* Tree contains a TK_COLLATE operator */
18150
-#define EP_Commuted 0x000200 /* Comparison operator has been commuted */
18151
-#define EP_IntValue 0x000400 /* Integer value contained in u.iValue */
18152
-#define EP_xIsSelect 0x000800 /* x.pSelect is valid (otherwise x.pList is) */
18153
-#define EP_Skip 0x001000 /* Operator does not contribute to affinity */
18154
-#define EP_Reduced 0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
18155
-#define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
18181
+#define EP_FixedCol 0x000020 /* TK_Column with a known fixed value */
18182
+#define EP_VarSelect 0x000040 /* pSelect is correlated, not constant */
18183
+#define EP_DblQuoted 0x000080 /* token.z was originally in "..." */
18184
+#define EP_InfixFunc 0x000100 /* True for an infix function: LIKE, GLOB, etc */
18185
+#define EP_Collate 0x000200 /* Tree contains a TK_COLLATE operator */
18186
+#define EP_Commuted 0x000400 /* Comparison operator has been commuted */
18187
+#define EP_IntValue 0x000800 /* Integer value contained in u.iValue */
18188
+#define EP_xIsSelect 0x001000 /* x.pSelect is valid (otherwise x.pList is) */
18189
+#define EP_Skip 0x002000 /* Operator does not contribute to affinity */
18190
+#define EP_Reduced 0x004000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
1815618191
#define EP_Win 0x008000 /* Contains window functions */
18157
-#define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
18158
-#define EP_IfNullRow 0x020000 /* The TK_IF_NULL_ROW opcode */
18159
-#define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
18160
-#define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
18161
-#define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
18162
-#define EP_Subquery 0x200000 /* Tree contains a TK_SELECT operator */
18163
-#define EP_InnerJoin 0x400000 /* Originates in ON/USING of an inner join */
18192
+#define EP_TokenOnly 0x010000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
18193
+#define EP_MemToken 0x020000 /* Need to sqlite3DbFree() Expr.zToken */
18194
+#define EP_IfNullRow 0x040000 /* The TK_IF_NULL_ROW opcode */
18195
+#define EP_Unlikely 0x080000 /* unlikely() or likelihood() function */
18196
+#define EP_ConstFunc 0x100000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
18197
+#define EP_CanBeNull 0x200000 /* Can be null despite NOT NULL constraint */
18198
+#define EP_Subquery 0x400000 /* Tree contains a TK_SELECT operator */
1816418199
#define EP_Leaf 0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */
1816518200
#define EP_WinFunc 0x1000000 /* TK_FUNCTION with Expr.y.pWin set */
1816618201
#define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */
1816718202
#define EP_Quoted 0x4000000 /* TK_ID was originally quoted */
1816818203
#define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */
@@ -18181,12 +18216,12 @@
1818118216
*/
1818218217
#define ExprHasProperty(E,P) (((E)->flags&(P))!=0)
1818318218
#define ExprHasAllProperty(E,P) (((E)->flags&(P))==(P))
1818418219
#define ExprSetProperty(E,P) (E)->flags|=(P)
1818518220
#define ExprClearProperty(E,P) (E)->flags&=~(P)
18186
-#define ExprAlwaysTrue(E) (((E)->flags&(EP_FromJoin|EP_IsTrue))==EP_IsTrue)
18187
-#define ExprAlwaysFalse(E) (((E)->flags&(EP_FromJoin|EP_IsFalse))==EP_IsFalse)
18221
+#define ExprAlwaysTrue(E) (((E)->flags&(EP_OuterON|EP_IsTrue))==EP_IsTrue)
18222
+#define ExprAlwaysFalse(E) (((E)->flags&(EP_OuterON|EP_IsFalse))==EP_IsFalse)
1818818223
1818918224
/* Macros used to ensure that the correct members of unions are accessed
1819018225
** in Expr.
1819118226
*/
1819218227
#define ExprUseUToken(E) (((E)->flags&EP_IntValue)==0)
@@ -18269,17 +18304,22 @@
1826918304
int nExpr; /* Number of expressions on the list */
1827018305
int nAlloc; /* Number of a[] slots allocated */
1827118306
struct ExprList_item { /* For each expression in the list */
1827218307
Expr *pExpr; /* The parse tree for this expression */
1827318308
char *zEName; /* Token associated with this expression */
18274
- u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */
18275
- unsigned eEName :2; /* Meaning of zEName */
18276
- unsigned done :1; /* A flag to indicate when processing is finished */
18277
- unsigned reusable :1; /* Constant expression is reusable */
18278
- unsigned bSorterRef :1; /* Defer evaluation until after sorting */
18279
- unsigned bNulls: 1; /* True if explicit "NULLS FIRST/LAST" */
18280
- unsigned bUsed: 1; /* This column used in a SF_NestedFrom subquery */
18309
+ struct {
18310
+ u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */
18311
+ unsigned eEName :2; /* Meaning of zEName */
18312
+ unsigned done :1; /* Indicates when processing is finished */
18313
+ unsigned reusable :1; /* Constant expression is reusable */
18314
+ unsigned bSorterRef :1; /* Defer evaluation until after sorting */
18315
+ unsigned bNulls :1; /* True if explicit "NULLS FIRST/LAST" */
18316
+ unsigned bUsed :1; /* This column used in a SF_NestedFrom subquery */
18317
+ unsigned bUsingTerm:1; /* Term from the USING clause of a NestedFrom */
18318
+ unsigned bNoExpand: 1; /* Term is an auxiliary in NestedFrom and should
18319
+ ** not be expanded by "*" in parent queries */
18320
+ } fg;
1828118321
union {
1828218322
struct { /* Used by any ExprList other than Parse.pConsExpr */
1828318323
u16 iOrderByCol; /* For ORDER BY, column number in result set */
1828418324
u16 iAlias; /* Index into Parse.aAlias[] for zName */
1828518325
} x;
@@ -18356,10 +18396,11 @@
1835618396
u8 jointype; /* Type of join between this table and the previous */
1835718397
unsigned notIndexed :1; /* True if there is a NOT INDEXED clause */
1835818398
unsigned isIndexedBy :1; /* True if there is an INDEXED BY clause */
1835918399
unsigned isTabFunc :1; /* True if table-valued-function syntax */
1836018400
unsigned isCorrelated :1; /* True if sub-query is correlated */
18401
+ unsigned isMaterialized:1; /* This is a materialized view */
1836118402
unsigned viaCoroutine :1; /* Implemented as a co-routine */
1836218403
unsigned isRecursive :1; /* True for recursive reference in WITH */
1836318404
unsigned fromDDL :1; /* Comes from sqlite_schema */
1836418405
unsigned isCte :1; /* This is a CTE */
1836518406
unsigned notCte :1; /* This item may not match a CTE */
@@ -19729,10 +19770,11 @@
1972919770
SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView*, const Expr*, u8);
1973019771
SQLITE_PRIVATE void sqlite3TreeViewBareExprList(TreeView*, const ExprList*, const char*);
1973119772
SQLITE_PRIVATE void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*);
1973219773
SQLITE_PRIVATE void sqlite3TreeViewBareIdList(TreeView*, const IdList*, const char*);
1973319774
SQLITE_PRIVATE void sqlite3TreeViewIdList(TreeView*, const IdList*, u8, const char*);
19775
+SQLITE_PRIVATE void sqlite3TreeViewColumnList(TreeView*, const Column*, int, u8);
1973419776
SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView*, const SrcList*);
1973519777
SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView*, const Select*, u8);
1973619778
SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView*, const With*, u8);
1973719779
SQLITE_PRIVATE void sqlite3TreeViewUpsert(TreeView*, const Upsert*, u8);
1973819780
SQLITE_PRIVATE void sqlite3TreeViewDelete(const With*, const SrcList*, const Expr*,
@@ -20022,10 +20064,11 @@
2002220064
SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
2002320065
SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
2002420066
SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
2002520067
SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
2002620068
SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
20069
+SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr*,const SrcItem*);
2002720070
#ifdef SQLITE_ENABLE_CURSOR_HINTS
2002820071
SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
2002920072
#endif
2003020073
SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*);
2003120074
SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
@@ -30462,12 +30505,18 @@
3046230505
sqlite3_str_append(pAccum, ".", 1);
3046330506
}
3046430507
sqlite3_str_appendall(pAccum, pItem->zName);
3046530508
}else if( pItem->zAlias ){
3046630509
sqlite3_str_appendall(pAccum, pItem->zAlias);
30467
- }else if( ALWAYS(pItem->pSelect) ){
30468
- sqlite3_str_appendf(pAccum, "SUBQUERY %u", pItem->pSelect->selId);
30510
+ }else{
30511
+ Select *pSel = pItem->pSelect;
30512
+ assert( pSel!=0 );
30513
+ if( pSel->selFlags & SF_NestedFrom ){
30514
+ sqlite3_str_appendf(pAccum, "(join-%u)", pSel->selId);
30515
+ }else{
30516
+ sqlite3_str_appendf(pAccum, "(subquery-%u)", pSel->selId);
30517
+ }
3046930518
}
3047030519
length = width = 0;
3047130520
break;
3047230521
}
3047330522
default: {
@@ -30526,11 +30575,13 @@
3052630575
/*
3052730576
** If pExpr has a byte offset for the start of a token, record that as
3052830577
** as the error offset.
3052930578
*/
3053030579
SQLITE_PRIVATE void sqlite3RecordErrorOffsetOfExpr(sqlite3 *db, const Expr *pExpr){
30531
- while( pExpr && (ExprHasProperty(pExpr,EP_FromJoin) || pExpr->w.iOfst<=0) ){
30580
+ while( pExpr
30581
+ && (ExprHasProperty(pExpr,EP_OuterON|EP_InnerON) || pExpr->w.iOfst<=0)
30582
+ ){
3053230583
pExpr = pExpr->pLeft;
3053330584
}
3053430585
if( pExpr==0 ) return;
3053530586
db->errByteOffset = pExpr->w.iOfst;
3053630587
}
@@ -31047,10 +31098,57 @@
3104731098
*/
3104831099
static void sqlite3TreeViewItem(TreeView *p, const char *zLabel,u8 moreFollows){
3104931100
sqlite3TreeViewPush(&p, moreFollows);
3105031101
sqlite3TreeViewLine(p, "%s", zLabel);
3105131102
}
31103
+
31104
+/*
31105
+** Show a list of Column objects in tree format.
31106
+*/
31107
+SQLITE_PRIVATE void sqlite3TreeViewColumnList(
31108
+ TreeView *pView,
31109
+ const Column *aCol,
31110
+ int nCol,
31111
+ u8 moreToFollow
31112
+){
31113
+ int i;
31114
+ sqlite3TreeViewPush(&pView, moreToFollow);
31115
+ sqlite3TreeViewLine(pView, "COLUMNS");
31116
+ for(i=0; i<nCol; i++){
31117
+ u16 flg = aCol[i].colFlags;
31118
+ int moreToFollow = i<(nCol - 1);
31119
+ sqlite3TreeViewPush(&pView, moreToFollow);
31120
+ sqlite3TreeViewLine(pView, 0);
31121
+ printf(" %s", aCol[i].zCnName);
31122
+ switch( aCol[i].eCType ){
31123
+ case COLTYPE_ANY: printf(" ANY"); break;
31124
+ case COLTYPE_BLOB: printf(" BLOB"); break;
31125
+ case COLTYPE_INT: printf(" INT"); break;
31126
+ case COLTYPE_INTEGER: printf(" INTEGER"); break;
31127
+ case COLTYPE_REAL: printf(" REAL"); break;
31128
+ case COLTYPE_TEXT: printf(" TEXT"); break;
31129
+ case COLTYPE_CUSTOM: {
31130
+ if( flg & COLFLAG_HASTYPE ){
31131
+ const char *z = aCol[i].zCnName;
31132
+ z += strlen(z)+1;
31133
+ printf(" X-%s", z);
31134
+ break;
31135
+ }
31136
+ }
31137
+ }
31138
+ if( flg & COLFLAG_PRIMKEY ) printf(" PRIMARY KEY");
31139
+ if( flg & COLFLAG_HIDDEN ) printf(" HIDDEN");
31140
+#ifdef COLFLAG_NOEXPAND
31141
+ if( flg & COLFLAG_NOEXPAND ) printf(" NO-EXPAND");
31142
+#endif
31143
+ if( flg ) printf(" flags=%04x", flg);
31144
+ printf("\n");
31145
+ fflush(stdout);
31146
+ sqlite3TreeViewPop(&pView);
31147
+ }
31148
+ sqlite3TreeViewPop(&pView);
31149
+}
3105231150
3105331151
/*
3105431152
** Generate a human-readable description of a WITH clause.
3105531153
*/
3105631154
SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 moreToFollow){
@@ -31077,10 +31175,14 @@
3107731175
sqlite3_str_appendf(&x, "%c%s", cSep, pCte->pCols->a[j].zEName);
3107831176
cSep = ',';
3107931177
}
3108031178
sqlite3_str_appendf(&x, ")");
3108131179
}
31180
+ if( pCte->eM10d!=M10d_Any ){
31181
+ sqlite3_str_appendf(&x, " %sMATERIALIZED",
31182
+ pCte->eM10d==M10d_No ? "NOT " : "");
31183
+ }
3108231184
if( pCte->pUse ){
3108331185
sqlite3_str_appendf(&x, " (pUse=0x%p, nUse=%d)", pCte->pUse,
3108431186
pCte->pUse->nUse);
3108531187
}
3108631188
sqlite3StrAccumFinish(&x);
@@ -31099,10 +31201,11 @@
3109931201
int i;
3110031202
if( pSrc==0 ) return;
3110131203
for(i=0; i<pSrc->nSrc; i++){
3110231204
const SrcItem *pItem = &pSrc->a[i];
3110331205
StrAccum x;
31206
+ int n = 0;
3110431207
char zLine[100];
3110531208
sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
3110631209
x.printfFlags |= SQLITE_PRINTF_INTERNAL;
3110731210
sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem);
3110831211
if( pItem->pTab ){
@@ -31127,13 +31230,24 @@
3112731230
if( pItem->fg.isCte ){
3112831231
sqlite3_str_appendf(&x, " CteUse=0x%p", pItem->u2.pCteUse);
3112931232
}
3113031233
sqlite3StrAccumFinish(&x);
3113131234
sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1);
31235
+ n = 0;
31236
+ if( pItem->pSelect ) n++;
31237
+ if( pItem->fg.isTabFunc ) n++;
31238
+ if( pItem->fg.isUsing ) n++;
31239
+ if( pItem->fg.isUsing ){
31240
+ sqlite3TreeViewIdList(pView, pItem->u3.pUsing, (--n)>0, "USING");
31241
+ }
3113231242
if( pItem->pSelect ){
31243
+ if( pItem->pTab ){
31244
+ Table *pTab = pItem->pTab;
31245
+ sqlite3TreeViewColumnList(pView, pTab->aCol, pTab->nCol, 1);
31246
+ }
3113331247
assert( pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
31134
- sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
31248
+ sqlite3TreeViewSelect(pView, pItem->pSelect, (--n)>0);
3113531249
}
3113631250
if( pItem->fg.isTabFunc ){
3113731251
sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:");
3113831252
}
3113931253
sqlite3TreeViewPop(&pView);
@@ -31296,10 +31410,11 @@
3129631410
/*
3129731411
** Generate a human-readable explanation for a Window object
3129831412
*/
3129931413
SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){
3130031414
int nElement = 0;
31415
+ if( pWin==0 ) return;
3130131416
if( pWin->pFilter ){
3130231417
sqlite3TreeViewItem(pView, "FILTER", 1);
3130331418
sqlite3TreeViewExpr(pView, pWin->pFilter, 0);
3130431419
sqlite3TreeViewPop(&pView);
3130531420
}
@@ -31360,10 +31475,11 @@
3136031475
#ifndef SQLITE_OMIT_WINDOWFUNC
3136131476
/*
3136231477
** Generate a human-readable explanation for a Window Function object
3136331478
*/
3136431479
SQLITE_PRIVATE void sqlite3TreeViewWinFunc(TreeView *pView, const Window *pWin, u8 more){
31480
+ if( pWin==0 ) return;
3136531481
sqlite3TreeViewPush(&pView, more);
3136631482
sqlite3TreeViewLine(pView, "WINFUNC %s(%d)",
3136731483
pWin->pWFunc->zName, pWin->pWFunc->nArg);
3136831484
sqlite3TreeViewWindow(pView, pWin, 0);
3136931485
sqlite3TreeViewPop(&pView);
@@ -31386,12 +31502,15 @@
3138631502
if( pExpr->flags || pExpr->affExpr || pExpr->vvaFlags ){
3138731503
StrAccum x;
3138831504
sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0);
3138931505
sqlite3_str_appendf(&x, " fg.af=%x.%c",
3139031506
pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n');
31391
- if( ExprHasProperty(pExpr, EP_FromJoin) ){
31392
- sqlite3_str_appendf(&x, " iJoin=%d", pExpr->w.iJoin);
31507
+ if( ExprHasProperty(pExpr, EP_OuterON) ){
31508
+ sqlite3_str_appendf(&x, " outer.iJoin=%d", pExpr->w.iJoin);
31509
+ }
31510
+ if( ExprHasProperty(pExpr, EP_InnerON) ){
31511
+ sqlite3_str_appendf(&x, " inner.iJoin=%d", pExpr->w.iJoin);
3139331512
}
3139431513
if( ExprHasProperty(pExpr, EP_FromDDL) ){
3139531514
sqlite3_str_appendf(&x, " DDL");
3139631515
}
3139731516
if( ExprHasVVAProperty(pExpr, EP_Immutable) ){
@@ -31611,11 +31730,21 @@
3161131730
sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags);
3161231731
sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
3161331732
break;
3161431733
}
3161531734
case TK_IN: {
31616
- sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags);
31735
+ sqlite3_str *pStr = sqlite3_str_new(0);
31736
+ char *z;
31737
+ sqlite3_str_appendf(pStr, "IN flags=0x%x", pExpr->flags);
31738
+ if( pExpr->iTable ) sqlite3_str_appendf(pStr, " iTable=%d",pExpr->iTable);
31739
+ if( ExprHasProperty(pExpr, EP_Subrtn) ){
31740
+ sqlite3_str_appendf(pStr, " subrtn(%d,%d)",
31741
+ pExpr->y.sub.regReturn, pExpr->y.sub.iAddr);
31742
+ }
31743
+ z = sqlite3_str_finish(pStr);
31744
+ sqlite3TreeViewLine(pView, z);
31745
+ sqlite3_free(z);
3161731746
sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
3161831747
if( ExprUseXSelect(pExpr) ){
3161931748
sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
3162031749
}else{
3162131750
sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
@@ -31762,17 +31891,19 @@
3176231891
if( j || zName ){
3176331892
sqlite3TreeViewPush(&pView, moreToFollow);
3176431893
moreToFollow = 0;
3176531894
sqlite3TreeViewLine(pView, 0);
3176631895
if( zName ){
31767
- switch( pList->a[i].eEName ){
31896
+ switch( pList->a[i].fg.eEName ){
3176831897
default:
3176931898
fprintf(stdout, "AS %s ", zName);
3177031899
break;
3177131900
case ENAME_TAB:
3177231901
fprintf(stdout, "TABLE-ALIAS-NAME(\"%s\") ", zName);
31773
- if( pList->a[i].bUsed==0 ) fprintf(stdout, "(unused) ");
31902
+ if( pList->a[i].fg.bUsed ) fprintf(stdout, "(used) ");
31903
+ if( pList->a[i].fg.bUsingTerm ) fprintf(stdout, "(USING-term) ");
31904
+ if( pList->a[i].fg.bNoExpand ) fprintf(stdout, "(NoExpand) ");
3177431905
break;
3177531906
case ENAME_SPAN:
3177631907
fprintf(stdout, "SPAN(\"%s\") ", zName);
3177731908
break;
3177831909
}
@@ -41741,90 +41872,103 @@
4174141872
}
4174241873
return SQLITE_OK;
4174341874
}
4174441875
4174541876
/*
41746
-** If the last component of the pathname in z[0]..z[j-1] is something
41747
-** other than ".." then back it out and return true. If the last
41748
-** component is empty or if it is ".." then return false.
41749
-*/
41750
-static int unixBackupDir(const char *z, int *pJ){
41751
- int j = *pJ;
41752
- int i;
41753
- if( j<=0 ) return 0;
41754
- for(i=j-1; i>0 && z[i-1]!='/'; i--){}
41755
- if( i==0 ) return 0;
41756
- if( z[i]=='.' && i==j-2 && z[i+1]=='.' ) return 0;
41757
- *pJ = i-1;
41758
- return 1;
41759
-}
41760
-
41761
-/*
41762
-** Convert a relative pathname into a full pathname. Also
41763
-** simplify the pathname as follows:
41764
-**
41765
-** Remove all instances of /./
41766
-** Remove all isntances of /X/../ for any X
41767
-*/
41768
-static int mkFullPathname(
41769
- const char *zPath, /* Input path */
41770
- char *zOut, /* Output buffer */
41771
- int nOut /* Allocated size of buffer zOut */
41772
-){
41773
- int nPath = sqlite3Strlen30(zPath);
41774
- int iOff = 0;
41775
- int i, j;
41776
- if( zPath[0]!='/' ){
41777
- if( osGetcwd(zOut, nOut-2)==0 ){
41778
- return unixLogError(SQLITE_CANTOPEN_BKPT, "getcwd", zPath);
41779
- }
41780
- iOff = sqlite3Strlen30(zOut);
41781
- zOut[iOff++] = '/';
41782
- }
41783
- if( (iOff+nPath+1)>nOut ){
41784
- /* SQLite assumes that xFullPathname() nul-terminates the output buffer
41785
- ** even if it returns an error. */
41786
- zOut[iOff] = '\0';
41787
- return SQLITE_CANTOPEN_BKPT;
41788
- }
41789
- sqlite3_snprintf(nOut-iOff, &zOut[iOff], "%s", zPath);
41790
-
41791
- /* Remove duplicate '/' characters. Except, two // at the beginning
41792
- ** of a pathname is allowed since this is important on windows. */
41793
- for(i=j=1; zOut[i]; i++){
41794
- zOut[j++] = zOut[i];
41795
- while( zOut[i]=='/' && zOut[i+1]=='/' ) i++;
41796
- }
41797
- zOut[j] = 0;
41798
-
41799
- assert( zOut[0]=='/' );
41800
- for(i=j=0; zOut[i]; i++){
41801
- if( zOut[i]=='/' ){
41802
- /* Skip over internal "/." directory components */
41803
- if( zOut[i+1]=='.' && zOut[i+2]=='/' ){
41804
- i += 1;
41805
- continue;
41806
- }
41807
-
41808
- /* If this is a "/.." directory component then back out the
41809
- ** previous term of the directory if it is something other than "..".
41810
- */
41811
- if( zOut[i+1]=='.'
41812
- && zOut[i+2]=='.'
41813
- && zOut[i+3]=='/'
41814
- && unixBackupDir(zOut, &j)
41815
- ){
41816
- i += 2;
41817
- continue;
41818
- }
41819
- }
41820
- if( ALWAYS(j>=0) ) zOut[j] = zOut[i];
41821
- j++;
41822
- }
41823
- if( NEVER(j==0) ) zOut[j++] = '/';
41824
- zOut[j] = 0;
41825
- return SQLITE_OK;
41877
+** A pathname under construction
41878
+*/
41879
+typedef struct DbPath DbPath;
41880
+struct DbPath {
41881
+ int rc; /* Non-zero following any error */
41882
+ int nSymlink; /* Number of symlinks resolved */
41883
+ char *zOut; /* Write the pathname here */
41884
+ int nOut; /* Bytes of space available to zOut[] */
41885
+ int nUsed; /* Bytes of zOut[] currently being used */
41886
+};
41887
+
41888
+/* Forward reference */
41889
+static void appendAllPathElements(DbPath*,const char*);
41890
+
41891
+/*
41892
+** Append a single path element to the DbPath under construction
41893
+*/
41894
+static void appendOnePathElement(
41895
+ DbPath *pPath, /* Path under construction, to which to append zName */
41896
+ const char *zName, /* Name to append to pPath. Not zero-terminated */
41897
+ int nName /* Number of significant bytes in zName */
41898
+){
41899
+ assert( nName>0 );
41900
+ assert( zName!=0 );
41901
+ if( zName[0]=='.' ){
41902
+ if( nName==1 ) return;
41903
+ if( zName[1]=='.' && nName==2 ){
41904
+ if( pPath->nUsed<=1 ){
41905
+ pPath->rc = SQLITE_ERROR;
41906
+ return;
41907
+ }
41908
+ assert( pPath->zOut[0]=='/' );
41909
+ while( pPath->zOut[--pPath->nUsed]!='/' ){}
41910
+ return;
41911
+ }
41912
+ }
41913
+ if( pPath->nUsed + nName + 2 >= pPath->nOut ){
41914
+ pPath->rc = SQLITE_ERROR;
41915
+ return;
41916
+ }
41917
+ pPath->zOut[pPath->nUsed++] = '/';
41918
+ memcpy(&pPath->zOut[pPath->nUsed], zName, nName);
41919
+ pPath->nUsed += nName;
41920
+#if defined(HAVE_READLINK) && defined(HAVE_LSTAT)
41921
+ if( pPath->rc==SQLITE_OK ){
41922
+ const char *zIn;
41923
+ struct stat buf;
41924
+ pPath->zOut[pPath->nUsed] = 0;
41925
+ zIn = pPath->zOut;
41926
+ if( osLstat(zIn, &buf)!=0 ){
41927
+ if( errno!=ENOENT ){
41928
+ pPath->rc = unixLogError(SQLITE_CANTOPEN_BKPT, "lstat", zIn);
41929
+ }
41930
+ }else if( S_ISLNK(buf.st_mode) ){
41931
+ ssize_t got;
41932
+ char zLnk[SQLITE_MAX_PATHLEN+2];
41933
+ if( pPath->nSymlink++ > SQLITE_MAX_SYMLINK ){
41934
+ pPath->rc = SQLITE_CANTOPEN_BKPT;
41935
+ return;
41936
+ }
41937
+ got = osReadlink(zIn, zLnk, sizeof(zLnk)-2);
41938
+ if( got<=0 || got>=(ssize_t)sizeof(zLnk)-2 ){
41939
+ pPath->rc = unixLogError(SQLITE_CANTOPEN_BKPT, "readlink", zIn);
41940
+ return;
41941
+ }
41942
+ zLnk[got] = 0;
41943
+ if( zLnk[0]=='/' ){
41944
+ pPath->nUsed = 0;
41945
+ }else{
41946
+ pPath->nUsed -= nName + 1;
41947
+ }
41948
+ appendAllPathElements(pPath, zLnk);
41949
+ }
41950
+ }
41951
+#endif
41952
+}
41953
+
41954
+/*
41955
+** Append all path elements in zPath to the DbPath under construction.
41956
+*/
41957
+static void appendAllPathElements(
41958
+ DbPath *pPath, /* Path under construction, to which to append zName */
41959
+ const char *zPath /* Path to append to pPath. Is zero-terminated */
41960
+){
41961
+ int i = 0;
41962
+ int j = 0;
41963
+ do{
41964
+ while( zPath[i] && zPath[i]!='/' ){ i++; }
41965
+ if( i>j ){
41966
+ appendOnePathElement(pPath, &zPath[j], i-j);
41967
+ }
41968
+ j = i+1;
41969
+ }while( zPath[i++] );
4182641970
}
4182741971
4182841972
/*
4182941973
** Turn a relative pathname into a full pathname. The relative path
4183041974
** is stored as a nul-terminated string in the buffer pointed to by
@@ -41838,89 +41982,30 @@
4183841982
sqlite3_vfs *pVfs, /* Pointer to vfs object */
4183941983
const char *zPath, /* Possibly relative input path */
4184041984
int nOut, /* Size of output buffer in bytes */
4184141985
char *zOut /* Output buffer */
4184241986
){
41843
-#if !defined(HAVE_READLINK) || !defined(HAVE_LSTAT)
41844
- return mkFullPathname(zPath, zOut, nOut);
41845
-#else
41846
- int rc = SQLITE_OK;
41847
- int nByte;
41848
- int nLink = 0; /* Number of symbolic links followed so far */
41849
- const char *zIn = zPath; /* Input path for each iteration of loop */
41850
- char *zDel = 0;
41851
-
41852
- assert( pVfs->mxPathname==MAX_PATHNAME );
41987
+ DbPath path;
4185341988
UNUSED_PARAMETER(pVfs);
41854
-
41855
- /* It's odd to simulate an io-error here, but really this is just
41856
- ** using the io-error infrastructure to test that SQLite handles this
41857
- ** function failing. This function could fail if, for example, the
41858
- ** current working directory has been unlinked.
41859
- */
41860
- SimulateIOError( return SQLITE_ERROR );
41861
-
41862
- do {
41863
-
41864
- /* Call stat() on path zIn. Set bLink to true if the path is a symbolic
41865
- ** link, or false otherwise. */
41866
- int bLink = 0;
41867
- struct stat buf;
41868
- if( osLstat(zIn, &buf)!=0 ){
41869
- if( errno!=ENOENT ){
41870
- rc = unixLogError(SQLITE_CANTOPEN_BKPT, "lstat", zIn);
41871
- }
41872
- }else{
41873
- bLink = S_ISLNK(buf.st_mode);
41874
- }
41875
-
41876
- if( bLink ){
41877
- nLink++;
41878
- if( zDel==0 ){
41879
- zDel = sqlite3_malloc(nOut);
41880
- if( zDel==0 ) rc = SQLITE_NOMEM_BKPT;
41881
- }else if( nLink>=SQLITE_MAX_SYMLINKS ){
41882
- rc = SQLITE_CANTOPEN_BKPT;
41883
- }
41884
-
41885
- if( rc==SQLITE_OK ){
41886
- nByte = osReadlink(zIn, zDel, nOut-1);
41887
- if( nByte<0 ){
41888
- rc = unixLogError(SQLITE_CANTOPEN_BKPT, "readlink", zIn);
41889
- }else{
41890
- if( zDel[0]!='/' ){
41891
- int n;
41892
- for(n = sqlite3Strlen30(zIn); n>0 && zIn[n-1]!='/'; n--);
41893
- if( nByte+n+1>nOut ){
41894
- rc = SQLITE_CANTOPEN_BKPT;
41895
- }else{
41896
- memmove(&zDel[n], zDel, nByte+1);
41897
- memcpy(zDel, zIn, n);
41898
- nByte += n;
41899
- }
41900
- }
41901
- zDel[nByte] = '\0';
41902
- }
41903
- }
41904
-
41905
- zIn = zDel;
41906
- }
41907
-
41908
- assert( rc!=SQLITE_OK || zIn!=zOut || zIn[0]=='/' );
41909
- if( rc==SQLITE_OK && zIn!=zOut ){
41910
- rc = mkFullPathname(zIn, zOut, nOut);
41911
- }
41912
- if( bLink==0 ) break;
41913
- zIn = zOut;
41914
- }while( rc==SQLITE_OK );
41915
-
41916
- sqlite3_free(zDel);
41917
- if( rc==SQLITE_OK && nLink ) rc = SQLITE_OK_SYMLINK;
41918
- return rc;
41919
-#endif /* HAVE_READLINK && HAVE_LSTAT */
41920
-}
41921
-
41989
+ path.rc = 0;
41990
+ path.nUsed = 0;
41991
+ path.nSymlink = 0;
41992
+ path.nOut = nOut;
41993
+ path.zOut = zOut;
41994
+ if( zPath[0]!='/' ){
41995
+ char zPwd[SQLITE_MAX_PATHLEN+2];
41996
+ if( osGetcwd(zPwd, sizeof(zPwd)-2)==0 ){
41997
+ return unixLogError(SQLITE_CANTOPEN_BKPT, "getcwd", zPath);
41998
+ }
41999
+ appendAllPathElements(&path, zPwd);
42000
+ }
42001
+ appendAllPathElements(&path, zPath);
42002
+ zOut[path.nUsed] = 0;
42003
+ if( path.rc || path.nUsed<2 ) return SQLITE_CANTOPEN_BKPT;
42004
+ if( path.nSymlink ) return SQLITE_OK_SYMLINK;
42005
+ return SQLITE_OK;
42006
+}
4192242007
4192342008
#ifndef SQLITE_OMIT_LOAD_EXTENSION
4192442009
/*
4192542010
** Interfaces for opening a shared library, finding entry points
4192642011
** within the shared library, and closing the shared library.
@@ -75861,11 +75946,11 @@
7586175946
}
7586275947
7586375948
TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
7586475949
pCur->pgnoRoot, pX->nKey, pX->nData, pPage->pgno,
7586575950
loc==0 ? "overwrite" : "new entry"));
75866
- assert( pPage->isInit );
75951
+ assert( pPage->isInit || CORRUPT_DB );
7586775952
newCell = pBt->pTmpSpace;
7586875953
assert( newCell!=0 );
7586975954
if( flags & BTREE_PREFORMAT ){
7587075955
rc = SQLITE_OK;
7587175956
szNew = pBt->nPreformatSize;
@@ -81423,10 +81508,94 @@
8142381508
pParse->nLabel = 0;
8142481509
*pMaxFuncArgs = nMaxArgs;
8142581510
assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) );
8142681511
}
8142781512
81513
+#ifdef SQLITE_DEBUG
81514
+/*
81515
+** Check to see if a subroutine contains a jump to a location outside of
81516
+** the subroutine. If a jump outside the subroutine is detected, add code
81517
+** that will cause the program to halt with an error message.
81518
+**
81519
+** The subroutine consists of opcodes between iFirst and iLast. Jumps to
81520
+** locations within the subroutine are acceptable. iRetReg is a register
81521
+** that contains the return address. Jumps to outside the range of iFirst
81522
+** through iLast are also acceptable as long as the jump destination is
81523
+** an OP_Return to iReturnAddr.
81524
+**
81525
+** A jump to an unresolved label means that the jump destination will be
81526
+** beyond the current address. That is normally a jump to an early
81527
+** termination and is consider acceptable.
81528
+**
81529
+** This routine only runs during debug builds. The purpose is (of course)
81530
+** to detect invalid escapes out of a subroutine. The OP_Halt opcode
81531
+** is generated rather than an assert() or other error, so that ".eqp full"
81532
+** will still work to show the original bytecode, to aid in debugging.
81533
+*/
81534
+SQLITE_PRIVATE void sqlite3VdbeNoJumpsOutsideSubrtn(
81535
+ Vdbe *v, /* The byte-code program under construction */
81536
+ int iFirst, /* First opcode of the subroutine */
81537
+ int iLast, /* Last opcode of the subroutine */
81538
+ int iRetReg /* Subroutine return address register */
81539
+){
81540
+ VdbeOp *pOp;
81541
+ Parse *pParse;
81542
+ int i;
81543
+ sqlite3_str *pErr = 0;
81544
+ assert( v!=0 );
81545
+ pParse = v->pParse;
81546
+ assert( pParse!=0 );
81547
+ if( pParse->nErr ) return;
81548
+ assert( iLast>=iFirst );
81549
+ assert( iLast<v->nOp );
81550
+ pOp = &v->aOp[iFirst];
81551
+ for(i=iFirst; i<=iLast; i++, pOp++){
81552
+ if( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 ){
81553
+ int iDest = pOp->p2; /* Jump destination */
81554
+ if( iDest==0 ) continue;
81555
+ if( pOp->opcode==OP_Gosub ) continue;
81556
+ if( iDest<0 ){
81557
+ int j = ADDR(iDest);
81558
+ assert( j>=0 );
81559
+ if( j>=-pParse->nLabel || pParse->aLabel[j]<0 ){
81560
+ continue;
81561
+ }
81562
+ iDest = pParse->aLabel[j];
81563
+ }
81564
+ if( iDest<iFirst || iDest>iLast ){
81565
+ int j = iDest;
81566
+ for(; j<v->nOp; j++){
81567
+ VdbeOp *pX = &v->aOp[j];
81568
+ if( pX->opcode==OP_Return ){
81569
+ if( pX->p1==iRetReg ) break;
81570
+ continue;
81571
+ }
81572
+ if( pX->opcode==OP_Noop ) continue;
81573
+ if( pX->opcode==OP_Explain ) continue;
81574
+ if( pErr==0 ){
81575
+ pErr = sqlite3_str_new(0);
81576
+ }else{
81577
+ sqlite3_str_appendchar(pErr, 1, '\n');
81578
+ }
81579
+ sqlite3_str_appendf(pErr,
81580
+ "Opcode at %d jumps to %d which is outside the "
81581
+ "subroutine at %d..%d",
81582
+ i, iDest, iFirst, iLast);
81583
+ break;
81584
+ }
81585
+ }
81586
+ }
81587
+ }
81588
+ if( pErr ){
81589
+ char *zErr = sqlite3_str_finish(pErr);
81590
+ sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_INTERNAL, OE_Abort, 0, zErr, 0);
81591
+ sqlite3_free(zErr);
81592
+ sqlite3MayAbort(pParse);
81593
+ }
81594
+}
81595
+#endif /* SQLITE_DEBUG */
81596
+
8142881597
/*
8142981598
** Return the address of the next instruction to be inserted.
8143081599
*/
8143181600
SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe *p){
8143281601
assert( p->eVdbeState==VDBE_INIT_STATE );
@@ -82035,15 +82204,13 @@
8203582204
if( c=='4' ){
8203682205
sqlite3_str_appendall(&x, zP4);
8203782206
}else if( c=='X' ){
8203882207
if( pOp->zComment && pOp->zComment[0] ){
8203982208
sqlite3_str_appendall(&x, pOp->zComment);
82040
- }else{
82041
- sqlite3_str_appendall(&x, zSynopsis+1);
82209
+ seenCom = 1;
82210
+ break;
8204282211
}
82043
- seenCom = 1;
82044
- break;
8204582212
}else{
8204682213
int v1 = translateP(c, pOp);
8204782214
int v2;
8204882215
if( strncmp(zSynopsis+ii+1, "@P", 2)==0 ){
8204982216
ii += 3;
@@ -89154,10 +89321,12 @@
8915489321
if( pOp->p2==0 ) break;
8915589322
8915689323
/* Most jump operations do a goto to this spot in order to update
8915789324
** the pOp pointer. */
8915889325
jump_to_p2:
89326
+ assert( pOp->p2>0 ); /* There are never any jumps to instruction 0 */
89327
+ assert( pOp->p2<p->nOp ); /* Jumps must be in range */
8915989328
pOp = &aOp[pOp->p2 - 1];
8916089329
break;
8916189330
}
8916289331
8916389332
/* Opcode: EndCoroutine P1 * * * *
@@ -101365,11 +101534,11 @@
101365101534
const char *zTab,
101366101535
const char *zDb
101367101536
){
101368101537
int n;
101369101538
const char *zSpan;
101370
- if( pItem->eEName!=ENAME_TAB ) return 0;
101539
+ if( pItem->fg.eEName!=ENAME_TAB ) return 0;
101371101540
zSpan = pItem->zEName;
101372101541
for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
101373101542
if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){
101374101543
return 0;
101375101544
}
@@ -101594,12 +101763,13 @@
101594101763
}
101595101764
cnt++;
101596101765
cntTab = 2;
101597101766
pMatch = pItem;
101598101767
pExpr->iColumn = j;
101599
- pEList->a[j].bUsed = 1;
101768
+ pEList->a[j].fg.bUsed = 1;
101600101769
hit = 1;
101770
+ if( pEList->a[j].fg.bUsingTerm ) break;
101601101771
}
101602101772
if( hit || zTab==0 ) continue;
101603101773
}
101604101774
assert( zDb==0 || zTab!=0 );
101605101775
if( zTab ){
@@ -101818,11 +101988,11 @@
101818101988
){
101819101989
pEList = pNC->uNC.pEList;
101820101990
assert( pEList!=0 );
101821101991
for(j=0; j<pEList->nExpr; j++){
101822101992
char *zAs = pEList->a[j].zEName;
101823
- if( pEList->a[j].eEName==ENAME_NAME
101993
+ if( pEList->a[j].fg.eEName==ENAME_NAME
101824101994
&& sqlite3_stricmp(zAs, zCol)==0
101825101995
){
101826101996
Expr *pOrig;
101827101997
assert( pExpr->pLeft==0 && pExpr->pRight==0 );
101828101998
assert( ExprUseXList(pExpr)==0 || pExpr->x.pList==0 );
@@ -102162,11 +102332,11 @@
102162102332
for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){
102163102333
anRef[i] = p->nRef;
102164102334
}
102165102335
sqlite3WalkExpr(pWalker, pExpr->pLeft);
102166102336
if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){
102167
- testcase( ExprHasProperty(pExpr, EP_FromJoin) );
102337
+ testcase( ExprHasProperty(pExpr, EP_OuterON) );
102168102338
assert( !ExprHasProperty(pExpr, EP_IntValue) );
102169102339
if( pExpr->op==TK_NOTNULL ){
102170102340
pExpr->u.zToken = "true";
102171102341
ExprSetProperty(pExpr, EP_IsTrue);
102172102342
}else{
@@ -102571,11 +102741,11 @@
102571102741
if( pE->op==TK_ID ){
102572102742
const char *zCol;
102573102743
assert( !ExprHasProperty(pE, EP_IntValue) );
102574102744
zCol = pE->u.zToken;
102575102745
for(i=0; i<pEList->nExpr; i++){
102576
- if( pEList->a[i].eEName==ENAME_NAME
102746
+ if( pEList->a[i].fg.eEName==ENAME_NAME
102577102747
&& sqlite3_stricmp(pEList->a[i].zEName, zCol)==0
102578102748
){
102579102749
return i+1;
102580102750
}
102581102751
}
@@ -102692,11 +102862,11 @@
102692102862
if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
102693102863
sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause");
102694102864
return 1;
102695102865
}
102696102866
for(i=0; i<pOrderBy->nExpr; i++){
102697
- pOrderBy->a[i].done = 0;
102867
+ pOrderBy->a[i].fg.done = 0;
102698102868
}
102699102869
pSelect->pNext = 0;
102700102870
while( pSelect->pPrior ){
102701102871
pSelect->pPrior->pNext = pSelect;
102702102872
pSelect = pSelect->pPrior;
@@ -102707,11 +102877,11 @@
102707102877
pEList = pSelect->pEList;
102708102878
assert( pEList!=0 );
102709102879
for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
102710102880
int iCol = -1;
102711102881
Expr *pE, *pDup;
102712
- if( pItem->done ) continue;
102882
+ if( pItem->fg.done ) continue;
102713102883
pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr);
102714102884
if( NEVER(pE==0) ) continue;
102715102885
if( sqlite3ExprIsInteger(pE, &iCol) ){
102716102886
if( iCol<=0 || iCol>pEList->nExpr ){
102717102887
resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr, pE);
@@ -102760,19 +102930,19 @@
102760102930
pParent->pLeft = pNew;
102761102931
}
102762102932
sqlite3ExprDelete(db, pE);
102763102933
pItem->u.x.iOrderByCol = (u16)iCol;
102764102934
}
102765
- pItem->done = 1;
102935
+ pItem->fg.done = 1;
102766102936
}else{
102767102937
moreToDo = 1;
102768102938
}
102769102939
}
102770102940
pSelect = pSelect->pNext;
102771102941
}
102772102942
for(i=0; i<pOrderBy->nExpr; i++){
102773
- if( pOrderBy->a[i].done==0 ){
102943
+ if( pOrderBy->a[i].fg.done==0 ){
102774102944
sqlite3ErrorMsg(pParse, "%r ORDER BY term does not match any "
102775102945
"column in the result set", i+1);
102776102946
return 1;
102777102947
}
102778102948
}
@@ -104453,10 +104623,11 @@
104453104623
pNew = sqlite3ExprAlloc(db, TK_FUNCTION, pToken, 1);
104454104624
if( pNew==0 ){
104455104625
sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */
104456104626
return 0;
104457104627
}
104628
+ assert( !ExprHasProperty(pNew, EP_InnerON|EP_OuterON) );
104458104629
pNew->w.iOfst = (int)(pToken->z - pParse->zTail);
104459104630
if( pList
104460104631
&& pList->nExpr > pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG]
104461104632
&& !pParse->nested
104462104633
){
@@ -104731,11 +104902,11 @@
104731104902
#endif
104732104903
){
104733104904
nSize = EXPR_FULLSIZE;
104734104905
}else{
104735104906
assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
104736
- assert( !ExprHasProperty(p, EP_FromJoin) );
104907
+ assert( !ExprHasProperty(p, EP_OuterON) );
104737104908
assert( !ExprHasProperty(p, EP_MemToken) );
104738104909
assert( !ExprHasVVAProperty(p, EP_NoReduce) );
104739104910
if( p->pLeft || p->x.pList ){
104740104911
nSize = EXPR_REDUCEDSIZE | EP_Reduced;
104741104912
}else{
@@ -104911,10 +105082,11 @@
104911105082
pRet->nCte = p->nCte;
104912105083
for(i=0; i<p->nCte; i++){
104913105084
pRet->a[i].pSelect = sqlite3SelectDup(db, p->a[i].pSelect, 0);
104914105085
pRet->a[i].pCols = sqlite3ExprListDup(db, p->a[i].pCols, 0);
104915105086
pRet->a[i].zName = sqlite3DbStrDup(db, p->a[i].zName);
105087
+ pRet->a[i].eM10d = p->a[i].eM10d;
104916105088
}
104917105089
}
104918105090
}
104919105091
return pRet;
104920105092
}
@@ -105011,16 +105183,12 @@
105011105183
}
105012105184
pNewExpr->pLeft = pPriorSelectColNew;
105013105185
}
105014105186
}
105015105187
pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName);
105016
- pItem->sortFlags = pOldItem->sortFlags;
105017
- pItem->eEName = pOldItem->eEName;
105018
- pItem->done = 0;
105019
- pItem->bNulls = pOldItem->bNulls;
105020
- pItem->bUsed = pOldItem->bUsed;
105021
- pItem->bSorterRef = pOldItem->bSorterRef;
105188
+ pItem->fg = pOldItem->fg;
105189
+ pItem->fg.done = 0;
105022105190
pItem->u = pOldItem->u;
105023105191
}
105024105192
return pNew;
105025105193
}
105026105194
@@ -105316,20 +105484,20 @@
105316105484
|| eNulls==SQLITE_SO_ASC
105317105485
|| eNulls==SQLITE_SO_DESC
105318105486
);
105319105487
105320105488
pItem = &p->a[p->nExpr-1];
105321
- assert( pItem->bNulls==0 );
105489
+ assert( pItem->fg.bNulls==0 );
105322105490
if( iSortOrder==SQLITE_SO_UNDEFINED ){
105323105491
iSortOrder = SQLITE_SO_ASC;
105324105492
}
105325
- pItem->sortFlags = (u8)iSortOrder;
105493
+ pItem->fg.sortFlags = (u8)iSortOrder;
105326105494
105327105495
if( eNulls!=SQLITE_SO_UNDEFINED ){
105328
- pItem->bNulls = 1;
105496
+ pItem->fg.bNulls = 1;
105329105497
if( iSortOrder!=eNulls ){
105330
- pItem->sortFlags |= KEYINFO_ORDER_BIGNULL;
105498
+ pItem->fg.sortFlags |= KEYINFO_ORDER_BIGNULL;
105331105499
}
105332105500
}
105333105501
}
105334105502
105335105503
/*
@@ -105351,11 +105519,11 @@
105351105519
if( pList ){
105352105520
struct ExprList_item *pItem;
105353105521
assert( pList->nExpr>0 );
105354105522
pItem = &pList->a[pList->nExpr-1];
105355105523
assert( pItem->zEName==0 );
105356
- assert( pItem->eEName==ENAME_NAME );
105524
+ assert( pItem->fg.eEName==ENAME_NAME );
105357105525
pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
105358105526
if( dequote ){
105359105527
/* If dequote==0, then pName->z does not point to part of a DDL
105360105528
** statement handled by the parser. And so no token need be added
105361105529
** to the token-map. */
@@ -105386,11 +105554,11 @@
105386105554
if( pList ){
105387105555
struct ExprList_item *pItem = &pList->a[pList->nExpr-1];
105388105556
assert( pList->nExpr>0 );
105389105557
if( pItem->zEName==0 ){
105390105558
pItem->zEName = sqlite3DbSpanDup(db, zStart, zEnd);
105391
- pItem->eEName = ENAME_SPAN;
105559
+ pItem->fg.eEName = ENAME_SPAN;
105392105560
}
105393105561
}
105394105562
}
105395105563
105396105564
/*
@@ -105560,11 +105728,11 @@
105560105728
static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
105561105729
105562105730
/* If pWalker->eCode is 2 then any term of the expression that comes from
105563105731
** the ON or USING clauses of an outer join disqualifies the expression
105564105732
** from being considered constant. */
105565
- if( pWalker->eCode==2 && ExprHasProperty(pExpr, EP_FromJoin) ){
105733
+ if( pWalker->eCode==2 && ExprHasProperty(pExpr, EP_OuterON) ){
105566105734
pWalker->eCode = 0;
105567105735
return WRC_Abort;
105568105736
}
105569105737
105570105738
switch( pExpr->op ){
@@ -105678,10 +105846,46 @@
105678105846
** table other than iCur.
105679105847
*/
105680105848
SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){
105681105849
return exprIsConst(p, 3, iCur);
105682105850
}
105851
+
105852
+/*
105853
+** Check pExpr to see if it is an invariant constraint on data source pSrc.
105854
+** This is an optimization. False negatives will perhaps cause slower
105855
+** queries, but false positives will yield incorrect answers. So when in
105856
+** doubt, return 0.
105857
+**
105858
+** To be an invariant constraint, the following must be true:
105859
+**
105860
+** (1) pExpr cannot refer to any table other than pSrc->iCursor.
105861
+**
105862
+** (2) pExpr cannot use subqueries or non-deterministic functions.
105863
+**
105864
+** (3) pSrc cannot be part of the left operand for a RIGHT JOIN.
105865
+** (Is there some way to relax this constraint?)
105866
+**
105867
+** (4) If pSrc is the right operand of a LEFT JOIN, then...
105868
+** (4a) pExpr must come from an ON clause..
105869
+ (4b) and specifically the ON clause associated with the LEFT JOIN.
105870
+**
105871
+** (5) If pSrc is not the right operand of a LEFT JOIN or the left
105872
+** operand of a RIGHT JOIN, then pExpr must be from the WHERE
105873
+** clause, not an ON clause.
105874
+*/
105875
+SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr *pExpr, const SrcItem *pSrc){
105876
+ if( pSrc->fg.jointype & JT_LTORJ ){
105877
+ return 0; /* rule (3) */
105878
+ }
105879
+ if( pSrc->fg.jointype & JT_LEFT ){
105880
+ if( !ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* rule (4a) */
105881
+ if( pExpr->w.iJoin!=pSrc->iCursor ) return 0; /* rule (4b) */
105882
+ }else{
105883
+ if( ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* rule (5) */
105884
+ }
105885
+ return sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor); /* rules (1), (2) */
105886
+}
105683105887
105684105888
105685105889
/*
105686105890
** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy().
105687105891
*/
@@ -106006,11 +106210,11 @@
106006106210
** The job of this routine is to find or create a b-tree object that can
106007106211
** be used either to test for membership in the RHS set or to iterate through
106008106212
** all members of the RHS set, skipping duplicates.
106009106213
**
106010106214
** A cursor is opened on the b-tree object that is the RHS of the IN operator
106011
-** and pX->iTable is set to the index of that cursor.
106215
+** and the *piTab parameter is set to the index of that cursor.
106012106216
**
106013106217
** The returned value of this function indicates the b-tree type, as follows:
106014106218
**
106015106219
** IN_INDEX_ROWID - The cursor was opened on a database table.
106016106220
** IN_INDEX_INDEX_ASC - The cursor was opened on an ascending index.
@@ -106026,11 +106230,14 @@
106026106230
** SELECT <column1>, <column2>... FROM <table>
106027106231
**
106028106232
** If the RHS of the IN operator is a list or a more complex subquery, then
106029106233
** an ephemeral table might need to be generated from the RHS and then
106030106234
** pX->iTable made to point to the ephemeral table instead of an
106031
-** existing table.
106235
+** existing table. In this case, the creation and initialization of the
106236
+** ephmeral table might be put inside of a subroutine, the EP_Subrtn flag
106237
+** will be set on pX and the pX->y.sub fields will be set to show where
106238
+** the subroutine is coded.
106032106239
**
106033106240
** The inFlags parameter must contain, at a minimum, one of the bits
106034106241
** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP but not both. If inFlags contains
106035106242
** IN_INDEX_MEMBERSHIP, then the generated table will be used for a fast
106036106243
** membership test. When the IN_INDEX_LOOP bit is set, the IN index will
@@ -106087,16 +106294,17 @@
106087106294
int *aiMap, /* Mapping from Index fields to RHS fields */
106088106295
int *piTab /* OUT: index to use */
106089106296
){
106090106297
Select *p; /* SELECT to the right of IN operator */
106091106298
int eType = 0; /* Type of RHS table. IN_INDEX_* */
106092
- int iTab = pParse->nTab++; /* Cursor of the RHS table */
106299
+ int iTab; /* Cursor of the RHS table */
106093106300
int mustBeUnique; /* True if RHS must be unique */
106094106301
Vdbe *v = sqlite3GetVdbe(pParse); /* Virtual machine being coded */
106095106302
106096106303
assert( pX->op==TK_IN );
106097106304
mustBeUnique = (inFlags & IN_INDEX_LOOP)!=0;
106305
+ iTab = pParse->nTab++;
106098106306
106099106307
/* If the RHS of this IN(...) operator is a SELECT, and if it matters
106100106308
** whether or not the SELECT result contains NULL values, check whether
106101106309
** or not NULL is actually possible (it may not be, for example, due
106102106310
** to NOT NULL constraints in the schema). If no NULL values are possible,
@@ -106258,10 +106466,12 @@
106258106466
if( eType==0
106259106467
&& (inFlags & IN_INDEX_NOOP_OK)
106260106468
&& ExprUseXList(pX)
106261106469
&& (!sqlite3InRhsIsConstant(pX) || pX->x.pList->nExpr<=2)
106262106470
){
106471
+ pParse->nTab--; /* Back out the allocation of the unused cursor */
106472
+ iTab = -1; /* Cursor is not allocated */
106263106473
eType = IN_INDEX_NOOP;
106264106474
}
106265106475
106266106476
if( eType==0 ){
106267106477
/* Could not find an existing table or index to use as the RHS b-tree.
@@ -106424,10 +106634,11 @@
106424106634
pExpr->x.pSelect->selId));
106425106635
}
106426106636
assert( ExprUseYSub(pExpr) );
106427106637
sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
106428106638
pExpr->y.sub.iAddr);
106639
+ assert( iTab!=pExpr->iTable );
106429106640
sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable);
106430106641
sqlite3VdbeJumpHere(v, addrOnce);
106431106642
return;
106432106643
}
106433106644
@@ -107298,11 +107509,21 @@
107298107509
memset(&caseExpr, 0, sizeof(caseExpr));
107299107510
caseExpr.op = TK_CASE;
107300107511
caseExpr.x.pList = pFarg;
107301107512
return sqlite3ExprCodeTarget(pParse, &caseExpr, target);
107302107513
}
107303
-
107514
+#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
107515
+ case INLINEFUNC_sqlite_offset: {
107516
+ Expr *pArg = pFarg->a[0].pExpr;
107517
+ if( pArg->op==TK_COLUMN && pArg->iTable>=0 ){
107518
+ sqlite3VdbeAddOp3(v, OP_Offset, pArg->iTable, pArg->iColumn, target);
107519
+ }else{
107520
+ sqlite3VdbeAddOp2(v, OP_Null, 0, target);
107521
+ }
107522
+ break;
107523
+ }
107524
+#endif
107304107525
default: {
107305107526
/* The UNLIKELY() function is a no-op. The result is the value
107306107527
** of the first argument.
107307107528
*/
107308107529
assert( nFarg==1 || nFarg==2 );
@@ -107837,24 +108058,12 @@
107837108058
#endif
107838108059
if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){
107839108060
if( !pColl ) pColl = db->pDfltColl;
107840108061
sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
107841108062
}
107842
-#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
107843
- if( (pDef->funcFlags & SQLITE_FUNC_OFFSET)!=0 && ALWAYS(pFarg!=0) ){
107844
- Expr *pArg = pFarg->a[0].pExpr;
107845
- if( pArg->op==TK_COLUMN ){
107846
- sqlite3VdbeAddOp3(v, OP_Offset, pArg->iTable, pArg->iColumn, target);
107847
- }else{
107848
- sqlite3VdbeAddOp2(v, OP_Null, 0, target);
107849
- }
107850
- }else
107851
-#endif
107852
- {
107853
- sqlite3VdbeAddFunctionCall(pParse, constMask, r1, target, nFarg,
107854
- pDef, pExpr->op2);
107855
- }
108063
+ sqlite3VdbeAddFunctionCall(pParse, constMask, r1, target, nFarg,
108064
+ pDef, pExpr->op2);
107856108065
if( nFarg ){
107857108066
if( constMask==0 ){
107858108067
sqlite3ReleaseTempRange(pParse, r1, nFarg);
107859108068
}else{
107860108069
sqlite3VdbeReleaseRegisters(pParse, r1, nFarg, constMask, 1);
@@ -108164,11 +108373,13 @@
108164108373
p = pParse->pConstExpr;
108165108374
if( regDest<0 && p ){
108166108375
struct ExprList_item *pItem;
108167108376
int i;
108168108377
for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
108169
- if( pItem->reusable && sqlite3ExprCompare(0,pItem->pExpr,pExpr,-1)==0 ){
108378
+ if( pItem->fg.reusable
108379
+ && sqlite3ExprCompare(0,pItem->pExpr,pExpr,-1)==0
108380
+ ){
108170108381
return pItem->u.iConstExprReg;
108171108382
}
108172108383
}
108173108384
}
108174108385
pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
@@ -108187,11 +108398,11 @@
108187108398
sqlite3VdbeJumpHere(v, addr);
108188108399
}else{
108189108400
p = sqlite3ExprListAppend(pParse, p, pExpr);
108190108401
if( p ){
108191108402
struct ExprList_item *pItem = &p->a[p->nExpr-1];
108192
- pItem->reusable = regDest<0;
108403
+ pItem->fg.reusable = regDest<0;
108193108404
if( regDest<0 ) regDest = ++pParse->nMem;
108194108405
pItem->u.iConstExprReg = regDest;
108195108406
}
108196108407
pParse->pConstExpr = p;
108197108408
}
@@ -108321,11 +108532,11 @@
108321108532
n = pList->nExpr;
108322108533
if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR;
108323108534
for(pItem=pList->a, i=0; i<n; i++, pItem++){
108324108535
Expr *pExpr = pItem->pExpr;
108325108536
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
108326
- if( pItem->bSorterRef ){
108537
+ if( pItem->fg.bSorterRef ){
108327108538
i--;
108328108539
n--;
108329108540
}else
108330108541
#endif
108331108542
if( (flags & SQLITE_ECEL_REF)!=0 && (j = pItem->u.x.iOrderByCol)>0 ){
@@ -108415,12 +108626,12 @@
108415108626
}else{
108416108627
/* Mark the expression is being from the ON or USING clause of a join
108417108628
** so that the sqlite3ExprCodeTarget() routine will not attempt to move
108418108629
** it into the Parse.pConstExpr list. We should use a new bit for this,
108419108630
** for clarity, but we are out of bits in the Expr.flags field so we
108420
- ** have to reuse the EP_FromJoin bit. Bummer. */
108421
- pDel->flags |= EP_FromJoin;
108631
+ ** have to reuse the EP_OuterON bit. Bummer. */
108632
+ pDel->flags |= EP_OuterON;
108422108633
sqlite3ExprCodeTarget(pParse, &exprAnd, dest);
108423108634
}
108424108635
sqlite3ReleaseTempReg(pParse, regFree1);
108425108636
}
108426108637
sqlite3ExprDelete(db, pDel);
@@ -108946,11 +109157,11 @@
108946109157
if( pA->nExpr!=pB->nExpr ) return 1;
108947109158
for(i=0; i<pA->nExpr; i++){
108948109159
int res;
108949109160
Expr *pExprA = pA->a[i].pExpr;
108950109161
Expr *pExprB = pB->a[i].pExpr;
108951
- if( pA->a[i].sortFlags!=pB->a[i].sortFlags ) return 1;
109162
+ if( pA->a[i].fg.sortFlags!=pB->a[i].fg.sortFlags ) return 1;
108952109163
if( (res = sqlite3ExprCompare(0, pExprA, pExprB, iTab)) ) return res;
108953109164
}
108954109165
return 0;
108955109166
}
108956109167
@@ -109101,11 +109312,11 @@
109101109312
** (never setting pWalker->eCode) is a harmless missed optimization.
109102109313
*/
109103109314
static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){
109104109315
testcase( pExpr->op==TK_AGG_COLUMN );
109105109316
testcase( pExpr->op==TK_AGG_FUNCTION );
109106
- if( ExprHasProperty(pExpr, EP_FromJoin) ) return WRC_Prune;
109317
+ if( ExprHasProperty(pExpr, EP_OuterON) ) return WRC_Prune;
109107109318
switch( pExpr->op ){
109108109319
case TK_ISNOT:
109109109320
case TK_ISNULL:
109110109321
case TK_NOTNULL:
109111109322
case TK_IS:
@@ -109198,11 +109409,11 @@
109198109409
** is NULL. A false negative is merely a missed optimization opportunity.
109199109410
**
109200109411
** False positives are not allowed, however. A false positive may result
109201109412
** in an incorrect answer.
109202109413
**
109203
-** Terms of p that are marked with EP_FromJoin (and hence that come from
109414
+** Terms of p that are marked with EP_OuterON (and hence that come from
109204109415
** the ON or USING clauses of OUTER JOINS) are excluded from the analysis.
109205109416
**
109206109417
** This routine is used to check if a LEFT JOIN can be converted into
109207109418
** an ordinary JOIN. The p argument is the WHERE clause. If the WHERE
109208109419
** clause requires that some column of the right table of the LEFT JOIN
@@ -110635,11 +110846,11 @@
110635110846
return WRC_Prune;
110636110847
}
110637110848
if( ALWAYS(p->pEList) ){
110638110849
ExprList *pList = p->pEList;
110639110850
for(i=0; i<pList->nExpr; i++){
110640
- if( pList->a[i].zEName && pList->a[i].eEName==ENAME_NAME ){
110851
+ if( pList->a[i].zEName && pList->a[i].fg.eEName==ENAME_NAME ){
110641110852
sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName);
110642110853
}
110643110854
}
110644110855
}
110645110856
if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */
@@ -110684,11 +110895,11 @@
110684110895
memset(&sWalker, 0, sizeof(Walker));
110685110896
sWalker.pParse = pParse;
110686110897
sWalker.xExprCallback = renameUnmapExprCb;
110687110898
sqlite3WalkExprList(&sWalker, pEList);
110688110899
for(i=0; i<pEList->nExpr; i++){
110689
- if( ALWAYS(pEList->a[i].eEName==ENAME_NAME) ){
110900
+ if( ALWAYS(pEList->a[i].fg.eEName==ENAME_NAME) ){
110690110901
sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName);
110691110902
}
110692110903
}
110693110904
}
110694110905
}
@@ -110842,11 +111053,11 @@
110842111053
){
110843111054
if( pEList ){
110844111055
int i;
110845111056
for(i=0; i<pEList->nExpr; i++){
110846111057
const char *zName = pEList->a[i].zEName;
110847
- if( ALWAYS(pEList->a[i].eEName==ENAME_NAME)
111058
+ if( ALWAYS(pEList->a[i].fg.eEName==ENAME_NAME)
110848111059
&& ALWAYS(zName!=0)
110849111060
&& 0==sqlite3_stricmp(zName, zOld)
110850111061
){
110851111062
renameTokenFind(pParse, pCtx, (const void*)zName);
110852111063
}
@@ -111072,31 +111283,37 @@
111072111283
if( pParse->nErr ) rc = pParse->rc;
111073111284
}
111074111285
if( rc==SQLITE_OK && pStep->zTarget ){
111075111286
SrcList *pSrc = sqlite3TriggerStepSrc(pParse, pStep);
111076111287
if( pSrc ){
111077
- int i;
111078
- for(i=0; i<pSrc->nSrc && rc==SQLITE_OK; i++){
111079
- SrcItem *p = &pSrc->a[i];
111080
- p->iCursor = pParse->nTab++;
111081
- if( p->pSelect ){
111082
- sqlite3SelectPrep(pParse, p->pSelect, 0);
111083
- sqlite3ExpandSubquery(pParse, p);
111084
- assert( i>0 );
111085
- assert( pStep->pFrom->a[i-1].pSelect );
111086
- sqlite3SelectPrep(pParse, pStep->pFrom->a[i-1].pSelect, 0);
111087
- }else{
111088
- p->pTab = sqlite3LocateTableItem(pParse, 0, p);
111089
- if( p->pTab==0 ){
111090
- rc = SQLITE_ERROR;
111091
- }else{
111092
- p->pTab->nTabRef++;
111093
- rc = sqlite3ViewGetColumnNames(pParse, p->pTab);
111288
+ Select *pSel = sqlite3SelectNew(
111289
+ pParse, pStep->pExprList, pSrc, 0, 0, 0, 0, 0, 0
111290
+ );
111291
+ if( pSel==0 ){
111292
+ pStep->pExprList = 0;
111293
+ pSrc = 0;
111294
+ rc = SQLITE_NOMEM;
111295
+ }else{
111296
+ sqlite3SelectPrep(pParse, pSel, 0);
111297
+ rc = pParse->nErr ? SQLITE_ERROR : SQLITE_OK;
111298
+ assert( pStep->pExprList==0 || pStep->pExprList==pSel->pEList );
111299
+ assert( pSrc==pSel->pSrc );
111300
+ if( pStep->pExprList ) pSel->pEList = 0;
111301
+ pSel->pSrc = 0;
111302
+ sqlite3SelectDelete(db, pSel);
111303
+ }
111304
+ if( pStep->pFrom ){
111305
+ int i;
111306
+ for(i=0; i<pStep->pFrom->nSrc && rc==SQLITE_OK; i++){
111307
+ SrcItem *p = &pStep->pFrom->a[i];
111308
+ if( p->pSelect ){
111309
+ sqlite3SelectPrep(pParse, p->pSelect, 0);
111094111310
}
111095111311
}
111096111312
}
111097
- if( rc==SQLITE_OK && db->mallocFailed ){
111313
+
111314
+ if( db->mallocFailed ){
111098111315
rc = SQLITE_NOMEM;
111099111316
}
111100111317
sNC.pSrcList = pSrc;
111101111318
if( rc==SQLITE_OK && pStep->pWhere ){
111102111319
rc = sqlite3ResolveExprNames(&sNC, pStep->pWhere);
@@ -111543,10 +111760,19 @@
111543111760
if( rc==SQLITE_OK ){
111544111761
renameWalkTrigger(&sWalker, pTrigger);
111545111762
for(pStep=pTrigger->step_list; pStep; pStep=pStep->pNext){
111546111763
if( pStep->zTarget && 0==sqlite3_stricmp(pStep->zTarget, zOld) ){
111547111764
renameTokenFind(&sParse, &sCtx, pStep->zTarget);
111765
+ }
111766
+ if( pStep->pFrom ){
111767
+ int i;
111768
+ for(i=0; i<pStep->pFrom->nSrc; i++){
111769
+ SrcItem *pItem = &pStep->pFrom->a[i];
111770
+ if( 0==sqlite3_stricmp(pItem->zName, zOld) ){
111771
+ renameTokenFind(&sParse, &sCtx, pItem->zName);
111772
+ }
111773
+ }
111548111774
}
111549111775
}
111550111776
}
111551111777
}
111552111778
}
@@ -112867,13 +113093,18 @@
112867113093
** * the index contains 100 rows,
112868113094
** * "WHERE a=?" matches 10 rows, and
112869113095
** * "WHERE a=? AND b=?" matches 2 rows.
112870113096
**
112871113097
** If D is the count of distinct values and K is the total number of
112872
- ** rows, then each estimate is computed as:
113098
+ ** rows, then each estimate is usually computed as:
112873113099
**
112874113100
** I = (K+D-1)/D
113101
+ **
113102
+ ** In other words, I is K/D rounded up to the next whole integer.
113103
+ ** However, if I is between 1.0 and 1.1 (in other words if I is
113104
+ ** close to 1.0 but just a little larger) then do not round up but
113105
+ ** instead keep the I value at 1.0.
112875113106
*/
112876113107
sqlite3_str sStat; /* Text of the constructed "stat" line */
112877113108
int i; /* Loop counter */
112878113109
112879113110
sqlite3StrAccumInit(&sStat, 0, 0, 0, (p->nKeyCol+1)*100);
@@ -112880,10 +113111,11 @@
112880113111
sqlite3_str_appendf(&sStat, "%llu",
112881113112
p->nSkipAhead ? (u64)p->nEst : (u64)p->nRow);
112882113113
for(i=0; i<p->nKeyCol; i++){
112883113114
u64 nDistinct = p->current.anDLt[i] + 1;
112884113115
u64 iVal = (p->nRow + nDistinct - 1) / nDistinct;
113116
+ if( iVal==2 && p->nRow*10 <= nDistinct*11 ) iVal = 1;
112885113117
sqlite3_str_appendf(&sStat, " %llu", iVal);
112886113118
assert( p->current.anEq[i] );
112887113119
}
112888113120
sqlite3ResultStrAccum(context, &sStat);
112889113121
}
@@ -115001,13 +115233,11 @@
115001115233
Returning *pReturning = pParse->u1.pReturning;
115002115234
int addrRewind;
115003115235
int i;
115004115236
int reg;
115005115237
115006
- if( NEVER(pReturning->nRetCol==0) ){
115007
- assert( CORRUPT_DB );
115008
- }else{
115238
+ if( pReturning->nRetCol ){
115009115239
sqlite3VdbeAddOp0(v, OP_FkCheck);
115010115240
addrRewind =
115011115241
sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur);
115012115242
VdbeCoverage(v);
115013115243
reg = pReturning->iRetReg;
@@ -115099,13 +115329,11 @@
115099115329
}
115100115330
}
115101115331
115102115332
if( pParse->bReturning ){
115103115333
Returning *pRet = pParse->u1.pReturning;
115104
- if( NEVER(pRet->nRetCol==0) ){
115105
- assert( CORRUPT_DB );
115106
- }else{
115334
+ if( pRet->nRetCol ){
115107115335
sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
115108115336
}
115109115337
}
115110115338
115111115339
/* Finally, jump back to the beginning of the executable code. */
@@ -116723,11 +116951,11 @@
116723116951
}
116724116952
pTab->iPKey = iCol;
116725116953
pTab->keyConf = (u8)onError;
116726116954
assert( autoInc==0 || autoInc==1 );
116727116955
pTab->tabFlags |= autoInc*TF_Autoincrement;
116728
- if( pList ) pParse->iPkSortOrder = pList->a[0].sortFlags;
116956
+ if( pList ) pParse->iPkSortOrder = pList->a[0].fg.sortFlags;
116729116957
(void)sqlite3HasExplicitNulls(pParse, pList);
116730116958
}else if( autoInc ){
116731116959
#ifndef SQLITE_OMIT_AUTOINCREMENT
116732116960
sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an "
116733116961
"INTEGER PRIMARY KEY");
@@ -117217,11 +117445,11 @@
117217117445
return;
117218117446
}
117219117447
if( IN_RENAME_OBJECT ){
117220117448
sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey);
117221117449
}
117222
- pList->a[0].sortFlags = pParse->iPkSortOrder;
117450
+ pList->a[0].fg.sortFlags = pParse->iPkSortOrder;
117223117451
assert( pParse->pNewTable==pTab );
117224117452
pTab->iPKey = -1;
117225117453
sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
117226117454
SQLITE_IDXTYPE_PRIMARYKEY);
117227117455
if( pParse->nErr ){
@@ -117888,11 +118116,10 @@
117888118116
*/
117889118117
SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
117890118118
Table *pSelTab; /* A fake table from which we get the result set */
117891118119
Select *pSel; /* Copy of the SELECT that implements the view */
117892118120
int nErr = 0; /* Number of errors encountered */
117893
- int n; /* Temporarily holds the number of cursors assigned */
117894118121
sqlite3 *db = pParse->db; /* Database connection for malloc errors */
117895118122
#ifndef SQLITE_OMIT_VIRTUALTABLE
117896118123
int rc;
117897118124
#endif
117898118125
#ifndef SQLITE_OMIT_AUTHORIZATION
@@ -117946,12 +118173,13 @@
117946118173
*/
117947118174
assert( IsView(pTable) );
117948118175
pSel = sqlite3SelectDup(db, pTable->u.view.pSelect, 0);
117949118176
if( pSel ){
117950118177
u8 eParseMode = pParse->eParseMode;
118178
+ int nTab = pParse->nTab;
118179
+ int nSelect = pParse->nSelect;
117951118180
pParse->eParseMode = PARSE_MODE_NORMAL;
117952
- n = pParse->nTab;
117953118181
sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
117954118182
pTable->nCol = -1;
117955118183
DisableLookaside;
117956118184
#ifndef SQLITE_OMIT_AUTHORIZATION
117957118185
xAuth = db->xAuth;
@@ -117959,11 +118187,12 @@
117959118187
pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, SQLITE_AFF_NONE);
117960118188
db->xAuth = xAuth;
117961118189
#else
117962118190
pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, SQLITE_AFF_NONE);
117963118191
#endif
117964
- pParse->nTab = n;
118192
+ pParse->nTab = nTab;
118193
+ pParse->nSelect = nSelect;
117965118194
if( pSelTab==0 ){
117966118195
pTable->nCol = 0;
117967118196
nErr++;
117968118197
}else if( pTable->pCheck ){
117969118198
/* CREATE VIEW name(arglist) AS ...
@@ -118704,12 +118933,12 @@
118704118933
*/
118705118934
SQLITE_PRIVATE int sqlite3HasExplicitNulls(Parse *pParse, ExprList *pList){
118706118935
if( pList ){
118707118936
int i;
118708118937
for(i=0; i<pList->nExpr; i++){
118709
- if( pList->a[i].bNulls ){
118710
- u8 sf = pList->a[i].sortFlags;
118938
+ if( pList->a[i].fg.bNulls ){
118939
+ u8 sf = pList->a[i].fg.sortFlags;
118711118940
sqlite3ErrorMsg(pParse, "unsupported use of NULLS %s",
118712118941
(sf==0 || sf==3) ? "FIRST" : "LAST"
118713118942
);
118714118943
return 1;
118715118944
}
@@ -119058,11 +119287,11 @@
119058119287
if( !zColl ) zColl = sqlite3StrBINARY;
119059119288
if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
119060119289
goto exit_create_index;
119061119290
}
119062119291
pIndex->azColl[i] = zColl;
119063
- requestedSortOrder = pListItem->sortFlags & sortOrderMask;
119292
+ requestedSortOrder = pListItem->fg.sortFlags & sortOrderMask;
119064119293
pIndex->aSortOrder[i] = (u8)requestedSortOrder;
119065119294
}
119066119295
119067119296
/* Append the table key to the end of the index. For WITHOUT ROWID
119068119297
** tables (when pPk!=0) this will be the declared PRIMARY KEY. For
@@ -124139,15 +124368,15 @@
124139124368
}else{
124140124369
ans = log(x);
124141124370
switch( SQLITE_PTR_TO_INT(sqlite3_user_data(context)) ){
124142124371
case 1:
124143124372
/* Convert from natural logarithm to log base 10 */
124144
- ans *= 1.0/M_LN10;
124373
+ ans /= M_LN10;
124145124374
break;
124146124375
case 2:
124147124376
/* Convert from natural logarithm to log base 2 */
124148
- ans *= 1.0/M_LN2;
124377
+ ans /= M_LN2;
124149124378
break;
124150124379
default:
124151124380
break;
124152124381
}
124153124382
}
@@ -124282,12 +124511,11 @@
124282124511
#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
124283124512
INLINE_FUNC(unlikely, 1, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY),
124284124513
INLINE_FUNC(likelihood, 2, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY),
124285124514
INLINE_FUNC(likely, 1, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY),
124286124515
#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
124287
- {1, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_OFFSET|SQLITE_FUNC_TYPEOF,
124288
- 0, 0, noopFunc, 0, 0, 0, "sqlite_offset", {0} },
124516
+ INLINE_FUNC(sqlite_offset, 1, INLINEFUNC_sqlite_offset, 0 ),
124289124517
#endif
124290124518
FUNCTION(ltrim, 1, 1, 0, trimFunc ),
124291124519
FUNCTION(ltrim, 2, 1, 0, trimFunc ),
124292124520
FUNCTION(rtrim, 1, 2, 0, trimFunc ),
124293124521
FUNCTION(rtrim, 2, 2, 0, trimFunc ),
@@ -129567,10 +129795,11 @@
129567129795
/* Version 3.39.0 and later */
129568129796
int (*deserialize)(sqlite3*,const char*,unsigned char*,
129569129797
sqlite3_int64,sqlite3_int64,unsigned);
129570129798
unsigned char *(*serialize)(sqlite3*,const char *,sqlite3_int64*,
129571129799
unsigned int);
129800
+ const char *(*db_name)(sqlite3*,int);
129572129801
};
129573129802
129574129803
/*
129575129804
** This is the function signature used for all extension entry points. It
129576129805
** is also defined in the file "loadext.c".
@@ -129885,14 +130114,16 @@
129885130114
#define sqlite3_vtab_rhs_value sqlite3_api->vtab_rhs_value
129886130115
#define sqlite3_vtab_distinct sqlite3_api->vtab_distinct
129887130116
#define sqlite3_vtab_in sqlite3_api->vtab_in
129888130117
#define sqlite3_vtab_in_first sqlite3_api->vtab_in_first
129889130118
#define sqlite3_vtab_in_next sqlite3_api->vtab_in_next
130119
+/* Version 3.39.0 and later */
129890130120
#ifndef SQLITE_OMIT_DESERIALIZE
129891130121
#define sqlite3_deserialize sqlite3_api->deserialize
129892130122
#define sqlite3_serialize sqlite3_api->serialize
129893130123
#endif
130124
+#define sqlite3_db_name sqlite3_api->db_name
129894130125
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
129895130126
129896130127
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
129897130128
/* This case when the file really is being compiled as a loadable
129898130129
** extension */
@@ -130380,23 +130611,32 @@
130380130611
sqlite3_total_changes64,
130381130612
/* Version 3.37.0 and later */
130382130613
sqlite3_autovacuum_pages,
130383130614
/* Version 3.38.0 and later */
130384130615
sqlite3_error_offset,
130616
+#ifndef SQLITE_OMIT_VIRTUALTABLE
130385130617
sqlite3_vtab_rhs_value,
130386130618
sqlite3_vtab_distinct,
130387130619
sqlite3_vtab_in,
130388130620
sqlite3_vtab_in_first,
130389130621
sqlite3_vtab_in_next,
130622
+#else
130623
+ 0,
130624
+ 0,
130625
+ 0,
130626
+ 0,
130627
+ 0,
130628
+#endif
130390130629
/* Version 3.39.0 and later */
130391130630
#ifndef SQLITE_OMIT_DESERIALIZE
130392130631
sqlite3_deserialize,
130393
- sqlite3_serialize
130632
+ sqlite3_serialize,
130394130633
#else
130634
+ 0,
130395130635
0,
130396
- 0
130397130636
#endif
130637
+ sqlite3_db_name
130398130638
};
130399130639
130400130640
/* True if x is the directory separator character
130401130641
*/
130402130642
#if SQLITE_OS_WIN
@@ -134828,10 +135068,18 @@
134828135068
db->pParse = pParse;
134829135069
pParse->db = db;
134830135070
if( db->mallocFailed ) sqlite3ErrorMsg(pParse, "out of memory");
134831135071
}
134832135072
135073
+/*
135074
+** Maximum number of times that we will try again to prepare a statement
135075
+** that returns SQLITE_ERROR_RETRY.
135076
+*/
135077
+#ifndef SQLITE_MAX_PREPARE_RETRY
135078
+# define SQLITE_MAX_PREPARE_RETRY 25
135079
+#endif
135080
+
134833135081
/*
134834135082
** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
134835135083
*/
134836135084
static int sqlite3Prepare(
134837135085
sqlite3 *db, /* Database handle. */
@@ -135002,11 +135250,11 @@
135002135250
** or encounters a permanent error. A schema problem after one schema
135003135251
** reset is considered a permanent error. */
135004135252
rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail);
135005135253
assert( rc==SQLITE_OK || *ppStmt==0 );
135006135254
if( rc==SQLITE_OK || db->mallocFailed ) break;
135007
- }while( rc==SQLITE_ERROR_RETRY
135255
+ }while( (rc==SQLITE_ERROR_RETRY && (cnt++)<SQLITE_MAX_PREPARE_RETRY)
135008135256
|| (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) );
135009135257
sqlite3BtreeLeaveAll(db);
135010135258
rc = sqlite3ApiExit(db, rc);
135011135259
assert( (rc&db->errMask)==rc );
135012135260
db->busyHandler.nBusy = 0;
@@ -135553,11 +135801,11 @@
135553135801
ExprList *pResults;
135554135802
assert( pItem->pSelect!=0 );
135555135803
pResults = pItem->pSelect->pEList;
135556135804
assert( pResults!=0 );
135557135805
assert( iCol>=0 && iCol<pResults->nExpr );
135558
- pResults->a[iCol].bUsed = 1;
135806
+ pResults->a[iCol].fg.bUsed = 1;
135559135807
}
135560135808
}
135561135809
135562135810
/*
135563135811
** Search the tables iStart..iEnd (inclusive) in pSrc, looking for a
@@ -135600,15 +135848,15 @@
135600135848
}
135601135849
return 0;
135602135850
}
135603135851
135604135852
/*
135605
-** Set the EP_FromJoin property on all terms of the given expression.
135853
+** Set the EP_OuterON property on all terms of the given expression.
135606135854
** And set the Expr.w.iJoin to iTable for every term in the
135607135855
** expression.
135608135856
**
135609
-** The EP_FromJoin property is used on terms of an expression to tell
135857
+** The EP_OuterON property is used on terms of an expression to tell
135610135858
** the OUTER JOIN processing logic that this term is part of the
135611135859
** join restriction specified in the ON or USING clause and not a part
135612135860
** of the more general WHERE clause. These terms are moved over to the
135613135861
** WHERE clause during join processing but we need to remember that they
135614135862
** originated in the ON or USING clause.
@@ -135626,11 +135874,11 @@
135626135874
** defer the handling of t1.x=5, it will be processed immediately
135627135875
** after the t1 loop and rows with t1.x!=5 will never appear in
135628135876
** the output, which is incorrect.
135629135877
*/
135630135878
SQLITE_PRIVATE void sqlite3SetJoinExpr(Expr *p, int iTable, u32 joinFlag){
135631
- assert( joinFlag==EP_FromJoin || joinFlag==EP_InnerJoin );
135879
+ assert( joinFlag==EP_OuterON || joinFlag==EP_InnerON );
135632135880
while( p ){
135633135881
ExprSetProperty(p, joinFlag);
135634135882
assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
135635135883
ExprSetVVAProperty(p, EP_NoReduce);
135636135884
p->w.iJoin = iTable;
@@ -135647,21 +135895,21 @@
135647135895
p = p->pRight;
135648135896
}
135649135897
}
135650135898
135651135899
/* Undo the work of sqlite3SetJoinExpr(). In the expression p, convert every
135652
-** term that is marked with EP_FromJoin and w.iJoin==iTable into
135653
-** an ordinary term that omits the EP_FromJoin mark.
135900
+** term that is marked with EP_OuterON and w.iJoin==iTable into
135901
+** an ordinary term that omits the EP_OuterON mark.
135654135902
**
135655135903
** This happens when a LEFT JOIN is simplified into an ordinary JOIN.
135656135904
*/
135657135905
static void unsetJoinExpr(Expr *p, int iTable){
135658135906
while( p ){
135659
- if( ExprHasProperty(p, EP_FromJoin)
135907
+ if( ExprHasProperty(p, EP_OuterON)
135660135908
&& (iTable<0 || p->w.iJoin==iTable) ){
135661
- ExprClearProperty(p, EP_FromJoin);
135662
- ExprSetProperty(p, EP_InnerJoin);
135909
+ ExprClearProperty(p, EP_OuterON);
135910
+ ExprSetProperty(p, EP_InnerON);
135663135911
}
135664135912
if( p->op==TK_COLUMN && p->iTable==iTable ){
135665135913
ExprClearProperty(p, EP_CanBeNull);
135666135914
}
135667135915
if( p->op==TK_FUNCTION ){
@@ -135685,12 +135933,12 @@
135685135933
** do not need to be concerned with NATURAL joins and we only have
135686135934
** think about USING joins.
135687135935
**
135688135936
** * ON and USING clauses result in extra terms being added to the
135689135937
** WHERE clause to enforce the specified constraints. The extra
135690
-** WHERE clause terms will be tagged with EP_FromJoin or
135691
-** EP_InnerJoin so that we know that they originated in ON/USING.
135938
+** WHERE clause terms will be tagged with EP_OuterON or
135939
+** EP_InnerON so that we know that they originated in ON/USING.
135692135940
**
135693135941
** The terms of a FROM clause are contained in the Select.pSrc structure.
135694135942
** The left most table is the first entry in Select.pSrc. The right-most
135695135943
** table is the last entry. The join operator is held in the entry to
135696135944
** the right. Thus entry 1 contains the join operator for the join between
@@ -135711,11 +135959,11 @@
135711135959
for(i=0; i<pSrc->nSrc-1; i++, pRight++, pLeft++){
135712135960
Table *pRightTab = pRight->pTab;
135713135961
u32 joinType;
135714135962
135715135963
if( NEVER(pLeft->pTab==0 || pRightTab==0) ) continue;
135716
- joinType = (pRight->fg.jointype & JT_OUTER)!=0 ? EP_FromJoin : EP_InnerJoin;
135964
+ joinType = (pRight->fg.jointype & JT_OUTER)!=0 ? EP_OuterON : EP_InnerON;
135717135965
135718135966
/* If this is a NATURAL join, synthesize an approprate USING clause
135719135967
** to specify which columns should be joined.
135720135968
*/
135721135969
if( pRight->fg.jointype & JT_NATURAL ){
@@ -136221,11 +136469,11 @@
136221136469
** the row from table t1 is stored instead. Then, as records are extracted from
136222136470
** the sorter to return to the user, the required value of bigblob is
136223136471
** retrieved directly from table t1. If the values are very large, this
136224136472
** can be more efficient than storing them directly in the sorter records.
136225136473
**
136226
-** The ExprList_item.bSorterRef flag is set for each expression in pEList
136474
+** The ExprList_item.fg.bSorterRef flag is set for each expression in pEList
136227136475
** for which the sorter-reference optimization should be enabled.
136228136476
** Additionally, the pSort->aDefer[] array is populated with entries
136229136477
** for all cursors required to evaluate all selected expressions. Finally.
136230136478
** output variable (*ppExtra) is set to an expression list containing
136231136479
** expressions for all extra PK values that should be stored in the
@@ -136281,11 +136529,11 @@
136281136529
pSort->aDefer[nDefer].iCsr = pExpr->iTable;
136282136530
pSort->aDefer[nDefer].nKey = nKey;
136283136531
nDefer++;
136284136532
}
136285136533
}
136286
- pItem->bSorterRef = 1;
136534
+ pItem->fg.bSorterRef = 1;
136287136535
}
136288136536
}
136289136537
}
136290136538
pSort->nDefer = (u8)nDefer;
136291136539
*ppExtra = pExtra;
@@ -136412,11 +136660,11 @@
136412136660
** from the sorter by the optimizations in this branch */
136413136661
pEList = p->pEList;
136414136662
for(i=0; i<pEList->nExpr; i++){
136415136663
if( pEList->a[i].u.x.iOrderByCol>0
136416136664
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
136417
- || pEList->a[i].bSorterRef
136665
+ || pEList->a[i].fg.bSorterRef
136418136666
#endif
136419136667
){
136420136668
nResultCol--;
136421136669
regOrig = 0;
136422136670
}
@@ -136774,11 +137022,11 @@
136774137022
pInfo = sqlite3KeyInfoAlloc(db, nExpr-iStart, nExtra+1);
136775137023
if( pInfo ){
136776137024
assert( sqlite3KeyInfoIsWriteable(pInfo) );
136777137025
for(i=iStart, pItem=pList->a+iStart; i<nExpr; i++, pItem++){
136778137026
pInfo->aColl[i-iStart] = sqlite3ExprNNCollSeq(pParse, pItem->pExpr);
136779
- pInfo->aSortFlags[i-iStart] = pItem->sortFlags;
137027
+ pInfo->aSortFlags[i-iStart] = pItem->fg.sortFlags;
136780137028
}
136781137029
}
136782137030
return pInfo;
136783137031
}
136784137032
@@ -136913,11 +137161,11 @@
136913137161
iSortTab = iTab;
136914137162
bSeq = 1;
136915137163
}
136916137164
for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){
136917137165
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
136918
- if( aOutEx[i].bSorterRef ) continue;
137166
+ if( aOutEx[i].fg.bSorterRef ) continue;
136919137167
#endif
136920137168
if( aOutEx[i].u.x.iOrderByCol==0 ) iCol++;
136921137169
}
136922137170
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
136923137171
if( pSort->nDefer ){
@@ -136950,11 +137198,11 @@
136950137198
sqlite3ReleaseTempRange(pParse, regKey, nRefKey);
136951137199
}
136952137200
#endif
136953137201
for(i=nColumn-1; i>=0; i--){
136954137202
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
136955
- if( aOutEx[i].bSorterRef ){
137203
+ if( aOutEx[i].fg.bSorterRef ){
136956137204
sqlite3ExprCode(pParse, aOutEx[i].pExpr, regRow+i);
136957137205
}else
136958137206
#endif
136959137207
{
136960137208
int iRead;
@@ -137316,11 +137564,11 @@
137316137564
137317137565
assert( p!=0 );
137318137566
assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */
137319137567
assert( p->op!=TK_COLUMN
137320137568
|| (ExprUseYTab(p) && p->y.pTab!=0) ); /* Covering idx not yet coded */
137321
- if( pEList->a[i].zEName && pEList->a[i].eEName==ENAME_NAME ){
137569
+ if( pEList->a[i].zEName && pEList->a[i].fg.eEName==ENAME_NAME ){
137322137570
/* An AS clause always takes first priority */
137323137571
char *zName = pEList->a[i].zEName;
137324137572
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
137325137573
}else if( srcName && p->op==TK_COLUMN ){
137326137574
char *zCol;
@@ -137402,26 +137650,28 @@
137402137650
*pnCol = nCol;
137403137651
*paCol = aCol;
137404137652
137405137653
for(i=0, pCol=aCol; i<nCol && !db->mallocFailed; i++, pCol++){
137406137654
struct ExprList_item *pX = &pEList->a[i];
137655
+ struct ExprList_item *pCollide;
137407137656
/* Get an appropriate name for the column
137408137657
*/
137409
- if( (zName = pX->zEName)!=0 && pX->eEName==ENAME_NAME ){
137658
+ if( (zName = pX->zEName)!=0 && pX->fg.eEName==ENAME_NAME ){
137410137659
/* If the column contains an "AS <name>" phrase, use <name> as the name */
137411137660
}else{
137412137661
Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pX->pExpr);
137413137662
while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){
137414137663
pColExpr = pColExpr->pRight;
137415137664
assert( pColExpr!=0 );
137416137665
}
137417137666
if( pColExpr->op==TK_COLUMN
137418137667
&& ALWAYS( ExprUseYTab(pColExpr) )
137419
- && (pTab = pColExpr->y.pTab)!=0
137668
+ && ALWAYS( pColExpr->y.pTab!=0 )
137420137669
){
137421137670
/* For columns use the column name name */
137422137671
int iCol = pColExpr->iColumn;
137672
+ pTab = pColExpr->y.pTab;
137423137673
if( iCol<0 ) iCol = pTab->iPKey;
137424137674
zName = iCol>=0 ? pTab->aCol[iCol].zCnName : "rowid";
137425137675
}else if( pColExpr->op==TK_ID ){
137426137676
assert( !ExprHasProperty(pColExpr, EP_IntValue) );
137427137677
zName = pColExpr->u.zToken;
@@ -137438,11 +137688,14 @@
137438137688
137439137689
/* Make sure the column name is unique. If the name is not unique,
137440137690
** append an integer to the name so that it becomes unique.
137441137691
*/
137442137692
cnt = 0;
137443
- while( zName && sqlite3HashFind(&ht, zName)!=0 ){
137693
+ while( zName && (pCollide = sqlite3HashFind(&ht, zName))!=0 ){
137694
+ if( pCollide->fg.bUsingTerm ){
137695
+ pCol->colFlags |= COLFLAG_NOEXPAND;
137696
+ }
137444137697
nName = sqlite3Strlen30(zName);
137445137698
if( nName>0 ){
137446137699
for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){}
137447137700
if( zName[j]==':' ) nName = j;
137448137701
}
@@ -137449,12 +137702,15 @@
137449137702
zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt);
137450137703
if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt);
137451137704
}
137452137705
pCol->zCnName = zName;
137453137706
pCol->hName = sqlite3StrIHash(zName);
137707
+ if( pX->fg.bNoExpand ){
137708
+ pCol->colFlags |= COLFLAG_NOEXPAND;
137709
+ }
137454137710
sqlite3ColumnPropertiesFromName(0, pCol);
137455
- if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){
137711
+ if( zName && sqlite3HashInsert(&ht, zName, pX)==pX ){
137456137712
sqlite3OomFault(db);
137457137713
}
137458137714
}
137459137715
sqlite3HashClear(&ht);
137460137716
if( db->mallocFailed ){
@@ -137707,11 +137963,11 @@
137707137963
pOrderBy->a[i].pExpr =
137708137964
sqlite3ExprAddCollateString(pParse, pTerm, pColl->zName);
137709137965
}
137710137966
assert( sqlite3KeyInfoIsWriteable(pRet) );
137711137967
pRet->aColl[i] = pColl;
137712
- pRet->aSortFlags[i] = pOrderBy->a[i].sortFlags;
137968
+ pRet->aSortFlags[i] = pOrderBy->a[i].fg.sortFlags;
137713137969
}
137714137970
}
137715137971
137716137972
return pRet;
137717137973
}
@@ -138977,11 +139233,11 @@
138977139233
static Expr *substExpr(
138978139234
SubstContext *pSubst, /* Description of the substitution */
138979139235
Expr *pExpr /* Expr in which substitution occurs */
138980139236
){
138981139237
if( pExpr==0 ) return 0;
138982
- if( ExprHasProperty(pExpr, EP_FromJoin)
139238
+ if( ExprHasProperty(pExpr, EP_OuterON)
138983139239
&& pExpr->w.iJoin==pSubst->iTable
138984139240
){
138985139241
pExpr->w.iJoin = pSubst->iNewTable;
138986139242
}
138987139243
if( pExpr->op==TK_COLUMN
@@ -139018,16 +139274,21 @@
139018139274
return pExpr;
139019139275
}
139020139276
if( pSubst->isOuterJoin ){
139021139277
ExprSetProperty(pNew, EP_CanBeNull);
139022139278
}
139023
- if( ExprHasProperty(pExpr,EP_FromJoin|EP_InnerJoin) ){
139279
+ if( ExprHasProperty(pExpr,EP_OuterON|EP_InnerON) ){
139024139280
sqlite3SetJoinExpr(pNew, pExpr->w.iJoin,
139025
- pExpr->flags & (EP_FromJoin|EP_InnerJoin));
139281
+ pExpr->flags & (EP_OuterON|EP_InnerON));
139026139282
}
139027139283
sqlite3ExprDelete(db, pExpr);
139028139284
pExpr = pNew;
139285
+ if( pExpr->op==TK_TRUEFALSE ){
139286
+ pExpr->u.iValue = sqlite3ExprTruthValue(pExpr);
139287
+ pExpr->op = TK_INTEGER;
139288
+ ExprSetProperty(pExpr, EP_IntValue);
139289
+ }
139029139290
139030139291
/* Ensure that the expression now has an implicit collation sequence,
139031139292
** just as it did when it was a column of a view or sub-query. */
139032139293
if( pExpr->op!=TK_COLUMN && pExpr->op!=TK_COLLATE ){
139033139294
CollSeq *pColl = sqlite3ExprCollSeq(pSubst->pParse, pExpr);
@@ -139184,11 +139445,11 @@
139184139445
static int renumberCursorsCb(Walker *pWalker, Expr *pExpr){
139185139446
int op = pExpr->op;
139186139447
if( op==TK_COLUMN || op==TK_IF_NULL_ROW ){
139187139448
renumberCursorDoMapping(pWalker, &pExpr->iTable);
139188139449
}
139189
- if( ExprHasProperty(pExpr, EP_FromJoin) ){
139450
+ if( ExprHasProperty(pExpr, EP_OuterON) ){
139190139451
renumberCursorDoMapping(pWalker, &pExpr->w.iJoin);
139191139452
}
139192139453
return WRC_Continue;
139193139454
}
139194139455
@@ -139375,10 +139636,12 @@
139375139636
** See also (3) for restrictions on LEFT JOIN.
139376139637
**
139377139638
** (27) The subquery may not contain a FULL or RIGHT JOIN unless it
139378139639
** is the first element of the parent query.
139379139640
**
139641
+** (28) The subquery is not a MATERIALIZED CTE.
139642
+**
139380139643
**
139381139644
** In this routine, the "p" parameter is a pointer to the outer query.
139382139645
** The subquery is p->pSrc->a[iFrom]. isAgg is true if the outer query
139383139646
** uses aggregates.
139384139647
**
@@ -139498,10 +139761,13 @@
139498139761
139499139762
assert( pSubSrc->nSrc>0 ); /* True by restriction (7) */
139500139763
if( iFrom>0 && (pSubSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
139501139764
return 0; /* Restriction (27) */
139502139765
}
139766
+ if( pSubitem->fg.isCte && pSubitem->u2.pCteUse->eM10d==M10d_Yes ){
139767
+ return 0; /* (28) */
139768
+ }
139503139769
139504139770
/* Restriction (17): If the sub-query is a compound SELECT, then it must
139505139771
** use only the UNION ALL operator. And none of the simple select queries
139506139772
** that make up the compound SELECT are allowed to be aggregate or distinct
139507139773
** queries.
@@ -139542,10 +139808,11 @@
139542139808
/* Restriction (23) */
139543139809
if( (p->selFlags & SF_Recursive) ) return 0;
139544139810
139545139811
if( pSrc->nSrc>1 ){
139546139812
if( pParse->nSelect>500 ) return 0;
139813
+ if( OptimizationDisabled(db, SQLITE_FlttnUnionAll) ) return 0;
139547139814
aCsrMap = sqlite3DbMallocZero(db, ((i64)pParse->nTab+1)*sizeof(int));
139548139815
if( aCsrMap ) aCsrMap[0] = pParse->nTab;
139549139816
}
139550139817
}
139551139818
@@ -139756,11 +140023,11 @@
139756140023
pSub->pOrderBy = 0;
139757140024
}
139758140025
pWhere = pSub->pWhere;
139759140026
pSub->pWhere = 0;
139760140027
if( isOuterJoin>0 ){
139761
- sqlite3SetJoinExpr(pWhere, iNewParent, EP_FromJoin);
140028
+ sqlite3SetJoinExpr(pWhere, iNewParent, EP_OuterON);
139762140029
}
139763140030
if( pWhere ){
139764140031
if( pParent->pWhere ){
139765140032
pParent->pWhere = sqlite3PExpr(pParse, TK_AND, pWhere, pParent->pWhere);
139766140033
}else{
@@ -139889,11 +140156,11 @@
139889140156
** found, add it to the pConst structure.
139890140157
*/
139891140158
static void findConstInWhere(WhereConst *pConst, Expr *pExpr){
139892140159
Expr *pRight, *pLeft;
139893140160
if( NEVER(pExpr==0) ) return;
139894
- if( ExprHasProperty(pExpr, EP_FromJoin) ) return;
140161
+ if( ExprHasProperty(pExpr, EP_OuterON) ) return;
139895140162
if( pExpr->op==TK_AND ){
139896140163
findConstInWhere(pConst, pExpr->pRight);
139897140164
findConstInWhere(pConst, pExpr->pLeft);
139898140165
return;
139899140166
}
@@ -139925,13 +140192,13 @@
139925140192
int bIgnoreAffBlob
139926140193
){
139927140194
int i;
139928140195
if( pConst->pOomFault[0] ) return WRC_Prune;
139929140196
if( pExpr->op!=TK_COLUMN ) return WRC_Continue;
139930
- if( ExprHasProperty(pExpr, EP_FixedCol|EP_FromJoin) ){
140197
+ if( ExprHasProperty(pExpr, EP_FixedCol|EP_OuterON) ){
139931140198
testcase( ExprHasProperty(pExpr, EP_FixedCol) );
139932
- testcase( ExprHasProperty(pExpr, EP_FromJoin) );
140199
+ testcase( ExprHasProperty(pExpr, EP_OuterON) );
139933140200
return WRC_Continue;
139934140201
}
139935140202
for(i=0; i<pConst->nConst; i++){
139936140203
Expr *pColumn = pConst->apExpr[i*2];
139937140204
if( pColumn==pExpr ) continue;
@@ -140170,17 +140437,17 @@
140170140437
*/
140171140438
static int pushDownWhereTerms(
140172140439
Parse *pParse, /* Parse context (for malloc() and error reporting) */
140173140440
Select *pSubq, /* The subquery whose WHERE clause is to be augmented */
140174140441
Expr *pWhere, /* The WHERE clause of the outer query */
140175
- int iCursor, /* Cursor number of the subquery */
140176
- int isLeftJoin /* True if pSubq is the right term of a LEFT JOIN */
140442
+ SrcItem *pSrc /* The subquery term of the outer FROM clause */
140177140443
){
140178140444
Expr *pNew;
140179140445
int nChng = 0;
140180140446
if( pWhere==0 ) return 0;
140181140447
if( pSubq->selFlags & (SF_Recursive|SF_MultiPart) ) return 0;
140448
+ if( pSrc->fg.jointype & (JT_LTORJ|JT_RIGHT) ) return 0;
140182140449
140183140450
#ifndef SQLITE_OMIT_WINDOWFUNC
140184140451
if( pSubq->pPrior ){
140185140452
Select *pSel;
140186140453
for(pSel=pSubq; pSel; pSel=pSel->pPrior){
@@ -140206,35 +140473,38 @@
140206140473
140207140474
if( pSubq->pLimit!=0 ){
140208140475
return 0; /* restriction (3) */
140209140476
}
140210140477
while( pWhere->op==TK_AND ){
140211
- nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight,
140212
- iCursor, isLeftJoin);
140478
+ nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, pSrc);
140213140479
pWhere = pWhere->pLeft;
140214140480
}
140481
+
140482
+#if 0 /* Legacy code. Checks now done by sqlite3ExprIsTableConstraint() */
140215140483
if( isLeftJoin
140216
- && (ExprHasProperty(pWhere,EP_FromJoin)==0
140484
+ && (ExprHasProperty(pWhere,EP_OuterON)==0
140217140485
|| pWhere->w.iJoin!=iCursor)
140218140486
){
140219140487
return 0; /* restriction (4) */
140220140488
}
140221
- if( ExprHasProperty(pWhere,EP_FromJoin)
140489
+ if( ExprHasProperty(pWhere,EP_OuterON)
140222140490
&& pWhere->w.iJoin!=iCursor
140223140491
){
140224140492
return 0; /* restriction (5) */
140225140493
}
140226
- if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
140494
+#endif
140495
+
140496
+ if( sqlite3ExprIsTableConstraint(pWhere, pSrc) ){
140227140497
nChng++;
140228140498
pSubq->selFlags |= SF_PushDown;
140229140499
while( pSubq ){
140230140500
SubstContext x;
140231140501
pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
140232140502
unsetJoinExpr(pNew, -1);
140233140503
x.pParse = pParse;
140234
- x.iTable = iCursor;
140235
- x.iNewTable = iCursor;
140504
+ x.iTable = pSrc->iCursor;
140505
+ x.iNewTable = pSrc->iCursor;
140236140506
x.isOuterJoin = 0;
140237140507
x.pEList = pSubq->pEList;
140238140508
pNew = substExpr(&x, pNew);
140239140509
#ifndef SQLITE_OMIT_WINDOWFUNC
140240140510
if( pSubq->pWin && 0==pushDownWindowCheck(pParse, pSubq, pNew) ){
@@ -140304,11 +140574,11 @@
140304140574
}else{
140305140575
return eRet;
140306140576
}
140307140577
*ppMinMax = pOrderBy = sqlite3ExprListDup(db, pEList, 0);
140308140578
assert( pOrderBy!=0 || db->mallocFailed );
140309
- if( pOrderBy ) pOrderBy->a[0].sortFlags = sortFlags;
140579
+ if( pOrderBy ) pOrderBy->a[0].fg.sortFlags = sortFlags;
140310140580
return eRet;
140311140581
}
140312140582
140313140583
/*
140314140584
** The select statement passed as the first argument is an aggregate query.
@@ -140773,11 +141043,11 @@
140773141043
if( pTab==0 ) return SQLITE_NOMEM;
140774141044
pTab->nTabRef = 1;
140775141045
if( pFrom->zAlias ){
140776141046
pTab->zName = sqlite3DbStrDup(pParse->db, pFrom->zAlias);
140777141047
}else{
140778
- pTab->zName = sqlite3MPrintf(pParse->db, "subquery_%u", pSel->selId);
141048
+ pTab->zName = sqlite3MPrintf(pParse->db, "%!S", pFrom);
140779141049
}
140780141050
while( pSel->pPrior ){ pSel = pSel->pPrior; }
140781141051
sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol);
140782141052
pTab->iPKey = -1;
140783141053
pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
@@ -141011,11 +141281,11 @@
141011141281
/* This particular expression does not need to be expanded.
141012141282
*/
141013141283
pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr);
141014141284
if( pNew ){
141015141285
pNew->a[pNew->nExpr-1].zEName = a[k].zEName;
141016
- pNew->a[pNew->nExpr-1].eEName = a[k].eEName;
141286
+ pNew->a[pNew->nExpr-1].fg.eEName = a[k].fg.eEName;
141017141287
a[k].zEName = 0;
141018141288
}
141019141289
a[k].pExpr = 0;
141020141290
}else{
141021141291
/* This expression is a "*" or a "TABLE.*" and needs to be
@@ -141026,39 +141296,64 @@
141026141296
assert( pE->pLeft!=0 );
141027141297
assert( !ExprHasProperty(pE->pLeft, EP_IntValue) );
141028141298
zTName = pE->pLeft->u.zToken;
141029141299
}
141030141300
for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
141031
- Table *pTab = pFrom->pTab;
141032
- Select *pSub;
141033
- char *zTabName = pFrom->zAlias;
141034
- const char *zSchemaName = 0;
141035
- int iDb;
141036
- if( zTabName==0 ){
141301
+ Table *pTab = pFrom->pTab; /* Table for this data source */
141302
+ ExprList *pNestedFrom; /* Result-set of a nested FROM clause */
141303
+ char *zTabName; /* AS name for this data source */
141304
+ const char *zSchemaName = 0; /* Schema name for this data source */
141305
+ int iDb; /* Schema index for this data src */
141306
+ IdList *pUsing; /* USING clause for pFrom[1] */
141307
+
141308
+ if( (zTabName = pFrom->zAlias)==0 ){
141037141309
zTabName = pTab->zName;
141038141310
}
141039141311
if( db->mallocFailed ) break;
141040141312
assert( pFrom->fg.isNestedFrom == IsNestedFrom(pFrom->pSelect) );
141041141313
if( pFrom->fg.isNestedFrom ){
141042
- pSub = pFrom->pSelect;
141043
- assert( pSub->pEList!=0 );
141044
- assert( pSub->pEList->nExpr==pTab->nCol );
141314
+ assert( pFrom->pSelect!=0 );
141315
+ pNestedFrom = pFrom->pSelect->pEList;
141316
+ assert( pNestedFrom!=0 );
141317
+ assert( pNestedFrom->nExpr==pTab->nCol );
141045141318
}else{
141046
- pSub = 0;
141047141319
if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
141048141320
continue;
141049141321
}
141322
+ pNestedFrom = 0;
141050141323
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
141051141324
zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*";
141325
+ }
141326
+ if( i+1<pTabList->nSrc
141327
+ && pFrom[1].fg.isUsing
141328
+ && (selFlags & SF_NestedFrom)!=0
141329
+ ){
141330
+ int ii;
141331
+ pUsing = pFrom[1].u3.pUsing;
141332
+ for(ii=0; ii<pUsing->nId; ii++){
141333
+ const char *zUName = pUsing->a[ii].zName;
141334
+ pRight = sqlite3Expr(db, TK_ID, zUName);
141335
+ pNew = sqlite3ExprListAppend(pParse, pNew, pRight);
141336
+ if( pNew ){
141337
+ struct ExprList_item *pX = &pNew->a[pNew->nExpr-1];
141338
+ assert( pX->zEName==0 );
141339
+ pX->zEName = sqlite3MPrintf(db,"..%s", zUName);
141340
+ pX->fg.eEName = ENAME_TAB;
141341
+ pX->fg.bUsingTerm = 1;
141342
+ }
141343
+ }
141344
+ }else{
141345
+ pUsing = 0;
141052141346
}
141053141347
for(j=0; j<pTab->nCol; j++){
141054141348
char *zName = pTab->aCol[j].zCnName;
141055141349
struct ExprList_item *pX; /* Newly added ExprList term */
141056141350
141057141351
assert( zName );
141058
- if( zTName && pSub
141059
- && sqlite3MatchEName(&pSub->pEList->a[j], 0, zTName, 0)==0
141352
+ if( zTName
141353
+ && pNestedFrom
141354
+ && sqlite3MatchEName(&pNestedFrom->a[j], 0, zTName, 0)==0
141060141355
){
141061141356
continue;
141062141357
}
141063141358
141064141359
/* If a column is marked as 'hidden', omit it from the expanded
@@ -141067,14 +141362,20 @@
141067141362
*/
141068141363
if( (p->selFlags & SF_IncludeHidden)==0
141069141364
&& IsHiddenColumn(&pTab->aCol[j])
141070141365
){
141071141366
continue;
141367
+ }
141368
+ if( (pTab->aCol[j].colFlags & COLFLAG_NOEXPAND)!=0
141369
+ && zTName==0
141370
+ && (selFlags & (SF_NestedFrom))==0
141371
+ ){
141372
+ continue;
141072141373
}
141073141374
tableSeen = 1;
141074141375
141075
- if( i>0 && zTName==0 ){
141376
+ if( i>0 && zTName==0 && (selFlags & SF_NestedFrom)==0 ){
141076141377
if( pFrom->fg.isUsing
141077141378
&& sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0
141078141379
){
141079141380
/* In a join with a USING clause, omit columns in the
141080141381
** using clause from the table on the right. */
@@ -141082,10 +141383,11 @@
141082141383
}
141083141384
}
141084141385
pRight = sqlite3Expr(db, TK_ID, zName);
141085141386
if( (pTabList->nSrc>1
141086141387
&& ( (pFrom->fg.jointype & JT_LTORJ)==0
141388
+ || (selFlags & SF_NestedFrom)!=0
141087141389
|| !inAnyUsingClause(zName,pFrom,pTabList->nSrc-i-1)
141088141390
)
141089141391
)
141090141392
|| IN_RENAME_OBJECT
141091141393
){
@@ -141107,25 +141409,32 @@
141107141409
break; /* OOM */
141108141410
}
141109141411
pX = &pNew->a[pNew->nExpr-1];
141110141412
assert( pX->zEName==0 );
141111141413
if( (selFlags & SF_NestedFrom)!=0 && !IN_RENAME_OBJECT ){
141112
- if( pSub ){
141113
- pX->zEName = sqlite3DbStrDup(db, pSub->pEList->a[j].zEName);
141414
+ if( pNestedFrom ){
141415
+ pX->zEName = sqlite3DbStrDup(db, pNestedFrom->a[j].zEName);
141114141416
testcase( pX->zEName==0 );
141115141417
}else{
141116141418
pX->zEName = sqlite3MPrintf(db, "%s.%s.%s",
141117141419
zSchemaName, zTabName, zName);
141118141420
testcase( pX->zEName==0 );
141119141421
}
141120
- pX->eEName = ENAME_TAB;
141422
+ pX->fg.eEName = ENAME_TAB;
141423
+ if( (pFrom->fg.isUsing
141424
+ && sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0)
141425
+ || (pUsing && sqlite3IdListIndex(pUsing, zName)>=0)
141426
+ || (pTab->aCol[j].colFlags & COLFLAG_NOEXPAND)!=0
141427
+ ){
141428
+ pX->fg.bNoExpand = 1;
141429
+ }
141121141430
}else if( longNames ){
141122141431
pX->zEName = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
141123
- pX->eEName = ENAME_NAME;
141432
+ pX->fg.eEName = ENAME_NAME;
141124141433
}else{
141125141434
pX->zEName = sqlite3DbStrDup(db, zName);
141126
- pX->eEName = ENAME_NAME;
141435
+ pX->fg.eEName = ENAME_NAME;
141127141436
}
141128141437
}
141129141438
}
141130141439
if( !tableSeen ){
141131141440
if( zTName ){
@@ -141684,10 +141993,33 @@
141684141993
}
141685141994
#endif
141686141995
return 1;
141687141996
}
141688141997
#endif /* SQLITE_COUNTOFVIEW_OPTIMIZATION */
141998
+
141999
+/*
142000
+** If any term of pSrc, or any SF_NestedFrom sub-query, is not the same
142001
+** as pSrcItem but has the same alias as p0, then return true.
142002
+** Otherwise return false.
142003
+*/
142004
+static int sameSrcAlias(SrcItem *p0, SrcList *pSrc){
142005
+ int i;
142006
+ for(i=0; i<pSrc->nSrc; i++){
142007
+ SrcItem *p1 = &pSrc->a[i];
142008
+ if( p1==p0 ) continue;
142009
+ if( p0->pTab==p1->pTab && 0==sqlite3_stricmp(p0->zAlias, p1->zAlias) ){
142010
+ return 1;
142011
+ }
142012
+ if( p1->pSelect
142013
+ && (p1->pSelect->selFlags & SF_NestedFrom)!=0
142014
+ && sameSrcAlias(p0, p1->pSelect->pSrc)
142015
+ ){
142016
+ return 1;
142017
+ }
142018
+ }
142019
+ return 0;
142020
+}
141689142021
141690142022
/*
141691142023
** Generate code for the SELECT statement given in the p argument.
141692142024
**
141693142025
** The results are returned according to the SelectDest structure.
@@ -141789,19 +142121,16 @@
141789142121
** systems handle this case differently, and not all the same way,
141790142122
** which is just confusing. To avoid this, we follow PG's lead and
141791142123
** disallow it altogether. */
141792142124
if( p->selFlags & SF_UFSrcCheck ){
141793142125
SrcItem *p0 = &p->pSrc->a[0];
141794
- for(i=1; i<p->pSrc->nSrc; i++){
141795
- SrcItem *p1 = &p->pSrc->a[i];
141796
- if( p0->pTab==p1->pTab && 0==sqlite3_stricmp(p0->zAlias, p1->zAlias) ){
141797
- sqlite3ErrorMsg(pParse,
141798
- "target object/alias may not appear in FROM clause: %s",
141799
- p0->zAlias ? p0->zAlias : p0->pTab->zName
141800
- );
141801
- goto select_end;
141802
- }
142126
+ if( sameSrcAlias(p0, p->pSrc) ){
142127
+ sqlite3ErrorMsg(pParse,
142128
+ "target object/alias may not appear in FROM clause: %s",
142129
+ p0->zAlias ? p0->zAlias : p0->pTab->zName
142130
+ );
142131
+ goto select_end;
141803142132
}
141804142133
141805142134
/* Clear the SF_UFSrcCheck flag. The check has already been performed,
141806142135
** and leaving this flag set can cause errors if a compound sub-query
141807142136
** in p->pSrc is flattened into this query and this function called
@@ -142053,13 +142382,11 @@
142053142382
** inside the subquery. This can help the subquery to run more efficiently.
142054142383
*/
142055142384
if( OptimizationEnabled(db, SQLITE_PushDown)
142056142385
&& (pItem->fg.isCte==0
142057142386
|| (pItem->u2.pCteUse->eM10d!=M10d_Yes && pItem->u2.pCteUse->nUse<2))
142058
- && (pItem->fg.jointype & JT_RIGHT)==0
142059
- && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem->iCursor,
142060
- (pItem->fg.jointype & JT_OUTER)!=0)
142387
+ && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem)
142061142388
){
142062142389
#if TREETRACE_ENABLED
142063142390
if( sqlite3TreeTrace & 0x100 ){
142064142391
SELECTTRACE(0x100,pParse,p,
142065142392
("After WHERE-clause push-down into subquery %d:\n", pSub->selId));
@@ -142074,11 +142401,11 @@
142074142401
zSavedAuthContext = pParse->zAuthContext;
142075142402
pParse->zAuthContext = pItem->zName;
142076142403
142077142404
/* Generate code to implement the subquery
142078142405
**
142079
- ** The subquery is implemented as a co-routine all of the following are
142406
+ ** The subquery is implemented as a co-routine all if the following are
142080142407
** true:
142081142408
**
142082142409
** (1) the subquery is guaranteed to be the outer loop (so that
142083142410
** it does not need to be computed more than once), and
142084142411
** (2) the subquery is not a CTE that should be materialized
@@ -142132,15 +142459,15 @@
142132142459
/* Materialize the view. If the view is not correlated, generate a
142133142460
** subroutine to do the materialization so that subsequent uses of
142134142461
** the same view can reuse the materialization. */
142135142462
int topAddr;
142136142463
int onceAddr = 0;
142137
- int retAddr;
142138142464
142139142465
pItem->regReturn = ++pParse->nMem;
142140
- topAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pItem->regReturn);
142466
+ topAddr = sqlite3VdbeAddOp0(v, OP_Goto);
142141142467
pItem->addrFillSub = topAddr+1;
142468
+ pItem->fg.isMaterialized = 1;
142142142469
if( pItem->fg.isCorrelated==0 ){
142143142470
/* If the subquery is not correlated and if we are not inside of
142144142471
** a trigger, then we only need to compute the value of the subquery
142145142472
** once. */
142146142473
onceAddr = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
@@ -142151,13 +142478,13 @@
142151142478
sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
142152142479
ExplainQueryPlan((pParse, 1, "MATERIALIZE %!S", pItem));
142153142480
sqlite3Select(pParse, pSub, &dest);
142154142481
pItem->pTab->nRowLogEst = pSub->nSelectRow;
142155142482
if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr);
142156
- retAddr = sqlite3VdbeAddOp1(v, OP_Return, pItem->regReturn);
142483
+ sqlite3VdbeAddOp2(v, OP_Return, pItem->regReturn, topAddr+1);
142157142484
VdbeComment((v, "end %!S", pItem));
142158
- sqlite3VdbeChangeP1(v, topAddr, retAddr);
142485
+ sqlite3VdbeJumpHere(v, topAddr);
142159142486
sqlite3ClearTempRegCache(pParse);
142160142487
if( pItem->fg.isCte && pItem->fg.isCorrelated==0 ){
142161142488
CteUse *pCteUse = pItem->u2.pCteUse;
142162142489
pCteUse->addrM9e = pItem->addrFillSub;
142163142490
pCteUse->regRtn = pItem->regReturn;
@@ -142251,17 +142578,17 @@
142251142578
if( pDest->eDest==SRT_EphemTab ){
142252142579
sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pDest->iSDParm, pEList->nExpr);
142253142580
if( p->selFlags & SF_NestedFrom ){
142254142581
/* Delete or NULL-out result columns that will never be used */
142255142582
int ii;
142256
- for(ii=pEList->nExpr-1; ii>0 && pEList->a[ii].bUsed==0; ii--){
142583
+ for(ii=pEList->nExpr-1; ii>0 && pEList->a[ii].fg.bUsed==0; ii--){
142257142584
sqlite3ExprDelete(db, pEList->a[ii].pExpr);
142258142585
sqlite3DbFree(db, pEList->a[ii].zEName);
142259142586
pEList->nExpr--;
142260142587
}
142261142588
for(ii=0; ii<pEList->nExpr; ii++){
142262
- if( pEList->a[ii].bUsed==0 ) pEList->a[ii].pExpr->op = TK_NULL;
142589
+ if( pEList->a[ii].fg.bUsed==0 ) pEList->a[ii].pExpr->op = TK_NULL;
142263142590
}
142264142591
}
142265142592
}
142266142593
142267142594
/* Set the limiter.
@@ -142409,12 +142736,13 @@
142409142736
** ASC or DESC order - only that each group is returned contiguously.
142410142737
** So set the ASC/DESC flags in the GROUP BY to match those in the
142411142738
** ORDER BY to maximize the chances of rows being delivered in an
142412142739
** order that makes the ORDER BY redundant. */
142413142740
for(ii=0; ii<pGroupBy->nExpr; ii++){
142414
- u8 sortFlags = sSort.pOrderBy->a[ii].sortFlags & KEYINFO_ORDER_DESC;
142415
- pGroupBy->a[ii].sortFlags = sortFlags;
142741
+ u8 sortFlags;
142742
+ sortFlags = sSort.pOrderBy->a[ii].fg.sortFlags & KEYINFO_ORDER_DESC;
142743
+ pGroupBy->a[ii].fg.sortFlags = sortFlags;
142416142744
}
142417142745
if( sqlite3ExprListCompare(pGroupBy, sSort.pOrderBy, -1)==0 ){
142418142746
orderByGrp = 1;
142419142747
}
142420142748
}
@@ -142875,11 +143203,11 @@
142875143203
}
142876143204
SELECTTRACE(1,pParse,p,("WhereBegin returns\n"));
142877143205
eDist = sqlite3WhereIsDistinct(pWInfo);
142878143206
updateAccumulator(pParse, regAcc, pAggInfo, eDist);
142879143207
if( eDist!=WHERE_DISTINCT_NOOP ){
142880
- struct AggInfo_func *pF = &pAggInfo->aFunc[0];
143208
+ struct AggInfo_func *pF = pAggInfo->aFunc;
142881143209
if( pF ){
142882143210
fixDistinctOpenEph(pParse, eDist, pF->iDistinct, pF->iDistAddr);
142883143211
}
142884143212
}
142885143213
@@ -143674,11 +144002,11 @@
143674144002
** sees an UPDATE statement inside the body of a CREATE TRIGGER.
143675144003
*/
143676144004
SQLITE_PRIVATE TriggerStep *sqlite3TriggerUpdateStep(
143677144005
Parse *pParse, /* Parser */
143678144006
Token *pTableName, /* Name of the table to be updated */
143679
- SrcList *pFrom,
144007
+ SrcList *pFrom, /* FROM clause for an UPDATE-FROM, or NULL */
143680144008
ExprList *pEList, /* The SET clause: list of column and new values */
143681144009
Expr *pWhere, /* The WHERE clause */
143682144010
u8 orconf, /* The conflict algorithm. (OE_Abort, OE_Ignore, etc) */
143683144011
const char *zStart, /* Start of SQL text */
143684144012
const char *zEnd /* End of SQL text */
@@ -144010,10 +144338,18 @@
144010144338
if( pSchema!=db->aDb[1].pSchema ){
144011144339
pSrc->a[0].pSchema = pSchema;
144012144340
}
144013144341
if( pStep->pFrom ){
144014144342
SrcList *pDup = sqlite3SrcListDup(db, pStep->pFrom, 0);
144343
+ if( pDup && pDup->nSrc>1 && !IN_RENAME_OBJECT ){
144344
+ Select *pSubquery;
144345
+ Token as;
144346
+ pSubquery = sqlite3SelectNew(pParse,0,pDup,0,0,0,0,SF_NestedFrom,0);
144347
+ as.n = 0;
144348
+ as.z = 0;
144349
+ pDup = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&as,pSubquery,0);
144350
+ }
144015144351
pSrc = sqlite3SrcListAppendList(pParse, pSrc, pDup);
144016144352
}
144017144353
}else{
144018144354
sqlite3DbFree(db, zName);
144019144355
}
@@ -144065,20 +144401,20 @@
144065144401
pNewExpr = sqlite3Expr(db, TK_ID, pTab->aCol[jj].zCnName);
144066144402
pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
144067144403
if( !db->mallocFailed ){
144068144404
struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
144069144405
pItem->zEName = sqlite3DbStrDup(db, pTab->aCol[jj].zCnName);
144070
- pItem->eEName = ENAME_NAME;
144406
+ pItem->fg.eEName = ENAME_NAME;
144071144407
}
144072144408
}
144073144409
}else{
144074144410
Expr *pNewExpr = sqlite3ExprDup(db, pOldExpr, 0);
144075144411
pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
144076144412
if( !db->mallocFailed && ALWAYS(pList->a[i].zEName!=0) ){
144077144413
struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
144078144414
pItem->zEName = sqlite3DbStrDup(db, pList->a[i].zEName);
144079
- pItem->eEName = pList->a[i].eEName;
144415
+ pItem->fg.eEName = pList->a[i].fg.eEName;
144080144416
}
144081144417
}
144082144418
}
144083144419
return pNew;
144084144420
}
@@ -146647,10 +146983,11 @@
146647146983
#endif
146648146984
}
146649146985
146650146986
assert( rc==SQLITE_OK );
146651146987
if( pOut==0 ){
146988
+ nRes = sqlite3BtreeGetRequestedReserve(pTemp);
146652146989
rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1);
146653146990
}
146654146991
146655146992
end_of_vacuum:
146656146993
/* Restore the original value of db->flags */
@@ -148098,11 +148435,11 @@
148098148435
** This object is a header on a block of allocated memory that will be
148099148436
** automatically freed when its WInfo oject is destructed.
148100148437
*/
148101148438
struct WhereMemBlock {
148102148439
WhereMemBlock *pNext; /* Next block in the chain */
148103
- u8 sz; /* Bytes of space */
148440
+ u64 sz; /* Bytes of space */
148104148441
};
148105148442
148106148443
/*
148107148444
** Extra information attached to a WhereLevel that is a RIGHT JOIN.
148108148445
*/
@@ -148109,10 +148446,11 @@
148109148446
struct WhereRightJoin {
148110148447
int iMatch; /* Cursor used to determine prior matched rows */
148111148448
int regBloom; /* Bloom filter for iRJMatch */
148112148449
int regReturn; /* Return register for the interior subroutine */
148113148450
int addrSubrtn; /* Starting address for the interior subroutine */
148451
+ int endSubrtn; /* The last opcode in the interior subroutine */
148114148452
};
148115148453
148116148454
/*
148117148455
** This object contains information needed to implement a single nested
148118148456
** loop in WHERE clause.
@@ -148668,12 +149006,13 @@
148668149006
#define WO_ISNULL 0x0100
148669149007
#define WO_OR 0x0200 /* Two or more OR-connected terms */
148670149008
#define WO_AND 0x0400 /* Two or more AND-connected terms */
148671149009
#define WO_EQUIV 0x0800 /* Of the form A==B, both columns */
148672149010
#define WO_NOOP 0x1000 /* This term does not restrict search space */
149011
+#define WO_ROWVAL 0x2000 /* A row-value term */
148673149012
148674
-#define WO_ALL 0x1fff /* Mask of all possible WO_* values */
149013
+#define WO_ALL 0x3fff /* Mask of all possible WO_* values */
148675149014
#define WO_SINGLE 0x01ff /* Mask of all non-compound WO_* values */
148676149015
148677149016
/*
148678149017
** These are definitions of bits in the WhereLoop.wsFlags field.
148679149018
** The particular combination of bits in each WhereLoop help to
@@ -149039,11 +149378,11 @@
149039149378
*/
149040149379
static void disableTerm(WhereLevel *pLevel, WhereTerm *pTerm){
149041149380
int nLoop = 0;
149042149381
assert( pTerm!=0 );
149043149382
while( (pTerm->wtFlags & TERM_CODED)==0
149044
- && (pLevel->iLeftJoin==0 || ExprHasProperty(pTerm->pExpr, EP_FromJoin))
149383
+ && (pLevel->iLeftJoin==0 || ExprHasProperty(pTerm->pExpr, EP_OuterON))
149045149384
&& (pLevel->notReady & pTerm->prereqAll)==0
149046149385
){
149047149386
if( nLoop && (pTerm->wtFlags & TERM_LIKE)!=0 ){
149048149387
pTerm->wtFlags |= TERM_LIKECOND;
149049149388
}else{
@@ -149300,20 +149639,25 @@
149300149639
149301149640
iTab = 0;
149302149641
if( !ExprUseXSelect(pX) || pX->x.pSelect->pEList->nExpr==1 ){
149303149642
eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
149304149643
}else{
149305
- sqlite3 *db = pParse->db;
149306
- pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
149307
-
149308
- if( !db->mallocFailed ){
149644
+ Expr *pExpr = pTerm->pExpr;
149645
+ if( pExpr->iTable==0 || !ExprHasProperty(pExpr, EP_Subrtn) ){
149646
+ sqlite3 *db = pParse->db;
149647
+ pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
149648
+ if( !db->mallocFailed ){
149649
+ aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq);
149650
+ eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap,&iTab);
149651
+ pExpr->iTable = iTab;
149652
+ }
149653
+ sqlite3ExprDelete(db, pX);
149654
+ }else{
149309149655
aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq);
149310149656
eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap, &iTab);
149311
- pTerm->pExpr->iTable = iTab;
149312149657
}
149313
- sqlite3ExprDelete(db, pX);
149314
- pX = pTerm->pExpr;
149658
+ pX = pExpr;
149315149659
}
149316149660
149317149661
if( eType==IN_INDEX_INDEX_DESC ){
149318149662
testcase( bRev );
149319149663
bRev = !bRev;
@@ -149755,20 +150099,20 @@
149755150099
**
149756150100
** are also excluded. See codeCursorHintIsOrFunction() for details.
149757150101
*/
149758150102
if( pTabItem->fg.jointype & JT_LEFT ){
149759150103
Expr *pExpr = pTerm->pExpr;
149760
- if( !ExprHasProperty(pExpr, EP_FromJoin)
150104
+ if( !ExprHasProperty(pExpr, EP_OuterON)
149761150105
|| pExpr->w.iJoin!=pTabItem->iCursor
149762150106
){
149763150107
sWalker.eCode = 0;
149764150108
sWalker.xExprCallback = codeCursorHintIsOrFunction;
149765150109
sqlite3WalkExpr(&sWalker, pTerm->pExpr);
149766150110
if( sWalker.eCode ) continue;
149767150111
}
149768150112
}else{
149769
- if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) continue;
150113
+ if( ExprHasProperty(pTerm->pExpr, EP_OuterON) ) continue;
149770150114
}
149771150115
149772150116
/* All terms in pWLoop->aLTerm[] except pEndRange are used to initialize
149773150117
** the cursor. These terms are not needed as hints for a pure range
149774150118
** scan (that has no == terms) so omit them. */
@@ -149936,16 +150280,16 @@
149936150280
** that contains the value of pExpr.
149937150281
*/
149938150282
static int whereIndexExprTransNode(Walker *p, Expr *pExpr){
149939150283
IdxExprTrans *pX = p->u.pIdxTrans;
149940150284
if( sqlite3ExprCompare(0, pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){
150285
+ pExpr = sqlite3ExprSkipCollate(pExpr);
149941150286
preserveExpr(pX, pExpr);
149942150287
pExpr->affExpr = sqlite3ExprAffinity(pExpr);
149943150288
pExpr->op = TK_COLUMN;
149944150289
pExpr->iTable = pX->iIdxCur;
149945150290
pExpr->iColumn = pX->iIdxCol;
149946
- testcase( ExprHasProperty(pExpr, EP_Skip) );
149947150291
testcase( ExprHasProperty(pExpr, EP_Unlikely) );
149948150292
ExprClearProperty(pExpr, EP_Skip|EP_Unlikely|EP_WinFunc|EP_Subrtn);
149949150293
pExpr->y.pTab = 0;
149950150294
return WRC_Prune;
149951150295
}else{
@@ -150095,10 +150439,12 @@
150095150439
if( pLevel->regFilter==0 ) continue;
150096150440
if( pLevel->pWLoop->nSkip ) continue;
150097150441
/* ,--- Because sqlite3ConstructBloomFilter() has will not have set
150098150442
** vvvvv--' pLevel->regFilter if this were true. */
150099150443
if( NEVER(pLoop->prereq & notReady) ) continue;
150444
+ assert( pLevel->addrBrk==0 );
150445
+ pLevel->addrBrk = addrNxt;
150100150446
if( pLoop->wsFlags & WHERE_IPK ){
150101150447
WhereTerm *pTerm = pLoop->aLTerm[0];
150102150448
int regRowid;
150103150449
assert( pTerm!=0 );
150104150450
assert( pTerm->pExpr!=0 );
@@ -150121,10 +150467,11 @@
150121150467
sqlite3VdbeAddOp4Int(pParse->pVdbe, OP_Filter, pLevel->regFilter,
150122150468
addrNxt, r1, nEq);
150123150469
VdbeCoverage(pParse->pVdbe);
150124150470
}
150125150471
pLevel->regFilter = 0;
150472
+ pLevel->addrBrk = 0;
150126150473
}
150127150474
}
150128150475
150129150476
/*
150130150477
** Generate code for the start of the iLevel-th loop in the WHERE clause
@@ -151092,11 +151439,11 @@
151092151439
WhereInfo *pSubWInfo; /* Info for single OR-term scan */
151093151440
Expr *pOrExpr = pOrTerm->pExpr; /* Current OR clause term */
151094151441
Expr *pDelete; /* Local copy of OR clause term */
151095151442
int jmp1 = 0; /* Address of jump operation */
151096151443
testcase( (pTabItem[0].fg.jointype & JT_LEFT)!=0
151097
- && !ExprHasProperty(pOrExpr, EP_FromJoin)
151444
+ && !ExprHasProperty(pOrExpr, EP_OuterON)
151098151445
); /* See TH3 vtab25.400 and ticket 614b25314c766238 */
151099151446
pDelete = pOrExpr = sqlite3ExprDup(db, pOrExpr, 0);
151100151447
if( db->mallocFailed ){
151101151448
sqlite3ExprDelete(db, pDelete);
151102151449
continue;
@@ -151300,16 +151647,26 @@
151300151647
pWInfo->untestedTerms = 1;
151301151648
continue;
151302151649
}
151303151650
pE = pTerm->pExpr;
151304151651
assert( pE!=0 );
151305
- if( (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ))
151306
- && !ExprHasProperty(pE,EP_FromJoin)
151307
- ){
151308
- continue;
151652
+ if( pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT) ){
151653
+ if( !ExprHasProperty(pE,EP_OuterON|EP_InnerON) ){
151654
+ /* Defer processing WHERE clause constraints until after outer
151655
+ ** join processing. tag-20220513a */
151656
+ continue;
151657
+ }else if( (pTabItem->fg.jointype & JT_LEFT)==JT_LEFT
151658
+ && !ExprHasProperty(pE,EP_OuterON) ){
151659
+ continue;
151660
+ }else{
151661
+ Bitmask m = sqlite3WhereGetMask(&pWInfo->sMaskSet, pE->w.iJoin);
151662
+ if( m & pLevel->notReady ){
151663
+ /* An ON clause that is not ripe */
151664
+ continue;
151665
+ }
151666
+ }
151309151667
}
151310
-
151311151668
if( iLoop==1 && !sqlite3ExprCoveredByIndex(pE, pLevel->iTabCur, pIdx) ){
151312151669
iNext = 2;
151313151670
continue;
151314151671
}
151315151672
if( iLoop<3 && (pTerm->wtFlags & TERM_VARSELECT) ){
@@ -151364,19 +151721,19 @@
151364151721
WhereTerm *pAlt;
151365151722
if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
151366151723
if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) continue;
151367151724
if( (pTerm->eOperator & WO_EQUIV)==0 ) continue;
151368151725
if( pTerm->leftCursor!=iCur ) continue;
151369
- if( pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ) ) continue;
151726
+ if( pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT) ) continue;
151370151727
pE = pTerm->pExpr;
151371151728
#ifdef WHERETRACE_ENABLED /* 0x800 */
151372151729
if( sqlite3WhereTrace & 0x800 ){
151373151730
sqlite3DebugPrintf("Coding transitive constraint:\n");
151374151731
sqlite3WhereTermPrint(pTerm, pWC->nTerm-j);
151375151732
}
151376151733
#endif
151377
- assert( !ExprHasProperty(pE, EP_FromJoin) );
151734
+ assert( !ExprHasProperty(pE, EP_OuterON) );
151378151735
assert( (pTerm->prereqRight & pLevel->notReady)!=0 );
151379151736
assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
151380151737
pAlt = sqlite3WhereFindTerm(pWC, iCur, pTerm->u.x.leftColumn, notReady,
151381151738
WO_EQ|WO_IN|WO_IS, 0);
151382151739
if( pAlt==0 ) continue;
@@ -151443,22 +151800,12 @@
151443151800
*/
151444151801
if( pLevel->iLeftJoin ){
151445151802
pLevel->addrFirst = sqlite3VdbeCurrentAddr(v);
151446151803
sqlite3VdbeAddOp2(v, OP_Integer, 1, pLevel->iLeftJoin);
151447151804
VdbeComment((v, "record LEFT JOIN hit"));
151448
- for(pTerm=pWC->a, j=0; j<pWC->nBase; j++, pTerm++){
151449
- testcase( pTerm->wtFlags & TERM_VIRTUAL );
151450
- testcase( pTerm->wtFlags & TERM_CODED );
151451
- if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
151452
- if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
151453
- assert( pWInfo->untestedTerms );
151454
- continue;
151455
- }
151456
- if( pTabItem->fg.jointype & JT_LTORJ ) continue;
151457
- assert( pTerm->pExpr );
151458
- sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
151459
- pTerm->wtFlags |= TERM_CODED;
151805
+ if( pLevel->pRJ==0 ){
151806
+ goto code_outer_join_constraints; /* WHERE clause constraints */
151460151807
}
151461151808
}
151462151809
151463151810
if( pLevel->pRJ ){
151464151811
/* Create a subroutine used to process all interior loops and code
@@ -151470,10 +151817,30 @@
151470151817
WhereRightJoin *pRJ = pLevel->pRJ;
151471151818
sqlite3VdbeAddOp2(v, OP_BeginSubrtn, 0, pRJ->regReturn);
151472151819
pRJ->addrSubrtn = sqlite3VdbeCurrentAddr(v);
151473151820
assert( pParse->withinRJSubrtn < 255 );
151474151821
pParse->withinRJSubrtn++;
151822
+
151823
+ /* WHERE clause constraints must be deferred until after outer join
151824
+ ** row elimination has completed, since WHERE clause constraints apply
151825
+ ** to the results of the OUTER JOIN. The following loop generates the
151826
+ ** appropriate WHERE clause constraint checks. tag-20220513a.
151827
+ */
151828
+ code_outer_join_constraints:
151829
+ for(pTerm=pWC->a, j=0; j<pWC->nBase; j++, pTerm++){
151830
+ testcase( pTerm->wtFlags & TERM_VIRTUAL );
151831
+ testcase( pTerm->wtFlags & TERM_CODED );
151832
+ if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
151833
+ if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
151834
+ assert( pWInfo->untestedTerms );
151835
+ continue;
151836
+ }
151837
+ if( pTabItem->fg.jointype & JT_LTORJ ) continue;
151838
+ assert( pTerm->pExpr );
151839
+ sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
151840
+ pTerm->wtFlags |= TERM_CODED;
151841
+ }
151475151842
}
151476151843
151477151844
#if WHERETRACE_ENABLED /* 0x20800 */
151478151845
if( sqlite3WhereTrace & 0x20000 ){
151479151846
sqlite3DebugPrintf("All WHERE-clause terms after coding level %d:\n",
@@ -151508,10 +151875,12 @@
151508151875
SrcList sFrom;
151509151876
Bitmask mAll = 0;
151510151877
int k;
151511151878
151512151879
ExplainQueryPlan((pParse, 1, "RIGHT-JOIN %s", pTabItem->pTab->zName));
151880
+ sqlite3VdbeNoJumpsOutsideSubrtn(v, pRJ->addrSubrtn, pRJ->endSubrtn,
151881
+ pRJ->regReturn);
151513151882
for(k=0; k<iLevel; k++){
151514151883
int iIdxCur;
151515151884
mAll |= pWInfo->a[k].pWLoop->maskSelf;
151516151885
sqlite3VdbeAddOp1(v, OP_NullRow, pWInfo->a[k].iTabCur);
151517151886
iIdxCur = pWInfo->a[k].iIdxCur;
@@ -151521,13 +151890,17 @@
151521151890
}
151522151891
if( (pTabItem->fg.jointype & JT_LTORJ)==0 ){
151523151892
mAll |= pLoop->maskSelf;
151524151893
for(k=0; k<pWC->nTerm; k++){
151525151894
WhereTerm *pTerm = &pWC->a[k];
151526
- if( pTerm->wtFlags & TERM_VIRTUAL ) break;
151895
+ if( (pTerm->wtFlags & (TERM_VIRTUAL|TERM_SLICE))!=0
151896
+ && pTerm->eOperator!=WO_ROWVAL
151897
+ ){
151898
+ break;
151899
+ }
151527151900
if( pTerm->prereqAll & ~mAll ) continue;
151528
- if( ExprHasProperty(pTerm->pExpr, EP_FromJoin|EP_InnerJoin) ) continue;
151901
+ if( ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON) ) continue;
151529151902
pSubWhere = sqlite3ExprAnd(pParse, pSubWhere,
151530151903
sqlite3ExprDup(pParse->db, pTerm->pExpr, 0));
151531151904
}
151532151905
}
151533151906
sFrom.nSrc = 1;
@@ -152035,12 +152408,12 @@
152035152408
/*
152036152409
** If the pBase expression originated in the ON or USING clause of
152037152410
** a join, then transfer the appropriate markings over to derived.
152038152411
*/
152039152412
static void transferJoinMarkings(Expr *pDerived, Expr *pBase){
152040
- if( pDerived ){
152041
- pDerived->flags |= pBase->flags & EP_FromJoin;
152413
+ if( pDerived && ExprHasProperty(pBase, EP_OuterON|EP_InnerON) ){
152414
+ pDerived->flags |= pBase->flags & (EP_OuterON|EP_InnerON);
152042152415
pDerived->w.iJoin = pBase->w.iJoin;
152043152416
}
152044152417
}
152045152418
152046152419
/*
@@ -152491,11 +152864,11 @@
152491152864
static int termIsEquivalence(Parse *pParse, Expr *pExpr){
152492152865
char aff1, aff2;
152493152866
CollSeq *pColl;
152494152867
if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0;
152495152868
if( pExpr->op!=TK_EQ && pExpr->op!=TK_IS ) return 0;
152496
- if( ExprHasProperty(pExpr, EP_FromJoin) ) return 0;
152869
+ if( ExprHasProperty(pExpr, EP_OuterON) ) return 0;
152497152870
aff1 = sqlite3ExprAffinity(pExpr->pLeft);
152498152871
aff2 = sqlite3ExprAffinity(pExpr->pRight);
152499152872
if( aff1!=aff2
152500152873
&& (!sqlite3IsNumericAffinity(aff1) || !sqlite3IsNumericAffinity(aff2))
152501152874
){
@@ -152679,22 +153052,30 @@
152679153052
152680153053
#ifdef SQLITE_DEBUG
152681153054
if( prereqAll!=sqlite3WhereExprUsageNN(pMaskSet, pExpr) ){
152682153055
printf("\n*** Incorrect prereqAll computed for:\n");
152683153056
sqlite3TreeViewExpr(0,pExpr,0);
152684
- abort();
153057
+ assert( 0 );
152685153058
}
152686153059
#endif
152687153060
152688
- if( ExprHasProperty(pExpr, EP_FromJoin) ){
153061
+ if( ExprHasProperty(pExpr, EP_OuterON|EP_InnerON) ){
152689153062
Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->w.iJoin);
152690
- prereqAll |= x;
152691
- extraRight = x-1; /* ON clause terms may not be used with an index
152692
- ** on left table of a LEFT JOIN. Ticket #3015 */
152693
- if( (prereqAll>>1)>=x ){
152694
- sqlite3ErrorMsg(pParse, "ON clause references tables to its right");
152695
- return;
153063
+ if( ExprHasProperty(pExpr, EP_OuterON) ){
153064
+ prereqAll |= x;
153065
+ extraRight = x-1; /* ON clause terms may not be used with an index
153066
+ ** on left table of a LEFT JOIN. Ticket #3015 */
153067
+ if( (prereqAll>>1)>=x ){
153068
+ sqlite3ErrorMsg(pParse, "ON clause references tables to its right");
153069
+ return;
153070
+ }
153071
+ }else if( (prereqAll>>1)>=x ){
153072
+ /* The ON clause of an INNER JOIN references a table to its right.
153073
+ ** Most other SQL database engines raise an error. But all versions
153074
+ ** of SQLite going back to 3.0.0 have just put the ON clause constraint
153075
+ ** into the WHERE clause and carried on. */
153076
+ ExprClearProperty(pExpr, EP_InnerON);
152696153077
}
152697153078
}
152698153079
pTerm->prereqAll = prereqAll;
152699153080
pTerm->leftCursor = -1;
152700153081
pTerm->iParent = -1;
@@ -152758,11 +153139,11 @@
152758153139
pNew->prereqRight = prereqLeft | extraRight;
152759153140
pNew->prereqAll = prereqAll;
152760153141
pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
152761153142
}else
152762153143
if( op==TK_ISNULL
152763
- && !ExprHasProperty(pExpr,EP_FromJoin)
153144
+ && !ExprHasProperty(pExpr,EP_OuterON)
152764153145
&& 0==sqlite3ExprCanBeNull(pLeft)
152765153146
){
152766153147
assert( !ExprHasProperty(pExpr, EP_IntValue) );
152767153148
pExpr->op = TK_TRUEFALSE;
152768153149
pExpr->u.zToken = "false";
@@ -152829,11 +153210,11 @@
152829153210
** The virtual term must be tagged with TERM_VNULL.
152830153211
*/
152831153212
else if( pExpr->op==TK_NOTNULL ){
152832153213
if( pExpr->pLeft->op==TK_COLUMN
152833153214
&& pExpr->pLeft->iColumn>=0
152834
- && !ExprHasProperty(pExpr, EP_FromJoin)
153215
+ && !ExprHasProperty(pExpr, EP_OuterON)
152835153216
){
152836153217
Expr *pNewExpr;
152837153218
Expr *pLeft = pExpr->pLeft;
152838153219
int idxNew;
152839153220
WhereTerm *pNewTerm;
@@ -152977,11 +153358,11 @@
152977153358
idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC|TERM_SLICE);
152978153359
exprAnalyze(pSrc, pWC, idxNew);
152979153360
}
152980153361
pTerm = &pWC->a[idxTerm];
152981153362
pTerm->wtFlags |= TERM_CODED|TERM_VIRTUAL; /* Disable the original */
152982
- pTerm->eOperator = 0;
153363
+ pTerm->eOperator = WO_ROWVAL;
152983153364
}
152984153365
152985153366
/* If there is a vector IN term - e.g. "(a, b) IN (SELECT ...)" - create
152986153367
** a virtual term for each vector component. The expression object
152987153368
** used by each such virtual term is pExpr (the full vector IN(...)
@@ -153033,12 +153414,12 @@
153033153414
prereqColumn = sqlite3WhereExprUsage(pMaskSet, pLeft);
153034153415
if( (prereqExpr & prereqColumn)==0 ){
153035153416
Expr *pNewExpr;
153036153417
pNewExpr = sqlite3PExpr(pParse, TK_MATCH,
153037153418
0, sqlite3ExprDup(db, pRight, 0));
153038
- if( ExprHasProperty(pExpr, EP_FromJoin) && pNewExpr ){
153039
- ExprSetProperty(pNewExpr, EP_FromJoin);
153419
+ if( ExprHasProperty(pExpr, EP_OuterON) && pNewExpr ){
153420
+ ExprSetProperty(pNewExpr, EP_OuterON);
153040153421
pNewExpr->w.iJoin = pExpr->w.iJoin;
153041153422
}
153042153423
idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
153043153424
testcase( idxNew==0 );
153044153425
pNewTerm = &pWC->a[idxNew];
@@ -153178,11 +153559,11 @@
153178153559
for(ii=0; ii<pWC->nTerm; ii++){
153179153560
if( pWC->a[ii].wtFlags & TERM_CODED ){
153180153561
/* This term is a vector operation that has been decomposed into
153181153562
** other, subsequent terms. It can be ignored. See tag-20220128a */
153182153563
assert( pWC->a[ii].wtFlags & TERM_VIRTUAL );
153183
- assert( pWC->a[ii].eOperator==0 );
153564
+ assert( pWC->a[ii].eOperator==WO_ROWVAL );
153184153565
continue;
153185153566
}
153186153567
if( pWC->a[ii].leftCursor!=iCsr ) return;
153187153568
}
153188153569
@@ -153190,11 +153571,11 @@
153190153571
if( pOrderBy ){
153191153572
for(ii=0; ii<pOrderBy->nExpr; ii++){
153192153573
Expr *pExpr = pOrderBy->a[ii].pExpr;
153193153574
if( pExpr->op!=TK_COLUMN ) return;
153194153575
if( pExpr->iTable!=iCsr ) return;
153195
- if( pOrderBy->a[ii].sortFlags & KEYINFO_ORDER_BIGNULL ) return;
153576
+ if( pOrderBy->a[ii].fg.sortFlags & KEYINFO_ORDER_BIGNULL ) return;
153196153577
}
153197153578
}
153198153579
153199153580
/* All conditions are met. Add the terms to the where-clause object. */
153200153581
assert( p->pLimit->op==TK_LIMIT );
@@ -153401,13 +153782,13 @@
153401153782
pItem->colUsed |= sqlite3ExprColUsed(pColRef);
153402153783
pRhs = sqlite3PExpr(pParse, TK_UPLUS,
153403153784
sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
153404153785
pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef, pRhs);
153405153786
if( pItem->fg.jointype & (JT_LEFT|JT_LTORJ) ){
153406
- joinType = EP_FromJoin;
153787
+ joinType = EP_OuterON;
153407153788
}else{
153408
- joinType = EP_InnerJoin;
153789
+ joinType = EP_InnerON;
153409153790
}
153410153791
sqlite3SetJoinExpr(pTerm, pItem->iCursor, joinType);
153411153792
whereClauseInsert(pWC, pTerm, TERM_DYNAMIC);
153412153793
}
153413153794
}
@@ -153516,11 +153897,11 @@
153516153897
** continuation of the inner-most loop. */
153517153898
return pWInfo->iContinue;
153518153899
}
153519153900
pInner = &pWInfo->a[pWInfo->nLevel-1];
153520153901
assert( pInner->addrNxt!=0 );
153521
- return pInner->addrNxt;
153902
+ return pInner->pRJ ? pWInfo->iContinue : pInner->addrNxt;
153522153903
}
153523153904
153524153905
/*
153525153906
** While generating code for the min/max optimization, after handling
153526153907
** the aggregate-step call to min() or max(), check to see if any
@@ -153744,11 +154125,11 @@
153744154125
if( pTerm->leftCursor==iCur
153745154126
&& pTerm->u.x.leftColumn==iColumn
153746154127
&& (iColumn!=XN_EXPR
153747154128
|| sqlite3ExprCompareSkip(pTerm->pExpr->pLeft,
153748154129
pScan->pIdxExpr,iCur)==0)
153749
- && (pScan->iEquiv<=1 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin))
154130
+ && (pScan->iEquiv<=1 || !ExprHasProperty(pTerm->pExpr, EP_OuterON))
153750154131
){
153751154132
if( (pTerm->eOperator & WO_EQUIV)!=0
153752154133
&& pScan->nEquiv<ArraySize(pScan->aiCur)
153753154134
&& (pX = whereRightSubexprIsColumn(pTerm->pExpr))!=0
153754154135
){
@@ -154171,11 +154552,11 @@
154171154552
){
154172154553
char aff;
154173154554
if( pTerm->leftCursor!=pSrc->iCursor ) return 0;
154174154555
if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) return 0;
154175154556
if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
154176
- && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
154557
+ && !ExprHasProperty(pTerm->pExpr, EP_OuterON)
154177154558
&& (pTerm->eOperator & WO_IS)
154178154559
){
154179154560
/* Cannot use an IS term from the WHERE clause as an index driver for
154180154561
** the RHS of a LEFT JOIN or for the LHS of a RIGHT JOIN. Such a term
154181154562
** can only be used if it is from the ON clause. */
@@ -154246,13 +154627,11 @@
154246154627
Expr *pExpr = pTerm->pExpr;
154247154628
/* Make the automatic index a partial index if there are terms in the
154248154629
** WHERE clause (or the ON clause of a LEFT join) that constrain which
154249154630
** rows of the target table (pSrc) that can be used. */
154250154631
if( (pTerm->wtFlags & TERM_VIRTUAL)==0
154251
- && ((pSrc->fg.jointype&(JT_LEFT|JT_LTORJ))==0
154252
- || ExprHasProperty(pExpr,EP_FromJoin))
154253
- && sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor)
154632
+ && sqlite3ExprIsTableConstraint(pExpr, pSrc)
154254154633
){
154255154634
pPartial = sqlite3ExprAnd(pParse, pPartial,
154256154635
sqlite3ExprDup(pParse->db, pExpr, 0));
154257154636
}
154258154637
if( termCanDriveIndex(pTerm, pSrc, notReady) ){
@@ -154487,11 +154866,11 @@
154487154866
addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, iCur); VdbeCoverage(v);
154488154867
pWCEnd = &pWInfo->sWC.a[pWInfo->sWC.nTerm];
154489154868
for(pTerm=pWInfo->sWC.a; pTerm<pWCEnd; pTerm++){
154490154869
Expr *pExpr = pTerm->pExpr;
154491154870
if( (pTerm->wtFlags & TERM_VIRTUAL)==0
154492
- && sqlite3ExprIsTableConstant(pExpr, iCur)
154871
+ && sqlite3ExprIsTableConstraint(pExpr, pItem)
154493154872
){
154494154873
sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
154495154874
}
154496154875
}
154497154876
if( pLoop->wsFlags & WHERE_IPK ){
@@ -154597,11 +154976,11 @@
154597154976
/* tag-20191211-002: WHERE-clause constraints are not useful to the
154598154977
** right-hand table of a LEFT JOIN nor to the left-hand table of a
154599154978
** RIGHT JOIN. See tag-20191211-001 for the
154600154979
** equivalent restriction for ordinary tables. */
154601154980
if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
154602
- && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
154981
+ && !ExprHasProperty(pTerm->pExpr, EP_OuterON)
154603154982
){
154604154983
continue;
154605154984
}
154606154985
nTerm++;
154607154986
pTerm->wtFlags |= TERM_OK;
@@ -154622,11 +155001,11 @@
154622155001
if( sqlite3ExprIsConstant(pExpr) ){
154623155002
continue;
154624155003
}
154625155004
154626155005
/* Virtual tables are unable to deal with NULLS FIRST */
154627
- if( pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL ) break;
155006
+ if( pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_BIGNULL ) break;
154628155007
154629155008
/* First case - a direct column references without a COLLATE operator */
154630155009
if( pExpr->op==TK_COLUMN && pExpr->iTable==pSrc->iCursor ){
154631155010
assert( pExpr->iColumn>=XN_ROWID && pExpr->iColumn<pTab->nCol );
154632155011
continue;
@@ -154734,11 +155113,11 @@
154734155113
if( sqlite3ExprIsConstant(pExpr) ) continue;
154735155114
assert( pExpr->op==TK_COLUMN
154736155115
|| (pExpr->op==TK_COLLATE && pExpr->pLeft->op==TK_COLUMN
154737155116
&& pExpr->iColumn==pExpr->pLeft->iColumn) );
154738155117
pIdxOrderBy[j].iColumn = pExpr->iColumn;
154739
- pIdxOrderBy[j].desc = pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC;
155118
+ pIdxOrderBy[j].desc = pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_DESC;
154740155119
j++;
154741155120
}
154742155121
pIdxInfo->nOrderBy = j;
154743155122
154744155123
*pmNoOmit = mNoOmit;
@@ -155475,11 +155854,11 @@
155475155854
char zType[8];
155476155855
char zLeft[50];
155477155856
memcpy(zType, "....", 5);
155478155857
if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V';
155479155858
if( pTerm->eOperator & WO_EQUIV ) zType[1] = 'E';
155480
- if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) zType[2] = 'L';
155859
+ if( ExprHasProperty(pTerm->pExpr, EP_OuterON) ) zType[2] = 'L';
155481155860
if( pTerm->wtFlags & TERM_CODED ) zType[3] = 'C';
155482155861
if( pTerm->eOperator & WO_SINGLE ){
155483155862
assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
155484155863
sqlite3_snprintf(sizeof(zLeft),zLeft,"left={%d:%d}",
155485155864
pTerm->leftCursor, pTerm->u.x.leftColumn);
@@ -156252,11 +156631,11 @@
156252156631
/* tag-20191211-001: Do not allow constraints from the WHERE clause to
156253156632
** be used by the right table of a LEFT JOIN nor by the left table of a
156254156633
** RIGHT JOIN. Only constraints in the
156255156634
** ON clause are allowed. See tag-20191211-002 for the vtab equivalent. */
156256156635
if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
156257
- && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
156636
+ && !ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON)
156258156637
){
156259156638
continue;
156260156639
}
156261156640
156262156641
if( IsUniqueIndex(pProbe) && saved_nEq==pProbe->nKeyCol-1 ){
@@ -156621,12 +157000,12 @@
156621157000
}
156622157001
if( pParse->db->flags & SQLITE_EnableQPSG ) pParse = 0;
156623157002
for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
156624157003
Expr *pExpr;
156625157004
pExpr = pTerm->pExpr;
156626
- if( (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->w.iJoin==iTab)
156627
- && (isLeft==0 || ExprHasProperty(pExpr, EP_FromJoin))
157005
+ if( (!ExprHasProperty(pExpr, EP_OuterON) || pExpr->w.iJoin==iTab)
157006
+ && (isLeft==0 || ExprHasProperty(pExpr, EP_OuterON))
156628157007
&& sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, iTab)
156629157008
&& (pTerm->wtFlags & TERM_VNULL)==0
156630157009
){
156631157010
return 1;
156632157011
}
@@ -156898,11 +157277,18 @@
156898157277
156899157278
pNew->rRun = sqlite3LogEstAdd(pNew->rRun, nLookup);
156900157279
}
156901157280
ApplyCostMultiplier(pNew->rRun, pTab->costMult);
156902157281
whereLoopOutputAdjust(pWC, pNew, rSize);
156903
- rc = whereLoopInsert(pBuilder, pNew);
157282
+ if( (pSrc->fg.jointype & JT_RIGHT)!=0 && pProbe->aColExpr ){
157283
+ /* Do not do an SCAN of a index-on-expression in a RIGHT JOIN
157284
+ ** because the cursor used to access the index might not be
157285
+ ** positioned to the correct row during the right-join no-match
157286
+ ** loop. */
157287
+ }else{
157288
+ rc = whereLoopInsert(pBuilder, pNew);
157289
+ }
156904157290
pNew->nOut = rSize;
156905157291
if( rc ) break;
156906157292
}
156907157293
}
156908157294
@@ -157073,10 +157459,11 @@
157073157459
pIdxInfo->orderByConsumed = 0;
157074157460
pIdxInfo->idxFlags &= ~SQLITE_INDEX_SCAN_UNIQUE;
157075157461
*pbIn = 1; assert( (mExclude & WO_IN)==0 );
157076157462
}
157077157463
157464
+ assert( pbRetryLimit || !isLimitTerm(pTerm) );
157078157465
if( isLimitTerm(pTerm) && *pbIn ){
157079157466
/* If there is an IN(...) term handled as an == (separate call to
157080157467
** xFilter for each value on the RHS of the IN) and a LIMIT or
157081157468
** OFFSET term handled as well, the plan is unusable. Set output
157082157469
** variable *pbRetryLimit to true to tell the caller to retry with
@@ -157546,11 +157933,13 @@
157546157933
SrcList *pTabList = pWInfo->pTabList;
157547157934
SrcItem *pItem;
157548157935
SrcItem *pEnd = &pTabList->a[pWInfo->nLevel];
157549157936
sqlite3 *db = pWInfo->pParse->db;
157550157937
int rc = SQLITE_OK;
157938
+ int bFirstPastRJ = 0;
157551157939
WhereLoop *pNew;
157940
+
157552157941
157553157942
/* Loop over the tables in the join, from left to right */
157554157943
pNew = pBuilder->pNew;
157555157944
whereLoopInit(pNew);
157556157945
pBuilder->iPlanLimit = SQLITE_QUERY_PLANNER_LIMIT;
@@ -157557,16 +157946,17 @@
157557157946
for(iTab=0, pItem=pTabList->a; pItem<pEnd; iTab++, pItem++){
157558157947
Bitmask mUnusable = 0;
157559157948
pNew->iTab = iTab;
157560157949
pBuilder->iPlanLimit += SQLITE_QUERY_PLANNER_LIMIT_INCR;
157561157950
pNew->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, pItem->iCursor);
157562
- if( (pItem->fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
157563
- /* This condition is true when pItem is the FROM clause term on the
157564
- ** right-hand-side of a OUTER or CROSS JOIN. */
157565
- mPrereq = mPrior;
157566
- }else{
157567
- mPrereq = 0;
157951
+ if( bFirstPastRJ || (pItem->fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
157952
+ /* Add prerequisites to prevent reordering of FROM clause terms
157953
+ ** across CROSS joins and outer joins. The bFirstPastRJ boolean
157954
+ ** prevents the right operand of a RIGHT JOIN from being swapped with
157955
+ ** other elements even further to the right. */
157956
+ mPrereq |= mPrior;
157957
+ bFirstPastRJ = (pItem->fg.jointype & JT_RIGHT)!=0;
157568157958
}
157569157959
#ifndef SQLITE_OMIT_VIRTUALTABLE
157570157960
if( IsVirtual(pItem->pTab) ){
157571157961
SrcItem *p;
157572157962
for(p=&pItem[1]; p<pEnd; p++){
@@ -157873,20 +158263,22 @@
157873158263
}
157874158264
if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
157875158265
/* Make sure the sort order is compatible in an ORDER BY clause.
157876158266
** Sort order is irrelevant for a GROUP BY clause. */
157877158267
if( revSet ){
157878
- if( (rev ^ revIdx)!=(pOrderBy->a[i].sortFlags&KEYINFO_ORDER_DESC) ){
158268
+ if( (rev ^ revIdx)
158269
+ != (pOrderBy->a[i].fg.sortFlags&KEYINFO_ORDER_DESC)
158270
+ ){
157879158271
isMatch = 0;
157880158272
}
157881158273
}else{
157882
- rev = revIdx ^ (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC);
158274
+ rev = revIdx ^ (pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_DESC);
157883158275
if( rev ) *pRevMask |= MASKBIT(iLoop);
157884158276
revSet = 1;
157885158277
}
157886158278
}
157887
- if( isMatch && (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL) ){
158279
+ if( isMatch && (pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_BIGNULL) ){
157888158280
if( j==pLoop->u.btree.nEq ){
157889158281
pLoop->wsFlags |= WHERE_BIGNULL_SORT;
157890158282
}else{
157891158283
isMatch = 0;
157892158284
}
@@ -158630,11 +159022,11 @@
158630159022
}
158631159023
if( (tabUsed & pLoop->maskSelf)!=0 ) continue;
158632159024
pEnd = pWInfo->sWC.a + pWInfo->sWC.nTerm;
158633159025
for(pTerm=pWInfo->sWC.a; pTerm<pEnd; pTerm++){
158634159026
if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){
158635
- if( !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
159027
+ if( !ExprHasProperty(pTerm->pExpr, EP_OuterON)
158636159028
|| pTerm->pExpr->w.iJoin!=pItem->iCursor
158637159029
){
158638159030
break;
158639159031
}
158640159032
}
@@ -159256,10 +159648,11 @@
159256159648
op = OP_ReopenIdx;
159257159649
}else{
159258159650
iIndexCur = pParse->nTab++;
159259159651
}
159260159652
pLevel->iIdxCur = iIndexCur;
159653
+ assert( pIx!=0 );
159261159654
assert( pIx->pSchema==pTab->pSchema );
159262159655
assert( iIndexCur>=0 );
159263159656
if( op ){
159264159657
sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
159265159658
sqlite3VdbeSetP4KeyInfo(pParse, pIx);
@@ -159331,13 +159724,24 @@
159331159724
** program.
159332159725
*/
159333159726
for(ii=0; ii<nTabList; ii++){
159334159727
int addrExplain;
159335159728
int wsFlags;
159729
+ SrcItem *pSrc;
159336159730
if( pParse->nErr ) goto whereBeginError;
159337159731
pLevel = &pWInfo->a[ii];
159338159732
wsFlags = pLevel->pWLoop->wsFlags;
159733
+ pSrc = &pTabList->a[pLevel->iFrom];
159734
+ if( pSrc->fg.isMaterialized ){
159735
+ if( pSrc->fg.isCorrelated ){
159736
+ sqlite3VdbeAddOp2(v, OP_Gosub, pSrc->regReturn, pSrc->addrFillSub);
159737
+ }else{
159738
+ int iOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
159739
+ sqlite3VdbeAddOp2(v, OP_Gosub, pSrc->regReturn, pSrc->addrFillSub);
159740
+ sqlite3VdbeJumpHere(v, iOnce);
159741
+ }
159742
+ }
159339159743
if( (wsFlags & (WHERE_AUTO_INDEX|WHERE_BLOOMFILTER))!=0 ){
159340159744
if( (wsFlags & WHERE_AUTO_INDEX)!=0 ){
159341159745
#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
159342159746
constructAutomaticIndex(pParse, &pWInfo->sWC,
159343159747
&pTabList->a[pLevel->iFrom], notReady, pLevel);
@@ -159425,10 +159829,11 @@
159425159829
WhereLevel *pLevel;
159426159830
WhereLoop *pLoop;
159427159831
SrcList *pTabList = pWInfo->pTabList;
159428159832
sqlite3 *db = pParse->db;
159429159833
int iEnd = sqlite3VdbeCurrentAddr(v);
159834
+ int nRJ = 0;
159430159835
159431159836
/* Generate loop termination code.
159432159837
*/
159433159838
VdbeModuleComment((v, "End WHERE-core"));
159434159839
for(i=pWInfo->nLevel-1; i>=0; i--){
@@ -159438,14 +159843,14 @@
159438159843
/* Terminate the subroutine that forms the interior of the loop of
159439159844
** the RIGHT JOIN table */
159440159845
WhereRightJoin *pRJ = pLevel->pRJ;
159441159846
sqlite3VdbeResolveLabel(v, pLevel->addrCont);
159442159847
pLevel->addrCont = 0;
159848
+ pRJ->endSubrtn = sqlite3VdbeCurrentAddr(v);
159443159849
sqlite3VdbeAddOp3(v, OP_Return, pRJ->regReturn, pRJ->addrSubrtn, 1);
159444159850
VdbeCoverage(v);
159445
- assert( pParse->withinRJSubrtn>0 );
159446
- pParse->withinRJSubrtn--;
159851
+ nRJ++;
159447159852
}
159448159853
pLoop = pLevel->pWLoop;
159449159854
if( pLevel->op!=OP_Noop ){
159450159855
#ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
159451159856
int addrSeek = 0;
@@ -159583,10 +159988,11 @@
159583159988
VdbeModuleComment((v, "End WHERE-loop%d: %s", i,
159584159989
pWInfo->pTabList->a[pLevel->iFrom].pTab->zName));
159585159990
}
159586159991
159587159992
assert( pWInfo->nLevel<=pTabList->nSrc );
159993
+ if( pWInfo->pExprMods ) whereUndoExprMods(pWInfo);
159588159994
for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
159589159995
int k, last;
159590159996
VdbeOp *pOp, *pLastOp;
159591159997
Index *pIdx = 0;
159592159998
SrcItem *pTabItem = &pTabList->a[pLevel->iFrom];
@@ -159719,13 +160125,13 @@
159719160125
*/
159720160126
sqlite3VdbeResolveLabel(v, pWInfo->iBreak);
159721160127
159722160128
/* Final cleanup
159723160129
*/
159724
- if( pWInfo->pExprMods ) whereUndoExprMods(pWInfo);
159725160130
pParse->nQueryLoop = pWInfo->savedNQueryLoop;
159726160131
whereInfoFree(db, pWInfo);
160132
+ pParse->withinRJSubrtn -= nRJ;
159727160133
return;
159728160134
}
159729160135
159730160136
/************** End of where.c ***********************************************/
159731160137
/************** Begin file window.c ******************************************/
@@ -160645,11 +161051,11 @@
160645161051
pSub->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse);
160646161052
pSub->u.zToken = 0;
160647161053
}
160648161054
}
160649161055
pList = sqlite3ExprListAppend(pParse, pList, pDup);
160650
- if( pList ) pList->a[nInit+i].sortFlags = pAppend->a[i].sortFlags;
161056
+ if( pList ) pList->a[nInit+i].fg.sortFlags = pAppend->a[i].fg.sortFlags;
160651161057
}
160652161058
}
160653161059
return pList;
160654161060
}
160655161061
@@ -161846,11 +162252,11 @@
161846162252
windowReadPeerValues(p, csr1, reg1);
161847162253
windowReadPeerValues(p, csr2, reg2);
161848162254
161849162255
assert( op==OP_Ge || op==OP_Gt || op==OP_Le );
161850162256
assert( pOrderBy && pOrderBy->nExpr==1 );
161851
- if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_DESC ){
162257
+ if( pOrderBy->a[0].fg.sortFlags & KEYINFO_ORDER_DESC ){
161852162258
switch( op ){
161853162259
case OP_Ge: op = OP_Le; break;
161854162260
case OP_Gt: op = OP_Lt; break;
161855162261
default: assert( op==OP_Le ); op = OP_Ge; break;
161856162262
}
@@ -161879,11 +162285,11 @@
161879162285
** }
161880162286
**
161881162287
** Additionally, if either reg1 or reg2 are NULL but the jump to lbl is
161882162288
** not taken, control jumps over the comparison operator coded below this
161883162289
** block. */
161884
- if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_BIGNULL ){
162290
+ if( pOrderBy->a[0].fg.sortFlags & KEYINFO_ORDER_BIGNULL ){
161885162291
/* This block runs if reg1 contains a NULL. */
161886162292
int addr = sqlite3VdbeAddOp1(v, OP_NotNull, reg1); VdbeCoverage(v);
161887162293
switch( op ){
161888162294
case OP_Ge:
161889162295
sqlite3VdbeAddOp2(v, OP_Goto, 0, lbl);
@@ -163347,22 +163753,22 @@
163347163753
#define sqlite3ParserCTX_PDECL ,Parse *pParse
163348163754
#define sqlite3ParserCTX_PARAM ,pParse
163349163755
#define sqlite3ParserCTX_FETCH Parse *pParse=yypParser->pParse;
163350163756
#define sqlite3ParserCTX_STORE yypParser->pParse=pParse;
163351163757
#define YYFALLBACK 1
163352
-#define YYNSTATE 570
163353
-#define YYNRULE 403
163354
-#define YYNRULE_WITH_ACTION 340
163758
+#define YYNSTATE 576
163759
+#define YYNRULE 405
163760
+#define YYNRULE_WITH_ACTION 342
163355163761
#define YYNTOKEN 185
163356
-#define YY_MAX_SHIFT 569
163357
-#define YY_MIN_SHIFTREDUCE 829
163358
-#define YY_MAX_SHIFTREDUCE 1231
163359
-#define YY_ERROR_ACTION 1232
163360
-#define YY_ACCEPT_ACTION 1233
163361
-#define YY_NO_ACTION 1234
163362
-#define YY_MIN_REDUCE 1235
163363
-#define YY_MAX_REDUCE 1637
163762
+#define YY_MAX_SHIFT 575
163763
+#define YY_MIN_SHIFTREDUCE 835
163764
+#define YY_MAX_SHIFTREDUCE 1239
163765
+#define YY_ERROR_ACTION 1240
163766
+#define YY_ACCEPT_ACTION 1241
163767
+#define YY_NO_ACTION 1242
163768
+#define YY_MIN_REDUCE 1243
163769
+#define YY_MAX_REDUCE 1647
163364163770
/************* End control #defines *******************************************/
163365163771
#define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))
163366163772
163367163773
/* Define the yytestcase() macro to be a no-op if is not already defined
163368163774
** otherwise.
@@ -163425,219 +163831,222 @@
163425163831
** yy_reduce_ofst[] For each state, the offset into yy_action for
163426163832
** shifting non-terminals after a reduce.
163427163833
** yy_default[] Default action for each state.
163428163834
**
163429163835
*********** Begin parsing tables **********************************************/
163430
-#define YY_ACTTAB_COUNT (2064)
163836
+#define YY_ACTTAB_COUNT (2098)
163431163837
static const YYACTIONTYPE yy_action[] = {
163432
- /* 0 */ 562, 204, 562, 116, 112, 225, 562, 116, 112, 225,
163433
- /* 10 */ 562, 1306, 373, 1285, 404, 556, 556, 556, 562, 405,
163434
- /* 20 */ 374, 1306, 1268, 41, 41, 41, 41, 204, 1516, 71,
163435
- /* 30 */ 71, 965, 415, 41, 41, 487, 299, 275, 299, 966,
163436
- /* 40 */ 393, 71, 71, 123, 124, 114, 1209, 1209, 1042, 1045,
163437
- /* 50 */ 1034, 1034, 121, 121, 122, 122, 122, 122, 472, 405,
163438
- /* 60 */ 1233, 1, 1, 569, 2, 1237, 544, 116, 112, 225,
163439
- /* 70 */ 313, 476, 142, 476, 520, 116, 112, 225, 525, 1319,
163440
- /* 80 */ 413, 519, 138, 123, 124, 114, 1209, 1209, 1042, 1045,
163441
- /* 90 */ 1034, 1034, 121, 121, 122, 122, 122, 122, 116, 112,
163442
- /* 100 */ 225, 323, 120, 120, 120, 120, 119, 119, 118, 118,
163443
- /* 110 */ 118, 117, 113, 440, 280, 280, 280, 280, 438, 438,
163444
- /* 120 */ 438, 1557, 372, 1559, 1184, 371, 1155, 559, 1155, 559,
163445
- /* 130 */ 405, 1557, 533, 255, 222, 440, 99, 141, 445, 312,
163446
- /* 140 */ 553, 236, 120, 120, 120, 120, 119, 119, 118, 118,
163447
- /* 150 */ 118, 117, 113, 440, 123, 124, 114, 1209, 1209, 1042,
163448
- /* 160 */ 1045, 1034, 1034, 121, 121, 122, 122, 122, 122, 138,
163449
- /* 170 */ 290, 1184, 335, 444, 118, 118, 118, 117, 113, 440,
163450
- /* 180 */ 125, 1184, 1185, 1186, 144, 437, 436, 562, 117, 113,
163451
- /* 190 */ 440, 122, 122, 122, 122, 115, 120, 120, 120, 120,
163452
- /* 200 */ 119, 119, 118, 118, 118, 117, 113, 440, 450, 110,
163453
- /* 210 */ 13, 13, 542, 120, 120, 120, 120, 119, 119, 118,
163454
- /* 220 */ 118, 118, 117, 113, 440, 418, 312, 553, 1184, 1185,
163455
- /* 230 */ 1186, 145, 1216, 405, 1216, 122, 122, 122, 122, 120,
163456
- /* 240 */ 120, 120, 120, 119, 119, 118, 118, 118, 117, 113,
163457
- /* 250 */ 440, 461, 338, 1031, 1031, 1043, 1046, 123, 124, 114,
163458
- /* 260 */ 1209, 1209, 1042, 1045, 1034, 1034, 121, 121, 122, 122,
163459
- /* 270 */ 122, 122, 1271, 518, 218, 1184, 562, 405, 220, 510,
163460
- /* 280 */ 171, 80, 81, 120, 120, 120, 120, 119, 119, 118,
163461
- /* 290 */ 118, 118, 117, 113, 440, 1001, 16, 16, 1184, 55,
163462
- /* 300 */ 55, 123, 124, 114, 1209, 1209, 1042, 1045, 1034, 1034,
163463
- /* 310 */ 121, 121, 122, 122, 122, 122, 120, 120, 120, 120,
163464
- /* 320 */ 119, 119, 118, 118, 118, 117, 113, 440, 1035, 542,
163465
- /* 330 */ 1184, 369, 1184, 1185, 1186, 248, 1426, 395, 500, 497,
163466
- /* 340 */ 496, 108, 554, 560, 4, 920, 920, 429, 495, 336,
163467
- /* 350 */ 456, 324, 356, 390, 1229, 1184, 1185, 1186, 557, 562,
163468
- /* 360 */ 120, 120, 120, 120, 119, 119, 118, 118, 118, 117,
163469
- /* 370 */ 113, 440, 280, 280, 365, 1570, 1597, 437, 436, 150,
163470
- /* 380 */ 405, 441, 71, 71, 1278, 559, 1213, 1184, 1185, 1186,
163471
- /* 390 */ 83, 1215, 267, 551, 539, 511, 1551, 562, 96, 1214,
163472
- /* 400 */ 6, 1270, 468, 138, 123, 124, 114, 1209, 1209, 1042,
163473
- /* 410 */ 1045, 1034, 1034, 121, 121, 122, 122, 122, 122, 544,
163474
- /* 420 */ 13, 13, 1021, 503, 1216, 1184, 1216, 543, 106, 106,
163475
- /* 430 */ 218, 562, 1230, 171, 562, 423, 107, 193, 441, 564,
163476
- /* 440 */ 563, 426, 1542, 1011, 321, 545, 1184, 266, 283, 364,
163477
- /* 450 */ 506, 359, 505, 253, 71, 71, 539, 71, 71, 355,
163478
- /* 460 */ 312, 553, 1603, 120, 120, 120, 120, 119, 119, 118,
163479
- /* 470 */ 118, 118, 117, 113, 440, 1011, 1011, 1013, 1014, 27,
163480
- /* 480 */ 280, 280, 1184, 1185, 1186, 1150, 562, 1602, 405, 895,
163481
- /* 490 */ 186, 544, 352, 559, 544, 931, 529, 513, 1150, 512,
163482
- /* 500 */ 409, 1150, 546, 1184, 1185, 1186, 562, 540, 1544, 51,
163483
- /* 510 */ 51, 210, 123, 124, 114, 1209, 1209, 1042, 1045, 1034,
163484
- /* 520 */ 1034, 121, 121, 122, 122, 122, 122, 1184, 470, 56,
163485
- /* 530 */ 56, 405, 280, 280, 1480, 501, 119, 119, 118, 118,
163486
- /* 540 */ 118, 117, 113, 440, 1001, 559, 514, 213, 537, 1551,
163487
- /* 550 */ 312, 553, 138, 6, 528, 123, 124, 114, 1209, 1209,
163488
- /* 560 */ 1042, 1045, 1034, 1034, 121, 121, 122, 122, 122, 122,
163489
- /* 570 */ 1545, 120, 120, 120, 120, 119, 119, 118, 118, 118,
163490
- /* 580 */ 117, 113, 440, 481, 1184, 1185, 1186, 478, 277, 1259,
163491
- /* 590 */ 951, 248, 1184, 369, 500, 497, 496, 1184, 336, 565,
163492
- /* 600 */ 1184, 565, 405, 288, 495, 951, 870, 187, 476, 312,
163493
- /* 610 */ 553, 380, 286, 376, 120, 120, 120, 120, 119, 119,
163494
- /* 620 */ 118, 118, 118, 117, 113, 440, 123, 124, 114, 1209,
163495
- /* 630 */ 1209, 1042, 1045, 1034, 1034, 121, 121, 122, 122, 122,
163496
- /* 640 */ 122, 405, 390, 1128, 1184, 863, 98, 280, 280, 1184,
163497
- /* 650 */ 1185, 1186, 369, 1085, 1184, 1185, 1186, 1184, 1185, 1186,
163498
- /* 660 */ 559, 451, 32, 369, 229, 123, 124, 114, 1209, 1209,
163499
- /* 670 */ 1042, 1045, 1034, 1034, 121, 121, 122, 122, 122, 122,
163500
- /* 680 */ 1425, 953, 562, 224, 952, 120, 120, 120, 120, 119,
163501
- /* 690 */ 119, 118, 118, 118, 117, 113, 440, 1150, 224, 1184,
163502
- /* 700 */ 153, 1184, 1185, 1186, 1543, 13, 13, 297, 951, 1224,
163503
- /* 710 */ 1150, 149, 405, 1150, 369, 1573, 1168, 5, 365, 1570,
163504
- /* 720 */ 425, 1230, 3, 951, 120, 120, 120, 120, 119, 119,
163505
- /* 730 */ 118, 118, 118, 117, 113, 440, 123, 124, 114, 1209,
163506
- /* 740 */ 1209, 1042, 1045, 1034, 1034, 121, 121, 122, 122, 122,
163507
- /* 750 */ 122, 405, 204, 561, 1184, 1022, 1184, 1185, 1186, 1184,
163508
- /* 760 */ 384, 846, 151, 1542, 282, 398, 1090, 1090, 484, 562,
163509
- /* 770 */ 461, 338, 1311, 1311, 1542, 123, 124, 114, 1209, 1209,
163510
- /* 780 */ 1042, 1045, 1034, 1034, 121, 121, 122, 122, 122, 122,
163511
- /* 790 */ 127, 562, 13, 13, 370, 120, 120, 120, 120, 119,
163512
- /* 800 */ 119, 118, 118, 118, 117, 113, 440, 298, 562, 449,
163513
- /* 810 */ 524, 1184, 1185, 1186, 13, 13, 1184, 1185, 1186, 1289,
163514
- /* 820 */ 459, 1259, 405, 1309, 1309, 1542, 1006, 449, 448, 196,
163515
- /* 830 */ 295, 71, 71, 1257, 120, 120, 120, 120, 119, 119,
163516
- /* 840 */ 118, 118, 118, 117, 113, 440, 123, 124, 114, 1209,
163517
- /* 850 */ 1209, 1042, 1045, 1034, 1034, 121, 121, 122, 122, 122,
163518
- /* 860 */ 122, 405, 223, 1065, 1150, 280, 280, 415, 308, 274,
163519
- /* 870 */ 274, 281, 281, 1411, 402, 401, 378, 1150, 559, 562,
163520
- /* 880 */ 1150, 1188, 559, 1590, 559, 123, 124, 114, 1209, 1209,
163521
- /* 890 */ 1042, 1045, 1034, 1034, 121, 121, 122, 122, 122, 122,
163522
- /* 900 */ 449, 1472, 13, 13, 1526, 120, 120, 120, 120, 119,
163523
- /* 910 */ 119, 118, 118, 118, 117, 113, 440, 197, 562, 350,
163524
- /* 920 */ 1576, 569, 2, 1237, 834, 835, 836, 1552, 313, 1204,
163525
- /* 930 */ 142, 6, 405, 251, 250, 249, 202, 1319, 9, 1188,
163526
- /* 940 */ 258, 71, 71, 420, 120, 120, 120, 120, 119, 119,
163527
- /* 950 */ 118, 118, 118, 117, 113, 440, 123, 124, 114, 1209,
163528
- /* 960 */ 1209, 1042, 1045, 1034, 1034, 121, 121, 122, 122, 122,
163529
- /* 970 */ 122, 562, 280, 280, 562, 1205, 405, 568, 309, 1237,
163530
- /* 980 */ 345, 1288, 348, 415, 313, 559, 142, 487, 521, 1633,
163531
- /* 990 */ 391, 367, 487, 1319, 70, 70, 1287, 71, 71, 236,
163532
- /* 1000 */ 1317, 101, 114, 1209, 1209, 1042, 1045, 1034, 1034, 121,
163533
- /* 1010 */ 121, 122, 122, 122, 122, 120, 120, 120, 120, 119,
163534
- /* 1020 */ 119, 118, 118, 118, 117, 113, 440, 1106, 280, 280,
163535
- /* 1030 */ 424, 444, 1515, 1205, 435, 280, 280, 1479, 1344, 307,
163536
- /* 1040 */ 470, 559, 1107, 965, 487, 487, 213, 1255, 559, 1528,
163537
- /* 1050 */ 562, 966, 203, 562, 1021, 236, 379, 1108, 515, 120,
163538
- /* 1060 */ 120, 120, 120, 119, 119, 118, 118, 118, 117, 113,
163539
- /* 1070 */ 440, 1012, 104, 71, 71, 1011, 13, 13, 906, 562,
163540
- /* 1080 */ 1485, 562, 280, 280, 95, 522, 487, 444, 907, 1318,
163541
- /* 1090 */ 1314, 541, 405, 280, 280, 559, 147, 205, 1485, 1487,
163542
- /* 1100 */ 258, 446, 15, 15, 43, 43, 559, 1011, 1011, 1013,
163543
- /* 1110 */ 439, 328, 405, 523, 12, 291, 123, 124, 114, 1209,
163544
- /* 1120 */ 1209, 1042, 1045, 1034, 1034, 121, 121, 122, 122, 122,
163545
- /* 1130 */ 122, 343, 405, 858, 1524, 1205, 123, 124, 114, 1209,
163546
- /* 1140 */ 1209, 1042, 1045, 1034, 1034, 121, 121, 122, 122, 122,
163547
- /* 1150 */ 122, 1129, 1631, 470, 1631, 367, 123, 111, 114, 1209,
163548
- /* 1160 */ 1209, 1042, 1045, 1034, 1034, 121, 121, 122, 122, 122,
163549
- /* 1170 */ 122, 1485, 325, 470, 327, 120, 120, 120, 120, 119,
163550
- /* 1180 */ 119, 118, 118, 118, 117, 113, 440, 199, 1411, 562,
163551
- /* 1190 */ 1286, 858, 460, 1205, 432, 120, 120, 120, 120, 119,
163552
- /* 1200 */ 119, 118, 118, 118, 117, 113, 440, 547, 1129, 1632,
163553
- /* 1210 */ 535, 1632, 57, 57, 886, 120, 120, 120, 120, 119,
163554
- /* 1220 */ 119, 118, 118, 118, 117, 113, 440, 562, 294, 534,
163555
- /* 1230 */ 1127, 1411, 1549, 1550, 1323, 405, 6, 6, 1161, 1260,
163556
- /* 1240 */ 411, 316, 280, 280, 1411, 504, 559, 521, 296, 453,
163557
- /* 1250 */ 44, 44, 562, 887, 12, 559, 326, 474, 421, 403,
163558
- /* 1260 */ 124, 114, 1209, 1209, 1042, 1045, 1034, 1034, 121, 121,
163559
- /* 1270 */ 122, 122, 122, 122, 562, 58, 58, 284, 1184, 1411,
163560
- /* 1280 */ 492, 454, 388, 388, 387, 269, 385, 1127, 1548, 843,
163561
- /* 1290 */ 1161, 403, 6, 562, 317, 1150, 466, 59, 59, 1547,
163562
- /* 1300 */ 1106, 422, 230, 6, 319, 252, 536, 252, 1150, 427,
163563
- /* 1310 */ 562, 1150, 318, 17, 483, 1107, 60, 60, 120, 120,
163564
- /* 1320 */ 120, 120, 119, 119, 118, 118, 118, 117, 113, 440,
163565
- /* 1330 */ 1108, 212, 477, 61, 61, 1184, 1185, 1186, 108, 554,
163566
- /* 1340 */ 320, 4, 232, 452, 522, 562, 233, 452, 562, 433,
163567
- /* 1350 */ 164, 550, 416, 137, 475, 557, 562, 289, 562, 1087,
163568
- /* 1360 */ 562, 289, 562, 1087, 527, 562, 866, 8, 62, 62,
163569
- /* 1370 */ 231, 45, 45, 562, 410, 562, 410, 562, 441, 46,
163570
- /* 1380 */ 46, 47, 47, 49, 49, 50, 50, 195, 63, 63,
163571
- /* 1390 */ 551, 562, 355, 562, 98, 482, 64, 64, 65, 65,
163572
- /* 1400 */ 14, 14, 555, 411, 531, 406, 562, 1021, 562, 530,
163573
- /* 1410 */ 312, 553, 312, 553, 66, 66, 129, 129, 562, 1021,
163574
- /* 1420 */ 562, 508, 926, 866, 1012, 106, 106, 925, 1011, 67,
163575
- /* 1430 */ 67, 52, 52, 107, 447, 441, 564, 563, 412, 173,
163576
- /* 1440 */ 1011, 68, 68, 69, 69, 562, 463, 562, 926, 467,
163577
- /* 1450 */ 1356, 279, 222, 925, 311, 1355, 403, 562, 455, 403,
163578
- /* 1460 */ 1011, 1011, 1013, 235, 403, 84, 209, 1342, 53, 53,
163579
- /* 1470 */ 159, 159, 1011, 1011, 1013, 1014, 27, 1575, 1172, 443,
163580
- /* 1480 */ 160, 160, 284, 95, 105, 1531, 103, 388, 388, 387,
163581
- /* 1490 */ 269, 385, 562, 873, 843, 877, 562, 108, 554, 462,
163582
- /* 1500 */ 4, 562, 148, 30, 38, 562, 1124, 230, 392, 319,
163583
- /* 1510 */ 108, 554, 523, 4, 557, 76, 76, 318, 562, 54,
163584
- /* 1520 */ 54, 562, 333, 464, 72, 72, 329, 557, 130, 130,
163585
- /* 1530 */ 562, 285, 1504, 562, 31, 1503, 562, 441, 334, 479,
163586
- /* 1540 */ 98, 73, 73, 340, 157, 157, 292, 232, 1072, 551,
163587
- /* 1550 */ 441, 873, 1352, 131, 131, 164, 132, 132, 137, 128,
163588
- /* 1560 */ 128, 1564, 551, 531, 562, 315, 562, 344, 532, 1003,
163589
- /* 1570 */ 469, 257, 257, 885, 884, 231, 531, 562, 1021, 562,
163590
- /* 1580 */ 471, 530, 257, 363, 106, 106, 517, 158, 158, 152,
163591
- /* 1590 */ 152, 1021, 107, 362, 441, 564, 563, 106, 106, 1011,
163592
- /* 1600 */ 136, 136, 135, 135, 562, 107, 1072, 441, 564, 563,
163593
- /* 1610 */ 406, 347, 1011, 562, 349, 312, 553, 562, 339, 562,
163594
- /* 1620 */ 98, 493, 353, 254, 98, 892, 893, 133, 133, 351,
163595
- /* 1630 */ 1302, 1011, 1011, 1013, 1014, 27, 134, 134, 1015, 447,
163596
- /* 1640 */ 75, 75, 77, 77, 1011, 1011, 1013, 1014, 27, 1172,
163597
- /* 1650 */ 443, 562, 358, 284, 108, 554, 368, 4, 388, 388,
163598
- /* 1660 */ 387, 269, 385, 562, 1133, 843, 562, 1068, 956, 254,
163599
- /* 1670 */ 257, 557, 968, 969, 74, 74, 549, 923, 230, 110,
163600
- /* 1680 */ 319, 108, 554, 1084, 4, 1084, 42, 42, 318, 48,
163601
- /* 1690 */ 48, 1083, 1365, 1083, 441, 856, 1015, 146, 557, 924,
163602
- /* 1700 */ 1410, 110, 1338, 1350, 548, 1416, 551, 1267, 207, 1258,
163603
- /* 1710 */ 1246, 1245, 1247, 1583, 11, 488, 272, 215, 232, 1335,
163604
- /* 1720 */ 304, 441, 305, 306, 389, 228, 164, 1397, 1392, 137,
163605
- /* 1730 */ 287, 331, 332, 551, 293, 1021, 1385, 337, 473, 200,
163606
- /* 1740 */ 361, 106, 106, 930, 498, 1402, 231, 1401, 1285, 107,
163607
- /* 1750 */ 396, 441, 564, 563, 219, 1476, 1011, 1347, 1475, 1348,
163608
- /* 1760 */ 1346, 1345, 1021, 1224, 552, 1586, 261, 1221, 106, 106,
163609
- /* 1770 */ 1523, 201, 383, 1521, 214, 414, 107, 83, 441, 564,
163610
- /* 1780 */ 563, 406, 211, 1011, 175, 1398, 312, 553, 1011, 1011,
163611
- /* 1790 */ 1013, 1014, 27, 226, 184, 169, 100, 554, 79, 4,
163612
- /* 1800 */ 82, 457, 35, 179, 458, 177, 491, 238, 96, 1481,
163613
- /* 1810 */ 447, 180, 1404, 557, 181, 1011, 1011, 1013, 1014, 27,
163614
- /* 1820 */ 182, 1403, 394, 36, 465, 1406, 397, 188, 1470, 480,
163615
- /* 1830 */ 242, 89, 1492, 486, 342, 244, 441, 273, 192, 346,
163616
- /* 1840 */ 489, 245, 399, 1248, 428, 246, 507, 1296, 551, 91,
163617
- /* 1850 */ 877, 1305, 1304, 220, 1601, 1295, 1303, 430, 431, 516,
163618
- /* 1860 */ 1569, 259, 400, 302, 1600, 1275, 303, 260, 360, 1274,
163619
- /* 1870 */ 1273, 1599, 366, 1555, 434, 1554, 1370, 1021, 1369, 542,
163620
- /* 1880 */ 126, 10, 1456, 106, 106, 377, 102, 97, 310, 526,
163621
- /* 1890 */ 34, 107, 566, 441, 564, 563, 1178, 271, 1011, 268,
163622
- /* 1900 */ 270, 567, 1243, 1238, 206, 1328, 375, 381, 1327, 382,
163623
- /* 1910 */ 407, 161, 174, 408, 1508, 1509, 143, 300, 830, 162,
163624
- /* 1920 */ 1507, 1506, 163, 442, 208, 314, 227, 216, 217, 78,
163625
- /* 1930 */ 1011, 1011, 1013, 1014, 27, 140, 1082, 322, 1080, 165,
163626
- /* 1940 */ 176, 1204, 234, 178, 909, 330, 237, 1096, 183, 166,
163627
- /* 1950 */ 167, 417, 85, 86, 419, 185, 87, 88, 168, 1099,
163628
- /* 1960 */ 239, 1095, 240, 154, 18, 241, 341, 1218, 257, 1088,
163629
- /* 1970 */ 243, 485, 190, 189, 37, 845, 490, 362, 247, 494,
163630
- /* 1980 */ 357, 191, 875, 90, 19, 502, 354, 20, 499, 92,
163631
- /* 1990 */ 170, 155, 888, 93, 301, 509, 94, 1166, 156, 1048,
163632
- /* 2000 */ 1135, 39, 221, 1134, 276, 278, 256, 194, 110, 960,
163633
- /* 2010 */ 954, 1156, 21, 1152, 22, 1160, 1140, 1154, 23, 33,
163634
- /* 2020 */ 24, 1159, 25, 538, 26, 198, 98, 1063, 1049, 1047,
163635
- /* 2030 */ 1051, 7, 1105, 262, 1104, 263, 1052, 28, 40, 558,
163636
- /* 2040 */ 1016, 857, 109, 29, 919, 386, 139, 172, 264, 265,
163637
- /* 2050 */ 1174, 1592, 1173, 1234, 1234, 1234, 1234, 1234, 1234, 1234,
163638
- /* 2060 */ 1234, 1234, 1234, 1591,
163838
+ /* 0 */ 568, 208, 568, 118, 115, 229, 568, 118, 115, 229,
163839
+ /* 10 */ 568, 1314, 377, 1293, 408, 562, 562, 562, 568, 409,
163840
+ /* 20 */ 378, 1314, 1276, 41, 41, 41, 41, 208, 1526, 71,
163841
+ /* 30 */ 71, 971, 419, 41, 41, 491, 303, 279, 303, 972,
163842
+ /* 40 */ 397, 71, 71, 125, 126, 80, 1217, 1217, 1050, 1053,
163843
+ /* 50 */ 1040, 1040, 123, 123, 124, 124, 124, 124, 476, 409,
163844
+ /* 60 */ 1241, 1, 1, 575, 2, 1245, 550, 118, 115, 229,
163845
+ /* 70 */ 317, 480, 146, 480, 524, 118, 115, 229, 529, 1327,
163846
+ /* 80 */ 417, 523, 142, 125, 126, 80, 1217, 1217, 1050, 1053,
163847
+ /* 90 */ 1040, 1040, 123, 123, 124, 124, 124, 124, 118, 115,
163848
+ /* 100 */ 229, 327, 122, 122, 122, 122, 121, 121, 120, 120,
163849
+ /* 110 */ 120, 119, 116, 444, 284, 284, 284, 284, 442, 442,
163850
+ /* 120 */ 442, 1567, 376, 1569, 1192, 375, 1163, 565, 1163, 565,
163851
+ /* 130 */ 409, 1567, 537, 259, 226, 444, 101, 145, 449, 316,
163852
+ /* 140 */ 559, 240, 122, 122, 122, 122, 121, 121, 120, 120,
163853
+ /* 150 */ 120, 119, 116, 444, 125, 126, 80, 1217, 1217, 1050,
163854
+ /* 160 */ 1053, 1040, 1040, 123, 123, 124, 124, 124, 124, 142,
163855
+ /* 170 */ 294, 1192, 339, 448, 120, 120, 120, 119, 116, 444,
163856
+ /* 180 */ 127, 1192, 1193, 1194, 148, 441, 440, 568, 119, 116,
163857
+ /* 190 */ 444, 124, 124, 124, 124, 117, 122, 122, 122, 122,
163858
+ /* 200 */ 121, 121, 120, 120, 120, 119, 116, 444, 454, 113,
163859
+ /* 210 */ 13, 13, 546, 122, 122, 122, 122, 121, 121, 120,
163860
+ /* 220 */ 120, 120, 119, 116, 444, 422, 316, 559, 1192, 1193,
163861
+ /* 230 */ 1194, 149, 1224, 409, 1224, 124, 124, 124, 124, 122,
163862
+ /* 240 */ 122, 122, 122, 121, 121, 120, 120, 120, 119, 116,
163863
+ /* 250 */ 444, 465, 342, 1037, 1037, 1051, 1054, 125, 126, 80,
163864
+ /* 260 */ 1217, 1217, 1050, 1053, 1040, 1040, 123, 123, 124, 124,
163865
+ /* 270 */ 124, 124, 1279, 522, 222, 1192, 568, 409, 224, 514,
163866
+ /* 280 */ 175, 82, 83, 122, 122, 122, 122, 121, 121, 120,
163867
+ /* 290 */ 120, 120, 119, 116, 444, 1007, 16, 16, 1192, 133,
163868
+ /* 300 */ 133, 125, 126, 80, 1217, 1217, 1050, 1053, 1040, 1040,
163869
+ /* 310 */ 123, 123, 124, 124, 124, 124, 122, 122, 122, 122,
163870
+ /* 320 */ 121, 121, 120, 120, 120, 119, 116, 444, 1041, 546,
163871
+ /* 330 */ 1192, 373, 1192, 1193, 1194, 252, 1434, 399, 504, 501,
163872
+ /* 340 */ 500, 111, 560, 566, 4, 926, 926, 433, 499, 340,
163873
+ /* 350 */ 460, 328, 360, 394, 1237, 1192, 1193, 1194, 563, 568,
163874
+ /* 360 */ 122, 122, 122, 122, 121, 121, 120, 120, 120, 119,
163875
+ /* 370 */ 116, 444, 284, 284, 369, 1580, 1607, 441, 440, 154,
163876
+ /* 380 */ 409, 445, 71, 71, 1286, 565, 1221, 1192, 1193, 1194,
163877
+ /* 390 */ 85, 1223, 271, 557, 543, 515, 1561, 568, 98, 1222,
163878
+ /* 400 */ 6, 1278, 472, 142, 125, 126, 80, 1217, 1217, 1050,
163879
+ /* 410 */ 1053, 1040, 1040, 123, 123, 124, 124, 124, 124, 550,
163880
+ /* 420 */ 13, 13, 1027, 507, 1224, 1192, 1224, 549, 109, 109,
163881
+ /* 430 */ 222, 568, 1238, 175, 568, 427, 110, 197, 445, 570,
163882
+ /* 440 */ 569, 430, 1552, 1017, 325, 551, 1192, 270, 287, 368,
163883
+ /* 450 */ 510, 363, 509, 257, 71, 71, 543, 71, 71, 359,
163884
+ /* 460 */ 316, 559, 1613, 122, 122, 122, 122, 121, 121, 120,
163885
+ /* 470 */ 120, 120, 119, 116, 444, 1017, 1017, 1019, 1020, 27,
163886
+ /* 480 */ 284, 284, 1192, 1193, 1194, 1158, 568, 1612, 409, 901,
163887
+ /* 490 */ 190, 550, 356, 565, 550, 937, 533, 517, 1158, 516,
163888
+ /* 500 */ 413, 1158, 552, 1192, 1193, 1194, 568, 544, 1554, 51,
163889
+ /* 510 */ 51, 214, 125, 126, 80, 1217, 1217, 1050, 1053, 1040,
163890
+ /* 520 */ 1040, 123, 123, 124, 124, 124, 124, 1192, 474, 135,
163891
+ /* 530 */ 135, 409, 284, 284, 1490, 505, 121, 121, 120, 120,
163892
+ /* 540 */ 120, 119, 116, 444, 1007, 565, 518, 217, 541, 1561,
163893
+ /* 550 */ 316, 559, 142, 6, 532, 125, 126, 80, 1217, 1217,
163894
+ /* 560 */ 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124, 124,
163895
+ /* 570 */ 1555, 122, 122, 122, 122, 121, 121, 120, 120, 120,
163896
+ /* 580 */ 119, 116, 444, 485, 1192, 1193, 1194, 482, 281, 1267,
163897
+ /* 590 */ 957, 252, 1192, 373, 504, 501, 500, 1192, 340, 571,
163898
+ /* 600 */ 1192, 571, 409, 292, 499, 957, 876, 191, 480, 316,
163899
+ /* 610 */ 559, 384, 290, 380, 122, 122, 122, 122, 121, 121,
163900
+ /* 620 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1217,
163901
+ /* 630 */ 1217, 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124,
163902
+ /* 640 */ 124, 409, 394, 1136, 1192, 869, 100, 284, 284, 1192,
163903
+ /* 650 */ 1193, 1194, 373, 1093, 1192, 1193, 1194, 1192, 1193, 1194,
163904
+ /* 660 */ 565, 455, 32, 373, 233, 125, 126, 80, 1217, 1217,
163905
+ /* 670 */ 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124, 124,
163906
+ /* 680 */ 1433, 959, 568, 228, 958, 122, 122, 122, 122, 121,
163907
+ /* 690 */ 121, 120, 120, 120, 119, 116, 444, 1158, 228, 1192,
163908
+ /* 700 */ 157, 1192, 1193, 1194, 1553, 13, 13, 301, 957, 1232,
163909
+ /* 710 */ 1158, 153, 409, 1158, 373, 1583, 1176, 5, 369, 1580,
163910
+ /* 720 */ 429, 1238, 3, 957, 122, 122, 122, 122, 121, 121,
163911
+ /* 730 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1217,
163912
+ /* 740 */ 1217, 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124,
163913
+ /* 750 */ 124, 409, 208, 567, 1192, 1028, 1192, 1193, 1194, 1192,
163914
+ /* 760 */ 388, 852, 155, 1552, 286, 402, 1098, 1098, 488, 568,
163915
+ /* 770 */ 465, 342, 1319, 1319, 1552, 125, 126, 80, 1217, 1217,
163916
+ /* 780 */ 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124, 124,
163917
+ /* 790 */ 129, 568, 13, 13, 374, 122, 122, 122, 122, 121,
163918
+ /* 800 */ 121, 120, 120, 120, 119, 116, 444, 302, 568, 453,
163919
+ /* 810 */ 528, 1192, 1193, 1194, 13, 13, 1192, 1193, 1194, 1297,
163920
+ /* 820 */ 463, 1267, 409, 1317, 1317, 1552, 1012, 453, 452, 200,
163921
+ /* 830 */ 299, 71, 71, 1265, 122, 122, 122, 122, 121, 121,
163922
+ /* 840 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1217,
163923
+ /* 850 */ 1217, 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124,
163924
+ /* 860 */ 124, 409, 227, 1073, 1158, 284, 284, 419, 312, 278,
163925
+ /* 870 */ 278, 285, 285, 1419, 406, 405, 382, 1158, 565, 568,
163926
+ /* 880 */ 1158, 1196, 565, 1600, 565, 125, 126, 80, 1217, 1217,
163927
+ /* 890 */ 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124, 124,
163928
+ /* 900 */ 453, 1482, 13, 13, 1536, 122, 122, 122, 122, 121,
163929
+ /* 910 */ 121, 120, 120, 120, 119, 116, 444, 201, 568, 354,
163930
+ /* 920 */ 1586, 575, 2, 1245, 840, 841, 842, 1562, 317, 1212,
163931
+ /* 930 */ 146, 6, 409, 255, 254, 253, 206, 1327, 9, 1196,
163932
+ /* 940 */ 262, 71, 71, 424, 122, 122, 122, 122, 121, 121,
163933
+ /* 950 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1217,
163934
+ /* 960 */ 1217, 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124,
163935
+ /* 970 */ 124, 568, 284, 284, 568, 1213, 409, 574, 313, 1245,
163936
+ /* 980 */ 349, 1296, 352, 419, 317, 565, 146, 491, 525, 1643,
163937
+ /* 990 */ 395, 371, 491, 1327, 70, 70, 1295, 71, 71, 240,
163938
+ /* 1000 */ 1325, 104, 80, 1217, 1217, 1050, 1053, 1040, 1040, 123,
163939
+ /* 1010 */ 123, 124, 124, 124, 124, 122, 122, 122, 122, 121,
163940
+ /* 1020 */ 121, 120, 120, 120, 119, 116, 444, 1114, 284, 284,
163941
+ /* 1030 */ 428, 448, 1525, 1213, 439, 284, 284, 1489, 1352, 311,
163942
+ /* 1040 */ 474, 565, 1115, 971, 491, 491, 217, 1263, 565, 1538,
163943
+ /* 1050 */ 568, 972, 207, 568, 1027, 240, 383, 1116, 519, 122,
163944
+ /* 1060 */ 122, 122, 122, 121, 121, 120, 120, 120, 119, 116,
163945
+ /* 1070 */ 444, 1018, 107, 71, 71, 1017, 13, 13, 912, 568,
163946
+ /* 1080 */ 1495, 568, 284, 284, 97, 526, 491, 448, 913, 1326,
163947
+ /* 1090 */ 1322, 545, 409, 284, 284, 565, 151, 209, 1495, 1497,
163948
+ /* 1100 */ 262, 450, 55, 55, 56, 56, 565, 1017, 1017, 1019,
163949
+ /* 1110 */ 443, 332, 409, 527, 12, 295, 125, 126, 80, 1217,
163950
+ /* 1120 */ 1217, 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124,
163951
+ /* 1130 */ 124, 347, 409, 864, 1534, 1213, 125, 126, 80, 1217,
163952
+ /* 1140 */ 1217, 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124,
163953
+ /* 1150 */ 124, 1137, 1641, 474, 1641, 371, 125, 114, 80, 1217,
163954
+ /* 1160 */ 1217, 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124,
163955
+ /* 1170 */ 124, 1495, 329, 474, 331, 122, 122, 122, 122, 121,
163956
+ /* 1180 */ 121, 120, 120, 120, 119, 116, 444, 203, 1419, 568,
163957
+ /* 1190 */ 1294, 864, 464, 1213, 436, 122, 122, 122, 122, 121,
163958
+ /* 1200 */ 121, 120, 120, 120, 119, 116, 444, 553, 1137, 1642,
163959
+ /* 1210 */ 539, 1642, 15, 15, 892, 122, 122, 122, 122, 121,
163960
+ /* 1220 */ 121, 120, 120, 120, 119, 116, 444, 568, 298, 538,
163961
+ /* 1230 */ 1135, 1419, 1559, 1560, 1331, 409, 6, 6, 1169, 1268,
163962
+ /* 1240 */ 415, 320, 284, 284, 1419, 508, 565, 525, 300, 457,
163963
+ /* 1250 */ 43, 43, 568, 893, 12, 565, 330, 478, 425, 407,
163964
+ /* 1260 */ 126, 80, 1217, 1217, 1050, 1053, 1040, 1040, 123, 123,
163965
+ /* 1270 */ 124, 124, 124, 124, 568, 57, 57, 288, 1192, 1419,
163966
+ /* 1280 */ 496, 458, 392, 392, 391, 273, 389, 1135, 1558, 849,
163967
+ /* 1290 */ 1169, 407, 6, 568, 321, 1158, 470, 44, 44, 1557,
163968
+ /* 1300 */ 1114, 426, 234, 6, 323, 256, 540, 256, 1158, 431,
163969
+ /* 1310 */ 568, 1158, 322, 17, 487, 1115, 58, 58, 122, 122,
163970
+ /* 1320 */ 122, 122, 121, 121, 120, 120, 120, 119, 116, 444,
163971
+ /* 1330 */ 1116, 216, 481, 59, 59, 1192, 1193, 1194, 111, 560,
163972
+ /* 1340 */ 324, 4, 236, 456, 526, 568, 237, 456, 568, 437,
163973
+ /* 1350 */ 168, 556, 420, 141, 479, 563, 568, 293, 568, 1095,
163974
+ /* 1360 */ 568, 293, 568, 1095, 531, 568, 872, 8, 60, 60,
163975
+ /* 1370 */ 235, 61, 61, 568, 414, 568, 414, 568, 445, 62,
163976
+ /* 1380 */ 62, 45, 45, 46, 46, 47, 47, 199, 49, 49,
163977
+ /* 1390 */ 557, 568, 359, 568, 100, 486, 50, 50, 63, 63,
163978
+ /* 1400 */ 64, 64, 561, 415, 535, 410, 568, 1027, 568, 534,
163979
+ /* 1410 */ 316, 559, 316, 559, 65, 65, 14, 14, 568, 1027,
163980
+ /* 1420 */ 568, 512, 932, 872, 1018, 109, 109, 931, 1017, 66,
163981
+ /* 1430 */ 66, 131, 131, 110, 451, 445, 570, 569, 416, 177,
163982
+ /* 1440 */ 1017, 132, 132, 67, 67, 568, 467, 568, 932, 471,
163983
+ /* 1450 */ 1364, 283, 226, 931, 315, 1363, 407, 568, 459, 407,
163984
+ /* 1460 */ 1017, 1017, 1019, 239, 407, 86, 213, 1350, 52, 52,
163985
+ /* 1470 */ 68, 68, 1017, 1017, 1019, 1020, 27, 1585, 1180, 447,
163986
+ /* 1480 */ 69, 69, 288, 97, 108, 1541, 106, 392, 392, 391,
163987
+ /* 1490 */ 273, 389, 568, 879, 849, 883, 568, 111, 560, 466,
163988
+ /* 1500 */ 4, 568, 152, 30, 38, 568, 1132, 234, 396, 323,
163989
+ /* 1510 */ 111, 560, 527, 4, 563, 53, 53, 322, 568, 163,
163990
+ /* 1520 */ 163, 568, 337, 468, 164, 164, 333, 563, 76, 76,
163991
+ /* 1530 */ 568, 289, 1514, 568, 31, 1513, 568, 445, 338, 483,
163992
+ /* 1540 */ 100, 54, 54, 344, 72, 72, 296, 236, 1080, 557,
163993
+ /* 1550 */ 445, 879, 1360, 134, 134, 168, 73, 73, 141, 161,
163994
+ /* 1560 */ 161, 1574, 557, 535, 568, 319, 568, 348, 536, 1009,
163995
+ /* 1570 */ 473, 261, 261, 891, 890, 235, 535, 568, 1027, 568,
163996
+ /* 1580 */ 475, 534, 261, 367, 109, 109, 521, 136, 136, 130,
163997
+ /* 1590 */ 130, 1027, 110, 366, 445, 570, 569, 109, 109, 1017,
163998
+ /* 1600 */ 162, 162, 156, 156, 568, 110, 1080, 445, 570, 569,
163999
+ /* 1610 */ 410, 351, 1017, 568, 353, 316, 559, 568, 343, 568,
164000
+ /* 1620 */ 100, 497, 357, 258, 100, 898, 899, 140, 140, 355,
164001
+ /* 1630 */ 1310, 1017, 1017, 1019, 1020, 27, 139, 139, 362, 451,
164002
+ /* 1640 */ 137, 137, 138, 138, 1017, 1017, 1019, 1020, 27, 1180,
164003
+ /* 1650 */ 447, 568, 372, 288, 111, 560, 1021, 4, 392, 392,
164004
+ /* 1660 */ 391, 273, 389, 568, 1141, 849, 568, 1076, 568, 258,
164005
+ /* 1670 */ 492, 563, 568, 211, 75, 75, 555, 962, 234, 261,
164006
+ /* 1680 */ 323, 111, 560, 929, 4, 113, 77, 77, 322, 74,
164007
+ /* 1690 */ 74, 42, 42, 1373, 445, 48, 48, 1418, 563, 974,
164008
+ /* 1700 */ 975, 1092, 1091, 1092, 1091, 862, 557, 150, 930, 1346,
164009
+ /* 1710 */ 113, 1358, 554, 1424, 1021, 1275, 1266, 1254, 236, 1253,
164010
+ /* 1720 */ 1255, 445, 1593, 1343, 308, 276, 168, 309, 11, 141,
164011
+ /* 1730 */ 393, 310, 232, 557, 1405, 1027, 335, 291, 1400, 219,
164012
+ /* 1740 */ 336, 109, 109, 936, 297, 1410, 235, 341, 477, 110,
164013
+ /* 1750 */ 502, 445, 570, 569, 1393, 1409, 1017, 400, 1293, 365,
164014
+ /* 1760 */ 223, 1486, 1027, 1485, 1355, 1356, 1354, 1353, 109, 109,
164015
+ /* 1770 */ 204, 1596, 1232, 558, 265, 218, 110, 205, 445, 570,
164016
+ /* 1780 */ 569, 410, 387, 1017, 1533, 179, 316, 559, 1017, 1017,
164017
+ /* 1790 */ 1019, 1020, 27, 230, 1531, 1229, 79, 560, 85, 4,
164018
+ /* 1800 */ 418, 215, 548, 81, 84, 188, 1406, 173, 181, 461,
164019
+ /* 1810 */ 451, 35, 462, 563, 183, 1017, 1017, 1019, 1020, 27,
164020
+ /* 1820 */ 184, 1491, 185, 186, 495, 242, 98, 398, 1412, 36,
164021
+ /* 1830 */ 1411, 484, 91, 469, 401, 1414, 445, 192, 1480, 246,
164022
+ /* 1840 */ 1502, 490, 346, 277, 248, 196, 493, 511, 557, 350,
164023
+ /* 1850 */ 1256, 249, 250, 403, 1313, 1312, 111, 560, 432, 4,
164024
+ /* 1860 */ 1311, 1304, 93, 1611, 883, 1610, 224, 404, 434, 520,
164025
+ /* 1870 */ 263, 435, 1579, 563, 1283, 1282, 364, 1027, 306, 1281,
164026
+ /* 1880 */ 264, 1609, 1565, 109, 109, 370, 1303, 307, 1564, 438,
164027
+ /* 1890 */ 128, 110, 1378, 445, 570, 569, 445, 546, 1017, 10,
164028
+ /* 1900 */ 1466, 105, 381, 1377, 34, 572, 99, 1336, 557, 314,
164029
+ /* 1910 */ 1186, 530, 272, 274, 379, 210, 1335, 547, 385, 386,
164030
+ /* 1920 */ 275, 573, 1251, 1246, 411, 412, 1518, 165, 178, 1519,
164031
+ /* 1930 */ 1017, 1017, 1019, 1020, 27, 1517, 1516, 1027, 78, 147,
164032
+ /* 1940 */ 166, 220, 221, 109, 109, 836, 304, 167, 446, 212,
164033
+ /* 1950 */ 318, 110, 231, 445, 570, 569, 144, 1090, 1017, 1088,
164034
+ /* 1960 */ 326, 180, 169, 1212, 182, 334, 238, 915, 241, 1104,
164035
+ /* 1970 */ 187, 170, 171, 421, 87, 88, 423, 189, 89, 90,
164036
+ /* 1980 */ 172, 1107, 243, 1103, 244, 158, 18, 245, 345, 247,
164037
+ /* 1990 */ 1017, 1017, 1019, 1020, 27, 261, 1096, 193, 1226, 489,
164038
+ /* 2000 */ 194, 37, 366, 851, 494, 251, 195, 506, 92, 19,
164039
+ /* 2010 */ 498, 358, 20, 503, 881, 361, 94, 894, 305, 159,
164040
+ /* 2020 */ 513, 39, 95, 1174, 160, 1056, 966, 1143, 96, 174,
164041
+ /* 2030 */ 1142, 225, 280, 282, 198, 960, 113, 1164, 1160, 260,
164042
+ /* 2040 */ 21, 22, 23, 1162, 1168, 1167, 1148, 24, 33, 25,
164043
+ /* 2050 */ 202, 542, 26, 100, 1071, 102, 1057, 103, 7, 1055,
164044
+ /* 2060 */ 1059, 1113, 1060, 1112, 266, 267, 28, 40, 390, 1022,
164045
+ /* 2070 */ 863, 112, 29, 564, 1182, 1181, 268, 176, 143, 925,
164046
+ /* 2080 */ 1242, 1242, 1242, 1242, 1242, 1242, 1242, 1242, 1242, 1242,
164047
+ /* 2090 */ 1242, 1242, 1242, 1242, 269, 1602, 1242, 1601,
163639164048
};
163640164049
static const YYCODETYPE yy_lookahead[] = {
163641164050
/* 0 */ 193, 193, 193, 274, 275, 276, 193, 274, 275, 276,
163642164051
/* 10 */ 193, 223, 219, 225, 206, 210, 211, 212, 193, 19,
163643164052
/* 20 */ 219, 233, 216, 216, 217, 216, 217, 193, 295, 216,
@@ -163799,57 +164208,57 @@
163799164208
/* 1580 */ 23, 90, 25, 121, 106, 107, 19, 216, 217, 216,
163800164209
/* 1590 */ 217, 100, 114, 131, 116, 117, 118, 106, 107, 121,
163801164210
/* 1600 */ 216, 217, 216, 217, 193, 114, 117, 116, 117, 118,
163802164211
/* 1610 */ 133, 193, 121, 193, 193, 138, 139, 193, 23, 193,
163803164212
/* 1620 */ 25, 23, 23, 25, 25, 7, 8, 216, 217, 193,
163804
- /* 1630 */ 193, 153, 154, 155, 156, 157, 216, 217, 59, 162,
164213
+ /* 1630 */ 193, 153, 154, 155, 156, 157, 216, 217, 193, 162,
163805164214
/* 1640 */ 216, 217, 216, 217, 153, 154, 155, 156, 157, 1,
163806
- /* 1650 */ 2, 193, 193, 5, 19, 20, 193, 22, 10, 11,
163807
- /* 1660 */ 12, 13, 14, 193, 97, 17, 193, 23, 23, 25,
163808
- /* 1670 */ 25, 36, 83, 84, 216, 217, 236, 23, 30, 25,
163809
- /* 1680 */ 32, 19, 20, 153, 22, 155, 216, 217, 40, 216,
163810
- /* 1690 */ 217, 153, 193, 155, 59, 23, 117, 25, 36, 23,
163811
- /* 1700 */ 193, 25, 193, 193, 193, 193, 71, 193, 242, 193,
163812
- /* 1710 */ 193, 193, 193, 193, 243, 288, 287, 214, 70, 255,
163813
- /* 1720 */ 255, 59, 255, 255, 191, 297, 78, 271, 267, 81,
163814
- /* 1730 */ 245, 293, 246, 71, 246, 100, 267, 245, 293, 249,
163815
- /* 1740 */ 219, 106, 107, 108, 220, 271, 98, 271, 225, 114,
163816
- /* 1750 */ 271, 116, 117, 118, 229, 219, 121, 259, 219, 259,
163817
- /* 1760 */ 259, 259, 100, 60, 280, 196, 141, 38, 106, 107,
163818
- /* 1770 */ 200, 249, 245, 200, 243, 200, 114, 151, 116, 117,
163819
- /* 1780 */ 118, 133, 150, 121, 297, 272, 138, 139, 153, 154,
163820
- /* 1790 */ 155, 156, 157, 297, 22, 43, 19, 20, 294, 22,
163821
- /* 1800 */ 294, 18, 270, 237, 200, 234, 18, 199, 149, 283,
163822
- /* 1810 */ 162, 237, 272, 36, 237, 153, 154, 155, 156, 157,
163823
- /* 1820 */ 237, 272, 246, 270, 246, 234, 246, 234, 246, 200,
163824
- /* 1830 */ 199, 158, 290, 62, 289, 199, 59, 200, 22, 200,
163825
- /* 1840 */ 221, 199, 221, 200, 64, 199, 115, 227, 71, 22,
163826
- /* 1850 */ 126, 218, 218, 165, 224, 227, 218, 24, 113, 305,
163827
- /* 1860 */ 312, 200, 221, 282, 224, 218, 282, 91, 218, 220,
163828
- /* 1870 */ 218, 218, 221, 317, 82, 317, 265, 100, 265, 145,
163829
- /* 1880 */ 148, 22, 277, 106, 107, 200, 158, 147, 279, 146,
163830
- /* 1890 */ 25, 114, 202, 116, 117, 118, 13, 6, 121, 194,
163831
- /* 1900 */ 194, 192, 192, 192, 248, 250, 249, 247, 250, 246,
163832
- /* 1910 */ 303, 207, 300, 303, 213, 213, 222, 222, 4, 207,
163833
- /* 1920 */ 213, 213, 207, 3, 22, 163, 15, 214, 214, 213,
163834
- /* 1930 */ 153, 154, 155, 156, 157, 16, 23, 139, 23, 130,
163835
- /* 1940 */ 151, 25, 24, 142, 20, 16, 144, 1, 142, 130,
163836
- /* 1950 */ 130, 61, 53, 53, 37, 151, 53, 53, 130, 116,
163837
- /* 1960 */ 34, 1, 141, 5, 22, 115, 161, 75, 25, 68,
163838
- /* 1970 */ 141, 41, 115, 68, 24, 20, 19, 131, 125, 67,
163839
- /* 1980 */ 24, 22, 59, 22, 22, 96, 23, 22, 67, 22,
163840
- /* 1990 */ 37, 23, 28, 149, 67, 22, 25, 23, 23, 23,
163841
- /* 2000 */ 23, 22, 141, 97, 23, 23, 34, 22, 25, 116,
163842
- /* 2010 */ 143, 75, 34, 88, 34, 75, 23, 86, 34, 22,
163843
- /* 2020 */ 34, 93, 34, 24, 34, 25, 25, 23, 23, 23,
163844
- /* 2030 */ 23, 44, 23, 25, 23, 22, 11, 22, 22, 25,
163845
- /* 2040 */ 23, 23, 22, 22, 135, 15, 23, 25, 141, 141,
163846
- /* 2050 */ 1, 141, 1, 319, 319, 319, 319, 319, 319, 319,
163847
- /* 2060 */ 319, 319, 319, 141, 319, 319, 319, 319, 319, 319,
163848
- /* 2070 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
164215
+ /* 1650 */ 2, 193, 193, 5, 19, 20, 59, 22, 10, 11,
164216
+ /* 1660 */ 12, 13, 14, 193, 97, 17, 193, 23, 193, 25,
164217
+ /* 1670 */ 288, 36, 193, 242, 216, 217, 236, 23, 30, 25,
164218
+ /* 1680 */ 32, 19, 20, 23, 22, 25, 216, 217, 40, 216,
164219
+ /* 1690 */ 217, 216, 217, 193, 59, 216, 217, 193, 36, 83,
164220
+ /* 1700 */ 84, 153, 153, 155, 155, 23, 71, 25, 23, 193,
164221
+ /* 1710 */ 25, 193, 193, 193, 117, 193, 193, 193, 70, 193,
164222
+ /* 1720 */ 193, 59, 193, 255, 255, 287, 78, 255, 243, 81,
164223
+ /* 1730 */ 191, 255, 297, 71, 271, 100, 293, 245, 267, 214,
164224
+ /* 1740 */ 246, 106, 107, 108, 246, 271, 98, 245, 293, 114,
164225
+ /* 1750 */ 220, 116, 117, 118, 267, 271, 121, 271, 225, 219,
164226
+ /* 1760 */ 229, 219, 100, 219, 259, 259, 259, 259, 106, 107,
164227
+ /* 1770 */ 249, 196, 60, 280, 141, 243, 114, 249, 116, 117,
164228
+ /* 1780 */ 118, 133, 245, 121, 200, 297, 138, 139, 153, 154,
164229
+ /* 1790 */ 155, 156, 157, 297, 200, 38, 19, 20, 151, 22,
164230
+ /* 1800 */ 200, 150, 140, 294, 294, 22, 272, 43, 234, 18,
164231
+ /* 1810 */ 162, 270, 200, 36, 237, 153, 154, 155, 156, 157,
164232
+ /* 1820 */ 237, 283, 237, 237, 18, 199, 149, 246, 272, 270,
164233
+ /* 1830 */ 272, 200, 158, 246, 246, 234, 59, 234, 246, 199,
164234
+ /* 1840 */ 290, 62, 289, 200, 199, 22, 221, 115, 71, 200,
164235
+ /* 1850 */ 200, 199, 199, 221, 218, 218, 19, 20, 64, 22,
164236
+ /* 1860 */ 218, 227, 22, 224, 126, 224, 165, 221, 24, 305,
164237
+ /* 1870 */ 200, 113, 312, 36, 218, 220, 218, 100, 282, 218,
164238
+ /* 1880 */ 91, 218, 317, 106, 107, 221, 227, 282, 317, 82,
164239
+ /* 1890 */ 148, 114, 265, 116, 117, 118, 59, 145, 121, 22,
164240
+ /* 1900 */ 277, 158, 200, 265, 25, 202, 147, 250, 71, 279,
164241
+ /* 1910 */ 13, 146, 194, 194, 249, 248, 250, 140, 247, 246,
164242
+ /* 1920 */ 6, 192, 192, 192, 303, 303, 213, 207, 300, 213,
164243
+ /* 1930 */ 153, 154, 155, 156, 157, 213, 213, 100, 213, 222,
164244
+ /* 1940 */ 207, 214, 214, 106, 107, 4, 222, 207, 3, 22,
164245
+ /* 1950 */ 163, 114, 15, 116, 117, 118, 16, 23, 121, 23,
164246
+ /* 1960 */ 139, 151, 130, 25, 142, 16, 24, 20, 144, 1,
164247
+ /* 1970 */ 142, 130, 130, 61, 53, 53, 37, 151, 53, 53,
164248
+ /* 1980 */ 130, 116, 34, 1, 141, 5, 22, 115, 161, 141,
164249
+ /* 1990 */ 153, 154, 155, 156, 157, 25, 68, 68, 75, 41,
164250
+ /* 2000 */ 115, 24, 131, 20, 19, 125, 22, 96, 22, 22,
164251
+ /* 2010 */ 67, 23, 22, 67, 59, 24, 22, 28, 67, 23,
164252
+ /* 2020 */ 22, 22, 149, 23, 23, 23, 116, 23, 25, 37,
164253
+ /* 2030 */ 97, 141, 23, 23, 22, 143, 25, 75, 88, 34,
164254
+ /* 2040 */ 34, 34, 34, 86, 75, 93, 23, 34, 22, 34,
164255
+ /* 2050 */ 25, 24, 34, 25, 23, 142, 23, 142, 44, 23,
164256
+ /* 2060 */ 23, 23, 11, 23, 25, 22, 22, 22, 15, 23,
164257
+ /* 2070 */ 23, 22, 22, 25, 1, 1, 141, 25, 23, 135,
163849164258
/* 2080 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
163850
- /* 2090 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
164259
+ /* 2090 */ 319, 319, 319, 319, 141, 141, 319, 141, 319, 319,
163851164260
/* 2100 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
163852164261
/* 2110 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
163853164262
/* 2120 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
163854164263
/* 2130 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
163855164264
/* 2140 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
@@ -163860,77 +164269,82 @@
163860164269
/* 2190 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
163861164270
/* 2200 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
163862164271
/* 2210 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
163863164272
/* 2220 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
163864164273
/* 2230 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
163865
- /* 2240 */ 319, 319, 319, 319, 319, 319, 319, 319, 319,
164274
+ /* 2240 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
164275
+ /* 2250 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
164276
+ /* 2260 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
164277
+ /* 2270 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
164278
+ /* 2280 */ 319, 319, 319,
163866164279
};
163867
-#define YY_SHIFT_COUNT (569)
164280
+#define YY_SHIFT_COUNT (575)
163868164281
#define YY_SHIFT_MIN (0)
163869
-#define YY_SHIFT_MAX (2051)
164282
+#define YY_SHIFT_MAX (2074)
163870164283
static const unsigned short int yy_shift_ofst[] = {
163871
- /* 0 */ 1648, 1477, 1272, 322, 322, 1, 1319, 1478, 1491, 1662,
163872
- /* 10 */ 1662, 1662, 471, 0, 0, 214, 1093, 1662, 1662, 1662,
163873
- /* 20 */ 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662,
164284
+ /* 0 */ 1648, 1477, 1272, 322, 322, 1, 1319, 1478, 1491, 1837,
164285
+ /* 10 */ 1837, 1837, 471, 0, 0, 214, 1093, 1837, 1837, 1837,
164286
+ /* 20 */ 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837,
163874164287
/* 30 */ 271, 271, 1219, 1219, 216, 88, 1, 1, 1, 1,
163875164288
/* 40 */ 1, 40, 111, 258, 361, 469, 512, 583, 622, 693,
163876164289
/* 50 */ 732, 803, 842, 913, 1073, 1093, 1093, 1093, 1093, 1093,
163877164290
/* 60 */ 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093,
163878164291
/* 70 */ 1093, 1093, 1093, 1113, 1093, 1216, 957, 957, 1635, 1662,
163879
- /* 80 */ 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662,
163880
- /* 90 */ 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662,
163881
- /* 100 */ 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662,
163882
- /* 110 */ 1662, 1662, 1662, 1662, 1777, 1662, 1662, 1662, 1662, 1662,
163883
- /* 120 */ 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 137, 181,
163884
- /* 130 */ 181, 181, 181, 181, 94, 430, 66, 65, 112, 366,
163885
- /* 140 */ 533, 533, 740, 1261, 533, 533, 79, 79, 533, 412,
163886
- /* 150 */ 412, 412, 77, 412, 123, 113, 113, 22, 22, 2064,
163887
- /* 160 */ 2064, 328, 328, 328, 239, 468, 468, 468, 468, 1015,
163888
- /* 170 */ 1015, 409, 366, 1129, 1186, 533, 533, 533, 533, 533,
164292
+ /* 80 */ 1777, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837,
164293
+ /* 90 */ 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837,
164294
+ /* 100 */ 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837,
164295
+ /* 110 */ 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837,
164296
+ /* 120 */ 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837,
164297
+ /* 130 */ 137, 181, 181, 181, 181, 181, 181, 181, 94, 430,
164298
+ /* 140 */ 66, 65, 112, 366, 533, 533, 740, 1261, 533, 533,
164299
+ /* 150 */ 79, 79, 533, 412, 412, 412, 77, 412, 123, 113,
164300
+ /* 160 */ 113, 22, 22, 2098, 2098, 328, 328, 328, 239, 468,
164301
+ /* 170 */ 468, 468, 468, 1015, 1015, 409, 366, 1129, 1186, 533,
163889164302
/* 180 */ 533, 533, 533, 533, 533, 533, 533, 533, 533, 533,
163890
- /* 190 */ 533, 533, 533, 533, 533, 969, 621, 621, 533, 642,
163891
- /* 200 */ 788, 788, 1228, 1228, 822, 822, 67, 1274, 2064, 2064,
163892
- /* 210 */ 2064, 2064, 2064, 2064, 2064, 1307, 954, 954, 585, 472,
163893
- /* 220 */ 640, 387, 695, 538, 541, 700, 533, 533, 533, 533,
163894
- /* 230 */ 533, 533, 533, 533, 533, 533, 222, 533, 533, 533,
163895
- /* 240 */ 533, 533, 533, 533, 533, 533, 533, 533, 533, 1179,
163896
- /* 250 */ 1179, 1179, 533, 533, 533, 565, 533, 533, 533, 916,
163897
- /* 260 */ 1144, 533, 533, 1288, 533, 533, 533, 533, 533, 533,
163898
- /* 270 */ 533, 533, 639, 1330, 209, 1076, 1076, 1076, 1076, 580,
163899
- /* 280 */ 209, 209, 1313, 768, 917, 649, 1181, 1316, 405, 1316,
163900
- /* 290 */ 1238, 249, 1181, 1181, 249, 1181, 405, 1238, 1369, 464,
163901
- /* 300 */ 1259, 1012, 1012, 1012, 1368, 1368, 1368, 1368, 184, 184,
163902
- /* 310 */ 1326, 904, 1287, 1480, 1703, 1703, 1625, 1625, 1729, 1729,
163903
- /* 320 */ 1625, 1626, 1632, 1772, 1752, 1783, 1783, 1783, 1783, 1625,
163904
- /* 330 */ 1788, 1659, 1632, 1632, 1659, 1772, 1752, 1659, 1752, 1659,
163905
- /* 340 */ 1625, 1788, 1673, 1771, 1625, 1788, 1816, 1625, 1788, 1625,
163906
- /* 350 */ 1788, 1816, 1731, 1731, 1731, 1780, 1827, 1827, 1816, 1731,
163907
- /* 360 */ 1724, 1731, 1780, 1731, 1731, 1688, 1833, 1745, 1745, 1816,
163908
- /* 370 */ 1625, 1776, 1776, 1792, 1792, 1732, 1734, 1859, 1625, 1728,
163909
- /* 380 */ 1732, 1740, 1743, 1659, 1865, 1883, 1883, 1891, 1891, 1891,
163910
- /* 390 */ 2064, 2064, 2064, 2064, 2064, 2064, 2064, 2064, 2064, 2064,
163911
- /* 400 */ 2064, 2064, 2064, 2064, 2064, 207, 1095, 331, 620, 903,
163912
- /* 410 */ 806, 1074, 1483, 1432, 1481, 1322, 1370, 1394, 1515, 1291,
163913
- /* 420 */ 1546, 1547, 1557, 1595, 1598, 1599, 1434, 1453, 1618, 1462,
163914
- /* 430 */ 1567, 1489, 1644, 1645, 1589, 1654, 1530, 1538, 1672, 1676,
163915
- /* 440 */ 1579, 742, 1914, 1920, 1902, 1762, 1911, 1919, 1913, 1915,
163916
- /* 450 */ 1798, 1789, 1809, 1916, 1916, 1918, 1801, 1924, 1802, 1929,
163917
- /* 460 */ 1946, 1806, 1819, 1916, 1820, 1890, 1917, 1916, 1804, 1899,
163918
- /* 470 */ 1900, 1903, 1904, 1828, 1843, 1926, 1821, 1960, 1958, 1942,
163919
- /* 480 */ 1850, 1805, 1901, 1943, 1905, 1892, 1930, 1829, 1857, 1950,
163920
- /* 490 */ 1955, 1957, 1846, 1853, 1959, 1912, 1961, 1962, 1963, 1965,
163921
- /* 500 */ 1921, 1923, 1956, 1889, 1964, 1967, 1927, 1953, 1968, 1844,
163922
- /* 510 */ 1973, 1974, 1975, 1976, 1971, 1977, 1979, 1906, 1861, 1981,
163923
- /* 520 */ 1982, 1893, 1972, 1985, 1867, 1983, 1978, 1980, 1984, 1986,
163924
- /* 530 */ 1925, 1936, 1931, 1987, 1940, 1928, 1988, 1993, 1997, 1999,
163925
- /* 540 */ 2000, 2001, 1990, 2004, 1983, 2005, 2006, 2007, 2009, 2008,
163926
- /* 550 */ 2011, 2013, 2025, 2015, 2016, 2017, 2018, 2020, 2021, 2014,
163927
- /* 560 */ 1909, 1907, 1908, 1910, 1922, 2022, 2023, 2030, 2049, 2051,
164303
+ /* 190 */ 533, 533, 533, 533, 533, 533, 533, 533, 533, 969,
164304
+ /* 200 */ 621, 621, 533, 642, 788, 788, 1228, 1228, 822, 822,
164305
+ /* 210 */ 67, 1274, 2098, 2098, 2098, 2098, 2098, 2098, 2098, 1307,
164306
+ /* 220 */ 954, 954, 585, 472, 640, 387, 695, 538, 541, 700,
164307
+ /* 230 */ 533, 533, 533, 533, 533, 533, 533, 533, 533, 533,
164308
+ /* 240 */ 222, 533, 533, 533, 533, 533, 533, 533, 533, 533,
164309
+ /* 250 */ 533, 533, 533, 1179, 1179, 1179, 533, 533, 533, 565,
164310
+ /* 260 */ 533, 533, 533, 916, 1144, 533, 533, 1288, 533, 533,
164311
+ /* 270 */ 533, 533, 533, 533, 533, 533, 639, 1330, 209, 1076,
164312
+ /* 280 */ 1076, 1076, 1076, 580, 209, 209, 1313, 768, 917, 649,
164313
+ /* 290 */ 1181, 1316, 405, 1316, 1238, 249, 1181, 1181, 249, 1181,
164314
+ /* 300 */ 405, 1238, 1369, 464, 1259, 1012, 1012, 1012, 1368, 1368,
164315
+ /* 310 */ 1368, 1368, 184, 184, 1326, 904, 1287, 1480, 1712, 1712,
164316
+ /* 320 */ 1633, 1633, 1757, 1757, 1633, 1647, 1651, 1783, 1764, 1791,
164317
+ /* 330 */ 1791, 1791, 1791, 1633, 1806, 1677, 1651, 1651, 1677, 1783,
164318
+ /* 340 */ 1764, 1677, 1764, 1677, 1633, 1806, 1674, 1779, 1633, 1806,
164319
+ /* 350 */ 1823, 1633, 1806, 1633, 1806, 1823, 1732, 1732, 1732, 1794,
164320
+ /* 360 */ 1840, 1840, 1823, 1732, 1738, 1732, 1794, 1732, 1732, 1701,
164321
+ /* 370 */ 1844, 1758, 1758, 1823, 1633, 1789, 1789, 1807, 1807, 1742,
164322
+ /* 380 */ 1752, 1877, 1633, 1743, 1742, 1759, 1765, 1677, 1879, 1897,
164323
+ /* 390 */ 1897, 1914, 1914, 1914, 2098, 2098, 2098, 2098, 2098, 2098,
164324
+ /* 400 */ 2098, 2098, 2098, 2098, 2098, 2098, 2098, 2098, 2098, 207,
164325
+ /* 410 */ 1095, 331, 620, 903, 806, 1074, 1483, 1432, 1481, 1322,
164326
+ /* 420 */ 1370, 1394, 1515, 1291, 1546, 1547, 1557, 1595, 1598, 1599,
164327
+ /* 430 */ 1434, 1453, 1618, 1462, 1567, 1489, 1644, 1654, 1616, 1660,
164328
+ /* 440 */ 1548, 1549, 1682, 1685, 1597, 742, 1941, 1945, 1927, 1787,
164329
+ /* 450 */ 1937, 1940, 1934, 1936, 1821, 1810, 1832, 1938, 1938, 1942,
164330
+ /* 460 */ 1822, 1947, 1824, 1949, 1968, 1828, 1841, 1938, 1842, 1912,
164331
+ /* 470 */ 1939, 1938, 1826, 1921, 1922, 1925, 1926, 1850, 1865, 1948,
164332
+ /* 480 */ 1843, 1982, 1980, 1964, 1872, 1827, 1928, 1970, 1929, 1923,
164333
+ /* 490 */ 1958, 1848, 1885, 1977, 1983, 1985, 1871, 1880, 1984, 1943,
164334
+ /* 500 */ 1986, 1987, 1988, 1990, 1946, 1955, 1991, 1911, 1989, 1994,
164335
+ /* 510 */ 1951, 1992, 1996, 1873, 1998, 2000, 2001, 2002, 2003, 2004,
164336
+ /* 520 */ 1999, 1933, 1890, 2009, 2010, 1910, 2005, 2012, 1892, 2011,
164337
+ /* 530 */ 2006, 2007, 2008, 2013, 1950, 1962, 1957, 2014, 1969, 1952,
164338
+ /* 540 */ 2015, 2023, 2026, 2027, 2025, 2028, 2018, 1913, 1915, 2031,
164339
+ /* 550 */ 2011, 2033, 2036, 2037, 2038, 2039, 2040, 2043, 2051, 2044,
164340
+ /* 560 */ 2045, 2046, 2047, 2049, 2050, 2048, 1944, 1935, 1953, 1954,
164341
+ /* 570 */ 1956, 2052, 2055, 2053, 2073, 2074,
163928164342
};
163929
-#define YY_REDUCE_COUNT (404)
164343
+#define YY_REDUCE_COUNT (408)
163930164344
#define YY_REDUCE_MIN (-271)
163931
-#define YY_REDUCE_MAX (1716)
164345
+#define YY_REDUCE_MAX (1740)
163932164346
static const short yy_reduce_ofst[] = {
163933164347
/* 0 */ -125, 733, 789, 241, 293, -123, -193, -191, -183, -187,
163934164348
/* 10 */ 166, 238, 133, -207, -199, -267, -176, -6, 204, 489,
163935164349
/* 20 */ 576, -175, 598, 686, 615, 725, 860, 778, 781, 857,
163936164350
/* 30 */ 616, 887, 87, 240, -192, 408, 626, 796, 843, 854,
@@ -163940,98 +164354,99 @@
163940164354
/* 70 */ -271, -271, -271, -271, -271, -271, -271, -271, 80, 83,
163941164355
/* 80 */ 313, 886, 888, 996, 1034, 1059, 1081, 1100, 1117, 1152,
163942164356
/* 90 */ 1155, 1163, 1165, 1167, 1169, 1172, 1180, 1182, 1184, 1198,
163943164357
/* 100 */ 1200, 1213, 1215, 1225, 1227, 1252, 1254, 1264, 1299, 1303,
163944164358
/* 110 */ 1308, 1312, 1325, 1328, 1337, 1340, 1343, 1371, 1373, 1384,
163945
- /* 120 */ 1386, 1411, 1420, 1424, 1426, 1458, 1470, 1473, -271, -271,
163946
- /* 130 */ -271, -271, -271, -271, -271, -271, -271, 138, 459, 396,
163947
- /* 140 */ -158, 470, 302, -212, 521, 201, -195, -92, 559, 630,
163948
- /* 150 */ 632, 630, -271, 632, 901, 63, 407, -271, -271, -271,
163949
- /* 160 */ -271, 161, 161, 161, 251, 335, 847, 960, 980, 537,
163950
- /* 170 */ 588, 618, 628, 688, 688, -166, -161, 674, 790, 794,
163951
- /* 180 */ 799, 851, 852, -122, 680, -120, 995, 1038, 415, 1051,
163952
- /* 190 */ 893, 798, 962, 400, 1086, 779, 923, 924, 263, 1041,
163953
- /* 200 */ 979, 990, 1083, 1097, 1031, 1194, 362, 994, 1139, 1005,
163954
- /* 210 */ 1037, 1202, 1205, 1195, 1210, -194, 56, 185, -135, 232,
163955
- /* 220 */ 522, 560, 601, 617, 669, 683, 711, 856, 908, 941,
163956
- /* 230 */ 1048, 1101, 1147, 1257, 1262, 1265, 392, 1292, 1333, 1339,
163957
- /* 240 */ 1342, 1346, 1350, 1359, 1374, 1418, 1421, 1436, 1437, 593,
163958
- /* 250 */ 755, 770, 997, 1459, 1463, 1209, 1499, 1507, 1509, 1132,
163959
- /* 260 */ 1243, 1510, 1511, 1440, 1512, 560, 1514, 1516, 1517, 1518,
163960
- /* 270 */ 1519, 1520, 1427, 1429, 1466, 1464, 1465, 1467, 1468, 1209,
163961
- /* 280 */ 1466, 1466, 1471, 1503, 1533, 1428, 1456, 1461, 1485, 1469,
163962
- /* 290 */ 1438, 1486, 1474, 1476, 1488, 1479, 1492, 1445, 1524, 1525,
163963
- /* 300 */ 1523, 1521, 1536, 1539, 1498, 1500, 1501, 1502, 1490, 1522,
163964
- /* 310 */ 1484, 1527, 1531, 1569, 1487, 1496, 1570, 1573, 1504, 1506,
163965
- /* 320 */ 1575, 1526, 1513, 1532, 1571, 1566, 1574, 1577, 1583, 1604,
163966
- /* 330 */ 1608, 1576, 1540, 1549, 1578, 1553, 1591, 1580, 1593, 1582,
163967
- /* 340 */ 1629, 1631, 1542, 1545, 1637, 1636, 1619, 1639, 1642, 1643,
163968
- /* 350 */ 1646, 1621, 1633, 1634, 1638, 1620, 1630, 1640, 1641, 1647,
163969
- /* 360 */ 1649, 1650, 1628, 1652, 1653, 1548, 1554, 1581, 1584, 1651,
163970
- /* 370 */ 1661, 1556, 1558, 1611, 1613, 1655, 1657, 1605, 1685, 1609,
163971
- /* 380 */ 1658, 1656, 1660, 1663, 1690, 1705, 1706, 1709, 1710, 1711,
163972
- /* 390 */ 1607, 1610, 1612, 1704, 1701, 1702, 1707, 1708, 1712, 1694,
163973
- /* 400 */ 1695, 1713, 1714, 1716, 1715,
164359
+ /* 120 */ 1386, 1411, 1420, 1424, 1426, 1458, 1470, 1473, 1475, 1479,
164360
+ /* 130 */ -271, -271, -271, -271, -271, -271, -271, -271, -271, -271,
164361
+ /* 140 */ -271, 138, 459, 396, -158, 470, 302, -212, 521, 201,
164362
+ /* 150 */ -195, -92, 559, 630, 632, 630, -271, 632, 901, 63,
164363
+ /* 160 */ 407, -271, -271, -271, -271, 161, 161, 161, 251, 335,
164364
+ /* 170 */ 847, 960, 980, 537, 588, 618, 628, 688, 688, -166,
164365
+ /* 180 */ -161, 674, 790, 794, 799, 851, 852, -122, 680, -120,
164366
+ /* 190 */ 995, 1038, 415, 1051, 893, 798, 962, 400, 1086, 779,
164367
+ /* 200 */ 923, 924, 263, 1041, 979, 990, 1083, 1097, 1031, 1194,
164368
+ /* 210 */ 362, 994, 1139, 1005, 1037, 1202, 1205, 1195, 1210, -194,
164369
+ /* 220 */ 56, 185, -135, 232, 522, 560, 601, 617, 669, 683,
164370
+ /* 230 */ 711, 856, 908, 941, 1048, 1101, 1147, 1257, 1262, 1265,
164371
+ /* 240 */ 392, 1292, 1333, 1339, 1342, 1346, 1350, 1359, 1374, 1418,
164372
+ /* 250 */ 1421, 1436, 1437, 593, 755, 770, 997, 1445, 1459, 1209,
164373
+ /* 260 */ 1500, 1504, 1516, 1132, 1243, 1518, 1519, 1440, 1520, 560,
164374
+ /* 270 */ 1522, 1523, 1524, 1526, 1527, 1529, 1382, 1438, 1431, 1468,
164375
+ /* 280 */ 1469, 1472, 1476, 1209, 1431, 1431, 1485, 1525, 1539, 1435,
164376
+ /* 290 */ 1463, 1471, 1492, 1487, 1443, 1494, 1474, 1484, 1498, 1486,
164377
+ /* 300 */ 1502, 1455, 1530, 1531, 1533, 1540, 1542, 1544, 1505, 1506,
164378
+ /* 310 */ 1507, 1508, 1521, 1528, 1493, 1537, 1532, 1575, 1488, 1496,
164379
+ /* 320 */ 1584, 1594, 1509, 1510, 1600, 1538, 1534, 1541, 1574, 1577,
164380
+ /* 330 */ 1583, 1585, 1586, 1612, 1626, 1581, 1556, 1558, 1587, 1559,
164381
+ /* 340 */ 1601, 1588, 1603, 1592, 1631, 1640, 1550, 1553, 1643, 1645,
164382
+ /* 350 */ 1625, 1649, 1652, 1650, 1653, 1632, 1636, 1637, 1642, 1634,
164383
+ /* 360 */ 1639, 1641, 1646, 1656, 1655, 1658, 1659, 1661, 1663, 1560,
164384
+ /* 370 */ 1564, 1596, 1605, 1664, 1670, 1565, 1571, 1627, 1638, 1657,
164385
+ /* 380 */ 1665, 1623, 1702, 1630, 1666, 1667, 1671, 1673, 1703, 1718,
164386
+ /* 390 */ 1719, 1729, 1730, 1731, 1621, 1622, 1628, 1720, 1713, 1716,
164387
+ /* 400 */ 1722, 1723, 1733, 1717, 1724, 1727, 1728, 1725, 1740,
163974164388
};
163975164389
static const YYACTIONTYPE yy_default[] = {
163976
- /* 0 */ 1637, 1637, 1637, 1465, 1232, 1343, 1232, 1232, 1232, 1465,
163977
- /* 10 */ 1465, 1465, 1232, 1373, 1373, 1518, 1265, 1232, 1232, 1232,
163978
- /* 20 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1464, 1232, 1232,
163979
- /* 30 */ 1232, 1232, 1553, 1553, 1232, 1232, 1232, 1232, 1232, 1232,
163980
- /* 40 */ 1232, 1232, 1382, 1232, 1389, 1232, 1232, 1232, 1232, 1232,
163981
- /* 50 */ 1466, 1467, 1232, 1232, 1232, 1517, 1519, 1482, 1396, 1395,
163982
- /* 60 */ 1394, 1393, 1500, 1361, 1387, 1380, 1384, 1460, 1461, 1459,
163983
- /* 70 */ 1463, 1467, 1466, 1232, 1383, 1430, 1444, 1429, 1232, 1232,
163984
- /* 80 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
163985
- /* 90 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
163986
- /* 100 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
163987
- /* 110 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
163988
- /* 120 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1438, 1443,
163989
- /* 130 */ 1450, 1442, 1439, 1432, 1431, 1433, 1434, 1232, 1232, 1256,
163990
- /* 140 */ 1232, 1232, 1253, 1307, 1232, 1232, 1232, 1232, 1232, 1537,
163991
- /* 150 */ 1536, 1232, 1435, 1232, 1265, 1424, 1423, 1447, 1436, 1446,
163992
- /* 160 */ 1445, 1525, 1589, 1588, 1483, 1232, 1232, 1232, 1232, 1232,
163993
- /* 170 */ 1232, 1553, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
163994
- /* 180 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
163995
- /* 190 */ 1232, 1232, 1232, 1232, 1232, 1363, 1553, 1553, 1232, 1265,
163996
- /* 200 */ 1553, 1553, 1364, 1364, 1261, 1261, 1367, 1232, 1532, 1334,
163997
- /* 210 */ 1334, 1334, 1334, 1343, 1334, 1232, 1232, 1232, 1232, 1232,
163998
- /* 220 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
163999
- /* 230 */ 1522, 1520, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
164000
- /* 240 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
164001
- /* 250 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1339,
164002
- /* 260 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
164003
- /* 270 */ 1232, 1582, 1232, 1495, 1321, 1339, 1339, 1339, 1339, 1341,
164004
- /* 280 */ 1322, 1320, 1333, 1266, 1239, 1629, 1399, 1388, 1340, 1388,
164005
- /* 290 */ 1626, 1386, 1399, 1399, 1386, 1399, 1340, 1626, 1282, 1605,
164006
- /* 300 */ 1277, 1373, 1373, 1373, 1363, 1363, 1363, 1363, 1367, 1367,
164007
- /* 310 */ 1462, 1340, 1333, 1232, 1629, 1629, 1349, 1349, 1628, 1628,
164008
- /* 320 */ 1349, 1483, 1613, 1408, 1310, 1316, 1316, 1316, 1316, 1349,
164009
- /* 330 */ 1250, 1386, 1613, 1613, 1386, 1408, 1310, 1386, 1310, 1386,
164010
- /* 340 */ 1349, 1250, 1499, 1623, 1349, 1250, 1473, 1349, 1250, 1349,
164011
- /* 350 */ 1250, 1473, 1308, 1308, 1308, 1297, 1232, 1232, 1473, 1308,
164012
- /* 360 */ 1282, 1308, 1297, 1308, 1308, 1571, 1232, 1477, 1477, 1473,
164013
- /* 370 */ 1349, 1563, 1563, 1376, 1376, 1381, 1367, 1468, 1349, 1232,
164014
- /* 380 */ 1381, 1379, 1377, 1386, 1300, 1585, 1585, 1581, 1581, 1581,
164015
- /* 390 */ 1634, 1634, 1532, 1598, 1265, 1265, 1265, 1265, 1598, 1284,
164016
- /* 400 */ 1284, 1266, 1266, 1265, 1598, 1232, 1232, 1232, 1232, 1232,
164017
- /* 410 */ 1232, 1593, 1232, 1527, 1484, 1353, 1232, 1232, 1232, 1232,
164018
- /* 420 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
164019
- /* 430 */ 1538, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
164020
- /* 440 */ 1232, 1413, 1232, 1235, 1529, 1232, 1232, 1232, 1232, 1232,
164021
- /* 450 */ 1232, 1232, 1232, 1390, 1391, 1354, 1232, 1232, 1232, 1232,
164022
- /* 460 */ 1232, 1232, 1232, 1405, 1232, 1232, 1232, 1400, 1232, 1232,
164023
- /* 470 */ 1232, 1232, 1232, 1232, 1232, 1232, 1625, 1232, 1232, 1232,
164024
- /* 480 */ 1232, 1232, 1232, 1498, 1497, 1232, 1232, 1351, 1232, 1232,
164025
- /* 490 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
164026
- /* 500 */ 1232, 1280, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
164027
- /* 510 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
164028
- /* 520 */ 1232, 1232, 1232, 1232, 1232, 1378, 1232, 1232, 1232, 1232,
164029
- /* 530 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
164030
- /* 540 */ 1568, 1368, 1232, 1232, 1616, 1232, 1232, 1232, 1232, 1232,
164031
- /* 550 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1609,
164032
- /* 560 */ 1324, 1415, 1232, 1414, 1418, 1254, 1232, 1244, 1232, 1232,
164390
+ /* 0 */ 1647, 1647, 1647, 1475, 1240, 1351, 1240, 1240, 1240, 1475,
164391
+ /* 10 */ 1475, 1475, 1240, 1381, 1381, 1528, 1273, 1240, 1240, 1240,
164392
+ /* 20 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1474, 1240, 1240,
164393
+ /* 30 */ 1240, 1240, 1563, 1563, 1240, 1240, 1240, 1240, 1240, 1240,
164394
+ /* 40 */ 1240, 1240, 1390, 1240, 1397, 1240, 1240, 1240, 1240, 1240,
164395
+ /* 50 */ 1476, 1477, 1240, 1240, 1240, 1527, 1529, 1492, 1404, 1403,
164396
+ /* 60 */ 1402, 1401, 1510, 1369, 1395, 1388, 1392, 1470, 1471, 1469,
164397
+ /* 70 */ 1473, 1477, 1476, 1240, 1391, 1438, 1454, 1437, 1240, 1240,
164398
+ /* 80 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164399
+ /* 90 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164400
+ /* 100 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164401
+ /* 110 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164402
+ /* 120 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164403
+ /* 130 */ 1446, 1453, 1452, 1451, 1460, 1450, 1447, 1440, 1439, 1441,
164404
+ /* 140 */ 1442, 1240, 1240, 1264, 1240, 1240, 1261, 1315, 1240, 1240,
164405
+ /* 150 */ 1240, 1240, 1240, 1547, 1546, 1240, 1443, 1240, 1273, 1432,
164406
+ /* 160 */ 1431, 1457, 1444, 1456, 1455, 1535, 1599, 1598, 1493, 1240,
164407
+ /* 170 */ 1240, 1240, 1240, 1240, 1240, 1563, 1240, 1240, 1240, 1240,
164408
+ /* 180 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164409
+ /* 190 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1371,
164410
+ /* 200 */ 1563, 1563, 1240, 1273, 1563, 1563, 1372, 1372, 1269, 1269,
164411
+ /* 210 */ 1375, 1240, 1542, 1342, 1342, 1342, 1342, 1351, 1342, 1240,
164412
+ /* 220 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164413
+ /* 230 */ 1240, 1240, 1240, 1240, 1532, 1530, 1240, 1240, 1240, 1240,
164414
+ /* 240 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164415
+ /* 250 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164416
+ /* 260 */ 1240, 1240, 1240, 1347, 1240, 1240, 1240, 1240, 1240, 1240,
164417
+ /* 270 */ 1240, 1240, 1240, 1240, 1240, 1592, 1240, 1505, 1329, 1347,
164418
+ /* 280 */ 1347, 1347, 1347, 1349, 1330, 1328, 1341, 1274, 1247, 1639,
164419
+ /* 290 */ 1407, 1396, 1348, 1396, 1636, 1394, 1407, 1407, 1394, 1407,
164420
+ /* 300 */ 1348, 1636, 1290, 1615, 1285, 1381, 1381, 1381, 1371, 1371,
164421
+ /* 310 */ 1371, 1371, 1375, 1375, 1472, 1348, 1341, 1240, 1639, 1639,
164422
+ /* 320 */ 1357, 1357, 1638, 1638, 1357, 1493, 1623, 1416, 1318, 1324,
164423
+ /* 330 */ 1324, 1324, 1324, 1357, 1258, 1394, 1623, 1623, 1394, 1416,
164424
+ /* 340 */ 1318, 1394, 1318, 1394, 1357, 1258, 1509, 1633, 1357, 1258,
164425
+ /* 350 */ 1483, 1357, 1258, 1357, 1258, 1483, 1316, 1316, 1316, 1305,
164426
+ /* 360 */ 1240, 1240, 1483, 1316, 1290, 1316, 1305, 1316, 1316, 1581,
164427
+ /* 370 */ 1240, 1487, 1487, 1483, 1357, 1573, 1573, 1384, 1384, 1389,
164428
+ /* 380 */ 1375, 1478, 1357, 1240, 1389, 1387, 1385, 1394, 1308, 1595,
164429
+ /* 390 */ 1595, 1591, 1591, 1591, 1644, 1644, 1542, 1608, 1273, 1273,
164430
+ /* 400 */ 1273, 1273, 1608, 1292, 1292, 1274, 1274, 1273, 1608, 1240,
164431
+ /* 410 */ 1240, 1240, 1240, 1240, 1240, 1603, 1240, 1537, 1494, 1361,
164432
+ /* 420 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164433
+ /* 430 */ 1240, 1240, 1240, 1240, 1548, 1240, 1240, 1240, 1240, 1240,
164434
+ /* 440 */ 1240, 1240, 1240, 1240, 1240, 1421, 1240, 1243, 1539, 1240,
164435
+ /* 450 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1398, 1399, 1362,
164436
+ /* 460 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1413, 1240, 1240,
164437
+ /* 470 */ 1240, 1408, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164438
+ /* 480 */ 1635, 1240, 1240, 1240, 1240, 1240, 1240, 1508, 1507, 1240,
164439
+ /* 490 */ 1240, 1359, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164440
+ /* 500 */ 1240, 1240, 1240, 1240, 1240, 1288, 1240, 1240, 1240, 1240,
164441
+ /* 510 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164442
+ /* 520 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1386,
164443
+ /* 530 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164444
+ /* 540 */ 1240, 1240, 1240, 1240, 1578, 1376, 1240, 1240, 1240, 1240,
164445
+ /* 550 */ 1626, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164446
+ /* 560 */ 1240, 1240, 1240, 1240, 1240, 1619, 1332, 1423, 1240, 1422,
164447
+ /* 570 */ 1426, 1262, 1240, 1252, 1240, 1240,
164033164448
};
164034164449
/********** End of lemon-generated parsing tables *****************************/
164035164450
164036164451
/* The next table maps tokens (terminal symbols) into fallback tokens.
164037164452
** If a construct like the following:
@@ -164855,204 +165270,206 @@
164855165270
/* 204 */ "expr ::= expr likeop expr ESCAPE expr",
164856165271
/* 205 */ "expr ::= expr ISNULL|NOTNULL",
164857165272
/* 206 */ "expr ::= expr NOT NULL",
164858165273
/* 207 */ "expr ::= expr IS expr",
164859165274
/* 208 */ "expr ::= expr IS NOT expr",
164860
- /* 209 */ "expr ::= NOT expr",
164861
- /* 210 */ "expr ::= BITNOT expr",
164862
- /* 211 */ "expr ::= PLUS|MINUS expr",
164863
- /* 212 */ "expr ::= expr PTR expr",
164864
- /* 213 */ "between_op ::= BETWEEN",
164865
- /* 214 */ "between_op ::= NOT BETWEEN",
164866
- /* 215 */ "expr ::= expr between_op expr AND expr",
164867
- /* 216 */ "in_op ::= IN",
164868
- /* 217 */ "in_op ::= NOT IN",
164869
- /* 218 */ "expr ::= expr in_op LP exprlist RP",
164870
- /* 219 */ "expr ::= LP select RP",
164871
- /* 220 */ "expr ::= expr in_op LP select RP",
164872
- /* 221 */ "expr ::= expr in_op nm dbnm paren_exprlist",
164873
- /* 222 */ "expr ::= EXISTS LP select RP",
164874
- /* 223 */ "expr ::= CASE case_operand case_exprlist case_else END",
164875
- /* 224 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
164876
- /* 225 */ "case_exprlist ::= WHEN expr THEN expr",
164877
- /* 226 */ "case_else ::= ELSE expr",
164878
- /* 227 */ "case_else ::=",
164879
- /* 228 */ "case_operand ::= expr",
164880
- /* 229 */ "case_operand ::=",
164881
- /* 230 */ "exprlist ::=",
164882
- /* 231 */ "nexprlist ::= nexprlist COMMA expr",
164883
- /* 232 */ "nexprlist ::= expr",
164884
- /* 233 */ "paren_exprlist ::=",
164885
- /* 234 */ "paren_exprlist ::= LP exprlist RP",
164886
- /* 235 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt",
164887
- /* 236 */ "uniqueflag ::= UNIQUE",
164888
- /* 237 */ "uniqueflag ::=",
164889
- /* 238 */ "eidlist_opt ::=",
164890
- /* 239 */ "eidlist_opt ::= LP eidlist RP",
164891
- /* 240 */ "eidlist ::= eidlist COMMA nm collate sortorder",
164892
- /* 241 */ "eidlist ::= nm collate sortorder",
164893
- /* 242 */ "collate ::=",
164894
- /* 243 */ "collate ::= COLLATE ID|STRING",
164895
- /* 244 */ "cmd ::= DROP INDEX ifexists fullname",
164896
- /* 245 */ "cmd ::= VACUUM vinto",
164897
- /* 246 */ "cmd ::= VACUUM nm vinto",
164898
- /* 247 */ "vinto ::= INTO expr",
164899
- /* 248 */ "vinto ::=",
164900
- /* 249 */ "cmd ::= PRAGMA nm dbnm",
164901
- /* 250 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
164902
- /* 251 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
164903
- /* 252 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
164904
- /* 253 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
164905
- /* 254 */ "plus_num ::= PLUS INTEGER|FLOAT",
164906
- /* 255 */ "minus_num ::= MINUS INTEGER|FLOAT",
164907
- /* 256 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
164908
- /* 257 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
164909
- /* 258 */ "trigger_time ::= BEFORE|AFTER",
164910
- /* 259 */ "trigger_time ::= INSTEAD OF",
164911
- /* 260 */ "trigger_time ::=",
164912
- /* 261 */ "trigger_event ::= DELETE|INSERT",
164913
- /* 262 */ "trigger_event ::= UPDATE",
164914
- /* 263 */ "trigger_event ::= UPDATE OF idlist",
164915
- /* 264 */ "when_clause ::=",
164916
- /* 265 */ "when_clause ::= WHEN expr",
164917
- /* 266 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
164918
- /* 267 */ "trigger_cmd_list ::= trigger_cmd SEMI",
164919
- /* 268 */ "trnm ::= nm DOT nm",
164920
- /* 269 */ "tridxby ::= INDEXED BY nm",
164921
- /* 270 */ "tridxby ::= NOT INDEXED",
164922
- /* 271 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt",
164923
- /* 272 */ "trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt",
164924
- /* 273 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt",
164925
- /* 274 */ "trigger_cmd ::= scanpt select scanpt",
164926
- /* 275 */ "expr ::= RAISE LP IGNORE RP",
164927
- /* 276 */ "expr ::= RAISE LP raisetype COMMA nm RP",
164928
- /* 277 */ "raisetype ::= ROLLBACK",
164929
- /* 278 */ "raisetype ::= ABORT",
164930
- /* 279 */ "raisetype ::= FAIL",
164931
- /* 280 */ "cmd ::= DROP TRIGGER ifexists fullname",
164932
- /* 281 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
164933
- /* 282 */ "cmd ::= DETACH database_kw_opt expr",
164934
- /* 283 */ "key_opt ::=",
164935
- /* 284 */ "key_opt ::= KEY expr",
164936
- /* 285 */ "cmd ::= REINDEX",
164937
- /* 286 */ "cmd ::= REINDEX nm dbnm",
164938
- /* 287 */ "cmd ::= ANALYZE",
164939
- /* 288 */ "cmd ::= ANALYZE nm dbnm",
164940
- /* 289 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
164941
- /* 290 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist",
164942
- /* 291 */ "cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm",
164943
- /* 292 */ "add_column_fullname ::= fullname",
164944
- /* 293 */ "cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm",
164945
- /* 294 */ "cmd ::= create_vtab",
164946
- /* 295 */ "cmd ::= create_vtab LP vtabarglist RP",
164947
- /* 296 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
164948
- /* 297 */ "vtabarg ::=",
164949
- /* 298 */ "vtabargtoken ::= ANY",
164950
- /* 299 */ "vtabargtoken ::= lp anylist RP",
164951
- /* 300 */ "lp ::= LP",
164952
- /* 301 */ "with ::= WITH wqlist",
164953
- /* 302 */ "with ::= WITH RECURSIVE wqlist",
164954
- /* 303 */ "wqas ::= AS",
164955
- /* 304 */ "wqas ::= AS MATERIALIZED",
164956
- /* 305 */ "wqas ::= AS NOT MATERIALIZED",
164957
- /* 306 */ "wqitem ::= nm eidlist_opt wqas LP select RP",
164958
- /* 307 */ "wqlist ::= wqitem",
164959
- /* 308 */ "wqlist ::= wqlist COMMA wqitem",
164960
- /* 309 */ "windowdefn_list ::= windowdefn",
164961
- /* 310 */ "windowdefn_list ::= windowdefn_list COMMA windowdefn",
164962
- /* 311 */ "windowdefn ::= nm AS LP window RP",
164963
- /* 312 */ "window ::= PARTITION BY nexprlist orderby_opt frame_opt",
164964
- /* 313 */ "window ::= nm PARTITION BY nexprlist orderby_opt frame_opt",
164965
- /* 314 */ "window ::= ORDER BY sortlist frame_opt",
164966
- /* 315 */ "window ::= nm ORDER BY sortlist frame_opt",
164967
- /* 316 */ "window ::= frame_opt",
164968
- /* 317 */ "window ::= nm frame_opt",
164969
- /* 318 */ "frame_opt ::=",
164970
- /* 319 */ "frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt",
164971
- /* 320 */ "frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt",
164972
- /* 321 */ "range_or_rows ::= RANGE|ROWS|GROUPS",
164973
- /* 322 */ "frame_bound_s ::= frame_bound",
164974
- /* 323 */ "frame_bound_s ::= UNBOUNDED PRECEDING",
164975
- /* 324 */ "frame_bound_e ::= frame_bound",
164976
- /* 325 */ "frame_bound_e ::= UNBOUNDED FOLLOWING",
164977
- /* 326 */ "frame_bound ::= expr PRECEDING|FOLLOWING",
164978
- /* 327 */ "frame_bound ::= CURRENT ROW",
164979
- /* 328 */ "frame_exclude_opt ::=",
164980
- /* 329 */ "frame_exclude_opt ::= EXCLUDE frame_exclude",
164981
- /* 330 */ "frame_exclude ::= NO OTHERS",
164982
- /* 331 */ "frame_exclude ::= CURRENT ROW",
164983
- /* 332 */ "frame_exclude ::= GROUP|TIES",
164984
- /* 333 */ "window_clause ::= WINDOW windowdefn_list",
164985
- /* 334 */ "filter_over ::= filter_clause over_clause",
164986
- /* 335 */ "filter_over ::= over_clause",
164987
- /* 336 */ "filter_over ::= filter_clause",
164988
- /* 337 */ "over_clause ::= OVER LP window RP",
164989
- /* 338 */ "over_clause ::= OVER nm",
164990
- /* 339 */ "filter_clause ::= FILTER LP WHERE expr RP",
164991
- /* 340 */ "input ::= cmdlist",
164992
- /* 341 */ "cmdlist ::= cmdlist ecmd",
164993
- /* 342 */ "cmdlist ::= ecmd",
164994
- /* 343 */ "ecmd ::= SEMI",
164995
- /* 344 */ "ecmd ::= cmdx SEMI",
164996
- /* 345 */ "ecmd ::= explain cmdx SEMI",
164997
- /* 346 */ "trans_opt ::=",
164998
- /* 347 */ "trans_opt ::= TRANSACTION",
164999
- /* 348 */ "trans_opt ::= TRANSACTION nm",
165000
- /* 349 */ "savepoint_opt ::= SAVEPOINT",
165001
- /* 350 */ "savepoint_opt ::=",
165002
- /* 351 */ "cmd ::= create_table create_table_args",
165003
- /* 352 */ "table_option_set ::= table_option",
165004
- /* 353 */ "columnlist ::= columnlist COMMA columnname carglist",
165005
- /* 354 */ "columnlist ::= columnname carglist",
165006
- /* 355 */ "nm ::= ID|INDEXED",
165007
- /* 356 */ "nm ::= STRING",
165008
- /* 357 */ "nm ::= JOIN_KW",
165009
- /* 358 */ "typetoken ::= typename",
165010
- /* 359 */ "typename ::= ID|STRING",
165011
- /* 360 */ "signed ::= plus_num",
165012
- /* 361 */ "signed ::= minus_num",
165013
- /* 362 */ "carglist ::= carglist ccons",
165014
- /* 363 */ "carglist ::=",
165015
- /* 364 */ "ccons ::= NULL onconf",
165016
- /* 365 */ "ccons ::= GENERATED ALWAYS AS generated",
165017
- /* 366 */ "ccons ::= AS generated",
165018
- /* 367 */ "conslist_opt ::= COMMA conslist",
165019
- /* 368 */ "conslist ::= conslist tconscomma tcons",
165020
- /* 369 */ "conslist ::= tcons",
165021
- /* 370 */ "tconscomma ::=",
165022
- /* 371 */ "defer_subclause_opt ::= defer_subclause",
165023
- /* 372 */ "resolvetype ::= raisetype",
165024
- /* 373 */ "selectnowith ::= oneselect",
165025
- /* 374 */ "oneselect ::= values",
165026
- /* 375 */ "sclp ::= selcollist COMMA",
165027
- /* 376 */ "as ::= ID|STRING",
165028
- /* 377 */ "indexed_opt ::= indexed_by",
165029
- /* 378 */ "returning ::=",
165030
- /* 379 */ "expr ::= term",
165031
- /* 380 */ "likeop ::= LIKE_KW|MATCH",
165032
- /* 381 */ "exprlist ::= nexprlist",
165033
- /* 382 */ "nmnum ::= plus_num",
165034
- /* 383 */ "nmnum ::= nm",
165035
- /* 384 */ "nmnum ::= ON",
165036
- /* 385 */ "nmnum ::= DELETE",
165037
- /* 386 */ "nmnum ::= DEFAULT",
165038
- /* 387 */ "plus_num ::= INTEGER|FLOAT",
165039
- /* 388 */ "foreach_clause ::=",
165040
- /* 389 */ "foreach_clause ::= FOR EACH ROW",
165041
- /* 390 */ "trnm ::= nm",
165042
- /* 391 */ "tridxby ::=",
165043
- /* 392 */ "database_kw_opt ::= DATABASE",
165044
- /* 393 */ "database_kw_opt ::=",
165045
- /* 394 */ "kwcolumn_opt ::=",
165046
- /* 395 */ "kwcolumn_opt ::= COLUMNKW",
165047
- /* 396 */ "vtabarglist ::= vtabarg",
165048
- /* 397 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
165049
- /* 398 */ "vtabarg ::= vtabarg vtabargtoken",
165050
- /* 399 */ "anylist ::=",
165051
- /* 400 */ "anylist ::= anylist LP anylist RP",
165052
- /* 401 */ "anylist ::= anylist ANY",
165053
- /* 402 */ "with ::=",
165275
+ /* 209 */ "expr ::= expr IS NOT DISTINCT FROM expr",
165276
+ /* 210 */ "expr ::= expr IS DISTINCT FROM expr",
165277
+ /* 211 */ "expr ::= NOT expr",
165278
+ /* 212 */ "expr ::= BITNOT expr",
165279
+ /* 213 */ "expr ::= PLUS|MINUS expr",
165280
+ /* 214 */ "expr ::= expr PTR expr",
165281
+ /* 215 */ "between_op ::= BETWEEN",
165282
+ /* 216 */ "between_op ::= NOT BETWEEN",
165283
+ /* 217 */ "expr ::= expr between_op expr AND expr",
165284
+ /* 218 */ "in_op ::= IN",
165285
+ /* 219 */ "in_op ::= NOT IN",
165286
+ /* 220 */ "expr ::= expr in_op LP exprlist RP",
165287
+ /* 221 */ "expr ::= LP select RP",
165288
+ /* 222 */ "expr ::= expr in_op LP select RP",
165289
+ /* 223 */ "expr ::= expr in_op nm dbnm paren_exprlist",
165290
+ /* 224 */ "expr ::= EXISTS LP select RP",
165291
+ /* 225 */ "expr ::= CASE case_operand case_exprlist case_else END",
165292
+ /* 226 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
165293
+ /* 227 */ "case_exprlist ::= WHEN expr THEN expr",
165294
+ /* 228 */ "case_else ::= ELSE expr",
165295
+ /* 229 */ "case_else ::=",
165296
+ /* 230 */ "case_operand ::= expr",
165297
+ /* 231 */ "case_operand ::=",
165298
+ /* 232 */ "exprlist ::=",
165299
+ /* 233 */ "nexprlist ::= nexprlist COMMA expr",
165300
+ /* 234 */ "nexprlist ::= expr",
165301
+ /* 235 */ "paren_exprlist ::=",
165302
+ /* 236 */ "paren_exprlist ::= LP exprlist RP",
165303
+ /* 237 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt",
165304
+ /* 238 */ "uniqueflag ::= UNIQUE",
165305
+ /* 239 */ "uniqueflag ::=",
165306
+ /* 240 */ "eidlist_opt ::=",
165307
+ /* 241 */ "eidlist_opt ::= LP eidlist RP",
165308
+ /* 242 */ "eidlist ::= eidlist COMMA nm collate sortorder",
165309
+ /* 243 */ "eidlist ::= nm collate sortorder",
165310
+ /* 244 */ "collate ::=",
165311
+ /* 245 */ "collate ::= COLLATE ID|STRING",
165312
+ /* 246 */ "cmd ::= DROP INDEX ifexists fullname",
165313
+ /* 247 */ "cmd ::= VACUUM vinto",
165314
+ /* 248 */ "cmd ::= VACUUM nm vinto",
165315
+ /* 249 */ "vinto ::= INTO expr",
165316
+ /* 250 */ "vinto ::=",
165317
+ /* 251 */ "cmd ::= PRAGMA nm dbnm",
165318
+ /* 252 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
165319
+ /* 253 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
165320
+ /* 254 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
165321
+ /* 255 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
165322
+ /* 256 */ "plus_num ::= PLUS INTEGER|FLOAT",
165323
+ /* 257 */ "minus_num ::= MINUS INTEGER|FLOAT",
165324
+ /* 258 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
165325
+ /* 259 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
165326
+ /* 260 */ "trigger_time ::= BEFORE|AFTER",
165327
+ /* 261 */ "trigger_time ::= INSTEAD OF",
165328
+ /* 262 */ "trigger_time ::=",
165329
+ /* 263 */ "trigger_event ::= DELETE|INSERT",
165330
+ /* 264 */ "trigger_event ::= UPDATE",
165331
+ /* 265 */ "trigger_event ::= UPDATE OF idlist",
165332
+ /* 266 */ "when_clause ::=",
165333
+ /* 267 */ "when_clause ::= WHEN expr",
165334
+ /* 268 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
165335
+ /* 269 */ "trigger_cmd_list ::= trigger_cmd SEMI",
165336
+ /* 270 */ "trnm ::= nm DOT nm",
165337
+ /* 271 */ "tridxby ::= INDEXED BY nm",
165338
+ /* 272 */ "tridxby ::= NOT INDEXED",
165339
+ /* 273 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt",
165340
+ /* 274 */ "trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt",
165341
+ /* 275 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt",
165342
+ /* 276 */ "trigger_cmd ::= scanpt select scanpt",
165343
+ /* 277 */ "expr ::= RAISE LP IGNORE RP",
165344
+ /* 278 */ "expr ::= RAISE LP raisetype COMMA nm RP",
165345
+ /* 279 */ "raisetype ::= ROLLBACK",
165346
+ /* 280 */ "raisetype ::= ABORT",
165347
+ /* 281 */ "raisetype ::= FAIL",
165348
+ /* 282 */ "cmd ::= DROP TRIGGER ifexists fullname",
165349
+ /* 283 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
165350
+ /* 284 */ "cmd ::= DETACH database_kw_opt expr",
165351
+ /* 285 */ "key_opt ::=",
165352
+ /* 286 */ "key_opt ::= KEY expr",
165353
+ /* 287 */ "cmd ::= REINDEX",
165354
+ /* 288 */ "cmd ::= REINDEX nm dbnm",
165355
+ /* 289 */ "cmd ::= ANALYZE",
165356
+ /* 290 */ "cmd ::= ANALYZE nm dbnm",
165357
+ /* 291 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
165358
+ /* 292 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist",
165359
+ /* 293 */ "cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm",
165360
+ /* 294 */ "add_column_fullname ::= fullname",
165361
+ /* 295 */ "cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm",
165362
+ /* 296 */ "cmd ::= create_vtab",
165363
+ /* 297 */ "cmd ::= create_vtab LP vtabarglist RP",
165364
+ /* 298 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
165365
+ /* 299 */ "vtabarg ::=",
165366
+ /* 300 */ "vtabargtoken ::= ANY",
165367
+ /* 301 */ "vtabargtoken ::= lp anylist RP",
165368
+ /* 302 */ "lp ::= LP",
165369
+ /* 303 */ "with ::= WITH wqlist",
165370
+ /* 304 */ "with ::= WITH RECURSIVE wqlist",
165371
+ /* 305 */ "wqas ::= AS",
165372
+ /* 306 */ "wqas ::= AS MATERIALIZED",
165373
+ /* 307 */ "wqas ::= AS NOT MATERIALIZED",
165374
+ /* 308 */ "wqitem ::= nm eidlist_opt wqas LP select RP",
165375
+ /* 309 */ "wqlist ::= wqitem",
165376
+ /* 310 */ "wqlist ::= wqlist COMMA wqitem",
165377
+ /* 311 */ "windowdefn_list ::= windowdefn",
165378
+ /* 312 */ "windowdefn_list ::= windowdefn_list COMMA windowdefn",
165379
+ /* 313 */ "windowdefn ::= nm AS LP window RP",
165380
+ /* 314 */ "window ::= PARTITION BY nexprlist orderby_opt frame_opt",
165381
+ /* 315 */ "window ::= nm PARTITION BY nexprlist orderby_opt frame_opt",
165382
+ /* 316 */ "window ::= ORDER BY sortlist frame_opt",
165383
+ /* 317 */ "window ::= nm ORDER BY sortlist frame_opt",
165384
+ /* 318 */ "window ::= frame_opt",
165385
+ /* 319 */ "window ::= nm frame_opt",
165386
+ /* 320 */ "frame_opt ::=",
165387
+ /* 321 */ "frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt",
165388
+ /* 322 */ "frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt",
165389
+ /* 323 */ "range_or_rows ::= RANGE|ROWS|GROUPS",
165390
+ /* 324 */ "frame_bound_s ::= frame_bound",
165391
+ /* 325 */ "frame_bound_s ::= UNBOUNDED PRECEDING",
165392
+ /* 326 */ "frame_bound_e ::= frame_bound",
165393
+ /* 327 */ "frame_bound_e ::= UNBOUNDED FOLLOWING",
165394
+ /* 328 */ "frame_bound ::= expr PRECEDING|FOLLOWING",
165395
+ /* 329 */ "frame_bound ::= CURRENT ROW",
165396
+ /* 330 */ "frame_exclude_opt ::=",
165397
+ /* 331 */ "frame_exclude_opt ::= EXCLUDE frame_exclude",
165398
+ /* 332 */ "frame_exclude ::= NO OTHERS",
165399
+ /* 333 */ "frame_exclude ::= CURRENT ROW",
165400
+ /* 334 */ "frame_exclude ::= GROUP|TIES",
165401
+ /* 335 */ "window_clause ::= WINDOW windowdefn_list",
165402
+ /* 336 */ "filter_over ::= filter_clause over_clause",
165403
+ /* 337 */ "filter_over ::= over_clause",
165404
+ /* 338 */ "filter_over ::= filter_clause",
165405
+ /* 339 */ "over_clause ::= OVER LP window RP",
165406
+ /* 340 */ "over_clause ::= OVER nm",
165407
+ /* 341 */ "filter_clause ::= FILTER LP WHERE expr RP",
165408
+ /* 342 */ "input ::= cmdlist",
165409
+ /* 343 */ "cmdlist ::= cmdlist ecmd",
165410
+ /* 344 */ "cmdlist ::= ecmd",
165411
+ /* 345 */ "ecmd ::= SEMI",
165412
+ /* 346 */ "ecmd ::= cmdx SEMI",
165413
+ /* 347 */ "ecmd ::= explain cmdx SEMI",
165414
+ /* 348 */ "trans_opt ::=",
165415
+ /* 349 */ "trans_opt ::= TRANSACTION",
165416
+ /* 350 */ "trans_opt ::= TRANSACTION nm",
165417
+ /* 351 */ "savepoint_opt ::= SAVEPOINT",
165418
+ /* 352 */ "savepoint_opt ::=",
165419
+ /* 353 */ "cmd ::= create_table create_table_args",
165420
+ /* 354 */ "table_option_set ::= table_option",
165421
+ /* 355 */ "columnlist ::= columnlist COMMA columnname carglist",
165422
+ /* 356 */ "columnlist ::= columnname carglist",
165423
+ /* 357 */ "nm ::= ID|INDEXED",
165424
+ /* 358 */ "nm ::= STRING",
165425
+ /* 359 */ "nm ::= JOIN_KW",
165426
+ /* 360 */ "typetoken ::= typename",
165427
+ /* 361 */ "typename ::= ID|STRING",
165428
+ /* 362 */ "signed ::= plus_num",
165429
+ /* 363 */ "signed ::= minus_num",
165430
+ /* 364 */ "carglist ::= carglist ccons",
165431
+ /* 365 */ "carglist ::=",
165432
+ /* 366 */ "ccons ::= NULL onconf",
165433
+ /* 367 */ "ccons ::= GENERATED ALWAYS AS generated",
165434
+ /* 368 */ "ccons ::= AS generated",
165435
+ /* 369 */ "conslist_opt ::= COMMA conslist",
165436
+ /* 370 */ "conslist ::= conslist tconscomma tcons",
165437
+ /* 371 */ "conslist ::= tcons",
165438
+ /* 372 */ "tconscomma ::=",
165439
+ /* 373 */ "defer_subclause_opt ::= defer_subclause",
165440
+ /* 374 */ "resolvetype ::= raisetype",
165441
+ /* 375 */ "selectnowith ::= oneselect",
165442
+ /* 376 */ "oneselect ::= values",
165443
+ /* 377 */ "sclp ::= selcollist COMMA",
165444
+ /* 378 */ "as ::= ID|STRING",
165445
+ /* 379 */ "indexed_opt ::= indexed_by",
165446
+ /* 380 */ "returning ::=",
165447
+ /* 381 */ "expr ::= term",
165448
+ /* 382 */ "likeop ::= LIKE_KW|MATCH",
165449
+ /* 383 */ "exprlist ::= nexprlist",
165450
+ /* 384 */ "nmnum ::= plus_num",
165451
+ /* 385 */ "nmnum ::= nm",
165452
+ /* 386 */ "nmnum ::= ON",
165453
+ /* 387 */ "nmnum ::= DELETE",
165454
+ /* 388 */ "nmnum ::= DEFAULT",
165455
+ /* 389 */ "plus_num ::= INTEGER|FLOAT",
165456
+ /* 390 */ "foreach_clause ::=",
165457
+ /* 391 */ "foreach_clause ::= FOR EACH ROW",
165458
+ /* 392 */ "trnm ::= nm",
165459
+ /* 393 */ "tridxby ::=",
165460
+ /* 394 */ "database_kw_opt ::= DATABASE",
165461
+ /* 395 */ "database_kw_opt ::=",
165462
+ /* 396 */ "kwcolumn_opt ::=",
165463
+ /* 397 */ "kwcolumn_opt ::= COLUMNKW",
165464
+ /* 398 */ "vtabarglist ::= vtabarg",
165465
+ /* 399 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
165466
+ /* 400 */ "vtabarg ::= vtabarg vtabargtoken",
165467
+ /* 401 */ "anylist ::=",
165468
+ /* 402 */ "anylist ::= anylist LP anylist RP",
165469
+ /* 403 */ "anylist ::= anylist ANY",
165470
+ /* 404 */ "with ::=",
165054165471
};
165055165472
#endif /* NDEBUG */
165056165473
165057165474
165058165475
#if YYSTACKDEPTH<=0
@@ -165764,204 +166181,206 @@
165764166181
217, /* (204) expr ::= expr likeop expr ESCAPE expr */
165765166182
217, /* (205) expr ::= expr ISNULL|NOTNULL */
165766166183
217, /* (206) expr ::= expr NOT NULL */
165767166184
217, /* (207) expr ::= expr IS expr */
165768166185
217, /* (208) expr ::= expr IS NOT expr */
165769
- 217, /* (209) expr ::= NOT expr */
165770
- 217, /* (210) expr ::= BITNOT expr */
165771
- 217, /* (211) expr ::= PLUS|MINUS expr */
165772
- 217, /* (212) expr ::= expr PTR expr */
165773
- 275, /* (213) between_op ::= BETWEEN */
165774
- 275, /* (214) between_op ::= NOT BETWEEN */
165775
- 217, /* (215) expr ::= expr between_op expr AND expr */
165776
- 276, /* (216) in_op ::= IN */
165777
- 276, /* (217) in_op ::= NOT IN */
165778
- 217, /* (218) expr ::= expr in_op LP exprlist RP */
165779
- 217, /* (219) expr ::= LP select RP */
165780
- 217, /* (220) expr ::= expr in_op LP select RP */
165781
- 217, /* (221) expr ::= expr in_op nm dbnm paren_exprlist */
165782
- 217, /* (222) expr ::= EXISTS LP select RP */
165783
- 217, /* (223) expr ::= CASE case_operand case_exprlist case_else END */
165784
- 279, /* (224) case_exprlist ::= case_exprlist WHEN expr THEN expr */
165785
- 279, /* (225) case_exprlist ::= WHEN expr THEN expr */
165786
- 280, /* (226) case_else ::= ELSE expr */
165787
- 280, /* (227) case_else ::= */
165788
- 278, /* (228) case_operand ::= expr */
165789
- 278, /* (229) case_operand ::= */
165790
- 261, /* (230) exprlist ::= */
165791
- 253, /* (231) nexprlist ::= nexprlist COMMA expr */
165792
- 253, /* (232) nexprlist ::= expr */
165793
- 277, /* (233) paren_exprlist ::= */
165794
- 277, /* (234) paren_exprlist ::= LP exprlist RP */
165795
- 190, /* (235) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
165796
- 281, /* (236) uniqueflag ::= UNIQUE */
165797
- 281, /* (237) uniqueflag ::= */
165798
- 221, /* (238) eidlist_opt ::= */
165799
- 221, /* (239) eidlist_opt ::= LP eidlist RP */
165800
- 232, /* (240) eidlist ::= eidlist COMMA nm collate sortorder */
165801
- 232, /* (241) eidlist ::= nm collate sortorder */
165802
- 282, /* (242) collate ::= */
165803
- 282, /* (243) collate ::= COLLATE ID|STRING */
165804
- 190, /* (244) cmd ::= DROP INDEX ifexists fullname */
165805
- 190, /* (245) cmd ::= VACUUM vinto */
165806
- 190, /* (246) cmd ::= VACUUM nm vinto */
165807
- 283, /* (247) vinto ::= INTO expr */
165808
- 283, /* (248) vinto ::= */
165809
- 190, /* (249) cmd ::= PRAGMA nm dbnm */
165810
- 190, /* (250) cmd ::= PRAGMA nm dbnm EQ nmnum */
165811
- 190, /* (251) cmd ::= PRAGMA nm dbnm LP nmnum RP */
165812
- 190, /* (252) cmd ::= PRAGMA nm dbnm EQ minus_num */
165813
- 190, /* (253) cmd ::= PRAGMA nm dbnm LP minus_num RP */
165814
- 211, /* (254) plus_num ::= PLUS INTEGER|FLOAT */
165815
- 212, /* (255) minus_num ::= MINUS INTEGER|FLOAT */
165816
- 190, /* (256) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
165817
- 285, /* (257) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
165818
- 287, /* (258) trigger_time ::= BEFORE|AFTER */
165819
- 287, /* (259) trigger_time ::= INSTEAD OF */
165820
- 287, /* (260) trigger_time ::= */
165821
- 288, /* (261) trigger_event ::= DELETE|INSERT */
165822
- 288, /* (262) trigger_event ::= UPDATE */
165823
- 288, /* (263) trigger_event ::= UPDATE OF idlist */
165824
- 290, /* (264) when_clause ::= */
165825
- 290, /* (265) when_clause ::= WHEN expr */
165826
- 286, /* (266) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
165827
- 286, /* (267) trigger_cmd_list ::= trigger_cmd SEMI */
165828
- 292, /* (268) trnm ::= nm DOT nm */
165829
- 293, /* (269) tridxby ::= INDEXED BY nm */
165830
- 293, /* (270) tridxby ::= NOT INDEXED */
165831
- 291, /* (271) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
165832
- 291, /* (272) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
165833
- 291, /* (273) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
165834
- 291, /* (274) trigger_cmd ::= scanpt select scanpt */
165835
- 217, /* (275) expr ::= RAISE LP IGNORE RP */
165836
- 217, /* (276) expr ::= RAISE LP raisetype COMMA nm RP */
165837
- 236, /* (277) raisetype ::= ROLLBACK */
165838
- 236, /* (278) raisetype ::= ABORT */
165839
- 236, /* (279) raisetype ::= FAIL */
165840
- 190, /* (280) cmd ::= DROP TRIGGER ifexists fullname */
165841
- 190, /* (281) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
165842
- 190, /* (282) cmd ::= DETACH database_kw_opt expr */
165843
- 295, /* (283) key_opt ::= */
165844
- 295, /* (284) key_opt ::= KEY expr */
165845
- 190, /* (285) cmd ::= REINDEX */
165846
- 190, /* (286) cmd ::= REINDEX nm dbnm */
165847
- 190, /* (287) cmd ::= ANALYZE */
165848
- 190, /* (288) cmd ::= ANALYZE nm dbnm */
165849
- 190, /* (289) cmd ::= ALTER TABLE fullname RENAME TO nm */
165850
- 190, /* (290) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
165851
- 190, /* (291) cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
165852
- 296, /* (292) add_column_fullname ::= fullname */
165853
- 190, /* (293) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
165854
- 190, /* (294) cmd ::= create_vtab */
165855
- 190, /* (295) cmd ::= create_vtab LP vtabarglist RP */
165856
- 298, /* (296) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
165857
- 300, /* (297) vtabarg ::= */
165858
- 301, /* (298) vtabargtoken ::= ANY */
165859
- 301, /* (299) vtabargtoken ::= lp anylist RP */
165860
- 302, /* (300) lp ::= LP */
165861
- 266, /* (301) with ::= WITH wqlist */
165862
- 266, /* (302) with ::= WITH RECURSIVE wqlist */
165863
- 305, /* (303) wqas ::= AS */
165864
- 305, /* (304) wqas ::= AS MATERIALIZED */
165865
- 305, /* (305) wqas ::= AS NOT MATERIALIZED */
165866
- 304, /* (306) wqitem ::= nm eidlist_opt wqas LP select RP */
165867
- 241, /* (307) wqlist ::= wqitem */
165868
- 241, /* (308) wqlist ::= wqlist COMMA wqitem */
165869
- 306, /* (309) windowdefn_list ::= windowdefn */
165870
- 306, /* (310) windowdefn_list ::= windowdefn_list COMMA windowdefn */
165871
- 307, /* (311) windowdefn ::= nm AS LP window RP */
165872
- 308, /* (312) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
165873
- 308, /* (313) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
165874
- 308, /* (314) window ::= ORDER BY sortlist frame_opt */
165875
- 308, /* (315) window ::= nm ORDER BY sortlist frame_opt */
165876
- 308, /* (316) window ::= frame_opt */
165877
- 308, /* (317) window ::= nm frame_opt */
165878
- 309, /* (318) frame_opt ::= */
165879
- 309, /* (319) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
165880
- 309, /* (320) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
165881
- 313, /* (321) range_or_rows ::= RANGE|ROWS|GROUPS */
165882
- 315, /* (322) frame_bound_s ::= frame_bound */
165883
- 315, /* (323) frame_bound_s ::= UNBOUNDED PRECEDING */
165884
- 316, /* (324) frame_bound_e ::= frame_bound */
165885
- 316, /* (325) frame_bound_e ::= UNBOUNDED FOLLOWING */
165886
- 314, /* (326) frame_bound ::= expr PRECEDING|FOLLOWING */
165887
- 314, /* (327) frame_bound ::= CURRENT ROW */
165888
- 317, /* (328) frame_exclude_opt ::= */
165889
- 317, /* (329) frame_exclude_opt ::= EXCLUDE frame_exclude */
165890
- 318, /* (330) frame_exclude ::= NO OTHERS */
165891
- 318, /* (331) frame_exclude ::= CURRENT ROW */
165892
- 318, /* (332) frame_exclude ::= GROUP|TIES */
165893
- 251, /* (333) window_clause ::= WINDOW windowdefn_list */
165894
- 273, /* (334) filter_over ::= filter_clause over_clause */
165895
- 273, /* (335) filter_over ::= over_clause */
165896
- 273, /* (336) filter_over ::= filter_clause */
165897
- 312, /* (337) over_clause ::= OVER LP window RP */
165898
- 312, /* (338) over_clause ::= OVER nm */
165899
- 311, /* (339) filter_clause ::= FILTER LP WHERE expr RP */
165900
- 185, /* (340) input ::= cmdlist */
165901
- 186, /* (341) cmdlist ::= cmdlist ecmd */
165902
- 186, /* (342) cmdlist ::= ecmd */
165903
- 187, /* (343) ecmd ::= SEMI */
165904
- 187, /* (344) ecmd ::= cmdx SEMI */
165905
- 187, /* (345) ecmd ::= explain cmdx SEMI */
165906
- 192, /* (346) trans_opt ::= */
165907
- 192, /* (347) trans_opt ::= TRANSACTION */
165908
- 192, /* (348) trans_opt ::= TRANSACTION nm */
165909
- 194, /* (349) savepoint_opt ::= SAVEPOINT */
165910
- 194, /* (350) savepoint_opt ::= */
165911
- 190, /* (351) cmd ::= create_table create_table_args */
165912
- 203, /* (352) table_option_set ::= table_option */
165913
- 201, /* (353) columnlist ::= columnlist COMMA columnname carglist */
165914
- 201, /* (354) columnlist ::= columnname carglist */
165915
- 193, /* (355) nm ::= ID|INDEXED */
165916
- 193, /* (356) nm ::= STRING */
165917
- 193, /* (357) nm ::= JOIN_KW */
165918
- 208, /* (358) typetoken ::= typename */
165919
- 209, /* (359) typename ::= ID|STRING */
165920
- 210, /* (360) signed ::= plus_num */
165921
- 210, /* (361) signed ::= minus_num */
165922
- 207, /* (362) carglist ::= carglist ccons */
165923
- 207, /* (363) carglist ::= */
165924
- 215, /* (364) ccons ::= NULL onconf */
165925
- 215, /* (365) ccons ::= GENERATED ALWAYS AS generated */
165926
- 215, /* (366) ccons ::= AS generated */
165927
- 202, /* (367) conslist_opt ::= COMMA conslist */
165928
- 228, /* (368) conslist ::= conslist tconscomma tcons */
165929
- 228, /* (369) conslist ::= tcons */
165930
- 229, /* (370) tconscomma ::= */
165931
- 233, /* (371) defer_subclause_opt ::= defer_subclause */
165932
- 235, /* (372) resolvetype ::= raisetype */
165933
- 239, /* (373) selectnowith ::= oneselect */
165934
- 240, /* (374) oneselect ::= values */
165935
- 254, /* (375) sclp ::= selcollist COMMA */
165936
- 255, /* (376) as ::= ID|STRING */
165937
- 264, /* (377) indexed_opt ::= indexed_by */
165938
- 272, /* (378) returning ::= */
165939
- 217, /* (379) expr ::= term */
165940
- 274, /* (380) likeop ::= LIKE_KW|MATCH */
165941
- 261, /* (381) exprlist ::= nexprlist */
165942
- 284, /* (382) nmnum ::= plus_num */
165943
- 284, /* (383) nmnum ::= nm */
165944
- 284, /* (384) nmnum ::= ON */
165945
- 284, /* (385) nmnum ::= DELETE */
165946
- 284, /* (386) nmnum ::= DEFAULT */
165947
- 211, /* (387) plus_num ::= INTEGER|FLOAT */
165948
- 289, /* (388) foreach_clause ::= */
165949
- 289, /* (389) foreach_clause ::= FOR EACH ROW */
165950
- 292, /* (390) trnm ::= nm */
165951
- 293, /* (391) tridxby ::= */
165952
- 294, /* (392) database_kw_opt ::= DATABASE */
165953
- 294, /* (393) database_kw_opt ::= */
165954
- 297, /* (394) kwcolumn_opt ::= */
165955
- 297, /* (395) kwcolumn_opt ::= COLUMNKW */
165956
- 299, /* (396) vtabarglist ::= vtabarg */
165957
- 299, /* (397) vtabarglist ::= vtabarglist COMMA vtabarg */
165958
- 300, /* (398) vtabarg ::= vtabarg vtabargtoken */
165959
- 303, /* (399) anylist ::= */
165960
- 303, /* (400) anylist ::= anylist LP anylist RP */
165961
- 303, /* (401) anylist ::= anylist ANY */
165962
- 266, /* (402) with ::= */
166186
+ 217, /* (209) expr ::= expr IS NOT DISTINCT FROM expr */
166187
+ 217, /* (210) expr ::= expr IS DISTINCT FROM expr */
166188
+ 217, /* (211) expr ::= NOT expr */
166189
+ 217, /* (212) expr ::= BITNOT expr */
166190
+ 217, /* (213) expr ::= PLUS|MINUS expr */
166191
+ 217, /* (214) expr ::= expr PTR expr */
166192
+ 275, /* (215) between_op ::= BETWEEN */
166193
+ 275, /* (216) between_op ::= NOT BETWEEN */
166194
+ 217, /* (217) expr ::= expr between_op expr AND expr */
166195
+ 276, /* (218) in_op ::= IN */
166196
+ 276, /* (219) in_op ::= NOT IN */
166197
+ 217, /* (220) expr ::= expr in_op LP exprlist RP */
166198
+ 217, /* (221) expr ::= LP select RP */
166199
+ 217, /* (222) expr ::= expr in_op LP select RP */
166200
+ 217, /* (223) expr ::= expr in_op nm dbnm paren_exprlist */
166201
+ 217, /* (224) expr ::= EXISTS LP select RP */
166202
+ 217, /* (225) expr ::= CASE case_operand case_exprlist case_else END */
166203
+ 279, /* (226) case_exprlist ::= case_exprlist WHEN expr THEN expr */
166204
+ 279, /* (227) case_exprlist ::= WHEN expr THEN expr */
166205
+ 280, /* (228) case_else ::= ELSE expr */
166206
+ 280, /* (229) case_else ::= */
166207
+ 278, /* (230) case_operand ::= expr */
166208
+ 278, /* (231) case_operand ::= */
166209
+ 261, /* (232) exprlist ::= */
166210
+ 253, /* (233) nexprlist ::= nexprlist COMMA expr */
166211
+ 253, /* (234) nexprlist ::= expr */
166212
+ 277, /* (235) paren_exprlist ::= */
166213
+ 277, /* (236) paren_exprlist ::= LP exprlist RP */
166214
+ 190, /* (237) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
166215
+ 281, /* (238) uniqueflag ::= UNIQUE */
166216
+ 281, /* (239) uniqueflag ::= */
166217
+ 221, /* (240) eidlist_opt ::= */
166218
+ 221, /* (241) eidlist_opt ::= LP eidlist RP */
166219
+ 232, /* (242) eidlist ::= eidlist COMMA nm collate sortorder */
166220
+ 232, /* (243) eidlist ::= nm collate sortorder */
166221
+ 282, /* (244) collate ::= */
166222
+ 282, /* (245) collate ::= COLLATE ID|STRING */
166223
+ 190, /* (246) cmd ::= DROP INDEX ifexists fullname */
166224
+ 190, /* (247) cmd ::= VACUUM vinto */
166225
+ 190, /* (248) cmd ::= VACUUM nm vinto */
166226
+ 283, /* (249) vinto ::= INTO expr */
166227
+ 283, /* (250) vinto ::= */
166228
+ 190, /* (251) cmd ::= PRAGMA nm dbnm */
166229
+ 190, /* (252) cmd ::= PRAGMA nm dbnm EQ nmnum */
166230
+ 190, /* (253) cmd ::= PRAGMA nm dbnm LP nmnum RP */
166231
+ 190, /* (254) cmd ::= PRAGMA nm dbnm EQ minus_num */
166232
+ 190, /* (255) cmd ::= PRAGMA nm dbnm LP minus_num RP */
166233
+ 211, /* (256) plus_num ::= PLUS INTEGER|FLOAT */
166234
+ 212, /* (257) minus_num ::= MINUS INTEGER|FLOAT */
166235
+ 190, /* (258) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
166236
+ 285, /* (259) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
166237
+ 287, /* (260) trigger_time ::= BEFORE|AFTER */
166238
+ 287, /* (261) trigger_time ::= INSTEAD OF */
166239
+ 287, /* (262) trigger_time ::= */
166240
+ 288, /* (263) trigger_event ::= DELETE|INSERT */
166241
+ 288, /* (264) trigger_event ::= UPDATE */
166242
+ 288, /* (265) trigger_event ::= UPDATE OF idlist */
166243
+ 290, /* (266) when_clause ::= */
166244
+ 290, /* (267) when_clause ::= WHEN expr */
166245
+ 286, /* (268) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
166246
+ 286, /* (269) trigger_cmd_list ::= trigger_cmd SEMI */
166247
+ 292, /* (270) trnm ::= nm DOT nm */
166248
+ 293, /* (271) tridxby ::= INDEXED BY nm */
166249
+ 293, /* (272) tridxby ::= NOT INDEXED */
166250
+ 291, /* (273) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
166251
+ 291, /* (274) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
166252
+ 291, /* (275) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
166253
+ 291, /* (276) trigger_cmd ::= scanpt select scanpt */
166254
+ 217, /* (277) expr ::= RAISE LP IGNORE RP */
166255
+ 217, /* (278) expr ::= RAISE LP raisetype COMMA nm RP */
166256
+ 236, /* (279) raisetype ::= ROLLBACK */
166257
+ 236, /* (280) raisetype ::= ABORT */
166258
+ 236, /* (281) raisetype ::= FAIL */
166259
+ 190, /* (282) cmd ::= DROP TRIGGER ifexists fullname */
166260
+ 190, /* (283) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
166261
+ 190, /* (284) cmd ::= DETACH database_kw_opt expr */
166262
+ 295, /* (285) key_opt ::= */
166263
+ 295, /* (286) key_opt ::= KEY expr */
166264
+ 190, /* (287) cmd ::= REINDEX */
166265
+ 190, /* (288) cmd ::= REINDEX nm dbnm */
166266
+ 190, /* (289) cmd ::= ANALYZE */
166267
+ 190, /* (290) cmd ::= ANALYZE nm dbnm */
166268
+ 190, /* (291) cmd ::= ALTER TABLE fullname RENAME TO nm */
166269
+ 190, /* (292) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
166270
+ 190, /* (293) cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
166271
+ 296, /* (294) add_column_fullname ::= fullname */
166272
+ 190, /* (295) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
166273
+ 190, /* (296) cmd ::= create_vtab */
166274
+ 190, /* (297) cmd ::= create_vtab LP vtabarglist RP */
166275
+ 298, /* (298) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
166276
+ 300, /* (299) vtabarg ::= */
166277
+ 301, /* (300) vtabargtoken ::= ANY */
166278
+ 301, /* (301) vtabargtoken ::= lp anylist RP */
166279
+ 302, /* (302) lp ::= LP */
166280
+ 266, /* (303) with ::= WITH wqlist */
166281
+ 266, /* (304) with ::= WITH RECURSIVE wqlist */
166282
+ 305, /* (305) wqas ::= AS */
166283
+ 305, /* (306) wqas ::= AS MATERIALIZED */
166284
+ 305, /* (307) wqas ::= AS NOT MATERIALIZED */
166285
+ 304, /* (308) wqitem ::= nm eidlist_opt wqas LP select RP */
166286
+ 241, /* (309) wqlist ::= wqitem */
166287
+ 241, /* (310) wqlist ::= wqlist COMMA wqitem */
166288
+ 306, /* (311) windowdefn_list ::= windowdefn */
166289
+ 306, /* (312) windowdefn_list ::= windowdefn_list COMMA windowdefn */
166290
+ 307, /* (313) windowdefn ::= nm AS LP window RP */
166291
+ 308, /* (314) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
166292
+ 308, /* (315) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
166293
+ 308, /* (316) window ::= ORDER BY sortlist frame_opt */
166294
+ 308, /* (317) window ::= nm ORDER BY sortlist frame_opt */
166295
+ 308, /* (318) window ::= frame_opt */
166296
+ 308, /* (319) window ::= nm frame_opt */
166297
+ 309, /* (320) frame_opt ::= */
166298
+ 309, /* (321) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
166299
+ 309, /* (322) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
166300
+ 313, /* (323) range_or_rows ::= RANGE|ROWS|GROUPS */
166301
+ 315, /* (324) frame_bound_s ::= frame_bound */
166302
+ 315, /* (325) frame_bound_s ::= UNBOUNDED PRECEDING */
166303
+ 316, /* (326) frame_bound_e ::= frame_bound */
166304
+ 316, /* (327) frame_bound_e ::= UNBOUNDED FOLLOWING */
166305
+ 314, /* (328) frame_bound ::= expr PRECEDING|FOLLOWING */
166306
+ 314, /* (329) frame_bound ::= CURRENT ROW */
166307
+ 317, /* (330) frame_exclude_opt ::= */
166308
+ 317, /* (331) frame_exclude_opt ::= EXCLUDE frame_exclude */
166309
+ 318, /* (332) frame_exclude ::= NO OTHERS */
166310
+ 318, /* (333) frame_exclude ::= CURRENT ROW */
166311
+ 318, /* (334) frame_exclude ::= GROUP|TIES */
166312
+ 251, /* (335) window_clause ::= WINDOW windowdefn_list */
166313
+ 273, /* (336) filter_over ::= filter_clause over_clause */
166314
+ 273, /* (337) filter_over ::= over_clause */
166315
+ 273, /* (338) filter_over ::= filter_clause */
166316
+ 312, /* (339) over_clause ::= OVER LP window RP */
166317
+ 312, /* (340) over_clause ::= OVER nm */
166318
+ 311, /* (341) filter_clause ::= FILTER LP WHERE expr RP */
166319
+ 185, /* (342) input ::= cmdlist */
166320
+ 186, /* (343) cmdlist ::= cmdlist ecmd */
166321
+ 186, /* (344) cmdlist ::= ecmd */
166322
+ 187, /* (345) ecmd ::= SEMI */
166323
+ 187, /* (346) ecmd ::= cmdx SEMI */
166324
+ 187, /* (347) ecmd ::= explain cmdx SEMI */
166325
+ 192, /* (348) trans_opt ::= */
166326
+ 192, /* (349) trans_opt ::= TRANSACTION */
166327
+ 192, /* (350) trans_opt ::= TRANSACTION nm */
166328
+ 194, /* (351) savepoint_opt ::= SAVEPOINT */
166329
+ 194, /* (352) savepoint_opt ::= */
166330
+ 190, /* (353) cmd ::= create_table create_table_args */
166331
+ 203, /* (354) table_option_set ::= table_option */
166332
+ 201, /* (355) columnlist ::= columnlist COMMA columnname carglist */
166333
+ 201, /* (356) columnlist ::= columnname carglist */
166334
+ 193, /* (357) nm ::= ID|INDEXED */
166335
+ 193, /* (358) nm ::= STRING */
166336
+ 193, /* (359) nm ::= JOIN_KW */
166337
+ 208, /* (360) typetoken ::= typename */
166338
+ 209, /* (361) typename ::= ID|STRING */
166339
+ 210, /* (362) signed ::= plus_num */
166340
+ 210, /* (363) signed ::= minus_num */
166341
+ 207, /* (364) carglist ::= carglist ccons */
166342
+ 207, /* (365) carglist ::= */
166343
+ 215, /* (366) ccons ::= NULL onconf */
166344
+ 215, /* (367) ccons ::= GENERATED ALWAYS AS generated */
166345
+ 215, /* (368) ccons ::= AS generated */
166346
+ 202, /* (369) conslist_opt ::= COMMA conslist */
166347
+ 228, /* (370) conslist ::= conslist tconscomma tcons */
166348
+ 228, /* (371) conslist ::= tcons */
166349
+ 229, /* (372) tconscomma ::= */
166350
+ 233, /* (373) defer_subclause_opt ::= defer_subclause */
166351
+ 235, /* (374) resolvetype ::= raisetype */
166352
+ 239, /* (375) selectnowith ::= oneselect */
166353
+ 240, /* (376) oneselect ::= values */
166354
+ 254, /* (377) sclp ::= selcollist COMMA */
166355
+ 255, /* (378) as ::= ID|STRING */
166356
+ 264, /* (379) indexed_opt ::= indexed_by */
166357
+ 272, /* (380) returning ::= */
166358
+ 217, /* (381) expr ::= term */
166359
+ 274, /* (382) likeop ::= LIKE_KW|MATCH */
166360
+ 261, /* (383) exprlist ::= nexprlist */
166361
+ 284, /* (384) nmnum ::= plus_num */
166362
+ 284, /* (385) nmnum ::= nm */
166363
+ 284, /* (386) nmnum ::= ON */
166364
+ 284, /* (387) nmnum ::= DELETE */
166365
+ 284, /* (388) nmnum ::= DEFAULT */
166366
+ 211, /* (389) plus_num ::= INTEGER|FLOAT */
166367
+ 289, /* (390) foreach_clause ::= */
166368
+ 289, /* (391) foreach_clause ::= FOR EACH ROW */
166369
+ 292, /* (392) trnm ::= nm */
166370
+ 293, /* (393) tridxby ::= */
166371
+ 294, /* (394) database_kw_opt ::= DATABASE */
166372
+ 294, /* (395) database_kw_opt ::= */
166373
+ 297, /* (396) kwcolumn_opt ::= */
166374
+ 297, /* (397) kwcolumn_opt ::= COLUMNKW */
166375
+ 299, /* (398) vtabarglist ::= vtabarg */
166376
+ 299, /* (399) vtabarglist ::= vtabarglist COMMA vtabarg */
166377
+ 300, /* (400) vtabarg ::= vtabarg vtabargtoken */
166378
+ 303, /* (401) anylist ::= */
166379
+ 303, /* (402) anylist ::= anylist LP anylist RP */
166380
+ 303, /* (403) anylist ::= anylist ANY */
166381
+ 266, /* (404) with ::= */
165963166382
};
165964166383
165965166384
/* For rule J, yyRuleInfoNRhs[J] contains the negative of the number
165966166385
** of symbols on the right-hand side of that rule. */
165967166386
static const signed char yyRuleInfoNRhs[] = {
@@ -166172,204 +166591,206 @@
166172166591
-5, /* (204) expr ::= expr likeop expr ESCAPE expr */
166173166592
-2, /* (205) expr ::= expr ISNULL|NOTNULL */
166174166593
-3, /* (206) expr ::= expr NOT NULL */
166175166594
-3, /* (207) expr ::= expr IS expr */
166176166595
-4, /* (208) expr ::= expr IS NOT expr */
166177
- -2, /* (209) expr ::= NOT expr */
166178
- -2, /* (210) expr ::= BITNOT expr */
166179
- -2, /* (211) expr ::= PLUS|MINUS expr */
166180
- -3, /* (212) expr ::= expr PTR expr */
166181
- -1, /* (213) between_op ::= BETWEEN */
166182
- -2, /* (214) between_op ::= NOT BETWEEN */
166183
- -5, /* (215) expr ::= expr between_op expr AND expr */
166184
- -1, /* (216) in_op ::= IN */
166185
- -2, /* (217) in_op ::= NOT IN */
166186
- -5, /* (218) expr ::= expr in_op LP exprlist RP */
166187
- -3, /* (219) expr ::= LP select RP */
166188
- -5, /* (220) expr ::= expr in_op LP select RP */
166189
- -5, /* (221) expr ::= expr in_op nm dbnm paren_exprlist */
166190
- -4, /* (222) expr ::= EXISTS LP select RP */
166191
- -5, /* (223) expr ::= CASE case_operand case_exprlist case_else END */
166192
- -5, /* (224) case_exprlist ::= case_exprlist WHEN expr THEN expr */
166193
- -4, /* (225) case_exprlist ::= WHEN expr THEN expr */
166194
- -2, /* (226) case_else ::= ELSE expr */
166195
- 0, /* (227) case_else ::= */
166196
- -1, /* (228) case_operand ::= expr */
166197
- 0, /* (229) case_operand ::= */
166198
- 0, /* (230) exprlist ::= */
166199
- -3, /* (231) nexprlist ::= nexprlist COMMA expr */
166200
- -1, /* (232) nexprlist ::= expr */
166201
- 0, /* (233) paren_exprlist ::= */
166202
- -3, /* (234) paren_exprlist ::= LP exprlist RP */
166203
- -12, /* (235) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
166204
- -1, /* (236) uniqueflag ::= UNIQUE */
166205
- 0, /* (237) uniqueflag ::= */
166206
- 0, /* (238) eidlist_opt ::= */
166207
- -3, /* (239) eidlist_opt ::= LP eidlist RP */
166208
- -5, /* (240) eidlist ::= eidlist COMMA nm collate sortorder */
166209
- -3, /* (241) eidlist ::= nm collate sortorder */
166210
- 0, /* (242) collate ::= */
166211
- -2, /* (243) collate ::= COLLATE ID|STRING */
166212
- -4, /* (244) cmd ::= DROP INDEX ifexists fullname */
166213
- -2, /* (245) cmd ::= VACUUM vinto */
166214
- -3, /* (246) cmd ::= VACUUM nm vinto */
166215
- -2, /* (247) vinto ::= INTO expr */
166216
- 0, /* (248) vinto ::= */
166217
- -3, /* (249) cmd ::= PRAGMA nm dbnm */
166218
- -5, /* (250) cmd ::= PRAGMA nm dbnm EQ nmnum */
166219
- -6, /* (251) cmd ::= PRAGMA nm dbnm LP nmnum RP */
166220
- -5, /* (252) cmd ::= PRAGMA nm dbnm EQ minus_num */
166221
- -6, /* (253) cmd ::= PRAGMA nm dbnm LP minus_num RP */
166222
- -2, /* (254) plus_num ::= PLUS INTEGER|FLOAT */
166223
- -2, /* (255) minus_num ::= MINUS INTEGER|FLOAT */
166224
- -5, /* (256) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
166225
- -11, /* (257) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
166226
- -1, /* (258) trigger_time ::= BEFORE|AFTER */
166227
- -2, /* (259) trigger_time ::= INSTEAD OF */
166228
- 0, /* (260) trigger_time ::= */
166229
- -1, /* (261) trigger_event ::= DELETE|INSERT */
166230
- -1, /* (262) trigger_event ::= UPDATE */
166231
- -3, /* (263) trigger_event ::= UPDATE OF idlist */
166232
- 0, /* (264) when_clause ::= */
166233
- -2, /* (265) when_clause ::= WHEN expr */
166234
- -3, /* (266) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
166235
- -2, /* (267) trigger_cmd_list ::= trigger_cmd SEMI */
166236
- -3, /* (268) trnm ::= nm DOT nm */
166237
- -3, /* (269) tridxby ::= INDEXED BY nm */
166238
- -2, /* (270) tridxby ::= NOT INDEXED */
166239
- -9, /* (271) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
166240
- -8, /* (272) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
166241
- -6, /* (273) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
166242
- -3, /* (274) trigger_cmd ::= scanpt select scanpt */
166243
- -4, /* (275) expr ::= RAISE LP IGNORE RP */
166244
- -6, /* (276) expr ::= RAISE LP raisetype COMMA nm RP */
166245
- -1, /* (277) raisetype ::= ROLLBACK */
166246
- -1, /* (278) raisetype ::= ABORT */
166247
- -1, /* (279) raisetype ::= FAIL */
166248
- -4, /* (280) cmd ::= DROP TRIGGER ifexists fullname */
166249
- -6, /* (281) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
166250
- -3, /* (282) cmd ::= DETACH database_kw_opt expr */
166251
- 0, /* (283) key_opt ::= */
166252
- -2, /* (284) key_opt ::= KEY expr */
166253
- -1, /* (285) cmd ::= REINDEX */
166254
- -3, /* (286) cmd ::= REINDEX nm dbnm */
166255
- -1, /* (287) cmd ::= ANALYZE */
166256
- -3, /* (288) cmd ::= ANALYZE nm dbnm */
166257
- -6, /* (289) cmd ::= ALTER TABLE fullname RENAME TO nm */
166258
- -7, /* (290) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
166259
- -6, /* (291) cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
166260
- -1, /* (292) add_column_fullname ::= fullname */
166261
- -8, /* (293) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
166262
- -1, /* (294) cmd ::= create_vtab */
166263
- -4, /* (295) cmd ::= create_vtab LP vtabarglist RP */
166264
- -8, /* (296) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
166265
- 0, /* (297) vtabarg ::= */
166266
- -1, /* (298) vtabargtoken ::= ANY */
166267
- -3, /* (299) vtabargtoken ::= lp anylist RP */
166268
- -1, /* (300) lp ::= LP */
166269
- -2, /* (301) with ::= WITH wqlist */
166270
- -3, /* (302) with ::= WITH RECURSIVE wqlist */
166271
- -1, /* (303) wqas ::= AS */
166272
- -2, /* (304) wqas ::= AS MATERIALIZED */
166273
- -3, /* (305) wqas ::= AS NOT MATERIALIZED */
166274
- -6, /* (306) wqitem ::= nm eidlist_opt wqas LP select RP */
166275
- -1, /* (307) wqlist ::= wqitem */
166276
- -3, /* (308) wqlist ::= wqlist COMMA wqitem */
166277
- -1, /* (309) windowdefn_list ::= windowdefn */
166278
- -3, /* (310) windowdefn_list ::= windowdefn_list COMMA windowdefn */
166279
- -5, /* (311) windowdefn ::= nm AS LP window RP */
166280
- -5, /* (312) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
166281
- -6, /* (313) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
166282
- -4, /* (314) window ::= ORDER BY sortlist frame_opt */
166283
- -5, /* (315) window ::= nm ORDER BY sortlist frame_opt */
166284
- -1, /* (316) window ::= frame_opt */
166285
- -2, /* (317) window ::= nm frame_opt */
166286
- 0, /* (318) frame_opt ::= */
166287
- -3, /* (319) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
166288
- -6, /* (320) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
166289
- -1, /* (321) range_or_rows ::= RANGE|ROWS|GROUPS */
166290
- -1, /* (322) frame_bound_s ::= frame_bound */
166291
- -2, /* (323) frame_bound_s ::= UNBOUNDED PRECEDING */
166292
- -1, /* (324) frame_bound_e ::= frame_bound */
166293
- -2, /* (325) frame_bound_e ::= UNBOUNDED FOLLOWING */
166294
- -2, /* (326) frame_bound ::= expr PRECEDING|FOLLOWING */
166295
- -2, /* (327) frame_bound ::= CURRENT ROW */
166296
- 0, /* (328) frame_exclude_opt ::= */
166297
- -2, /* (329) frame_exclude_opt ::= EXCLUDE frame_exclude */
166298
- -2, /* (330) frame_exclude ::= NO OTHERS */
166299
- -2, /* (331) frame_exclude ::= CURRENT ROW */
166300
- -1, /* (332) frame_exclude ::= GROUP|TIES */
166301
- -2, /* (333) window_clause ::= WINDOW windowdefn_list */
166302
- -2, /* (334) filter_over ::= filter_clause over_clause */
166303
- -1, /* (335) filter_over ::= over_clause */
166304
- -1, /* (336) filter_over ::= filter_clause */
166305
- -4, /* (337) over_clause ::= OVER LP window RP */
166306
- -2, /* (338) over_clause ::= OVER nm */
166307
- -5, /* (339) filter_clause ::= FILTER LP WHERE expr RP */
166308
- -1, /* (340) input ::= cmdlist */
166309
- -2, /* (341) cmdlist ::= cmdlist ecmd */
166310
- -1, /* (342) cmdlist ::= ecmd */
166311
- -1, /* (343) ecmd ::= SEMI */
166312
- -2, /* (344) ecmd ::= cmdx SEMI */
166313
- -3, /* (345) ecmd ::= explain cmdx SEMI */
166314
- 0, /* (346) trans_opt ::= */
166315
- -1, /* (347) trans_opt ::= TRANSACTION */
166316
- -2, /* (348) trans_opt ::= TRANSACTION nm */
166317
- -1, /* (349) savepoint_opt ::= SAVEPOINT */
166318
- 0, /* (350) savepoint_opt ::= */
166319
- -2, /* (351) cmd ::= create_table create_table_args */
166320
- -1, /* (352) table_option_set ::= table_option */
166321
- -4, /* (353) columnlist ::= columnlist COMMA columnname carglist */
166322
- -2, /* (354) columnlist ::= columnname carglist */
166323
- -1, /* (355) nm ::= ID|INDEXED */
166324
- -1, /* (356) nm ::= STRING */
166325
- -1, /* (357) nm ::= JOIN_KW */
166326
- -1, /* (358) typetoken ::= typename */
166327
- -1, /* (359) typename ::= ID|STRING */
166328
- -1, /* (360) signed ::= plus_num */
166329
- -1, /* (361) signed ::= minus_num */
166330
- -2, /* (362) carglist ::= carglist ccons */
166331
- 0, /* (363) carglist ::= */
166332
- -2, /* (364) ccons ::= NULL onconf */
166333
- -4, /* (365) ccons ::= GENERATED ALWAYS AS generated */
166334
- -2, /* (366) ccons ::= AS generated */
166335
- -2, /* (367) conslist_opt ::= COMMA conslist */
166336
- -3, /* (368) conslist ::= conslist tconscomma tcons */
166337
- -1, /* (369) conslist ::= tcons */
166338
- 0, /* (370) tconscomma ::= */
166339
- -1, /* (371) defer_subclause_opt ::= defer_subclause */
166340
- -1, /* (372) resolvetype ::= raisetype */
166341
- -1, /* (373) selectnowith ::= oneselect */
166342
- -1, /* (374) oneselect ::= values */
166343
- -2, /* (375) sclp ::= selcollist COMMA */
166344
- -1, /* (376) as ::= ID|STRING */
166345
- -1, /* (377) indexed_opt ::= indexed_by */
166346
- 0, /* (378) returning ::= */
166347
- -1, /* (379) expr ::= term */
166348
- -1, /* (380) likeop ::= LIKE_KW|MATCH */
166349
- -1, /* (381) exprlist ::= nexprlist */
166350
- -1, /* (382) nmnum ::= plus_num */
166351
- -1, /* (383) nmnum ::= nm */
166352
- -1, /* (384) nmnum ::= ON */
166353
- -1, /* (385) nmnum ::= DELETE */
166354
- -1, /* (386) nmnum ::= DEFAULT */
166355
- -1, /* (387) plus_num ::= INTEGER|FLOAT */
166356
- 0, /* (388) foreach_clause ::= */
166357
- -3, /* (389) foreach_clause ::= FOR EACH ROW */
166358
- -1, /* (390) trnm ::= nm */
166359
- 0, /* (391) tridxby ::= */
166360
- -1, /* (392) database_kw_opt ::= DATABASE */
166361
- 0, /* (393) database_kw_opt ::= */
166362
- 0, /* (394) kwcolumn_opt ::= */
166363
- -1, /* (395) kwcolumn_opt ::= COLUMNKW */
166364
- -1, /* (396) vtabarglist ::= vtabarg */
166365
- -3, /* (397) vtabarglist ::= vtabarglist COMMA vtabarg */
166366
- -2, /* (398) vtabarg ::= vtabarg vtabargtoken */
166367
- 0, /* (399) anylist ::= */
166368
- -4, /* (400) anylist ::= anylist LP anylist RP */
166369
- -2, /* (401) anylist ::= anylist ANY */
166370
- 0, /* (402) with ::= */
166596
+ -6, /* (209) expr ::= expr IS NOT DISTINCT FROM expr */
166597
+ -5, /* (210) expr ::= expr IS DISTINCT FROM expr */
166598
+ -2, /* (211) expr ::= NOT expr */
166599
+ -2, /* (212) expr ::= BITNOT expr */
166600
+ -2, /* (213) expr ::= PLUS|MINUS expr */
166601
+ -3, /* (214) expr ::= expr PTR expr */
166602
+ -1, /* (215) between_op ::= BETWEEN */
166603
+ -2, /* (216) between_op ::= NOT BETWEEN */
166604
+ -5, /* (217) expr ::= expr between_op expr AND expr */
166605
+ -1, /* (218) in_op ::= IN */
166606
+ -2, /* (219) in_op ::= NOT IN */
166607
+ -5, /* (220) expr ::= expr in_op LP exprlist RP */
166608
+ -3, /* (221) expr ::= LP select RP */
166609
+ -5, /* (222) expr ::= expr in_op LP select RP */
166610
+ -5, /* (223) expr ::= expr in_op nm dbnm paren_exprlist */
166611
+ -4, /* (224) expr ::= EXISTS LP select RP */
166612
+ -5, /* (225) expr ::= CASE case_operand case_exprlist case_else END */
166613
+ -5, /* (226) case_exprlist ::= case_exprlist WHEN expr THEN expr */
166614
+ -4, /* (227) case_exprlist ::= WHEN expr THEN expr */
166615
+ -2, /* (228) case_else ::= ELSE expr */
166616
+ 0, /* (229) case_else ::= */
166617
+ -1, /* (230) case_operand ::= expr */
166618
+ 0, /* (231) case_operand ::= */
166619
+ 0, /* (232) exprlist ::= */
166620
+ -3, /* (233) nexprlist ::= nexprlist COMMA expr */
166621
+ -1, /* (234) nexprlist ::= expr */
166622
+ 0, /* (235) paren_exprlist ::= */
166623
+ -3, /* (236) paren_exprlist ::= LP exprlist RP */
166624
+ -12, /* (237) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
166625
+ -1, /* (238) uniqueflag ::= UNIQUE */
166626
+ 0, /* (239) uniqueflag ::= */
166627
+ 0, /* (240) eidlist_opt ::= */
166628
+ -3, /* (241) eidlist_opt ::= LP eidlist RP */
166629
+ -5, /* (242) eidlist ::= eidlist COMMA nm collate sortorder */
166630
+ -3, /* (243) eidlist ::= nm collate sortorder */
166631
+ 0, /* (244) collate ::= */
166632
+ -2, /* (245) collate ::= COLLATE ID|STRING */
166633
+ -4, /* (246) cmd ::= DROP INDEX ifexists fullname */
166634
+ -2, /* (247) cmd ::= VACUUM vinto */
166635
+ -3, /* (248) cmd ::= VACUUM nm vinto */
166636
+ -2, /* (249) vinto ::= INTO expr */
166637
+ 0, /* (250) vinto ::= */
166638
+ -3, /* (251) cmd ::= PRAGMA nm dbnm */
166639
+ -5, /* (252) cmd ::= PRAGMA nm dbnm EQ nmnum */
166640
+ -6, /* (253) cmd ::= PRAGMA nm dbnm LP nmnum RP */
166641
+ -5, /* (254) cmd ::= PRAGMA nm dbnm EQ minus_num */
166642
+ -6, /* (255) cmd ::= PRAGMA nm dbnm LP minus_num RP */
166643
+ -2, /* (256) plus_num ::= PLUS INTEGER|FLOAT */
166644
+ -2, /* (257) minus_num ::= MINUS INTEGER|FLOAT */
166645
+ -5, /* (258) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
166646
+ -11, /* (259) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
166647
+ -1, /* (260) trigger_time ::= BEFORE|AFTER */
166648
+ -2, /* (261) trigger_time ::= INSTEAD OF */
166649
+ 0, /* (262) trigger_time ::= */
166650
+ -1, /* (263) trigger_event ::= DELETE|INSERT */
166651
+ -1, /* (264) trigger_event ::= UPDATE */
166652
+ -3, /* (265) trigger_event ::= UPDATE OF idlist */
166653
+ 0, /* (266) when_clause ::= */
166654
+ -2, /* (267) when_clause ::= WHEN expr */
166655
+ -3, /* (268) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
166656
+ -2, /* (269) trigger_cmd_list ::= trigger_cmd SEMI */
166657
+ -3, /* (270) trnm ::= nm DOT nm */
166658
+ -3, /* (271) tridxby ::= INDEXED BY nm */
166659
+ -2, /* (272) tridxby ::= NOT INDEXED */
166660
+ -9, /* (273) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
166661
+ -8, /* (274) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
166662
+ -6, /* (275) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
166663
+ -3, /* (276) trigger_cmd ::= scanpt select scanpt */
166664
+ -4, /* (277) expr ::= RAISE LP IGNORE RP */
166665
+ -6, /* (278) expr ::= RAISE LP raisetype COMMA nm RP */
166666
+ -1, /* (279) raisetype ::= ROLLBACK */
166667
+ -1, /* (280) raisetype ::= ABORT */
166668
+ -1, /* (281) raisetype ::= FAIL */
166669
+ -4, /* (282) cmd ::= DROP TRIGGER ifexists fullname */
166670
+ -6, /* (283) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
166671
+ -3, /* (284) cmd ::= DETACH database_kw_opt expr */
166672
+ 0, /* (285) key_opt ::= */
166673
+ -2, /* (286) key_opt ::= KEY expr */
166674
+ -1, /* (287) cmd ::= REINDEX */
166675
+ -3, /* (288) cmd ::= REINDEX nm dbnm */
166676
+ -1, /* (289) cmd ::= ANALYZE */
166677
+ -3, /* (290) cmd ::= ANALYZE nm dbnm */
166678
+ -6, /* (291) cmd ::= ALTER TABLE fullname RENAME TO nm */
166679
+ -7, /* (292) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
166680
+ -6, /* (293) cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
166681
+ -1, /* (294) add_column_fullname ::= fullname */
166682
+ -8, /* (295) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
166683
+ -1, /* (296) cmd ::= create_vtab */
166684
+ -4, /* (297) cmd ::= create_vtab LP vtabarglist RP */
166685
+ -8, /* (298) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
166686
+ 0, /* (299) vtabarg ::= */
166687
+ -1, /* (300) vtabargtoken ::= ANY */
166688
+ -3, /* (301) vtabargtoken ::= lp anylist RP */
166689
+ -1, /* (302) lp ::= LP */
166690
+ -2, /* (303) with ::= WITH wqlist */
166691
+ -3, /* (304) with ::= WITH RECURSIVE wqlist */
166692
+ -1, /* (305) wqas ::= AS */
166693
+ -2, /* (306) wqas ::= AS MATERIALIZED */
166694
+ -3, /* (307) wqas ::= AS NOT MATERIALIZED */
166695
+ -6, /* (308) wqitem ::= nm eidlist_opt wqas LP select RP */
166696
+ -1, /* (309) wqlist ::= wqitem */
166697
+ -3, /* (310) wqlist ::= wqlist COMMA wqitem */
166698
+ -1, /* (311) windowdefn_list ::= windowdefn */
166699
+ -3, /* (312) windowdefn_list ::= windowdefn_list COMMA windowdefn */
166700
+ -5, /* (313) windowdefn ::= nm AS LP window RP */
166701
+ -5, /* (314) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
166702
+ -6, /* (315) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
166703
+ -4, /* (316) window ::= ORDER BY sortlist frame_opt */
166704
+ -5, /* (317) window ::= nm ORDER BY sortlist frame_opt */
166705
+ -1, /* (318) window ::= frame_opt */
166706
+ -2, /* (319) window ::= nm frame_opt */
166707
+ 0, /* (320) frame_opt ::= */
166708
+ -3, /* (321) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
166709
+ -6, /* (322) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
166710
+ -1, /* (323) range_or_rows ::= RANGE|ROWS|GROUPS */
166711
+ -1, /* (324) frame_bound_s ::= frame_bound */
166712
+ -2, /* (325) frame_bound_s ::= UNBOUNDED PRECEDING */
166713
+ -1, /* (326) frame_bound_e ::= frame_bound */
166714
+ -2, /* (327) frame_bound_e ::= UNBOUNDED FOLLOWING */
166715
+ -2, /* (328) frame_bound ::= expr PRECEDING|FOLLOWING */
166716
+ -2, /* (329) frame_bound ::= CURRENT ROW */
166717
+ 0, /* (330) frame_exclude_opt ::= */
166718
+ -2, /* (331) frame_exclude_opt ::= EXCLUDE frame_exclude */
166719
+ -2, /* (332) frame_exclude ::= NO OTHERS */
166720
+ -2, /* (333) frame_exclude ::= CURRENT ROW */
166721
+ -1, /* (334) frame_exclude ::= GROUP|TIES */
166722
+ -2, /* (335) window_clause ::= WINDOW windowdefn_list */
166723
+ -2, /* (336) filter_over ::= filter_clause over_clause */
166724
+ -1, /* (337) filter_over ::= over_clause */
166725
+ -1, /* (338) filter_over ::= filter_clause */
166726
+ -4, /* (339) over_clause ::= OVER LP window RP */
166727
+ -2, /* (340) over_clause ::= OVER nm */
166728
+ -5, /* (341) filter_clause ::= FILTER LP WHERE expr RP */
166729
+ -1, /* (342) input ::= cmdlist */
166730
+ -2, /* (343) cmdlist ::= cmdlist ecmd */
166731
+ -1, /* (344) cmdlist ::= ecmd */
166732
+ -1, /* (345) ecmd ::= SEMI */
166733
+ -2, /* (346) ecmd ::= cmdx SEMI */
166734
+ -3, /* (347) ecmd ::= explain cmdx SEMI */
166735
+ 0, /* (348) trans_opt ::= */
166736
+ -1, /* (349) trans_opt ::= TRANSACTION */
166737
+ -2, /* (350) trans_opt ::= TRANSACTION nm */
166738
+ -1, /* (351) savepoint_opt ::= SAVEPOINT */
166739
+ 0, /* (352) savepoint_opt ::= */
166740
+ -2, /* (353) cmd ::= create_table create_table_args */
166741
+ -1, /* (354) table_option_set ::= table_option */
166742
+ -4, /* (355) columnlist ::= columnlist COMMA columnname carglist */
166743
+ -2, /* (356) columnlist ::= columnname carglist */
166744
+ -1, /* (357) nm ::= ID|INDEXED */
166745
+ -1, /* (358) nm ::= STRING */
166746
+ -1, /* (359) nm ::= JOIN_KW */
166747
+ -1, /* (360) typetoken ::= typename */
166748
+ -1, /* (361) typename ::= ID|STRING */
166749
+ -1, /* (362) signed ::= plus_num */
166750
+ -1, /* (363) signed ::= minus_num */
166751
+ -2, /* (364) carglist ::= carglist ccons */
166752
+ 0, /* (365) carglist ::= */
166753
+ -2, /* (366) ccons ::= NULL onconf */
166754
+ -4, /* (367) ccons ::= GENERATED ALWAYS AS generated */
166755
+ -2, /* (368) ccons ::= AS generated */
166756
+ -2, /* (369) conslist_opt ::= COMMA conslist */
166757
+ -3, /* (370) conslist ::= conslist tconscomma tcons */
166758
+ -1, /* (371) conslist ::= tcons */
166759
+ 0, /* (372) tconscomma ::= */
166760
+ -1, /* (373) defer_subclause_opt ::= defer_subclause */
166761
+ -1, /* (374) resolvetype ::= raisetype */
166762
+ -1, /* (375) selectnowith ::= oneselect */
166763
+ -1, /* (376) oneselect ::= values */
166764
+ -2, /* (377) sclp ::= selcollist COMMA */
166765
+ -1, /* (378) as ::= ID|STRING */
166766
+ -1, /* (379) indexed_opt ::= indexed_by */
166767
+ 0, /* (380) returning ::= */
166768
+ -1, /* (381) expr ::= term */
166769
+ -1, /* (382) likeop ::= LIKE_KW|MATCH */
166770
+ -1, /* (383) exprlist ::= nexprlist */
166771
+ -1, /* (384) nmnum ::= plus_num */
166772
+ -1, /* (385) nmnum ::= nm */
166773
+ -1, /* (386) nmnum ::= ON */
166774
+ -1, /* (387) nmnum ::= DELETE */
166775
+ -1, /* (388) nmnum ::= DEFAULT */
166776
+ -1, /* (389) plus_num ::= INTEGER|FLOAT */
166777
+ 0, /* (390) foreach_clause ::= */
166778
+ -3, /* (391) foreach_clause ::= FOR EACH ROW */
166779
+ -1, /* (392) trnm ::= nm */
166780
+ 0, /* (393) tridxby ::= */
166781
+ -1, /* (394) database_kw_opt ::= DATABASE */
166782
+ 0, /* (395) database_kw_opt ::= */
166783
+ 0, /* (396) kwcolumn_opt ::= */
166784
+ -1, /* (397) kwcolumn_opt ::= COLUMNKW */
166785
+ -1, /* (398) vtabarglist ::= vtabarg */
166786
+ -3, /* (399) vtabarglist ::= vtabarglist COMMA vtabarg */
166787
+ -2, /* (400) vtabarg ::= vtabarg vtabargtoken */
166788
+ 0, /* (401) anylist ::= */
166789
+ -4, /* (402) anylist ::= anylist LP anylist RP */
166790
+ -2, /* (403) anylist ::= anylist ANY */
166791
+ 0, /* (404) with ::= */
166371166792
};
166372166793
166373166794
static void yy_accept(yyParser*); /* Forward Declaration */
166374166795
166375166796
/*
@@ -166425,11 +166846,11 @@
166425166846
{yymsp[1].minor.yy394 = TK_DEFERRED;}
166426166847
break;
166427166848
case 5: /* transtype ::= DEFERRED */
166428166849
case 6: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==6);
166429166850
case 7: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==7);
166430
- case 321: /* range_or_rows ::= RANGE|ROWS|GROUPS */ yytestcase(yyruleno==321);
166851
+ case 323: /* range_or_rows ::= RANGE|ROWS|GROUPS */ yytestcase(yyruleno==323);
166431166852
{yymsp[0].minor.yy394 = yymsp[0].major; /*A-overwrites-X*/}
166432166853
break;
166433166854
case 8: /* cmd ::= COMMIT|END trans_opt */
166434166855
case 9: /* cmd ::= ROLLBACK trans_opt */ yytestcase(yyruleno==9);
166435166856
{sqlite3EndTransaction(pParse,yymsp[-1].major);}
@@ -166462,11 +166883,11 @@
166462166883
case 47: /* autoinc ::= */ yytestcase(yyruleno==47);
166463166884
case 62: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==62);
166464166885
case 72: /* defer_subclause_opt ::= */ yytestcase(yyruleno==72);
166465166886
case 81: /* ifexists ::= */ yytestcase(yyruleno==81);
166466166887
case 98: /* distinct ::= */ yytestcase(yyruleno==98);
166467
- case 242: /* collate ::= */ yytestcase(yyruleno==242);
166888
+ case 244: /* collate ::= */ yytestcase(yyruleno==244);
166468166889
{yymsp[1].minor.yy394 = 0;}
166469166890
break;
166470166891
case 16: /* ifnotexists ::= IF NOT EXISTS */
166471166892
{yymsp[-2].minor.yy394 = 1;}
166472166893
break;
@@ -166646,13 +167067,13 @@
166646167067
case 171: /* insert_cmd ::= INSERT orconf */ yytestcase(yyruleno==171);
166647167068
{yymsp[-1].minor.yy394 = yymsp[0].minor.yy394;}
166648167069
break;
166649167070
case 63: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
166650167071
case 80: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==80);
166651
- case 214: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==214);
166652
- case 217: /* in_op ::= NOT IN */ yytestcase(yyruleno==217);
166653
- case 243: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==243);
167072
+ case 216: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==216);
167073
+ case 219: /* in_op ::= NOT IN */ yytestcase(yyruleno==219);
167074
+ case 245: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==245);
166654167075
{yymsp[-1].minor.yy394 = 1;}
166655167076
break;
166656167077
case 64: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
166657167078
{yymsp[-1].minor.yy394 = 0;}
166658167079
break;
@@ -166798,13 +167219,13 @@
166798167219
{yymsp[0].minor.yy394 = SF_All;}
166799167220
break;
166800167221
case 99: /* sclp ::= */
166801167222
case 132: /* orderby_opt ::= */ yytestcase(yyruleno==132);
166802167223
case 142: /* groupby_opt ::= */ yytestcase(yyruleno==142);
166803
- case 230: /* exprlist ::= */ yytestcase(yyruleno==230);
166804
- case 233: /* paren_exprlist ::= */ yytestcase(yyruleno==233);
166805
- case 238: /* eidlist_opt ::= */ yytestcase(yyruleno==238);
167224
+ case 232: /* exprlist ::= */ yytestcase(yyruleno==232);
167225
+ case 235: /* paren_exprlist ::= */ yytestcase(yyruleno==235);
167226
+ case 240: /* eidlist_opt ::= */ yytestcase(yyruleno==240);
166806167227
{yymsp[1].minor.yy322 = 0;}
166807167228
break;
166808167229
case 100: /* selcollist ::= sclp scanpt expr scanpt as */
166809167230
{
166810167231
yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy322, yymsp[-2].minor.yy528);
@@ -166826,12 +167247,12 @@
166826167247
yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, pDot);
166827167248
}
166828167249
break;
166829167250
case 103: /* as ::= AS nm */
166830167251
case 115: /* dbnm ::= DOT nm */ yytestcase(yyruleno==115);
166831
- case 254: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==254);
166832
- case 255: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==255);
167252
+ case 256: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==256);
167253
+ case 257: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==257);
166833167254
{yymsp[-1].minor.yy0 = yymsp[0].minor.yy0;}
166834167255
break;
166835167256
case 105: /* from ::= */
166836167257
case 108: /* stl_prefix ::= */ yytestcase(yyruleno==108);
166837167258
{yymsp[1].minor.yy131 = 0;}
@@ -166999,20 +167420,20 @@
166999167420
break;
167000167421
case 144: /* having_opt ::= */
167001167422
case 146: /* limit_opt ::= */ yytestcase(yyruleno==146);
167002167423
case 151: /* where_opt ::= */ yytestcase(yyruleno==151);
167003167424
case 153: /* where_opt_ret ::= */ yytestcase(yyruleno==153);
167004
- case 227: /* case_else ::= */ yytestcase(yyruleno==227);
167005
- case 229: /* case_operand ::= */ yytestcase(yyruleno==229);
167006
- case 248: /* vinto ::= */ yytestcase(yyruleno==248);
167425
+ case 229: /* case_else ::= */ yytestcase(yyruleno==229);
167426
+ case 231: /* case_operand ::= */ yytestcase(yyruleno==231);
167427
+ case 250: /* vinto ::= */ yytestcase(yyruleno==250);
167007167428
{yymsp[1].minor.yy528 = 0;}
167008167429
break;
167009167430
case 145: /* having_opt ::= HAVING expr */
167010167431
case 152: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==152);
167011167432
case 154: /* where_opt_ret ::= WHERE expr */ yytestcase(yyruleno==154);
167012
- case 226: /* case_else ::= ELSE expr */ yytestcase(yyruleno==226);
167013
- case 247: /* vinto ::= INTO expr */ yytestcase(yyruleno==247);
167433
+ case 228: /* case_else ::= ELSE expr */ yytestcase(yyruleno==228);
167434
+ case 249: /* vinto ::= INTO expr */ yytestcase(yyruleno==249);
167014167435
{yymsp[-1].minor.yy528 = yymsp[0].minor.yy528;}
167015167436
break;
167016167437
case 147: /* limit_opt ::= LIMIT expr */
167017167438
{yymsp[-1].minor.yy528 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy528,0);}
167018167439
break;
@@ -167036,11 +167457,22 @@
167036167457
break;
167037167458
case 157: /* cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist from where_opt_ret */
167038167459
{
167039167460
sqlite3SrcListIndexedBy(pParse, yymsp[-5].minor.yy131, &yymsp[-4].minor.yy0);
167040167461
sqlite3ExprListCheckLength(pParse,yymsp[-2].minor.yy322,"set list");
167041
- yymsp[-5].minor.yy131 = sqlite3SrcListAppendList(pParse, yymsp[-5].minor.yy131, yymsp[-1].minor.yy131);
167462
+ if( yymsp[-1].minor.yy131 ){
167463
+ SrcList *pFromClause = yymsp[-1].minor.yy131;
167464
+ if( pFromClause->nSrc>1 ){
167465
+ Select *pSubquery;
167466
+ Token as;
167467
+ pSubquery = sqlite3SelectNew(pParse,0,pFromClause,0,0,0,0,SF_NestedFrom,0);
167468
+ as.n = 0;
167469
+ as.z = 0;
167470
+ pFromClause = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&as,pSubquery,0);
167471
+ }
167472
+ yymsp[-5].minor.yy131 = sqlite3SrcListAppendList(pParse, yymsp[-5].minor.yy131, pFromClause);
167473
+ }
167042167474
sqlite3Update(pParse,yymsp[-5].minor.yy131,yymsp[-2].minor.yy322,yymsp[0].minor.yy528,yymsp[-6].minor.yy394,0,0,0);
167043167475
}
167044167476
break;
167045167477
case 158: /* setlist ::= setlist COMMA nm EQ expr */
167046167478
{
@@ -167282,33 +167714,45 @@
167282167714
{
167283167715
yymsp[-3].minor.yy528 = sqlite3PExpr(pParse,TK_ISNOT,yymsp[-3].minor.yy528,yymsp[0].minor.yy528);
167284167716
binaryToUnaryIfNull(pParse, yymsp[0].minor.yy528, yymsp[-3].minor.yy528, TK_NOTNULL);
167285167717
}
167286167718
break;
167287
- case 209: /* expr ::= NOT expr */
167288
- case 210: /* expr ::= BITNOT expr */ yytestcase(yyruleno==210);
167719
+ case 209: /* expr ::= expr IS NOT DISTINCT FROM expr */
167720
+{
167721
+ yymsp[-5].minor.yy528 = sqlite3PExpr(pParse,TK_IS,yymsp[-5].minor.yy528,yymsp[0].minor.yy528);
167722
+ binaryToUnaryIfNull(pParse, yymsp[0].minor.yy528, yymsp[-5].minor.yy528, TK_ISNULL);
167723
+}
167724
+ break;
167725
+ case 210: /* expr ::= expr IS DISTINCT FROM expr */
167726
+{
167727
+ yymsp[-4].minor.yy528 = sqlite3PExpr(pParse,TK_ISNOT,yymsp[-4].minor.yy528,yymsp[0].minor.yy528);
167728
+ binaryToUnaryIfNull(pParse, yymsp[0].minor.yy528, yymsp[-4].minor.yy528, TK_NOTNULL);
167729
+}
167730
+ break;
167731
+ case 211: /* expr ::= NOT expr */
167732
+ case 212: /* expr ::= BITNOT expr */ yytestcase(yyruleno==212);
167289167733
{yymsp[-1].minor.yy528 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy528, 0);/*A-overwrites-B*/}
167290167734
break;
167291
- case 211: /* expr ::= PLUS|MINUS expr */
167735
+ case 213: /* expr ::= PLUS|MINUS expr */
167292167736
{
167293167737
yymsp[-1].minor.yy528 = sqlite3PExpr(pParse, yymsp[-1].major==TK_PLUS ? TK_UPLUS : TK_UMINUS, yymsp[0].minor.yy528, 0);
167294167738
/*A-overwrites-B*/
167295167739
}
167296167740
break;
167297
- case 212: /* expr ::= expr PTR expr */
167741
+ case 214: /* expr ::= expr PTR expr */
167298167742
{
167299167743
ExprList *pList = sqlite3ExprListAppend(pParse, 0, yymsp[-2].minor.yy528);
167300167744
pList = sqlite3ExprListAppend(pParse, pList, yymsp[0].minor.yy528);
167301167745
yylhsminor.yy528 = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy0, 0);
167302167746
}
167303167747
yymsp[-2].minor.yy528 = yylhsminor.yy528;
167304167748
break;
167305
- case 213: /* between_op ::= BETWEEN */
167306
- case 216: /* in_op ::= IN */ yytestcase(yyruleno==216);
167749
+ case 215: /* between_op ::= BETWEEN */
167750
+ case 218: /* in_op ::= IN */ yytestcase(yyruleno==218);
167307167751
{yymsp[0].minor.yy394 = 0;}
167308167752
break;
167309
- case 215: /* expr ::= expr between_op expr AND expr */
167753
+ case 217: /* expr ::= expr between_op expr AND expr */
167310167754
{
167311167755
ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy528);
167312167756
pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy528);
167313167757
yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy528, 0);
167314167758
if( yymsp[-4].minor.yy528 ){
@@ -167317,11 +167761,11 @@
167317167761
sqlite3ExprListDelete(pParse->db, pList);
167318167762
}
167319167763
if( yymsp[-3].minor.yy394 ) yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy528, 0);
167320167764
}
167321167765
break;
167322
- case 218: /* expr ::= expr in_op LP exprlist RP */
167766
+ case 220: /* expr ::= expr in_op LP exprlist RP */
167323167767
{
167324167768
if( yymsp[-1].minor.yy322==0 ){
167325167769
/* Expressions of the form
167326167770
**
167327167771
** expr1 IN ()
@@ -167329,11 +167773,12 @@
167329167773
**
167330167774
** simplify to constants 0 (false) and 1 (true), respectively,
167331167775
** regardless of the value of expr1.
167332167776
*/
167333167777
sqlite3ExprUnmapAndDelete(pParse, yymsp[-4].minor.yy528);
167334
- yymsp[-4].minor.yy528 = sqlite3Expr(pParse->db, TK_INTEGER, yymsp[-3].minor.yy394 ? "1" : "0");
167778
+ yymsp[-4].minor.yy528 = sqlite3Expr(pParse->db, TK_STRING, yymsp[-3].minor.yy394 ? "true" : "false");
167779
+ if( yymsp[-4].minor.yy528 ) sqlite3ExprIdToTrueFalse(yymsp[-4].minor.yy528);
167335167780
}else{
167336167781
Expr *pRHS = yymsp[-1].minor.yy322->a[0].pExpr;
167337167782
if( yymsp[-1].minor.yy322->nExpr==1 && sqlite3ExprIsConstant(pRHS) && yymsp[-4].minor.yy528->op!=TK_VECTOR ){
167338167783
yymsp[-1].minor.yy322->a[0].pExpr = 0;
167339167784
sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy322);
@@ -167357,41 +167802,41 @@
167357167802
}
167358167803
if( yymsp[-3].minor.yy394 ) yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy528, 0);
167359167804
}
167360167805
}
167361167806
break;
167362
- case 219: /* expr ::= LP select RP */
167807
+ case 221: /* expr ::= LP select RP */
167363167808
{
167364167809
yymsp[-2].minor.yy528 = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
167365167810
sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy528, yymsp[-1].minor.yy47);
167366167811
}
167367167812
break;
167368
- case 220: /* expr ::= expr in_op LP select RP */
167813
+ case 222: /* expr ::= expr in_op LP select RP */
167369167814
{
167370167815
yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy528, 0);
167371167816
sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy528, yymsp[-1].minor.yy47);
167372167817
if( yymsp[-3].minor.yy394 ) yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy528, 0);
167373167818
}
167374167819
break;
167375
- case 221: /* expr ::= expr in_op nm dbnm paren_exprlist */
167820
+ case 223: /* expr ::= expr in_op nm dbnm paren_exprlist */
167376167821
{
167377167822
SrcList *pSrc = sqlite3SrcListAppend(pParse, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);
167378167823
Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0);
167379167824
if( yymsp[0].minor.yy322 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy322);
167380167825
yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy528, 0);
167381167826
sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy528, pSelect);
167382167827
if( yymsp[-3].minor.yy394 ) yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy528, 0);
167383167828
}
167384167829
break;
167385
- case 222: /* expr ::= EXISTS LP select RP */
167830
+ case 224: /* expr ::= EXISTS LP select RP */
167386167831
{
167387167832
Expr *p;
167388167833
p = yymsp[-3].minor.yy528 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
167389167834
sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy47);
167390167835
}
167391167836
break;
167392
- case 223: /* expr ::= CASE case_operand case_exprlist case_else END */
167837
+ case 225: /* expr ::= CASE case_operand case_exprlist case_else END */
167393167838
{
167394167839
yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy528, 0);
167395167840
if( yymsp[-4].minor.yy528 ){
167396167841
yymsp[-4].minor.yy528->x.pList = yymsp[-1].minor.yy528 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[-1].minor.yy528) : yymsp[-2].minor.yy322;
167397167842
sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy528);
@@ -167399,406 +167844,406 @@
167399167844
sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy322);
167400167845
sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy528);
167401167846
}
167402167847
}
167403167848
break;
167404
- case 224: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
167849
+ case 226: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
167405167850
{
167406167851
yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, yymsp[-2].minor.yy528);
167407167852
yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, yymsp[0].minor.yy528);
167408167853
}
167409167854
break;
167410
- case 225: /* case_exprlist ::= WHEN expr THEN expr */
167855
+ case 227: /* case_exprlist ::= WHEN expr THEN expr */
167411167856
{
167412167857
yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy528);
167413167858
yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322, yymsp[0].minor.yy528);
167414167859
}
167415167860
break;
167416
- case 228: /* case_operand ::= expr */
167861
+ case 230: /* case_operand ::= expr */
167417167862
{yymsp[0].minor.yy528 = yymsp[0].minor.yy528; /*A-overwrites-X*/}
167418167863
break;
167419
- case 231: /* nexprlist ::= nexprlist COMMA expr */
167864
+ case 233: /* nexprlist ::= nexprlist COMMA expr */
167420167865
{yymsp[-2].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[0].minor.yy528);}
167421167866
break;
167422
- case 232: /* nexprlist ::= expr */
167867
+ case 234: /* nexprlist ::= expr */
167423167868
{yymsp[0].minor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy528); /*A-overwrites-Y*/}
167424167869
break;
167425
- case 234: /* paren_exprlist ::= LP exprlist RP */
167426
- case 239: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==239);
167870
+ case 236: /* paren_exprlist ::= LP exprlist RP */
167871
+ case 241: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==241);
167427167872
{yymsp[-2].minor.yy322 = yymsp[-1].minor.yy322;}
167428167873
break;
167429
- case 235: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
167874
+ case 237: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
167430167875
{
167431167876
sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0,
167432167877
sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy322, yymsp[-10].minor.yy394,
167433167878
&yymsp[-11].minor.yy0, yymsp[0].minor.yy528, SQLITE_SO_ASC, yymsp[-8].minor.yy394, SQLITE_IDXTYPE_APPDEF);
167434167879
if( IN_RENAME_OBJECT && pParse->pNewIndex ){
167435167880
sqlite3RenameTokenMap(pParse, pParse->pNewIndex->zName, &yymsp[-4].minor.yy0);
167436167881
}
167437167882
}
167438167883
break;
167439
- case 236: /* uniqueflag ::= UNIQUE */
167440
- case 278: /* raisetype ::= ABORT */ yytestcase(yyruleno==278);
167884
+ case 238: /* uniqueflag ::= UNIQUE */
167885
+ case 280: /* raisetype ::= ABORT */ yytestcase(yyruleno==280);
167441167886
{yymsp[0].minor.yy394 = OE_Abort;}
167442167887
break;
167443
- case 237: /* uniqueflag ::= */
167888
+ case 239: /* uniqueflag ::= */
167444167889
{yymsp[1].minor.yy394 = OE_None;}
167445167890
break;
167446
- case 240: /* eidlist ::= eidlist COMMA nm collate sortorder */
167891
+ case 242: /* eidlist ::= eidlist COMMA nm collate sortorder */
167447167892
{
167448167893
yymsp[-4].minor.yy322 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy322, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy394, yymsp[0].minor.yy394);
167449167894
}
167450167895
break;
167451
- case 241: /* eidlist ::= nm collate sortorder */
167896
+ case 243: /* eidlist ::= nm collate sortorder */
167452167897
{
167453167898
yymsp[-2].minor.yy322 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy394, yymsp[0].minor.yy394); /*A-overwrites-Y*/
167454167899
}
167455167900
break;
167456
- case 244: /* cmd ::= DROP INDEX ifexists fullname */
167901
+ case 246: /* cmd ::= DROP INDEX ifexists fullname */
167457167902
{sqlite3DropIndex(pParse, yymsp[0].minor.yy131, yymsp[-1].minor.yy394);}
167458167903
break;
167459
- case 245: /* cmd ::= VACUUM vinto */
167904
+ case 247: /* cmd ::= VACUUM vinto */
167460167905
{sqlite3Vacuum(pParse,0,yymsp[0].minor.yy528);}
167461167906
break;
167462
- case 246: /* cmd ::= VACUUM nm vinto */
167907
+ case 248: /* cmd ::= VACUUM nm vinto */
167463167908
{sqlite3Vacuum(pParse,&yymsp[-1].minor.yy0,yymsp[0].minor.yy528);}
167464167909
break;
167465
- case 249: /* cmd ::= PRAGMA nm dbnm */
167910
+ case 251: /* cmd ::= PRAGMA nm dbnm */
167466167911
{sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
167467167912
break;
167468
- case 250: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
167913
+ case 252: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
167469167914
{sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
167470167915
break;
167471
- case 251: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
167916
+ case 253: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
167472167917
{sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
167473167918
break;
167474
- case 252: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
167919
+ case 254: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
167475167920
{sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
167476167921
break;
167477
- case 253: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
167922
+ case 255: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
167478167923
{sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
167479167924
break;
167480
- case 256: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
167925
+ case 258: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
167481167926
{
167482167927
Token all;
167483167928
all.z = yymsp[-3].minor.yy0.z;
167484167929
all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
167485167930
sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy33, &all);
167486167931
}
167487167932
break;
167488
- case 257: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
167933
+ case 259: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
167489167934
{
167490167935
sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy394, yymsp[-4].minor.yy180.a, yymsp[-4].minor.yy180.b, yymsp[-2].minor.yy131, yymsp[0].minor.yy528, yymsp[-10].minor.yy394, yymsp[-8].minor.yy394);
167491167936
yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/
167492167937
}
167493167938
break;
167494
- case 258: /* trigger_time ::= BEFORE|AFTER */
167939
+ case 260: /* trigger_time ::= BEFORE|AFTER */
167495167940
{ yymsp[0].minor.yy394 = yymsp[0].major; /*A-overwrites-X*/ }
167496167941
break;
167497
- case 259: /* trigger_time ::= INSTEAD OF */
167942
+ case 261: /* trigger_time ::= INSTEAD OF */
167498167943
{ yymsp[-1].minor.yy394 = TK_INSTEAD;}
167499167944
break;
167500
- case 260: /* trigger_time ::= */
167945
+ case 262: /* trigger_time ::= */
167501167946
{ yymsp[1].minor.yy394 = TK_BEFORE; }
167502167947
break;
167503
- case 261: /* trigger_event ::= DELETE|INSERT */
167504
- case 262: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==262);
167948
+ case 263: /* trigger_event ::= DELETE|INSERT */
167949
+ case 264: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==264);
167505167950
{yymsp[0].minor.yy180.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy180.b = 0;}
167506167951
break;
167507
- case 263: /* trigger_event ::= UPDATE OF idlist */
167952
+ case 265: /* trigger_event ::= UPDATE OF idlist */
167508167953
{yymsp[-2].minor.yy180.a = TK_UPDATE; yymsp[-2].minor.yy180.b = yymsp[0].minor.yy254;}
167509167954
break;
167510
- case 264: /* when_clause ::= */
167511
- case 283: /* key_opt ::= */ yytestcase(yyruleno==283);
167955
+ case 266: /* when_clause ::= */
167956
+ case 285: /* key_opt ::= */ yytestcase(yyruleno==285);
167512167957
{ yymsp[1].minor.yy528 = 0; }
167513167958
break;
167514
- case 265: /* when_clause ::= WHEN expr */
167515
- case 284: /* key_opt ::= KEY expr */ yytestcase(yyruleno==284);
167959
+ case 267: /* when_clause ::= WHEN expr */
167960
+ case 286: /* key_opt ::= KEY expr */ yytestcase(yyruleno==286);
167516167961
{ yymsp[-1].minor.yy528 = yymsp[0].minor.yy528; }
167517167962
break;
167518
- case 266: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
167963
+ case 268: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
167519167964
{
167520167965
assert( yymsp[-2].minor.yy33!=0 );
167521167966
yymsp[-2].minor.yy33->pLast->pNext = yymsp[-1].minor.yy33;
167522167967
yymsp[-2].minor.yy33->pLast = yymsp[-1].minor.yy33;
167523167968
}
167524167969
break;
167525
- case 267: /* trigger_cmd_list ::= trigger_cmd SEMI */
167970
+ case 269: /* trigger_cmd_list ::= trigger_cmd SEMI */
167526167971
{
167527167972
assert( yymsp[-1].minor.yy33!=0 );
167528167973
yymsp[-1].minor.yy33->pLast = yymsp[-1].minor.yy33;
167529167974
}
167530167975
break;
167531
- case 268: /* trnm ::= nm DOT nm */
167976
+ case 270: /* trnm ::= nm DOT nm */
167532167977
{
167533167978
yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;
167534167979
sqlite3ErrorMsg(pParse,
167535167980
"qualified table names are not allowed on INSERT, UPDATE, and DELETE "
167536167981
"statements within triggers");
167537167982
}
167538167983
break;
167539
- case 269: /* tridxby ::= INDEXED BY nm */
167984
+ case 271: /* tridxby ::= INDEXED BY nm */
167540167985
{
167541167986
sqlite3ErrorMsg(pParse,
167542167987
"the INDEXED BY clause is not allowed on UPDATE or DELETE statements "
167543167988
"within triggers");
167544167989
}
167545167990
break;
167546
- case 270: /* tridxby ::= NOT INDEXED */
167991
+ case 272: /* tridxby ::= NOT INDEXED */
167547167992
{
167548167993
sqlite3ErrorMsg(pParse,
167549167994
"the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
167550167995
"within triggers");
167551167996
}
167552167997
break;
167553
- case 271: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
167998
+ case 273: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
167554167999
{yylhsminor.yy33 = sqlite3TriggerUpdateStep(pParse, &yymsp[-6].minor.yy0, yymsp[-2].minor.yy131, yymsp[-3].minor.yy322, yymsp[-1].minor.yy528, yymsp[-7].minor.yy394, yymsp[-8].minor.yy0.z, yymsp[0].minor.yy522);}
167555168000
yymsp[-8].minor.yy33 = yylhsminor.yy33;
167556168001
break;
167557
- case 272: /* trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
168002
+ case 274: /* trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
167558168003
{
167559168004
yylhsminor.yy33 = sqlite3TriggerInsertStep(pParse,&yymsp[-4].minor.yy0,yymsp[-3].minor.yy254,yymsp[-2].minor.yy47,yymsp[-6].minor.yy394,yymsp[-1].minor.yy444,yymsp[-7].minor.yy522,yymsp[0].minor.yy522);/*yylhsminor.yy33-overwrites-yymsp[-6].minor.yy394*/
167560168005
}
167561168006
yymsp[-7].minor.yy33 = yylhsminor.yy33;
167562168007
break;
167563
- case 273: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
168008
+ case 275: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
167564168009
{yylhsminor.yy33 = sqlite3TriggerDeleteStep(pParse, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy528, yymsp[-5].minor.yy0.z, yymsp[0].minor.yy522);}
167565168010
yymsp[-5].minor.yy33 = yylhsminor.yy33;
167566168011
break;
167567
- case 274: /* trigger_cmd ::= scanpt select scanpt */
168012
+ case 276: /* trigger_cmd ::= scanpt select scanpt */
167568168013
{yylhsminor.yy33 = sqlite3TriggerSelectStep(pParse->db, yymsp[-1].minor.yy47, yymsp[-2].minor.yy522, yymsp[0].minor.yy522); /*yylhsminor.yy33-overwrites-yymsp[-1].minor.yy47*/}
167569168014
yymsp[-2].minor.yy33 = yylhsminor.yy33;
167570168015
break;
167571
- case 275: /* expr ::= RAISE LP IGNORE RP */
168016
+ case 277: /* expr ::= RAISE LP IGNORE RP */
167572168017
{
167573168018
yymsp[-3].minor.yy528 = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
167574168019
if( yymsp[-3].minor.yy528 ){
167575168020
yymsp[-3].minor.yy528->affExpr = OE_Ignore;
167576168021
}
167577168022
}
167578168023
break;
167579
- case 276: /* expr ::= RAISE LP raisetype COMMA nm RP */
168024
+ case 278: /* expr ::= RAISE LP raisetype COMMA nm RP */
167580168025
{
167581168026
yymsp[-5].minor.yy528 = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1);
167582168027
if( yymsp[-5].minor.yy528 ) {
167583168028
yymsp[-5].minor.yy528->affExpr = (char)yymsp[-3].minor.yy394;
167584168029
}
167585168030
}
167586168031
break;
167587
- case 277: /* raisetype ::= ROLLBACK */
168032
+ case 279: /* raisetype ::= ROLLBACK */
167588168033
{yymsp[0].minor.yy394 = OE_Rollback;}
167589168034
break;
167590
- case 279: /* raisetype ::= FAIL */
168035
+ case 281: /* raisetype ::= FAIL */
167591168036
{yymsp[0].minor.yy394 = OE_Fail;}
167592168037
break;
167593
- case 280: /* cmd ::= DROP TRIGGER ifexists fullname */
168038
+ case 282: /* cmd ::= DROP TRIGGER ifexists fullname */
167594168039
{
167595168040
sqlite3DropTrigger(pParse,yymsp[0].minor.yy131,yymsp[-1].minor.yy394);
167596168041
}
167597168042
break;
167598
- case 281: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
168043
+ case 283: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
167599168044
{
167600168045
sqlite3Attach(pParse, yymsp[-3].minor.yy528, yymsp[-1].minor.yy528, yymsp[0].minor.yy528);
167601168046
}
167602168047
break;
167603
- case 282: /* cmd ::= DETACH database_kw_opt expr */
168048
+ case 284: /* cmd ::= DETACH database_kw_opt expr */
167604168049
{
167605168050
sqlite3Detach(pParse, yymsp[0].minor.yy528);
167606168051
}
167607168052
break;
167608
- case 285: /* cmd ::= REINDEX */
168053
+ case 287: /* cmd ::= REINDEX */
167609168054
{sqlite3Reindex(pParse, 0, 0);}
167610168055
break;
167611
- case 286: /* cmd ::= REINDEX nm dbnm */
168056
+ case 288: /* cmd ::= REINDEX nm dbnm */
167612168057
{sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
167613168058
break;
167614
- case 287: /* cmd ::= ANALYZE */
168059
+ case 289: /* cmd ::= ANALYZE */
167615168060
{sqlite3Analyze(pParse, 0, 0);}
167616168061
break;
167617
- case 288: /* cmd ::= ANALYZE nm dbnm */
168062
+ case 290: /* cmd ::= ANALYZE nm dbnm */
167618168063
{sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
167619168064
break;
167620
- case 289: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
168065
+ case 291: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
167621168066
{
167622168067
sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy131,&yymsp[0].minor.yy0);
167623168068
}
167624168069
break;
167625
- case 290: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
168070
+ case 292: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
167626168071
{
167627168072
yymsp[-1].minor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-1].minor.yy0.z) + pParse->sLastToken.n;
167628168073
sqlite3AlterFinishAddColumn(pParse, &yymsp[-1].minor.yy0);
167629168074
}
167630168075
break;
167631
- case 291: /* cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
168076
+ case 293: /* cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
167632168077
{
167633168078
sqlite3AlterDropColumn(pParse, yymsp[-3].minor.yy131, &yymsp[0].minor.yy0);
167634168079
}
167635168080
break;
167636
- case 292: /* add_column_fullname ::= fullname */
168081
+ case 294: /* add_column_fullname ::= fullname */
167637168082
{
167638168083
disableLookaside(pParse);
167639168084
sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy131);
167640168085
}
167641168086
break;
167642
- case 293: /* cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
168087
+ case 295: /* cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
167643168088
{
167644168089
sqlite3AlterRenameColumn(pParse, yymsp[-5].minor.yy131, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);
167645168090
}
167646168091
break;
167647
- case 294: /* cmd ::= create_vtab */
168092
+ case 296: /* cmd ::= create_vtab */
167648168093
{sqlite3VtabFinishParse(pParse,0);}
167649168094
break;
167650
- case 295: /* cmd ::= create_vtab LP vtabarglist RP */
168095
+ case 297: /* cmd ::= create_vtab LP vtabarglist RP */
167651168096
{sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
167652168097
break;
167653
- case 296: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
168098
+ case 298: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
167654168099
{
167655168100
sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy394);
167656168101
}
167657168102
break;
167658
- case 297: /* vtabarg ::= */
168103
+ case 299: /* vtabarg ::= */
167659168104
{sqlite3VtabArgInit(pParse);}
167660168105
break;
167661
- case 298: /* vtabargtoken ::= ANY */
167662
- case 299: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==299);
167663
- case 300: /* lp ::= LP */ yytestcase(yyruleno==300);
168106
+ case 300: /* vtabargtoken ::= ANY */
168107
+ case 301: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==301);
168108
+ case 302: /* lp ::= LP */ yytestcase(yyruleno==302);
167664168109
{sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
167665168110
break;
167666
- case 301: /* with ::= WITH wqlist */
167667
- case 302: /* with ::= WITH RECURSIVE wqlist */ yytestcase(yyruleno==302);
168111
+ case 303: /* with ::= WITH wqlist */
168112
+ case 304: /* with ::= WITH RECURSIVE wqlist */ yytestcase(yyruleno==304);
167668168113
{ sqlite3WithPush(pParse, yymsp[0].minor.yy521, 1); }
167669168114
break;
167670
- case 303: /* wqas ::= AS */
168115
+ case 305: /* wqas ::= AS */
167671168116
{yymsp[0].minor.yy516 = M10d_Any;}
167672168117
break;
167673
- case 304: /* wqas ::= AS MATERIALIZED */
168118
+ case 306: /* wqas ::= AS MATERIALIZED */
167674168119
{yymsp[-1].minor.yy516 = M10d_Yes;}
167675168120
break;
167676
- case 305: /* wqas ::= AS NOT MATERIALIZED */
168121
+ case 307: /* wqas ::= AS NOT MATERIALIZED */
167677168122
{yymsp[-2].minor.yy516 = M10d_No;}
167678168123
break;
167679
- case 306: /* wqitem ::= nm eidlist_opt wqas LP select RP */
168124
+ case 308: /* wqitem ::= nm eidlist_opt wqas LP select RP */
167680168125
{
167681168126
yymsp[-5].minor.yy385 = sqlite3CteNew(pParse, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy322, yymsp[-1].minor.yy47, yymsp[-3].minor.yy516); /*A-overwrites-X*/
167682168127
}
167683168128
break;
167684
- case 307: /* wqlist ::= wqitem */
168129
+ case 309: /* wqlist ::= wqitem */
167685168130
{
167686168131
yymsp[0].minor.yy521 = sqlite3WithAdd(pParse, 0, yymsp[0].minor.yy385); /*A-overwrites-X*/
167687168132
}
167688168133
break;
167689
- case 308: /* wqlist ::= wqlist COMMA wqitem */
168134
+ case 310: /* wqlist ::= wqlist COMMA wqitem */
167690168135
{
167691168136
yymsp[-2].minor.yy521 = sqlite3WithAdd(pParse, yymsp[-2].minor.yy521, yymsp[0].minor.yy385);
167692168137
}
167693168138
break;
167694
- case 309: /* windowdefn_list ::= windowdefn */
168139
+ case 311: /* windowdefn_list ::= windowdefn */
167695168140
{ yylhsminor.yy41 = yymsp[0].minor.yy41; }
167696168141
yymsp[0].minor.yy41 = yylhsminor.yy41;
167697168142
break;
167698
- case 310: /* windowdefn_list ::= windowdefn_list COMMA windowdefn */
168143
+ case 312: /* windowdefn_list ::= windowdefn_list COMMA windowdefn */
167699168144
{
167700168145
assert( yymsp[0].minor.yy41!=0 );
167701168146
sqlite3WindowChain(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy41);
167702168147
yymsp[0].minor.yy41->pNextWin = yymsp[-2].minor.yy41;
167703168148
yylhsminor.yy41 = yymsp[0].minor.yy41;
167704168149
}
167705168150
yymsp[-2].minor.yy41 = yylhsminor.yy41;
167706168151
break;
167707
- case 311: /* windowdefn ::= nm AS LP window RP */
168152
+ case 313: /* windowdefn ::= nm AS LP window RP */
167708168153
{
167709168154
if( ALWAYS(yymsp[-1].minor.yy41) ){
167710168155
yymsp[-1].minor.yy41->zName = sqlite3DbStrNDup(pParse->db, yymsp[-4].minor.yy0.z, yymsp[-4].minor.yy0.n);
167711168156
}
167712168157
yylhsminor.yy41 = yymsp[-1].minor.yy41;
167713168158
}
167714168159
yymsp[-4].minor.yy41 = yylhsminor.yy41;
167715168160
break;
167716
- case 312: /* window ::= PARTITION BY nexprlist orderby_opt frame_opt */
168161
+ case 314: /* window ::= PARTITION BY nexprlist orderby_opt frame_opt */
167717168162
{
167718168163
yymsp[-4].minor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy322, yymsp[-1].minor.yy322, 0);
167719168164
}
167720168165
break;
167721
- case 313: /* window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
168166
+ case 315: /* window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
167722168167
{
167723168168
yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy322, yymsp[-1].minor.yy322, &yymsp[-5].minor.yy0);
167724168169
}
167725168170
yymsp[-5].minor.yy41 = yylhsminor.yy41;
167726168171
break;
167727
- case 314: /* window ::= ORDER BY sortlist frame_opt */
168172
+ case 316: /* window ::= ORDER BY sortlist frame_opt */
167728168173
{
167729168174
yymsp[-3].minor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, yymsp[-1].minor.yy322, 0);
167730168175
}
167731168176
break;
167732
- case 315: /* window ::= nm ORDER BY sortlist frame_opt */
168177
+ case 317: /* window ::= nm ORDER BY sortlist frame_opt */
167733168178
{
167734168179
yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, yymsp[-1].minor.yy322, &yymsp[-4].minor.yy0);
167735168180
}
167736168181
yymsp[-4].minor.yy41 = yylhsminor.yy41;
167737168182
break;
167738
- case 316: /* window ::= frame_opt */
167739
- case 335: /* filter_over ::= over_clause */ yytestcase(yyruleno==335);
168183
+ case 318: /* window ::= frame_opt */
168184
+ case 337: /* filter_over ::= over_clause */ yytestcase(yyruleno==337);
167740168185
{
167741168186
yylhsminor.yy41 = yymsp[0].minor.yy41;
167742168187
}
167743168188
yymsp[0].minor.yy41 = yylhsminor.yy41;
167744168189
break;
167745
- case 317: /* window ::= nm frame_opt */
168190
+ case 319: /* window ::= nm frame_opt */
167746168191
{
167747168192
yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, 0, &yymsp[-1].minor.yy0);
167748168193
}
167749168194
yymsp[-1].minor.yy41 = yylhsminor.yy41;
167750168195
break;
167751
- case 318: /* frame_opt ::= */
168196
+ case 320: /* frame_opt ::= */
167752168197
{
167753168198
yymsp[1].minor.yy41 = sqlite3WindowAlloc(pParse, 0, TK_UNBOUNDED, 0, TK_CURRENT, 0, 0);
167754168199
}
167755168200
break;
167756
- case 319: /* frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
168201
+ case 321: /* frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
167757168202
{
167758168203
yylhsminor.yy41 = sqlite3WindowAlloc(pParse, yymsp[-2].minor.yy394, yymsp[-1].minor.yy595.eType, yymsp[-1].minor.yy595.pExpr, TK_CURRENT, 0, yymsp[0].minor.yy516);
167759168204
}
167760168205
yymsp[-2].minor.yy41 = yylhsminor.yy41;
167761168206
break;
167762
- case 320: /* frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
168207
+ case 322: /* frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
167763168208
{
167764168209
yylhsminor.yy41 = sqlite3WindowAlloc(pParse, yymsp[-5].minor.yy394, yymsp[-3].minor.yy595.eType, yymsp[-3].minor.yy595.pExpr, yymsp[-1].minor.yy595.eType, yymsp[-1].minor.yy595.pExpr, yymsp[0].minor.yy516);
167765168210
}
167766168211
yymsp[-5].minor.yy41 = yylhsminor.yy41;
167767168212
break;
167768
- case 322: /* frame_bound_s ::= frame_bound */
167769
- case 324: /* frame_bound_e ::= frame_bound */ yytestcase(yyruleno==324);
168213
+ case 324: /* frame_bound_s ::= frame_bound */
168214
+ case 326: /* frame_bound_e ::= frame_bound */ yytestcase(yyruleno==326);
167770168215
{yylhsminor.yy595 = yymsp[0].minor.yy595;}
167771168216
yymsp[0].minor.yy595 = yylhsminor.yy595;
167772168217
break;
167773
- case 323: /* frame_bound_s ::= UNBOUNDED PRECEDING */
167774
- case 325: /* frame_bound_e ::= UNBOUNDED FOLLOWING */ yytestcase(yyruleno==325);
167775
- case 327: /* frame_bound ::= CURRENT ROW */ yytestcase(yyruleno==327);
168218
+ case 325: /* frame_bound_s ::= UNBOUNDED PRECEDING */
168219
+ case 327: /* frame_bound_e ::= UNBOUNDED FOLLOWING */ yytestcase(yyruleno==327);
168220
+ case 329: /* frame_bound ::= CURRENT ROW */ yytestcase(yyruleno==329);
167776168221
{yylhsminor.yy595.eType = yymsp[-1].major; yylhsminor.yy595.pExpr = 0;}
167777168222
yymsp[-1].minor.yy595 = yylhsminor.yy595;
167778168223
break;
167779
- case 326: /* frame_bound ::= expr PRECEDING|FOLLOWING */
168224
+ case 328: /* frame_bound ::= expr PRECEDING|FOLLOWING */
167780168225
{yylhsminor.yy595.eType = yymsp[0].major; yylhsminor.yy595.pExpr = yymsp[-1].minor.yy528;}
167781168226
yymsp[-1].minor.yy595 = yylhsminor.yy595;
167782168227
break;
167783
- case 328: /* frame_exclude_opt ::= */
168228
+ case 330: /* frame_exclude_opt ::= */
167784168229
{yymsp[1].minor.yy516 = 0;}
167785168230
break;
167786
- case 329: /* frame_exclude_opt ::= EXCLUDE frame_exclude */
168231
+ case 331: /* frame_exclude_opt ::= EXCLUDE frame_exclude */
167787168232
{yymsp[-1].minor.yy516 = yymsp[0].minor.yy516;}
167788168233
break;
167789
- case 330: /* frame_exclude ::= NO OTHERS */
167790
- case 331: /* frame_exclude ::= CURRENT ROW */ yytestcase(yyruleno==331);
168234
+ case 332: /* frame_exclude ::= NO OTHERS */
168235
+ case 333: /* frame_exclude ::= CURRENT ROW */ yytestcase(yyruleno==333);
167791168236
{yymsp[-1].minor.yy516 = yymsp[-1].major; /*A-overwrites-X*/}
167792168237
break;
167793
- case 332: /* frame_exclude ::= GROUP|TIES */
168238
+ case 334: /* frame_exclude ::= GROUP|TIES */
167794168239
{yymsp[0].minor.yy516 = yymsp[0].major; /*A-overwrites-X*/}
167795168240
break;
167796
- case 333: /* window_clause ::= WINDOW windowdefn_list */
168241
+ case 335: /* window_clause ::= WINDOW windowdefn_list */
167797168242
{ yymsp[-1].minor.yy41 = yymsp[0].minor.yy41; }
167798168243
break;
167799
- case 334: /* filter_over ::= filter_clause over_clause */
168244
+ case 336: /* filter_over ::= filter_clause over_clause */
167800168245
{
167801168246
if( yymsp[0].minor.yy41 ){
167802168247
yymsp[0].minor.yy41->pFilter = yymsp[-1].minor.yy528;
167803168248
}else{
167804168249
sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy528);
@@ -167805,11 +168250,11 @@
167805168250
}
167806168251
yylhsminor.yy41 = yymsp[0].minor.yy41;
167807168252
}
167808168253
yymsp[-1].minor.yy41 = yylhsminor.yy41;
167809168254
break;
167810
- case 336: /* filter_over ::= filter_clause */
168255
+ case 338: /* filter_over ::= filter_clause */
167811168256
{
167812168257
yylhsminor.yy41 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
167813168258
if( yylhsminor.yy41 ){
167814168259
yylhsminor.yy41->eFrmType = TK_FILTER;
167815168260
yylhsminor.yy41->pFilter = yymsp[0].minor.yy528;
@@ -167817,91 +168262,91 @@
167817168262
sqlite3ExprDelete(pParse->db, yymsp[0].minor.yy528);
167818168263
}
167819168264
}
167820168265
yymsp[0].minor.yy41 = yylhsminor.yy41;
167821168266
break;
167822
- case 337: /* over_clause ::= OVER LP window RP */
168267
+ case 339: /* over_clause ::= OVER LP window RP */
167823168268
{
167824168269
yymsp[-3].minor.yy41 = yymsp[-1].minor.yy41;
167825168270
assert( yymsp[-3].minor.yy41!=0 );
167826168271
}
167827168272
break;
167828
- case 338: /* over_clause ::= OVER nm */
168273
+ case 340: /* over_clause ::= OVER nm */
167829168274
{
167830168275
yymsp[-1].minor.yy41 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
167831168276
if( yymsp[-1].minor.yy41 ){
167832168277
yymsp[-1].minor.yy41->zName = sqlite3DbStrNDup(pParse->db, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n);
167833168278
}
167834168279
}
167835168280
break;
167836
- case 339: /* filter_clause ::= FILTER LP WHERE expr RP */
168281
+ case 341: /* filter_clause ::= FILTER LP WHERE expr RP */
167837168282
{ yymsp[-4].minor.yy528 = yymsp[-1].minor.yy528; }
167838168283
break;
167839168284
default:
167840
- /* (340) input ::= cmdlist */ yytestcase(yyruleno==340);
167841
- /* (341) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==341);
167842
- /* (342) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=342);
167843
- /* (343) ecmd ::= SEMI */ yytestcase(yyruleno==343);
167844
- /* (344) ecmd ::= cmdx SEMI */ yytestcase(yyruleno==344);
167845
- /* (345) ecmd ::= explain cmdx SEMI (NEVER REDUCES) */ assert(yyruleno!=345);
167846
- /* (346) trans_opt ::= */ yytestcase(yyruleno==346);
167847
- /* (347) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==347);
167848
- /* (348) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==348);
167849
- /* (349) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==349);
167850
- /* (350) savepoint_opt ::= */ yytestcase(yyruleno==350);
167851
- /* (351) cmd ::= create_table create_table_args */ yytestcase(yyruleno==351);
167852
- /* (352) table_option_set ::= table_option (OPTIMIZED OUT) */ assert(yyruleno!=352);
167853
- /* (353) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==353);
167854
- /* (354) columnlist ::= columnname carglist */ yytestcase(yyruleno==354);
167855
- /* (355) nm ::= ID|INDEXED */ yytestcase(yyruleno==355);
167856
- /* (356) nm ::= STRING */ yytestcase(yyruleno==356);
167857
- /* (357) nm ::= JOIN_KW */ yytestcase(yyruleno==357);
167858
- /* (358) typetoken ::= typename */ yytestcase(yyruleno==358);
167859
- /* (359) typename ::= ID|STRING */ yytestcase(yyruleno==359);
167860
- /* (360) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=360);
167861
- /* (361) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=361);
167862
- /* (362) carglist ::= carglist ccons */ yytestcase(yyruleno==362);
167863
- /* (363) carglist ::= */ yytestcase(yyruleno==363);
167864
- /* (364) ccons ::= NULL onconf */ yytestcase(yyruleno==364);
167865
- /* (365) ccons ::= GENERATED ALWAYS AS generated */ yytestcase(yyruleno==365);
167866
- /* (366) ccons ::= AS generated */ yytestcase(yyruleno==366);
167867
- /* (367) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==367);
167868
- /* (368) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==368);
167869
- /* (369) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=369);
167870
- /* (370) tconscomma ::= */ yytestcase(yyruleno==370);
167871
- /* (371) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=371);
167872
- /* (372) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=372);
167873
- /* (373) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=373);
167874
- /* (374) oneselect ::= values */ yytestcase(yyruleno==374);
167875
- /* (375) sclp ::= selcollist COMMA */ yytestcase(yyruleno==375);
167876
- /* (376) as ::= ID|STRING */ yytestcase(yyruleno==376);
167877
- /* (377) indexed_opt ::= indexed_by (OPTIMIZED OUT) */ assert(yyruleno!=377);
167878
- /* (378) returning ::= */ yytestcase(yyruleno==378);
167879
- /* (379) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=379);
167880
- /* (380) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==380);
167881
- /* (381) exprlist ::= nexprlist */ yytestcase(yyruleno==381);
167882
- /* (382) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=382);
167883
- /* (383) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=383);
167884
- /* (384) nmnum ::= ON */ yytestcase(yyruleno==384);
167885
- /* (385) nmnum ::= DELETE */ yytestcase(yyruleno==385);
167886
- /* (386) nmnum ::= DEFAULT */ yytestcase(yyruleno==386);
167887
- /* (387) plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==387);
167888
- /* (388) foreach_clause ::= */ yytestcase(yyruleno==388);
167889
- /* (389) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==389);
167890
- /* (390) trnm ::= nm */ yytestcase(yyruleno==390);
167891
- /* (391) tridxby ::= */ yytestcase(yyruleno==391);
167892
- /* (392) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==392);
167893
- /* (393) database_kw_opt ::= */ yytestcase(yyruleno==393);
167894
- /* (394) kwcolumn_opt ::= */ yytestcase(yyruleno==394);
167895
- /* (395) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==395);
167896
- /* (396) vtabarglist ::= vtabarg */ yytestcase(yyruleno==396);
167897
- /* (397) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==397);
167898
- /* (398) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==398);
167899
- /* (399) anylist ::= */ yytestcase(yyruleno==399);
167900
- /* (400) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==400);
167901
- /* (401) anylist ::= anylist ANY */ yytestcase(yyruleno==401);
167902
- /* (402) with ::= */ yytestcase(yyruleno==402);
168285
+ /* (342) input ::= cmdlist */ yytestcase(yyruleno==342);
168286
+ /* (343) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==343);
168287
+ /* (344) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=344);
168288
+ /* (345) ecmd ::= SEMI */ yytestcase(yyruleno==345);
168289
+ /* (346) ecmd ::= cmdx SEMI */ yytestcase(yyruleno==346);
168290
+ /* (347) ecmd ::= explain cmdx SEMI (NEVER REDUCES) */ assert(yyruleno!=347);
168291
+ /* (348) trans_opt ::= */ yytestcase(yyruleno==348);
168292
+ /* (349) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==349);
168293
+ /* (350) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==350);
168294
+ /* (351) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==351);
168295
+ /* (352) savepoint_opt ::= */ yytestcase(yyruleno==352);
168296
+ /* (353) cmd ::= create_table create_table_args */ yytestcase(yyruleno==353);
168297
+ /* (354) table_option_set ::= table_option (OPTIMIZED OUT) */ assert(yyruleno!=354);
168298
+ /* (355) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==355);
168299
+ /* (356) columnlist ::= columnname carglist */ yytestcase(yyruleno==356);
168300
+ /* (357) nm ::= ID|INDEXED */ yytestcase(yyruleno==357);
168301
+ /* (358) nm ::= STRING */ yytestcase(yyruleno==358);
168302
+ /* (359) nm ::= JOIN_KW */ yytestcase(yyruleno==359);
168303
+ /* (360) typetoken ::= typename */ yytestcase(yyruleno==360);
168304
+ /* (361) typename ::= ID|STRING */ yytestcase(yyruleno==361);
168305
+ /* (362) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=362);
168306
+ /* (363) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=363);
168307
+ /* (364) carglist ::= carglist ccons */ yytestcase(yyruleno==364);
168308
+ /* (365) carglist ::= */ yytestcase(yyruleno==365);
168309
+ /* (366) ccons ::= NULL onconf */ yytestcase(yyruleno==366);
168310
+ /* (367) ccons ::= GENERATED ALWAYS AS generated */ yytestcase(yyruleno==367);
168311
+ /* (368) ccons ::= AS generated */ yytestcase(yyruleno==368);
168312
+ /* (369) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==369);
168313
+ /* (370) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==370);
168314
+ /* (371) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=371);
168315
+ /* (372) tconscomma ::= */ yytestcase(yyruleno==372);
168316
+ /* (373) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=373);
168317
+ /* (374) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=374);
168318
+ /* (375) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=375);
168319
+ /* (376) oneselect ::= values */ yytestcase(yyruleno==376);
168320
+ /* (377) sclp ::= selcollist COMMA */ yytestcase(yyruleno==377);
168321
+ /* (378) as ::= ID|STRING */ yytestcase(yyruleno==378);
168322
+ /* (379) indexed_opt ::= indexed_by (OPTIMIZED OUT) */ assert(yyruleno!=379);
168323
+ /* (380) returning ::= */ yytestcase(yyruleno==380);
168324
+ /* (381) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=381);
168325
+ /* (382) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==382);
168326
+ /* (383) exprlist ::= nexprlist */ yytestcase(yyruleno==383);
168327
+ /* (384) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=384);
168328
+ /* (385) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=385);
168329
+ /* (386) nmnum ::= ON */ yytestcase(yyruleno==386);
168330
+ /* (387) nmnum ::= DELETE */ yytestcase(yyruleno==387);
168331
+ /* (388) nmnum ::= DEFAULT */ yytestcase(yyruleno==388);
168332
+ /* (389) plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==389);
168333
+ /* (390) foreach_clause ::= */ yytestcase(yyruleno==390);
168334
+ /* (391) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==391);
168335
+ /* (392) trnm ::= nm */ yytestcase(yyruleno==392);
168336
+ /* (393) tridxby ::= */ yytestcase(yyruleno==393);
168337
+ /* (394) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==394);
168338
+ /* (395) database_kw_opt ::= */ yytestcase(yyruleno==395);
168339
+ /* (396) kwcolumn_opt ::= */ yytestcase(yyruleno==396);
168340
+ /* (397) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==397);
168341
+ /* (398) vtabarglist ::= vtabarg */ yytestcase(yyruleno==398);
168342
+ /* (399) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==399);
168343
+ /* (400) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==400);
168344
+ /* (401) anylist ::= */ yytestcase(yyruleno==401);
168345
+ /* (402) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==402);
168346
+ /* (403) anylist ::= anylist ANY */ yytestcase(yyruleno==403);
168347
+ /* (404) with ::= */ yytestcase(yyruleno==404);
167903168348
break;
167904168349
/********** End reduce actions ************************************************/
167905168350
};
167906168351
assert( yyruleno<sizeof(yyRuleInfoLhs)/sizeof(yyRuleInfoLhs[0]) );
167907168352
yygoto = yyRuleInfoLhs[yyruleno];
@@ -174597,10 +175042,28 @@
174597175042
*/
174598175043
SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){
174599175044
int iDb = zDbName ? sqlite3FindDbName(db, zDbName) : 0;
174600175045
return iDb<0 ? 0 : db->aDb[iDb].pBt;
174601175046
}
175047
+
175048
+/*
175049
+** Return the name of the N-th database schema. Return NULL if N is out
175050
+** of range.
175051
+*/
175052
+SQLITE_API const char *sqlite3_db_name(sqlite3 *db, int N){
175053
+#ifdef SQLITE_ENABLE_API_ARMOR
175054
+ if( !sqlite3SafetyCheckOk(db) ){
175055
+ (void)SQLITE_MISUSE_BKPT;
175056
+ return 0;
175057
+ }
175058
+#endif
175059
+ if( N<0 || N>=db->nDb ){
175060
+ return 0;
175061
+ }else{
175062
+ return db->aDb[N].zDbSName;
175063
+ }
175064
+}
174602175065
174603175066
/*
174604175067
** Return the filename of the database associated with a database
174605175068
** connection.
174606175069
*/
@@ -190236,10 +190699,12 @@
190236190699
if( rc==SQLITE_OK ){
190237190700
if( pNode->key.n ){
190238190701
pBlk->n += sqlite3Fts3PutVarint(&pBlk->a[pBlk->n], nPrefix);
190239190702
}
190240190703
pBlk->n += sqlite3Fts3PutVarint(&pBlk->a[pBlk->n], nSuffix);
190704
+ assert( nPrefix+nSuffix<=nTerm );
190705
+ assert( nPrefix>=0 );
190241190706
memcpy(&pBlk->a[pBlk->n], &zTerm[nPrefix], nSuffix);
190242190707
pBlk->n += nSuffix;
190243190708
190244190709
memcpy(pNode->key.a, zTerm, nTerm);
190245190710
pNode->key.n = nTerm;
@@ -190358,10 +190823,11 @@
190358190823
NodeWriter *pLeaf; /* Object used to write leaf nodes */
190359190824
190360190825
pLeaf = &pWriter->aNodeWriter[0];
190361190826
nPrefix = fts3PrefixCompress(pLeaf->key.a, pLeaf->key.n, zTerm, nTerm);
190362190827
nSuffix = nTerm - nPrefix;
190828
+ if(nSuffix<=0 ) return FTS_CORRUPT_VTAB;
190363190829
190364190830
nSpace = sqlite3Fts3VarintLen(nPrefix);
190365190831
nSpace += sqlite3Fts3VarintLen(nSuffix) + nSuffix;
190366190832
nSpace += sqlite3Fts3VarintLen(nDoclist) + nDoclist;
190367190833
@@ -226663,11 +227129,11 @@
226663227129
/* State used by the fts5DataXXX() functions. */
226664227130
sqlite3_blob *pReader; /* RO incr-blob open on %_data table */
226665227131
sqlite3_stmt *pWriter; /* "INSERT ... %_data VALUES(?,?)" */
226666227132
sqlite3_stmt *pDeleter; /* "DELETE FROM %_data ... id>=? AND id<=?" */
226667227133
sqlite3_stmt *pIdxWriter; /* "INSERT ... %_idx VALUES(?,?,?,?)" */
226668
- sqlite3_stmt *pIdxDeleter; /* "DELETE FROM %_idx WHERE segid=? */
227134
+ sqlite3_stmt *pIdxDeleter; /* "DELETE FROM %_idx WHERE segid=?" */
226669227135
sqlite3_stmt *pIdxSelect;
226670227136
int nRead; /* Total number of blocks read */
226671227137
226672227138
sqlite3_stmt *pDataVersion;
226673227139
i64 iStructVersion; /* data_version when pStruct read */
@@ -235980,11 +236446,11 @@
235980236446
int nArg, /* Number of args */
235981236447
sqlite3_value **apUnused /* Function arguments */
235982236448
){
235983236449
assert( nArg==0 );
235984236450
UNUSED_PARAM2(nArg, apUnused);
235985
- sqlite3_result_text(pCtx, "fts5: 2022-04-19 15:56:03 b966d52437f08a6759a83a45cafb0d706a8933a8e55dee38ae78166d1a5b3ba4", -1, SQLITE_TRANSIENT);
236451
+ sqlite3_result_text(pCtx, "fts5: 2022-06-03 14:08:40 d18818afc6021a32989499c26ab38fa442e5a55e662e39bb06e5c0daa9c65e25", -1, SQLITE_TRANSIENT);
235986236452
}
235987236453
235988236454
/*
235989236455
** Return true if zName is the extension on one of the shadow tables used
235990236456
** by this module.
235991236457
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.39.0"
456 #define SQLITE_VERSION_NUMBER 3039000
457 #define SQLITE_SOURCE_ID "2022-04-21 19:38:17 f766dff012af0ea3c28a8ce4db850cd0205729a8283bce1e442992aded7c734b"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -6580,10 +6580,32 @@
6580 ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
6581 ** create the statement in the first place.
6582 */
6583 SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
6584
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6585 /*
6586 ** CAPI3REF: Return The Filename For A Database Connection
6587 ** METHOD: sqlite3
6588 **
6589 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to the filename
@@ -15790,12 +15812,14 @@
15790 # define sqlite3VdbeVerifyNoMallocRequired(A,B)
15791 # define sqlite3VdbeVerifyNoResultRow(A)
15792 #endif
15793 #if defined(SQLITE_DEBUG)
15794 SQLITE_PRIVATE void sqlite3VdbeVerifyAbortable(Vdbe *p, int);
 
15795 #else
15796 # define sqlite3VdbeVerifyAbortable(A,B)
 
15797 #endif
15798 SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp,int iLineno);
15799 #ifndef SQLITE_OMIT_EXPLAIN
15800 SQLITE_PRIVATE void sqlite3VdbeExplain(Parse*,u8,const char*,...);
15801 SQLITE_PRIVATE void sqlite3VdbeExplainPop(Parse*);
@@ -16283,10 +16307,17 @@
16283 /* Maximum pathname length. Note: FILENAME_MAX defined by stdio.h
16284 */
16285 #ifndef SQLITE_MAX_PATHLEN
16286 # define SQLITE_MAX_PATHLEN FILENAME_MAX
16287 #endif
 
 
 
 
 
 
 
16288
16289 /*
16290 ** The default size of a disk sector
16291 */
16292 #ifndef SQLITE_DEFAULT_SECTOR_SIZE
@@ -17051,10 +17082,12 @@
17051 /* TH3 expects this value ^^^^^^^^^^ to be 0x40000. Coordinate any change */
17052 #define SQLITE_BloomFilter 0x00080000 /* Use a Bloom filter on searches */
17053 #define SQLITE_BloomPulldown 0x00100000 /* Run Bloom filters early */
17054 #define SQLITE_BalancedMerge 0x00200000 /* Balance multi-way merges */
17055 #define SQLITE_ReleaseReg 0x00400000 /* Use OP_ReleaseReg for testing */
 
 
17056 #define SQLITE_AllOpts 0xffffffff /* All optimizations */
17057
17058 /*
17059 ** Macros for testing whether or not optimizations are enabled or disabled.
17060 */
@@ -17153,11 +17186,11 @@
17153 #define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */
17154 #define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */
17155 #define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a
17156 ** single query - might change over time */
17157 #define SQLITE_FUNC_TEST 0x4000 /* Built-in testing functions */
17158 #define SQLITE_FUNC_OFFSET 0x8000 /* Built-in sqlite_offset() function */
17159 #define SQLITE_FUNC_WINDOW 0x00010000 /* Built-in window-only function */
17160 #define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */
17161 #define SQLITE_FUNC_DIRECT 0x00080000 /* Not for use in TRIGGERs or VIEWs */
17162 #define SQLITE_FUNC_SUBTYPE 0x00100000 /* Result likely to have sub-type */
17163 #define SQLITE_FUNC_UNSAFE 0x00200000 /* Function has side effects */
@@ -17170,10 +17203,11 @@
17170 #define INLINEFUNC_implies_nonnull_row 1
17171 #define INLINEFUNC_expr_implies_expr 2
17172 #define INLINEFUNC_expr_compare 3
17173 #define INLINEFUNC_affinity 4
17174 #define INLINEFUNC_iif 5
 
17175 #define INLINEFUNC_unlikely 99 /* Default case */
17176
17177 /*
17178 ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
17179 ** used to create the initializers for the FuncDef structures.
@@ -17396,10 +17430,11 @@
17396 #define COLFLAG_VIRTUAL 0x0020 /* GENERATED ALWAYS AS ... VIRTUAL */
17397 #define COLFLAG_STORED 0x0040 /* GENERATED ALWAYS AS ... STORED */
17398 #define COLFLAG_NOTAVAIL 0x0080 /* STORED column not yet calculated */
17399 #define COLFLAG_BUSY 0x0100 /* Blocks recursion on GENERATED columns */
17400 #define COLFLAG_HASCOLL 0x0200 /* Has collating sequence name in zCnName */
 
17401 #define COLFLAG_GENERATED 0x0060 /* Combo: _STORED, _VIRTUAL */
17402 #define COLFLAG_NOINSERT 0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */
17403
17404 /*
17405 ** A "Collating Sequence" is defined by an instance of the following
@@ -18115,11 +18150,11 @@
18115 ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
18116 ** TK_VARIABLE: variable number (always >= 1).
18117 ** TK_SELECT_COLUMN: column of the result vector */
18118 i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
18119 union {
18120 int iJoin; /* If EP_FromJoin, the right table of the join */
18121 int iOfst; /* else: start of token from start of statement */
18122 } w;
18123 AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
18124 union {
18125 Table *pTab; /* TK_COLUMN: Table containing column. Can be NULL
@@ -18136,33 +18171,33 @@
18136 ** Value restrictions:
18137 **
18138 ** EP_Agg == NC_HasAgg == SF_HasAgg
18139 ** EP_Win == NC_HasWin
18140 */
18141 #define EP_FromJoin 0x000001 /* Originates in ON/USING clause of outer join */
18142 #define EP_Distinct 0x000002 /* Aggregate function with DISTINCT keyword */
18143 #define EP_HasFunc 0x000004 /* Contains one or more functions of any kind */
18144 #define EP_FixedCol 0x000008 /* TK_Column with a known fixed value */
18145 #define EP_Agg 0x000010 /* Contains one or more aggregate functions */
18146 #define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */
18147 #define EP_DblQuoted 0x000040 /* token.z was originally in "..." */
18148 #define EP_InfixFunc 0x000080 /* True for an infix function: LIKE, GLOB, etc */
18149 #define EP_Collate 0x000100 /* Tree contains a TK_COLLATE operator */
18150 #define EP_Commuted 0x000200 /* Comparison operator has been commuted */
18151 #define EP_IntValue 0x000400 /* Integer value contained in u.iValue */
18152 #define EP_xIsSelect 0x000800 /* x.pSelect is valid (otherwise x.pList is) */
18153 #define EP_Skip 0x001000 /* Operator does not contribute to affinity */
18154 #define EP_Reduced 0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
18155 #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
18156 #define EP_Win 0x008000 /* Contains window functions */
18157 #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
18158 #define EP_IfNullRow 0x020000 /* The TK_IF_NULL_ROW opcode */
18159 #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
18160 #define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
18161 #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
18162 #define EP_Subquery 0x200000 /* Tree contains a TK_SELECT operator */
18163 #define EP_InnerJoin 0x400000 /* Originates in ON/USING of an inner join */
18164 #define EP_Leaf 0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */
18165 #define EP_WinFunc 0x1000000 /* TK_FUNCTION with Expr.y.pWin set */
18166 #define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */
18167 #define EP_Quoted 0x4000000 /* TK_ID was originally quoted */
18168 #define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */
@@ -18181,12 +18216,12 @@
18181 */
18182 #define ExprHasProperty(E,P) (((E)->flags&(P))!=0)
18183 #define ExprHasAllProperty(E,P) (((E)->flags&(P))==(P))
18184 #define ExprSetProperty(E,P) (E)->flags|=(P)
18185 #define ExprClearProperty(E,P) (E)->flags&=~(P)
18186 #define ExprAlwaysTrue(E) (((E)->flags&(EP_FromJoin|EP_IsTrue))==EP_IsTrue)
18187 #define ExprAlwaysFalse(E) (((E)->flags&(EP_FromJoin|EP_IsFalse))==EP_IsFalse)
18188
18189 /* Macros used to ensure that the correct members of unions are accessed
18190 ** in Expr.
18191 */
18192 #define ExprUseUToken(E) (((E)->flags&EP_IntValue)==0)
@@ -18269,17 +18304,22 @@
18269 int nExpr; /* Number of expressions on the list */
18270 int nAlloc; /* Number of a[] slots allocated */
18271 struct ExprList_item { /* For each expression in the list */
18272 Expr *pExpr; /* The parse tree for this expression */
18273 char *zEName; /* Token associated with this expression */
18274 u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */
18275 unsigned eEName :2; /* Meaning of zEName */
18276 unsigned done :1; /* A flag to indicate when processing is finished */
18277 unsigned reusable :1; /* Constant expression is reusable */
18278 unsigned bSorterRef :1; /* Defer evaluation until after sorting */
18279 unsigned bNulls: 1; /* True if explicit "NULLS FIRST/LAST" */
18280 unsigned bUsed: 1; /* This column used in a SF_NestedFrom subquery */
 
 
 
 
 
18281 union {
18282 struct { /* Used by any ExprList other than Parse.pConsExpr */
18283 u16 iOrderByCol; /* For ORDER BY, column number in result set */
18284 u16 iAlias; /* Index into Parse.aAlias[] for zName */
18285 } x;
@@ -18356,10 +18396,11 @@
18356 u8 jointype; /* Type of join between this table and the previous */
18357 unsigned notIndexed :1; /* True if there is a NOT INDEXED clause */
18358 unsigned isIndexedBy :1; /* True if there is an INDEXED BY clause */
18359 unsigned isTabFunc :1; /* True if table-valued-function syntax */
18360 unsigned isCorrelated :1; /* True if sub-query is correlated */
 
18361 unsigned viaCoroutine :1; /* Implemented as a co-routine */
18362 unsigned isRecursive :1; /* True for recursive reference in WITH */
18363 unsigned fromDDL :1; /* Comes from sqlite_schema */
18364 unsigned isCte :1; /* This is a CTE */
18365 unsigned notCte :1; /* This item may not match a CTE */
@@ -19729,10 +19770,11 @@
19729 SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView*, const Expr*, u8);
19730 SQLITE_PRIVATE void sqlite3TreeViewBareExprList(TreeView*, const ExprList*, const char*);
19731 SQLITE_PRIVATE void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*);
19732 SQLITE_PRIVATE void sqlite3TreeViewBareIdList(TreeView*, const IdList*, const char*);
19733 SQLITE_PRIVATE void sqlite3TreeViewIdList(TreeView*, const IdList*, u8, const char*);
 
19734 SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView*, const SrcList*);
19735 SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView*, const Select*, u8);
19736 SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView*, const With*, u8);
19737 SQLITE_PRIVATE void sqlite3TreeViewUpsert(TreeView*, const Upsert*, u8);
19738 SQLITE_PRIVATE void sqlite3TreeViewDelete(const With*, const SrcList*, const Expr*,
@@ -20022,10 +20064,11 @@
20022 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
20023 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
20024 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
20025 SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
20026 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
 
20027 #ifdef SQLITE_ENABLE_CURSOR_HINTS
20028 SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
20029 #endif
20030 SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*);
20031 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
@@ -30462,12 +30505,18 @@
30462 sqlite3_str_append(pAccum, ".", 1);
30463 }
30464 sqlite3_str_appendall(pAccum, pItem->zName);
30465 }else if( pItem->zAlias ){
30466 sqlite3_str_appendall(pAccum, pItem->zAlias);
30467 }else if( ALWAYS(pItem->pSelect) ){
30468 sqlite3_str_appendf(pAccum, "SUBQUERY %u", pItem->pSelect->selId);
 
 
 
 
 
 
30469 }
30470 length = width = 0;
30471 break;
30472 }
30473 default: {
@@ -30526,11 +30575,13 @@
30526 /*
30527 ** If pExpr has a byte offset for the start of a token, record that as
30528 ** as the error offset.
30529 */
30530 SQLITE_PRIVATE void sqlite3RecordErrorOffsetOfExpr(sqlite3 *db, const Expr *pExpr){
30531 while( pExpr && (ExprHasProperty(pExpr,EP_FromJoin) || pExpr->w.iOfst<=0) ){
 
 
30532 pExpr = pExpr->pLeft;
30533 }
30534 if( pExpr==0 ) return;
30535 db->errByteOffset = pExpr->w.iOfst;
30536 }
@@ -31047,10 +31098,57 @@
31047 */
31048 static void sqlite3TreeViewItem(TreeView *p, const char *zLabel,u8 moreFollows){
31049 sqlite3TreeViewPush(&p, moreFollows);
31050 sqlite3TreeViewLine(p, "%s", zLabel);
31051 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31052
31053 /*
31054 ** Generate a human-readable description of a WITH clause.
31055 */
31056 SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 moreToFollow){
@@ -31077,10 +31175,14 @@
31077 sqlite3_str_appendf(&x, "%c%s", cSep, pCte->pCols->a[j].zEName);
31078 cSep = ',';
31079 }
31080 sqlite3_str_appendf(&x, ")");
31081 }
 
 
 
 
31082 if( pCte->pUse ){
31083 sqlite3_str_appendf(&x, " (pUse=0x%p, nUse=%d)", pCte->pUse,
31084 pCte->pUse->nUse);
31085 }
31086 sqlite3StrAccumFinish(&x);
@@ -31099,10 +31201,11 @@
31099 int i;
31100 if( pSrc==0 ) return;
31101 for(i=0; i<pSrc->nSrc; i++){
31102 const SrcItem *pItem = &pSrc->a[i];
31103 StrAccum x;
 
31104 char zLine[100];
31105 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
31106 x.printfFlags |= SQLITE_PRINTF_INTERNAL;
31107 sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem);
31108 if( pItem->pTab ){
@@ -31127,13 +31230,24 @@
31127 if( pItem->fg.isCte ){
31128 sqlite3_str_appendf(&x, " CteUse=0x%p", pItem->u2.pCteUse);
31129 }
31130 sqlite3StrAccumFinish(&x);
31131 sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1);
 
 
 
 
 
 
 
31132 if( pItem->pSelect ){
 
 
 
 
31133 assert( pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
31134 sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
31135 }
31136 if( pItem->fg.isTabFunc ){
31137 sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:");
31138 }
31139 sqlite3TreeViewPop(&pView);
@@ -31296,10 +31410,11 @@
31296 /*
31297 ** Generate a human-readable explanation for a Window object
31298 */
31299 SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){
31300 int nElement = 0;
 
31301 if( pWin->pFilter ){
31302 sqlite3TreeViewItem(pView, "FILTER", 1);
31303 sqlite3TreeViewExpr(pView, pWin->pFilter, 0);
31304 sqlite3TreeViewPop(&pView);
31305 }
@@ -31360,10 +31475,11 @@
31360 #ifndef SQLITE_OMIT_WINDOWFUNC
31361 /*
31362 ** Generate a human-readable explanation for a Window Function object
31363 */
31364 SQLITE_PRIVATE void sqlite3TreeViewWinFunc(TreeView *pView, const Window *pWin, u8 more){
 
31365 sqlite3TreeViewPush(&pView, more);
31366 sqlite3TreeViewLine(pView, "WINFUNC %s(%d)",
31367 pWin->pWFunc->zName, pWin->pWFunc->nArg);
31368 sqlite3TreeViewWindow(pView, pWin, 0);
31369 sqlite3TreeViewPop(&pView);
@@ -31386,12 +31502,15 @@
31386 if( pExpr->flags || pExpr->affExpr || pExpr->vvaFlags ){
31387 StrAccum x;
31388 sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0);
31389 sqlite3_str_appendf(&x, " fg.af=%x.%c",
31390 pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n');
31391 if( ExprHasProperty(pExpr, EP_FromJoin) ){
31392 sqlite3_str_appendf(&x, " iJoin=%d", pExpr->w.iJoin);
 
 
 
31393 }
31394 if( ExprHasProperty(pExpr, EP_FromDDL) ){
31395 sqlite3_str_appendf(&x, " DDL");
31396 }
31397 if( ExprHasVVAProperty(pExpr, EP_Immutable) ){
@@ -31611,11 +31730,21 @@
31611 sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags);
31612 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
31613 break;
31614 }
31615 case TK_IN: {
31616 sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags);
 
 
 
 
 
 
 
 
 
 
31617 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
31618 if( ExprUseXSelect(pExpr) ){
31619 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
31620 }else{
31621 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
@@ -31762,17 +31891,19 @@
31762 if( j || zName ){
31763 sqlite3TreeViewPush(&pView, moreToFollow);
31764 moreToFollow = 0;
31765 sqlite3TreeViewLine(pView, 0);
31766 if( zName ){
31767 switch( pList->a[i].eEName ){
31768 default:
31769 fprintf(stdout, "AS %s ", zName);
31770 break;
31771 case ENAME_TAB:
31772 fprintf(stdout, "TABLE-ALIAS-NAME(\"%s\") ", zName);
31773 if( pList->a[i].bUsed==0 ) fprintf(stdout, "(unused) ");
 
 
31774 break;
31775 case ENAME_SPAN:
31776 fprintf(stdout, "SPAN(\"%s\") ", zName);
31777 break;
31778 }
@@ -41741,90 +41872,103 @@
41741 }
41742 return SQLITE_OK;
41743 }
41744
41745 /*
41746 ** If the last component of the pathname in z[0]..z[j-1] is something
41747 ** other than ".." then back it out and return true. If the last
41748 ** component is empty or if it is ".." then return false.
41749 */
41750 static int unixBackupDir(const char *z, int *pJ){
41751 int j = *pJ;
41752 int i;
41753 if( j<=0 ) return 0;
41754 for(i=j-1; i>0 && z[i-1]!='/'; i--){}
41755 if( i==0 ) return 0;
41756 if( z[i]=='.' && i==j-2 && z[i+1]=='.' ) return 0;
41757 *pJ = i-1;
41758 return 1;
41759 }
41760
41761 /*
41762 ** Convert a relative pathname into a full pathname. Also
41763 ** simplify the pathname as follows:
41764 **
41765 ** Remove all instances of /./
41766 ** Remove all isntances of /X/../ for any X
41767 */
41768 static int mkFullPathname(
41769 const char *zPath, /* Input path */
41770 char *zOut, /* Output buffer */
41771 int nOut /* Allocated size of buffer zOut */
41772 ){
41773 int nPath = sqlite3Strlen30(zPath);
41774 int iOff = 0;
41775 int i, j;
41776 if( zPath[0]!='/' ){
41777 if( osGetcwd(zOut, nOut-2)==0 ){
41778 return unixLogError(SQLITE_CANTOPEN_BKPT, "getcwd", zPath);
41779 }
41780 iOff = sqlite3Strlen30(zOut);
41781 zOut[iOff++] = '/';
41782 }
41783 if( (iOff+nPath+1)>nOut ){
41784 /* SQLite assumes that xFullPathname() nul-terminates the output buffer
41785 ** even if it returns an error. */
41786 zOut[iOff] = '\0';
41787 return SQLITE_CANTOPEN_BKPT;
41788 }
41789 sqlite3_snprintf(nOut-iOff, &zOut[iOff], "%s", zPath);
41790
41791 /* Remove duplicate '/' characters. Except, two // at the beginning
41792 ** of a pathname is allowed since this is important on windows. */
41793 for(i=j=1; zOut[i]; i++){
41794 zOut[j++] = zOut[i];
41795 while( zOut[i]=='/' && zOut[i+1]=='/' ) i++;
41796 }
41797 zOut[j] = 0;
41798
41799 assert( zOut[0]=='/' );
41800 for(i=j=0; zOut[i]; i++){
41801 if( zOut[i]=='/' ){
41802 /* Skip over internal "/." directory components */
41803 if( zOut[i+1]=='.' && zOut[i+2]=='/' ){
41804 i += 1;
41805 continue;
41806 }
41807
41808 /* If this is a "/.." directory component then back out the
41809 ** previous term of the directory if it is something other than "..".
41810 */
41811 if( zOut[i+1]=='.'
41812 && zOut[i+2]=='.'
41813 && zOut[i+3]=='/'
41814 && unixBackupDir(zOut, &j)
41815 ){
41816 i += 2;
41817 continue;
41818 }
41819 }
41820 if( ALWAYS(j>=0) ) zOut[j] = zOut[i];
41821 j++;
41822 }
41823 if( NEVER(j==0) ) zOut[j++] = '/';
41824 zOut[j] = 0;
41825 return SQLITE_OK;
 
 
 
 
 
 
 
 
 
 
 
 
 
41826 }
41827
41828 /*
41829 ** Turn a relative pathname into a full pathname. The relative path
41830 ** is stored as a nul-terminated string in the buffer pointed to by
@@ -41838,89 +41982,30 @@
41838 sqlite3_vfs *pVfs, /* Pointer to vfs object */
41839 const char *zPath, /* Possibly relative input path */
41840 int nOut, /* Size of output buffer in bytes */
41841 char *zOut /* Output buffer */
41842 ){
41843 #if !defined(HAVE_READLINK) || !defined(HAVE_LSTAT)
41844 return mkFullPathname(zPath, zOut, nOut);
41845 #else
41846 int rc = SQLITE_OK;
41847 int nByte;
41848 int nLink = 0; /* Number of symbolic links followed so far */
41849 const char *zIn = zPath; /* Input path for each iteration of loop */
41850 char *zDel = 0;
41851
41852 assert( pVfs->mxPathname==MAX_PATHNAME );
41853 UNUSED_PARAMETER(pVfs);
41854
41855 /* It's odd to simulate an io-error here, but really this is just
41856 ** using the io-error infrastructure to test that SQLite handles this
41857 ** function failing. This function could fail if, for example, the
41858 ** current working directory has been unlinked.
41859 */
41860 SimulateIOError( return SQLITE_ERROR );
41861
41862 do {
41863
41864 /* Call stat() on path zIn. Set bLink to true if the path is a symbolic
41865 ** link, or false otherwise. */
41866 int bLink = 0;
41867 struct stat buf;
41868 if( osLstat(zIn, &buf)!=0 ){
41869 if( errno!=ENOENT ){
41870 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "lstat", zIn);
41871 }
41872 }else{
41873 bLink = S_ISLNK(buf.st_mode);
41874 }
41875
41876 if( bLink ){
41877 nLink++;
41878 if( zDel==0 ){
41879 zDel = sqlite3_malloc(nOut);
41880 if( zDel==0 ) rc = SQLITE_NOMEM_BKPT;
41881 }else if( nLink>=SQLITE_MAX_SYMLINKS ){
41882 rc = SQLITE_CANTOPEN_BKPT;
41883 }
41884
41885 if( rc==SQLITE_OK ){
41886 nByte = osReadlink(zIn, zDel, nOut-1);
41887 if( nByte<0 ){
41888 rc = unixLogError(SQLITE_CANTOPEN_BKPT, "readlink", zIn);
41889 }else{
41890 if( zDel[0]!='/' ){
41891 int n;
41892 for(n = sqlite3Strlen30(zIn); n>0 && zIn[n-1]!='/'; n--);
41893 if( nByte+n+1>nOut ){
41894 rc = SQLITE_CANTOPEN_BKPT;
41895 }else{
41896 memmove(&zDel[n], zDel, nByte+1);
41897 memcpy(zDel, zIn, n);
41898 nByte += n;
41899 }
41900 }
41901 zDel[nByte] = '\0';
41902 }
41903 }
41904
41905 zIn = zDel;
41906 }
41907
41908 assert( rc!=SQLITE_OK || zIn!=zOut || zIn[0]=='/' );
41909 if( rc==SQLITE_OK && zIn!=zOut ){
41910 rc = mkFullPathname(zIn, zOut, nOut);
41911 }
41912 if( bLink==0 ) break;
41913 zIn = zOut;
41914 }while( rc==SQLITE_OK );
41915
41916 sqlite3_free(zDel);
41917 if( rc==SQLITE_OK && nLink ) rc = SQLITE_OK_SYMLINK;
41918 return rc;
41919 #endif /* HAVE_READLINK && HAVE_LSTAT */
41920 }
41921
41922
41923 #ifndef SQLITE_OMIT_LOAD_EXTENSION
41924 /*
41925 ** Interfaces for opening a shared library, finding entry points
41926 ** within the shared library, and closing the shared library.
@@ -75861,11 +75946,11 @@
75861 }
75862
75863 TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
75864 pCur->pgnoRoot, pX->nKey, pX->nData, pPage->pgno,
75865 loc==0 ? "overwrite" : "new entry"));
75866 assert( pPage->isInit );
75867 newCell = pBt->pTmpSpace;
75868 assert( newCell!=0 );
75869 if( flags & BTREE_PREFORMAT ){
75870 rc = SQLITE_OK;
75871 szNew = pBt->nPreformatSize;
@@ -81423,10 +81508,94 @@
81423 pParse->nLabel = 0;
81424 *pMaxFuncArgs = nMaxArgs;
81425 assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) );
81426 }
81427
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81428 /*
81429 ** Return the address of the next instruction to be inserted.
81430 */
81431 SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe *p){
81432 assert( p->eVdbeState==VDBE_INIT_STATE );
@@ -82035,15 +82204,13 @@
82035 if( c=='4' ){
82036 sqlite3_str_appendall(&x, zP4);
82037 }else if( c=='X' ){
82038 if( pOp->zComment && pOp->zComment[0] ){
82039 sqlite3_str_appendall(&x, pOp->zComment);
82040 }else{
82041 sqlite3_str_appendall(&x, zSynopsis+1);
82042 }
82043 seenCom = 1;
82044 break;
82045 }else{
82046 int v1 = translateP(c, pOp);
82047 int v2;
82048 if( strncmp(zSynopsis+ii+1, "@P", 2)==0 ){
82049 ii += 3;
@@ -89154,10 +89321,12 @@
89154 if( pOp->p2==0 ) break;
89155
89156 /* Most jump operations do a goto to this spot in order to update
89157 ** the pOp pointer. */
89158 jump_to_p2:
 
 
89159 pOp = &aOp[pOp->p2 - 1];
89160 break;
89161 }
89162
89163 /* Opcode: EndCoroutine P1 * * * *
@@ -101365,11 +101534,11 @@
101365 const char *zTab,
101366 const char *zDb
101367 ){
101368 int n;
101369 const char *zSpan;
101370 if( pItem->eEName!=ENAME_TAB ) return 0;
101371 zSpan = pItem->zEName;
101372 for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
101373 if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){
101374 return 0;
101375 }
@@ -101594,12 +101763,13 @@
101594 }
101595 cnt++;
101596 cntTab = 2;
101597 pMatch = pItem;
101598 pExpr->iColumn = j;
101599 pEList->a[j].bUsed = 1;
101600 hit = 1;
 
101601 }
101602 if( hit || zTab==0 ) continue;
101603 }
101604 assert( zDb==0 || zTab!=0 );
101605 if( zTab ){
@@ -101818,11 +101988,11 @@
101818 ){
101819 pEList = pNC->uNC.pEList;
101820 assert( pEList!=0 );
101821 for(j=0; j<pEList->nExpr; j++){
101822 char *zAs = pEList->a[j].zEName;
101823 if( pEList->a[j].eEName==ENAME_NAME
101824 && sqlite3_stricmp(zAs, zCol)==0
101825 ){
101826 Expr *pOrig;
101827 assert( pExpr->pLeft==0 && pExpr->pRight==0 );
101828 assert( ExprUseXList(pExpr)==0 || pExpr->x.pList==0 );
@@ -102162,11 +102332,11 @@
102162 for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){
102163 anRef[i] = p->nRef;
102164 }
102165 sqlite3WalkExpr(pWalker, pExpr->pLeft);
102166 if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){
102167 testcase( ExprHasProperty(pExpr, EP_FromJoin) );
102168 assert( !ExprHasProperty(pExpr, EP_IntValue) );
102169 if( pExpr->op==TK_NOTNULL ){
102170 pExpr->u.zToken = "true";
102171 ExprSetProperty(pExpr, EP_IsTrue);
102172 }else{
@@ -102571,11 +102741,11 @@
102571 if( pE->op==TK_ID ){
102572 const char *zCol;
102573 assert( !ExprHasProperty(pE, EP_IntValue) );
102574 zCol = pE->u.zToken;
102575 for(i=0; i<pEList->nExpr; i++){
102576 if( pEList->a[i].eEName==ENAME_NAME
102577 && sqlite3_stricmp(pEList->a[i].zEName, zCol)==0
102578 ){
102579 return i+1;
102580 }
102581 }
@@ -102692,11 +102862,11 @@
102692 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
102693 sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause");
102694 return 1;
102695 }
102696 for(i=0; i<pOrderBy->nExpr; i++){
102697 pOrderBy->a[i].done = 0;
102698 }
102699 pSelect->pNext = 0;
102700 while( pSelect->pPrior ){
102701 pSelect->pPrior->pNext = pSelect;
102702 pSelect = pSelect->pPrior;
@@ -102707,11 +102877,11 @@
102707 pEList = pSelect->pEList;
102708 assert( pEList!=0 );
102709 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
102710 int iCol = -1;
102711 Expr *pE, *pDup;
102712 if( pItem->done ) continue;
102713 pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr);
102714 if( NEVER(pE==0) ) continue;
102715 if( sqlite3ExprIsInteger(pE, &iCol) ){
102716 if( iCol<=0 || iCol>pEList->nExpr ){
102717 resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr, pE);
@@ -102760,19 +102930,19 @@
102760 pParent->pLeft = pNew;
102761 }
102762 sqlite3ExprDelete(db, pE);
102763 pItem->u.x.iOrderByCol = (u16)iCol;
102764 }
102765 pItem->done = 1;
102766 }else{
102767 moreToDo = 1;
102768 }
102769 }
102770 pSelect = pSelect->pNext;
102771 }
102772 for(i=0; i<pOrderBy->nExpr; i++){
102773 if( pOrderBy->a[i].done==0 ){
102774 sqlite3ErrorMsg(pParse, "%r ORDER BY term does not match any "
102775 "column in the result set", i+1);
102776 return 1;
102777 }
102778 }
@@ -104453,10 +104623,11 @@
104453 pNew = sqlite3ExprAlloc(db, TK_FUNCTION, pToken, 1);
104454 if( pNew==0 ){
104455 sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */
104456 return 0;
104457 }
 
104458 pNew->w.iOfst = (int)(pToken->z - pParse->zTail);
104459 if( pList
104460 && pList->nExpr > pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG]
104461 && !pParse->nested
104462 ){
@@ -104731,11 +104902,11 @@
104731 #endif
104732 ){
104733 nSize = EXPR_FULLSIZE;
104734 }else{
104735 assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
104736 assert( !ExprHasProperty(p, EP_FromJoin) );
104737 assert( !ExprHasProperty(p, EP_MemToken) );
104738 assert( !ExprHasVVAProperty(p, EP_NoReduce) );
104739 if( p->pLeft || p->x.pList ){
104740 nSize = EXPR_REDUCEDSIZE | EP_Reduced;
104741 }else{
@@ -104911,10 +105082,11 @@
104911 pRet->nCte = p->nCte;
104912 for(i=0; i<p->nCte; i++){
104913 pRet->a[i].pSelect = sqlite3SelectDup(db, p->a[i].pSelect, 0);
104914 pRet->a[i].pCols = sqlite3ExprListDup(db, p->a[i].pCols, 0);
104915 pRet->a[i].zName = sqlite3DbStrDup(db, p->a[i].zName);
 
104916 }
104917 }
104918 }
104919 return pRet;
104920 }
@@ -105011,16 +105183,12 @@
105011 }
105012 pNewExpr->pLeft = pPriorSelectColNew;
105013 }
105014 }
105015 pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName);
105016 pItem->sortFlags = pOldItem->sortFlags;
105017 pItem->eEName = pOldItem->eEName;
105018 pItem->done = 0;
105019 pItem->bNulls = pOldItem->bNulls;
105020 pItem->bUsed = pOldItem->bUsed;
105021 pItem->bSorterRef = pOldItem->bSorterRef;
105022 pItem->u = pOldItem->u;
105023 }
105024 return pNew;
105025 }
105026
@@ -105316,20 +105484,20 @@
105316 || eNulls==SQLITE_SO_ASC
105317 || eNulls==SQLITE_SO_DESC
105318 );
105319
105320 pItem = &p->a[p->nExpr-1];
105321 assert( pItem->bNulls==0 );
105322 if( iSortOrder==SQLITE_SO_UNDEFINED ){
105323 iSortOrder = SQLITE_SO_ASC;
105324 }
105325 pItem->sortFlags = (u8)iSortOrder;
105326
105327 if( eNulls!=SQLITE_SO_UNDEFINED ){
105328 pItem->bNulls = 1;
105329 if( iSortOrder!=eNulls ){
105330 pItem->sortFlags |= KEYINFO_ORDER_BIGNULL;
105331 }
105332 }
105333 }
105334
105335 /*
@@ -105351,11 +105519,11 @@
105351 if( pList ){
105352 struct ExprList_item *pItem;
105353 assert( pList->nExpr>0 );
105354 pItem = &pList->a[pList->nExpr-1];
105355 assert( pItem->zEName==0 );
105356 assert( pItem->eEName==ENAME_NAME );
105357 pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
105358 if( dequote ){
105359 /* If dequote==0, then pName->z does not point to part of a DDL
105360 ** statement handled by the parser. And so no token need be added
105361 ** to the token-map. */
@@ -105386,11 +105554,11 @@
105386 if( pList ){
105387 struct ExprList_item *pItem = &pList->a[pList->nExpr-1];
105388 assert( pList->nExpr>0 );
105389 if( pItem->zEName==0 ){
105390 pItem->zEName = sqlite3DbSpanDup(db, zStart, zEnd);
105391 pItem->eEName = ENAME_SPAN;
105392 }
105393 }
105394 }
105395
105396 /*
@@ -105560,11 +105728,11 @@
105560 static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
105561
105562 /* If pWalker->eCode is 2 then any term of the expression that comes from
105563 ** the ON or USING clauses of an outer join disqualifies the expression
105564 ** from being considered constant. */
105565 if( pWalker->eCode==2 && ExprHasProperty(pExpr, EP_FromJoin) ){
105566 pWalker->eCode = 0;
105567 return WRC_Abort;
105568 }
105569
105570 switch( pExpr->op ){
@@ -105678,10 +105846,46 @@
105678 ** table other than iCur.
105679 */
105680 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){
105681 return exprIsConst(p, 3, iCur);
105682 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105683
105684
105685 /*
105686 ** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy().
105687 */
@@ -106006,11 +106210,11 @@
106006 ** The job of this routine is to find or create a b-tree object that can
106007 ** be used either to test for membership in the RHS set or to iterate through
106008 ** all members of the RHS set, skipping duplicates.
106009 **
106010 ** A cursor is opened on the b-tree object that is the RHS of the IN operator
106011 ** and pX->iTable is set to the index of that cursor.
106012 **
106013 ** The returned value of this function indicates the b-tree type, as follows:
106014 **
106015 ** IN_INDEX_ROWID - The cursor was opened on a database table.
106016 ** IN_INDEX_INDEX_ASC - The cursor was opened on an ascending index.
@@ -106026,11 +106230,14 @@
106026 ** SELECT <column1>, <column2>... FROM <table>
106027 **
106028 ** If the RHS of the IN operator is a list or a more complex subquery, then
106029 ** an ephemeral table might need to be generated from the RHS and then
106030 ** pX->iTable made to point to the ephemeral table instead of an
106031 ** existing table.
 
 
 
106032 **
106033 ** The inFlags parameter must contain, at a minimum, one of the bits
106034 ** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP but not both. If inFlags contains
106035 ** IN_INDEX_MEMBERSHIP, then the generated table will be used for a fast
106036 ** membership test. When the IN_INDEX_LOOP bit is set, the IN index will
@@ -106087,16 +106294,17 @@
106087 int *aiMap, /* Mapping from Index fields to RHS fields */
106088 int *piTab /* OUT: index to use */
106089 ){
106090 Select *p; /* SELECT to the right of IN operator */
106091 int eType = 0; /* Type of RHS table. IN_INDEX_* */
106092 int iTab = pParse->nTab++; /* Cursor of the RHS table */
106093 int mustBeUnique; /* True if RHS must be unique */
106094 Vdbe *v = sqlite3GetVdbe(pParse); /* Virtual machine being coded */
106095
106096 assert( pX->op==TK_IN );
106097 mustBeUnique = (inFlags & IN_INDEX_LOOP)!=0;
 
106098
106099 /* If the RHS of this IN(...) operator is a SELECT, and if it matters
106100 ** whether or not the SELECT result contains NULL values, check whether
106101 ** or not NULL is actually possible (it may not be, for example, due
106102 ** to NOT NULL constraints in the schema). If no NULL values are possible,
@@ -106258,10 +106466,12 @@
106258 if( eType==0
106259 && (inFlags & IN_INDEX_NOOP_OK)
106260 && ExprUseXList(pX)
106261 && (!sqlite3InRhsIsConstant(pX) || pX->x.pList->nExpr<=2)
106262 ){
 
 
106263 eType = IN_INDEX_NOOP;
106264 }
106265
106266 if( eType==0 ){
106267 /* Could not find an existing table or index to use as the RHS b-tree.
@@ -106424,10 +106634,11 @@
106424 pExpr->x.pSelect->selId));
106425 }
106426 assert( ExprUseYSub(pExpr) );
106427 sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
106428 pExpr->y.sub.iAddr);
 
106429 sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable);
106430 sqlite3VdbeJumpHere(v, addrOnce);
106431 return;
106432 }
106433
@@ -107298,11 +107509,21 @@
107298 memset(&caseExpr, 0, sizeof(caseExpr));
107299 caseExpr.op = TK_CASE;
107300 caseExpr.x.pList = pFarg;
107301 return sqlite3ExprCodeTarget(pParse, &caseExpr, target);
107302 }
107303
 
 
 
 
 
 
 
 
 
 
107304 default: {
107305 /* The UNLIKELY() function is a no-op. The result is the value
107306 ** of the first argument.
107307 */
107308 assert( nFarg==1 || nFarg==2 );
@@ -107837,24 +108058,12 @@
107837 #endif
107838 if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){
107839 if( !pColl ) pColl = db->pDfltColl;
107840 sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
107841 }
107842 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
107843 if( (pDef->funcFlags & SQLITE_FUNC_OFFSET)!=0 && ALWAYS(pFarg!=0) ){
107844 Expr *pArg = pFarg->a[0].pExpr;
107845 if( pArg->op==TK_COLUMN ){
107846 sqlite3VdbeAddOp3(v, OP_Offset, pArg->iTable, pArg->iColumn, target);
107847 }else{
107848 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
107849 }
107850 }else
107851 #endif
107852 {
107853 sqlite3VdbeAddFunctionCall(pParse, constMask, r1, target, nFarg,
107854 pDef, pExpr->op2);
107855 }
107856 if( nFarg ){
107857 if( constMask==0 ){
107858 sqlite3ReleaseTempRange(pParse, r1, nFarg);
107859 }else{
107860 sqlite3VdbeReleaseRegisters(pParse, r1, nFarg, constMask, 1);
@@ -108164,11 +108373,13 @@
108164 p = pParse->pConstExpr;
108165 if( regDest<0 && p ){
108166 struct ExprList_item *pItem;
108167 int i;
108168 for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
108169 if( pItem->reusable && sqlite3ExprCompare(0,pItem->pExpr,pExpr,-1)==0 ){
 
 
108170 return pItem->u.iConstExprReg;
108171 }
108172 }
108173 }
108174 pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
@@ -108187,11 +108398,11 @@
108187 sqlite3VdbeJumpHere(v, addr);
108188 }else{
108189 p = sqlite3ExprListAppend(pParse, p, pExpr);
108190 if( p ){
108191 struct ExprList_item *pItem = &p->a[p->nExpr-1];
108192 pItem->reusable = regDest<0;
108193 if( regDest<0 ) regDest = ++pParse->nMem;
108194 pItem->u.iConstExprReg = regDest;
108195 }
108196 pParse->pConstExpr = p;
108197 }
@@ -108321,11 +108532,11 @@
108321 n = pList->nExpr;
108322 if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR;
108323 for(pItem=pList->a, i=0; i<n; i++, pItem++){
108324 Expr *pExpr = pItem->pExpr;
108325 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
108326 if( pItem->bSorterRef ){
108327 i--;
108328 n--;
108329 }else
108330 #endif
108331 if( (flags & SQLITE_ECEL_REF)!=0 && (j = pItem->u.x.iOrderByCol)>0 ){
@@ -108415,12 +108626,12 @@
108415 }else{
108416 /* Mark the expression is being from the ON or USING clause of a join
108417 ** so that the sqlite3ExprCodeTarget() routine will not attempt to move
108418 ** it into the Parse.pConstExpr list. We should use a new bit for this,
108419 ** for clarity, but we are out of bits in the Expr.flags field so we
108420 ** have to reuse the EP_FromJoin bit. Bummer. */
108421 pDel->flags |= EP_FromJoin;
108422 sqlite3ExprCodeTarget(pParse, &exprAnd, dest);
108423 }
108424 sqlite3ReleaseTempReg(pParse, regFree1);
108425 }
108426 sqlite3ExprDelete(db, pDel);
@@ -108946,11 +109157,11 @@
108946 if( pA->nExpr!=pB->nExpr ) return 1;
108947 for(i=0; i<pA->nExpr; i++){
108948 int res;
108949 Expr *pExprA = pA->a[i].pExpr;
108950 Expr *pExprB = pB->a[i].pExpr;
108951 if( pA->a[i].sortFlags!=pB->a[i].sortFlags ) return 1;
108952 if( (res = sqlite3ExprCompare(0, pExprA, pExprB, iTab)) ) return res;
108953 }
108954 return 0;
108955 }
108956
@@ -109101,11 +109312,11 @@
109101 ** (never setting pWalker->eCode) is a harmless missed optimization.
109102 */
109103 static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){
109104 testcase( pExpr->op==TK_AGG_COLUMN );
109105 testcase( pExpr->op==TK_AGG_FUNCTION );
109106 if( ExprHasProperty(pExpr, EP_FromJoin) ) return WRC_Prune;
109107 switch( pExpr->op ){
109108 case TK_ISNOT:
109109 case TK_ISNULL:
109110 case TK_NOTNULL:
109111 case TK_IS:
@@ -109198,11 +109409,11 @@
109198 ** is NULL. A false negative is merely a missed optimization opportunity.
109199 **
109200 ** False positives are not allowed, however. A false positive may result
109201 ** in an incorrect answer.
109202 **
109203 ** Terms of p that are marked with EP_FromJoin (and hence that come from
109204 ** the ON or USING clauses of OUTER JOINS) are excluded from the analysis.
109205 **
109206 ** This routine is used to check if a LEFT JOIN can be converted into
109207 ** an ordinary JOIN. The p argument is the WHERE clause. If the WHERE
109208 ** clause requires that some column of the right table of the LEFT JOIN
@@ -110635,11 +110846,11 @@
110635 return WRC_Prune;
110636 }
110637 if( ALWAYS(p->pEList) ){
110638 ExprList *pList = p->pEList;
110639 for(i=0; i<pList->nExpr; i++){
110640 if( pList->a[i].zEName && pList->a[i].eEName==ENAME_NAME ){
110641 sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName);
110642 }
110643 }
110644 }
110645 if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */
@@ -110684,11 +110895,11 @@
110684 memset(&sWalker, 0, sizeof(Walker));
110685 sWalker.pParse = pParse;
110686 sWalker.xExprCallback = renameUnmapExprCb;
110687 sqlite3WalkExprList(&sWalker, pEList);
110688 for(i=0; i<pEList->nExpr; i++){
110689 if( ALWAYS(pEList->a[i].eEName==ENAME_NAME) ){
110690 sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName);
110691 }
110692 }
110693 }
110694 }
@@ -110842,11 +111053,11 @@
110842 ){
110843 if( pEList ){
110844 int i;
110845 for(i=0; i<pEList->nExpr; i++){
110846 const char *zName = pEList->a[i].zEName;
110847 if( ALWAYS(pEList->a[i].eEName==ENAME_NAME)
110848 && ALWAYS(zName!=0)
110849 && 0==sqlite3_stricmp(zName, zOld)
110850 ){
110851 renameTokenFind(pParse, pCtx, (const void*)zName);
110852 }
@@ -111072,31 +111283,37 @@
111072 if( pParse->nErr ) rc = pParse->rc;
111073 }
111074 if( rc==SQLITE_OK && pStep->zTarget ){
111075 SrcList *pSrc = sqlite3TriggerStepSrc(pParse, pStep);
111076 if( pSrc ){
111077 int i;
111078 for(i=0; i<pSrc->nSrc && rc==SQLITE_OK; i++){
111079 SrcItem *p = &pSrc->a[i];
111080 p->iCursor = pParse->nTab++;
111081 if( p->pSelect ){
111082 sqlite3SelectPrep(pParse, p->pSelect, 0);
111083 sqlite3ExpandSubquery(pParse, p);
111084 assert( i>0 );
111085 assert( pStep->pFrom->a[i-1].pSelect );
111086 sqlite3SelectPrep(pParse, pStep->pFrom->a[i-1].pSelect, 0);
111087 }else{
111088 p->pTab = sqlite3LocateTableItem(pParse, 0, p);
111089 if( p->pTab==0 ){
111090 rc = SQLITE_ERROR;
111091 }else{
111092 p->pTab->nTabRef++;
111093 rc = sqlite3ViewGetColumnNames(pParse, p->pTab);
 
 
 
 
 
111094 }
111095 }
111096 }
111097 if( rc==SQLITE_OK && db->mallocFailed ){
 
111098 rc = SQLITE_NOMEM;
111099 }
111100 sNC.pSrcList = pSrc;
111101 if( rc==SQLITE_OK && pStep->pWhere ){
111102 rc = sqlite3ResolveExprNames(&sNC, pStep->pWhere);
@@ -111543,10 +111760,19 @@
111543 if( rc==SQLITE_OK ){
111544 renameWalkTrigger(&sWalker, pTrigger);
111545 for(pStep=pTrigger->step_list; pStep; pStep=pStep->pNext){
111546 if( pStep->zTarget && 0==sqlite3_stricmp(pStep->zTarget, zOld) ){
111547 renameTokenFind(&sParse, &sCtx, pStep->zTarget);
 
 
 
 
 
 
 
 
 
111548 }
111549 }
111550 }
111551 }
111552 }
@@ -112867,13 +113093,18 @@
112867 ** * the index contains 100 rows,
112868 ** * "WHERE a=?" matches 10 rows, and
112869 ** * "WHERE a=? AND b=?" matches 2 rows.
112870 **
112871 ** If D is the count of distinct values and K is the total number of
112872 ** rows, then each estimate is computed as:
112873 **
112874 ** I = (K+D-1)/D
 
 
 
 
 
112875 */
112876 sqlite3_str sStat; /* Text of the constructed "stat" line */
112877 int i; /* Loop counter */
112878
112879 sqlite3StrAccumInit(&sStat, 0, 0, 0, (p->nKeyCol+1)*100);
@@ -112880,10 +113111,11 @@
112880 sqlite3_str_appendf(&sStat, "%llu",
112881 p->nSkipAhead ? (u64)p->nEst : (u64)p->nRow);
112882 for(i=0; i<p->nKeyCol; i++){
112883 u64 nDistinct = p->current.anDLt[i] + 1;
112884 u64 iVal = (p->nRow + nDistinct - 1) / nDistinct;
 
112885 sqlite3_str_appendf(&sStat, " %llu", iVal);
112886 assert( p->current.anEq[i] );
112887 }
112888 sqlite3ResultStrAccum(context, &sStat);
112889 }
@@ -115001,13 +115233,11 @@
115001 Returning *pReturning = pParse->u1.pReturning;
115002 int addrRewind;
115003 int i;
115004 int reg;
115005
115006 if( NEVER(pReturning->nRetCol==0) ){
115007 assert( CORRUPT_DB );
115008 }else{
115009 sqlite3VdbeAddOp0(v, OP_FkCheck);
115010 addrRewind =
115011 sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur);
115012 VdbeCoverage(v);
115013 reg = pReturning->iRetReg;
@@ -115099,13 +115329,11 @@
115099 }
115100 }
115101
115102 if( pParse->bReturning ){
115103 Returning *pRet = pParse->u1.pReturning;
115104 if( NEVER(pRet->nRetCol==0) ){
115105 assert( CORRUPT_DB );
115106 }else{
115107 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
115108 }
115109 }
115110
115111 /* Finally, jump back to the beginning of the executable code. */
@@ -116723,11 +116951,11 @@
116723 }
116724 pTab->iPKey = iCol;
116725 pTab->keyConf = (u8)onError;
116726 assert( autoInc==0 || autoInc==1 );
116727 pTab->tabFlags |= autoInc*TF_Autoincrement;
116728 if( pList ) pParse->iPkSortOrder = pList->a[0].sortFlags;
116729 (void)sqlite3HasExplicitNulls(pParse, pList);
116730 }else if( autoInc ){
116731 #ifndef SQLITE_OMIT_AUTOINCREMENT
116732 sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an "
116733 "INTEGER PRIMARY KEY");
@@ -117217,11 +117445,11 @@
117217 return;
117218 }
117219 if( IN_RENAME_OBJECT ){
117220 sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey);
117221 }
117222 pList->a[0].sortFlags = pParse->iPkSortOrder;
117223 assert( pParse->pNewTable==pTab );
117224 pTab->iPKey = -1;
117225 sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
117226 SQLITE_IDXTYPE_PRIMARYKEY);
117227 if( pParse->nErr ){
@@ -117888,11 +118116,10 @@
117888 */
117889 SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
117890 Table *pSelTab; /* A fake table from which we get the result set */
117891 Select *pSel; /* Copy of the SELECT that implements the view */
117892 int nErr = 0; /* Number of errors encountered */
117893 int n; /* Temporarily holds the number of cursors assigned */
117894 sqlite3 *db = pParse->db; /* Database connection for malloc errors */
117895 #ifndef SQLITE_OMIT_VIRTUALTABLE
117896 int rc;
117897 #endif
117898 #ifndef SQLITE_OMIT_AUTHORIZATION
@@ -117946,12 +118173,13 @@
117946 */
117947 assert( IsView(pTable) );
117948 pSel = sqlite3SelectDup(db, pTable->u.view.pSelect, 0);
117949 if( pSel ){
117950 u8 eParseMode = pParse->eParseMode;
 
 
117951 pParse->eParseMode = PARSE_MODE_NORMAL;
117952 n = pParse->nTab;
117953 sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
117954 pTable->nCol = -1;
117955 DisableLookaside;
117956 #ifndef SQLITE_OMIT_AUTHORIZATION
117957 xAuth = db->xAuth;
@@ -117959,11 +118187,12 @@
117959 pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, SQLITE_AFF_NONE);
117960 db->xAuth = xAuth;
117961 #else
117962 pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, SQLITE_AFF_NONE);
117963 #endif
117964 pParse->nTab = n;
 
117965 if( pSelTab==0 ){
117966 pTable->nCol = 0;
117967 nErr++;
117968 }else if( pTable->pCheck ){
117969 /* CREATE VIEW name(arglist) AS ...
@@ -118704,12 +118933,12 @@
118704 */
118705 SQLITE_PRIVATE int sqlite3HasExplicitNulls(Parse *pParse, ExprList *pList){
118706 if( pList ){
118707 int i;
118708 for(i=0; i<pList->nExpr; i++){
118709 if( pList->a[i].bNulls ){
118710 u8 sf = pList->a[i].sortFlags;
118711 sqlite3ErrorMsg(pParse, "unsupported use of NULLS %s",
118712 (sf==0 || sf==3) ? "FIRST" : "LAST"
118713 );
118714 return 1;
118715 }
@@ -119058,11 +119287,11 @@
119058 if( !zColl ) zColl = sqlite3StrBINARY;
119059 if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
119060 goto exit_create_index;
119061 }
119062 pIndex->azColl[i] = zColl;
119063 requestedSortOrder = pListItem->sortFlags & sortOrderMask;
119064 pIndex->aSortOrder[i] = (u8)requestedSortOrder;
119065 }
119066
119067 /* Append the table key to the end of the index. For WITHOUT ROWID
119068 ** tables (when pPk!=0) this will be the declared PRIMARY KEY. For
@@ -124139,15 +124368,15 @@
124139 }else{
124140 ans = log(x);
124141 switch( SQLITE_PTR_TO_INT(sqlite3_user_data(context)) ){
124142 case 1:
124143 /* Convert from natural logarithm to log base 10 */
124144 ans *= 1.0/M_LN10;
124145 break;
124146 case 2:
124147 /* Convert from natural logarithm to log base 2 */
124148 ans *= 1.0/M_LN2;
124149 break;
124150 default:
124151 break;
124152 }
124153 }
@@ -124282,12 +124511,11 @@
124282 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
124283 INLINE_FUNC(unlikely, 1, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY),
124284 INLINE_FUNC(likelihood, 2, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY),
124285 INLINE_FUNC(likely, 1, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY),
124286 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
124287 {1, SQLITE_FUNC_BUILTIN|SQLITE_UTF8|SQLITE_FUNC_OFFSET|SQLITE_FUNC_TYPEOF,
124288 0, 0, noopFunc, 0, 0, 0, "sqlite_offset", {0} },
124289 #endif
124290 FUNCTION(ltrim, 1, 1, 0, trimFunc ),
124291 FUNCTION(ltrim, 2, 1, 0, trimFunc ),
124292 FUNCTION(rtrim, 1, 2, 0, trimFunc ),
124293 FUNCTION(rtrim, 2, 2, 0, trimFunc ),
@@ -129567,10 +129795,11 @@
129567 /* Version 3.39.0 and later */
129568 int (*deserialize)(sqlite3*,const char*,unsigned char*,
129569 sqlite3_int64,sqlite3_int64,unsigned);
129570 unsigned char *(*serialize)(sqlite3*,const char *,sqlite3_int64*,
129571 unsigned int);
 
129572 };
129573
129574 /*
129575 ** This is the function signature used for all extension entry points. It
129576 ** is also defined in the file "loadext.c".
@@ -129885,14 +130114,16 @@
129885 #define sqlite3_vtab_rhs_value sqlite3_api->vtab_rhs_value
129886 #define sqlite3_vtab_distinct sqlite3_api->vtab_distinct
129887 #define sqlite3_vtab_in sqlite3_api->vtab_in
129888 #define sqlite3_vtab_in_first sqlite3_api->vtab_in_first
129889 #define sqlite3_vtab_in_next sqlite3_api->vtab_in_next
 
129890 #ifndef SQLITE_OMIT_DESERIALIZE
129891 #define sqlite3_deserialize sqlite3_api->deserialize
129892 #define sqlite3_serialize sqlite3_api->serialize
129893 #endif
 
129894 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
129895
129896 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
129897 /* This case when the file really is being compiled as a loadable
129898 ** extension */
@@ -130380,23 +130611,32 @@
130380 sqlite3_total_changes64,
130381 /* Version 3.37.0 and later */
130382 sqlite3_autovacuum_pages,
130383 /* Version 3.38.0 and later */
130384 sqlite3_error_offset,
 
130385 sqlite3_vtab_rhs_value,
130386 sqlite3_vtab_distinct,
130387 sqlite3_vtab_in,
130388 sqlite3_vtab_in_first,
130389 sqlite3_vtab_in_next,
 
 
 
 
 
 
 
130390 /* Version 3.39.0 and later */
130391 #ifndef SQLITE_OMIT_DESERIALIZE
130392 sqlite3_deserialize,
130393 sqlite3_serialize
130394 #else
 
130395 0,
130396 0
130397 #endif
 
130398 };
130399
130400 /* True if x is the directory separator character
130401 */
130402 #if SQLITE_OS_WIN
@@ -134828,10 +135068,18 @@
134828 db->pParse = pParse;
134829 pParse->db = db;
134830 if( db->mallocFailed ) sqlite3ErrorMsg(pParse, "out of memory");
134831 }
134832
 
 
 
 
 
 
 
 
134833 /*
134834 ** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
134835 */
134836 static int sqlite3Prepare(
134837 sqlite3 *db, /* Database handle. */
@@ -135002,11 +135250,11 @@
135002 ** or encounters a permanent error. A schema problem after one schema
135003 ** reset is considered a permanent error. */
135004 rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail);
135005 assert( rc==SQLITE_OK || *ppStmt==0 );
135006 if( rc==SQLITE_OK || db->mallocFailed ) break;
135007 }while( rc==SQLITE_ERROR_RETRY
135008 || (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) );
135009 sqlite3BtreeLeaveAll(db);
135010 rc = sqlite3ApiExit(db, rc);
135011 assert( (rc&db->errMask)==rc );
135012 db->busyHandler.nBusy = 0;
@@ -135553,11 +135801,11 @@
135553 ExprList *pResults;
135554 assert( pItem->pSelect!=0 );
135555 pResults = pItem->pSelect->pEList;
135556 assert( pResults!=0 );
135557 assert( iCol>=0 && iCol<pResults->nExpr );
135558 pResults->a[iCol].bUsed = 1;
135559 }
135560 }
135561
135562 /*
135563 ** Search the tables iStart..iEnd (inclusive) in pSrc, looking for a
@@ -135600,15 +135848,15 @@
135600 }
135601 return 0;
135602 }
135603
135604 /*
135605 ** Set the EP_FromJoin property on all terms of the given expression.
135606 ** And set the Expr.w.iJoin to iTable for every term in the
135607 ** expression.
135608 **
135609 ** The EP_FromJoin property is used on terms of an expression to tell
135610 ** the OUTER JOIN processing logic that this term is part of the
135611 ** join restriction specified in the ON or USING clause and not a part
135612 ** of the more general WHERE clause. These terms are moved over to the
135613 ** WHERE clause during join processing but we need to remember that they
135614 ** originated in the ON or USING clause.
@@ -135626,11 +135874,11 @@
135626 ** defer the handling of t1.x=5, it will be processed immediately
135627 ** after the t1 loop and rows with t1.x!=5 will never appear in
135628 ** the output, which is incorrect.
135629 */
135630 SQLITE_PRIVATE void sqlite3SetJoinExpr(Expr *p, int iTable, u32 joinFlag){
135631 assert( joinFlag==EP_FromJoin || joinFlag==EP_InnerJoin );
135632 while( p ){
135633 ExprSetProperty(p, joinFlag);
135634 assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
135635 ExprSetVVAProperty(p, EP_NoReduce);
135636 p->w.iJoin = iTable;
@@ -135647,21 +135895,21 @@
135647 p = p->pRight;
135648 }
135649 }
135650
135651 /* Undo the work of sqlite3SetJoinExpr(). In the expression p, convert every
135652 ** term that is marked with EP_FromJoin and w.iJoin==iTable into
135653 ** an ordinary term that omits the EP_FromJoin mark.
135654 **
135655 ** This happens when a LEFT JOIN is simplified into an ordinary JOIN.
135656 */
135657 static void unsetJoinExpr(Expr *p, int iTable){
135658 while( p ){
135659 if( ExprHasProperty(p, EP_FromJoin)
135660 && (iTable<0 || p->w.iJoin==iTable) ){
135661 ExprClearProperty(p, EP_FromJoin);
135662 ExprSetProperty(p, EP_InnerJoin);
135663 }
135664 if( p->op==TK_COLUMN && p->iTable==iTable ){
135665 ExprClearProperty(p, EP_CanBeNull);
135666 }
135667 if( p->op==TK_FUNCTION ){
@@ -135685,12 +135933,12 @@
135685 ** do not need to be concerned with NATURAL joins and we only have
135686 ** think about USING joins.
135687 **
135688 ** * ON and USING clauses result in extra terms being added to the
135689 ** WHERE clause to enforce the specified constraints. The extra
135690 ** WHERE clause terms will be tagged with EP_FromJoin or
135691 ** EP_InnerJoin so that we know that they originated in ON/USING.
135692 **
135693 ** The terms of a FROM clause are contained in the Select.pSrc structure.
135694 ** The left most table is the first entry in Select.pSrc. The right-most
135695 ** table is the last entry. The join operator is held in the entry to
135696 ** the right. Thus entry 1 contains the join operator for the join between
@@ -135711,11 +135959,11 @@
135711 for(i=0; i<pSrc->nSrc-1; i++, pRight++, pLeft++){
135712 Table *pRightTab = pRight->pTab;
135713 u32 joinType;
135714
135715 if( NEVER(pLeft->pTab==0 || pRightTab==0) ) continue;
135716 joinType = (pRight->fg.jointype & JT_OUTER)!=0 ? EP_FromJoin : EP_InnerJoin;
135717
135718 /* If this is a NATURAL join, synthesize an approprate USING clause
135719 ** to specify which columns should be joined.
135720 */
135721 if( pRight->fg.jointype & JT_NATURAL ){
@@ -136221,11 +136469,11 @@
136221 ** the row from table t1 is stored instead. Then, as records are extracted from
136222 ** the sorter to return to the user, the required value of bigblob is
136223 ** retrieved directly from table t1. If the values are very large, this
136224 ** can be more efficient than storing them directly in the sorter records.
136225 **
136226 ** The ExprList_item.bSorterRef flag is set for each expression in pEList
136227 ** for which the sorter-reference optimization should be enabled.
136228 ** Additionally, the pSort->aDefer[] array is populated with entries
136229 ** for all cursors required to evaluate all selected expressions. Finally.
136230 ** output variable (*ppExtra) is set to an expression list containing
136231 ** expressions for all extra PK values that should be stored in the
@@ -136281,11 +136529,11 @@
136281 pSort->aDefer[nDefer].iCsr = pExpr->iTable;
136282 pSort->aDefer[nDefer].nKey = nKey;
136283 nDefer++;
136284 }
136285 }
136286 pItem->bSorterRef = 1;
136287 }
136288 }
136289 }
136290 pSort->nDefer = (u8)nDefer;
136291 *ppExtra = pExtra;
@@ -136412,11 +136660,11 @@
136412 ** from the sorter by the optimizations in this branch */
136413 pEList = p->pEList;
136414 for(i=0; i<pEList->nExpr; i++){
136415 if( pEList->a[i].u.x.iOrderByCol>0
136416 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
136417 || pEList->a[i].bSorterRef
136418 #endif
136419 ){
136420 nResultCol--;
136421 regOrig = 0;
136422 }
@@ -136774,11 +137022,11 @@
136774 pInfo = sqlite3KeyInfoAlloc(db, nExpr-iStart, nExtra+1);
136775 if( pInfo ){
136776 assert( sqlite3KeyInfoIsWriteable(pInfo) );
136777 for(i=iStart, pItem=pList->a+iStart; i<nExpr; i++, pItem++){
136778 pInfo->aColl[i-iStart] = sqlite3ExprNNCollSeq(pParse, pItem->pExpr);
136779 pInfo->aSortFlags[i-iStart] = pItem->sortFlags;
136780 }
136781 }
136782 return pInfo;
136783 }
136784
@@ -136913,11 +137161,11 @@
136913 iSortTab = iTab;
136914 bSeq = 1;
136915 }
136916 for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){
136917 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
136918 if( aOutEx[i].bSorterRef ) continue;
136919 #endif
136920 if( aOutEx[i].u.x.iOrderByCol==0 ) iCol++;
136921 }
136922 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
136923 if( pSort->nDefer ){
@@ -136950,11 +137198,11 @@
136950 sqlite3ReleaseTempRange(pParse, regKey, nRefKey);
136951 }
136952 #endif
136953 for(i=nColumn-1; i>=0; i--){
136954 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
136955 if( aOutEx[i].bSorterRef ){
136956 sqlite3ExprCode(pParse, aOutEx[i].pExpr, regRow+i);
136957 }else
136958 #endif
136959 {
136960 int iRead;
@@ -137316,11 +137564,11 @@
137316
137317 assert( p!=0 );
137318 assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */
137319 assert( p->op!=TK_COLUMN
137320 || (ExprUseYTab(p) && p->y.pTab!=0) ); /* Covering idx not yet coded */
137321 if( pEList->a[i].zEName && pEList->a[i].eEName==ENAME_NAME ){
137322 /* An AS clause always takes first priority */
137323 char *zName = pEList->a[i].zEName;
137324 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
137325 }else if( srcName && p->op==TK_COLUMN ){
137326 char *zCol;
@@ -137402,26 +137650,28 @@
137402 *pnCol = nCol;
137403 *paCol = aCol;
137404
137405 for(i=0, pCol=aCol; i<nCol && !db->mallocFailed; i++, pCol++){
137406 struct ExprList_item *pX = &pEList->a[i];
 
137407 /* Get an appropriate name for the column
137408 */
137409 if( (zName = pX->zEName)!=0 && pX->eEName==ENAME_NAME ){
137410 /* If the column contains an "AS <name>" phrase, use <name> as the name */
137411 }else{
137412 Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pX->pExpr);
137413 while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){
137414 pColExpr = pColExpr->pRight;
137415 assert( pColExpr!=0 );
137416 }
137417 if( pColExpr->op==TK_COLUMN
137418 && ALWAYS( ExprUseYTab(pColExpr) )
137419 && (pTab = pColExpr->y.pTab)!=0
137420 ){
137421 /* For columns use the column name name */
137422 int iCol = pColExpr->iColumn;
 
137423 if( iCol<0 ) iCol = pTab->iPKey;
137424 zName = iCol>=0 ? pTab->aCol[iCol].zCnName : "rowid";
137425 }else if( pColExpr->op==TK_ID ){
137426 assert( !ExprHasProperty(pColExpr, EP_IntValue) );
137427 zName = pColExpr->u.zToken;
@@ -137438,11 +137688,14 @@
137438
137439 /* Make sure the column name is unique. If the name is not unique,
137440 ** append an integer to the name so that it becomes unique.
137441 */
137442 cnt = 0;
137443 while( zName && sqlite3HashFind(&ht, zName)!=0 ){
 
 
 
137444 nName = sqlite3Strlen30(zName);
137445 if( nName>0 ){
137446 for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){}
137447 if( zName[j]==':' ) nName = j;
137448 }
@@ -137449,12 +137702,15 @@
137449 zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt);
137450 if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt);
137451 }
137452 pCol->zCnName = zName;
137453 pCol->hName = sqlite3StrIHash(zName);
 
 
 
137454 sqlite3ColumnPropertiesFromName(0, pCol);
137455 if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){
137456 sqlite3OomFault(db);
137457 }
137458 }
137459 sqlite3HashClear(&ht);
137460 if( db->mallocFailed ){
@@ -137707,11 +137963,11 @@
137707 pOrderBy->a[i].pExpr =
137708 sqlite3ExprAddCollateString(pParse, pTerm, pColl->zName);
137709 }
137710 assert( sqlite3KeyInfoIsWriteable(pRet) );
137711 pRet->aColl[i] = pColl;
137712 pRet->aSortFlags[i] = pOrderBy->a[i].sortFlags;
137713 }
137714 }
137715
137716 return pRet;
137717 }
@@ -138977,11 +139233,11 @@
138977 static Expr *substExpr(
138978 SubstContext *pSubst, /* Description of the substitution */
138979 Expr *pExpr /* Expr in which substitution occurs */
138980 ){
138981 if( pExpr==0 ) return 0;
138982 if( ExprHasProperty(pExpr, EP_FromJoin)
138983 && pExpr->w.iJoin==pSubst->iTable
138984 ){
138985 pExpr->w.iJoin = pSubst->iNewTable;
138986 }
138987 if( pExpr->op==TK_COLUMN
@@ -139018,16 +139274,21 @@
139018 return pExpr;
139019 }
139020 if( pSubst->isOuterJoin ){
139021 ExprSetProperty(pNew, EP_CanBeNull);
139022 }
139023 if( ExprHasProperty(pExpr,EP_FromJoin|EP_InnerJoin) ){
139024 sqlite3SetJoinExpr(pNew, pExpr->w.iJoin,
139025 pExpr->flags & (EP_FromJoin|EP_InnerJoin));
139026 }
139027 sqlite3ExprDelete(db, pExpr);
139028 pExpr = pNew;
 
 
 
 
 
139029
139030 /* Ensure that the expression now has an implicit collation sequence,
139031 ** just as it did when it was a column of a view or sub-query. */
139032 if( pExpr->op!=TK_COLUMN && pExpr->op!=TK_COLLATE ){
139033 CollSeq *pColl = sqlite3ExprCollSeq(pSubst->pParse, pExpr);
@@ -139184,11 +139445,11 @@
139184 static int renumberCursorsCb(Walker *pWalker, Expr *pExpr){
139185 int op = pExpr->op;
139186 if( op==TK_COLUMN || op==TK_IF_NULL_ROW ){
139187 renumberCursorDoMapping(pWalker, &pExpr->iTable);
139188 }
139189 if( ExprHasProperty(pExpr, EP_FromJoin) ){
139190 renumberCursorDoMapping(pWalker, &pExpr->w.iJoin);
139191 }
139192 return WRC_Continue;
139193 }
139194
@@ -139375,10 +139636,12 @@
139375 ** See also (3) for restrictions on LEFT JOIN.
139376 **
139377 ** (27) The subquery may not contain a FULL or RIGHT JOIN unless it
139378 ** is the first element of the parent query.
139379 **
 
 
139380 **
139381 ** In this routine, the "p" parameter is a pointer to the outer query.
139382 ** The subquery is p->pSrc->a[iFrom]. isAgg is true if the outer query
139383 ** uses aggregates.
139384 **
@@ -139498,10 +139761,13 @@
139498
139499 assert( pSubSrc->nSrc>0 ); /* True by restriction (7) */
139500 if( iFrom>0 && (pSubSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
139501 return 0; /* Restriction (27) */
139502 }
 
 
 
139503
139504 /* Restriction (17): If the sub-query is a compound SELECT, then it must
139505 ** use only the UNION ALL operator. And none of the simple select queries
139506 ** that make up the compound SELECT are allowed to be aggregate or distinct
139507 ** queries.
@@ -139542,10 +139808,11 @@
139542 /* Restriction (23) */
139543 if( (p->selFlags & SF_Recursive) ) return 0;
139544
139545 if( pSrc->nSrc>1 ){
139546 if( pParse->nSelect>500 ) return 0;
 
139547 aCsrMap = sqlite3DbMallocZero(db, ((i64)pParse->nTab+1)*sizeof(int));
139548 if( aCsrMap ) aCsrMap[0] = pParse->nTab;
139549 }
139550 }
139551
@@ -139756,11 +140023,11 @@
139756 pSub->pOrderBy = 0;
139757 }
139758 pWhere = pSub->pWhere;
139759 pSub->pWhere = 0;
139760 if( isOuterJoin>0 ){
139761 sqlite3SetJoinExpr(pWhere, iNewParent, EP_FromJoin);
139762 }
139763 if( pWhere ){
139764 if( pParent->pWhere ){
139765 pParent->pWhere = sqlite3PExpr(pParse, TK_AND, pWhere, pParent->pWhere);
139766 }else{
@@ -139889,11 +140156,11 @@
139889 ** found, add it to the pConst structure.
139890 */
139891 static void findConstInWhere(WhereConst *pConst, Expr *pExpr){
139892 Expr *pRight, *pLeft;
139893 if( NEVER(pExpr==0) ) return;
139894 if( ExprHasProperty(pExpr, EP_FromJoin) ) return;
139895 if( pExpr->op==TK_AND ){
139896 findConstInWhere(pConst, pExpr->pRight);
139897 findConstInWhere(pConst, pExpr->pLeft);
139898 return;
139899 }
@@ -139925,13 +140192,13 @@
139925 int bIgnoreAffBlob
139926 ){
139927 int i;
139928 if( pConst->pOomFault[0] ) return WRC_Prune;
139929 if( pExpr->op!=TK_COLUMN ) return WRC_Continue;
139930 if( ExprHasProperty(pExpr, EP_FixedCol|EP_FromJoin) ){
139931 testcase( ExprHasProperty(pExpr, EP_FixedCol) );
139932 testcase( ExprHasProperty(pExpr, EP_FromJoin) );
139933 return WRC_Continue;
139934 }
139935 for(i=0; i<pConst->nConst; i++){
139936 Expr *pColumn = pConst->apExpr[i*2];
139937 if( pColumn==pExpr ) continue;
@@ -140170,17 +140437,17 @@
140170 */
140171 static int pushDownWhereTerms(
140172 Parse *pParse, /* Parse context (for malloc() and error reporting) */
140173 Select *pSubq, /* The subquery whose WHERE clause is to be augmented */
140174 Expr *pWhere, /* The WHERE clause of the outer query */
140175 int iCursor, /* Cursor number of the subquery */
140176 int isLeftJoin /* True if pSubq is the right term of a LEFT JOIN */
140177 ){
140178 Expr *pNew;
140179 int nChng = 0;
140180 if( pWhere==0 ) return 0;
140181 if( pSubq->selFlags & (SF_Recursive|SF_MultiPart) ) return 0;
 
140182
140183 #ifndef SQLITE_OMIT_WINDOWFUNC
140184 if( pSubq->pPrior ){
140185 Select *pSel;
140186 for(pSel=pSubq; pSel; pSel=pSel->pPrior){
@@ -140206,35 +140473,38 @@
140206
140207 if( pSubq->pLimit!=0 ){
140208 return 0; /* restriction (3) */
140209 }
140210 while( pWhere->op==TK_AND ){
140211 nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight,
140212 iCursor, isLeftJoin);
140213 pWhere = pWhere->pLeft;
140214 }
 
 
140215 if( isLeftJoin
140216 && (ExprHasProperty(pWhere,EP_FromJoin)==0
140217 || pWhere->w.iJoin!=iCursor)
140218 ){
140219 return 0; /* restriction (4) */
140220 }
140221 if( ExprHasProperty(pWhere,EP_FromJoin)
140222 && pWhere->w.iJoin!=iCursor
140223 ){
140224 return 0; /* restriction (5) */
140225 }
140226 if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
 
 
140227 nChng++;
140228 pSubq->selFlags |= SF_PushDown;
140229 while( pSubq ){
140230 SubstContext x;
140231 pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
140232 unsetJoinExpr(pNew, -1);
140233 x.pParse = pParse;
140234 x.iTable = iCursor;
140235 x.iNewTable = iCursor;
140236 x.isOuterJoin = 0;
140237 x.pEList = pSubq->pEList;
140238 pNew = substExpr(&x, pNew);
140239 #ifndef SQLITE_OMIT_WINDOWFUNC
140240 if( pSubq->pWin && 0==pushDownWindowCheck(pParse, pSubq, pNew) ){
@@ -140304,11 +140574,11 @@
140304 }else{
140305 return eRet;
140306 }
140307 *ppMinMax = pOrderBy = sqlite3ExprListDup(db, pEList, 0);
140308 assert( pOrderBy!=0 || db->mallocFailed );
140309 if( pOrderBy ) pOrderBy->a[0].sortFlags = sortFlags;
140310 return eRet;
140311 }
140312
140313 /*
140314 ** The select statement passed as the first argument is an aggregate query.
@@ -140773,11 +141043,11 @@
140773 if( pTab==0 ) return SQLITE_NOMEM;
140774 pTab->nTabRef = 1;
140775 if( pFrom->zAlias ){
140776 pTab->zName = sqlite3DbStrDup(pParse->db, pFrom->zAlias);
140777 }else{
140778 pTab->zName = sqlite3MPrintf(pParse->db, "subquery_%u", pSel->selId);
140779 }
140780 while( pSel->pPrior ){ pSel = pSel->pPrior; }
140781 sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol);
140782 pTab->iPKey = -1;
140783 pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
@@ -141011,11 +141281,11 @@
141011 /* This particular expression does not need to be expanded.
141012 */
141013 pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr);
141014 if( pNew ){
141015 pNew->a[pNew->nExpr-1].zEName = a[k].zEName;
141016 pNew->a[pNew->nExpr-1].eEName = a[k].eEName;
141017 a[k].zEName = 0;
141018 }
141019 a[k].pExpr = 0;
141020 }else{
141021 /* This expression is a "*" or a "TABLE.*" and needs to be
@@ -141026,39 +141296,64 @@
141026 assert( pE->pLeft!=0 );
141027 assert( !ExprHasProperty(pE->pLeft, EP_IntValue) );
141028 zTName = pE->pLeft->u.zToken;
141029 }
141030 for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
141031 Table *pTab = pFrom->pTab;
141032 Select *pSub;
141033 char *zTabName = pFrom->zAlias;
141034 const char *zSchemaName = 0;
141035 int iDb;
141036 if( zTabName==0 ){
 
 
141037 zTabName = pTab->zName;
141038 }
141039 if( db->mallocFailed ) break;
141040 assert( pFrom->fg.isNestedFrom == IsNestedFrom(pFrom->pSelect) );
141041 if( pFrom->fg.isNestedFrom ){
141042 pSub = pFrom->pSelect;
141043 assert( pSub->pEList!=0 );
141044 assert( pSub->pEList->nExpr==pTab->nCol );
 
141045 }else{
141046 pSub = 0;
141047 if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
141048 continue;
141049 }
 
141050 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
141051 zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141052 }
141053 for(j=0; j<pTab->nCol; j++){
141054 char *zName = pTab->aCol[j].zCnName;
141055 struct ExprList_item *pX; /* Newly added ExprList term */
141056
141057 assert( zName );
141058 if( zTName && pSub
141059 && sqlite3MatchEName(&pSub->pEList->a[j], 0, zTName, 0)==0
 
141060 ){
141061 continue;
141062 }
141063
141064 /* If a column is marked as 'hidden', omit it from the expanded
@@ -141067,14 +141362,20 @@
141067 */
141068 if( (p->selFlags & SF_IncludeHidden)==0
141069 && IsHiddenColumn(&pTab->aCol[j])
141070 ){
141071 continue;
 
 
 
 
 
 
141072 }
141073 tableSeen = 1;
141074
141075 if( i>0 && zTName==0 ){
141076 if( pFrom->fg.isUsing
141077 && sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0
141078 ){
141079 /* In a join with a USING clause, omit columns in the
141080 ** using clause from the table on the right. */
@@ -141082,10 +141383,11 @@
141082 }
141083 }
141084 pRight = sqlite3Expr(db, TK_ID, zName);
141085 if( (pTabList->nSrc>1
141086 && ( (pFrom->fg.jointype & JT_LTORJ)==0
 
141087 || !inAnyUsingClause(zName,pFrom,pTabList->nSrc-i-1)
141088 )
141089 )
141090 || IN_RENAME_OBJECT
141091 ){
@@ -141107,25 +141409,32 @@
141107 break; /* OOM */
141108 }
141109 pX = &pNew->a[pNew->nExpr-1];
141110 assert( pX->zEName==0 );
141111 if( (selFlags & SF_NestedFrom)!=0 && !IN_RENAME_OBJECT ){
141112 if( pSub ){
141113 pX->zEName = sqlite3DbStrDup(db, pSub->pEList->a[j].zEName);
141114 testcase( pX->zEName==0 );
141115 }else{
141116 pX->zEName = sqlite3MPrintf(db, "%s.%s.%s",
141117 zSchemaName, zTabName, zName);
141118 testcase( pX->zEName==0 );
141119 }
141120 pX->eEName = ENAME_TAB;
 
 
 
 
 
 
 
141121 }else if( longNames ){
141122 pX->zEName = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
141123 pX->eEName = ENAME_NAME;
141124 }else{
141125 pX->zEName = sqlite3DbStrDup(db, zName);
141126 pX->eEName = ENAME_NAME;
141127 }
141128 }
141129 }
141130 if( !tableSeen ){
141131 if( zTName ){
@@ -141684,10 +141993,33 @@
141684 }
141685 #endif
141686 return 1;
141687 }
141688 #endif /* SQLITE_COUNTOFVIEW_OPTIMIZATION */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141689
141690 /*
141691 ** Generate code for the SELECT statement given in the p argument.
141692 **
141693 ** The results are returned according to the SelectDest structure.
@@ -141789,19 +142121,16 @@
141789 ** systems handle this case differently, and not all the same way,
141790 ** which is just confusing. To avoid this, we follow PG's lead and
141791 ** disallow it altogether. */
141792 if( p->selFlags & SF_UFSrcCheck ){
141793 SrcItem *p0 = &p->pSrc->a[0];
141794 for(i=1; i<p->pSrc->nSrc; i++){
141795 SrcItem *p1 = &p->pSrc->a[i];
141796 if( p0->pTab==p1->pTab && 0==sqlite3_stricmp(p0->zAlias, p1->zAlias) ){
141797 sqlite3ErrorMsg(pParse,
141798 "target object/alias may not appear in FROM clause: %s",
141799 p0->zAlias ? p0->zAlias : p0->pTab->zName
141800 );
141801 goto select_end;
141802 }
141803 }
141804
141805 /* Clear the SF_UFSrcCheck flag. The check has already been performed,
141806 ** and leaving this flag set can cause errors if a compound sub-query
141807 ** in p->pSrc is flattened into this query and this function called
@@ -142053,13 +142382,11 @@
142053 ** inside the subquery. This can help the subquery to run more efficiently.
142054 */
142055 if( OptimizationEnabled(db, SQLITE_PushDown)
142056 && (pItem->fg.isCte==0
142057 || (pItem->u2.pCteUse->eM10d!=M10d_Yes && pItem->u2.pCteUse->nUse<2))
142058 && (pItem->fg.jointype & JT_RIGHT)==0
142059 && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem->iCursor,
142060 (pItem->fg.jointype & JT_OUTER)!=0)
142061 ){
142062 #if TREETRACE_ENABLED
142063 if( sqlite3TreeTrace & 0x100 ){
142064 SELECTTRACE(0x100,pParse,p,
142065 ("After WHERE-clause push-down into subquery %d:\n", pSub->selId));
@@ -142074,11 +142401,11 @@
142074 zSavedAuthContext = pParse->zAuthContext;
142075 pParse->zAuthContext = pItem->zName;
142076
142077 /* Generate code to implement the subquery
142078 **
142079 ** The subquery is implemented as a co-routine all of the following are
142080 ** true:
142081 **
142082 ** (1) the subquery is guaranteed to be the outer loop (so that
142083 ** it does not need to be computed more than once), and
142084 ** (2) the subquery is not a CTE that should be materialized
@@ -142132,15 +142459,15 @@
142132 /* Materialize the view. If the view is not correlated, generate a
142133 ** subroutine to do the materialization so that subsequent uses of
142134 ** the same view can reuse the materialization. */
142135 int topAddr;
142136 int onceAddr = 0;
142137 int retAddr;
142138
142139 pItem->regReturn = ++pParse->nMem;
142140 topAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pItem->regReturn);
142141 pItem->addrFillSub = topAddr+1;
 
142142 if( pItem->fg.isCorrelated==0 ){
142143 /* If the subquery is not correlated and if we are not inside of
142144 ** a trigger, then we only need to compute the value of the subquery
142145 ** once. */
142146 onceAddr = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
@@ -142151,13 +142478,13 @@
142151 sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
142152 ExplainQueryPlan((pParse, 1, "MATERIALIZE %!S", pItem));
142153 sqlite3Select(pParse, pSub, &dest);
142154 pItem->pTab->nRowLogEst = pSub->nSelectRow;
142155 if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr);
142156 retAddr = sqlite3VdbeAddOp1(v, OP_Return, pItem->regReturn);
142157 VdbeComment((v, "end %!S", pItem));
142158 sqlite3VdbeChangeP1(v, topAddr, retAddr);
142159 sqlite3ClearTempRegCache(pParse);
142160 if( pItem->fg.isCte && pItem->fg.isCorrelated==0 ){
142161 CteUse *pCteUse = pItem->u2.pCteUse;
142162 pCteUse->addrM9e = pItem->addrFillSub;
142163 pCteUse->regRtn = pItem->regReturn;
@@ -142251,17 +142578,17 @@
142251 if( pDest->eDest==SRT_EphemTab ){
142252 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pDest->iSDParm, pEList->nExpr);
142253 if( p->selFlags & SF_NestedFrom ){
142254 /* Delete or NULL-out result columns that will never be used */
142255 int ii;
142256 for(ii=pEList->nExpr-1; ii>0 && pEList->a[ii].bUsed==0; ii--){
142257 sqlite3ExprDelete(db, pEList->a[ii].pExpr);
142258 sqlite3DbFree(db, pEList->a[ii].zEName);
142259 pEList->nExpr--;
142260 }
142261 for(ii=0; ii<pEList->nExpr; ii++){
142262 if( pEList->a[ii].bUsed==0 ) pEList->a[ii].pExpr->op = TK_NULL;
142263 }
142264 }
142265 }
142266
142267 /* Set the limiter.
@@ -142409,12 +142736,13 @@
142409 ** ASC or DESC order - only that each group is returned contiguously.
142410 ** So set the ASC/DESC flags in the GROUP BY to match those in the
142411 ** ORDER BY to maximize the chances of rows being delivered in an
142412 ** order that makes the ORDER BY redundant. */
142413 for(ii=0; ii<pGroupBy->nExpr; ii++){
142414 u8 sortFlags = sSort.pOrderBy->a[ii].sortFlags & KEYINFO_ORDER_DESC;
142415 pGroupBy->a[ii].sortFlags = sortFlags;
 
142416 }
142417 if( sqlite3ExprListCompare(pGroupBy, sSort.pOrderBy, -1)==0 ){
142418 orderByGrp = 1;
142419 }
142420 }
@@ -142875,11 +143203,11 @@
142875 }
142876 SELECTTRACE(1,pParse,p,("WhereBegin returns\n"));
142877 eDist = sqlite3WhereIsDistinct(pWInfo);
142878 updateAccumulator(pParse, regAcc, pAggInfo, eDist);
142879 if( eDist!=WHERE_DISTINCT_NOOP ){
142880 struct AggInfo_func *pF = &pAggInfo->aFunc[0];
142881 if( pF ){
142882 fixDistinctOpenEph(pParse, eDist, pF->iDistinct, pF->iDistAddr);
142883 }
142884 }
142885
@@ -143674,11 +144002,11 @@
143674 ** sees an UPDATE statement inside the body of a CREATE TRIGGER.
143675 */
143676 SQLITE_PRIVATE TriggerStep *sqlite3TriggerUpdateStep(
143677 Parse *pParse, /* Parser */
143678 Token *pTableName, /* Name of the table to be updated */
143679 SrcList *pFrom,
143680 ExprList *pEList, /* The SET clause: list of column and new values */
143681 Expr *pWhere, /* The WHERE clause */
143682 u8 orconf, /* The conflict algorithm. (OE_Abort, OE_Ignore, etc) */
143683 const char *zStart, /* Start of SQL text */
143684 const char *zEnd /* End of SQL text */
@@ -144010,10 +144338,18 @@
144010 if( pSchema!=db->aDb[1].pSchema ){
144011 pSrc->a[0].pSchema = pSchema;
144012 }
144013 if( pStep->pFrom ){
144014 SrcList *pDup = sqlite3SrcListDup(db, pStep->pFrom, 0);
 
 
 
 
 
 
 
 
144015 pSrc = sqlite3SrcListAppendList(pParse, pSrc, pDup);
144016 }
144017 }else{
144018 sqlite3DbFree(db, zName);
144019 }
@@ -144065,20 +144401,20 @@
144065 pNewExpr = sqlite3Expr(db, TK_ID, pTab->aCol[jj].zCnName);
144066 pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
144067 if( !db->mallocFailed ){
144068 struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
144069 pItem->zEName = sqlite3DbStrDup(db, pTab->aCol[jj].zCnName);
144070 pItem->eEName = ENAME_NAME;
144071 }
144072 }
144073 }else{
144074 Expr *pNewExpr = sqlite3ExprDup(db, pOldExpr, 0);
144075 pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
144076 if( !db->mallocFailed && ALWAYS(pList->a[i].zEName!=0) ){
144077 struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
144078 pItem->zEName = sqlite3DbStrDup(db, pList->a[i].zEName);
144079 pItem->eEName = pList->a[i].eEName;
144080 }
144081 }
144082 }
144083 return pNew;
144084 }
@@ -146647,10 +146983,11 @@
146647 #endif
146648 }
146649
146650 assert( rc==SQLITE_OK );
146651 if( pOut==0 ){
 
146652 rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1);
146653 }
146654
146655 end_of_vacuum:
146656 /* Restore the original value of db->flags */
@@ -148098,11 +148435,11 @@
148098 ** This object is a header on a block of allocated memory that will be
148099 ** automatically freed when its WInfo oject is destructed.
148100 */
148101 struct WhereMemBlock {
148102 WhereMemBlock *pNext; /* Next block in the chain */
148103 u8 sz; /* Bytes of space */
148104 };
148105
148106 /*
148107 ** Extra information attached to a WhereLevel that is a RIGHT JOIN.
148108 */
@@ -148109,10 +148446,11 @@
148109 struct WhereRightJoin {
148110 int iMatch; /* Cursor used to determine prior matched rows */
148111 int regBloom; /* Bloom filter for iRJMatch */
148112 int regReturn; /* Return register for the interior subroutine */
148113 int addrSubrtn; /* Starting address for the interior subroutine */
 
148114 };
148115
148116 /*
148117 ** This object contains information needed to implement a single nested
148118 ** loop in WHERE clause.
@@ -148668,12 +149006,13 @@
148668 #define WO_ISNULL 0x0100
148669 #define WO_OR 0x0200 /* Two or more OR-connected terms */
148670 #define WO_AND 0x0400 /* Two or more AND-connected terms */
148671 #define WO_EQUIV 0x0800 /* Of the form A==B, both columns */
148672 #define WO_NOOP 0x1000 /* This term does not restrict search space */
 
148673
148674 #define WO_ALL 0x1fff /* Mask of all possible WO_* values */
148675 #define WO_SINGLE 0x01ff /* Mask of all non-compound WO_* values */
148676
148677 /*
148678 ** These are definitions of bits in the WhereLoop.wsFlags field.
148679 ** The particular combination of bits in each WhereLoop help to
@@ -149039,11 +149378,11 @@
149039 */
149040 static void disableTerm(WhereLevel *pLevel, WhereTerm *pTerm){
149041 int nLoop = 0;
149042 assert( pTerm!=0 );
149043 while( (pTerm->wtFlags & TERM_CODED)==0
149044 && (pLevel->iLeftJoin==0 || ExprHasProperty(pTerm->pExpr, EP_FromJoin))
149045 && (pLevel->notReady & pTerm->prereqAll)==0
149046 ){
149047 if( nLoop && (pTerm->wtFlags & TERM_LIKE)!=0 ){
149048 pTerm->wtFlags |= TERM_LIKECOND;
149049 }else{
@@ -149300,20 +149639,25 @@
149300
149301 iTab = 0;
149302 if( !ExprUseXSelect(pX) || pX->x.pSelect->pEList->nExpr==1 ){
149303 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
149304 }else{
149305 sqlite3 *db = pParse->db;
149306 pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
149307
149308 if( !db->mallocFailed ){
 
 
 
 
 
 
 
149309 aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq);
149310 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap, &iTab);
149311 pTerm->pExpr->iTable = iTab;
149312 }
149313 sqlite3ExprDelete(db, pX);
149314 pX = pTerm->pExpr;
149315 }
149316
149317 if( eType==IN_INDEX_INDEX_DESC ){
149318 testcase( bRev );
149319 bRev = !bRev;
@@ -149755,20 +150099,20 @@
149755 **
149756 ** are also excluded. See codeCursorHintIsOrFunction() for details.
149757 */
149758 if( pTabItem->fg.jointype & JT_LEFT ){
149759 Expr *pExpr = pTerm->pExpr;
149760 if( !ExprHasProperty(pExpr, EP_FromJoin)
149761 || pExpr->w.iJoin!=pTabItem->iCursor
149762 ){
149763 sWalker.eCode = 0;
149764 sWalker.xExprCallback = codeCursorHintIsOrFunction;
149765 sqlite3WalkExpr(&sWalker, pTerm->pExpr);
149766 if( sWalker.eCode ) continue;
149767 }
149768 }else{
149769 if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) continue;
149770 }
149771
149772 /* All terms in pWLoop->aLTerm[] except pEndRange are used to initialize
149773 ** the cursor. These terms are not needed as hints for a pure range
149774 ** scan (that has no == terms) so omit them. */
@@ -149936,16 +150280,16 @@
149936 ** that contains the value of pExpr.
149937 */
149938 static int whereIndexExprTransNode(Walker *p, Expr *pExpr){
149939 IdxExprTrans *pX = p->u.pIdxTrans;
149940 if( sqlite3ExprCompare(0, pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){
 
149941 preserveExpr(pX, pExpr);
149942 pExpr->affExpr = sqlite3ExprAffinity(pExpr);
149943 pExpr->op = TK_COLUMN;
149944 pExpr->iTable = pX->iIdxCur;
149945 pExpr->iColumn = pX->iIdxCol;
149946 testcase( ExprHasProperty(pExpr, EP_Skip) );
149947 testcase( ExprHasProperty(pExpr, EP_Unlikely) );
149948 ExprClearProperty(pExpr, EP_Skip|EP_Unlikely|EP_WinFunc|EP_Subrtn);
149949 pExpr->y.pTab = 0;
149950 return WRC_Prune;
149951 }else{
@@ -150095,10 +150439,12 @@
150095 if( pLevel->regFilter==0 ) continue;
150096 if( pLevel->pWLoop->nSkip ) continue;
150097 /* ,--- Because sqlite3ConstructBloomFilter() has will not have set
150098 ** vvvvv--' pLevel->regFilter if this were true. */
150099 if( NEVER(pLoop->prereq & notReady) ) continue;
 
 
150100 if( pLoop->wsFlags & WHERE_IPK ){
150101 WhereTerm *pTerm = pLoop->aLTerm[0];
150102 int regRowid;
150103 assert( pTerm!=0 );
150104 assert( pTerm->pExpr!=0 );
@@ -150121,10 +150467,11 @@
150121 sqlite3VdbeAddOp4Int(pParse->pVdbe, OP_Filter, pLevel->regFilter,
150122 addrNxt, r1, nEq);
150123 VdbeCoverage(pParse->pVdbe);
150124 }
150125 pLevel->regFilter = 0;
 
150126 }
150127 }
150128
150129 /*
150130 ** Generate code for the start of the iLevel-th loop in the WHERE clause
@@ -151092,11 +151439,11 @@
151092 WhereInfo *pSubWInfo; /* Info for single OR-term scan */
151093 Expr *pOrExpr = pOrTerm->pExpr; /* Current OR clause term */
151094 Expr *pDelete; /* Local copy of OR clause term */
151095 int jmp1 = 0; /* Address of jump operation */
151096 testcase( (pTabItem[0].fg.jointype & JT_LEFT)!=0
151097 && !ExprHasProperty(pOrExpr, EP_FromJoin)
151098 ); /* See TH3 vtab25.400 and ticket 614b25314c766238 */
151099 pDelete = pOrExpr = sqlite3ExprDup(db, pOrExpr, 0);
151100 if( db->mallocFailed ){
151101 sqlite3ExprDelete(db, pDelete);
151102 continue;
@@ -151300,16 +151647,26 @@
151300 pWInfo->untestedTerms = 1;
151301 continue;
151302 }
151303 pE = pTerm->pExpr;
151304 assert( pE!=0 );
151305 if( (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ))
151306 && !ExprHasProperty(pE,EP_FromJoin)
151307 ){
151308 continue;
 
 
 
 
 
 
 
 
 
 
 
151309 }
151310
151311 if( iLoop==1 && !sqlite3ExprCoveredByIndex(pE, pLevel->iTabCur, pIdx) ){
151312 iNext = 2;
151313 continue;
151314 }
151315 if( iLoop<3 && (pTerm->wtFlags & TERM_VARSELECT) ){
@@ -151364,19 +151721,19 @@
151364 WhereTerm *pAlt;
151365 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
151366 if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) continue;
151367 if( (pTerm->eOperator & WO_EQUIV)==0 ) continue;
151368 if( pTerm->leftCursor!=iCur ) continue;
151369 if( pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ) ) continue;
151370 pE = pTerm->pExpr;
151371 #ifdef WHERETRACE_ENABLED /* 0x800 */
151372 if( sqlite3WhereTrace & 0x800 ){
151373 sqlite3DebugPrintf("Coding transitive constraint:\n");
151374 sqlite3WhereTermPrint(pTerm, pWC->nTerm-j);
151375 }
151376 #endif
151377 assert( !ExprHasProperty(pE, EP_FromJoin) );
151378 assert( (pTerm->prereqRight & pLevel->notReady)!=0 );
151379 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
151380 pAlt = sqlite3WhereFindTerm(pWC, iCur, pTerm->u.x.leftColumn, notReady,
151381 WO_EQ|WO_IN|WO_IS, 0);
151382 if( pAlt==0 ) continue;
@@ -151443,22 +151800,12 @@
151443 */
151444 if( pLevel->iLeftJoin ){
151445 pLevel->addrFirst = sqlite3VdbeCurrentAddr(v);
151446 sqlite3VdbeAddOp2(v, OP_Integer, 1, pLevel->iLeftJoin);
151447 VdbeComment((v, "record LEFT JOIN hit"));
151448 for(pTerm=pWC->a, j=0; j<pWC->nBase; j++, pTerm++){
151449 testcase( pTerm->wtFlags & TERM_VIRTUAL );
151450 testcase( pTerm->wtFlags & TERM_CODED );
151451 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
151452 if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
151453 assert( pWInfo->untestedTerms );
151454 continue;
151455 }
151456 if( pTabItem->fg.jointype & JT_LTORJ ) continue;
151457 assert( pTerm->pExpr );
151458 sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
151459 pTerm->wtFlags |= TERM_CODED;
151460 }
151461 }
151462
151463 if( pLevel->pRJ ){
151464 /* Create a subroutine used to process all interior loops and code
@@ -151470,10 +151817,30 @@
151470 WhereRightJoin *pRJ = pLevel->pRJ;
151471 sqlite3VdbeAddOp2(v, OP_BeginSubrtn, 0, pRJ->regReturn);
151472 pRJ->addrSubrtn = sqlite3VdbeCurrentAddr(v);
151473 assert( pParse->withinRJSubrtn < 255 );
151474 pParse->withinRJSubrtn++;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151475 }
151476
151477 #if WHERETRACE_ENABLED /* 0x20800 */
151478 if( sqlite3WhereTrace & 0x20000 ){
151479 sqlite3DebugPrintf("All WHERE-clause terms after coding level %d:\n",
@@ -151508,10 +151875,12 @@
151508 SrcList sFrom;
151509 Bitmask mAll = 0;
151510 int k;
151511
151512 ExplainQueryPlan((pParse, 1, "RIGHT-JOIN %s", pTabItem->pTab->zName));
 
 
151513 for(k=0; k<iLevel; k++){
151514 int iIdxCur;
151515 mAll |= pWInfo->a[k].pWLoop->maskSelf;
151516 sqlite3VdbeAddOp1(v, OP_NullRow, pWInfo->a[k].iTabCur);
151517 iIdxCur = pWInfo->a[k].iIdxCur;
@@ -151521,13 +151890,17 @@
151521 }
151522 if( (pTabItem->fg.jointype & JT_LTORJ)==0 ){
151523 mAll |= pLoop->maskSelf;
151524 for(k=0; k<pWC->nTerm; k++){
151525 WhereTerm *pTerm = &pWC->a[k];
151526 if( pTerm->wtFlags & TERM_VIRTUAL ) break;
 
 
 
 
151527 if( pTerm->prereqAll & ~mAll ) continue;
151528 if( ExprHasProperty(pTerm->pExpr, EP_FromJoin|EP_InnerJoin) ) continue;
151529 pSubWhere = sqlite3ExprAnd(pParse, pSubWhere,
151530 sqlite3ExprDup(pParse->db, pTerm->pExpr, 0));
151531 }
151532 }
151533 sFrom.nSrc = 1;
@@ -152035,12 +152408,12 @@
152035 /*
152036 ** If the pBase expression originated in the ON or USING clause of
152037 ** a join, then transfer the appropriate markings over to derived.
152038 */
152039 static void transferJoinMarkings(Expr *pDerived, Expr *pBase){
152040 if( pDerived ){
152041 pDerived->flags |= pBase->flags & EP_FromJoin;
152042 pDerived->w.iJoin = pBase->w.iJoin;
152043 }
152044 }
152045
152046 /*
@@ -152491,11 +152864,11 @@
152491 static int termIsEquivalence(Parse *pParse, Expr *pExpr){
152492 char aff1, aff2;
152493 CollSeq *pColl;
152494 if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0;
152495 if( pExpr->op!=TK_EQ && pExpr->op!=TK_IS ) return 0;
152496 if( ExprHasProperty(pExpr, EP_FromJoin) ) return 0;
152497 aff1 = sqlite3ExprAffinity(pExpr->pLeft);
152498 aff2 = sqlite3ExprAffinity(pExpr->pRight);
152499 if( aff1!=aff2
152500 && (!sqlite3IsNumericAffinity(aff1) || !sqlite3IsNumericAffinity(aff2))
152501 ){
@@ -152679,22 +153052,30 @@
152679
152680 #ifdef SQLITE_DEBUG
152681 if( prereqAll!=sqlite3WhereExprUsageNN(pMaskSet, pExpr) ){
152682 printf("\n*** Incorrect prereqAll computed for:\n");
152683 sqlite3TreeViewExpr(0,pExpr,0);
152684 abort();
152685 }
152686 #endif
152687
152688 if( ExprHasProperty(pExpr, EP_FromJoin) ){
152689 Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->w.iJoin);
152690 prereqAll |= x;
152691 extraRight = x-1; /* ON clause terms may not be used with an index
152692 ** on left table of a LEFT JOIN. Ticket #3015 */
152693 if( (prereqAll>>1)>=x ){
152694 sqlite3ErrorMsg(pParse, "ON clause references tables to its right");
152695 return;
 
 
 
 
 
 
 
 
152696 }
152697 }
152698 pTerm->prereqAll = prereqAll;
152699 pTerm->leftCursor = -1;
152700 pTerm->iParent = -1;
@@ -152758,11 +153139,11 @@
152758 pNew->prereqRight = prereqLeft | extraRight;
152759 pNew->prereqAll = prereqAll;
152760 pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
152761 }else
152762 if( op==TK_ISNULL
152763 && !ExprHasProperty(pExpr,EP_FromJoin)
152764 && 0==sqlite3ExprCanBeNull(pLeft)
152765 ){
152766 assert( !ExprHasProperty(pExpr, EP_IntValue) );
152767 pExpr->op = TK_TRUEFALSE;
152768 pExpr->u.zToken = "false";
@@ -152829,11 +153210,11 @@
152829 ** The virtual term must be tagged with TERM_VNULL.
152830 */
152831 else if( pExpr->op==TK_NOTNULL ){
152832 if( pExpr->pLeft->op==TK_COLUMN
152833 && pExpr->pLeft->iColumn>=0
152834 && !ExprHasProperty(pExpr, EP_FromJoin)
152835 ){
152836 Expr *pNewExpr;
152837 Expr *pLeft = pExpr->pLeft;
152838 int idxNew;
152839 WhereTerm *pNewTerm;
@@ -152977,11 +153358,11 @@
152977 idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC|TERM_SLICE);
152978 exprAnalyze(pSrc, pWC, idxNew);
152979 }
152980 pTerm = &pWC->a[idxTerm];
152981 pTerm->wtFlags |= TERM_CODED|TERM_VIRTUAL; /* Disable the original */
152982 pTerm->eOperator = 0;
152983 }
152984
152985 /* If there is a vector IN term - e.g. "(a, b) IN (SELECT ...)" - create
152986 ** a virtual term for each vector component. The expression object
152987 ** used by each such virtual term is pExpr (the full vector IN(...)
@@ -153033,12 +153414,12 @@
153033 prereqColumn = sqlite3WhereExprUsage(pMaskSet, pLeft);
153034 if( (prereqExpr & prereqColumn)==0 ){
153035 Expr *pNewExpr;
153036 pNewExpr = sqlite3PExpr(pParse, TK_MATCH,
153037 0, sqlite3ExprDup(db, pRight, 0));
153038 if( ExprHasProperty(pExpr, EP_FromJoin) && pNewExpr ){
153039 ExprSetProperty(pNewExpr, EP_FromJoin);
153040 pNewExpr->w.iJoin = pExpr->w.iJoin;
153041 }
153042 idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
153043 testcase( idxNew==0 );
153044 pNewTerm = &pWC->a[idxNew];
@@ -153178,11 +153559,11 @@
153178 for(ii=0; ii<pWC->nTerm; ii++){
153179 if( pWC->a[ii].wtFlags & TERM_CODED ){
153180 /* This term is a vector operation that has been decomposed into
153181 ** other, subsequent terms. It can be ignored. See tag-20220128a */
153182 assert( pWC->a[ii].wtFlags & TERM_VIRTUAL );
153183 assert( pWC->a[ii].eOperator==0 );
153184 continue;
153185 }
153186 if( pWC->a[ii].leftCursor!=iCsr ) return;
153187 }
153188
@@ -153190,11 +153571,11 @@
153190 if( pOrderBy ){
153191 for(ii=0; ii<pOrderBy->nExpr; ii++){
153192 Expr *pExpr = pOrderBy->a[ii].pExpr;
153193 if( pExpr->op!=TK_COLUMN ) return;
153194 if( pExpr->iTable!=iCsr ) return;
153195 if( pOrderBy->a[ii].sortFlags & KEYINFO_ORDER_BIGNULL ) return;
153196 }
153197 }
153198
153199 /* All conditions are met. Add the terms to the where-clause object. */
153200 assert( p->pLimit->op==TK_LIMIT );
@@ -153401,13 +153782,13 @@
153401 pItem->colUsed |= sqlite3ExprColUsed(pColRef);
153402 pRhs = sqlite3PExpr(pParse, TK_UPLUS,
153403 sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
153404 pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef, pRhs);
153405 if( pItem->fg.jointype & (JT_LEFT|JT_LTORJ) ){
153406 joinType = EP_FromJoin;
153407 }else{
153408 joinType = EP_InnerJoin;
153409 }
153410 sqlite3SetJoinExpr(pTerm, pItem->iCursor, joinType);
153411 whereClauseInsert(pWC, pTerm, TERM_DYNAMIC);
153412 }
153413 }
@@ -153516,11 +153897,11 @@
153516 ** continuation of the inner-most loop. */
153517 return pWInfo->iContinue;
153518 }
153519 pInner = &pWInfo->a[pWInfo->nLevel-1];
153520 assert( pInner->addrNxt!=0 );
153521 return pInner->addrNxt;
153522 }
153523
153524 /*
153525 ** While generating code for the min/max optimization, after handling
153526 ** the aggregate-step call to min() or max(), check to see if any
@@ -153744,11 +154125,11 @@
153744 if( pTerm->leftCursor==iCur
153745 && pTerm->u.x.leftColumn==iColumn
153746 && (iColumn!=XN_EXPR
153747 || sqlite3ExprCompareSkip(pTerm->pExpr->pLeft,
153748 pScan->pIdxExpr,iCur)==0)
153749 && (pScan->iEquiv<=1 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin))
153750 ){
153751 if( (pTerm->eOperator & WO_EQUIV)!=0
153752 && pScan->nEquiv<ArraySize(pScan->aiCur)
153753 && (pX = whereRightSubexprIsColumn(pTerm->pExpr))!=0
153754 ){
@@ -154171,11 +154552,11 @@
154171 ){
154172 char aff;
154173 if( pTerm->leftCursor!=pSrc->iCursor ) return 0;
154174 if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) return 0;
154175 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
154176 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
154177 && (pTerm->eOperator & WO_IS)
154178 ){
154179 /* Cannot use an IS term from the WHERE clause as an index driver for
154180 ** the RHS of a LEFT JOIN or for the LHS of a RIGHT JOIN. Such a term
154181 ** can only be used if it is from the ON clause. */
@@ -154246,13 +154627,11 @@
154246 Expr *pExpr = pTerm->pExpr;
154247 /* Make the automatic index a partial index if there are terms in the
154248 ** WHERE clause (or the ON clause of a LEFT join) that constrain which
154249 ** rows of the target table (pSrc) that can be used. */
154250 if( (pTerm->wtFlags & TERM_VIRTUAL)==0
154251 && ((pSrc->fg.jointype&(JT_LEFT|JT_LTORJ))==0
154252 || ExprHasProperty(pExpr,EP_FromJoin))
154253 && sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor)
154254 ){
154255 pPartial = sqlite3ExprAnd(pParse, pPartial,
154256 sqlite3ExprDup(pParse->db, pExpr, 0));
154257 }
154258 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
@@ -154487,11 +154866,11 @@
154487 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, iCur); VdbeCoverage(v);
154488 pWCEnd = &pWInfo->sWC.a[pWInfo->sWC.nTerm];
154489 for(pTerm=pWInfo->sWC.a; pTerm<pWCEnd; pTerm++){
154490 Expr *pExpr = pTerm->pExpr;
154491 if( (pTerm->wtFlags & TERM_VIRTUAL)==0
154492 && sqlite3ExprIsTableConstant(pExpr, iCur)
154493 ){
154494 sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
154495 }
154496 }
154497 if( pLoop->wsFlags & WHERE_IPK ){
@@ -154597,11 +154976,11 @@
154597 /* tag-20191211-002: WHERE-clause constraints are not useful to the
154598 ** right-hand table of a LEFT JOIN nor to the left-hand table of a
154599 ** RIGHT JOIN. See tag-20191211-001 for the
154600 ** equivalent restriction for ordinary tables. */
154601 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
154602 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
154603 ){
154604 continue;
154605 }
154606 nTerm++;
154607 pTerm->wtFlags |= TERM_OK;
@@ -154622,11 +155001,11 @@
154622 if( sqlite3ExprIsConstant(pExpr) ){
154623 continue;
154624 }
154625
154626 /* Virtual tables are unable to deal with NULLS FIRST */
154627 if( pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL ) break;
154628
154629 /* First case - a direct column references without a COLLATE operator */
154630 if( pExpr->op==TK_COLUMN && pExpr->iTable==pSrc->iCursor ){
154631 assert( pExpr->iColumn>=XN_ROWID && pExpr->iColumn<pTab->nCol );
154632 continue;
@@ -154734,11 +155113,11 @@
154734 if( sqlite3ExprIsConstant(pExpr) ) continue;
154735 assert( pExpr->op==TK_COLUMN
154736 || (pExpr->op==TK_COLLATE && pExpr->pLeft->op==TK_COLUMN
154737 && pExpr->iColumn==pExpr->pLeft->iColumn) );
154738 pIdxOrderBy[j].iColumn = pExpr->iColumn;
154739 pIdxOrderBy[j].desc = pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC;
154740 j++;
154741 }
154742 pIdxInfo->nOrderBy = j;
154743
154744 *pmNoOmit = mNoOmit;
@@ -155475,11 +155854,11 @@
155475 char zType[8];
155476 char zLeft[50];
155477 memcpy(zType, "....", 5);
155478 if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V';
155479 if( pTerm->eOperator & WO_EQUIV ) zType[1] = 'E';
155480 if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) zType[2] = 'L';
155481 if( pTerm->wtFlags & TERM_CODED ) zType[3] = 'C';
155482 if( pTerm->eOperator & WO_SINGLE ){
155483 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
155484 sqlite3_snprintf(sizeof(zLeft),zLeft,"left={%d:%d}",
155485 pTerm->leftCursor, pTerm->u.x.leftColumn);
@@ -156252,11 +156631,11 @@
156252 /* tag-20191211-001: Do not allow constraints from the WHERE clause to
156253 ** be used by the right table of a LEFT JOIN nor by the left table of a
156254 ** RIGHT JOIN. Only constraints in the
156255 ** ON clause are allowed. See tag-20191211-002 for the vtab equivalent. */
156256 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
156257 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
156258 ){
156259 continue;
156260 }
156261
156262 if( IsUniqueIndex(pProbe) && saved_nEq==pProbe->nKeyCol-1 ){
@@ -156621,12 +157000,12 @@
156621 }
156622 if( pParse->db->flags & SQLITE_EnableQPSG ) pParse = 0;
156623 for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
156624 Expr *pExpr;
156625 pExpr = pTerm->pExpr;
156626 if( (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->w.iJoin==iTab)
156627 && (isLeft==0 || ExprHasProperty(pExpr, EP_FromJoin))
156628 && sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, iTab)
156629 && (pTerm->wtFlags & TERM_VNULL)==0
156630 ){
156631 return 1;
156632 }
@@ -156898,11 +157277,18 @@
156898
156899 pNew->rRun = sqlite3LogEstAdd(pNew->rRun, nLookup);
156900 }
156901 ApplyCostMultiplier(pNew->rRun, pTab->costMult);
156902 whereLoopOutputAdjust(pWC, pNew, rSize);
156903 rc = whereLoopInsert(pBuilder, pNew);
 
 
 
 
 
 
 
156904 pNew->nOut = rSize;
156905 if( rc ) break;
156906 }
156907 }
156908
@@ -157073,10 +157459,11 @@
157073 pIdxInfo->orderByConsumed = 0;
157074 pIdxInfo->idxFlags &= ~SQLITE_INDEX_SCAN_UNIQUE;
157075 *pbIn = 1; assert( (mExclude & WO_IN)==0 );
157076 }
157077
 
157078 if( isLimitTerm(pTerm) && *pbIn ){
157079 /* If there is an IN(...) term handled as an == (separate call to
157080 ** xFilter for each value on the RHS of the IN) and a LIMIT or
157081 ** OFFSET term handled as well, the plan is unusable. Set output
157082 ** variable *pbRetryLimit to true to tell the caller to retry with
@@ -157546,11 +157933,13 @@
157546 SrcList *pTabList = pWInfo->pTabList;
157547 SrcItem *pItem;
157548 SrcItem *pEnd = &pTabList->a[pWInfo->nLevel];
157549 sqlite3 *db = pWInfo->pParse->db;
157550 int rc = SQLITE_OK;
 
157551 WhereLoop *pNew;
 
157552
157553 /* Loop over the tables in the join, from left to right */
157554 pNew = pBuilder->pNew;
157555 whereLoopInit(pNew);
157556 pBuilder->iPlanLimit = SQLITE_QUERY_PLANNER_LIMIT;
@@ -157557,16 +157946,17 @@
157557 for(iTab=0, pItem=pTabList->a; pItem<pEnd; iTab++, pItem++){
157558 Bitmask mUnusable = 0;
157559 pNew->iTab = iTab;
157560 pBuilder->iPlanLimit += SQLITE_QUERY_PLANNER_LIMIT_INCR;
157561 pNew->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, pItem->iCursor);
157562 if( (pItem->fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
157563 /* This condition is true when pItem is the FROM clause term on the
157564 ** right-hand-side of a OUTER or CROSS JOIN. */
157565 mPrereq = mPrior;
157566 }else{
157567 mPrereq = 0;
 
157568 }
157569 #ifndef SQLITE_OMIT_VIRTUALTABLE
157570 if( IsVirtual(pItem->pTab) ){
157571 SrcItem *p;
157572 for(p=&pItem[1]; p<pEnd; p++){
@@ -157873,20 +158263,22 @@
157873 }
157874 if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
157875 /* Make sure the sort order is compatible in an ORDER BY clause.
157876 ** Sort order is irrelevant for a GROUP BY clause. */
157877 if( revSet ){
157878 if( (rev ^ revIdx)!=(pOrderBy->a[i].sortFlags&KEYINFO_ORDER_DESC) ){
 
 
157879 isMatch = 0;
157880 }
157881 }else{
157882 rev = revIdx ^ (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC);
157883 if( rev ) *pRevMask |= MASKBIT(iLoop);
157884 revSet = 1;
157885 }
157886 }
157887 if( isMatch && (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL) ){
157888 if( j==pLoop->u.btree.nEq ){
157889 pLoop->wsFlags |= WHERE_BIGNULL_SORT;
157890 }else{
157891 isMatch = 0;
157892 }
@@ -158630,11 +159022,11 @@
158630 }
158631 if( (tabUsed & pLoop->maskSelf)!=0 ) continue;
158632 pEnd = pWInfo->sWC.a + pWInfo->sWC.nTerm;
158633 for(pTerm=pWInfo->sWC.a; pTerm<pEnd; pTerm++){
158634 if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){
158635 if( !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
158636 || pTerm->pExpr->w.iJoin!=pItem->iCursor
158637 ){
158638 break;
158639 }
158640 }
@@ -159256,10 +159648,11 @@
159256 op = OP_ReopenIdx;
159257 }else{
159258 iIndexCur = pParse->nTab++;
159259 }
159260 pLevel->iIdxCur = iIndexCur;
 
159261 assert( pIx->pSchema==pTab->pSchema );
159262 assert( iIndexCur>=0 );
159263 if( op ){
159264 sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
159265 sqlite3VdbeSetP4KeyInfo(pParse, pIx);
@@ -159331,13 +159724,24 @@
159331 ** program.
159332 */
159333 for(ii=0; ii<nTabList; ii++){
159334 int addrExplain;
159335 int wsFlags;
 
159336 if( pParse->nErr ) goto whereBeginError;
159337 pLevel = &pWInfo->a[ii];
159338 wsFlags = pLevel->pWLoop->wsFlags;
 
 
 
 
 
 
 
 
 
 
159339 if( (wsFlags & (WHERE_AUTO_INDEX|WHERE_BLOOMFILTER))!=0 ){
159340 if( (wsFlags & WHERE_AUTO_INDEX)!=0 ){
159341 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
159342 constructAutomaticIndex(pParse, &pWInfo->sWC,
159343 &pTabList->a[pLevel->iFrom], notReady, pLevel);
@@ -159425,10 +159829,11 @@
159425 WhereLevel *pLevel;
159426 WhereLoop *pLoop;
159427 SrcList *pTabList = pWInfo->pTabList;
159428 sqlite3 *db = pParse->db;
159429 int iEnd = sqlite3VdbeCurrentAddr(v);
 
159430
159431 /* Generate loop termination code.
159432 */
159433 VdbeModuleComment((v, "End WHERE-core"));
159434 for(i=pWInfo->nLevel-1; i>=0; i--){
@@ -159438,14 +159843,14 @@
159438 /* Terminate the subroutine that forms the interior of the loop of
159439 ** the RIGHT JOIN table */
159440 WhereRightJoin *pRJ = pLevel->pRJ;
159441 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
159442 pLevel->addrCont = 0;
 
159443 sqlite3VdbeAddOp3(v, OP_Return, pRJ->regReturn, pRJ->addrSubrtn, 1);
159444 VdbeCoverage(v);
159445 assert( pParse->withinRJSubrtn>0 );
159446 pParse->withinRJSubrtn--;
159447 }
159448 pLoop = pLevel->pWLoop;
159449 if( pLevel->op!=OP_Noop ){
159450 #ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
159451 int addrSeek = 0;
@@ -159583,10 +159988,11 @@
159583 VdbeModuleComment((v, "End WHERE-loop%d: %s", i,
159584 pWInfo->pTabList->a[pLevel->iFrom].pTab->zName));
159585 }
159586
159587 assert( pWInfo->nLevel<=pTabList->nSrc );
 
159588 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
159589 int k, last;
159590 VdbeOp *pOp, *pLastOp;
159591 Index *pIdx = 0;
159592 SrcItem *pTabItem = &pTabList->a[pLevel->iFrom];
@@ -159719,13 +160125,13 @@
159719 */
159720 sqlite3VdbeResolveLabel(v, pWInfo->iBreak);
159721
159722 /* Final cleanup
159723 */
159724 if( pWInfo->pExprMods ) whereUndoExprMods(pWInfo);
159725 pParse->nQueryLoop = pWInfo->savedNQueryLoop;
159726 whereInfoFree(db, pWInfo);
 
159727 return;
159728 }
159729
159730 /************** End of where.c ***********************************************/
159731 /************** Begin file window.c ******************************************/
@@ -160645,11 +161051,11 @@
160645 pSub->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse);
160646 pSub->u.zToken = 0;
160647 }
160648 }
160649 pList = sqlite3ExprListAppend(pParse, pList, pDup);
160650 if( pList ) pList->a[nInit+i].sortFlags = pAppend->a[i].sortFlags;
160651 }
160652 }
160653 return pList;
160654 }
160655
@@ -161846,11 +162252,11 @@
161846 windowReadPeerValues(p, csr1, reg1);
161847 windowReadPeerValues(p, csr2, reg2);
161848
161849 assert( op==OP_Ge || op==OP_Gt || op==OP_Le );
161850 assert( pOrderBy && pOrderBy->nExpr==1 );
161851 if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_DESC ){
161852 switch( op ){
161853 case OP_Ge: op = OP_Le; break;
161854 case OP_Gt: op = OP_Lt; break;
161855 default: assert( op==OP_Le ); op = OP_Ge; break;
161856 }
@@ -161879,11 +162285,11 @@
161879 ** }
161880 **
161881 ** Additionally, if either reg1 or reg2 are NULL but the jump to lbl is
161882 ** not taken, control jumps over the comparison operator coded below this
161883 ** block. */
161884 if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_BIGNULL ){
161885 /* This block runs if reg1 contains a NULL. */
161886 int addr = sqlite3VdbeAddOp1(v, OP_NotNull, reg1); VdbeCoverage(v);
161887 switch( op ){
161888 case OP_Ge:
161889 sqlite3VdbeAddOp2(v, OP_Goto, 0, lbl);
@@ -163347,22 +163753,22 @@
163347 #define sqlite3ParserCTX_PDECL ,Parse *pParse
163348 #define sqlite3ParserCTX_PARAM ,pParse
163349 #define sqlite3ParserCTX_FETCH Parse *pParse=yypParser->pParse;
163350 #define sqlite3ParserCTX_STORE yypParser->pParse=pParse;
163351 #define YYFALLBACK 1
163352 #define YYNSTATE 570
163353 #define YYNRULE 403
163354 #define YYNRULE_WITH_ACTION 340
163355 #define YYNTOKEN 185
163356 #define YY_MAX_SHIFT 569
163357 #define YY_MIN_SHIFTREDUCE 829
163358 #define YY_MAX_SHIFTREDUCE 1231
163359 #define YY_ERROR_ACTION 1232
163360 #define YY_ACCEPT_ACTION 1233
163361 #define YY_NO_ACTION 1234
163362 #define YY_MIN_REDUCE 1235
163363 #define YY_MAX_REDUCE 1637
163364 /************* End control #defines *******************************************/
163365 #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))
163366
163367 /* Define the yytestcase() macro to be a no-op if is not already defined
163368 ** otherwise.
@@ -163425,219 +163831,222 @@
163425 ** yy_reduce_ofst[] For each state, the offset into yy_action for
163426 ** shifting non-terminals after a reduce.
163427 ** yy_default[] Default action for each state.
163428 **
163429 *********** Begin parsing tables **********************************************/
163430 #define YY_ACTTAB_COUNT (2064)
163431 static const YYACTIONTYPE yy_action[] = {
163432 /* 0 */ 562, 204, 562, 116, 112, 225, 562, 116, 112, 225,
163433 /* 10 */ 562, 1306, 373, 1285, 404, 556, 556, 556, 562, 405,
163434 /* 20 */ 374, 1306, 1268, 41, 41, 41, 41, 204, 1516, 71,
163435 /* 30 */ 71, 965, 415, 41, 41, 487, 299, 275, 299, 966,
163436 /* 40 */ 393, 71, 71, 123, 124, 114, 1209, 1209, 1042, 1045,
163437 /* 50 */ 1034, 1034, 121, 121, 122, 122, 122, 122, 472, 405,
163438 /* 60 */ 1233, 1, 1, 569, 2, 1237, 544, 116, 112, 225,
163439 /* 70 */ 313, 476, 142, 476, 520, 116, 112, 225, 525, 1319,
163440 /* 80 */ 413, 519, 138, 123, 124, 114, 1209, 1209, 1042, 1045,
163441 /* 90 */ 1034, 1034, 121, 121, 122, 122, 122, 122, 116, 112,
163442 /* 100 */ 225, 323, 120, 120, 120, 120, 119, 119, 118, 118,
163443 /* 110 */ 118, 117, 113, 440, 280, 280, 280, 280, 438, 438,
163444 /* 120 */ 438, 1557, 372, 1559, 1184, 371, 1155, 559, 1155, 559,
163445 /* 130 */ 405, 1557, 533, 255, 222, 440, 99, 141, 445, 312,
163446 /* 140 */ 553, 236, 120, 120, 120, 120, 119, 119, 118, 118,
163447 /* 150 */ 118, 117, 113, 440, 123, 124, 114, 1209, 1209, 1042,
163448 /* 160 */ 1045, 1034, 1034, 121, 121, 122, 122, 122, 122, 138,
163449 /* 170 */ 290, 1184, 335, 444, 118, 118, 118, 117, 113, 440,
163450 /* 180 */ 125, 1184, 1185, 1186, 144, 437, 436, 562, 117, 113,
163451 /* 190 */ 440, 122, 122, 122, 122, 115, 120, 120, 120, 120,
163452 /* 200 */ 119, 119, 118, 118, 118, 117, 113, 440, 450, 110,
163453 /* 210 */ 13, 13, 542, 120, 120, 120, 120, 119, 119, 118,
163454 /* 220 */ 118, 118, 117, 113, 440, 418, 312, 553, 1184, 1185,
163455 /* 230 */ 1186, 145, 1216, 405, 1216, 122, 122, 122, 122, 120,
163456 /* 240 */ 120, 120, 120, 119, 119, 118, 118, 118, 117, 113,
163457 /* 250 */ 440, 461, 338, 1031, 1031, 1043, 1046, 123, 124, 114,
163458 /* 260 */ 1209, 1209, 1042, 1045, 1034, 1034, 121, 121, 122, 122,
163459 /* 270 */ 122, 122, 1271, 518, 218, 1184, 562, 405, 220, 510,
163460 /* 280 */ 171, 80, 81, 120, 120, 120, 120, 119, 119, 118,
163461 /* 290 */ 118, 118, 117, 113, 440, 1001, 16, 16, 1184, 55,
163462 /* 300 */ 55, 123, 124, 114, 1209, 1209, 1042, 1045, 1034, 1034,
163463 /* 310 */ 121, 121, 122, 122, 122, 122, 120, 120, 120, 120,
163464 /* 320 */ 119, 119, 118, 118, 118, 117, 113, 440, 1035, 542,
163465 /* 330 */ 1184, 369, 1184, 1185, 1186, 248, 1426, 395, 500, 497,
163466 /* 340 */ 496, 108, 554, 560, 4, 920, 920, 429, 495, 336,
163467 /* 350 */ 456, 324, 356, 390, 1229, 1184, 1185, 1186, 557, 562,
163468 /* 360 */ 120, 120, 120, 120, 119, 119, 118, 118, 118, 117,
163469 /* 370 */ 113, 440, 280, 280, 365, 1570, 1597, 437, 436, 150,
163470 /* 380 */ 405, 441, 71, 71, 1278, 559, 1213, 1184, 1185, 1186,
163471 /* 390 */ 83, 1215, 267, 551, 539, 511, 1551, 562, 96, 1214,
163472 /* 400 */ 6, 1270, 468, 138, 123, 124, 114, 1209, 1209, 1042,
163473 /* 410 */ 1045, 1034, 1034, 121, 121, 122, 122, 122, 122, 544,
163474 /* 420 */ 13, 13, 1021, 503, 1216, 1184, 1216, 543, 106, 106,
163475 /* 430 */ 218, 562, 1230, 171, 562, 423, 107, 193, 441, 564,
163476 /* 440 */ 563, 426, 1542, 1011, 321, 545, 1184, 266, 283, 364,
163477 /* 450 */ 506, 359, 505, 253, 71, 71, 539, 71, 71, 355,
163478 /* 460 */ 312, 553, 1603, 120, 120, 120, 120, 119, 119, 118,
163479 /* 470 */ 118, 118, 117, 113, 440, 1011, 1011, 1013, 1014, 27,
163480 /* 480 */ 280, 280, 1184, 1185, 1186, 1150, 562, 1602, 405, 895,
163481 /* 490 */ 186, 544, 352, 559, 544, 931, 529, 513, 1150, 512,
163482 /* 500 */ 409, 1150, 546, 1184, 1185, 1186, 562, 540, 1544, 51,
163483 /* 510 */ 51, 210, 123, 124, 114, 1209, 1209, 1042, 1045, 1034,
163484 /* 520 */ 1034, 121, 121, 122, 122, 122, 122, 1184, 470, 56,
163485 /* 530 */ 56, 405, 280, 280, 1480, 501, 119, 119, 118, 118,
163486 /* 540 */ 118, 117, 113, 440, 1001, 559, 514, 213, 537, 1551,
163487 /* 550 */ 312, 553, 138, 6, 528, 123, 124, 114, 1209, 1209,
163488 /* 560 */ 1042, 1045, 1034, 1034, 121, 121, 122, 122, 122, 122,
163489 /* 570 */ 1545, 120, 120, 120, 120, 119, 119, 118, 118, 118,
163490 /* 580 */ 117, 113, 440, 481, 1184, 1185, 1186, 478, 277, 1259,
163491 /* 590 */ 951, 248, 1184, 369, 500, 497, 496, 1184, 336, 565,
163492 /* 600 */ 1184, 565, 405, 288, 495, 951, 870, 187, 476, 312,
163493 /* 610 */ 553, 380, 286, 376, 120, 120, 120, 120, 119, 119,
163494 /* 620 */ 118, 118, 118, 117, 113, 440, 123, 124, 114, 1209,
163495 /* 630 */ 1209, 1042, 1045, 1034, 1034, 121, 121, 122, 122, 122,
163496 /* 640 */ 122, 405, 390, 1128, 1184, 863, 98, 280, 280, 1184,
163497 /* 650 */ 1185, 1186, 369, 1085, 1184, 1185, 1186, 1184, 1185, 1186,
163498 /* 660 */ 559, 451, 32, 369, 229, 123, 124, 114, 1209, 1209,
163499 /* 670 */ 1042, 1045, 1034, 1034, 121, 121, 122, 122, 122, 122,
163500 /* 680 */ 1425, 953, 562, 224, 952, 120, 120, 120, 120, 119,
163501 /* 690 */ 119, 118, 118, 118, 117, 113, 440, 1150, 224, 1184,
163502 /* 700 */ 153, 1184, 1185, 1186, 1543, 13, 13, 297, 951, 1224,
163503 /* 710 */ 1150, 149, 405, 1150, 369, 1573, 1168, 5, 365, 1570,
163504 /* 720 */ 425, 1230, 3, 951, 120, 120, 120, 120, 119, 119,
163505 /* 730 */ 118, 118, 118, 117, 113, 440, 123, 124, 114, 1209,
163506 /* 740 */ 1209, 1042, 1045, 1034, 1034, 121, 121, 122, 122, 122,
163507 /* 750 */ 122, 405, 204, 561, 1184, 1022, 1184, 1185, 1186, 1184,
163508 /* 760 */ 384, 846, 151, 1542, 282, 398, 1090, 1090, 484, 562,
163509 /* 770 */ 461, 338, 1311, 1311, 1542, 123, 124, 114, 1209, 1209,
163510 /* 780 */ 1042, 1045, 1034, 1034, 121, 121, 122, 122, 122, 122,
163511 /* 790 */ 127, 562, 13, 13, 370, 120, 120, 120, 120, 119,
163512 /* 800 */ 119, 118, 118, 118, 117, 113, 440, 298, 562, 449,
163513 /* 810 */ 524, 1184, 1185, 1186, 13, 13, 1184, 1185, 1186, 1289,
163514 /* 820 */ 459, 1259, 405, 1309, 1309, 1542, 1006, 449, 448, 196,
163515 /* 830 */ 295, 71, 71, 1257, 120, 120, 120, 120, 119, 119,
163516 /* 840 */ 118, 118, 118, 117, 113, 440, 123, 124, 114, 1209,
163517 /* 850 */ 1209, 1042, 1045, 1034, 1034, 121, 121, 122, 122, 122,
163518 /* 860 */ 122, 405, 223, 1065, 1150, 280, 280, 415, 308, 274,
163519 /* 870 */ 274, 281, 281, 1411, 402, 401, 378, 1150, 559, 562,
163520 /* 880 */ 1150, 1188, 559, 1590, 559, 123, 124, 114, 1209, 1209,
163521 /* 890 */ 1042, 1045, 1034, 1034, 121, 121, 122, 122, 122, 122,
163522 /* 900 */ 449, 1472, 13, 13, 1526, 120, 120, 120, 120, 119,
163523 /* 910 */ 119, 118, 118, 118, 117, 113, 440, 197, 562, 350,
163524 /* 920 */ 1576, 569, 2, 1237, 834, 835, 836, 1552, 313, 1204,
163525 /* 930 */ 142, 6, 405, 251, 250, 249, 202, 1319, 9, 1188,
163526 /* 940 */ 258, 71, 71, 420, 120, 120, 120, 120, 119, 119,
163527 /* 950 */ 118, 118, 118, 117, 113, 440, 123, 124, 114, 1209,
163528 /* 960 */ 1209, 1042, 1045, 1034, 1034, 121, 121, 122, 122, 122,
163529 /* 970 */ 122, 562, 280, 280, 562, 1205, 405, 568, 309, 1237,
163530 /* 980 */ 345, 1288, 348, 415, 313, 559, 142, 487, 521, 1633,
163531 /* 990 */ 391, 367, 487, 1319, 70, 70, 1287, 71, 71, 236,
163532 /* 1000 */ 1317, 101, 114, 1209, 1209, 1042, 1045, 1034, 1034, 121,
163533 /* 1010 */ 121, 122, 122, 122, 122, 120, 120, 120, 120, 119,
163534 /* 1020 */ 119, 118, 118, 118, 117, 113, 440, 1106, 280, 280,
163535 /* 1030 */ 424, 444, 1515, 1205, 435, 280, 280, 1479, 1344, 307,
163536 /* 1040 */ 470, 559, 1107, 965, 487, 487, 213, 1255, 559, 1528,
163537 /* 1050 */ 562, 966, 203, 562, 1021, 236, 379, 1108, 515, 120,
163538 /* 1060 */ 120, 120, 120, 119, 119, 118, 118, 118, 117, 113,
163539 /* 1070 */ 440, 1012, 104, 71, 71, 1011, 13, 13, 906, 562,
163540 /* 1080 */ 1485, 562, 280, 280, 95, 522, 487, 444, 907, 1318,
163541 /* 1090 */ 1314, 541, 405, 280, 280, 559, 147, 205, 1485, 1487,
163542 /* 1100 */ 258, 446, 15, 15, 43, 43, 559, 1011, 1011, 1013,
163543 /* 1110 */ 439, 328, 405, 523, 12, 291, 123, 124, 114, 1209,
163544 /* 1120 */ 1209, 1042, 1045, 1034, 1034, 121, 121, 122, 122, 122,
163545 /* 1130 */ 122, 343, 405, 858, 1524, 1205, 123, 124, 114, 1209,
163546 /* 1140 */ 1209, 1042, 1045, 1034, 1034, 121, 121, 122, 122, 122,
163547 /* 1150 */ 122, 1129, 1631, 470, 1631, 367, 123, 111, 114, 1209,
163548 /* 1160 */ 1209, 1042, 1045, 1034, 1034, 121, 121, 122, 122, 122,
163549 /* 1170 */ 122, 1485, 325, 470, 327, 120, 120, 120, 120, 119,
163550 /* 1180 */ 119, 118, 118, 118, 117, 113, 440, 199, 1411, 562,
163551 /* 1190 */ 1286, 858, 460, 1205, 432, 120, 120, 120, 120, 119,
163552 /* 1200 */ 119, 118, 118, 118, 117, 113, 440, 547, 1129, 1632,
163553 /* 1210 */ 535, 1632, 57, 57, 886, 120, 120, 120, 120, 119,
163554 /* 1220 */ 119, 118, 118, 118, 117, 113, 440, 562, 294, 534,
163555 /* 1230 */ 1127, 1411, 1549, 1550, 1323, 405, 6, 6, 1161, 1260,
163556 /* 1240 */ 411, 316, 280, 280, 1411, 504, 559, 521, 296, 453,
163557 /* 1250 */ 44, 44, 562, 887, 12, 559, 326, 474, 421, 403,
163558 /* 1260 */ 124, 114, 1209, 1209, 1042, 1045, 1034, 1034, 121, 121,
163559 /* 1270 */ 122, 122, 122, 122, 562, 58, 58, 284, 1184, 1411,
163560 /* 1280 */ 492, 454, 388, 388, 387, 269, 385, 1127, 1548, 843,
163561 /* 1290 */ 1161, 403, 6, 562, 317, 1150, 466, 59, 59, 1547,
163562 /* 1300 */ 1106, 422, 230, 6, 319, 252, 536, 252, 1150, 427,
163563 /* 1310 */ 562, 1150, 318, 17, 483, 1107, 60, 60, 120, 120,
163564 /* 1320 */ 120, 120, 119, 119, 118, 118, 118, 117, 113, 440,
163565 /* 1330 */ 1108, 212, 477, 61, 61, 1184, 1185, 1186, 108, 554,
163566 /* 1340 */ 320, 4, 232, 452, 522, 562, 233, 452, 562, 433,
163567 /* 1350 */ 164, 550, 416, 137, 475, 557, 562, 289, 562, 1087,
163568 /* 1360 */ 562, 289, 562, 1087, 527, 562, 866, 8, 62, 62,
163569 /* 1370 */ 231, 45, 45, 562, 410, 562, 410, 562, 441, 46,
163570 /* 1380 */ 46, 47, 47, 49, 49, 50, 50, 195, 63, 63,
163571 /* 1390 */ 551, 562, 355, 562, 98, 482, 64, 64, 65, 65,
163572 /* 1400 */ 14, 14, 555, 411, 531, 406, 562, 1021, 562, 530,
163573 /* 1410 */ 312, 553, 312, 553, 66, 66, 129, 129, 562, 1021,
163574 /* 1420 */ 562, 508, 926, 866, 1012, 106, 106, 925, 1011, 67,
163575 /* 1430 */ 67, 52, 52, 107, 447, 441, 564, 563, 412, 173,
163576 /* 1440 */ 1011, 68, 68, 69, 69, 562, 463, 562, 926, 467,
163577 /* 1450 */ 1356, 279, 222, 925, 311, 1355, 403, 562, 455, 403,
163578 /* 1460 */ 1011, 1011, 1013, 235, 403, 84, 209, 1342, 53, 53,
163579 /* 1470 */ 159, 159, 1011, 1011, 1013, 1014, 27, 1575, 1172, 443,
163580 /* 1480 */ 160, 160, 284, 95, 105, 1531, 103, 388, 388, 387,
163581 /* 1490 */ 269, 385, 562, 873, 843, 877, 562, 108, 554, 462,
163582 /* 1500 */ 4, 562, 148, 30, 38, 562, 1124, 230, 392, 319,
163583 /* 1510 */ 108, 554, 523, 4, 557, 76, 76, 318, 562, 54,
163584 /* 1520 */ 54, 562, 333, 464, 72, 72, 329, 557, 130, 130,
163585 /* 1530 */ 562, 285, 1504, 562, 31, 1503, 562, 441, 334, 479,
163586 /* 1540 */ 98, 73, 73, 340, 157, 157, 292, 232, 1072, 551,
163587 /* 1550 */ 441, 873, 1352, 131, 131, 164, 132, 132, 137, 128,
163588 /* 1560 */ 128, 1564, 551, 531, 562, 315, 562, 344, 532, 1003,
163589 /* 1570 */ 469, 257, 257, 885, 884, 231, 531, 562, 1021, 562,
163590 /* 1580 */ 471, 530, 257, 363, 106, 106, 517, 158, 158, 152,
163591 /* 1590 */ 152, 1021, 107, 362, 441, 564, 563, 106, 106, 1011,
163592 /* 1600 */ 136, 136, 135, 135, 562, 107, 1072, 441, 564, 563,
163593 /* 1610 */ 406, 347, 1011, 562, 349, 312, 553, 562, 339, 562,
163594 /* 1620 */ 98, 493, 353, 254, 98, 892, 893, 133, 133, 351,
163595 /* 1630 */ 1302, 1011, 1011, 1013, 1014, 27, 134, 134, 1015, 447,
163596 /* 1640 */ 75, 75, 77, 77, 1011, 1011, 1013, 1014, 27, 1172,
163597 /* 1650 */ 443, 562, 358, 284, 108, 554, 368, 4, 388, 388,
163598 /* 1660 */ 387, 269, 385, 562, 1133, 843, 562, 1068, 956, 254,
163599 /* 1670 */ 257, 557, 968, 969, 74, 74, 549, 923, 230, 110,
163600 /* 1680 */ 319, 108, 554, 1084, 4, 1084, 42, 42, 318, 48,
163601 /* 1690 */ 48, 1083, 1365, 1083, 441, 856, 1015, 146, 557, 924,
163602 /* 1700 */ 1410, 110, 1338, 1350, 548, 1416, 551, 1267, 207, 1258,
163603 /* 1710 */ 1246, 1245, 1247, 1583, 11, 488, 272, 215, 232, 1335,
163604 /* 1720 */ 304, 441, 305, 306, 389, 228, 164, 1397, 1392, 137,
163605 /* 1730 */ 287, 331, 332, 551, 293, 1021, 1385, 337, 473, 200,
163606 /* 1740 */ 361, 106, 106, 930, 498, 1402, 231, 1401, 1285, 107,
163607 /* 1750 */ 396, 441, 564, 563, 219, 1476, 1011, 1347, 1475, 1348,
163608 /* 1760 */ 1346, 1345, 1021, 1224, 552, 1586, 261, 1221, 106, 106,
163609 /* 1770 */ 1523, 201, 383, 1521, 214, 414, 107, 83, 441, 564,
163610 /* 1780 */ 563, 406, 211, 1011, 175, 1398, 312, 553, 1011, 1011,
163611 /* 1790 */ 1013, 1014, 27, 226, 184, 169, 100, 554, 79, 4,
163612 /* 1800 */ 82, 457, 35, 179, 458, 177, 491, 238, 96, 1481,
163613 /* 1810 */ 447, 180, 1404, 557, 181, 1011, 1011, 1013, 1014, 27,
163614 /* 1820 */ 182, 1403, 394, 36, 465, 1406, 397, 188, 1470, 480,
163615 /* 1830 */ 242, 89, 1492, 486, 342, 244, 441, 273, 192, 346,
163616 /* 1840 */ 489, 245, 399, 1248, 428, 246, 507, 1296, 551, 91,
163617 /* 1850 */ 877, 1305, 1304, 220, 1601, 1295, 1303, 430, 431, 516,
163618 /* 1860 */ 1569, 259, 400, 302, 1600, 1275, 303, 260, 360, 1274,
163619 /* 1870 */ 1273, 1599, 366, 1555, 434, 1554, 1370, 1021, 1369, 542,
163620 /* 1880 */ 126, 10, 1456, 106, 106, 377, 102, 97, 310, 526,
163621 /* 1890 */ 34, 107, 566, 441, 564, 563, 1178, 271, 1011, 268,
163622 /* 1900 */ 270, 567, 1243, 1238, 206, 1328, 375, 381, 1327, 382,
163623 /* 1910 */ 407, 161, 174, 408, 1508, 1509, 143, 300, 830, 162,
163624 /* 1920 */ 1507, 1506, 163, 442, 208, 314, 227, 216, 217, 78,
163625 /* 1930 */ 1011, 1011, 1013, 1014, 27, 140, 1082, 322, 1080, 165,
163626 /* 1940 */ 176, 1204, 234, 178, 909, 330, 237, 1096, 183, 166,
163627 /* 1950 */ 167, 417, 85, 86, 419, 185, 87, 88, 168, 1099,
163628 /* 1960 */ 239, 1095, 240, 154, 18, 241, 341, 1218, 257, 1088,
163629 /* 1970 */ 243, 485, 190, 189, 37, 845, 490, 362, 247, 494,
163630 /* 1980 */ 357, 191, 875, 90, 19, 502, 354, 20, 499, 92,
163631 /* 1990 */ 170, 155, 888, 93, 301, 509, 94, 1166, 156, 1048,
163632 /* 2000 */ 1135, 39, 221, 1134, 276, 278, 256, 194, 110, 960,
163633 /* 2010 */ 954, 1156, 21, 1152, 22, 1160, 1140, 1154, 23, 33,
163634 /* 2020 */ 24, 1159, 25, 538, 26, 198, 98, 1063, 1049, 1047,
163635 /* 2030 */ 1051, 7, 1105, 262, 1104, 263, 1052, 28, 40, 558,
163636 /* 2040 */ 1016, 857, 109, 29, 919, 386, 139, 172, 264, 265,
163637 /* 2050 */ 1174, 1592, 1173, 1234, 1234, 1234, 1234, 1234, 1234, 1234,
163638 /* 2060 */ 1234, 1234, 1234, 1591,
 
 
 
163639 };
163640 static const YYCODETYPE yy_lookahead[] = {
163641 /* 0 */ 193, 193, 193, 274, 275, 276, 193, 274, 275, 276,
163642 /* 10 */ 193, 223, 219, 225, 206, 210, 211, 212, 193, 19,
163643 /* 20 */ 219, 233, 216, 216, 217, 216, 217, 193, 295, 216,
@@ -163799,57 +164208,57 @@
163799 /* 1580 */ 23, 90, 25, 121, 106, 107, 19, 216, 217, 216,
163800 /* 1590 */ 217, 100, 114, 131, 116, 117, 118, 106, 107, 121,
163801 /* 1600 */ 216, 217, 216, 217, 193, 114, 117, 116, 117, 118,
163802 /* 1610 */ 133, 193, 121, 193, 193, 138, 139, 193, 23, 193,
163803 /* 1620 */ 25, 23, 23, 25, 25, 7, 8, 216, 217, 193,
163804 /* 1630 */ 193, 153, 154, 155, 156, 157, 216, 217, 59, 162,
163805 /* 1640 */ 216, 217, 216, 217, 153, 154, 155, 156, 157, 1,
163806 /* 1650 */ 2, 193, 193, 5, 19, 20, 193, 22, 10, 11,
163807 /* 1660 */ 12, 13, 14, 193, 97, 17, 193, 23, 23, 25,
163808 /* 1670 */ 25, 36, 83, 84, 216, 217, 236, 23, 30, 25,
163809 /* 1680 */ 32, 19, 20, 153, 22, 155, 216, 217, 40, 216,
163810 /* 1690 */ 217, 153, 193, 155, 59, 23, 117, 25, 36, 23,
163811 /* 1700 */ 193, 25, 193, 193, 193, 193, 71, 193, 242, 193,
163812 /* 1710 */ 193, 193, 193, 193, 243, 288, 287, 214, 70, 255,
163813 /* 1720 */ 255, 59, 255, 255, 191, 297, 78, 271, 267, 81,
163814 /* 1730 */ 245, 293, 246, 71, 246, 100, 267, 245, 293, 249,
163815 /* 1740 */ 219, 106, 107, 108, 220, 271, 98, 271, 225, 114,
163816 /* 1750 */ 271, 116, 117, 118, 229, 219, 121, 259, 219, 259,
163817 /* 1760 */ 259, 259, 100, 60, 280, 196, 141, 38, 106, 107,
163818 /* 1770 */ 200, 249, 245, 200, 243, 200, 114, 151, 116, 117,
163819 /* 1780 */ 118, 133, 150, 121, 297, 272, 138, 139, 153, 154,
163820 /* 1790 */ 155, 156, 157, 297, 22, 43, 19, 20, 294, 22,
163821 /* 1800 */ 294, 18, 270, 237, 200, 234, 18, 199, 149, 283,
163822 /* 1810 */ 162, 237, 272, 36, 237, 153, 154, 155, 156, 157,
163823 /* 1820 */ 237, 272, 246, 270, 246, 234, 246, 234, 246, 200,
163824 /* 1830 */ 199, 158, 290, 62, 289, 199, 59, 200, 22, 200,
163825 /* 1840 */ 221, 199, 221, 200, 64, 199, 115, 227, 71, 22,
163826 /* 1850 */ 126, 218, 218, 165, 224, 227, 218, 24, 113, 305,
163827 /* 1860 */ 312, 200, 221, 282, 224, 218, 282, 91, 218, 220,
163828 /* 1870 */ 218, 218, 221, 317, 82, 317, 265, 100, 265, 145,
163829 /* 1880 */ 148, 22, 277, 106, 107, 200, 158, 147, 279, 146,
163830 /* 1890 */ 25, 114, 202, 116, 117, 118, 13, 6, 121, 194,
163831 /* 1900 */ 194, 192, 192, 192, 248, 250, 249, 247, 250, 246,
163832 /* 1910 */ 303, 207, 300, 303, 213, 213, 222, 222, 4, 207,
163833 /* 1920 */ 213, 213, 207, 3, 22, 163, 15, 214, 214, 213,
163834 /* 1930 */ 153, 154, 155, 156, 157, 16, 23, 139, 23, 130,
163835 /* 1940 */ 151, 25, 24, 142, 20, 16, 144, 1, 142, 130,
163836 /* 1950 */ 130, 61, 53, 53, 37, 151, 53, 53, 130, 116,
163837 /* 1960 */ 34, 1, 141, 5, 22, 115, 161, 75, 25, 68,
163838 /* 1970 */ 141, 41, 115, 68, 24, 20, 19, 131, 125, 67,
163839 /* 1980 */ 24, 22, 59, 22, 22, 96, 23, 22, 67, 22,
163840 /* 1990 */ 37, 23, 28, 149, 67, 22, 25, 23, 23, 23,
163841 /* 2000 */ 23, 22, 141, 97, 23, 23, 34, 22, 25, 116,
163842 /* 2010 */ 143, 75, 34, 88, 34, 75, 23, 86, 34, 22,
163843 /* 2020 */ 34, 93, 34, 24, 34, 25, 25, 23, 23, 23,
163844 /* 2030 */ 23, 44, 23, 25, 23, 22, 11, 22, 22, 25,
163845 /* 2040 */ 23, 23, 22, 22, 135, 15, 23, 25, 141, 141,
163846 /* 2050 */ 1, 141, 1, 319, 319, 319, 319, 319, 319, 319,
163847 /* 2060 */ 319, 319, 319, 141, 319, 319, 319, 319, 319, 319,
163848 /* 2070 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
163849 /* 2080 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
163850 /* 2090 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
163851 /* 2100 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
163852 /* 2110 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
163853 /* 2120 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
163854 /* 2130 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
163855 /* 2140 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
@@ -163860,77 +164269,82 @@
163860 /* 2190 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
163861 /* 2200 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
163862 /* 2210 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
163863 /* 2220 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
163864 /* 2230 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
163865 /* 2240 */ 319, 319, 319, 319, 319, 319, 319, 319, 319,
 
 
 
 
163866 };
163867 #define YY_SHIFT_COUNT (569)
163868 #define YY_SHIFT_MIN (0)
163869 #define YY_SHIFT_MAX (2051)
163870 static const unsigned short int yy_shift_ofst[] = {
163871 /* 0 */ 1648, 1477, 1272, 322, 322, 1, 1319, 1478, 1491, 1662,
163872 /* 10 */ 1662, 1662, 471, 0, 0, 214, 1093, 1662, 1662, 1662,
163873 /* 20 */ 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662,
163874 /* 30 */ 271, 271, 1219, 1219, 216, 88, 1, 1, 1, 1,
163875 /* 40 */ 1, 40, 111, 258, 361, 469, 512, 583, 622, 693,
163876 /* 50 */ 732, 803, 842, 913, 1073, 1093, 1093, 1093, 1093, 1093,
163877 /* 60 */ 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093,
163878 /* 70 */ 1093, 1093, 1093, 1113, 1093, 1216, 957, 957, 1635, 1662,
163879 /* 80 */ 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662,
163880 /* 90 */ 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662,
163881 /* 100 */ 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662,
163882 /* 110 */ 1662, 1662, 1662, 1662, 1777, 1662, 1662, 1662, 1662, 1662,
163883 /* 120 */ 1662, 1662, 1662, 1662, 1662, 1662, 1662, 1662, 137, 181,
163884 /* 130 */ 181, 181, 181, 181, 94, 430, 66, 65, 112, 366,
163885 /* 140 */ 533, 533, 740, 1261, 533, 533, 79, 79, 533, 412,
163886 /* 150 */ 412, 412, 77, 412, 123, 113, 113, 22, 22, 2064,
163887 /* 160 */ 2064, 328, 328, 328, 239, 468, 468, 468, 468, 1015,
163888 /* 170 */ 1015, 409, 366, 1129, 1186, 533, 533, 533, 533, 533,
163889 /* 180 */ 533, 533, 533, 533, 533, 533, 533, 533, 533, 533,
163890 /* 190 */ 533, 533, 533, 533, 533, 969, 621, 621, 533, 642,
163891 /* 200 */ 788, 788, 1228, 1228, 822, 822, 67, 1274, 2064, 2064,
163892 /* 210 */ 2064, 2064, 2064, 2064, 2064, 1307, 954, 954, 585, 472,
163893 /* 220 */ 640, 387, 695, 538, 541, 700, 533, 533, 533, 533,
163894 /* 230 */ 533, 533, 533, 533, 533, 533, 222, 533, 533, 533,
163895 /* 240 */ 533, 533, 533, 533, 533, 533, 533, 533, 533, 1179,
163896 /* 250 */ 1179, 1179, 533, 533, 533, 565, 533, 533, 533, 916,
163897 /* 260 */ 1144, 533, 533, 1288, 533, 533, 533, 533, 533, 533,
163898 /* 270 */ 533, 533, 639, 1330, 209, 1076, 1076, 1076, 1076, 580,
163899 /* 280 */ 209, 209, 1313, 768, 917, 649, 1181, 1316, 405, 1316,
163900 /* 290 */ 1238, 249, 1181, 1181, 249, 1181, 405, 1238, 1369, 464,
163901 /* 300 */ 1259, 1012, 1012, 1012, 1368, 1368, 1368, 1368, 184, 184,
163902 /* 310 */ 1326, 904, 1287, 1480, 1703, 1703, 1625, 1625, 1729, 1729,
163903 /* 320 */ 1625, 1626, 1632, 1772, 1752, 1783, 1783, 1783, 1783, 1625,
163904 /* 330 */ 1788, 1659, 1632, 1632, 1659, 1772, 1752, 1659, 1752, 1659,
163905 /* 340 */ 1625, 1788, 1673, 1771, 1625, 1788, 1816, 1625, 1788, 1625,
163906 /* 350 */ 1788, 1816, 1731, 1731, 1731, 1780, 1827, 1827, 1816, 1731,
163907 /* 360 */ 1724, 1731, 1780, 1731, 1731, 1688, 1833, 1745, 1745, 1816,
163908 /* 370 */ 1625, 1776, 1776, 1792, 1792, 1732, 1734, 1859, 1625, 1728,
163909 /* 380 */ 1732, 1740, 1743, 1659, 1865, 1883, 1883, 1891, 1891, 1891,
163910 /* 390 */ 2064, 2064, 2064, 2064, 2064, 2064, 2064, 2064, 2064, 2064,
163911 /* 400 */ 2064, 2064, 2064, 2064, 2064, 207, 1095, 331, 620, 903,
163912 /* 410 */ 806, 1074, 1483, 1432, 1481, 1322, 1370, 1394, 1515, 1291,
163913 /* 420 */ 1546, 1547, 1557, 1595, 1598, 1599, 1434, 1453, 1618, 1462,
163914 /* 430 */ 1567, 1489, 1644, 1645, 1589, 1654, 1530, 1538, 1672, 1676,
163915 /* 440 */ 1579, 742, 1914, 1920, 1902, 1762, 1911, 1919, 1913, 1915,
163916 /* 450 */ 1798, 1789, 1809, 1916, 1916, 1918, 1801, 1924, 1802, 1929,
163917 /* 460 */ 1946, 1806, 1819, 1916, 1820, 1890, 1917, 1916, 1804, 1899,
163918 /* 470 */ 1900, 1903, 1904, 1828, 1843, 1926, 1821, 1960, 1958, 1942,
163919 /* 480 */ 1850, 1805, 1901, 1943, 1905, 1892, 1930, 1829, 1857, 1950,
163920 /* 490 */ 1955, 1957, 1846, 1853, 1959, 1912, 1961, 1962, 1963, 1965,
163921 /* 500 */ 1921, 1923, 1956, 1889, 1964, 1967, 1927, 1953, 1968, 1844,
163922 /* 510 */ 1973, 1974, 1975, 1976, 1971, 1977, 1979, 1906, 1861, 1981,
163923 /* 520 */ 1982, 1893, 1972, 1985, 1867, 1983, 1978, 1980, 1984, 1986,
163924 /* 530 */ 1925, 1936, 1931, 1987, 1940, 1928, 1988, 1993, 1997, 1999,
163925 /* 540 */ 2000, 2001, 1990, 2004, 1983, 2005, 2006, 2007, 2009, 2008,
163926 /* 550 */ 2011, 2013, 2025, 2015, 2016, 2017, 2018, 2020, 2021, 2014,
163927 /* 560 */ 1909, 1907, 1908, 1910, 1922, 2022, 2023, 2030, 2049, 2051,
 
163928 };
163929 #define YY_REDUCE_COUNT (404)
163930 #define YY_REDUCE_MIN (-271)
163931 #define YY_REDUCE_MAX (1716)
163932 static const short yy_reduce_ofst[] = {
163933 /* 0 */ -125, 733, 789, 241, 293, -123, -193, -191, -183, -187,
163934 /* 10 */ 166, 238, 133, -207, -199, -267, -176, -6, 204, 489,
163935 /* 20 */ 576, -175, 598, 686, 615, 725, 860, 778, 781, 857,
163936 /* 30 */ 616, 887, 87, 240, -192, 408, 626, 796, 843, 854,
@@ -163940,98 +164354,99 @@
163940 /* 70 */ -271, -271, -271, -271, -271, -271, -271, -271, 80, 83,
163941 /* 80 */ 313, 886, 888, 996, 1034, 1059, 1081, 1100, 1117, 1152,
163942 /* 90 */ 1155, 1163, 1165, 1167, 1169, 1172, 1180, 1182, 1184, 1198,
163943 /* 100 */ 1200, 1213, 1215, 1225, 1227, 1252, 1254, 1264, 1299, 1303,
163944 /* 110 */ 1308, 1312, 1325, 1328, 1337, 1340, 1343, 1371, 1373, 1384,
163945 /* 120 */ 1386, 1411, 1420, 1424, 1426, 1458, 1470, 1473, -271, -271,
163946 /* 130 */ -271, -271, -271, -271, -271, -271, -271, 138, 459, 396,
163947 /* 140 */ -158, 470, 302, -212, 521, 201, -195, -92, 559, 630,
163948 /* 150 */ 632, 630, -271, 632, 901, 63, 407, -271, -271, -271,
163949 /* 160 */ -271, 161, 161, 161, 251, 335, 847, 960, 980, 537,
163950 /* 170 */ 588, 618, 628, 688, 688, -166, -161, 674, 790, 794,
163951 /* 180 */ 799, 851, 852, -122, 680, -120, 995, 1038, 415, 1051,
163952 /* 190 */ 893, 798, 962, 400, 1086, 779, 923, 924, 263, 1041,
163953 /* 200 */ 979, 990, 1083, 1097, 1031, 1194, 362, 994, 1139, 1005,
163954 /* 210 */ 1037, 1202, 1205, 1195, 1210, -194, 56, 185, -135, 232,
163955 /* 220 */ 522, 560, 601, 617, 669, 683, 711, 856, 908, 941,
163956 /* 230 */ 1048, 1101, 1147, 1257, 1262, 1265, 392, 1292, 1333, 1339,
163957 /* 240 */ 1342, 1346, 1350, 1359, 1374, 1418, 1421, 1436, 1437, 593,
163958 /* 250 */ 755, 770, 997, 1459, 1463, 1209, 1499, 1507, 1509, 1132,
163959 /* 260 */ 1243, 1510, 1511, 1440, 1512, 560, 1514, 1516, 1517, 1518,
163960 /* 270 */ 1519, 1520, 1427, 1429, 1466, 1464, 1465, 1467, 1468, 1209,
163961 /* 280 */ 1466, 1466, 1471, 1503, 1533, 1428, 1456, 1461, 1485, 1469,
163962 /* 290 */ 1438, 1486, 1474, 1476, 1488, 1479, 1492, 1445, 1524, 1525,
163963 /* 300 */ 1523, 1521, 1536, 1539, 1498, 1500, 1501, 1502, 1490, 1522,
163964 /* 310 */ 1484, 1527, 1531, 1569, 1487, 1496, 1570, 1573, 1504, 1506,
163965 /* 320 */ 1575, 1526, 1513, 1532, 1571, 1566, 1574, 1577, 1583, 1604,
163966 /* 330 */ 1608, 1576, 1540, 1549, 1578, 1553, 1591, 1580, 1593, 1582,
163967 /* 340 */ 1629, 1631, 1542, 1545, 1637, 1636, 1619, 1639, 1642, 1643,
163968 /* 350 */ 1646, 1621, 1633, 1634, 1638, 1620, 1630, 1640, 1641, 1647,
163969 /* 360 */ 1649, 1650, 1628, 1652, 1653, 1548, 1554, 1581, 1584, 1651,
163970 /* 370 */ 1661, 1556, 1558, 1611, 1613, 1655, 1657, 1605, 1685, 1609,
163971 /* 380 */ 1658, 1656, 1660, 1663, 1690, 1705, 1706, 1709, 1710, 1711,
163972 /* 390 */ 1607, 1610, 1612, 1704, 1701, 1702, 1707, 1708, 1712, 1694,
163973 /* 400 */ 1695, 1713, 1714, 1716, 1715,
163974 };
163975 static const YYACTIONTYPE yy_default[] = {
163976 /* 0 */ 1637, 1637, 1637, 1465, 1232, 1343, 1232, 1232, 1232, 1465,
163977 /* 10 */ 1465, 1465, 1232, 1373, 1373, 1518, 1265, 1232, 1232, 1232,
163978 /* 20 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1464, 1232, 1232,
163979 /* 30 */ 1232, 1232, 1553, 1553, 1232, 1232, 1232, 1232, 1232, 1232,
163980 /* 40 */ 1232, 1232, 1382, 1232, 1389, 1232, 1232, 1232, 1232, 1232,
163981 /* 50 */ 1466, 1467, 1232, 1232, 1232, 1517, 1519, 1482, 1396, 1395,
163982 /* 60 */ 1394, 1393, 1500, 1361, 1387, 1380, 1384, 1460, 1461, 1459,
163983 /* 70 */ 1463, 1467, 1466, 1232, 1383, 1430, 1444, 1429, 1232, 1232,
163984 /* 80 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
163985 /* 90 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
163986 /* 100 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
163987 /* 110 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
163988 /* 120 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1438, 1443,
163989 /* 130 */ 1450, 1442, 1439, 1432, 1431, 1433, 1434, 1232, 1232, 1256,
163990 /* 140 */ 1232, 1232, 1253, 1307, 1232, 1232, 1232, 1232, 1232, 1537,
163991 /* 150 */ 1536, 1232, 1435, 1232, 1265, 1424, 1423, 1447, 1436, 1446,
163992 /* 160 */ 1445, 1525, 1589, 1588, 1483, 1232, 1232, 1232, 1232, 1232,
163993 /* 170 */ 1232, 1553, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
163994 /* 180 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
163995 /* 190 */ 1232, 1232, 1232, 1232, 1232, 1363, 1553, 1553, 1232, 1265,
163996 /* 200 */ 1553, 1553, 1364, 1364, 1261, 1261, 1367, 1232, 1532, 1334,
163997 /* 210 */ 1334, 1334, 1334, 1343, 1334, 1232, 1232, 1232, 1232, 1232,
163998 /* 220 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
163999 /* 230 */ 1522, 1520, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
164000 /* 240 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
164001 /* 250 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1339,
164002 /* 260 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
164003 /* 270 */ 1232, 1582, 1232, 1495, 1321, 1339, 1339, 1339, 1339, 1341,
164004 /* 280 */ 1322, 1320, 1333, 1266, 1239, 1629, 1399, 1388, 1340, 1388,
164005 /* 290 */ 1626, 1386, 1399, 1399, 1386, 1399, 1340, 1626, 1282, 1605,
164006 /* 300 */ 1277, 1373, 1373, 1373, 1363, 1363, 1363, 1363, 1367, 1367,
164007 /* 310 */ 1462, 1340, 1333, 1232, 1629, 1629, 1349, 1349, 1628, 1628,
164008 /* 320 */ 1349, 1483, 1613, 1408, 1310, 1316, 1316, 1316, 1316, 1349,
164009 /* 330 */ 1250, 1386, 1613, 1613, 1386, 1408, 1310, 1386, 1310, 1386,
164010 /* 340 */ 1349, 1250, 1499, 1623, 1349, 1250, 1473, 1349, 1250, 1349,
164011 /* 350 */ 1250, 1473, 1308, 1308, 1308, 1297, 1232, 1232, 1473, 1308,
164012 /* 360 */ 1282, 1308, 1297, 1308, 1308, 1571, 1232, 1477, 1477, 1473,
164013 /* 370 */ 1349, 1563, 1563, 1376, 1376, 1381, 1367, 1468, 1349, 1232,
164014 /* 380 */ 1381, 1379, 1377, 1386, 1300, 1585, 1585, 1581, 1581, 1581,
164015 /* 390 */ 1634, 1634, 1532, 1598, 1265, 1265, 1265, 1265, 1598, 1284,
164016 /* 400 */ 1284, 1266, 1266, 1265, 1598, 1232, 1232, 1232, 1232, 1232,
164017 /* 410 */ 1232, 1593, 1232, 1527, 1484, 1353, 1232, 1232, 1232, 1232,
164018 /* 420 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
164019 /* 430 */ 1538, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
164020 /* 440 */ 1232, 1413, 1232, 1235, 1529, 1232, 1232, 1232, 1232, 1232,
164021 /* 450 */ 1232, 1232, 1232, 1390, 1391, 1354, 1232, 1232, 1232, 1232,
164022 /* 460 */ 1232, 1232, 1232, 1405, 1232, 1232, 1232, 1400, 1232, 1232,
164023 /* 470 */ 1232, 1232, 1232, 1232, 1232, 1232, 1625, 1232, 1232, 1232,
164024 /* 480 */ 1232, 1232, 1232, 1498, 1497, 1232, 1232, 1351, 1232, 1232,
164025 /* 490 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
164026 /* 500 */ 1232, 1280, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
164027 /* 510 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
164028 /* 520 */ 1232, 1232, 1232, 1232, 1232, 1378, 1232, 1232, 1232, 1232,
164029 /* 530 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232,
164030 /* 540 */ 1568, 1368, 1232, 1232, 1616, 1232, 1232, 1232, 1232, 1232,
164031 /* 550 */ 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1232, 1609,
164032 /* 560 */ 1324, 1415, 1232, 1414, 1418, 1254, 1232, 1244, 1232, 1232,
 
164033 };
164034 /********** End of lemon-generated parsing tables *****************************/
164035
164036 /* The next table maps tokens (terminal symbols) into fallback tokens.
164037 ** If a construct like the following:
@@ -164855,204 +165270,206 @@
164855 /* 204 */ "expr ::= expr likeop expr ESCAPE expr",
164856 /* 205 */ "expr ::= expr ISNULL|NOTNULL",
164857 /* 206 */ "expr ::= expr NOT NULL",
164858 /* 207 */ "expr ::= expr IS expr",
164859 /* 208 */ "expr ::= expr IS NOT expr",
164860 /* 209 */ "expr ::= NOT expr",
164861 /* 210 */ "expr ::= BITNOT expr",
164862 /* 211 */ "expr ::= PLUS|MINUS expr",
164863 /* 212 */ "expr ::= expr PTR expr",
164864 /* 213 */ "between_op ::= BETWEEN",
164865 /* 214 */ "between_op ::= NOT BETWEEN",
164866 /* 215 */ "expr ::= expr between_op expr AND expr",
164867 /* 216 */ "in_op ::= IN",
164868 /* 217 */ "in_op ::= NOT IN",
164869 /* 218 */ "expr ::= expr in_op LP exprlist RP",
164870 /* 219 */ "expr ::= LP select RP",
164871 /* 220 */ "expr ::= expr in_op LP select RP",
164872 /* 221 */ "expr ::= expr in_op nm dbnm paren_exprlist",
164873 /* 222 */ "expr ::= EXISTS LP select RP",
164874 /* 223 */ "expr ::= CASE case_operand case_exprlist case_else END",
164875 /* 224 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
164876 /* 225 */ "case_exprlist ::= WHEN expr THEN expr",
164877 /* 226 */ "case_else ::= ELSE expr",
164878 /* 227 */ "case_else ::=",
164879 /* 228 */ "case_operand ::= expr",
164880 /* 229 */ "case_operand ::=",
164881 /* 230 */ "exprlist ::=",
164882 /* 231 */ "nexprlist ::= nexprlist COMMA expr",
164883 /* 232 */ "nexprlist ::= expr",
164884 /* 233 */ "paren_exprlist ::=",
164885 /* 234 */ "paren_exprlist ::= LP exprlist RP",
164886 /* 235 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt",
164887 /* 236 */ "uniqueflag ::= UNIQUE",
164888 /* 237 */ "uniqueflag ::=",
164889 /* 238 */ "eidlist_opt ::=",
164890 /* 239 */ "eidlist_opt ::= LP eidlist RP",
164891 /* 240 */ "eidlist ::= eidlist COMMA nm collate sortorder",
164892 /* 241 */ "eidlist ::= nm collate sortorder",
164893 /* 242 */ "collate ::=",
164894 /* 243 */ "collate ::= COLLATE ID|STRING",
164895 /* 244 */ "cmd ::= DROP INDEX ifexists fullname",
164896 /* 245 */ "cmd ::= VACUUM vinto",
164897 /* 246 */ "cmd ::= VACUUM nm vinto",
164898 /* 247 */ "vinto ::= INTO expr",
164899 /* 248 */ "vinto ::=",
164900 /* 249 */ "cmd ::= PRAGMA nm dbnm",
164901 /* 250 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
164902 /* 251 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
164903 /* 252 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
164904 /* 253 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
164905 /* 254 */ "plus_num ::= PLUS INTEGER|FLOAT",
164906 /* 255 */ "minus_num ::= MINUS INTEGER|FLOAT",
164907 /* 256 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
164908 /* 257 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
164909 /* 258 */ "trigger_time ::= BEFORE|AFTER",
164910 /* 259 */ "trigger_time ::= INSTEAD OF",
164911 /* 260 */ "trigger_time ::=",
164912 /* 261 */ "trigger_event ::= DELETE|INSERT",
164913 /* 262 */ "trigger_event ::= UPDATE",
164914 /* 263 */ "trigger_event ::= UPDATE OF idlist",
164915 /* 264 */ "when_clause ::=",
164916 /* 265 */ "when_clause ::= WHEN expr",
164917 /* 266 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
164918 /* 267 */ "trigger_cmd_list ::= trigger_cmd SEMI",
164919 /* 268 */ "trnm ::= nm DOT nm",
164920 /* 269 */ "tridxby ::= INDEXED BY nm",
164921 /* 270 */ "tridxby ::= NOT INDEXED",
164922 /* 271 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt",
164923 /* 272 */ "trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt",
164924 /* 273 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt",
164925 /* 274 */ "trigger_cmd ::= scanpt select scanpt",
164926 /* 275 */ "expr ::= RAISE LP IGNORE RP",
164927 /* 276 */ "expr ::= RAISE LP raisetype COMMA nm RP",
164928 /* 277 */ "raisetype ::= ROLLBACK",
164929 /* 278 */ "raisetype ::= ABORT",
164930 /* 279 */ "raisetype ::= FAIL",
164931 /* 280 */ "cmd ::= DROP TRIGGER ifexists fullname",
164932 /* 281 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
164933 /* 282 */ "cmd ::= DETACH database_kw_opt expr",
164934 /* 283 */ "key_opt ::=",
164935 /* 284 */ "key_opt ::= KEY expr",
164936 /* 285 */ "cmd ::= REINDEX",
164937 /* 286 */ "cmd ::= REINDEX nm dbnm",
164938 /* 287 */ "cmd ::= ANALYZE",
164939 /* 288 */ "cmd ::= ANALYZE nm dbnm",
164940 /* 289 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
164941 /* 290 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist",
164942 /* 291 */ "cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm",
164943 /* 292 */ "add_column_fullname ::= fullname",
164944 /* 293 */ "cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm",
164945 /* 294 */ "cmd ::= create_vtab",
164946 /* 295 */ "cmd ::= create_vtab LP vtabarglist RP",
164947 /* 296 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
164948 /* 297 */ "vtabarg ::=",
164949 /* 298 */ "vtabargtoken ::= ANY",
164950 /* 299 */ "vtabargtoken ::= lp anylist RP",
164951 /* 300 */ "lp ::= LP",
164952 /* 301 */ "with ::= WITH wqlist",
164953 /* 302 */ "with ::= WITH RECURSIVE wqlist",
164954 /* 303 */ "wqas ::= AS",
164955 /* 304 */ "wqas ::= AS MATERIALIZED",
164956 /* 305 */ "wqas ::= AS NOT MATERIALIZED",
164957 /* 306 */ "wqitem ::= nm eidlist_opt wqas LP select RP",
164958 /* 307 */ "wqlist ::= wqitem",
164959 /* 308 */ "wqlist ::= wqlist COMMA wqitem",
164960 /* 309 */ "windowdefn_list ::= windowdefn",
164961 /* 310 */ "windowdefn_list ::= windowdefn_list COMMA windowdefn",
164962 /* 311 */ "windowdefn ::= nm AS LP window RP",
164963 /* 312 */ "window ::= PARTITION BY nexprlist orderby_opt frame_opt",
164964 /* 313 */ "window ::= nm PARTITION BY nexprlist orderby_opt frame_opt",
164965 /* 314 */ "window ::= ORDER BY sortlist frame_opt",
164966 /* 315 */ "window ::= nm ORDER BY sortlist frame_opt",
164967 /* 316 */ "window ::= frame_opt",
164968 /* 317 */ "window ::= nm frame_opt",
164969 /* 318 */ "frame_opt ::=",
164970 /* 319 */ "frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt",
164971 /* 320 */ "frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt",
164972 /* 321 */ "range_or_rows ::= RANGE|ROWS|GROUPS",
164973 /* 322 */ "frame_bound_s ::= frame_bound",
164974 /* 323 */ "frame_bound_s ::= UNBOUNDED PRECEDING",
164975 /* 324 */ "frame_bound_e ::= frame_bound",
164976 /* 325 */ "frame_bound_e ::= UNBOUNDED FOLLOWING",
164977 /* 326 */ "frame_bound ::= expr PRECEDING|FOLLOWING",
164978 /* 327 */ "frame_bound ::= CURRENT ROW",
164979 /* 328 */ "frame_exclude_opt ::=",
164980 /* 329 */ "frame_exclude_opt ::= EXCLUDE frame_exclude",
164981 /* 330 */ "frame_exclude ::= NO OTHERS",
164982 /* 331 */ "frame_exclude ::= CURRENT ROW",
164983 /* 332 */ "frame_exclude ::= GROUP|TIES",
164984 /* 333 */ "window_clause ::= WINDOW windowdefn_list",
164985 /* 334 */ "filter_over ::= filter_clause over_clause",
164986 /* 335 */ "filter_over ::= over_clause",
164987 /* 336 */ "filter_over ::= filter_clause",
164988 /* 337 */ "over_clause ::= OVER LP window RP",
164989 /* 338 */ "over_clause ::= OVER nm",
164990 /* 339 */ "filter_clause ::= FILTER LP WHERE expr RP",
164991 /* 340 */ "input ::= cmdlist",
164992 /* 341 */ "cmdlist ::= cmdlist ecmd",
164993 /* 342 */ "cmdlist ::= ecmd",
164994 /* 343 */ "ecmd ::= SEMI",
164995 /* 344 */ "ecmd ::= cmdx SEMI",
164996 /* 345 */ "ecmd ::= explain cmdx SEMI",
164997 /* 346 */ "trans_opt ::=",
164998 /* 347 */ "trans_opt ::= TRANSACTION",
164999 /* 348 */ "trans_opt ::= TRANSACTION nm",
165000 /* 349 */ "savepoint_opt ::= SAVEPOINT",
165001 /* 350 */ "savepoint_opt ::=",
165002 /* 351 */ "cmd ::= create_table create_table_args",
165003 /* 352 */ "table_option_set ::= table_option",
165004 /* 353 */ "columnlist ::= columnlist COMMA columnname carglist",
165005 /* 354 */ "columnlist ::= columnname carglist",
165006 /* 355 */ "nm ::= ID|INDEXED",
165007 /* 356 */ "nm ::= STRING",
165008 /* 357 */ "nm ::= JOIN_KW",
165009 /* 358 */ "typetoken ::= typename",
165010 /* 359 */ "typename ::= ID|STRING",
165011 /* 360 */ "signed ::= plus_num",
165012 /* 361 */ "signed ::= minus_num",
165013 /* 362 */ "carglist ::= carglist ccons",
165014 /* 363 */ "carglist ::=",
165015 /* 364 */ "ccons ::= NULL onconf",
165016 /* 365 */ "ccons ::= GENERATED ALWAYS AS generated",
165017 /* 366 */ "ccons ::= AS generated",
165018 /* 367 */ "conslist_opt ::= COMMA conslist",
165019 /* 368 */ "conslist ::= conslist tconscomma tcons",
165020 /* 369 */ "conslist ::= tcons",
165021 /* 370 */ "tconscomma ::=",
165022 /* 371 */ "defer_subclause_opt ::= defer_subclause",
165023 /* 372 */ "resolvetype ::= raisetype",
165024 /* 373 */ "selectnowith ::= oneselect",
165025 /* 374 */ "oneselect ::= values",
165026 /* 375 */ "sclp ::= selcollist COMMA",
165027 /* 376 */ "as ::= ID|STRING",
165028 /* 377 */ "indexed_opt ::= indexed_by",
165029 /* 378 */ "returning ::=",
165030 /* 379 */ "expr ::= term",
165031 /* 380 */ "likeop ::= LIKE_KW|MATCH",
165032 /* 381 */ "exprlist ::= nexprlist",
165033 /* 382 */ "nmnum ::= plus_num",
165034 /* 383 */ "nmnum ::= nm",
165035 /* 384 */ "nmnum ::= ON",
165036 /* 385 */ "nmnum ::= DELETE",
165037 /* 386 */ "nmnum ::= DEFAULT",
165038 /* 387 */ "plus_num ::= INTEGER|FLOAT",
165039 /* 388 */ "foreach_clause ::=",
165040 /* 389 */ "foreach_clause ::= FOR EACH ROW",
165041 /* 390 */ "trnm ::= nm",
165042 /* 391 */ "tridxby ::=",
165043 /* 392 */ "database_kw_opt ::= DATABASE",
165044 /* 393 */ "database_kw_opt ::=",
165045 /* 394 */ "kwcolumn_opt ::=",
165046 /* 395 */ "kwcolumn_opt ::= COLUMNKW",
165047 /* 396 */ "vtabarglist ::= vtabarg",
165048 /* 397 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
165049 /* 398 */ "vtabarg ::= vtabarg vtabargtoken",
165050 /* 399 */ "anylist ::=",
165051 /* 400 */ "anylist ::= anylist LP anylist RP",
165052 /* 401 */ "anylist ::= anylist ANY",
165053 /* 402 */ "with ::=",
 
 
165054 };
165055 #endif /* NDEBUG */
165056
165057
165058 #if YYSTACKDEPTH<=0
@@ -165764,204 +166181,206 @@
165764 217, /* (204) expr ::= expr likeop expr ESCAPE expr */
165765 217, /* (205) expr ::= expr ISNULL|NOTNULL */
165766 217, /* (206) expr ::= expr NOT NULL */
165767 217, /* (207) expr ::= expr IS expr */
165768 217, /* (208) expr ::= expr IS NOT expr */
165769 217, /* (209) expr ::= NOT expr */
165770 217, /* (210) expr ::= BITNOT expr */
165771 217, /* (211) expr ::= PLUS|MINUS expr */
165772 217, /* (212) expr ::= expr PTR expr */
165773 275, /* (213) between_op ::= BETWEEN */
165774 275, /* (214) between_op ::= NOT BETWEEN */
165775 217, /* (215) expr ::= expr between_op expr AND expr */
165776 276, /* (216) in_op ::= IN */
165777 276, /* (217) in_op ::= NOT IN */
165778 217, /* (218) expr ::= expr in_op LP exprlist RP */
165779 217, /* (219) expr ::= LP select RP */
165780 217, /* (220) expr ::= expr in_op LP select RP */
165781 217, /* (221) expr ::= expr in_op nm dbnm paren_exprlist */
165782 217, /* (222) expr ::= EXISTS LP select RP */
165783 217, /* (223) expr ::= CASE case_operand case_exprlist case_else END */
165784 279, /* (224) case_exprlist ::= case_exprlist WHEN expr THEN expr */
165785 279, /* (225) case_exprlist ::= WHEN expr THEN expr */
165786 280, /* (226) case_else ::= ELSE expr */
165787 280, /* (227) case_else ::= */
165788 278, /* (228) case_operand ::= expr */
165789 278, /* (229) case_operand ::= */
165790 261, /* (230) exprlist ::= */
165791 253, /* (231) nexprlist ::= nexprlist COMMA expr */
165792 253, /* (232) nexprlist ::= expr */
165793 277, /* (233) paren_exprlist ::= */
165794 277, /* (234) paren_exprlist ::= LP exprlist RP */
165795 190, /* (235) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
165796 281, /* (236) uniqueflag ::= UNIQUE */
165797 281, /* (237) uniqueflag ::= */
165798 221, /* (238) eidlist_opt ::= */
165799 221, /* (239) eidlist_opt ::= LP eidlist RP */
165800 232, /* (240) eidlist ::= eidlist COMMA nm collate sortorder */
165801 232, /* (241) eidlist ::= nm collate sortorder */
165802 282, /* (242) collate ::= */
165803 282, /* (243) collate ::= COLLATE ID|STRING */
165804 190, /* (244) cmd ::= DROP INDEX ifexists fullname */
165805 190, /* (245) cmd ::= VACUUM vinto */
165806 190, /* (246) cmd ::= VACUUM nm vinto */
165807 283, /* (247) vinto ::= INTO expr */
165808 283, /* (248) vinto ::= */
165809 190, /* (249) cmd ::= PRAGMA nm dbnm */
165810 190, /* (250) cmd ::= PRAGMA nm dbnm EQ nmnum */
165811 190, /* (251) cmd ::= PRAGMA nm dbnm LP nmnum RP */
165812 190, /* (252) cmd ::= PRAGMA nm dbnm EQ minus_num */
165813 190, /* (253) cmd ::= PRAGMA nm dbnm LP minus_num RP */
165814 211, /* (254) plus_num ::= PLUS INTEGER|FLOAT */
165815 212, /* (255) minus_num ::= MINUS INTEGER|FLOAT */
165816 190, /* (256) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
165817 285, /* (257) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
165818 287, /* (258) trigger_time ::= BEFORE|AFTER */
165819 287, /* (259) trigger_time ::= INSTEAD OF */
165820 287, /* (260) trigger_time ::= */
165821 288, /* (261) trigger_event ::= DELETE|INSERT */
165822 288, /* (262) trigger_event ::= UPDATE */
165823 288, /* (263) trigger_event ::= UPDATE OF idlist */
165824 290, /* (264) when_clause ::= */
165825 290, /* (265) when_clause ::= WHEN expr */
165826 286, /* (266) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
165827 286, /* (267) trigger_cmd_list ::= trigger_cmd SEMI */
165828 292, /* (268) trnm ::= nm DOT nm */
165829 293, /* (269) tridxby ::= INDEXED BY nm */
165830 293, /* (270) tridxby ::= NOT INDEXED */
165831 291, /* (271) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
165832 291, /* (272) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
165833 291, /* (273) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
165834 291, /* (274) trigger_cmd ::= scanpt select scanpt */
165835 217, /* (275) expr ::= RAISE LP IGNORE RP */
165836 217, /* (276) expr ::= RAISE LP raisetype COMMA nm RP */
165837 236, /* (277) raisetype ::= ROLLBACK */
165838 236, /* (278) raisetype ::= ABORT */
165839 236, /* (279) raisetype ::= FAIL */
165840 190, /* (280) cmd ::= DROP TRIGGER ifexists fullname */
165841 190, /* (281) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
165842 190, /* (282) cmd ::= DETACH database_kw_opt expr */
165843 295, /* (283) key_opt ::= */
165844 295, /* (284) key_opt ::= KEY expr */
165845 190, /* (285) cmd ::= REINDEX */
165846 190, /* (286) cmd ::= REINDEX nm dbnm */
165847 190, /* (287) cmd ::= ANALYZE */
165848 190, /* (288) cmd ::= ANALYZE nm dbnm */
165849 190, /* (289) cmd ::= ALTER TABLE fullname RENAME TO nm */
165850 190, /* (290) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
165851 190, /* (291) cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
165852 296, /* (292) add_column_fullname ::= fullname */
165853 190, /* (293) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
165854 190, /* (294) cmd ::= create_vtab */
165855 190, /* (295) cmd ::= create_vtab LP vtabarglist RP */
165856 298, /* (296) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
165857 300, /* (297) vtabarg ::= */
165858 301, /* (298) vtabargtoken ::= ANY */
165859 301, /* (299) vtabargtoken ::= lp anylist RP */
165860 302, /* (300) lp ::= LP */
165861 266, /* (301) with ::= WITH wqlist */
165862 266, /* (302) with ::= WITH RECURSIVE wqlist */
165863 305, /* (303) wqas ::= AS */
165864 305, /* (304) wqas ::= AS MATERIALIZED */
165865 305, /* (305) wqas ::= AS NOT MATERIALIZED */
165866 304, /* (306) wqitem ::= nm eidlist_opt wqas LP select RP */
165867 241, /* (307) wqlist ::= wqitem */
165868 241, /* (308) wqlist ::= wqlist COMMA wqitem */
165869 306, /* (309) windowdefn_list ::= windowdefn */
165870 306, /* (310) windowdefn_list ::= windowdefn_list COMMA windowdefn */
165871 307, /* (311) windowdefn ::= nm AS LP window RP */
165872 308, /* (312) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
165873 308, /* (313) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
165874 308, /* (314) window ::= ORDER BY sortlist frame_opt */
165875 308, /* (315) window ::= nm ORDER BY sortlist frame_opt */
165876 308, /* (316) window ::= frame_opt */
165877 308, /* (317) window ::= nm frame_opt */
165878 309, /* (318) frame_opt ::= */
165879 309, /* (319) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
165880 309, /* (320) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
165881 313, /* (321) range_or_rows ::= RANGE|ROWS|GROUPS */
165882 315, /* (322) frame_bound_s ::= frame_bound */
165883 315, /* (323) frame_bound_s ::= UNBOUNDED PRECEDING */
165884 316, /* (324) frame_bound_e ::= frame_bound */
165885 316, /* (325) frame_bound_e ::= UNBOUNDED FOLLOWING */
165886 314, /* (326) frame_bound ::= expr PRECEDING|FOLLOWING */
165887 314, /* (327) frame_bound ::= CURRENT ROW */
165888 317, /* (328) frame_exclude_opt ::= */
165889 317, /* (329) frame_exclude_opt ::= EXCLUDE frame_exclude */
165890 318, /* (330) frame_exclude ::= NO OTHERS */
165891 318, /* (331) frame_exclude ::= CURRENT ROW */
165892 318, /* (332) frame_exclude ::= GROUP|TIES */
165893 251, /* (333) window_clause ::= WINDOW windowdefn_list */
165894 273, /* (334) filter_over ::= filter_clause over_clause */
165895 273, /* (335) filter_over ::= over_clause */
165896 273, /* (336) filter_over ::= filter_clause */
165897 312, /* (337) over_clause ::= OVER LP window RP */
165898 312, /* (338) over_clause ::= OVER nm */
165899 311, /* (339) filter_clause ::= FILTER LP WHERE expr RP */
165900 185, /* (340) input ::= cmdlist */
165901 186, /* (341) cmdlist ::= cmdlist ecmd */
165902 186, /* (342) cmdlist ::= ecmd */
165903 187, /* (343) ecmd ::= SEMI */
165904 187, /* (344) ecmd ::= cmdx SEMI */
165905 187, /* (345) ecmd ::= explain cmdx SEMI */
165906 192, /* (346) trans_opt ::= */
165907 192, /* (347) trans_opt ::= TRANSACTION */
165908 192, /* (348) trans_opt ::= TRANSACTION nm */
165909 194, /* (349) savepoint_opt ::= SAVEPOINT */
165910 194, /* (350) savepoint_opt ::= */
165911 190, /* (351) cmd ::= create_table create_table_args */
165912 203, /* (352) table_option_set ::= table_option */
165913 201, /* (353) columnlist ::= columnlist COMMA columnname carglist */
165914 201, /* (354) columnlist ::= columnname carglist */
165915 193, /* (355) nm ::= ID|INDEXED */
165916 193, /* (356) nm ::= STRING */
165917 193, /* (357) nm ::= JOIN_KW */
165918 208, /* (358) typetoken ::= typename */
165919 209, /* (359) typename ::= ID|STRING */
165920 210, /* (360) signed ::= plus_num */
165921 210, /* (361) signed ::= minus_num */
165922 207, /* (362) carglist ::= carglist ccons */
165923 207, /* (363) carglist ::= */
165924 215, /* (364) ccons ::= NULL onconf */
165925 215, /* (365) ccons ::= GENERATED ALWAYS AS generated */
165926 215, /* (366) ccons ::= AS generated */
165927 202, /* (367) conslist_opt ::= COMMA conslist */
165928 228, /* (368) conslist ::= conslist tconscomma tcons */
165929 228, /* (369) conslist ::= tcons */
165930 229, /* (370) tconscomma ::= */
165931 233, /* (371) defer_subclause_opt ::= defer_subclause */
165932 235, /* (372) resolvetype ::= raisetype */
165933 239, /* (373) selectnowith ::= oneselect */
165934 240, /* (374) oneselect ::= values */
165935 254, /* (375) sclp ::= selcollist COMMA */
165936 255, /* (376) as ::= ID|STRING */
165937 264, /* (377) indexed_opt ::= indexed_by */
165938 272, /* (378) returning ::= */
165939 217, /* (379) expr ::= term */
165940 274, /* (380) likeop ::= LIKE_KW|MATCH */
165941 261, /* (381) exprlist ::= nexprlist */
165942 284, /* (382) nmnum ::= plus_num */
165943 284, /* (383) nmnum ::= nm */
165944 284, /* (384) nmnum ::= ON */
165945 284, /* (385) nmnum ::= DELETE */
165946 284, /* (386) nmnum ::= DEFAULT */
165947 211, /* (387) plus_num ::= INTEGER|FLOAT */
165948 289, /* (388) foreach_clause ::= */
165949 289, /* (389) foreach_clause ::= FOR EACH ROW */
165950 292, /* (390) trnm ::= nm */
165951 293, /* (391) tridxby ::= */
165952 294, /* (392) database_kw_opt ::= DATABASE */
165953 294, /* (393) database_kw_opt ::= */
165954 297, /* (394) kwcolumn_opt ::= */
165955 297, /* (395) kwcolumn_opt ::= COLUMNKW */
165956 299, /* (396) vtabarglist ::= vtabarg */
165957 299, /* (397) vtabarglist ::= vtabarglist COMMA vtabarg */
165958 300, /* (398) vtabarg ::= vtabarg vtabargtoken */
165959 303, /* (399) anylist ::= */
165960 303, /* (400) anylist ::= anylist LP anylist RP */
165961 303, /* (401) anylist ::= anylist ANY */
165962 266, /* (402) with ::= */
 
 
165963 };
165964
165965 /* For rule J, yyRuleInfoNRhs[J] contains the negative of the number
165966 ** of symbols on the right-hand side of that rule. */
165967 static const signed char yyRuleInfoNRhs[] = {
@@ -166172,204 +166591,206 @@
166172 -5, /* (204) expr ::= expr likeop expr ESCAPE expr */
166173 -2, /* (205) expr ::= expr ISNULL|NOTNULL */
166174 -3, /* (206) expr ::= expr NOT NULL */
166175 -3, /* (207) expr ::= expr IS expr */
166176 -4, /* (208) expr ::= expr IS NOT expr */
166177 -2, /* (209) expr ::= NOT expr */
166178 -2, /* (210) expr ::= BITNOT expr */
166179 -2, /* (211) expr ::= PLUS|MINUS expr */
166180 -3, /* (212) expr ::= expr PTR expr */
166181 -1, /* (213) between_op ::= BETWEEN */
166182 -2, /* (214) between_op ::= NOT BETWEEN */
166183 -5, /* (215) expr ::= expr between_op expr AND expr */
166184 -1, /* (216) in_op ::= IN */
166185 -2, /* (217) in_op ::= NOT IN */
166186 -5, /* (218) expr ::= expr in_op LP exprlist RP */
166187 -3, /* (219) expr ::= LP select RP */
166188 -5, /* (220) expr ::= expr in_op LP select RP */
166189 -5, /* (221) expr ::= expr in_op nm dbnm paren_exprlist */
166190 -4, /* (222) expr ::= EXISTS LP select RP */
166191 -5, /* (223) expr ::= CASE case_operand case_exprlist case_else END */
166192 -5, /* (224) case_exprlist ::= case_exprlist WHEN expr THEN expr */
166193 -4, /* (225) case_exprlist ::= WHEN expr THEN expr */
166194 -2, /* (226) case_else ::= ELSE expr */
166195 0, /* (227) case_else ::= */
166196 -1, /* (228) case_operand ::= expr */
166197 0, /* (229) case_operand ::= */
166198 0, /* (230) exprlist ::= */
166199 -3, /* (231) nexprlist ::= nexprlist COMMA expr */
166200 -1, /* (232) nexprlist ::= expr */
166201 0, /* (233) paren_exprlist ::= */
166202 -3, /* (234) paren_exprlist ::= LP exprlist RP */
166203 -12, /* (235) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
166204 -1, /* (236) uniqueflag ::= UNIQUE */
166205 0, /* (237) uniqueflag ::= */
166206 0, /* (238) eidlist_opt ::= */
166207 -3, /* (239) eidlist_opt ::= LP eidlist RP */
166208 -5, /* (240) eidlist ::= eidlist COMMA nm collate sortorder */
166209 -3, /* (241) eidlist ::= nm collate sortorder */
166210 0, /* (242) collate ::= */
166211 -2, /* (243) collate ::= COLLATE ID|STRING */
166212 -4, /* (244) cmd ::= DROP INDEX ifexists fullname */
166213 -2, /* (245) cmd ::= VACUUM vinto */
166214 -3, /* (246) cmd ::= VACUUM nm vinto */
166215 -2, /* (247) vinto ::= INTO expr */
166216 0, /* (248) vinto ::= */
166217 -3, /* (249) cmd ::= PRAGMA nm dbnm */
166218 -5, /* (250) cmd ::= PRAGMA nm dbnm EQ nmnum */
166219 -6, /* (251) cmd ::= PRAGMA nm dbnm LP nmnum RP */
166220 -5, /* (252) cmd ::= PRAGMA nm dbnm EQ minus_num */
166221 -6, /* (253) cmd ::= PRAGMA nm dbnm LP minus_num RP */
166222 -2, /* (254) plus_num ::= PLUS INTEGER|FLOAT */
166223 -2, /* (255) minus_num ::= MINUS INTEGER|FLOAT */
166224 -5, /* (256) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
166225 -11, /* (257) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
166226 -1, /* (258) trigger_time ::= BEFORE|AFTER */
166227 -2, /* (259) trigger_time ::= INSTEAD OF */
166228 0, /* (260) trigger_time ::= */
166229 -1, /* (261) trigger_event ::= DELETE|INSERT */
166230 -1, /* (262) trigger_event ::= UPDATE */
166231 -3, /* (263) trigger_event ::= UPDATE OF idlist */
166232 0, /* (264) when_clause ::= */
166233 -2, /* (265) when_clause ::= WHEN expr */
166234 -3, /* (266) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
166235 -2, /* (267) trigger_cmd_list ::= trigger_cmd SEMI */
166236 -3, /* (268) trnm ::= nm DOT nm */
166237 -3, /* (269) tridxby ::= INDEXED BY nm */
166238 -2, /* (270) tridxby ::= NOT INDEXED */
166239 -9, /* (271) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
166240 -8, /* (272) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
166241 -6, /* (273) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
166242 -3, /* (274) trigger_cmd ::= scanpt select scanpt */
166243 -4, /* (275) expr ::= RAISE LP IGNORE RP */
166244 -6, /* (276) expr ::= RAISE LP raisetype COMMA nm RP */
166245 -1, /* (277) raisetype ::= ROLLBACK */
166246 -1, /* (278) raisetype ::= ABORT */
166247 -1, /* (279) raisetype ::= FAIL */
166248 -4, /* (280) cmd ::= DROP TRIGGER ifexists fullname */
166249 -6, /* (281) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
166250 -3, /* (282) cmd ::= DETACH database_kw_opt expr */
166251 0, /* (283) key_opt ::= */
166252 -2, /* (284) key_opt ::= KEY expr */
166253 -1, /* (285) cmd ::= REINDEX */
166254 -3, /* (286) cmd ::= REINDEX nm dbnm */
166255 -1, /* (287) cmd ::= ANALYZE */
166256 -3, /* (288) cmd ::= ANALYZE nm dbnm */
166257 -6, /* (289) cmd ::= ALTER TABLE fullname RENAME TO nm */
166258 -7, /* (290) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
166259 -6, /* (291) cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
166260 -1, /* (292) add_column_fullname ::= fullname */
166261 -8, /* (293) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
166262 -1, /* (294) cmd ::= create_vtab */
166263 -4, /* (295) cmd ::= create_vtab LP vtabarglist RP */
166264 -8, /* (296) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
166265 0, /* (297) vtabarg ::= */
166266 -1, /* (298) vtabargtoken ::= ANY */
166267 -3, /* (299) vtabargtoken ::= lp anylist RP */
166268 -1, /* (300) lp ::= LP */
166269 -2, /* (301) with ::= WITH wqlist */
166270 -3, /* (302) with ::= WITH RECURSIVE wqlist */
166271 -1, /* (303) wqas ::= AS */
166272 -2, /* (304) wqas ::= AS MATERIALIZED */
166273 -3, /* (305) wqas ::= AS NOT MATERIALIZED */
166274 -6, /* (306) wqitem ::= nm eidlist_opt wqas LP select RP */
166275 -1, /* (307) wqlist ::= wqitem */
166276 -3, /* (308) wqlist ::= wqlist COMMA wqitem */
166277 -1, /* (309) windowdefn_list ::= windowdefn */
166278 -3, /* (310) windowdefn_list ::= windowdefn_list COMMA windowdefn */
166279 -5, /* (311) windowdefn ::= nm AS LP window RP */
166280 -5, /* (312) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
166281 -6, /* (313) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
166282 -4, /* (314) window ::= ORDER BY sortlist frame_opt */
166283 -5, /* (315) window ::= nm ORDER BY sortlist frame_opt */
166284 -1, /* (316) window ::= frame_opt */
166285 -2, /* (317) window ::= nm frame_opt */
166286 0, /* (318) frame_opt ::= */
166287 -3, /* (319) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
166288 -6, /* (320) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
166289 -1, /* (321) range_or_rows ::= RANGE|ROWS|GROUPS */
166290 -1, /* (322) frame_bound_s ::= frame_bound */
166291 -2, /* (323) frame_bound_s ::= UNBOUNDED PRECEDING */
166292 -1, /* (324) frame_bound_e ::= frame_bound */
166293 -2, /* (325) frame_bound_e ::= UNBOUNDED FOLLOWING */
166294 -2, /* (326) frame_bound ::= expr PRECEDING|FOLLOWING */
166295 -2, /* (327) frame_bound ::= CURRENT ROW */
166296 0, /* (328) frame_exclude_opt ::= */
166297 -2, /* (329) frame_exclude_opt ::= EXCLUDE frame_exclude */
166298 -2, /* (330) frame_exclude ::= NO OTHERS */
166299 -2, /* (331) frame_exclude ::= CURRENT ROW */
166300 -1, /* (332) frame_exclude ::= GROUP|TIES */
166301 -2, /* (333) window_clause ::= WINDOW windowdefn_list */
166302 -2, /* (334) filter_over ::= filter_clause over_clause */
166303 -1, /* (335) filter_over ::= over_clause */
166304 -1, /* (336) filter_over ::= filter_clause */
166305 -4, /* (337) over_clause ::= OVER LP window RP */
166306 -2, /* (338) over_clause ::= OVER nm */
166307 -5, /* (339) filter_clause ::= FILTER LP WHERE expr RP */
166308 -1, /* (340) input ::= cmdlist */
166309 -2, /* (341) cmdlist ::= cmdlist ecmd */
166310 -1, /* (342) cmdlist ::= ecmd */
166311 -1, /* (343) ecmd ::= SEMI */
166312 -2, /* (344) ecmd ::= cmdx SEMI */
166313 -3, /* (345) ecmd ::= explain cmdx SEMI */
166314 0, /* (346) trans_opt ::= */
166315 -1, /* (347) trans_opt ::= TRANSACTION */
166316 -2, /* (348) trans_opt ::= TRANSACTION nm */
166317 -1, /* (349) savepoint_opt ::= SAVEPOINT */
166318 0, /* (350) savepoint_opt ::= */
166319 -2, /* (351) cmd ::= create_table create_table_args */
166320 -1, /* (352) table_option_set ::= table_option */
166321 -4, /* (353) columnlist ::= columnlist COMMA columnname carglist */
166322 -2, /* (354) columnlist ::= columnname carglist */
166323 -1, /* (355) nm ::= ID|INDEXED */
166324 -1, /* (356) nm ::= STRING */
166325 -1, /* (357) nm ::= JOIN_KW */
166326 -1, /* (358) typetoken ::= typename */
166327 -1, /* (359) typename ::= ID|STRING */
166328 -1, /* (360) signed ::= plus_num */
166329 -1, /* (361) signed ::= minus_num */
166330 -2, /* (362) carglist ::= carglist ccons */
166331 0, /* (363) carglist ::= */
166332 -2, /* (364) ccons ::= NULL onconf */
166333 -4, /* (365) ccons ::= GENERATED ALWAYS AS generated */
166334 -2, /* (366) ccons ::= AS generated */
166335 -2, /* (367) conslist_opt ::= COMMA conslist */
166336 -3, /* (368) conslist ::= conslist tconscomma tcons */
166337 -1, /* (369) conslist ::= tcons */
166338 0, /* (370) tconscomma ::= */
166339 -1, /* (371) defer_subclause_opt ::= defer_subclause */
166340 -1, /* (372) resolvetype ::= raisetype */
166341 -1, /* (373) selectnowith ::= oneselect */
166342 -1, /* (374) oneselect ::= values */
166343 -2, /* (375) sclp ::= selcollist COMMA */
166344 -1, /* (376) as ::= ID|STRING */
166345 -1, /* (377) indexed_opt ::= indexed_by */
166346 0, /* (378) returning ::= */
166347 -1, /* (379) expr ::= term */
166348 -1, /* (380) likeop ::= LIKE_KW|MATCH */
166349 -1, /* (381) exprlist ::= nexprlist */
166350 -1, /* (382) nmnum ::= plus_num */
166351 -1, /* (383) nmnum ::= nm */
166352 -1, /* (384) nmnum ::= ON */
166353 -1, /* (385) nmnum ::= DELETE */
166354 -1, /* (386) nmnum ::= DEFAULT */
166355 -1, /* (387) plus_num ::= INTEGER|FLOAT */
166356 0, /* (388) foreach_clause ::= */
166357 -3, /* (389) foreach_clause ::= FOR EACH ROW */
166358 -1, /* (390) trnm ::= nm */
166359 0, /* (391) tridxby ::= */
166360 -1, /* (392) database_kw_opt ::= DATABASE */
166361 0, /* (393) database_kw_opt ::= */
166362 0, /* (394) kwcolumn_opt ::= */
166363 -1, /* (395) kwcolumn_opt ::= COLUMNKW */
166364 -1, /* (396) vtabarglist ::= vtabarg */
166365 -3, /* (397) vtabarglist ::= vtabarglist COMMA vtabarg */
166366 -2, /* (398) vtabarg ::= vtabarg vtabargtoken */
166367 0, /* (399) anylist ::= */
166368 -4, /* (400) anylist ::= anylist LP anylist RP */
166369 -2, /* (401) anylist ::= anylist ANY */
166370 0, /* (402) with ::= */
 
 
166371 };
166372
166373 static void yy_accept(yyParser*); /* Forward Declaration */
166374
166375 /*
@@ -166425,11 +166846,11 @@
166425 {yymsp[1].minor.yy394 = TK_DEFERRED;}
166426 break;
166427 case 5: /* transtype ::= DEFERRED */
166428 case 6: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==6);
166429 case 7: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==7);
166430 case 321: /* range_or_rows ::= RANGE|ROWS|GROUPS */ yytestcase(yyruleno==321);
166431 {yymsp[0].minor.yy394 = yymsp[0].major; /*A-overwrites-X*/}
166432 break;
166433 case 8: /* cmd ::= COMMIT|END trans_opt */
166434 case 9: /* cmd ::= ROLLBACK trans_opt */ yytestcase(yyruleno==9);
166435 {sqlite3EndTransaction(pParse,yymsp[-1].major);}
@@ -166462,11 +166883,11 @@
166462 case 47: /* autoinc ::= */ yytestcase(yyruleno==47);
166463 case 62: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==62);
166464 case 72: /* defer_subclause_opt ::= */ yytestcase(yyruleno==72);
166465 case 81: /* ifexists ::= */ yytestcase(yyruleno==81);
166466 case 98: /* distinct ::= */ yytestcase(yyruleno==98);
166467 case 242: /* collate ::= */ yytestcase(yyruleno==242);
166468 {yymsp[1].minor.yy394 = 0;}
166469 break;
166470 case 16: /* ifnotexists ::= IF NOT EXISTS */
166471 {yymsp[-2].minor.yy394 = 1;}
166472 break;
@@ -166646,13 +167067,13 @@
166646 case 171: /* insert_cmd ::= INSERT orconf */ yytestcase(yyruleno==171);
166647 {yymsp[-1].minor.yy394 = yymsp[0].minor.yy394;}
166648 break;
166649 case 63: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
166650 case 80: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==80);
166651 case 214: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==214);
166652 case 217: /* in_op ::= NOT IN */ yytestcase(yyruleno==217);
166653 case 243: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==243);
166654 {yymsp[-1].minor.yy394 = 1;}
166655 break;
166656 case 64: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
166657 {yymsp[-1].minor.yy394 = 0;}
166658 break;
@@ -166798,13 +167219,13 @@
166798 {yymsp[0].minor.yy394 = SF_All;}
166799 break;
166800 case 99: /* sclp ::= */
166801 case 132: /* orderby_opt ::= */ yytestcase(yyruleno==132);
166802 case 142: /* groupby_opt ::= */ yytestcase(yyruleno==142);
166803 case 230: /* exprlist ::= */ yytestcase(yyruleno==230);
166804 case 233: /* paren_exprlist ::= */ yytestcase(yyruleno==233);
166805 case 238: /* eidlist_opt ::= */ yytestcase(yyruleno==238);
166806 {yymsp[1].minor.yy322 = 0;}
166807 break;
166808 case 100: /* selcollist ::= sclp scanpt expr scanpt as */
166809 {
166810 yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy322, yymsp[-2].minor.yy528);
@@ -166826,12 +167247,12 @@
166826 yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, pDot);
166827 }
166828 break;
166829 case 103: /* as ::= AS nm */
166830 case 115: /* dbnm ::= DOT nm */ yytestcase(yyruleno==115);
166831 case 254: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==254);
166832 case 255: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==255);
166833 {yymsp[-1].minor.yy0 = yymsp[0].minor.yy0;}
166834 break;
166835 case 105: /* from ::= */
166836 case 108: /* stl_prefix ::= */ yytestcase(yyruleno==108);
166837 {yymsp[1].minor.yy131 = 0;}
@@ -166999,20 +167420,20 @@
166999 break;
167000 case 144: /* having_opt ::= */
167001 case 146: /* limit_opt ::= */ yytestcase(yyruleno==146);
167002 case 151: /* where_opt ::= */ yytestcase(yyruleno==151);
167003 case 153: /* where_opt_ret ::= */ yytestcase(yyruleno==153);
167004 case 227: /* case_else ::= */ yytestcase(yyruleno==227);
167005 case 229: /* case_operand ::= */ yytestcase(yyruleno==229);
167006 case 248: /* vinto ::= */ yytestcase(yyruleno==248);
167007 {yymsp[1].minor.yy528 = 0;}
167008 break;
167009 case 145: /* having_opt ::= HAVING expr */
167010 case 152: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==152);
167011 case 154: /* where_opt_ret ::= WHERE expr */ yytestcase(yyruleno==154);
167012 case 226: /* case_else ::= ELSE expr */ yytestcase(yyruleno==226);
167013 case 247: /* vinto ::= INTO expr */ yytestcase(yyruleno==247);
167014 {yymsp[-1].minor.yy528 = yymsp[0].minor.yy528;}
167015 break;
167016 case 147: /* limit_opt ::= LIMIT expr */
167017 {yymsp[-1].minor.yy528 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy528,0);}
167018 break;
@@ -167036,11 +167457,22 @@
167036 break;
167037 case 157: /* cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist from where_opt_ret */
167038 {
167039 sqlite3SrcListIndexedBy(pParse, yymsp[-5].minor.yy131, &yymsp[-4].minor.yy0);
167040 sqlite3ExprListCheckLength(pParse,yymsp[-2].minor.yy322,"set list");
167041 yymsp[-5].minor.yy131 = sqlite3SrcListAppendList(pParse, yymsp[-5].minor.yy131, yymsp[-1].minor.yy131);
 
 
 
 
 
 
 
 
 
 
 
167042 sqlite3Update(pParse,yymsp[-5].minor.yy131,yymsp[-2].minor.yy322,yymsp[0].minor.yy528,yymsp[-6].minor.yy394,0,0,0);
167043 }
167044 break;
167045 case 158: /* setlist ::= setlist COMMA nm EQ expr */
167046 {
@@ -167282,33 +167714,45 @@
167282 {
167283 yymsp[-3].minor.yy528 = sqlite3PExpr(pParse,TK_ISNOT,yymsp[-3].minor.yy528,yymsp[0].minor.yy528);
167284 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy528, yymsp[-3].minor.yy528, TK_NOTNULL);
167285 }
167286 break;
167287 case 209: /* expr ::= NOT expr */
167288 case 210: /* expr ::= BITNOT expr */ yytestcase(yyruleno==210);
 
 
 
 
 
 
 
 
 
 
 
 
167289 {yymsp[-1].minor.yy528 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy528, 0);/*A-overwrites-B*/}
167290 break;
167291 case 211: /* expr ::= PLUS|MINUS expr */
167292 {
167293 yymsp[-1].minor.yy528 = sqlite3PExpr(pParse, yymsp[-1].major==TK_PLUS ? TK_UPLUS : TK_UMINUS, yymsp[0].minor.yy528, 0);
167294 /*A-overwrites-B*/
167295 }
167296 break;
167297 case 212: /* expr ::= expr PTR expr */
167298 {
167299 ExprList *pList = sqlite3ExprListAppend(pParse, 0, yymsp[-2].minor.yy528);
167300 pList = sqlite3ExprListAppend(pParse, pList, yymsp[0].minor.yy528);
167301 yylhsminor.yy528 = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy0, 0);
167302 }
167303 yymsp[-2].minor.yy528 = yylhsminor.yy528;
167304 break;
167305 case 213: /* between_op ::= BETWEEN */
167306 case 216: /* in_op ::= IN */ yytestcase(yyruleno==216);
167307 {yymsp[0].minor.yy394 = 0;}
167308 break;
167309 case 215: /* expr ::= expr between_op expr AND expr */
167310 {
167311 ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy528);
167312 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy528);
167313 yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy528, 0);
167314 if( yymsp[-4].minor.yy528 ){
@@ -167317,11 +167761,11 @@
167317 sqlite3ExprListDelete(pParse->db, pList);
167318 }
167319 if( yymsp[-3].minor.yy394 ) yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy528, 0);
167320 }
167321 break;
167322 case 218: /* expr ::= expr in_op LP exprlist RP */
167323 {
167324 if( yymsp[-1].minor.yy322==0 ){
167325 /* Expressions of the form
167326 **
167327 ** expr1 IN ()
@@ -167329,11 +167773,12 @@
167329 **
167330 ** simplify to constants 0 (false) and 1 (true), respectively,
167331 ** regardless of the value of expr1.
167332 */
167333 sqlite3ExprUnmapAndDelete(pParse, yymsp[-4].minor.yy528);
167334 yymsp[-4].minor.yy528 = sqlite3Expr(pParse->db, TK_INTEGER, yymsp[-3].minor.yy394 ? "1" : "0");
 
167335 }else{
167336 Expr *pRHS = yymsp[-1].minor.yy322->a[0].pExpr;
167337 if( yymsp[-1].minor.yy322->nExpr==1 && sqlite3ExprIsConstant(pRHS) && yymsp[-4].minor.yy528->op!=TK_VECTOR ){
167338 yymsp[-1].minor.yy322->a[0].pExpr = 0;
167339 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy322);
@@ -167357,41 +167802,41 @@
167357 }
167358 if( yymsp[-3].minor.yy394 ) yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy528, 0);
167359 }
167360 }
167361 break;
167362 case 219: /* expr ::= LP select RP */
167363 {
167364 yymsp[-2].minor.yy528 = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
167365 sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy528, yymsp[-1].minor.yy47);
167366 }
167367 break;
167368 case 220: /* expr ::= expr in_op LP select RP */
167369 {
167370 yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy528, 0);
167371 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy528, yymsp[-1].minor.yy47);
167372 if( yymsp[-3].minor.yy394 ) yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy528, 0);
167373 }
167374 break;
167375 case 221: /* expr ::= expr in_op nm dbnm paren_exprlist */
167376 {
167377 SrcList *pSrc = sqlite3SrcListAppend(pParse, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);
167378 Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0);
167379 if( yymsp[0].minor.yy322 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy322);
167380 yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy528, 0);
167381 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy528, pSelect);
167382 if( yymsp[-3].minor.yy394 ) yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy528, 0);
167383 }
167384 break;
167385 case 222: /* expr ::= EXISTS LP select RP */
167386 {
167387 Expr *p;
167388 p = yymsp[-3].minor.yy528 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
167389 sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy47);
167390 }
167391 break;
167392 case 223: /* expr ::= CASE case_operand case_exprlist case_else END */
167393 {
167394 yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy528, 0);
167395 if( yymsp[-4].minor.yy528 ){
167396 yymsp[-4].minor.yy528->x.pList = yymsp[-1].minor.yy528 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[-1].minor.yy528) : yymsp[-2].minor.yy322;
167397 sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy528);
@@ -167399,406 +167844,406 @@
167399 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy322);
167400 sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy528);
167401 }
167402 }
167403 break;
167404 case 224: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
167405 {
167406 yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, yymsp[-2].minor.yy528);
167407 yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, yymsp[0].minor.yy528);
167408 }
167409 break;
167410 case 225: /* case_exprlist ::= WHEN expr THEN expr */
167411 {
167412 yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy528);
167413 yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322, yymsp[0].minor.yy528);
167414 }
167415 break;
167416 case 228: /* case_operand ::= expr */
167417 {yymsp[0].minor.yy528 = yymsp[0].minor.yy528; /*A-overwrites-X*/}
167418 break;
167419 case 231: /* nexprlist ::= nexprlist COMMA expr */
167420 {yymsp[-2].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[0].minor.yy528);}
167421 break;
167422 case 232: /* nexprlist ::= expr */
167423 {yymsp[0].minor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy528); /*A-overwrites-Y*/}
167424 break;
167425 case 234: /* paren_exprlist ::= LP exprlist RP */
167426 case 239: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==239);
167427 {yymsp[-2].minor.yy322 = yymsp[-1].minor.yy322;}
167428 break;
167429 case 235: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
167430 {
167431 sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0,
167432 sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy322, yymsp[-10].minor.yy394,
167433 &yymsp[-11].minor.yy0, yymsp[0].minor.yy528, SQLITE_SO_ASC, yymsp[-8].minor.yy394, SQLITE_IDXTYPE_APPDEF);
167434 if( IN_RENAME_OBJECT && pParse->pNewIndex ){
167435 sqlite3RenameTokenMap(pParse, pParse->pNewIndex->zName, &yymsp[-4].minor.yy0);
167436 }
167437 }
167438 break;
167439 case 236: /* uniqueflag ::= UNIQUE */
167440 case 278: /* raisetype ::= ABORT */ yytestcase(yyruleno==278);
167441 {yymsp[0].minor.yy394 = OE_Abort;}
167442 break;
167443 case 237: /* uniqueflag ::= */
167444 {yymsp[1].minor.yy394 = OE_None;}
167445 break;
167446 case 240: /* eidlist ::= eidlist COMMA nm collate sortorder */
167447 {
167448 yymsp[-4].minor.yy322 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy322, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy394, yymsp[0].minor.yy394);
167449 }
167450 break;
167451 case 241: /* eidlist ::= nm collate sortorder */
167452 {
167453 yymsp[-2].minor.yy322 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy394, yymsp[0].minor.yy394); /*A-overwrites-Y*/
167454 }
167455 break;
167456 case 244: /* cmd ::= DROP INDEX ifexists fullname */
167457 {sqlite3DropIndex(pParse, yymsp[0].minor.yy131, yymsp[-1].minor.yy394);}
167458 break;
167459 case 245: /* cmd ::= VACUUM vinto */
167460 {sqlite3Vacuum(pParse,0,yymsp[0].minor.yy528);}
167461 break;
167462 case 246: /* cmd ::= VACUUM nm vinto */
167463 {sqlite3Vacuum(pParse,&yymsp[-1].minor.yy0,yymsp[0].minor.yy528);}
167464 break;
167465 case 249: /* cmd ::= PRAGMA nm dbnm */
167466 {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
167467 break;
167468 case 250: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
167469 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
167470 break;
167471 case 251: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
167472 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
167473 break;
167474 case 252: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
167475 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
167476 break;
167477 case 253: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
167478 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
167479 break;
167480 case 256: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
167481 {
167482 Token all;
167483 all.z = yymsp[-3].minor.yy0.z;
167484 all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
167485 sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy33, &all);
167486 }
167487 break;
167488 case 257: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
167489 {
167490 sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy394, yymsp[-4].minor.yy180.a, yymsp[-4].minor.yy180.b, yymsp[-2].minor.yy131, yymsp[0].minor.yy528, yymsp[-10].minor.yy394, yymsp[-8].minor.yy394);
167491 yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/
167492 }
167493 break;
167494 case 258: /* trigger_time ::= BEFORE|AFTER */
167495 { yymsp[0].minor.yy394 = yymsp[0].major; /*A-overwrites-X*/ }
167496 break;
167497 case 259: /* trigger_time ::= INSTEAD OF */
167498 { yymsp[-1].minor.yy394 = TK_INSTEAD;}
167499 break;
167500 case 260: /* trigger_time ::= */
167501 { yymsp[1].minor.yy394 = TK_BEFORE; }
167502 break;
167503 case 261: /* trigger_event ::= DELETE|INSERT */
167504 case 262: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==262);
167505 {yymsp[0].minor.yy180.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy180.b = 0;}
167506 break;
167507 case 263: /* trigger_event ::= UPDATE OF idlist */
167508 {yymsp[-2].minor.yy180.a = TK_UPDATE; yymsp[-2].minor.yy180.b = yymsp[0].minor.yy254;}
167509 break;
167510 case 264: /* when_clause ::= */
167511 case 283: /* key_opt ::= */ yytestcase(yyruleno==283);
167512 { yymsp[1].minor.yy528 = 0; }
167513 break;
167514 case 265: /* when_clause ::= WHEN expr */
167515 case 284: /* key_opt ::= KEY expr */ yytestcase(yyruleno==284);
167516 { yymsp[-1].minor.yy528 = yymsp[0].minor.yy528; }
167517 break;
167518 case 266: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
167519 {
167520 assert( yymsp[-2].minor.yy33!=0 );
167521 yymsp[-2].minor.yy33->pLast->pNext = yymsp[-1].minor.yy33;
167522 yymsp[-2].minor.yy33->pLast = yymsp[-1].minor.yy33;
167523 }
167524 break;
167525 case 267: /* trigger_cmd_list ::= trigger_cmd SEMI */
167526 {
167527 assert( yymsp[-1].minor.yy33!=0 );
167528 yymsp[-1].minor.yy33->pLast = yymsp[-1].minor.yy33;
167529 }
167530 break;
167531 case 268: /* trnm ::= nm DOT nm */
167532 {
167533 yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;
167534 sqlite3ErrorMsg(pParse,
167535 "qualified table names are not allowed on INSERT, UPDATE, and DELETE "
167536 "statements within triggers");
167537 }
167538 break;
167539 case 269: /* tridxby ::= INDEXED BY nm */
167540 {
167541 sqlite3ErrorMsg(pParse,
167542 "the INDEXED BY clause is not allowed on UPDATE or DELETE statements "
167543 "within triggers");
167544 }
167545 break;
167546 case 270: /* tridxby ::= NOT INDEXED */
167547 {
167548 sqlite3ErrorMsg(pParse,
167549 "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
167550 "within triggers");
167551 }
167552 break;
167553 case 271: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
167554 {yylhsminor.yy33 = sqlite3TriggerUpdateStep(pParse, &yymsp[-6].minor.yy0, yymsp[-2].minor.yy131, yymsp[-3].minor.yy322, yymsp[-1].minor.yy528, yymsp[-7].minor.yy394, yymsp[-8].minor.yy0.z, yymsp[0].minor.yy522);}
167555 yymsp[-8].minor.yy33 = yylhsminor.yy33;
167556 break;
167557 case 272: /* trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
167558 {
167559 yylhsminor.yy33 = sqlite3TriggerInsertStep(pParse,&yymsp[-4].minor.yy0,yymsp[-3].minor.yy254,yymsp[-2].minor.yy47,yymsp[-6].minor.yy394,yymsp[-1].minor.yy444,yymsp[-7].minor.yy522,yymsp[0].minor.yy522);/*yylhsminor.yy33-overwrites-yymsp[-6].minor.yy394*/
167560 }
167561 yymsp[-7].minor.yy33 = yylhsminor.yy33;
167562 break;
167563 case 273: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
167564 {yylhsminor.yy33 = sqlite3TriggerDeleteStep(pParse, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy528, yymsp[-5].minor.yy0.z, yymsp[0].minor.yy522);}
167565 yymsp[-5].minor.yy33 = yylhsminor.yy33;
167566 break;
167567 case 274: /* trigger_cmd ::= scanpt select scanpt */
167568 {yylhsminor.yy33 = sqlite3TriggerSelectStep(pParse->db, yymsp[-1].minor.yy47, yymsp[-2].minor.yy522, yymsp[0].minor.yy522); /*yylhsminor.yy33-overwrites-yymsp[-1].minor.yy47*/}
167569 yymsp[-2].minor.yy33 = yylhsminor.yy33;
167570 break;
167571 case 275: /* expr ::= RAISE LP IGNORE RP */
167572 {
167573 yymsp[-3].minor.yy528 = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
167574 if( yymsp[-3].minor.yy528 ){
167575 yymsp[-3].minor.yy528->affExpr = OE_Ignore;
167576 }
167577 }
167578 break;
167579 case 276: /* expr ::= RAISE LP raisetype COMMA nm RP */
167580 {
167581 yymsp[-5].minor.yy528 = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1);
167582 if( yymsp[-5].minor.yy528 ) {
167583 yymsp[-5].minor.yy528->affExpr = (char)yymsp[-3].minor.yy394;
167584 }
167585 }
167586 break;
167587 case 277: /* raisetype ::= ROLLBACK */
167588 {yymsp[0].minor.yy394 = OE_Rollback;}
167589 break;
167590 case 279: /* raisetype ::= FAIL */
167591 {yymsp[0].minor.yy394 = OE_Fail;}
167592 break;
167593 case 280: /* cmd ::= DROP TRIGGER ifexists fullname */
167594 {
167595 sqlite3DropTrigger(pParse,yymsp[0].minor.yy131,yymsp[-1].minor.yy394);
167596 }
167597 break;
167598 case 281: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
167599 {
167600 sqlite3Attach(pParse, yymsp[-3].minor.yy528, yymsp[-1].minor.yy528, yymsp[0].minor.yy528);
167601 }
167602 break;
167603 case 282: /* cmd ::= DETACH database_kw_opt expr */
167604 {
167605 sqlite3Detach(pParse, yymsp[0].minor.yy528);
167606 }
167607 break;
167608 case 285: /* cmd ::= REINDEX */
167609 {sqlite3Reindex(pParse, 0, 0);}
167610 break;
167611 case 286: /* cmd ::= REINDEX nm dbnm */
167612 {sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
167613 break;
167614 case 287: /* cmd ::= ANALYZE */
167615 {sqlite3Analyze(pParse, 0, 0);}
167616 break;
167617 case 288: /* cmd ::= ANALYZE nm dbnm */
167618 {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
167619 break;
167620 case 289: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
167621 {
167622 sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy131,&yymsp[0].minor.yy0);
167623 }
167624 break;
167625 case 290: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
167626 {
167627 yymsp[-1].minor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-1].minor.yy0.z) + pParse->sLastToken.n;
167628 sqlite3AlterFinishAddColumn(pParse, &yymsp[-1].minor.yy0);
167629 }
167630 break;
167631 case 291: /* cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
167632 {
167633 sqlite3AlterDropColumn(pParse, yymsp[-3].minor.yy131, &yymsp[0].minor.yy0);
167634 }
167635 break;
167636 case 292: /* add_column_fullname ::= fullname */
167637 {
167638 disableLookaside(pParse);
167639 sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy131);
167640 }
167641 break;
167642 case 293: /* cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
167643 {
167644 sqlite3AlterRenameColumn(pParse, yymsp[-5].minor.yy131, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);
167645 }
167646 break;
167647 case 294: /* cmd ::= create_vtab */
167648 {sqlite3VtabFinishParse(pParse,0);}
167649 break;
167650 case 295: /* cmd ::= create_vtab LP vtabarglist RP */
167651 {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
167652 break;
167653 case 296: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
167654 {
167655 sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy394);
167656 }
167657 break;
167658 case 297: /* vtabarg ::= */
167659 {sqlite3VtabArgInit(pParse);}
167660 break;
167661 case 298: /* vtabargtoken ::= ANY */
167662 case 299: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==299);
167663 case 300: /* lp ::= LP */ yytestcase(yyruleno==300);
167664 {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
167665 break;
167666 case 301: /* with ::= WITH wqlist */
167667 case 302: /* with ::= WITH RECURSIVE wqlist */ yytestcase(yyruleno==302);
167668 { sqlite3WithPush(pParse, yymsp[0].minor.yy521, 1); }
167669 break;
167670 case 303: /* wqas ::= AS */
167671 {yymsp[0].minor.yy516 = M10d_Any;}
167672 break;
167673 case 304: /* wqas ::= AS MATERIALIZED */
167674 {yymsp[-1].minor.yy516 = M10d_Yes;}
167675 break;
167676 case 305: /* wqas ::= AS NOT MATERIALIZED */
167677 {yymsp[-2].minor.yy516 = M10d_No;}
167678 break;
167679 case 306: /* wqitem ::= nm eidlist_opt wqas LP select RP */
167680 {
167681 yymsp[-5].minor.yy385 = sqlite3CteNew(pParse, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy322, yymsp[-1].minor.yy47, yymsp[-3].minor.yy516); /*A-overwrites-X*/
167682 }
167683 break;
167684 case 307: /* wqlist ::= wqitem */
167685 {
167686 yymsp[0].minor.yy521 = sqlite3WithAdd(pParse, 0, yymsp[0].minor.yy385); /*A-overwrites-X*/
167687 }
167688 break;
167689 case 308: /* wqlist ::= wqlist COMMA wqitem */
167690 {
167691 yymsp[-2].minor.yy521 = sqlite3WithAdd(pParse, yymsp[-2].minor.yy521, yymsp[0].minor.yy385);
167692 }
167693 break;
167694 case 309: /* windowdefn_list ::= windowdefn */
167695 { yylhsminor.yy41 = yymsp[0].minor.yy41; }
167696 yymsp[0].minor.yy41 = yylhsminor.yy41;
167697 break;
167698 case 310: /* windowdefn_list ::= windowdefn_list COMMA windowdefn */
167699 {
167700 assert( yymsp[0].minor.yy41!=0 );
167701 sqlite3WindowChain(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy41);
167702 yymsp[0].minor.yy41->pNextWin = yymsp[-2].minor.yy41;
167703 yylhsminor.yy41 = yymsp[0].minor.yy41;
167704 }
167705 yymsp[-2].minor.yy41 = yylhsminor.yy41;
167706 break;
167707 case 311: /* windowdefn ::= nm AS LP window RP */
167708 {
167709 if( ALWAYS(yymsp[-1].minor.yy41) ){
167710 yymsp[-1].minor.yy41->zName = sqlite3DbStrNDup(pParse->db, yymsp[-4].minor.yy0.z, yymsp[-4].minor.yy0.n);
167711 }
167712 yylhsminor.yy41 = yymsp[-1].minor.yy41;
167713 }
167714 yymsp[-4].minor.yy41 = yylhsminor.yy41;
167715 break;
167716 case 312: /* window ::= PARTITION BY nexprlist orderby_opt frame_opt */
167717 {
167718 yymsp[-4].minor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy322, yymsp[-1].minor.yy322, 0);
167719 }
167720 break;
167721 case 313: /* window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
167722 {
167723 yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy322, yymsp[-1].minor.yy322, &yymsp[-5].minor.yy0);
167724 }
167725 yymsp[-5].minor.yy41 = yylhsminor.yy41;
167726 break;
167727 case 314: /* window ::= ORDER BY sortlist frame_opt */
167728 {
167729 yymsp[-3].minor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, yymsp[-1].minor.yy322, 0);
167730 }
167731 break;
167732 case 315: /* window ::= nm ORDER BY sortlist frame_opt */
167733 {
167734 yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, yymsp[-1].minor.yy322, &yymsp[-4].minor.yy0);
167735 }
167736 yymsp[-4].minor.yy41 = yylhsminor.yy41;
167737 break;
167738 case 316: /* window ::= frame_opt */
167739 case 335: /* filter_over ::= over_clause */ yytestcase(yyruleno==335);
167740 {
167741 yylhsminor.yy41 = yymsp[0].minor.yy41;
167742 }
167743 yymsp[0].minor.yy41 = yylhsminor.yy41;
167744 break;
167745 case 317: /* window ::= nm frame_opt */
167746 {
167747 yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, 0, &yymsp[-1].minor.yy0);
167748 }
167749 yymsp[-1].minor.yy41 = yylhsminor.yy41;
167750 break;
167751 case 318: /* frame_opt ::= */
167752 {
167753 yymsp[1].minor.yy41 = sqlite3WindowAlloc(pParse, 0, TK_UNBOUNDED, 0, TK_CURRENT, 0, 0);
167754 }
167755 break;
167756 case 319: /* frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
167757 {
167758 yylhsminor.yy41 = sqlite3WindowAlloc(pParse, yymsp[-2].minor.yy394, yymsp[-1].minor.yy595.eType, yymsp[-1].minor.yy595.pExpr, TK_CURRENT, 0, yymsp[0].minor.yy516);
167759 }
167760 yymsp[-2].minor.yy41 = yylhsminor.yy41;
167761 break;
167762 case 320: /* frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
167763 {
167764 yylhsminor.yy41 = sqlite3WindowAlloc(pParse, yymsp[-5].minor.yy394, yymsp[-3].minor.yy595.eType, yymsp[-3].minor.yy595.pExpr, yymsp[-1].minor.yy595.eType, yymsp[-1].minor.yy595.pExpr, yymsp[0].minor.yy516);
167765 }
167766 yymsp[-5].minor.yy41 = yylhsminor.yy41;
167767 break;
167768 case 322: /* frame_bound_s ::= frame_bound */
167769 case 324: /* frame_bound_e ::= frame_bound */ yytestcase(yyruleno==324);
167770 {yylhsminor.yy595 = yymsp[0].minor.yy595;}
167771 yymsp[0].minor.yy595 = yylhsminor.yy595;
167772 break;
167773 case 323: /* frame_bound_s ::= UNBOUNDED PRECEDING */
167774 case 325: /* frame_bound_e ::= UNBOUNDED FOLLOWING */ yytestcase(yyruleno==325);
167775 case 327: /* frame_bound ::= CURRENT ROW */ yytestcase(yyruleno==327);
167776 {yylhsminor.yy595.eType = yymsp[-1].major; yylhsminor.yy595.pExpr = 0;}
167777 yymsp[-1].minor.yy595 = yylhsminor.yy595;
167778 break;
167779 case 326: /* frame_bound ::= expr PRECEDING|FOLLOWING */
167780 {yylhsminor.yy595.eType = yymsp[0].major; yylhsminor.yy595.pExpr = yymsp[-1].minor.yy528;}
167781 yymsp[-1].minor.yy595 = yylhsminor.yy595;
167782 break;
167783 case 328: /* frame_exclude_opt ::= */
167784 {yymsp[1].minor.yy516 = 0;}
167785 break;
167786 case 329: /* frame_exclude_opt ::= EXCLUDE frame_exclude */
167787 {yymsp[-1].minor.yy516 = yymsp[0].minor.yy516;}
167788 break;
167789 case 330: /* frame_exclude ::= NO OTHERS */
167790 case 331: /* frame_exclude ::= CURRENT ROW */ yytestcase(yyruleno==331);
167791 {yymsp[-1].minor.yy516 = yymsp[-1].major; /*A-overwrites-X*/}
167792 break;
167793 case 332: /* frame_exclude ::= GROUP|TIES */
167794 {yymsp[0].minor.yy516 = yymsp[0].major; /*A-overwrites-X*/}
167795 break;
167796 case 333: /* window_clause ::= WINDOW windowdefn_list */
167797 { yymsp[-1].minor.yy41 = yymsp[0].minor.yy41; }
167798 break;
167799 case 334: /* filter_over ::= filter_clause over_clause */
167800 {
167801 if( yymsp[0].minor.yy41 ){
167802 yymsp[0].minor.yy41->pFilter = yymsp[-1].minor.yy528;
167803 }else{
167804 sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy528);
@@ -167805,11 +168250,11 @@
167805 }
167806 yylhsminor.yy41 = yymsp[0].minor.yy41;
167807 }
167808 yymsp[-1].minor.yy41 = yylhsminor.yy41;
167809 break;
167810 case 336: /* filter_over ::= filter_clause */
167811 {
167812 yylhsminor.yy41 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
167813 if( yylhsminor.yy41 ){
167814 yylhsminor.yy41->eFrmType = TK_FILTER;
167815 yylhsminor.yy41->pFilter = yymsp[0].minor.yy528;
@@ -167817,91 +168262,91 @@
167817 sqlite3ExprDelete(pParse->db, yymsp[0].minor.yy528);
167818 }
167819 }
167820 yymsp[0].minor.yy41 = yylhsminor.yy41;
167821 break;
167822 case 337: /* over_clause ::= OVER LP window RP */
167823 {
167824 yymsp[-3].minor.yy41 = yymsp[-1].minor.yy41;
167825 assert( yymsp[-3].minor.yy41!=0 );
167826 }
167827 break;
167828 case 338: /* over_clause ::= OVER nm */
167829 {
167830 yymsp[-1].minor.yy41 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
167831 if( yymsp[-1].minor.yy41 ){
167832 yymsp[-1].minor.yy41->zName = sqlite3DbStrNDup(pParse->db, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n);
167833 }
167834 }
167835 break;
167836 case 339: /* filter_clause ::= FILTER LP WHERE expr RP */
167837 { yymsp[-4].minor.yy528 = yymsp[-1].minor.yy528; }
167838 break;
167839 default:
167840 /* (340) input ::= cmdlist */ yytestcase(yyruleno==340);
167841 /* (341) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==341);
167842 /* (342) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=342);
167843 /* (343) ecmd ::= SEMI */ yytestcase(yyruleno==343);
167844 /* (344) ecmd ::= cmdx SEMI */ yytestcase(yyruleno==344);
167845 /* (345) ecmd ::= explain cmdx SEMI (NEVER REDUCES) */ assert(yyruleno!=345);
167846 /* (346) trans_opt ::= */ yytestcase(yyruleno==346);
167847 /* (347) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==347);
167848 /* (348) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==348);
167849 /* (349) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==349);
167850 /* (350) savepoint_opt ::= */ yytestcase(yyruleno==350);
167851 /* (351) cmd ::= create_table create_table_args */ yytestcase(yyruleno==351);
167852 /* (352) table_option_set ::= table_option (OPTIMIZED OUT) */ assert(yyruleno!=352);
167853 /* (353) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==353);
167854 /* (354) columnlist ::= columnname carglist */ yytestcase(yyruleno==354);
167855 /* (355) nm ::= ID|INDEXED */ yytestcase(yyruleno==355);
167856 /* (356) nm ::= STRING */ yytestcase(yyruleno==356);
167857 /* (357) nm ::= JOIN_KW */ yytestcase(yyruleno==357);
167858 /* (358) typetoken ::= typename */ yytestcase(yyruleno==358);
167859 /* (359) typename ::= ID|STRING */ yytestcase(yyruleno==359);
167860 /* (360) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=360);
167861 /* (361) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=361);
167862 /* (362) carglist ::= carglist ccons */ yytestcase(yyruleno==362);
167863 /* (363) carglist ::= */ yytestcase(yyruleno==363);
167864 /* (364) ccons ::= NULL onconf */ yytestcase(yyruleno==364);
167865 /* (365) ccons ::= GENERATED ALWAYS AS generated */ yytestcase(yyruleno==365);
167866 /* (366) ccons ::= AS generated */ yytestcase(yyruleno==366);
167867 /* (367) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==367);
167868 /* (368) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==368);
167869 /* (369) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=369);
167870 /* (370) tconscomma ::= */ yytestcase(yyruleno==370);
167871 /* (371) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=371);
167872 /* (372) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=372);
167873 /* (373) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=373);
167874 /* (374) oneselect ::= values */ yytestcase(yyruleno==374);
167875 /* (375) sclp ::= selcollist COMMA */ yytestcase(yyruleno==375);
167876 /* (376) as ::= ID|STRING */ yytestcase(yyruleno==376);
167877 /* (377) indexed_opt ::= indexed_by (OPTIMIZED OUT) */ assert(yyruleno!=377);
167878 /* (378) returning ::= */ yytestcase(yyruleno==378);
167879 /* (379) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=379);
167880 /* (380) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==380);
167881 /* (381) exprlist ::= nexprlist */ yytestcase(yyruleno==381);
167882 /* (382) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=382);
167883 /* (383) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=383);
167884 /* (384) nmnum ::= ON */ yytestcase(yyruleno==384);
167885 /* (385) nmnum ::= DELETE */ yytestcase(yyruleno==385);
167886 /* (386) nmnum ::= DEFAULT */ yytestcase(yyruleno==386);
167887 /* (387) plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==387);
167888 /* (388) foreach_clause ::= */ yytestcase(yyruleno==388);
167889 /* (389) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==389);
167890 /* (390) trnm ::= nm */ yytestcase(yyruleno==390);
167891 /* (391) tridxby ::= */ yytestcase(yyruleno==391);
167892 /* (392) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==392);
167893 /* (393) database_kw_opt ::= */ yytestcase(yyruleno==393);
167894 /* (394) kwcolumn_opt ::= */ yytestcase(yyruleno==394);
167895 /* (395) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==395);
167896 /* (396) vtabarglist ::= vtabarg */ yytestcase(yyruleno==396);
167897 /* (397) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==397);
167898 /* (398) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==398);
167899 /* (399) anylist ::= */ yytestcase(yyruleno==399);
167900 /* (400) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==400);
167901 /* (401) anylist ::= anylist ANY */ yytestcase(yyruleno==401);
167902 /* (402) with ::= */ yytestcase(yyruleno==402);
167903 break;
167904 /********** End reduce actions ************************************************/
167905 };
167906 assert( yyruleno<sizeof(yyRuleInfoLhs)/sizeof(yyRuleInfoLhs[0]) );
167907 yygoto = yyRuleInfoLhs[yyruleno];
@@ -174597,10 +175042,28 @@
174597 */
174598 SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){
174599 int iDb = zDbName ? sqlite3FindDbName(db, zDbName) : 0;
174600 return iDb<0 ? 0 : db->aDb[iDb].pBt;
174601 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174602
174603 /*
174604 ** Return the filename of the database associated with a database
174605 ** connection.
174606 */
@@ -190236,10 +190699,12 @@
190236 if( rc==SQLITE_OK ){
190237 if( pNode->key.n ){
190238 pBlk->n += sqlite3Fts3PutVarint(&pBlk->a[pBlk->n], nPrefix);
190239 }
190240 pBlk->n += sqlite3Fts3PutVarint(&pBlk->a[pBlk->n], nSuffix);
 
 
190241 memcpy(&pBlk->a[pBlk->n], &zTerm[nPrefix], nSuffix);
190242 pBlk->n += nSuffix;
190243
190244 memcpy(pNode->key.a, zTerm, nTerm);
190245 pNode->key.n = nTerm;
@@ -190358,10 +190823,11 @@
190358 NodeWriter *pLeaf; /* Object used to write leaf nodes */
190359
190360 pLeaf = &pWriter->aNodeWriter[0];
190361 nPrefix = fts3PrefixCompress(pLeaf->key.a, pLeaf->key.n, zTerm, nTerm);
190362 nSuffix = nTerm - nPrefix;
 
190363
190364 nSpace = sqlite3Fts3VarintLen(nPrefix);
190365 nSpace += sqlite3Fts3VarintLen(nSuffix) + nSuffix;
190366 nSpace += sqlite3Fts3VarintLen(nDoclist) + nDoclist;
190367
@@ -226663,11 +227129,11 @@
226663 /* State used by the fts5DataXXX() functions. */
226664 sqlite3_blob *pReader; /* RO incr-blob open on %_data table */
226665 sqlite3_stmt *pWriter; /* "INSERT ... %_data VALUES(?,?)" */
226666 sqlite3_stmt *pDeleter; /* "DELETE FROM %_data ... id>=? AND id<=?" */
226667 sqlite3_stmt *pIdxWriter; /* "INSERT ... %_idx VALUES(?,?,?,?)" */
226668 sqlite3_stmt *pIdxDeleter; /* "DELETE FROM %_idx WHERE segid=? */
226669 sqlite3_stmt *pIdxSelect;
226670 int nRead; /* Total number of blocks read */
226671
226672 sqlite3_stmt *pDataVersion;
226673 i64 iStructVersion; /* data_version when pStruct read */
@@ -235980,11 +236446,11 @@
235980 int nArg, /* Number of args */
235981 sqlite3_value **apUnused /* Function arguments */
235982 ){
235983 assert( nArg==0 );
235984 UNUSED_PARAM2(nArg, apUnused);
235985 sqlite3_result_text(pCtx, "fts5: 2022-04-19 15:56:03 b966d52437f08a6759a83a45cafb0d706a8933a8e55dee38ae78166d1a5b3ba4", -1, SQLITE_TRANSIENT);
235986 }
235987
235988 /*
235989 ** Return true if zName is the extension on one of the shadow tables used
235990 ** by this module.
235991
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.39.0"
456 #define SQLITE_VERSION_NUMBER 3039000
457 #define SQLITE_SOURCE_ID "2022-06-03 14:08:40 d18818afc6021a32989499c26ab38fa442e5a55e662e39bb06e5c0daa9c65e25"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -6580,10 +6580,32 @@
6580 ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
6581 ** create the statement in the first place.
6582 */
6583 SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
6584
6585 /*
6586 ** CAPI3REF: Return The Schema Name For A Database Connection
6587 ** METHOD: sqlite3
6588 **
6589 ** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name
6590 ** for the N-th database on database connection D, or a NULL pointer of N is
6591 ** out of range. An N alue of 0 means the main database file. An N of 1 is
6592 ** the "temp" schema. Larger values of N correspond to various ATTACH-ed
6593 ** databases.
6594 **
6595 ** Space to hold the string that is returned by sqlite3_db_name() is managed
6596 ** by SQLite itself. The string might be deallocated by any operation that
6597 ** changes the schema, including [ATTACH] or [DETACH] or calls to
6598 ** [sqlite3_serialize()] or [sqlite3_deserialize()], even operations that
6599 ** occur on a different thread. Applications that need to
6600 ** remember the string long-term should make their own copy. Applications that
6601 ** are accessing the same database connection simultaneously on multiple
6602 ** threads should mutex-protect calls to this API and should make their own
6603 ** private copy of the result prior to releasing the mutex.
6604 */
6605 SQLITE_API const char *sqlite3_db_name(sqlite3 *db, int N);
6606
6607 /*
6608 ** CAPI3REF: Return The Filename For A Database Connection
6609 ** METHOD: sqlite3
6610 **
6611 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to the filename
@@ -15790,12 +15812,14 @@
15812 # define sqlite3VdbeVerifyNoMallocRequired(A,B)
15813 # define sqlite3VdbeVerifyNoResultRow(A)
15814 #endif
15815 #if defined(SQLITE_DEBUG)
15816 SQLITE_PRIVATE void sqlite3VdbeVerifyAbortable(Vdbe *p, int);
15817 SQLITE_PRIVATE void sqlite3VdbeNoJumpsOutsideSubrtn(Vdbe*,int,int,int);
15818 #else
15819 # define sqlite3VdbeVerifyAbortable(A,B)
15820 # define sqlite3VdbeNoJumpsOutsideSubrtn(A,B,C,D)
15821 #endif
15822 SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp,int iLineno);
15823 #ifndef SQLITE_OMIT_EXPLAIN
15824 SQLITE_PRIVATE void sqlite3VdbeExplain(Parse*,u8,const char*,...);
15825 SQLITE_PRIVATE void sqlite3VdbeExplainPop(Parse*);
@@ -16283,10 +16307,17 @@
16307 /* Maximum pathname length. Note: FILENAME_MAX defined by stdio.h
16308 */
16309 #ifndef SQLITE_MAX_PATHLEN
16310 # define SQLITE_MAX_PATHLEN FILENAME_MAX
16311 #endif
16312
16313 /* Maximum number of symlinks that will be resolved while trying to
16314 ** expand a filename in xFullPathname() in the VFS.
16315 */
16316 #ifndef SQLITE_MAX_SYMLINK
16317 # define SQLITE_MAX_SYMLINK 200
16318 #endif
16319
16320 /*
16321 ** The default size of a disk sector
16322 */
16323 #ifndef SQLITE_DEFAULT_SECTOR_SIZE
@@ -17051,10 +17082,12 @@
17082 /* TH3 expects this value ^^^^^^^^^^ to be 0x40000. Coordinate any change */
17083 #define SQLITE_BloomFilter 0x00080000 /* Use a Bloom filter on searches */
17084 #define SQLITE_BloomPulldown 0x00100000 /* Run Bloom filters early */
17085 #define SQLITE_BalancedMerge 0x00200000 /* Balance multi-way merges */
17086 #define SQLITE_ReleaseReg 0x00400000 /* Use OP_ReleaseReg for testing */
17087 #define SQLITE_FlttnUnionAll 0x00800000 /* Disable the UNION ALL flattener */
17088 /* TH3 expects this value ^^^^^^^^^^ See flatten04.test */
17089 #define SQLITE_AllOpts 0xffffffff /* All optimizations */
17090
17091 /*
17092 ** Macros for testing whether or not optimizations are enabled or disabled.
17093 */
@@ -17153,11 +17186,11 @@
17186 #define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */
17187 #define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */
17188 #define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a
17189 ** single query - might change over time */
17190 #define SQLITE_FUNC_TEST 0x4000 /* Built-in testing functions */
17191 /* 0x8000 -- available for reuse */
17192 #define SQLITE_FUNC_WINDOW 0x00010000 /* Built-in window-only function */
17193 #define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */
17194 #define SQLITE_FUNC_DIRECT 0x00080000 /* Not for use in TRIGGERs or VIEWs */
17195 #define SQLITE_FUNC_SUBTYPE 0x00100000 /* Result likely to have sub-type */
17196 #define SQLITE_FUNC_UNSAFE 0x00200000 /* Function has side effects */
@@ -17170,10 +17203,11 @@
17203 #define INLINEFUNC_implies_nonnull_row 1
17204 #define INLINEFUNC_expr_implies_expr 2
17205 #define INLINEFUNC_expr_compare 3
17206 #define INLINEFUNC_affinity 4
17207 #define INLINEFUNC_iif 5
17208 #define INLINEFUNC_sqlite_offset 6
17209 #define INLINEFUNC_unlikely 99 /* Default case */
17210
17211 /*
17212 ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
17213 ** used to create the initializers for the FuncDef structures.
@@ -17396,10 +17430,11 @@
17430 #define COLFLAG_VIRTUAL 0x0020 /* GENERATED ALWAYS AS ... VIRTUAL */
17431 #define COLFLAG_STORED 0x0040 /* GENERATED ALWAYS AS ... STORED */
17432 #define COLFLAG_NOTAVAIL 0x0080 /* STORED column not yet calculated */
17433 #define COLFLAG_BUSY 0x0100 /* Blocks recursion on GENERATED columns */
17434 #define COLFLAG_HASCOLL 0x0200 /* Has collating sequence name in zCnName */
17435 #define COLFLAG_NOEXPAND 0x0400 /* Omit this column when expanding "*" */
17436 #define COLFLAG_GENERATED 0x0060 /* Combo: _STORED, _VIRTUAL */
17437 #define COLFLAG_NOINSERT 0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */
17438
17439 /*
17440 ** A "Collating Sequence" is defined by an instance of the following
@@ -18115,11 +18150,11 @@
18150 ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
18151 ** TK_VARIABLE: variable number (always >= 1).
18152 ** TK_SELECT_COLUMN: column of the result vector */
18153 i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
18154 union {
18155 int iJoin; /* If EP_OuterON or EP_InnerON, the right table */
18156 int iOfst; /* else: start of token from start of statement */
18157 } w;
18158 AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
18159 union {
18160 Table *pTab; /* TK_COLUMN: Table containing column. Can be NULL
@@ -18136,33 +18171,33 @@
18171 ** Value restrictions:
18172 **
18173 ** EP_Agg == NC_HasAgg == SF_HasAgg
18174 ** EP_Win == NC_HasWin
18175 */
18176 #define EP_OuterON 0x000001 /* Originates in ON/USING clause of outer join */
18177 #define EP_InnerON 0x000002 /* Originates in ON/USING of an inner join */
18178 #define EP_Distinct 0x000004 /* Aggregate function with DISTINCT keyword */
18179 #define EP_HasFunc 0x000008 /* Contains one or more functions of any kind */
18180 #define EP_Agg 0x000010 /* Contains one or more aggregate functions */
18181 #define EP_FixedCol 0x000020 /* TK_Column with a known fixed value */
18182 #define EP_VarSelect 0x000040 /* pSelect is correlated, not constant */
18183 #define EP_DblQuoted 0x000080 /* token.z was originally in "..." */
18184 #define EP_InfixFunc 0x000100 /* True for an infix function: LIKE, GLOB, etc */
18185 #define EP_Collate 0x000200 /* Tree contains a TK_COLLATE operator */
18186 #define EP_Commuted 0x000400 /* Comparison operator has been commuted */
18187 #define EP_IntValue 0x000800 /* Integer value contained in u.iValue */
18188 #define EP_xIsSelect 0x001000 /* x.pSelect is valid (otherwise x.pList is) */
18189 #define EP_Skip 0x002000 /* Operator does not contribute to affinity */
18190 #define EP_Reduced 0x004000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
18191 #define EP_Win 0x008000 /* Contains window functions */
18192 #define EP_TokenOnly 0x010000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
18193 #define EP_MemToken 0x020000 /* Need to sqlite3DbFree() Expr.zToken */
18194 #define EP_IfNullRow 0x040000 /* The TK_IF_NULL_ROW opcode */
18195 #define EP_Unlikely 0x080000 /* unlikely() or likelihood() function */
18196 #define EP_ConstFunc 0x100000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
18197 #define EP_CanBeNull 0x200000 /* Can be null despite NOT NULL constraint */
18198 #define EP_Subquery 0x400000 /* Tree contains a TK_SELECT operator */
18199 #define EP_Leaf 0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */
18200 #define EP_WinFunc 0x1000000 /* TK_FUNCTION with Expr.y.pWin set */
18201 #define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */
18202 #define EP_Quoted 0x4000000 /* TK_ID was originally quoted */
18203 #define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */
@@ -18181,12 +18216,12 @@
18216 */
18217 #define ExprHasProperty(E,P) (((E)->flags&(P))!=0)
18218 #define ExprHasAllProperty(E,P) (((E)->flags&(P))==(P))
18219 #define ExprSetProperty(E,P) (E)->flags|=(P)
18220 #define ExprClearProperty(E,P) (E)->flags&=~(P)
18221 #define ExprAlwaysTrue(E) (((E)->flags&(EP_OuterON|EP_IsTrue))==EP_IsTrue)
18222 #define ExprAlwaysFalse(E) (((E)->flags&(EP_OuterON|EP_IsFalse))==EP_IsFalse)
18223
18224 /* Macros used to ensure that the correct members of unions are accessed
18225 ** in Expr.
18226 */
18227 #define ExprUseUToken(E) (((E)->flags&EP_IntValue)==0)
@@ -18269,17 +18304,22 @@
18304 int nExpr; /* Number of expressions on the list */
18305 int nAlloc; /* Number of a[] slots allocated */
18306 struct ExprList_item { /* For each expression in the list */
18307 Expr *pExpr; /* The parse tree for this expression */
18308 char *zEName; /* Token associated with this expression */
18309 struct {
18310 u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */
18311 unsigned eEName :2; /* Meaning of zEName */
18312 unsigned done :1; /* Indicates when processing is finished */
18313 unsigned reusable :1; /* Constant expression is reusable */
18314 unsigned bSorterRef :1; /* Defer evaluation until after sorting */
18315 unsigned bNulls :1; /* True if explicit "NULLS FIRST/LAST" */
18316 unsigned bUsed :1; /* This column used in a SF_NestedFrom subquery */
18317 unsigned bUsingTerm:1; /* Term from the USING clause of a NestedFrom */
18318 unsigned bNoExpand: 1; /* Term is an auxiliary in NestedFrom and should
18319 ** not be expanded by "*" in parent queries */
18320 } fg;
18321 union {
18322 struct { /* Used by any ExprList other than Parse.pConsExpr */
18323 u16 iOrderByCol; /* For ORDER BY, column number in result set */
18324 u16 iAlias; /* Index into Parse.aAlias[] for zName */
18325 } x;
@@ -18356,10 +18396,11 @@
18396 u8 jointype; /* Type of join between this table and the previous */
18397 unsigned notIndexed :1; /* True if there is a NOT INDEXED clause */
18398 unsigned isIndexedBy :1; /* True if there is an INDEXED BY clause */
18399 unsigned isTabFunc :1; /* True if table-valued-function syntax */
18400 unsigned isCorrelated :1; /* True if sub-query is correlated */
18401 unsigned isMaterialized:1; /* This is a materialized view */
18402 unsigned viaCoroutine :1; /* Implemented as a co-routine */
18403 unsigned isRecursive :1; /* True for recursive reference in WITH */
18404 unsigned fromDDL :1; /* Comes from sqlite_schema */
18405 unsigned isCte :1; /* This is a CTE */
18406 unsigned notCte :1; /* This item may not match a CTE */
@@ -19729,10 +19770,11 @@
19770 SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView*, const Expr*, u8);
19771 SQLITE_PRIVATE void sqlite3TreeViewBareExprList(TreeView*, const ExprList*, const char*);
19772 SQLITE_PRIVATE void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*);
19773 SQLITE_PRIVATE void sqlite3TreeViewBareIdList(TreeView*, const IdList*, const char*);
19774 SQLITE_PRIVATE void sqlite3TreeViewIdList(TreeView*, const IdList*, u8, const char*);
19775 SQLITE_PRIVATE void sqlite3TreeViewColumnList(TreeView*, const Column*, int, u8);
19776 SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView*, const SrcList*);
19777 SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView*, const Select*, u8);
19778 SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView*, const With*, u8);
19779 SQLITE_PRIVATE void sqlite3TreeViewUpsert(TreeView*, const Upsert*, u8);
19780 SQLITE_PRIVATE void sqlite3TreeViewDelete(const With*, const SrcList*, const Expr*,
@@ -20022,10 +20064,11 @@
20064 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
20065 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
20066 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
20067 SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
20068 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
20069 SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr*,const SrcItem*);
20070 #ifdef SQLITE_ENABLE_CURSOR_HINTS
20071 SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
20072 #endif
20073 SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*);
20074 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
@@ -30462,12 +30505,18 @@
30505 sqlite3_str_append(pAccum, ".", 1);
30506 }
30507 sqlite3_str_appendall(pAccum, pItem->zName);
30508 }else if( pItem->zAlias ){
30509 sqlite3_str_appendall(pAccum, pItem->zAlias);
30510 }else{
30511 Select *pSel = pItem->pSelect;
30512 assert( pSel!=0 );
30513 if( pSel->selFlags & SF_NestedFrom ){
30514 sqlite3_str_appendf(pAccum, "(join-%u)", pSel->selId);
30515 }else{
30516 sqlite3_str_appendf(pAccum, "(subquery-%u)", pSel->selId);
30517 }
30518 }
30519 length = width = 0;
30520 break;
30521 }
30522 default: {
@@ -30526,11 +30575,13 @@
30575 /*
30576 ** If pExpr has a byte offset for the start of a token, record that as
30577 ** as the error offset.
30578 */
30579 SQLITE_PRIVATE void sqlite3RecordErrorOffsetOfExpr(sqlite3 *db, const Expr *pExpr){
30580 while( pExpr
30581 && (ExprHasProperty(pExpr,EP_OuterON|EP_InnerON) || pExpr->w.iOfst<=0)
30582 ){
30583 pExpr = pExpr->pLeft;
30584 }
30585 if( pExpr==0 ) return;
30586 db->errByteOffset = pExpr->w.iOfst;
30587 }
@@ -31047,10 +31098,57 @@
31098 */
31099 static void sqlite3TreeViewItem(TreeView *p, const char *zLabel,u8 moreFollows){
31100 sqlite3TreeViewPush(&p, moreFollows);
31101 sqlite3TreeViewLine(p, "%s", zLabel);
31102 }
31103
31104 /*
31105 ** Show a list of Column objects in tree format.
31106 */
31107 SQLITE_PRIVATE void sqlite3TreeViewColumnList(
31108 TreeView *pView,
31109 const Column *aCol,
31110 int nCol,
31111 u8 moreToFollow
31112 ){
31113 int i;
31114 sqlite3TreeViewPush(&pView, moreToFollow);
31115 sqlite3TreeViewLine(pView, "COLUMNS");
31116 for(i=0; i<nCol; i++){
31117 u16 flg = aCol[i].colFlags;
31118 int moreToFollow = i<(nCol - 1);
31119 sqlite3TreeViewPush(&pView, moreToFollow);
31120 sqlite3TreeViewLine(pView, 0);
31121 printf(" %s", aCol[i].zCnName);
31122 switch( aCol[i].eCType ){
31123 case COLTYPE_ANY: printf(" ANY"); break;
31124 case COLTYPE_BLOB: printf(" BLOB"); break;
31125 case COLTYPE_INT: printf(" INT"); break;
31126 case COLTYPE_INTEGER: printf(" INTEGER"); break;
31127 case COLTYPE_REAL: printf(" REAL"); break;
31128 case COLTYPE_TEXT: printf(" TEXT"); break;
31129 case COLTYPE_CUSTOM: {
31130 if( flg & COLFLAG_HASTYPE ){
31131 const char *z = aCol[i].zCnName;
31132 z += strlen(z)+1;
31133 printf(" X-%s", z);
31134 break;
31135 }
31136 }
31137 }
31138 if( flg & COLFLAG_PRIMKEY ) printf(" PRIMARY KEY");
31139 if( flg & COLFLAG_HIDDEN ) printf(" HIDDEN");
31140 #ifdef COLFLAG_NOEXPAND
31141 if( flg & COLFLAG_NOEXPAND ) printf(" NO-EXPAND");
31142 #endif
31143 if( flg ) printf(" flags=%04x", flg);
31144 printf("\n");
31145 fflush(stdout);
31146 sqlite3TreeViewPop(&pView);
31147 }
31148 sqlite3TreeViewPop(&pView);
31149 }
31150
31151 /*
31152 ** Generate a human-readable description of a WITH clause.
31153 */
31154 SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 moreToFollow){
@@ -31077,10 +31175,14 @@
31175 sqlite3_str_appendf(&x, "%c%s", cSep, pCte->pCols->a[j].zEName);
31176 cSep = ',';
31177 }
31178 sqlite3_str_appendf(&x, ")");
31179 }
31180 if( pCte->eM10d!=M10d_Any ){
31181 sqlite3_str_appendf(&x, " %sMATERIALIZED",
31182 pCte->eM10d==M10d_No ? "NOT " : "");
31183 }
31184 if( pCte->pUse ){
31185 sqlite3_str_appendf(&x, " (pUse=0x%p, nUse=%d)", pCte->pUse,
31186 pCte->pUse->nUse);
31187 }
31188 sqlite3StrAccumFinish(&x);
@@ -31099,10 +31201,11 @@
31201 int i;
31202 if( pSrc==0 ) return;
31203 for(i=0; i<pSrc->nSrc; i++){
31204 const SrcItem *pItem = &pSrc->a[i];
31205 StrAccum x;
31206 int n = 0;
31207 char zLine[100];
31208 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
31209 x.printfFlags |= SQLITE_PRINTF_INTERNAL;
31210 sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem);
31211 if( pItem->pTab ){
@@ -31127,13 +31230,24 @@
31230 if( pItem->fg.isCte ){
31231 sqlite3_str_appendf(&x, " CteUse=0x%p", pItem->u2.pCteUse);
31232 }
31233 sqlite3StrAccumFinish(&x);
31234 sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1);
31235 n = 0;
31236 if( pItem->pSelect ) n++;
31237 if( pItem->fg.isTabFunc ) n++;
31238 if( pItem->fg.isUsing ) n++;
31239 if( pItem->fg.isUsing ){
31240 sqlite3TreeViewIdList(pView, pItem->u3.pUsing, (--n)>0, "USING");
31241 }
31242 if( pItem->pSelect ){
31243 if( pItem->pTab ){
31244 Table *pTab = pItem->pTab;
31245 sqlite3TreeViewColumnList(pView, pTab->aCol, pTab->nCol, 1);
31246 }
31247 assert( pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
31248 sqlite3TreeViewSelect(pView, pItem->pSelect, (--n)>0);
31249 }
31250 if( pItem->fg.isTabFunc ){
31251 sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:");
31252 }
31253 sqlite3TreeViewPop(&pView);
@@ -31296,10 +31410,11 @@
31410 /*
31411 ** Generate a human-readable explanation for a Window object
31412 */
31413 SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){
31414 int nElement = 0;
31415 if( pWin==0 ) return;
31416 if( pWin->pFilter ){
31417 sqlite3TreeViewItem(pView, "FILTER", 1);
31418 sqlite3TreeViewExpr(pView, pWin->pFilter, 0);
31419 sqlite3TreeViewPop(&pView);
31420 }
@@ -31360,10 +31475,11 @@
31475 #ifndef SQLITE_OMIT_WINDOWFUNC
31476 /*
31477 ** Generate a human-readable explanation for a Window Function object
31478 */
31479 SQLITE_PRIVATE void sqlite3TreeViewWinFunc(TreeView *pView, const Window *pWin, u8 more){
31480 if( pWin==0 ) return;
31481 sqlite3TreeViewPush(&pView, more);
31482 sqlite3TreeViewLine(pView, "WINFUNC %s(%d)",
31483 pWin->pWFunc->zName, pWin->pWFunc->nArg);
31484 sqlite3TreeViewWindow(pView, pWin, 0);
31485 sqlite3TreeViewPop(&pView);
@@ -31386,12 +31502,15 @@
31502 if( pExpr->flags || pExpr->affExpr || pExpr->vvaFlags ){
31503 StrAccum x;
31504 sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0);
31505 sqlite3_str_appendf(&x, " fg.af=%x.%c",
31506 pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n');
31507 if( ExprHasProperty(pExpr, EP_OuterON) ){
31508 sqlite3_str_appendf(&x, " outer.iJoin=%d", pExpr->w.iJoin);
31509 }
31510 if( ExprHasProperty(pExpr, EP_InnerON) ){
31511 sqlite3_str_appendf(&x, " inner.iJoin=%d", pExpr->w.iJoin);
31512 }
31513 if( ExprHasProperty(pExpr, EP_FromDDL) ){
31514 sqlite3_str_appendf(&x, " DDL");
31515 }
31516 if( ExprHasVVAProperty(pExpr, EP_Immutable) ){
@@ -31611,11 +31730,21 @@
31730 sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags);
31731 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
31732 break;
31733 }
31734 case TK_IN: {
31735 sqlite3_str *pStr = sqlite3_str_new(0);
31736 char *z;
31737 sqlite3_str_appendf(pStr, "IN flags=0x%x", pExpr->flags);
31738 if( pExpr->iTable ) sqlite3_str_appendf(pStr, " iTable=%d",pExpr->iTable);
31739 if( ExprHasProperty(pExpr, EP_Subrtn) ){
31740 sqlite3_str_appendf(pStr, " subrtn(%d,%d)",
31741 pExpr->y.sub.regReturn, pExpr->y.sub.iAddr);
31742 }
31743 z = sqlite3_str_finish(pStr);
31744 sqlite3TreeViewLine(pView, z);
31745 sqlite3_free(z);
31746 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
31747 if( ExprUseXSelect(pExpr) ){
31748 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
31749 }else{
31750 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
@@ -31762,17 +31891,19 @@
31891 if( j || zName ){
31892 sqlite3TreeViewPush(&pView, moreToFollow);
31893 moreToFollow = 0;
31894 sqlite3TreeViewLine(pView, 0);
31895 if( zName ){
31896 switch( pList->a[i].fg.eEName ){
31897 default:
31898 fprintf(stdout, "AS %s ", zName);
31899 break;
31900 case ENAME_TAB:
31901 fprintf(stdout, "TABLE-ALIAS-NAME(\"%s\") ", zName);
31902 if( pList->a[i].fg.bUsed ) fprintf(stdout, "(used) ");
31903 if( pList->a[i].fg.bUsingTerm ) fprintf(stdout, "(USING-term) ");
31904 if( pList->a[i].fg.bNoExpand ) fprintf(stdout, "(NoExpand) ");
31905 break;
31906 case ENAME_SPAN:
31907 fprintf(stdout, "SPAN(\"%s\") ", zName);
31908 break;
31909 }
@@ -41741,90 +41872,103 @@
41872 }
41873 return SQLITE_OK;
41874 }
41875
41876 /*
41877 ** A pathname under construction
41878 */
41879 typedef struct DbPath DbPath;
41880 struct DbPath {
41881 int rc; /* Non-zero following any error */
41882 int nSymlink; /* Number of symlinks resolved */
41883 char *zOut; /* Write the pathname here */
41884 int nOut; /* Bytes of space available to zOut[] */
41885 int nUsed; /* Bytes of zOut[] currently being used */
41886 };
41887
41888 /* Forward reference */
41889 static void appendAllPathElements(DbPath*,const char*);
41890
41891 /*
41892 ** Append a single path element to the DbPath under construction
41893 */
41894 static void appendOnePathElement(
41895 DbPath *pPath, /* Path under construction, to which to append zName */
41896 const char *zName, /* Name to append to pPath. Not zero-terminated */
41897 int nName /* Number of significant bytes in zName */
41898 ){
41899 assert( nName>0 );
41900 assert( zName!=0 );
41901 if( zName[0]=='.' ){
41902 if( nName==1 ) return;
41903 if( zName[1]=='.' && nName==2 ){
41904 if( pPath->nUsed<=1 ){
41905 pPath->rc = SQLITE_ERROR;
41906 return;
41907 }
41908 assert( pPath->zOut[0]=='/' );
41909 while( pPath->zOut[--pPath->nUsed]!='/' ){}
41910 return;
41911 }
41912 }
41913 if( pPath->nUsed + nName + 2 >= pPath->nOut ){
41914 pPath->rc = SQLITE_ERROR;
41915 return;
41916 }
41917 pPath->zOut[pPath->nUsed++] = '/';
41918 memcpy(&pPath->zOut[pPath->nUsed], zName, nName);
41919 pPath->nUsed += nName;
41920 #if defined(HAVE_READLINK) && defined(HAVE_LSTAT)
41921 if( pPath->rc==SQLITE_OK ){
41922 const char *zIn;
41923 struct stat buf;
41924 pPath->zOut[pPath->nUsed] = 0;
41925 zIn = pPath->zOut;
41926 if( osLstat(zIn, &buf)!=0 ){
41927 if( errno!=ENOENT ){
41928 pPath->rc = unixLogError(SQLITE_CANTOPEN_BKPT, "lstat", zIn);
41929 }
41930 }else if( S_ISLNK(buf.st_mode) ){
41931 ssize_t got;
41932 char zLnk[SQLITE_MAX_PATHLEN+2];
41933 if( pPath->nSymlink++ > SQLITE_MAX_SYMLINK ){
41934 pPath->rc = SQLITE_CANTOPEN_BKPT;
41935 return;
41936 }
41937 got = osReadlink(zIn, zLnk, sizeof(zLnk)-2);
41938 if( got<=0 || got>=(ssize_t)sizeof(zLnk)-2 ){
41939 pPath->rc = unixLogError(SQLITE_CANTOPEN_BKPT, "readlink", zIn);
41940 return;
41941 }
41942 zLnk[got] = 0;
41943 if( zLnk[0]=='/' ){
41944 pPath->nUsed = 0;
41945 }else{
41946 pPath->nUsed -= nName + 1;
41947 }
41948 appendAllPathElements(pPath, zLnk);
41949 }
41950 }
41951 #endif
41952 }
41953
41954 /*
41955 ** Append all path elements in zPath to the DbPath under construction.
41956 */
41957 static void appendAllPathElements(
41958 DbPath *pPath, /* Path under construction, to which to append zName */
41959 const char *zPath /* Path to append to pPath. Is zero-terminated */
41960 ){
41961 int i = 0;
41962 int j = 0;
41963 do{
41964 while( zPath[i] && zPath[i]!='/' ){ i++; }
41965 if( i>j ){
41966 appendOnePathElement(pPath, &zPath[j], i-j);
41967 }
41968 j = i+1;
41969 }while( zPath[i++] );
41970 }
41971
41972 /*
41973 ** Turn a relative pathname into a full pathname. The relative path
41974 ** is stored as a nul-terminated string in the buffer pointed to by
@@ -41838,89 +41982,30 @@
41982 sqlite3_vfs *pVfs, /* Pointer to vfs object */
41983 const char *zPath, /* Possibly relative input path */
41984 int nOut, /* Size of output buffer in bytes */
41985 char *zOut /* Output buffer */
41986 ){
41987 DbPath path;
 
 
 
 
 
 
 
 
 
41988 UNUSED_PARAMETER(pVfs);
41989 path.rc = 0;
41990 path.nUsed = 0;
41991 path.nSymlink = 0;
41992 path.nOut = nOut;
41993 path.zOut = zOut;
41994 if( zPath[0]!='/' ){
41995 char zPwd[SQLITE_MAX_PATHLEN+2];
41996 if( osGetcwd(zPwd, sizeof(zPwd)-2)==0 ){
41997 return unixLogError(SQLITE_CANTOPEN_BKPT, "getcwd", zPath);
41998 }
41999 appendAllPathElements(&path, zPwd);
42000 }
42001 appendAllPathElements(&path, zPath);
42002 zOut[path.nUsed] = 0;
42003 if( path.rc || path.nUsed<2 ) return SQLITE_CANTOPEN_BKPT;
42004 if( path.nSymlink ) return SQLITE_OK_SYMLINK;
42005 return SQLITE_OK;
42006 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42007
42008 #ifndef SQLITE_OMIT_LOAD_EXTENSION
42009 /*
42010 ** Interfaces for opening a shared library, finding entry points
42011 ** within the shared library, and closing the shared library.
@@ -75861,11 +75946,11 @@
75946 }
75947
75948 TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
75949 pCur->pgnoRoot, pX->nKey, pX->nData, pPage->pgno,
75950 loc==0 ? "overwrite" : "new entry"));
75951 assert( pPage->isInit || CORRUPT_DB );
75952 newCell = pBt->pTmpSpace;
75953 assert( newCell!=0 );
75954 if( flags & BTREE_PREFORMAT ){
75955 rc = SQLITE_OK;
75956 szNew = pBt->nPreformatSize;
@@ -81423,10 +81508,94 @@
81508 pParse->nLabel = 0;
81509 *pMaxFuncArgs = nMaxArgs;
81510 assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) );
81511 }
81512
81513 #ifdef SQLITE_DEBUG
81514 /*
81515 ** Check to see if a subroutine contains a jump to a location outside of
81516 ** the subroutine. If a jump outside the subroutine is detected, add code
81517 ** that will cause the program to halt with an error message.
81518 **
81519 ** The subroutine consists of opcodes between iFirst and iLast. Jumps to
81520 ** locations within the subroutine are acceptable. iRetReg is a register
81521 ** that contains the return address. Jumps to outside the range of iFirst
81522 ** through iLast are also acceptable as long as the jump destination is
81523 ** an OP_Return to iReturnAddr.
81524 **
81525 ** A jump to an unresolved label means that the jump destination will be
81526 ** beyond the current address. That is normally a jump to an early
81527 ** termination and is consider acceptable.
81528 **
81529 ** This routine only runs during debug builds. The purpose is (of course)
81530 ** to detect invalid escapes out of a subroutine. The OP_Halt opcode
81531 ** is generated rather than an assert() or other error, so that ".eqp full"
81532 ** will still work to show the original bytecode, to aid in debugging.
81533 */
81534 SQLITE_PRIVATE void sqlite3VdbeNoJumpsOutsideSubrtn(
81535 Vdbe *v, /* The byte-code program under construction */
81536 int iFirst, /* First opcode of the subroutine */
81537 int iLast, /* Last opcode of the subroutine */
81538 int iRetReg /* Subroutine return address register */
81539 ){
81540 VdbeOp *pOp;
81541 Parse *pParse;
81542 int i;
81543 sqlite3_str *pErr = 0;
81544 assert( v!=0 );
81545 pParse = v->pParse;
81546 assert( pParse!=0 );
81547 if( pParse->nErr ) return;
81548 assert( iLast>=iFirst );
81549 assert( iLast<v->nOp );
81550 pOp = &v->aOp[iFirst];
81551 for(i=iFirst; i<=iLast; i++, pOp++){
81552 if( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 ){
81553 int iDest = pOp->p2; /* Jump destination */
81554 if( iDest==0 ) continue;
81555 if( pOp->opcode==OP_Gosub ) continue;
81556 if( iDest<0 ){
81557 int j = ADDR(iDest);
81558 assert( j>=0 );
81559 if( j>=-pParse->nLabel || pParse->aLabel[j]<0 ){
81560 continue;
81561 }
81562 iDest = pParse->aLabel[j];
81563 }
81564 if( iDest<iFirst || iDest>iLast ){
81565 int j = iDest;
81566 for(; j<v->nOp; j++){
81567 VdbeOp *pX = &v->aOp[j];
81568 if( pX->opcode==OP_Return ){
81569 if( pX->p1==iRetReg ) break;
81570 continue;
81571 }
81572 if( pX->opcode==OP_Noop ) continue;
81573 if( pX->opcode==OP_Explain ) continue;
81574 if( pErr==0 ){
81575 pErr = sqlite3_str_new(0);
81576 }else{
81577 sqlite3_str_appendchar(pErr, 1, '\n');
81578 }
81579 sqlite3_str_appendf(pErr,
81580 "Opcode at %d jumps to %d which is outside the "
81581 "subroutine at %d..%d",
81582 i, iDest, iFirst, iLast);
81583 break;
81584 }
81585 }
81586 }
81587 }
81588 if( pErr ){
81589 char *zErr = sqlite3_str_finish(pErr);
81590 sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_INTERNAL, OE_Abort, 0, zErr, 0);
81591 sqlite3_free(zErr);
81592 sqlite3MayAbort(pParse);
81593 }
81594 }
81595 #endif /* SQLITE_DEBUG */
81596
81597 /*
81598 ** Return the address of the next instruction to be inserted.
81599 */
81600 SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe *p){
81601 assert( p->eVdbeState==VDBE_INIT_STATE );
@@ -82035,15 +82204,13 @@
82204 if( c=='4' ){
82205 sqlite3_str_appendall(&x, zP4);
82206 }else if( c=='X' ){
82207 if( pOp->zComment && pOp->zComment[0] ){
82208 sqlite3_str_appendall(&x, pOp->zComment);
82209 seenCom = 1;
82210 break;
82211 }
 
 
82212 }else{
82213 int v1 = translateP(c, pOp);
82214 int v2;
82215 if( strncmp(zSynopsis+ii+1, "@P", 2)==0 ){
82216 ii += 3;
@@ -89154,10 +89321,12 @@
89321 if( pOp->p2==0 ) break;
89322
89323 /* Most jump operations do a goto to this spot in order to update
89324 ** the pOp pointer. */
89325 jump_to_p2:
89326 assert( pOp->p2>0 ); /* There are never any jumps to instruction 0 */
89327 assert( pOp->p2<p->nOp ); /* Jumps must be in range */
89328 pOp = &aOp[pOp->p2 - 1];
89329 break;
89330 }
89331
89332 /* Opcode: EndCoroutine P1 * * * *
@@ -101365,11 +101534,11 @@
101534 const char *zTab,
101535 const char *zDb
101536 ){
101537 int n;
101538 const char *zSpan;
101539 if( pItem->fg.eEName!=ENAME_TAB ) return 0;
101540 zSpan = pItem->zEName;
101541 for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
101542 if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){
101543 return 0;
101544 }
@@ -101594,12 +101763,13 @@
101763 }
101764 cnt++;
101765 cntTab = 2;
101766 pMatch = pItem;
101767 pExpr->iColumn = j;
101768 pEList->a[j].fg.bUsed = 1;
101769 hit = 1;
101770 if( pEList->a[j].fg.bUsingTerm ) break;
101771 }
101772 if( hit || zTab==0 ) continue;
101773 }
101774 assert( zDb==0 || zTab!=0 );
101775 if( zTab ){
@@ -101818,11 +101988,11 @@
101988 ){
101989 pEList = pNC->uNC.pEList;
101990 assert( pEList!=0 );
101991 for(j=0; j<pEList->nExpr; j++){
101992 char *zAs = pEList->a[j].zEName;
101993 if( pEList->a[j].fg.eEName==ENAME_NAME
101994 && sqlite3_stricmp(zAs, zCol)==0
101995 ){
101996 Expr *pOrig;
101997 assert( pExpr->pLeft==0 && pExpr->pRight==0 );
101998 assert( ExprUseXList(pExpr)==0 || pExpr->x.pList==0 );
@@ -102162,11 +102332,11 @@
102332 for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){
102333 anRef[i] = p->nRef;
102334 }
102335 sqlite3WalkExpr(pWalker, pExpr->pLeft);
102336 if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){
102337 testcase( ExprHasProperty(pExpr, EP_OuterON) );
102338 assert( !ExprHasProperty(pExpr, EP_IntValue) );
102339 if( pExpr->op==TK_NOTNULL ){
102340 pExpr->u.zToken = "true";
102341 ExprSetProperty(pExpr, EP_IsTrue);
102342 }else{
@@ -102571,11 +102741,11 @@
102741 if( pE->op==TK_ID ){
102742 const char *zCol;
102743 assert( !ExprHasProperty(pE, EP_IntValue) );
102744 zCol = pE->u.zToken;
102745 for(i=0; i<pEList->nExpr; i++){
102746 if( pEList->a[i].fg.eEName==ENAME_NAME
102747 && sqlite3_stricmp(pEList->a[i].zEName, zCol)==0
102748 ){
102749 return i+1;
102750 }
102751 }
@@ -102692,11 +102862,11 @@
102862 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
102863 sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause");
102864 return 1;
102865 }
102866 for(i=0; i<pOrderBy->nExpr; i++){
102867 pOrderBy->a[i].fg.done = 0;
102868 }
102869 pSelect->pNext = 0;
102870 while( pSelect->pPrior ){
102871 pSelect->pPrior->pNext = pSelect;
102872 pSelect = pSelect->pPrior;
@@ -102707,11 +102877,11 @@
102877 pEList = pSelect->pEList;
102878 assert( pEList!=0 );
102879 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
102880 int iCol = -1;
102881 Expr *pE, *pDup;
102882 if( pItem->fg.done ) continue;
102883 pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr);
102884 if( NEVER(pE==0) ) continue;
102885 if( sqlite3ExprIsInteger(pE, &iCol) ){
102886 if( iCol<=0 || iCol>pEList->nExpr ){
102887 resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr, pE);
@@ -102760,19 +102930,19 @@
102930 pParent->pLeft = pNew;
102931 }
102932 sqlite3ExprDelete(db, pE);
102933 pItem->u.x.iOrderByCol = (u16)iCol;
102934 }
102935 pItem->fg.done = 1;
102936 }else{
102937 moreToDo = 1;
102938 }
102939 }
102940 pSelect = pSelect->pNext;
102941 }
102942 for(i=0; i<pOrderBy->nExpr; i++){
102943 if( pOrderBy->a[i].fg.done==0 ){
102944 sqlite3ErrorMsg(pParse, "%r ORDER BY term does not match any "
102945 "column in the result set", i+1);
102946 return 1;
102947 }
102948 }
@@ -104453,10 +104623,11 @@
104623 pNew = sqlite3ExprAlloc(db, TK_FUNCTION, pToken, 1);
104624 if( pNew==0 ){
104625 sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */
104626 return 0;
104627 }
104628 assert( !ExprHasProperty(pNew, EP_InnerON|EP_OuterON) );
104629 pNew->w.iOfst = (int)(pToken->z - pParse->zTail);
104630 if( pList
104631 && pList->nExpr > pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG]
104632 && !pParse->nested
104633 ){
@@ -104731,11 +104902,11 @@
104902 #endif
104903 ){
104904 nSize = EXPR_FULLSIZE;
104905 }else{
104906 assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
104907 assert( !ExprHasProperty(p, EP_OuterON) );
104908 assert( !ExprHasProperty(p, EP_MemToken) );
104909 assert( !ExprHasVVAProperty(p, EP_NoReduce) );
104910 if( p->pLeft || p->x.pList ){
104911 nSize = EXPR_REDUCEDSIZE | EP_Reduced;
104912 }else{
@@ -104911,10 +105082,11 @@
105082 pRet->nCte = p->nCte;
105083 for(i=0; i<p->nCte; i++){
105084 pRet->a[i].pSelect = sqlite3SelectDup(db, p->a[i].pSelect, 0);
105085 pRet->a[i].pCols = sqlite3ExprListDup(db, p->a[i].pCols, 0);
105086 pRet->a[i].zName = sqlite3DbStrDup(db, p->a[i].zName);
105087 pRet->a[i].eM10d = p->a[i].eM10d;
105088 }
105089 }
105090 }
105091 return pRet;
105092 }
@@ -105011,16 +105183,12 @@
105183 }
105184 pNewExpr->pLeft = pPriorSelectColNew;
105185 }
105186 }
105187 pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName);
105188 pItem->fg = pOldItem->fg;
105189 pItem->fg.done = 0;
 
 
 
 
105190 pItem->u = pOldItem->u;
105191 }
105192 return pNew;
105193 }
105194
@@ -105316,20 +105484,20 @@
105484 || eNulls==SQLITE_SO_ASC
105485 || eNulls==SQLITE_SO_DESC
105486 );
105487
105488 pItem = &p->a[p->nExpr-1];
105489 assert( pItem->fg.bNulls==0 );
105490 if( iSortOrder==SQLITE_SO_UNDEFINED ){
105491 iSortOrder = SQLITE_SO_ASC;
105492 }
105493 pItem->fg.sortFlags = (u8)iSortOrder;
105494
105495 if( eNulls!=SQLITE_SO_UNDEFINED ){
105496 pItem->fg.bNulls = 1;
105497 if( iSortOrder!=eNulls ){
105498 pItem->fg.sortFlags |= KEYINFO_ORDER_BIGNULL;
105499 }
105500 }
105501 }
105502
105503 /*
@@ -105351,11 +105519,11 @@
105519 if( pList ){
105520 struct ExprList_item *pItem;
105521 assert( pList->nExpr>0 );
105522 pItem = &pList->a[pList->nExpr-1];
105523 assert( pItem->zEName==0 );
105524 assert( pItem->fg.eEName==ENAME_NAME );
105525 pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
105526 if( dequote ){
105527 /* If dequote==0, then pName->z does not point to part of a DDL
105528 ** statement handled by the parser. And so no token need be added
105529 ** to the token-map. */
@@ -105386,11 +105554,11 @@
105554 if( pList ){
105555 struct ExprList_item *pItem = &pList->a[pList->nExpr-1];
105556 assert( pList->nExpr>0 );
105557 if( pItem->zEName==0 ){
105558 pItem->zEName = sqlite3DbSpanDup(db, zStart, zEnd);
105559 pItem->fg.eEName = ENAME_SPAN;
105560 }
105561 }
105562 }
105563
105564 /*
@@ -105560,11 +105728,11 @@
105728 static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
105729
105730 /* If pWalker->eCode is 2 then any term of the expression that comes from
105731 ** the ON or USING clauses of an outer join disqualifies the expression
105732 ** from being considered constant. */
105733 if( pWalker->eCode==2 && ExprHasProperty(pExpr, EP_OuterON) ){
105734 pWalker->eCode = 0;
105735 return WRC_Abort;
105736 }
105737
105738 switch( pExpr->op ){
@@ -105678,10 +105846,46 @@
105846 ** table other than iCur.
105847 */
105848 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){
105849 return exprIsConst(p, 3, iCur);
105850 }
105851
105852 /*
105853 ** Check pExpr to see if it is an invariant constraint on data source pSrc.
105854 ** This is an optimization. False negatives will perhaps cause slower
105855 ** queries, but false positives will yield incorrect answers. So when in
105856 ** doubt, return 0.
105857 **
105858 ** To be an invariant constraint, the following must be true:
105859 **
105860 ** (1) pExpr cannot refer to any table other than pSrc->iCursor.
105861 **
105862 ** (2) pExpr cannot use subqueries or non-deterministic functions.
105863 **
105864 ** (3) pSrc cannot be part of the left operand for a RIGHT JOIN.
105865 ** (Is there some way to relax this constraint?)
105866 **
105867 ** (4) If pSrc is the right operand of a LEFT JOIN, then...
105868 ** (4a) pExpr must come from an ON clause..
105869 (4b) and specifically the ON clause associated with the LEFT JOIN.
105870 **
105871 ** (5) If pSrc is not the right operand of a LEFT JOIN or the left
105872 ** operand of a RIGHT JOIN, then pExpr must be from the WHERE
105873 ** clause, not an ON clause.
105874 */
105875 SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr *pExpr, const SrcItem *pSrc){
105876 if( pSrc->fg.jointype & JT_LTORJ ){
105877 return 0; /* rule (3) */
105878 }
105879 if( pSrc->fg.jointype & JT_LEFT ){
105880 if( !ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* rule (4a) */
105881 if( pExpr->w.iJoin!=pSrc->iCursor ) return 0; /* rule (4b) */
105882 }else{
105883 if( ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* rule (5) */
105884 }
105885 return sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor); /* rules (1), (2) */
105886 }
105887
105888
105889 /*
105890 ** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy().
105891 */
@@ -106006,11 +106210,11 @@
106210 ** The job of this routine is to find or create a b-tree object that can
106211 ** be used either to test for membership in the RHS set or to iterate through
106212 ** all members of the RHS set, skipping duplicates.
106213 **
106214 ** A cursor is opened on the b-tree object that is the RHS of the IN operator
106215 ** and the *piTab parameter is set to the index of that cursor.
106216 **
106217 ** The returned value of this function indicates the b-tree type, as follows:
106218 **
106219 ** IN_INDEX_ROWID - The cursor was opened on a database table.
106220 ** IN_INDEX_INDEX_ASC - The cursor was opened on an ascending index.
@@ -106026,11 +106230,14 @@
106230 ** SELECT <column1>, <column2>... FROM <table>
106231 **
106232 ** If the RHS of the IN operator is a list or a more complex subquery, then
106233 ** an ephemeral table might need to be generated from the RHS and then
106234 ** pX->iTable made to point to the ephemeral table instead of an
106235 ** existing table. In this case, the creation and initialization of the
106236 ** ephmeral table might be put inside of a subroutine, the EP_Subrtn flag
106237 ** will be set on pX and the pX->y.sub fields will be set to show where
106238 ** the subroutine is coded.
106239 **
106240 ** The inFlags parameter must contain, at a minimum, one of the bits
106241 ** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP but not both. If inFlags contains
106242 ** IN_INDEX_MEMBERSHIP, then the generated table will be used for a fast
106243 ** membership test. When the IN_INDEX_LOOP bit is set, the IN index will
@@ -106087,16 +106294,17 @@
106294 int *aiMap, /* Mapping from Index fields to RHS fields */
106295 int *piTab /* OUT: index to use */
106296 ){
106297 Select *p; /* SELECT to the right of IN operator */
106298 int eType = 0; /* Type of RHS table. IN_INDEX_* */
106299 int iTab; /* Cursor of the RHS table */
106300 int mustBeUnique; /* True if RHS must be unique */
106301 Vdbe *v = sqlite3GetVdbe(pParse); /* Virtual machine being coded */
106302
106303 assert( pX->op==TK_IN );
106304 mustBeUnique = (inFlags & IN_INDEX_LOOP)!=0;
106305 iTab = pParse->nTab++;
106306
106307 /* If the RHS of this IN(...) operator is a SELECT, and if it matters
106308 ** whether or not the SELECT result contains NULL values, check whether
106309 ** or not NULL is actually possible (it may not be, for example, due
106310 ** to NOT NULL constraints in the schema). If no NULL values are possible,
@@ -106258,10 +106466,12 @@
106466 if( eType==0
106467 && (inFlags & IN_INDEX_NOOP_OK)
106468 && ExprUseXList(pX)
106469 && (!sqlite3InRhsIsConstant(pX) || pX->x.pList->nExpr<=2)
106470 ){
106471 pParse->nTab--; /* Back out the allocation of the unused cursor */
106472 iTab = -1; /* Cursor is not allocated */
106473 eType = IN_INDEX_NOOP;
106474 }
106475
106476 if( eType==0 ){
106477 /* Could not find an existing table or index to use as the RHS b-tree.
@@ -106424,10 +106634,11 @@
106634 pExpr->x.pSelect->selId));
106635 }
106636 assert( ExprUseYSub(pExpr) );
106637 sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
106638 pExpr->y.sub.iAddr);
106639 assert( iTab!=pExpr->iTable );
106640 sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable);
106641 sqlite3VdbeJumpHere(v, addrOnce);
106642 return;
106643 }
106644
@@ -107298,11 +107509,21 @@
107509 memset(&caseExpr, 0, sizeof(caseExpr));
107510 caseExpr.op = TK_CASE;
107511 caseExpr.x.pList = pFarg;
107512 return sqlite3ExprCodeTarget(pParse, &caseExpr, target);
107513 }
107514 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
107515 case INLINEFUNC_sqlite_offset: {
107516 Expr *pArg = pFarg->a[0].pExpr;
107517 if( pArg->op==TK_COLUMN && pArg->iTable>=0 ){
107518 sqlite3VdbeAddOp3(v, OP_Offset, pArg->iTable, pArg->iColumn, target);
107519 }else{
107520 sqlite3VdbeAddOp2(v, OP_Null, 0, target);
107521 }
107522 break;
107523 }
107524 #endif
107525 default: {
107526 /* The UNLIKELY() function is a no-op. The result is the value
107527 ** of the first argument.
107528 */
107529 assert( nFarg==1 || nFarg==2 );
@@ -107837,24 +108058,12 @@
108058 #endif
108059 if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){
108060 if( !pColl ) pColl = db->pDfltColl;
108061 sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
108062 }
108063 sqlite3VdbeAddFunctionCall(pParse, constMask, r1, target, nFarg,
108064 pDef, pExpr->op2);
 
 
 
 
 
 
 
 
 
 
 
 
108065 if( nFarg ){
108066 if( constMask==0 ){
108067 sqlite3ReleaseTempRange(pParse, r1, nFarg);
108068 }else{
108069 sqlite3VdbeReleaseRegisters(pParse, r1, nFarg, constMask, 1);
@@ -108164,11 +108373,13 @@
108373 p = pParse->pConstExpr;
108374 if( regDest<0 && p ){
108375 struct ExprList_item *pItem;
108376 int i;
108377 for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
108378 if( pItem->fg.reusable
108379 && sqlite3ExprCompare(0,pItem->pExpr,pExpr,-1)==0
108380 ){
108381 return pItem->u.iConstExprReg;
108382 }
108383 }
108384 }
108385 pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
@@ -108187,11 +108398,11 @@
108398 sqlite3VdbeJumpHere(v, addr);
108399 }else{
108400 p = sqlite3ExprListAppend(pParse, p, pExpr);
108401 if( p ){
108402 struct ExprList_item *pItem = &p->a[p->nExpr-1];
108403 pItem->fg.reusable = regDest<0;
108404 if( regDest<0 ) regDest = ++pParse->nMem;
108405 pItem->u.iConstExprReg = regDest;
108406 }
108407 pParse->pConstExpr = p;
108408 }
@@ -108321,11 +108532,11 @@
108532 n = pList->nExpr;
108533 if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR;
108534 for(pItem=pList->a, i=0; i<n; i++, pItem++){
108535 Expr *pExpr = pItem->pExpr;
108536 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
108537 if( pItem->fg.bSorterRef ){
108538 i--;
108539 n--;
108540 }else
108541 #endif
108542 if( (flags & SQLITE_ECEL_REF)!=0 && (j = pItem->u.x.iOrderByCol)>0 ){
@@ -108415,12 +108626,12 @@
108626 }else{
108627 /* Mark the expression is being from the ON or USING clause of a join
108628 ** so that the sqlite3ExprCodeTarget() routine will not attempt to move
108629 ** it into the Parse.pConstExpr list. We should use a new bit for this,
108630 ** for clarity, but we are out of bits in the Expr.flags field so we
108631 ** have to reuse the EP_OuterON bit. Bummer. */
108632 pDel->flags |= EP_OuterON;
108633 sqlite3ExprCodeTarget(pParse, &exprAnd, dest);
108634 }
108635 sqlite3ReleaseTempReg(pParse, regFree1);
108636 }
108637 sqlite3ExprDelete(db, pDel);
@@ -108946,11 +109157,11 @@
109157 if( pA->nExpr!=pB->nExpr ) return 1;
109158 for(i=0; i<pA->nExpr; i++){
109159 int res;
109160 Expr *pExprA = pA->a[i].pExpr;
109161 Expr *pExprB = pB->a[i].pExpr;
109162 if( pA->a[i].fg.sortFlags!=pB->a[i].fg.sortFlags ) return 1;
109163 if( (res = sqlite3ExprCompare(0, pExprA, pExprB, iTab)) ) return res;
109164 }
109165 return 0;
109166 }
109167
@@ -109101,11 +109312,11 @@
109312 ** (never setting pWalker->eCode) is a harmless missed optimization.
109313 */
109314 static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){
109315 testcase( pExpr->op==TK_AGG_COLUMN );
109316 testcase( pExpr->op==TK_AGG_FUNCTION );
109317 if( ExprHasProperty(pExpr, EP_OuterON) ) return WRC_Prune;
109318 switch( pExpr->op ){
109319 case TK_ISNOT:
109320 case TK_ISNULL:
109321 case TK_NOTNULL:
109322 case TK_IS:
@@ -109198,11 +109409,11 @@
109409 ** is NULL. A false negative is merely a missed optimization opportunity.
109410 **
109411 ** False positives are not allowed, however. A false positive may result
109412 ** in an incorrect answer.
109413 **
109414 ** Terms of p that are marked with EP_OuterON (and hence that come from
109415 ** the ON or USING clauses of OUTER JOINS) are excluded from the analysis.
109416 **
109417 ** This routine is used to check if a LEFT JOIN can be converted into
109418 ** an ordinary JOIN. The p argument is the WHERE clause. If the WHERE
109419 ** clause requires that some column of the right table of the LEFT JOIN
@@ -110635,11 +110846,11 @@
110846 return WRC_Prune;
110847 }
110848 if( ALWAYS(p->pEList) ){
110849 ExprList *pList = p->pEList;
110850 for(i=0; i<pList->nExpr; i++){
110851 if( pList->a[i].zEName && pList->a[i].fg.eEName==ENAME_NAME ){
110852 sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName);
110853 }
110854 }
110855 }
110856 if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */
@@ -110684,11 +110895,11 @@
110895 memset(&sWalker, 0, sizeof(Walker));
110896 sWalker.pParse = pParse;
110897 sWalker.xExprCallback = renameUnmapExprCb;
110898 sqlite3WalkExprList(&sWalker, pEList);
110899 for(i=0; i<pEList->nExpr; i++){
110900 if( ALWAYS(pEList->a[i].fg.eEName==ENAME_NAME) ){
110901 sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName);
110902 }
110903 }
110904 }
110905 }
@@ -110842,11 +111053,11 @@
111053 ){
111054 if( pEList ){
111055 int i;
111056 for(i=0; i<pEList->nExpr; i++){
111057 const char *zName = pEList->a[i].zEName;
111058 if( ALWAYS(pEList->a[i].fg.eEName==ENAME_NAME)
111059 && ALWAYS(zName!=0)
111060 && 0==sqlite3_stricmp(zName, zOld)
111061 ){
111062 renameTokenFind(pParse, pCtx, (const void*)zName);
111063 }
@@ -111072,31 +111283,37 @@
111283 if( pParse->nErr ) rc = pParse->rc;
111284 }
111285 if( rc==SQLITE_OK && pStep->zTarget ){
111286 SrcList *pSrc = sqlite3TriggerStepSrc(pParse, pStep);
111287 if( pSrc ){
111288 Select *pSel = sqlite3SelectNew(
111289 pParse, pStep->pExprList, pSrc, 0, 0, 0, 0, 0, 0
111290 );
111291 if( pSel==0 ){
111292 pStep->pExprList = 0;
111293 pSrc = 0;
111294 rc = SQLITE_NOMEM;
111295 }else{
111296 sqlite3SelectPrep(pParse, pSel, 0);
111297 rc = pParse->nErr ? SQLITE_ERROR : SQLITE_OK;
111298 assert( pStep->pExprList==0 || pStep->pExprList==pSel->pEList );
111299 assert( pSrc==pSel->pSrc );
111300 if( pStep->pExprList ) pSel->pEList = 0;
111301 pSel->pSrc = 0;
111302 sqlite3SelectDelete(db, pSel);
111303 }
111304 if( pStep->pFrom ){
111305 int i;
111306 for(i=0; i<pStep->pFrom->nSrc && rc==SQLITE_OK; i++){
111307 SrcItem *p = &pStep->pFrom->a[i];
111308 if( p->pSelect ){
111309 sqlite3SelectPrep(pParse, p->pSelect, 0);
111310 }
111311 }
111312 }
111313
111314 if( db->mallocFailed ){
111315 rc = SQLITE_NOMEM;
111316 }
111317 sNC.pSrcList = pSrc;
111318 if( rc==SQLITE_OK && pStep->pWhere ){
111319 rc = sqlite3ResolveExprNames(&sNC, pStep->pWhere);
@@ -111543,10 +111760,19 @@
111760 if( rc==SQLITE_OK ){
111761 renameWalkTrigger(&sWalker, pTrigger);
111762 for(pStep=pTrigger->step_list; pStep; pStep=pStep->pNext){
111763 if( pStep->zTarget && 0==sqlite3_stricmp(pStep->zTarget, zOld) ){
111764 renameTokenFind(&sParse, &sCtx, pStep->zTarget);
111765 }
111766 if( pStep->pFrom ){
111767 int i;
111768 for(i=0; i<pStep->pFrom->nSrc; i++){
111769 SrcItem *pItem = &pStep->pFrom->a[i];
111770 if( 0==sqlite3_stricmp(pItem->zName, zOld) ){
111771 renameTokenFind(&sParse, &sCtx, pItem->zName);
111772 }
111773 }
111774 }
111775 }
111776 }
111777 }
111778 }
@@ -112867,13 +113093,18 @@
113093 ** * the index contains 100 rows,
113094 ** * "WHERE a=?" matches 10 rows, and
113095 ** * "WHERE a=? AND b=?" matches 2 rows.
113096 **
113097 ** If D is the count of distinct values and K is the total number of
113098 ** rows, then each estimate is usually computed as:
113099 **
113100 ** I = (K+D-1)/D
113101 **
113102 ** In other words, I is K/D rounded up to the next whole integer.
113103 ** However, if I is between 1.0 and 1.1 (in other words if I is
113104 ** close to 1.0 but just a little larger) then do not round up but
113105 ** instead keep the I value at 1.0.
113106 */
113107 sqlite3_str sStat; /* Text of the constructed "stat" line */
113108 int i; /* Loop counter */
113109
113110 sqlite3StrAccumInit(&sStat, 0, 0, 0, (p->nKeyCol+1)*100);
@@ -112880,10 +113111,11 @@
113111 sqlite3_str_appendf(&sStat, "%llu",
113112 p->nSkipAhead ? (u64)p->nEst : (u64)p->nRow);
113113 for(i=0; i<p->nKeyCol; i++){
113114 u64 nDistinct = p->current.anDLt[i] + 1;
113115 u64 iVal = (p->nRow + nDistinct - 1) / nDistinct;
113116 if( iVal==2 && p->nRow*10 <= nDistinct*11 ) iVal = 1;
113117 sqlite3_str_appendf(&sStat, " %llu", iVal);
113118 assert( p->current.anEq[i] );
113119 }
113120 sqlite3ResultStrAccum(context, &sStat);
113121 }
@@ -115001,13 +115233,11 @@
115233 Returning *pReturning = pParse->u1.pReturning;
115234 int addrRewind;
115235 int i;
115236 int reg;
115237
115238 if( pReturning->nRetCol ){
 
 
115239 sqlite3VdbeAddOp0(v, OP_FkCheck);
115240 addrRewind =
115241 sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur);
115242 VdbeCoverage(v);
115243 reg = pReturning->iRetReg;
@@ -115099,13 +115329,11 @@
115329 }
115330 }
115331
115332 if( pParse->bReturning ){
115333 Returning *pRet = pParse->u1.pReturning;
115334 if( pRet->nRetCol ){
 
 
115335 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
115336 }
115337 }
115338
115339 /* Finally, jump back to the beginning of the executable code. */
@@ -116723,11 +116951,11 @@
116951 }
116952 pTab->iPKey = iCol;
116953 pTab->keyConf = (u8)onError;
116954 assert( autoInc==0 || autoInc==1 );
116955 pTab->tabFlags |= autoInc*TF_Autoincrement;
116956 if( pList ) pParse->iPkSortOrder = pList->a[0].fg.sortFlags;
116957 (void)sqlite3HasExplicitNulls(pParse, pList);
116958 }else if( autoInc ){
116959 #ifndef SQLITE_OMIT_AUTOINCREMENT
116960 sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an "
116961 "INTEGER PRIMARY KEY");
@@ -117217,11 +117445,11 @@
117445 return;
117446 }
117447 if( IN_RENAME_OBJECT ){
117448 sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey);
117449 }
117450 pList->a[0].fg.sortFlags = pParse->iPkSortOrder;
117451 assert( pParse->pNewTable==pTab );
117452 pTab->iPKey = -1;
117453 sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
117454 SQLITE_IDXTYPE_PRIMARYKEY);
117455 if( pParse->nErr ){
@@ -117888,11 +118116,10 @@
118116 */
118117 SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
118118 Table *pSelTab; /* A fake table from which we get the result set */
118119 Select *pSel; /* Copy of the SELECT that implements the view */
118120 int nErr = 0; /* Number of errors encountered */
 
118121 sqlite3 *db = pParse->db; /* Database connection for malloc errors */
118122 #ifndef SQLITE_OMIT_VIRTUALTABLE
118123 int rc;
118124 #endif
118125 #ifndef SQLITE_OMIT_AUTHORIZATION
@@ -117946,12 +118173,13 @@
118173 */
118174 assert( IsView(pTable) );
118175 pSel = sqlite3SelectDup(db, pTable->u.view.pSelect, 0);
118176 if( pSel ){
118177 u8 eParseMode = pParse->eParseMode;
118178 int nTab = pParse->nTab;
118179 int nSelect = pParse->nSelect;
118180 pParse->eParseMode = PARSE_MODE_NORMAL;
 
118181 sqlite3SrcListAssignCursors(pParse, pSel->pSrc);
118182 pTable->nCol = -1;
118183 DisableLookaside;
118184 #ifndef SQLITE_OMIT_AUTHORIZATION
118185 xAuth = db->xAuth;
@@ -117959,11 +118187,12 @@
118187 pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, SQLITE_AFF_NONE);
118188 db->xAuth = xAuth;
118189 #else
118190 pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, SQLITE_AFF_NONE);
118191 #endif
118192 pParse->nTab = nTab;
118193 pParse->nSelect = nSelect;
118194 if( pSelTab==0 ){
118195 pTable->nCol = 0;
118196 nErr++;
118197 }else if( pTable->pCheck ){
118198 /* CREATE VIEW name(arglist) AS ...
@@ -118704,12 +118933,12 @@
118933 */
118934 SQLITE_PRIVATE int sqlite3HasExplicitNulls(Parse *pParse, ExprList *pList){
118935 if( pList ){
118936 int i;
118937 for(i=0; i<pList->nExpr; i++){
118938 if( pList->a[i].fg.bNulls ){
118939 u8 sf = pList->a[i].fg.sortFlags;
118940 sqlite3ErrorMsg(pParse, "unsupported use of NULLS %s",
118941 (sf==0 || sf==3) ? "FIRST" : "LAST"
118942 );
118943 return 1;
118944 }
@@ -119058,11 +119287,11 @@
119287 if( !zColl ) zColl = sqlite3StrBINARY;
119288 if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
119289 goto exit_create_index;
119290 }
119291 pIndex->azColl[i] = zColl;
119292 requestedSortOrder = pListItem->fg.sortFlags & sortOrderMask;
119293 pIndex->aSortOrder[i] = (u8)requestedSortOrder;
119294 }
119295
119296 /* Append the table key to the end of the index. For WITHOUT ROWID
119297 ** tables (when pPk!=0) this will be the declared PRIMARY KEY. For
@@ -124139,15 +124368,15 @@
124368 }else{
124369 ans = log(x);
124370 switch( SQLITE_PTR_TO_INT(sqlite3_user_data(context)) ){
124371 case 1:
124372 /* Convert from natural logarithm to log base 10 */
124373 ans /= M_LN10;
124374 break;
124375 case 2:
124376 /* Convert from natural logarithm to log base 2 */
124377 ans /= M_LN2;
124378 break;
124379 default:
124380 break;
124381 }
124382 }
@@ -124282,12 +124511,11 @@
124511 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
124512 INLINE_FUNC(unlikely, 1, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY),
124513 INLINE_FUNC(likelihood, 2, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY),
124514 INLINE_FUNC(likely, 1, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY),
124515 #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
124516 INLINE_FUNC(sqlite_offset, 1, INLINEFUNC_sqlite_offset, 0 ),
 
124517 #endif
124518 FUNCTION(ltrim, 1, 1, 0, trimFunc ),
124519 FUNCTION(ltrim, 2, 1, 0, trimFunc ),
124520 FUNCTION(rtrim, 1, 2, 0, trimFunc ),
124521 FUNCTION(rtrim, 2, 2, 0, trimFunc ),
@@ -129567,10 +129795,11 @@
129795 /* Version 3.39.0 and later */
129796 int (*deserialize)(sqlite3*,const char*,unsigned char*,
129797 sqlite3_int64,sqlite3_int64,unsigned);
129798 unsigned char *(*serialize)(sqlite3*,const char *,sqlite3_int64*,
129799 unsigned int);
129800 const char *(*db_name)(sqlite3*,int);
129801 };
129802
129803 /*
129804 ** This is the function signature used for all extension entry points. It
129805 ** is also defined in the file "loadext.c".
@@ -129885,14 +130114,16 @@
130114 #define sqlite3_vtab_rhs_value sqlite3_api->vtab_rhs_value
130115 #define sqlite3_vtab_distinct sqlite3_api->vtab_distinct
130116 #define sqlite3_vtab_in sqlite3_api->vtab_in
130117 #define sqlite3_vtab_in_first sqlite3_api->vtab_in_first
130118 #define sqlite3_vtab_in_next sqlite3_api->vtab_in_next
130119 /* Version 3.39.0 and later */
130120 #ifndef SQLITE_OMIT_DESERIALIZE
130121 #define sqlite3_deserialize sqlite3_api->deserialize
130122 #define sqlite3_serialize sqlite3_api->serialize
130123 #endif
130124 #define sqlite3_db_name sqlite3_api->db_name
130125 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
130126
130127 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
130128 /* This case when the file really is being compiled as a loadable
130129 ** extension */
@@ -130380,23 +130611,32 @@
130611 sqlite3_total_changes64,
130612 /* Version 3.37.0 and later */
130613 sqlite3_autovacuum_pages,
130614 /* Version 3.38.0 and later */
130615 sqlite3_error_offset,
130616 #ifndef SQLITE_OMIT_VIRTUALTABLE
130617 sqlite3_vtab_rhs_value,
130618 sqlite3_vtab_distinct,
130619 sqlite3_vtab_in,
130620 sqlite3_vtab_in_first,
130621 sqlite3_vtab_in_next,
130622 #else
130623 0,
130624 0,
130625 0,
130626 0,
130627 0,
130628 #endif
130629 /* Version 3.39.0 and later */
130630 #ifndef SQLITE_OMIT_DESERIALIZE
130631 sqlite3_deserialize,
130632 sqlite3_serialize,
130633 #else
130634 0,
130635 0,
 
130636 #endif
130637 sqlite3_db_name
130638 };
130639
130640 /* True if x is the directory separator character
130641 */
130642 #if SQLITE_OS_WIN
@@ -134828,10 +135068,18 @@
135068 db->pParse = pParse;
135069 pParse->db = db;
135070 if( db->mallocFailed ) sqlite3ErrorMsg(pParse, "out of memory");
135071 }
135072
135073 /*
135074 ** Maximum number of times that we will try again to prepare a statement
135075 ** that returns SQLITE_ERROR_RETRY.
135076 */
135077 #ifndef SQLITE_MAX_PREPARE_RETRY
135078 # define SQLITE_MAX_PREPARE_RETRY 25
135079 #endif
135080
135081 /*
135082 ** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
135083 */
135084 static int sqlite3Prepare(
135085 sqlite3 *db, /* Database handle. */
@@ -135002,11 +135250,11 @@
135250 ** or encounters a permanent error. A schema problem after one schema
135251 ** reset is considered a permanent error. */
135252 rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail);
135253 assert( rc==SQLITE_OK || *ppStmt==0 );
135254 if( rc==SQLITE_OK || db->mallocFailed ) break;
135255 }while( (rc==SQLITE_ERROR_RETRY && (cnt++)<SQLITE_MAX_PREPARE_RETRY)
135256 || (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) );
135257 sqlite3BtreeLeaveAll(db);
135258 rc = sqlite3ApiExit(db, rc);
135259 assert( (rc&db->errMask)==rc );
135260 db->busyHandler.nBusy = 0;
@@ -135553,11 +135801,11 @@
135801 ExprList *pResults;
135802 assert( pItem->pSelect!=0 );
135803 pResults = pItem->pSelect->pEList;
135804 assert( pResults!=0 );
135805 assert( iCol>=0 && iCol<pResults->nExpr );
135806 pResults->a[iCol].fg.bUsed = 1;
135807 }
135808 }
135809
135810 /*
135811 ** Search the tables iStart..iEnd (inclusive) in pSrc, looking for a
@@ -135600,15 +135848,15 @@
135848 }
135849 return 0;
135850 }
135851
135852 /*
135853 ** Set the EP_OuterON property on all terms of the given expression.
135854 ** And set the Expr.w.iJoin to iTable for every term in the
135855 ** expression.
135856 **
135857 ** The EP_OuterON property is used on terms of an expression to tell
135858 ** the OUTER JOIN processing logic that this term is part of the
135859 ** join restriction specified in the ON or USING clause and not a part
135860 ** of the more general WHERE clause. These terms are moved over to the
135861 ** WHERE clause during join processing but we need to remember that they
135862 ** originated in the ON or USING clause.
@@ -135626,11 +135874,11 @@
135874 ** defer the handling of t1.x=5, it will be processed immediately
135875 ** after the t1 loop and rows with t1.x!=5 will never appear in
135876 ** the output, which is incorrect.
135877 */
135878 SQLITE_PRIVATE void sqlite3SetJoinExpr(Expr *p, int iTable, u32 joinFlag){
135879 assert( joinFlag==EP_OuterON || joinFlag==EP_InnerON );
135880 while( p ){
135881 ExprSetProperty(p, joinFlag);
135882 assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
135883 ExprSetVVAProperty(p, EP_NoReduce);
135884 p->w.iJoin = iTable;
@@ -135647,21 +135895,21 @@
135895 p = p->pRight;
135896 }
135897 }
135898
135899 /* Undo the work of sqlite3SetJoinExpr(). In the expression p, convert every
135900 ** term that is marked with EP_OuterON and w.iJoin==iTable into
135901 ** an ordinary term that omits the EP_OuterON mark.
135902 **
135903 ** This happens when a LEFT JOIN is simplified into an ordinary JOIN.
135904 */
135905 static void unsetJoinExpr(Expr *p, int iTable){
135906 while( p ){
135907 if( ExprHasProperty(p, EP_OuterON)
135908 && (iTable<0 || p->w.iJoin==iTable) ){
135909 ExprClearProperty(p, EP_OuterON);
135910 ExprSetProperty(p, EP_InnerON);
135911 }
135912 if( p->op==TK_COLUMN && p->iTable==iTable ){
135913 ExprClearProperty(p, EP_CanBeNull);
135914 }
135915 if( p->op==TK_FUNCTION ){
@@ -135685,12 +135933,12 @@
135933 ** do not need to be concerned with NATURAL joins and we only have
135934 ** think about USING joins.
135935 **
135936 ** * ON and USING clauses result in extra terms being added to the
135937 ** WHERE clause to enforce the specified constraints. The extra
135938 ** WHERE clause terms will be tagged with EP_OuterON or
135939 ** EP_InnerON so that we know that they originated in ON/USING.
135940 **
135941 ** The terms of a FROM clause are contained in the Select.pSrc structure.
135942 ** The left most table is the first entry in Select.pSrc. The right-most
135943 ** table is the last entry. The join operator is held in the entry to
135944 ** the right. Thus entry 1 contains the join operator for the join between
@@ -135711,11 +135959,11 @@
135959 for(i=0; i<pSrc->nSrc-1; i++, pRight++, pLeft++){
135960 Table *pRightTab = pRight->pTab;
135961 u32 joinType;
135962
135963 if( NEVER(pLeft->pTab==0 || pRightTab==0) ) continue;
135964 joinType = (pRight->fg.jointype & JT_OUTER)!=0 ? EP_OuterON : EP_InnerON;
135965
135966 /* If this is a NATURAL join, synthesize an approprate USING clause
135967 ** to specify which columns should be joined.
135968 */
135969 if( pRight->fg.jointype & JT_NATURAL ){
@@ -136221,11 +136469,11 @@
136469 ** the row from table t1 is stored instead. Then, as records are extracted from
136470 ** the sorter to return to the user, the required value of bigblob is
136471 ** retrieved directly from table t1. If the values are very large, this
136472 ** can be more efficient than storing them directly in the sorter records.
136473 **
136474 ** The ExprList_item.fg.bSorterRef flag is set for each expression in pEList
136475 ** for which the sorter-reference optimization should be enabled.
136476 ** Additionally, the pSort->aDefer[] array is populated with entries
136477 ** for all cursors required to evaluate all selected expressions. Finally.
136478 ** output variable (*ppExtra) is set to an expression list containing
136479 ** expressions for all extra PK values that should be stored in the
@@ -136281,11 +136529,11 @@
136529 pSort->aDefer[nDefer].iCsr = pExpr->iTable;
136530 pSort->aDefer[nDefer].nKey = nKey;
136531 nDefer++;
136532 }
136533 }
136534 pItem->fg.bSorterRef = 1;
136535 }
136536 }
136537 }
136538 pSort->nDefer = (u8)nDefer;
136539 *ppExtra = pExtra;
@@ -136412,11 +136660,11 @@
136660 ** from the sorter by the optimizations in this branch */
136661 pEList = p->pEList;
136662 for(i=0; i<pEList->nExpr; i++){
136663 if( pEList->a[i].u.x.iOrderByCol>0
136664 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
136665 || pEList->a[i].fg.bSorterRef
136666 #endif
136667 ){
136668 nResultCol--;
136669 regOrig = 0;
136670 }
@@ -136774,11 +137022,11 @@
137022 pInfo = sqlite3KeyInfoAlloc(db, nExpr-iStart, nExtra+1);
137023 if( pInfo ){
137024 assert( sqlite3KeyInfoIsWriteable(pInfo) );
137025 for(i=iStart, pItem=pList->a+iStart; i<nExpr; i++, pItem++){
137026 pInfo->aColl[i-iStart] = sqlite3ExprNNCollSeq(pParse, pItem->pExpr);
137027 pInfo->aSortFlags[i-iStart] = pItem->fg.sortFlags;
137028 }
137029 }
137030 return pInfo;
137031 }
137032
@@ -136913,11 +137161,11 @@
137161 iSortTab = iTab;
137162 bSeq = 1;
137163 }
137164 for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){
137165 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
137166 if( aOutEx[i].fg.bSorterRef ) continue;
137167 #endif
137168 if( aOutEx[i].u.x.iOrderByCol==0 ) iCol++;
137169 }
137170 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
137171 if( pSort->nDefer ){
@@ -136950,11 +137198,11 @@
137198 sqlite3ReleaseTempRange(pParse, regKey, nRefKey);
137199 }
137200 #endif
137201 for(i=nColumn-1; i>=0; i--){
137202 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
137203 if( aOutEx[i].fg.bSorterRef ){
137204 sqlite3ExprCode(pParse, aOutEx[i].pExpr, regRow+i);
137205 }else
137206 #endif
137207 {
137208 int iRead;
@@ -137316,11 +137564,11 @@
137564
137565 assert( p!=0 );
137566 assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */
137567 assert( p->op!=TK_COLUMN
137568 || (ExprUseYTab(p) && p->y.pTab!=0) ); /* Covering idx not yet coded */
137569 if( pEList->a[i].zEName && pEList->a[i].fg.eEName==ENAME_NAME ){
137570 /* An AS clause always takes first priority */
137571 char *zName = pEList->a[i].zEName;
137572 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
137573 }else if( srcName && p->op==TK_COLUMN ){
137574 char *zCol;
@@ -137402,26 +137650,28 @@
137650 *pnCol = nCol;
137651 *paCol = aCol;
137652
137653 for(i=0, pCol=aCol; i<nCol && !db->mallocFailed; i++, pCol++){
137654 struct ExprList_item *pX = &pEList->a[i];
137655 struct ExprList_item *pCollide;
137656 /* Get an appropriate name for the column
137657 */
137658 if( (zName = pX->zEName)!=0 && pX->fg.eEName==ENAME_NAME ){
137659 /* If the column contains an "AS <name>" phrase, use <name> as the name */
137660 }else{
137661 Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pX->pExpr);
137662 while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){
137663 pColExpr = pColExpr->pRight;
137664 assert( pColExpr!=0 );
137665 }
137666 if( pColExpr->op==TK_COLUMN
137667 && ALWAYS( ExprUseYTab(pColExpr) )
137668 && ALWAYS( pColExpr->y.pTab!=0 )
137669 ){
137670 /* For columns use the column name name */
137671 int iCol = pColExpr->iColumn;
137672 pTab = pColExpr->y.pTab;
137673 if( iCol<0 ) iCol = pTab->iPKey;
137674 zName = iCol>=0 ? pTab->aCol[iCol].zCnName : "rowid";
137675 }else if( pColExpr->op==TK_ID ){
137676 assert( !ExprHasProperty(pColExpr, EP_IntValue) );
137677 zName = pColExpr->u.zToken;
@@ -137438,11 +137688,14 @@
137688
137689 /* Make sure the column name is unique. If the name is not unique,
137690 ** append an integer to the name so that it becomes unique.
137691 */
137692 cnt = 0;
137693 while( zName && (pCollide = sqlite3HashFind(&ht, zName))!=0 ){
137694 if( pCollide->fg.bUsingTerm ){
137695 pCol->colFlags |= COLFLAG_NOEXPAND;
137696 }
137697 nName = sqlite3Strlen30(zName);
137698 if( nName>0 ){
137699 for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){}
137700 if( zName[j]==':' ) nName = j;
137701 }
@@ -137449,12 +137702,15 @@
137702 zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt);
137703 if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt);
137704 }
137705 pCol->zCnName = zName;
137706 pCol->hName = sqlite3StrIHash(zName);
137707 if( pX->fg.bNoExpand ){
137708 pCol->colFlags |= COLFLAG_NOEXPAND;
137709 }
137710 sqlite3ColumnPropertiesFromName(0, pCol);
137711 if( zName && sqlite3HashInsert(&ht, zName, pX)==pX ){
137712 sqlite3OomFault(db);
137713 }
137714 }
137715 sqlite3HashClear(&ht);
137716 if( db->mallocFailed ){
@@ -137707,11 +137963,11 @@
137963 pOrderBy->a[i].pExpr =
137964 sqlite3ExprAddCollateString(pParse, pTerm, pColl->zName);
137965 }
137966 assert( sqlite3KeyInfoIsWriteable(pRet) );
137967 pRet->aColl[i] = pColl;
137968 pRet->aSortFlags[i] = pOrderBy->a[i].fg.sortFlags;
137969 }
137970 }
137971
137972 return pRet;
137973 }
@@ -138977,11 +139233,11 @@
139233 static Expr *substExpr(
139234 SubstContext *pSubst, /* Description of the substitution */
139235 Expr *pExpr /* Expr in which substitution occurs */
139236 ){
139237 if( pExpr==0 ) return 0;
139238 if( ExprHasProperty(pExpr, EP_OuterON)
139239 && pExpr->w.iJoin==pSubst->iTable
139240 ){
139241 pExpr->w.iJoin = pSubst->iNewTable;
139242 }
139243 if( pExpr->op==TK_COLUMN
@@ -139018,16 +139274,21 @@
139274 return pExpr;
139275 }
139276 if( pSubst->isOuterJoin ){
139277 ExprSetProperty(pNew, EP_CanBeNull);
139278 }
139279 if( ExprHasProperty(pExpr,EP_OuterON|EP_InnerON) ){
139280 sqlite3SetJoinExpr(pNew, pExpr->w.iJoin,
139281 pExpr->flags & (EP_OuterON|EP_InnerON));
139282 }
139283 sqlite3ExprDelete(db, pExpr);
139284 pExpr = pNew;
139285 if( pExpr->op==TK_TRUEFALSE ){
139286 pExpr->u.iValue = sqlite3ExprTruthValue(pExpr);
139287 pExpr->op = TK_INTEGER;
139288 ExprSetProperty(pExpr, EP_IntValue);
139289 }
139290
139291 /* Ensure that the expression now has an implicit collation sequence,
139292 ** just as it did when it was a column of a view or sub-query. */
139293 if( pExpr->op!=TK_COLUMN && pExpr->op!=TK_COLLATE ){
139294 CollSeq *pColl = sqlite3ExprCollSeq(pSubst->pParse, pExpr);
@@ -139184,11 +139445,11 @@
139445 static int renumberCursorsCb(Walker *pWalker, Expr *pExpr){
139446 int op = pExpr->op;
139447 if( op==TK_COLUMN || op==TK_IF_NULL_ROW ){
139448 renumberCursorDoMapping(pWalker, &pExpr->iTable);
139449 }
139450 if( ExprHasProperty(pExpr, EP_OuterON) ){
139451 renumberCursorDoMapping(pWalker, &pExpr->w.iJoin);
139452 }
139453 return WRC_Continue;
139454 }
139455
@@ -139375,10 +139636,12 @@
139636 ** See also (3) for restrictions on LEFT JOIN.
139637 **
139638 ** (27) The subquery may not contain a FULL or RIGHT JOIN unless it
139639 ** is the first element of the parent query.
139640 **
139641 ** (28) The subquery is not a MATERIALIZED CTE.
139642 **
139643 **
139644 ** In this routine, the "p" parameter is a pointer to the outer query.
139645 ** The subquery is p->pSrc->a[iFrom]. isAgg is true if the outer query
139646 ** uses aggregates.
139647 **
@@ -139498,10 +139761,13 @@
139761
139762 assert( pSubSrc->nSrc>0 ); /* True by restriction (7) */
139763 if( iFrom>0 && (pSubSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
139764 return 0; /* Restriction (27) */
139765 }
139766 if( pSubitem->fg.isCte && pSubitem->u2.pCteUse->eM10d==M10d_Yes ){
139767 return 0; /* (28) */
139768 }
139769
139770 /* Restriction (17): If the sub-query is a compound SELECT, then it must
139771 ** use only the UNION ALL operator. And none of the simple select queries
139772 ** that make up the compound SELECT are allowed to be aggregate or distinct
139773 ** queries.
@@ -139542,10 +139808,11 @@
139808 /* Restriction (23) */
139809 if( (p->selFlags & SF_Recursive) ) return 0;
139810
139811 if( pSrc->nSrc>1 ){
139812 if( pParse->nSelect>500 ) return 0;
139813 if( OptimizationDisabled(db, SQLITE_FlttnUnionAll) ) return 0;
139814 aCsrMap = sqlite3DbMallocZero(db, ((i64)pParse->nTab+1)*sizeof(int));
139815 if( aCsrMap ) aCsrMap[0] = pParse->nTab;
139816 }
139817 }
139818
@@ -139756,11 +140023,11 @@
140023 pSub->pOrderBy = 0;
140024 }
140025 pWhere = pSub->pWhere;
140026 pSub->pWhere = 0;
140027 if( isOuterJoin>0 ){
140028 sqlite3SetJoinExpr(pWhere, iNewParent, EP_OuterON);
140029 }
140030 if( pWhere ){
140031 if( pParent->pWhere ){
140032 pParent->pWhere = sqlite3PExpr(pParse, TK_AND, pWhere, pParent->pWhere);
140033 }else{
@@ -139889,11 +140156,11 @@
140156 ** found, add it to the pConst structure.
140157 */
140158 static void findConstInWhere(WhereConst *pConst, Expr *pExpr){
140159 Expr *pRight, *pLeft;
140160 if( NEVER(pExpr==0) ) return;
140161 if( ExprHasProperty(pExpr, EP_OuterON) ) return;
140162 if( pExpr->op==TK_AND ){
140163 findConstInWhere(pConst, pExpr->pRight);
140164 findConstInWhere(pConst, pExpr->pLeft);
140165 return;
140166 }
@@ -139925,13 +140192,13 @@
140192 int bIgnoreAffBlob
140193 ){
140194 int i;
140195 if( pConst->pOomFault[0] ) return WRC_Prune;
140196 if( pExpr->op!=TK_COLUMN ) return WRC_Continue;
140197 if( ExprHasProperty(pExpr, EP_FixedCol|EP_OuterON) ){
140198 testcase( ExprHasProperty(pExpr, EP_FixedCol) );
140199 testcase( ExprHasProperty(pExpr, EP_OuterON) );
140200 return WRC_Continue;
140201 }
140202 for(i=0; i<pConst->nConst; i++){
140203 Expr *pColumn = pConst->apExpr[i*2];
140204 if( pColumn==pExpr ) continue;
@@ -140170,17 +140437,17 @@
140437 */
140438 static int pushDownWhereTerms(
140439 Parse *pParse, /* Parse context (for malloc() and error reporting) */
140440 Select *pSubq, /* The subquery whose WHERE clause is to be augmented */
140441 Expr *pWhere, /* The WHERE clause of the outer query */
140442 SrcItem *pSrc /* The subquery term of the outer FROM clause */
 
140443 ){
140444 Expr *pNew;
140445 int nChng = 0;
140446 if( pWhere==0 ) return 0;
140447 if( pSubq->selFlags & (SF_Recursive|SF_MultiPart) ) return 0;
140448 if( pSrc->fg.jointype & (JT_LTORJ|JT_RIGHT) ) return 0;
140449
140450 #ifndef SQLITE_OMIT_WINDOWFUNC
140451 if( pSubq->pPrior ){
140452 Select *pSel;
140453 for(pSel=pSubq; pSel; pSel=pSel->pPrior){
@@ -140206,35 +140473,38 @@
140473
140474 if( pSubq->pLimit!=0 ){
140475 return 0; /* restriction (3) */
140476 }
140477 while( pWhere->op==TK_AND ){
140478 nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, pSrc);
 
140479 pWhere = pWhere->pLeft;
140480 }
140481
140482 #if 0 /* Legacy code. Checks now done by sqlite3ExprIsTableConstraint() */
140483 if( isLeftJoin
140484 && (ExprHasProperty(pWhere,EP_OuterON)==0
140485 || pWhere->w.iJoin!=iCursor)
140486 ){
140487 return 0; /* restriction (4) */
140488 }
140489 if( ExprHasProperty(pWhere,EP_OuterON)
140490 && pWhere->w.iJoin!=iCursor
140491 ){
140492 return 0; /* restriction (5) */
140493 }
140494 #endif
140495
140496 if( sqlite3ExprIsTableConstraint(pWhere, pSrc) ){
140497 nChng++;
140498 pSubq->selFlags |= SF_PushDown;
140499 while( pSubq ){
140500 SubstContext x;
140501 pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
140502 unsetJoinExpr(pNew, -1);
140503 x.pParse = pParse;
140504 x.iTable = pSrc->iCursor;
140505 x.iNewTable = pSrc->iCursor;
140506 x.isOuterJoin = 0;
140507 x.pEList = pSubq->pEList;
140508 pNew = substExpr(&x, pNew);
140509 #ifndef SQLITE_OMIT_WINDOWFUNC
140510 if( pSubq->pWin && 0==pushDownWindowCheck(pParse, pSubq, pNew) ){
@@ -140304,11 +140574,11 @@
140574 }else{
140575 return eRet;
140576 }
140577 *ppMinMax = pOrderBy = sqlite3ExprListDup(db, pEList, 0);
140578 assert( pOrderBy!=0 || db->mallocFailed );
140579 if( pOrderBy ) pOrderBy->a[0].fg.sortFlags = sortFlags;
140580 return eRet;
140581 }
140582
140583 /*
140584 ** The select statement passed as the first argument is an aggregate query.
@@ -140773,11 +141043,11 @@
141043 if( pTab==0 ) return SQLITE_NOMEM;
141044 pTab->nTabRef = 1;
141045 if( pFrom->zAlias ){
141046 pTab->zName = sqlite3DbStrDup(pParse->db, pFrom->zAlias);
141047 }else{
141048 pTab->zName = sqlite3MPrintf(pParse->db, "%!S", pFrom);
141049 }
141050 while( pSel->pPrior ){ pSel = pSel->pPrior; }
141051 sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol);
141052 pTab->iPKey = -1;
141053 pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
@@ -141011,11 +141281,11 @@
141281 /* This particular expression does not need to be expanded.
141282 */
141283 pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr);
141284 if( pNew ){
141285 pNew->a[pNew->nExpr-1].zEName = a[k].zEName;
141286 pNew->a[pNew->nExpr-1].fg.eEName = a[k].fg.eEName;
141287 a[k].zEName = 0;
141288 }
141289 a[k].pExpr = 0;
141290 }else{
141291 /* This expression is a "*" or a "TABLE.*" and needs to be
@@ -141026,39 +141296,64 @@
141296 assert( pE->pLeft!=0 );
141297 assert( !ExprHasProperty(pE->pLeft, EP_IntValue) );
141298 zTName = pE->pLeft->u.zToken;
141299 }
141300 for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
141301 Table *pTab = pFrom->pTab; /* Table for this data source */
141302 ExprList *pNestedFrom; /* Result-set of a nested FROM clause */
141303 char *zTabName; /* AS name for this data source */
141304 const char *zSchemaName = 0; /* Schema name for this data source */
141305 int iDb; /* Schema index for this data src */
141306 IdList *pUsing; /* USING clause for pFrom[1] */
141307
141308 if( (zTabName = pFrom->zAlias)==0 ){
141309 zTabName = pTab->zName;
141310 }
141311 if( db->mallocFailed ) break;
141312 assert( pFrom->fg.isNestedFrom == IsNestedFrom(pFrom->pSelect) );
141313 if( pFrom->fg.isNestedFrom ){
141314 assert( pFrom->pSelect!=0 );
141315 pNestedFrom = pFrom->pSelect->pEList;
141316 assert( pNestedFrom!=0 );
141317 assert( pNestedFrom->nExpr==pTab->nCol );
141318 }else{
 
141319 if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
141320 continue;
141321 }
141322 pNestedFrom = 0;
141323 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
141324 zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*";
141325 }
141326 if( i+1<pTabList->nSrc
141327 && pFrom[1].fg.isUsing
141328 && (selFlags & SF_NestedFrom)!=0
141329 ){
141330 int ii;
141331 pUsing = pFrom[1].u3.pUsing;
141332 for(ii=0; ii<pUsing->nId; ii++){
141333 const char *zUName = pUsing->a[ii].zName;
141334 pRight = sqlite3Expr(db, TK_ID, zUName);
141335 pNew = sqlite3ExprListAppend(pParse, pNew, pRight);
141336 if( pNew ){
141337 struct ExprList_item *pX = &pNew->a[pNew->nExpr-1];
141338 assert( pX->zEName==0 );
141339 pX->zEName = sqlite3MPrintf(db,"..%s", zUName);
141340 pX->fg.eEName = ENAME_TAB;
141341 pX->fg.bUsingTerm = 1;
141342 }
141343 }
141344 }else{
141345 pUsing = 0;
141346 }
141347 for(j=0; j<pTab->nCol; j++){
141348 char *zName = pTab->aCol[j].zCnName;
141349 struct ExprList_item *pX; /* Newly added ExprList term */
141350
141351 assert( zName );
141352 if( zTName
141353 && pNestedFrom
141354 && sqlite3MatchEName(&pNestedFrom->a[j], 0, zTName, 0)==0
141355 ){
141356 continue;
141357 }
141358
141359 /* If a column is marked as 'hidden', omit it from the expanded
@@ -141067,14 +141362,20 @@
141362 */
141363 if( (p->selFlags & SF_IncludeHidden)==0
141364 && IsHiddenColumn(&pTab->aCol[j])
141365 ){
141366 continue;
141367 }
141368 if( (pTab->aCol[j].colFlags & COLFLAG_NOEXPAND)!=0
141369 && zTName==0
141370 && (selFlags & (SF_NestedFrom))==0
141371 ){
141372 continue;
141373 }
141374 tableSeen = 1;
141375
141376 if( i>0 && zTName==0 && (selFlags & SF_NestedFrom)==0 ){
141377 if( pFrom->fg.isUsing
141378 && sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0
141379 ){
141380 /* In a join with a USING clause, omit columns in the
141381 ** using clause from the table on the right. */
@@ -141082,10 +141383,11 @@
141383 }
141384 }
141385 pRight = sqlite3Expr(db, TK_ID, zName);
141386 if( (pTabList->nSrc>1
141387 && ( (pFrom->fg.jointype & JT_LTORJ)==0
141388 || (selFlags & SF_NestedFrom)!=0
141389 || !inAnyUsingClause(zName,pFrom,pTabList->nSrc-i-1)
141390 )
141391 )
141392 || IN_RENAME_OBJECT
141393 ){
@@ -141107,25 +141409,32 @@
141409 break; /* OOM */
141410 }
141411 pX = &pNew->a[pNew->nExpr-1];
141412 assert( pX->zEName==0 );
141413 if( (selFlags & SF_NestedFrom)!=0 && !IN_RENAME_OBJECT ){
141414 if( pNestedFrom ){
141415 pX->zEName = sqlite3DbStrDup(db, pNestedFrom->a[j].zEName);
141416 testcase( pX->zEName==0 );
141417 }else{
141418 pX->zEName = sqlite3MPrintf(db, "%s.%s.%s",
141419 zSchemaName, zTabName, zName);
141420 testcase( pX->zEName==0 );
141421 }
141422 pX->fg.eEName = ENAME_TAB;
141423 if( (pFrom->fg.isUsing
141424 && sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0)
141425 || (pUsing && sqlite3IdListIndex(pUsing, zName)>=0)
141426 || (pTab->aCol[j].colFlags & COLFLAG_NOEXPAND)!=0
141427 ){
141428 pX->fg.bNoExpand = 1;
141429 }
141430 }else if( longNames ){
141431 pX->zEName = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
141432 pX->fg.eEName = ENAME_NAME;
141433 }else{
141434 pX->zEName = sqlite3DbStrDup(db, zName);
141435 pX->fg.eEName = ENAME_NAME;
141436 }
141437 }
141438 }
141439 if( !tableSeen ){
141440 if( zTName ){
@@ -141684,10 +141993,33 @@
141993 }
141994 #endif
141995 return 1;
141996 }
141997 #endif /* SQLITE_COUNTOFVIEW_OPTIMIZATION */
141998
141999 /*
142000 ** If any term of pSrc, or any SF_NestedFrom sub-query, is not the same
142001 ** as pSrcItem but has the same alias as p0, then return true.
142002 ** Otherwise return false.
142003 */
142004 static int sameSrcAlias(SrcItem *p0, SrcList *pSrc){
142005 int i;
142006 for(i=0; i<pSrc->nSrc; i++){
142007 SrcItem *p1 = &pSrc->a[i];
142008 if( p1==p0 ) continue;
142009 if( p0->pTab==p1->pTab && 0==sqlite3_stricmp(p0->zAlias, p1->zAlias) ){
142010 return 1;
142011 }
142012 if( p1->pSelect
142013 && (p1->pSelect->selFlags & SF_NestedFrom)!=0
142014 && sameSrcAlias(p0, p1->pSelect->pSrc)
142015 ){
142016 return 1;
142017 }
142018 }
142019 return 0;
142020 }
142021
142022 /*
142023 ** Generate code for the SELECT statement given in the p argument.
142024 **
142025 ** The results are returned according to the SelectDest structure.
@@ -141789,19 +142121,16 @@
142121 ** systems handle this case differently, and not all the same way,
142122 ** which is just confusing. To avoid this, we follow PG's lead and
142123 ** disallow it altogether. */
142124 if( p->selFlags & SF_UFSrcCheck ){
142125 SrcItem *p0 = &p->pSrc->a[0];
142126 if( sameSrcAlias(p0, p->pSrc) ){
142127 sqlite3ErrorMsg(pParse,
142128 "target object/alias may not appear in FROM clause: %s",
142129 p0->zAlias ? p0->zAlias : p0->pTab->zName
142130 );
142131 goto select_end;
 
 
 
142132 }
142133
142134 /* Clear the SF_UFSrcCheck flag. The check has already been performed,
142135 ** and leaving this flag set can cause errors if a compound sub-query
142136 ** in p->pSrc is flattened into this query and this function called
@@ -142053,13 +142382,11 @@
142382 ** inside the subquery. This can help the subquery to run more efficiently.
142383 */
142384 if( OptimizationEnabled(db, SQLITE_PushDown)
142385 && (pItem->fg.isCte==0
142386 || (pItem->u2.pCteUse->eM10d!=M10d_Yes && pItem->u2.pCteUse->nUse<2))
142387 && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem)
 
 
142388 ){
142389 #if TREETRACE_ENABLED
142390 if( sqlite3TreeTrace & 0x100 ){
142391 SELECTTRACE(0x100,pParse,p,
142392 ("After WHERE-clause push-down into subquery %d:\n", pSub->selId));
@@ -142074,11 +142401,11 @@
142401 zSavedAuthContext = pParse->zAuthContext;
142402 pParse->zAuthContext = pItem->zName;
142403
142404 /* Generate code to implement the subquery
142405 **
142406 ** The subquery is implemented as a co-routine all if the following are
142407 ** true:
142408 **
142409 ** (1) the subquery is guaranteed to be the outer loop (so that
142410 ** it does not need to be computed more than once), and
142411 ** (2) the subquery is not a CTE that should be materialized
@@ -142132,15 +142459,15 @@
142459 /* Materialize the view. If the view is not correlated, generate a
142460 ** subroutine to do the materialization so that subsequent uses of
142461 ** the same view can reuse the materialization. */
142462 int topAddr;
142463 int onceAddr = 0;
 
142464
142465 pItem->regReturn = ++pParse->nMem;
142466 topAddr = sqlite3VdbeAddOp0(v, OP_Goto);
142467 pItem->addrFillSub = topAddr+1;
142468 pItem->fg.isMaterialized = 1;
142469 if( pItem->fg.isCorrelated==0 ){
142470 /* If the subquery is not correlated and if we are not inside of
142471 ** a trigger, then we only need to compute the value of the subquery
142472 ** once. */
142473 onceAddr = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
@@ -142151,13 +142478,13 @@
142478 sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
142479 ExplainQueryPlan((pParse, 1, "MATERIALIZE %!S", pItem));
142480 sqlite3Select(pParse, pSub, &dest);
142481 pItem->pTab->nRowLogEst = pSub->nSelectRow;
142482 if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr);
142483 sqlite3VdbeAddOp2(v, OP_Return, pItem->regReturn, topAddr+1);
142484 VdbeComment((v, "end %!S", pItem));
142485 sqlite3VdbeJumpHere(v, topAddr);
142486 sqlite3ClearTempRegCache(pParse);
142487 if( pItem->fg.isCte && pItem->fg.isCorrelated==0 ){
142488 CteUse *pCteUse = pItem->u2.pCteUse;
142489 pCteUse->addrM9e = pItem->addrFillSub;
142490 pCteUse->regRtn = pItem->regReturn;
@@ -142251,17 +142578,17 @@
142578 if( pDest->eDest==SRT_EphemTab ){
142579 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pDest->iSDParm, pEList->nExpr);
142580 if( p->selFlags & SF_NestedFrom ){
142581 /* Delete or NULL-out result columns that will never be used */
142582 int ii;
142583 for(ii=pEList->nExpr-1; ii>0 && pEList->a[ii].fg.bUsed==0; ii--){
142584 sqlite3ExprDelete(db, pEList->a[ii].pExpr);
142585 sqlite3DbFree(db, pEList->a[ii].zEName);
142586 pEList->nExpr--;
142587 }
142588 for(ii=0; ii<pEList->nExpr; ii++){
142589 if( pEList->a[ii].fg.bUsed==0 ) pEList->a[ii].pExpr->op = TK_NULL;
142590 }
142591 }
142592 }
142593
142594 /* Set the limiter.
@@ -142409,12 +142736,13 @@
142736 ** ASC or DESC order - only that each group is returned contiguously.
142737 ** So set the ASC/DESC flags in the GROUP BY to match those in the
142738 ** ORDER BY to maximize the chances of rows being delivered in an
142739 ** order that makes the ORDER BY redundant. */
142740 for(ii=0; ii<pGroupBy->nExpr; ii++){
142741 u8 sortFlags;
142742 sortFlags = sSort.pOrderBy->a[ii].fg.sortFlags & KEYINFO_ORDER_DESC;
142743 pGroupBy->a[ii].fg.sortFlags = sortFlags;
142744 }
142745 if( sqlite3ExprListCompare(pGroupBy, sSort.pOrderBy, -1)==0 ){
142746 orderByGrp = 1;
142747 }
142748 }
@@ -142875,11 +143203,11 @@
143203 }
143204 SELECTTRACE(1,pParse,p,("WhereBegin returns\n"));
143205 eDist = sqlite3WhereIsDistinct(pWInfo);
143206 updateAccumulator(pParse, regAcc, pAggInfo, eDist);
143207 if( eDist!=WHERE_DISTINCT_NOOP ){
143208 struct AggInfo_func *pF = pAggInfo->aFunc;
143209 if( pF ){
143210 fixDistinctOpenEph(pParse, eDist, pF->iDistinct, pF->iDistAddr);
143211 }
143212 }
143213
@@ -143674,11 +144002,11 @@
144002 ** sees an UPDATE statement inside the body of a CREATE TRIGGER.
144003 */
144004 SQLITE_PRIVATE TriggerStep *sqlite3TriggerUpdateStep(
144005 Parse *pParse, /* Parser */
144006 Token *pTableName, /* Name of the table to be updated */
144007 SrcList *pFrom, /* FROM clause for an UPDATE-FROM, or NULL */
144008 ExprList *pEList, /* The SET clause: list of column and new values */
144009 Expr *pWhere, /* The WHERE clause */
144010 u8 orconf, /* The conflict algorithm. (OE_Abort, OE_Ignore, etc) */
144011 const char *zStart, /* Start of SQL text */
144012 const char *zEnd /* End of SQL text */
@@ -144010,10 +144338,18 @@
144338 if( pSchema!=db->aDb[1].pSchema ){
144339 pSrc->a[0].pSchema = pSchema;
144340 }
144341 if( pStep->pFrom ){
144342 SrcList *pDup = sqlite3SrcListDup(db, pStep->pFrom, 0);
144343 if( pDup && pDup->nSrc>1 && !IN_RENAME_OBJECT ){
144344 Select *pSubquery;
144345 Token as;
144346 pSubquery = sqlite3SelectNew(pParse,0,pDup,0,0,0,0,SF_NestedFrom,0);
144347 as.n = 0;
144348 as.z = 0;
144349 pDup = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&as,pSubquery,0);
144350 }
144351 pSrc = sqlite3SrcListAppendList(pParse, pSrc, pDup);
144352 }
144353 }else{
144354 sqlite3DbFree(db, zName);
144355 }
@@ -144065,20 +144401,20 @@
144401 pNewExpr = sqlite3Expr(db, TK_ID, pTab->aCol[jj].zCnName);
144402 pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
144403 if( !db->mallocFailed ){
144404 struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
144405 pItem->zEName = sqlite3DbStrDup(db, pTab->aCol[jj].zCnName);
144406 pItem->fg.eEName = ENAME_NAME;
144407 }
144408 }
144409 }else{
144410 Expr *pNewExpr = sqlite3ExprDup(db, pOldExpr, 0);
144411 pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
144412 if( !db->mallocFailed && ALWAYS(pList->a[i].zEName!=0) ){
144413 struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
144414 pItem->zEName = sqlite3DbStrDup(db, pList->a[i].zEName);
144415 pItem->fg.eEName = pList->a[i].fg.eEName;
144416 }
144417 }
144418 }
144419 return pNew;
144420 }
@@ -146647,10 +146983,11 @@
146983 #endif
146984 }
146985
146986 assert( rc==SQLITE_OK );
146987 if( pOut==0 ){
146988 nRes = sqlite3BtreeGetRequestedReserve(pTemp);
146989 rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1);
146990 }
146991
146992 end_of_vacuum:
146993 /* Restore the original value of db->flags */
@@ -148098,11 +148435,11 @@
148435 ** This object is a header on a block of allocated memory that will be
148436 ** automatically freed when its WInfo oject is destructed.
148437 */
148438 struct WhereMemBlock {
148439 WhereMemBlock *pNext; /* Next block in the chain */
148440 u64 sz; /* Bytes of space */
148441 };
148442
148443 /*
148444 ** Extra information attached to a WhereLevel that is a RIGHT JOIN.
148445 */
@@ -148109,10 +148446,11 @@
148446 struct WhereRightJoin {
148447 int iMatch; /* Cursor used to determine prior matched rows */
148448 int regBloom; /* Bloom filter for iRJMatch */
148449 int regReturn; /* Return register for the interior subroutine */
148450 int addrSubrtn; /* Starting address for the interior subroutine */
148451 int endSubrtn; /* The last opcode in the interior subroutine */
148452 };
148453
148454 /*
148455 ** This object contains information needed to implement a single nested
148456 ** loop in WHERE clause.
@@ -148668,12 +149006,13 @@
149006 #define WO_ISNULL 0x0100
149007 #define WO_OR 0x0200 /* Two or more OR-connected terms */
149008 #define WO_AND 0x0400 /* Two or more AND-connected terms */
149009 #define WO_EQUIV 0x0800 /* Of the form A==B, both columns */
149010 #define WO_NOOP 0x1000 /* This term does not restrict search space */
149011 #define WO_ROWVAL 0x2000 /* A row-value term */
149012
149013 #define WO_ALL 0x3fff /* Mask of all possible WO_* values */
149014 #define WO_SINGLE 0x01ff /* Mask of all non-compound WO_* values */
149015
149016 /*
149017 ** These are definitions of bits in the WhereLoop.wsFlags field.
149018 ** The particular combination of bits in each WhereLoop help to
@@ -149039,11 +149378,11 @@
149378 */
149379 static void disableTerm(WhereLevel *pLevel, WhereTerm *pTerm){
149380 int nLoop = 0;
149381 assert( pTerm!=0 );
149382 while( (pTerm->wtFlags & TERM_CODED)==0
149383 && (pLevel->iLeftJoin==0 || ExprHasProperty(pTerm->pExpr, EP_OuterON))
149384 && (pLevel->notReady & pTerm->prereqAll)==0
149385 ){
149386 if( nLoop && (pTerm->wtFlags & TERM_LIKE)!=0 ){
149387 pTerm->wtFlags |= TERM_LIKECOND;
149388 }else{
@@ -149300,20 +149639,25 @@
149639
149640 iTab = 0;
149641 if( !ExprUseXSelect(pX) || pX->x.pSelect->pEList->nExpr==1 ){
149642 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
149643 }else{
149644 Expr *pExpr = pTerm->pExpr;
149645 if( pExpr->iTable==0 || !ExprHasProperty(pExpr, EP_Subrtn) ){
149646 sqlite3 *db = pParse->db;
149647 pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
149648 if( !db->mallocFailed ){
149649 aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq);
149650 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap,&iTab);
149651 pExpr->iTable = iTab;
149652 }
149653 sqlite3ExprDelete(db, pX);
149654 }else{
149655 aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq);
149656 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap, &iTab);
 
149657 }
149658 pX = pExpr;
 
149659 }
149660
149661 if( eType==IN_INDEX_INDEX_DESC ){
149662 testcase( bRev );
149663 bRev = !bRev;
@@ -149755,20 +150099,20 @@
150099 **
150100 ** are also excluded. See codeCursorHintIsOrFunction() for details.
150101 */
150102 if( pTabItem->fg.jointype & JT_LEFT ){
150103 Expr *pExpr = pTerm->pExpr;
150104 if( !ExprHasProperty(pExpr, EP_OuterON)
150105 || pExpr->w.iJoin!=pTabItem->iCursor
150106 ){
150107 sWalker.eCode = 0;
150108 sWalker.xExprCallback = codeCursorHintIsOrFunction;
150109 sqlite3WalkExpr(&sWalker, pTerm->pExpr);
150110 if( sWalker.eCode ) continue;
150111 }
150112 }else{
150113 if( ExprHasProperty(pTerm->pExpr, EP_OuterON) ) continue;
150114 }
150115
150116 /* All terms in pWLoop->aLTerm[] except pEndRange are used to initialize
150117 ** the cursor. These terms are not needed as hints for a pure range
150118 ** scan (that has no == terms) so omit them. */
@@ -149936,16 +150280,16 @@
150280 ** that contains the value of pExpr.
150281 */
150282 static int whereIndexExprTransNode(Walker *p, Expr *pExpr){
150283 IdxExprTrans *pX = p->u.pIdxTrans;
150284 if( sqlite3ExprCompare(0, pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){
150285 pExpr = sqlite3ExprSkipCollate(pExpr);
150286 preserveExpr(pX, pExpr);
150287 pExpr->affExpr = sqlite3ExprAffinity(pExpr);
150288 pExpr->op = TK_COLUMN;
150289 pExpr->iTable = pX->iIdxCur;
150290 pExpr->iColumn = pX->iIdxCol;
 
150291 testcase( ExprHasProperty(pExpr, EP_Unlikely) );
150292 ExprClearProperty(pExpr, EP_Skip|EP_Unlikely|EP_WinFunc|EP_Subrtn);
150293 pExpr->y.pTab = 0;
150294 return WRC_Prune;
150295 }else{
@@ -150095,10 +150439,12 @@
150439 if( pLevel->regFilter==0 ) continue;
150440 if( pLevel->pWLoop->nSkip ) continue;
150441 /* ,--- Because sqlite3ConstructBloomFilter() has will not have set
150442 ** vvvvv--' pLevel->regFilter if this were true. */
150443 if( NEVER(pLoop->prereq & notReady) ) continue;
150444 assert( pLevel->addrBrk==0 );
150445 pLevel->addrBrk = addrNxt;
150446 if( pLoop->wsFlags & WHERE_IPK ){
150447 WhereTerm *pTerm = pLoop->aLTerm[0];
150448 int regRowid;
150449 assert( pTerm!=0 );
150450 assert( pTerm->pExpr!=0 );
@@ -150121,10 +150467,11 @@
150467 sqlite3VdbeAddOp4Int(pParse->pVdbe, OP_Filter, pLevel->regFilter,
150468 addrNxt, r1, nEq);
150469 VdbeCoverage(pParse->pVdbe);
150470 }
150471 pLevel->regFilter = 0;
150472 pLevel->addrBrk = 0;
150473 }
150474 }
150475
150476 /*
150477 ** Generate code for the start of the iLevel-th loop in the WHERE clause
@@ -151092,11 +151439,11 @@
151439 WhereInfo *pSubWInfo; /* Info for single OR-term scan */
151440 Expr *pOrExpr = pOrTerm->pExpr; /* Current OR clause term */
151441 Expr *pDelete; /* Local copy of OR clause term */
151442 int jmp1 = 0; /* Address of jump operation */
151443 testcase( (pTabItem[0].fg.jointype & JT_LEFT)!=0
151444 && !ExprHasProperty(pOrExpr, EP_OuterON)
151445 ); /* See TH3 vtab25.400 and ticket 614b25314c766238 */
151446 pDelete = pOrExpr = sqlite3ExprDup(db, pOrExpr, 0);
151447 if( db->mallocFailed ){
151448 sqlite3ExprDelete(db, pDelete);
151449 continue;
@@ -151300,16 +151647,26 @@
151647 pWInfo->untestedTerms = 1;
151648 continue;
151649 }
151650 pE = pTerm->pExpr;
151651 assert( pE!=0 );
151652 if( pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT) ){
151653 if( !ExprHasProperty(pE,EP_OuterON|EP_InnerON) ){
151654 /* Defer processing WHERE clause constraints until after outer
151655 ** join processing. tag-20220513a */
151656 continue;
151657 }else if( (pTabItem->fg.jointype & JT_LEFT)==JT_LEFT
151658 && !ExprHasProperty(pE,EP_OuterON) ){
151659 continue;
151660 }else{
151661 Bitmask m = sqlite3WhereGetMask(&pWInfo->sMaskSet, pE->w.iJoin);
151662 if( m & pLevel->notReady ){
151663 /* An ON clause that is not ripe */
151664 continue;
151665 }
151666 }
151667 }
 
151668 if( iLoop==1 && !sqlite3ExprCoveredByIndex(pE, pLevel->iTabCur, pIdx) ){
151669 iNext = 2;
151670 continue;
151671 }
151672 if( iLoop<3 && (pTerm->wtFlags & TERM_VARSELECT) ){
@@ -151364,19 +151721,19 @@
151721 WhereTerm *pAlt;
151722 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
151723 if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) continue;
151724 if( (pTerm->eOperator & WO_EQUIV)==0 ) continue;
151725 if( pTerm->leftCursor!=iCur ) continue;
151726 if( pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT) ) continue;
151727 pE = pTerm->pExpr;
151728 #ifdef WHERETRACE_ENABLED /* 0x800 */
151729 if( sqlite3WhereTrace & 0x800 ){
151730 sqlite3DebugPrintf("Coding transitive constraint:\n");
151731 sqlite3WhereTermPrint(pTerm, pWC->nTerm-j);
151732 }
151733 #endif
151734 assert( !ExprHasProperty(pE, EP_OuterON) );
151735 assert( (pTerm->prereqRight & pLevel->notReady)!=0 );
151736 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
151737 pAlt = sqlite3WhereFindTerm(pWC, iCur, pTerm->u.x.leftColumn, notReady,
151738 WO_EQ|WO_IN|WO_IS, 0);
151739 if( pAlt==0 ) continue;
@@ -151443,22 +151800,12 @@
151800 */
151801 if( pLevel->iLeftJoin ){
151802 pLevel->addrFirst = sqlite3VdbeCurrentAddr(v);
151803 sqlite3VdbeAddOp2(v, OP_Integer, 1, pLevel->iLeftJoin);
151804 VdbeComment((v, "record LEFT JOIN hit"));
151805 if( pLevel->pRJ==0 ){
151806 goto code_outer_join_constraints; /* WHERE clause constraints */
 
 
 
 
 
 
 
 
 
 
151807 }
151808 }
151809
151810 if( pLevel->pRJ ){
151811 /* Create a subroutine used to process all interior loops and code
@@ -151470,10 +151817,30 @@
151817 WhereRightJoin *pRJ = pLevel->pRJ;
151818 sqlite3VdbeAddOp2(v, OP_BeginSubrtn, 0, pRJ->regReturn);
151819 pRJ->addrSubrtn = sqlite3VdbeCurrentAddr(v);
151820 assert( pParse->withinRJSubrtn < 255 );
151821 pParse->withinRJSubrtn++;
151822
151823 /* WHERE clause constraints must be deferred until after outer join
151824 ** row elimination has completed, since WHERE clause constraints apply
151825 ** to the results of the OUTER JOIN. The following loop generates the
151826 ** appropriate WHERE clause constraint checks. tag-20220513a.
151827 */
151828 code_outer_join_constraints:
151829 for(pTerm=pWC->a, j=0; j<pWC->nBase; j++, pTerm++){
151830 testcase( pTerm->wtFlags & TERM_VIRTUAL );
151831 testcase( pTerm->wtFlags & TERM_CODED );
151832 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
151833 if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
151834 assert( pWInfo->untestedTerms );
151835 continue;
151836 }
151837 if( pTabItem->fg.jointype & JT_LTORJ ) continue;
151838 assert( pTerm->pExpr );
151839 sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
151840 pTerm->wtFlags |= TERM_CODED;
151841 }
151842 }
151843
151844 #if WHERETRACE_ENABLED /* 0x20800 */
151845 if( sqlite3WhereTrace & 0x20000 ){
151846 sqlite3DebugPrintf("All WHERE-clause terms after coding level %d:\n",
@@ -151508,10 +151875,12 @@
151875 SrcList sFrom;
151876 Bitmask mAll = 0;
151877 int k;
151878
151879 ExplainQueryPlan((pParse, 1, "RIGHT-JOIN %s", pTabItem->pTab->zName));
151880 sqlite3VdbeNoJumpsOutsideSubrtn(v, pRJ->addrSubrtn, pRJ->endSubrtn,
151881 pRJ->regReturn);
151882 for(k=0; k<iLevel; k++){
151883 int iIdxCur;
151884 mAll |= pWInfo->a[k].pWLoop->maskSelf;
151885 sqlite3VdbeAddOp1(v, OP_NullRow, pWInfo->a[k].iTabCur);
151886 iIdxCur = pWInfo->a[k].iIdxCur;
@@ -151521,13 +151890,17 @@
151890 }
151891 if( (pTabItem->fg.jointype & JT_LTORJ)==0 ){
151892 mAll |= pLoop->maskSelf;
151893 for(k=0; k<pWC->nTerm; k++){
151894 WhereTerm *pTerm = &pWC->a[k];
151895 if( (pTerm->wtFlags & (TERM_VIRTUAL|TERM_SLICE))!=0
151896 && pTerm->eOperator!=WO_ROWVAL
151897 ){
151898 break;
151899 }
151900 if( pTerm->prereqAll & ~mAll ) continue;
151901 if( ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON) ) continue;
151902 pSubWhere = sqlite3ExprAnd(pParse, pSubWhere,
151903 sqlite3ExprDup(pParse->db, pTerm->pExpr, 0));
151904 }
151905 }
151906 sFrom.nSrc = 1;
@@ -152035,12 +152408,12 @@
152408 /*
152409 ** If the pBase expression originated in the ON or USING clause of
152410 ** a join, then transfer the appropriate markings over to derived.
152411 */
152412 static void transferJoinMarkings(Expr *pDerived, Expr *pBase){
152413 if( pDerived && ExprHasProperty(pBase, EP_OuterON|EP_InnerON) ){
152414 pDerived->flags |= pBase->flags & (EP_OuterON|EP_InnerON);
152415 pDerived->w.iJoin = pBase->w.iJoin;
152416 }
152417 }
152418
152419 /*
@@ -152491,11 +152864,11 @@
152864 static int termIsEquivalence(Parse *pParse, Expr *pExpr){
152865 char aff1, aff2;
152866 CollSeq *pColl;
152867 if( !OptimizationEnabled(pParse->db, SQLITE_Transitive) ) return 0;
152868 if( pExpr->op!=TK_EQ && pExpr->op!=TK_IS ) return 0;
152869 if( ExprHasProperty(pExpr, EP_OuterON) ) return 0;
152870 aff1 = sqlite3ExprAffinity(pExpr->pLeft);
152871 aff2 = sqlite3ExprAffinity(pExpr->pRight);
152872 if( aff1!=aff2
152873 && (!sqlite3IsNumericAffinity(aff1) || !sqlite3IsNumericAffinity(aff2))
152874 ){
@@ -152679,22 +153052,30 @@
153052
153053 #ifdef SQLITE_DEBUG
153054 if( prereqAll!=sqlite3WhereExprUsageNN(pMaskSet, pExpr) ){
153055 printf("\n*** Incorrect prereqAll computed for:\n");
153056 sqlite3TreeViewExpr(0,pExpr,0);
153057 assert( 0 );
153058 }
153059 #endif
153060
153061 if( ExprHasProperty(pExpr, EP_OuterON|EP_InnerON) ){
153062 Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->w.iJoin);
153063 if( ExprHasProperty(pExpr, EP_OuterON) ){
153064 prereqAll |= x;
153065 extraRight = x-1; /* ON clause terms may not be used with an index
153066 ** on left table of a LEFT JOIN. Ticket #3015 */
153067 if( (prereqAll>>1)>=x ){
153068 sqlite3ErrorMsg(pParse, "ON clause references tables to its right");
153069 return;
153070 }
153071 }else if( (prereqAll>>1)>=x ){
153072 /* The ON clause of an INNER JOIN references a table to its right.
153073 ** Most other SQL database engines raise an error. But all versions
153074 ** of SQLite going back to 3.0.0 have just put the ON clause constraint
153075 ** into the WHERE clause and carried on. */
153076 ExprClearProperty(pExpr, EP_InnerON);
153077 }
153078 }
153079 pTerm->prereqAll = prereqAll;
153080 pTerm->leftCursor = -1;
153081 pTerm->iParent = -1;
@@ -152758,11 +153139,11 @@
153139 pNew->prereqRight = prereqLeft | extraRight;
153140 pNew->prereqAll = prereqAll;
153141 pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
153142 }else
153143 if( op==TK_ISNULL
153144 && !ExprHasProperty(pExpr,EP_OuterON)
153145 && 0==sqlite3ExprCanBeNull(pLeft)
153146 ){
153147 assert( !ExprHasProperty(pExpr, EP_IntValue) );
153148 pExpr->op = TK_TRUEFALSE;
153149 pExpr->u.zToken = "false";
@@ -152829,11 +153210,11 @@
153210 ** The virtual term must be tagged with TERM_VNULL.
153211 */
153212 else if( pExpr->op==TK_NOTNULL ){
153213 if( pExpr->pLeft->op==TK_COLUMN
153214 && pExpr->pLeft->iColumn>=0
153215 && !ExprHasProperty(pExpr, EP_OuterON)
153216 ){
153217 Expr *pNewExpr;
153218 Expr *pLeft = pExpr->pLeft;
153219 int idxNew;
153220 WhereTerm *pNewTerm;
@@ -152977,11 +153358,11 @@
153358 idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC|TERM_SLICE);
153359 exprAnalyze(pSrc, pWC, idxNew);
153360 }
153361 pTerm = &pWC->a[idxTerm];
153362 pTerm->wtFlags |= TERM_CODED|TERM_VIRTUAL; /* Disable the original */
153363 pTerm->eOperator = WO_ROWVAL;
153364 }
153365
153366 /* If there is a vector IN term - e.g. "(a, b) IN (SELECT ...)" - create
153367 ** a virtual term for each vector component. The expression object
153368 ** used by each such virtual term is pExpr (the full vector IN(...)
@@ -153033,12 +153414,12 @@
153414 prereqColumn = sqlite3WhereExprUsage(pMaskSet, pLeft);
153415 if( (prereqExpr & prereqColumn)==0 ){
153416 Expr *pNewExpr;
153417 pNewExpr = sqlite3PExpr(pParse, TK_MATCH,
153418 0, sqlite3ExprDup(db, pRight, 0));
153419 if( ExprHasProperty(pExpr, EP_OuterON) && pNewExpr ){
153420 ExprSetProperty(pNewExpr, EP_OuterON);
153421 pNewExpr->w.iJoin = pExpr->w.iJoin;
153422 }
153423 idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
153424 testcase( idxNew==0 );
153425 pNewTerm = &pWC->a[idxNew];
@@ -153178,11 +153559,11 @@
153559 for(ii=0; ii<pWC->nTerm; ii++){
153560 if( pWC->a[ii].wtFlags & TERM_CODED ){
153561 /* This term is a vector operation that has been decomposed into
153562 ** other, subsequent terms. It can be ignored. See tag-20220128a */
153563 assert( pWC->a[ii].wtFlags & TERM_VIRTUAL );
153564 assert( pWC->a[ii].eOperator==WO_ROWVAL );
153565 continue;
153566 }
153567 if( pWC->a[ii].leftCursor!=iCsr ) return;
153568 }
153569
@@ -153190,11 +153571,11 @@
153571 if( pOrderBy ){
153572 for(ii=0; ii<pOrderBy->nExpr; ii++){
153573 Expr *pExpr = pOrderBy->a[ii].pExpr;
153574 if( pExpr->op!=TK_COLUMN ) return;
153575 if( pExpr->iTable!=iCsr ) return;
153576 if( pOrderBy->a[ii].fg.sortFlags & KEYINFO_ORDER_BIGNULL ) return;
153577 }
153578 }
153579
153580 /* All conditions are met. Add the terms to the where-clause object. */
153581 assert( p->pLimit->op==TK_LIMIT );
@@ -153401,13 +153782,13 @@
153782 pItem->colUsed |= sqlite3ExprColUsed(pColRef);
153783 pRhs = sqlite3PExpr(pParse, TK_UPLUS,
153784 sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
153785 pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef, pRhs);
153786 if( pItem->fg.jointype & (JT_LEFT|JT_LTORJ) ){
153787 joinType = EP_OuterON;
153788 }else{
153789 joinType = EP_InnerON;
153790 }
153791 sqlite3SetJoinExpr(pTerm, pItem->iCursor, joinType);
153792 whereClauseInsert(pWC, pTerm, TERM_DYNAMIC);
153793 }
153794 }
@@ -153516,11 +153897,11 @@
153897 ** continuation of the inner-most loop. */
153898 return pWInfo->iContinue;
153899 }
153900 pInner = &pWInfo->a[pWInfo->nLevel-1];
153901 assert( pInner->addrNxt!=0 );
153902 return pInner->pRJ ? pWInfo->iContinue : pInner->addrNxt;
153903 }
153904
153905 /*
153906 ** While generating code for the min/max optimization, after handling
153907 ** the aggregate-step call to min() or max(), check to see if any
@@ -153744,11 +154125,11 @@
154125 if( pTerm->leftCursor==iCur
154126 && pTerm->u.x.leftColumn==iColumn
154127 && (iColumn!=XN_EXPR
154128 || sqlite3ExprCompareSkip(pTerm->pExpr->pLeft,
154129 pScan->pIdxExpr,iCur)==0)
154130 && (pScan->iEquiv<=1 || !ExprHasProperty(pTerm->pExpr, EP_OuterON))
154131 ){
154132 if( (pTerm->eOperator & WO_EQUIV)!=0
154133 && pScan->nEquiv<ArraySize(pScan->aiCur)
154134 && (pX = whereRightSubexprIsColumn(pTerm->pExpr))!=0
154135 ){
@@ -154171,11 +154552,11 @@
154552 ){
154553 char aff;
154554 if( pTerm->leftCursor!=pSrc->iCursor ) return 0;
154555 if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) return 0;
154556 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
154557 && !ExprHasProperty(pTerm->pExpr, EP_OuterON)
154558 && (pTerm->eOperator & WO_IS)
154559 ){
154560 /* Cannot use an IS term from the WHERE clause as an index driver for
154561 ** the RHS of a LEFT JOIN or for the LHS of a RIGHT JOIN. Such a term
154562 ** can only be used if it is from the ON clause. */
@@ -154246,13 +154627,11 @@
154627 Expr *pExpr = pTerm->pExpr;
154628 /* Make the automatic index a partial index if there are terms in the
154629 ** WHERE clause (or the ON clause of a LEFT join) that constrain which
154630 ** rows of the target table (pSrc) that can be used. */
154631 if( (pTerm->wtFlags & TERM_VIRTUAL)==0
154632 && sqlite3ExprIsTableConstraint(pExpr, pSrc)
 
 
154633 ){
154634 pPartial = sqlite3ExprAnd(pParse, pPartial,
154635 sqlite3ExprDup(pParse->db, pExpr, 0));
154636 }
154637 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
@@ -154487,11 +154866,11 @@
154866 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, iCur); VdbeCoverage(v);
154867 pWCEnd = &pWInfo->sWC.a[pWInfo->sWC.nTerm];
154868 for(pTerm=pWInfo->sWC.a; pTerm<pWCEnd; pTerm++){
154869 Expr *pExpr = pTerm->pExpr;
154870 if( (pTerm->wtFlags & TERM_VIRTUAL)==0
154871 && sqlite3ExprIsTableConstraint(pExpr, pItem)
154872 ){
154873 sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
154874 }
154875 }
154876 if( pLoop->wsFlags & WHERE_IPK ){
@@ -154597,11 +154976,11 @@
154976 /* tag-20191211-002: WHERE-clause constraints are not useful to the
154977 ** right-hand table of a LEFT JOIN nor to the left-hand table of a
154978 ** RIGHT JOIN. See tag-20191211-001 for the
154979 ** equivalent restriction for ordinary tables. */
154980 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
154981 && !ExprHasProperty(pTerm->pExpr, EP_OuterON)
154982 ){
154983 continue;
154984 }
154985 nTerm++;
154986 pTerm->wtFlags |= TERM_OK;
@@ -154622,11 +155001,11 @@
155001 if( sqlite3ExprIsConstant(pExpr) ){
155002 continue;
155003 }
155004
155005 /* Virtual tables are unable to deal with NULLS FIRST */
155006 if( pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_BIGNULL ) break;
155007
155008 /* First case - a direct column references without a COLLATE operator */
155009 if( pExpr->op==TK_COLUMN && pExpr->iTable==pSrc->iCursor ){
155010 assert( pExpr->iColumn>=XN_ROWID && pExpr->iColumn<pTab->nCol );
155011 continue;
@@ -154734,11 +155113,11 @@
155113 if( sqlite3ExprIsConstant(pExpr) ) continue;
155114 assert( pExpr->op==TK_COLUMN
155115 || (pExpr->op==TK_COLLATE && pExpr->pLeft->op==TK_COLUMN
155116 && pExpr->iColumn==pExpr->pLeft->iColumn) );
155117 pIdxOrderBy[j].iColumn = pExpr->iColumn;
155118 pIdxOrderBy[j].desc = pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_DESC;
155119 j++;
155120 }
155121 pIdxInfo->nOrderBy = j;
155122
155123 *pmNoOmit = mNoOmit;
@@ -155475,11 +155854,11 @@
155854 char zType[8];
155855 char zLeft[50];
155856 memcpy(zType, "....", 5);
155857 if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V';
155858 if( pTerm->eOperator & WO_EQUIV ) zType[1] = 'E';
155859 if( ExprHasProperty(pTerm->pExpr, EP_OuterON) ) zType[2] = 'L';
155860 if( pTerm->wtFlags & TERM_CODED ) zType[3] = 'C';
155861 if( pTerm->eOperator & WO_SINGLE ){
155862 assert( (pTerm->eOperator & (WO_OR|WO_AND))==0 );
155863 sqlite3_snprintf(sizeof(zLeft),zLeft,"left={%d:%d}",
155864 pTerm->leftCursor, pTerm->u.x.leftColumn);
@@ -156252,11 +156631,11 @@
156631 /* tag-20191211-001: Do not allow constraints from the WHERE clause to
156632 ** be used by the right table of a LEFT JOIN nor by the left table of a
156633 ** RIGHT JOIN. Only constraints in the
156634 ** ON clause are allowed. See tag-20191211-002 for the vtab equivalent. */
156635 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
156636 && !ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON)
156637 ){
156638 continue;
156639 }
156640
156641 if( IsUniqueIndex(pProbe) && saved_nEq==pProbe->nKeyCol-1 ){
@@ -156621,12 +157000,12 @@
157000 }
157001 if( pParse->db->flags & SQLITE_EnableQPSG ) pParse = 0;
157002 for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
157003 Expr *pExpr;
157004 pExpr = pTerm->pExpr;
157005 if( (!ExprHasProperty(pExpr, EP_OuterON) || pExpr->w.iJoin==iTab)
157006 && (isLeft==0 || ExprHasProperty(pExpr, EP_OuterON))
157007 && sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, iTab)
157008 && (pTerm->wtFlags & TERM_VNULL)==0
157009 ){
157010 return 1;
157011 }
@@ -156898,11 +157277,18 @@
157277
157278 pNew->rRun = sqlite3LogEstAdd(pNew->rRun, nLookup);
157279 }
157280 ApplyCostMultiplier(pNew->rRun, pTab->costMult);
157281 whereLoopOutputAdjust(pWC, pNew, rSize);
157282 if( (pSrc->fg.jointype & JT_RIGHT)!=0 && pProbe->aColExpr ){
157283 /* Do not do an SCAN of a index-on-expression in a RIGHT JOIN
157284 ** because the cursor used to access the index might not be
157285 ** positioned to the correct row during the right-join no-match
157286 ** loop. */
157287 }else{
157288 rc = whereLoopInsert(pBuilder, pNew);
157289 }
157290 pNew->nOut = rSize;
157291 if( rc ) break;
157292 }
157293 }
157294
@@ -157073,10 +157459,11 @@
157459 pIdxInfo->orderByConsumed = 0;
157460 pIdxInfo->idxFlags &= ~SQLITE_INDEX_SCAN_UNIQUE;
157461 *pbIn = 1; assert( (mExclude & WO_IN)==0 );
157462 }
157463
157464 assert( pbRetryLimit || !isLimitTerm(pTerm) );
157465 if( isLimitTerm(pTerm) && *pbIn ){
157466 /* If there is an IN(...) term handled as an == (separate call to
157467 ** xFilter for each value on the RHS of the IN) and a LIMIT or
157468 ** OFFSET term handled as well, the plan is unusable. Set output
157469 ** variable *pbRetryLimit to true to tell the caller to retry with
@@ -157546,11 +157933,13 @@
157933 SrcList *pTabList = pWInfo->pTabList;
157934 SrcItem *pItem;
157935 SrcItem *pEnd = &pTabList->a[pWInfo->nLevel];
157936 sqlite3 *db = pWInfo->pParse->db;
157937 int rc = SQLITE_OK;
157938 int bFirstPastRJ = 0;
157939 WhereLoop *pNew;
157940
157941
157942 /* Loop over the tables in the join, from left to right */
157943 pNew = pBuilder->pNew;
157944 whereLoopInit(pNew);
157945 pBuilder->iPlanLimit = SQLITE_QUERY_PLANNER_LIMIT;
@@ -157557,16 +157946,17 @@
157946 for(iTab=0, pItem=pTabList->a; pItem<pEnd; iTab++, pItem++){
157947 Bitmask mUnusable = 0;
157948 pNew->iTab = iTab;
157949 pBuilder->iPlanLimit += SQLITE_QUERY_PLANNER_LIMIT_INCR;
157950 pNew->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, pItem->iCursor);
157951 if( bFirstPastRJ || (pItem->fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
157952 /* Add prerequisites to prevent reordering of FROM clause terms
157953 ** across CROSS joins and outer joins. The bFirstPastRJ boolean
157954 ** prevents the right operand of a RIGHT JOIN from being swapped with
157955 ** other elements even further to the right. */
157956 mPrereq |= mPrior;
157957 bFirstPastRJ = (pItem->fg.jointype & JT_RIGHT)!=0;
157958 }
157959 #ifndef SQLITE_OMIT_VIRTUALTABLE
157960 if( IsVirtual(pItem->pTab) ){
157961 SrcItem *p;
157962 for(p=&pItem[1]; p<pEnd; p++){
@@ -157873,20 +158263,22 @@
158263 }
158264 if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
158265 /* Make sure the sort order is compatible in an ORDER BY clause.
158266 ** Sort order is irrelevant for a GROUP BY clause. */
158267 if( revSet ){
158268 if( (rev ^ revIdx)
158269 != (pOrderBy->a[i].fg.sortFlags&KEYINFO_ORDER_DESC)
158270 ){
158271 isMatch = 0;
158272 }
158273 }else{
158274 rev = revIdx ^ (pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_DESC);
158275 if( rev ) *pRevMask |= MASKBIT(iLoop);
158276 revSet = 1;
158277 }
158278 }
158279 if( isMatch && (pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_BIGNULL) ){
158280 if( j==pLoop->u.btree.nEq ){
158281 pLoop->wsFlags |= WHERE_BIGNULL_SORT;
158282 }else{
158283 isMatch = 0;
158284 }
@@ -158630,11 +159022,11 @@
159022 }
159023 if( (tabUsed & pLoop->maskSelf)!=0 ) continue;
159024 pEnd = pWInfo->sWC.a + pWInfo->sWC.nTerm;
159025 for(pTerm=pWInfo->sWC.a; pTerm<pEnd; pTerm++){
159026 if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){
159027 if( !ExprHasProperty(pTerm->pExpr, EP_OuterON)
159028 || pTerm->pExpr->w.iJoin!=pItem->iCursor
159029 ){
159030 break;
159031 }
159032 }
@@ -159256,10 +159648,11 @@
159648 op = OP_ReopenIdx;
159649 }else{
159650 iIndexCur = pParse->nTab++;
159651 }
159652 pLevel->iIdxCur = iIndexCur;
159653 assert( pIx!=0 );
159654 assert( pIx->pSchema==pTab->pSchema );
159655 assert( iIndexCur>=0 );
159656 if( op ){
159657 sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
159658 sqlite3VdbeSetP4KeyInfo(pParse, pIx);
@@ -159331,13 +159724,24 @@
159724 ** program.
159725 */
159726 for(ii=0; ii<nTabList; ii++){
159727 int addrExplain;
159728 int wsFlags;
159729 SrcItem *pSrc;
159730 if( pParse->nErr ) goto whereBeginError;
159731 pLevel = &pWInfo->a[ii];
159732 wsFlags = pLevel->pWLoop->wsFlags;
159733 pSrc = &pTabList->a[pLevel->iFrom];
159734 if( pSrc->fg.isMaterialized ){
159735 if( pSrc->fg.isCorrelated ){
159736 sqlite3VdbeAddOp2(v, OP_Gosub, pSrc->regReturn, pSrc->addrFillSub);
159737 }else{
159738 int iOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
159739 sqlite3VdbeAddOp2(v, OP_Gosub, pSrc->regReturn, pSrc->addrFillSub);
159740 sqlite3VdbeJumpHere(v, iOnce);
159741 }
159742 }
159743 if( (wsFlags & (WHERE_AUTO_INDEX|WHERE_BLOOMFILTER))!=0 ){
159744 if( (wsFlags & WHERE_AUTO_INDEX)!=0 ){
159745 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
159746 constructAutomaticIndex(pParse, &pWInfo->sWC,
159747 &pTabList->a[pLevel->iFrom], notReady, pLevel);
@@ -159425,10 +159829,11 @@
159829 WhereLevel *pLevel;
159830 WhereLoop *pLoop;
159831 SrcList *pTabList = pWInfo->pTabList;
159832 sqlite3 *db = pParse->db;
159833 int iEnd = sqlite3VdbeCurrentAddr(v);
159834 int nRJ = 0;
159835
159836 /* Generate loop termination code.
159837 */
159838 VdbeModuleComment((v, "End WHERE-core"));
159839 for(i=pWInfo->nLevel-1; i>=0; i--){
@@ -159438,14 +159843,14 @@
159843 /* Terminate the subroutine that forms the interior of the loop of
159844 ** the RIGHT JOIN table */
159845 WhereRightJoin *pRJ = pLevel->pRJ;
159846 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
159847 pLevel->addrCont = 0;
159848 pRJ->endSubrtn = sqlite3VdbeCurrentAddr(v);
159849 sqlite3VdbeAddOp3(v, OP_Return, pRJ->regReturn, pRJ->addrSubrtn, 1);
159850 VdbeCoverage(v);
159851 nRJ++;
 
159852 }
159853 pLoop = pLevel->pWLoop;
159854 if( pLevel->op!=OP_Noop ){
159855 #ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
159856 int addrSeek = 0;
@@ -159583,10 +159988,11 @@
159988 VdbeModuleComment((v, "End WHERE-loop%d: %s", i,
159989 pWInfo->pTabList->a[pLevel->iFrom].pTab->zName));
159990 }
159991
159992 assert( pWInfo->nLevel<=pTabList->nSrc );
159993 if( pWInfo->pExprMods ) whereUndoExprMods(pWInfo);
159994 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
159995 int k, last;
159996 VdbeOp *pOp, *pLastOp;
159997 Index *pIdx = 0;
159998 SrcItem *pTabItem = &pTabList->a[pLevel->iFrom];
@@ -159719,13 +160125,13 @@
160125 */
160126 sqlite3VdbeResolveLabel(v, pWInfo->iBreak);
160127
160128 /* Final cleanup
160129 */
 
160130 pParse->nQueryLoop = pWInfo->savedNQueryLoop;
160131 whereInfoFree(db, pWInfo);
160132 pParse->withinRJSubrtn -= nRJ;
160133 return;
160134 }
160135
160136 /************** End of where.c ***********************************************/
160137 /************** Begin file window.c ******************************************/
@@ -160645,11 +161051,11 @@
161051 pSub->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse);
161052 pSub->u.zToken = 0;
161053 }
161054 }
161055 pList = sqlite3ExprListAppend(pParse, pList, pDup);
161056 if( pList ) pList->a[nInit+i].fg.sortFlags = pAppend->a[i].fg.sortFlags;
161057 }
161058 }
161059 return pList;
161060 }
161061
@@ -161846,11 +162252,11 @@
162252 windowReadPeerValues(p, csr1, reg1);
162253 windowReadPeerValues(p, csr2, reg2);
162254
162255 assert( op==OP_Ge || op==OP_Gt || op==OP_Le );
162256 assert( pOrderBy && pOrderBy->nExpr==1 );
162257 if( pOrderBy->a[0].fg.sortFlags & KEYINFO_ORDER_DESC ){
162258 switch( op ){
162259 case OP_Ge: op = OP_Le; break;
162260 case OP_Gt: op = OP_Lt; break;
162261 default: assert( op==OP_Le ); op = OP_Ge; break;
162262 }
@@ -161879,11 +162285,11 @@
162285 ** }
162286 **
162287 ** Additionally, if either reg1 or reg2 are NULL but the jump to lbl is
162288 ** not taken, control jumps over the comparison operator coded below this
162289 ** block. */
162290 if( pOrderBy->a[0].fg.sortFlags & KEYINFO_ORDER_BIGNULL ){
162291 /* This block runs if reg1 contains a NULL. */
162292 int addr = sqlite3VdbeAddOp1(v, OP_NotNull, reg1); VdbeCoverage(v);
162293 switch( op ){
162294 case OP_Ge:
162295 sqlite3VdbeAddOp2(v, OP_Goto, 0, lbl);
@@ -163347,22 +163753,22 @@
163753 #define sqlite3ParserCTX_PDECL ,Parse *pParse
163754 #define sqlite3ParserCTX_PARAM ,pParse
163755 #define sqlite3ParserCTX_FETCH Parse *pParse=yypParser->pParse;
163756 #define sqlite3ParserCTX_STORE yypParser->pParse=pParse;
163757 #define YYFALLBACK 1
163758 #define YYNSTATE 576
163759 #define YYNRULE 405
163760 #define YYNRULE_WITH_ACTION 342
163761 #define YYNTOKEN 185
163762 #define YY_MAX_SHIFT 575
163763 #define YY_MIN_SHIFTREDUCE 835
163764 #define YY_MAX_SHIFTREDUCE 1239
163765 #define YY_ERROR_ACTION 1240
163766 #define YY_ACCEPT_ACTION 1241
163767 #define YY_NO_ACTION 1242
163768 #define YY_MIN_REDUCE 1243
163769 #define YY_MAX_REDUCE 1647
163770 /************* End control #defines *******************************************/
163771 #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))
163772
163773 /* Define the yytestcase() macro to be a no-op if is not already defined
163774 ** otherwise.
@@ -163425,219 +163831,222 @@
163831 ** yy_reduce_ofst[] For each state, the offset into yy_action for
163832 ** shifting non-terminals after a reduce.
163833 ** yy_default[] Default action for each state.
163834 **
163835 *********** Begin parsing tables **********************************************/
163836 #define YY_ACTTAB_COUNT (2098)
163837 static const YYACTIONTYPE yy_action[] = {
163838 /* 0 */ 568, 208, 568, 118, 115, 229, 568, 118, 115, 229,
163839 /* 10 */ 568, 1314, 377, 1293, 408, 562, 562, 562, 568, 409,
163840 /* 20 */ 378, 1314, 1276, 41, 41, 41, 41, 208, 1526, 71,
163841 /* 30 */ 71, 971, 419, 41, 41, 491, 303, 279, 303, 972,
163842 /* 40 */ 397, 71, 71, 125, 126, 80, 1217, 1217, 1050, 1053,
163843 /* 50 */ 1040, 1040, 123, 123, 124, 124, 124, 124, 476, 409,
163844 /* 60 */ 1241, 1, 1, 575, 2, 1245, 550, 118, 115, 229,
163845 /* 70 */ 317, 480, 146, 480, 524, 118, 115, 229, 529, 1327,
163846 /* 80 */ 417, 523, 142, 125, 126, 80, 1217, 1217, 1050, 1053,
163847 /* 90 */ 1040, 1040, 123, 123, 124, 124, 124, 124, 118, 115,
163848 /* 100 */ 229, 327, 122, 122, 122, 122, 121, 121, 120, 120,
163849 /* 110 */ 120, 119, 116, 444, 284, 284, 284, 284, 442, 442,
163850 /* 120 */ 442, 1567, 376, 1569, 1192, 375, 1163, 565, 1163, 565,
163851 /* 130 */ 409, 1567, 537, 259, 226, 444, 101, 145, 449, 316,
163852 /* 140 */ 559, 240, 122, 122, 122, 122, 121, 121, 120, 120,
163853 /* 150 */ 120, 119, 116, 444, 125, 126, 80, 1217, 1217, 1050,
163854 /* 160 */ 1053, 1040, 1040, 123, 123, 124, 124, 124, 124, 142,
163855 /* 170 */ 294, 1192, 339, 448, 120, 120, 120, 119, 116, 444,
163856 /* 180 */ 127, 1192, 1193, 1194, 148, 441, 440, 568, 119, 116,
163857 /* 190 */ 444, 124, 124, 124, 124, 117, 122, 122, 122, 122,
163858 /* 200 */ 121, 121, 120, 120, 120, 119, 116, 444, 454, 113,
163859 /* 210 */ 13, 13, 546, 122, 122, 122, 122, 121, 121, 120,
163860 /* 220 */ 120, 120, 119, 116, 444, 422, 316, 559, 1192, 1193,
163861 /* 230 */ 1194, 149, 1224, 409, 1224, 124, 124, 124, 124, 122,
163862 /* 240 */ 122, 122, 122, 121, 121, 120, 120, 120, 119, 116,
163863 /* 250 */ 444, 465, 342, 1037, 1037, 1051, 1054, 125, 126, 80,
163864 /* 260 */ 1217, 1217, 1050, 1053, 1040, 1040, 123, 123, 124, 124,
163865 /* 270 */ 124, 124, 1279, 522, 222, 1192, 568, 409, 224, 514,
163866 /* 280 */ 175, 82, 83, 122, 122, 122, 122, 121, 121, 120,
163867 /* 290 */ 120, 120, 119, 116, 444, 1007, 16, 16, 1192, 133,
163868 /* 300 */ 133, 125, 126, 80, 1217, 1217, 1050, 1053, 1040, 1040,
163869 /* 310 */ 123, 123, 124, 124, 124, 124, 122, 122, 122, 122,
163870 /* 320 */ 121, 121, 120, 120, 120, 119, 116, 444, 1041, 546,
163871 /* 330 */ 1192, 373, 1192, 1193, 1194, 252, 1434, 399, 504, 501,
163872 /* 340 */ 500, 111, 560, 566, 4, 926, 926, 433, 499, 340,
163873 /* 350 */ 460, 328, 360, 394, 1237, 1192, 1193, 1194, 563, 568,
163874 /* 360 */ 122, 122, 122, 122, 121, 121, 120, 120, 120, 119,
163875 /* 370 */ 116, 444, 284, 284, 369, 1580, 1607, 441, 440, 154,
163876 /* 380 */ 409, 445, 71, 71, 1286, 565, 1221, 1192, 1193, 1194,
163877 /* 390 */ 85, 1223, 271, 557, 543, 515, 1561, 568, 98, 1222,
163878 /* 400 */ 6, 1278, 472, 142, 125, 126, 80, 1217, 1217, 1050,
163879 /* 410 */ 1053, 1040, 1040, 123, 123, 124, 124, 124, 124, 550,
163880 /* 420 */ 13, 13, 1027, 507, 1224, 1192, 1224, 549, 109, 109,
163881 /* 430 */ 222, 568, 1238, 175, 568, 427, 110, 197, 445, 570,
163882 /* 440 */ 569, 430, 1552, 1017, 325, 551, 1192, 270, 287, 368,
163883 /* 450 */ 510, 363, 509, 257, 71, 71, 543, 71, 71, 359,
163884 /* 460 */ 316, 559, 1613, 122, 122, 122, 122, 121, 121, 120,
163885 /* 470 */ 120, 120, 119, 116, 444, 1017, 1017, 1019, 1020, 27,
163886 /* 480 */ 284, 284, 1192, 1193, 1194, 1158, 568, 1612, 409, 901,
163887 /* 490 */ 190, 550, 356, 565, 550, 937, 533, 517, 1158, 516,
163888 /* 500 */ 413, 1158, 552, 1192, 1193, 1194, 568, 544, 1554, 51,
163889 /* 510 */ 51, 214, 125, 126, 80, 1217, 1217, 1050, 1053, 1040,
163890 /* 520 */ 1040, 123, 123, 124, 124, 124, 124, 1192, 474, 135,
163891 /* 530 */ 135, 409, 284, 284, 1490, 505, 121, 121, 120, 120,
163892 /* 540 */ 120, 119, 116, 444, 1007, 565, 518, 217, 541, 1561,
163893 /* 550 */ 316, 559, 142, 6, 532, 125, 126, 80, 1217, 1217,
163894 /* 560 */ 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124, 124,
163895 /* 570 */ 1555, 122, 122, 122, 122, 121, 121, 120, 120, 120,
163896 /* 580 */ 119, 116, 444, 485, 1192, 1193, 1194, 482, 281, 1267,
163897 /* 590 */ 957, 252, 1192, 373, 504, 501, 500, 1192, 340, 571,
163898 /* 600 */ 1192, 571, 409, 292, 499, 957, 876, 191, 480, 316,
163899 /* 610 */ 559, 384, 290, 380, 122, 122, 122, 122, 121, 121,
163900 /* 620 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1217,
163901 /* 630 */ 1217, 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124,
163902 /* 640 */ 124, 409, 394, 1136, 1192, 869, 100, 284, 284, 1192,
163903 /* 650 */ 1193, 1194, 373, 1093, 1192, 1193, 1194, 1192, 1193, 1194,
163904 /* 660 */ 565, 455, 32, 373, 233, 125, 126, 80, 1217, 1217,
163905 /* 670 */ 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124, 124,
163906 /* 680 */ 1433, 959, 568, 228, 958, 122, 122, 122, 122, 121,
163907 /* 690 */ 121, 120, 120, 120, 119, 116, 444, 1158, 228, 1192,
163908 /* 700 */ 157, 1192, 1193, 1194, 1553, 13, 13, 301, 957, 1232,
163909 /* 710 */ 1158, 153, 409, 1158, 373, 1583, 1176, 5, 369, 1580,
163910 /* 720 */ 429, 1238, 3, 957, 122, 122, 122, 122, 121, 121,
163911 /* 730 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1217,
163912 /* 740 */ 1217, 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124,
163913 /* 750 */ 124, 409, 208, 567, 1192, 1028, 1192, 1193, 1194, 1192,
163914 /* 760 */ 388, 852, 155, 1552, 286, 402, 1098, 1098, 488, 568,
163915 /* 770 */ 465, 342, 1319, 1319, 1552, 125, 126, 80, 1217, 1217,
163916 /* 780 */ 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124, 124,
163917 /* 790 */ 129, 568, 13, 13, 374, 122, 122, 122, 122, 121,
163918 /* 800 */ 121, 120, 120, 120, 119, 116, 444, 302, 568, 453,
163919 /* 810 */ 528, 1192, 1193, 1194, 13, 13, 1192, 1193, 1194, 1297,
163920 /* 820 */ 463, 1267, 409, 1317, 1317, 1552, 1012, 453, 452, 200,
163921 /* 830 */ 299, 71, 71, 1265, 122, 122, 122, 122, 121, 121,
163922 /* 840 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1217,
163923 /* 850 */ 1217, 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124,
163924 /* 860 */ 124, 409, 227, 1073, 1158, 284, 284, 419, 312, 278,
163925 /* 870 */ 278, 285, 285, 1419, 406, 405, 382, 1158, 565, 568,
163926 /* 880 */ 1158, 1196, 565, 1600, 565, 125, 126, 80, 1217, 1217,
163927 /* 890 */ 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124, 124,
163928 /* 900 */ 453, 1482, 13, 13, 1536, 122, 122, 122, 122, 121,
163929 /* 910 */ 121, 120, 120, 120, 119, 116, 444, 201, 568, 354,
163930 /* 920 */ 1586, 575, 2, 1245, 840, 841, 842, 1562, 317, 1212,
163931 /* 930 */ 146, 6, 409, 255, 254, 253, 206, 1327, 9, 1196,
163932 /* 940 */ 262, 71, 71, 424, 122, 122, 122, 122, 121, 121,
163933 /* 950 */ 120, 120, 120, 119, 116, 444, 125, 126, 80, 1217,
163934 /* 960 */ 1217, 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124,
163935 /* 970 */ 124, 568, 284, 284, 568, 1213, 409, 574, 313, 1245,
163936 /* 980 */ 349, 1296, 352, 419, 317, 565, 146, 491, 525, 1643,
163937 /* 990 */ 395, 371, 491, 1327, 70, 70, 1295, 71, 71, 240,
163938 /* 1000 */ 1325, 104, 80, 1217, 1217, 1050, 1053, 1040, 1040, 123,
163939 /* 1010 */ 123, 124, 124, 124, 124, 122, 122, 122, 122, 121,
163940 /* 1020 */ 121, 120, 120, 120, 119, 116, 444, 1114, 284, 284,
163941 /* 1030 */ 428, 448, 1525, 1213, 439, 284, 284, 1489, 1352, 311,
163942 /* 1040 */ 474, 565, 1115, 971, 491, 491, 217, 1263, 565, 1538,
163943 /* 1050 */ 568, 972, 207, 568, 1027, 240, 383, 1116, 519, 122,
163944 /* 1060 */ 122, 122, 122, 121, 121, 120, 120, 120, 119, 116,
163945 /* 1070 */ 444, 1018, 107, 71, 71, 1017, 13, 13, 912, 568,
163946 /* 1080 */ 1495, 568, 284, 284, 97, 526, 491, 448, 913, 1326,
163947 /* 1090 */ 1322, 545, 409, 284, 284, 565, 151, 209, 1495, 1497,
163948 /* 1100 */ 262, 450, 55, 55, 56, 56, 565, 1017, 1017, 1019,
163949 /* 1110 */ 443, 332, 409, 527, 12, 295, 125, 126, 80, 1217,
163950 /* 1120 */ 1217, 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124,
163951 /* 1130 */ 124, 347, 409, 864, 1534, 1213, 125, 126, 80, 1217,
163952 /* 1140 */ 1217, 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124,
163953 /* 1150 */ 124, 1137, 1641, 474, 1641, 371, 125, 114, 80, 1217,
163954 /* 1160 */ 1217, 1050, 1053, 1040, 1040, 123, 123, 124, 124, 124,
163955 /* 1170 */ 124, 1495, 329, 474, 331, 122, 122, 122, 122, 121,
163956 /* 1180 */ 121, 120, 120, 120, 119, 116, 444, 203, 1419, 568,
163957 /* 1190 */ 1294, 864, 464, 1213, 436, 122, 122, 122, 122, 121,
163958 /* 1200 */ 121, 120, 120, 120, 119, 116, 444, 553, 1137, 1642,
163959 /* 1210 */ 539, 1642, 15, 15, 892, 122, 122, 122, 122, 121,
163960 /* 1220 */ 121, 120, 120, 120, 119, 116, 444, 568, 298, 538,
163961 /* 1230 */ 1135, 1419, 1559, 1560, 1331, 409, 6, 6, 1169, 1268,
163962 /* 1240 */ 415, 320, 284, 284, 1419, 508, 565, 525, 300, 457,
163963 /* 1250 */ 43, 43, 568, 893, 12, 565, 330, 478, 425, 407,
163964 /* 1260 */ 126, 80, 1217, 1217, 1050, 1053, 1040, 1040, 123, 123,
163965 /* 1270 */ 124, 124, 124, 124, 568, 57, 57, 288, 1192, 1419,
163966 /* 1280 */ 496, 458, 392, 392, 391, 273, 389, 1135, 1558, 849,
163967 /* 1290 */ 1169, 407, 6, 568, 321, 1158, 470, 44, 44, 1557,
163968 /* 1300 */ 1114, 426, 234, 6, 323, 256, 540, 256, 1158, 431,
163969 /* 1310 */ 568, 1158, 322, 17, 487, 1115, 58, 58, 122, 122,
163970 /* 1320 */ 122, 122, 121, 121, 120, 120, 120, 119, 116, 444,
163971 /* 1330 */ 1116, 216, 481, 59, 59, 1192, 1193, 1194, 111, 560,
163972 /* 1340 */ 324, 4, 236, 456, 526, 568, 237, 456, 568, 437,
163973 /* 1350 */ 168, 556, 420, 141, 479, 563, 568, 293, 568, 1095,
163974 /* 1360 */ 568, 293, 568, 1095, 531, 568, 872, 8, 60, 60,
163975 /* 1370 */ 235, 61, 61, 568, 414, 568, 414, 568, 445, 62,
163976 /* 1380 */ 62, 45, 45, 46, 46, 47, 47, 199, 49, 49,
163977 /* 1390 */ 557, 568, 359, 568, 100, 486, 50, 50, 63, 63,
163978 /* 1400 */ 64, 64, 561, 415, 535, 410, 568, 1027, 568, 534,
163979 /* 1410 */ 316, 559, 316, 559, 65, 65, 14, 14, 568, 1027,
163980 /* 1420 */ 568, 512, 932, 872, 1018, 109, 109, 931, 1017, 66,
163981 /* 1430 */ 66, 131, 131, 110, 451, 445, 570, 569, 416, 177,
163982 /* 1440 */ 1017, 132, 132, 67, 67, 568, 467, 568, 932, 471,
163983 /* 1450 */ 1364, 283, 226, 931, 315, 1363, 407, 568, 459, 407,
163984 /* 1460 */ 1017, 1017, 1019, 239, 407, 86, 213, 1350, 52, 52,
163985 /* 1470 */ 68, 68, 1017, 1017, 1019, 1020, 27, 1585, 1180, 447,
163986 /* 1480 */ 69, 69, 288, 97, 108, 1541, 106, 392, 392, 391,
163987 /* 1490 */ 273, 389, 568, 879, 849, 883, 568, 111, 560, 466,
163988 /* 1500 */ 4, 568, 152, 30, 38, 568, 1132, 234, 396, 323,
163989 /* 1510 */ 111, 560, 527, 4, 563, 53, 53, 322, 568, 163,
163990 /* 1520 */ 163, 568, 337, 468, 164, 164, 333, 563, 76, 76,
163991 /* 1530 */ 568, 289, 1514, 568, 31, 1513, 568, 445, 338, 483,
163992 /* 1540 */ 100, 54, 54, 344, 72, 72, 296, 236, 1080, 557,
163993 /* 1550 */ 445, 879, 1360, 134, 134, 168, 73, 73, 141, 161,
163994 /* 1560 */ 161, 1574, 557, 535, 568, 319, 568, 348, 536, 1009,
163995 /* 1570 */ 473, 261, 261, 891, 890, 235, 535, 568, 1027, 568,
163996 /* 1580 */ 475, 534, 261, 367, 109, 109, 521, 136, 136, 130,
163997 /* 1590 */ 130, 1027, 110, 366, 445, 570, 569, 109, 109, 1017,
163998 /* 1600 */ 162, 162, 156, 156, 568, 110, 1080, 445, 570, 569,
163999 /* 1610 */ 410, 351, 1017, 568, 353, 316, 559, 568, 343, 568,
164000 /* 1620 */ 100, 497, 357, 258, 100, 898, 899, 140, 140, 355,
164001 /* 1630 */ 1310, 1017, 1017, 1019, 1020, 27, 139, 139, 362, 451,
164002 /* 1640 */ 137, 137, 138, 138, 1017, 1017, 1019, 1020, 27, 1180,
164003 /* 1650 */ 447, 568, 372, 288, 111, 560, 1021, 4, 392, 392,
164004 /* 1660 */ 391, 273, 389, 568, 1141, 849, 568, 1076, 568, 258,
164005 /* 1670 */ 492, 563, 568, 211, 75, 75, 555, 962, 234, 261,
164006 /* 1680 */ 323, 111, 560, 929, 4, 113, 77, 77, 322, 74,
164007 /* 1690 */ 74, 42, 42, 1373, 445, 48, 48, 1418, 563, 974,
164008 /* 1700 */ 975, 1092, 1091, 1092, 1091, 862, 557, 150, 930, 1346,
164009 /* 1710 */ 113, 1358, 554, 1424, 1021, 1275, 1266, 1254, 236, 1253,
164010 /* 1720 */ 1255, 445, 1593, 1343, 308, 276, 168, 309, 11, 141,
164011 /* 1730 */ 393, 310, 232, 557, 1405, 1027, 335, 291, 1400, 219,
164012 /* 1740 */ 336, 109, 109, 936, 297, 1410, 235, 341, 477, 110,
164013 /* 1750 */ 502, 445, 570, 569, 1393, 1409, 1017, 400, 1293, 365,
164014 /* 1760 */ 223, 1486, 1027, 1485, 1355, 1356, 1354, 1353, 109, 109,
164015 /* 1770 */ 204, 1596, 1232, 558, 265, 218, 110, 205, 445, 570,
164016 /* 1780 */ 569, 410, 387, 1017, 1533, 179, 316, 559, 1017, 1017,
164017 /* 1790 */ 1019, 1020, 27, 230, 1531, 1229, 79, 560, 85, 4,
164018 /* 1800 */ 418, 215, 548, 81, 84, 188, 1406, 173, 181, 461,
164019 /* 1810 */ 451, 35, 462, 563, 183, 1017, 1017, 1019, 1020, 27,
164020 /* 1820 */ 184, 1491, 185, 186, 495, 242, 98, 398, 1412, 36,
164021 /* 1830 */ 1411, 484, 91, 469, 401, 1414, 445, 192, 1480, 246,
164022 /* 1840 */ 1502, 490, 346, 277, 248, 196, 493, 511, 557, 350,
164023 /* 1850 */ 1256, 249, 250, 403, 1313, 1312, 111, 560, 432, 4,
164024 /* 1860 */ 1311, 1304, 93, 1611, 883, 1610, 224, 404, 434, 520,
164025 /* 1870 */ 263, 435, 1579, 563, 1283, 1282, 364, 1027, 306, 1281,
164026 /* 1880 */ 264, 1609, 1565, 109, 109, 370, 1303, 307, 1564, 438,
164027 /* 1890 */ 128, 110, 1378, 445, 570, 569, 445, 546, 1017, 10,
164028 /* 1900 */ 1466, 105, 381, 1377, 34, 572, 99, 1336, 557, 314,
164029 /* 1910 */ 1186, 530, 272, 274, 379, 210, 1335, 547, 385, 386,
164030 /* 1920 */ 275, 573, 1251, 1246, 411, 412, 1518, 165, 178, 1519,
164031 /* 1930 */ 1017, 1017, 1019, 1020, 27, 1517, 1516, 1027, 78, 147,
164032 /* 1940 */ 166, 220, 221, 109, 109, 836, 304, 167, 446, 212,
164033 /* 1950 */ 318, 110, 231, 445, 570, 569, 144, 1090, 1017, 1088,
164034 /* 1960 */ 326, 180, 169, 1212, 182, 334, 238, 915, 241, 1104,
164035 /* 1970 */ 187, 170, 171, 421, 87, 88, 423, 189, 89, 90,
164036 /* 1980 */ 172, 1107, 243, 1103, 244, 158, 18, 245, 345, 247,
164037 /* 1990 */ 1017, 1017, 1019, 1020, 27, 261, 1096, 193, 1226, 489,
164038 /* 2000 */ 194, 37, 366, 851, 494, 251, 195, 506, 92, 19,
164039 /* 2010 */ 498, 358, 20, 503, 881, 361, 94, 894, 305, 159,
164040 /* 2020 */ 513, 39, 95, 1174, 160, 1056, 966, 1143, 96, 174,
164041 /* 2030 */ 1142, 225, 280, 282, 198, 960, 113, 1164, 1160, 260,
164042 /* 2040 */ 21, 22, 23, 1162, 1168, 1167, 1148, 24, 33, 25,
164043 /* 2050 */ 202, 542, 26, 100, 1071, 102, 1057, 103, 7, 1055,
164044 /* 2060 */ 1059, 1113, 1060, 1112, 266, 267, 28, 40, 390, 1022,
164045 /* 2070 */ 863, 112, 29, 564, 1182, 1181, 268, 176, 143, 925,
164046 /* 2080 */ 1242, 1242, 1242, 1242, 1242, 1242, 1242, 1242, 1242, 1242,
164047 /* 2090 */ 1242, 1242, 1242, 1242, 269, 1602, 1242, 1601,
164048 };
164049 static const YYCODETYPE yy_lookahead[] = {
164050 /* 0 */ 193, 193, 193, 274, 275, 276, 193, 274, 275, 276,
164051 /* 10 */ 193, 223, 219, 225, 206, 210, 211, 212, 193, 19,
164052 /* 20 */ 219, 233, 216, 216, 217, 216, 217, 193, 295, 216,
@@ -163799,57 +164208,57 @@
164208 /* 1580 */ 23, 90, 25, 121, 106, 107, 19, 216, 217, 216,
164209 /* 1590 */ 217, 100, 114, 131, 116, 117, 118, 106, 107, 121,
164210 /* 1600 */ 216, 217, 216, 217, 193, 114, 117, 116, 117, 118,
164211 /* 1610 */ 133, 193, 121, 193, 193, 138, 139, 193, 23, 193,
164212 /* 1620 */ 25, 23, 23, 25, 25, 7, 8, 216, 217, 193,
164213 /* 1630 */ 193, 153, 154, 155, 156, 157, 216, 217, 193, 162,
164214 /* 1640 */ 216, 217, 216, 217, 153, 154, 155, 156, 157, 1,
164215 /* 1650 */ 2, 193, 193, 5, 19, 20, 59, 22, 10, 11,
164216 /* 1660 */ 12, 13, 14, 193, 97, 17, 193, 23, 193, 25,
164217 /* 1670 */ 288, 36, 193, 242, 216, 217, 236, 23, 30, 25,
164218 /* 1680 */ 32, 19, 20, 23, 22, 25, 216, 217, 40, 216,
164219 /* 1690 */ 217, 216, 217, 193, 59, 216, 217, 193, 36, 83,
164220 /* 1700 */ 84, 153, 153, 155, 155, 23, 71, 25, 23, 193,
164221 /* 1710 */ 25, 193, 193, 193, 117, 193, 193, 193, 70, 193,
164222 /* 1720 */ 193, 59, 193, 255, 255, 287, 78, 255, 243, 81,
164223 /* 1730 */ 191, 255, 297, 71, 271, 100, 293, 245, 267, 214,
164224 /* 1740 */ 246, 106, 107, 108, 246, 271, 98, 245, 293, 114,
164225 /* 1750 */ 220, 116, 117, 118, 267, 271, 121, 271, 225, 219,
164226 /* 1760 */ 229, 219, 100, 219, 259, 259, 259, 259, 106, 107,
164227 /* 1770 */ 249, 196, 60, 280, 141, 243, 114, 249, 116, 117,
164228 /* 1780 */ 118, 133, 245, 121, 200, 297, 138, 139, 153, 154,
164229 /* 1790 */ 155, 156, 157, 297, 200, 38, 19, 20, 151, 22,
164230 /* 1800 */ 200, 150, 140, 294, 294, 22, 272, 43, 234, 18,
164231 /* 1810 */ 162, 270, 200, 36, 237, 153, 154, 155, 156, 157,
164232 /* 1820 */ 237, 283, 237, 237, 18, 199, 149, 246, 272, 270,
164233 /* 1830 */ 272, 200, 158, 246, 246, 234, 59, 234, 246, 199,
164234 /* 1840 */ 290, 62, 289, 200, 199, 22, 221, 115, 71, 200,
164235 /* 1850 */ 200, 199, 199, 221, 218, 218, 19, 20, 64, 22,
164236 /* 1860 */ 218, 227, 22, 224, 126, 224, 165, 221, 24, 305,
164237 /* 1870 */ 200, 113, 312, 36, 218, 220, 218, 100, 282, 218,
164238 /* 1880 */ 91, 218, 317, 106, 107, 221, 227, 282, 317, 82,
164239 /* 1890 */ 148, 114, 265, 116, 117, 118, 59, 145, 121, 22,
164240 /* 1900 */ 277, 158, 200, 265, 25, 202, 147, 250, 71, 279,
164241 /* 1910 */ 13, 146, 194, 194, 249, 248, 250, 140, 247, 246,
164242 /* 1920 */ 6, 192, 192, 192, 303, 303, 213, 207, 300, 213,
164243 /* 1930 */ 153, 154, 155, 156, 157, 213, 213, 100, 213, 222,
164244 /* 1940 */ 207, 214, 214, 106, 107, 4, 222, 207, 3, 22,
164245 /* 1950 */ 163, 114, 15, 116, 117, 118, 16, 23, 121, 23,
164246 /* 1960 */ 139, 151, 130, 25, 142, 16, 24, 20, 144, 1,
164247 /* 1970 */ 142, 130, 130, 61, 53, 53, 37, 151, 53, 53,
164248 /* 1980 */ 130, 116, 34, 1, 141, 5, 22, 115, 161, 141,
164249 /* 1990 */ 153, 154, 155, 156, 157, 25, 68, 68, 75, 41,
164250 /* 2000 */ 115, 24, 131, 20, 19, 125, 22, 96, 22, 22,
164251 /* 2010 */ 67, 23, 22, 67, 59, 24, 22, 28, 67, 23,
164252 /* 2020 */ 22, 22, 149, 23, 23, 23, 116, 23, 25, 37,
164253 /* 2030 */ 97, 141, 23, 23, 22, 143, 25, 75, 88, 34,
164254 /* 2040 */ 34, 34, 34, 86, 75, 93, 23, 34, 22, 34,
164255 /* 2050 */ 25, 24, 34, 25, 23, 142, 23, 142, 44, 23,
164256 /* 2060 */ 23, 23, 11, 23, 25, 22, 22, 22, 15, 23,
164257 /* 2070 */ 23, 22, 22, 25, 1, 1, 141, 25, 23, 135,
164258 /* 2080 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
164259 /* 2090 */ 319, 319, 319, 319, 141, 141, 319, 141, 319, 319,
164260 /* 2100 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
164261 /* 2110 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
164262 /* 2120 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
164263 /* 2130 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
164264 /* 2140 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
@@ -163860,77 +164269,82 @@
164269 /* 2190 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
164270 /* 2200 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
164271 /* 2210 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
164272 /* 2220 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
164273 /* 2230 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
164274 /* 2240 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
164275 /* 2250 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
164276 /* 2260 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
164277 /* 2270 */ 319, 319, 319, 319, 319, 319, 319, 319, 319, 319,
164278 /* 2280 */ 319, 319, 319,
164279 };
164280 #define YY_SHIFT_COUNT (575)
164281 #define YY_SHIFT_MIN (0)
164282 #define YY_SHIFT_MAX (2074)
164283 static const unsigned short int yy_shift_ofst[] = {
164284 /* 0 */ 1648, 1477, 1272, 322, 322, 1, 1319, 1478, 1491, 1837,
164285 /* 10 */ 1837, 1837, 471, 0, 0, 214, 1093, 1837, 1837, 1837,
164286 /* 20 */ 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837,
164287 /* 30 */ 271, 271, 1219, 1219, 216, 88, 1, 1, 1, 1,
164288 /* 40 */ 1, 40, 111, 258, 361, 469, 512, 583, 622, 693,
164289 /* 50 */ 732, 803, 842, 913, 1073, 1093, 1093, 1093, 1093, 1093,
164290 /* 60 */ 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093,
164291 /* 70 */ 1093, 1093, 1093, 1113, 1093, 1216, 957, 957, 1635, 1662,
164292 /* 80 */ 1777, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837,
164293 /* 90 */ 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837,
164294 /* 100 */ 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837,
164295 /* 110 */ 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837,
164296 /* 120 */ 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837, 1837,
164297 /* 130 */ 137, 181, 181, 181, 181, 181, 181, 181, 94, 430,
164298 /* 140 */ 66, 65, 112, 366, 533, 533, 740, 1261, 533, 533,
164299 /* 150 */ 79, 79, 533, 412, 412, 412, 77, 412, 123, 113,
164300 /* 160 */ 113, 22, 22, 2098, 2098, 328, 328, 328, 239, 468,
164301 /* 170 */ 468, 468, 468, 1015, 1015, 409, 366, 1129, 1186, 533,
164302 /* 180 */ 533, 533, 533, 533, 533, 533, 533, 533, 533, 533,
164303 /* 190 */ 533, 533, 533, 533, 533, 533, 533, 533, 533, 969,
164304 /* 200 */ 621, 621, 533, 642, 788, 788, 1228, 1228, 822, 822,
164305 /* 210 */ 67, 1274, 2098, 2098, 2098, 2098, 2098, 2098, 2098, 1307,
164306 /* 220 */ 954, 954, 585, 472, 640, 387, 695, 538, 541, 700,
164307 /* 230 */ 533, 533, 533, 533, 533, 533, 533, 533, 533, 533,
164308 /* 240 */ 222, 533, 533, 533, 533, 533, 533, 533, 533, 533,
164309 /* 250 */ 533, 533, 533, 1179, 1179, 1179, 533, 533, 533, 565,
164310 /* 260 */ 533, 533, 533, 916, 1144, 533, 533, 1288, 533, 533,
164311 /* 270 */ 533, 533, 533, 533, 533, 533, 639, 1330, 209, 1076,
164312 /* 280 */ 1076, 1076, 1076, 580, 209, 209, 1313, 768, 917, 649,
164313 /* 290 */ 1181, 1316, 405, 1316, 1238, 249, 1181, 1181, 249, 1181,
164314 /* 300 */ 405, 1238, 1369, 464, 1259, 1012, 1012, 1012, 1368, 1368,
164315 /* 310 */ 1368, 1368, 184, 184, 1326, 904, 1287, 1480, 1712, 1712,
164316 /* 320 */ 1633, 1633, 1757, 1757, 1633, 1647, 1651, 1783, 1764, 1791,
164317 /* 330 */ 1791, 1791, 1791, 1633, 1806, 1677, 1651, 1651, 1677, 1783,
164318 /* 340 */ 1764, 1677, 1764, 1677, 1633, 1806, 1674, 1779, 1633, 1806,
164319 /* 350 */ 1823, 1633, 1806, 1633, 1806, 1823, 1732, 1732, 1732, 1794,
164320 /* 360 */ 1840, 1840, 1823, 1732, 1738, 1732, 1794, 1732, 1732, 1701,
164321 /* 370 */ 1844, 1758, 1758, 1823, 1633, 1789, 1789, 1807, 1807, 1742,
164322 /* 380 */ 1752, 1877, 1633, 1743, 1742, 1759, 1765, 1677, 1879, 1897,
164323 /* 390 */ 1897, 1914, 1914, 1914, 2098, 2098, 2098, 2098, 2098, 2098,
164324 /* 400 */ 2098, 2098, 2098, 2098, 2098, 2098, 2098, 2098, 2098, 207,
164325 /* 410 */ 1095, 331, 620, 903, 806, 1074, 1483, 1432, 1481, 1322,
164326 /* 420 */ 1370, 1394, 1515, 1291, 1546, 1547, 1557, 1595, 1598, 1599,
164327 /* 430 */ 1434, 1453, 1618, 1462, 1567, 1489, 1644, 1654, 1616, 1660,
164328 /* 440 */ 1548, 1549, 1682, 1685, 1597, 742, 1941, 1945, 1927, 1787,
164329 /* 450 */ 1937, 1940, 1934, 1936, 1821, 1810, 1832, 1938, 1938, 1942,
164330 /* 460 */ 1822, 1947, 1824, 1949, 1968, 1828, 1841, 1938, 1842, 1912,
164331 /* 470 */ 1939, 1938, 1826, 1921, 1922, 1925, 1926, 1850, 1865, 1948,
164332 /* 480 */ 1843, 1982, 1980, 1964, 1872, 1827, 1928, 1970, 1929, 1923,
164333 /* 490 */ 1958, 1848, 1885, 1977, 1983, 1985, 1871, 1880, 1984, 1943,
164334 /* 500 */ 1986, 1987, 1988, 1990, 1946, 1955, 1991, 1911, 1989, 1994,
164335 /* 510 */ 1951, 1992, 1996, 1873, 1998, 2000, 2001, 2002, 2003, 2004,
164336 /* 520 */ 1999, 1933, 1890, 2009, 2010, 1910, 2005, 2012, 1892, 2011,
164337 /* 530 */ 2006, 2007, 2008, 2013, 1950, 1962, 1957, 2014, 1969, 1952,
164338 /* 540 */ 2015, 2023, 2026, 2027, 2025, 2028, 2018, 1913, 1915, 2031,
164339 /* 550 */ 2011, 2033, 2036, 2037, 2038, 2039, 2040, 2043, 2051, 2044,
164340 /* 560 */ 2045, 2046, 2047, 2049, 2050, 2048, 1944, 1935, 1953, 1954,
164341 /* 570 */ 1956, 2052, 2055, 2053, 2073, 2074,
164342 };
164343 #define YY_REDUCE_COUNT (408)
164344 #define YY_REDUCE_MIN (-271)
164345 #define YY_REDUCE_MAX (1740)
164346 static const short yy_reduce_ofst[] = {
164347 /* 0 */ -125, 733, 789, 241, 293, -123, -193, -191, -183, -187,
164348 /* 10 */ 166, 238, 133, -207, -199, -267, -176, -6, 204, 489,
164349 /* 20 */ 576, -175, 598, 686, 615, 725, 860, 778, 781, 857,
164350 /* 30 */ 616, 887, 87, 240, -192, 408, 626, 796, 843, 854,
@@ -163940,98 +164354,99 @@
164354 /* 70 */ -271, -271, -271, -271, -271, -271, -271, -271, 80, 83,
164355 /* 80 */ 313, 886, 888, 996, 1034, 1059, 1081, 1100, 1117, 1152,
164356 /* 90 */ 1155, 1163, 1165, 1167, 1169, 1172, 1180, 1182, 1184, 1198,
164357 /* 100 */ 1200, 1213, 1215, 1225, 1227, 1252, 1254, 1264, 1299, 1303,
164358 /* 110 */ 1308, 1312, 1325, 1328, 1337, 1340, 1343, 1371, 1373, 1384,
164359 /* 120 */ 1386, 1411, 1420, 1424, 1426, 1458, 1470, 1473, 1475, 1479,
164360 /* 130 */ -271, -271, -271, -271, -271, -271, -271, -271, -271, -271,
164361 /* 140 */ -271, 138, 459, 396, -158, 470, 302, -212, 521, 201,
164362 /* 150 */ -195, -92, 559, 630, 632, 630, -271, 632, 901, 63,
164363 /* 160 */ 407, -271, -271, -271, -271, 161, 161, 161, 251, 335,
164364 /* 170 */ 847, 960, 980, 537, 588, 618, 628, 688, 688, -166,
164365 /* 180 */ -161, 674, 790, 794, 799, 851, 852, -122, 680, -120,
164366 /* 190 */ 995, 1038, 415, 1051, 893, 798, 962, 400, 1086, 779,
164367 /* 200 */ 923, 924, 263, 1041, 979, 990, 1083, 1097, 1031, 1194,
164368 /* 210 */ 362, 994, 1139, 1005, 1037, 1202, 1205, 1195, 1210, -194,
164369 /* 220 */ 56, 185, -135, 232, 522, 560, 601, 617, 669, 683,
164370 /* 230 */ 711, 856, 908, 941, 1048, 1101, 1147, 1257, 1262, 1265,
164371 /* 240 */ 392, 1292, 1333, 1339, 1342, 1346, 1350, 1359, 1374, 1418,
164372 /* 250 */ 1421, 1436, 1437, 593, 755, 770, 997, 1445, 1459, 1209,
164373 /* 260 */ 1500, 1504, 1516, 1132, 1243, 1518, 1519, 1440, 1520, 560,
164374 /* 270 */ 1522, 1523, 1524, 1526, 1527, 1529, 1382, 1438, 1431, 1468,
164375 /* 280 */ 1469, 1472, 1476, 1209, 1431, 1431, 1485, 1525, 1539, 1435,
164376 /* 290 */ 1463, 1471, 1492, 1487, 1443, 1494, 1474, 1484, 1498, 1486,
164377 /* 300 */ 1502, 1455, 1530, 1531, 1533, 1540, 1542, 1544, 1505, 1506,
164378 /* 310 */ 1507, 1508, 1521, 1528, 1493, 1537, 1532, 1575, 1488, 1496,
164379 /* 320 */ 1584, 1594, 1509, 1510, 1600, 1538, 1534, 1541, 1574, 1577,
164380 /* 330 */ 1583, 1585, 1586, 1612, 1626, 1581, 1556, 1558, 1587, 1559,
164381 /* 340 */ 1601, 1588, 1603, 1592, 1631, 1640, 1550, 1553, 1643, 1645,
164382 /* 350 */ 1625, 1649, 1652, 1650, 1653, 1632, 1636, 1637, 1642, 1634,
164383 /* 360 */ 1639, 1641, 1646, 1656, 1655, 1658, 1659, 1661, 1663, 1560,
164384 /* 370 */ 1564, 1596, 1605, 1664, 1670, 1565, 1571, 1627, 1638, 1657,
164385 /* 380 */ 1665, 1623, 1702, 1630, 1666, 1667, 1671, 1673, 1703, 1718,
164386 /* 390 */ 1719, 1729, 1730, 1731, 1621, 1622, 1628, 1720, 1713, 1716,
164387 /* 400 */ 1722, 1723, 1733, 1717, 1724, 1727, 1728, 1725, 1740,
164388 };
164389 static const YYACTIONTYPE yy_default[] = {
164390 /* 0 */ 1647, 1647, 1647, 1475, 1240, 1351, 1240, 1240, 1240, 1475,
164391 /* 10 */ 1475, 1475, 1240, 1381, 1381, 1528, 1273, 1240, 1240, 1240,
164392 /* 20 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1474, 1240, 1240,
164393 /* 30 */ 1240, 1240, 1563, 1563, 1240, 1240, 1240, 1240, 1240, 1240,
164394 /* 40 */ 1240, 1240, 1390, 1240, 1397, 1240, 1240, 1240, 1240, 1240,
164395 /* 50 */ 1476, 1477, 1240, 1240, 1240, 1527, 1529, 1492, 1404, 1403,
164396 /* 60 */ 1402, 1401, 1510, 1369, 1395, 1388, 1392, 1470, 1471, 1469,
164397 /* 70 */ 1473, 1477, 1476, 1240, 1391, 1438, 1454, 1437, 1240, 1240,
164398 /* 80 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164399 /* 90 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164400 /* 100 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164401 /* 110 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164402 /* 120 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164403 /* 130 */ 1446, 1453, 1452, 1451, 1460, 1450, 1447, 1440, 1439, 1441,
164404 /* 140 */ 1442, 1240, 1240, 1264, 1240, 1240, 1261, 1315, 1240, 1240,
164405 /* 150 */ 1240, 1240, 1240, 1547, 1546, 1240, 1443, 1240, 1273, 1432,
164406 /* 160 */ 1431, 1457, 1444, 1456, 1455, 1535, 1599, 1598, 1493, 1240,
164407 /* 170 */ 1240, 1240, 1240, 1240, 1240, 1563, 1240, 1240, 1240, 1240,
164408 /* 180 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164409 /* 190 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1371,
164410 /* 200 */ 1563, 1563, 1240, 1273, 1563, 1563, 1372, 1372, 1269, 1269,
164411 /* 210 */ 1375, 1240, 1542, 1342, 1342, 1342, 1342, 1351, 1342, 1240,
164412 /* 220 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164413 /* 230 */ 1240, 1240, 1240, 1240, 1532, 1530, 1240, 1240, 1240, 1240,
164414 /* 240 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164415 /* 250 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164416 /* 260 */ 1240, 1240, 1240, 1347, 1240, 1240, 1240, 1240, 1240, 1240,
164417 /* 270 */ 1240, 1240, 1240, 1240, 1240, 1592, 1240, 1505, 1329, 1347,
164418 /* 280 */ 1347, 1347, 1347, 1349, 1330, 1328, 1341, 1274, 1247, 1639,
164419 /* 290 */ 1407, 1396, 1348, 1396, 1636, 1394, 1407, 1407, 1394, 1407,
164420 /* 300 */ 1348, 1636, 1290, 1615, 1285, 1381, 1381, 1381, 1371, 1371,
164421 /* 310 */ 1371, 1371, 1375, 1375, 1472, 1348, 1341, 1240, 1639, 1639,
164422 /* 320 */ 1357, 1357, 1638, 1638, 1357, 1493, 1623, 1416, 1318, 1324,
164423 /* 330 */ 1324, 1324, 1324, 1357, 1258, 1394, 1623, 1623, 1394, 1416,
164424 /* 340 */ 1318, 1394, 1318, 1394, 1357, 1258, 1509, 1633, 1357, 1258,
164425 /* 350 */ 1483, 1357, 1258, 1357, 1258, 1483, 1316, 1316, 1316, 1305,
164426 /* 360 */ 1240, 1240, 1483, 1316, 1290, 1316, 1305, 1316, 1316, 1581,
164427 /* 370 */ 1240, 1487, 1487, 1483, 1357, 1573, 1573, 1384, 1384, 1389,
164428 /* 380 */ 1375, 1478, 1357, 1240, 1389, 1387, 1385, 1394, 1308, 1595,
164429 /* 390 */ 1595, 1591, 1591, 1591, 1644, 1644, 1542, 1608, 1273, 1273,
164430 /* 400 */ 1273, 1273, 1608, 1292, 1292, 1274, 1274, 1273, 1608, 1240,
164431 /* 410 */ 1240, 1240, 1240, 1240, 1240, 1603, 1240, 1537, 1494, 1361,
164432 /* 420 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164433 /* 430 */ 1240, 1240, 1240, 1240, 1548, 1240, 1240, 1240, 1240, 1240,
164434 /* 440 */ 1240, 1240, 1240, 1240, 1240, 1421, 1240, 1243, 1539, 1240,
164435 /* 450 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1398, 1399, 1362,
164436 /* 460 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1413, 1240, 1240,
164437 /* 470 */ 1240, 1408, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164438 /* 480 */ 1635, 1240, 1240, 1240, 1240, 1240, 1240, 1508, 1507, 1240,
164439 /* 490 */ 1240, 1359, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164440 /* 500 */ 1240, 1240, 1240, 1240, 1240, 1288, 1240, 1240, 1240, 1240,
164441 /* 510 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164442 /* 520 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1386,
164443 /* 530 */ 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164444 /* 540 */ 1240, 1240, 1240, 1240, 1578, 1376, 1240, 1240, 1240, 1240,
164445 /* 550 */ 1626, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240, 1240,
164446 /* 560 */ 1240, 1240, 1240, 1240, 1240, 1619, 1332, 1423, 1240, 1422,
164447 /* 570 */ 1426, 1262, 1240, 1252, 1240, 1240,
164448 };
164449 /********** End of lemon-generated parsing tables *****************************/
164450
164451 /* The next table maps tokens (terminal symbols) into fallback tokens.
164452 ** If a construct like the following:
@@ -164855,204 +165270,206 @@
165270 /* 204 */ "expr ::= expr likeop expr ESCAPE expr",
165271 /* 205 */ "expr ::= expr ISNULL|NOTNULL",
165272 /* 206 */ "expr ::= expr NOT NULL",
165273 /* 207 */ "expr ::= expr IS expr",
165274 /* 208 */ "expr ::= expr IS NOT expr",
165275 /* 209 */ "expr ::= expr IS NOT DISTINCT FROM expr",
165276 /* 210 */ "expr ::= expr IS DISTINCT FROM expr",
165277 /* 211 */ "expr ::= NOT expr",
165278 /* 212 */ "expr ::= BITNOT expr",
165279 /* 213 */ "expr ::= PLUS|MINUS expr",
165280 /* 214 */ "expr ::= expr PTR expr",
165281 /* 215 */ "between_op ::= BETWEEN",
165282 /* 216 */ "between_op ::= NOT BETWEEN",
165283 /* 217 */ "expr ::= expr between_op expr AND expr",
165284 /* 218 */ "in_op ::= IN",
165285 /* 219 */ "in_op ::= NOT IN",
165286 /* 220 */ "expr ::= expr in_op LP exprlist RP",
165287 /* 221 */ "expr ::= LP select RP",
165288 /* 222 */ "expr ::= expr in_op LP select RP",
165289 /* 223 */ "expr ::= expr in_op nm dbnm paren_exprlist",
165290 /* 224 */ "expr ::= EXISTS LP select RP",
165291 /* 225 */ "expr ::= CASE case_operand case_exprlist case_else END",
165292 /* 226 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
165293 /* 227 */ "case_exprlist ::= WHEN expr THEN expr",
165294 /* 228 */ "case_else ::= ELSE expr",
165295 /* 229 */ "case_else ::=",
165296 /* 230 */ "case_operand ::= expr",
165297 /* 231 */ "case_operand ::=",
165298 /* 232 */ "exprlist ::=",
165299 /* 233 */ "nexprlist ::= nexprlist COMMA expr",
165300 /* 234 */ "nexprlist ::= expr",
165301 /* 235 */ "paren_exprlist ::=",
165302 /* 236 */ "paren_exprlist ::= LP exprlist RP",
165303 /* 237 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt",
165304 /* 238 */ "uniqueflag ::= UNIQUE",
165305 /* 239 */ "uniqueflag ::=",
165306 /* 240 */ "eidlist_opt ::=",
165307 /* 241 */ "eidlist_opt ::= LP eidlist RP",
165308 /* 242 */ "eidlist ::= eidlist COMMA nm collate sortorder",
165309 /* 243 */ "eidlist ::= nm collate sortorder",
165310 /* 244 */ "collate ::=",
165311 /* 245 */ "collate ::= COLLATE ID|STRING",
165312 /* 246 */ "cmd ::= DROP INDEX ifexists fullname",
165313 /* 247 */ "cmd ::= VACUUM vinto",
165314 /* 248 */ "cmd ::= VACUUM nm vinto",
165315 /* 249 */ "vinto ::= INTO expr",
165316 /* 250 */ "vinto ::=",
165317 /* 251 */ "cmd ::= PRAGMA nm dbnm",
165318 /* 252 */ "cmd ::= PRAGMA nm dbnm EQ nmnum",
165319 /* 253 */ "cmd ::= PRAGMA nm dbnm LP nmnum RP",
165320 /* 254 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
165321 /* 255 */ "cmd ::= PRAGMA nm dbnm LP minus_num RP",
165322 /* 256 */ "plus_num ::= PLUS INTEGER|FLOAT",
165323 /* 257 */ "minus_num ::= MINUS INTEGER|FLOAT",
165324 /* 258 */ "cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END",
165325 /* 259 */ "trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
165326 /* 260 */ "trigger_time ::= BEFORE|AFTER",
165327 /* 261 */ "trigger_time ::= INSTEAD OF",
165328 /* 262 */ "trigger_time ::=",
165329 /* 263 */ "trigger_event ::= DELETE|INSERT",
165330 /* 264 */ "trigger_event ::= UPDATE",
165331 /* 265 */ "trigger_event ::= UPDATE OF idlist",
165332 /* 266 */ "when_clause ::=",
165333 /* 267 */ "when_clause ::= WHEN expr",
165334 /* 268 */ "trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI",
165335 /* 269 */ "trigger_cmd_list ::= trigger_cmd SEMI",
165336 /* 270 */ "trnm ::= nm DOT nm",
165337 /* 271 */ "tridxby ::= INDEXED BY nm",
165338 /* 272 */ "tridxby ::= NOT INDEXED",
165339 /* 273 */ "trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt",
165340 /* 274 */ "trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt",
165341 /* 275 */ "trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt",
165342 /* 276 */ "trigger_cmd ::= scanpt select scanpt",
165343 /* 277 */ "expr ::= RAISE LP IGNORE RP",
165344 /* 278 */ "expr ::= RAISE LP raisetype COMMA nm RP",
165345 /* 279 */ "raisetype ::= ROLLBACK",
165346 /* 280 */ "raisetype ::= ABORT",
165347 /* 281 */ "raisetype ::= FAIL",
165348 /* 282 */ "cmd ::= DROP TRIGGER ifexists fullname",
165349 /* 283 */ "cmd ::= ATTACH database_kw_opt expr AS expr key_opt",
165350 /* 284 */ "cmd ::= DETACH database_kw_opt expr",
165351 /* 285 */ "key_opt ::=",
165352 /* 286 */ "key_opt ::= KEY expr",
165353 /* 287 */ "cmd ::= REINDEX",
165354 /* 288 */ "cmd ::= REINDEX nm dbnm",
165355 /* 289 */ "cmd ::= ANALYZE",
165356 /* 290 */ "cmd ::= ANALYZE nm dbnm",
165357 /* 291 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
165358 /* 292 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist",
165359 /* 293 */ "cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm",
165360 /* 294 */ "add_column_fullname ::= fullname",
165361 /* 295 */ "cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm",
165362 /* 296 */ "cmd ::= create_vtab",
165363 /* 297 */ "cmd ::= create_vtab LP vtabarglist RP",
165364 /* 298 */ "create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm",
165365 /* 299 */ "vtabarg ::=",
165366 /* 300 */ "vtabargtoken ::= ANY",
165367 /* 301 */ "vtabargtoken ::= lp anylist RP",
165368 /* 302 */ "lp ::= LP",
165369 /* 303 */ "with ::= WITH wqlist",
165370 /* 304 */ "with ::= WITH RECURSIVE wqlist",
165371 /* 305 */ "wqas ::= AS",
165372 /* 306 */ "wqas ::= AS MATERIALIZED",
165373 /* 307 */ "wqas ::= AS NOT MATERIALIZED",
165374 /* 308 */ "wqitem ::= nm eidlist_opt wqas LP select RP",
165375 /* 309 */ "wqlist ::= wqitem",
165376 /* 310 */ "wqlist ::= wqlist COMMA wqitem",
165377 /* 311 */ "windowdefn_list ::= windowdefn",
165378 /* 312 */ "windowdefn_list ::= windowdefn_list COMMA windowdefn",
165379 /* 313 */ "windowdefn ::= nm AS LP window RP",
165380 /* 314 */ "window ::= PARTITION BY nexprlist orderby_opt frame_opt",
165381 /* 315 */ "window ::= nm PARTITION BY nexprlist orderby_opt frame_opt",
165382 /* 316 */ "window ::= ORDER BY sortlist frame_opt",
165383 /* 317 */ "window ::= nm ORDER BY sortlist frame_opt",
165384 /* 318 */ "window ::= frame_opt",
165385 /* 319 */ "window ::= nm frame_opt",
165386 /* 320 */ "frame_opt ::=",
165387 /* 321 */ "frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt",
165388 /* 322 */ "frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt",
165389 /* 323 */ "range_or_rows ::= RANGE|ROWS|GROUPS",
165390 /* 324 */ "frame_bound_s ::= frame_bound",
165391 /* 325 */ "frame_bound_s ::= UNBOUNDED PRECEDING",
165392 /* 326 */ "frame_bound_e ::= frame_bound",
165393 /* 327 */ "frame_bound_e ::= UNBOUNDED FOLLOWING",
165394 /* 328 */ "frame_bound ::= expr PRECEDING|FOLLOWING",
165395 /* 329 */ "frame_bound ::= CURRENT ROW",
165396 /* 330 */ "frame_exclude_opt ::=",
165397 /* 331 */ "frame_exclude_opt ::= EXCLUDE frame_exclude",
165398 /* 332 */ "frame_exclude ::= NO OTHERS",
165399 /* 333 */ "frame_exclude ::= CURRENT ROW",
165400 /* 334 */ "frame_exclude ::= GROUP|TIES",
165401 /* 335 */ "window_clause ::= WINDOW windowdefn_list",
165402 /* 336 */ "filter_over ::= filter_clause over_clause",
165403 /* 337 */ "filter_over ::= over_clause",
165404 /* 338 */ "filter_over ::= filter_clause",
165405 /* 339 */ "over_clause ::= OVER LP window RP",
165406 /* 340 */ "over_clause ::= OVER nm",
165407 /* 341 */ "filter_clause ::= FILTER LP WHERE expr RP",
165408 /* 342 */ "input ::= cmdlist",
165409 /* 343 */ "cmdlist ::= cmdlist ecmd",
165410 /* 344 */ "cmdlist ::= ecmd",
165411 /* 345 */ "ecmd ::= SEMI",
165412 /* 346 */ "ecmd ::= cmdx SEMI",
165413 /* 347 */ "ecmd ::= explain cmdx SEMI",
165414 /* 348 */ "trans_opt ::=",
165415 /* 349 */ "trans_opt ::= TRANSACTION",
165416 /* 350 */ "trans_opt ::= TRANSACTION nm",
165417 /* 351 */ "savepoint_opt ::= SAVEPOINT",
165418 /* 352 */ "savepoint_opt ::=",
165419 /* 353 */ "cmd ::= create_table create_table_args",
165420 /* 354 */ "table_option_set ::= table_option",
165421 /* 355 */ "columnlist ::= columnlist COMMA columnname carglist",
165422 /* 356 */ "columnlist ::= columnname carglist",
165423 /* 357 */ "nm ::= ID|INDEXED",
165424 /* 358 */ "nm ::= STRING",
165425 /* 359 */ "nm ::= JOIN_KW",
165426 /* 360 */ "typetoken ::= typename",
165427 /* 361 */ "typename ::= ID|STRING",
165428 /* 362 */ "signed ::= plus_num",
165429 /* 363 */ "signed ::= minus_num",
165430 /* 364 */ "carglist ::= carglist ccons",
165431 /* 365 */ "carglist ::=",
165432 /* 366 */ "ccons ::= NULL onconf",
165433 /* 367 */ "ccons ::= GENERATED ALWAYS AS generated",
165434 /* 368 */ "ccons ::= AS generated",
165435 /* 369 */ "conslist_opt ::= COMMA conslist",
165436 /* 370 */ "conslist ::= conslist tconscomma tcons",
165437 /* 371 */ "conslist ::= tcons",
165438 /* 372 */ "tconscomma ::=",
165439 /* 373 */ "defer_subclause_opt ::= defer_subclause",
165440 /* 374 */ "resolvetype ::= raisetype",
165441 /* 375 */ "selectnowith ::= oneselect",
165442 /* 376 */ "oneselect ::= values",
165443 /* 377 */ "sclp ::= selcollist COMMA",
165444 /* 378 */ "as ::= ID|STRING",
165445 /* 379 */ "indexed_opt ::= indexed_by",
165446 /* 380 */ "returning ::=",
165447 /* 381 */ "expr ::= term",
165448 /* 382 */ "likeop ::= LIKE_KW|MATCH",
165449 /* 383 */ "exprlist ::= nexprlist",
165450 /* 384 */ "nmnum ::= plus_num",
165451 /* 385 */ "nmnum ::= nm",
165452 /* 386 */ "nmnum ::= ON",
165453 /* 387 */ "nmnum ::= DELETE",
165454 /* 388 */ "nmnum ::= DEFAULT",
165455 /* 389 */ "plus_num ::= INTEGER|FLOAT",
165456 /* 390 */ "foreach_clause ::=",
165457 /* 391 */ "foreach_clause ::= FOR EACH ROW",
165458 /* 392 */ "trnm ::= nm",
165459 /* 393 */ "tridxby ::=",
165460 /* 394 */ "database_kw_opt ::= DATABASE",
165461 /* 395 */ "database_kw_opt ::=",
165462 /* 396 */ "kwcolumn_opt ::=",
165463 /* 397 */ "kwcolumn_opt ::= COLUMNKW",
165464 /* 398 */ "vtabarglist ::= vtabarg",
165465 /* 399 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
165466 /* 400 */ "vtabarg ::= vtabarg vtabargtoken",
165467 /* 401 */ "anylist ::=",
165468 /* 402 */ "anylist ::= anylist LP anylist RP",
165469 /* 403 */ "anylist ::= anylist ANY",
165470 /* 404 */ "with ::=",
165471 };
165472 #endif /* NDEBUG */
165473
165474
165475 #if YYSTACKDEPTH<=0
@@ -165764,204 +166181,206 @@
166181 217, /* (204) expr ::= expr likeop expr ESCAPE expr */
166182 217, /* (205) expr ::= expr ISNULL|NOTNULL */
166183 217, /* (206) expr ::= expr NOT NULL */
166184 217, /* (207) expr ::= expr IS expr */
166185 217, /* (208) expr ::= expr IS NOT expr */
166186 217, /* (209) expr ::= expr IS NOT DISTINCT FROM expr */
166187 217, /* (210) expr ::= expr IS DISTINCT FROM expr */
166188 217, /* (211) expr ::= NOT expr */
166189 217, /* (212) expr ::= BITNOT expr */
166190 217, /* (213) expr ::= PLUS|MINUS expr */
166191 217, /* (214) expr ::= expr PTR expr */
166192 275, /* (215) between_op ::= BETWEEN */
166193 275, /* (216) between_op ::= NOT BETWEEN */
166194 217, /* (217) expr ::= expr between_op expr AND expr */
166195 276, /* (218) in_op ::= IN */
166196 276, /* (219) in_op ::= NOT IN */
166197 217, /* (220) expr ::= expr in_op LP exprlist RP */
166198 217, /* (221) expr ::= LP select RP */
166199 217, /* (222) expr ::= expr in_op LP select RP */
166200 217, /* (223) expr ::= expr in_op nm dbnm paren_exprlist */
166201 217, /* (224) expr ::= EXISTS LP select RP */
166202 217, /* (225) expr ::= CASE case_operand case_exprlist case_else END */
166203 279, /* (226) case_exprlist ::= case_exprlist WHEN expr THEN expr */
166204 279, /* (227) case_exprlist ::= WHEN expr THEN expr */
166205 280, /* (228) case_else ::= ELSE expr */
166206 280, /* (229) case_else ::= */
166207 278, /* (230) case_operand ::= expr */
166208 278, /* (231) case_operand ::= */
166209 261, /* (232) exprlist ::= */
166210 253, /* (233) nexprlist ::= nexprlist COMMA expr */
166211 253, /* (234) nexprlist ::= expr */
166212 277, /* (235) paren_exprlist ::= */
166213 277, /* (236) paren_exprlist ::= LP exprlist RP */
166214 190, /* (237) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
166215 281, /* (238) uniqueflag ::= UNIQUE */
166216 281, /* (239) uniqueflag ::= */
166217 221, /* (240) eidlist_opt ::= */
166218 221, /* (241) eidlist_opt ::= LP eidlist RP */
166219 232, /* (242) eidlist ::= eidlist COMMA nm collate sortorder */
166220 232, /* (243) eidlist ::= nm collate sortorder */
166221 282, /* (244) collate ::= */
166222 282, /* (245) collate ::= COLLATE ID|STRING */
166223 190, /* (246) cmd ::= DROP INDEX ifexists fullname */
166224 190, /* (247) cmd ::= VACUUM vinto */
166225 190, /* (248) cmd ::= VACUUM nm vinto */
166226 283, /* (249) vinto ::= INTO expr */
166227 283, /* (250) vinto ::= */
166228 190, /* (251) cmd ::= PRAGMA nm dbnm */
166229 190, /* (252) cmd ::= PRAGMA nm dbnm EQ nmnum */
166230 190, /* (253) cmd ::= PRAGMA nm dbnm LP nmnum RP */
166231 190, /* (254) cmd ::= PRAGMA nm dbnm EQ minus_num */
166232 190, /* (255) cmd ::= PRAGMA nm dbnm LP minus_num RP */
166233 211, /* (256) plus_num ::= PLUS INTEGER|FLOAT */
166234 212, /* (257) minus_num ::= MINUS INTEGER|FLOAT */
166235 190, /* (258) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
166236 285, /* (259) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
166237 287, /* (260) trigger_time ::= BEFORE|AFTER */
166238 287, /* (261) trigger_time ::= INSTEAD OF */
166239 287, /* (262) trigger_time ::= */
166240 288, /* (263) trigger_event ::= DELETE|INSERT */
166241 288, /* (264) trigger_event ::= UPDATE */
166242 288, /* (265) trigger_event ::= UPDATE OF idlist */
166243 290, /* (266) when_clause ::= */
166244 290, /* (267) when_clause ::= WHEN expr */
166245 286, /* (268) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
166246 286, /* (269) trigger_cmd_list ::= trigger_cmd SEMI */
166247 292, /* (270) trnm ::= nm DOT nm */
166248 293, /* (271) tridxby ::= INDEXED BY nm */
166249 293, /* (272) tridxby ::= NOT INDEXED */
166250 291, /* (273) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
166251 291, /* (274) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
166252 291, /* (275) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
166253 291, /* (276) trigger_cmd ::= scanpt select scanpt */
166254 217, /* (277) expr ::= RAISE LP IGNORE RP */
166255 217, /* (278) expr ::= RAISE LP raisetype COMMA nm RP */
166256 236, /* (279) raisetype ::= ROLLBACK */
166257 236, /* (280) raisetype ::= ABORT */
166258 236, /* (281) raisetype ::= FAIL */
166259 190, /* (282) cmd ::= DROP TRIGGER ifexists fullname */
166260 190, /* (283) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
166261 190, /* (284) cmd ::= DETACH database_kw_opt expr */
166262 295, /* (285) key_opt ::= */
166263 295, /* (286) key_opt ::= KEY expr */
166264 190, /* (287) cmd ::= REINDEX */
166265 190, /* (288) cmd ::= REINDEX nm dbnm */
166266 190, /* (289) cmd ::= ANALYZE */
166267 190, /* (290) cmd ::= ANALYZE nm dbnm */
166268 190, /* (291) cmd ::= ALTER TABLE fullname RENAME TO nm */
166269 190, /* (292) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
166270 190, /* (293) cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
166271 296, /* (294) add_column_fullname ::= fullname */
166272 190, /* (295) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
166273 190, /* (296) cmd ::= create_vtab */
166274 190, /* (297) cmd ::= create_vtab LP vtabarglist RP */
166275 298, /* (298) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
166276 300, /* (299) vtabarg ::= */
166277 301, /* (300) vtabargtoken ::= ANY */
166278 301, /* (301) vtabargtoken ::= lp anylist RP */
166279 302, /* (302) lp ::= LP */
166280 266, /* (303) with ::= WITH wqlist */
166281 266, /* (304) with ::= WITH RECURSIVE wqlist */
166282 305, /* (305) wqas ::= AS */
166283 305, /* (306) wqas ::= AS MATERIALIZED */
166284 305, /* (307) wqas ::= AS NOT MATERIALIZED */
166285 304, /* (308) wqitem ::= nm eidlist_opt wqas LP select RP */
166286 241, /* (309) wqlist ::= wqitem */
166287 241, /* (310) wqlist ::= wqlist COMMA wqitem */
166288 306, /* (311) windowdefn_list ::= windowdefn */
166289 306, /* (312) windowdefn_list ::= windowdefn_list COMMA windowdefn */
166290 307, /* (313) windowdefn ::= nm AS LP window RP */
166291 308, /* (314) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
166292 308, /* (315) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
166293 308, /* (316) window ::= ORDER BY sortlist frame_opt */
166294 308, /* (317) window ::= nm ORDER BY sortlist frame_opt */
166295 308, /* (318) window ::= frame_opt */
166296 308, /* (319) window ::= nm frame_opt */
166297 309, /* (320) frame_opt ::= */
166298 309, /* (321) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
166299 309, /* (322) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
166300 313, /* (323) range_or_rows ::= RANGE|ROWS|GROUPS */
166301 315, /* (324) frame_bound_s ::= frame_bound */
166302 315, /* (325) frame_bound_s ::= UNBOUNDED PRECEDING */
166303 316, /* (326) frame_bound_e ::= frame_bound */
166304 316, /* (327) frame_bound_e ::= UNBOUNDED FOLLOWING */
166305 314, /* (328) frame_bound ::= expr PRECEDING|FOLLOWING */
166306 314, /* (329) frame_bound ::= CURRENT ROW */
166307 317, /* (330) frame_exclude_opt ::= */
166308 317, /* (331) frame_exclude_opt ::= EXCLUDE frame_exclude */
166309 318, /* (332) frame_exclude ::= NO OTHERS */
166310 318, /* (333) frame_exclude ::= CURRENT ROW */
166311 318, /* (334) frame_exclude ::= GROUP|TIES */
166312 251, /* (335) window_clause ::= WINDOW windowdefn_list */
166313 273, /* (336) filter_over ::= filter_clause over_clause */
166314 273, /* (337) filter_over ::= over_clause */
166315 273, /* (338) filter_over ::= filter_clause */
166316 312, /* (339) over_clause ::= OVER LP window RP */
166317 312, /* (340) over_clause ::= OVER nm */
166318 311, /* (341) filter_clause ::= FILTER LP WHERE expr RP */
166319 185, /* (342) input ::= cmdlist */
166320 186, /* (343) cmdlist ::= cmdlist ecmd */
166321 186, /* (344) cmdlist ::= ecmd */
166322 187, /* (345) ecmd ::= SEMI */
166323 187, /* (346) ecmd ::= cmdx SEMI */
166324 187, /* (347) ecmd ::= explain cmdx SEMI */
166325 192, /* (348) trans_opt ::= */
166326 192, /* (349) trans_opt ::= TRANSACTION */
166327 192, /* (350) trans_opt ::= TRANSACTION nm */
166328 194, /* (351) savepoint_opt ::= SAVEPOINT */
166329 194, /* (352) savepoint_opt ::= */
166330 190, /* (353) cmd ::= create_table create_table_args */
166331 203, /* (354) table_option_set ::= table_option */
166332 201, /* (355) columnlist ::= columnlist COMMA columnname carglist */
166333 201, /* (356) columnlist ::= columnname carglist */
166334 193, /* (357) nm ::= ID|INDEXED */
166335 193, /* (358) nm ::= STRING */
166336 193, /* (359) nm ::= JOIN_KW */
166337 208, /* (360) typetoken ::= typename */
166338 209, /* (361) typename ::= ID|STRING */
166339 210, /* (362) signed ::= plus_num */
166340 210, /* (363) signed ::= minus_num */
166341 207, /* (364) carglist ::= carglist ccons */
166342 207, /* (365) carglist ::= */
166343 215, /* (366) ccons ::= NULL onconf */
166344 215, /* (367) ccons ::= GENERATED ALWAYS AS generated */
166345 215, /* (368) ccons ::= AS generated */
166346 202, /* (369) conslist_opt ::= COMMA conslist */
166347 228, /* (370) conslist ::= conslist tconscomma tcons */
166348 228, /* (371) conslist ::= tcons */
166349 229, /* (372) tconscomma ::= */
166350 233, /* (373) defer_subclause_opt ::= defer_subclause */
166351 235, /* (374) resolvetype ::= raisetype */
166352 239, /* (375) selectnowith ::= oneselect */
166353 240, /* (376) oneselect ::= values */
166354 254, /* (377) sclp ::= selcollist COMMA */
166355 255, /* (378) as ::= ID|STRING */
166356 264, /* (379) indexed_opt ::= indexed_by */
166357 272, /* (380) returning ::= */
166358 217, /* (381) expr ::= term */
166359 274, /* (382) likeop ::= LIKE_KW|MATCH */
166360 261, /* (383) exprlist ::= nexprlist */
166361 284, /* (384) nmnum ::= plus_num */
166362 284, /* (385) nmnum ::= nm */
166363 284, /* (386) nmnum ::= ON */
166364 284, /* (387) nmnum ::= DELETE */
166365 284, /* (388) nmnum ::= DEFAULT */
166366 211, /* (389) plus_num ::= INTEGER|FLOAT */
166367 289, /* (390) foreach_clause ::= */
166368 289, /* (391) foreach_clause ::= FOR EACH ROW */
166369 292, /* (392) trnm ::= nm */
166370 293, /* (393) tridxby ::= */
166371 294, /* (394) database_kw_opt ::= DATABASE */
166372 294, /* (395) database_kw_opt ::= */
166373 297, /* (396) kwcolumn_opt ::= */
166374 297, /* (397) kwcolumn_opt ::= COLUMNKW */
166375 299, /* (398) vtabarglist ::= vtabarg */
166376 299, /* (399) vtabarglist ::= vtabarglist COMMA vtabarg */
166377 300, /* (400) vtabarg ::= vtabarg vtabargtoken */
166378 303, /* (401) anylist ::= */
166379 303, /* (402) anylist ::= anylist LP anylist RP */
166380 303, /* (403) anylist ::= anylist ANY */
166381 266, /* (404) with ::= */
166382 };
166383
166384 /* For rule J, yyRuleInfoNRhs[J] contains the negative of the number
166385 ** of symbols on the right-hand side of that rule. */
166386 static const signed char yyRuleInfoNRhs[] = {
@@ -166172,204 +166591,206 @@
166591 -5, /* (204) expr ::= expr likeop expr ESCAPE expr */
166592 -2, /* (205) expr ::= expr ISNULL|NOTNULL */
166593 -3, /* (206) expr ::= expr NOT NULL */
166594 -3, /* (207) expr ::= expr IS expr */
166595 -4, /* (208) expr ::= expr IS NOT expr */
166596 -6, /* (209) expr ::= expr IS NOT DISTINCT FROM expr */
166597 -5, /* (210) expr ::= expr IS DISTINCT FROM expr */
166598 -2, /* (211) expr ::= NOT expr */
166599 -2, /* (212) expr ::= BITNOT expr */
166600 -2, /* (213) expr ::= PLUS|MINUS expr */
166601 -3, /* (214) expr ::= expr PTR expr */
166602 -1, /* (215) between_op ::= BETWEEN */
166603 -2, /* (216) between_op ::= NOT BETWEEN */
166604 -5, /* (217) expr ::= expr between_op expr AND expr */
166605 -1, /* (218) in_op ::= IN */
166606 -2, /* (219) in_op ::= NOT IN */
166607 -5, /* (220) expr ::= expr in_op LP exprlist RP */
166608 -3, /* (221) expr ::= LP select RP */
166609 -5, /* (222) expr ::= expr in_op LP select RP */
166610 -5, /* (223) expr ::= expr in_op nm dbnm paren_exprlist */
166611 -4, /* (224) expr ::= EXISTS LP select RP */
166612 -5, /* (225) expr ::= CASE case_operand case_exprlist case_else END */
166613 -5, /* (226) case_exprlist ::= case_exprlist WHEN expr THEN expr */
166614 -4, /* (227) case_exprlist ::= WHEN expr THEN expr */
166615 -2, /* (228) case_else ::= ELSE expr */
166616 0, /* (229) case_else ::= */
166617 -1, /* (230) case_operand ::= expr */
166618 0, /* (231) case_operand ::= */
166619 0, /* (232) exprlist ::= */
166620 -3, /* (233) nexprlist ::= nexprlist COMMA expr */
166621 -1, /* (234) nexprlist ::= expr */
166622 0, /* (235) paren_exprlist ::= */
166623 -3, /* (236) paren_exprlist ::= LP exprlist RP */
166624 -12, /* (237) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
166625 -1, /* (238) uniqueflag ::= UNIQUE */
166626 0, /* (239) uniqueflag ::= */
166627 0, /* (240) eidlist_opt ::= */
166628 -3, /* (241) eidlist_opt ::= LP eidlist RP */
166629 -5, /* (242) eidlist ::= eidlist COMMA nm collate sortorder */
166630 -3, /* (243) eidlist ::= nm collate sortorder */
166631 0, /* (244) collate ::= */
166632 -2, /* (245) collate ::= COLLATE ID|STRING */
166633 -4, /* (246) cmd ::= DROP INDEX ifexists fullname */
166634 -2, /* (247) cmd ::= VACUUM vinto */
166635 -3, /* (248) cmd ::= VACUUM nm vinto */
166636 -2, /* (249) vinto ::= INTO expr */
166637 0, /* (250) vinto ::= */
166638 -3, /* (251) cmd ::= PRAGMA nm dbnm */
166639 -5, /* (252) cmd ::= PRAGMA nm dbnm EQ nmnum */
166640 -6, /* (253) cmd ::= PRAGMA nm dbnm LP nmnum RP */
166641 -5, /* (254) cmd ::= PRAGMA nm dbnm EQ minus_num */
166642 -6, /* (255) cmd ::= PRAGMA nm dbnm LP minus_num RP */
166643 -2, /* (256) plus_num ::= PLUS INTEGER|FLOAT */
166644 -2, /* (257) minus_num ::= MINUS INTEGER|FLOAT */
166645 -5, /* (258) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
166646 -11, /* (259) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
166647 -1, /* (260) trigger_time ::= BEFORE|AFTER */
166648 -2, /* (261) trigger_time ::= INSTEAD OF */
166649 0, /* (262) trigger_time ::= */
166650 -1, /* (263) trigger_event ::= DELETE|INSERT */
166651 -1, /* (264) trigger_event ::= UPDATE */
166652 -3, /* (265) trigger_event ::= UPDATE OF idlist */
166653 0, /* (266) when_clause ::= */
166654 -2, /* (267) when_clause ::= WHEN expr */
166655 -3, /* (268) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
166656 -2, /* (269) trigger_cmd_list ::= trigger_cmd SEMI */
166657 -3, /* (270) trnm ::= nm DOT nm */
166658 -3, /* (271) tridxby ::= INDEXED BY nm */
166659 -2, /* (272) tridxby ::= NOT INDEXED */
166660 -9, /* (273) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
166661 -8, /* (274) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
166662 -6, /* (275) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
166663 -3, /* (276) trigger_cmd ::= scanpt select scanpt */
166664 -4, /* (277) expr ::= RAISE LP IGNORE RP */
166665 -6, /* (278) expr ::= RAISE LP raisetype COMMA nm RP */
166666 -1, /* (279) raisetype ::= ROLLBACK */
166667 -1, /* (280) raisetype ::= ABORT */
166668 -1, /* (281) raisetype ::= FAIL */
166669 -4, /* (282) cmd ::= DROP TRIGGER ifexists fullname */
166670 -6, /* (283) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
166671 -3, /* (284) cmd ::= DETACH database_kw_opt expr */
166672 0, /* (285) key_opt ::= */
166673 -2, /* (286) key_opt ::= KEY expr */
166674 -1, /* (287) cmd ::= REINDEX */
166675 -3, /* (288) cmd ::= REINDEX nm dbnm */
166676 -1, /* (289) cmd ::= ANALYZE */
166677 -3, /* (290) cmd ::= ANALYZE nm dbnm */
166678 -6, /* (291) cmd ::= ALTER TABLE fullname RENAME TO nm */
166679 -7, /* (292) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
166680 -6, /* (293) cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
166681 -1, /* (294) add_column_fullname ::= fullname */
166682 -8, /* (295) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
166683 -1, /* (296) cmd ::= create_vtab */
166684 -4, /* (297) cmd ::= create_vtab LP vtabarglist RP */
166685 -8, /* (298) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
166686 0, /* (299) vtabarg ::= */
166687 -1, /* (300) vtabargtoken ::= ANY */
166688 -3, /* (301) vtabargtoken ::= lp anylist RP */
166689 -1, /* (302) lp ::= LP */
166690 -2, /* (303) with ::= WITH wqlist */
166691 -3, /* (304) with ::= WITH RECURSIVE wqlist */
166692 -1, /* (305) wqas ::= AS */
166693 -2, /* (306) wqas ::= AS MATERIALIZED */
166694 -3, /* (307) wqas ::= AS NOT MATERIALIZED */
166695 -6, /* (308) wqitem ::= nm eidlist_opt wqas LP select RP */
166696 -1, /* (309) wqlist ::= wqitem */
166697 -3, /* (310) wqlist ::= wqlist COMMA wqitem */
166698 -1, /* (311) windowdefn_list ::= windowdefn */
166699 -3, /* (312) windowdefn_list ::= windowdefn_list COMMA windowdefn */
166700 -5, /* (313) windowdefn ::= nm AS LP window RP */
166701 -5, /* (314) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
166702 -6, /* (315) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
166703 -4, /* (316) window ::= ORDER BY sortlist frame_opt */
166704 -5, /* (317) window ::= nm ORDER BY sortlist frame_opt */
166705 -1, /* (318) window ::= frame_opt */
166706 -2, /* (319) window ::= nm frame_opt */
166707 0, /* (320) frame_opt ::= */
166708 -3, /* (321) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
166709 -6, /* (322) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
166710 -1, /* (323) range_or_rows ::= RANGE|ROWS|GROUPS */
166711 -1, /* (324) frame_bound_s ::= frame_bound */
166712 -2, /* (325) frame_bound_s ::= UNBOUNDED PRECEDING */
166713 -1, /* (326) frame_bound_e ::= frame_bound */
166714 -2, /* (327) frame_bound_e ::= UNBOUNDED FOLLOWING */
166715 -2, /* (328) frame_bound ::= expr PRECEDING|FOLLOWING */
166716 -2, /* (329) frame_bound ::= CURRENT ROW */
166717 0, /* (330) frame_exclude_opt ::= */
166718 -2, /* (331) frame_exclude_opt ::= EXCLUDE frame_exclude */
166719 -2, /* (332) frame_exclude ::= NO OTHERS */
166720 -2, /* (333) frame_exclude ::= CURRENT ROW */
166721 -1, /* (334) frame_exclude ::= GROUP|TIES */
166722 -2, /* (335) window_clause ::= WINDOW windowdefn_list */
166723 -2, /* (336) filter_over ::= filter_clause over_clause */
166724 -1, /* (337) filter_over ::= over_clause */
166725 -1, /* (338) filter_over ::= filter_clause */
166726 -4, /* (339) over_clause ::= OVER LP window RP */
166727 -2, /* (340) over_clause ::= OVER nm */
166728 -5, /* (341) filter_clause ::= FILTER LP WHERE expr RP */
166729 -1, /* (342) input ::= cmdlist */
166730 -2, /* (343) cmdlist ::= cmdlist ecmd */
166731 -1, /* (344) cmdlist ::= ecmd */
166732 -1, /* (345) ecmd ::= SEMI */
166733 -2, /* (346) ecmd ::= cmdx SEMI */
166734 -3, /* (347) ecmd ::= explain cmdx SEMI */
166735 0, /* (348) trans_opt ::= */
166736 -1, /* (349) trans_opt ::= TRANSACTION */
166737 -2, /* (350) trans_opt ::= TRANSACTION nm */
166738 -1, /* (351) savepoint_opt ::= SAVEPOINT */
166739 0, /* (352) savepoint_opt ::= */
166740 -2, /* (353) cmd ::= create_table create_table_args */
166741 -1, /* (354) table_option_set ::= table_option */
166742 -4, /* (355) columnlist ::= columnlist COMMA columnname carglist */
166743 -2, /* (356) columnlist ::= columnname carglist */
166744 -1, /* (357) nm ::= ID|INDEXED */
166745 -1, /* (358) nm ::= STRING */
166746 -1, /* (359) nm ::= JOIN_KW */
166747 -1, /* (360) typetoken ::= typename */
166748 -1, /* (361) typename ::= ID|STRING */
166749 -1, /* (362) signed ::= plus_num */
166750 -1, /* (363) signed ::= minus_num */
166751 -2, /* (364) carglist ::= carglist ccons */
166752 0, /* (365) carglist ::= */
166753 -2, /* (366) ccons ::= NULL onconf */
166754 -4, /* (367) ccons ::= GENERATED ALWAYS AS generated */
166755 -2, /* (368) ccons ::= AS generated */
166756 -2, /* (369) conslist_opt ::= COMMA conslist */
166757 -3, /* (370) conslist ::= conslist tconscomma tcons */
166758 -1, /* (371) conslist ::= tcons */
166759 0, /* (372) tconscomma ::= */
166760 -1, /* (373) defer_subclause_opt ::= defer_subclause */
166761 -1, /* (374) resolvetype ::= raisetype */
166762 -1, /* (375) selectnowith ::= oneselect */
166763 -1, /* (376) oneselect ::= values */
166764 -2, /* (377) sclp ::= selcollist COMMA */
166765 -1, /* (378) as ::= ID|STRING */
166766 -1, /* (379) indexed_opt ::= indexed_by */
166767 0, /* (380) returning ::= */
166768 -1, /* (381) expr ::= term */
166769 -1, /* (382) likeop ::= LIKE_KW|MATCH */
166770 -1, /* (383) exprlist ::= nexprlist */
166771 -1, /* (384) nmnum ::= plus_num */
166772 -1, /* (385) nmnum ::= nm */
166773 -1, /* (386) nmnum ::= ON */
166774 -1, /* (387) nmnum ::= DELETE */
166775 -1, /* (388) nmnum ::= DEFAULT */
166776 -1, /* (389) plus_num ::= INTEGER|FLOAT */
166777 0, /* (390) foreach_clause ::= */
166778 -3, /* (391) foreach_clause ::= FOR EACH ROW */
166779 -1, /* (392) trnm ::= nm */
166780 0, /* (393) tridxby ::= */
166781 -1, /* (394) database_kw_opt ::= DATABASE */
166782 0, /* (395) database_kw_opt ::= */
166783 0, /* (396) kwcolumn_opt ::= */
166784 -1, /* (397) kwcolumn_opt ::= COLUMNKW */
166785 -1, /* (398) vtabarglist ::= vtabarg */
166786 -3, /* (399) vtabarglist ::= vtabarglist COMMA vtabarg */
166787 -2, /* (400) vtabarg ::= vtabarg vtabargtoken */
166788 0, /* (401) anylist ::= */
166789 -4, /* (402) anylist ::= anylist LP anylist RP */
166790 -2, /* (403) anylist ::= anylist ANY */
166791 0, /* (404) with ::= */
166792 };
166793
166794 static void yy_accept(yyParser*); /* Forward Declaration */
166795
166796 /*
@@ -166425,11 +166846,11 @@
166846 {yymsp[1].minor.yy394 = TK_DEFERRED;}
166847 break;
166848 case 5: /* transtype ::= DEFERRED */
166849 case 6: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==6);
166850 case 7: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==7);
166851 case 323: /* range_or_rows ::= RANGE|ROWS|GROUPS */ yytestcase(yyruleno==323);
166852 {yymsp[0].minor.yy394 = yymsp[0].major; /*A-overwrites-X*/}
166853 break;
166854 case 8: /* cmd ::= COMMIT|END trans_opt */
166855 case 9: /* cmd ::= ROLLBACK trans_opt */ yytestcase(yyruleno==9);
166856 {sqlite3EndTransaction(pParse,yymsp[-1].major);}
@@ -166462,11 +166883,11 @@
166883 case 47: /* autoinc ::= */ yytestcase(yyruleno==47);
166884 case 62: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==62);
166885 case 72: /* defer_subclause_opt ::= */ yytestcase(yyruleno==72);
166886 case 81: /* ifexists ::= */ yytestcase(yyruleno==81);
166887 case 98: /* distinct ::= */ yytestcase(yyruleno==98);
166888 case 244: /* collate ::= */ yytestcase(yyruleno==244);
166889 {yymsp[1].minor.yy394 = 0;}
166890 break;
166891 case 16: /* ifnotexists ::= IF NOT EXISTS */
166892 {yymsp[-2].minor.yy394 = 1;}
166893 break;
@@ -166646,13 +167067,13 @@
167067 case 171: /* insert_cmd ::= INSERT orconf */ yytestcase(yyruleno==171);
167068 {yymsp[-1].minor.yy394 = yymsp[0].minor.yy394;}
167069 break;
167070 case 63: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
167071 case 80: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==80);
167072 case 216: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==216);
167073 case 219: /* in_op ::= NOT IN */ yytestcase(yyruleno==219);
167074 case 245: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==245);
167075 {yymsp[-1].minor.yy394 = 1;}
167076 break;
167077 case 64: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
167078 {yymsp[-1].minor.yy394 = 0;}
167079 break;
@@ -166798,13 +167219,13 @@
167219 {yymsp[0].minor.yy394 = SF_All;}
167220 break;
167221 case 99: /* sclp ::= */
167222 case 132: /* orderby_opt ::= */ yytestcase(yyruleno==132);
167223 case 142: /* groupby_opt ::= */ yytestcase(yyruleno==142);
167224 case 232: /* exprlist ::= */ yytestcase(yyruleno==232);
167225 case 235: /* paren_exprlist ::= */ yytestcase(yyruleno==235);
167226 case 240: /* eidlist_opt ::= */ yytestcase(yyruleno==240);
167227 {yymsp[1].minor.yy322 = 0;}
167228 break;
167229 case 100: /* selcollist ::= sclp scanpt expr scanpt as */
167230 {
167231 yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy322, yymsp[-2].minor.yy528);
@@ -166826,12 +167247,12 @@
167247 yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, pDot);
167248 }
167249 break;
167250 case 103: /* as ::= AS nm */
167251 case 115: /* dbnm ::= DOT nm */ yytestcase(yyruleno==115);
167252 case 256: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==256);
167253 case 257: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==257);
167254 {yymsp[-1].minor.yy0 = yymsp[0].minor.yy0;}
167255 break;
167256 case 105: /* from ::= */
167257 case 108: /* stl_prefix ::= */ yytestcase(yyruleno==108);
167258 {yymsp[1].minor.yy131 = 0;}
@@ -166999,20 +167420,20 @@
167420 break;
167421 case 144: /* having_opt ::= */
167422 case 146: /* limit_opt ::= */ yytestcase(yyruleno==146);
167423 case 151: /* where_opt ::= */ yytestcase(yyruleno==151);
167424 case 153: /* where_opt_ret ::= */ yytestcase(yyruleno==153);
167425 case 229: /* case_else ::= */ yytestcase(yyruleno==229);
167426 case 231: /* case_operand ::= */ yytestcase(yyruleno==231);
167427 case 250: /* vinto ::= */ yytestcase(yyruleno==250);
167428 {yymsp[1].minor.yy528 = 0;}
167429 break;
167430 case 145: /* having_opt ::= HAVING expr */
167431 case 152: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==152);
167432 case 154: /* where_opt_ret ::= WHERE expr */ yytestcase(yyruleno==154);
167433 case 228: /* case_else ::= ELSE expr */ yytestcase(yyruleno==228);
167434 case 249: /* vinto ::= INTO expr */ yytestcase(yyruleno==249);
167435 {yymsp[-1].minor.yy528 = yymsp[0].minor.yy528;}
167436 break;
167437 case 147: /* limit_opt ::= LIMIT expr */
167438 {yymsp[-1].minor.yy528 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy528,0);}
167439 break;
@@ -167036,11 +167457,22 @@
167457 break;
167458 case 157: /* cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist from where_opt_ret */
167459 {
167460 sqlite3SrcListIndexedBy(pParse, yymsp[-5].minor.yy131, &yymsp[-4].minor.yy0);
167461 sqlite3ExprListCheckLength(pParse,yymsp[-2].minor.yy322,"set list");
167462 if( yymsp[-1].minor.yy131 ){
167463 SrcList *pFromClause = yymsp[-1].minor.yy131;
167464 if( pFromClause->nSrc>1 ){
167465 Select *pSubquery;
167466 Token as;
167467 pSubquery = sqlite3SelectNew(pParse,0,pFromClause,0,0,0,0,SF_NestedFrom,0);
167468 as.n = 0;
167469 as.z = 0;
167470 pFromClause = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&as,pSubquery,0);
167471 }
167472 yymsp[-5].minor.yy131 = sqlite3SrcListAppendList(pParse, yymsp[-5].minor.yy131, pFromClause);
167473 }
167474 sqlite3Update(pParse,yymsp[-5].minor.yy131,yymsp[-2].minor.yy322,yymsp[0].minor.yy528,yymsp[-6].minor.yy394,0,0,0);
167475 }
167476 break;
167477 case 158: /* setlist ::= setlist COMMA nm EQ expr */
167478 {
@@ -167282,33 +167714,45 @@
167714 {
167715 yymsp[-3].minor.yy528 = sqlite3PExpr(pParse,TK_ISNOT,yymsp[-3].minor.yy528,yymsp[0].minor.yy528);
167716 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy528, yymsp[-3].minor.yy528, TK_NOTNULL);
167717 }
167718 break;
167719 case 209: /* expr ::= expr IS NOT DISTINCT FROM expr */
167720 {
167721 yymsp[-5].minor.yy528 = sqlite3PExpr(pParse,TK_IS,yymsp[-5].minor.yy528,yymsp[0].minor.yy528);
167722 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy528, yymsp[-5].minor.yy528, TK_ISNULL);
167723 }
167724 break;
167725 case 210: /* expr ::= expr IS DISTINCT FROM expr */
167726 {
167727 yymsp[-4].minor.yy528 = sqlite3PExpr(pParse,TK_ISNOT,yymsp[-4].minor.yy528,yymsp[0].minor.yy528);
167728 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy528, yymsp[-4].minor.yy528, TK_NOTNULL);
167729 }
167730 break;
167731 case 211: /* expr ::= NOT expr */
167732 case 212: /* expr ::= BITNOT expr */ yytestcase(yyruleno==212);
167733 {yymsp[-1].minor.yy528 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy528, 0);/*A-overwrites-B*/}
167734 break;
167735 case 213: /* expr ::= PLUS|MINUS expr */
167736 {
167737 yymsp[-1].minor.yy528 = sqlite3PExpr(pParse, yymsp[-1].major==TK_PLUS ? TK_UPLUS : TK_UMINUS, yymsp[0].minor.yy528, 0);
167738 /*A-overwrites-B*/
167739 }
167740 break;
167741 case 214: /* expr ::= expr PTR expr */
167742 {
167743 ExprList *pList = sqlite3ExprListAppend(pParse, 0, yymsp[-2].minor.yy528);
167744 pList = sqlite3ExprListAppend(pParse, pList, yymsp[0].minor.yy528);
167745 yylhsminor.yy528 = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy0, 0);
167746 }
167747 yymsp[-2].minor.yy528 = yylhsminor.yy528;
167748 break;
167749 case 215: /* between_op ::= BETWEEN */
167750 case 218: /* in_op ::= IN */ yytestcase(yyruleno==218);
167751 {yymsp[0].minor.yy394 = 0;}
167752 break;
167753 case 217: /* expr ::= expr between_op expr AND expr */
167754 {
167755 ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy528);
167756 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy528);
167757 yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy528, 0);
167758 if( yymsp[-4].minor.yy528 ){
@@ -167317,11 +167761,11 @@
167761 sqlite3ExprListDelete(pParse->db, pList);
167762 }
167763 if( yymsp[-3].minor.yy394 ) yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy528, 0);
167764 }
167765 break;
167766 case 220: /* expr ::= expr in_op LP exprlist RP */
167767 {
167768 if( yymsp[-1].minor.yy322==0 ){
167769 /* Expressions of the form
167770 **
167771 ** expr1 IN ()
@@ -167329,11 +167773,12 @@
167773 **
167774 ** simplify to constants 0 (false) and 1 (true), respectively,
167775 ** regardless of the value of expr1.
167776 */
167777 sqlite3ExprUnmapAndDelete(pParse, yymsp[-4].minor.yy528);
167778 yymsp[-4].minor.yy528 = sqlite3Expr(pParse->db, TK_STRING, yymsp[-3].minor.yy394 ? "true" : "false");
167779 if( yymsp[-4].minor.yy528 ) sqlite3ExprIdToTrueFalse(yymsp[-4].minor.yy528);
167780 }else{
167781 Expr *pRHS = yymsp[-1].minor.yy322->a[0].pExpr;
167782 if( yymsp[-1].minor.yy322->nExpr==1 && sqlite3ExprIsConstant(pRHS) && yymsp[-4].minor.yy528->op!=TK_VECTOR ){
167783 yymsp[-1].minor.yy322->a[0].pExpr = 0;
167784 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy322);
@@ -167357,41 +167802,41 @@
167802 }
167803 if( yymsp[-3].minor.yy394 ) yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy528, 0);
167804 }
167805 }
167806 break;
167807 case 221: /* expr ::= LP select RP */
167808 {
167809 yymsp[-2].minor.yy528 = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
167810 sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy528, yymsp[-1].minor.yy47);
167811 }
167812 break;
167813 case 222: /* expr ::= expr in_op LP select RP */
167814 {
167815 yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy528, 0);
167816 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy528, yymsp[-1].minor.yy47);
167817 if( yymsp[-3].minor.yy394 ) yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy528, 0);
167818 }
167819 break;
167820 case 223: /* expr ::= expr in_op nm dbnm paren_exprlist */
167821 {
167822 SrcList *pSrc = sqlite3SrcListAppend(pParse, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);
167823 Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0);
167824 if( yymsp[0].minor.yy322 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy322);
167825 yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy528, 0);
167826 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy528, pSelect);
167827 if( yymsp[-3].minor.yy394 ) yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy528, 0);
167828 }
167829 break;
167830 case 224: /* expr ::= EXISTS LP select RP */
167831 {
167832 Expr *p;
167833 p = yymsp[-3].minor.yy528 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
167834 sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy47);
167835 }
167836 break;
167837 case 225: /* expr ::= CASE case_operand case_exprlist case_else END */
167838 {
167839 yymsp[-4].minor.yy528 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy528, 0);
167840 if( yymsp[-4].minor.yy528 ){
167841 yymsp[-4].minor.yy528->x.pList = yymsp[-1].minor.yy528 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[-1].minor.yy528) : yymsp[-2].minor.yy322;
167842 sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy528);
@@ -167399,406 +167844,406 @@
167844 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy322);
167845 sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy528);
167846 }
167847 }
167848 break;
167849 case 226: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
167850 {
167851 yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, yymsp[-2].minor.yy528);
167852 yymsp[-4].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy322, yymsp[0].minor.yy528);
167853 }
167854 break;
167855 case 227: /* case_exprlist ::= WHEN expr THEN expr */
167856 {
167857 yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy528);
167858 yymsp[-3].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy322, yymsp[0].minor.yy528);
167859 }
167860 break;
167861 case 230: /* case_operand ::= expr */
167862 {yymsp[0].minor.yy528 = yymsp[0].minor.yy528; /*A-overwrites-X*/}
167863 break;
167864 case 233: /* nexprlist ::= nexprlist COMMA expr */
167865 {yymsp[-2].minor.yy322 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy322,yymsp[0].minor.yy528);}
167866 break;
167867 case 234: /* nexprlist ::= expr */
167868 {yymsp[0].minor.yy322 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy528); /*A-overwrites-Y*/}
167869 break;
167870 case 236: /* paren_exprlist ::= LP exprlist RP */
167871 case 241: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==241);
167872 {yymsp[-2].minor.yy322 = yymsp[-1].minor.yy322;}
167873 break;
167874 case 237: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
167875 {
167876 sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0,
167877 sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy322, yymsp[-10].minor.yy394,
167878 &yymsp[-11].minor.yy0, yymsp[0].minor.yy528, SQLITE_SO_ASC, yymsp[-8].minor.yy394, SQLITE_IDXTYPE_APPDEF);
167879 if( IN_RENAME_OBJECT && pParse->pNewIndex ){
167880 sqlite3RenameTokenMap(pParse, pParse->pNewIndex->zName, &yymsp[-4].minor.yy0);
167881 }
167882 }
167883 break;
167884 case 238: /* uniqueflag ::= UNIQUE */
167885 case 280: /* raisetype ::= ABORT */ yytestcase(yyruleno==280);
167886 {yymsp[0].minor.yy394 = OE_Abort;}
167887 break;
167888 case 239: /* uniqueflag ::= */
167889 {yymsp[1].minor.yy394 = OE_None;}
167890 break;
167891 case 242: /* eidlist ::= eidlist COMMA nm collate sortorder */
167892 {
167893 yymsp[-4].minor.yy322 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy322, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy394, yymsp[0].minor.yy394);
167894 }
167895 break;
167896 case 243: /* eidlist ::= nm collate sortorder */
167897 {
167898 yymsp[-2].minor.yy322 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy394, yymsp[0].minor.yy394); /*A-overwrites-Y*/
167899 }
167900 break;
167901 case 246: /* cmd ::= DROP INDEX ifexists fullname */
167902 {sqlite3DropIndex(pParse, yymsp[0].minor.yy131, yymsp[-1].minor.yy394);}
167903 break;
167904 case 247: /* cmd ::= VACUUM vinto */
167905 {sqlite3Vacuum(pParse,0,yymsp[0].minor.yy528);}
167906 break;
167907 case 248: /* cmd ::= VACUUM nm vinto */
167908 {sqlite3Vacuum(pParse,&yymsp[-1].minor.yy0,yymsp[0].minor.yy528);}
167909 break;
167910 case 251: /* cmd ::= PRAGMA nm dbnm */
167911 {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
167912 break;
167913 case 252: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
167914 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0);}
167915 break;
167916 case 253: /* cmd ::= PRAGMA nm dbnm LP nmnum RP */
167917 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0);}
167918 break;
167919 case 254: /* cmd ::= PRAGMA nm dbnm EQ minus_num */
167920 {sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,1);}
167921 break;
167922 case 255: /* cmd ::= PRAGMA nm dbnm LP minus_num RP */
167923 {sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,1);}
167924 break;
167925 case 258: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
167926 {
167927 Token all;
167928 all.z = yymsp[-3].minor.yy0.z;
167929 all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
167930 sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy33, &all);
167931 }
167932 break;
167933 case 259: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
167934 {
167935 sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy394, yymsp[-4].minor.yy180.a, yymsp[-4].minor.yy180.b, yymsp[-2].minor.yy131, yymsp[0].minor.yy528, yymsp[-10].minor.yy394, yymsp[-8].minor.yy394);
167936 yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/
167937 }
167938 break;
167939 case 260: /* trigger_time ::= BEFORE|AFTER */
167940 { yymsp[0].minor.yy394 = yymsp[0].major; /*A-overwrites-X*/ }
167941 break;
167942 case 261: /* trigger_time ::= INSTEAD OF */
167943 { yymsp[-1].minor.yy394 = TK_INSTEAD;}
167944 break;
167945 case 262: /* trigger_time ::= */
167946 { yymsp[1].minor.yy394 = TK_BEFORE; }
167947 break;
167948 case 263: /* trigger_event ::= DELETE|INSERT */
167949 case 264: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==264);
167950 {yymsp[0].minor.yy180.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy180.b = 0;}
167951 break;
167952 case 265: /* trigger_event ::= UPDATE OF idlist */
167953 {yymsp[-2].minor.yy180.a = TK_UPDATE; yymsp[-2].minor.yy180.b = yymsp[0].minor.yy254;}
167954 break;
167955 case 266: /* when_clause ::= */
167956 case 285: /* key_opt ::= */ yytestcase(yyruleno==285);
167957 { yymsp[1].minor.yy528 = 0; }
167958 break;
167959 case 267: /* when_clause ::= WHEN expr */
167960 case 286: /* key_opt ::= KEY expr */ yytestcase(yyruleno==286);
167961 { yymsp[-1].minor.yy528 = yymsp[0].minor.yy528; }
167962 break;
167963 case 268: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
167964 {
167965 assert( yymsp[-2].minor.yy33!=0 );
167966 yymsp[-2].minor.yy33->pLast->pNext = yymsp[-1].minor.yy33;
167967 yymsp[-2].minor.yy33->pLast = yymsp[-1].minor.yy33;
167968 }
167969 break;
167970 case 269: /* trigger_cmd_list ::= trigger_cmd SEMI */
167971 {
167972 assert( yymsp[-1].minor.yy33!=0 );
167973 yymsp[-1].minor.yy33->pLast = yymsp[-1].minor.yy33;
167974 }
167975 break;
167976 case 270: /* trnm ::= nm DOT nm */
167977 {
167978 yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;
167979 sqlite3ErrorMsg(pParse,
167980 "qualified table names are not allowed on INSERT, UPDATE, and DELETE "
167981 "statements within triggers");
167982 }
167983 break;
167984 case 271: /* tridxby ::= INDEXED BY nm */
167985 {
167986 sqlite3ErrorMsg(pParse,
167987 "the INDEXED BY clause is not allowed on UPDATE or DELETE statements "
167988 "within triggers");
167989 }
167990 break;
167991 case 272: /* tridxby ::= NOT INDEXED */
167992 {
167993 sqlite3ErrorMsg(pParse,
167994 "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
167995 "within triggers");
167996 }
167997 break;
167998 case 273: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist from where_opt scanpt */
167999 {yylhsminor.yy33 = sqlite3TriggerUpdateStep(pParse, &yymsp[-6].minor.yy0, yymsp[-2].minor.yy131, yymsp[-3].minor.yy322, yymsp[-1].minor.yy528, yymsp[-7].minor.yy394, yymsp[-8].minor.yy0.z, yymsp[0].minor.yy522);}
168000 yymsp[-8].minor.yy33 = yylhsminor.yy33;
168001 break;
168002 case 274: /* trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
168003 {
168004 yylhsminor.yy33 = sqlite3TriggerInsertStep(pParse,&yymsp[-4].minor.yy0,yymsp[-3].minor.yy254,yymsp[-2].minor.yy47,yymsp[-6].minor.yy394,yymsp[-1].minor.yy444,yymsp[-7].minor.yy522,yymsp[0].minor.yy522);/*yylhsminor.yy33-overwrites-yymsp[-6].minor.yy394*/
168005 }
168006 yymsp[-7].minor.yy33 = yylhsminor.yy33;
168007 break;
168008 case 275: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
168009 {yylhsminor.yy33 = sqlite3TriggerDeleteStep(pParse, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy528, yymsp[-5].minor.yy0.z, yymsp[0].minor.yy522);}
168010 yymsp[-5].minor.yy33 = yylhsminor.yy33;
168011 break;
168012 case 276: /* trigger_cmd ::= scanpt select scanpt */
168013 {yylhsminor.yy33 = sqlite3TriggerSelectStep(pParse->db, yymsp[-1].minor.yy47, yymsp[-2].minor.yy522, yymsp[0].minor.yy522); /*yylhsminor.yy33-overwrites-yymsp[-1].minor.yy47*/}
168014 yymsp[-2].minor.yy33 = yylhsminor.yy33;
168015 break;
168016 case 277: /* expr ::= RAISE LP IGNORE RP */
168017 {
168018 yymsp[-3].minor.yy528 = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
168019 if( yymsp[-3].minor.yy528 ){
168020 yymsp[-3].minor.yy528->affExpr = OE_Ignore;
168021 }
168022 }
168023 break;
168024 case 278: /* expr ::= RAISE LP raisetype COMMA nm RP */
168025 {
168026 yymsp[-5].minor.yy528 = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1);
168027 if( yymsp[-5].minor.yy528 ) {
168028 yymsp[-5].minor.yy528->affExpr = (char)yymsp[-3].minor.yy394;
168029 }
168030 }
168031 break;
168032 case 279: /* raisetype ::= ROLLBACK */
168033 {yymsp[0].minor.yy394 = OE_Rollback;}
168034 break;
168035 case 281: /* raisetype ::= FAIL */
168036 {yymsp[0].minor.yy394 = OE_Fail;}
168037 break;
168038 case 282: /* cmd ::= DROP TRIGGER ifexists fullname */
168039 {
168040 sqlite3DropTrigger(pParse,yymsp[0].minor.yy131,yymsp[-1].minor.yy394);
168041 }
168042 break;
168043 case 283: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
168044 {
168045 sqlite3Attach(pParse, yymsp[-3].minor.yy528, yymsp[-1].minor.yy528, yymsp[0].minor.yy528);
168046 }
168047 break;
168048 case 284: /* cmd ::= DETACH database_kw_opt expr */
168049 {
168050 sqlite3Detach(pParse, yymsp[0].minor.yy528);
168051 }
168052 break;
168053 case 287: /* cmd ::= REINDEX */
168054 {sqlite3Reindex(pParse, 0, 0);}
168055 break;
168056 case 288: /* cmd ::= REINDEX nm dbnm */
168057 {sqlite3Reindex(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
168058 break;
168059 case 289: /* cmd ::= ANALYZE */
168060 {sqlite3Analyze(pParse, 0, 0);}
168061 break;
168062 case 290: /* cmd ::= ANALYZE nm dbnm */
168063 {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
168064 break;
168065 case 291: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
168066 {
168067 sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy131,&yymsp[0].minor.yy0);
168068 }
168069 break;
168070 case 292: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
168071 {
168072 yymsp[-1].minor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-1].minor.yy0.z) + pParse->sLastToken.n;
168073 sqlite3AlterFinishAddColumn(pParse, &yymsp[-1].minor.yy0);
168074 }
168075 break;
168076 case 293: /* cmd ::= ALTER TABLE fullname DROP kwcolumn_opt nm */
168077 {
168078 sqlite3AlterDropColumn(pParse, yymsp[-3].minor.yy131, &yymsp[0].minor.yy0);
168079 }
168080 break;
168081 case 294: /* add_column_fullname ::= fullname */
168082 {
168083 disableLookaside(pParse);
168084 sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy131);
168085 }
168086 break;
168087 case 295: /* cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
168088 {
168089 sqlite3AlterRenameColumn(pParse, yymsp[-5].minor.yy131, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);
168090 }
168091 break;
168092 case 296: /* cmd ::= create_vtab */
168093 {sqlite3VtabFinishParse(pParse,0);}
168094 break;
168095 case 297: /* cmd ::= create_vtab LP vtabarglist RP */
168096 {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
168097 break;
168098 case 298: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
168099 {
168100 sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy394);
168101 }
168102 break;
168103 case 299: /* vtabarg ::= */
168104 {sqlite3VtabArgInit(pParse);}
168105 break;
168106 case 300: /* vtabargtoken ::= ANY */
168107 case 301: /* vtabargtoken ::= lp anylist RP */ yytestcase(yyruleno==301);
168108 case 302: /* lp ::= LP */ yytestcase(yyruleno==302);
168109 {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
168110 break;
168111 case 303: /* with ::= WITH wqlist */
168112 case 304: /* with ::= WITH RECURSIVE wqlist */ yytestcase(yyruleno==304);
168113 { sqlite3WithPush(pParse, yymsp[0].minor.yy521, 1); }
168114 break;
168115 case 305: /* wqas ::= AS */
168116 {yymsp[0].minor.yy516 = M10d_Any;}
168117 break;
168118 case 306: /* wqas ::= AS MATERIALIZED */
168119 {yymsp[-1].minor.yy516 = M10d_Yes;}
168120 break;
168121 case 307: /* wqas ::= AS NOT MATERIALIZED */
168122 {yymsp[-2].minor.yy516 = M10d_No;}
168123 break;
168124 case 308: /* wqitem ::= nm eidlist_opt wqas LP select RP */
168125 {
168126 yymsp[-5].minor.yy385 = sqlite3CteNew(pParse, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy322, yymsp[-1].minor.yy47, yymsp[-3].minor.yy516); /*A-overwrites-X*/
168127 }
168128 break;
168129 case 309: /* wqlist ::= wqitem */
168130 {
168131 yymsp[0].minor.yy521 = sqlite3WithAdd(pParse, 0, yymsp[0].minor.yy385); /*A-overwrites-X*/
168132 }
168133 break;
168134 case 310: /* wqlist ::= wqlist COMMA wqitem */
168135 {
168136 yymsp[-2].minor.yy521 = sqlite3WithAdd(pParse, yymsp[-2].minor.yy521, yymsp[0].minor.yy385);
168137 }
168138 break;
168139 case 311: /* windowdefn_list ::= windowdefn */
168140 { yylhsminor.yy41 = yymsp[0].minor.yy41; }
168141 yymsp[0].minor.yy41 = yylhsminor.yy41;
168142 break;
168143 case 312: /* windowdefn_list ::= windowdefn_list COMMA windowdefn */
168144 {
168145 assert( yymsp[0].minor.yy41!=0 );
168146 sqlite3WindowChain(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy41);
168147 yymsp[0].minor.yy41->pNextWin = yymsp[-2].minor.yy41;
168148 yylhsminor.yy41 = yymsp[0].minor.yy41;
168149 }
168150 yymsp[-2].minor.yy41 = yylhsminor.yy41;
168151 break;
168152 case 313: /* windowdefn ::= nm AS LP window RP */
168153 {
168154 if( ALWAYS(yymsp[-1].minor.yy41) ){
168155 yymsp[-1].minor.yy41->zName = sqlite3DbStrNDup(pParse->db, yymsp[-4].minor.yy0.z, yymsp[-4].minor.yy0.n);
168156 }
168157 yylhsminor.yy41 = yymsp[-1].minor.yy41;
168158 }
168159 yymsp[-4].minor.yy41 = yylhsminor.yy41;
168160 break;
168161 case 314: /* window ::= PARTITION BY nexprlist orderby_opt frame_opt */
168162 {
168163 yymsp[-4].minor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy322, yymsp[-1].minor.yy322, 0);
168164 }
168165 break;
168166 case 315: /* window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
168167 {
168168 yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, yymsp[-2].minor.yy322, yymsp[-1].minor.yy322, &yymsp[-5].minor.yy0);
168169 }
168170 yymsp[-5].minor.yy41 = yylhsminor.yy41;
168171 break;
168172 case 316: /* window ::= ORDER BY sortlist frame_opt */
168173 {
168174 yymsp[-3].minor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, yymsp[-1].minor.yy322, 0);
168175 }
168176 break;
168177 case 317: /* window ::= nm ORDER BY sortlist frame_opt */
168178 {
168179 yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, yymsp[-1].minor.yy322, &yymsp[-4].minor.yy0);
168180 }
168181 yymsp[-4].minor.yy41 = yylhsminor.yy41;
168182 break;
168183 case 318: /* window ::= frame_opt */
168184 case 337: /* filter_over ::= over_clause */ yytestcase(yyruleno==337);
168185 {
168186 yylhsminor.yy41 = yymsp[0].minor.yy41;
168187 }
168188 yymsp[0].minor.yy41 = yylhsminor.yy41;
168189 break;
168190 case 319: /* window ::= nm frame_opt */
168191 {
168192 yylhsminor.yy41 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy41, 0, 0, &yymsp[-1].minor.yy0);
168193 }
168194 yymsp[-1].minor.yy41 = yylhsminor.yy41;
168195 break;
168196 case 320: /* frame_opt ::= */
168197 {
168198 yymsp[1].minor.yy41 = sqlite3WindowAlloc(pParse, 0, TK_UNBOUNDED, 0, TK_CURRENT, 0, 0);
168199 }
168200 break;
168201 case 321: /* frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
168202 {
168203 yylhsminor.yy41 = sqlite3WindowAlloc(pParse, yymsp[-2].minor.yy394, yymsp[-1].minor.yy595.eType, yymsp[-1].minor.yy595.pExpr, TK_CURRENT, 0, yymsp[0].minor.yy516);
168204 }
168205 yymsp[-2].minor.yy41 = yylhsminor.yy41;
168206 break;
168207 case 322: /* frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
168208 {
168209 yylhsminor.yy41 = sqlite3WindowAlloc(pParse, yymsp[-5].minor.yy394, yymsp[-3].minor.yy595.eType, yymsp[-3].minor.yy595.pExpr, yymsp[-1].minor.yy595.eType, yymsp[-1].minor.yy595.pExpr, yymsp[0].minor.yy516);
168210 }
168211 yymsp[-5].minor.yy41 = yylhsminor.yy41;
168212 break;
168213 case 324: /* frame_bound_s ::= frame_bound */
168214 case 326: /* frame_bound_e ::= frame_bound */ yytestcase(yyruleno==326);
168215 {yylhsminor.yy595 = yymsp[0].minor.yy595;}
168216 yymsp[0].minor.yy595 = yylhsminor.yy595;
168217 break;
168218 case 325: /* frame_bound_s ::= UNBOUNDED PRECEDING */
168219 case 327: /* frame_bound_e ::= UNBOUNDED FOLLOWING */ yytestcase(yyruleno==327);
168220 case 329: /* frame_bound ::= CURRENT ROW */ yytestcase(yyruleno==329);
168221 {yylhsminor.yy595.eType = yymsp[-1].major; yylhsminor.yy595.pExpr = 0;}
168222 yymsp[-1].minor.yy595 = yylhsminor.yy595;
168223 break;
168224 case 328: /* frame_bound ::= expr PRECEDING|FOLLOWING */
168225 {yylhsminor.yy595.eType = yymsp[0].major; yylhsminor.yy595.pExpr = yymsp[-1].minor.yy528;}
168226 yymsp[-1].minor.yy595 = yylhsminor.yy595;
168227 break;
168228 case 330: /* frame_exclude_opt ::= */
168229 {yymsp[1].minor.yy516 = 0;}
168230 break;
168231 case 331: /* frame_exclude_opt ::= EXCLUDE frame_exclude */
168232 {yymsp[-1].minor.yy516 = yymsp[0].minor.yy516;}
168233 break;
168234 case 332: /* frame_exclude ::= NO OTHERS */
168235 case 333: /* frame_exclude ::= CURRENT ROW */ yytestcase(yyruleno==333);
168236 {yymsp[-1].minor.yy516 = yymsp[-1].major; /*A-overwrites-X*/}
168237 break;
168238 case 334: /* frame_exclude ::= GROUP|TIES */
168239 {yymsp[0].minor.yy516 = yymsp[0].major; /*A-overwrites-X*/}
168240 break;
168241 case 335: /* window_clause ::= WINDOW windowdefn_list */
168242 { yymsp[-1].minor.yy41 = yymsp[0].minor.yy41; }
168243 break;
168244 case 336: /* filter_over ::= filter_clause over_clause */
168245 {
168246 if( yymsp[0].minor.yy41 ){
168247 yymsp[0].minor.yy41->pFilter = yymsp[-1].minor.yy528;
168248 }else{
168249 sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy528);
@@ -167805,11 +168250,11 @@
168250 }
168251 yylhsminor.yy41 = yymsp[0].minor.yy41;
168252 }
168253 yymsp[-1].minor.yy41 = yylhsminor.yy41;
168254 break;
168255 case 338: /* filter_over ::= filter_clause */
168256 {
168257 yylhsminor.yy41 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
168258 if( yylhsminor.yy41 ){
168259 yylhsminor.yy41->eFrmType = TK_FILTER;
168260 yylhsminor.yy41->pFilter = yymsp[0].minor.yy528;
@@ -167817,91 +168262,91 @@
168262 sqlite3ExprDelete(pParse->db, yymsp[0].minor.yy528);
168263 }
168264 }
168265 yymsp[0].minor.yy41 = yylhsminor.yy41;
168266 break;
168267 case 339: /* over_clause ::= OVER LP window RP */
168268 {
168269 yymsp[-3].minor.yy41 = yymsp[-1].minor.yy41;
168270 assert( yymsp[-3].minor.yy41!=0 );
168271 }
168272 break;
168273 case 340: /* over_clause ::= OVER nm */
168274 {
168275 yymsp[-1].minor.yy41 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
168276 if( yymsp[-1].minor.yy41 ){
168277 yymsp[-1].minor.yy41->zName = sqlite3DbStrNDup(pParse->db, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n);
168278 }
168279 }
168280 break;
168281 case 341: /* filter_clause ::= FILTER LP WHERE expr RP */
168282 { yymsp[-4].minor.yy528 = yymsp[-1].minor.yy528; }
168283 break;
168284 default:
168285 /* (342) input ::= cmdlist */ yytestcase(yyruleno==342);
168286 /* (343) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==343);
168287 /* (344) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=344);
168288 /* (345) ecmd ::= SEMI */ yytestcase(yyruleno==345);
168289 /* (346) ecmd ::= cmdx SEMI */ yytestcase(yyruleno==346);
168290 /* (347) ecmd ::= explain cmdx SEMI (NEVER REDUCES) */ assert(yyruleno!=347);
168291 /* (348) trans_opt ::= */ yytestcase(yyruleno==348);
168292 /* (349) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==349);
168293 /* (350) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==350);
168294 /* (351) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==351);
168295 /* (352) savepoint_opt ::= */ yytestcase(yyruleno==352);
168296 /* (353) cmd ::= create_table create_table_args */ yytestcase(yyruleno==353);
168297 /* (354) table_option_set ::= table_option (OPTIMIZED OUT) */ assert(yyruleno!=354);
168298 /* (355) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==355);
168299 /* (356) columnlist ::= columnname carglist */ yytestcase(yyruleno==356);
168300 /* (357) nm ::= ID|INDEXED */ yytestcase(yyruleno==357);
168301 /* (358) nm ::= STRING */ yytestcase(yyruleno==358);
168302 /* (359) nm ::= JOIN_KW */ yytestcase(yyruleno==359);
168303 /* (360) typetoken ::= typename */ yytestcase(yyruleno==360);
168304 /* (361) typename ::= ID|STRING */ yytestcase(yyruleno==361);
168305 /* (362) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=362);
168306 /* (363) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=363);
168307 /* (364) carglist ::= carglist ccons */ yytestcase(yyruleno==364);
168308 /* (365) carglist ::= */ yytestcase(yyruleno==365);
168309 /* (366) ccons ::= NULL onconf */ yytestcase(yyruleno==366);
168310 /* (367) ccons ::= GENERATED ALWAYS AS generated */ yytestcase(yyruleno==367);
168311 /* (368) ccons ::= AS generated */ yytestcase(yyruleno==368);
168312 /* (369) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==369);
168313 /* (370) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==370);
168314 /* (371) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=371);
168315 /* (372) tconscomma ::= */ yytestcase(yyruleno==372);
168316 /* (373) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=373);
168317 /* (374) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=374);
168318 /* (375) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=375);
168319 /* (376) oneselect ::= values */ yytestcase(yyruleno==376);
168320 /* (377) sclp ::= selcollist COMMA */ yytestcase(yyruleno==377);
168321 /* (378) as ::= ID|STRING */ yytestcase(yyruleno==378);
168322 /* (379) indexed_opt ::= indexed_by (OPTIMIZED OUT) */ assert(yyruleno!=379);
168323 /* (380) returning ::= */ yytestcase(yyruleno==380);
168324 /* (381) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=381);
168325 /* (382) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==382);
168326 /* (383) exprlist ::= nexprlist */ yytestcase(yyruleno==383);
168327 /* (384) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=384);
168328 /* (385) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=385);
168329 /* (386) nmnum ::= ON */ yytestcase(yyruleno==386);
168330 /* (387) nmnum ::= DELETE */ yytestcase(yyruleno==387);
168331 /* (388) nmnum ::= DEFAULT */ yytestcase(yyruleno==388);
168332 /* (389) plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==389);
168333 /* (390) foreach_clause ::= */ yytestcase(yyruleno==390);
168334 /* (391) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==391);
168335 /* (392) trnm ::= nm */ yytestcase(yyruleno==392);
168336 /* (393) tridxby ::= */ yytestcase(yyruleno==393);
168337 /* (394) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==394);
168338 /* (395) database_kw_opt ::= */ yytestcase(yyruleno==395);
168339 /* (396) kwcolumn_opt ::= */ yytestcase(yyruleno==396);
168340 /* (397) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==397);
168341 /* (398) vtabarglist ::= vtabarg */ yytestcase(yyruleno==398);
168342 /* (399) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==399);
168343 /* (400) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==400);
168344 /* (401) anylist ::= */ yytestcase(yyruleno==401);
168345 /* (402) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==402);
168346 /* (403) anylist ::= anylist ANY */ yytestcase(yyruleno==403);
168347 /* (404) with ::= */ yytestcase(yyruleno==404);
168348 break;
168349 /********** End reduce actions ************************************************/
168350 };
168351 assert( yyruleno<sizeof(yyRuleInfoLhs)/sizeof(yyRuleInfoLhs[0]) );
168352 yygoto = yyRuleInfoLhs[yyruleno];
@@ -174597,10 +175042,28 @@
175042 */
175043 SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){
175044 int iDb = zDbName ? sqlite3FindDbName(db, zDbName) : 0;
175045 return iDb<0 ? 0 : db->aDb[iDb].pBt;
175046 }
175047
175048 /*
175049 ** Return the name of the N-th database schema. Return NULL if N is out
175050 ** of range.
175051 */
175052 SQLITE_API const char *sqlite3_db_name(sqlite3 *db, int N){
175053 #ifdef SQLITE_ENABLE_API_ARMOR
175054 if( !sqlite3SafetyCheckOk(db) ){
175055 (void)SQLITE_MISUSE_BKPT;
175056 return 0;
175057 }
175058 #endif
175059 if( N<0 || N>=db->nDb ){
175060 return 0;
175061 }else{
175062 return db->aDb[N].zDbSName;
175063 }
175064 }
175065
175066 /*
175067 ** Return the filename of the database associated with a database
175068 ** connection.
175069 */
@@ -190236,10 +190699,12 @@
190699 if( rc==SQLITE_OK ){
190700 if( pNode->key.n ){
190701 pBlk->n += sqlite3Fts3PutVarint(&pBlk->a[pBlk->n], nPrefix);
190702 }
190703 pBlk->n += sqlite3Fts3PutVarint(&pBlk->a[pBlk->n], nSuffix);
190704 assert( nPrefix+nSuffix<=nTerm );
190705 assert( nPrefix>=0 );
190706 memcpy(&pBlk->a[pBlk->n], &zTerm[nPrefix], nSuffix);
190707 pBlk->n += nSuffix;
190708
190709 memcpy(pNode->key.a, zTerm, nTerm);
190710 pNode->key.n = nTerm;
@@ -190358,10 +190823,11 @@
190823 NodeWriter *pLeaf; /* Object used to write leaf nodes */
190824
190825 pLeaf = &pWriter->aNodeWriter[0];
190826 nPrefix = fts3PrefixCompress(pLeaf->key.a, pLeaf->key.n, zTerm, nTerm);
190827 nSuffix = nTerm - nPrefix;
190828 if(nSuffix<=0 ) return FTS_CORRUPT_VTAB;
190829
190830 nSpace = sqlite3Fts3VarintLen(nPrefix);
190831 nSpace += sqlite3Fts3VarintLen(nSuffix) + nSuffix;
190832 nSpace += sqlite3Fts3VarintLen(nDoclist) + nDoclist;
190833
@@ -226663,11 +227129,11 @@
227129 /* State used by the fts5DataXXX() functions. */
227130 sqlite3_blob *pReader; /* RO incr-blob open on %_data table */
227131 sqlite3_stmt *pWriter; /* "INSERT ... %_data VALUES(?,?)" */
227132 sqlite3_stmt *pDeleter; /* "DELETE FROM %_data ... id>=? AND id<=?" */
227133 sqlite3_stmt *pIdxWriter; /* "INSERT ... %_idx VALUES(?,?,?,?)" */
227134 sqlite3_stmt *pIdxDeleter; /* "DELETE FROM %_idx WHERE segid=?" */
227135 sqlite3_stmt *pIdxSelect;
227136 int nRead; /* Total number of blocks read */
227137
227138 sqlite3_stmt *pDataVersion;
227139 i64 iStructVersion; /* data_version when pStruct read */
@@ -235980,11 +236446,11 @@
236446 int nArg, /* Number of args */
236447 sqlite3_value **apUnused /* Function arguments */
236448 ){
236449 assert( nArg==0 );
236450 UNUSED_PARAM2(nArg, apUnused);
236451 sqlite3_result_text(pCtx, "fts5: 2022-06-03 14:08:40 d18818afc6021a32989499c26ab38fa442e5a55e662e39bb06e5c0daa9c65e25", -1, SQLITE_TRANSIENT);
236452 }
236453
236454 /*
236455 ** Return true if zName is the extension on one of the shadow tables used
236456 ** by this module.
236457
+23 -1
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.39.0"
150150
#define SQLITE_VERSION_NUMBER 3039000
151
-#define SQLITE_SOURCE_ID "2022-04-21 19:38:17 f766dff012af0ea3c28a8ce4db850cd0205729a8283bce1e442992aded7c734b"
151
+#define SQLITE_SOURCE_ID "2022-06-03 14:08:40 d18818afc6021a32989499c26ab38fa442e5a55e662e39bb06e5c0daa9c65e25"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -6274,10 +6274,32 @@
62746274
** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
62756275
** create the statement in the first place.
62766276
*/
62776277
SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
62786278
6279
+/*
6280
+** CAPI3REF: Return The Schema Name For A Database Connection
6281
+** METHOD: sqlite3
6282
+**
6283
+** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name
6284
+** for the N-th database on database connection D, or a NULL pointer of N is
6285
+** out of range. An N alue of 0 means the main database file. An N of 1 is
6286
+** the "temp" schema. Larger values of N correspond to various ATTACH-ed
6287
+** databases.
6288
+**
6289
+** Space to hold the string that is returned by sqlite3_db_name() is managed
6290
+** by SQLite itself. The string might be deallocated by any operation that
6291
+** changes the schema, including [ATTACH] or [DETACH] or calls to
6292
+** [sqlite3_serialize()] or [sqlite3_deserialize()], even operations that
6293
+** occur on a different thread. Applications that need to
6294
+** remember the string long-term should make their own copy. Applications that
6295
+** are accessing the same database connection simultaneously on multiple
6296
+** threads should mutex-protect calls to this API and should make their own
6297
+** private copy of the result prior to releasing the mutex.
6298
+*/
6299
+SQLITE_API const char *sqlite3_db_name(sqlite3 *db, int N);
6300
+
62796301
/*
62806302
** CAPI3REF: Return The Filename For A Database Connection
62816303
** METHOD: sqlite3
62826304
**
62836305
** ^The sqlite3_db_filename(D,N) interface returns a pointer to the filename
62846306
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.39.0"
150 #define SQLITE_VERSION_NUMBER 3039000
151 #define SQLITE_SOURCE_ID "2022-04-21 19:38:17 f766dff012af0ea3c28a8ce4db850cd0205729a8283bce1e442992aded7c734b"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -6274,10 +6274,32 @@
6274 ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
6275 ** create the statement in the first place.
6276 */
6277 SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
6278
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6279 /*
6280 ** CAPI3REF: Return The Filename For A Database Connection
6281 ** METHOD: sqlite3
6282 **
6283 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to the filename
6284
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.39.0"
150 #define SQLITE_VERSION_NUMBER 3039000
151 #define SQLITE_SOURCE_ID "2022-06-03 14:08:40 d18818afc6021a32989499c26ab38fa442e5a55e662e39bb06e5c0daa9c65e25"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -6274,10 +6274,32 @@
6274 ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
6275 ** create the statement in the first place.
6276 */
6277 SQLITE_API sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
6278
6279 /*
6280 ** CAPI3REF: Return The Schema Name For A Database Connection
6281 ** METHOD: sqlite3
6282 **
6283 ** ^The sqlite3_db_name(D,N) interface returns a pointer to the schema name
6284 ** for the N-th database on database connection D, or a NULL pointer of N is
6285 ** out of range. An N alue of 0 means the main database file. An N of 1 is
6286 ** the "temp" schema. Larger values of N correspond to various ATTACH-ed
6287 ** databases.
6288 **
6289 ** Space to hold the string that is returned by sqlite3_db_name() is managed
6290 ** by SQLite itself. The string might be deallocated by any operation that
6291 ** changes the schema, including [ATTACH] or [DETACH] or calls to
6292 ** [sqlite3_serialize()] or [sqlite3_deserialize()], even operations that
6293 ** occur on a different thread. Applications that need to
6294 ** remember the string long-term should make their own copy. Applications that
6295 ** are accessing the same database connection simultaneously on multiple
6296 ** threads should mutex-protect calls to this API and should make their own
6297 ** private copy of the result prior to releasing the mutex.
6298 */
6299 SQLITE_API const char *sqlite3_db_name(sqlite3 *db, int N);
6300
6301 /*
6302 ** CAPI3REF: Return The Filename For A Database Connection
6303 ** METHOD: sqlite3
6304 **
6305 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to the filename
6306
--- skins/darkmode/css.txt
+++ skins/darkmode/css.txt
@@ -131,13 +131,12 @@
131131
.button:focus,
132132
button:focus,
133133
input[type=button]:focus,
134134
input[type=reset]:focus,
135135
input[type=submit]:focus {
136
- color: #333;
136
+ outline: 2px outset #333;
137137
border-color: #888;
138
- outline: 0
139138
}
140139
141140
/* All page content from the bottom of the menu or submenu down to
142141
** the footer */
143142
div.content {
144143
--- skins/darkmode/css.txt
+++ skins/darkmode/css.txt
@@ -131,13 +131,12 @@
131 .button:focus,
132 button:focus,
133 input[type=button]:focus,
134 input[type=reset]:focus,
135 input[type=submit]:focus {
136 color: #333;
137 border-color: #888;
138 outline: 0
139 }
140
141 /* All page content from the bottom of the menu or submenu down to
142 ** the footer */
143 div.content {
144
--- skins/darkmode/css.txt
+++ skins/darkmode/css.txt
@@ -131,13 +131,12 @@
131 .button:focus,
132 button:focus,
133 input[type=button]:focus,
134 input[type=reset]:focus,
135 input[type=submit]:focus {
136 outline: 2px outset #333;
137 border-color: #888;
 
138 }
139
140 /* All page content from the bottom of the menu or submenu down to
141 ** the footer */
142 div.content {
143
+3 -1
--- src/add.c
+++ src/add.c
@@ -882,11 +882,13 @@
882882
}
883883
}
884884
db_finalize(&q);
885885
/* show command summary */
886886
fossil_print("added %d files, deleted %d files\n", nAdd, nDelete);
887
-
887
+ if(dryRunFlag!=0){
888
+ fossil_print("Dry-run mode: no changes were made.\n");
889
+ }
888890
db_end_transaction(dryRunFlag);
889891
}
890892
891893
/*
892894
** Rename a single file.
893895
--- src/add.c
+++ src/add.c
@@ -882,11 +882,13 @@
882 }
883 }
884 db_finalize(&q);
885 /* show command summary */
886 fossil_print("added %d files, deleted %d files\n", nAdd, nDelete);
887
 
 
888 db_end_transaction(dryRunFlag);
889 }
890
891 /*
892 ** Rename a single file.
893
--- src/add.c
+++ src/add.c
@@ -882,11 +882,13 @@
882 }
883 }
884 db_finalize(&q);
885 /* show command summary */
886 fossil_print("added %d files, deleted %d files\n", nAdd, nDelete);
887 if(dryRunFlag!=0){
888 fossil_print("Dry-run mode: no changes were made.\n");
889 }
890 db_end_transaction(dryRunFlag);
891 }
892
893 /*
894 ** Rename a single file.
895
+20 -1
--- src/alerts.c
+++ src/alerts.c
@@ -278,10 +278,18 @@
278278
@ the "From:" address of the email notification.
279279
@ The system administrator should arrange for emails sent to this address
280280
@ to be handed off to the "fossil email incoming" command so that Fossil
281281
@ can handle bounces. (Property: "email-self")</p>
282282
@ <hr>
283
+
284
+ entry_attribute("List-ID", 40, "email-listid",
285
+ "elistid", "", 0);
286
+ @ <p>
287
+ @ If this is not an empty string, then it becomes the argument to
288
+ @ a "List-ID:" header on all out-bound notification emails.
289
+ @ (Property: "email-listid")</p>
290
+ @ <hr>
283291
284292
entry_attribute("Repository Nickname", 16, "email-subname",
285293
"enn", "", 0);
286294
@ <p><b>Required.</b>
287295
@ This is short name used to identifies the repository in the
@@ -409,10 +417,11 @@
409417
const char *zDest; /* How to send email. */
410418
const char *zDb; /* Name of database file */
411419
const char *zDir; /* Directory in which to store as email files */
412420
const char *zCmd; /* Command to run for each email */
413421
const char *zFrom; /* Emails come from here */
422
+ const char *zListId; /* Argument to List-ID header */
414423
SmtpSession *pSmtp; /* SMTP relay connection */
415424
Blob out; /* For zDest=="blob" */
416425
char *zErr; /* Error message */
417426
u32 mFlags; /* Flags */
418427
int bImmediateFail; /* On any error, call fossil_fatal() */
@@ -434,10 +443,11 @@
434443
sqlite3_close(p->db);
435444
p->db = 0;
436445
p->zDb = 0;
437446
p->zDir = 0;
438447
p->zCmd = 0;
448
+ p->zListId = 0;
439449
if( p->pSmtp ){
440450
smtp_client_quit(p->pSmtp);
441451
smtp_session_free(p->pSmtp);
442452
p->pSmtp = 0;
443453
}
@@ -514,10 +524,11 @@
514524
}else{
515525
p->zDest = db_get("email-send-method",0);
516526
}
517527
if( fossil_strcmp(p->zDest,"off")==0 ) return p;
518528
if( emailerGetSetting(p, &p->zFrom, "email-self") ) return p;
529
+ p->zListId = db_get("email-listid", 0);
519530
if( fossil_strcmp(p->zDest,"db")==0 ){
520531
char *zErr;
521532
int rc;
522533
if( emailerGetSetting(p, &p->zDb, "email-send-db") ) return p;
523534
rc = sqlite3_open(p->zDb, &p->db);
@@ -881,10 +892,13 @@
881892
blob_appendf(pOut, "Sender: <%s>\r\n", p->zFrom);
882893
}else{
883894
blob_appendf(pOut, "From: <%s>\r\n", p->zFrom);
884895
}
885896
blob_appendf(pOut, "Date: %z\r\n", cgi_rfc822_datestamp(time(0)));
897
+ if( p->zListId && p->zListId[0] ){
898
+ blob_appendf(pOut, "List-Id: %s\r\n", p->zListId);
899
+ }
886900
if( strstr(blob_str(pHdr), "\r\nMessage-Id:")==0 ){
887901
/* Message-id format: "<$(date)x$(random)@$(from-host)>" where $(date) is
888902
** the current unix-time in hex, $(random) is a 64-bit random number,
889903
** and $(from) is the domain part of the email-self setting. */
890904
sqlite3_randomness(sizeof(r1), &r1);
@@ -969,11 +983,11 @@
969983
** brackets. Examples: "[fossil-src]", "[sqlite-src]".
970984
*/
971985
/*
972986
** SETTING: email-renew-interval width=16
973987
** If this setting as an integer N that is 14 or greater then email
974
-** notification is suspected for subscriptions that have a "last contact
988
+** notification is suspended for subscriptions that have a "last contact
975989
** time" of more than N days ago. The "last contact time" is recorded
976990
** in the SUBSCRIBER.LASTCONTACT entry of the database. Logging in,
977991
** sending a forum post, editing a wiki page, changing subscription settings
978992
** at /alerts, or visiting /renew all update the last contact time.
979993
** If this setting is not an integer value or is less than 14 or undefined,
@@ -1029,10 +1043,15 @@
10291043
/*
10301044
** SETTING: email-self width=40
10311045
** This is the email address for the repository. Outbound emails add
10321046
** this email address as the "From:" field.
10331047
*/
1048
+/*
1049
+** SETTING: email-listid width=40
1050
+** If this setting is not an empty string, then it becomes the argument to
1051
+** a "List-ID:" header that is added to all out-bound notification emails.
1052
+*/
10341053
/*
10351054
** SETTING: email-send-relayhost width=40 sensitive
10361055
** This is the hostname and TCP port to which output email messages
10371056
** are sent when email-send-method is "relay". There should be an
10381057
** SMTP server configured as a Mail Submission Agent listening on the
10391058
--- src/alerts.c
+++ src/alerts.c
@@ -278,10 +278,18 @@
278 @ the "From:" address of the email notification.
279 @ The system administrator should arrange for emails sent to this address
280 @ to be handed off to the "fossil email incoming" command so that Fossil
281 @ can handle bounces. (Property: "email-self")</p>
282 @ <hr>
 
 
 
 
 
 
 
 
283
284 entry_attribute("Repository Nickname", 16, "email-subname",
285 "enn", "", 0);
286 @ <p><b>Required.</b>
287 @ This is short name used to identifies the repository in the
@@ -409,10 +417,11 @@
409 const char *zDest; /* How to send email. */
410 const char *zDb; /* Name of database file */
411 const char *zDir; /* Directory in which to store as email files */
412 const char *zCmd; /* Command to run for each email */
413 const char *zFrom; /* Emails come from here */
 
414 SmtpSession *pSmtp; /* SMTP relay connection */
415 Blob out; /* For zDest=="blob" */
416 char *zErr; /* Error message */
417 u32 mFlags; /* Flags */
418 int bImmediateFail; /* On any error, call fossil_fatal() */
@@ -434,10 +443,11 @@
434 sqlite3_close(p->db);
435 p->db = 0;
436 p->zDb = 0;
437 p->zDir = 0;
438 p->zCmd = 0;
 
439 if( p->pSmtp ){
440 smtp_client_quit(p->pSmtp);
441 smtp_session_free(p->pSmtp);
442 p->pSmtp = 0;
443 }
@@ -514,10 +524,11 @@
514 }else{
515 p->zDest = db_get("email-send-method",0);
516 }
517 if( fossil_strcmp(p->zDest,"off")==0 ) return p;
518 if( emailerGetSetting(p, &p->zFrom, "email-self") ) return p;
 
519 if( fossil_strcmp(p->zDest,"db")==0 ){
520 char *zErr;
521 int rc;
522 if( emailerGetSetting(p, &p->zDb, "email-send-db") ) return p;
523 rc = sqlite3_open(p->zDb, &p->db);
@@ -881,10 +892,13 @@
881 blob_appendf(pOut, "Sender: <%s>\r\n", p->zFrom);
882 }else{
883 blob_appendf(pOut, "From: <%s>\r\n", p->zFrom);
884 }
885 blob_appendf(pOut, "Date: %z\r\n", cgi_rfc822_datestamp(time(0)));
 
 
 
886 if( strstr(blob_str(pHdr), "\r\nMessage-Id:")==0 ){
887 /* Message-id format: "<$(date)x$(random)@$(from-host)>" where $(date) is
888 ** the current unix-time in hex, $(random) is a 64-bit random number,
889 ** and $(from) is the domain part of the email-self setting. */
890 sqlite3_randomness(sizeof(r1), &r1);
@@ -969,11 +983,11 @@
969 ** brackets. Examples: "[fossil-src]", "[sqlite-src]".
970 */
971 /*
972 ** SETTING: email-renew-interval width=16
973 ** If this setting as an integer N that is 14 or greater then email
974 ** notification is suspected for subscriptions that have a "last contact
975 ** time" of more than N days ago. The "last contact time" is recorded
976 ** in the SUBSCRIBER.LASTCONTACT entry of the database. Logging in,
977 ** sending a forum post, editing a wiki page, changing subscription settings
978 ** at /alerts, or visiting /renew all update the last contact time.
979 ** If this setting is not an integer value or is less than 14 or undefined,
@@ -1029,10 +1043,15 @@
1029 /*
1030 ** SETTING: email-self width=40
1031 ** This is the email address for the repository. Outbound emails add
1032 ** this email address as the "From:" field.
1033 */
 
 
 
 
 
1034 /*
1035 ** SETTING: email-send-relayhost width=40 sensitive
1036 ** This is the hostname and TCP port to which output email messages
1037 ** are sent when email-send-method is "relay". There should be an
1038 ** SMTP server configured as a Mail Submission Agent listening on the
1039
--- src/alerts.c
+++ src/alerts.c
@@ -278,10 +278,18 @@
278 @ the "From:" address of the email notification.
279 @ The system administrator should arrange for emails sent to this address
280 @ to be handed off to the "fossil email incoming" command so that Fossil
281 @ can handle bounces. (Property: "email-self")</p>
282 @ <hr>
283
284 entry_attribute("List-ID", 40, "email-listid",
285 "elistid", "", 0);
286 @ <p>
287 @ If this is not an empty string, then it becomes the argument to
288 @ a "List-ID:" header on all out-bound notification emails.
289 @ (Property: "email-listid")</p>
290 @ <hr>
291
292 entry_attribute("Repository Nickname", 16, "email-subname",
293 "enn", "", 0);
294 @ <p><b>Required.</b>
295 @ This is short name used to identifies the repository in the
@@ -409,10 +417,11 @@
417 const char *zDest; /* How to send email. */
418 const char *zDb; /* Name of database file */
419 const char *zDir; /* Directory in which to store as email files */
420 const char *zCmd; /* Command to run for each email */
421 const char *zFrom; /* Emails come from here */
422 const char *zListId; /* Argument to List-ID header */
423 SmtpSession *pSmtp; /* SMTP relay connection */
424 Blob out; /* For zDest=="blob" */
425 char *zErr; /* Error message */
426 u32 mFlags; /* Flags */
427 int bImmediateFail; /* On any error, call fossil_fatal() */
@@ -434,10 +443,11 @@
443 sqlite3_close(p->db);
444 p->db = 0;
445 p->zDb = 0;
446 p->zDir = 0;
447 p->zCmd = 0;
448 p->zListId = 0;
449 if( p->pSmtp ){
450 smtp_client_quit(p->pSmtp);
451 smtp_session_free(p->pSmtp);
452 p->pSmtp = 0;
453 }
@@ -514,10 +524,11 @@
524 }else{
525 p->zDest = db_get("email-send-method",0);
526 }
527 if( fossil_strcmp(p->zDest,"off")==0 ) return p;
528 if( emailerGetSetting(p, &p->zFrom, "email-self") ) return p;
529 p->zListId = db_get("email-listid", 0);
530 if( fossil_strcmp(p->zDest,"db")==0 ){
531 char *zErr;
532 int rc;
533 if( emailerGetSetting(p, &p->zDb, "email-send-db") ) return p;
534 rc = sqlite3_open(p->zDb, &p->db);
@@ -881,10 +892,13 @@
892 blob_appendf(pOut, "Sender: <%s>\r\n", p->zFrom);
893 }else{
894 blob_appendf(pOut, "From: <%s>\r\n", p->zFrom);
895 }
896 blob_appendf(pOut, "Date: %z\r\n", cgi_rfc822_datestamp(time(0)));
897 if( p->zListId && p->zListId[0] ){
898 blob_appendf(pOut, "List-Id: %s\r\n", p->zListId);
899 }
900 if( strstr(blob_str(pHdr), "\r\nMessage-Id:")==0 ){
901 /* Message-id format: "<$(date)x$(random)@$(from-host)>" where $(date) is
902 ** the current unix-time in hex, $(random) is a 64-bit random number,
903 ** and $(from) is the domain part of the email-self setting. */
904 sqlite3_randomness(sizeof(r1), &r1);
@@ -969,11 +983,11 @@
983 ** brackets. Examples: "[fossil-src]", "[sqlite-src]".
984 */
985 /*
986 ** SETTING: email-renew-interval width=16
987 ** If this setting as an integer N that is 14 or greater then email
988 ** notification is suspended for subscriptions that have a "last contact
989 ** time" of more than N days ago. The "last contact time" is recorded
990 ** in the SUBSCRIBER.LASTCONTACT entry of the database. Logging in,
991 ** sending a forum post, editing a wiki page, changing subscription settings
992 ** at /alerts, or visiting /renew all update the last contact time.
993 ** If this setting is not an integer value or is less than 14 or undefined,
@@ -1029,10 +1043,15 @@
1043 /*
1044 ** SETTING: email-self width=40
1045 ** This is the email address for the repository. Outbound emails add
1046 ** this email address as the "From:" field.
1047 */
1048 /*
1049 ** SETTING: email-listid width=40
1050 ** If this setting is not an empty string, then it becomes the argument to
1051 ** a "List-ID:" header that is added to all out-bound notification emails.
1052 */
1053 /*
1054 ** SETTING: email-send-relayhost width=40 sensitive
1055 ** This is the hostname and TCP port to which output email messages
1056 ** are sent when email-send-method is "relay". There should be an
1057 ** SMTP server configured as a Mail Submission Agent listening on the
1058
+19 -5
--- src/backlink.c
+++ src/backlink.c
@@ -179,11 +179,12 @@
179179
rid = db_int(0, "SELECT rid FROM tagxref WHERE tagid=%d"
180180
" ORDER BY mtime DESC LIMIT 1", tagid);
181181
if( rid==0 ) return;
182182
pWiki = manifest_get(rid, CFTYPE_WIKI, 0);
183183
if( pWiki ){
184
- backlink_extract(pWiki->zWiki, pWiki->zMimetype, tagid, BKLNK_WIKI,
184
+ int mimetype = parse_mimetype( pWiki->zMimetype );
185
+ backlink_extract(pWiki->zWiki, mimetype, tagid, BKLNK_WIKI,
185186
pWiki->rDate, 1);
186187
manifest_destroy(pWiki);
187188
}
188189
}
189190
@@ -296,17 +297,28 @@
296297
markdown(&out, &in, &html_renderer);
297298
blob_reset(&out);
298299
blob_reset(&in);
299300
}
300301
302
+/*
303
+** Transform mimetype string into an integer code.
304
+** NOTE: In the sake of compatability empty string is parsed as MT_UNKNOWN;
305
+** it is yet unclear whether it can safely be changed to MT_NONE.
306
+*/
307
+int parse_mimetype(const char* zMimetype){
308
+ if( zMimetype==0 ) return MT_NONE;
309
+ if( strstr(zMimetype,"wiki")!=0 ) return MT_WIKI;
310
+ if( strstr(zMimetype,"markdown")!=0 ) return MT_MARKDOWN;
311
+ return MT_UNKNOWN;
312
+}
301313
/*
302314
** Parse text looking for hyperlinks. Insert references into the
303315
** BACKLINK table.
304316
*/
305317
void backlink_extract(
306318
char *zSrc, /* Input text from which links are extracted */
307
- const char *zMimetype, /* Mimetype of input. NULL means fossil-wiki */
319
+ int mimetype, /* Mimetype of input. MT_NONE works as MT_WIKI */
308320
int srcid, /* srcid for the source document */
309321
int srctype, /* One of BKLNK_*. 0=comment 1=ticket 2=wiki */
310322
double mtime, /* mtime field for new BACKLINK table entries */
311323
int replaceFlag /* True to overwrite prior BACKLINK entries */
312324
){
@@ -315,15 +327,16 @@
315327
db_multi_exec("DELETE FROM backlink WHERE srctype=%d AND srcid=%d",
316328
srctype, srcid);
317329
}
318330
bklnk.srcid = srcid;
319331
assert( ValidBklnk(srctype) );
332
+ assert( ValidMTC(mimetype) );
320333
bklnk.srctype = srctype;
321334
bklnk.mtime = mtime;
322
- if( zMimetype==0 || strstr(zMimetype,"wiki")!=0 ){
335
+ if( mimetype==MT_NONE || mimetype==MT_WIKI ){
323336
wiki_extract_links(zSrc, &bklnk, srctype==BKLNK_COMMENT ? WIKI_INLINE : 0);
324
- }else if( strstr(zMimetype,"markdown")!=0 ){
337
+ }else if( mimetype==MT_MARKDOWN ){
325338
markdown_extract_links(zSrc, &bklnk);
326339
}
327340
}
328341
329342
/*
@@ -341,10 +354,11 @@
341354
** --mimetype TYPE Use an alternative mimetype.
342355
*/
343356
void test_backlinks_cmd(void){
344357
const char *zMTime = find_option("mtime",0,1);
345358
const char *zMimetype = find_option("mimetype",0,1);
359
+ const int mimetype = parse_mimetype(zMimetype);
346360
Blob in;
347361
int srcid;
348362
int srctype;
349363
double mtime;
350364
@@ -372,11 +386,11 @@
372386
" ' srcid='||quote(new.srcid)||"
373387
" ' mtime='||datetime(new.mtime));\n"
374388
" SELECT raise(ignore);\n"
375389
"END;"
376390
);
377
- backlink_extract(blob_str(&in),zMimetype,srcid,srctype,mtime,0);
391
+ backlink_extract(blob_str(&in),mimetype,srcid,srctype,mtime,0);
378392
blob_reset(&in);
379393
}
380394
381395
382396
/*
383397
--- src/backlink.c
+++ src/backlink.c
@@ -179,11 +179,12 @@
179 rid = db_int(0, "SELECT rid FROM tagxref WHERE tagid=%d"
180 " ORDER BY mtime DESC LIMIT 1", tagid);
181 if( rid==0 ) return;
182 pWiki = manifest_get(rid, CFTYPE_WIKI, 0);
183 if( pWiki ){
184 backlink_extract(pWiki->zWiki, pWiki->zMimetype, tagid, BKLNK_WIKI,
 
185 pWiki->rDate, 1);
186 manifest_destroy(pWiki);
187 }
188 }
189
@@ -296,17 +297,28 @@
296 markdown(&out, &in, &html_renderer);
297 blob_reset(&out);
298 blob_reset(&in);
299 }
300
 
 
 
 
 
 
 
 
 
 
 
301 /*
302 ** Parse text looking for hyperlinks. Insert references into the
303 ** BACKLINK table.
304 */
305 void backlink_extract(
306 char *zSrc, /* Input text from which links are extracted */
307 const char *zMimetype, /* Mimetype of input. NULL means fossil-wiki */
308 int srcid, /* srcid for the source document */
309 int srctype, /* One of BKLNK_*. 0=comment 1=ticket 2=wiki */
310 double mtime, /* mtime field for new BACKLINK table entries */
311 int replaceFlag /* True to overwrite prior BACKLINK entries */
312 ){
@@ -315,15 +327,16 @@
315 db_multi_exec("DELETE FROM backlink WHERE srctype=%d AND srcid=%d",
316 srctype, srcid);
317 }
318 bklnk.srcid = srcid;
319 assert( ValidBklnk(srctype) );
 
320 bklnk.srctype = srctype;
321 bklnk.mtime = mtime;
322 if( zMimetype==0 || strstr(zMimetype,"wiki")!=0 ){
323 wiki_extract_links(zSrc, &bklnk, srctype==BKLNK_COMMENT ? WIKI_INLINE : 0);
324 }else if( strstr(zMimetype,"markdown")!=0 ){
325 markdown_extract_links(zSrc, &bklnk);
326 }
327 }
328
329 /*
@@ -341,10 +354,11 @@
341 ** --mimetype TYPE Use an alternative mimetype.
342 */
343 void test_backlinks_cmd(void){
344 const char *zMTime = find_option("mtime",0,1);
345 const char *zMimetype = find_option("mimetype",0,1);
 
346 Blob in;
347 int srcid;
348 int srctype;
349 double mtime;
350
@@ -372,11 +386,11 @@
372 " ' srcid='||quote(new.srcid)||"
373 " ' mtime='||datetime(new.mtime));\n"
374 " SELECT raise(ignore);\n"
375 "END;"
376 );
377 backlink_extract(blob_str(&in),zMimetype,srcid,srctype,mtime,0);
378 blob_reset(&in);
379 }
380
381
382 /*
383
--- src/backlink.c
+++ src/backlink.c
@@ -179,11 +179,12 @@
179 rid = db_int(0, "SELECT rid FROM tagxref WHERE tagid=%d"
180 " ORDER BY mtime DESC LIMIT 1", tagid);
181 if( rid==0 ) return;
182 pWiki = manifest_get(rid, CFTYPE_WIKI, 0);
183 if( pWiki ){
184 int mimetype = parse_mimetype( pWiki->zMimetype );
185 backlink_extract(pWiki->zWiki, mimetype, tagid, BKLNK_WIKI,
186 pWiki->rDate, 1);
187 manifest_destroy(pWiki);
188 }
189 }
190
@@ -296,17 +297,28 @@
297 markdown(&out, &in, &html_renderer);
298 blob_reset(&out);
299 blob_reset(&in);
300 }
301
302 /*
303 ** Transform mimetype string into an integer code.
304 ** NOTE: In the sake of compatability empty string is parsed as MT_UNKNOWN;
305 ** it is yet unclear whether it can safely be changed to MT_NONE.
306 */
307 int parse_mimetype(const char* zMimetype){
308 if( zMimetype==0 ) return MT_NONE;
309 if( strstr(zMimetype,"wiki")!=0 ) return MT_WIKI;
310 if( strstr(zMimetype,"markdown")!=0 ) return MT_MARKDOWN;
311 return MT_UNKNOWN;
312 }
313 /*
314 ** Parse text looking for hyperlinks. Insert references into the
315 ** BACKLINK table.
316 */
317 void backlink_extract(
318 char *zSrc, /* Input text from which links are extracted */
319 int mimetype, /* Mimetype of input. MT_NONE works as MT_WIKI */
320 int srcid, /* srcid for the source document */
321 int srctype, /* One of BKLNK_*. 0=comment 1=ticket 2=wiki */
322 double mtime, /* mtime field for new BACKLINK table entries */
323 int replaceFlag /* True to overwrite prior BACKLINK entries */
324 ){
@@ -315,15 +327,16 @@
327 db_multi_exec("DELETE FROM backlink WHERE srctype=%d AND srcid=%d",
328 srctype, srcid);
329 }
330 bklnk.srcid = srcid;
331 assert( ValidBklnk(srctype) );
332 assert( ValidMTC(mimetype) );
333 bklnk.srctype = srctype;
334 bklnk.mtime = mtime;
335 if( mimetype==MT_NONE || mimetype==MT_WIKI ){
336 wiki_extract_links(zSrc, &bklnk, srctype==BKLNK_COMMENT ? WIKI_INLINE : 0);
337 }else if( mimetype==MT_MARKDOWN ){
338 markdown_extract_links(zSrc, &bklnk);
339 }
340 }
341
342 /*
@@ -341,10 +354,11 @@
354 ** --mimetype TYPE Use an alternative mimetype.
355 */
356 void test_backlinks_cmd(void){
357 const char *zMTime = find_option("mtime",0,1);
358 const char *zMimetype = find_option("mimetype",0,1);
359 const int mimetype = parse_mimetype(zMimetype);
360 Blob in;
361 int srcid;
362 int srctype;
363 double mtime;
364
@@ -372,11 +386,11 @@
386 " ' srcid='||quote(new.srcid)||"
387 " ' mtime='||datetime(new.mtime));\n"
388 " SELECT raise(ignore);\n"
389 "END;"
390 );
391 backlink_extract(blob_str(&in),mimetype,srcid,srctype,mtime,0);
392 blob_reset(&in);
393 }
394
395
396 /*
397
+19 -5
--- src/backlink.c
+++ src/backlink.c
@@ -179,11 +179,12 @@
179179
rid = db_int(0, "SELECT rid FROM tagxref WHERE tagid=%d"
180180
" ORDER BY mtime DESC LIMIT 1", tagid);
181181
if( rid==0 ) return;
182182
pWiki = manifest_get(rid, CFTYPE_WIKI, 0);
183183
if( pWiki ){
184
- backlink_extract(pWiki->zWiki, pWiki->zMimetype, tagid, BKLNK_WIKI,
184
+ int mimetype = parse_mimetype( pWiki->zMimetype );
185
+ backlink_extract(pWiki->zWiki, mimetype, tagid, BKLNK_WIKI,
185186
pWiki->rDate, 1);
186187
manifest_destroy(pWiki);
187188
}
188189
}
189190
@@ -296,17 +297,28 @@
296297
markdown(&out, &in, &html_renderer);
297298
blob_reset(&out);
298299
blob_reset(&in);
299300
}
300301
302
+/*
303
+** Transform mimetype string into an integer code.
304
+** NOTE: In the sake of compatability empty string is parsed as MT_UNKNOWN;
305
+** it is yet unclear whether it can safely be changed to MT_NONE.
306
+*/
307
+int parse_mimetype(const char* zMimetype){
308
+ if( zMimetype==0 ) return MT_NONE;
309
+ if( strstr(zMimetype,"wiki")!=0 ) return MT_WIKI;
310
+ if( strstr(zMimetype,"markdown")!=0 ) return MT_MARKDOWN;
311
+ return MT_UNKNOWN;
312
+}
301313
/*
302314
** Parse text looking for hyperlinks. Insert references into the
303315
** BACKLINK table.
304316
*/
305317
void backlink_extract(
306318
char *zSrc, /* Input text from which links are extracted */
307
- const char *zMimetype, /* Mimetype of input. NULL means fossil-wiki */
319
+ int mimetype, /* Mimetype of input. MT_NONE works as MT_WIKI */
308320
int srcid, /* srcid for the source document */
309321
int srctype, /* One of BKLNK_*. 0=comment 1=ticket 2=wiki */
310322
double mtime, /* mtime field for new BACKLINK table entries */
311323
int replaceFlag /* True to overwrite prior BACKLINK entries */
312324
){
@@ -315,15 +327,16 @@
315327
db_multi_exec("DELETE FROM backlink WHERE srctype=%d AND srcid=%d",
316328
srctype, srcid);
317329
}
318330
bklnk.srcid = srcid;
319331
assert( ValidBklnk(srctype) );
332
+ assert( ValidMTC(mimetype) );
320333
bklnk.srctype = srctype;
321334
bklnk.mtime = mtime;
322
- if( zMimetype==0 || strstr(zMimetype,"wiki")!=0 ){
335
+ if( mimetype==MT_NONE || mimetype==MT_WIKI ){
323336
wiki_extract_links(zSrc, &bklnk, srctype==BKLNK_COMMENT ? WIKI_INLINE : 0);
324
- }else if( strstr(zMimetype,"markdown")!=0 ){
337
+ }else if( mimetype==MT_MARKDOWN ){
325338
markdown_extract_links(zSrc, &bklnk);
326339
}
327340
}
328341
329342
/*
@@ -341,10 +354,11 @@
341354
** --mimetype TYPE Use an alternative mimetype.
342355
*/
343356
void test_backlinks_cmd(void){
344357
const char *zMTime = find_option("mtime",0,1);
345358
const char *zMimetype = find_option("mimetype",0,1);
359
+ const int mimetype = parse_mimetype(zMimetype);
346360
Blob in;
347361
int srcid;
348362
int srctype;
349363
double mtime;
350364
@@ -372,11 +386,11 @@
372386
" ' srcid='||quote(new.srcid)||"
373387
" ' mtime='||datetime(new.mtime));\n"
374388
" SELECT raise(ignore);\n"
375389
"END;"
376390
);
377
- backlink_extract(blob_str(&in),zMimetype,srcid,srctype,mtime,0);
391
+ backlink_extract(blob_str(&in),mimetype,srcid,srctype,mtime,0);
378392
blob_reset(&in);
379393
}
380394
381395
382396
/*
383397
--- src/backlink.c
+++ src/backlink.c
@@ -179,11 +179,12 @@
179 rid = db_int(0, "SELECT rid FROM tagxref WHERE tagid=%d"
180 " ORDER BY mtime DESC LIMIT 1", tagid);
181 if( rid==0 ) return;
182 pWiki = manifest_get(rid, CFTYPE_WIKI, 0);
183 if( pWiki ){
184 backlink_extract(pWiki->zWiki, pWiki->zMimetype, tagid, BKLNK_WIKI,
 
185 pWiki->rDate, 1);
186 manifest_destroy(pWiki);
187 }
188 }
189
@@ -296,17 +297,28 @@
296 markdown(&out, &in, &html_renderer);
297 blob_reset(&out);
298 blob_reset(&in);
299 }
300
 
 
 
 
 
 
 
 
 
 
 
301 /*
302 ** Parse text looking for hyperlinks. Insert references into the
303 ** BACKLINK table.
304 */
305 void backlink_extract(
306 char *zSrc, /* Input text from which links are extracted */
307 const char *zMimetype, /* Mimetype of input. NULL means fossil-wiki */
308 int srcid, /* srcid for the source document */
309 int srctype, /* One of BKLNK_*. 0=comment 1=ticket 2=wiki */
310 double mtime, /* mtime field for new BACKLINK table entries */
311 int replaceFlag /* True to overwrite prior BACKLINK entries */
312 ){
@@ -315,15 +327,16 @@
315 db_multi_exec("DELETE FROM backlink WHERE srctype=%d AND srcid=%d",
316 srctype, srcid);
317 }
318 bklnk.srcid = srcid;
319 assert( ValidBklnk(srctype) );
 
320 bklnk.srctype = srctype;
321 bklnk.mtime = mtime;
322 if( zMimetype==0 || strstr(zMimetype,"wiki")!=0 ){
323 wiki_extract_links(zSrc, &bklnk, srctype==BKLNK_COMMENT ? WIKI_INLINE : 0);
324 }else if( strstr(zMimetype,"markdown")!=0 ){
325 markdown_extract_links(zSrc, &bklnk);
326 }
327 }
328
329 /*
@@ -341,10 +354,11 @@
341 ** --mimetype TYPE Use an alternative mimetype.
342 */
343 void test_backlinks_cmd(void){
344 const char *zMTime = find_option("mtime",0,1);
345 const char *zMimetype = find_option("mimetype",0,1);
 
346 Blob in;
347 int srcid;
348 int srctype;
349 double mtime;
350
@@ -372,11 +386,11 @@
372 " ' srcid='||quote(new.srcid)||"
373 " ' mtime='||datetime(new.mtime));\n"
374 " SELECT raise(ignore);\n"
375 "END;"
376 );
377 backlink_extract(blob_str(&in),zMimetype,srcid,srctype,mtime,0);
378 blob_reset(&in);
379 }
380
381
382 /*
383
--- src/backlink.c
+++ src/backlink.c
@@ -179,11 +179,12 @@
179 rid = db_int(0, "SELECT rid FROM tagxref WHERE tagid=%d"
180 " ORDER BY mtime DESC LIMIT 1", tagid);
181 if( rid==0 ) return;
182 pWiki = manifest_get(rid, CFTYPE_WIKI, 0);
183 if( pWiki ){
184 int mimetype = parse_mimetype( pWiki->zMimetype );
185 backlink_extract(pWiki->zWiki, mimetype, tagid, BKLNK_WIKI,
186 pWiki->rDate, 1);
187 manifest_destroy(pWiki);
188 }
189 }
190
@@ -296,17 +297,28 @@
297 markdown(&out, &in, &html_renderer);
298 blob_reset(&out);
299 blob_reset(&in);
300 }
301
302 /*
303 ** Transform mimetype string into an integer code.
304 ** NOTE: In the sake of compatability empty string is parsed as MT_UNKNOWN;
305 ** it is yet unclear whether it can safely be changed to MT_NONE.
306 */
307 int parse_mimetype(const char* zMimetype){
308 if( zMimetype==0 ) return MT_NONE;
309 if( strstr(zMimetype,"wiki")!=0 ) return MT_WIKI;
310 if( strstr(zMimetype,"markdown")!=0 ) return MT_MARKDOWN;
311 return MT_UNKNOWN;
312 }
313 /*
314 ** Parse text looking for hyperlinks. Insert references into the
315 ** BACKLINK table.
316 */
317 void backlink_extract(
318 char *zSrc, /* Input text from which links are extracted */
319 int mimetype, /* Mimetype of input. MT_NONE works as MT_WIKI */
320 int srcid, /* srcid for the source document */
321 int srctype, /* One of BKLNK_*. 0=comment 1=ticket 2=wiki */
322 double mtime, /* mtime field for new BACKLINK table entries */
323 int replaceFlag /* True to overwrite prior BACKLINK entries */
324 ){
@@ -315,15 +327,16 @@
327 db_multi_exec("DELETE FROM backlink WHERE srctype=%d AND srcid=%d",
328 srctype, srcid);
329 }
330 bklnk.srcid = srcid;
331 assert( ValidBklnk(srctype) );
332 assert( ValidMTC(mimetype) );
333 bklnk.srctype = srctype;
334 bklnk.mtime = mtime;
335 if( mimetype==MT_NONE || mimetype==MT_WIKI ){
336 wiki_extract_links(zSrc, &bklnk, srctype==BKLNK_COMMENT ? WIKI_INLINE : 0);
337 }else if( mimetype==MT_MARKDOWN ){
338 markdown_extract_links(zSrc, &bklnk);
339 }
340 }
341
342 /*
@@ -341,10 +354,11 @@
354 ** --mimetype TYPE Use an alternative mimetype.
355 */
356 void test_backlinks_cmd(void){
357 const char *zMTime = find_option("mtime",0,1);
358 const char *zMimetype = find_option("mimetype",0,1);
359 const int mimetype = parse_mimetype(zMimetype);
360 Blob in;
361 int srcid;
362 int srctype;
363 double mtime;
364
@@ -372,11 +386,11 @@
386 " ' srcid='||quote(new.srcid)||"
387 " ' mtime='||datetime(new.mtime));\n"
388 " SELECT raise(ignore);\n"
389 "END;"
390 );
391 backlink_extract(blob_str(&in),mimetype,srcid,srctype,mtime,0);
392 blob_reset(&in);
393 }
394
395
396 /*
397
+9 -2
--- src/bisect.c
+++ src/bisect.c
@@ -81,10 +81,11 @@
8181
"skip\"" },
8282
{ "direct-only", "on", "Follow only primary parent-child links, not "
8383
"merges\n" },
8484
{ "display", "chart", "Command to run after \"next\". \"chart\", "
8585
"\"log\", \"status\", or \"none\"" },
86
+ { "linear", "off", "Do a linear scan rather than a true bisect" },
8687
};
8788
8889
/*
8990
** Return the value of a boolean bisect option.
9091
*/
@@ -375,11 +376,12 @@
375376
** Reset the bisect subsystem.
376377
*/
377378
void bisect_reset(void){
378379
db_multi_exec(
379380
"DELETE FROM vvar WHERE name IN "
380
- " ('bisect-good', 'bisect-bad', 'bisect-log', 'bisect-complete')"
381
+ " ('bisect-good', 'bisect-bad', 'bisect-log', 'bisect-complete',"
382
+ " 'bisect-linear')"
381383
);
382384
}
383385
384386
/*
385387
** fossil bisect run [OPTIONS] COMMAND
@@ -630,11 +632,16 @@
630632
if( strncmp(zCmd, "next", n)==0 ){
631633
PathNode *pMid;
632634
char *zDisplay = db_lget("bisect-display","chart");
633635
int m = (int)strlen(zDisplay);
634636
bisect_path();
635
- pMid = path_midpoint();
637
+ if( db_lget_boolean("bisect-linear",0) ){
638
+ pMid = path_next();
639
+ if( pMid && pMid->rid==db_lget_int("checkout",0) ) pMid = 0;
640
+ }else{
641
+ pMid = path_midpoint();
642
+ }
636643
if( pMid==0 ){
637644
fossil_print("bisect complete\n");
638645
db_lset_int("bisect-complete",1);
639646
}else{
640647
int nSpan = path_length_not_hidden();
641648
--- src/bisect.c
+++ src/bisect.c
@@ -81,10 +81,11 @@
81 "skip\"" },
82 { "direct-only", "on", "Follow only primary parent-child links, not "
83 "merges\n" },
84 { "display", "chart", "Command to run after \"next\". \"chart\", "
85 "\"log\", \"status\", or \"none\"" },
 
86 };
87
88 /*
89 ** Return the value of a boolean bisect option.
90 */
@@ -375,11 +376,12 @@
375 ** Reset the bisect subsystem.
376 */
377 void bisect_reset(void){
378 db_multi_exec(
379 "DELETE FROM vvar WHERE name IN "
380 " ('bisect-good', 'bisect-bad', 'bisect-log', 'bisect-complete')"
 
381 );
382 }
383
384 /*
385 ** fossil bisect run [OPTIONS] COMMAND
@@ -630,11 +632,16 @@
630 if( strncmp(zCmd, "next", n)==0 ){
631 PathNode *pMid;
632 char *zDisplay = db_lget("bisect-display","chart");
633 int m = (int)strlen(zDisplay);
634 bisect_path();
635 pMid = path_midpoint();
 
 
 
 
 
636 if( pMid==0 ){
637 fossil_print("bisect complete\n");
638 db_lset_int("bisect-complete",1);
639 }else{
640 int nSpan = path_length_not_hidden();
641
--- src/bisect.c
+++ src/bisect.c
@@ -81,10 +81,11 @@
81 "skip\"" },
82 { "direct-only", "on", "Follow only primary parent-child links, not "
83 "merges\n" },
84 { "display", "chart", "Command to run after \"next\". \"chart\", "
85 "\"log\", \"status\", or \"none\"" },
86 { "linear", "off", "Do a linear scan rather than a true bisect" },
87 };
88
89 /*
90 ** Return the value of a boolean bisect option.
91 */
@@ -375,11 +376,12 @@
376 ** Reset the bisect subsystem.
377 */
378 void bisect_reset(void){
379 db_multi_exec(
380 "DELETE FROM vvar WHERE name IN "
381 " ('bisect-good', 'bisect-bad', 'bisect-log', 'bisect-complete',"
382 " 'bisect-linear')"
383 );
384 }
385
386 /*
387 ** fossil bisect run [OPTIONS] COMMAND
@@ -630,11 +632,16 @@
632 if( strncmp(zCmd, "next", n)==0 ){
633 PathNode *pMid;
634 char *zDisplay = db_lget("bisect-display","chart");
635 int m = (int)strlen(zDisplay);
636 bisect_path();
637 if( db_lget_boolean("bisect-linear",0) ){
638 pMid = path_next();
639 if( pMid && pMid->rid==db_lget_int("checkout",0) ) pMid = 0;
640 }else{
641 pMid = path_midpoint();
642 }
643 if( pMid==0 ){
644 fossil_print("bisect complete\n");
645 db_lset_int("bisect-complete",1);
646 }else{
647 int nSpan = path_length_not_hidden();
648
+4 -5
--- src/builtin.c
+++ src/builtin.c
@@ -130,20 +130,19 @@
130130
blob_reset(&x);
131131
}
132132
133133
/*
134134
** Input zList is a list of numeric identifiers for files in
135
-** aBuiltinFiles[]. Return the concatenation of all of those
136
-** files using mimetype zType, or as application/javascript if
137
-** zType is 0.
135
+** aBuiltinFiles[]. Return the concatenation of all of those files
136
+** using mimetype zType, or as text/javascript if zType is 0.
138137
*/
139138
static void builtin_deliver_multiple_js_files(
140139
const char *zList, /* List of numeric identifiers */
141140
const char *zType /* Override mimetype */
142141
){
143142
Blob *pOut;
144
- if( zType==0 ) zType = "application/javascript";
143
+ if( zType==0 ) zType = "text/javascript";
145144
cgi_set_content_type(zType);
146145
pOut = cgi_output_blob();
147146
while( zList[0] ){
148147
int i = atoi(zList);
149148
if( i>0 && i<=count(aBuiltinFiles) ){
@@ -203,11 +202,11 @@
203202
@ File "%h(zName)" not found
204203
return;
205204
}
206205
if( zType==0 ){
207206
if( sqlite3_strglob("*.js", zName)==0 ){
208
- zType = "application/javascript";
207
+ zType = "text/javascript";
209208
}else{
210209
zType = mimetype_from_name(zName);
211210
}
212211
}
213212
cgi_set_content_type(zType);
214213
--- src/builtin.c
+++ src/builtin.c
@@ -130,20 +130,19 @@
130 blob_reset(&x);
131 }
132
133 /*
134 ** Input zList is a list of numeric identifiers for files in
135 ** aBuiltinFiles[]. Return the concatenation of all of those
136 ** files using mimetype zType, or as application/javascript if
137 ** zType is 0.
138 */
139 static void builtin_deliver_multiple_js_files(
140 const char *zList, /* List of numeric identifiers */
141 const char *zType /* Override mimetype */
142 ){
143 Blob *pOut;
144 if( zType==0 ) zType = "application/javascript";
145 cgi_set_content_type(zType);
146 pOut = cgi_output_blob();
147 while( zList[0] ){
148 int i = atoi(zList);
149 if( i>0 && i<=count(aBuiltinFiles) ){
@@ -203,11 +202,11 @@
203 @ File "%h(zName)" not found
204 return;
205 }
206 if( zType==0 ){
207 if( sqlite3_strglob("*.js", zName)==0 ){
208 zType = "application/javascript";
209 }else{
210 zType = mimetype_from_name(zName);
211 }
212 }
213 cgi_set_content_type(zType);
214
--- src/builtin.c
+++ src/builtin.c
@@ -130,20 +130,19 @@
130 blob_reset(&x);
131 }
132
133 /*
134 ** Input zList is a list of numeric identifiers for files in
135 ** aBuiltinFiles[]. Return the concatenation of all of those files
136 ** using mimetype zType, or as text/javascript if zType is 0.
 
137 */
138 static void builtin_deliver_multiple_js_files(
139 const char *zList, /* List of numeric identifiers */
140 const char *zType /* Override mimetype */
141 ){
142 Blob *pOut;
143 if( zType==0 ) zType = "text/javascript";
144 cgi_set_content_type(zType);
145 pOut = cgi_output_blob();
146 while( zList[0] ){
147 int i = atoi(zList);
148 if( i>0 && i<=count(aBuiltinFiles) ){
@@ -203,11 +202,11 @@
202 @ File "%h(zName)" not found
203 return;
204 }
205 if( zType==0 ){
206 if( sqlite3_strglob("*.js", zName)==0 ){
207 zType = "text/javascript";
208 }else{
209 zType = mimetype_from_name(zName);
210 }
211 }
212 cgi_set_content_type(zType);
213
+58 -12
--- src/cgi.c
+++ src/cgi.c
@@ -307,11 +307,11 @@
307307
if(!g.isHTTP) return /* e.g. JSON CLI mode, where g.zTop is not set */;
308308
else if( zPath==0 ){
309309
zPath = g.zTop;
310310
if( zPath[0]==0 ) zPath = "/";
311311
}
312
- if( g.zBaseURL!=0 && strncmp(g.zBaseURL, "https:", 6)==0 ){
312
+ if( g.zBaseURL!=0 && fossil_strncmp(g.zBaseURL, "https:", 6)==0 ){
313313
zSecure = " secure;";
314314
}
315315
if( lifetime!=0 ){
316316
blob_appendf(&extraHeader,
317317
"Set-Cookie: %s=%t; Path=%s; max-age=%d; HttpOnly; "
@@ -330,13 +330,37 @@
330330
** Return true if the response should be sent with Content-Encoding: gzip.
331331
*/
332332
static int is_gzippable(void){
333333
if( g.fNoHttpCompress ) return 0;
334334
if( strstr(PD("HTTP_ACCEPT_ENCODING", ""), "gzip")==0 ) return 0;
335
- return strncmp(zContentType, "text/", 5)==0
336
- || sqlite3_strglob("application/*xml", zContentType)==0
337
- || sqlite3_strglob("application/*javascript", zContentType)==0;
335
+ /* Maintenance note: this oddball structure is intended to make
336
+ ** adding new mimetypes to this list less of a performance hit than
337
+ ** doing a strcmp/glob over a growing set of compressible types. */
338
+ switch(zContentType ? *zContentType : 0){
339
+ case (int)'a':
340
+ if(0==fossil_strncmp("application/",zContentType,12)){
341
+ const char * z = &zContentType[12];
342
+ switch(*z){
343
+ case (int)'j':
344
+ return fossil_strcmp("javascript", z)==0
345
+ || fossil_strcmp("json", z)==0;
346
+ case (int)'w': return fossil_strcmp("wasm", z)==0;
347
+ case (int)'x':
348
+ return fossil_strcmp("x-tcl", z)==0
349
+ || fossil_strcmp("x-tar", z)==0;
350
+ default:
351
+ return sqlite3_strglob("*xml", z)==0;
352
+ }
353
+ }
354
+ break;
355
+ case (int)'i':
356
+ return fossil_strcmp(zContentType, "image/svg+xml")==0
357
+ || fossil_strcmp(zContentType, "image/vnd.microsoft.icon")==0;
358
+ case (int)'t':
359
+ return fossil_strncmp(zContentType, "text/", 5)==0;
360
+ }
361
+ return 0;
338362
}
339363
340364
341365
/*
342366
** The following routines read or write content from/to the wire for
@@ -419,10 +443,29 @@
419443
if( !g.httpUseSSL ){
420444
fflush(g.httpOut);
421445
}
422446
}
423447
448
+/*
449
+** Given a Content-Type value, returns a string suitable for appending
450
+** to the Content-Type header for adding (or not) the "; charset=..."
451
+** part. It returns an empty string for most types or if zContentType
452
+** is NULL.
453
+**
454
+** See forum post f60dece061c364d1 for the discussions which lead to
455
+** this. Previously we always appended the charset, but WASM loaders
456
+** are pedantic and refuse to load any responses which have a
457
+** charset. Also, adding a charset is not strictly appropriate for
458
+** most types (and not required for many others which may ostensibly
459
+** benefit from one, as detailed in that forum post).
460
+*/
461
+static const char * content_type_charset(const char *zContentType){
462
+ if(0==fossil_strncmp(zContentType,"text/",5)){
463
+ return "; charset=utf-8";
464
+ }
465
+ return "";
466
+}
424467
425468
/*
426469
** Generate the reply to a web request. The output might be an
427470
** full HTTP response, or a CGI response, depending on how things have
428471
** be set up.
@@ -493,11 +536,12 @@
493536
494537
/* Content intended for logged in users should only be cached in
495538
** the browser, not some shared location.
496539
*/
497540
if( iReplyStatus!=304 ) {
498
- blob_appendf(&hdr, "Content-Type: %s; charset=utf-8\r\n", zContentType);
541
+ blob_appendf(&hdr, "Content-Type: %s%s\r\n", zContentType,
542
+ content_type_charset(zContentType));
499543
if( fossil_strcmp(zContentType,"application/x-fossil")==0 ){
500544
cgi_combine_header_and_body();
501545
blob_compress(&cgiContent[0], &cgiContent[0]);
502546
}
503547
@@ -569,11 +613,12 @@
569613
int iStat,
570614
const char *zStat
571615
){
572616
char *zLocation;
573617
CGIDEBUG(("redirect to %s\n", zURL));
574
- if( strncmp(zURL,"http:",5)==0 || strncmp(zURL,"https:",6)==0 ){
618
+ if( fossil_strncmp(zURL,"http:",5)==0
619
+ || fossil_strncmp(zURL,"https:",6)==0 ){
575620
zLocation = mprintf("Location: %s\r\n", zURL);
576621
}else if( *zURL=='/' ){
577622
int n1 = (int)strlen(g.zBaseURL);
578623
int n2 = (int)strlen(g.zTop);
579624
if( g.zBaseURL[n1-1]=='/' ) zURL++;
@@ -653,11 +698,11 @@
653698
const char *zMethod = P("REQUEST_METHOD");
654699
if( zMethod==0 ) return 0;
655700
if( strcmp(zMethod,"POST")!=0 ) return 0;
656701
}
657702
nBase = (int)strlen(g.zBaseURL);
658
- if( strncmp(g.zBaseURL,zRef,nBase)!=0 ) return 0;
703
+ if( fossil_strncmp(g.zBaseURL,zRef,nBase)!=0 ) return 0;
659704
if( zRef[nBase]!=0 && zRef[nBase]!='/' ) return 0;
660705
return 1;
661706
}
662707
663708
/*
@@ -920,11 +965,12 @@
920965
int len = *pLen;
921966
int i;
922967
int nBoundary = strlen(zBoundary);
923968
*pnContent = len;
924969
for(i=0; i<len; i++){
925
- if( z[i]=='\n' && strncmp(zBoundary, &z[i+1], nBoundary)==0 ){
970
+ if( z[i]=='\n' && fossil_strncmp(zBoundary, &z[i+1],
971
+ nBoundary)==0 ){
926972
if( i>0 && z[i-1]=='\r' ) i--;
927973
z[i] = 0;
928974
*pnContent = i;
929975
i += nBoundary;
930976
break;
@@ -1348,11 +1394,11 @@
13481394
*/
13491395
void cgi_decode_post_parameters(void){
13501396
int len = blob_size(&g.cgiIn);
13511397
if( len==0 ) return;
13521398
if( fossil_strcmp(g.zContentType,"application/x-www-form-urlencoded")==0
1353
- || strncmp(g.zContentType,"multipart/form-data",19)==0
1399
+ || fossil_strncmp(g.zContentType,"multipart/form-data",19)==0
13541400
){
13551401
char *z = blob_str(&g.cgiIn);
13561402
cgi_trace(z);
13571403
if( g.zContentType[0]=='a' ){
13581404
add_param_list(z, '&');
@@ -2309,11 +2355,11 @@
23092355
}
23102356
break;
23112357
}
23122358
if( iPort>mxPort ){
23132359
if( mnPort==mxPort ){
2314
- fossil_fatal("unable to open listening socket on ports %d", mnPort);
2360
+ fossil_fatal("unable to open listening socket on port %d", mnPort);
23152361
}else{
23162362
fossil_fatal("unable to open listening socket on any"
23172363
" port in the range %d..%d", mnPort, mxPort);
23182364
}
23192365
}
@@ -2326,11 +2372,11 @@
23262372
if( zBrowser ){
23272373
assert( strstr(zBrowser,"%d")!=0 );
23282374
zBrowser = mprintf(zBrowser /*works-like:"%d"*/, iPort);
23292375
#if defined(__CYGWIN__)
23302376
/* On Cygwin, we can do better than "echo" */
2331
- if( strncmp(zBrowser, "echo ", 5)==0 ){
2377
+ if( fossil_strncmp(zBrowser, "echo ", 5)==0 ){
23322378
wchar_t *wUrl = fossil_utf8_to_unicode(zBrowser+5);
23332379
wUrl[wcslen(wUrl)-2] = 0; /* Strip terminating " &" */
23342380
if( (size_t)ShellExecuteW(0, L"open", wUrl, 0, 0, 1)<33 ){
23352381
fossil_warning("cannot start browser\n");
23362382
}
@@ -2486,11 +2532,11 @@
24862532
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec", 0};
24872533
if( 7==sscanf(zDate, "%3[A-Za-z], %d %3[A-Za-z] %d %d:%d:%d", zIgnore,
24882534
&mday, zMonth, &year, &hour, &min, &sec)){
24892535
if( year > 1900 ) year -= 1900;
24902536
for(mon=0; azMonths[mon]; mon++){
2491
- if( !strncmp( azMonths[mon], zMonth, 3 )){
2537
+ if( !fossil_strncmp( azMonths[mon], zMonth, 3 )){
24922538
int nDay;
24932539
int isLeapYr;
24942540
static int priorDays[] =
24952541
{ 0, 31, 59, 90,120,151,181,212,243,273,304,334 };
24962542
if( mon<0 ){
24972543
--- src/cgi.c
+++ src/cgi.c
@@ -307,11 +307,11 @@
307 if(!g.isHTTP) return /* e.g. JSON CLI mode, where g.zTop is not set */;
308 else if( zPath==0 ){
309 zPath = g.zTop;
310 if( zPath[0]==0 ) zPath = "/";
311 }
312 if( g.zBaseURL!=0 && strncmp(g.zBaseURL, "https:", 6)==0 ){
313 zSecure = " secure;";
314 }
315 if( lifetime!=0 ){
316 blob_appendf(&extraHeader,
317 "Set-Cookie: %s=%t; Path=%s; max-age=%d; HttpOnly; "
@@ -330,13 +330,37 @@
330 ** Return true if the response should be sent with Content-Encoding: gzip.
331 */
332 static int is_gzippable(void){
333 if( g.fNoHttpCompress ) return 0;
334 if( strstr(PD("HTTP_ACCEPT_ENCODING", ""), "gzip")==0 ) return 0;
335 return strncmp(zContentType, "text/", 5)==0
336 || sqlite3_strglob("application/*xml", zContentType)==0
337 || sqlite3_strglob("application/*javascript", zContentType)==0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
338 }
339
340
341 /*
342 ** The following routines read or write content from/to the wire for
@@ -419,10 +443,29 @@
419 if( !g.httpUseSSL ){
420 fflush(g.httpOut);
421 }
422 }
423
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
424
425 /*
426 ** Generate the reply to a web request. The output might be an
427 ** full HTTP response, or a CGI response, depending on how things have
428 ** be set up.
@@ -493,11 +536,12 @@
493
494 /* Content intended for logged in users should only be cached in
495 ** the browser, not some shared location.
496 */
497 if( iReplyStatus!=304 ) {
498 blob_appendf(&hdr, "Content-Type: %s; charset=utf-8\r\n", zContentType);
 
499 if( fossil_strcmp(zContentType,"application/x-fossil")==0 ){
500 cgi_combine_header_and_body();
501 blob_compress(&cgiContent[0], &cgiContent[0]);
502 }
503
@@ -569,11 +613,12 @@
569 int iStat,
570 const char *zStat
571 ){
572 char *zLocation;
573 CGIDEBUG(("redirect to %s\n", zURL));
574 if( strncmp(zURL,"http:",5)==0 || strncmp(zURL,"https:",6)==0 ){
 
575 zLocation = mprintf("Location: %s\r\n", zURL);
576 }else if( *zURL=='/' ){
577 int n1 = (int)strlen(g.zBaseURL);
578 int n2 = (int)strlen(g.zTop);
579 if( g.zBaseURL[n1-1]=='/' ) zURL++;
@@ -653,11 +698,11 @@
653 const char *zMethod = P("REQUEST_METHOD");
654 if( zMethod==0 ) return 0;
655 if( strcmp(zMethod,"POST")!=0 ) return 0;
656 }
657 nBase = (int)strlen(g.zBaseURL);
658 if( strncmp(g.zBaseURL,zRef,nBase)!=0 ) return 0;
659 if( zRef[nBase]!=0 && zRef[nBase]!='/' ) return 0;
660 return 1;
661 }
662
663 /*
@@ -920,11 +965,12 @@
920 int len = *pLen;
921 int i;
922 int nBoundary = strlen(zBoundary);
923 *pnContent = len;
924 for(i=0; i<len; i++){
925 if( z[i]=='\n' && strncmp(zBoundary, &z[i+1], nBoundary)==0 ){
 
926 if( i>0 && z[i-1]=='\r' ) i--;
927 z[i] = 0;
928 *pnContent = i;
929 i += nBoundary;
930 break;
@@ -1348,11 +1394,11 @@
1348 */
1349 void cgi_decode_post_parameters(void){
1350 int len = blob_size(&g.cgiIn);
1351 if( len==0 ) return;
1352 if( fossil_strcmp(g.zContentType,"application/x-www-form-urlencoded")==0
1353 || strncmp(g.zContentType,"multipart/form-data",19)==0
1354 ){
1355 char *z = blob_str(&g.cgiIn);
1356 cgi_trace(z);
1357 if( g.zContentType[0]=='a' ){
1358 add_param_list(z, '&');
@@ -2309,11 +2355,11 @@
2309 }
2310 break;
2311 }
2312 if( iPort>mxPort ){
2313 if( mnPort==mxPort ){
2314 fossil_fatal("unable to open listening socket on ports %d", mnPort);
2315 }else{
2316 fossil_fatal("unable to open listening socket on any"
2317 " port in the range %d..%d", mnPort, mxPort);
2318 }
2319 }
@@ -2326,11 +2372,11 @@
2326 if( zBrowser ){
2327 assert( strstr(zBrowser,"%d")!=0 );
2328 zBrowser = mprintf(zBrowser /*works-like:"%d"*/, iPort);
2329 #if defined(__CYGWIN__)
2330 /* On Cygwin, we can do better than "echo" */
2331 if( strncmp(zBrowser, "echo ", 5)==0 ){
2332 wchar_t *wUrl = fossil_utf8_to_unicode(zBrowser+5);
2333 wUrl[wcslen(wUrl)-2] = 0; /* Strip terminating " &" */
2334 if( (size_t)ShellExecuteW(0, L"open", wUrl, 0, 0, 1)<33 ){
2335 fossil_warning("cannot start browser\n");
2336 }
@@ -2486,11 +2532,11 @@
2486 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", 0};
2487 if( 7==sscanf(zDate, "%3[A-Za-z], %d %3[A-Za-z] %d %d:%d:%d", zIgnore,
2488 &mday, zMonth, &year, &hour, &min, &sec)){
2489 if( year > 1900 ) year -= 1900;
2490 for(mon=0; azMonths[mon]; mon++){
2491 if( !strncmp( azMonths[mon], zMonth, 3 )){
2492 int nDay;
2493 int isLeapYr;
2494 static int priorDays[] =
2495 { 0, 31, 59, 90,120,151,181,212,243,273,304,334 };
2496 if( mon<0 ){
2497
--- src/cgi.c
+++ src/cgi.c
@@ -307,11 +307,11 @@
307 if(!g.isHTTP) return /* e.g. JSON CLI mode, where g.zTop is not set */;
308 else if( zPath==0 ){
309 zPath = g.zTop;
310 if( zPath[0]==0 ) zPath = "/";
311 }
312 if( g.zBaseURL!=0 && fossil_strncmp(g.zBaseURL, "https:", 6)==0 ){
313 zSecure = " secure;";
314 }
315 if( lifetime!=0 ){
316 blob_appendf(&extraHeader,
317 "Set-Cookie: %s=%t; Path=%s; max-age=%d; HttpOnly; "
@@ -330,13 +330,37 @@
330 ** Return true if the response should be sent with Content-Encoding: gzip.
331 */
332 static int is_gzippable(void){
333 if( g.fNoHttpCompress ) return 0;
334 if( strstr(PD("HTTP_ACCEPT_ENCODING", ""), "gzip")==0 ) return 0;
335 /* Maintenance note: this oddball structure is intended to make
336 ** adding new mimetypes to this list less of a performance hit than
337 ** doing a strcmp/glob over a growing set of compressible types. */
338 switch(zContentType ? *zContentType : 0){
339 case (int)'a':
340 if(0==fossil_strncmp("application/",zContentType,12)){
341 const char * z = &zContentType[12];
342 switch(*z){
343 case (int)'j':
344 return fossil_strcmp("javascript", z)==0
345 || fossil_strcmp("json", z)==0;
346 case (int)'w': return fossil_strcmp("wasm", z)==0;
347 case (int)'x':
348 return fossil_strcmp("x-tcl", z)==0
349 || fossil_strcmp("x-tar", z)==0;
350 default:
351 return sqlite3_strglob("*xml", z)==0;
352 }
353 }
354 break;
355 case (int)'i':
356 return fossil_strcmp(zContentType, "image/svg+xml")==0
357 || fossil_strcmp(zContentType, "image/vnd.microsoft.icon")==0;
358 case (int)'t':
359 return fossil_strncmp(zContentType, "text/", 5)==0;
360 }
361 return 0;
362 }
363
364
365 /*
366 ** The following routines read or write content from/to the wire for
@@ -419,10 +443,29 @@
443 if( !g.httpUseSSL ){
444 fflush(g.httpOut);
445 }
446 }
447
448 /*
449 ** Given a Content-Type value, returns a string suitable for appending
450 ** to the Content-Type header for adding (or not) the "; charset=..."
451 ** part. It returns an empty string for most types or if zContentType
452 ** is NULL.
453 **
454 ** See forum post f60dece061c364d1 for the discussions which lead to
455 ** this. Previously we always appended the charset, but WASM loaders
456 ** are pedantic and refuse to load any responses which have a
457 ** charset. Also, adding a charset is not strictly appropriate for
458 ** most types (and not required for many others which may ostensibly
459 ** benefit from one, as detailed in that forum post).
460 */
461 static const char * content_type_charset(const char *zContentType){
462 if(0==fossil_strncmp(zContentType,"text/",5)){
463 return "; charset=utf-8";
464 }
465 return "";
466 }
467
468 /*
469 ** Generate the reply to a web request. The output might be an
470 ** full HTTP response, or a CGI response, depending on how things have
471 ** be set up.
@@ -493,11 +536,12 @@
536
537 /* Content intended for logged in users should only be cached in
538 ** the browser, not some shared location.
539 */
540 if( iReplyStatus!=304 ) {
541 blob_appendf(&hdr, "Content-Type: %s%s\r\n", zContentType,
542 content_type_charset(zContentType));
543 if( fossil_strcmp(zContentType,"application/x-fossil")==0 ){
544 cgi_combine_header_and_body();
545 blob_compress(&cgiContent[0], &cgiContent[0]);
546 }
547
@@ -569,11 +613,12 @@
613 int iStat,
614 const char *zStat
615 ){
616 char *zLocation;
617 CGIDEBUG(("redirect to %s\n", zURL));
618 if( fossil_strncmp(zURL,"http:",5)==0
619 || fossil_strncmp(zURL,"https:",6)==0 ){
620 zLocation = mprintf("Location: %s\r\n", zURL);
621 }else if( *zURL=='/' ){
622 int n1 = (int)strlen(g.zBaseURL);
623 int n2 = (int)strlen(g.zTop);
624 if( g.zBaseURL[n1-1]=='/' ) zURL++;
@@ -653,11 +698,11 @@
698 const char *zMethod = P("REQUEST_METHOD");
699 if( zMethod==0 ) return 0;
700 if( strcmp(zMethod,"POST")!=0 ) return 0;
701 }
702 nBase = (int)strlen(g.zBaseURL);
703 if( fossil_strncmp(g.zBaseURL,zRef,nBase)!=0 ) return 0;
704 if( zRef[nBase]!=0 && zRef[nBase]!='/' ) return 0;
705 return 1;
706 }
707
708 /*
@@ -920,11 +965,12 @@
965 int len = *pLen;
966 int i;
967 int nBoundary = strlen(zBoundary);
968 *pnContent = len;
969 for(i=0; i<len; i++){
970 if( z[i]=='\n' && fossil_strncmp(zBoundary, &z[i+1],
971 nBoundary)==0 ){
972 if( i>0 && z[i-1]=='\r' ) i--;
973 z[i] = 0;
974 *pnContent = i;
975 i += nBoundary;
976 break;
@@ -1348,11 +1394,11 @@
1394 */
1395 void cgi_decode_post_parameters(void){
1396 int len = blob_size(&g.cgiIn);
1397 if( len==0 ) return;
1398 if( fossil_strcmp(g.zContentType,"application/x-www-form-urlencoded")==0
1399 || fossil_strncmp(g.zContentType,"multipart/form-data",19)==0
1400 ){
1401 char *z = blob_str(&g.cgiIn);
1402 cgi_trace(z);
1403 if( g.zContentType[0]=='a' ){
1404 add_param_list(z, '&');
@@ -2309,11 +2355,11 @@
2355 }
2356 break;
2357 }
2358 if( iPort>mxPort ){
2359 if( mnPort==mxPort ){
2360 fossil_fatal("unable to open listening socket on port %d", mnPort);
2361 }else{
2362 fossil_fatal("unable to open listening socket on any"
2363 " port in the range %d..%d", mnPort, mxPort);
2364 }
2365 }
@@ -2326,11 +2372,11 @@
2372 if( zBrowser ){
2373 assert( strstr(zBrowser,"%d")!=0 );
2374 zBrowser = mprintf(zBrowser /*works-like:"%d"*/, iPort);
2375 #if defined(__CYGWIN__)
2376 /* On Cygwin, we can do better than "echo" */
2377 if( fossil_strncmp(zBrowser, "echo ", 5)==0 ){
2378 wchar_t *wUrl = fossil_utf8_to_unicode(zBrowser+5);
2379 wUrl[wcslen(wUrl)-2] = 0; /* Strip terminating " &" */
2380 if( (size_t)ShellExecuteW(0, L"open", wUrl, 0, 0, 1)<33 ){
2381 fossil_warning("cannot start browser\n");
2382 }
@@ -2486,11 +2532,11 @@
2532 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", 0};
2533 if( 7==sscanf(zDate, "%3[A-Za-z], %d %3[A-Za-z] %d %d:%d:%d", zIgnore,
2534 &mday, zMonth, &year, &hour, &min, &sec)){
2535 if( year > 1900 ) year -= 1900;
2536 for(mon=0; azMonths[mon]; mon++){
2537 if( !fossil_strncmp( azMonths[mon], zMonth, 3 )){
2538 int nDay;
2539 int isLeapYr;
2540 static int priorDays[] =
2541 { 0, 31, 59, 90,120,151,181,212,243,273,304,334 };
2542 if( mon<0 ){
2543
+12 -4
--- src/db.c
+++ src/db.c
@@ -3436,10 +3436,20 @@
34363436
void db_lset(const char *zName, const char *zValue){
34373437
db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%Q)", zName, zValue);
34383438
}
34393439
int db_lget_int(const char *zName, int dflt){
34403440
return db_int(dflt, "SELECT value FROM vvar WHERE name=%Q", zName);
3441
+}
3442
+int db_lget_boolean(const char *zName, int dflt){
3443
+ char *zVal = db_lget(zName, dflt ? "on" : "off");
3444
+ if( is_truth(zVal) ){
3445
+ dflt = 1;
3446
+ }else if( is_false(zVal) ){
3447
+ dflt = 0;
3448
+ }
3449
+ fossil_free(zVal);
3450
+ return dflt;
34413451
}
34423452
void db_lset_int(const char *zName, int value){
34433453
db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%d)", zName, value);
34443454
}
34453455
@@ -4368,14 +4378,12 @@
43684378
** which will cause the client to avoid generating a delta
43694379
** manifest.
43704380
*/
43714381
/*
43724382
** SETTING: proxy width=32 default=off
4373
-** URL of the HTTP proxy. If undefined or "off" then
4374
-** the "http_proxy" environment variable is consulted.
4375
-** If the http_proxy environment variable is undefined
4376
-** then a direct HTTP connection is used.
4383
+** URL of the HTTP proxy. If "system", the "http_proxy" environment variable is
4384
+** consulted. If undefined or "off", a direct HTTP connection is used.
43774385
*/
43784386
/*
43794387
** SETTING: redirect-to-https default=0 width=-1
43804388
** Specifies whether or not to redirect http:// requests to
43814389
** https:// URIs. A value of 0 (the default) means not to
43824390
--- src/db.c
+++ src/db.c
@@ -3436,10 +3436,20 @@
3436 void db_lset(const char *zName, const char *zValue){
3437 db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%Q)", zName, zValue);
3438 }
3439 int db_lget_int(const char *zName, int dflt){
3440 return db_int(dflt, "SELECT value FROM vvar WHERE name=%Q", zName);
 
 
 
 
 
 
 
 
 
 
3441 }
3442 void db_lset_int(const char *zName, int value){
3443 db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%d)", zName, value);
3444 }
3445
@@ -4368,14 +4378,12 @@
4368 ** which will cause the client to avoid generating a delta
4369 ** manifest.
4370 */
4371 /*
4372 ** SETTING: proxy width=32 default=off
4373 ** URL of the HTTP proxy. If undefined or "off" then
4374 ** the "http_proxy" environment variable is consulted.
4375 ** If the http_proxy environment variable is undefined
4376 ** then a direct HTTP connection is used.
4377 */
4378 /*
4379 ** SETTING: redirect-to-https default=0 width=-1
4380 ** Specifies whether or not to redirect http:// requests to
4381 ** https:// URIs. A value of 0 (the default) means not to
4382
--- src/db.c
+++ src/db.c
@@ -3436,10 +3436,20 @@
3436 void db_lset(const char *zName, const char *zValue){
3437 db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%Q)", zName, zValue);
3438 }
3439 int db_lget_int(const char *zName, int dflt){
3440 return db_int(dflt, "SELECT value FROM vvar WHERE name=%Q", zName);
3441 }
3442 int db_lget_boolean(const char *zName, int dflt){
3443 char *zVal = db_lget(zName, dflt ? "on" : "off");
3444 if( is_truth(zVal) ){
3445 dflt = 1;
3446 }else if( is_false(zVal) ){
3447 dflt = 0;
3448 }
3449 fossil_free(zVal);
3450 return dflt;
3451 }
3452 void db_lset_int(const char *zName, int value){
3453 db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%d)", zName, value);
3454 }
3455
@@ -4368,14 +4378,12 @@
4378 ** which will cause the client to avoid generating a delta
4379 ** manifest.
4380 */
4381 /*
4382 ** SETTING: proxy width=32 default=off
4383 ** URL of the HTTP proxy. If "system", the "http_proxy" environment variable is
4384 ** consulted. If undefined or "off", a direct HTTP connection is used.
 
 
4385 */
4386 /*
4387 ** SETTING: redirect-to-https default=0 width=-1
4388 ** Specifies whether or not to redirect http:// requests to
4389 ** https:// URIs. A value of 0 (the default) means not to
4390
+14 -6
--- src/default.css
+++ src/default.css
@@ -1007,10 +1007,13 @@
10071007
background-color: #ffb;
10081008
}
10091009
label {
10101010
white-space: nowrap;
10111011
}
1012
+label[for] {
1013
+ cursor: pointer;
1014
+}
10121015
.copy-button {
10131016
display: inline-block;
10141017
width: 14px;
10151018
height: 14px;
10161019
/*Note: .24em is slightly smaller than the average width of a normal space.*/
@@ -1075,16 +1078,21 @@
10751078
}
10761079
.warning {
10771080
color: black;
10781081
background: yellow;
10791082
}
1080
-.hidden {
1081
- /* The framework-wide way of hiding elements is to assign them this
1082
- CSS class. To make them visible again, remove it. The !important
1083
- qualifiers are unfortunate but sometimes necessary when hidden
1084
- element has other classes which specify visibility-related
1085
- options. */
1083
+.hidden, .initially-hidden {
1084
+ /* The framework-wide way of hiding elements is to assign them th
1085
+ .hidden class. To make them visible again, remove it. The
1086
+ !important qualifiers are unfortunate but sometimes necessary
1087
+ when hidden element has other classes which specify
1088
+ visibility-related options. The .initially-hidden class is for
1089
+ pages which need to show, e.g., a progress widget while a large
1090
+ WASM blob loads. Elements aside from that load-time widget can be
1091
+ made .initially-hidden and then have that class removed once the
1092
+ long-running startup process is done. See /pikchrshow for an
1093
+ example. */
10861094
position: absolute !important;
10871095
opacity: 0 !important;
10881096
pointer-events: none !important;
10891097
display: none !important;
10901098
}
10911099
--- src/default.css
+++ src/default.css
@@ -1007,10 +1007,13 @@
1007 background-color: #ffb;
1008 }
1009 label {
1010 white-space: nowrap;
1011 }
 
 
 
1012 .copy-button {
1013 display: inline-block;
1014 width: 14px;
1015 height: 14px;
1016 /*Note: .24em is slightly smaller than the average width of a normal space.*/
@@ -1075,16 +1078,21 @@
1075 }
1076 .warning {
1077 color: black;
1078 background: yellow;
1079 }
1080 .hidden {
1081 /* The framework-wide way of hiding elements is to assign them this
1082 CSS class. To make them visible again, remove it. The !important
1083 qualifiers are unfortunate but sometimes necessary when hidden
1084 element has other classes which specify visibility-related
1085 options. */
 
 
 
 
 
1086 position: absolute !important;
1087 opacity: 0 !important;
1088 pointer-events: none !important;
1089 display: none !important;
1090 }
1091
--- src/default.css
+++ src/default.css
@@ -1007,10 +1007,13 @@
1007 background-color: #ffb;
1008 }
1009 label {
1010 white-space: nowrap;
1011 }
1012 label[for] {
1013 cursor: pointer;
1014 }
1015 .copy-button {
1016 display: inline-block;
1017 width: 14px;
1018 height: 14px;
1019 /*Note: .24em is slightly smaller than the average width of a normal space.*/
@@ -1075,16 +1078,21 @@
1078 }
1079 .warning {
1080 color: black;
1081 background: yellow;
1082 }
1083 .hidden, .initially-hidden {
1084 /* The framework-wide way of hiding elements is to assign them th
1085 .hidden class. To make them visible again, remove it. The
1086 !important qualifiers are unfortunate but sometimes necessary
1087 when hidden element has other classes which specify
1088 visibility-related options. The .initially-hidden class is for
1089 pages which need to show, e.g., a progress widget while a large
1090 WASM blob loads. Elements aside from that load-time widget can be
1091 made .initially-hidden and then have that class removed once the
1092 long-running startup process is done. See /pikchrshow for an
1093 example. */
1094 position: absolute !important;
1095 opacity: 0 !important;
1096 pointer-events: none !important;
1097 display: none !important;
1098 }
1099
-19
--- src/diff.c
+++ src/diff.c
@@ -2211,11 +2211,10 @@
22112211
unsigned int b = 0; /* Index of next line in B[] */
22122212
const int *R; /* Array of COPY/DELETE/INSERT triples */
22132213
unsigned int r; /* Index into R[] */
22142214
unsigned int nr; /* Number of COPY/DELETE/INSERT triples to process */
22152215
unsigned int mxr; /* Maximum value for r */
2216
- unsigned int na, nb; /* Number of lines shown from A and B */
22172216
unsigned int i, j; /* Loop counters */
22182217
unsigned int m, ma, mb;/* Number of lines to output */
22192218
signed int skip = 0; /* Number of lines to skip */
22202219
unsigned int nContext; /* Lines of context above and below each change */
22212220
@@ -2257,32 +2256,14 @@
22572256
22582257
/* Figure out how many lines of A and B are to be displayed
22592258
** for this change block.
22602259
*/
22612260
if( R[r]>nContext ){
2262
- na = nb = nContext;
22632261
skip = R[r] - nContext;
22642262
}else{
2265
- na = nb = R[r];
22662263
skip = 0;
22672264
}
2268
- for(i=0; i<nr; i++){
2269
- na += R[r+i*3+1];
2270
- nb += R[r+i*3+2];
2271
- }
2272
- if( R[r+nr*3]>nContext ){
2273
- na += nContext;
2274
- nb += nContext;
2275
- }else{
2276
- na += R[r+nr*3];
2277
- nb += R[r+nr*3];
2278
- }
2279
- for(i=1; i<nr; i++){
2280
- na += R[r+i*3];
2281
- nb += R[r+i*3];
2282
- }
2283
-
22842265
/* Show the initial common area */
22852266
a += skip;
22862267
b += skip;
22872268
m = R[r] - skip;
22882269
if( r ) skip -= nContext;
22892270
--- src/diff.c
+++ src/diff.c
@@ -2211,11 +2211,10 @@
2211 unsigned int b = 0; /* Index of next line in B[] */
2212 const int *R; /* Array of COPY/DELETE/INSERT triples */
2213 unsigned int r; /* Index into R[] */
2214 unsigned int nr; /* Number of COPY/DELETE/INSERT triples to process */
2215 unsigned int mxr; /* Maximum value for r */
2216 unsigned int na, nb; /* Number of lines shown from A and B */
2217 unsigned int i, j; /* Loop counters */
2218 unsigned int m, ma, mb;/* Number of lines to output */
2219 signed int skip = 0; /* Number of lines to skip */
2220 unsigned int nContext; /* Lines of context above and below each change */
2221
@@ -2257,32 +2256,14 @@
2257
2258 /* Figure out how many lines of A and B are to be displayed
2259 ** for this change block.
2260 */
2261 if( R[r]>nContext ){
2262 na = nb = nContext;
2263 skip = R[r] - nContext;
2264 }else{
2265 na = nb = R[r];
2266 skip = 0;
2267 }
2268 for(i=0; i<nr; i++){
2269 na += R[r+i*3+1];
2270 nb += R[r+i*3+2];
2271 }
2272 if( R[r+nr*3]>nContext ){
2273 na += nContext;
2274 nb += nContext;
2275 }else{
2276 na += R[r+nr*3];
2277 nb += R[r+nr*3];
2278 }
2279 for(i=1; i<nr; i++){
2280 na += R[r+i*3];
2281 nb += R[r+i*3];
2282 }
2283
2284 /* Show the initial common area */
2285 a += skip;
2286 b += skip;
2287 m = R[r] - skip;
2288 if( r ) skip -= nContext;
2289
--- src/diff.c
+++ src/diff.c
@@ -2211,11 +2211,10 @@
2211 unsigned int b = 0; /* Index of next line in B[] */
2212 const int *R; /* Array of COPY/DELETE/INSERT triples */
2213 unsigned int r; /* Index into R[] */
2214 unsigned int nr; /* Number of COPY/DELETE/INSERT triples to process */
2215 unsigned int mxr; /* Maximum value for r */
 
2216 unsigned int i, j; /* Loop counters */
2217 unsigned int m, ma, mb;/* Number of lines to output */
2218 signed int skip = 0; /* Number of lines to skip */
2219 unsigned int nContext; /* Lines of context above and below each change */
2220
@@ -2257,32 +2256,14 @@
2256
2257 /* Figure out how many lines of A and B are to be displayed
2258 ** for this change block.
2259 */
2260 if( R[r]>nContext ){
 
2261 skip = R[r] - nContext;
2262 }else{
 
2263 skip = 0;
2264 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2265 /* Show the initial common area */
2266 a += skip;
2267 b += skip;
2268 m = R[r] - skip;
2269 if( r ) skip -= nContext;
2270
+8 -1
--- src/doc.c
+++ src/doc.c
@@ -156,11 +156,16 @@
156156
{ "jad", 3, "text/vnd.sun.j2me.app-descriptor" },
157157
{ "jar", 3, "application/java-archive" },
158158
{ "jpe", 3, "image/jpeg" },
159159
{ "jpeg", 4, "image/jpeg" },
160160
{ "jpg", 3, "image/jpeg" },
161
- { "js", 2, "application/javascript" },
161
+ { "js", 2, "text/javascript" },
162
+ /* application/javascript is commonly used for JS, but the
163
+ ** spec says text/javascript is correct:
164
+ ** https://html.spec.whatwg.org/multipage/scripting.html
165
+ ** #scriptingLanguages:javascript-mime-type */
166
+ { "json", 4, "application/json" },
162167
{ "kar", 3, "audio/midi" },
163168
{ "latex", 5, "application/x-latex" },
164169
{ "lha", 3, "application/octet-stream" },
165170
{ "lsp", 3, "application/x-lisp" },
166171
{ "lzh", 3, "application/octet-stream" },
@@ -173,10 +178,11 @@
173178
{ "mesh", 4, "model/mesh" },
174179
{ "mid", 3, "audio/midi" },
175180
{ "midi", 4, "audio/midi" },
176181
{ "mif", 3, "application/x-mif" },
177182
{ "mime", 4, "www/mime" },
183
+ { "mjs", 3, "text/javascript" /*EM6 modules*/ },
178184
{ "mkd", 3, "text/x-markdown" },
179185
{ "mov", 3, "video/quicktime" },
180186
{ "movie", 5, "video/x-sgi-movie" },
181187
{ "mp2", 3, "audio/mpeg" },
182188
{ "mp3", 3, "audio/mpeg" },
@@ -277,10 +283,11 @@
277283
{ "vcd", 3, "application/x-cdlink" },
278284
{ "vda", 3, "application/vda" },
279285
{ "viv", 3, "video/vnd.vivo" },
280286
{ "vivo", 4, "video/vnd.vivo" },
281287
{ "vrml", 4, "model/vrml" },
288
+ { "wasm", 4, "application/wasm" },
282289
{ "wav", 3, "audio/x-wav" },
283290
{ "wax", 3, "audio/x-ms-wax" },
284291
{ "webp", 4, "image/webp" },
285292
{ "wiki", 4, "text/x-fossil-wiki" },
286293
{ "wma", 3, "audio/x-ms-wma" },
287294
--- src/doc.c
+++ src/doc.c
@@ -156,11 +156,16 @@
156 { "jad", 3, "text/vnd.sun.j2me.app-descriptor" },
157 { "jar", 3, "application/java-archive" },
158 { "jpe", 3, "image/jpeg" },
159 { "jpeg", 4, "image/jpeg" },
160 { "jpg", 3, "image/jpeg" },
161 { "js", 2, "application/javascript" },
 
 
 
 
 
162 { "kar", 3, "audio/midi" },
163 { "latex", 5, "application/x-latex" },
164 { "lha", 3, "application/octet-stream" },
165 { "lsp", 3, "application/x-lisp" },
166 { "lzh", 3, "application/octet-stream" },
@@ -173,10 +178,11 @@
173 { "mesh", 4, "model/mesh" },
174 { "mid", 3, "audio/midi" },
175 { "midi", 4, "audio/midi" },
176 { "mif", 3, "application/x-mif" },
177 { "mime", 4, "www/mime" },
 
178 { "mkd", 3, "text/x-markdown" },
179 { "mov", 3, "video/quicktime" },
180 { "movie", 5, "video/x-sgi-movie" },
181 { "mp2", 3, "audio/mpeg" },
182 { "mp3", 3, "audio/mpeg" },
@@ -277,10 +283,11 @@
277 { "vcd", 3, "application/x-cdlink" },
278 { "vda", 3, "application/vda" },
279 { "viv", 3, "video/vnd.vivo" },
280 { "vivo", 4, "video/vnd.vivo" },
281 { "vrml", 4, "model/vrml" },
 
282 { "wav", 3, "audio/x-wav" },
283 { "wax", 3, "audio/x-ms-wax" },
284 { "webp", 4, "image/webp" },
285 { "wiki", 4, "text/x-fossil-wiki" },
286 { "wma", 3, "audio/x-ms-wma" },
287
--- src/doc.c
+++ src/doc.c
@@ -156,11 +156,16 @@
156 { "jad", 3, "text/vnd.sun.j2me.app-descriptor" },
157 { "jar", 3, "application/java-archive" },
158 { "jpe", 3, "image/jpeg" },
159 { "jpeg", 4, "image/jpeg" },
160 { "jpg", 3, "image/jpeg" },
161 { "js", 2, "text/javascript" },
162 /* application/javascript is commonly used for JS, but the
163 ** spec says text/javascript is correct:
164 ** https://html.spec.whatwg.org/multipage/scripting.html
165 ** #scriptingLanguages:javascript-mime-type */
166 { "json", 4, "application/json" },
167 { "kar", 3, "audio/midi" },
168 { "latex", 5, "application/x-latex" },
169 { "lha", 3, "application/octet-stream" },
170 { "lsp", 3, "application/x-lisp" },
171 { "lzh", 3, "application/octet-stream" },
@@ -173,10 +178,11 @@
178 { "mesh", 4, "model/mesh" },
179 { "mid", 3, "audio/midi" },
180 { "midi", 4, "audio/midi" },
181 { "mif", 3, "application/x-mif" },
182 { "mime", 4, "www/mime" },
183 { "mjs", 3, "text/javascript" /*EM6 modules*/ },
184 { "mkd", 3, "text/x-markdown" },
185 { "mov", 3, "video/quicktime" },
186 { "movie", 5, "video/x-sgi-movie" },
187 { "mp2", 3, "audio/mpeg" },
188 { "mp3", 3, "audio/mpeg" },
@@ -277,10 +283,11 @@
283 { "vcd", 3, "application/x-cdlink" },
284 { "vda", 3, "application/vda" },
285 { "viv", 3, "video/vnd.vivo" },
286 { "vivo", 4, "video/vnd.vivo" },
287 { "vrml", 4, "model/vrml" },
288 { "wasm", 4, "application/wasm" },
289 { "wav", 3, "audio/x-wav" },
290 { "wax", 3, "audio/x-ms-wax" },
291 { "webp", 4, "image/webp" },
292 { "wiki", 4, "text/x-fossil-wiki" },
293 { "wma", 3, "audio/x-ms-wma" },
294
--- src/fossil.copybutton.js
+++ src/fossil.copybutton.js
@@ -17,13 +17,10 @@
1717
1818
.copyFromElement: DOM element
1919
2020
.copyFromId: DOM element ID
2121
22
- One of copyFromElement or copyFromId must be provided, but copyFromId
23
- may optionally be provided via e.dataset.copyFromId.
24
-
2522
.extractText: optional callback which is triggered when the copy
2623
button is clicked. It must return the text to copy to the
2724
clipboard. The default is to extract it from the copy-from
2825
element, using its [value] member, if it has one, else its
2926
[innerText]. A client-provided callback may use any data source
@@ -30,10 +27,15 @@
3027
it likes, so long as it's synchronous. If this function returns a
3128
falsy value then the clipboard is not modified. This function is
3229
called with the fully expanded/resolved options object as its
3330
"this" (that's a different instance than the one passed to this
3431
function!).
32
+
33
+ At least one of copyFromElement, copyFromId, or extractText must
34
+ be provided, but if copyFromId is not set and e.dataset.copyFromId
35
+ is then that value is used in its place. extractText() trumps the
36
+ other two options.
3537
3638
.cssClass: optional CSS class, or list of classes, to apply to e.
3739
3840
.style: optional object of properties to copy directly into
3941
e.style.
4042
--- src/fossil.copybutton.js
+++ src/fossil.copybutton.js
@@ -17,13 +17,10 @@
17
18 .copyFromElement: DOM element
19
20 .copyFromId: DOM element ID
21
22 One of copyFromElement or copyFromId must be provided, but copyFromId
23 may optionally be provided via e.dataset.copyFromId.
24
25 .extractText: optional callback which is triggered when the copy
26 button is clicked. It must return the text to copy to the
27 clipboard. The default is to extract it from the copy-from
28 element, using its [value] member, if it has one, else its
29 [innerText]. A client-provided callback may use any data source
@@ -30,10 +27,15 @@
30 it likes, so long as it's synchronous. If this function returns a
31 falsy value then the clipboard is not modified. This function is
32 called with the fully expanded/resolved options object as its
33 "this" (that's a different instance than the one passed to this
34 function!).
 
 
 
 
 
35
36 .cssClass: optional CSS class, or list of classes, to apply to e.
37
38 .style: optional object of properties to copy directly into
39 e.style.
40
--- src/fossil.copybutton.js
+++ src/fossil.copybutton.js
@@ -17,13 +17,10 @@
17
18 .copyFromElement: DOM element
19
20 .copyFromId: DOM element ID
21
 
 
 
22 .extractText: optional callback which is triggered when the copy
23 button is clicked. It must return the text to copy to the
24 clipboard. The default is to extract it from the copy-from
25 element, using its [value] member, if it has one, else its
26 [innerText]. A client-provided callback may use any data source
@@ -30,10 +27,15 @@
27 it likes, so long as it's synchronous. If this function returns a
28 falsy value then the clipboard is not modified. This function is
29 called with the fully expanded/resolved options object as its
30 "this" (that's a different instance than the one passed to this
31 function!).
32
33 At least one of copyFromElement, copyFromId, or extractText must
34 be provided, but if copyFromId is not set and e.dataset.copyFromId
35 is then that value is used in its place. extractText() trumps the
36 other two options.
37
38 .cssClass: optional CSS class, or list of classes, to apply to e.
39
40 .style: optional object of properties to copy directly into
41 e.style.
42
--- src/fossil.page.chat.js
+++ src/fossil.page.chat.js
@@ -795,10 +795,15 @@
795795
}
796796
if(!e || !id) return false;
797797
else if(e.$isToggling) return;
798798
e.$isToggling = true;
799799
const content = e.querySelector('.content-target');
800
+ if(!content){
801
+ console.warn("Should not be possible: trying to toggle text",
802
+ "mode of a message with no .content-target.", e);
803
+ return;
804
+ }
800805
if(!content.$elems){
801806
content.$elems = [
802807
content.firstElementChild, // parsed elem
803808
undefined // plaintext elem
804809
];
@@ -807,21 +812,39 @@
807812
const child = (
808813
content.firstElementChild===content.$elems[0]
809814
? content.$elems[1]
810815
: content.$elems[0]
811816
);
817
+ D.clearElement(content);
818
+ if(child===content.$elems[1]){
819
+ /* When showing the unformatted version, inject a
820
+ copy-to-clipboard button. This is a workaround for
821
+ mouse-copying from that field collecting twice as many
822
+ newlines as it should (for unknown reasons). */
823
+ const cpId = 'copy-to-clipboard-'+id;
824
+ /* ^^^ copy button element ID, needed for LABEL element
825
+ pairing. Recall that we destroy all child elements of
826
+ `content` each time we hit this block, so we can reuse
827
+ that element ID on subsequent toggles. */
828
+ const btnCp = D.attr(D.addClass(D.span(),'copy-button'), 'id', cpId);
829
+ F.copyButton(btnCp, {extractText: ()=>child._xmsgRaw});
830
+ const lblCp = D.label(cpId, "Copy unformatted text");
831
+ lblCp.addEventListener('click',()=>btnCp.click(), false);
832
+ D.append(content, D.append(D.addClass(D.span(), 'nobr'), btnCp, lblCp));
833
+ }
812834
delete e.$isToggling;
813
- D.append(D.clearElement(content), child);
835
+ D.append(content, child);
814836
return;
815837
}
816838
// We need to fetch the plain-text version...
817839
const self = this;
818840
F.fetch('chat-fetch-one',{
819841
urlParams:{ name: id, raw: true},
820842
responseType: 'json',
821843
onload: function(msg){
822844
content.$elems[1] = D.append(D.pre(),msg.xmsg);
845
+ content.$elems[1]._xmsgRaw = msg.xmsg/*used for copy-to-clipboard feature*/;
823846
self.toggleTextMode(e);
824847
},
825848
aftersend:function(){
826849
delete e.$isToggling;
827850
Chat.ajaxEnd();
@@ -1313,15 +1336,19 @@
13131336
eMsg.scrollIntoView();
13141337
}
13151338
));
13161339
const toolbar2 = D.addClass(D.div(), 'toolbar');
13171340
D.append(this.e, toolbar2);
1318
- D.append(toolbar2, D.button(
1319
- "Toggle text mode", function(){
1320
- self.hide();
1321
- Chat.toggleTextMode(eMsg);
1322
- }));
1341
+ if(eMsg.querySelector('.content-target')){
1342
+ /* ^^^ messages with only an embedded image have no
1343
+ .content-target area. */
1344
+ D.append(toolbar2, D.button(
1345
+ "Toggle text mode", function(){
1346
+ self.hide();
1347
+ Chat.toggleTextMode(eMsg);
1348
+ }));
1349
+ }
13231350
if(eMsg.dataset.xfrom){
13241351
/* Add a link to the /timeline filtered on this user. */
13251352
const timelineLink = D.attr(
13261353
D.a(F.repoUrl('timeline',{
13271354
u: eMsg.dataset.xfrom,
@@ -1530,29 +1557,35 @@
15301557
*/
15311558
Chat.submitMessage = function f(){
15321559
if(!f.spaces){
15331560
f.spaces = /\s+$/;
15341561
f.markdownContinuation = /\\\s+$/;
1562
+ f.spaces2 = /\s{3,}$/;
15351563
}
15361564
this.setCurrentView(this.e.viewMessages);
15371565
const fd = new FormData();
15381566
const fallback = {msg: this.inputValue()};
1539
- var msg = fallback.msg.trim();
1567
+ var msg = fallback.msg;
15401568
if(msg && (msg.indexOf('\n')>0 || f.spaces.test(msg))){
1541
- /* Cosmetic: trim whitespace from the ends of lines to try to
1569
+ /* Cosmetic: trim most whitespace from the ends of lines to try to
15421570
keep copy/paste from terminals, especially wide ones, from
15431571
forcing a horizontal scrollbar on all clients. This breaks
15441572
markdown's use of blackslash-space-space for paragraph
15451573
continuation, but *not* doing this affects all clients every
15461574
time someone pastes in console copy/paste from an affected
15471575
platform. We seem to have narrowed to the console pasting
1548
- problem to users of tmux. Most consoles don't behave
1549
- that way. */
1576
+ problem to users of tmux together with certain apps (vim, at
1577
+ a minimum). Most consoles don't behave that way.
1578
+
1579
+ We retain two trailing spaces so that markdown conventions
1580
+ which use end-of-line spacing aren't broken by this
1581
+ stripping.
1582
+ */
15501583
const xmsg = msg.split('\n');
15511584
xmsg.forEach(function(line,ndx){
15521585
if(!f.markdownContinuation.test(line)){
1553
- xmsg[ndx] = line.trimRight();
1586
+ xmsg[ndx] = line.replace(f.spaces2, ' ');
15541587
}
15551588
});
15561589
msg = xmsg.join('\n');
15571590
}
15581591
if(msg) fd.set('msg',msg);
15591592
--- src/fossil.page.chat.js
+++ src/fossil.page.chat.js
@@ -795,10 +795,15 @@
795 }
796 if(!e || !id) return false;
797 else if(e.$isToggling) return;
798 e.$isToggling = true;
799 const content = e.querySelector('.content-target');
 
 
 
 
 
800 if(!content.$elems){
801 content.$elems = [
802 content.firstElementChild, // parsed elem
803 undefined // plaintext elem
804 ];
@@ -807,21 +812,39 @@
807 const child = (
808 content.firstElementChild===content.$elems[0]
809 ? content.$elems[1]
810 : content.$elems[0]
811 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
812 delete e.$isToggling;
813 D.append(D.clearElement(content), child);
814 return;
815 }
816 // We need to fetch the plain-text version...
817 const self = this;
818 F.fetch('chat-fetch-one',{
819 urlParams:{ name: id, raw: true},
820 responseType: 'json',
821 onload: function(msg){
822 content.$elems[1] = D.append(D.pre(),msg.xmsg);
 
823 self.toggleTextMode(e);
824 },
825 aftersend:function(){
826 delete e.$isToggling;
827 Chat.ajaxEnd();
@@ -1313,15 +1336,19 @@
1313 eMsg.scrollIntoView();
1314 }
1315 ));
1316 const toolbar2 = D.addClass(D.div(), 'toolbar');
1317 D.append(this.e, toolbar2);
1318 D.append(toolbar2, D.button(
1319 "Toggle text mode", function(){
1320 self.hide();
1321 Chat.toggleTextMode(eMsg);
1322 }));
 
 
 
 
1323 if(eMsg.dataset.xfrom){
1324 /* Add a link to the /timeline filtered on this user. */
1325 const timelineLink = D.attr(
1326 D.a(F.repoUrl('timeline',{
1327 u: eMsg.dataset.xfrom,
@@ -1530,29 +1557,35 @@
1530 */
1531 Chat.submitMessage = function f(){
1532 if(!f.spaces){
1533 f.spaces = /\s+$/;
1534 f.markdownContinuation = /\\\s+$/;
 
1535 }
1536 this.setCurrentView(this.e.viewMessages);
1537 const fd = new FormData();
1538 const fallback = {msg: this.inputValue()};
1539 var msg = fallback.msg.trim();
1540 if(msg && (msg.indexOf('\n')>0 || f.spaces.test(msg))){
1541 /* Cosmetic: trim whitespace from the ends of lines to try to
1542 keep copy/paste from terminals, especially wide ones, from
1543 forcing a horizontal scrollbar on all clients. This breaks
1544 markdown's use of blackslash-space-space for paragraph
1545 continuation, but *not* doing this affects all clients every
1546 time someone pastes in console copy/paste from an affected
1547 platform. We seem to have narrowed to the console pasting
1548 problem to users of tmux. Most consoles don't behave
1549 that way. */
 
 
 
 
 
1550 const xmsg = msg.split('\n');
1551 xmsg.forEach(function(line,ndx){
1552 if(!f.markdownContinuation.test(line)){
1553 xmsg[ndx] = line.trimRight();
1554 }
1555 });
1556 msg = xmsg.join('\n');
1557 }
1558 if(msg) fd.set('msg',msg);
1559
--- src/fossil.page.chat.js
+++ src/fossil.page.chat.js
@@ -795,10 +795,15 @@
795 }
796 if(!e || !id) return false;
797 else if(e.$isToggling) return;
798 e.$isToggling = true;
799 const content = e.querySelector('.content-target');
800 if(!content){
801 console.warn("Should not be possible: trying to toggle text",
802 "mode of a message with no .content-target.", e);
803 return;
804 }
805 if(!content.$elems){
806 content.$elems = [
807 content.firstElementChild, // parsed elem
808 undefined // plaintext elem
809 ];
@@ -807,21 +812,39 @@
812 const child = (
813 content.firstElementChild===content.$elems[0]
814 ? content.$elems[1]
815 : content.$elems[0]
816 );
817 D.clearElement(content);
818 if(child===content.$elems[1]){
819 /* When showing the unformatted version, inject a
820 copy-to-clipboard button. This is a workaround for
821 mouse-copying from that field collecting twice as many
822 newlines as it should (for unknown reasons). */
823 const cpId = 'copy-to-clipboard-'+id;
824 /* ^^^ copy button element ID, needed for LABEL element
825 pairing. Recall that we destroy all child elements of
826 `content` each time we hit this block, so we can reuse
827 that element ID on subsequent toggles. */
828 const btnCp = D.attr(D.addClass(D.span(),'copy-button'), 'id', cpId);
829 F.copyButton(btnCp, {extractText: ()=>child._xmsgRaw});
830 const lblCp = D.label(cpId, "Copy unformatted text");
831 lblCp.addEventListener('click',()=>btnCp.click(), false);
832 D.append(content, D.append(D.addClass(D.span(), 'nobr'), btnCp, lblCp));
833 }
834 delete e.$isToggling;
835 D.append(content, child);
836 return;
837 }
838 // We need to fetch the plain-text version...
839 const self = this;
840 F.fetch('chat-fetch-one',{
841 urlParams:{ name: id, raw: true},
842 responseType: 'json',
843 onload: function(msg){
844 content.$elems[1] = D.append(D.pre(),msg.xmsg);
845 content.$elems[1]._xmsgRaw = msg.xmsg/*used for copy-to-clipboard feature*/;
846 self.toggleTextMode(e);
847 },
848 aftersend:function(){
849 delete e.$isToggling;
850 Chat.ajaxEnd();
@@ -1313,15 +1336,19 @@
1336 eMsg.scrollIntoView();
1337 }
1338 ));
1339 const toolbar2 = D.addClass(D.div(), 'toolbar');
1340 D.append(this.e, toolbar2);
1341 if(eMsg.querySelector('.content-target')){
1342 /* ^^^ messages with only an embedded image have no
1343 .content-target area. */
1344 D.append(toolbar2, D.button(
1345 "Toggle text mode", function(){
1346 self.hide();
1347 Chat.toggleTextMode(eMsg);
1348 }));
1349 }
1350 if(eMsg.dataset.xfrom){
1351 /* Add a link to the /timeline filtered on this user. */
1352 const timelineLink = D.attr(
1353 D.a(F.repoUrl('timeline',{
1354 u: eMsg.dataset.xfrom,
@@ -1530,29 +1557,35 @@
1557 */
1558 Chat.submitMessage = function f(){
1559 if(!f.spaces){
1560 f.spaces = /\s+$/;
1561 f.markdownContinuation = /\\\s+$/;
1562 f.spaces2 = /\s{3,}$/;
1563 }
1564 this.setCurrentView(this.e.viewMessages);
1565 const fd = new FormData();
1566 const fallback = {msg: this.inputValue()};
1567 var msg = fallback.msg;
1568 if(msg && (msg.indexOf('\n')>0 || f.spaces.test(msg))){
1569 /* Cosmetic: trim most whitespace from the ends of lines to try to
1570 keep copy/paste from terminals, especially wide ones, from
1571 forcing a horizontal scrollbar on all clients. This breaks
1572 markdown's use of blackslash-space-space for paragraph
1573 continuation, but *not* doing this affects all clients every
1574 time someone pastes in console copy/paste from an affected
1575 platform. We seem to have narrowed to the console pasting
1576 problem to users of tmux together with certain apps (vim, at
1577 a minimum). Most consoles don't behave that way.
1578
1579 We retain two trailing spaces so that markdown conventions
1580 which use end-of-line spacing aren't broken by this
1581 stripping.
1582 */
1583 const xmsg = msg.split('\n');
1584 xmsg.forEach(function(line,ndx){
1585 if(!f.markdownContinuation.test(line)){
1586 xmsg[ndx] = line.replace(f.spaces2, ' ');
1587 }
1588 });
1589 msg = xmsg.join('\n');
1590 }
1591 if(msg) fd.set('msg',msg);
1592
--- src/fossil.page.chat.js
+++ src/fossil.page.chat.js
@@ -795,10 +795,15 @@
795795
}
796796
if(!e || !id) return false;
797797
else if(e.$isToggling) return;
798798
e.$isToggling = true;
799799
const content = e.querySelector('.content-target');
800
+ if(!content){
801
+ console.warn("Should not be possible: trying to toggle text",
802
+ "mode of a message with no .content-target.", e);
803
+ return;
804
+ }
800805
if(!content.$elems){
801806
content.$elems = [
802807
content.firstElementChild, // parsed elem
803808
undefined // plaintext elem
804809
];
@@ -807,21 +812,39 @@
807812
const child = (
808813
content.firstElementChild===content.$elems[0]
809814
? content.$elems[1]
810815
: content.$elems[0]
811816
);
817
+ D.clearElement(content);
818
+ if(child===content.$elems[1]){
819
+ /* When showing the unformatted version, inject a
820
+ copy-to-clipboard button. This is a workaround for
821
+ mouse-copying from that field collecting twice as many
822
+ newlines as it should (for unknown reasons). */
823
+ const cpId = 'copy-to-clipboard-'+id;
824
+ /* ^^^ copy button element ID, needed for LABEL element
825
+ pairing. Recall that we destroy all child elements of
826
+ `content` each time we hit this block, so we can reuse
827
+ that element ID on subsequent toggles. */
828
+ const btnCp = D.attr(D.addClass(D.span(),'copy-button'), 'id', cpId);
829
+ F.copyButton(btnCp, {extractText: ()=>child._xmsgRaw});
830
+ const lblCp = D.label(cpId, "Copy unformatted text");
831
+ lblCp.addEventListener('click',()=>btnCp.click(), false);
832
+ D.append(content, D.append(D.addClass(D.span(), 'nobr'), btnCp, lblCp));
833
+ }
812834
delete e.$isToggling;
813
- D.append(D.clearElement(content), child);
835
+ D.append(content, child);
814836
return;
815837
}
816838
// We need to fetch the plain-text version...
817839
const self = this;
818840
F.fetch('chat-fetch-one',{
819841
urlParams:{ name: id, raw: true},
820842
responseType: 'json',
821843
onload: function(msg){
822844
content.$elems[1] = D.append(D.pre(),msg.xmsg);
845
+ content.$elems[1]._xmsgRaw = msg.xmsg/*used for copy-to-clipboard feature*/;
823846
self.toggleTextMode(e);
824847
},
825848
aftersend:function(){
826849
delete e.$isToggling;
827850
Chat.ajaxEnd();
@@ -1313,15 +1336,19 @@
13131336
eMsg.scrollIntoView();
13141337
}
13151338
));
13161339
const toolbar2 = D.addClass(D.div(), 'toolbar');
13171340
D.append(this.e, toolbar2);
1318
- D.append(toolbar2, D.button(
1319
- "Toggle text mode", function(){
1320
- self.hide();
1321
- Chat.toggleTextMode(eMsg);
1322
- }));
1341
+ if(eMsg.querySelector('.content-target')){
1342
+ /* ^^^ messages with only an embedded image have no
1343
+ .content-target area. */
1344
+ D.append(toolbar2, D.button(
1345
+ "Toggle text mode", function(){
1346
+ self.hide();
1347
+ Chat.toggleTextMode(eMsg);
1348
+ }));
1349
+ }
13231350
if(eMsg.dataset.xfrom){
13241351
/* Add a link to the /timeline filtered on this user. */
13251352
const timelineLink = D.attr(
13261353
D.a(F.repoUrl('timeline',{
13271354
u: eMsg.dataset.xfrom,
@@ -1530,29 +1557,35 @@
15301557
*/
15311558
Chat.submitMessage = function f(){
15321559
if(!f.spaces){
15331560
f.spaces = /\s+$/;
15341561
f.markdownContinuation = /\\\s+$/;
1562
+ f.spaces2 = /\s{3,}$/;
15351563
}
15361564
this.setCurrentView(this.e.viewMessages);
15371565
const fd = new FormData();
15381566
const fallback = {msg: this.inputValue()};
1539
- var msg = fallback.msg.trim();
1567
+ var msg = fallback.msg;
15401568
if(msg && (msg.indexOf('\n')>0 || f.spaces.test(msg))){
1541
- /* Cosmetic: trim whitespace from the ends of lines to try to
1569
+ /* Cosmetic: trim most whitespace from the ends of lines to try to
15421570
keep copy/paste from terminals, especially wide ones, from
15431571
forcing a horizontal scrollbar on all clients. This breaks
15441572
markdown's use of blackslash-space-space for paragraph
15451573
continuation, but *not* doing this affects all clients every
15461574
time someone pastes in console copy/paste from an affected
15471575
platform. We seem to have narrowed to the console pasting
1548
- problem to users of tmux. Most consoles don't behave
1549
- that way. */
1576
+ problem to users of tmux together with certain apps (vim, at
1577
+ a minimum). Most consoles don't behave that way.
1578
+
1579
+ We retain two trailing spaces so that markdown conventions
1580
+ which use end-of-line spacing aren't broken by this
1581
+ stripping.
1582
+ */
15501583
const xmsg = msg.split('\n');
15511584
xmsg.forEach(function(line,ndx){
15521585
if(!f.markdownContinuation.test(line)){
1553
- xmsg[ndx] = line.trimRight();
1586
+ xmsg[ndx] = line.replace(f.spaces2, ' ');
15541587
}
15551588
});
15561589
msg = xmsg.join('\n');
15571590
}
15581591
if(msg) fd.set('msg',msg);
15591592
--- src/fossil.page.chat.js
+++ src/fossil.page.chat.js
@@ -795,10 +795,15 @@
795 }
796 if(!e || !id) return false;
797 else if(e.$isToggling) return;
798 e.$isToggling = true;
799 const content = e.querySelector('.content-target');
 
 
 
 
 
800 if(!content.$elems){
801 content.$elems = [
802 content.firstElementChild, // parsed elem
803 undefined // plaintext elem
804 ];
@@ -807,21 +812,39 @@
807 const child = (
808 content.firstElementChild===content.$elems[0]
809 ? content.$elems[1]
810 : content.$elems[0]
811 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
812 delete e.$isToggling;
813 D.append(D.clearElement(content), child);
814 return;
815 }
816 // We need to fetch the plain-text version...
817 const self = this;
818 F.fetch('chat-fetch-one',{
819 urlParams:{ name: id, raw: true},
820 responseType: 'json',
821 onload: function(msg){
822 content.$elems[1] = D.append(D.pre(),msg.xmsg);
 
823 self.toggleTextMode(e);
824 },
825 aftersend:function(){
826 delete e.$isToggling;
827 Chat.ajaxEnd();
@@ -1313,15 +1336,19 @@
1313 eMsg.scrollIntoView();
1314 }
1315 ));
1316 const toolbar2 = D.addClass(D.div(), 'toolbar');
1317 D.append(this.e, toolbar2);
1318 D.append(toolbar2, D.button(
1319 "Toggle text mode", function(){
1320 self.hide();
1321 Chat.toggleTextMode(eMsg);
1322 }));
 
 
 
 
1323 if(eMsg.dataset.xfrom){
1324 /* Add a link to the /timeline filtered on this user. */
1325 const timelineLink = D.attr(
1326 D.a(F.repoUrl('timeline',{
1327 u: eMsg.dataset.xfrom,
@@ -1530,29 +1557,35 @@
1530 */
1531 Chat.submitMessage = function f(){
1532 if(!f.spaces){
1533 f.spaces = /\s+$/;
1534 f.markdownContinuation = /\\\s+$/;
 
1535 }
1536 this.setCurrentView(this.e.viewMessages);
1537 const fd = new FormData();
1538 const fallback = {msg: this.inputValue()};
1539 var msg = fallback.msg.trim();
1540 if(msg && (msg.indexOf('\n')>0 || f.spaces.test(msg))){
1541 /* Cosmetic: trim whitespace from the ends of lines to try to
1542 keep copy/paste from terminals, especially wide ones, from
1543 forcing a horizontal scrollbar on all clients. This breaks
1544 markdown's use of blackslash-space-space for paragraph
1545 continuation, but *not* doing this affects all clients every
1546 time someone pastes in console copy/paste from an affected
1547 platform. We seem to have narrowed to the console pasting
1548 problem to users of tmux. Most consoles don't behave
1549 that way. */
 
 
 
 
 
1550 const xmsg = msg.split('\n');
1551 xmsg.forEach(function(line,ndx){
1552 if(!f.markdownContinuation.test(line)){
1553 xmsg[ndx] = line.trimRight();
1554 }
1555 });
1556 msg = xmsg.join('\n');
1557 }
1558 if(msg) fd.set('msg',msg);
1559
--- src/fossil.page.chat.js
+++ src/fossil.page.chat.js
@@ -795,10 +795,15 @@
795 }
796 if(!e || !id) return false;
797 else if(e.$isToggling) return;
798 e.$isToggling = true;
799 const content = e.querySelector('.content-target');
800 if(!content){
801 console.warn("Should not be possible: trying to toggle text",
802 "mode of a message with no .content-target.", e);
803 return;
804 }
805 if(!content.$elems){
806 content.$elems = [
807 content.firstElementChild, // parsed elem
808 undefined // plaintext elem
809 ];
@@ -807,21 +812,39 @@
812 const child = (
813 content.firstElementChild===content.$elems[0]
814 ? content.$elems[1]
815 : content.$elems[0]
816 );
817 D.clearElement(content);
818 if(child===content.$elems[1]){
819 /* When showing the unformatted version, inject a
820 copy-to-clipboard button. This is a workaround for
821 mouse-copying from that field collecting twice as many
822 newlines as it should (for unknown reasons). */
823 const cpId = 'copy-to-clipboard-'+id;
824 /* ^^^ copy button element ID, needed for LABEL element
825 pairing. Recall that we destroy all child elements of
826 `content` each time we hit this block, so we can reuse
827 that element ID on subsequent toggles. */
828 const btnCp = D.attr(D.addClass(D.span(),'copy-button'), 'id', cpId);
829 F.copyButton(btnCp, {extractText: ()=>child._xmsgRaw});
830 const lblCp = D.label(cpId, "Copy unformatted text");
831 lblCp.addEventListener('click',()=>btnCp.click(), false);
832 D.append(content, D.append(D.addClass(D.span(), 'nobr'), btnCp, lblCp));
833 }
834 delete e.$isToggling;
835 D.append(content, child);
836 return;
837 }
838 // We need to fetch the plain-text version...
839 const self = this;
840 F.fetch('chat-fetch-one',{
841 urlParams:{ name: id, raw: true},
842 responseType: 'json',
843 onload: function(msg){
844 content.$elems[1] = D.append(D.pre(),msg.xmsg);
845 content.$elems[1]._xmsgRaw = msg.xmsg/*used for copy-to-clipboard feature*/;
846 self.toggleTextMode(e);
847 },
848 aftersend:function(){
849 delete e.$isToggling;
850 Chat.ajaxEnd();
@@ -1313,15 +1336,19 @@
1336 eMsg.scrollIntoView();
1337 }
1338 ));
1339 const toolbar2 = D.addClass(D.div(), 'toolbar');
1340 D.append(this.e, toolbar2);
1341 if(eMsg.querySelector('.content-target')){
1342 /* ^^^ messages with only an embedded image have no
1343 .content-target area. */
1344 D.append(toolbar2, D.button(
1345 "Toggle text mode", function(){
1346 self.hide();
1347 Chat.toggleTextMode(eMsg);
1348 }));
1349 }
1350 if(eMsg.dataset.xfrom){
1351 /* Add a link to the /timeline filtered on this user. */
1352 const timelineLink = D.attr(
1353 D.a(F.repoUrl('timeline',{
1354 u: eMsg.dataset.xfrom,
@@ -1530,29 +1557,35 @@
1557 */
1558 Chat.submitMessage = function f(){
1559 if(!f.spaces){
1560 f.spaces = /\s+$/;
1561 f.markdownContinuation = /\\\s+$/;
1562 f.spaces2 = /\s{3,}$/;
1563 }
1564 this.setCurrentView(this.e.viewMessages);
1565 const fd = new FormData();
1566 const fallback = {msg: this.inputValue()};
1567 var msg = fallback.msg;
1568 if(msg && (msg.indexOf('\n')>0 || f.spaces.test(msg))){
1569 /* Cosmetic: trim most whitespace from the ends of lines to try to
1570 keep copy/paste from terminals, especially wide ones, from
1571 forcing a horizontal scrollbar on all clients. This breaks
1572 markdown's use of blackslash-space-space for paragraph
1573 continuation, but *not* doing this affects all clients every
1574 time someone pastes in console copy/paste from an affected
1575 platform. We seem to have narrowed to the console pasting
1576 problem to users of tmux together with certain apps (vim, at
1577 a minimum). Most consoles don't behave that way.
1578
1579 We retain two trailing spaces so that markdown conventions
1580 which use end-of-line spacing aren't broken by this
1581 stripping.
1582 */
1583 const xmsg = msg.split('\n');
1584 xmsg.forEach(function(line,ndx){
1585 if(!f.markdownContinuation.test(line)){
1586 xmsg[ndx] = line.replace(f.spaces2, ' ');
1587 }
1588 });
1589 msg = xmsg.join('\n');
1590 }
1591 if(msg) fd.set('msg',msg);
1592
--- src/fossil.page.pikchrshow.js
+++ src/fossil.page.pikchrshow.js
@@ -1,12 +1,20 @@
11
(function(F/*the fossil object*/){
22
"use strict";
33
/**
4
- Client-side implementation of the /pikchrshow app. Requires that
4
+ Client-side implementation of the /pikchrshowcs app. Requires that
55
the fossil JS bootstrapping is complete and that these fossil JS
66
APIs have been installed: fossil.fetch, fossil.dom,
77
fossil.copybutton, fossil.popupwidget, fossil.storage
8
+
9
+ Maintenance funkiness note: this file is for the legacy
10
+ /pikchrshowcs app, which was formerly named /pikchrshow. This
11
+ file and its replacement were not renamed because the replacement
12
+ impl would end up getting this file's name and cause confusion in
13
+ the file history. Whether that confusion would be less than this
14
+ file's name matching the _other_ /pikchrshow impl will cause more
15
+ or less confusion than that remains to be seen.
816
*/
917
const E = (s)=>document.querySelector(s),
1018
D = F.dom,
1119
P = F.page;
1220
1321
1422
ADDED src/fossil.page.pikchrshowasm.js
--- src/fossil.page.pikchrshow.js
+++ src/fossil.page.pikchrshow.js
@@ -1,12 +1,20 @@
1 (function(F/*the fossil object*/){
2 "use strict";
3 /**
4 Client-side implementation of the /pikchrshow app. Requires that
5 the fossil JS bootstrapping is complete and that these fossil JS
6 APIs have been installed: fossil.fetch, fossil.dom,
7 fossil.copybutton, fossil.popupwidget, fossil.storage
 
 
 
 
 
 
 
 
8 */
9 const E = (s)=>document.querySelector(s),
10 D = F.dom,
11 P = F.page;
12
13
14 DDED src/fossil.page.pikchrshowasm.js
--- src/fossil.page.pikchrshow.js
+++ src/fossil.page.pikchrshow.js
@@ -1,12 +1,20 @@
1 (function(F/*the fossil object*/){
2 "use strict";
3 /**
4 Client-side implementation of the /pikchrshowcs app. Requires that
5 the fossil JS bootstrapping is complete and that these fossil JS
6 APIs have been installed: fossil.fetch, fossil.dom,
7 fossil.copybutton, fossil.popupwidget, fossil.storage
8
9 Maintenance funkiness note: this file is for the legacy
10 /pikchrshowcs app, which was formerly named /pikchrshow. This
11 file and its replacement were not renamed because the replacement
12 impl would end up getting this file's name and cause confusion in
13 the file history. Whether that confusion would be less than this
14 file's name matching the _other_ /pikchrshow impl will cause more
15 or less confusion than that remains to be seen.
16 */
17 const E = (s)=>document.querySelector(s),
18 D = F.dom,
19 P = F.page;
20
21
22 DDED src/fossil.page.pikchrshowasm.js
--- a/src/fossil.page.pikchrshowasm.js
+++ b/src/fossil.page.pikchrshowasm.js
@@ -0,0 +1,24 @@
1
+/*
2
+ 2022-05-20
3
+
4
+ The author disclaims copyright to this source code. In place of a
5
+ legal notice, here is a blessing:
6
+
7
+ * May you do good and not evil.
8
+ * May you find forgiveness for yourself and forgive others.
9
+ * May you share freely, never taking more than you give.
10
+
11
+ ***********************************************************************
12
+
13
+ This is the main entry point for the WASM r
14
+ * May you share fre/*
15
+ :div.didiv. ttr(selectScript, 'aria-label', 'Example Scripts');
16
+ D.attr(selectScript,...EAll('body > *:not(.content)let ht = whht -= F.dom.effectiveHeight(e))
17
+ ];
18
+
19
+
20
+})(window.fossil);
21
+E('body > header.header'),
22
+ E('body > nav.mainmenu'),
23
+ E('body > footer.footervar ht;
24
+ var extra = 0e ? extra + ht = wh - extradivdidivshowshow-ready',show
--- a/src/fossil.page.pikchrshowasm.js
+++ b/src/fossil.page.pikchrshowasm.js
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/src/fossil.page.pikchrshowasm.js
+++ b/src/fossil.page.pikchrshowasm.js
@@ -0,0 +1,24 @@
1 /*
2 2022-05-20
3
4 The author disclaims copyright to this source code. In place of a
5 legal notice, here is a blessing:
6
7 * May you do good and not evil.
8 * May you find forgiveness for yourself and forgive others.
9 * May you share freely, never taking more than you give.
10
11 ***********************************************************************
12
13 This is the main entry point for the WASM r
14 * May you share fre/*
15 :div.didiv. ttr(selectScript, 'aria-label', 'Example Scripts');
16 D.attr(selectScript,...EAll('body > *:not(.content)let ht = whht -= F.dom.effectiveHeight(e))
17 ];
18
19
20 })(window.fossil);
21 E('body > header.header'),
22 E('body > nav.mainmenu'),
23 E('body > footer.footervar ht;
24 var extra = 0e ? extra + ht = wh - extradivdidivshowshow-ready',show
+1 -1
--- src/hook.c
+++ src/hook.c
@@ -476,11 +476,11 @@
476476
int childPid;
477477
if( cnt==0 ){
478478
hook_changes(&chng, zLastRcvid, 0);
479479
}
480480
zCmd = hook_subst(db_column_text(&q,0), 0);
481
- if( popen2(zCmd, &fdFromChild, &toChild, &childPid, 0) ){
481
+ if( popen2(zCmd, &fdFromChild, &toChild, &childPid, 0)==0 ){
482482
if( toChild ){
483483
fwrite(blob_buffer(&chng),1,blob_size(&chng),toChild);
484484
}
485485
pclose2(fdFromChild, toChild, childPid);
486486
}
487487
--- src/hook.c
+++ src/hook.c
@@ -476,11 +476,11 @@
476 int childPid;
477 if( cnt==0 ){
478 hook_changes(&chng, zLastRcvid, 0);
479 }
480 zCmd = hook_subst(db_column_text(&q,0), 0);
481 if( popen2(zCmd, &fdFromChild, &toChild, &childPid, 0) ){
482 if( toChild ){
483 fwrite(blob_buffer(&chng),1,blob_size(&chng),toChild);
484 }
485 pclose2(fdFromChild, toChild, childPid);
486 }
487
--- src/hook.c
+++ src/hook.c
@@ -476,11 +476,11 @@
476 int childPid;
477 if( cnt==0 ){
478 hook_changes(&chng, zLastRcvid, 0);
479 }
480 zCmd = hook_subst(db_column_text(&q,0), 0);
481 if( popen2(zCmd, &fdFromChild, &toChild, &childPid, 0)==0 ){
482 if( toChild ){
483 fwrite(blob_buffer(&chng),1,blob_size(&chng),toChild);
484 }
485 pclose2(fdFromChild, toChild, childPid);
486 }
487
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -1178,5 +1178,19 @@
11781178
wellknown_notfound:
11791179
fossil_free(zPath);
11801180
webpage_notfound_error(0);
11811181
return;
11821182
}
1183
+
1184
+/*
1185
+** Return the OpenSSL version number being used. Space to hold
1186
+** this name is obtained from fossil_malloc() and should be
1187
+** freed by the caller.
1188
+*/
1189
+char *fossil_openssl_version(void){
1190
+#if defined(FOSSIL_ENABLE_SSL)
1191
+ return mprintf("%s (0x%09x)\n",
1192
+ SSLeay_version(SSLEAY_VERSION), OPENSSL_VERSION_NUMBER);
1193
+#else
1194
+ return mprintf("none");
1195
+#endif
1196
+}
11831197
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -1178,5 +1178,19 @@
1178 wellknown_notfound:
1179 fossil_free(zPath);
1180 webpage_notfound_error(0);
1181 return;
1182 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1183
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -1178,5 +1178,19 @@
1178 wellknown_notfound:
1179 fossil_free(zPath);
1180 webpage_notfound_error(0);
1181 return;
1182 }
1183
1184 /*
1185 ** Return the OpenSSL version number being used. Space to hold
1186 ** this name is obtained from fossil_malloc() and should be
1187 ** freed by the caller.
1188 */
1189 char *fossil_openssl_version(void){
1190 #if defined(FOSSIL_ENABLE_SSL)
1191 return mprintf("%s (0x%09x)\n",
1192 SSLeay_version(SSLEAY_VERSION), OPENSSL_VERSION_NUMBER);
1193 #else
1194 return mprintf("none");
1195 #endif
1196 }
1197
+1 -1
--- src/info.c
+++ src/info.c
@@ -988,11 +988,11 @@
988988
moderation_approve('w', rid);
989989
}
990990
}
991991
style_header("Update of \"%h\"", pWiki->zWikiTitle);
992992
zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
993
- zDate = db_text(0, "SELECT datetime(%.17g)", pWiki->rDate);
993
+ zDate = db_text(0, "SELECT datetime(%.17g,toLocal())", pWiki->rDate);
994994
style_submenu_element("Raw", "%R/artifact/%s", zUuid);
995995
style_submenu_element("History", "%R/whistory?name=%t", pWiki->zWikiTitle);
996996
style_submenu_element("Page", "%R/wiki?name=%t", pWiki->zWikiTitle);
997997
login_anonymous_available();
998998
@ <div class="section">Overview</div>
999999
--- src/info.c
+++ src/info.c
@@ -988,11 +988,11 @@
988 moderation_approve('w', rid);
989 }
990 }
991 style_header("Update of \"%h\"", pWiki->zWikiTitle);
992 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
993 zDate = db_text(0, "SELECT datetime(%.17g)", pWiki->rDate);
994 style_submenu_element("Raw", "%R/artifact/%s", zUuid);
995 style_submenu_element("History", "%R/whistory?name=%t", pWiki->zWikiTitle);
996 style_submenu_element("Page", "%R/wiki?name=%t", pWiki->zWikiTitle);
997 login_anonymous_available();
998 @ <div class="section">Overview</div>
999
--- src/info.c
+++ src/info.c
@@ -988,11 +988,11 @@
988 moderation_approve('w', rid);
989 }
990 }
991 style_header("Update of \"%h\"", pWiki->zWikiTitle);
992 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
993 zDate = db_text(0, "SELECT datetime(%.17g,toLocal())", pWiki->rDate);
994 style_submenu_element("Raw", "%R/artifact/%s", zUuid);
995 style_submenu_element("History", "%R/whistory?name=%t", pWiki->zWikiTitle);
996 style_submenu_element("Page", "%R/wiki?name=%t", pWiki->zWikiTitle);
997 login_anonymous_available();
998 @ <div class="section">Overview</div>
999
+10 -8
--- src/json.c
+++ src/json.c
@@ -558,11 +558,11 @@
558558
/*
559559
** Guesses a RESPONSE Content-Type value based (primarily) on the
560560
** HTTP_ACCEPT header.
561561
**
562562
** It will try to figure out if the client can support
563
-** application/json or application/javascript, and will fall back to
563
+** application/json, text/javascript, and will fall back to
564564
** text/plain if it cannot figure out anything more specific.
565565
**
566566
** Returned memory is static and immutable, but if the environment
567567
** changes after calling this then subsequent calls to this function
568568
** might return different (also static/immutable) values.
@@ -573,12 +573,12 @@
573573
cset = PD("HTTP_ACCEPT_CHARSET",NULL);
574574
doUtf8 = ((NULL == cset) || (NULL!=strstr("utf-8",cset)))
575575
? 1 : 0;
576576
if( g.json.jsonp ){
577577
return doUtf8
578
- ? "application/javascript; charset=utf-8"
579
- : "application/javascript";
578
+ ? "text/javascript; charset=utf-8"
579
+ : "text/javascript";
580580
}else{
581581
/*
582582
Content-type
583583
584584
If the browser does not sent an ACCEPT for application/json
@@ -605,18 +605,19 @@
605605
606606
/*
607607
** Given a request CONTENT_TYPE value, this function returns true
608608
** if it is of a type which the JSON API can ostensibly read.
609609
**
610
- ** It accepts any of application/json, text/plain, or
611
- ** application/javascript. The former is preferred, but was not
612
- ** widespread when this API was initially built, so the latter forms
613
- ** are permitted as fallbacks.
610
+ ** It accepts any of application/json, text/plain,
611
+ ** application/javascript, or text/javascript. The former is
612
+ ** preferred, but was not widespread when this API was initially
613
+ ** built, so the latter forms are permitted as fallbacks.
614614
*/
615615
int json_can_consume_content_type(const char * zType){
616616
return fossil_strcmp(zType, "application/json")==0
617617
|| fossil_strcmp(zType,"text/plain")==0/*assume this MIGHT be JSON*/
618
+ || fossil_strcmp(zType,"text/javascript")==0
618619
|| fossil_strcmp(zType,"application/javascript")==0;
619620
}
620621
621622
/*
622623
** Sends pResponse to the output stream as the response object. This
@@ -627,18 +628,19 @@
627628
** In CLI mode pResponse is sent to stdout immediately. In HTTP
628629
** mode pResponse replaces any current CGI content but cgi_reply()
629630
** is not called to flush the output.
630631
**
631632
** If g.json.jsonp is not NULL then the content type is set to
632
-** application/javascript and the output is wrapped in a jsonp
633
+** text/javascript and the output is wrapped in a jsonp
633634
** wrapper.
634635
*/
635636
void json_send_response( cson_value const * pResponse ){
636637
assert( NULL != pResponse );
637638
if( g.isHTTP ){
638639
cgi_reset_content();
639640
if( g.json.jsonp ){
641
+ cgi_set_content_type("text/javascript");
640642
cgi_printf("%s(",g.json.jsonp);
641643
}
642644
cson_output( pResponse, cson_data_dest_cgi, NULL, &g.json.outOpt );
643645
if( g.json.jsonp ){
644646
cgi_append_content(")",1);
645647
--- src/json.c
+++ src/json.c
@@ -558,11 +558,11 @@
558 /*
559 ** Guesses a RESPONSE Content-Type value based (primarily) on the
560 ** HTTP_ACCEPT header.
561 **
562 ** It will try to figure out if the client can support
563 ** application/json or application/javascript, and will fall back to
564 ** text/plain if it cannot figure out anything more specific.
565 **
566 ** Returned memory is static and immutable, but if the environment
567 ** changes after calling this then subsequent calls to this function
568 ** might return different (also static/immutable) values.
@@ -573,12 +573,12 @@
573 cset = PD("HTTP_ACCEPT_CHARSET",NULL);
574 doUtf8 = ((NULL == cset) || (NULL!=strstr("utf-8",cset)))
575 ? 1 : 0;
576 if( g.json.jsonp ){
577 return doUtf8
578 ? "application/javascript; charset=utf-8"
579 : "application/javascript";
580 }else{
581 /*
582 Content-type
583
584 If the browser does not sent an ACCEPT for application/json
@@ -605,18 +605,19 @@
605
606 /*
607 ** Given a request CONTENT_TYPE value, this function returns true
608 ** if it is of a type which the JSON API can ostensibly read.
609 **
610 ** It accepts any of application/json, text/plain, or
611 ** application/javascript. The former is preferred, but was not
612 ** widespread when this API was initially built, so the latter forms
613 ** are permitted as fallbacks.
614 */
615 int json_can_consume_content_type(const char * zType){
616 return fossil_strcmp(zType, "application/json")==0
617 || fossil_strcmp(zType,"text/plain")==0/*assume this MIGHT be JSON*/
 
618 || fossil_strcmp(zType,"application/javascript")==0;
619 }
620
621 /*
622 ** Sends pResponse to the output stream as the response object. This
@@ -627,18 +628,19 @@
627 ** In CLI mode pResponse is sent to stdout immediately. In HTTP
628 ** mode pResponse replaces any current CGI content but cgi_reply()
629 ** is not called to flush the output.
630 **
631 ** If g.json.jsonp is not NULL then the content type is set to
632 ** application/javascript and the output is wrapped in a jsonp
633 ** wrapper.
634 */
635 void json_send_response( cson_value const * pResponse ){
636 assert( NULL != pResponse );
637 if( g.isHTTP ){
638 cgi_reset_content();
639 if( g.json.jsonp ){
 
640 cgi_printf("%s(",g.json.jsonp);
641 }
642 cson_output( pResponse, cson_data_dest_cgi, NULL, &g.json.outOpt );
643 if( g.json.jsonp ){
644 cgi_append_content(")",1);
645
--- src/json.c
+++ src/json.c
@@ -558,11 +558,11 @@
558 /*
559 ** Guesses a RESPONSE Content-Type value based (primarily) on the
560 ** HTTP_ACCEPT header.
561 **
562 ** It will try to figure out if the client can support
563 ** application/json, text/javascript, and will fall back to
564 ** text/plain if it cannot figure out anything more specific.
565 **
566 ** Returned memory is static and immutable, but if the environment
567 ** changes after calling this then subsequent calls to this function
568 ** might return different (also static/immutable) values.
@@ -573,12 +573,12 @@
573 cset = PD("HTTP_ACCEPT_CHARSET",NULL);
574 doUtf8 = ((NULL == cset) || (NULL!=strstr("utf-8",cset)))
575 ? 1 : 0;
576 if( g.json.jsonp ){
577 return doUtf8
578 ? "text/javascript; charset=utf-8"
579 : "text/javascript";
580 }else{
581 /*
582 Content-type
583
584 If the browser does not sent an ACCEPT for application/json
@@ -605,18 +605,19 @@
605
606 /*
607 ** Given a request CONTENT_TYPE value, this function returns true
608 ** if it is of a type which the JSON API can ostensibly read.
609 **
610 ** It accepts any of application/json, text/plain,
611 ** application/javascript, or text/javascript. The former is
612 ** preferred, but was not widespread when this API was initially
613 ** built, so the latter forms are permitted as fallbacks.
614 */
615 int json_can_consume_content_type(const char * zType){
616 return fossil_strcmp(zType, "application/json")==0
617 || fossil_strcmp(zType,"text/plain")==0/*assume this MIGHT be JSON*/
618 || fossil_strcmp(zType,"text/javascript")==0
619 || fossil_strcmp(zType,"application/javascript")==0;
620 }
621
622 /*
623 ** Sends pResponse to the output stream as the response object. This
@@ -627,18 +628,19 @@
628 ** In CLI mode pResponse is sent to stdout immediately. In HTTP
629 ** mode pResponse replaces any current CGI content but cgi_reply()
630 ** is not called to flush the output.
631 **
632 ** If g.json.jsonp is not NULL then the content type is set to
633 ** text/javascript and the output is wrapped in a jsonp
634 ** wrapper.
635 */
636 void json_send_response( cson_value const * pResponse ){
637 assert( NULL != pResponse );
638 if( g.isHTTP ){
639 cgi_reset_content();
640 if( g.json.jsonp ){
641 cgi_set_content_type("text/javascript");
642 cgi_printf("%s(",g.json.jsonp);
643 }
644 cson_output( pResponse, cson_data_dest_cgi, NULL, &g.json.outOpt );
645 if( g.json.jsonp ){
646 cgi_append_content(")",1);
647
+3 -2
--- src/main.c
+++ src/main.c
@@ -138,11 +138,12 @@
138138
139139
struct Global {
140140
int argc; char **argv; /* Command-line arguments to the program */
141141
char *nameOfExe; /* Full path of executable. */
142142
const char *zErrlog; /* Log errors to this file, if not NULL */
143
- const char *zPhase; /* Phase of operation, for use by the error log */
143
+ const char *zPhase; /* Phase of operation, for use by the error log
144
+ ** and for deriving $canonical_page TH1 variable */
144145
int isConst; /* True if the output is unchanging & cacheable */
145146
const char *zVfsName; /* The VFS to use for database connections */
146147
sqlite3 *db; /* The connection to the databases */
147148
sqlite3 *dbConfig; /* Separate connection for global_config table */
148149
char *zAuxSchema; /* Main repository aux-schema */
@@ -176,11 +177,11 @@
176177
int fNoHttpCompress; /* Do not compress HTTP traffic (for debugging) */
177178
char *zSshCmd; /* SSH command string */
178179
const char *zHttpCmd; /* External program to do HTTP requests */
179180
int fNoSync; /* Do not do an autosync ever. --nosync */
180181
int fIPv4; /* Use only IPv4, not IPv6. --ipv4 */
181
- char *zPath; /* Name of webpage being served */
182
+ char *zPath; /* Name of webpage being served (may be NULL) */
182183
char *zExtra; /* Extra path information past the webpage name */
183184
char *zBaseURL; /* Full text of the URL being served */
184185
char *zHttpsURL; /* zBaseURL translated to https: */
185186
char *zTop; /* Parent directory of zPath */
186187
int nExtraURL; /* Extra bytes added to SCRIPT_NAME */
187188
--- src/main.c
+++ src/main.c
@@ -138,11 +138,12 @@
138
139 struct Global {
140 int argc; char **argv; /* Command-line arguments to the program */
141 char *nameOfExe; /* Full path of executable. */
142 const char *zErrlog; /* Log errors to this file, if not NULL */
143 const char *zPhase; /* Phase of operation, for use by the error log */
 
144 int isConst; /* True if the output is unchanging & cacheable */
145 const char *zVfsName; /* The VFS to use for database connections */
146 sqlite3 *db; /* The connection to the databases */
147 sqlite3 *dbConfig; /* Separate connection for global_config table */
148 char *zAuxSchema; /* Main repository aux-schema */
@@ -176,11 +177,11 @@
176 int fNoHttpCompress; /* Do not compress HTTP traffic (for debugging) */
177 char *zSshCmd; /* SSH command string */
178 const char *zHttpCmd; /* External program to do HTTP requests */
179 int fNoSync; /* Do not do an autosync ever. --nosync */
180 int fIPv4; /* Use only IPv4, not IPv6. --ipv4 */
181 char *zPath; /* Name of webpage being served */
182 char *zExtra; /* Extra path information past the webpage name */
183 char *zBaseURL; /* Full text of the URL being served */
184 char *zHttpsURL; /* zBaseURL translated to https: */
185 char *zTop; /* Parent directory of zPath */
186 int nExtraURL; /* Extra bytes added to SCRIPT_NAME */
187
--- src/main.c
+++ src/main.c
@@ -138,11 +138,12 @@
138
139 struct Global {
140 int argc; char **argv; /* Command-line arguments to the program */
141 char *nameOfExe; /* Full path of executable. */
142 const char *zErrlog; /* Log errors to this file, if not NULL */
143 const char *zPhase; /* Phase of operation, for use by the error log
144 ** and for deriving $canonical_page TH1 variable */
145 int isConst; /* True if the output is unchanging & cacheable */
146 const char *zVfsName; /* The VFS to use for database connections */
147 sqlite3 *db; /* The connection to the databases */
148 sqlite3 *dbConfig; /* Separate connection for global_config table */
149 char *zAuxSchema; /* Main repository aux-schema */
@@ -176,11 +177,11 @@
177 int fNoHttpCompress; /* Do not compress HTTP traffic (for debugging) */
178 char *zSshCmd; /* SSH command string */
179 const char *zHttpCmd; /* External program to do HTTP requests */
180 int fNoSync; /* Do not do an autosync ever. --nosync */
181 int fIPv4; /* Use only IPv4, not IPv6. --ipv4 */
182 char *zPath; /* Name of webpage being served (may be NULL) */
183 char *zExtra; /* Extra path information past the webpage name */
184 char *zBaseURL; /* Full text of the URL being served */
185 char *zHttpsURL; /* zBaseURL translated to https: */
186 char *zTop; /* Parent directory of zPath */
187 int nExtraURL; /* Extra bytes added to SCRIPT_NAME */
188
+10
--- src/main.mk
+++ src/main.mk
@@ -163,10 +163,13 @@
163163
$(SRCDIR)/xfer.c \
164164
$(SRCDIR)/xfersetup.c \
165165
$(SRCDIR)/zip.c
166166
167167
EXTRA_FILES = \
168
+ $(SRCDIR)/../extsrc/pikchr-worker.js \
169
+ $(SRCDIR)/../extsrc/pikchr.js \
170
+ $(SRCDIR)/../extsrc/pikchr.wasm \
168171
$(SRCDIR)/../skins/ardoise/css.txt \
169172
$(SRCDIR)/../skins/ardoise/details.txt \
170173
$(SRCDIR)/../skins/ardoise/footer.txt \
171174
$(SRCDIR)/../skins/ardoise/header.txt \
172175
$(SRCDIR)/../skins/black_and_white/css.txt \
@@ -231,10 +234,11 @@
231234
$(SRCDIR)/fossil.page.brlist.js \
232235
$(SRCDIR)/fossil.page.chat.js \
233236
$(SRCDIR)/fossil.page.fileedit.js \
234237
$(SRCDIR)/fossil.page.forumpost.js \
235238
$(SRCDIR)/fossil.page.pikchrshow.js \
239
+ $(SRCDIR)/fossil.page.pikchrshowasm.js \
236240
$(SRCDIR)/fossil.page.whistory.js \
237241
$(SRCDIR)/fossil.page.wikiedit.js \
238242
$(SRCDIR)/fossil.pikchr.js \
239243
$(SRCDIR)/fossil.popupwidget.js \
240244
$(SRCDIR)/fossil.storage.js \
@@ -266,10 +270,11 @@
266270
$(SRCDIR)/sounds/e.wav \
267271
$(SRCDIR)/sounds/f.wav \
268272
$(SRCDIR)/style.admin_log.css \
269273
$(SRCDIR)/style.chat.css \
270274
$(SRCDIR)/style.fileedit.css \
275
+ $(SRCDIR)/style.pikchrshow.css \
271276
$(SRCDIR)/style.wikiedit.css \
272277
$(SRCDIR)/tree.js \
273278
$(SRCDIR)/useredit.js \
274279
$(SRCDIR)/wiki.wiki
275280
@@ -2108,13 +2113,18 @@
21082113
$(OBJDIR)/pikchr.o: $(SRCDIR_extsrc)/pikchr.c
21092114
$(XTCC) $(PIKCHR_OPTIONS) -c $(SRCDIR_extsrc)/pikchr.c -o $@
21102115
21112116
$(OBJDIR)/cson_amalgamation.o: $(SRCDIR_extsrc)/cson_amalgamation.c
21122117
$(XTCC) -c $(SRCDIR_extsrc)/cson_amalgamation.c -o $@
2118
+
2119
+$(SRCDIR_extsrc)/pikchr.js: $(SRCDIR_extsrc)/pikchr.c
2120
+ $(EMCC_WRAPPER) -o $@ $(EMCC_OPT) --no-entry -sEXPORTED_RUNTIME_METHODS=cwrap,setValue,getValue,stackSave,stackRestore -sEXPORTED_FUNCTIONS=_pikchr $(SRCDIR_extsrc)/pikchr.c -sENVIRONMENT=web -sMODULARIZE -sEXPORT_NAME=initPikchrModule --minify 0
2121
+ @chmod -x $(SRCDIR_extsrc)/pikchr.wasm
2122
+wasm: $(SRCDIR_extsrc)/pikchr.js
21132123
21142124
#
21152125
# The list of all the targets that do not correspond to real files. This stops
21162126
# 'make' from getting confused when someone makes an error in a rule.
21172127
#
21182128
21192129
.PHONY: all install test clean
21202130
21212131
--- src/main.mk
+++ src/main.mk
@@ -163,10 +163,13 @@
163 $(SRCDIR)/xfer.c \
164 $(SRCDIR)/xfersetup.c \
165 $(SRCDIR)/zip.c
166
167 EXTRA_FILES = \
 
 
 
168 $(SRCDIR)/../skins/ardoise/css.txt \
169 $(SRCDIR)/../skins/ardoise/details.txt \
170 $(SRCDIR)/../skins/ardoise/footer.txt \
171 $(SRCDIR)/../skins/ardoise/header.txt \
172 $(SRCDIR)/../skins/black_and_white/css.txt \
@@ -231,10 +234,11 @@
231 $(SRCDIR)/fossil.page.brlist.js \
232 $(SRCDIR)/fossil.page.chat.js \
233 $(SRCDIR)/fossil.page.fileedit.js \
234 $(SRCDIR)/fossil.page.forumpost.js \
235 $(SRCDIR)/fossil.page.pikchrshow.js \
 
236 $(SRCDIR)/fossil.page.whistory.js \
237 $(SRCDIR)/fossil.page.wikiedit.js \
238 $(SRCDIR)/fossil.pikchr.js \
239 $(SRCDIR)/fossil.popupwidget.js \
240 $(SRCDIR)/fossil.storage.js \
@@ -266,10 +270,11 @@
266 $(SRCDIR)/sounds/e.wav \
267 $(SRCDIR)/sounds/f.wav \
268 $(SRCDIR)/style.admin_log.css \
269 $(SRCDIR)/style.chat.css \
270 $(SRCDIR)/style.fileedit.css \
 
271 $(SRCDIR)/style.wikiedit.css \
272 $(SRCDIR)/tree.js \
273 $(SRCDIR)/useredit.js \
274 $(SRCDIR)/wiki.wiki
275
@@ -2108,13 +2113,18 @@
2108 $(OBJDIR)/pikchr.o: $(SRCDIR_extsrc)/pikchr.c
2109 $(XTCC) $(PIKCHR_OPTIONS) -c $(SRCDIR_extsrc)/pikchr.c -o $@
2110
2111 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR_extsrc)/cson_amalgamation.c
2112 $(XTCC) -c $(SRCDIR_extsrc)/cson_amalgamation.c -o $@
 
 
 
 
 
2113
2114 #
2115 # The list of all the targets that do not correspond to real files. This stops
2116 # 'make' from getting confused when someone makes an error in a rule.
2117 #
2118
2119 .PHONY: all install test clean
2120
2121
--- src/main.mk
+++ src/main.mk
@@ -163,10 +163,13 @@
163 $(SRCDIR)/xfer.c \
164 $(SRCDIR)/xfersetup.c \
165 $(SRCDIR)/zip.c
166
167 EXTRA_FILES = \
168 $(SRCDIR)/../extsrc/pikchr-worker.js \
169 $(SRCDIR)/../extsrc/pikchr.js \
170 $(SRCDIR)/../extsrc/pikchr.wasm \
171 $(SRCDIR)/../skins/ardoise/css.txt \
172 $(SRCDIR)/../skins/ardoise/details.txt \
173 $(SRCDIR)/../skins/ardoise/footer.txt \
174 $(SRCDIR)/../skins/ardoise/header.txt \
175 $(SRCDIR)/../skins/black_and_white/css.txt \
@@ -231,10 +234,11 @@
234 $(SRCDIR)/fossil.page.brlist.js \
235 $(SRCDIR)/fossil.page.chat.js \
236 $(SRCDIR)/fossil.page.fileedit.js \
237 $(SRCDIR)/fossil.page.forumpost.js \
238 $(SRCDIR)/fossil.page.pikchrshow.js \
239 $(SRCDIR)/fossil.page.pikchrshowasm.js \
240 $(SRCDIR)/fossil.page.whistory.js \
241 $(SRCDIR)/fossil.page.wikiedit.js \
242 $(SRCDIR)/fossil.pikchr.js \
243 $(SRCDIR)/fossil.popupwidget.js \
244 $(SRCDIR)/fossil.storage.js \
@@ -266,10 +270,11 @@
270 $(SRCDIR)/sounds/e.wav \
271 $(SRCDIR)/sounds/f.wav \
272 $(SRCDIR)/style.admin_log.css \
273 $(SRCDIR)/style.chat.css \
274 $(SRCDIR)/style.fileedit.css \
275 $(SRCDIR)/style.pikchrshow.css \
276 $(SRCDIR)/style.wikiedit.css \
277 $(SRCDIR)/tree.js \
278 $(SRCDIR)/useredit.js \
279 $(SRCDIR)/wiki.wiki
280
@@ -2108,13 +2113,18 @@
2113 $(OBJDIR)/pikchr.o: $(SRCDIR_extsrc)/pikchr.c
2114 $(XTCC) $(PIKCHR_OPTIONS) -c $(SRCDIR_extsrc)/pikchr.c -o $@
2115
2116 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR_extsrc)/cson_amalgamation.c
2117 $(XTCC) -c $(SRCDIR_extsrc)/cson_amalgamation.c -o $@
2118
2119 $(SRCDIR_extsrc)/pikchr.js: $(SRCDIR_extsrc)/pikchr.c
2120 $(EMCC_WRAPPER) -o $@ $(EMCC_OPT) --no-entry -sEXPORTED_RUNTIME_METHODS=cwrap,setValue,getValue,stackSave,stackRestore -sEXPORTED_FUNCTIONS=_pikchr $(SRCDIR_extsrc)/pikchr.c -sENVIRONMENT=web -sMODULARIZE -sEXPORT_NAME=initPikchrModule --minify 0
2121 @chmod -x $(SRCDIR_extsrc)/pikchr.wasm
2122 wasm: $(SRCDIR_extsrc)/pikchr.js
2123
2124 #
2125 # The list of all the targets that do not correspond to real files. This stops
2126 # 'make' from getting confused when someone makes an error in a rule.
2127 #
2128
2129 .PHONY: all install test clean
2130
2131
+3 -2
--- src/manifest.c
+++ src/manifest.c
@@ -2395,11 +2395,11 @@
23952395
rid, p->zUser, p->zComment,
23962396
TAG_BGCOLOR, rid,
23972397
TAG_USER, rid,
23982398
TAG_COMMENT, rid, p->rDate
23992399
);
2400
- backlink_extract(zCom, 0, rid, BKLNK_COMMENT, p->rDate, 1);
2400
+ backlink_extract(zCom, MT_NONE, rid, BKLNK_COMMENT, p->rDate, 1);
24012401
fossil_free(zCom);
24022402
24032403
/* If this is a delta-manifest, record the fact that this repository
24042404
** contains delta manifests, to free the "commit" logic to generate
24052405
** new delta manifests.
@@ -2853,11 +2853,12 @@
28532853
p->rDate, rid, p->zUser, zFType, zTitle
28542854
);
28552855
fossil_free(zTitle);
28562856
}
28572857
if( p->zWiki[0] ){
2858
- backlink_extract(p->zWiki, p->zMimetype, rid, BKLNK_FORUM, p->rDate, 1);
2858
+ int mimetype = parse_mimetype(p->zMimetype);
2859
+ backlink_extract(p->zWiki, mimetype, rid, BKLNK_FORUM, p->rDate, 1);
28592860
}
28602861
}
28612862
28622863
db_end_transaction(0);
28632864
if( permitHooks ){
28642865
--- src/manifest.c
+++ src/manifest.c
@@ -2395,11 +2395,11 @@
2395 rid, p->zUser, p->zComment,
2396 TAG_BGCOLOR, rid,
2397 TAG_USER, rid,
2398 TAG_COMMENT, rid, p->rDate
2399 );
2400 backlink_extract(zCom, 0, rid, BKLNK_COMMENT, p->rDate, 1);
2401 fossil_free(zCom);
2402
2403 /* If this is a delta-manifest, record the fact that this repository
2404 ** contains delta manifests, to free the "commit" logic to generate
2405 ** new delta manifests.
@@ -2853,11 +2853,12 @@
2853 p->rDate, rid, p->zUser, zFType, zTitle
2854 );
2855 fossil_free(zTitle);
2856 }
2857 if( p->zWiki[0] ){
2858 backlink_extract(p->zWiki, p->zMimetype, rid, BKLNK_FORUM, p->rDate, 1);
 
2859 }
2860 }
2861
2862 db_end_transaction(0);
2863 if( permitHooks ){
2864
--- src/manifest.c
+++ src/manifest.c
@@ -2395,11 +2395,11 @@
2395 rid, p->zUser, p->zComment,
2396 TAG_BGCOLOR, rid,
2397 TAG_USER, rid,
2398 TAG_COMMENT, rid, p->rDate
2399 );
2400 backlink_extract(zCom, MT_NONE, rid, BKLNK_COMMENT, p->rDate, 1);
2401 fossil_free(zCom);
2402
2403 /* If this is a delta-manifest, record the fact that this repository
2404 ** contains delta manifests, to free the "commit" logic to generate
2405 ** new delta manifests.
@@ -2853,11 +2853,12 @@
2853 p->rDate, rid, p->zUser, zFType, zTitle
2854 );
2855 fossil_free(zTitle);
2856 }
2857 if( p->zWiki[0] ){
2858 int mimetype = parse_mimetype(p->zMimetype);
2859 backlink_extract(p->zWiki, mimetype, rid, BKLNK_FORUM, p->rDate, 1);
2860 }
2861 }
2862
2863 db_end_transaction(0);
2864 if( permitHooks ){
2865
+2 -1
--- src/markdown.c
+++ src/markdown.c
@@ -2833,10 +2833,11 @@
28332833
){
28342834
struct link_ref *lr;
28352835
struct footnote *fn;
28362836
size_t i, beg, end = 0;
28372837
struct render rndr;
2838
+ size_t size;
28382839
Blob text = BLOB_INITIALIZER; /* input after the first pass */
28392840
Blob * const allNotes = &rndr.notes.all;
28402841
28412842
/* filling the render structure */
28422843
if( !rndrer ) return;
@@ -2874,11 +2875,11 @@
28742875
rndr.active_char['&'] = char_entity;
28752876
28762877
/* first pass: iterate over lines looking for references,
28772878
* copying everything else into "text" */
28782879
beg = 0;
2879
- for(const size_t size = blob_size(ib); beg<size ;){
2880
+ for(size = blob_size(ib); beg<size ;){
28802881
const char* const data = blob_buffer(ib);
28812882
if( is_ref(data, beg, size, &end, &rndr.refs) ){
28822883
beg = end;
28832884
}else if(is_footnote(data, beg, size, &end, &rndr.notes.all)){
28842885
beg = end;
28852886
--- src/markdown.c
+++ src/markdown.c
@@ -2833,10 +2833,11 @@
2833 ){
2834 struct link_ref *lr;
2835 struct footnote *fn;
2836 size_t i, beg, end = 0;
2837 struct render rndr;
 
2838 Blob text = BLOB_INITIALIZER; /* input after the first pass */
2839 Blob * const allNotes = &rndr.notes.all;
2840
2841 /* filling the render structure */
2842 if( !rndrer ) return;
@@ -2874,11 +2875,11 @@
2874 rndr.active_char['&'] = char_entity;
2875
2876 /* first pass: iterate over lines looking for references,
2877 * copying everything else into "text" */
2878 beg = 0;
2879 for(const size_t size = blob_size(ib); beg<size ;){
2880 const char* const data = blob_buffer(ib);
2881 if( is_ref(data, beg, size, &end, &rndr.refs) ){
2882 beg = end;
2883 }else if(is_footnote(data, beg, size, &end, &rndr.notes.all)){
2884 beg = end;
2885
--- src/markdown.c
+++ src/markdown.c
@@ -2833,10 +2833,11 @@
2833 ){
2834 struct link_ref *lr;
2835 struct footnote *fn;
2836 size_t i, beg, end = 0;
2837 struct render rndr;
2838 size_t size;
2839 Blob text = BLOB_INITIALIZER; /* input after the first pass */
2840 Blob * const allNotes = &rndr.notes.all;
2841
2842 /* filling the render structure */
2843 if( !rndrer ) return;
@@ -2874,11 +2875,11 @@
2875 rndr.active_char['&'] = char_entity;
2876
2877 /* first pass: iterate over lines looking for references,
2878 * copying everything else into "text" */
2879 beg = 0;
2880 for(size = blob_size(ib); beg<size ;){
2881 const char* const data = blob_buffer(ib);
2882 if( is_ref(data, beg, size, &end, &rndr.refs) ){
2883 beg = end;
2884 }else if(is_footnote(data, beg, size, &end, &rndr.notes.all)){
2885 beg = end;
2886
+2 -1
--- src/markdown.c
+++ src/markdown.c
@@ -2833,10 +2833,11 @@
28332833
){
28342834
struct link_ref *lr;
28352835
struct footnote *fn;
28362836
size_t i, beg, end = 0;
28372837
struct render rndr;
2838
+ size_t size;
28382839
Blob text = BLOB_INITIALIZER; /* input after the first pass */
28392840
Blob * const allNotes = &rndr.notes.all;
28402841
28412842
/* filling the render structure */
28422843
if( !rndrer ) return;
@@ -2874,11 +2875,11 @@
28742875
rndr.active_char['&'] = char_entity;
28752876
28762877
/* first pass: iterate over lines looking for references,
28772878
* copying everything else into "text" */
28782879
beg = 0;
2879
- for(const size_t size = blob_size(ib); beg<size ;){
2880
+ for(size = blob_size(ib); beg<size ;){
28802881
const char* const data = blob_buffer(ib);
28812882
if( is_ref(data, beg, size, &end, &rndr.refs) ){
28822883
beg = end;
28832884
}else if(is_footnote(data, beg, size, &end, &rndr.notes.all)){
28842885
beg = end;
28852886
--- src/markdown.c
+++ src/markdown.c
@@ -2833,10 +2833,11 @@
2833 ){
2834 struct link_ref *lr;
2835 struct footnote *fn;
2836 size_t i, beg, end = 0;
2837 struct render rndr;
 
2838 Blob text = BLOB_INITIALIZER; /* input after the first pass */
2839 Blob * const allNotes = &rndr.notes.all;
2840
2841 /* filling the render structure */
2842 if( !rndrer ) return;
@@ -2874,11 +2875,11 @@
2874 rndr.active_char['&'] = char_entity;
2875
2876 /* first pass: iterate over lines looking for references,
2877 * copying everything else into "text" */
2878 beg = 0;
2879 for(const size_t size = blob_size(ib); beg<size ;){
2880 const char* const data = blob_buffer(ib);
2881 if( is_ref(data, beg, size, &end, &rndr.refs) ){
2882 beg = end;
2883 }else if(is_footnote(data, beg, size, &end, &rndr.notes.all)){
2884 beg = end;
2885
--- src/markdown.c
+++ src/markdown.c
@@ -2833,10 +2833,11 @@
2833 ){
2834 struct link_ref *lr;
2835 struct footnote *fn;
2836 size_t i, beg, end = 0;
2837 struct render rndr;
2838 size_t size;
2839 Blob text = BLOB_INITIALIZER; /* input after the first pass */
2840 Blob * const allNotes = &rndr.notes.all;
2841
2842 /* filling the render structure */
2843 if( !rndrer ) return;
@@ -2874,11 +2875,11 @@
2875 rndr.active_char['&'] = char_entity;
2876
2877 /* first pass: iterate over lines looking for references,
2878 * copying everything else into "text" */
2879 beg = 0;
2880 for(size = blob_size(ib); beg<size ;){
2881 const char* const data = blob_buffer(ib);
2882 if( is_ref(data, beg, size, &end, &rndr.refs) ){
2883 beg = end;
2884 }else if(is_footnote(data, beg, size, &end, &rndr.notes.all)){
2885 beg = end;
2886
+2 -1
--- src/markdown.md
+++ src/markdown.md
@@ -187,11 +187,12 @@
187187
> are subject to further interpretation as Markdown sources.
188188
189189
## Miscellaneous ##
190190
191191
> * In-line images are made using **\!\[alt-text\]\(image-URL\)**.
192
-> * Use HTML for advanced formatting such as forms.
192
+> * Use HTML for advanced formatting such as forms, noting that certain
193
+> tags are [disallowed in some contexts](/help?cmd=safe-html).
193194
> * **\<!--** HTML-style comments **-->** are supported.
194195
> * Escape special characters (ex: **\[** **\(** **\|** **\***)
195196
> using backslash (ex: **\\\[** **\\\(** **\\\|** **\\\***).
196197
> * A line consisting of **---**, **\*\*\***, or **\_\_\_** is a horizontal
197198
> rule. Spaces and extra **-**/**\***/**_** are allowed.
198199
--- src/markdown.md
+++ src/markdown.md
@@ -187,11 +187,12 @@
187 > are subject to further interpretation as Markdown sources.
188
189 ## Miscellaneous ##
190
191 > * In-line images are made using **\!\[alt-text\]\(image-URL\)**.
192 > * Use HTML for advanced formatting such as forms.
 
193 > * **\<!--** HTML-style comments **-->** are supported.
194 > * Escape special characters (ex: **\[** **\(** **\|** **\***)
195 > using backslash (ex: **\\\[** **\\\(** **\\\|** **\\\***).
196 > * A line consisting of **---**, **\*\*\***, or **\_\_\_** is a horizontal
197 > rule. Spaces and extra **-**/**\***/**_** are allowed.
198
--- src/markdown.md
+++ src/markdown.md
@@ -187,11 +187,12 @@
187 > are subject to further interpretation as Markdown sources.
188
189 ## Miscellaneous ##
190
191 > * In-line images are made using **\!\[alt-text\]\(image-URL\)**.
192 > * Use HTML for advanced formatting such as forms, noting that certain
193 > tags are [disallowed in some contexts](/help?cmd=safe-html).
194 > * **\<!--** HTML-style comments **-->** are supported.
195 > * Escape special characters (ex: **\[** **\(** **\|** **\***)
196 > using backslash (ex: **\\\[** **\\\(** **\\\|** **\\\***).
197 > * A line consisting of **---**, **\*\*\***, or **\_\_\_** is a horizontal
198 > rule. Spaces and extra **-**/**\***/**_** are allowed.
199
+10 -4
--- src/name.c
+++ src/name.c
@@ -261,10 +261,11 @@
261261
** * "next"
262262
**
263263
** The following modifier prefixes may be applied to the above forms:
264264
**
265265
** * "root:BR" = The origin of the branch named BR.
266
+** * "start:BR" = The first check-in of the branch named BR.
266267
** * "merge-in:BR" = The most recent merge-in for the branch named BR.
267268
**
268269
** In those forms, BR may be any symbolic form but is assumed to be a
269270
** checkin. Thus root:2021-02-01 would resolve to a checkin, possibly
270271
** in a branch and possibly in the trunk, but never a wiki edit or
@@ -378,11 +379,18 @@
378379
/* root:BR -> The origin of the branch named BR */
379380
if( strncmp(zTag, "root:", 5)==0 ){
380381
rid = symbolic_name_to_rid(zTag+5, zType);
381382
return start_of_branch(rid, 0);
382383
}
383
- /* merge-in:BR -> Most recent merge-in for the branch name BR */
384
+
385
+ /* start:BR -> The first check-in on branch named BR */
386
+ if( strncmp(zTag, "start:", 6)==0 ){
387
+ rid = symbolic_name_to_rid(zTag+6, zType);
388
+ return start_of_branch(rid, 1);
389
+ }
390
+
391
+ /* merge-in:BR -> Most recent merge-in for the branch named BR */
384392
if( strncmp(zTag, "merge-in:", 9)==0 ){
385393
rid = symbolic_name_to_rid(zTag+9, zType);
386394
return start_of_branch(rid, 2);
387395
}
388396
@@ -1743,11 +1751,11 @@
17431751
/*
17441752
** Generate a report on the number of collisions in artifact hashes
17451753
** generated by the SQL given in the argument.
17461754
*/
17471755
static void collision_report(const char *zSql){
1748
- int i, j, kk;
1756
+ int i, j;
17491757
int nHash = 0;
17501758
Stmt q;
17511759
char zPrev[HNAME_MAX+1];
17521760
struct {
17531761
int cnt;
@@ -1780,15 +1788,13 @@
17801788
if( aCollide[i].cnt==0 ) continue;
17811789
@ <tr><td>%d(i)<td>%d(aCollide[i].cnt)<td>%h(aCollide[i].z)</tr>
17821790
}
17831791
@ </tbody></table>
17841792
@ <p>Total number of hashes: %d(nHash)</p>
1785
- kk = 0;
17861793
for(i=HNAME_MAX; i>=4; i--){
17871794
if( aCollide[i].cnt==0 ) continue;
17881795
if( aCollide[i].cnt>200 ) break;
1789
- kk += aCollide[i].cnt;
17901796
if( aCollide[i].cnt<25 ){
17911797
@ <p>Collisions of length %d(i):
17921798
}else{
17931799
@ <p>First 25 collisions of length %d(i):
17941800
}
17951801
--- src/name.c
+++ src/name.c
@@ -261,10 +261,11 @@
261 ** * "next"
262 **
263 ** The following modifier prefixes may be applied to the above forms:
264 **
265 ** * "root:BR" = The origin of the branch named BR.
 
266 ** * "merge-in:BR" = The most recent merge-in for the branch named BR.
267 **
268 ** In those forms, BR may be any symbolic form but is assumed to be a
269 ** checkin. Thus root:2021-02-01 would resolve to a checkin, possibly
270 ** in a branch and possibly in the trunk, but never a wiki edit or
@@ -378,11 +379,18 @@
378 /* root:BR -> The origin of the branch named BR */
379 if( strncmp(zTag, "root:", 5)==0 ){
380 rid = symbolic_name_to_rid(zTag+5, zType);
381 return start_of_branch(rid, 0);
382 }
383 /* merge-in:BR -> Most recent merge-in for the branch name BR */
 
 
 
 
 
 
 
384 if( strncmp(zTag, "merge-in:", 9)==0 ){
385 rid = symbolic_name_to_rid(zTag+9, zType);
386 return start_of_branch(rid, 2);
387 }
388
@@ -1743,11 +1751,11 @@
1743 /*
1744 ** Generate a report on the number of collisions in artifact hashes
1745 ** generated by the SQL given in the argument.
1746 */
1747 static void collision_report(const char *zSql){
1748 int i, j, kk;
1749 int nHash = 0;
1750 Stmt q;
1751 char zPrev[HNAME_MAX+1];
1752 struct {
1753 int cnt;
@@ -1780,15 +1788,13 @@
1780 if( aCollide[i].cnt==0 ) continue;
1781 @ <tr><td>%d(i)<td>%d(aCollide[i].cnt)<td>%h(aCollide[i].z)</tr>
1782 }
1783 @ </tbody></table>
1784 @ <p>Total number of hashes: %d(nHash)</p>
1785 kk = 0;
1786 for(i=HNAME_MAX; i>=4; i--){
1787 if( aCollide[i].cnt==0 ) continue;
1788 if( aCollide[i].cnt>200 ) break;
1789 kk += aCollide[i].cnt;
1790 if( aCollide[i].cnt<25 ){
1791 @ <p>Collisions of length %d(i):
1792 }else{
1793 @ <p>First 25 collisions of length %d(i):
1794 }
1795
--- src/name.c
+++ src/name.c
@@ -261,10 +261,11 @@
261 ** * "next"
262 **
263 ** The following modifier prefixes may be applied to the above forms:
264 **
265 ** * "root:BR" = The origin of the branch named BR.
266 ** * "start:BR" = The first check-in of the branch named BR.
267 ** * "merge-in:BR" = The most recent merge-in for the branch named BR.
268 **
269 ** In those forms, BR may be any symbolic form but is assumed to be a
270 ** checkin. Thus root:2021-02-01 would resolve to a checkin, possibly
271 ** in a branch and possibly in the trunk, but never a wiki edit or
@@ -378,11 +379,18 @@
379 /* root:BR -> The origin of the branch named BR */
380 if( strncmp(zTag, "root:", 5)==0 ){
381 rid = symbolic_name_to_rid(zTag+5, zType);
382 return start_of_branch(rid, 0);
383 }
384
385 /* start:BR -> The first check-in on branch named BR */
386 if( strncmp(zTag, "start:", 6)==0 ){
387 rid = symbolic_name_to_rid(zTag+6, zType);
388 return start_of_branch(rid, 1);
389 }
390
391 /* merge-in:BR -> Most recent merge-in for the branch named BR */
392 if( strncmp(zTag, "merge-in:", 9)==0 ){
393 rid = symbolic_name_to_rid(zTag+9, zType);
394 return start_of_branch(rid, 2);
395 }
396
@@ -1743,11 +1751,11 @@
1751 /*
1752 ** Generate a report on the number of collisions in artifact hashes
1753 ** generated by the SQL given in the argument.
1754 */
1755 static void collision_report(const char *zSql){
1756 int i, j;
1757 int nHash = 0;
1758 Stmt q;
1759 char zPrev[HNAME_MAX+1];
1760 struct {
1761 int cnt;
@@ -1780,15 +1788,13 @@
1788 if( aCollide[i].cnt==0 ) continue;
1789 @ <tr><td>%d(i)<td>%d(aCollide[i].cnt)<td>%h(aCollide[i].z)</tr>
1790 }
1791 @ </tbody></table>
1792 @ <p>Total number of hashes: %d(nHash)</p>
 
1793 for(i=HNAME_MAX; i>=4; i--){
1794 if( aCollide[i].cnt==0 ) continue;
1795 if( aCollide[i].cnt>200 ) break;
 
1796 if( aCollide[i].cnt<25 ){
1797 @ <p>Collisions of length %d(i):
1798 }else{
1799 @ <p>First 25 collisions of length %d(i):
1800 }
1801
+10
--- src/path.c
+++ src/path.c
@@ -205,10 +205,20 @@
205205
for(p=path.pEnd, i=0; p && (p->isHidden || i<path.nNotHidden/2); p=p->pFrom){
206206
if( !p->isHidden ) i++;
207207
}
208208
return p;
209209
}
210
+
211
+/*
212
+** Find the next most recent node on a path.
213
+*/
214
+PathNode *path_next(void){
215
+ PathNode *p;
216
+ p = path.pStart;
217
+ if( p ) p = p->u.pTo;
218
+ return p;
219
+}
210220
211221
/*
212222
** Return an estimate of the number of comparisons remaining in order
213223
** to bisect path. This is based on the log2() of path.nStep.
214224
*/
215225
--- src/path.c
+++ src/path.c
@@ -205,10 +205,20 @@
205 for(p=path.pEnd, i=0; p && (p->isHidden || i<path.nNotHidden/2); p=p->pFrom){
206 if( !p->isHidden ) i++;
207 }
208 return p;
209 }
 
 
 
 
 
 
 
 
 
 
210
211 /*
212 ** Return an estimate of the number of comparisons remaining in order
213 ** to bisect path. This is based on the log2() of path.nStep.
214 */
215
--- src/path.c
+++ src/path.c
@@ -205,10 +205,20 @@
205 for(p=path.pEnd, i=0; p && (p->isHidden || i<path.nNotHidden/2); p=p->pFrom){
206 if( !p->isHidden ) i++;
207 }
208 return p;
209 }
210
211 /*
212 ** Find the next most recent node on a path.
213 */
214 PathNode *path_next(void){
215 PathNode *p;
216 p = path.pStart;
217 if( p ) p = p->u.pTo;
218 return p;
219 }
220
221 /*
222 ** Return an estimate of the number of comparisons remaining in order
223 ** to bisect path. This is based on the log2() of path.nStep.
224 */
225
+146 -9
--- src/pikchrshow.c
+++ src/pikchrshow.c
@@ -230,30 +230,36 @@
230230
blob_reset(&bIn);
231231
return isErr;
232232
}
233233
234234
/*
235
-** WEBPAGE: pikchrshow
235
+** Legacy impl of /pikchrshow. pikchrshow_page() will delegate to
236
+** this one if the "legacy" or "ajax" request arguments are set.
236237
**
237238
** A pikchr code editor and previewer, allowing users to experiment
238239
** with pikchr code or prototype it for use in copy/pasting into forum
239
-** posts, wiki pages, or embedded docs.
240
-**
241
-** It optionally accepts a p=pikchr-script-code URL parameter or POST
242
-** value to pre-populate the editor with that code.
240
+** posts, wiki pages, or embedded docs. This version of pikchrshow
241
+** uses JavaScript to send pikchr code to the server for
242
+** processing. The newer /pikchrshow applications runs pikchr on the
243
+** client machine, without the need for back-and-forth network
244
+** traffic.
243245
*/
244
-void pikchrshow_page(void){
246
+void pikchrshowcs_page(void){
245247
const char *zContent = 0;
246248
int isDark; /* true if the current skin is "dark" */
247249
int pikFlags =
248250
PIKCHR_PROCESS_DIV
249251
| PIKCHR_PROCESS_SRC
250252
| PIKCHR_PROCESS_ERR_PRE;
251253
252254
login_check_credentials();
253255
if( !g.perm.RdWiki && !g.perm.Read && !g.perm.RdForum ){
254
- cgi_redirectf("%R/login?g=pikchrshow");
256
+ cgi_redirectf("%R/login?g=pikchrshowcs");
257
+ }
258
+ if(P("wasm")){
259
+ pikchrshow_page();
260
+ return;
255261
}
256262
zContent = PD("content",P("p"));
257263
if(P("ajax")!=0){
258264
/* Called from the JS-side preview updater.
259265
TODO: respond with JSON instead.*/
@@ -279,11 +285,11 @@
279285
"box rad 10px \"Markdown\" \"Formatter\" \"(markdown.c)\" fit\n"
280286
"arrow right 200% \"HTML+SVG\" \"Output\"\n"
281287
"arrow <-> down from last box.s\n"
282288
"box same \"Pikchr\" \"Formatter\" \"(pikchr.c)\" fit\n";
283289
}
284
- style_header("PikchrShow");
290
+ style_header("PikchrShow Client/Server");
285291
CX("<style>"); {
286292
CX("div.content { padding-top: 0.5em }\n");
287293
CX("#sbs-wrapper {"
288294
"display: flex; flex-direction: column;"
289295
"}\n");
@@ -336,11 +342,11 @@
336342
"vertical-align: middle"
337343
"}\n");
338344
CX(".dragover {border: 3px dotted rgba(0,255,0,0.6)}\n");
339345
} CX("</style>");
340346
CX("<div>Input pikchr code and tap Preview (or Shift-Enter) to render "
341
- "it:</div>");
347
+ "it. <a href='?wasm'>Switch to WASM mode</a>.</div>");
342348
CX("<div id='sbs-wrapper'>"); {
343349
CX("<div id='pikchrshow-form'>"); {
344350
CX("<textarea id='content' name='content' rows='15'>"
345351
"%s</textarea>",zContent/*safe-for-%s*/);
346352
CX("<div id='pikchrshow-controls'>"); {
@@ -376,10 +382,141 @@
376382
"storage", "pikchr", NULL);
377383
builtin_request_js("fossil.page.pikchrshow.js");
378384
builtin_fulfill_js_requests();
379385
style_finish_page();
380386
}
387
+
388
+/*
389
+** WEBPAGE: pikchrshow
390
+**
391
+** A pikchr code editor and previewer, allowing users to experiment
392
+** with pikchr code or prototype it for use in copy/pasting into forum
393
+** posts, wiki pages, or embedded docs. This version of pikchrshow
394
+** uses WebAssembly to run entirely in the client browser, without a
395
+** need for back-and-forth client/server traffic to perform the
396
+** rendering. The "legacy" version of this application, which sends
397
+** all input to the server for rendering, can be accessed by adding
398
+** the "legacy" URL argument.
399
+**
400
+** It optionally accepts a p=pikchr-script-code URL parameter or POST
401
+** value to pre-populate the editor with that code.
402
+*/
403
+void pikchrshow_page(void){
404
+ const char *zContent = 0;
405
+
406
+ if(P("legacy") || P("ajax")){
407
+ pikchrshowcs_page();
408
+ return;
409
+ }
410
+ login_check_credentials();
411
+ if( !g.perm.RdWiki && !g.perm.Read && !g.perm.RdForum ){
412
+ cgi_redirectf("%R/login?g=pikchrshow");
413
+ }
414
+ style_emit_noscript_for_js_page();
415
+ style_header("PikchrShow");
416
+ zContent = PD("content",P("p"));
417
+ if(!zContent){
418
+ zContent = "arrow right 200% \"Markdown\" \"Source\"\n"
419
+ "box rad 10px \"Markdown\" \"Formatter\" \"(markdown.c)\" fit\n"
420
+ "arrow right 200% \"HTML+SVG\" \"Output\"\n"
421
+ "arrow <-> down from last box.s\n"
422
+ "box same \"Pikchr\" \"Formatter\" \"(pikchr.c)\" fit\n";
423
+ }
424
+ /* Wasm load/init progress widget... */
425
+ CX("<div class='emscripten'>"); {
426
+ CX("<figure id='module-spinner'>");
427
+ CX("<div class='spinner'></div>");
428
+ CX("<div class='center'><strong>Initializing app...</strong></div>");
429
+ CX("<div class='center'>");
430
+ CX("On a slow internet connection this may take a moment. If this ");
431
+ CX("message displays for \"a long time\", intialization may have ");
432
+ CX("failed and the JavaScript console may contain clues as to why. ");
433
+ CX("</div>");
434
+ CX("<div><a href='?legacy'>Switch to legacy mode</a></div>");
435
+ CX("</figure>");
436
+ CX("<div class='emscripten' id='module-status'>Downloading...</div>");
437
+ CX("<progress value='0' max='100' id='module-progress' hidden='1'>"
438
+ "</progress>");
439
+ } CX("</div><!-- .emscripten -->");
440
+ /* Main view... */
441
+ CX("<div id='view-split' class='app-view initially-hidden'>"); {
442
+ CX("<fieldset class='options collapsible'>"); {
443
+ CX("<legend><button class='fieldset-toggle'>Options</button></legend>");
444
+ CX("<div>");
445
+ CX("<span class='labeled-input'>");
446
+ CX("<input type='checkbox' id='opt-cb-sbs' ");
447
+ CX("data-csstgt='#main-wrapper' ");
448
+ CX("data-cssclass='side-by-side' ");
449
+ CX("data-config='sideBySide'>");
450
+ CX("<label for='opt-cb-sbs'>Side-by-side</label>");
451
+ CX("</span>");
452
+ CX("<span class='labeled-input'>");
453
+ CX("<input type='checkbox' id='opt-cb-swapio' ");
454
+ CX("data-csstgt='#main-wrapper' ");
455
+ CX("data-cssclass='swapio' ");
456
+ CX("data-config='swapInOut'>");
457
+ CX("<label for='opt-cb-swapio'>Swap in/out</label>");
458
+ CX("</span>");
459
+ CX("<span class='labeled-input'>");
460
+ CX("<input type='checkbox' id='opt-cb-autofit' ");
461
+ CX("data-config='renderAutofit'>");
462
+ CX("<label for='opt-cb-autofit' "
463
+ "title='Attempt to scale SVG to fit viewport. "
464
+ "Whether it will work depends in part on the size "
465
+ "and shape of the image and the viewport.'"
466
+ ">Auto-fit SVG</label>");
467
+ CX("</span>");
468
+ CX("<span class='labeled-input'>");
469
+ CX("<input type='checkbox' id='opt-cb-autorender' ");
470
+ CX("data-csstgt='#main-wrapper' ");
471
+ CX("data-cssclass='auto-render' ");
472
+ CX("data-config='renderWhileTyping'>");
473
+ CX("<label for='opt-cb-autorender'>Render while typing</label>");
474
+ CX("</span>");
475
+ CX("<span class='labeled-input'>");
476
+ CX("<a href='?legacy'>Legacy mode</a>");
477
+ CX("</span>");
478
+ CX("</div><!-- options wrapper -->");
479
+ } CX("</fieldset>");
480
+ CX("<div id='main-wrapper' class=''>"); {
481
+ CX("<fieldset class='zone-wrapper input'>"); {
482
+ CX("<legend><div class='button-bar'>");
483
+ CX("<button id='btn-render' "
484
+ "title='Ctrl-Enter/Shift-Enter'>Render</button>");
485
+ CX("<button id='btn-clear'>Clear Input</button>");
486
+ CX("</div></legend>");
487
+ CX("<div><textarea id='input'");
488
+ CX("placeholder='Pikchr input. Ctrl-enter/shift-enter runs it.'>");
489
+ CX("/**\n");
490
+ CX(" Use ctrl-enter or shift-enter to execute\n");
491
+ CX(" pikchr code. If only a subset is currently\n");
492
+ CX(" selected, only that part is evaluated.\n*/\n");
493
+ CX("%s</textarea></div>",zContent/*safe-for-%s*/);
494
+ } CX("</fieldset><!-- .zone-wrapper.input -->");
495
+ CX("<fieldset class='zone-wrapper output'>"); {
496
+ CX("<legend><div class='button-bar'>");
497
+ CX("<button id='btn-render-mode'>Render Mode</button> ");
498
+ CX("<span style='white-space:nowrap'>"
499
+ "<span id='preview-copy-button' "
500
+ "title='Tap to copy to clipboard.'></span>"
501
+ "<label for='preview-copy-button' "
502
+ "title='Tap to copy to clipboard.'></label>"
503
+ "</span>");
504
+ CX("</div></legend>");
505
+ CX("<div id='pikchr-output-wrapper'>");
506
+ CX("<div id='pikchr-output'></div>");
507
+ CX("<textarea class='hidden' id='pikchr-output-text'></textarea>");
508
+ CX("</div>");
509
+ } CX("</fieldset> <!-- .zone-wrapper.output -->");
510
+ } CX("</div><!-- #main-wrapper -->");
511
+ } CX("</div><!-- #view-split -->");
512
+ builtin_fossil_js_bundle_or("dom", "storage", "copybutton", NULL);
513
+ builtin_request_js("fossil.page.pikchrshowasm.js");
514
+ builtin_fulfill_js_requests();
515
+ style_finish_page();
516
+}
517
+
381518
382519
/*
383520
** COMMAND: pikchr*
384521
**
385522
** Usage: %fossil pikchr [options] ?INFILE? ?OUTFILE?
386523
--- src/pikchrshow.c
+++ src/pikchrshow.c
@@ -230,30 +230,36 @@
230 blob_reset(&bIn);
231 return isErr;
232 }
233
234 /*
235 ** WEBPAGE: pikchrshow
 
236 **
237 ** A pikchr code editor and previewer, allowing users to experiment
238 ** with pikchr code or prototype it for use in copy/pasting into forum
239 ** posts, wiki pages, or embedded docs.
240 **
241 ** It optionally accepts a p=pikchr-script-code URL parameter or POST
242 ** value to pre-populate the editor with that code.
 
243 */
244 void pikchrshow_page(void){
245 const char *zContent = 0;
246 int isDark; /* true if the current skin is "dark" */
247 int pikFlags =
248 PIKCHR_PROCESS_DIV
249 | PIKCHR_PROCESS_SRC
250 | PIKCHR_PROCESS_ERR_PRE;
251
252 login_check_credentials();
253 if( !g.perm.RdWiki && !g.perm.Read && !g.perm.RdForum ){
254 cgi_redirectf("%R/login?g=pikchrshow");
 
 
 
 
255 }
256 zContent = PD("content",P("p"));
257 if(P("ajax")!=0){
258 /* Called from the JS-side preview updater.
259 TODO: respond with JSON instead.*/
@@ -279,11 +285,11 @@
279 "box rad 10px \"Markdown\" \"Formatter\" \"(markdown.c)\" fit\n"
280 "arrow right 200% \"HTML+SVG\" \"Output\"\n"
281 "arrow <-> down from last box.s\n"
282 "box same \"Pikchr\" \"Formatter\" \"(pikchr.c)\" fit\n";
283 }
284 style_header("PikchrShow");
285 CX("<style>"); {
286 CX("div.content { padding-top: 0.5em }\n");
287 CX("#sbs-wrapper {"
288 "display: flex; flex-direction: column;"
289 "}\n");
@@ -336,11 +342,11 @@
336 "vertical-align: middle"
337 "}\n");
338 CX(".dragover {border: 3px dotted rgba(0,255,0,0.6)}\n");
339 } CX("</style>");
340 CX("<div>Input pikchr code and tap Preview (or Shift-Enter) to render "
341 "it:</div>");
342 CX("<div id='sbs-wrapper'>"); {
343 CX("<div id='pikchrshow-form'>"); {
344 CX("<textarea id='content' name='content' rows='15'>"
345 "%s</textarea>",zContent/*safe-for-%s*/);
346 CX("<div id='pikchrshow-controls'>"); {
@@ -376,10 +382,141 @@
376 "storage", "pikchr", NULL);
377 builtin_request_js("fossil.page.pikchrshow.js");
378 builtin_fulfill_js_requests();
379 style_finish_page();
380 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
381
382 /*
383 ** COMMAND: pikchr*
384 **
385 ** Usage: %fossil pikchr [options] ?INFILE? ?OUTFILE?
386
--- src/pikchrshow.c
+++ src/pikchrshow.c
@@ -230,30 +230,36 @@
230 blob_reset(&bIn);
231 return isErr;
232 }
233
234 /*
235 ** Legacy impl of /pikchrshow. pikchrshow_page() will delegate to
236 ** this one if the "legacy" or "ajax" request arguments are set.
237 **
238 ** A pikchr code editor and previewer, allowing users to experiment
239 ** with pikchr code or prototype it for use in copy/pasting into forum
240 ** posts, wiki pages, or embedded docs. This version of pikchrshow
241 ** uses JavaScript to send pikchr code to the server for
242 ** processing. The newer /pikchrshow applications runs pikchr on the
243 ** client machine, without the need for back-and-forth network
244 ** traffic.
245 */
246 void pikchrshowcs_page(void){
247 const char *zContent = 0;
248 int isDark; /* true if the current skin is "dark" */
249 int pikFlags =
250 PIKCHR_PROCESS_DIV
251 | PIKCHR_PROCESS_SRC
252 | PIKCHR_PROCESS_ERR_PRE;
253
254 login_check_credentials();
255 if( !g.perm.RdWiki && !g.perm.Read && !g.perm.RdForum ){
256 cgi_redirectf("%R/login?g=pikchrshowcs");
257 }
258 if(P("wasm")){
259 pikchrshow_page();
260 return;
261 }
262 zContent = PD("content",P("p"));
263 if(P("ajax")!=0){
264 /* Called from the JS-side preview updater.
265 TODO: respond with JSON instead.*/
@@ -279,11 +285,11 @@
285 "box rad 10px \"Markdown\" \"Formatter\" \"(markdown.c)\" fit\n"
286 "arrow right 200% \"HTML+SVG\" \"Output\"\n"
287 "arrow <-> down from last box.s\n"
288 "box same \"Pikchr\" \"Formatter\" \"(pikchr.c)\" fit\n";
289 }
290 style_header("PikchrShow Client/Server");
291 CX("<style>"); {
292 CX("div.content { padding-top: 0.5em }\n");
293 CX("#sbs-wrapper {"
294 "display: flex; flex-direction: column;"
295 "}\n");
@@ -336,11 +342,11 @@
342 "vertical-align: middle"
343 "}\n");
344 CX(".dragover {border: 3px dotted rgba(0,255,0,0.6)}\n");
345 } CX("</style>");
346 CX("<div>Input pikchr code and tap Preview (or Shift-Enter) to render "
347 "it. <a href='?wasm'>Switch to WASM mode</a>.</div>");
348 CX("<div id='sbs-wrapper'>"); {
349 CX("<div id='pikchrshow-form'>"); {
350 CX("<textarea id='content' name='content' rows='15'>"
351 "%s</textarea>",zContent/*safe-for-%s*/);
352 CX("<div id='pikchrshow-controls'>"); {
@@ -376,10 +382,141 @@
382 "storage", "pikchr", NULL);
383 builtin_request_js("fossil.page.pikchrshow.js");
384 builtin_fulfill_js_requests();
385 style_finish_page();
386 }
387
388 /*
389 ** WEBPAGE: pikchrshow
390 **
391 ** A pikchr code editor and previewer, allowing users to experiment
392 ** with pikchr code or prototype it for use in copy/pasting into forum
393 ** posts, wiki pages, or embedded docs. This version of pikchrshow
394 ** uses WebAssembly to run entirely in the client browser, without a
395 ** need for back-and-forth client/server traffic to perform the
396 ** rendering. The "legacy" version of this application, which sends
397 ** all input to the server for rendering, can be accessed by adding
398 ** the "legacy" URL argument.
399 **
400 ** It optionally accepts a p=pikchr-script-code URL parameter or POST
401 ** value to pre-populate the editor with that code.
402 */
403 void pikchrshow_page(void){
404 const char *zContent = 0;
405
406 if(P("legacy") || P("ajax")){
407 pikchrshowcs_page();
408 return;
409 }
410 login_check_credentials();
411 if( !g.perm.RdWiki && !g.perm.Read && !g.perm.RdForum ){
412 cgi_redirectf("%R/login?g=pikchrshow");
413 }
414 style_emit_noscript_for_js_page();
415 style_header("PikchrShow");
416 zContent = PD("content",P("p"));
417 if(!zContent){
418 zContent = "arrow right 200% \"Markdown\" \"Source\"\n"
419 "box rad 10px \"Markdown\" \"Formatter\" \"(markdown.c)\" fit\n"
420 "arrow right 200% \"HTML+SVG\" \"Output\"\n"
421 "arrow <-> down from last box.s\n"
422 "box same \"Pikchr\" \"Formatter\" \"(pikchr.c)\" fit\n";
423 }
424 /* Wasm load/init progress widget... */
425 CX("<div class='emscripten'>"); {
426 CX("<figure id='module-spinner'>");
427 CX("<div class='spinner'></div>");
428 CX("<div class='center'><strong>Initializing app...</strong></div>");
429 CX("<div class='center'>");
430 CX("On a slow internet connection this may take a moment. If this ");
431 CX("message displays for \"a long time\", intialization may have ");
432 CX("failed and the JavaScript console may contain clues as to why. ");
433 CX("</div>");
434 CX("<div><a href='?legacy'>Switch to legacy mode</a></div>");
435 CX("</figure>");
436 CX("<div class='emscripten' id='module-status'>Downloading...</div>");
437 CX("<progress value='0' max='100' id='module-progress' hidden='1'>"
438 "</progress>");
439 } CX("</div><!-- .emscripten -->");
440 /* Main view... */
441 CX("<div id='view-split' class='app-view initially-hidden'>"); {
442 CX("<fieldset class='options collapsible'>"); {
443 CX("<legend><button class='fieldset-toggle'>Options</button></legend>");
444 CX("<div>");
445 CX("<span class='labeled-input'>");
446 CX("<input type='checkbox' id='opt-cb-sbs' ");
447 CX("data-csstgt='#main-wrapper' ");
448 CX("data-cssclass='side-by-side' ");
449 CX("data-config='sideBySide'>");
450 CX("<label for='opt-cb-sbs'>Side-by-side</label>");
451 CX("</span>");
452 CX("<span class='labeled-input'>");
453 CX("<input type='checkbox' id='opt-cb-swapio' ");
454 CX("data-csstgt='#main-wrapper' ");
455 CX("data-cssclass='swapio' ");
456 CX("data-config='swapInOut'>");
457 CX("<label for='opt-cb-swapio'>Swap in/out</label>");
458 CX("</span>");
459 CX("<span class='labeled-input'>");
460 CX("<input type='checkbox' id='opt-cb-autofit' ");
461 CX("data-config='renderAutofit'>");
462 CX("<label for='opt-cb-autofit' "
463 "title='Attempt to scale SVG to fit viewport. "
464 "Whether it will work depends in part on the size "
465 "and shape of the image and the viewport.'"
466 ">Auto-fit SVG</label>");
467 CX("</span>");
468 CX("<span class='labeled-input'>");
469 CX("<input type='checkbox' id='opt-cb-autorender' ");
470 CX("data-csstgt='#main-wrapper' ");
471 CX("data-cssclass='auto-render' ");
472 CX("data-config='renderWhileTyping'>");
473 CX("<label for='opt-cb-autorender'>Render while typing</label>");
474 CX("</span>");
475 CX("<span class='labeled-input'>");
476 CX("<a href='?legacy'>Legacy mode</a>");
477 CX("</span>");
478 CX("</div><!-- options wrapper -->");
479 } CX("</fieldset>");
480 CX("<div id='main-wrapper' class=''>"); {
481 CX("<fieldset class='zone-wrapper input'>"); {
482 CX("<legend><div class='button-bar'>");
483 CX("<button id='btn-render' "
484 "title='Ctrl-Enter/Shift-Enter'>Render</button>");
485 CX("<button id='btn-clear'>Clear Input</button>");
486 CX("</div></legend>");
487 CX("<div><textarea id='input'");
488 CX("placeholder='Pikchr input. Ctrl-enter/shift-enter runs it.'>");
489 CX("/**\n");
490 CX(" Use ctrl-enter or shift-enter to execute\n");
491 CX(" pikchr code. If only a subset is currently\n");
492 CX(" selected, only that part is evaluated.\n*/\n");
493 CX("%s</textarea></div>",zContent/*safe-for-%s*/);
494 } CX("</fieldset><!-- .zone-wrapper.input -->");
495 CX("<fieldset class='zone-wrapper output'>"); {
496 CX("<legend><div class='button-bar'>");
497 CX("<button id='btn-render-mode'>Render Mode</button> ");
498 CX("<span style='white-space:nowrap'>"
499 "<span id='preview-copy-button' "
500 "title='Tap to copy to clipboard.'></span>"
501 "<label for='preview-copy-button' "
502 "title='Tap to copy to clipboard.'></label>"
503 "</span>");
504 CX("</div></legend>");
505 CX("<div id='pikchr-output-wrapper'>");
506 CX("<div id='pikchr-output'></div>");
507 CX("<textarea class='hidden' id='pikchr-output-text'></textarea>");
508 CX("</div>");
509 } CX("</fieldset> <!-- .zone-wrapper.output -->");
510 } CX("</div><!-- #main-wrapper -->");
511 } CX("</div><!-- #view-split -->");
512 builtin_fossil_js_bundle_or("dom", "storage", "copybutton", NULL);
513 builtin_request_js("fossil.page.pikchrshowasm.js");
514 builtin_fulfill_js_requests();
515 style_finish_page();
516 }
517
518
519 /*
520 ** COMMAND: pikchr*
521 **
522 ** Usage: %fossil pikchr [options] ?INFILE? ?OUTFILE?
523
+1 -1
--- src/repolist.c
+++ src/repolist.c
@@ -210,11 +210,11 @@
210210
if( rNow <= x.rMTime ){
211211
x.rMTime = rNow;
212212
}else if( x.rMTime<0.0 ){
213213
x.rMTime = rNow;
214214
}
215
- iAge = (double)(rNow - x.rMTime)*86400;
215
+ iAge = (sqlite3_int64)((rNow - x.rMTime)*86400);
216216
zAge = human_readable_age(rNow - x.rMTime);
217217
if( x.rMTime==0.0 ){
218218
/* This repository has no entry in the "event" table.
219219
** Its age will still be maximum, so data-sortkey will work. */
220220
zAge = mprintf("unknown");
221221
--- src/repolist.c
+++ src/repolist.c
@@ -210,11 +210,11 @@
210 if( rNow <= x.rMTime ){
211 x.rMTime = rNow;
212 }else if( x.rMTime<0.0 ){
213 x.rMTime = rNow;
214 }
215 iAge = (double)(rNow - x.rMTime)*86400;
216 zAge = human_readable_age(rNow - x.rMTime);
217 if( x.rMTime==0.0 ){
218 /* This repository has no entry in the "event" table.
219 ** Its age will still be maximum, so data-sortkey will work. */
220 zAge = mprintf("unknown");
221
--- src/repolist.c
+++ src/repolist.c
@@ -210,11 +210,11 @@
210 if( rNow <= x.rMTime ){
211 x.rMTime = rNow;
212 }else if( x.rMTime<0.0 ){
213 x.rMTime = rNow;
214 }
215 iAge = (sqlite3_int64)((rNow - x.rMTime)*86400);
216 zAge = human_readable_age(rNow - x.rMTime);
217 if( x.rMTime==0.0 ){
218 /* This repository has no entry in the "event" table.
219 ** Its age will still be maximum, so data-sortkey will work. */
220 zAge = mprintf("unknown");
221
+12
--- src/schema.c
+++ src/schema.c
@@ -458,10 +458,11 @@
458458
@ CREATE TABLE ticketchng(
459459
@ -- Do not change any column that begins with tkt_
460460
@ tkt_id INTEGER REFERENCES ticket,
461461
@ tkt_rid INTEGER REFERENCES blob,
462462
@ tkt_mtime DATE,
463
+@ tkt_user TEXT,
463464
@ -- Add as many fields as required below this line
464465
@ login TEXT,
465466
@ username TEXT,
466467
@ mimetype TEXT,
467468
@ icomment TEXT
@@ -488,10 +489,21 @@
488489
# define BKLNK_EVENT 3 /* Technote */
489490
# define BKLNK_FORUM 4 /* Forum post */
490491
# define ValidBklnk(X) (X>=0 && X<=4) /* True if backlink.srctype is valid */
491492
#endif
492493
494
+/*
495
+** Allowed values for MIMEtype codes
496
+*/
497
+#if INTERFACE
498
+# define MT_NONE 0 /* unspecified */
499
+# define MT_WIKI 1 /* Wiki */
500
+# define MT_MARKDOWN 2 /* Markdonw */
501
+# define MT_UNKNOWN 3 /* unknown */
502
+# define ValidMTC(X) ((X)>=0 && (X)<=3) /* True if MIMEtype code is valid */
503
+#endif
504
+
493505
/*
494506
** Predefined tagid values
495507
*/
496508
#if INTERFACE
497509
# define TAG_BGCOLOR 1 /* Set the background color for display */
498510
--- src/schema.c
+++ src/schema.c
@@ -458,10 +458,11 @@
458 @ CREATE TABLE ticketchng(
459 @ -- Do not change any column that begins with tkt_
460 @ tkt_id INTEGER REFERENCES ticket,
461 @ tkt_rid INTEGER REFERENCES blob,
462 @ tkt_mtime DATE,
 
463 @ -- Add as many fields as required below this line
464 @ login TEXT,
465 @ username TEXT,
466 @ mimetype TEXT,
467 @ icomment TEXT
@@ -488,10 +489,21 @@
488 # define BKLNK_EVENT 3 /* Technote */
489 # define BKLNK_FORUM 4 /* Forum post */
490 # define ValidBklnk(X) (X>=0 && X<=4) /* True if backlink.srctype is valid */
491 #endif
492
 
 
 
 
 
 
 
 
 
 
 
493 /*
494 ** Predefined tagid values
495 */
496 #if INTERFACE
497 # define TAG_BGCOLOR 1 /* Set the background color for display */
498
--- src/schema.c
+++ src/schema.c
@@ -458,10 +458,11 @@
458 @ CREATE TABLE ticketchng(
459 @ -- Do not change any column that begins with tkt_
460 @ tkt_id INTEGER REFERENCES ticket,
461 @ tkt_rid INTEGER REFERENCES blob,
462 @ tkt_mtime DATE,
463 @ tkt_user TEXT,
464 @ -- Add as many fields as required below this line
465 @ login TEXT,
466 @ username TEXT,
467 @ mimetype TEXT,
468 @ icomment TEXT
@@ -488,10 +489,21 @@
489 # define BKLNK_EVENT 3 /* Technote */
490 # define BKLNK_FORUM 4 /* Forum post */
491 # define ValidBklnk(X) (X>=0 && X<=4) /* True if backlink.srctype is valid */
492 #endif
493
494 /*
495 ** Allowed values for MIMEtype codes
496 */
497 #if INTERFACE
498 # define MT_NONE 0 /* unspecified */
499 # define MT_WIKI 1 /* Wiki */
500 # define MT_MARKDOWN 2 /* Markdonw */
501 # define MT_UNKNOWN 3 /* unknown */
502 # define ValidMTC(X) ((X)>=0 && (X)<=3) /* True if MIMEtype code is valid */
503 #endif
504
505 /*
506 ** Predefined tagid values
507 */
508 #if INTERFACE
509 # define TAG_BGCOLOR 1 /* Set the background color for display */
510
+2 -2
--- src/search.c
+++ src/search.c
@@ -18,12 +18,12 @@
1818
** This file contains code to implement a search functions
1919
** against timeline comments, check-in content, wiki pages, tickets,
2020
** and/or forum posts.
2121
**
2222
** The search can be either a per-query "grep"-like search that scans
23
-** the entire corpus. Or it can use the FTS4 or FTS5 search engine of
24
-** SQLite. The choice is a administrator configuration option.
23
+** the entire corpus. Or it can use the FTS4 search engine of SQLite.
24
+** The choice is a administrator configuration option.
2525
**
2626
** The first option is referred to as "full-scan search". The second
2727
** option is called "indexed search".
2828
**
2929
** The code in this file is ordered approximately as follows:
3030
--- src/search.c
+++ src/search.c
@@ -18,12 +18,12 @@
18 ** This file contains code to implement a search functions
19 ** against timeline comments, check-in content, wiki pages, tickets,
20 ** and/or forum posts.
21 **
22 ** The search can be either a per-query "grep"-like search that scans
23 ** the entire corpus. Or it can use the FTS4 or FTS5 search engine of
24 ** SQLite. The choice is a administrator configuration option.
25 **
26 ** The first option is referred to as "full-scan search". The second
27 ** option is called "indexed search".
28 **
29 ** The code in this file is ordered approximately as follows:
30
--- src/search.c
+++ src/search.c
@@ -18,12 +18,12 @@
18 ** This file contains code to implement a search functions
19 ** against timeline comments, check-in content, wiki pages, tickets,
20 ** and/or forum posts.
21 **
22 ** The search can be either a per-query "grep"-like search that scans
23 ** the entire corpus. Or it can use the FTS4 search engine of SQLite.
24 ** The choice is a administrator configuration option.
25 **
26 ** The first option is referred to as "full-scan search". The second
27 ** option is called "indexed search".
28 **
29 ** The code in this file is ordered approximately as follows:
30
+3 -1
--- src/skins.c
+++ src/skins.c
@@ -1014,11 +1014,13 @@
10141014
style_header("Customize Skin");
10151015
10161016
@ <p>Customize the look of this Fossil repository by making changes
10171017
@ to the CSS, Header, Footer, and Detail Settings in one of nine "draft"
10181018
@ configurations. Then, after verifying that all is working correctly,
1019
- @ publish the draft to become the new main Skin.<p>
1019
+ @ publish the draft to become the new main Skin. Users can select a skin
1020
+ @ of their choice from the built-in ones or the locally-edited one via
1021
+ @ <a href='%R/skins'>the /skins page</a>.</p>
10201022
@
10211023
@ <a name='step1'></a>
10221024
@ <h1>Step 1: Identify Which Draft To Use</h1>
10231025
@
10241026
@ <p>The main skin of Fossil cannot be edited directly. Instead,
10251027
--- src/skins.c
+++ src/skins.c
@@ -1014,11 +1014,13 @@
1014 style_header("Customize Skin");
1015
1016 @ <p>Customize the look of this Fossil repository by making changes
1017 @ to the CSS, Header, Footer, and Detail Settings in one of nine "draft"
1018 @ configurations. Then, after verifying that all is working correctly,
1019 @ publish the draft to become the new main Skin.<p>
 
 
1020 @
1021 @ <a name='step1'></a>
1022 @ <h1>Step 1: Identify Which Draft To Use</h1>
1023 @
1024 @ <p>The main skin of Fossil cannot be edited directly. Instead,
1025
--- src/skins.c
+++ src/skins.c
@@ -1014,11 +1014,13 @@
1014 style_header("Customize Skin");
1015
1016 @ <p>Customize the look of this Fossil repository by making changes
1017 @ to the CSS, Header, Footer, and Detail Settings in one of nine "draft"
1018 @ configurations. Then, after verifying that all is working correctly,
1019 @ publish the draft to become the new main Skin. Users can select a skin
1020 @ of their choice from the built-in ones or the locally-edited one via
1021 @ <a href='%R/skins'>the /skins page</a>.</p>
1022 @
1023 @ <a name='step1'></a>
1024 @ <h1>Step 1: Identify Which Draft To Use</h1>
1025 @
1026 @ <p>The main skin of Fossil cannot be edited directly. Instead,
1027
--- src/stash.c
+++ src/stash.c
@@ -597,10 +597,11 @@
597597
/* Make sure the stash has committed before running the revert, so that
598598
** we have a copy of the changes before deleting them. */
599599
db_commit_transaction();
600600
g.argv[1] = "revert";
601601
revert_cmd();
602
+ fossil_print("stash %d saved\n", stashid);
602603
return;
603604
}else
604605
if( memcmp(zCmd, "snapshot", nCmd)==0 ){
605606
stash_create();
606607
}else
607608
--- src/stash.c
+++ src/stash.c
@@ -597,10 +597,11 @@
597 /* Make sure the stash has committed before running the revert, so that
598 ** we have a copy of the changes before deleting them. */
599 db_commit_transaction();
600 g.argv[1] = "revert";
601 revert_cmd();
 
602 return;
603 }else
604 if( memcmp(zCmd, "snapshot", nCmd)==0 ){
605 stash_create();
606 }else
607
--- src/stash.c
+++ src/stash.c
@@ -597,10 +597,11 @@
597 /* Make sure the stash has committed before running the revert, so that
598 ** we have a copy of the changes before deleting them. */
599 db_commit_transaction();
600 g.argv[1] = "revert";
601 revert_cmd();
602 fossil_print("stash %d saved\n", stashid);
603 return;
604 }else
605 if( memcmp(zCmd, "snapshot", nCmd)==0 ){
606 stash_create();
607 }else
608
+8
--- src/stat.c
+++ src/stat.c
@@ -280,10 +280,18 @@
280280
@ (%h(RELEASE_VERSION)) <a href='version?verbose'>(details)</a>
281281
@ </td></tr>
282282
@ <tr><th>SQLite&nbsp;Version:</th><td>%.19s(sqlite3_sourceid())
283283
@ [%.10s(&sqlite3_sourceid()[20])] (%s(sqlite3_libversion()))
284284
@ <a href='version?verbose'>(details)</a></td></tr>
285
+ if( g.perm.Admin ){
286
+ const char *zCgi = P("SERVER_SOFTWARE");
287
+ @ <tr><th>OpenSSL&nbsp;Version:</th>
288
+ @ <td>%z(fossil_openssl_version())</td></tr>
289
+ if( zCgi ){
290
+ @ <tr><th>Web&nbsp;Server:</th><td>%s(zCgi)</td></tr>
291
+ }
292
+ }
285293
if( g.eHashPolicy!=HPOLICY_AUTO ){
286294
@ <tr><th>Schema&nbsp;Version:</th><td>%h(g.zAuxSchema),
287295
@ %s(hpolicy_name())</td></tr>
288296
}else{
289297
@ <tr><th>Schema&nbsp;Version:</th><td>%h(g.zAuxSchema)</td></tr>
290298
--- src/stat.c
+++ src/stat.c
@@ -280,10 +280,18 @@
280 @ (%h(RELEASE_VERSION)) <a href='version?verbose'>(details)</a>
281 @ </td></tr>
282 @ <tr><th>SQLite&nbsp;Version:</th><td>%.19s(sqlite3_sourceid())
283 @ [%.10s(&sqlite3_sourceid()[20])] (%s(sqlite3_libversion()))
284 @ <a href='version?verbose'>(details)</a></td></tr>
 
 
 
 
 
 
 
 
285 if( g.eHashPolicy!=HPOLICY_AUTO ){
286 @ <tr><th>Schema&nbsp;Version:</th><td>%h(g.zAuxSchema),
287 @ %s(hpolicy_name())</td></tr>
288 }else{
289 @ <tr><th>Schema&nbsp;Version:</th><td>%h(g.zAuxSchema)</td></tr>
290
--- src/stat.c
+++ src/stat.c
@@ -280,10 +280,18 @@
280 @ (%h(RELEASE_VERSION)) <a href='version?verbose'>(details)</a>
281 @ </td></tr>
282 @ <tr><th>SQLite&nbsp;Version:</th><td>%.19s(sqlite3_sourceid())
283 @ [%.10s(&sqlite3_sourceid()[20])] (%s(sqlite3_libversion()))
284 @ <a href='version?verbose'>(details)</a></td></tr>
285 if( g.perm.Admin ){
286 const char *zCgi = P("SERVER_SOFTWARE");
287 @ <tr><th>OpenSSL&nbsp;Version:</th>
288 @ <td>%z(fossil_openssl_version())</td></tr>
289 if( zCgi ){
290 @ <tr><th>Web&nbsp;Server:</th><td>%s(zCgi)</td></tr>
291 }
292 }
293 if( g.eHashPolicy!=HPOLICY_AUTO ){
294 @ <tr><th>Schema&nbsp;Version:</th><td>%h(g.zAuxSchema),
295 @ %s(hpolicy_name())</td></tr>
296 }else{
297 @ <tr><th>Schema&nbsp;Version:</th><td>%h(g.zAuxSchema)</td></tr>
298
--- src/statrep.c
+++ src/statrep.c
@@ -344,11 +344,10 @@
344344
** Implements the "byuser" view for /reports.
345345
*/
346346
static void stats_report_by_user(){
347347
Stmt query = empty_Stmt;
348348
int nRowNumber = 0; /* current TR number */
349
- int nEventTotal = 0; /* Total event count */
350349
int rowClass = 0; /* counter for alternating
351350
row colors */
352351
int nMaxEvents = 1; /* max number of events for
353352
all rows. */
354353
stats_report_init_view();
@@ -392,11 +391,10 @@
392391
? (int)(100 * nCount / nMaxEvents)
393392
: 0;
394393
if(!nCount) continue /* arguable! Possible? */;
395394
else if(!nSize) nSize = 1;
396395
rowClass = ++nRowNumber % 2;
397
- nEventTotal += nCount;
398396
@ <tr class='row%d(rowClass)'>
399397
@ <td>
400398
@ <a href="?view=bymonth&user=%h(zUser)&type=%c(y)">%h(zUser)</a>
401399
@ </td><td data-sortkey='%08x(-nCount)'>%d(nCount)</td>
402400
@ <td>
@@ -475,11 +473,10 @@
475473
** the report is restricted to events created by the named user account.
476474
*/
477475
static void stats_report_day_of_week(const char *zUserName){
478476
Stmt query = empty_Stmt;
479477
int nRowNumber = 0; /* current TR number */
480
- int nEventTotal = 0; /* Total event count */
481478
int rowClass = 0; /* counter for alternating
482479
row colors */
483480
int nMaxEvents = 1; /* max number of events for
484481
all rows. */
485482
Blob userFilter = empty_blob; /* Optional user=johndoe query string */
@@ -549,11 +546,10 @@
549546
? (int)(100 * nCount / nMaxEvents)
550547
: 0;
551548
if(!nCount) continue /* arguable! Possible? */;
552549
else if(!nSize) nSize = 1;
553550
rowClass = ++nRowNumber % 2;
554
- nEventTotal += nCount;
555551
@<tr class='row%d(rowClass)'>
556552
@ <td>%d(dayNum)</td>
557553
@ <td>%s(daysOfWeek[dayNum])</td>
558554
@ <td>%d(nCount)</td>
559555
@ <td>
560556
--- src/statrep.c
+++ src/statrep.c
@@ -344,11 +344,10 @@
344 ** Implements the "byuser" view for /reports.
345 */
346 static void stats_report_by_user(){
347 Stmt query = empty_Stmt;
348 int nRowNumber = 0; /* current TR number */
349 int nEventTotal = 0; /* Total event count */
350 int rowClass = 0; /* counter for alternating
351 row colors */
352 int nMaxEvents = 1; /* max number of events for
353 all rows. */
354 stats_report_init_view();
@@ -392,11 +391,10 @@
392 ? (int)(100 * nCount / nMaxEvents)
393 : 0;
394 if(!nCount) continue /* arguable! Possible? */;
395 else if(!nSize) nSize = 1;
396 rowClass = ++nRowNumber % 2;
397 nEventTotal += nCount;
398 @ <tr class='row%d(rowClass)'>
399 @ <td>
400 @ <a href="?view=bymonth&user=%h(zUser)&type=%c(y)">%h(zUser)</a>
401 @ </td><td data-sortkey='%08x(-nCount)'>%d(nCount)</td>
402 @ <td>
@@ -475,11 +473,10 @@
475 ** the report is restricted to events created by the named user account.
476 */
477 static void stats_report_day_of_week(const char *zUserName){
478 Stmt query = empty_Stmt;
479 int nRowNumber = 0; /* current TR number */
480 int nEventTotal = 0; /* Total event count */
481 int rowClass = 0; /* counter for alternating
482 row colors */
483 int nMaxEvents = 1; /* max number of events for
484 all rows. */
485 Blob userFilter = empty_blob; /* Optional user=johndoe query string */
@@ -549,11 +546,10 @@
549 ? (int)(100 * nCount / nMaxEvents)
550 : 0;
551 if(!nCount) continue /* arguable! Possible? */;
552 else if(!nSize) nSize = 1;
553 rowClass = ++nRowNumber % 2;
554 nEventTotal += nCount;
555 @<tr class='row%d(rowClass)'>
556 @ <td>%d(dayNum)</td>
557 @ <td>%s(daysOfWeek[dayNum])</td>
558 @ <td>%d(nCount)</td>
559 @ <td>
560
--- src/statrep.c
+++ src/statrep.c
@@ -344,11 +344,10 @@
344 ** Implements the "byuser" view for /reports.
345 */
346 static void stats_report_by_user(){
347 Stmt query = empty_Stmt;
348 int nRowNumber = 0; /* current TR number */
 
349 int rowClass = 0; /* counter for alternating
350 row colors */
351 int nMaxEvents = 1; /* max number of events for
352 all rows. */
353 stats_report_init_view();
@@ -392,11 +391,10 @@
391 ? (int)(100 * nCount / nMaxEvents)
392 : 0;
393 if(!nCount) continue /* arguable! Possible? */;
394 else if(!nSize) nSize = 1;
395 rowClass = ++nRowNumber % 2;
 
396 @ <tr class='row%d(rowClass)'>
397 @ <td>
398 @ <a href="?view=bymonth&user=%h(zUser)&type=%c(y)">%h(zUser)</a>
399 @ </td><td data-sortkey='%08x(-nCount)'>%d(nCount)</td>
400 @ <td>
@@ -475,11 +473,10 @@
473 ** the report is restricted to events created by the named user account.
474 */
475 static void stats_report_day_of_week(const char *zUserName){
476 Stmt query = empty_Stmt;
477 int nRowNumber = 0; /* current TR number */
 
478 int rowClass = 0; /* counter for alternating
479 row colors */
480 int nMaxEvents = 1; /* max number of events for
481 all rows. */
482 Blob userFilter = empty_blob; /* Optional user=johndoe query string */
@@ -549,11 +546,10 @@
546 ? (int)(100 * nCount / nMaxEvents)
547 : 0;
548 if(!nCount) continue /* arguable! Possible? */;
549 else if(!nSize) nSize = 1;
550 rowClass = ++nRowNumber % 2;
 
551 @<tr class='row%d(rowClass)'>
552 @ <td>%d(dayNum)</td>
553 @ <td>%s(daysOfWeek[dayNum])</td>
554 @ <td>%d(nCount)</td>
555 @ <td>
556
+55 -11
--- src/style.c
+++ src/style.c
@@ -647,20 +647,20 @@
647647
** prepended.
648648
*/
649649
static const char zDfltHeader[] =
650650
@ <html>
651651
@ <head>
652
-@ <base href="$baseurl/$current_page" />
653652
@ <meta charset="UTF-8">
653
+@ <base href="$baseurl/$current_page" />
654654
@ <meta http-equiv="Content-Security-Policy" content="$default_csp" />
655655
@ <meta name="viewport" content="width=device-width, initial-scale=1.0">
656656
@ <title>$<project_name>: $<title></title>
657657
@ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \
658658
@ href="$home/timeline.rss" />
659659
@ <link rel="stylesheet" href="$stylesheet_url" type="text/css" />
660660
@ </head>
661
-@ <body class="$current_feature">
661
+@ <body class="$current_feature rpage-$requested_page cpage-$canonical_page">
662662
;
663663
664664
/*
665665
** Returns the default page header.
666666
*/
@@ -769,10 +769,19 @@
769769
Th_Store("secureurl", fossil_wants_https(1)? g.zHttpsURL: g.zBaseURL);
770770
Th_Store("home", g.zTop);
771771
Th_Store("index_page", db_get("index-page","/home"));
772772
if( local_zCurrentPage==0 ) style_set_current_page("%T", g.zPath);
773773
Th_Store("current_page", local_zCurrentPage);
774
+ if( g.zPath ){ /* store the first segment of a path; */
775
+ char *pSlash = strchr(g.zPath,'/');
776
+ if( pSlash ) *pSlash = 0; /* make a temporary cut if necessary */
777
+ Th_Store("requested_page", escape_quotes(g.zPath));
778
+ if( pSlash ) *pSlash = '/';
779
+ }else{
780
+ Th_Store("requested_page", "");
781
+ }
782
+ Th_Store("canonical_page", escape_quotes(g.zPhase+1));
774783
Th_Store("csrf_token", g.zCsrfToken);
775784
Th_Store("release_version", RELEASE_VERSION);
776785
Th_Store("manifest_version", MANIFEST_VERSION);
777786
Th_Store("manifest_date", MANIFEST_DATE);
778787
Th_Store("compiler_name", COMPILER_NAME);
@@ -892,11 +901,11 @@
892901
static void style_load_all_js_files(void){
893902
if( needHrefJs && g.perm.Hyperlink ){
894903
int nDelay = db_get_int("auto-hyperlink-delay",0);
895904
int bMouseover = db_get_boolean("auto-hyperlink-mouseover",0)
896905
&& sqlite3_strglob("*Android*",PD("HTTP_USER_AGENT",""));
897
- @ <script id='href-data' type='application/json'>\
906
+ @ <script id='href-data' type='text/json'>\
898907
@ {"delay":%d(nDelay),"mouseover":%d(bMouseover)}</script>
899908
}
900909
@ <script nonce="%h(style_nonce())">/* style.c:%d(__LINE__) */
901910
@ function debugMsg(msg){
902911
@ var n = document.getElementById("debugMsg");
@@ -912,10 +921,41 @@
912921
cgi_append_content("\n}\n", -1);
913922
}
914923
@ </script>
915924
builtin_fulfill_js_requests();
916925
}
926
+
927
+/*
928
+** Transorm input string into a token that is safe for inclusion into
929
+** class attribute. Digits and low-case letter are passed unchanged,
930
+** upper-case letters are transformed to low-case, everything else is
931
+** tranformed into hyphens; consequtive and pending hyphens are squeezed.
932
+** If result does not fit into szOut chars then it is truncated.
933
+** Result is always terminated with null.
934
+*/
935
+void style_derive_classname(const char *zIn, char *zOut, int szOut){
936
+ assert( zOut );
937
+ assert( szOut>0 );
938
+ if( zIn ){
939
+ int n = 0; /* number of chars written to zOut */
940
+ char c;
941
+ for(--szOut; (c=*zIn) && n<szOut; zIn++) {
942
+ if( ('a'<=c && c<='z') || ('0'<=c && c<='9') ){
943
+ *zOut = c;
944
+ }else if( 'A'<=c && c<='Z' ){
945
+ *zOut = c - 'A' + 'a';
946
+ }else{
947
+ if( n==0 || zOut[-1]=='-' ) continue;
948
+ *zOut = '-';
949
+ }
950
+ zOut++;
951
+ n++;
952
+ }
953
+ if( n && zOut[-1]=='-' ) zOut--;
954
+ }
955
+ *zOut = 0;
956
+}
917957
918958
/*
919959
** Invoke this routine after all of the content for a webpage has been
920960
** generated. This routine should be called once for every webpage, at
921961
** or near the end of page generation. This routine does the following:
@@ -941,10 +981,11 @@
941981
** to the submenu while generating page text.
942982
*/
943983
cgi_destination(CGI_HEADER);
944984
if( submenuEnable && nSubmenu+nSubmenuCtrl>0 ){
945985
int i;
986
+ char zClass[32]; /* reduced form of the main attribute */
946987
if( nSubmenuCtrl ){
947988
@ <form id='f01' method='GET' action='%R/%s(g.zPath)'>
948989
@ <input type='hidden' name='udc' value='1'>
949990
cgi_tag_query_parameter("udc");
950991
}
@@ -951,33 +992,36 @@
951992
@ <div class="submenu">
952993
if( nSubmenu>0 ){
953994
qsort(aSubmenu, nSubmenu, sizeof(aSubmenu[0]), submenuCompare);
954995
for(i=0; i<nSubmenu; i++){
955996
struct Submenu *p = &aSubmenu[i];
997
+ style_derive_classname(p->zLabel, zClass, sizeof zClass);
956998
/* switching away from the %h formatting below might be dangerous
957999
** because some places use %s to compose zLabel and zLink;
958
- ** e.g. /rptview page
1000
+ ** e.g. /rptview page. "sml" stands for submenu link.
9591001
*/
9601002
if( p->zLink==0 ){
961
- @ <span class="label">%h(p->zLabel)</span>
1003
+ @ <span class="label sml-%s(zClass)">%h(p->zLabel)</span>
9621004
}else{
963
- @ <a class="label" href="%h(p->zLink)">%h(p->zLabel)</a>
1005
+ @ <a class="label sml-%s(zClass)" href="%h(p->zLink)">%h(p->zLabel)</a>
9641006
}
9651007
}
9661008
}
1009
+ strcpy(zClass,"smc-"); /* common prefix for submenu controls */
9671010
for(i=0; i<nSubmenuCtrl; i++){
9681011
const char *zQPN = aSubmenuCtrl[i].zName;
9691012
const char *zDisabled = "";
9701013
const char *zXtraClass = "";
9711014
if( aSubmenuCtrl[i].eVisible & STYLE_DISABLED ){
9721015
zDisabled = " disabled";
9731016
}else if( zQPN ){
9741017
cgi_tag_query_parameter(zQPN);
9751018
}
1019
+ style_derive_classname(zQPN, zClass+4, sizeof(zClass)-4);
9761020
switch( aSubmenuCtrl[i].eType ){
9771021
case FF_ENTRY:
978
- @ <span class='submenuctrl%s(zXtraClass)'>\
1022
+ @ <span class='submenuctrl%s(zXtraClass) %s(zClass)'>\
9791023
@ &nbsp;%h(aSubmenuCtrl[i].zLabel)\
9801024
@ <input type='text' name='%s(zQPN)' value='%h(PD(zQPN, ""))' \
9811025
if( aSubmenuCtrl[i].iSize<0 ){
9821026
@ size='%d(-aSubmenuCtrl[i].iSize)' \
9831027
}else if( aSubmenuCtrl[i].iSize>0 ){
@@ -988,16 +1032,16 @@
9881032
break;
9891033
case FF_MULTI: {
9901034
int j;
9911035
const char *zVal = P(zQPN);
9921036
if( zXtraClass[0] ){
993
- @ <span class='%s(zXtraClass+1)'>
1037
+ @ <span class='%s(zXtraClass+1) %s(zClass)'>
9941038
}
9951039
if( aSubmenuCtrl[i].zLabel ){
9961040
@ &nbsp;%h(aSubmenuCtrl[i].zLabel)\
9971041
}
998
- @ <select class='submenuctrl' size='1' name='%s(zQPN)' \
1042
+ @ <select class='submenuctrl %s(zClass)' size='1' name='%s(zQPN)' \
9991043
@ id='submenuctrl-%d(i)'%s(zDisabled)>
10001044
for(j=0; j<aSubmenuCtrl[i].iSize*2; j+=2){
10011045
const char *zQPV = aSubmenuCtrl[i].azChoice[j];
10021046
@ <option value='%h(zQPV)'\
10031047
if( fossil_strcmp(zVal, zQPV)==0 ){
@@ -1027,11 +1071,11 @@
10271071
@ >%h(aSubmenuCtrl[i].zFalse)</option>
10281072
@ </select>
10291073
break;
10301074
}
10311075
case FF_CHECKBOX: {
1032
- @ <label class='submenuctrl submenuckbox%s(zXtraClass)'>\
1076
+ @ <label class='submenuctrl submenuckbox%s(zXtraClass) %s(zClass)'>\
10331077
@ <input type='checkbox' name='%s(zQPN)' id='submenuctrl-%d(i)' \
10341078
if( PB(zQPN) ){
10351079
@ checked \
10361080
}
10371081
if( aSubmenuCtrl[i].zJS ){
@@ -1176,11 +1220,11 @@
11761220
/* Render the script as plain-text for testing purposes, if the "test"
11771221
** query parameter is present */
11781222
cgi_set_content_type("text/plain");
11791223
}else{
11801224
/* Default behavior is to return javascript */
1181
- cgi_set_content_type("application/javascript");
1225
+ cgi_set_content_type("text/javascript");
11821226
}
11831227
style_init_th1_vars(0);
11841228
Th_Render(zScript?zScript:"");
11851229
}
11861230
11871231
11881232
ADDED src/style.pikchrshow.css
--- src/style.c
+++ src/style.c
@@ -647,20 +647,20 @@
647 ** prepended.
648 */
649 static const char zDfltHeader[] =
650 @ <html>
651 @ <head>
652 @ <base href="$baseurl/$current_page" />
653 @ <meta charset="UTF-8">
 
654 @ <meta http-equiv="Content-Security-Policy" content="$default_csp" />
655 @ <meta name="viewport" content="width=device-width, initial-scale=1.0">
656 @ <title>$<project_name>: $<title></title>
657 @ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \
658 @ href="$home/timeline.rss" />
659 @ <link rel="stylesheet" href="$stylesheet_url" type="text/css" />
660 @ </head>
661 @ <body class="$current_feature">
662 ;
663
664 /*
665 ** Returns the default page header.
666 */
@@ -769,10 +769,19 @@
769 Th_Store("secureurl", fossil_wants_https(1)? g.zHttpsURL: g.zBaseURL);
770 Th_Store("home", g.zTop);
771 Th_Store("index_page", db_get("index-page","/home"));
772 if( local_zCurrentPage==0 ) style_set_current_page("%T", g.zPath);
773 Th_Store("current_page", local_zCurrentPage);
 
 
 
 
 
 
 
 
 
774 Th_Store("csrf_token", g.zCsrfToken);
775 Th_Store("release_version", RELEASE_VERSION);
776 Th_Store("manifest_version", MANIFEST_VERSION);
777 Th_Store("manifest_date", MANIFEST_DATE);
778 Th_Store("compiler_name", COMPILER_NAME);
@@ -892,11 +901,11 @@
892 static void style_load_all_js_files(void){
893 if( needHrefJs && g.perm.Hyperlink ){
894 int nDelay = db_get_int("auto-hyperlink-delay",0);
895 int bMouseover = db_get_boolean("auto-hyperlink-mouseover",0)
896 && sqlite3_strglob("*Android*",PD("HTTP_USER_AGENT",""));
897 @ <script id='href-data' type='application/json'>\
898 @ {"delay":%d(nDelay),"mouseover":%d(bMouseover)}</script>
899 }
900 @ <script nonce="%h(style_nonce())">/* style.c:%d(__LINE__) */
901 @ function debugMsg(msg){
902 @ var n = document.getElementById("debugMsg");
@@ -912,10 +921,41 @@
912 cgi_append_content("\n}\n", -1);
913 }
914 @ </script>
915 builtin_fulfill_js_requests();
916 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
917
918 /*
919 ** Invoke this routine after all of the content for a webpage has been
920 ** generated. This routine should be called once for every webpage, at
921 ** or near the end of page generation. This routine does the following:
@@ -941,10 +981,11 @@
941 ** to the submenu while generating page text.
942 */
943 cgi_destination(CGI_HEADER);
944 if( submenuEnable && nSubmenu+nSubmenuCtrl>0 ){
945 int i;
 
946 if( nSubmenuCtrl ){
947 @ <form id='f01' method='GET' action='%R/%s(g.zPath)'>
948 @ <input type='hidden' name='udc' value='1'>
949 cgi_tag_query_parameter("udc");
950 }
@@ -951,33 +992,36 @@
951 @ <div class="submenu">
952 if( nSubmenu>0 ){
953 qsort(aSubmenu, nSubmenu, sizeof(aSubmenu[0]), submenuCompare);
954 for(i=0; i<nSubmenu; i++){
955 struct Submenu *p = &aSubmenu[i];
 
956 /* switching away from the %h formatting below might be dangerous
957 ** because some places use %s to compose zLabel and zLink;
958 ** e.g. /rptview page
959 */
960 if( p->zLink==0 ){
961 @ <span class="label">%h(p->zLabel)</span>
962 }else{
963 @ <a class="label" href="%h(p->zLink)">%h(p->zLabel)</a>
964 }
965 }
966 }
 
967 for(i=0; i<nSubmenuCtrl; i++){
968 const char *zQPN = aSubmenuCtrl[i].zName;
969 const char *zDisabled = "";
970 const char *zXtraClass = "";
971 if( aSubmenuCtrl[i].eVisible & STYLE_DISABLED ){
972 zDisabled = " disabled";
973 }else if( zQPN ){
974 cgi_tag_query_parameter(zQPN);
975 }
 
976 switch( aSubmenuCtrl[i].eType ){
977 case FF_ENTRY:
978 @ <span class='submenuctrl%s(zXtraClass)'>\
979 @ &nbsp;%h(aSubmenuCtrl[i].zLabel)\
980 @ <input type='text' name='%s(zQPN)' value='%h(PD(zQPN, ""))' \
981 if( aSubmenuCtrl[i].iSize<0 ){
982 @ size='%d(-aSubmenuCtrl[i].iSize)' \
983 }else if( aSubmenuCtrl[i].iSize>0 ){
@@ -988,16 +1032,16 @@
988 break;
989 case FF_MULTI: {
990 int j;
991 const char *zVal = P(zQPN);
992 if( zXtraClass[0] ){
993 @ <span class='%s(zXtraClass+1)'>
994 }
995 if( aSubmenuCtrl[i].zLabel ){
996 @ &nbsp;%h(aSubmenuCtrl[i].zLabel)\
997 }
998 @ <select class='submenuctrl' size='1' name='%s(zQPN)' \
999 @ id='submenuctrl-%d(i)'%s(zDisabled)>
1000 for(j=0; j<aSubmenuCtrl[i].iSize*2; j+=2){
1001 const char *zQPV = aSubmenuCtrl[i].azChoice[j];
1002 @ <option value='%h(zQPV)'\
1003 if( fossil_strcmp(zVal, zQPV)==0 ){
@@ -1027,11 +1071,11 @@
1027 @ >%h(aSubmenuCtrl[i].zFalse)</option>
1028 @ </select>
1029 break;
1030 }
1031 case FF_CHECKBOX: {
1032 @ <label class='submenuctrl submenuckbox%s(zXtraClass)'>\
1033 @ <input type='checkbox' name='%s(zQPN)' id='submenuctrl-%d(i)' \
1034 if( PB(zQPN) ){
1035 @ checked \
1036 }
1037 if( aSubmenuCtrl[i].zJS ){
@@ -1176,11 +1220,11 @@
1176 /* Render the script as plain-text for testing purposes, if the "test"
1177 ** query parameter is present */
1178 cgi_set_content_type("text/plain");
1179 }else{
1180 /* Default behavior is to return javascript */
1181 cgi_set_content_type("application/javascript");
1182 }
1183 style_init_th1_vars(0);
1184 Th_Render(zScript?zScript:"");
1185 }
1186
1187
1188 DDED src/style.pikchrshow.css
--- src/style.c
+++ src/style.c
@@ -647,20 +647,20 @@
647 ** prepended.
648 */
649 static const char zDfltHeader[] =
650 @ <html>
651 @ <head>
 
652 @ <meta charset="UTF-8">
653 @ <base href="$baseurl/$current_page" />
654 @ <meta http-equiv="Content-Security-Policy" content="$default_csp" />
655 @ <meta name="viewport" content="width=device-width, initial-scale=1.0">
656 @ <title>$<project_name>: $<title></title>
657 @ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \
658 @ href="$home/timeline.rss" />
659 @ <link rel="stylesheet" href="$stylesheet_url" type="text/css" />
660 @ </head>
661 @ <body class="$current_feature rpage-$requested_page cpage-$canonical_page">
662 ;
663
664 /*
665 ** Returns the default page header.
666 */
@@ -769,10 +769,19 @@
769 Th_Store("secureurl", fossil_wants_https(1)? g.zHttpsURL: g.zBaseURL);
770 Th_Store("home", g.zTop);
771 Th_Store("index_page", db_get("index-page","/home"));
772 if( local_zCurrentPage==0 ) style_set_current_page("%T", g.zPath);
773 Th_Store("current_page", local_zCurrentPage);
774 if( g.zPath ){ /* store the first segment of a path; */
775 char *pSlash = strchr(g.zPath,'/');
776 if( pSlash ) *pSlash = 0; /* make a temporary cut if necessary */
777 Th_Store("requested_page", escape_quotes(g.zPath));
778 if( pSlash ) *pSlash = '/';
779 }else{
780 Th_Store("requested_page", "");
781 }
782 Th_Store("canonical_page", escape_quotes(g.zPhase+1));
783 Th_Store("csrf_token", g.zCsrfToken);
784 Th_Store("release_version", RELEASE_VERSION);
785 Th_Store("manifest_version", MANIFEST_VERSION);
786 Th_Store("manifest_date", MANIFEST_DATE);
787 Th_Store("compiler_name", COMPILER_NAME);
@@ -892,11 +901,11 @@
901 static void style_load_all_js_files(void){
902 if( needHrefJs && g.perm.Hyperlink ){
903 int nDelay = db_get_int("auto-hyperlink-delay",0);
904 int bMouseover = db_get_boolean("auto-hyperlink-mouseover",0)
905 && sqlite3_strglob("*Android*",PD("HTTP_USER_AGENT",""));
906 @ <script id='href-data' type='text/json'>\
907 @ {"delay":%d(nDelay),"mouseover":%d(bMouseover)}</script>
908 }
909 @ <script nonce="%h(style_nonce())">/* style.c:%d(__LINE__) */
910 @ function debugMsg(msg){
911 @ var n = document.getElementById("debugMsg");
@@ -912,10 +921,41 @@
921 cgi_append_content("\n}\n", -1);
922 }
923 @ </script>
924 builtin_fulfill_js_requests();
925 }
926
927 /*
928 ** Transorm input string into a token that is safe for inclusion into
929 ** class attribute. Digits and low-case letter are passed unchanged,
930 ** upper-case letters are transformed to low-case, everything else is
931 ** tranformed into hyphens; consequtive and pending hyphens are squeezed.
932 ** If result does not fit into szOut chars then it is truncated.
933 ** Result is always terminated with null.
934 */
935 void style_derive_classname(const char *zIn, char *zOut, int szOut){
936 assert( zOut );
937 assert( szOut>0 );
938 if( zIn ){
939 int n = 0; /* number of chars written to zOut */
940 char c;
941 for(--szOut; (c=*zIn) && n<szOut; zIn++) {
942 if( ('a'<=c && c<='z') || ('0'<=c && c<='9') ){
943 *zOut = c;
944 }else if( 'A'<=c && c<='Z' ){
945 *zOut = c - 'A' + 'a';
946 }else{
947 if( n==0 || zOut[-1]=='-' ) continue;
948 *zOut = '-';
949 }
950 zOut++;
951 n++;
952 }
953 if( n && zOut[-1]=='-' ) zOut--;
954 }
955 *zOut = 0;
956 }
957
958 /*
959 ** Invoke this routine after all of the content for a webpage has been
960 ** generated. This routine should be called once for every webpage, at
961 ** or near the end of page generation. This routine does the following:
@@ -941,10 +981,11 @@
981 ** to the submenu while generating page text.
982 */
983 cgi_destination(CGI_HEADER);
984 if( submenuEnable && nSubmenu+nSubmenuCtrl>0 ){
985 int i;
986 char zClass[32]; /* reduced form of the main attribute */
987 if( nSubmenuCtrl ){
988 @ <form id='f01' method='GET' action='%R/%s(g.zPath)'>
989 @ <input type='hidden' name='udc' value='1'>
990 cgi_tag_query_parameter("udc");
991 }
@@ -951,33 +992,36 @@
992 @ <div class="submenu">
993 if( nSubmenu>0 ){
994 qsort(aSubmenu, nSubmenu, sizeof(aSubmenu[0]), submenuCompare);
995 for(i=0; i<nSubmenu; i++){
996 struct Submenu *p = &aSubmenu[i];
997 style_derive_classname(p->zLabel, zClass, sizeof zClass);
998 /* switching away from the %h formatting below might be dangerous
999 ** because some places use %s to compose zLabel and zLink;
1000 ** e.g. /rptview page. "sml" stands for submenu link.
1001 */
1002 if( p->zLink==0 ){
1003 @ <span class="label sml-%s(zClass)">%h(p->zLabel)</span>
1004 }else{
1005 @ <a class="label sml-%s(zClass)" href="%h(p->zLink)">%h(p->zLabel)</a>
1006 }
1007 }
1008 }
1009 strcpy(zClass,"smc-"); /* common prefix for submenu controls */
1010 for(i=0; i<nSubmenuCtrl; i++){
1011 const char *zQPN = aSubmenuCtrl[i].zName;
1012 const char *zDisabled = "";
1013 const char *zXtraClass = "";
1014 if( aSubmenuCtrl[i].eVisible & STYLE_DISABLED ){
1015 zDisabled = " disabled";
1016 }else if( zQPN ){
1017 cgi_tag_query_parameter(zQPN);
1018 }
1019 style_derive_classname(zQPN, zClass+4, sizeof(zClass)-4);
1020 switch( aSubmenuCtrl[i].eType ){
1021 case FF_ENTRY:
1022 @ <span class='submenuctrl%s(zXtraClass) %s(zClass)'>\
1023 @ &nbsp;%h(aSubmenuCtrl[i].zLabel)\
1024 @ <input type='text' name='%s(zQPN)' value='%h(PD(zQPN, ""))' \
1025 if( aSubmenuCtrl[i].iSize<0 ){
1026 @ size='%d(-aSubmenuCtrl[i].iSize)' \
1027 }else if( aSubmenuCtrl[i].iSize>0 ){
@@ -988,16 +1032,16 @@
1032 break;
1033 case FF_MULTI: {
1034 int j;
1035 const char *zVal = P(zQPN);
1036 if( zXtraClass[0] ){
1037 @ <span class='%s(zXtraClass+1) %s(zClass)'>
1038 }
1039 if( aSubmenuCtrl[i].zLabel ){
1040 @ &nbsp;%h(aSubmenuCtrl[i].zLabel)\
1041 }
1042 @ <select class='submenuctrl %s(zClass)' size='1' name='%s(zQPN)' \
1043 @ id='submenuctrl-%d(i)'%s(zDisabled)>
1044 for(j=0; j<aSubmenuCtrl[i].iSize*2; j+=2){
1045 const char *zQPV = aSubmenuCtrl[i].azChoice[j];
1046 @ <option value='%h(zQPV)'\
1047 if( fossil_strcmp(zVal, zQPV)==0 ){
@@ -1027,11 +1071,11 @@
1071 @ >%h(aSubmenuCtrl[i].zFalse)</option>
1072 @ </select>
1073 break;
1074 }
1075 case FF_CHECKBOX: {
1076 @ <label class='submenuctrl submenuckbox%s(zXtraClass) %s(zClass)'>\
1077 @ <input type='checkbox' name='%s(zQPN)' id='submenuctrl-%d(i)' \
1078 if( PB(zQPN) ){
1079 @ checked \
1080 }
1081 if( aSubmenuCtrl[i].zJS ){
@@ -1176,11 +1220,11 @@
1220 /* Render the script as plain-text for testing purposes, if the "test"
1221 ** query parameter is present */
1222 cgi_set_content_type("text/plain");
1223 }else{
1224 /* Default behavior is to return javascript */
1225 cgi_set_content_type("text/javascript");
1226 }
1227 style_init_th1_vars(0);
1228 Th_Render(zScript?zScript:"");
1229 }
1230
1231
1232 DDED src/style.pikchrshow.css
--- a/src/style.pikchrshow.css
+++ b/src/style.pikchrshow.css
@@ -0,0 +1,163 @@
1
+ during the module load/initialization processes... */
2
+.emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
3
+div.emscripten { text-align: center; }
4
+div.emscripten_border { border: 1px solid black; }
5
+#module-spinner { overflow: visible; }
6
+#module-spinner > * {
7
+ margin-top: 1em;
8
+}
9
+.spinner {
10
+ height: 50px;
11
+ width: 50px;
12
+ margin: 0px auto;
13
+ animation: rotation 0.8s linear infinite;
14
+ border-left: 10px solid rgb(0,150,240);
15
+ border-right: 10px solid rgb(0,150,240);
16
+ border-bottom: 10px solid rgb(0,150,240);
17
+ border-top: 10px solid rgb(100,0,200);
18
+ border-radius: 100%;
19
+ background-color: rgb(200,100,250);
20
+}
21
+@keyframes rotation {
22
+ from {transform: rotate(0deg);}
23
+ to {transform: rotate(360deg);}
24
+}
25
+
26
+/* The following styles are for app-level use. */
27
+/* TODO: consolidate the WASM- and legacy-mode CSS into this file.
28
+ Since both versions of /pikchrshow share a URI, they both load this
29
+ file. */
30
+textarea {
31
+ font-family: monospace;
32
+ flex: 1 1 auto;
33
+}
34
+#main-wrapper {
35
+ display: flex;
36
+ flex-direction: column-reverse;
37
+ flex: 1 1 auto;
38
+ margin: 0.5em 0;
39
+ overflow: hidden;
40
+}
41
+#main-wrapper.side-by-side {
42
+ flex-direction: row;
43
+}
44
+#main-wrapper.side-by-side > fieldset {
45
+ margin-left: 0.25em;
46
+ margin-right: 0.25em;
47
+}
48
+#main-wrapper:not(.side-by-side) > fieldset {
49
+ margin-bottom: 0.25em;
50
+}
51
+#main-wrapper.swapio {
52
+ flex-direction: column;
53
+}
54
+#main-wrapper.side-by-side.swapio {
55
+ flex-direction: row-reverse;
56
+}
57
+.zone-wrapper{
58
+ display: flex;
59
+ margin: 0;
60
+ flex: 1 1 0%;
61
+ border-radius: 0.5em;
62
+ min-width: inherit/*important: resolves inability to scroll fieldset child element!*/;
63
+ padding: 0.35em 0 0 0;
64
+}
65
+.zone-wrapper > div {
66
+ display:flex;
67
+ flex: 1 1 0%;
68
+}
69
+.zone-wrapper.output {
70
+}
71
+#main-wrapper.side-by-side .zone-wrapper {
72
+ /* Keep the layout from "flopping around" when
73
+ render-while-typing mode is on. */
74
+ /*max-width: 50%;*/
75
+}
76
+#pikchr-output {
77
+ padding: 0;
78
+ margin: 0 auto/*auto resolves a weird left-shift truncation of the SVG*/;
79
+}
80
+#pikchr-output-wrapper {
81
+ flex: 1 1 auto;
82
+ overflow: auto;
83
+}
84
+#pikchr-output-wrapper.text {
85
+ display: flex;
86
+ align-items: stretch;
87
+}
88
+#pikchr-output-wrapper:not(.autofit) {;
89
+}
90
+#main-wrapper:not(.szation processes... */
91
+. duriper.text > #pikchr-output {
92
+ display: flex;
93
+ align-items: stretch;
94
+ fle during the module loa module load/initializat during the module load/initialization processes... */
95
+.emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
96
+div.emscripten { text-align: center; }
97
+div.emscripten_border { border: 1px solid black; }
98
+#module-spinner { overflow: visible; }
99
+#module-spinner > * {
100
+ margin-top: 1em;
101
+}
102
+.spinner {
103
+ height: 50px;
104
+ width: 50px;
105
+ margin: 0px auto;
106
+ animation: rotation 0.8s linear infinite;
107
+ border-left: 10px solid rgb(0,150,240);
108
+ border-right: 10px solid rgb(0,150,240);
109
+ border-bottom: 10px solid rgb(0,150,240);
110
+ border-top: 10px solid rgb(100,0,200);
111
+ border-radius: 100%;
112
+ background-color: rgb(200,100,250);
113
+}
114
+@keyframes rotation {
115
+ from {transform: rotate(0deg);}
116
+ to {transform: rotate(360deg);}
117
+}
118
+
119
+/* The following styles are for app-level use. */
120
+/* TODO: consolidate the WASM- and legacy-mode CSS into this file.
121
+ Since both versions of /pikchrshow share a URI, they both load this
122
+ file. */
123
+textarea {
124
+ font-family: monospace;
125
+ flex: 1 1 auto;
126
+}
127
+#main-wrapper {
128
+ display: flex;
129
+ flex-direction: column-reverse;
130
+ flex: 1 1 auto;
131
+ margin: 0.5em 0;
132
+ overflow: hidden;
133
+}
134
+#main-wrapper.side-by-side {
135
+ flex-direction: row;
136
+}
137
+#main-wrapper.side-by-side > fieldset {
138
+ margin-left: 0.25em;
139
+ margin-right: 0.25em;
140
+}
141
+#main-wrapper:not(.side-by-side) > fieldset {
142
+ margin-bottom: 0.25em;
143
+}
144
+#main-wrapper.swapio {
145
+ flex-direction: column;
146
+}
147
+#main-wrapper.side-by-side.swapio {
148
+ flex-direction: row-reverse;
149
+}
150
+.zone-wrapper{
151
+ display: flex;
152
+ margin: 0;
153
+ flex: 1 1 0%;
154
+ border-radius: 0.5em;
155
+ min-width: inherit/*important: resolves inability to scroll fieldset child element!*/;
156
+ padding: 0.35em 0 0 0;
157
+}
158
+.zone-wrapper > div {
159
+ display:flex;
160
+ flex: 1 1 0%;
161
+}
162
+.zone-wrapper.output {
163
+}
--- a/src/style.pikchrshow.css
+++ b/src/style.pikchrshow.css
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/src/style.pikchrshow.css
+++ b/src/style.pikchrshow.css
@@ -0,0 +1,163 @@
1 during the module load/initialization processes... */
2 .emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
3 div.emscripten { text-align: center; }
4 div.emscripten_border { border: 1px solid black; }
5 #module-spinner { overflow: visible; }
6 #module-spinner > * {
7 margin-top: 1em;
8 }
9 .spinner {
10 height: 50px;
11 width: 50px;
12 margin: 0px auto;
13 animation: rotation 0.8s linear infinite;
14 border-left: 10px solid rgb(0,150,240);
15 border-right: 10px solid rgb(0,150,240);
16 border-bottom: 10px solid rgb(0,150,240);
17 border-top: 10px solid rgb(100,0,200);
18 border-radius: 100%;
19 background-color: rgb(200,100,250);
20 }
21 @keyframes rotation {
22 from {transform: rotate(0deg);}
23 to {transform: rotate(360deg);}
24 }
25
26 /* The following styles are for app-level use. */
27 /* TODO: consolidate the WASM- and legacy-mode CSS into this file.
28 Since both versions of /pikchrshow share a URI, they both load this
29 file. */
30 textarea {
31 font-family: monospace;
32 flex: 1 1 auto;
33 }
34 #main-wrapper {
35 display: flex;
36 flex-direction: column-reverse;
37 flex: 1 1 auto;
38 margin: 0.5em 0;
39 overflow: hidden;
40 }
41 #main-wrapper.side-by-side {
42 flex-direction: row;
43 }
44 #main-wrapper.side-by-side > fieldset {
45 margin-left: 0.25em;
46 margin-right: 0.25em;
47 }
48 #main-wrapper:not(.side-by-side) > fieldset {
49 margin-bottom: 0.25em;
50 }
51 #main-wrapper.swapio {
52 flex-direction: column;
53 }
54 #main-wrapper.side-by-side.swapio {
55 flex-direction: row-reverse;
56 }
57 .zone-wrapper{
58 display: flex;
59 margin: 0;
60 flex: 1 1 0%;
61 border-radius: 0.5em;
62 min-width: inherit/*important: resolves inability to scroll fieldset child element!*/;
63 padding: 0.35em 0 0 0;
64 }
65 .zone-wrapper > div {
66 display:flex;
67 flex: 1 1 0%;
68 }
69 .zone-wrapper.output {
70 }
71 #main-wrapper.side-by-side .zone-wrapper {
72 /* Keep the layout from "flopping around" when
73 render-while-typing mode is on. */
74 /*max-width: 50%;*/
75 }
76 #pikchr-output {
77 padding: 0;
78 margin: 0 auto/*auto resolves a weird left-shift truncation of the SVG*/;
79 }
80 #pikchr-output-wrapper {
81 flex: 1 1 auto;
82 overflow: auto;
83 }
84 #pikchr-output-wrapper.text {
85 display: flex;
86 align-items: stretch;
87 }
88 #pikchr-output-wrapper:not(.autofit) {;
89 }
90 #main-wrapper:not(.szation processes... */
91 . duriper.text > #pikchr-output {
92 display: flex;
93 align-items: stretch;
94 fle during the module loa module load/initializat during the module load/initialization processes... */
95 .emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
96 div.emscripten { text-align: center; }
97 div.emscripten_border { border: 1px solid black; }
98 #module-spinner { overflow: visible; }
99 #module-spinner > * {
100 margin-top: 1em;
101 }
102 .spinner {
103 height: 50px;
104 width: 50px;
105 margin: 0px auto;
106 animation: rotation 0.8s linear infinite;
107 border-left: 10px solid rgb(0,150,240);
108 border-right: 10px solid rgb(0,150,240);
109 border-bottom: 10px solid rgb(0,150,240);
110 border-top: 10px solid rgb(100,0,200);
111 border-radius: 100%;
112 background-color: rgb(200,100,250);
113 }
114 @keyframes rotation {
115 from {transform: rotate(0deg);}
116 to {transform: rotate(360deg);}
117 }
118
119 /* The following styles are for app-level use. */
120 /* TODO: consolidate the WASM- and legacy-mode CSS into this file.
121 Since both versions of /pikchrshow share a URI, they both load this
122 file. */
123 textarea {
124 font-family: monospace;
125 flex: 1 1 auto;
126 }
127 #main-wrapper {
128 display: flex;
129 flex-direction: column-reverse;
130 flex: 1 1 auto;
131 margin: 0.5em 0;
132 overflow: hidden;
133 }
134 #main-wrapper.side-by-side {
135 flex-direction: row;
136 }
137 #main-wrapper.side-by-side > fieldset {
138 margin-left: 0.25em;
139 margin-right: 0.25em;
140 }
141 #main-wrapper:not(.side-by-side) > fieldset {
142 margin-bottom: 0.25em;
143 }
144 #main-wrapper.swapio {
145 flex-direction: column;
146 }
147 #main-wrapper.side-by-side.swapio {
148 flex-direction: row-reverse;
149 }
150 .zone-wrapper{
151 display: flex;
152 margin: 0;
153 flex: 1 1 0%;
154 border-radius: 0.5em;
155 min-width: inherit/*important: resolves inability to scroll fieldset child element!*/;
156 padding: 0.35em 0 0 0;
157 }
158 .zone-wrapper > div {
159 display:flex;
160 flex: 1 1 0%;
161 }
162 .zone-wrapper.output {
163 }
+9 -3
--- src/sync.c
+++ src/sync.c
@@ -24,16 +24,22 @@
2424
/*
2525
** Explain what type of sync operation is about to occur
2626
*/
2727
static void sync_explain(unsigned syncFlags){
2828
if( g.url.isAlias ){
29
+ const char *url;
30
+ if( g.url.useProxy ){
31
+ url = g.url.proxyUrlCanonical;
32
+ }else{
33
+ url = g.url.canonical;
34
+ }
2935
if( (syncFlags & (SYNC_PUSH|SYNC_PULL))==(SYNC_PUSH|SYNC_PULL) ){
30
- fossil_print("Sync with %s\n", g.url.canonical);
36
+ fossil_print("Sync with %s\n", url);
3137
}else if( syncFlags & SYNC_PUSH ){
32
- fossil_print("Push to %s\n", g.url.canonical);
38
+ fossil_print("Push to %s\n", url);
3339
}else if( syncFlags & SYNC_PULL ){
34
- fossil_print("Pull from %s\n", g.url.canonical);
40
+ fossil_print("Pull from %s\n", url);
3541
}
3642
}
3743
}
3844
3945
4046
--- src/sync.c
+++ src/sync.c
@@ -24,16 +24,22 @@
24 /*
25 ** Explain what type of sync operation is about to occur
26 */
27 static void sync_explain(unsigned syncFlags){
28 if( g.url.isAlias ){
 
 
 
 
 
 
29 if( (syncFlags & (SYNC_PUSH|SYNC_PULL))==(SYNC_PUSH|SYNC_PULL) ){
30 fossil_print("Sync with %s\n", g.url.canonical);
31 }else if( syncFlags & SYNC_PUSH ){
32 fossil_print("Push to %s\n", g.url.canonical);
33 }else if( syncFlags & SYNC_PULL ){
34 fossil_print("Pull from %s\n", g.url.canonical);
35 }
36 }
37 }
38
39
40
--- src/sync.c
+++ src/sync.c
@@ -24,16 +24,22 @@
24 /*
25 ** Explain what type of sync operation is about to occur
26 */
27 static void sync_explain(unsigned syncFlags){
28 if( g.url.isAlias ){
29 const char *url;
30 if( g.url.useProxy ){
31 url = g.url.proxyUrlCanonical;
32 }else{
33 url = g.url.canonical;
34 }
35 if( (syncFlags & (SYNC_PUSH|SYNC_PULL))==(SYNC_PUSH|SYNC_PULL) ){
36 fossil_print("Sync with %s\n", url);
37 }else if( syncFlags & SYNC_PUSH ){
38 fossil_print("Push to %s\n", url);
39 }else if( syncFlags & SYNC_PULL ){
40 fossil_print("Pull from %s\n", url);
41 }
42 }
43 }
44
45
46
+1 -1
--- src/tag.c
+++ src/tag.c
@@ -220,11 +220,11 @@
220220
if( zCol ){
221221
db_multi_exec("UPDATE event SET \"%w\"=%Q WHERE objid=%d",
222222
zCol, zValue, rid);
223223
if( tagid==TAG_COMMENT ){
224224
char *zCopy = mprintf("%s", zValue);
225
- backlink_extract(zCopy, 0, rid, BKLNK_COMMENT, mtime, 1);
225
+ backlink_extract(zCopy, MT_NONE, rid, BKLNK_COMMENT, mtime, 1);
226226
free(zCopy);
227227
}
228228
}
229229
if( tagid==TAG_DATE ){
230230
db_multi_exec("UPDATE event "
231231
--- src/tag.c
+++ src/tag.c
@@ -220,11 +220,11 @@
220 if( zCol ){
221 db_multi_exec("UPDATE event SET \"%w\"=%Q WHERE objid=%d",
222 zCol, zValue, rid);
223 if( tagid==TAG_COMMENT ){
224 char *zCopy = mprintf("%s", zValue);
225 backlink_extract(zCopy, 0, rid, BKLNK_COMMENT, mtime, 1);
226 free(zCopy);
227 }
228 }
229 if( tagid==TAG_DATE ){
230 db_multi_exec("UPDATE event "
231
--- src/tag.c
+++ src/tag.c
@@ -220,11 +220,11 @@
220 if( zCol ){
221 db_multi_exec("UPDATE event SET \"%w\"=%Q WHERE objid=%d",
222 zCol, zValue, rid);
223 if( tagid==TAG_COMMENT ){
224 char *zCopy = mprintf("%s", zValue);
225 backlink_extract(zCopy, MT_NONE, rid, BKLNK_COMMENT, mtime, 1);
226 free(zCopy);
227 }
228 }
229 if( tagid==TAG_DATE ){
230 db_multi_exec("UPDATE event "
231
+4 -3
--- src/timeline.c
+++ src/timeline.c
@@ -524,13 +524,14 @@
524524
@ Added wiki page "%z(href("%R/wiki?name=%t",zCom+1))%h(zCom+1)</a>"
525525
}else if( zCom[0]==':' ){
526526
@ Changes to wiki page "%z(href("%R/wiki?name=%t",zCom+1))\
527527
@ %h(zCom+1)</a>"
528528
}else{
529
- /* Legacy EVENT table entry that needs to be rebuilt */
530
- @ Changes to a wiki page &rarr; Obsolete EVENT table information.
531
- @ Run "fossil rebuild" on the repository.
529
+ /* Assume this is an attachment message. It _might_ also
530
+ ** be a legacy-format wiki log entry, in which case it
531
+ ** will simply be rendered in the older format. */
532
+ wiki_convert(&comment, 0, WIKI_INLINE);
532533
}
533534
wiki_hyperlink_override(0);
534535
}else{
535536
wiki_convert(&comment, 0, WIKI_INLINE);
536537
}
537538
--- src/timeline.c
+++ src/timeline.c
@@ -524,13 +524,14 @@
524 @ Added wiki page "%z(href("%R/wiki?name=%t",zCom+1))%h(zCom+1)</a>"
525 }else if( zCom[0]==':' ){
526 @ Changes to wiki page "%z(href("%R/wiki?name=%t",zCom+1))\
527 @ %h(zCom+1)</a>"
528 }else{
529 /* Legacy EVENT table entry that needs to be rebuilt */
530 @ Changes to a wiki page &rarr; Obsolete EVENT table information.
531 @ Run "fossil rebuild" on the repository.
 
532 }
533 wiki_hyperlink_override(0);
534 }else{
535 wiki_convert(&comment, 0, WIKI_INLINE);
536 }
537
--- src/timeline.c
+++ src/timeline.c
@@ -524,13 +524,14 @@
524 @ Added wiki page "%z(href("%R/wiki?name=%t",zCom+1))%h(zCom+1)</a>"
525 }else if( zCom[0]==':' ){
526 @ Changes to wiki page "%z(href("%R/wiki?name=%t",zCom+1))\
527 @ %h(zCom+1)</a>"
528 }else{
529 /* Assume this is an attachment message. It _might_ also
530 ** be a legacy-format wiki log entry, in which case it
531 ** will simply be rendered in the older format. */
532 wiki_convert(&comment, 0, WIKI_INLINE);
533 }
534 wiki_hyperlink_override(0);
535 }else{
536 wiki_convert(&comment, 0, WIKI_INLINE);
537 }
538
+90 -35
--- src/tkt.c
+++ src/tkt.c
@@ -23,11 +23,11 @@
2323
#include <assert.h>
2424
2525
/*
2626
** The list of database user-defined fields in the TICKET table.
2727
** The real table also contains some addition fields for internal
28
-** used. The internal-use fields begin with "tkt_".
28
+** use. The internal-use fields begin with "tkt_".
2929
*/
3030
static int nField = 0;
3131
static struct tktFieldInfo {
3232
char *zName; /* Name of the database field */
3333
char *zValue; /* Value to store */
@@ -39,10 +39,14 @@
3939
#define USEDBY_BOTH 03
4040
static u8 haveTicket = 0; /* True if the TICKET table exists */
4141
static u8 haveTicketCTime = 0; /* True if TICKET.TKT_CTIME exists */
4242
static u8 haveTicketChng = 0; /* True if the TICKETCHNG table exists */
4343
static u8 haveTicketChngRid = 0; /* True if TICKETCHNG.TKT_RID exists */
44
+static u8 haveTicketChngUser = 0;/* True if TICKETCHNG.TKT_USER exists */
45
+static u8 useTicketGenMt = 0; /* use generated TICKET.MIMETYPE */
46
+static u8 useTicketChngGenMt = 0;/* use generated TICKETCHNG.MIMETYPE */
47
+
4448
4549
/*
4650
** Compare two entries in aField[] for sorting purposes
4751
*/
4852
static int nameCmpr(const void *a, const void *b){
@@ -69,11 +73,11 @@
6973
** The haveTicket and haveTicketChng variables are set to 1 if the TICKET and
7074
** TICKETCHANGE tables exist, respectively.
7175
*/
7276
static void getAllTicketFields(void){
7377
Stmt q;
74
- int i;
78
+ int i, noRegularMimetype;
7579
static int once = 0;
7680
if( once ) return;
7781
once = 1;
7882
db_prepare(&q, "PRAGMA table_info(ticket)");
7983
while( db_step(&q)==SQLITE_ROW ){
@@ -81,10 +85,11 @@
8185
haveTicket = 1;
8286
if( memcmp(zFieldName,"tkt_",4)==0 ){
8387
if( strcmp(zFieldName, "tkt_ctime")==0 ) haveTicketCTime = 1;
8488
continue;
8589
}
90
+ if( strchr(zFieldName,' ')!=0 ) continue;
8691
if( nField%10==0 ){
8792
aField = fossil_realloc(aField, sizeof(aField[0])*(nField+10) );
8893
}
8994
aField[nField].zName = mprintf("%s", zFieldName);
9095
aField[nField].mUsed = USEDBY_TICKET;
@@ -94,13 +99,18 @@
9499
db_prepare(&q, "PRAGMA table_info(ticketchng)");
95100
while( db_step(&q)==SQLITE_ROW ){
96101
const char *zFieldName = db_column_text(&q, 1);
97102
haveTicketChng = 1;
98103
if( memcmp(zFieldName,"tkt_",4)==0 ){
99
- if( strcmp(zFieldName,"tkt_rid")==0 ) haveTicketChngRid = 1;
104
+ if( strcmp(zFieldName+4,"rid")==0 ){
105
+ haveTicketChngRid = 1; /* tkt_rid */
106
+ }else if( strcmp(zFieldName+4,"user")==0 ){
107
+ haveTicketChngUser = 1; /* tkt_user */
108
+ }
100109
continue;
101110
}
111
+ if( strchr(zFieldName,' ')!=0 ) continue;
102112
if( (i = fieldId(zFieldName))>=0 ){
103113
aField[i].mUsed |= USEDBY_TICKETCHNG;
104114
continue;
105115
}
106116
if( nField%10==0 ){
@@ -110,13 +120,25 @@
110120
aField[nField].mUsed = USEDBY_TICKETCHNG;
111121
nField++;
112122
}
113123
db_finalize(&q);
114124
qsort(aField, nField, sizeof(aField[0]), nameCmpr);
125
+ noRegularMimetype = 1;
115126
for(i=0; i<nField; i++){
116127
aField[i].zValue = "";
117128
aField[i].zAppend = 0;
129
+ if( strcmp(aField[i].zName,"mimetype")==0 ){
130
+ noRegularMimetype = 0;
131
+ }
132
+ }
133
+ if( noRegularMimetype ){ /* check for generated "mimetype" columns */
134
+ useTicketGenMt = db_exists(
135
+ "SELECT 1 FROM pragma_table_xinfo('ticket') "
136
+ "WHERE name = 'mimetype'");
137
+ useTicketChngGenMt = db_exists(
138
+ "SELECT 1 FROM pragma_table_xinfo('ticketchng') "
139
+ "WHERE name = 'mimetype'");
118140
}
119141
}
120142
121143
/*
122144
** Query the database for all TICKET fields for the specific
@@ -189,16 +211,18 @@
189211
**
190212
** Parameter rid is the recordID for the ticket artifact in the BLOB table.
191213
**
192214
** Return the new rowid of the TICKET table entry.
193215
*/
194
-static int ticket_insert(const Manifest *p, int rid, int tktid){
195
- Blob sql1, sql2, sql3;
216
+static int ticket_insert(const Manifest *p, const int rid, int tktid){
217
+ Blob sql1; /* update or replace TICKET ... */
218
+ Blob sql2; /* list of TICKETCHNG's fields that are in the manifest */
219
+ Blob sql3; /* list of values which correspond to the previous list */
196220
Stmt q;
197221
int i, j;
198222
char *aUsed;
199
- const char *zMimetype = 0;
223
+ int mimetype_tkt = MT_NONE, mimetype_tktchng = MT_NONE;
200224
201225
if( tktid==0 ){
202226
db_multi_exec("INSERT INTO ticket(tkt_uuid, tkt_mtime) "
203227
"VALUES(%Q, 0)", p->zTicketUuid);
204228
tktid = db_last_insert_rowid();
@@ -211,59 +235,60 @@
211235
blob_append_sql(&sql1, ", tkt_ctime=coalesce(tkt_ctime,:mtime)");
212236
}
213237
aUsed = fossil_malloc( nField );
214238
memset(aUsed, 0, nField);
215239
for(i=0; i<p->nField; i++){
216
- const char *zName = p->aField[i].zName;
217
- const char *zBaseName = zName[0]=='+' ? zName+1 : zName;
240
+ const char * const zName = p->aField[i].zName;
241
+ const char * const zBaseName = zName[0]=='+' ? zName+1 : zName;
218242
j = fieldId(zBaseName);
219243
if( j<0 ) continue;
220244
aUsed[j] = 1;
221245
if( aField[j].mUsed & USEDBY_TICKET ){
222
- const char *zUsedByName = zName;
223
- if( zUsedByName[0]=='+' ){
224
- zUsedByName++;
246
+ if( zName[0]=='+' ){
225247
blob_append_sql(&sql1,", \"%w\"=coalesce(\"%w\",'') || %Q",
226
- zUsedByName, zUsedByName, p->aField[i].zValue);
248
+ zBaseName, zBaseName, p->aField[i].zValue);
227249
}else{
228
- blob_append_sql(&sql1,", \"%w\"=%Q", zUsedByName, p->aField[i].zValue);
250
+ blob_append_sql(&sql1,", \"%w\"=%Q", zBaseName, p->aField[i].zValue);
229251
}
230252
}
231253
if( aField[j].mUsed & USEDBY_TICKETCHNG ){
232
- const char *zUsedByName = zName;
233
- if( zUsedByName[0]=='+' ){
234
- zUsedByName++;
235
- }
236
- blob_append_sql(&sql2, ",\"%w\"", zUsedByName);
254
+ blob_append_sql(&sql2, ",\"%w\"", zBaseName);
237255
blob_append_sql(&sql3, ",%Q", p->aField[i].zValue);
238256
}
239257
if( strcmp(zBaseName,"mimetype")==0 ){
240
- zMimetype = p->aField[i].zValue;
241
- }
242
- }
243
- if( rid>0 ){
244
- for(i=0; i<p->nField; i++){
245
- const char *zName = p->aField[i].zName;
246
- const char *zBaseName = zName[0]=='+' ? zName+1 : zName;
247
- j = fieldId(zBaseName);
248
- if( j<0 ) continue;
249
- backlink_extract(p->aField[i].zValue, zMimetype, rid, BKLNK_TICKET,
250
- p->rDate, i==0);
258
+ const char *zMimetype = p->aField[i].zValue;
259
+ /* "mimetype" is a regular column => these two flags must be 0 */
260
+ assert(!useTicketGenMt);
261
+ assert(!useTicketChngGenMt);
262
+ mimetype_tkt = mimetype_tktchng = parse_mimetype( zMimetype );
251263
}
252264
}
253265
blob_append_sql(&sql1, " WHERE tkt_id=%d", tktid);
266
+ if( useTicketGenMt ){
267
+ blob_append_literal(&sql1, " RETURNING mimetype");
268
+ }
254269
db_prepare(&q, "%s", blob_sql_text(&sql1));
255270
db_bind_double(&q, ":mtime", p->rDate);
256271
db_step(&q);
272
+ if( useTicketGenMt ){
273
+ mimetype_tkt = parse_mimetype( db_column_text(&q,0) );
274
+ if( !useTicketChngGenMt ){
275
+ mimetype_tktchng = mimetype_tkt;
276
+ }
277
+ }
257278
db_finalize(&q);
258279
blob_reset(&sql1);
259
- if( blob_size(&sql2)>0 || haveTicketChngRid ){
280
+ if( blob_size(&sql2)>0 || haveTicketChngRid || haveTicketChngUser ){
260281
int fromTkt = 0;
261282
if( haveTicketChngRid ){
262
- blob_append(&sql2, ",tkt_rid", -1);
283
+ blob_append_literal(&sql2, ",tkt_rid");
263284
blob_append_sql(&sql3, ",%d", rid);
264285
}
286
+ if( haveTicketChngUser && p->zUser ){
287
+ blob_append_literal(&sql2, ",tkt_user");
288
+ blob_append_sql(&sql3, ",%Q", p->zUser);
289
+ }
265290
for(i=0; i<nField; i++){
266291
if( aUsed[i]==0
267292
&& (aField[i].mUsed & USEDBY_BOTH)==USEDBY_BOTH
268293
){
269294
const char *z = aField[i].zName;
@@ -273,25 +298,55 @@
273298
blob_append_sql(&sql3, ",\"%w\"", z);
274299
}
275300
}
276301
if( fromTkt ){
277302
db_prepare(&q, "INSERT INTO ticketchng(tkt_id,tkt_mtime%s)"
278
- "SELECT %d,:mtime%s FROM ticket WHERE tkt_id=%d",
303
+ "SELECT %d,:mtime%s FROM ticket WHERE tkt_id=%d%s",
279304
blob_sql_text(&sql2), tktid,
280
- blob_sql_text(&sql3), tktid);
305
+ blob_sql_text(&sql3), tktid,
306
+ useTicketChngGenMt ? " RETURNING mimetype" : "");
281307
}else{
282308
db_prepare(&q, "INSERT INTO ticketchng(tkt_id,tkt_mtime%s)"
283
- "VALUES(%d,:mtime%s)",
284
- blob_sql_text(&sql2), tktid, blob_sql_text(&sql3));
309
+ "VALUES(%d,:mtime%s)%s",
310
+ blob_sql_text(&sql2), tktid, blob_sql_text(&sql3),
311
+ useTicketChngGenMt ? " RETURNING mimetype" : "");
285312
}
286313
db_bind_double(&q, ":mtime", p->rDate);
287314
db_step(&q);
315
+ if( useTicketChngGenMt ){
316
+ mimetype_tktchng = parse_mimetype( db_column_text(&q, 0) );
317
+ /* substitute NULL with a value generated within another table */
318
+ if( !useTicketGenMt ){
319
+ mimetype_tkt = mimetype_tktchng;
320
+ }else if( mimetype_tktchng==MT_NONE ){
321
+ mimetype_tktchng = mimetype_tkt;
322
+ }else if( mimetype_tkt==MT_NONE ){
323
+ mimetype_tkt = mimetype_tktchng;
324
+ }
325
+ }
288326
db_finalize(&q);
289327
}
290328
blob_reset(&sql2);
291329
blob_reset(&sql3);
292330
fossil_free(aUsed);
331
+ if( rid>0 ){ /* extract backlinks */
332
+ int bReplace = 1, mimetype;
333
+ for(i=0; i<p->nField; i++){
334
+ const char *zName = p->aField[i].zName;
335
+ const char *zBaseName = zName[0]=='+' ? zName+1 : zName;
336
+ j = fieldId(zBaseName);
337
+ if( j<0 ) continue;
338
+ if( aField[j].mUsed & USEDBY_TICKETCHNG ){
339
+ mimetype = mimetype_tktchng;
340
+ }else{
341
+ mimetype = mimetype_tkt;
342
+ }
343
+ backlink_extract(p->aField[i].zValue, mimetype, rid, BKLNK_TICKET,
344
+ p->rDate, bReplace);
345
+ bReplace = 0;
346
+ }
347
+ }
293348
return tktid;
294349
}
295350
296351
/*
297352
** Returns non-zero if moderation is required for ticket changes and ticket
298353
--- src/tkt.c
+++ src/tkt.c
@@ -23,11 +23,11 @@
23 #include <assert.h>
24
25 /*
26 ** The list of database user-defined fields in the TICKET table.
27 ** The real table also contains some addition fields for internal
28 ** used. The internal-use fields begin with "tkt_".
29 */
30 static int nField = 0;
31 static struct tktFieldInfo {
32 char *zName; /* Name of the database field */
33 char *zValue; /* Value to store */
@@ -39,10 +39,14 @@
39 #define USEDBY_BOTH 03
40 static u8 haveTicket = 0; /* True if the TICKET table exists */
41 static u8 haveTicketCTime = 0; /* True if TICKET.TKT_CTIME exists */
42 static u8 haveTicketChng = 0; /* True if the TICKETCHNG table exists */
43 static u8 haveTicketChngRid = 0; /* True if TICKETCHNG.TKT_RID exists */
 
 
 
 
44
45 /*
46 ** Compare two entries in aField[] for sorting purposes
47 */
48 static int nameCmpr(const void *a, const void *b){
@@ -69,11 +73,11 @@
69 ** The haveTicket and haveTicketChng variables are set to 1 if the TICKET and
70 ** TICKETCHANGE tables exist, respectively.
71 */
72 static void getAllTicketFields(void){
73 Stmt q;
74 int i;
75 static int once = 0;
76 if( once ) return;
77 once = 1;
78 db_prepare(&q, "PRAGMA table_info(ticket)");
79 while( db_step(&q)==SQLITE_ROW ){
@@ -81,10 +85,11 @@
81 haveTicket = 1;
82 if( memcmp(zFieldName,"tkt_",4)==0 ){
83 if( strcmp(zFieldName, "tkt_ctime")==0 ) haveTicketCTime = 1;
84 continue;
85 }
 
86 if( nField%10==0 ){
87 aField = fossil_realloc(aField, sizeof(aField[0])*(nField+10) );
88 }
89 aField[nField].zName = mprintf("%s", zFieldName);
90 aField[nField].mUsed = USEDBY_TICKET;
@@ -94,13 +99,18 @@
94 db_prepare(&q, "PRAGMA table_info(ticketchng)");
95 while( db_step(&q)==SQLITE_ROW ){
96 const char *zFieldName = db_column_text(&q, 1);
97 haveTicketChng = 1;
98 if( memcmp(zFieldName,"tkt_",4)==0 ){
99 if( strcmp(zFieldName,"tkt_rid")==0 ) haveTicketChngRid = 1;
 
 
 
 
100 continue;
101 }
 
102 if( (i = fieldId(zFieldName))>=0 ){
103 aField[i].mUsed |= USEDBY_TICKETCHNG;
104 continue;
105 }
106 if( nField%10==0 ){
@@ -110,13 +120,25 @@
110 aField[nField].mUsed = USEDBY_TICKETCHNG;
111 nField++;
112 }
113 db_finalize(&q);
114 qsort(aField, nField, sizeof(aField[0]), nameCmpr);
 
115 for(i=0; i<nField; i++){
116 aField[i].zValue = "";
117 aField[i].zAppend = 0;
 
 
 
 
 
 
 
 
 
 
 
118 }
119 }
120
121 /*
122 ** Query the database for all TICKET fields for the specific
@@ -189,16 +211,18 @@
189 **
190 ** Parameter rid is the recordID for the ticket artifact in the BLOB table.
191 **
192 ** Return the new rowid of the TICKET table entry.
193 */
194 static int ticket_insert(const Manifest *p, int rid, int tktid){
195 Blob sql1, sql2, sql3;
 
 
196 Stmt q;
197 int i, j;
198 char *aUsed;
199 const char *zMimetype = 0;
200
201 if( tktid==0 ){
202 db_multi_exec("INSERT INTO ticket(tkt_uuid, tkt_mtime) "
203 "VALUES(%Q, 0)", p->zTicketUuid);
204 tktid = db_last_insert_rowid();
@@ -211,59 +235,60 @@
211 blob_append_sql(&sql1, ", tkt_ctime=coalesce(tkt_ctime,:mtime)");
212 }
213 aUsed = fossil_malloc( nField );
214 memset(aUsed, 0, nField);
215 for(i=0; i<p->nField; i++){
216 const char *zName = p->aField[i].zName;
217 const char *zBaseName = zName[0]=='+' ? zName+1 : zName;
218 j = fieldId(zBaseName);
219 if( j<0 ) continue;
220 aUsed[j] = 1;
221 if( aField[j].mUsed & USEDBY_TICKET ){
222 const char *zUsedByName = zName;
223 if( zUsedByName[0]=='+' ){
224 zUsedByName++;
225 blob_append_sql(&sql1,", \"%w\"=coalesce(\"%w\",'') || %Q",
226 zUsedByName, zUsedByName, p->aField[i].zValue);
227 }else{
228 blob_append_sql(&sql1,", \"%w\"=%Q", zUsedByName, p->aField[i].zValue);
229 }
230 }
231 if( aField[j].mUsed & USEDBY_TICKETCHNG ){
232 const char *zUsedByName = zName;
233 if( zUsedByName[0]=='+' ){
234 zUsedByName++;
235 }
236 blob_append_sql(&sql2, ",\"%w\"", zUsedByName);
237 blob_append_sql(&sql3, ",%Q", p->aField[i].zValue);
238 }
239 if( strcmp(zBaseName,"mimetype")==0 ){
240 zMimetype = p->aField[i].zValue;
241 }
242 }
243 if( rid>0 ){
244 for(i=0; i<p->nField; i++){
245 const char *zName = p->aField[i].zName;
246 const char *zBaseName = zName[0]=='+' ? zName+1 : zName;
247 j = fieldId(zBaseName);
248 if( j<0 ) continue;
249 backlink_extract(p->aField[i].zValue, zMimetype, rid, BKLNK_TICKET,
250 p->rDate, i==0);
251 }
252 }
253 blob_append_sql(&sql1, " WHERE tkt_id=%d", tktid);
 
 
 
254 db_prepare(&q, "%s", blob_sql_text(&sql1));
255 db_bind_double(&q, ":mtime", p->rDate);
256 db_step(&q);
 
 
 
 
 
 
257 db_finalize(&q);
258 blob_reset(&sql1);
259 if( blob_size(&sql2)>0 || haveTicketChngRid ){
260 int fromTkt = 0;
261 if( haveTicketChngRid ){
262 blob_append(&sql2, ",tkt_rid", -1);
263 blob_append_sql(&sql3, ",%d", rid);
264 }
 
 
 
 
265 for(i=0; i<nField; i++){
266 if( aUsed[i]==0
267 && (aField[i].mUsed & USEDBY_BOTH)==USEDBY_BOTH
268 ){
269 const char *z = aField[i].zName;
@@ -273,25 +298,55 @@
273 blob_append_sql(&sql3, ",\"%w\"", z);
274 }
275 }
276 if( fromTkt ){
277 db_prepare(&q, "INSERT INTO ticketchng(tkt_id,tkt_mtime%s)"
278 "SELECT %d,:mtime%s FROM ticket WHERE tkt_id=%d",
279 blob_sql_text(&sql2), tktid,
280 blob_sql_text(&sql3), tktid);
 
281 }else{
282 db_prepare(&q, "INSERT INTO ticketchng(tkt_id,tkt_mtime%s)"
283 "VALUES(%d,:mtime%s)",
284 blob_sql_text(&sql2), tktid, blob_sql_text(&sql3));
 
285 }
286 db_bind_double(&q, ":mtime", p->rDate);
287 db_step(&q);
 
 
 
 
 
 
 
 
 
 
 
288 db_finalize(&q);
289 }
290 blob_reset(&sql2);
291 blob_reset(&sql3);
292 fossil_free(aUsed);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
293 return tktid;
294 }
295
296 /*
297 ** Returns non-zero if moderation is required for ticket changes and ticket
298
--- src/tkt.c
+++ src/tkt.c
@@ -23,11 +23,11 @@
23 #include <assert.h>
24
25 /*
26 ** The list of database user-defined fields in the TICKET table.
27 ** The real table also contains some addition fields for internal
28 ** use. The internal-use fields begin with "tkt_".
29 */
30 static int nField = 0;
31 static struct tktFieldInfo {
32 char *zName; /* Name of the database field */
33 char *zValue; /* Value to store */
@@ -39,10 +39,14 @@
39 #define USEDBY_BOTH 03
40 static u8 haveTicket = 0; /* True if the TICKET table exists */
41 static u8 haveTicketCTime = 0; /* True if TICKET.TKT_CTIME exists */
42 static u8 haveTicketChng = 0; /* True if the TICKETCHNG table exists */
43 static u8 haveTicketChngRid = 0; /* True if TICKETCHNG.TKT_RID exists */
44 static u8 haveTicketChngUser = 0;/* True if TICKETCHNG.TKT_USER exists */
45 static u8 useTicketGenMt = 0; /* use generated TICKET.MIMETYPE */
46 static u8 useTicketChngGenMt = 0;/* use generated TICKETCHNG.MIMETYPE */
47
48
49 /*
50 ** Compare two entries in aField[] for sorting purposes
51 */
52 static int nameCmpr(const void *a, const void *b){
@@ -69,11 +73,11 @@
73 ** The haveTicket and haveTicketChng variables are set to 1 if the TICKET and
74 ** TICKETCHANGE tables exist, respectively.
75 */
76 static void getAllTicketFields(void){
77 Stmt q;
78 int i, noRegularMimetype;
79 static int once = 0;
80 if( once ) return;
81 once = 1;
82 db_prepare(&q, "PRAGMA table_info(ticket)");
83 while( db_step(&q)==SQLITE_ROW ){
@@ -81,10 +85,11 @@
85 haveTicket = 1;
86 if( memcmp(zFieldName,"tkt_",4)==0 ){
87 if( strcmp(zFieldName, "tkt_ctime")==0 ) haveTicketCTime = 1;
88 continue;
89 }
90 if( strchr(zFieldName,' ')!=0 ) continue;
91 if( nField%10==0 ){
92 aField = fossil_realloc(aField, sizeof(aField[0])*(nField+10) );
93 }
94 aField[nField].zName = mprintf("%s", zFieldName);
95 aField[nField].mUsed = USEDBY_TICKET;
@@ -94,13 +99,18 @@
99 db_prepare(&q, "PRAGMA table_info(ticketchng)");
100 while( db_step(&q)==SQLITE_ROW ){
101 const char *zFieldName = db_column_text(&q, 1);
102 haveTicketChng = 1;
103 if( memcmp(zFieldName,"tkt_",4)==0 ){
104 if( strcmp(zFieldName+4,"rid")==0 ){
105 haveTicketChngRid = 1; /* tkt_rid */
106 }else if( strcmp(zFieldName+4,"user")==0 ){
107 haveTicketChngUser = 1; /* tkt_user */
108 }
109 continue;
110 }
111 if( strchr(zFieldName,' ')!=0 ) continue;
112 if( (i = fieldId(zFieldName))>=0 ){
113 aField[i].mUsed |= USEDBY_TICKETCHNG;
114 continue;
115 }
116 if( nField%10==0 ){
@@ -110,13 +120,25 @@
120 aField[nField].mUsed = USEDBY_TICKETCHNG;
121 nField++;
122 }
123 db_finalize(&q);
124 qsort(aField, nField, sizeof(aField[0]), nameCmpr);
125 noRegularMimetype = 1;
126 for(i=0; i<nField; i++){
127 aField[i].zValue = "";
128 aField[i].zAppend = 0;
129 if( strcmp(aField[i].zName,"mimetype")==0 ){
130 noRegularMimetype = 0;
131 }
132 }
133 if( noRegularMimetype ){ /* check for generated "mimetype" columns */
134 useTicketGenMt = db_exists(
135 "SELECT 1 FROM pragma_table_xinfo('ticket') "
136 "WHERE name = 'mimetype'");
137 useTicketChngGenMt = db_exists(
138 "SELECT 1 FROM pragma_table_xinfo('ticketchng') "
139 "WHERE name = 'mimetype'");
140 }
141 }
142
143 /*
144 ** Query the database for all TICKET fields for the specific
@@ -189,16 +211,18 @@
211 **
212 ** Parameter rid is the recordID for the ticket artifact in the BLOB table.
213 **
214 ** Return the new rowid of the TICKET table entry.
215 */
216 static int ticket_insert(const Manifest *p, const int rid, int tktid){
217 Blob sql1; /* update or replace TICKET ... */
218 Blob sql2; /* list of TICKETCHNG's fields that are in the manifest */
219 Blob sql3; /* list of values which correspond to the previous list */
220 Stmt q;
221 int i, j;
222 char *aUsed;
223 int mimetype_tkt = MT_NONE, mimetype_tktchng = MT_NONE;
224
225 if( tktid==0 ){
226 db_multi_exec("INSERT INTO ticket(tkt_uuid, tkt_mtime) "
227 "VALUES(%Q, 0)", p->zTicketUuid);
228 tktid = db_last_insert_rowid();
@@ -211,59 +235,60 @@
235 blob_append_sql(&sql1, ", tkt_ctime=coalesce(tkt_ctime,:mtime)");
236 }
237 aUsed = fossil_malloc( nField );
238 memset(aUsed, 0, nField);
239 for(i=0; i<p->nField; i++){
240 const char * const zName = p->aField[i].zName;
241 const char * const zBaseName = zName[0]=='+' ? zName+1 : zName;
242 j = fieldId(zBaseName);
243 if( j<0 ) continue;
244 aUsed[j] = 1;
245 if( aField[j].mUsed & USEDBY_TICKET ){
246 if( zName[0]=='+' ){
 
 
247 blob_append_sql(&sql1,", \"%w\"=coalesce(\"%w\",'') || %Q",
248 zBaseName, zBaseName, p->aField[i].zValue);
249 }else{
250 blob_append_sql(&sql1,", \"%w\"=%Q", zBaseName, p->aField[i].zValue);
251 }
252 }
253 if( aField[j].mUsed & USEDBY_TICKETCHNG ){
254 blob_append_sql(&sql2, ",\"%w\"", zBaseName);
 
 
 
 
255 blob_append_sql(&sql3, ",%Q", p->aField[i].zValue);
256 }
257 if( strcmp(zBaseName,"mimetype")==0 ){
258 const char *zMimetype = p->aField[i].zValue;
259 /* "mimetype" is a regular column => these two flags must be 0 */
260 assert(!useTicketGenMt);
261 assert(!useTicketChngGenMt);
262 mimetype_tkt = mimetype_tktchng = parse_mimetype( zMimetype );
 
 
 
 
 
 
263 }
264 }
265 blob_append_sql(&sql1, " WHERE tkt_id=%d", tktid);
266 if( useTicketGenMt ){
267 blob_append_literal(&sql1, " RETURNING mimetype");
268 }
269 db_prepare(&q, "%s", blob_sql_text(&sql1));
270 db_bind_double(&q, ":mtime", p->rDate);
271 db_step(&q);
272 if( useTicketGenMt ){
273 mimetype_tkt = parse_mimetype( db_column_text(&q,0) );
274 if( !useTicketChngGenMt ){
275 mimetype_tktchng = mimetype_tkt;
276 }
277 }
278 db_finalize(&q);
279 blob_reset(&sql1);
280 if( blob_size(&sql2)>0 || haveTicketChngRid || haveTicketChngUser ){
281 int fromTkt = 0;
282 if( haveTicketChngRid ){
283 blob_append_literal(&sql2, ",tkt_rid");
284 blob_append_sql(&sql3, ",%d", rid);
285 }
286 if( haveTicketChngUser && p->zUser ){
287 blob_append_literal(&sql2, ",tkt_user");
288 blob_append_sql(&sql3, ",%Q", p->zUser);
289 }
290 for(i=0; i<nField; i++){
291 if( aUsed[i]==0
292 && (aField[i].mUsed & USEDBY_BOTH)==USEDBY_BOTH
293 ){
294 const char *z = aField[i].zName;
@@ -273,25 +298,55 @@
298 blob_append_sql(&sql3, ",\"%w\"", z);
299 }
300 }
301 if( fromTkt ){
302 db_prepare(&q, "INSERT INTO ticketchng(tkt_id,tkt_mtime%s)"
303 "SELECT %d,:mtime%s FROM ticket WHERE tkt_id=%d%s",
304 blob_sql_text(&sql2), tktid,
305 blob_sql_text(&sql3), tktid,
306 useTicketChngGenMt ? " RETURNING mimetype" : "");
307 }else{
308 db_prepare(&q, "INSERT INTO ticketchng(tkt_id,tkt_mtime%s)"
309 "VALUES(%d,:mtime%s)%s",
310 blob_sql_text(&sql2), tktid, blob_sql_text(&sql3),
311 useTicketChngGenMt ? " RETURNING mimetype" : "");
312 }
313 db_bind_double(&q, ":mtime", p->rDate);
314 db_step(&q);
315 if( useTicketChngGenMt ){
316 mimetype_tktchng = parse_mimetype( db_column_text(&q, 0) );
317 /* substitute NULL with a value generated within another table */
318 if( !useTicketGenMt ){
319 mimetype_tkt = mimetype_tktchng;
320 }else if( mimetype_tktchng==MT_NONE ){
321 mimetype_tktchng = mimetype_tkt;
322 }else if( mimetype_tkt==MT_NONE ){
323 mimetype_tkt = mimetype_tktchng;
324 }
325 }
326 db_finalize(&q);
327 }
328 blob_reset(&sql2);
329 blob_reset(&sql3);
330 fossil_free(aUsed);
331 if( rid>0 ){ /* extract backlinks */
332 int bReplace = 1, mimetype;
333 for(i=0; i<p->nField; i++){
334 const char *zName = p->aField[i].zName;
335 const char *zBaseName = zName[0]=='+' ? zName+1 : zName;
336 j = fieldId(zBaseName);
337 if( j<0 ) continue;
338 if( aField[j].mUsed & USEDBY_TICKETCHNG ){
339 mimetype = mimetype_tktchng;
340 }else{
341 mimetype = mimetype_tkt;
342 }
343 backlink_extract(p->aField[i].zValue, mimetype, rid, BKLNK_TICKET,
344 p->rDate, bReplace);
345 bReplace = 0;
346 }
347 }
348 return tktid;
349 }
350
351 /*
352 ** Returns non-zero if moderation is required for ticket changes and ticket
353
--- src/tktsetup.c
+++ src/tktsetup.c
@@ -86,10 +86,11 @@
8686
@ CREATE TABLE ticketchng(
8787
@ -- Do not change any column that begins with tkt_
8888
@ tkt_id INTEGER REFERENCES ticket,
8989
@ tkt_rid INTEGER REFERENCES blob,
9090
@ tkt_mtime DATE,
91
+@ tkt_user TEXT,
9192
@ -- Add as many fields as required below this line
9293
@ login TEXT,
9394
@ username TEXT,
9495
@ mimetype TEXT,
9596
@ icomment TEXT
9697
--- src/tktsetup.c
+++ src/tktsetup.c
@@ -86,10 +86,11 @@
86 @ CREATE TABLE ticketchng(
87 @ -- Do not change any column that begins with tkt_
88 @ tkt_id INTEGER REFERENCES ticket,
89 @ tkt_rid INTEGER REFERENCES blob,
90 @ tkt_mtime DATE,
 
91 @ -- Add as many fields as required below this line
92 @ login TEXT,
93 @ username TEXT,
94 @ mimetype TEXT,
95 @ icomment TEXT
96
--- src/tktsetup.c
+++ src/tktsetup.c
@@ -86,10 +86,11 @@
86 @ CREATE TABLE ticketchng(
87 @ -- Do not change any column that begins with tkt_
88 @ tkt_id INTEGER REFERENCES ticket,
89 @ tkt_rid INTEGER REFERENCES blob,
90 @ tkt_mtime DATE,
91 @ tkt_user TEXT,
92 @ -- Add as many fields as required below this line
93 @ login TEXT,
94 @ username TEXT,
95 @ mimetype TEXT,
96 @ icomment TEXT
97
+12 -4
--- src/url.c
+++ src/url.c
@@ -63,11 +63,12 @@
6363
char *canonical; /* Canonical representation of the URL */
6464
char *proxyAuth; /* Proxy-Authorizer: string */
6565
char *fossil; /* The fossil query parameter on ssh: */
6666
unsigned flags; /* Boolean flags controlling URL processing */
6767
int useProxy; /* Used to remember that a proxy is in use */
68
- char *proxyUrlPath;
68
+ char *proxyUrlPath; /* Remember path when proxy is use */
69
+ char *proxyUrlCanonical; /* Remember canonical path when proxy is use */
6970
int proxyOrigPort; /* Tunneled port number for https through proxy */
7071
};
7172
#endif /* INTERFACE */
7273
7374
@@ -534,11 +535,11 @@
534535
void url_enable_proxy(const char *zMsg){
535536
const char *zProxy;
536537
zProxy = zProxyOpt;
537538
if( zProxy==0 ){
538539
zProxy = db_get("proxy", 0);
539
- if( zProxy==0 || zProxy[0]==0 || is_false(zProxy) ){
540
+ if( fossil_strcmp(zProxy, "system")==0 ){
540541
zProxy = fossil_getenv("http_proxy");
541542
}
542543
}
543544
if( zProxy && zProxy[0] && !is_false(zProxy)
544545
&& !g.url.isSsh && !g.url.isFile ){
@@ -564,10 +565,11 @@
564565
}
565566
g.url.user = zOriginalUser;
566567
g.url.passwd = zOriginalPasswd;
567568
g.url.isHttps = fOriginalIsHttps;
568569
g.url.useProxy = 1;
570
+ g.url.proxyUrlCanonical = zOriginalUrl;;
569571
g.url.proxyUrlPath = zOriginalUrlPath;
570572
g.url.proxyOrigPort = iOriginalPort;
571573
g.url.flags = uOriginalFlags;
572574
}
573575
}
@@ -722,14 +724,20 @@
722724
/*
723725
** Remember the URL and password if requested.
724726
*/
725727
void url_remember(void){
726728
if( g.url.flags & URL_REMEMBER ){
729
+ const char *url;
730
+ if( g.url.useProxy ){
731
+ url = g.url.proxyUrlCanonical;
732
+ }else{
733
+ url = g.url.canonical;
734
+ }
727735
if( g.url.flags & URL_USE_PARENT ){
728
- db_set("parent-project-url", g.url.canonical, 0);
736
+ db_set("parent-project-url", url, 0);
729737
}else{
730
- db_set("last-sync-url", g.url.canonical, 0);
738
+ db_set("last-sync-url", url, 0);
731739
}
732740
if( g.url.user!=0 && g.url.passwd!=0 && ( g.url.flags & URL_REMEMBER_PW ) ){
733741
if( g.url.flags & URL_USE_PARENT ){
734742
db_set("parent-project-pw", obscure(g.url.passwd), 0);
735743
}else{
736744
--- src/url.c
+++ src/url.c
@@ -63,11 +63,12 @@
63 char *canonical; /* Canonical representation of the URL */
64 char *proxyAuth; /* Proxy-Authorizer: string */
65 char *fossil; /* The fossil query parameter on ssh: */
66 unsigned flags; /* Boolean flags controlling URL processing */
67 int useProxy; /* Used to remember that a proxy is in use */
68 char *proxyUrlPath;
 
69 int proxyOrigPort; /* Tunneled port number for https through proxy */
70 };
71 #endif /* INTERFACE */
72
73
@@ -534,11 +535,11 @@
534 void url_enable_proxy(const char *zMsg){
535 const char *zProxy;
536 zProxy = zProxyOpt;
537 if( zProxy==0 ){
538 zProxy = db_get("proxy", 0);
539 if( zProxy==0 || zProxy[0]==0 || is_false(zProxy) ){
540 zProxy = fossil_getenv("http_proxy");
541 }
542 }
543 if( zProxy && zProxy[0] && !is_false(zProxy)
544 && !g.url.isSsh && !g.url.isFile ){
@@ -564,10 +565,11 @@
564 }
565 g.url.user = zOriginalUser;
566 g.url.passwd = zOriginalPasswd;
567 g.url.isHttps = fOriginalIsHttps;
568 g.url.useProxy = 1;
 
569 g.url.proxyUrlPath = zOriginalUrlPath;
570 g.url.proxyOrigPort = iOriginalPort;
571 g.url.flags = uOriginalFlags;
572 }
573 }
@@ -722,14 +724,20 @@
722 /*
723 ** Remember the URL and password if requested.
724 */
725 void url_remember(void){
726 if( g.url.flags & URL_REMEMBER ){
 
 
 
 
 
 
727 if( g.url.flags & URL_USE_PARENT ){
728 db_set("parent-project-url", g.url.canonical, 0);
729 }else{
730 db_set("last-sync-url", g.url.canonical, 0);
731 }
732 if( g.url.user!=0 && g.url.passwd!=0 && ( g.url.flags & URL_REMEMBER_PW ) ){
733 if( g.url.flags & URL_USE_PARENT ){
734 db_set("parent-project-pw", obscure(g.url.passwd), 0);
735 }else{
736
--- src/url.c
+++ src/url.c
@@ -63,11 +63,12 @@
63 char *canonical; /* Canonical representation of the URL */
64 char *proxyAuth; /* Proxy-Authorizer: string */
65 char *fossil; /* The fossil query parameter on ssh: */
66 unsigned flags; /* Boolean flags controlling URL processing */
67 int useProxy; /* Used to remember that a proxy is in use */
68 char *proxyUrlPath; /* Remember path when proxy is use */
69 char *proxyUrlCanonical; /* Remember canonical path when proxy is use */
70 int proxyOrigPort; /* Tunneled port number for https through proxy */
71 };
72 #endif /* INTERFACE */
73
74
@@ -534,11 +535,11 @@
535 void url_enable_proxy(const char *zMsg){
536 const char *zProxy;
537 zProxy = zProxyOpt;
538 if( zProxy==0 ){
539 zProxy = db_get("proxy", 0);
540 if( fossil_strcmp(zProxy, "system")==0 ){
541 zProxy = fossil_getenv("http_proxy");
542 }
543 }
544 if( zProxy && zProxy[0] && !is_false(zProxy)
545 && !g.url.isSsh && !g.url.isFile ){
@@ -564,10 +565,11 @@
565 }
566 g.url.user = zOriginalUser;
567 g.url.passwd = zOriginalPasswd;
568 g.url.isHttps = fOriginalIsHttps;
569 g.url.useProxy = 1;
570 g.url.proxyUrlCanonical = zOriginalUrl;;
571 g.url.proxyUrlPath = zOriginalUrlPath;
572 g.url.proxyOrigPort = iOriginalPort;
573 g.url.flags = uOriginalFlags;
574 }
575 }
@@ -722,14 +724,20 @@
724 /*
725 ** Remember the URL and password if requested.
726 */
727 void url_remember(void){
728 if( g.url.flags & URL_REMEMBER ){
729 const char *url;
730 if( g.url.useProxy ){
731 url = g.url.proxyUrlCanonical;
732 }else{
733 url = g.url.canonical;
734 }
735 if( g.url.flags & URL_USE_PARENT ){
736 db_set("parent-project-url", url, 0);
737 }else{
738 db_set("last-sync-url", url, 0);
739 }
740 if( g.url.user!=0 && g.url.passwd!=0 && ( g.url.flags & URL_REMEMBER_PW ) ){
741 if( g.url.flags & URL_USE_PARENT ){
742 db_set("parent-project-pw", obscure(g.url.passwd), 0);
743 }else{
744
+3 -1
--- src/util.c
+++ src/util.c
@@ -903,11 +903,13 @@
903903
** On non-Windows systems, calls nice(2) with the given level. Errors
904904
** are ignored. On Windows this is a no-op.
905905
*/
906906
void fossil_nice(int level){
907907
#ifndef _WIN32
908
- nice(level);
908
+ /* dummy if() condition to avoid nuisance warning about unused result on
909
+ certain compiler */
910
+ if( nice(level) ){ /*ignored*/ }
909911
#else
910912
(void)level;
911913
#endif
912914
}
913915
914916
--- src/util.c
+++ src/util.c
@@ -903,11 +903,13 @@
903 ** On non-Windows systems, calls nice(2) with the given level. Errors
904 ** are ignored. On Windows this is a no-op.
905 */
906 void fossil_nice(int level){
907 #ifndef _WIN32
908 nice(level);
 
 
909 #else
910 (void)level;
911 #endif
912 }
913
914
--- src/util.c
+++ src/util.c
@@ -903,11 +903,13 @@
903 ** On non-Windows systems, calls nice(2) with the given level. Errors
904 ** are ignored. On Windows this is a no-op.
905 */
906 void fossil_nice(int level){
907 #ifndef _WIN32
908 /* dummy if() condition to avoid nuisance warning about unused result on
909 certain compiler */
910 if( nice(level) ){ /*ignored*/ }
911 #else
912 (void)level;
913 #endif
914 }
915
916
+17 -1
--- src/wiki.c
+++ src/wiki.c
@@ -1917,10 +1917,11 @@
19171917
void wcontent_page(void){
19181918
Stmt q;
19191919
double rNow;
19201920
int showAll = P("all")!=0;
19211921
int showRid = P("showid")!=0;
1922
+ int showCkBr = P("showckbr")!=0;
19221923
19231924
login_check_credentials();
19241925
if( !g.perm.RdWiki ){ login_needed(g.anon.RdWiki); return; }
19251926
style_set_current_feature("wiki");
19261927
style_header("Available Wiki Pages");
@@ -1927,10 +1928,11 @@
19271928
if( showAll ){
19281929
style_submenu_element("Active", "%R/wcontent");
19291930
}else{
19301931
style_submenu_element("All", "%R/wcontent?all=1");
19311932
}
1933
+ style_submenu_checkbox("showckbr", "Show associated wikis", 0, 0);
19321934
wiki_standard_submenu(W_ALL_BUT(W_LIST));
19331935
db_prepare(&q, listAllWikiPages/*works-like:""*/);
19341936
@ <div class="brlist">
19351937
@ <table class='sortable' data-column-types='tKN' data-init-sort='1'>
19361938
@ <thead><tr>
@@ -1954,10 +1956,15 @@
19541956
19551957
if( sqlite3_strglob("checkin/*", zWName)==0 ){
19561958
zWDisplayName = mprintf("%.25s...", zWName);
19571959
}else{
19581960
zWDisplayName = mprintf("%s", zWName);
1961
+ }
1962
+ if( !showCkBr &&
1963
+ (sqlite3_strglob("checkin/*", zWName)==0 ||
1964
+ sqlite3_strglob("branch/*", zWName)==0) ){
1965
+ continue;
19591966
}
19601967
if( wrid==0 ){
19611968
if( !showAll ) continue;
19621969
@ <tr><td data-sortkey="%h(zSort)">\
19631970
@ %z(href("%R/whistory?name=%T",zWName))<s>%h(zWDisplayName)</s></a></td>
@@ -2182,19 +2189,22 @@
21822189
**
21832190
** > fossil wiki list ?OPTIONS?
21842191
** > fossil wiki ls ?OPTIONS?
21852192
**
21862193
** Lists all wiki entries, one per line, ordered
2187
-** case-insensitively by name.
2194
+** case-insensitively by name. Wiki pages associated with
2195
+** check-ins and branches are NOT shown, unless -a is given.
21882196
**
21892197
** Options:
21902198
** --all Include "deleted" pages in output.
21912199
** By default deleted pages are elided.
21922200
** -t|--technote Technotes will be listed instead of
21932201
** pages. The technotes will be in order
21942202
** of timestamp with the most recent
21952203
** first.
2204
+** -a|--show-associated Show wiki pages associated with
2205
+** check-ins and branches.
21962206
** -s|--show-technote-ids The id of the tech note will be listed
21972207
** along side the timestamp. The tech note
21982208
** id will be the first word on each line.
21992209
** This option only applies if the
22002210
** --technote option is also specified.
@@ -2424,10 +2434,11 @@
24242434
}else if(( strncmp(g.argv[2],"list",n)==0 )
24252435
|| ( strncmp(g.argv[2],"ls",n)==0 )){
24262436
Stmt q;
24272437
const int fTechnote = find_option("technote","t",0)!=0;
24282438
const int showIds = find_option("show-technote-ids","s",0)!=0;
2439
+ const int showCkBr = find_option("show-associated","a",0)!=0;
24292440
verify_all_options();
24302441
if (fTechnote==0){
24312442
db_prepare(&q, listAllWikiPages/*works-like:""*/);
24322443
}else{
24332444
db_prepare(&q,
@@ -2442,10 +2453,15 @@
24422453
while( db_step(&q)==SQLITE_ROW ){
24432454
const char *zName = db_column_text(&q, 0);
24442455
const int wrid = db_column_int(&q, 2);
24452456
if(!showAll && !wrid){
24462457
continue;
2458
+ }
2459
+ if( !showCkBr &&
2460
+ (sqlite3_strglob("checkin/*", zName)==0 ||
2461
+ sqlite3_strglob("branch/*", zName)==0) ){
2462
+ continue;
24472463
}
24482464
if( showIds ){
24492465
const char *zUuid = db_column_text(&q, 1);
24502466
fossil_print("%s ",zUuid);
24512467
}
24522468
--- src/wiki.c
+++ src/wiki.c
@@ -1917,10 +1917,11 @@
1917 void wcontent_page(void){
1918 Stmt q;
1919 double rNow;
1920 int showAll = P("all")!=0;
1921 int showRid = P("showid")!=0;
 
1922
1923 login_check_credentials();
1924 if( !g.perm.RdWiki ){ login_needed(g.anon.RdWiki); return; }
1925 style_set_current_feature("wiki");
1926 style_header("Available Wiki Pages");
@@ -1927,10 +1928,11 @@
1927 if( showAll ){
1928 style_submenu_element("Active", "%R/wcontent");
1929 }else{
1930 style_submenu_element("All", "%R/wcontent?all=1");
1931 }
 
1932 wiki_standard_submenu(W_ALL_BUT(W_LIST));
1933 db_prepare(&q, listAllWikiPages/*works-like:""*/);
1934 @ <div class="brlist">
1935 @ <table class='sortable' data-column-types='tKN' data-init-sort='1'>
1936 @ <thead><tr>
@@ -1954,10 +1956,15 @@
1954
1955 if( sqlite3_strglob("checkin/*", zWName)==0 ){
1956 zWDisplayName = mprintf("%.25s...", zWName);
1957 }else{
1958 zWDisplayName = mprintf("%s", zWName);
 
 
 
 
 
1959 }
1960 if( wrid==0 ){
1961 if( !showAll ) continue;
1962 @ <tr><td data-sortkey="%h(zSort)">\
1963 @ %z(href("%R/whistory?name=%T",zWName))<s>%h(zWDisplayName)</s></a></td>
@@ -2182,19 +2189,22 @@
2182 **
2183 ** > fossil wiki list ?OPTIONS?
2184 ** > fossil wiki ls ?OPTIONS?
2185 **
2186 ** Lists all wiki entries, one per line, ordered
2187 ** case-insensitively by name.
 
2188 **
2189 ** Options:
2190 ** --all Include "deleted" pages in output.
2191 ** By default deleted pages are elided.
2192 ** -t|--technote Technotes will be listed instead of
2193 ** pages. The technotes will be in order
2194 ** of timestamp with the most recent
2195 ** first.
 
 
2196 ** -s|--show-technote-ids The id of the tech note will be listed
2197 ** along side the timestamp. The tech note
2198 ** id will be the first word on each line.
2199 ** This option only applies if the
2200 ** --technote option is also specified.
@@ -2424,10 +2434,11 @@
2424 }else if(( strncmp(g.argv[2],"list",n)==0 )
2425 || ( strncmp(g.argv[2],"ls",n)==0 )){
2426 Stmt q;
2427 const int fTechnote = find_option("technote","t",0)!=0;
2428 const int showIds = find_option("show-technote-ids","s",0)!=0;
 
2429 verify_all_options();
2430 if (fTechnote==0){
2431 db_prepare(&q, listAllWikiPages/*works-like:""*/);
2432 }else{
2433 db_prepare(&q,
@@ -2442,10 +2453,15 @@
2442 while( db_step(&q)==SQLITE_ROW ){
2443 const char *zName = db_column_text(&q, 0);
2444 const int wrid = db_column_int(&q, 2);
2445 if(!showAll && !wrid){
2446 continue;
 
 
 
 
 
2447 }
2448 if( showIds ){
2449 const char *zUuid = db_column_text(&q, 1);
2450 fossil_print("%s ",zUuid);
2451 }
2452
--- src/wiki.c
+++ src/wiki.c
@@ -1917,10 +1917,11 @@
1917 void wcontent_page(void){
1918 Stmt q;
1919 double rNow;
1920 int showAll = P("all")!=0;
1921 int showRid = P("showid")!=0;
1922 int showCkBr = P("showckbr")!=0;
1923
1924 login_check_credentials();
1925 if( !g.perm.RdWiki ){ login_needed(g.anon.RdWiki); return; }
1926 style_set_current_feature("wiki");
1927 style_header("Available Wiki Pages");
@@ -1927,10 +1928,11 @@
1928 if( showAll ){
1929 style_submenu_element("Active", "%R/wcontent");
1930 }else{
1931 style_submenu_element("All", "%R/wcontent?all=1");
1932 }
1933 style_submenu_checkbox("showckbr", "Show associated wikis", 0, 0);
1934 wiki_standard_submenu(W_ALL_BUT(W_LIST));
1935 db_prepare(&q, listAllWikiPages/*works-like:""*/);
1936 @ <div class="brlist">
1937 @ <table class='sortable' data-column-types='tKN' data-init-sort='1'>
1938 @ <thead><tr>
@@ -1954,10 +1956,15 @@
1956
1957 if( sqlite3_strglob("checkin/*", zWName)==0 ){
1958 zWDisplayName = mprintf("%.25s...", zWName);
1959 }else{
1960 zWDisplayName = mprintf("%s", zWName);
1961 }
1962 if( !showCkBr &&
1963 (sqlite3_strglob("checkin/*", zWName)==0 ||
1964 sqlite3_strglob("branch/*", zWName)==0) ){
1965 continue;
1966 }
1967 if( wrid==0 ){
1968 if( !showAll ) continue;
1969 @ <tr><td data-sortkey="%h(zSort)">\
1970 @ %z(href("%R/whistory?name=%T",zWName))<s>%h(zWDisplayName)</s></a></td>
@@ -2182,19 +2189,22 @@
2189 **
2190 ** > fossil wiki list ?OPTIONS?
2191 ** > fossil wiki ls ?OPTIONS?
2192 **
2193 ** Lists all wiki entries, one per line, ordered
2194 ** case-insensitively by name. Wiki pages associated with
2195 ** check-ins and branches are NOT shown, unless -a is given.
2196 **
2197 ** Options:
2198 ** --all Include "deleted" pages in output.
2199 ** By default deleted pages are elided.
2200 ** -t|--technote Technotes will be listed instead of
2201 ** pages. The technotes will be in order
2202 ** of timestamp with the most recent
2203 ** first.
2204 ** -a|--show-associated Show wiki pages associated with
2205 ** check-ins and branches.
2206 ** -s|--show-technote-ids The id of the tech note will be listed
2207 ** along side the timestamp. The tech note
2208 ** id will be the first word on each line.
2209 ** This option only applies if the
2210 ** --technote option is also specified.
@@ -2424,10 +2434,11 @@
2434 }else if(( strncmp(g.argv[2],"list",n)==0 )
2435 || ( strncmp(g.argv[2],"ls",n)==0 )){
2436 Stmt q;
2437 const int fTechnote = find_option("technote","t",0)!=0;
2438 const int showIds = find_option("show-technote-ids","s",0)!=0;
2439 const int showCkBr = find_option("show-associated","a",0)!=0;
2440 verify_all_options();
2441 if (fTechnote==0){
2442 db_prepare(&q, listAllWikiPages/*works-like:""*/);
2443 }else{
2444 db_prepare(&q,
@@ -2442,10 +2453,15 @@
2453 while( db_step(&q)==SQLITE_ROW ){
2454 const char *zName = db_column_text(&q, 0);
2455 const int wrid = db_column_int(&q, 2);
2456 if(!showAll && !wrid){
2457 continue;
2458 }
2459 if( !showCkBr &&
2460 (sqlite3_strglob("checkin/*", zName)==0 ||
2461 sqlite3_strglob("branch/*", zName)==0) ){
2462 continue;
2463 }
2464 if( showIds ){
2465 const char *zUuid = db_column_text(&q, 1);
2466 fossil_print("%s ",zUuid);
2467 }
2468
+71 -66
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -175,76 +175,79 @@
175175
** Allowed markup.
176176
**
177177
** Except for MARKUP_INVALID, this must all be in alphabetical order
178178
** and in numerical sequence. The first markup type must be zero.
179179
** The value for MARKUP_XYZ must correspond to the <xyz> entry
180
-** in aAllowedMarkup[].
181
-*/
182
-#define MARKUP_INVALID 0
183
-#define MARKUP_A 1
184
-#define MARKUP_ADDRESS 2
185
-#define MARKUP_HTML5_ARTICLE 3
186
-#define MARKUP_HTML5_ASIDE 4
187
-#define MARKUP_B 5
188
-#define MARKUP_BIG 6
189
-#define MARKUP_BLOCKQUOTE 7
190
-#define MARKUP_BR 8
191
-#define MARKUP_CENTER 9
192
-#define MARKUP_CITE 10
193
-#define MARKUP_CODE 11
194
-#define MARKUP_COL 12
195
-#define MARKUP_COLGROUP 13
196
-#define MARKUP_DD 14
197
-#define MARKUP_DEL 15
198
-#define MARKUP_DFN 16
199
-#define MARKUP_DIV 17
200
-#define MARKUP_DL 18
201
-#define MARKUP_DT 19
202
-#define MARKUP_EM 20
203
-#define MARKUP_FONT 21
204
-#define MARKUP_HTML5_FOOTER 22
205
-#define MARKUP_H1 23
206
-#define MARKUP_H2 24
207
-#define MARKUP_H3 25
208
-#define MARKUP_H4 26
209
-#define MARKUP_H5 27
210
-#define MARKUP_H6 28
211
-#define MARKUP_HTML5_HEADER 29
212
-#define MARKUP_HR 30
213
-#define MARKUP_I 31
214
-#define MARKUP_IMG 32
215
-#define MARKUP_INS 33
216
-#define MARKUP_KBD 34
217
-#define MARKUP_LI 35
218
-#define MARKUP_HTML5_NAV 36
219
-#define MARKUP_NOBR 37
220
-#define MARKUP_NOWIKI 38
221
-#define MARKUP_OL 39
222
-#define MARKUP_P 40
223
-#define MARKUP_PRE 41
224
-#define MARKUP_S 42
225
-#define MARKUP_SAMP 43
226
-#define MARKUP_HTML5_SECTION 44
227
-#define MARKUP_SMALL 45
228
-#define MARKUP_SPAN 46
229
-#define MARKUP_STRIKE 47
230
-#define MARKUP_STRONG 48
231
-#define MARKUP_SUB 49
232
-#define MARKUP_SUP 50
233
-#define MARKUP_TABLE 51
234
-#define MARKUP_TBODY 52
235
-#define MARKUP_TD 53
236
-#define MARKUP_TFOOT 54
237
-#define MARKUP_TH 55
238
-#define MARKUP_THEAD 56
239
-#define MARKUP_TITLE 57
240
-#define MARKUP_TR 58
241
-#define MARKUP_TT 59
242
-#define MARKUP_U 60
243
-#define MARKUP_UL 61
244
-#define MARKUP_VAR 62
245
-#define MARKUP_VERBATIM 63
180
+** in aMarkup[].
181
+*/
182
+enum markup_t {
183
+ MARKUP_INVALID = 0,
184
+ MARKUP_A,
185
+ MARKUP_ABBR,
186
+ MARKUP_ADDRESS,
187
+ MARKUP_HTML5_ARTICLE,
188
+ MARKUP_HTML5_ASIDE,
189
+ MARKUP_B,
190
+ MARKUP_BIG,
191
+ MARKUP_BLOCKQUOTE,
192
+ MARKUP_BR,
193
+ MARKUP_CENTER,
194
+ MARKUP_CITE,
195
+ MARKUP_CODE,
196
+ MARKUP_COL,
197
+ MARKUP_COLGROUP,
198
+ MARKUP_DD,
199
+ MARKUP_DEL,
200
+ MARKUP_DFN,
201
+ MARKUP_DIV,
202
+ MARKUP_DL,
203
+ MARKUP_DT,
204
+ MARKUP_EM,
205
+ MARKUP_FONT,
206
+ MARKUP_HTML5_FOOTER,
207
+ MARKUP_H1,
208
+ MARKUP_H2,
209
+ MARKUP_H3,
210
+ MARKUP_H4,
211
+ MARKUP_H5,
212
+ MARKUP_H6,
213
+ MARKUP_HTML5_HEADER,
214
+ MARKUP_HR,
215
+ MARKUP_I,
216
+ MARKUP_IMG,
217
+ MARKUP_INS,
218
+ MARKUP_KBD,
219
+ MARKUP_LI,
220
+ MARKUP_HTML5_NAV,
221
+ MARKUP_NOBR,
222
+ MARKUP_NOWIKI,
223
+ MARKUP_OL,
224
+ MARKUP_P,
225
+ MARKUP_PRE,
226
+ MARKUP_S,
227
+ MARKUP_SAMP,
228
+ MARKUP_HTML5_SECTION,
229
+ MARKUP_SMALL,
230
+ MARKUP_SPAN,
231
+ MARKUP_STRIKE,
232
+ MARKUP_STRONG,
233
+ MARKUP_SUB,
234
+ MARKUP_SUP,
235
+ MARKUP_TABLE,
236
+ MARKUP_TBODY,
237
+ MARKUP_TD,
238
+ MARKUP_TFOOT,
239
+ MARKUP_TH,
240
+ MARKUP_THEAD,
241
+ MARKUP_TITLE,
242
+ MARKUP_TR,
243
+ MARKUP_TT,
244
+ MARKUP_U,
245
+ MARKUP_UL,
246
+ MARKUP_VAR,
247
+ MARKUP_VERBATIM
248
+};
246249
247250
/*
248251
** The various markup is divided into the following types:
249252
*/
250253
#define MUTYPE_SINGLE 0x0001 /* <img>, <br>, or <hr> */
@@ -279,10 +282,12 @@
279282
} aMarkup[] = {
280283
{ 0, MARKUP_INVALID, 0, 0 },
281284
{ "a", MARKUP_A, MUTYPE_HYPERLINK,
282285
AMSK_HREF|AMSK_NAME|AMSK_CLASS|AMSK_TARGET|AMSK_STYLE|
283286
AMSK_TITLE},
287
+ { "abbr", MARKUP_ABBR, MUTYPE_FONT,
288
+ AMSK_ID|AMSK_CLASS|AMSK_STYLE|AMSK_TITLE },
284289
{ "address", MARKUP_ADDRESS, MUTYPE_BLOCK, AMSK_STYLE },
285290
{ "article", MARKUP_HTML5_ARTICLE, MUTYPE_BLOCK,
286291
AMSK_ID|AMSK_CLASS|AMSK_STYLE },
287292
{ "aside", MARKUP_HTML5_ASIDE, MUTYPE_BLOCK,
288293
AMSK_ID|AMSK_CLASS|AMSK_STYLE },
289294
290295
ADDED tools/emcc.sh.in
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -175,76 +175,79 @@
175 ** Allowed markup.
176 **
177 ** Except for MARKUP_INVALID, this must all be in alphabetical order
178 ** and in numerical sequence. The first markup type must be zero.
179 ** The value for MARKUP_XYZ must correspond to the <xyz> entry
180 ** in aAllowedMarkup[].
181 */
182 #define MARKUP_INVALID 0
183 #define MARKUP_A 1
184 #define MARKUP_ADDRESS 2
185 #define MARKUP_HTML5_ARTICLE 3
186 #define MARKUP_HTML5_ASIDE 4
187 #define MARKUP_B 5
188 #define MARKUP_BIG 6
189 #define MARKUP_BLOCKQUOTE 7
190 #define MARKUP_BR 8
191 #define MARKUP_CENTER 9
192 #define MARKUP_CITE 10
193 #define MARKUP_CODE 11
194 #define MARKUP_COL 12
195 #define MARKUP_COLGROUP 13
196 #define MARKUP_DD 14
197 #define MARKUP_DEL 15
198 #define MARKUP_DFN 16
199 #define MARKUP_DIV 17
200 #define MARKUP_DL 18
201 #define MARKUP_DT 19
202 #define MARKUP_EM 20
203 #define MARKUP_FONT 21
204 #define MARKUP_HTML5_FOOTER 22
205 #define MARKUP_H1 23
206 #define MARKUP_H2 24
207 #define MARKUP_H3 25
208 #define MARKUP_H4 26
209 #define MARKUP_H5 27
210 #define MARKUP_H6 28
211 #define MARKUP_HTML5_HEADER 29
212 #define MARKUP_HR 30
213 #define MARKUP_I 31
214 #define MARKUP_IMG 32
215 #define MARKUP_INS 33
216 #define MARKUP_KBD 34
217 #define MARKUP_LI 35
218 #define MARKUP_HTML5_NAV 36
219 #define MARKUP_NOBR 37
220 #define MARKUP_NOWIKI 38
221 #define MARKUP_OL 39
222 #define MARKUP_P 40
223 #define MARKUP_PRE 41
224 #define MARKUP_S 42
225 #define MARKUP_SAMP 43
226 #define MARKUP_HTML5_SECTION 44
227 #define MARKUP_SMALL 45
228 #define MARKUP_SPAN 46
229 #define MARKUP_STRIKE 47
230 #define MARKUP_STRONG 48
231 #define MARKUP_SUB 49
232 #define MARKUP_SUP 50
233 #define MARKUP_TABLE 51
234 #define MARKUP_TBODY 52
235 #define MARKUP_TD 53
236 #define MARKUP_TFOOT 54
237 #define MARKUP_TH 55
238 #define MARKUP_THEAD 56
239 #define MARKUP_TITLE 57
240 #define MARKUP_TR 58
241 #define MARKUP_TT 59
242 #define MARKUP_U 60
243 #define MARKUP_UL 61
244 #define MARKUP_VAR 62
245 #define MARKUP_VERBATIM 63
 
 
 
246
247 /*
248 ** The various markup is divided into the following types:
249 */
250 #define MUTYPE_SINGLE 0x0001 /* <img>, <br>, or <hr> */
@@ -279,10 +282,12 @@
279 } aMarkup[] = {
280 { 0, MARKUP_INVALID, 0, 0 },
281 { "a", MARKUP_A, MUTYPE_HYPERLINK,
282 AMSK_HREF|AMSK_NAME|AMSK_CLASS|AMSK_TARGET|AMSK_STYLE|
283 AMSK_TITLE},
 
 
284 { "address", MARKUP_ADDRESS, MUTYPE_BLOCK, AMSK_STYLE },
285 { "article", MARKUP_HTML5_ARTICLE, MUTYPE_BLOCK,
286 AMSK_ID|AMSK_CLASS|AMSK_STYLE },
287 { "aside", MARKUP_HTML5_ASIDE, MUTYPE_BLOCK,
288 AMSK_ID|AMSK_CLASS|AMSK_STYLE },
289
290 DDED tools/emcc.sh.in
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -175,76 +175,79 @@
175 ** Allowed markup.
176 **
177 ** Except for MARKUP_INVALID, this must all be in alphabetical order
178 ** and in numerical sequence. The first markup type must be zero.
179 ** The value for MARKUP_XYZ must correspond to the <xyz> entry
180 ** in aMarkup[].
181 */
182 enum markup_t {
183 MARKUP_INVALID = 0,
184 MARKUP_A,
185 MARKUP_ABBR,
186 MARKUP_ADDRESS,
187 MARKUP_HTML5_ARTICLE,
188 MARKUP_HTML5_ASIDE,
189 MARKUP_B,
190 MARKUP_BIG,
191 MARKUP_BLOCKQUOTE,
192 MARKUP_BR,
193 MARKUP_CENTER,
194 MARKUP_CITE,
195 MARKUP_CODE,
196 MARKUP_COL,
197 MARKUP_COLGROUP,
198 MARKUP_DD,
199 MARKUP_DEL,
200 MARKUP_DFN,
201 MARKUP_DIV,
202 MARKUP_DL,
203 MARKUP_DT,
204 MARKUP_EM,
205 MARKUP_FONT,
206 MARKUP_HTML5_FOOTER,
207 MARKUP_H1,
208 MARKUP_H2,
209 MARKUP_H3,
210 MARKUP_H4,
211 MARKUP_H5,
212 MARKUP_H6,
213 MARKUP_HTML5_HEADER,
214 MARKUP_HR,
215 MARKUP_I,
216 MARKUP_IMG,
217 MARKUP_INS,
218 MARKUP_KBD,
219 MARKUP_LI,
220 MARKUP_HTML5_NAV,
221 MARKUP_NOBR,
222 MARKUP_NOWIKI,
223 MARKUP_OL,
224 MARKUP_P,
225 MARKUP_PRE,
226 MARKUP_S,
227 MARKUP_SAMP,
228 MARKUP_HTML5_SECTION,
229 MARKUP_SMALL,
230 MARKUP_SPAN,
231 MARKUP_STRIKE,
232 MARKUP_STRONG,
233 MARKUP_SUB,
234 MARKUP_SUP,
235 MARKUP_TABLE,
236 MARKUP_TBODY,
237 MARKUP_TD,
238 MARKUP_TFOOT,
239 MARKUP_TH,
240 MARKUP_THEAD,
241 MARKUP_TITLE,
242 MARKUP_TR,
243 MARKUP_TT,
244 MARKUP_U,
245 MARKUP_UL,
246 MARKUP_VAR,
247 MARKUP_VERBATIM
248 };
249
250 /*
251 ** The various markup is divided into the following types:
252 */
253 #define MUTYPE_SINGLE 0x0001 /* <img>, <br>, or <hr> */
@@ -279,10 +282,12 @@
282 } aMarkup[] = {
283 { 0, MARKUP_INVALID, 0, 0 },
284 { "a", MARKUP_A, MUTYPE_HYPERLINK,
285 AMSK_HREF|AMSK_NAME|AMSK_CLASS|AMSK_TARGET|AMSK_STYLE|
286 AMSK_TITLE},
287 { "abbr", MARKUP_ABBR, MUTYPE_FONT,
288 AMSK_ID|AMSK_CLASS|AMSK_STYLE|AMSK_TITLE },
289 { "address", MARKUP_ADDRESS, MUTYPE_BLOCK, AMSK_STYLE },
290 { "article", MARKUP_HTML5_ARTICLE, MUTYPE_BLOCK,
291 AMSK_ID|AMSK_CLASS|AMSK_STYLE },
292 { "aside", MARKUP_HTML5_ASIDE, MUTYPE_BLOCK,
293 AMSK_ID|AMSK_CLASS|AMSK_STYLE },
294
295 DDED tools/emcc.sh.in
+71 -66
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -175,76 +175,79 @@
175175
** Allowed markup.
176176
**
177177
** Except for MARKUP_INVALID, this must all be in alphabetical order
178178
** and in numerical sequence. The first markup type must be zero.
179179
** The value for MARKUP_XYZ must correspond to the <xyz> entry
180
-** in aAllowedMarkup[].
181
-*/
182
-#define MARKUP_INVALID 0
183
-#define MARKUP_A 1
184
-#define MARKUP_ADDRESS 2
185
-#define MARKUP_HTML5_ARTICLE 3
186
-#define MARKUP_HTML5_ASIDE 4
187
-#define MARKUP_B 5
188
-#define MARKUP_BIG 6
189
-#define MARKUP_BLOCKQUOTE 7
190
-#define MARKUP_BR 8
191
-#define MARKUP_CENTER 9
192
-#define MARKUP_CITE 10
193
-#define MARKUP_CODE 11
194
-#define MARKUP_COL 12
195
-#define MARKUP_COLGROUP 13
196
-#define MARKUP_DD 14
197
-#define MARKUP_DEL 15
198
-#define MARKUP_DFN 16
199
-#define MARKUP_DIV 17
200
-#define MARKUP_DL 18
201
-#define MARKUP_DT 19
202
-#define MARKUP_EM 20
203
-#define MARKUP_FONT 21
204
-#define MARKUP_HTML5_FOOTER 22
205
-#define MARKUP_H1 23
206
-#define MARKUP_H2 24
207
-#define MARKUP_H3 25
208
-#define MARKUP_H4 26
209
-#define MARKUP_H5 27
210
-#define MARKUP_H6 28
211
-#define MARKUP_HTML5_HEADER 29
212
-#define MARKUP_HR 30
213
-#define MARKUP_I 31
214
-#define MARKUP_IMG 32
215
-#define MARKUP_INS 33
216
-#define MARKUP_KBD 34
217
-#define MARKUP_LI 35
218
-#define MARKUP_HTML5_NAV 36
219
-#define MARKUP_NOBR 37
220
-#define MARKUP_NOWIKI 38
221
-#define MARKUP_OL 39
222
-#define MARKUP_P 40
223
-#define MARKUP_PRE 41
224
-#define MARKUP_S 42
225
-#define MARKUP_SAMP 43
226
-#define MARKUP_HTML5_SECTION 44
227
-#define MARKUP_SMALL 45
228
-#define MARKUP_SPAN 46
229
-#define MARKUP_STRIKE 47
230
-#define MARKUP_STRONG 48
231
-#define MARKUP_SUB 49
232
-#define MARKUP_SUP 50
233
-#define MARKUP_TABLE 51
234
-#define MARKUP_TBODY 52
235
-#define MARKUP_TD 53
236
-#define MARKUP_TFOOT 54
237
-#define MARKUP_TH 55
238
-#define MARKUP_THEAD 56
239
-#define MARKUP_TITLE 57
240
-#define MARKUP_TR 58
241
-#define MARKUP_TT 59
242
-#define MARKUP_U 60
243
-#define MARKUP_UL 61
244
-#define MARKUP_VAR 62
245
-#define MARKUP_VERBATIM 63
180
+** in aMarkup[].
181
+*/
182
+enum markup_t {
183
+ MARKUP_INVALID = 0,
184
+ MARKUP_A,
185
+ MARKUP_ABBR,
186
+ MARKUP_ADDRESS,
187
+ MARKUP_HTML5_ARTICLE,
188
+ MARKUP_HTML5_ASIDE,
189
+ MARKUP_B,
190
+ MARKUP_BIG,
191
+ MARKUP_BLOCKQUOTE,
192
+ MARKUP_BR,
193
+ MARKUP_CENTER,
194
+ MARKUP_CITE,
195
+ MARKUP_CODE,
196
+ MARKUP_COL,
197
+ MARKUP_COLGROUP,
198
+ MARKUP_DD,
199
+ MARKUP_DEL,
200
+ MARKUP_DFN,
201
+ MARKUP_DIV,
202
+ MARKUP_DL,
203
+ MARKUP_DT,
204
+ MARKUP_EM,
205
+ MARKUP_FONT,
206
+ MARKUP_HTML5_FOOTER,
207
+ MARKUP_H1,
208
+ MARKUP_H2,
209
+ MARKUP_H3,
210
+ MARKUP_H4,
211
+ MARKUP_H5,
212
+ MARKUP_H6,
213
+ MARKUP_HTML5_HEADER,
214
+ MARKUP_HR,
215
+ MARKUP_I,
216
+ MARKUP_IMG,
217
+ MARKUP_INS,
218
+ MARKUP_KBD,
219
+ MARKUP_LI,
220
+ MARKUP_HTML5_NAV,
221
+ MARKUP_NOBR,
222
+ MARKUP_NOWIKI,
223
+ MARKUP_OL,
224
+ MARKUP_P,
225
+ MARKUP_PRE,
226
+ MARKUP_S,
227
+ MARKUP_SAMP,
228
+ MARKUP_HTML5_SECTION,
229
+ MARKUP_SMALL,
230
+ MARKUP_SPAN,
231
+ MARKUP_STRIKE,
232
+ MARKUP_STRONG,
233
+ MARKUP_SUB,
234
+ MARKUP_SUP,
235
+ MARKUP_TABLE,
236
+ MARKUP_TBODY,
237
+ MARKUP_TD,
238
+ MARKUP_TFOOT,
239
+ MARKUP_TH,
240
+ MARKUP_THEAD,
241
+ MARKUP_TITLE,
242
+ MARKUP_TR,
243
+ MARKUP_TT,
244
+ MARKUP_U,
245
+ MARKUP_UL,
246
+ MARKUP_VAR,
247
+ MARKUP_VERBATIM
248
+};
246249
247250
/*
248251
** The various markup is divided into the following types:
249252
*/
250253
#define MUTYPE_SINGLE 0x0001 /* <img>, <br>, or <hr> */
@@ -279,10 +282,12 @@
279282
} aMarkup[] = {
280283
{ 0, MARKUP_INVALID, 0, 0 },
281284
{ "a", MARKUP_A, MUTYPE_HYPERLINK,
282285
AMSK_HREF|AMSK_NAME|AMSK_CLASS|AMSK_TARGET|AMSK_STYLE|
283286
AMSK_TITLE},
287
+ { "abbr", MARKUP_ABBR, MUTYPE_FONT,
288
+ AMSK_ID|AMSK_CLASS|AMSK_STYLE|AMSK_TITLE },
284289
{ "address", MARKUP_ADDRESS, MUTYPE_BLOCK, AMSK_STYLE },
285290
{ "article", MARKUP_HTML5_ARTICLE, MUTYPE_BLOCK,
286291
AMSK_ID|AMSK_CLASS|AMSK_STYLE },
287292
{ "aside", MARKUP_HTML5_ASIDE, MUTYPE_BLOCK,
288293
AMSK_ID|AMSK_CLASS|AMSK_STYLE },
289294
290295
ADDED tools/emcc.sh.in
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -175,76 +175,79 @@
175 ** Allowed markup.
176 **
177 ** Except for MARKUP_INVALID, this must all be in alphabetical order
178 ** and in numerical sequence. The first markup type must be zero.
179 ** The value for MARKUP_XYZ must correspond to the <xyz> entry
180 ** in aAllowedMarkup[].
181 */
182 #define MARKUP_INVALID 0
183 #define MARKUP_A 1
184 #define MARKUP_ADDRESS 2
185 #define MARKUP_HTML5_ARTICLE 3
186 #define MARKUP_HTML5_ASIDE 4
187 #define MARKUP_B 5
188 #define MARKUP_BIG 6
189 #define MARKUP_BLOCKQUOTE 7
190 #define MARKUP_BR 8
191 #define MARKUP_CENTER 9
192 #define MARKUP_CITE 10
193 #define MARKUP_CODE 11
194 #define MARKUP_COL 12
195 #define MARKUP_COLGROUP 13
196 #define MARKUP_DD 14
197 #define MARKUP_DEL 15
198 #define MARKUP_DFN 16
199 #define MARKUP_DIV 17
200 #define MARKUP_DL 18
201 #define MARKUP_DT 19
202 #define MARKUP_EM 20
203 #define MARKUP_FONT 21
204 #define MARKUP_HTML5_FOOTER 22
205 #define MARKUP_H1 23
206 #define MARKUP_H2 24
207 #define MARKUP_H3 25
208 #define MARKUP_H4 26
209 #define MARKUP_H5 27
210 #define MARKUP_H6 28
211 #define MARKUP_HTML5_HEADER 29
212 #define MARKUP_HR 30
213 #define MARKUP_I 31
214 #define MARKUP_IMG 32
215 #define MARKUP_INS 33
216 #define MARKUP_KBD 34
217 #define MARKUP_LI 35
218 #define MARKUP_HTML5_NAV 36
219 #define MARKUP_NOBR 37
220 #define MARKUP_NOWIKI 38
221 #define MARKUP_OL 39
222 #define MARKUP_P 40
223 #define MARKUP_PRE 41
224 #define MARKUP_S 42
225 #define MARKUP_SAMP 43
226 #define MARKUP_HTML5_SECTION 44
227 #define MARKUP_SMALL 45
228 #define MARKUP_SPAN 46
229 #define MARKUP_STRIKE 47
230 #define MARKUP_STRONG 48
231 #define MARKUP_SUB 49
232 #define MARKUP_SUP 50
233 #define MARKUP_TABLE 51
234 #define MARKUP_TBODY 52
235 #define MARKUP_TD 53
236 #define MARKUP_TFOOT 54
237 #define MARKUP_TH 55
238 #define MARKUP_THEAD 56
239 #define MARKUP_TITLE 57
240 #define MARKUP_TR 58
241 #define MARKUP_TT 59
242 #define MARKUP_U 60
243 #define MARKUP_UL 61
244 #define MARKUP_VAR 62
245 #define MARKUP_VERBATIM 63
 
 
 
246
247 /*
248 ** The various markup is divided into the following types:
249 */
250 #define MUTYPE_SINGLE 0x0001 /* <img>, <br>, or <hr> */
@@ -279,10 +282,12 @@
279 } aMarkup[] = {
280 { 0, MARKUP_INVALID, 0, 0 },
281 { "a", MARKUP_A, MUTYPE_HYPERLINK,
282 AMSK_HREF|AMSK_NAME|AMSK_CLASS|AMSK_TARGET|AMSK_STYLE|
283 AMSK_TITLE},
 
 
284 { "address", MARKUP_ADDRESS, MUTYPE_BLOCK, AMSK_STYLE },
285 { "article", MARKUP_HTML5_ARTICLE, MUTYPE_BLOCK,
286 AMSK_ID|AMSK_CLASS|AMSK_STYLE },
287 { "aside", MARKUP_HTML5_ASIDE, MUTYPE_BLOCK,
288 AMSK_ID|AMSK_CLASS|AMSK_STYLE },
289
290 DDED tools/emcc.sh.in
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -175,76 +175,79 @@
175 ** Allowed markup.
176 **
177 ** Except for MARKUP_INVALID, this must all be in alphabetical order
178 ** and in numerical sequence. The first markup type must be zero.
179 ** The value for MARKUP_XYZ must correspond to the <xyz> entry
180 ** in aMarkup[].
181 */
182 enum markup_t {
183 MARKUP_INVALID = 0,
184 MARKUP_A,
185 MARKUP_ABBR,
186 MARKUP_ADDRESS,
187 MARKUP_HTML5_ARTICLE,
188 MARKUP_HTML5_ASIDE,
189 MARKUP_B,
190 MARKUP_BIG,
191 MARKUP_BLOCKQUOTE,
192 MARKUP_BR,
193 MARKUP_CENTER,
194 MARKUP_CITE,
195 MARKUP_CODE,
196 MARKUP_COL,
197 MARKUP_COLGROUP,
198 MARKUP_DD,
199 MARKUP_DEL,
200 MARKUP_DFN,
201 MARKUP_DIV,
202 MARKUP_DL,
203 MARKUP_DT,
204 MARKUP_EM,
205 MARKUP_FONT,
206 MARKUP_HTML5_FOOTER,
207 MARKUP_H1,
208 MARKUP_H2,
209 MARKUP_H3,
210 MARKUP_H4,
211 MARKUP_H5,
212 MARKUP_H6,
213 MARKUP_HTML5_HEADER,
214 MARKUP_HR,
215 MARKUP_I,
216 MARKUP_IMG,
217 MARKUP_INS,
218 MARKUP_KBD,
219 MARKUP_LI,
220 MARKUP_HTML5_NAV,
221 MARKUP_NOBR,
222 MARKUP_NOWIKI,
223 MARKUP_OL,
224 MARKUP_P,
225 MARKUP_PRE,
226 MARKUP_S,
227 MARKUP_SAMP,
228 MARKUP_HTML5_SECTION,
229 MARKUP_SMALL,
230 MARKUP_SPAN,
231 MARKUP_STRIKE,
232 MARKUP_STRONG,
233 MARKUP_SUB,
234 MARKUP_SUP,
235 MARKUP_TABLE,
236 MARKUP_TBODY,
237 MARKUP_TD,
238 MARKUP_TFOOT,
239 MARKUP_TH,
240 MARKUP_THEAD,
241 MARKUP_TITLE,
242 MARKUP_TR,
243 MARKUP_TT,
244 MARKUP_U,
245 MARKUP_UL,
246 MARKUP_VAR,
247 MARKUP_VERBATIM
248 };
249
250 /*
251 ** The various markup is divided into the following types:
252 */
253 #define MUTYPE_SINGLE 0x0001 /* <img>, <br>, or <hr> */
@@ -279,10 +282,12 @@
282 } aMarkup[] = {
283 { 0, MARKUP_INVALID, 0, 0 },
284 { "a", MARKUP_A, MUTYPE_HYPERLINK,
285 AMSK_HREF|AMSK_NAME|AMSK_CLASS|AMSK_TARGET|AMSK_STYLE|
286 AMSK_TITLE},
287 { "abbr", MARKUP_ABBR, MUTYPE_FONT,
288 AMSK_ID|AMSK_CLASS|AMSK_STYLE|AMSK_TITLE },
289 { "address", MARKUP_ADDRESS, MUTYPE_BLOCK, AMSK_STYLE },
290 { "article", MARKUP_HTML5_ARTICLE, MUTYPE_BLOCK,
291 AMSK_ID|AMSK_CLASS|AMSK_STYLE },
292 { "aside", MARKUP_HTML5_ASIDE, MUTYPE_BLOCK,
293 AMSK_ID|AMSK_CLASS|AMSK_STYLE },
294
295 DDED tools/emcc.sh.in
--- a/tools/emcc.sh.in
+++ b/tools/emcc.sh.in
@@ -0,0 +1,65 @@
1
+#!/usr/bin/bash
2
+#############################################
3
+# WARNING: emcc.sh is generated from emcc.sh.in by the configure
4
+# process. Do not edit emcc.sh directly, as it may be deleted or
5
+# overwritten by the configure script.
6
+#
7
+# A wrapper around the emcc compiler which uses configure-time state
8
+# to locate the Emscripten SDK and import the SDK's environment
9
+# script, if needed.
10
+########################################################################
11
+# EMSDK_HOME comes from the configure --with-emsdk=/dir flag.
12
+# EMSDK_ENVk=/dir flag.
13
+# EMSDK_ENV_SH is ${thatDir}/emsdk_env.sh and is also set by the
14
+# ="@EMSDK_ENV@"
15
+
16
+emc`which emcc 2>/dev/null`
17
+fi
18
+
19
+if [ x = "x${emcc}" ]; then
20
+ # If emcc is not found in the path, try to find it via an emsdk
21
+ # installation. The SDK variant i
22
+ # style^^^^ Please try to keep this #!/bin/sh
23
+ emcc is also available
24
+ # via package managers on some OSes.
25
+ if [ x = "x${EMSDK_HOME}" ]; then
26
+ echo "EMSDK_HOME is not set. Pass --with-emsdk=/path/to/emsdk" \
27
+ "to the configure script." 1>&2
28
+ exit 1
29
+ fi
30
+
31
+ if [ x = "x${EMSDK_ENV_SH}" ]; then
32
+ if [ -f "${EMSDK_HOME}/emsdk_env.sh" ]; then
33
+ EMSDK_ENV_SH="${EMSDK_HOME}/emsdk_env.sh"
34
+ else
35
+ echo "EMSDK_ENV_SH is not set. Expecting configure script to set it." 1>&2
36
+ exit 2
37
+ fi
38
+ fi
39
+
40
+ if [ ! -f "${EMSDK_ENV_SH}" ]; then
41
+ echo "emsdk_env script not found: $EMSDK_ENV_SH" 1>&2
42
+ exit 3
43
+ fi
44
+
45
+ # $EMSDK is part of the state set by emsdk_env.sh.
46
+ if [ x = "x${EMSDK}" ]; then
47
+ EMSDK_QUIET=1
48
+ export EMSDK_QUIET
49
+ # ^^^ Squelches informational output from ${EMSDK_ENV_SH}.
50
+ source "${EMSDK_ENV_SH}" || {
51
+ rc=$?
52
+ echo "Error sourcing ${EMSDK_ENV_SH}"
53
+ exit $rc
54
+ }
55
+ fi
56
+ emcc=`which emcc 2>/dev/null`
57
+ if [ x = "x${emcc}" ]; then
58
+ echo "emcc not found in PATH. Normally that's set up by ${EMSDK_ENV_SH}." 1>&2
59
+ exit 4
60
+ fi
61
+fi
62
+
63
+exec $emcc "$@"
64
+}" ]; then
65
+ emcc "$@"
--- a/tools/emcc.sh.in
+++ b/tools/emcc.sh.in
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/tools/emcc.sh.in
+++ b/tools/emcc.sh.in
@@ -0,0 +1,65 @@
1 #!/usr/bin/bash
2 #############################################
3 # WARNING: emcc.sh is generated from emcc.sh.in by the configure
4 # process. Do not edit emcc.sh directly, as it may be deleted or
5 # overwritten by the configure script.
6 #
7 # A wrapper around the emcc compiler which uses configure-time state
8 # to locate the Emscripten SDK and import the SDK's environment
9 # script, if needed.
10 ########################################################################
11 # EMSDK_HOME comes from the configure --with-emsdk=/dir flag.
12 # EMSDK_ENVk=/dir flag.
13 # EMSDK_ENV_SH is ${thatDir}/emsdk_env.sh and is also set by the
14 # ="@EMSDK_ENV@"
15
16 emc`which emcc 2>/dev/null`
17 fi
18
19 if [ x = "x${emcc}" ]; then
20 # If emcc is not found in the path, try to find it via an emsdk
21 # installation. The SDK variant i
22 # style^^^^ Please try to keep this #!/bin/sh
23 emcc is also available
24 # via package managers on some OSes.
25 if [ x = "x${EMSDK_HOME}" ]; then
26 echo "EMSDK_HOME is not set. Pass --with-emsdk=/path/to/emsdk" \
27 "to the configure script." 1>&2
28 exit 1
29 fi
30
31 if [ x = "x${EMSDK_ENV_SH}" ]; then
32 if [ -f "${EMSDK_HOME}/emsdk_env.sh" ]; then
33 EMSDK_ENV_SH="${EMSDK_HOME}/emsdk_env.sh"
34 else
35 echo "EMSDK_ENV_SH is not set. Expecting configure script to set it." 1>&2
36 exit 2
37 fi
38 fi
39
40 if [ ! -f "${EMSDK_ENV_SH}" ]; then
41 echo "emsdk_env script not found: $EMSDK_ENV_SH" 1>&2
42 exit 3
43 fi
44
45 # $EMSDK is part of the state set by emsdk_env.sh.
46 if [ x = "x${EMSDK}" ]; then
47 EMSDK_QUIET=1
48 export EMSDK_QUIET
49 # ^^^ Squelches informational output from ${EMSDK_ENV_SH}.
50 source "${EMSDK_ENV_SH}" || {
51 rc=$?
52 echo "Error sourcing ${EMSDK_ENV_SH}"
53 exit $rc
54 }
55 fi
56 emcc=`which emcc 2>/dev/null`
57 if [ x = "x${emcc}" ]; then
58 echo "emcc not found in PATH. Normally that's set up by ${EMSDK_ENV_SH}." 1>&2
59 exit 4
60 fi
61 fi
62
63 exec $emcc "$@"
64 }" ]; then
65 emcc "$@"
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -217,10 +217,12 @@
217217
default.css
218218
style.*.css
219219
../skins/*/*.txt
220220
sounds/*.wav
221221
alerts/*.wav
222
+ ../extsrc/pikchr.wasm
223
+ ../extsrc/pikchr*.js
222224
}
223225
224226
# Options used to compile the included SQLite library.
225227
#
226228
set SQLITE_OPTIONS {
@@ -559,10 +561,21 @@
559561
$(XTCC) $(PIKCHR_OPTIONS) -c $(SRCDIR_extsrc)/pikchr.c -o $@
560562
561563
$(OBJDIR)/cson_amalgamation.o: $(SRCDIR_extsrc)/cson_amalgamation.c
562564
$(XTCC) -c $(SRCDIR_extsrc)/cson_amalgamation.c -o $@
563565
566
+$(SRCDIR_extsrc)/pikchr.js: $(SRCDIR_extsrc)/pikchr.c
567
+ $(EMCC_WRAPPER) -o $@ $(EMCC_OPT) --no-entry \
568
+ -sEXPORTED_RUNTIME_METHODS=cwrap,setValue,getValue,stackSave,stackRestore \
569
+ -sEXPORTED_FUNCTIONS=_pikchr $(SRCDIR_extsrc)/pikchr.c \
570
+ -sENVIRONMENT=web \
571
+ -sMODULARIZE \
572
+ -sEXPORT_NAME=initPikchrModule \
573
+ --minify 0
574
+ @chmod -x $(SRCDIR_extsrc)/pikchr.wasm
575
+wasm: $(SRCDIR_extsrc)/pikchr.js
576
+
564577
#
565578
# The list of all the targets that do not correspond to real files. This stops
566579
# 'make' from getting confused when someone makes an error in a rule.
567580
#
568581
@@ -637,11 +650,11 @@
637650
638651
#### Enable compiling with debug symbols (much larger binary)
639652
#
640653
# FOSSIL_ENABLE_SYMBOLS = 1
641654
642
-#### Enable JSON (http://www.json.org) support using "cson"
655
+#### Enable JSON (https://www.json.org) support using "cson"
643656
#
644657
# FOSSIL_ENABLE_JSON = 1
645658
646659
#### Enable HTTPS support via OpenSSL (links to libssl and libcrypto)
647660
#
648661
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -217,10 +217,12 @@
217 default.css
218 style.*.css
219 ../skins/*/*.txt
220 sounds/*.wav
221 alerts/*.wav
 
 
222 }
223
224 # Options used to compile the included SQLite library.
225 #
226 set SQLITE_OPTIONS {
@@ -559,10 +561,21 @@
559 $(XTCC) $(PIKCHR_OPTIONS) -c $(SRCDIR_extsrc)/pikchr.c -o $@
560
561 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR_extsrc)/cson_amalgamation.c
562 $(XTCC) -c $(SRCDIR_extsrc)/cson_amalgamation.c -o $@
563
 
 
 
 
 
 
 
 
 
 
 
564 #
565 # The list of all the targets that do not correspond to real files. This stops
566 # 'make' from getting confused when someone makes an error in a rule.
567 #
568
@@ -637,11 +650,11 @@
637
638 #### Enable compiling with debug symbols (much larger binary)
639 #
640 # FOSSIL_ENABLE_SYMBOLS = 1
641
642 #### Enable JSON (http://www.json.org) support using "cson"
643 #
644 # FOSSIL_ENABLE_JSON = 1
645
646 #### Enable HTTPS support via OpenSSL (links to libssl and libcrypto)
647 #
648
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -217,10 +217,12 @@
217 default.css
218 style.*.css
219 ../skins/*/*.txt
220 sounds/*.wav
221 alerts/*.wav
222 ../extsrc/pikchr.wasm
223 ../extsrc/pikchr*.js
224 }
225
226 # Options used to compile the included SQLite library.
227 #
228 set SQLITE_OPTIONS {
@@ -559,10 +561,21 @@
561 $(XTCC) $(PIKCHR_OPTIONS) -c $(SRCDIR_extsrc)/pikchr.c -o $@
562
563 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR_extsrc)/cson_amalgamation.c
564 $(XTCC) -c $(SRCDIR_extsrc)/cson_amalgamation.c -o $@
565
566 $(SRCDIR_extsrc)/pikchr.js: $(SRCDIR_extsrc)/pikchr.c
567 $(EMCC_WRAPPER) -o $@ $(EMCC_OPT) --no-entry \
568 -sEXPORTED_RUNTIME_METHODS=cwrap,setValue,getValue,stackSave,stackRestore \
569 -sEXPORTED_FUNCTIONS=_pikchr $(SRCDIR_extsrc)/pikchr.c \
570 -sENVIRONMENT=web \
571 -sMODULARIZE \
572 -sEXPORT_NAME=initPikchrModule \
573 --minify 0
574 @chmod -x $(SRCDIR_extsrc)/pikchr.wasm
575 wasm: $(SRCDIR_extsrc)/pikchr.js
576
577 #
578 # The list of all the targets that do not correspond to real files. This stops
579 # 'make' from getting confused when someone makes an error in a rule.
580 #
581
@@ -637,11 +650,11 @@
650
651 #### Enable compiling with debug symbols (much larger binary)
652 #
653 # FOSSIL_ENABLE_SYMBOLS = 1
654
655 #### Enable JSON (https://www.json.org) support using "cson"
656 #
657 # FOSSIL_ENABLE_JSON = 1
658
659 #### Enable HTTPS support via OpenSSL (links to libssl and libcrypto)
660 #
661
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -54,11 +54,11 @@
5454
5555
#### Enable compiling with debug symbols (much larger binary)
5656
#
5757
# FOSSIL_ENABLE_SYMBOLS = 1
5858
59
-#### Enable JSON (http://www.json.org) support using "cson"
59
+#### Enable JSON (https://www.json.org) support using "cson"
6060
#
6161
# FOSSIL_ENABLE_JSON = 1
6262
6363
#### Enable HTTPS support via OpenSSL (links to libssl and libcrypto)
6464
#
@@ -549,10 +549,13 @@
549549
$(SRCDIR)/xfer.c \
550550
$(SRCDIR)/xfersetup.c \
551551
$(SRCDIR)/zip.c
552552
553553
EXTRA_FILES = \
554
+ $(SRCDIR)/../extsrc/pikchr-worker.js \
555
+ $(SRCDIR)/../extsrc/pikchr.js \
556
+ $(SRCDIR)/../extsrc/pikchr.wasm \
554557
$(SRCDIR)/../skins/ardoise/css.txt \
555558
$(SRCDIR)/../skins/ardoise/details.txt \
556559
$(SRCDIR)/../skins/ardoise/footer.txt \
557560
$(SRCDIR)/../skins/ardoise/header.txt \
558561
$(SRCDIR)/../skins/black_and_white/css.txt \
@@ -617,10 +620,11 @@
617620
$(SRCDIR)/fossil.page.brlist.js \
618621
$(SRCDIR)/fossil.page.chat.js \
619622
$(SRCDIR)/fossil.page.fileedit.js \
620623
$(SRCDIR)/fossil.page.forumpost.js \
621624
$(SRCDIR)/fossil.page.pikchrshow.js \
625
+ $(SRCDIR)/fossil.page.pikchrshowasm.js \
622626
$(SRCDIR)/fossil.page.whistory.js \
623627
$(SRCDIR)/fossil.page.wikiedit.js \
624628
$(SRCDIR)/fossil.pikchr.js \
625629
$(SRCDIR)/fossil.popupwidget.js \
626630
$(SRCDIR)/fossil.storage.js \
@@ -652,10 +656,11 @@
652656
$(SRCDIR)/sounds/e.wav \
653657
$(SRCDIR)/sounds/f.wav \
654658
$(SRCDIR)/style.admin_log.css \
655659
$(SRCDIR)/style.chat.css \
656660
$(SRCDIR)/style.fileedit.css \
661
+ $(SRCDIR)/style.pikchrshow.css \
657662
$(SRCDIR)/style.wikiedit.css \
658663
$(SRCDIR)/tree.js \
659664
$(SRCDIR)/useredit.js \
660665
$(SRCDIR)/wiki.wiki
661666
662667
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -54,11 +54,11 @@
54
55 #### Enable compiling with debug symbols (much larger binary)
56 #
57 # FOSSIL_ENABLE_SYMBOLS = 1
58
59 #### Enable JSON (http://www.json.org) support using "cson"
60 #
61 # FOSSIL_ENABLE_JSON = 1
62
63 #### Enable HTTPS support via OpenSSL (links to libssl and libcrypto)
64 #
@@ -549,10 +549,13 @@
549 $(SRCDIR)/xfer.c \
550 $(SRCDIR)/xfersetup.c \
551 $(SRCDIR)/zip.c
552
553 EXTRA_FILES = \
 
 
 
554 $(SRCDIR)/../skins/ardoise/css.txt \
555 $(SRCDIR)/../skins/ardoise/details.txt \
556 $(SRCDIR)/../skins/ardoise/footer.txt \
557 $(SRCDIR)/../skins/ardoise/header.txt \
558 $(SRCDIR)/../skins/black_and_white/css.txt \
@@ -617,10 +620,11 @@
617 $(SRCDIR)/fossil.page.brlist.js \
618 $(SRCDIR)/fossil.page.chat.js \
619 $(SRCDIR)/fossil.page.fileedit.js \
620 $(SRCDIR)/fossil.page.forumpost.js \
621 $(SRCDIR)/fossil.page.pikchrshow.js \
 
622 $(SRCDIR)/fossil.page.whistory.js \
623 $(SRCDIR)/fossil.page.wikiedit.js \
624 $(SRCDIR)/fossil.pikchr.js \
625 $(SRCDIR)/fossil.popupwidget.js \
626 $(SRCDIR)/fossil.storage.js \
@@ -652,10 +656,11 @@
652 $(SRCDIR)/sounds/e.wav \
653 $(SRCDIR)/sounds/f.wav \
654 $(SRCDIR)/style.admin_log.css \
655 $(SRCDIR)/style.chat.css \
656 $(SRCDIR)/style.fileedit.css \
 
657 $(SRCDIR)/style.wikiedit.css \
658 $(SRCDIR)/tree.js \
659 $(SRCDIR)/useredit.js \
660 $(SRCDIR)/wiki.wiki
661
662
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -54,11 +54,11 @@
54
55 #### Enable compiling with debug symbols (much larger binary)
56 #
57 # FOSSIL_ENABLE_SYMBOLS = 1
58
59 #### Enable JSON (https://www.json.org) support using "cson"
60 #
61 # FOSSIL_ENABLE_JSON = 1
62
63 #### Enable HTTPS support via OpenSSL (links to libssl and libcrypto)
64 #
@@ -549,10 +549,13 @@
549 $(SRCDIR)/xfer.c \
550 $(SRCDIR)/xfersetup.c \
551 $(SRCDIR)/zip.c
552
553 EXTRA_FILES = \
554 $(SRCDIR)/../extsrc/pikchr-worker.js \
555 $(SRCDIR)/../extsrc/pikchr.js \
556 $(SRCDIR)/../extsrc/pikchr.wasm \
557 $(SRCDIR)/../skins/ardoise/css.txt \
558 $(SRCDIR)/../skins/ardoise/details.txt \
559 $(SRCDIR)/../skins/ardoise/footer.txt \
560 $(SRCDIR)/../skins/ardoise/header.txt \
561 $(SRCDIR)/../skins/black_and_white/css.txt \
@@ -617,10 +620,11 @@
620 $(SRCDIR)/fossil.page.brlist.js \
621 $(SRCDIR)/fossil.page.chat.js \
622 $(SRCDIR)/fossil.page.fileedit.js \
623 $(SRCDIR)/fossil.page.forumpost.js \
624 $(SRCDIR)/fossil.page.pikchrshow.js \
625 $(SRCDIR)/fossil.page.pikchrshowasm.js \
626 $(SRCDIR)/fossil.page.whistory.js \
627 $(SRCDIR)/fossil.page.wikiedit.js \
628 $(SRCDIR)/fossil.pikchr.js \
629 $(SRCDIR)/fossil.popupwidget.js \
630 $(SRCDIR)/fossil.storage.js \
@@ -652,10 +656,11 @@
656 $(SRCDIR)/sounds/e.wav \
657 $(SRCDIR)/sounds/f.wav \
658 $(SRCDIR)/style.admin_log.css \
659 $(SRCDIR)/style.chat.css \
660 $(SRCDIR)/style.fileedit.css \
661 $(SRCDIR)/style.pikchrshow.css \
662 $(SRCDIR)/style.wikiedit.css \
663 $(SRCDIR)/tree.js \
664 $(SRCDIR)/useredit.js \
665 $(SRCDIR)/wiki.wiki
666
667
+12 -2
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -505,11 +505,14 @@
505505
"$(OX)\xfer_.c" \
506506
"$(OX)\xfersetup_.c" \
507507
"$(OX)\zip_.c" \
508508
"$(SRCDIR_extsrc)\pikchr.c"
509509
510
-EXTRA_FILES = "$(SRCDIR)\..\skins\ardoise\css.txt" \
510
+EXTRA_FILES = "$(SRCDIR)\..\extsrc\pikchr-worker.js" \
511
+ "$(SRCDIR)\..\extsrc\pikchr.js" \
512
+ "$(SRCDIR)\..\extsrc\pikchr.wasm" \
513
+ "$(SRCDIR)\..\skins\ardoise\css.txt" \
511514
"$(SRCDIR)\..\skins\ardoise\details.txt" \
512515
"$(SRCDIR)\..\skins\ardoise\footer.txt" \
513516
"$(SRCDIR)\..\skins\ardoise\header.txt" \
514517
"$(SRCDIR)\..\skins\black_and_white\css.txt" \
515518
"$(SRCDIR)\..\skins\black_and_white\details.txt" \
@@ -573,10 +576,11 @@
573576
"$(SRCDIR)\fossil.page.brlist.js" \
574577
"$(SRCDIR)\fossil.page.chat.js" \
575578
"$(SRCDIR)\fossil.page.fileedit.js" \
576579
"$(SRCDIR)\fossil.page.forumpost.js" \
577580
"$(SRCDIR)\fossil.page.pikchrshow.js" \
581
+ "$(SRCDIR)\fossil.page.pikchrshowasm.js" \
578582
"$(SRCDIR)\fossil.page.whistory.js" \
579583
"$(SRCDIR)\fossil.page.wikiedit.js" \
580584
"$(SRCDIR)\fossil.pikchr.js" \
581585
"$(SRCDIR)\fossil.popupwidget.js" \
582586
"$(SRCDIR)\fossil.storage.js" \
@@ -608,10 +612,11 @@
608612
"$(SRCDIR)\sounds\e.wav" \
609613
"$(SRCDIR)\sounds\f.wav" \
610614
"$(SRCDIR)\style.admin_log.css" \
611615
"$(SRCDIR)\style.chat.css" \
612616
"$(SRCDIR)\style.fileedit.css" \
617
+ "$(SRCDIR)\style.pikchrshow.css" \
613618
"$(SRCDIR)\style.wikiedit.css" \
614619
"$(SRCDIR)\tree.js" \
615620
"$(SRCDIR)\useredit.js" \
616621
"$(SRCDIR)\wiki.wiki"
617622
@@ -1129,11 +1134,14 @@
11291134
"$(OBJDIR)\json_timeline$O" : "$(SRCDIR)\json_detail.h"
11301135
"$(OBJDIR)\json_user$O" : "$(SRCDIR)\json_detail.h"
11311136
"$(OBJDIR)\json_wiki$O" : "$(SRCDIR)\json_detail.h"
11321137
11331138
"$(OX)\builtin_data.reslist": $(EXTRA_FILES) "$(B)\win\Makefile.msc"
1134
- echo "$(SRCDIR)\../skins/ardoise/css.txt" > $@
1139
+ echo "$(SRCDIR)\../extsrc/pikchr-worker.js" > $@
1140
+ echo "$(SRCDIR)\../extsrc/pikchr.js" >> $@
1141
+ echo "$(SRCDIR)\../extsrc/pikchr.wasm" >> $@
1142
+ echo "$(SRCDIR)\../skins/ardoise/css.txt" >> $@
11351143
echo "$(SRCDIR)\../skins/ardoise/details.txt" >> $@
11361144
echo "$(SRCDIR)\../skins/ardoise/footer.txt" >> $@
11371145
echo "$(SRCDIR)\../skins/ardoise/header.txt" >> $@
11381146
echo "$(SRCDIR)\../skins/black_and_white/css.txt" >> $@
11391147
echo "$(SRCDIR)\../skins/black_and_white/details.txt" >> $@
@@ -1197,10 +1205,11 @@
11971205
echo "$(SRCDIR)\fossil.page.brlist.js" >> $@
11981206
echo "$(SRCDIR)\fossil.page.chat.js" >> $@
11991207
echo "$(SRCDIR)\fossil.page.fileedit.js" >> $@
12001208
echo "$(SRCDIR)\fossil.page.forumpost.js" >> $@
12011209
echo "$(SRCDIR)\fossil.page.pikchrshow.js" >> $@
1210
+ echo "$(SRCDIR)\fossil.page.pikchrshowasm.js" >> $@
12021211
echo "$(SRCDIR)\fossil.page.whistory.js" >> $@
12031212
echo "$(SRCDIR)\fossil.page.wikiedit.js" >> $@
12041213
echo "$(SRCDIR)\fossil.pikchr.js" >> $@
12051214
echo "$(SRCDIR)\fossil.popupwidget.js" >> $@
12061215
echo "$(SRCDIR)\fossil.storage.js" >> $@
@@ -1232,10 +1241,11 @@
12321241
echo "$(SRCDIR)\sounds/e.wav" >> $@
12331242
echo "$(SRCDIR)\sounds/f.wav" >> $@
12341243
echo "$(SRCDIR)\style.admin_log.css" >> $@
12351244
echo "$(SRCDIR)\style.chat.css" >> $@
12361245
echo "$(SRCDIR)\style.fileedit.css" >> $@
1246
+ echo "$(SRCDIR)\style.pikchrshow.css" >> $@
12371247
echo "$(SRCDIR)\style.wikiedit.css" >> $@
12381248
echo "$(SRCDIR)\tree.js" >> $@
12391249
echo "$(SRCDIR)\useredit.js" >> $@
12401250
echo "$(SRCDIR)\wiki.wiki" >> $@
12411251
12421252
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -505,11 +505,14 @@
505 "$(OX)\xfer_.c" \
506 "$(OX)\xfersetup_.c" \
507 "$(OX)\zip_.c" \
508 "$(SRCDIR_extsrc)\pikchr.c"
509
510 EXTRA_FILES = "$(SRCDIR)\..\skins\ardoise\css.txt" \
 
 
 
511 "$(SRCDIR)\..\skins\ardoise\details.txt" \
512 "$(SRCDIR)\..\skins\ardoise\footer.txt" \
513 "$(SRCDIR)\..\skins\ardoise\header.txt" \
514 "$(SRCDIR)\..\skins\black_and_white\css.txt" \
515 "$(SRCDIR)\..\skins\black_and_white\details.txt" \
@@ -573,10 +576,11 @@
573 "$(SRCDIR)\fossil.page.brlist.js" \
574 "$(SRCDIR)\fossil.page.chat.js" \
575 "$(SRCDIR)\fossil.page.fileedit.js" \
576 "$(SRCDIR)\fossil.page.forumpost.js" \
577 "$(SRCDIR)\fossil.page.pikchrshow.js" \
 
578 "$(SRCDIR)\fossil.page.whistory.js" \
579 "$(SRCDIR)\fossil.page.wikiedit.js" \
580 "$(SRCDIR)\fossil.pikchr.js" \
581 "$(SRCDIR)\fossil.popupwidget.js" \
582 "$(SRCDIR)\fossil.storage.js" \
@@ -608,10 +612,11 @@
608 "$(SRCDIR)\sounds\e.wav" \
609 "$(SRCDIR)\sounds\f.wav" \
610 "$(SRCDIR)\style.admin_log.css" \
611 "$(SRCDIR)\style.chat.css" \
612 "$(SRCDIR)\style.fileedit.css" \
 
613 "$(SRCDIR)\style.wikiedit.css" \
614 "$(SRCDIR)\tree.js" \
615 "$(SRCDIR)\useredit.js" \
616 "$(SRCDIR)\wiki.wiki"
617
@@ -1129,11 +1134,14 @@
1129 "$(OBJDIR)\json_timeline$O" : "$(SRCDIR)\json_detail.h"
1130 "$(OBJDIR)\json_user$O" : "$(SRCDIR)\json_detail.h"
1131 "$(OBJDIR)\json_wiki$O" : "$(SRCDIR)\json_detail.h"
1132
1133 "$(OX)\builtin_data.reslist": $(EXTRA_FILES) "$(B)\win\Makefile.msc"
1134 echo "$(SRCDIR)\../skins/ardoise/css.txt" > $@
 
 
 
1135 echo "$(SRCDIR)\../skins/ardoise/details.txt" >> $@
1136 echo "$(SRCDIR)\../skins/ardoise/footer.txt" >> $@
1137 echo "$(SRCDIR)\../skins/ardoise/header.txt" >> $@
1138 echo "$(SRCDIR)\../skins/black_and_white/css.txt" >> $@
1139 echo "$(SRCDIR)\../skins/black_and_white/details.txt" >> $@
@@ -1197,10 +1205,11 @@
1197 echo "$(SRCDIR)\fossil.page.brlist.js" >> $@
1198 echo "$(SRCDIR)\fossil.page.chat.js" >> $@
1199 echo "$(SRCDIR)\fossil.page.fileedit.js" >> $@
1200 echo "$(SRCDIR)\fossil.page.forumpost.js" >> $@
1201 echo "$(SRCDIR)\fossil.page.pikchrshow.js" >> $@
 
1202 echo "$(SRCDIR)\fossil.page.whistory.js" >> $@
1203 echo "$(SRCDIR)\fossil.page.wikiedit.js" >> $@
1204 echo "$(SRCDIR)\fossil.pikchr.js" >> $@
1205 echo "$(SRCDIR)\fossil.popupwidget.js" >> $@
1206 echo "$(SRCDIR)\fossil.storage.js" >> $@
@@ -1232,10 +1241,11 @@
1232 echo "$(SRCDIR)\sounds/e.wav" >> $@
1233 echo "$(SRCDIR)\sounds/f.wav" >> $@
1234 echo "$(SRCDIR)\style.admin_log.css" >> $@
1235 echo "$(SRCDIR)\style.chat.css" >> $@
1236 echo "$(SRCDIR)\style.fileedit.css" >> $@
 
1237 echo "$(SRCDIR)\style.wikiedit.css" >> $@
1238 echo "$(SRCDIR)\tree.js" >> $@
1239 echo "$(SRCDIR)\useredit.js" >> $@
1240 echo "$(SRCDIR)\wiki.wiki" >> $@
1241
1242
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -505,11 +505,14 @@
505 "$(OX)\xfer_.c" \
506 "$(OX)\xfersetup_.c" \
507 "$(OX)\zip_.c" \
508 "$(SRCDIR_extsrc)\pikchr.c"
509
510 EXTRA_FILES = "$(SRCDIR)\..\extsrc\pikchr-worker.js" \
511 "$(SRCDIR)\..\extsrc\pikchr.js" \
512 "$(SRCDIR)\..\extsrc\pikchr.wasm" \
513 "$(SRCDIR)\..\skins\ardoise\css.txt" \
514 "$(SRCDIR)\..\skins\ardoise\details.txt" \
515 "$(SRCDIR)\..\skins\ardoise\footer.txt" \
516 "$(SRCDIR)\..\skins\ardoise\header.txt" \
517 "$(SRCDIR)\..\skins\black_and_white\css.txt" \
518 "$(SRCDIR)\..\skins\black_and_white\details.txt" \
@@ -573,10 +576,11 @@
576 "$(SRCDIR)\fossil.page.brlist.js" \
577 "$(SRCDIR)\fossil.page.chat.js" \
578 "$(SRCDIR)\fossil.page.fileedit.js" \
579 "$(SRCDIR)\fossil.page.forumpost.js" \
580 "$(SRCDIR)\fossil.page.pikchrshow.js" \
581 "$(SRCDIR)\fossil.page.pikchrshowasm.js" \
582 "$(SRCDIR)\fossil.page.whistory.js" \
583 "$(SRCDIR)\fossil.page.wikiedit.js" \
584 "$(SRCDIR)\fossil.pikchr.js" \
585 "$(SRCDIR)\fossil.popupwidget.js" \
586 "$(SRCDIR)\fossil.storage.js" \
@@ -608,10 +612,11 @@
612 "$(SRCDIR)\sounds\e.wav" \
613 "$(SRCDIR)\sounds\f.wav" \
614 "$(SRCDIR)\style.admin_log.css" \
615 "$(SRCDIR)\style.chat.css" \
616 "$(SRCDIR)\style.fileedit.css" \
617 "$(SRCDIR)\style.pikchrshow.css" \
618 "$(SRCDIR)\style.wikiedit.css" \
619 "$(SRCDIR)\tree.js" \
620 "$(SRCDIR)\useredit.js" \
621 "$(SRCDIR)\wiki.wiki"
622
@@ -1129,11 +1134,14 @@
1134 "$(OBJDIR)\json_timeline$O" : "$(SRCDIR)\json_detail.h"
1135 "$(OBJDIR)\json_user$O" : "$(SRCDIR)\json_detail.h"
1136 "$(OBJDIR)\json_wiki$O" : "$(SRCDIR)\json_detail.h"
1137
1138 "$(OX)\builtin_data.reslist": $(EXTRA_FILES) "$(B)\win\Makefile.msc"
1139 echo "$(SRCDIR)\../extsrc/pikchr-worker.js" > $@
1140 echo "$(SRCDIR)\../extsrc/pikchr.js" >> $@
1141 echo "$(SRCDIR)\../extsrc/pikchr.wasm" >> $@
1142 echo "$(SRCDIR)\../skins/ardoise/css.txt" >> $@
1143 echo "$(SRCDIR)\../skins/ardoise/details.txt" >> $@
1144 echo "$(SRCDIR)\../skins/ardoise/footer.txt" >> $@
1145 echo "$(SRCDIR)\../skins/ardoise/header.txt" >> $@
1146 echo "$(SRCDIR)\../skins/black_and_white/css.txt" >> $@
1147 echo "$(SRCDIR)\../skins/black_and_white/details.txt" >> $@
@@ -1197,10 +1205,11 @@
1205 echo "$(SRCDIR)\fossil.page.brlist.js" >> $@
1206 echo "$(SRCDIR)\fossil.page.chat.js" >> $@
1207 echo "$(SRCDIR)\fossil.page.fileedit.js" >> $@
1208 echo "$(SRCDIR)\fossil.page.forumpost.js" >> $@
1209 echo "$(SRCDIR)\fossil.page.pikchrshow.js" >> $@
1210 echo "$(SRCDIR)\fossil.page.pikchrshowasm.js" >> $@
1211 echo "$(SRCDIR)\fossil.page.whistory.js" >> $@
1212 echo "$(SRCDIR)\fossil.page.wikiedit.js" >> $@
1213 echo "$(SRCDIR)\fossil.pikchr.js" >> $@
1214 echo "$(SRCDIR)\fossil.popupwidget.js" >> $@
1215 echo "$(SRCDIR)\fossil.storage.js" >> $@
@@ -1232,10 +1241,11 @@
1241 echo "$(SRCDIR)\sounds/e.wav" >> $@
1242 echo "$(SRCDIR)\sounds/f.wav" >> $@
1243 echo "$(SRCDIR)\style.admin_log.css" >> $@
1244 echo "$(SRCDIR)\style.chat.css" >> $@
1245 echo "$(SRCDIR)\style.fileedit.css" >> $@
1246 echo "$(SRCDIR)\style.pikchrshow.css" >> $@
1247 echo "$(SRCDIR)\style.wikiedit.css" >> $@
1248 echo "$(SRCDIR)\tree.js" >> $@
1249 echo "$(SRCDIR)\useredit.js" >> $@
1250 echo "$(SRCDIR)\wiki.wiki" >> $@
1251
1252
+148 -3
--- www/build.wiki
+++ www/build.wiki
@@ -332,11 +332,11 @@
332332
333333
<h2>6.0 Building on/for Android</h2>
334334
335335
<h3>6.1 Cross-compiling from Linux</h3>
336336
337
-The following instructions for building Fossil for Android,
337
+The following instructions for building Fossil for Android via Linux,
338338
without requiring a rooted OS, are adapted from
339339
[https://fossil-scm.org/forum/forumpost/e0e9de4a7e | forumpost/e0e9de4a7e].
340340
341341
On the development machine, from the fossil source tree:
342342
@@ -381,13 +381,12 @@
381381
Some information about these (reportedly harmless) warnings can
382382
be found
383383
[https://stackoverflow.com/a/41900551 | on this StackOverflow post].
384384
385385
386
-
387386
<a id='fuzzer'></a>
388
-<h2>Building for Fuzz Testing</h2>
387
+<h2>7.0 Building for Fuzz Testing</h2>
389388
390389
This feature is primarily intended for fossil's developers and may
391390
change at any time. It is only known to work on Linux systems and has
392391
been seen to work on x86/64 and ARM.
393392
@@ -460,5 +459,151 @@
460459
e.g. <tt>-jobs=4</tt> to start four fuzzer jobs in parallel, but doing
461460
so may cause the fuzzer to <em>strip the --fuzztype flag</em>, leading
462461
to it testing the wrong thing. When passing on fuzzer-specific flags
463462
along with <tt>--fuzztype</tt>, be sure to check your system's process
464463
list to ensure that your <tt>--fuzztype</tt> flag is there.
464
+
465
+
466
+<a id='wasm'></a>
467
+<h2>8.0 Building WebAssembly Components</h2>
468
+
469
+As of version 2.19, fossil uses one component built as
470
+[https://developer.mozilla.org/en-US/docs/WebAssembly | WebAssembly]
471
+a.k.a. WASM. Because compiling WASM code requires non-trivial
472
+client-side tooling, the repository includes compiled copies of these
473
+pieces. Most Fossil hackers should never need to concern themselves
474
+with the WASM parts, but this section describes how to for those who
475
+want or need to do so.
476
+
477
+<strong>The bits described in this section are necessary when updating
478
+<tt>extsrc/pikchr.c</tt></strong> from the upstream source, or the
479
+fossil binary will use a different version of pikchr than
480
+[/pikchrshow] does (as the latter runs the WASM build of pikchr).
481
+
482
+These instructions have only ever been tested on Linux systems. They
483
+"should" work on any Unix-like system supported by Emscripten. The
484
+fossil makefiles for Windows builds <em>do not</em> include any of the
485
+WASM-related components (patches to add that would be welcomed, of
486
+course).
487
+
488
+The first step is to configure the tree with support for
489
+[https://emscripten.org/|Emscripten]. This requires that the system
490
+has the Emscripten SDK (a.k.a. emsdk) installed, as documented at:
491
+
492
+[https://emscripten.org/docs/getting_started/downloads.html]
493
+
494
+For instructions on keeping the SDK up to date, see:
495
+
496
+[https://emscripten.org/docs/tools_reference/emsdk.html]
497
+
498
+ Sidebar: getting Emscripten up and running is trivial and
499
+ painless, at least on Linux systems, but the installer downloads
500
+ many hundreds of megabytes of tools and dependencies, all of which
501
+ will be installed under the single SDK directory (as opposed to
502
+ being installed at the system level). It does, however, require
503
+ that python3 be installed at the system level and it can
504
+ optionally make use of a system-level cmake for certain tasks
505
+ unrelated to how fossil uses the SDK.
506
+
507
+After installing the SDK, configure the fossil tree with emsdk
508
+support:
509
+
510
+<pre><code>$ ./configure --with-emsdk=/path/to/emsdk ...other options...
511
+</code></pre>
512
+
513
+If the <tt>--with-emsdk</tt> flag is not provided, the configure
514
+script will check for the environment variable <tt>EMSDK</tt>, which
515
+is one of the standard variables the SDK environment uses. If that
516
+variable is found, its value will implicitly be used in place of the
517
+missing <tt>--with-emsdk</tt> flag. Thus, if the <tt>emsdk_env.sh</tt>
518
+script is sourced into the shell before running the configure script,
519
+the SDK will be detected even without the config flag.
520
+
521
+The configure script installs some makefile variables which tell the
522
+build where to find the SDK and it generates a script named
523
+<tt>tools/emcc.sh</tt> (from the template file
524
+<tt>[/file/tools/emcc.sh.in|/tools/emcc.sh.in]</tt>), which is a
525
+wrapper around the Emscripten C compiler (<tt>emcc</tt>). The wrapper
526
+script uses the configure-time state to attempt to set up the various
527
+environment variables which are required by <tt>emcc</tt> and will
528
+fail if it cannot do so. Once it's set up the environment, it passes
529
+on all of its arguments to <tt>emcc</tt>.
530
+
531
+The WASM-related build parts are set up such that none of them should
532
+ever trigger implicity (e.g. via dependencies resolution) in a normal
533
+build cycle. They are instead explicitly built as described below.
534
+
535
+From the top of the source tree, all WASM-related components can be
536
+built with:
537
+
538
+<pre><code>$ make wasm</code></pre>
539
+
540
+As of this writing, those parts include:
541
+
542
+ * <tt>extsrc/pikchr.wasm</tt> is a WASM-compiled form of
543
+ <tt>extsrc/pikchr.c</tt>.
544
+ * <tt>extsrc/pikchr.js</tt> is JS/WASM glue code generated by Emscripten
545
+ to give JS code access to the API exported by the WASM file.
546
+
547
+ Sidebar: The file
548
+ <tt>[/file/extsrc/pikcher-worker.js|extsrc/pikcher-worker.js]</tt>
549
+ is hand-coded and intended to be loaded as a "Worker" in
550
+ JavaScript. That file loads the main module and provides an
551
+ interface via which a main JavaScript thread can communicate with
552
+ pikchr running in a Worker thread. The file
553
+ <tt>[/file/src/fossil.page.pikchrshowasm.js|src/fossil.page.pikchrshowasm.js]</tt>
554
+ implements the [/pikchrshow] app and demonstrates how
555
+ <tt>pikchr-worker.js</tt> is used.
556
+
557
+When a new version of <tt>extsrc/pikchr.c</tt> is installed, the
558
+files <tt>pikchr.{js,wasm}</tt> will need to be recompiled to account
559
+for that. Running <tt>make wasm</tt> will, if the build is set up for
560
+the emsdk, recompile those:
561
+
562
+<pre><code>$ make wasm
563
+./tools/emcc.sh -o extsrc/pikchr.js ...
564
+$ ls -la extsrc/pikchr.{js,wasm}
565
+-rw-rw-r-- 1 stephan stephan 17263 Jun 8 03:59 extsrc/pikchr.js
566
+-rw-rw-r-- 1 stephan stephan 97578 Jun 8 03:59 extsrc/pikchr.wasm
567
+</code></pre>
568
+
569
+<blockquote>Sidebar: if that fails with a message along the lines of:
570
+
571
+<pre><code>setting `EXPORTED_RUNTIME_METHODS` expects `<class 'list'>` but got `<class 'str'>`</code></pre>
572
+
573
+then the emcc being invoked is too old: emcc changed the format of
574
+list-type arguments at some point. The required minimum version is
575
+unknown, but any SDK version from May 2022 or later "should" (as of
576
+this writing) suffice. Any older version may or may not work.
577
+</blockquote>
578
+
579
+After that succeeds, we need to run the normal build so that those
580
+generated files can be compiled in to the fossil binary, accessible
581
+via the [/help?cmd=/builtin|/builtin page]:
582
+
583
+<pre><code>$ make</code></pre>
584
+
585
+Before checking in those newly-built files, they need to be tested by
586
+running the [/pikchrshow] page. If that page loads, the compilation
587
+process fundamentally worked (a load failure will be made obvious to
588
+the viewer). If it fails to load then the browser's dev tools console
589
+likely provides at least a small hint (and <em>sometimes</em> a useful
590
+hint) about the nature of the problem. Don't check those files in
591
+until [/pikchrshow] runs, though!
592
+
593
+Should pikchr's C interface ever change, <tt>pikchr-worker.js</tt>
594
+will need to be updated to accommodate it, but such modification is
595
+typically trivial.
596
+
597
+<h3>8.1 Solutions other than Emscripten?</h3>
598
+
599
+Emscripten is not the only option for building C as WASM, but it
600
+provides a complete toolchain which eliminates many other steps which
601
+must otherwise be accounted for on a per-project basis. Despite its
602
+convenience, it behooves us to explore other build options for the
603
+sake of portability and avoiding what amounts to vendor lock-in.
604
+
605
+For later refererence, here are articles specifically covering
606
+building WASM projects without using Emscripten:
607
+
608
+ * [https://surma.dev/things/c-to-webassembly/]
609
+ * [https://schellcode.github.io/webassembly-without-emscripten]
465610
--- www/build.wiki
+++ www/build.wiki
@@ -332,11 +332,11 @@
332
333 <h2>6.0 Building on/for Android</h2>
334
335 <h3>6.1 Cross-compiling from Linux</h3>
336
337 The following instructions for building Fossil for Android,
338 without requiring a rooted OS, are adapted from
339 [https://fossil-scm.org/forum/forumpost/e0e9de4a7e | forumpost/e0e9de4a7e].
340
341 On the development machine, from the fossil source tree:
342
@@ -381,13 +381,12 @@
381 Some information about these (reportedly harmless) warnings can
382 be found
383 [https://stackoverflow.com/a/41900551 | on this StackOverflow post].
384
385
386
387 <a id='fuzzer'></a>
388 <h2>Building for Fuzz Testing</h2>
389
390 This feature is primarily intended for fossil's developers and may
391 change at any time. It is only known to work on Linux systems and has
392 been seen to work on x86/64 and ARM.
393
@@ -460,5 +459,151 @@
460 e.g. <tt>-jobs=4</tt> to start four fuzzer jobs in parallel, but doing
461 so may cause the fuzzer to <em>strip the --fuzztype flag</em>, leading
462 to it testing the wrong thing. When passing on fuzzer-specific flags
463 along with <tt>--fuzztype</tt>, be sure to check your system's process
464 list to ensure that your <tt>--fuzztype</tt> flag is there.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
465
--- www/build.wiki
+++ www/build.wiki
@@ -332,11 +332,11 @@
332
333 <h2>6.0 Building on/for Android</h2>
334
335 <h3>6.1 Cross-compiling from Linux</h3>
336
337 The following instructions for building Fossil for Android via Linux,
338 without requiring a rooted OS, are adapted from
339 [https://fossil-scm.org/forum/forumpost/e0e9de4a7e | forumpost/e0e9de4a7e].
340
341 On the development machine, from the fossil source tree:
342
@@ -381,13 +381,12 @@
381 Some information about these (reportedly harmless) warnings can
382 be found
383 [https://stackoverflow.com/a/41900551 | on this StackOverflow post].
384
385
 
386 <a id='fuzzer'></a>
387 <h2>7.0 Building for Fuzz Testing</h2>
388
389 This feature is primarily intended for fossil's developers and may
390 change at any time. It is only known to work on Linux systems and has
391 been seen to work on x86/64 and ARM.
392
@@ -460,5 +459,151 @@
459 e.g. <tt>-jobs=4</tt> to start four fuzzer jobs in parallel, but doing
460 so may cause the fuzzer to <em>strip the --fuzztype flag</em>, leading
461 to it testing the wrong thing. When passing on fuzzer-specific flags
462 along with <tt>--fuzztype</tt>, be sure to check your system's process
463 list to ensure that your <tt>--fuzztype</tt> flag is there.
464
465
466 <a id='wasm'></a>
467 <h2>8.0 Building WebAssembly Components</h2>
468
469 As of version 2.19, fossil uses one component built as
470 [https://developer.mozilla.org/en-US/docs/WebAssembly | WebAssembly]
471 a.k.a. WASM. Because compiling WASM code requires non-trivial
472 client-side tooling, the repository includes compiled copies of these
473 pieces. Most Fossil hackers should never need to concern themselves
474 with the WASM parts, but this section describes how to for those who
475 want or need to do so.
476
477 <strong>The bits described in this section are necessary when updating
478 <tt>extsrc/pikchr.c</tt></strong> from the upstream source, or the
479 fossil binary will use a different version of pikchr than
480 [/pikchrshow] does (as the latter runs the WASM build of pikchr).
481
482 These instructions have only ever been tested on Linux systems. They
483 "should" work on any Unix-like system supported by Emscripten. The
484 fossil makefiles for Windows builds <em>do not</em> include any of the
485 WASM-related components (patches to add that would be welcomed, of
486 course).
487
488 The first step is to configure the tree with support for
489 [https://emscripten.org/|Emscripten]. This requires that the system
490 has the Emscripten SDK (a.k.a. emsdk) installed, as documented at:
491
492 [https://emscripten.org/docs/getting_started/downloads.html]
493
494 For instructions on keeping the SDK up to date, see:
495
496 [https://emscripten.org/docs/tools_reference/emsdk.html]
497
498 Sidebar: getting Emscripten up and running is trivial and
499 painless, at least on Linux systems, but the installer downloads
500 many hundreds of megabytes of tools and dependencies, all of which
501 will be installed under the single SDK directory (as opposed to
502 being installed at the system level). It does, however, require
503 that python3 be installed at the system level and it can
504 optionally make use of a system-level cmake for certain tasks
505 unrelated to how fossil uses the SDK.
506
507 After installing the SDK, configure the fossil tree with emsdk
508 support:
509
510 <pre><code>$ ./configure --with-emsdk=/path/to/emsdk ...other options...
511 </code></pre>
512
513 If the <tt>--with-emsdk</tt> flag is not provided, the configure
514 script will check for the environment variable <tt>EMSDK</tt>, which
515 is one of the standard variables the SDK environment uses. If that
516 variable is found, its value will implicitly be used in place of the
517 missing <tt>--with-emsdk</tt> flag. Thus, if the <tt>emsdk_env.sh</tt>
518 script is sourced into the shell before running the configure script,
519 the SDK will be detected even without the config flag.
520
521 The configure script installs some makefile variables which tell the
522 build where to find the SDK and it generates a script named
523 <tt>tools/emcc.sh</tt> (from the template file
524 <tt>[/file/tools/emcc.sh.in|/tools/emcc.sh.in]</tt>), which is a
525 wrapper around the Emscripten C compiler (<tt>emcc</tt>). The wrapper
526 script uses the configure-time state to attempt to set up the various
527 environment variables which are required by <tt>emcc</tt> and will
528 fail if it cannot do so. Once it's set up the environment, it passes
529 on all of its arguments to <tt>emcc</tt>.
530
531 The WASM-related build parts are set up such that none of them should
532 ever trigger implicity (e.g. via dependencies resolution) in a normal
533 build cycle. They are instead explicitly built as described below.
534
535 From the top of the source tree, all WASM-related components can be
536 built with:
537
538 <pre><code>$ make wasm</code></pre>
539
540 As of this writing, those parts include:
541
542 * <tt>extsrc/pikchr.wasm</tt> is a WASM-compiled form of
543 <tt>extsrc/pikchr.c</tt>.
544 * <tt>extsrc/pikchr.js</tt> is JS/WASM glue code generated by Emscripten
545 to give JS code access to the API exported by the WASM file.
546
547 Sidebar: The file
548 <tt>[/file/extsrc/pikcher-worker.js|extsrc/pikcher-worker.js]</tt>
549 is hand-coded and intended to be loaded as a "Worker" in
550 JavaScript. That file loads the main module and provides an
551 interface via which a main JavaScript thread can communicate with
552 pikchr running in a Worker thread. The file
553 <tt>[/file/src/fossil.page.pikchrshowasm.js|src/fossil.page.pikchrshowasm.js]</tt>
554 implements the [/pikchrshow] app and demonstrates how
555 <tt>pikchr-worker.js</tt> is used.
556
557 When a new version of <tt>extsrc/pikchr.c</tt> is installed, the
558 files <tt>pikchr.{js,wasm}</tt> will need to be recompiled to account
559 for that. Running <tt>make wasm</tt> will, if the build is set up for
560 the emsdk, recompile those:
561
562 <pre><code>$ make wasm
563 ./tools/emcc.sh -o extsrc/pikchr.js ...
564 $ ls -la extsrc/pikchr.{js,wasm}
565 -rw-rw-r-- 1 stephan stephan 17263 Jun 8 03:59 extsrc/pikchr.js
566 -rw-rw-r-- 1 stephan stephan 97578 Jun 8 03:59 extsrc/pikchr.wasm
567 </code></pre>
568
569 <blockquote>Sidebar: if that fails with a message along the lines of:
570
571 <pre><code>setting `EXPORTED_RUNTIME_METHODS` expects `<class 'list'>` but got `<class 'str'>`</code></pre>
572
573 then the emcc being invoked is too old: emcc changed the format of
574 list-type arguments at some point. The required minimum version is
575 unknown, but any SDK version from May 2022 or later "should" (as of
576 this writing) suffice. Any older version may or may not work.
577 </blockquote>
578
579 After that succeeds, we need to run the normal build so that those
580 generated files can be compiled in to the fossil binary, accessible
581 via the [/help?cmd=/builtin|/builtin page]:
582
583 <pre><code>$ make</code></pre>
584
585 Before checking in those newly-built files, they need to be tested by
586 running the [/pikchrshow] page. If that page loads, the compilation
587 process fundamentally worked (a load failure will be made obvious to
588 the viewer). If it fails to load then the browser's dev tools console
589 likely provides at least a small hint (and <em>sometimes</em> a useful
590 hint) about the nature of the problem. Don't check those files in
591 until [/pikchrshow] runs, though!
592
593 Should pikchr's C interface ever change, <tt>pikchr-worker.js</tt>
594 will need to be updated to accommodate it, but such modification is
595 typically trivial.
596
597 <h3>8.1 Solutions other than Emscripten?</h3>
598
599 Emscripten is not the only option for building C as WASM, but it
600 provides a complete toolchain which eliminates many other steps which
601 must otherwise be accounted for on a per-project basis. Despite its
602 convenience, it behooves us to explore other build options for the
603 sake of portability and avoiding what amounts to vendor lock-in.
604
605 For later refererence, here are articles specifically covering
606 building WASM projects without using Emscripten:
607
608 * [https://surma.dev/things/c-to-webassembly/]
609 * [https://schellcode.github.io/webassembly-without-emscripten]
610
--- www/caps/index.md
+++ www/caps/index.md
@@ -193,16 +193,16 @@
193193
The repo clone is completely under your user’s power at that point,
194194
affected only by OS file permissions and such. If you need to prevent
195195
that, you want to deny **Clone** capability instead.
196196
197197
Withholding the **Read** capability has a different effect: it
198
-prevents a web client from viewing [embedded
199
-documentation][edoc], using [the file
200
-browser](/help?name=/dir), and pulling file content via the
201
-[`/artifact`](/help?name=/artifact), [`/file`](/help?name=/file), and
202
-[`/raw`](/help?name=/raw) URLs.
203
-It is is common to withhold **Read** capability from low-status visitors
198
+prevents a web client from viewing [embedded documentation][edoc],
199
+using [the file browser](/help?name=/dir),
200
+exploring the [history](/help?name=/timeline) of check-ins,
201
+and pulling file content via the [`/artifact`](/help?name=/artifact),
202
+[`/file`](/help?name=/file), and [`/raw`](/help?name=/raw) URLs.
203
+It is common to withhold **Read** capability from low-status visitors
204204
on private or semi-private repos to prevent them from pulling individual
205205
elements of the repo over the web one at a time, as someone may do when
206206
denied the bulk **Clone** capability.
207207
208208
[edoc]: ../embeddeddoc.wiki
209209
--- www/caps/index.md
+++ www/caps/index.md
@@ -193,16 +193,16 @@
193 The repo clone is completely under your user’s power at that point,
194 affected only by OS file permissions and such. If you need to prevent
195 that, you want to deny **Clone** capability instead.
196
197 Withholding the **Read** capability has a different effect: it
198 prevents a web client from viewing [embedded
199 documentation][edoc], using [the file
200 browser](/help?name=/dir), and pulling file content via the
201 [`/artifact`](/help?name=/artifact), [`/file`](/help?name=/file), and
202 [`/raw`](/help?name=/raw) URLs.
203 It is is common to withhold **Read** capability from low-status visitors
204 on private or semi-private repos to prevent them from pulling individual
205 elements of the repo over the web one at a time, as someone may do when
206 denied the bulk **Clone** capability.
207
208 [edoc]: ../embeddeddoc.wiki
209
--- www/caps/index.md
+++ www/caps/index.md
@@ -193,16 +193,16 @@
193 The repo clone is completely under your user’s power at that point,
194 affected only by OS file permissions and such. If you need to prevent
195 that, you want to deny **Clone** capability instead.
196
197 Withholding the **Read** capability has a different effect: it
198 prevents a web client from viewing [embedded documentation][edoc],
199 using [the file browser](/help?name=/dir),
200 exploring the [history](/help?name=/timeline) of check-ins,
201 and pulling file content via the [`/artifact`](/help?name=/artifact),
202 [`/file`](/help?name=/file), and [`/raw`](/help?name=/raw) URLs.
203 It is common to withhold **Read** capability from low-status visitors
204 on private or semi-private repos to prevent them from pulling individual
205 elements of the repo over the web one at a time, as someone may do when
206 denied the bulk **Clone** capability.
207
208 [edoc]: ../embeddeddoc.wiki
209
--- www/caps/ref.html
+++ www/caps/ref.html
@@ -119,12 +119,13 @@
119119
<tr id="g">
120120
<th>g</th>
121121
<th>Clone</th>
122122
<td>
123123
Clone the repository. Note that this is distinct from <a
124
- href="#o">check-out capability, <b>o</b></a>. Mnemonic:
125
- <b>g</b>et.
124
+ href="#o">check-out capability, <b>o</b></a>; and that upon cloning
125
+ not just files, but also tickets, wikis, technotes and forum posts
126
+ are tranferred. Mnemonic: <b>g</b>et.
126127
</td>
127128
</tr>
128129
129130
<tr id="h">
130131
<th>h</th>
@@ -145,10 +146,12 @@
145146
<td>
146147
Check changes into the repository. Note that a lack of this
147148
capability does not prevent you from checking changes into your
148149
local clone, only from syncing those changes up to the parent
149150
repo, and then <a href="./basics.md#webonly">only over HTTP</a>.
151
+ Also note that not just files, but also tickets, wikis, technotes
152
+ and forum posts will be accepted from clones upon syncronization.
150153
Granting this capability also grants <b>o (Read)</b> Mnemonics:
151154
<b>i</b>nput, check <b>i</b>n changes.
152155
</td>
153156
</tr>
154157
@@ -202,11 +205,11 @@
202205
203206
<tr id="o">
204207
<th>o</th>
205208
<th>Read</th>
206209
<td>
207
- Read repository content from a remote Fossil instance over
210
+ Read content and history of files from a remote Fossil instance over
208211
HTTP. See <a href="index.md#read-v-clone">Reading vs.
209212
Cloning</a>. Mnemonic: check <b>o</b>ut remote repo contents.
210213
</td>
211214
</tr>
212215
213216
--- www/caps/ref.html
+++ www/caps/ref.html
@@ -119,12 +119,13 @@
119 <tr id="g">
120 <th>g</th>
121 <th>Clone</th>
122 <td>
123 Clone the repository. Note that this is distinct from <a
124 href="#o">check-out capability, <b>o</b></a>. Mnemonic:
125 <b>g</b>et.
 
126 </td>
127 </tr>
128
129 <tr id="h">
130 <th>h</th>
@@ -145,10 +146,12 @@
145 <td>
146 Check changes into the repository. Note that a lack of this
147 capability does not prevent you from checking changes into your
148 local clone, only from syncing those changes up to the parent
149 repo, and then <a href="./basics.md#webonly">only over HTTP</a>.
 
 
150 Granting this capability also grants <b>o (Read)</b> Mnemonics:
151 <b>i</b>nput, check <b>i</b>n changes.
152 </td>
153 </tr>
154
@@ -202,11 +205,11 @@
202
203 <tr id="o">
204 <th>o</th>
205 <th>Read</th>
206 <td>
207 Read repository content from a remote Fossil instance over
208 HTTP. See <a href="index.md#read-v-clone">Reading vs.
209 Cloning</a>. Mnemonic: check <b>o</b>ut remote repo contents.
210 </td>
211 </tr>
212
213
--- www/caps/ref.html
+++ www/caps/ref.html
@@ -119,12 +119,13 @@
119 <tr id="g">
120 <th>g</th>
121 <th>Clone</th>
122 <td>
123 Clone the repository. Note that this is distinct from <a
124 href="#o">check-out capability, <b>o</b></a>; and that upon cloning
125 not just files, but also tickets, wikis, technotes and forum posts
126 are tranferred. Mnemonic: <b>g</b>et.
127 </td>
128 </tr>
129
130 <tr id="h">
131 <th>h</th>
@@ -145,10 +146,12 @@
146 <td>
147 Check changes into the repository. Note that a lack of this
148 capability does not prevent you from checking changes into your
149 local clone, only from syncing those changes up to the parent
150 repo, and then <a href="./basics.md#webonly">only over HTTP</a>.
151 Also note that not just files, but also tickets, wikis, technotes
152 and forum posts will be accepted from clones upon syncronization.
153 Granting this capability also grants <b>o (Read)</b> Mnemonics:
154 <b>i</b>nput, check <b>i</b>n changes.
155 </td>
156 </tr>
157
@@ -202,11 +205,11 @@
205
206 <tr id="o">
207 <th>o</th>
208 <th>Read</th>
209 <td>
210 Read content and history of files from a remote Fossil instance over
211 HTTP. See <a href="index.md#read-v-clone">Reading vs.
212 Cloning</a>. Mnemonic: check <b>o</b>ut remote repo contents.
213 </td>
214 </tr>
215
216
--- www/changes.wiki
+++ www/changes.wiki
@@ -9,15 +9,32 @@
99
* Enhancements to the graph layout algorithm design to improve readability
1010
and promote better situational awareness.
1111
* Performance enhancement for the
1212
[./checkin_names.wiki#root|"root:BRANCHNAME" style of tag],
1313
accomplished using a Common Table Expression in the underlying SQL.
14
+ * Sort tag listings (command line and webpage) by taking numbers into
15
+ consideration so as to cater for tags that follow semantic versioning.
16
+ * On the wiki listings, omit by default wiki pages that are associated with
17
+ check-ins and branches.
1418
* Add the new "[/help?cmd=describe|fossil describe]" command.
1519
* Markdown subsystem extended with [../src/markdown.md#ftnts|footnotes support].
1620
See corresponding [../test/markdown-test3.md|test cases],
1721
[/wiki?name=branch/markdown-footnotes#il|known limitations] and
1822
[forum:/forumthread/ee1f1597e46ec07a|discussion].
23
+ * Add the new special name "start:BRANCH" to refer to the first check-in of
24
+ the branch.
25
+ * Support [/wiki?name=branch/generated-tkt-mimetype&p|generated "mimetype"]
26
+ columns in the <var>TICKET</var> and <var>TICKETCHNG</var> tables.
27
+ * Fix [/timeline?r=fix_remote_url_overwrite_with_proxy|remote-url-overwrite]
28
+ bug where remote-url is overwritten by the proxy setting during sync
29
+ operation. Also require explicit "system" proxy setting to use
30
+ "http_proxy" environment variable.
31
+ * Reimplemented the [/pikchrshow] app to use a WebAssembly build of
32
+ pikchr so that it can render pikchrs on the client instead of requiring
33
+ a server round-trip.
34
+ * Add the [/help?cmd=email-listid|email-listid setting]. If set, it is
35
+ used as the List-ID header for all outbound notification emails.
1936
2037
<h2 id='v2_18'>Changes for version 2.18 (2022-02-23)</h2>
2138
* Added support for [./ssl-server.md|SSL/TLS server mode] for commands
2239
like "[/help?cmd=server|fossil server]" and "[/help?cmd=http|fossil http]"
2340
* The new [/help?cmd=cherry-pick|cherry-pick command] is an alias for
2441
--- www/changes.wiki
+++ www/changes.wiki
@@ -9,15 +9,32 @@
9 * Enhancements to the graph layout algorithm design to improve readability
10 and promote better situational awareness.
11 * Performance enhancement for the
12 [./checkin_names.wiki#root|"root:BRANCHNAME" style of tag],
13 accomplished using a Common Table Expression in the underlying SQL.
 
 
 
 
14 * Add the new "[/help?cmd=describe|fossil describe]" command.
15 * Markdown subsystem extended with [../src/markdown.md#ftnts|footnotes support].
16 See corresponding [../test/markdown-test3.md|test cases],
17 [/wiki?name=branch/markdown-footnotes#il|known limitations] and
18 [forum:/forumthread/ee1f1597e46ec07a|discussion].
 
 
 
 
 
 
 
 
 
 
 
 
 
19
20 <h2 id='v2_18'>Changes for version 2.18 (2022-02-23)</h2>
21 * Added support for [./ssl-server.md|SSL/TLS server mode] for commands
22 like "[/help?cmd=server|fossil server]" and "[/help?cmd=http|fossil http]"
23 * The new [/help?cmd=cherry-pick|cherry-pick command] is an alias for
24
--- www/changes.wiki
+++ www/changes.wiki
@@ -9,15 +9,32 @@
9 * Enhancements to the graph layout algorithm design to improve readability
10 and promote better situational awareness.
11 * Performance enhancement for the
12 [./checkin_names.wiki#root|"root:BRANCHNAME" style of tag],
13 accomplished using a Common Table Expression in the underlying SQL.
14 * Sort tag listings (command line and webpage) by taking numbers into
15 consideration so as to cater for tags that follow semantic versioning.
16 * On the wiki listings, omit by default wiki pages that are associated with
17 check-ins and branches.
18 * Add the new "[/help?cmd=describe|fossil describe]" command.
19 * Markdown subsystem extended with [../src/markdown.md#ftnts|footnotes support].
20 See corresponding [../test/markdown-test3.md|test cases],
21 [/wiki?name=branch/markdown-footnotes#il|known limitations] and
22 [forum:/forumthread/ee1f1597e46ec07a|discussion].
23 * Add the new special name "start:BRANCH" to refer to the first check-in of
24 the branch.
25 * Support [/wiki?name=branch/generated-tkt-mimetype&p|generated "mimetype"]
26 columns in the <var>TICKET</var> and <var>TICKETCHNG</var> tables.
27 * Fix [/timeline?r=fix_remote_url_overwrite_with_proxy|remote-url-overwrite]
28 bug where remote-url is overwritten by the proxy setting during sync
29 operation. Also require explicit "system" proxy setting to use
30 "http_proxy" environment variable.
31 * Reimplemented the [/pikchrshow] app to use a WebAssembly build of
32 pikchr so that it can render pikchrs on the client instead of requiring
33 a server round-trip.
34 * Add the [/help?cmd=email-listid|email-listid setting]. If set, it is
35 used as the List-ID header for all outbound notification emails.
36
37 <h2 id='v2_18'>Changes for version 2.18 (2022-02-23)</h2>
38 * Added support for [./ssl-server.md|SSL/TLS server mode] for commands
39 like "[/help?cmd=server|fossil server]" and "[/help?cmd=http|fossil http]"
40 * The new [/help?cmd=cherry-pick|cherry-pick command] is an alias for
41
--- www/checkin_names.wiki
+++ www/checkin_names.wiki
@@ -8,10 +8,11 @@
88
<li> Branch name
99
<li> Tag name
1010
<li> Timestamp: <i>YYYY-MM-DD HH:MM:SS</i>
1111
<li> <i>tag-name</i> <big><b>:</b></big> <i>timestamp</i>
1212
<li> <b>root <big>:</big></b> <i>branchname</i>
13
+<li> <b>start <big>:</big></b> <i>branchname</i>
1314
<li> <b>merge-in <big>:</big></b> <i>branchname</i>
1415
<li> Special names:
1516
<ul>
1617
<li> <b>tip</b>
1718
<li> <b>current</b>
@@ -234,10 +235,13 @@
234235
the most recent merge-in point for that branch.
235236
The resulting diff will then show only the changes in
236237
the branch itself, omitting
237238
any changes that have already been merged in from the parent branch.
238239
240
+<a id="start"></a>
241
+The prefix "<tt>start:</tt>" gives the first check-in of the named branch.
242
+
239243
The prefixes "<tt>root:</tt>" and "<tt>merge-in:</tt>" can be chained: one
240244
can say for example
241245
242246
<blockquote><tt>
243247
fossil info merge-in:xyzzy:2022-03-01
@@ -299,12 +303,13 @@
299303
300304
# Exact matches on [#special | the special names]
301305
# [#timestamps | Timestamps], with preference to ISO8601 forms
302306
# [#tagpfx | tag:TAGNAME]
303307
# [#root | root:BRANCH]
308
+ # [#start | start:BRANCH]
304309
# [#merge-in | merge-in:BRANCH]
305310
# [#tag-ts | TAGNAME:timestamp]
306311
# Full artifact hash or hash prefix.
307312
# Any other type of symbolic name that Fossil extracts from
308313
artifacts.
309314
310315
<div style="height:50em" id="this-space-intentionally-left-blank"></div>
311316
--- www/checkin_names.wiki
+++ www/checkin_names.wiki
@@ -8,10 +8,11 @@
8 <li> Branch name
9 <li> Tag name
10 <li> Timestamp: <i>YYYY-MM-DD HH:MM:SS</i>
11 <li> <i>tag-name</i> <big><b>:</b></big> <i>timestamp</i>
12 <li> <b>root <big>:</big></b> <i>branchname</i>
 
13 <li> <b>merge-in <big>:</big></b> <i>branchname</i>
14 <li> Special names:
15 <ul>
16 <li> <b>tip</b>
17 <li> <b>current</b>
@@ -234,10 +235,13 @@
234 the most recent merge-in point for that branch.
235 The resulting diff will then show only the changes in
236 the branch itself, omitting
237 any changes that have already been merged in from the parent branch.
238
 
 
 
239 The prefixes "<tt>root:</tt>" and "<tt>merge-in:</tt>" can be chained: one
240 can say for example
241
242 <blockquote><tt>
243 fossil info merge-in:xyzzy:2022-03-01
@@ -299,12 +303,13 @@
299
300 # Exact matches on [#special | the special names]
301 # [#timestamps | Timestamps], with preference to ISO8601 forms
302 # [#tagpfx | tag:TAGNAME]
303 # [#root | root:BRANCH]
 
304 # [#merge-in | merge-in:BRANCH]
305 # [#tag-ts | TAGNAME:timestamp]
306 # Full artifact hash or hash prefix.
307 # Any other type of symbolic name that Fossil extracts from
308 artifacts.
309
310 <div style="height:50em" id="this-space-intentionally-left-blank"></div>
311
--- www/checkin_names.wiki
+++ www/checkin_names.wiki
@@ -8,10 +8,11 @@
8 <li> Branch name
9 <li> Tag name
10 <li> Timestamp: <i>YYYY-MM-DD HH:MM:SS</i>
11 <li> <i>tag-name</i> <big><b>:</b></big> <i>timestamp</i>
12 <li> <b>root <big>:</big></b> <i>branchname</i>
13 <li> <b>start <big>:</big></b> <i>branchname</i>
14 <li> <b>merge-in <big>:</big></b> <i>branchname</i>
15 <li> Special names:
16 <ul>
17 <li> <b>tip</b>
18 <li> <b>current</b>
@@ -234,10 +235,13 @@
235 the most recent merge-in point for that branch.
236 The resulting diff will then show only the changes in
237 the branch itself, omitting
238 any changes that have already been merged in from the parent branch.
239
240 <a id="start"></a>
241 The prefix "<tt>start:</tt>" gives the first check-in of the named branch.
242
243 The prefixes "<tt>root:</tt>" and "<tt>merge-in:</tt>" can be chained: one
244 can say for example
245
246 <blockquote><tt>
247 fossil info merge-in:xyzzy:2022-03-01
@@ -299,12 +303,13 @@
303
304 # Exact matches on [#special | the special names]
305 # [#timestamps | Timestamps], with preference to ISO8601 forms
306 # [#tagpfx | tag:TAGNAME]
307 # [#root | root:BRANCH]
308 # [#start | start:BRANCH]
309 # [#merge-in | merge-in:BRANCH]
310 # [#tag-ts | TAGNAME:timestamp]
311 # Full artifact hash or hash prefix.
312 # Any other type of symbolic name that Fossil extracts from
313 artifacts.
314
315 <div style="height:50em" id="this-space-intentionally-left-blank"></div>
316
--- www/reviews.wiki
+++ www/reviews.wiki
@@ -1,13 +1,10 @@
11
<title>Reviews</title>
22
<b>External links:</b>
33
44
* [http://nixtu.blogspot.com/2010/03/fossil-dvcs-on-go-first-impressions.html |
55
Fossil DVCS on the Go - First Impressions]
6
- * [http://blog.mired.org/2011/02/fossil-sweet-spot-in-vcs-space.html |
7
- Fossil - a sweet spot in the VCS space] by Mike Meyer.
8
- * [http://blog.s11n.net/?p=72|Four reasons to take a closer look at the Fossil SCM] by Stephan Beal
96
107
<b>See Also:</b>
118
129
* [./quotes.wiki | Short Quotes on Fossil, Git, And DVCSes]
1310
1411
--- www/reviews.wiki
+++ www/reviews.wiki
@@ -1,13 +1,10 @@
1 <title>Reviews</title>
2 <b>External links:</b>
3
4 * [http://nixtu.blogspot.com/2010/03/fossil-dvcs-on-go-first-impressions.html |
5 Fossil DVCS on the Go - First Impressions]
6 * [http://blog.mired.org/2011/02/fossil-sweet-spot-in-vcs-space.html |
7 Fossil - a sweet spot in the VCS space] by Mike Meyer.
8 * [http://blog.s11n.net/?p=72|Four reasons to take a closer look at the Fossil SCM] by Stephan Beal
9
10 <b>See Also:</b>
11
12 * [./quotes.wiki | Short Quotes on Fossil, Git, And DVCSes]
13
14
--- www/reviews.wiki
+++ www/reviews.wiki
@@ -1,13 +1,10 @@
1 <title>Reviews</title>
2 <b>External links:</b>
3
4 * [http://nixtu.blogspot.com/2010/03/fossil-dvcs-on-go-first-impressions.html |
5 Fossil DVCS on the Go - First Impressions]
 
 
 
6
7 <b>See Also:</b>
8
9 * [./quotes.wiki | Short Quotes on Fossil, Git, And DVCSes]
10
11
--- www/tech_overview.wiki
+++ www/tech_overview.wiki
@@ -177,11 +177,11 @@
177177
<h3>2.2 Repository Databases</h3>
178178
179179
The repository database is the file that is commonly referred to as
180180
"the repository". This is because the repository database contains,
181181
among other things, the complete revision, ticket, and wiki history for
182
-a project. It is customary to name the repository database after then
182
+a project. It is customary to name the repository database after the
183183
name of the project, with a ".fossil" suffix. For example, the repository
184184
database for the self-hosting Fossil repository is called "fossil.fossil"
185185
and the repository database for SQLite is called "sqlite.fossil".
186186
187187
<h4>2.2.1 Global Project State</h4>
188188
--- www/tech_overview.wiki
+++ www/tech_overview.wiki
@@ -177,11 +177,11 @@
177 <h3>2.2 Repository Databases</h3>
178
179 The repository database is the file that is commonly referred to as
180 "the repository". This is because the repository database contains,
181 among other things, the complete revision, ticket, and wiki history for
182 a project. It is customary to name the repository database after then
183 name of the project, with a ".fossil" suffix. For example, the repository
184 database for the self-hosting Fossil repository is called "fossil.fossil"
185 and the repository database for SQLite is called "sqlite.fossil".
186
187 <h4>2.2.1 Global Project State</h4>
188
--- www/tech_overview.wiki
+++ www/tech_overview.wiki
@@ -177,11 +177,11 @@
177 <h3>2.2 Repository Databases</h3>
178
179 The repository database is the file that is commonly referred to as
180 "the repository". This is because the repository database contains,
181 among other things, the complete revision, ticket, and wiki history for
182 a project. It is customary to name the repository database after the
183 name of the project, with a ".fossil" suffix. For example, the repository
184 database for the self-hosting Fossil repository is called "fossil.fossil"
185 and the repository database for SQLite is called "sqlite.fossil".
186
187 <h4>2.2.1 Global Project State</h4>
188

Keyboard Shortcuts

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