Fossil SCM

Merge trunk into remote-add-fix branch.

stephan 2022-09-06 22:25 remote-add-fix merge
Commit baf635cb7eacf422b67f7cd6752585323adb3d91aea2bb38bbbbd313fa5af62d
D .dockerignore
-23
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,23 +0,0 @@
1
-_FOSSIL_
2
-.fslckout
3
-ajax
4
-art
5
-autosetup
6
-bld
7
-compat
8
-debian
9
-fossil
10
-fossil.exe
11
-msvcbld
12
-setup
13
-src
14
-test
15
-tools
16
-win
17
-wbld
18
-win
19
-www
20
-*.a
21
-*.lib
22
-*.log
23
-*.mani
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,23 +0,0 @@
1 _FOSSIL_
2 .fslckout
3 ajax
4 art
5 autosetup
6 bld
7 compat
8 debian
9 fossil
10 fossil.exe
11 msvcbld
12 setup
13 src
14 test
15 tools
16 win
17 wbld
18 win
19 www
20 *.a
21 *.lib
22 *.log
23 *.mani
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,23 +0,0 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
+94 -27
--- Dockerfile
+++ Dockerfile
@@ -1,44 +1,111 @@
1
-# STAGE 1: Build a static Fossil binary atop Alpine Linux
2
-
3
-# Avoid the temptation to swap the wget call below out for an ADD URL
4
-# directive. The URL is fixed for a given release tag, which triggers
5
-# Docker's caching behavior, causing it to reuse that version as long
6
-# as it remains in the cache. We prefer to rely on the caching of the
7
-# server instance on fossil-scm.org, which will keep these trunk
8
-# tarballs around until the next trunk commit.
1
+# See www/containers.md for documentation on how to use this file.
2
+
3
+## ---------------------------------------------------------------------
4
+## STAGE 1: Build static Fossil & BusyBox binaries atop Alpine Linux
5
+## ---------------------------------------------------------------------
96
107
FROM alpine:latest AS builder
118
WORKDIR /tmp
12
-RUN apk update \
13
- && apk upgrade --no-cache \
14
- && apk add --no-cache \
15
- busybox-static gcc make \
16
- musl-dev \
9
+
10
+### Bake the basic Alpine Linux into a base layer so we never have to
11
+### repeat that step unless we change the package set. Although we're
12
+### going to throw this layer away below, we still pass --no-cache
13
+### because that cache is of no use in an immutable layer. Note that
14
+### we allow the UPX step to fail: it isn't in the ARM distros. We'll
15
+### check whether this optional piece exists before using it below.
16
+RUN set -x \
17
+ && apk update \
18
+ && apk upgrade --no-cache \
19
+ && apk add --no-cache \
20
+ gcc make moreutils \
21
+ linux-headers musl-dev \
1722
openssl-dev openssl-libs-static \
1823
zlib-dev zlib-static \
19
- && wget -O - https://fossil-scm.org/home/tarball/src | tar -xz \
20
- && src/configure --static CFLAGS='-Os -s' \
21
- && make -j
24
+ ; apk add --no-cache upx
25
+
26
+### Bake the custom BusyBox into another layer. The intent is that this
27
+### changes only when we change BBXVER. That will force an update of
28
+### the layers below, but this is a rare occurrence.
29
+ARG BBXVER="1_35_0"
30
+ENV BBXURL "https://github.com/mirror/busybox/tarball/${BBXVER}"
31
+COPY containers/busybox-config /tmp/bbx/.config
32
+ADD $BBXURL /tmp/bbx/src.tar.gz
33
+RUN set -x \
34
+ && tar --strip-components=1 -C bbx -xzf bbx/src.tar.gz \
35
+ && ( cd bbx && yes "" | make oldconfig && make -j11 ) \
36
+ && if [ -x /usr/bin/upx ] ; then upx -9q bbx/busybox ; fi
37
+
38
+### The changeable Fossil layer is the only one in the first stage that
39
+### changes often, so add it last, to make it independent of the others.
40
+###
41
+### $FSLSTB can be either a file or a directory due to a ADD's bizarre
42
+### behavior: it unpacks tarballs when added from a local file but not
43
+### from a URL! It matters because we default to a URL in case you're
44
+### building outside a Fossil checkout, but when building via the
45
+### container-image target, we can avoid a costly hit on the Fossil
46
+### project's home site by pulling the data from the local repo via the
47
+### "tarball" command. This is a DVCS, after all!
48
+ARG FSLVER="trunk"
49
+ARG FSLURL="https://fossil-scm.org/home/tarball/src?r=${FSLVER}"
50
+ENV FSLSTB=/tmp/fsl/src.tar.gz
51
+ADD $FSLURL $FSLSTB
52
+RUN set -x \
53
+ && if [ -d $FSLSTB ] ; then mv $FSLSTB/src fsl ; \
54
+ else tar -C fsl -xzf fsl/src.tar.gz ; fi \
55
+ && m=fsl/src/src/main.mk \
56
+ && grep -v '/skins/[a-ce-z]' $m | sponge $m \
57
+ && fsl/src/configure --static CFLAGS='-Os -s' && make -j11 \
58
+ && if [ -x /usr/bin/upx ] ; then upx -9q fossil ; fi
59
+
2260
23
-# STAGE 2: Pare that back to the bare essentials.
61
+## ---------------------------------------------------------------------
62
+## STAGE 2: Pare that back to the bare essentials.
63
+## ---------------------------------------------------------------------
2464
2565
FROM scratch
26
-ENV JAIL=/jail
27
-WORKDIR ${JAIL}
28
-COPY --from=builder /tmp/fossil ${JAIL}/bin/
29
-COPY --from=builder /bin/busybox.static /bin/busybox
66
+WORKDIR /jail
67
+ARG UID=499
68
+ENV PATH "/bin:/jail/bin"
69
+
70
+### Lay BusyBox down as the first base layer. Coupled with the host's
71
+### kernel, this is the "OS."
72
+COPY --from=builder /tmp/bbx/busybox /bin/
3073
RUN [ "/bin/busybox", "--install", "/bin" ]
31
-RUN mkdir -m 700 dev \
32
- && mknod -m 600 dev/null c 1 3 \
33
- && mknod -m 600 dev/urandom c 1 9
74
+
75
+### Set up that base OS for our specific use without tying it to
76
+### anything likely to change often. So long as the user leaves
77
+### UID alone, this layer will be durable.
78
+RUN set -x \
79
+ && echo 'root:x:0:0:SysAdmin:/:/bin/nologin' > /etc/passwd \
80
+ && echo 'root:x:0:root' > /etc/group \
81
+ && addgroup -S -g ${UID} fossil \
82
+ && adduser -S -h `pwd` -g 'Fossil User' -G fossil -u ${UID} fossil \
83
+ && install -d -m 700 -o fossil -g fossil log museum \
84
+ && install -d -m 755 -o fossil -g fossil dev \
85
+ && mknod -m 666 dev/null c 1 3 \
86
+ && mknod -m 444 dev/urandom c 1 9
87
+
88
+### Do Fossil-specific things atop those base layers; this will change
89
+### as often as the Fossil build-from-source layer above.
90
+COPY --from=builder /tmp/fossil bin/
91
+RUN set -x \
92
+ && ln -s /jail/bin/fossil /bin/f \
93
+ && echo -e '#!/bin/sh\nfossil sha1sum "$@"' > /bin/sha1sum \
94
+ && echo -e '#!/bin/sh\nfossil sha3sum "$@"' > /bin/sha3sum \
95
+ && echo -e '#!/bin/sh\nfossil sqlite3 --no-repository "$@"' > \
96
+ /bin/sqlite3 \
97
+ && chmod +x /bin/sha?sum /bin/sqlite3
98
+
3499
35
-# Now we can run the stripped-down environment in a chroot jail, while
36
-# leaving open the option to debug it live via the Busybox shell.
100
+## ---------------------------------------------------------------------
101
+## STAGE 3: Run!
102
+## ---------------------------------------------------------------------
37103
38104
EXPOSE 8080/tcp
39105
CMD [ \
40106
"bin/fossil", "server", \
107
+ "--chroot", "/jail", \
41108
"--create", \
42109
"--jsmode", "bundled", \
43110
"--user", "admin", \
44
- "repo.fossil"]
111
+ "museum/repo.fossil"]
45112
--- Dockerfile
+++ Dockerfile
@@ -1,44 +1,111 @@
1 # STAGE 1: Build a static Fossil binary atop Alpine Linux
2
3 # Avoid the temptation to swap the wget call below out for an ADD URL
4 # directive. The URL is fixed for a given release tag, which triggers
5 # Docker's caching behavior, causing it to reuse that version as long
6 # as it remains in the cache. We prefer to rely on the caching of the
7 # server instance on fossil-scm.org, which will keep these trunk
8 # tarballs around until the next trunk commit.
9
10 FROM alpine:latest AS builder
11 WORKDIR /tmp
12 RUN apk update \
13 && apk upgrade --no-cache \
14 && apk add --no-cache \
15 busybox-static gcc make \
16 musl-dev \
 
 
 
 
 
 
 
 
17 openssl-dev openssl-libs-static \
18 zlib-dev zlib-static \
19 && wget -O - https://fossil-scm.org/home/tarball/src | tar -xz \
20 && src/configure --static CFLAGS='-Os -s' \
21 && make -j
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
23 # STAGE 2: Pare that back to the bare essentials.
 
 
24
25 FROM scratch
26 ENV JAIL=/jail
27 WORKDIR ${JAIL}
28 COPY --from=builder /tmp/fossil ${JAIL}/bin/
29 COPY --from=builder /bin/busybox.static /bin/busybox
 
 
 
30 RUN [ "/bin/busybox", "--install", "/bin" ]
31 RUN mkdir -m 700 dev \
32 && mknod -m 600 dev/null c 1 3 \
33 && mknod -m 600 dev/urandom c 1 9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
35 # Now we can run the stripped-down environment in a chroot jail, while
36 # leaving open the option to debug it live via the Busybox shell.
 
37
38 EXPOSE 8080/tcp
39 CMD [ \
40 "bin/fossil", "server", \
 
41 "--create", \
42 "--jsmode", "bundled", \
43 "--user", "admin", \
44 "repo.fossil"]
45
--- Dockerfile
+++ Dockerfile
@@ -1,44 +1,111 @@
1 # See www/containers.md for documentation on how to use this file.
2
3 ## ---------------------------------------------------------------------
4 ## STAGE 1: Build static Fossil & BusyBox binaries atop Alpine Linux
5 ## ---------------------------------------------------------------------
 
 
 
6
7 FROM alpine:latest AS builder
8 WORKDIR /tmp
9
10 ### Bake the basic Alpine Linux into a base layer so we never have to
11 ### repeat that step unless we change the package set. Although we're
12 ### going to throw this layer away below, we still pass --no-cache
13 ### because that cache is of no use in an immutable layer. Note that
14 ### we allow the UPX step to fail: it isn't in the ARM distros. We'll
15 ### check whether this optional piece exists before using it below.
16 RUN set -x \
17 && apk update \
18 && apk upgrade --no-cache \
19 && apk add --no-cache \
20 gcc make moreutils \
21 linux-headers musl-dev \
22 openssl-dev openssl-libs-static \
23 zlib-dev zlib-static \
24 ; apk add --no-cache upx
25
26 ### Bake the custom BusyBox into another layer. The intent is that this
27 ### changes only when we change BBXVER. That will force an update of
28 ### the layers below, but this is a rare occurrence.
29 ARG BBXVER="1_35_0"
30 ENV BBXURL "https://github.com/mirror/busybox/tarball/${BBXVER}"
31 COPY containers/busybox-config /tmp/bbx/.config
32 ADD $BBXURL /tmp/bbx/src.tar.gz
33 RUN set -x \
34 && tar --strip-components=1 -C bbx -xzf bbx/src.tar.gz \
35 && ( cd bbx && yes "" | make oldconfig && make -j11 ) \
36 && if [ -x /usr/bin/upx ] ; then upx -9q bbx/busybox ; fi
37
38 ### The changeable Fossil layer is the only one in the first stage that
39 ### changes often, so add it last, to make it independent of the others.
40 ###
41 ### $FSLSTB can be either a file or a directory due to a ADD's bizarre
42 ### behavior: it unpacks tarballs when added from a local file but not
43 ### from a URL! It matters because we default to a URL in case you're
44 ### building outside a Fossil checkout, but when building via the
45 ### container-image target, we can avoid a costly hit on the Fossil
46 ### project's home site by pulling the data from the local repo via the
47 ### "tarball" command. This is a DVCS, after all!
48 ARG FSLVER="trunk"
49 ARG FSLURL="https://fossil-scm.org/home/tarball/src?r=${FSLVER}"
50 ENV FSLSTB=/tmp/fsl/src.tar.gz
51 ADD $FSLURL $FSLSTB
52 RUN set -x \
53 && if [ -d $FSLSTB ] ; then mv $FSLSTB/src fsl ; \
54 else tar -C fsl -xzf fsl/src.tar.gz ; fi \
55 && m=fsl/src/src/main.mk \
56 && grep -v '/skins/[a-ce-z]' $m | sponge $m \
57 && fsl/src/configure --static CFLAGS='-Os -s' && make -j11 \
58 && if [ -x /usr/bin/upx ] ; then upx -9q fossil ; fi
59
60
61 ## ---------------------------------------------------------------------
62 ## STAGE 2: Pare that back to the bare essentials.
63 ## ---------------------------------------------------------------------
64
65 FROM scratch
66 WORKDIR /jail
67 ARG UID=499
68 ENV PATH "/bin:/jail/bin"
69
70 ### Lay BusyBox down as the first base layer. Coupled with the host's
71 ### kernel, this is the "OS."
72 COPY --from=builder /tmp/bbx/busybox /bin/
73 RUN [ "/bin/busybox", "--install", "/bin" ]
74
75 ### Set up that base OS for our specific use without tying it to
76 ### anything likely to change often. So long as the user leaves
77 ### UID alone, this layer will be durable.
78 RUN set -x \
79 && echo 'root:x:0:0:SysAdmin:/:/bin/nologin' > /etc/passwd \
80 && echo 'root:x:0:root' > /etc/group \
81 && addgroup -S -g ${UID} fossil \
82 && adduser -S -h `pwd` -g 'Fossil User' -G fossil -u ${UID} fossil \
83 && install -d -m 700 -o fossil -g fossil log museum \
84 && install -d -m 755 -o fossil -g fossil dev \
85 && mknod -m 666 dev/null c 1 3 \
86 && mknod -m 444 dev/urandom c 1 9
87
88 ### Do Fossil-specific things atop those base layers; this will change
89 ### as often as the Fossil build-from-source layer above.
90 COPY --from=builder /tmp/fossil bin/
91 RUN set -x \
92 && ln -s /jail/bin/fossil /bin/f \
93 && echo -e '#!/bin/sh\nfossil sha1sum "$@"' > /bin/sha1sum \
94 && echo -e '#!/bin/sh\nfossil sha3sum "$@"' > /bin/sha3sum \
95 && echo -e '#!/bin/sh\nfossil sqlite3 --no-repository "$@"' > \
96 /bin/sqlite3 \
97 && chmod +x /bin/sha?sum /bin/sqlite3
98
99
100 ## ---------------------------------------------------------------------
101 ## STAGE 3: Run!
102 ## ---------------------------------------------------------------------
103
104 EXPOSE 8080/tcp
105 CMD [ \
106 "bin/fossil", "server", \
107 "--chroot", "/jail", \
108 "--create", \
109 "--jsmode", "bundled", \
110 "--user", "admin", \
111 "museum/repo.fossil"]
112
+26
--- Makefile.in
+++ Makefile.in
@@ -116,5 +116,31 @@
116116
# of delegating to it with "$(MAKE) reconfig": having children running
117117
# around interfering makes this failure mode even worse.
118118
Makefile: @srcdir@/Makefile.in $(SRCDIR)/main.mk @AUTODEPS@
119119
@AUTOREMAKE@
120120
touch @builddir@/Makefile
121
+
122
+# Container stuff
123
+SRCTB := src-@[email protected]
124
+container-image:
125
+ $(APPNAME) tarball --name src @FOSSIL_CI_PFX@ $(SRCTB)
126
+ docker build \
127
+ --tag fossil:@FOSSIL_CI_PFX@ \
128
+ --build-arg FSLURL=$(SRCTB) \
129
+ $(DBFLAGS) @srcdir@
130
+ rm -f $(SRCTB)
131
+
132
+container-run: container-image
133
+ docker run \
134
+ --name fossil-@FOSSIL_CI_PFX@ \
135
+ --cap-drop AUDIT_WRITE \
136
+ --cap-drop CHOWN \
137
+ --cap-drop FSETID \
138
+ --cap-drop KILL \
139
+ --cap-drop MKNOD \
140
+ --cap-drop NET_BIND_SERVICE \
141
+ --cap-drop NET_RAW \
142
+ --cap-drop SETFCAP \
143
+ --cap-drop SETPCAP \
144
+ --detach --publish 8080:8080 \
145
+ $(DRFLAGS) fossil:@FOSSIL_CI_PFX@
146
+ docker container logs fossil-@FOSSIL_CI_PFX@
121147
--- Makefile.in
+++ Makefile.in
@@ -116,5 +116,31 @@
116 # of delegating to it with "$(MAKE) reconfig": having children running
117 # around interfering makes this failure mode even worse.
118 Makefile: @srcdir@/Makefile.in $(SRCDIR)/main.mk @AUTODEPS@
119 @AUTOREMAKE@
120 touch @builddir@/Makefile
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
--- Makefile.in
+++ Makefile.in
@@ -116,5 +116,31 @@
116 # of delegating to it with "$(MAKE) reconfig": having children running
117 # around interfering makes this failure mode even worse.
118 Makefile: @srcdir@/Makefile.in $(SRCDIR)/main.mk @AUTODEPS@
119 @AUTOREMAKE@
120 touch @builddir@/Makefile
121
122 # Container stuff
123 SRCTB := src-@[email protected]
124 container-image:
125 $(APPNAME) tarball --name src @FOSSIL_CI_PFX@ $(SRCTB)
126 docker build \
127 --tag fossil:@FOSSIL_CI_PFX@ \
128 --build-arg FSLURL=$(SRCTB) \
129 $(DBFLAGS) @srcdir@
130 rm -f $(SRCTB)
131
132 container-run: container-image
133 docker run \
134 --name fossil-@FOSSIL_CI_PFX@ \
135 --cap-drop AUDIT_WRITE \
136 --cap-drop CHOWN \
137 --cap-drop FSETID \
138 --cap-drop KILL \
139 --cap-drop MKNOD \
140 --cap-drop NET_BIND_SERVICE \
141 --cap-drop NET_RAW \
142 --cap-drop SETFCAP \
143 --cap-drop SETPCAP \
144 --detach --publish 8080:8080 \
145 $(DRFLAGS) fossil:@FOSSIL_CI_PFX@
146 docker container logs fossil-@FOSSIL_CI_PFX@
147
+9
--- auto.def
+++ auto.def
@@ -764,8 +764,17 @@
764764
catch {exec chmod u+x tools/emcc.sh}
765765
} else {
766766
define EMCC_WRAPPER ""
767767
catch {exec rm -f tools/emcc.sh}
768768
}
769
+
770
+# Tag container builds with a prefix of the checkin ID of the version
771
+# of Fossil each one contains. This not only allows multiple images
772
+# to coexist and multiple containers to be created unamgiguosly from
773
+# them, it also changes the URL we fetch the source tarball from, so
774
+# repeated builds of a given version generate and fetch the source
775
+# tarball once only, keeping it in the local Docker/Podman cache.
776
+set ci [readfile "$::autosetup(srcdir)/manifest.uuid"]
777
+define FOSSIL_CI_PFX [string range $ci 0 11]
769778
770779
make-template Makefile.in
771780
make-config-header autoconfig.h -auto {USE_* FOSSIL_*}
772781
773782
ADDED containers/Dockerfile-nojail.patch
774783
ADDED containers/busybox-config
--- auto.def
+++ auto.def
@@ -764,8 +764,17 @@
764 catch {exec chmod u+x tools/emcc.sh}
765 } else {
766 define EMCC_WRAPPER ""
767 catch {exec rm -f tools/emcc.sh}
768 }
 
 
 
 
 
 
 
 
 
769
770 make-template Makefile.in
771 make-config-header autoconfig.h -auto {USE_* FOSSIL_*}
772
773 DDED containers/Dockerfile-nojail.patch
774 DDED containers/busybox-config
--- auto.def
+++ auto.def
@@ -764,8 +764,17 @@
764 catch {exec chmod u+x tools/emcc.sh}
765 } else {
766 define EMCC_WRAPPER ""
767 catch {exec rm -f tools/emcc.sh}
768 }
769
770 # Tag container builds with a prefix of the checkin ID of the version
771 # of Fossil each one contains. This not only allows multiple images
772 # to coexist and multiple containers to be created unamgiguosly from
773 # them, it also changes the URL we fetch the source tarball from, so
774 # repeated builds of a given version generate and fetch the source
775 # tarball once only, keeping it in the local Docker/Podman cache.
776 set ci [readfile "$::autosetup(srcdir)/manifest.uuid"]
777 define FOSSIL_CI_PFX [string range $ci 0 11]
778
779 make-template Makefile.in
780 make-config-header autoconfig.h -auto {USE_* FOSSIL_*}
781
782 DDED containers/Dockerfile-nojail.patch
783 DDED containers/busybox-config
--- a/containers/Dockerfile-nojail.patch
+++ b/containers/Dockerfile-nojail.patch
@@ -0,0 +1,7 @@
1
+Index: Doc62,13 +.in
2
+busybox /bin/
3
+ etc/os-rel -84,19 +84,17 @@
4
+ 61,13 +.in
++++ Dockerfile.in
5
+@@ -27,37 +27,35 @@
6
+ && if apk add upx ; then upx -9
--- a/containers/Dockerfile-nojail.patch
+++ b/containers/Dockerfile-nojail.patch
@@ -0,0 +1,7 @@
 
 
 
 
++++ Dockerfile.in
 
 
--- a/containers/Dockerfile-nojail.patch
+++ b/containers/Dockerfile-nojail.patch
@@ -0,0 +1,7 @@
1 Index: Doc62,13 +.in
2 busybox /bin/
3 etc/os-rel -84,19 +84,17 @@
4 61,13 +.in
++++ Dockerfile.in
5 @@ -27,37 +27,35 @@
6 && if apk add upx ; then upx -9
--- a/containers/busybox-config
+++ b/containers/busybox-config
@@ -0,0 +1,1200 @@
1
+#
2
+# Automatically generated make config: don't edit
3
+# Busybox version: 1.35.0
4
+# Tue Aug 16 02:15:21 2022
5
+#
6
+CONFIG_HAVE_DOT_CONFIG=y
7
+
8
+#
9
+# Settings
10
+#
11
+CONFIG_DESKTOP=y
12
+# CONFIG_EXTRA_COMPAT is not set
13
+# CONFIG_FEDORA_COMPAT is not set
14
+CONFIG_INCLUDE_SUSv2=y
15
+CONFIG_LONG_OPTS=y
16
+CONFIG_SHOW_USAGE=y
17
+CONFIG_FEATURE_VERBOSE_USAGE=y
18
+CONFIG_FEATURE_COMPRESS_USAGE=y
19
+CONFIG_LFS=y
20
+# CONFIG_PAM is not set
21
+CONFIG_FEATURE_DEVPTS=y
22
+CONFIG_FEATURE_UTMP=y
23
+CONFIG_FEATURE_WTMP=y
24
+CONFIG_FEATURE_PIDFILE=y
25
+CONFIG_PID_FILE_PATH="/var/run"
26
+CONFIG_BUSYBOX=y
27
+CONFIG_FEATURE_SHOW_SCRIPT=y
28
+CONFIG_FEATURE_INSTALLER=y
29
+# CONFIG_INSTALL_NO_USR is not set
30
+CONFIG_FEATURE_SUID=y
31
+CONFIG_FEATURE_SUID_CONFIG=y
32
+CONFIG_FEATURE_SUID_CONFIG_QUIET=y
33
+# CONFIG_FEATURE_PREFER_APPLETS is not set
34
+CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
35
+# CONFIG_SELINUX is not set
36
+# CONFIG_FEATURE_CLEAN_UP is not set
37
+CONFIG_FEATURE_SYSLOG_INFO=y
38
+CONFIG_FEATURE_SYSLOG=y
39
+
40
+#
41
+# Build Options
42
+#
43
+CONFIG_STATIC=y
44
+# CONFIG_PIE is not set
45
+# CONFIG_NOMMU is not set
46
+# CONFIG_BUILD_LIBBUSYBOX is not set
47
+# CONFIG_FEATURE_LIBBUSYBOX_STATIC is not set
48
+# CONFIG_FEATURE_INDIVIDUAL is not set
49
+# CONFIG_FEATURE_SHARED_BUSYBOX is not set
50
+CONFIG_CROSS_COMPILER_PREFIX=""
51
+CONFIG_SYSROOT=""
52
+CONFIG_EXTRA_CFLAGS=""
53
+CONFIG_EXTRA_LDFLAGS=""
54
+CONFIG_EXTRA_LDLIBS=""
55
+# CONFIG_USE_PORTABLE_CODE is not set
56
+CONFIG_STACK_OPTIMIZATION_386=y
57
+CONFIG_STATIC_LIBGCC=y
58
+
59
+#
60
+# Installation Options ("make install" behavior)
61
+#
62
+CONFIG_INSTALL_APPLET_SYMLINKS=y
63
+# CONFIG_INSTALL_APPLET_HARDLINKS is not set
64
+# CONFIG_INSTALL_APPLET_SCRIPT_WRAPPERS is not set
65
+# CONFIG_INSTALL_APPLET_DONT is not set
66
+# CONFIG_INSTALL_SH_APPLET_SYMLINK is not set
67
+# CONFIG_INSTALL_SH_APPLET_HARDLINK is not set
68
+# CONFIG_INSTALL_SH_APPLET_SCRIPT_WRAPPER is not set
69
+CONFIG_PREFIX="./_install"
70
+
71
+#
72
+# Debugging Options
73
+#
74
+# CONFIG_DEBUG is not set
75
+# CONFIG_DEBUG_PESSIMIZE is not set
76
+# CONFIG_DEBUG_SANITIZE is not set
77
+# CONFIG_UNIT_TEST is not set
78
+# CONFIG_WERROR is not set
79
+# CONFIG_WARN_SIMPLE_MSG is not set
80
+CONFIG_NO_DEBUG_LIB=y
81
+# CONFIG_DMALLOC is not set
82
+# CONFIG_EFENCE is not set
83
+
84
+#
85
+# Library Tuning
86
+#
87
+# CONFIG_FEATURE_USE_BSS_TAIL is not set
88
+CONFIG_FLOAT_DURATION=y
89
+CONFIG_FEATURE_RTMINMAX=y
90
+CONFIG_FEATURE_RTMINMAX_USE_LIBC_DEFINITIONS=y
91
+CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
92
+# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
93
+# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
94
+CONFIG_PASSWORD_MINLEN=6
95
+CONFIG_MD5_SMALL=1
96
+CONFIG_SHA3_SMALL=1
97
+CONFIG_FEATURE_NON_POSIX_CP=y
98
+# CONFIG_FEATURE_VERBOSE_CP_MESSAGE is not set
99
+CONFIG_FEATURE_USE_SENDFILE=y
100
+CONFIG_FEATURE_COPYBUF_KB=4
101
+CONFIG_MONOTONIC_SYSCALL=y
102
+CONFIG_IOCTL_HEX2STR_ERROR=y
103
+CONFIG_FEATURE_EDITING=y
104
+CONFIG_FEATURE_EDITING_MAX_LEN=1024
105
+# CONFIG_FEATURE_EDITING_VI is not set
106
+CONFIG_FEATURE_EDITING_HISTORY=255
107
+CONFIG_FEATURE_EDITING_SAVEHISTORY=y
108
+# CONFIG_FEATURE_EDITING_SAVE_ON_EXIT is not set
109
+CONFIG_FEATURE_REVERSE_SEARCH=y
110
+CONFIG_FEATURE_TAB_COMPLETION=y
111
+CONFIG_FEATURE_USERNAME_COMPLETION=y
112
+CONFIG_FEATURE_EDITING_FANCY_PROMPT=y
113
+CONFIG_FEATURE_EDITING_WINCH=y
114
+# CONFIG_FEATURE_EDITING_ASK_TERMINAL is not set
115
+# CONFIG_LOCALE_SUPPORT is not set
116
+CONFIG_UNICODE_SUPPORT=y
117
+# CONFIG_UNICODE_USING_LOCALE is not set
118
+# CONFIG_FEATURE_CHECK_UNICODE_IN_ENV is not set
119
+CONFIG_SUBST_WCHAR=63
120
+CONFIG_LAST_SUPPORTED_WCHAR=767
121
+# CONFIG_UNICODE_COMBINING_WCHARS is not set
122
+# CONFIG_UNICODE_WIDE_WCHARS is not set
123
+# CONFIG_UNICODE_BIDI_SUPPORT is not set
124
+# CONFIG_UNICODE_NEUTRAL_TABLE is not set
125
+# CONFIG_UNICODE_PRESERVE_BROKEN is not set
126
+
127
+#
128
+# Applets
129
+#
130
+
131
+#
132
+# Archival Utilities
133
+#
134
+# CONFIG_FEATURE_SEAMLESS_XZ is not set
135
+# CONFIG_FEATURE_SEAMLESS_LZMA is not set
136
+# CONFIG_FEATURE_SEAMLESS_BZ2 is not set
137
+CONFIG_FEATURE_SEAMLESS_GZ=y
138
+# CONFIG_FEATURE_SEAMLESS_Z is not set
139
+# CONFIG_AR is not set
140
+# CONFIG_FEATURE_AR_LONG_FILENAMES is not set
141
+# CONFIG_FEATURE_AR_CREATE is not set
142
+# CONFIG_UNCOMPRESS is not set
143
+CONFIG_GUNZIP=y
144
+CONFIG_ZCAT=y
145
+CONFIG_FEATURE_GUNZIP_LONG_OPTIONS=y
146
+# CONFIG_BUNZIP2 is not set
147
+# CONFIG_BZCAT is not set
148
+# CONFIG_UNLZMA is not set
149
+# CONFIG_LZCAT is not set
150
+# CONFIG_LZMA is not set
151
+# CONFIG_UNXZ is not set
152
+# CONFIG_XZCAT is not set
153
+# CONFIG_XZ is not set
154
+# CONFIG_BZIP2 is not set
155
+CONFIG_BZIP2_SMALL=0
156
+# CONFIG_FEATURE_BZIP2_DECOMPRESS is not set
157
+# CONFIG_CPIO is not set
158
+# CONFIG_FEATURE_CPIO_O is not set
159
+# CONFIG_FEATURE_CPIO_P is not set
160
+# CONFIG_FEATURE_CPIO_IGNORE_DEVNO is not set
161
+# CONFIG_FEATURE_CPIO_RENUMBER_INODES is not set
162
+# CONFIG_DPKG is not set
163
+# CONFIG_DPKG_DEB is not set
164
+CONFIG_GZIP=y
165
+CONFIG_FEATURE_GZIP_LONG_OPTIONS=y
166
+CONFIG_GZIP_FAST=0
167
+# CONFIG_FEATURE_GZIP_LEVELS is not set
168
+CONFIG_FEATURE_GZIP_DECOMPRESS=y
169
+# CONFIG_LZOP is not set
170
+# CONFIG_UNLZOP is not set
171
+# CONFIG_LZOPCAT is not set
172
+# CONFIG_LZOP_COMPR_HIGH is not set
173
+# CONFIG_RPM is not set
174
+# CONFIG_RPM2CPIO is not set
175
+CONFIG_TAR=y
176
+CONFIG_FEATURE_TAR_LONG_OPTIONS=y
177
+CONFIG_FEATURE_TAR_CREATE=y
178
+CONFIG_FEATURE_TAR_AUTODETECT=y
179
+CONFIG_FEATURE_TAR_FROM=y
180
+# CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY is not set
181
+# CONFIG_FEATURE_TAR_OLDSUN_COMPATIBILITY is not set
182
+CONFIG_FEATURE_TAR_GNU_EXTENSIONS=y
183
+# CONFIG_FEATURE_TAR_TO_COMMAND is not set
184
+CONFIG_FEATURE_TAR_UNAME_GNAME=y
185
+CONFIG_FEATURE_TAR_NOPRESERVE_TIME=y
186
+# CONFIG_FEATURE_TAR_SELINUX is not set
187
+CONFIG_UNZIP=y
188
+CONFIG_FEATURE_UNZIP_CDF=y
189
+CONFIG_FEATURE_UNZIP_BZIP2=y
190
+CONFIG_FEATURE_UNZIP_LZMA=y
191
+CONFIG_FEATURE_UNZIP_XZ=y
192
+# CONFIG_FEATURE_LZMA_FAST is not set
193
+
194
+#
195
+# Coreutils
196
+#
197
+CONFIG_FEATURE_VERBOSE=y
198
+
199
+#
200
+# Common options for date and touch
201
+#
202
+CONFIG_FEATURE_TIMEZONE=y
203
+
204
+#
205
+# Common options for cp and mv
206
+#
207
+CONFIG_FEATURE_PRESERVE_HARDLINKS=y
208
+
209
+#
210
+# Common options for df, du, ls
211
+#
212
+CONFIG_FEATURE_HUMAN_READABLE=y
213
+CONFIG_BASENAME=y
214
+CONFIG_CAT=y
215
+CONFIG_FEATURE_CATN=y
216
+CONFIG_FEATURE_CATV=y
217
+CONFIG_CHGRP=y
218
+CONFIG_CHMOD=y
219
+CONFIG_CHOWN=y
220
+CONFIG_FEATURE_CHOWN_LONG_OPTIONS=y
221
+CONFIG_CHROOT=y
222
+# CONFIG_CKSUM is not set
223
+# CONFIG_CRC32 is not set
224
+CONFIG_COMM=y
225
+CONFIG_CP=y
226
+CONFIG_FEATURE_CP_LONG_OPTIONS=y
227
+CONFIG_FEATURE_CP_REFLINK=y
228
+CONFIG_CUT=y
229
+CONFIG_FEATURE_CUT_REGEX=y
230
+CONFIG_DATE=y
231
+CONFIG_FEATURE_DATE_ISOFMT=y
232
+# CONFIG_FEATURE_DATE_NANO is not set
233
+CONFIG_FEATURE_DATE_COMPAT=y
234
+CONFIG_DD=y
235
+CONFIG_FEATURE_DD_SIGNAL_HANDLING=y
236
+CONFIG_FEATURE_DD_THIRD_STATUS_LINE=y
237
+CONFIG_FEATURE_DD_IBS_OBS=y
238
+CONFIG_FEATURE_DD_STATUS=y
239
+CONFIG_DF=y
240
+CONFIG_FEATURE_DF_FANCY=y
241
+CONFIG_FEATURE_SKIP_ROOTFS=y
242
+CONFIG_DIRNAME=y
243
+CONFIG_DOS2UNIX=y
244
+CONFIG_UNIX2DOS=y
245
+CONFIG_DU=y
246
+CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K=y
247
+# CONFIG_ECHO is not set
248
+CONFIG_FEATURE_FANCY_ECHO=y
249
+CONFIG_ENV=y
250
+CONFIG_EXPAND=y
251
+CONFIG_UNEXPAND=y
252
+CONFIG_EXPR=y
253
+CONFIG_EXPR_MATH_SUPPORT_64=y
254
+# CONFIG_FACTOR is not set
255
+CONFIG_FALSE=y
256
+CONFIG_FOLD=y
257
+CONFIG_HEAD=y
258
+CONFIG_FEATURE_FANCY_HEAD=y
259
+CONFIG_HOSTID=y
260
+CONFIG_ID=y
261
+CONFIG_GROUPS=y
262
+CONFIG_INSTALL=y
263
+CONFIG_FEATURE_INSTALL_LONG_OPTIONS=y
264
+CONFIG_LINK=y
265
+CONFIG_LN=y
266
+# CONFIG_LOGNAME is not set
267
+CONFIG_LS=y
268
+CONFIG_FEATURE_LS_FILETYPES=y
269
+CONFIG_FEATURE_LS_FOLLOWLINKS=y
270
+CONFIG_FEATURE_LS_RECURSIVE=y
271
+CONFIG_FEATURE_LS_WIDTH=y
272
+CONFIG_FEATURE_LS_SORTFILES=y
273
+CONFIG_FEATURE_LS_TIMESTAMPS=y
274
+CONFIG_FEATURE_LS_USERNAME=y
275
+CONFIG_FEATURE_LS_COLOR=y
276
+CONFIG_FEATURE_LS_COLOR_IS_DEFAULT=y
277
+# CONFIG_MD5SUM is not set
278
+# CONFIG_SHA1SUM is not set
279
+# CONFIG_SHA256SUM is not set
280
+# CONFIG_SHA512SUM is not set
281
+# CONFIG_SHA3SUM is not set
282
+# CONFIG_FEATURE_MD5_SHA1_SUM_CHECK is not set
283
+CONFIG_MKDIR=y
284
+CONFIG_MKFIFO=y
285
+CONFIG_MKNOD=y
286
+CONFIG_MKTEMP=y
287
+CONFIG_MV=y
288
+CONFIG_NICE=y
289
+CONFIG_NL=y
290
+CONFIG_NOHUP=y
291
+CONFIG_NPROC=y
292
+CONFIG_OD=y
293
+CONFIG_PASTE=y
294
+# CONFIG_PRINTENV is not set
295
+# CONFIG_PRINTF is not set
296
+CONFIG_PWD=y
297
+CONFIG_READLINK=y
298
+CONFIG_FEATURE_READLINK_FOLLOW=y
299
+CONFIG_REALPATH=y
300
+CONFIG_RM=y
301
+CONFIG_RMDIR=y
302
+CONFIG_SEQ=y
303
+CONFIG_SHRED=y
304
+CONFIG_SHUF=y
305
+CONFIG_SLEEP=y
306
+CONFIG_FEATURE_FANCY_SLEEP=y
307
+CONFIG_SORT=y
308
+# CONFIG_FEATURE_SORT_BIG is not set
309
+# CONFIG_FEATURE_SORT_OPTIMIZE_MEMORY is not set
310
+CONFIG_SPLIT=y
311
+CONFIG_FEATURE_SPLIT_FANCY=y
312
+CONFIG_STAT=y
313
+CONFIG_FEATURE_STAT_FORMAT=y
314
+CONFIG_FEATURE_STAT_FILESYSTEM=y
315
+CONFIG_STTY=y
316
+# CONFIG_SUM is not set
317
+CONFIG_SYNC=y
318
+CONFIG_FEATURE_SYNC_FANCY=y
319
+CONFIG_FSYNC=y
320
+CONFIG_TAC=y
321
+CONFIG_TAIL=y
322
+CONFIG_FEATURE_FANCY_TAIL=y
323
+CONFIG_TEE=y
324
+CONFIG_FEATURE_TEE_USE_BLOCK_IO=y
325
+# CONFIG_TEST is not set
326
+# CONFIG_TEST1 is not set
327
+# CONFIG_TEST2 is not set
328
+# CONFIG_FEATURE_TEST_64 is not set
329
+CONFIG_TIMEOUT=y
330
+CONFIG_TOUCH=y
331
+CONFIG_FEATURE_TOUCH_SUSV3=y
332
+CONFIG_TR=y
333
+CONFIG_FEATURE_TR_CLASSES=y
334
+CONFIG_FEATURE_TR_EQUIV=y
335
+CONFIG_TRUE=y
336
+CONFIG_TRUNCATE=y
337
+CONFIG_TTY=y
338
+CONFIG_UNAME=y
339
+CONFIG_UNAME_OSNAME="GNU/Linux"
340
+CONFIG_BB_ARCH=y
341
+CONFIG_UNIQ=y
342
+CONFIG_UNLINK=y
343
+CONFIG_USLEEP=y
344
+CONFIG_UUDECODE=y
345
+CONFIG_BASE32=y
346
+CONFIG_BASE64=y
347
+CONFIG_UUENCODE=y
348
+CONFIG_WC=y
349
+CONFIG_FEATURE_WC_LARGE=y
350
+CONFIG_WHO=y
351
+CONFIG_W=y
352
+CONFIG_USERS=y
353
+CONFIG_WHOAMI=y
354
+CONFIG_YES=y
355
+
356
+#
357
+# Console Utilities
358
+#
359
+# CONFIG_CHVT is not set
360
+CONFIG_CLEAR=y
361
+# CONFIG_DEALLOCVT is not set
362
+# CONFIG_DUMPKMAP is not set
363
+# CONFIG_FGCONSOLE is not set
364
+# CONFIG_KBD_MODE is not set
365
+# CONFIG_LOADFONT is not set
366
+# CONFIG_SETFONT is not set
367
+# CONFIG_FEATURE_SETFONT_TEXTUAL_MAP is not set
368
+CONFIG_DEFAULT_SETFONT_DIR=""
369
+# CONFIG_FEATURE_LOADFONT_PSF2 is not set
370
+# CONFIG_FEATURE_LOADFONT_RAW is not set
371
+# CONFIG_LOADKMAP is not set
372
+# CONFIG_OPENVT is not set
373
+# CONFIG_RESET is not set
374
+# CONFIG_RESIZE is not set
375
+# CONFIG_FEATURE_RESIZE_PRINT is not set
376
+# CONFIG_SETCONSOLE is not set
377
+# CONFIG_FEATURE_SETCONSOLE_LONG_OPTIONS is not set
378
+# CONFIG_SETKEYCODES is not set
379
+# CONFIG_SETLOGCONS is not set
380
+# CONFIG_SHOWKEY is not set
381
+
382
+#
383
+# Debian Utilities
384
+#
385
+# CONFIG_PIPE_PROGRESS is not set
386
+# CONFIG_RUN_PARTS is not set
387
+# CONFIG_FEATURE_RUN_PARTS_LONG_OPTIONS is not set
388
+# CONFIG_FEATURE_RUN_PARTS_FANCY is not set
389
+# CONFIG_START_STOP_DAEMON is not set
390
+# CONFIG_FEATURE_START_STOP_DAEMON_LONG_OPTIONS is not set
391
+# CONFIG_FEATURE_START_STOP_DAEMON_FANCY is not set
392
+CONFIG_WHICH=y
393
+
394
+#
395
+# klibc-utils
396
+#
397
+# CONFIG_MINIPS is not set
398
+# CONFIG_NUKE is not set
399
+# CONFIG_RESUME is not set
400
+# CONFIG_RUN_INIT is not set
401
+
402
+#
403
+# Editors
404
+#
405
+# CONFIG_AWK is not set
406
+# CONFIG_FEATURE_AWK_LIBM is not set
407
+# CONFIG_FEATURE_AWK_GNU_EXTENSIONS is not set
408
+# CONFIG_CMP is not set
409
+CONFIG_DIFF=y
410
+CONFIG_FEATURE_DIFF_LONG_OPTIONS=y
411
+CONFIG_FEATURE_DIFF_DIR=y
412
+# CONFIG_ED is not set
413
+CONFIG_PATCH=y
414
+CONFIG_SED=y
415
+CONFIG_VI=y
416
+CONFIG_FEATURE_VI_MAX_LEN=4096
417
+# CONFIG_FEATURE_VI_8BIT is not set
418
+CONFIG_FEATURE_VI_COLON=y
419
+CONFIG_FEATURE_VI_COLON_EXPAND=y
420
+CONFIG_FEATURE_VI_YANKMARK=y
421
+CONFIG_FEATURE_VI_SEARCH=y
422
+# CONFIG_FEATURE_VI_REGEX_SEARCH is not set
423
+CONFIG_FEATURE_VI_USE_SIGNALS=y
424
+CONFIG_FEATURE_VI_DOT_CMD=y
425
+CONFIG_FEATURE_VI_READONLY=y
426
+CONFIG_FEATURE_VI_SETOPTS=y
427
+CONFIG_FEATURE_VI_SET=y
428
+CONFIG_FEATURE_VI_WIN_RESIZE=y
429
+CONFIG_FEATURE_VI_ASK_TERMINAL=y
430
+CONFIG_FEATURE_VI_UNDO=y
431
+CONFIG_FEATURE_VI_UNDO_QUEUE=y
432
+CONFIG_FEATURE_VI_UNDO_QUEUE_MAX=256
433
+CONFIG_FEATURE_VI_VERBOSE_STATUS=y
434
+CONFIG_FEATURE_ALLOW_EXEC=y
435
+
436
+#
437
+# Finding Utilities
438
+#
439
+CONFIG_FIND=y
440
+CONFIG_FEATURE_FIND_PRINT0=y
441
+CONFIG_FEATURE_FIND_MTIME=y
442
+CONFIG_FEATURE_FIND_ATIME=y
443
+CONFIG_FEATURE_FIND_CTIME=y
444
+CONFIG_FEATURE_FIND_MMIN=y
445
+CONFIG_FEATURE_FIND_AMIN=y
446
+CONFIG_FEATURE_FIND_CMIN=y
447
+CONFIG_FEATURE_FIND_PERM=y
448
+CONFIG_FEATURE_FIND_TYPE=y
449
+CONFIG_FEATURE_FIND_EXECUTABLE=y
450
+CONFIG_FEATURE_FIND_XDEV=y
451
+CONFIG_FEATURE_FIND_MAXDEPTH=y
452
+CONFIG_FEATURE_FIND_NEWER=y
453
+CONFIG_FEATURE_FIND_INUM=y
454
+CONFIG_FEATURE_FIND_SAMEFILE=y
455
+CONFIG_FEATURE_FIND_EXEC=y
456
+CONFIG_FEATURE_FIND_EXEC_PLUS=y
457
+CONFIG_FEATURE_FIND_USER=y
458
+CONFIG_FEATURE_FIND_GROUP=y
459
+CONFIG_FEATURE_FIND_NOT=y
460
+CONFIG_FEATURE_FIND_DEPTH=y
461
+CONFIG_FEATURE_FIND_PAREN=y
462
+CONFIG_FEATURE_FIND_SIZE=y
463
+CONFIG_FEATURE_FIND_PRUNE=y
464
+CONFIG_FEATURE_FIND_QUIT=y
465
+CONFIG_FEATURE_FIND_DELETE=y
466
+CONFIG_FEATURE_FIND_EMPTY=y
467
+CONFIG_FEATURE_FIND_PATH=y
468
+CONFIG_FEATURE_FIND_REGEX=y
469
+# CONFIG_FEATURE_FIND_CONTEXT is not set
470
+CONFIG_FEATURE_FIND_LINKS=y
471
+CONFIG_GREP=y
472
+# CONFIG_EGREP is not set
473
+# CONFIG_FGREP is not set
474
+CONFIG_FEATURE_GREP_CONTEXT=y
475
+CONFIG_XARGS=y
476
+CONFIG_FEATURE_XARGS_SUPPORT_CONFIRMATION=y
477
+CONFIG_FEATURE_XARGS_SUPPORT_QUOTES=y
478
+CONFIG_FEATURE_XARGS_SUPPORT_TERMOPT=y
479
+CONFIG_FEATURE_XARGS_SUPPORT_ZERO_TERM=y
480
+CONFIG_FEATURE_XARGS_SUPPORT_REPL_STR=y
481
+CONFIG_FEATURE_XARGS_SUPPORT_PARALLEL=y
482
+CONFIG_FEATURE_XARGS_SUPPORT_ARGS_FILE=y
483
+
484
+#
485
+# Init Utilities
486
+#
487
+# CONFIG_BOOTCHARTD is not set
488
+# CONFIG_FEATURE_BOOTCHARTD_BLOATED_HEADER is not set
489
+# CONFIG_FEATURE_BOOTCHARTD_CONFIG_FILE is not set
490
+# CONFIG_HALT is not set
491
+# CONFIG_POWEROFF is not set
492
+# CONFIG_REBOOT is not set
493
+# CONFIG_FEATURE_WAIT_FOR_INIT is not set
494
+# CONFIG_FEATURE_CALL_TELINIT is not set
495
+CONFIG_TELINIT_PATH=""
496
+# CONFIG_INIT is not set
497
+# CONFIG_LINUXRC is not set
498
+# CONFIG_FEATURE_USE_INITTAB is not set
499
+# CONFIG_FEATURE_KILL_REMOVED is not set
500
+CONFIG_FEATURE_KILL_DELAY=0
501
+# CONFIG_FEATURE_INIT_SCTTY is not set
502
+# CONFIG_FEATURE_INIT_SYSLOG is not set
503
+# CONFIG_FEATURE_INIT_QUIET is not set
504
+# CONFIG_FEATURE_INIT_COREDUMPS is not set
505
+CONFIG_INIT_TERMINAL_TYPE=""
506
+# CONFIG_FEATURE_INIT_MODIFY_CMDLINE is not set
507
+
508
+#
509
+# Login/Password Management Utilities
510
+#
511
+# CONFIG_FEATURE_SHADOWPASSWDS is not set
512
+CONFIG_USE_BB_PWD_GRP=y
513
+# CONFIG_USE_BB_SHADOW is not set
514
+CONFIG_USE_BB_CRYPT=y
515
+CONFIG_USE_BB_CRYPT_SHA=y
516
+# CONFIG_ADD_SHELL is not set
517
+# CONFIG_REMOVE_SHELL is not set
518
+CONFIG_ADDGROUP=y
519
+# CONFIG_FEATURE_ADDUSER_TO_GROUP is not set
520
+CONFIG_ADDUSER=y
521
+# CONFIG_FEATURE_CHECK_NAMES is not set
522
+CONFIG_LAST_ID=60000
523
+CONFIG_FIRST_SYSTEM_ID=100
524
+CONFIG_LAST_SYSTEM_ID=999
525
+# CONFIG_CHPASSWD is not set
526
+CONFIG_FEATURE_DEFAULT_PASSWD_ALGO=""
527
+# CONFIG_CRYPTPW is not set
528
+# CONFIG_MKPASSWD is not set
529
+# CONFIG_DELUSER is not set
530
+# CONFIG_DELGROUP is not set
531
+# CONFIG_FEATURE_DEL_USER_FROM_GROUP is not set
532
+# CONFIG_GETTY is not set
533
+# CONFIG_LOGIN is not set
534
+# CONFIG_LOGIN_SESSION_AS_CHILD is not set
535
+# CONFIG_LOGIN_SCRIPTS is not set
536
+# CONFIG_FEATURE_NOLOGIN is not set
537
+# CONFIG_FEATURE_SECURETTY is not set
538
+# CONFIG_PASSWD is not set
539
+# CONFIG_FEATURE_PASSWD_WEAK_CHECK is not set
540
+# CONFIG_SU is not set
541
+# CONFIG_FEATURE_SU_SYSLOG is not set
542
+# CONFIG_FEATURE_SU_CHECKS_SHELLS is not set
543
+# CONFIG_FEATURE_SU_BLANK_PW_NEEDS_SECURE_TTY is not set
544
+# CONFIG_SULOGIN is not set
545
+# CONFIG_VLOCK is not set
546
+
547
+#
548
+# Linux Ext2 FS Progs
549
+#
550
+# CONFIG_CHATTR is not set
551
+# CONFIG_FSCK is not set
552
+# CONFIG_LSATTR is not set
553
+# CONFIG_TUNE2FS is not set
554
+
555
+#
556
+# Linux Module Utilities
557
+#
558
+# CONFIG_MODPROBE_SMALL is not set
559
+# CONFIG_DEPMOD is not set
560
+# CONFIG_INSMOD is not set
561
+# CONFIG_LSMOD is not set
562
+# CONFIG_FEATURE_LSMOD_PRETTY_2_6_OUTPUT is not set
563
+# CONFIG_MODINFO is not set
564
+# CONFIG_MODPROBE is not set
565
+# CONFIG_FEATURE_MODPROBE_BLACKLIST is not set
566
+# CONFIG_RMMOD is not set
567
+
568
+#
569
+# Options common to multiple modutils
570
+#
571
+# CONFIG_FEATURE_CMDLINE_MODULE_OPTIONS is not set
572
+# CONFIG_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED is not set
573
+# CONFIG_FEATURE_2_4_MODULES is not set
574
+# CONFIG_FEATURE_INSMOD_VERSION_CHECKING is not set
575
+# CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS is not set
576
+# CONFIG_FEATURE_INSMOD_LOADINKMEM is not set
577
+# CONFIG_FEATURE_INSMOD_LOAD_MAP is not set
578
+# CONFIG_FEATURE_INSMOD_LOAD_MAP_FULL is not set
579
+# CONFIG_FEATURE_CHECK_TAINTED_MODULE is not set
580
+# CONFIG_FEATURE_INSMOD_TRY_MMAP is not set
581
+# CONFIG_FEATURE_MODUTILS_ALIAS is not set
582
+# CONFIG_FEATURE_MODUTILS_SYMBOLS is not set
583
+CONFIG_DEFAULT_MODULES_DIR=""
584
+CONFIG_DEFAULT_DEPMOD_FILE=""
585
+
586
+#
587
+# Linux System Utilities
588
+#
589
+# CONFIG_ACPID is not set
590
+# CONFIG_FEATURE_ACPID_COMPAT is not set
591
+# CONFIG_BLKDISCARD is not set
592
+# CONFIG_BLKID is not set
593
+# CONFIG_FEATURE_BLKID_TYPE is not set
594
+# CONFIG_BLOCKDEV is not set
595
+# CONFIG_CAL is not set
596
+# CONFIG_CHRT is not set
597
+# CONFIG_DMESG is not set
598
+# CONFIG_FEATURE_DMESG_PRETTY is not set
599
+# CONFIG_EJECT is not set
600
+# CONFIG_FEATURE_EJECT_SCSI is not set
601
+# CONFIG_FALLOCATE is not set
602
+# CONFIG_FATATTR is not set
603
+# CONFIG_FBSET is not set
604
+# CONFIG_FEATURE_FBSET_FANCY is not set
605
+# CONFIG_FEATURE_FBSET_READMODE is not set
606
+# CONFIG_FDFORMAT is not set
607
+# CONFIG_FDISK is not set
608
+# CONFIG_FDISK_SUPPORT_LARGE_DISKS is not set
609
+# CONFIG_FEATURE_FDISK_WRITABLE is not set
610
+# CONFIG_FEATURE_AIX_LABEL is not set
611
+# CONFIG_FEATURE_SGI_LABEL is not set
612
+# CONFIG_FEATURE_SUN_LABEL is not set
613
+# CONFIG_FEATURE_OSF_LABEL is not set
614
+# CONFIG_FEATURE_GPT_LABEL is not set
615
+# CONFIG_FEATURE_FDISK_ADVANCED is not set
616
+# CONFIG_FINDFS is not set
617
+# CONFIG_FLOCK is not set
618
+# CONFIG_FDFLUSH is not set
619
+# CONFIG_FREERAMDISK is not set
620
+# CONFIG_FSCK_MINIX is not set
621
+# CONFIG_FSFREEZE is not set
622
+# CONFIG_FSTRIM is not set
623
+# CONFIG_GETOPT is not set
624
+# CONFIG_FEATURE_GETOPT_LONG is not set
625
+CONFIG_HEXDUMP=y
626
+CONFIG_HD=y
627
+CONFIG_XXD=y
628
+# CONFIG_HWCLOCK is not set
629
+# CONFIG_FEATURE_HWCLOCK_ADJTIME_FHS is not set
630
+# CONFIG_IONICE is not set
631
+# CONFIG_IPCRM is not set
632
+# CONFIG_IPCS is not set
633
+# CONFIG_LAST is not set
634
+# CONFIG_FEATURE_LAST_FANCY is not set
635
+# CONFIG_LOSETUP is not set
636
+# CONFIG_LSPCI is not set
637
+# CONFIG_LSUSB is not set
638
+# CONFIG_MDEV is not set
639
+# CONFIG_FEATURE_MDEV_CONF is not set
640
+# CONFIG_FEATURE_MDEV_RENAME is not set
641
+# CONFIG_FEATURE_MDEV_RENAME_REGEXP is not set
642
+# CONFIG_FEATURE_MDEV_EXEC is not set
643
+# CONFIG_FEATURE_MDEV_LOAD_FIRMWARE is not set
644
+# CONFIG_FEATURE_MDEV_DAEMON is not set
645
+# CONFIG_MESG is not set
646
+# CONFIG_FEATURE_MESG_ENABLE_ONLY_GROUP is not set
647
+# CONFIG_MKE2FS is not set
648
+# CONFIG_MKFS_EXT2 is not set
649
+# CONFIG_MKFS_MINIX is not set
650
+# CONFIG_FEATURE_MINIX2 is not set
651
+# CONFIG_MKFS_REISER is not set
652
+# CONFIG_MKDOSFS is not set
653
+# CONFIG_MKFS_VFAT is not set
654
+# CONFIG_MKSWAP is not set
655
+# CONFIG_FEATURE_MKSWAP_UUID is not set
656
+CONFIG_MORE=y
657
+CONFIG_MOUNT=y
658
+CONFIG_FEATURE_MOUNT_FAKE=y
659
+CONFIG_FEATURE_MOUNT_VERBOSE=y
660
+# CONFIG_FEATURE_MOUNT_HELPERS is not set
661
+# CONFIG_FEATURE_MOUNT_LABEL is not set
662
+# CONFIG_FEATURE_MOUNT_NFS is not set
663
+# CONFIG_FEATURE_MOUNT_CIFS is not set
664
+CONFIG_FEATURE_MOUNT_FLAGS=y
665
+CONFIG_FEATURE_MOUNT_FSTAB=y
666
+CONFIG_FEATURE_MOUNT_OTHERTAB=y
667
+# CONFIG_MOUNTPOINT is not set
668
+CONFIG_NOLOGIN=y
669
+# CONFIG_NOLOGIN_DEPENDENCIES is not set
670
+# CONFIG_NSENTER is not set
671
+# CONFIG_PIVOT_ROOT is not set
672
+# CONFIG_RDATE is not set
673
+# CONFIG_RDEV is not set
674
+# CONFIG_READPROFILE is not set
675
+CONFIG_RENICE=y
676
+CONFIG_REV=y
677
+# CONFIG_RTCWAKE is not set
678
+# CONFIG_SCRIPT is not set
679
+# CONFIG_SCRIPTREPLAY is not set
680
+# CONFIG_SETARCH is not set
681
+# CONFIG_LINUX32 is not set
682
+# CONFIG_LINUX64 is not set
683
+# CONFIG_SETPRIV is not set
684
+# CONFIG_FEATURE_SETPRIV_DUMP is not set
685
+# CONFIG_FEATURE_SETPRIV_CAPABILITIES is not set
686
+# CONFIG_FEATURE_SETPRIV_CAPABILITY_NAMES is not set
687
+# CONFIG_SETSID is not set
688
+# CONFIG_SWAPON is not set
689
+# CONFIG_FEATURE_SWAPON_DISCARD is not set
690
+# CONFIG_FEATURE_SWAPON_PRI is not set
691
+# CONFIG_SWAPOFF is not set
692
+# CONFIG_FEATURE_SWAPONOFF_LABEL is not set
693
+# CONFIG_SWITCH_ROOT is not set
694
+# CONFIG_TASKSET is not set
695
+# CONFIG_FEATURE_TASKSET_FANCY is not set
696
+# CONFIG_FEATURE_TASKSET_CPULIST is not set
697
+# CONFIG_UEVENT is not set
698
+CONFIG_UMOUNT=y
699
+CONFIG_FEATURE_UMOUNT_ALL=y
700
+# CONFIG_UNSHARE is not set
701
+# CONFIG_WALL is not set
702
+
703
+#
704
+# Common options for mount/umount
705
+#
706
+# CONFIG_FEATURE_MOUNT_LOOP is not set
707
+# CONFIG_FEATURE_MOUNT_LOOP_CREATE is not set
708
+# CONFIG_FEATURE_MTAB_SUPPORT is not set
709
+# CONFIG_VOLUMEID is not set
710
+# CONFIG_FEATURE_VOLUMEID_BCACHE is not set
711
+# CONFIG_FEATURE_VOLUMEID_BTRFS is not set
712
+# CONFIG_FEATURE_VOLUMEID_CRAMFS is not set
713
+# CONFIG_FEATURE_VOLUMEID_EROFS is not set
714
+# CONFIG_FEATURE_VOLUMEID_EXFAT is not set
715
+# CONFIG_FEATURE_VOLUMEID_EXT is not set
716
+# CONFIG_FEATURE_VOLUMEID_F2FS is not set
717
+# CONFIG_FEATURE_VOLUMEID_FAT is not set
718
+# CONFIG_FEATURE_VOLUMEID_HFS is not set
719
+# CONFIG_FEATURE_VOLUMEID_ISO9660 is not set
720
+# CONFIG_FEATURE_VOLUMEID_JFS is not set
721
+# CONFIG_FEATURE_VOLUMEID_LFS is not set
722
+# CONFIG_FEATURE_VOLUMEID_LINUXRAID is not set
723
+# CONFIG_FEATURE_VOLUMEID_LINUXSWAP is not set
724
+# CONFIG_FEATURE_VOLUMEID_LUKS is not set
725
+# CONFIG_FEATURE_VOLUMEID_MINIX is not set
726
+# CONFIG_FEATURE_VOLUMEID_NILFS is not set
727
+# CONFIG_FEATURE_VOLUMEID_NTFS is not set
728
+# CONFIG_FEATURE_VOLUMEID_OCFS2 is not set
729
+# CONFIG_FEATURE_VOLUMEID_REISERFS is not set
730
+# CONFIG_FEATURE_VOLUMEID_ROMFS is not set
731
+# CONFIG_FEATURE_VOLUMEID_SQUASHFS is not set
732
+# CONFIG_FEATURE_VOLUMEID_SYSV is not set
733
+# CONFIG_FEATURE_VOLUMEID_UBIFS is not set
734
+# CONFIG_FEATURE_VOLUMEID_UDF is not set
735
+# CONFIG_FEATURE_VOLUMEID_XFS is not set
736
+
737
+#
738
+# Miscellaneous Utilities
739
+#
740
+# CONFIG_ADJTIMEX is not set
741
+# CONFIG_ASCII is not set
742
+# CONFIG_BBCONFIG is not set
743
+# CONFIG_FEATURE_COMPRESS_BBCONFIG is not set
744
+CONFIG_BC=y
745
+# CONFIG_DC is not set
746
+CONFIG_FEATURE_DC_BIG=y
747
+# CONFIG_FEATURE_DC_LIBM is not set
748
+# CONFIG_FEATURE_BC_INTERACTIVE is not set
749
+# CONFIG_FEATURE_BC_LONG_OPTIONS is not set
750
+# CONFIG_BEEP is not set
751
+CONFIG_FEATURE_BEEP_FREQ=0
752
+CONFIG_FEATURE_BEEP_LENGTH_MS=0
753
+# CONFIG_CHAT is not set
754
+# CONFIG_FEATURE_CHAT_NOFAIL is not set
755
+# CONFIG_FEATURE_CHAT_TTY_HIFI is not set
756
+# CONFIG_FEATURE_CHAT_IMPLICIT_CR is not set
757
+# CONFIG_FEATURE_CHAT_SWALLOW_OPTS is not set
758
+# CONFIG_FEATURE_CHAT_SEND_ESCAPES is not set
759
+# CONFIG_FEATURE_CHAT_VAR_ABORT_LEN is not set
760
+# CONFIG_FEATURE_CHAT_CLR_ABORT is not set
761
+# CONFIG_CONSPY is not set
762
+CONFIG_CROND=y
763
+CONFIG_FEATURE_CROND_D=y
764
+CONFIG_FEATURE_CROND_CALL_SENDMAIL=y
765
+CONFIG_FEATURE_CROND_SPECIAL_TIMES=y
766
+CONFIG_FEATURE_CROND_DIR="/var/spool/cron"
767
+CONFIG_CRONTAB=y
768
+# CONFIG_DEVFSD is not set
769
+# CONFIG_DEVFSD_MODLOAD is not set
770
+# CONFIG_DEVFSD_FG_NP is not set
771
+# CONFIG_DEVFSD_VERBOSE is not set
772
+# CONFIG_FEATURE_DEVFS is not set
773
+# CONFIG_DEVMEM is not set
774
+# CONFIG_FBSPLASH is not set
775
+# CONFIG_FLASH_ERASEALL is not set
776
+# CONFIG_FLASH_LOCK is not set
777
+# CONFIG_FLASH_UNLOCK is not set
778
+# CONFIG_FLASHCP is not set
779
+# CONFIG_HDPARM is not set
780
+# CONFIG_FEATURE_HDPARM_GET_IDENTITY is not set
781
+# CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF is not set
782
+# CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF is not set
783
+# CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET is not set
784
+# CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF is not set
785
+# CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA is not set
786
+CONFIG_HEXEDIT=y
787
+# CONFIG_I2CGET is not set
788
+# CONFIG_I2CSET is not set
789
+# CONFIG_I2CDUMP is not set
790
+# CONFIG_I2CDETECT is not set
791
+# CONFIG_I2CTRANSFER is not set
792
+# CONFIG_INOTIFYD is not set
793
+CONFIG_LESS=y
794
+CONFIG_FEATURE_LESS_MAXLINES=9999999
795
+CONFIG_FEATURE_LESS_BRACKETS=y
796
+CONFIG_FEATURE_LESS_FLAGS=y
797
+CONFIG_FEATURE_LESS_TRUNCATE=y
798
+CONFIG_FEATURE_LESS_MARKS=y
799
+CONFIG_FEATURE_LESS_REGEXP=y
800
+CONFIG_FEATURE_LESS_WINCH=y
801
+CONFIG_FEATURE_LESS_ASK_TERMINAL=y
802
+CONFIG_FEATURE_LESS_DASHCMD=y
803
+CONFIG_FEATURE_LESS_LINENUMS=y
804
+CONFIG_FEATURE_LESS_RAW=y
805
+CONFIG_FEATURE_LESS_ENV=y
806
+# CONFIG_LSSCSI is not set
807
+# CONFIG_MAKEDEVS is not set
808
+# CONFIG_FEATURE_MAKEDEVS_LEAF is not set
809
+# CONFIG_FEATURE_MAKEDEVS_TABLE is not set
810
+# CONFIG_MAN is not set
811
+# CONFIG_MICROCOM is not set
812
+# CONFIG_MIM is not set
813
+# CONFIG_MT is not set
814
+# CONFIG_NANDWRITE is not set
815
+# CONFIG_NANDDUMP is not set
816
+# CONFIG_PARTPROBE is not set
817
+# CONFIG_RAIDAUTORUN is not set
818
+# CONFIG_READAHEAD is not set
819
+# CONFIG_RFKILL is not set
820
+# CONFIG_RUNLEVEL is not set
821
+# CONFIG_RX is not set
822
+# CONFIG_SETFATTR is not set
823
+# CONFIG_SETSERIAL is not set
824
+CONFIG_STRINGS=y
825
+CONFIG_TIME=y
826
+# CONFIG_TS is not set
827
+# CONFIG_TTYSIZE is not set
828
+# CONFIG_UBIATTACH is not set
829
+# CONFIG_UBIDETACH is not set
830
+# CONFIG_UBIMKVOL is not set
831
+# CONFIG_UBIRMVOL is not set
832
+# CONFIG_UBIRSVOL is not set
833
+# CONFIG_UBIUPDATEVOL is not set
834
+# CONFIG_UBIRENAME is not set
835
+# CONFIG_VOLNAME is not set
836
+# CONFIG_WATCHDOG is not set
837
+# CONFIG_FEATURE_WATCHDOG_OPEN_TWICE is not set
838
+
839
+#
840
+# Networking Utilities
841
+#
842
+CONFIG_FEATURE_IPV6=y
843
+# CONFIG_FEATURE_UNIX_LOCAL is not set
844
+CONFIG_FEATURE_PREFER_IPV4_ADDRESS=y
845
+# CONFIG_VERBOSE_RESOLUTION_ERRORS is not set
846
+# CONFIG_FEATURE_ETC_NETWORKS is not set
847
+# CONFIG_FEATURE_ETC_SERVICES is not set
848
+# CONFIG_FEATURE_HWIB is not set
849
+# CONFIG_FEATURE_TLS_SHA1 is not set
850
+# CONFIG_ARP is not set
851
+# CONFIG_ARPING is not set
852
+# CONFIG_BRCTL is not set
853
+# CONFIG_FEATURE_BRCTL_FANCY is not set
854
+# CONFIG_FEATURE_BRCTL_SHOW is not set
855
+# CONFIG_DNSD is not set
856
+# CONFIG_ETHER_WAKE is not set
857
+# CONFIG_FTPD is not set
858
+# CONFIG_FEATURE_FTPD_WRITE is not set
859
+# CONFIG_FEATURE_FTPD_ACCEPT_BROKEN_LIST is not set
860
+# CONFIG_FEATURE_FTPD_AUTHENTICATION is not set
861
+# CONFIG_FTPGET is not set
862
+# CONFIG_FTPPUT is not set
863
+# CONFIG_FEATURE_FTPGETPUT_LONG_OPTIONS is not set
864
+# CONFIG_HOSTNAME is not set
865
+# CONFIG_DNSDOMAINNAME is not set
866
+# CONFIG_HTTPD is not set
867
+CONFIG_FEATURE_HTTPD_PORT_DEFAULT=0
868
+# CONFIG_FEATURE_HTTPD_RANGES is not set
869
+# CONFIG_FEATURE_HTTPD_SETUID is not set
870
+# CONFIG_FEATURE_HTTPD_BASIC_AUTH is not set
871
+# CONFIG_FEATURE_HTTPD_AUTH_MD5 is not set
872
+# CONFIG_FEATURE_HTTPD_CGI is not set
873
+# CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR is not set
874
+# CONFIG_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV is not set
875
+# CONFIG_FEATURE_HTTPD_ENCODE_URL_STR is not set
876
+# CONFIG_FEATURE_HTTPD_ERROR_PAGES is not set
877
+# CONFIG_FEATURE_HTTPD_PROXY is not set
878
+# CONFIG_FEATURE_HTTPD_GZIP is not set
879
+# CONFIG_FEATURE_HTTPD_ETAG is not set
880
+# CONFIG_FEATURE_HTTPD_LAST_MODIFIED is not set
881
+# CONFIG_FEATURE_HTTPD_DATE is not set
882
+# CONFIG_FEATURE_HTTPD_ACL_IP is not set
883
+CONFIG_IFCONFIG=y
884
+CONFIG_FEATURE_IFCONFIG_STATUS=y
885
+# CONFIG_FEATURE_IFCONFIG_SLIP is not set
886
+CONFIG_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ=y
887
+CONFIG_FEATURE_IFCONFIG_HW=y
888
+CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS=y
889
+# CONFIG_IFENSLAVE is not set
890
+# CONFIG_IFPLUGD is not set
891
+# CONFIG_IFUP is not set
892
+# CONFIG_IFDOWN is not set
893
+CONFIG_IFUPDOWN_IFSTATE_PATH=""
894
+# CONFIG_FEATURE_IFUPDOWN_IP is not set
895
+# CONFIG_FEATURE_IFUPDOWN_IPV4 is not set
896
+# CONFIG_FEATURE_IFUPDOWN_IPV6 is not set
897
+# CONFIG_FEATURE_IFUPDOWN_MAPPING is not set
898
+# CONFIG_FEATURE_IFUPDOWN_EXTERNAL_DHCP is not set
899
+CONFIG_INETD=y
900
+# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_ECHO is not set
901
+# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DISCARD is not set
902
+# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_TIME is not set
903
+# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DAYTIME is not set
904
+# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_CHARGEN is not set
905
+# CONFIG_FEATURE_INETD_RPC is not set
906
+CONFIG_IP=y
907
+# CONFIG_IPADDR is not set
908
+# CONFIG_IPLINK is not set
909
+# CONFIG_IPROUTE is not set
910
+# CONFIG_IPTUNNEL is not set
911
+# CONFIG_IPRULE is not set
912
+# CONFIG_IPNEIGH is not set
913
+CONFIG_FEATURE_IP_ADDRESS=y
914
+CONFIG_FEATURE_IP_LINK=y
915
+CONFIG_FEATURE_IP_ROUTE=y
916
+CONFIG_FEATURE_IP_ROUTE_DIR="/etc/iproute2"
917
+# CONFIG_FEATURE_IP_TUNNEL is not set
918
+# CONFIG_FEATURE_IP_RULE is not set
919
+CONFIG_FEATURE_IP_NEIGH=y
920
+# CONFIG_FEATURE_IP_RARE_PROTOCOLS is not set
921
+CONFIG_IPCALC=y
922
+CONFIG_FEATURE_IPCALC_LONG_OPTIONS=y
923
+CONFIG_FEATURE_IPCALC_FANCY=y
924
+# CONFIG_FAKEIDENTD is not set
925
+# CONFIG_NAMEIF is not set
926
+# CONFIG_FEATURE_NAMEIF_EXTENDED is not set
927
+# CONFIG_NBDCLIENT is not set
928
+CONFIG_NC=y
929
+# CONFIG_NETCAT is not set
930
+CONFIG_NC_SERVER=y
931
+CONFIG_NC_EXTRA=y
932
+CONFIG_NC_110_COMPAT=y
933
+# CONFIG_NETSTAT is not set
934
+# CONFIG_FEATURE_NETSTAT_WIDE is not set
935
+# CONFIG_FEATURE_NETSTAT_PRG is not set
936
+# CONFIG_NSLOOKUP is not set
937
+# CONFIG_FEATURE_NSLOOKUP_BIG is not set
938
+# CONFIG_FEATURE_NSLOOKUP_LONG_OPTIONS is not set
939
+# CONFIG_NTPD is not set
940
+# CONFIG_FEATURE_NTPD_SERVER is not set
941
+# CONFIG_FEATURE_NTPD_CONF is not set
942
+# CONFIG_FEATURE_NTP_AUTH is not set
943
+# CONFIG_PING is not set
944
+# CONFIG_PING6 is not set
945
+# CONFIG_FEATURE_FANCY_PING is not set
946
+# CONFIG_PSCAN is not set
947
+CONFIG_ROUTE=y
948
+# CONFIG_SLATTACH is not set
949
+CONFIG_SSL_CLIENT=y
950
+# CONFIG_TC is not set
951
+# CONFIG_FEATURE_TC_INGRESS is not set
952
+# CONFIG_TCPSVD is not set
953
+# CONFIG_UDPSVD is not set
954
+# CONFIG_TELNET is not set
955
+# CONFIG_FEATURE_TELNET_TTYPE is not set
956
+# CONFIG_FEATURE_TELNET_AUTOLOGIN is not set
957
+# CONFIG_FEATURE_TELNET_WIDTH is not set
958
+# CONFIG_TELNETD is not set
959
+# CONFIG_FEATURE_TELNETD_STANDALONE is not set
960
+CONFIG_FEATURE_TELNETD_PORT_DEFAULT=0
961
+# CONFIG_FEATURE_TELNETD_INETD_WAIT is not set
962
+# CONFIG_TFTP is not set
963
+# CONFIG_FEATURE_TFTP_PROGRESS_BAR is not set
964
+# CONFIG_FEATURE_TFTP_HPA_COMPAT is not set
965
+# CONFIG_TFTPD is not set
966
+# CONFIG_FEATURE_TFTP_GET is not set
967
+# CONFIG_FEATURE_TFTP_PUT is not set
968
+# CONFIG_FEATURE_TFTP_BLOCKSIZE is not set
969
+# CONFIG_TFTP_DEBUG is not set
970
+CONFIG_TLS=y
971
+# CONFIG_TRACEROUTE is not set
972
+# CONFIG_TRACEROUTE6 is not set
973
+# CONFIG_FEATURE_TRACEROUTE_VERBOSE is not set
974
+# CONFIG_FEATURE_TRACEROUTE_USE_ICMP is not set
975
+# CONFIG_TUNCTL is not set
976
+# CONFIG_FEATURE_TUNCTL_UG is not set
977
+# CONFIG_VCONFIG is not set
978
+CONFIG_WGET=y
979
+CONFIG_FEATURE_WGET_LONG_OPTIONS=y
980
+CONFIG_FEATURE_WGET_STATUSBAR=y
981
+CONFIG_FEATURE_WGET_FTP=y
982
+CONFIG_FEATURE_WGET_AUTHENTICATION=y
983
+CONFIG_FEATURE_WGET_TIMEOUT=y
984
+CONFIG_FEATURE_WGET_HTTPS=y
985
+CONFIG_FEATURE_WGET_OPENSSL=y
986
+CONFIG_WHOIS=y
987
+# CONFIG_ZCIP is not set
988
+# CONFIG_UDHCPD is not set
989
+# CONFIG_FEATURE_UDHCPD_BASE_IP_ON_MAC is not set
990
+# CONFIG_FEATURE_UDHCPD_WRITE_LEASES_EARLY is not set
991
+CONFIG_DHCPD_LEASES_FILE=""
992
+# CONFIG_DUMPLEASES is not set
993
+# CONFIG_DHCPRELAY is not set
994
+# CONFIG_UDHCPC is not set
995
+# CONFIG_FEATURE_UDHCPC_ARPING is not set
996
+# CONFIG_FEATURE_UDHCPC_SANITIZEOPT is not set
997
+CONFIG_UDHCPC_DEFAULT_SCRIPT=""
998
+# CONFIG_UDHCPC6 is not set
999
+# CONFIG_FEATURE_UDHCPC6_RFC3646 is not set
1000
+# CONFIG_FEATURE_UDHCPC6_RFC4704 is not set
1001
+# CONFIG_FEATURE_UDHCPC6_RFC4833 is not set
1002
+# CONFIG_FEATURE_UDHCPC6_RFC5970 is not set
1003
+CONFIG_UDHCPC_DEFAULT_INTERFACE=""
1004
+# CONFIG_FEATURE_UDHCP_PORT is not set
1005
+CONFIG_UDHCP_DEBUG=0
1006
+CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS=0
1007
+# CONFIG_FEATURE_UDHCP_RFC3397 is not set
1008
+# CONFIG_FEATURE_UDHCP_8021Q is not set
1009
+CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS=""
1010
+
1011
+#
1012
+# Print Utilities
1013
+#
1014
+# CONFIG_LPD is not set
1015
+# CONFIG_LPR is not set
1016
+# CONFIG_LPQ is not set
1017
+
1018
+#
1019
+# Mail Utilities
1020
+#
1021
+CONFIG_FEATURE_MIME_CHARSET="utf-8"
1022
+# CONFIG_MAKEMIME is not set
1023
+# CONFIG_POPMAILDIR is not set
1024
+# CONFIG_FEATURE_POPMAILDIR_DELIVERY is not set
1025
+# CONFIG_REFORMIME is not set
1026
+# CONFIG_FEATURE_REFORMIME_COMPAT is not set
1027
+CONFIG_SENDMAIL=y
1028
+
1029
+#
1030
+# Process Utilities
1031
+#
1032
+# CONFIG_FEATURE_FAST_TOP is not set
1033
+CONFIG_FEATURE_SHOW_THREADS=y
1034
+CONFIG_FREE=y
1035
+CONFIG_FUSER=y
1036
+CONFIG_IOSTAT=y
1037
+CONFIG_KILL=y
1038
+CONFIG_KILLALL=y
1039
+# CONFIG_KILLALL5 is not set
1040
+CONFIG_LSOF=y
1041
+CONFIG_MPSTAT=y
1042
+CONFIG_NMETER=y
1043
+CONFIG_PGREP=y
1044
+CONFIG_PKILL=y
1045
+CONFIG_PIDOF=y
1046
+CONFIG_FEATURE_PIDOF_SINGLE=y
1047
+CONFIG_FEATURE_PIDOF_OMIT=y
1048
+CONFIG_PMAP=y
1049
+# CONFIG_POWERTOP is not set
1050
+# CONFIG_FEATURE_POWERTOP_INTERACTIVE is not set
1051
+CONFIG_PS=y
1052
+# CONFIG_FEATURE_PS_WIDE is not set
1053
+# CONFIG_FEATURE_PS_LONG is not set
1054
+CONFIG_FEATURE_PS_TIME=y
1055
+# CONFIG_FEATURE_PS_UNUSUAL_SYSTEMS is not set
1056
+CONFIG_FEATURE_PS_ADDITIONAL_COLUMNS=y
1057
+CONFIG_PSTREE=y
1058
+CONFIG_PWDX=y
1059
+CONFIG_SMEMCAP=y
1060
+CONFIG_BB_SYSCTL=y
1061
+CONFIG_TOP=y
1062
+CONFIG_FEATURE_TOP_INTERACTIVE=y
1063
+CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE=y
1064
+CONFIG_FEATURE_TOP_CPU_GLOBAL_PERCENTS=y
1065
+CONFIG_FEATURE_TOP_SMP_CPU=y
1066
+CONFIG_FEATURE_TOP_DECIMALS=y
1067
+CONFIG_FEATURE_TOP_SMP_PROCESS=y
1068
+CONFIG_FEATURE_TOPMEM=y
1069
+CONFIG_UPTIME=y
1070
+CONFIG_FEATURE_UPTIME_UTMP_SUPPORT=y
1071
+CONFIG_WATCH=y
1072
+
1073
+#
1074
+# Runit Utilities
1075
+#
1076
+CONFIG_CHPST=y
1077
+CONFIG_SETUIDGID=y
1078
+CONFIG_ENVUIDGID=y
1079
+CONFIG_ENVDIR=y
1080
+CONFIG_SOFTLIMIT=y
1081
+CONFIG_RUNSV=y
1082
+CONFIG_RUNSVDIR=y
1083
+# CONFIG_FEATURE_RUNSVDIR_LOG is not set
1084
+CONFIG_SV=y
1085
+CONFIG_SV_DEFAULT_SERVICE_DIR="/var/service"
1086
+CONFIG_SVC=y
1087
+CONFIG_SVOK=y
1088
+CONFIG_SVLOGD=y
1089
+# CONFIG_CHCON is not set
1090
+# CONFIG_GETENFORCE is not set
1091
+# CONFIG_GETSEBOOL is not set
1092
+# CONFIG_LOAD_POLICY is not set
1093
+# CONFIG_MATCHPATHCON is not set
1094
+# CONFIG_RUNCON is not set
1095
+# CONFIG_SELINUXENABLED is not set
1096
+# CONFIG_SESTATUS is not set
1097
+# CONFIG_SETENFORCE is not set
1098
+# CONFIG_SETFILES is not set
1099
+# CONFIG_FEATURE_SETFILES_CHECK_OPTION is not set
1100
+# CONFIG_RESTORECON is not set
1101
+# CONFIG_SETSEBOOL is not set
1102
+
1103
+#
1104
+# Shells
1105
+#
1106
+CONFIG_SH_IS_ASH=y
1107
+# CONFIG_SH_IS_HUSH is not set
1108
+# CONFIG_SH_IS_NONE is not set
1109
+# CONFIG_BASH_IS_ASH is not set
1110
+# CONFIG_BASH_IS_HUSH is not set
1111
+CONFIG_BASH_IS_NONE=y
1112
+CONFIG_SHELL_ASH=y
1113
+CONFIG_ASH=y
1114
+CONFIG_ASH_OPTIMIZE_FOR_SIZE=y
1115
+CONFIG_ASH_INTERNAL_GLOB=y
1116
+CONFIG_ASH_BASH_COMPAT=y
1117
+# CONFIG_ASH_BASH_SOURCE_CURDIR is not set
1118
+CONFIG_ASH_BASH_NOT_FOUND_HOOK=y
1119
+CONFIG_ASH_JOB_CONTROL=y
1120
+CONFIG_ASH_ALIAS=y
1121
+CONFIG_ASH_RANDOM_SUPPORT=y
1122
+CONFIG_ASH_EXPAND_PRMT=y
1123
+CONFIG_ASH_IDLE_TIMEOUT=y
1124
+CONFIG_ASH_MAIL=y
1125
+CONFIG_ASH_ECHO=y
1126
+CONFIG_ASH_PRINTF=y
1127
+CONFIG_ASH_TEST=y
1128
+CONFIG_ASH_HELP=y
1129
+CONFIG_ASH_GETOPTS=y
1130
+CONFIG_ASH_CMDCMD=y
1131
+# CONFIG_CTTYHACK is not set
1132
+# CONFIG_HUSH is not set
1133
+# CONFIG_SHELL_HUSH is not set
1134
+# CONFIG_HUSH_BASH_COMPAT is not set
1135
+# CONFIG_HUSH_BRACE_EXPANSION is not set
1136
+# CONFIG_HUSH_BASH_SOURCE_CURDIR is not set
1137
+# CONFIG_HUSH_LINENO_VAR is not set
1138
+# CONFIG_HUSH_INTERACTIVE is not set
1139
+# CONFIG_HUSH_SAVEHISTORY is not set
1140
+# CONFIG_HUSH_JOB is not set
1141
+# CONFIG_HUSH_TICK is not set
1142
+# CONFIG_HUSH_IF is not set
1143
+# CONFIG_HUSH_LOOPS is not set
1144
+# CONFIG_HUSH_CASE is not set
1145
+# CONFIG_HUSH_FUNCTIONS is not set
1146
+# CONFIG_HUSH_LOCAL is not set
1147
+# CONFIG_HUSH_RANDOM_SUPPORT is not set
1148
+# CONFIG_HUSH_MODE_X is not set
1149
+# CONFIG_HUSH_ECHO is not set
1150
+# CONFIG_HUSH_PRINTF is not set
1151
+# CONFIG_HUSH_TEST is not set
1152
+# CONFIG_HUSH_HELP is not set
1153
+# CONFIG_HUSH_EXPORT is not set
1154
+# CONFIG_HUSH_EXPORT_N is not set
1155
+# CONFIG_HUSH_READONLY is not set
1156
+# CONFIG_HUSH_KILL is not set
1157
+# CONFIG_HUSH_WAIT is not set
1158
+# CONFIG_HUSH_COMMAND is not set
1159
+# CONFIG_HUSH_TRAP is not set
1160
+# CONFIG_HUSH_TYPE is not set
1161
+# CONFIG_HUSH_TIMES is not set
1162
+# CONFIG_HUSH_READ is not set
1163
+# CONFIG_HUSH_SET is not set
1164
+# CONFIG_HUSH_UNSET is not set
1165
+# CONFIG_HUSH_ULIMIT is not set
1166
+# CONFIG_HUSH_UMASK is not set
1167
+# CONFIG_HUSH_GETOPTS is not set
1168
+# CONFIG_HUSH_MEMLEAK is not set
1169
+
1170
+#
1171
+# Options common to all shells
1172
+#
1173
+CONFIG_FEATURE_SH_MATH=y
1174
+CONFIG_FEATURE_SH_MATH_64=y
1175
+CONFIG_FEATURE_SH_MATH_BASE=y
1176
+CONFIG_FEATURE_SH_EXTRA_QUIET=y
1177
+# CONFIG_FEATURE_SH_STANDALONE is not set
1178
+# CONFIG_FEATURE_SH_NOFORK is not set
1179
+CONFIG_FEATURE_SH_READ_FRAC=y
1180
+CONFIG_FEATURE_SH_HISTFILESIZE=y
1181
+CONFIG_FEATURE_SH_EMBEDDED_SCRIPTS=y
1182
+
1183
+#
1184
+# System Logging Utilities
1185
+#
1186
+# CONFIG_KLOGD is not set
1187
+# CONFIG_FEATURE_KLOGD_KLOGCTL is not set
1188
+# CONFIG_LOGGER is not set
1189
+# CONFIG_LOGREAD is not set
1190
+# CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING is not set
1191
+# CONFIG_SYSLOGD is not set
1192
+# CONFIG_FEATURE_ROTATE_LOGFILE is not set
1193
+# CONFIG_FEATURE_REMOTE_LOG is not set
1194
+# CONFIG_FEATURE_SYSLOGD_DUP is not set
1195
+# CONFIG_FEATURE_SYSLOGD_CFG is not set
1196
+# CONFIG_FEATURE_SYSLOGD_PRECISE_TIMESTAMPS is not set
1197
+CONFIG_FEATURE_SYSLOGD_READ_BUFFER_SIZE=0
1198
+# CONFIG_FEATURE_IPC_SYSLOG is not set
1199
+CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE=0
1200
+# CONFIG_FEATURE_KMSG_SYSLOG is not set
--- a/containers/busybox-config
+++ b/containers/busybox-config
@@ -0,0 +1,1200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/containers/busybox-config
+++ b/containers/busybox-config
@@ -0,0 +1,1200 @@
1 #
2 # Automatically generated make config: don't edit
3 # Busybox version: 1.35.0
4 # Tue Aug 16 02:15:21 2022
5 #
6 CONFIG_HAVE_DOT_CONFIG=y
7
8 #
9 # Settings
10 #
11 CONFIG_DESKTOP=y
12 # CONFIG_EXTRA_COMPAT is not set
13 # CONFIG_FEDORA_COMPAT is not set
14 CONFIG_INCLUDE_SUSv2=y
15 CONFIG_LONG_OPTS=y
16 CONFIG_SHOW_USAGE=y
17 CONFIG_FEATURE_VERBOSE_USAGE=y
18 CONFIG_FEATURE_COMPRESS_USAGE=y
19 CONFIG_LFS=y
20 # CONFIG_PAM is not set
21 CONFIG_FEATURE_DEVPTS=y
22 CONFIG_FEATURE_UTMP=y
23 CONFIG_FEATURE_WTMP=y
24 CONFIG_FEATURE_PIDFILE=y
25 CONFIG_PID_FILE_PATH="/var/run"
26 CONFIG_BUSYBOX=y
27 CONFIG_FEATURE_SHOW_SCRIPT=y
28 CONFIG_FEATURE_INSTALLER=y
29 # CONFIG_INSTALL_NO_USR is not set
30 CONFIG_FEATURE_SUID=y
31 CONFIG_FEATURE_SUID_CONFIG=y
32 CONFIG_FEATURE_SUID_CONFIG_QUIET=y
33 # CONFIG_FEATURE_PREFER_APPLETS is not set
34 CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
35 # CONFIG_SELINUX is not set
36 # CONFIG_FEATURE_CLEAN_UP is not set
37 CONFIG_FEATURE_SYSLOG_INFO=y
38 CONFIG_FEATURE_SYSLOG=y
39
40 #
41 # Build Options
42 #
43 CONFIG_STATIC=y
44 # CONFIG_PIE is not set
45 # CONFIG_NOMMU is not set
46 # CONFIG_BUILD_LIBBUSYBOX is not set
47 # CONFIG_FEATURE_LIBBUSYBOX_STATIC is not set
48 # CONFIG_FEATURE_INDIVIDUAL is not set
49 # CONFIG_FEATURE_SHARED_BUSYBOX is not set
50 CONFIG_CROSS_COMPILER_PREFIX=""
51 CONFIG_SYSROOT=""
52 CONFIG_EXTRA_CFLAGS=""
53 CONFIG_EXTRA_LDFLAGS=""
54 CONFIG_EXTRA_LDLIBS=""
55 # CONFIG_USE_PORTABLE_CODE is not set
56 CONFIG_STACK_OPTIMIZATION_386=y
57 CONFIG_STATIC_LIBGCC=y
58
59 #
60 # Installation Options ("make install" behavior)
61 #
62 CONFIG_INSTALL_APPLET_SYMLINKS=y
63 # CONFIG_INSTALL_APPLET_HARDLINKS is not set
64 # CONFIG_INSTALL_APPLET_SCRIPT_WRAPPERS is not set
65 # CONFIG_INSTALL_APPLET_DONT is not set
66 # CONFIG_INSTALL_SH_APPLET_SYMLINK is not set
67 # CONFIG_INSTALL_SH_APPLET_HARDLINK is not set
68 # CONFIG_INSTALL_SH_APPLET_SCRIPT_WRAPPER is not set
69 CONFIG_PREFIX="./_install"
70
71 #
72 # Debugging Options
73 #
74 # CONFIG_DEBUG is not set
75 # CONFIG_DEBUG_PESSIMIZE is not set
76 # CONFIG_DEBUG_SANITIZE is not set
77 # CONFIG_UNIT_TEST is not set
78 # CONFIG_WERROR is not set
79 # CONFIG_WARN_SIMPLE_MSG is not set
80 CONFIG_NO_DEBUG_LIB=y
81 # CONFIG_DMALLOC is not set
82 # CONFIG_EFENCE is not set
83
84 #
85 # Library Tuning
86 #
87 # CONFIG_FEATURE_USE_BSS_TAIL is not set
88 CONFIG_FLOAT_DURATION=y
89 CONFIG_FEATURE_RTMINMAX=y
90 CONFIG_FEATURE_RTMINMAX_USE_LIBC_DEFINITIONS=y
91 CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
92 # CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
93 # CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
94 CONFIG_PASSWORD_MINLEN=6
95 CONFIG_MD5_SMALL=1
96 CONFIG_SHA3_SMALL=1
97 CONFIG_FEATURE_NON_POSIX_CP=y
98 # CONFIG_FEATURE_VERBOSE_CP_MESSAGE is not set
99 CONFIG_FEATURE_USE_SENDFILE=y
100 CONFIG_FEATURE_COPYBUF_KB=4
101 CONFIG_MONOTONIC_SYSCALL=y
102 CONFIG_IOCTL_HEX2STR_ERROR=y
103 CONFIG_FEATURE_EDITING=y
104 CONFIG_FEATURE_EDITING_MAX_LEN=1024
105 # CONFIG_FEATURE_EDITING_VI is not set
106 CONFIG_FEATURE_EDITING_HISTORY=255
107 CONFIG_FEATURE_EDITING_SAVEHISTORY=y
108 # CONFIG_FEATURE_EDITING_SAVE_ON_EXIT is not set
109 CONFIG_FEATURE_REVERSE_SEARCH=y
110 CONFIG_FEATURE_TAB_COMPLETION=y
111 CONFIG_FEATURE_USERNAME_COMPLETION=y
112 CONFIG_FEATURE_EDITING_FANCY_PROMPT=y
113 CONFIG_FEATURE_EDITING_WINCH=y
114 # CONFIG_FEATURE_EDITING_ASK_TERMINAL is not set
115 # CONFIG_LOCALE_SUPPORT is not set
116 CONFIG_UNICODE_SUPPORT=y
117 # CONFIG_UNICODE_USING_LOCALE is not set
118 # CONFIG_FEATURE_CHECK_UNICODE_IN_ENV is not set
119 CONFIG_SUBST_WCHAR=63
120 CONFIG_LAST_SUPPORTED_WCHAR=767
121 # CONFIG_UNICODE_COMBINING_WCHARS is not set
122 # CONFIG_UNICODE_WIDE_WCHARS is not set
123 # CONFIG_UNICODE_BIDI_SUPPORT is not set
124 # CONFIG_UNICODE_NEUTRAL_TABLE is not set
125 # CONFIG_UNICODE_PRESERVE_BROKEN is not set
126
127 #
128 # Applets
129 #
130
131 #
132 # Archival Utilities
133 #
134 # CONFIG_FEATURE_SEAMLESS_XZ is not set
135 # CONFIG_FEATURE_SEAMLESS_LZMA is not set
136 # CONFIG_FEATURE_SEAMLESS_BZ2 is not set
137 CONFIG_FEATURE_SEAMLESS_GZ=y
138 # CONFIG_FEATURE_SEAMLESS_Z is not set
139 # CONFIG_AR is not set
140 # CONFIG_FEATURE_AR_LONG_FILENAMES is not set
141 # CONFIG_FEATURE_AR_CREATE is not set
142 # CONFIG_UNCOMPRESS is not set
143 CONFIG_GUNZIP=y
144 CONFIG_ZCAT=y
145 CONFIG_FEATURE_GUNZIP_LONG_OPTIONS=y
146 # CONFIG_BUNZIP2 is not set
147 # CONFIG_BZCAT is not set
148 # CONFIG_UNLZMA is not set
149 # CONFIG_LZCAT is not set
150 # CONFIG_LZMA is not set
151 # CONFIG_UNXZ is not set
152 # CONFIG_XZCAT is not set
153 # CONFIG_XZ is not set
154 # CONFIG_BZIP2 is not set
155 CONFIG_BZIP2_SMALL=0
156 # CONFIG_FEATURE_BZIP2_DECOMPRESS is not set
157 # CONFIG_CPIO is not set
158 # CONFIG_FEATURE_CPIO_O is not set
159 # CONFIG_FEATURE_CPIO_P is not set
160 # CONFIG_FEATURE_CPIO_IGNORE_DEVNO is not set
161 # CONFIG_FEATURE_CPIO_RENUMBER_INODES is not set
162 # CONFIG_DPKG is not set
163 # CONFIG_DPKG_DEB is not set
164 CONFIG_GZIP=y
165 CONFIG_FEATURE_GZIP_LONG_OPTIONS=y
166 CONFIG_GZIP_FAST=0
167 # CONFIG_FEATURE_GZIP_LEVELS is not set
168 CONFIG_FEATURE_GZIP_DECOMPRESS=y
169 # CONFIG_LZOP is not set
170 # CONFIG_UNLZOP is not set
171 # CONFIG_LZOPCAT is not set
172 # CONFIG_LZOP_COMPR_HIGH is not set
173 # CONFIG_RPM is not set
174 # CONFIG_RPM2CPIO is not set
175 CONFIG_TAR=y
176 CONFIG_FEATURE_TAR_LONG_OPTIONS=y
177 CONFIG_FEATURE_TAR_CREATE=y
178 CONFIG_FEATURE_TAR_AUTODETECT=y
179 CONFIG_FEATURE_TAR_FROM=y
180 # CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY is not set
181 # CONFIG_FEATURE_TAR_OLDSUN_COMPATIBILITY is not set
182 CONFIG_FEATURE_TAR_GNU_EXTENSIONS=y
183 # CONFIG_FEATURE_TAR_TO_COMMAND is not set
184 CONFIG_FEATURE_TAR_UNAME_GNAME=y
185 CONFIG_FEATURE_TAR_NOPRESERVE_TIME=y
186 # CONFIG_FEATURE_TAR_SELINUX is not set
187 CONFIG_UNZIP=y
188 CONFIG_FEATURE_UNZIP_CDF=y
189 CONFIG_FEATURE_UNZIP_BZIP2=y
190 CONFIG_FEATURE_UNZIP_LZMA=y
191 CONFIG_FEATURE_UNZIP_XZ=y
192 # CONFIG_FEATURE_LZMA_FAST is not set
193
194 #
195 # Coreutils
196 #
197 CONFIG_FEATURE_VERBOSE=y
198
199 #
200 # Common options for date and touch
201 #
202 CONFIG_FEATURE_TIMEZONE=y
203
204 #
205 # Common options for cp and mv
206 #
207 CONFIG_FEATURE_PRESERVE_HARDLINKS=y
208
209 #
210 # Common options for df, du, ls
211 #
212 CONFIG_FEATURE_HUMAN_READABLE=y
213 CONFIG_BASENAME=y
214 CONFIG_CAT=y
215 CONFIG_FEATURE_CATN=y
216 CONFIG_FEATURE_CATV=y
217 CONFIG_CHGRP=y
218 CONFIG_CHMOD=y
219 CONFIG_CHOWN=y
220 CONFIG_FEATURE_CHOWN_LONG_OPTIONS=y
221 CONFIG_CHROOT=y
222 # CONFIG_CKSUM is not set
223 # CONFIG_CRC32 is not set
224 CONFIG_COMM=y
225 CONFIG_CP=y
226 CONFIG_FEATURE_CP_LONG_OPTIONS=y
227 CONFIG_FEATURE_CP_REFLINK=y
228 CONFIG_CUT=y
229 CONFIG_FEATURE_CUT_REGEX=y
230 CONFIG_DATE=y
231 CONFIG_FEATURE_DATE_ISOFMT=y
232 # CONFIG_FEATURE_DATE_NANO is not set
233 CONFIG_FEATURE_DATE_COMPAT=y
234 CONFIG_DD=y
235 CONFIG_FEATURE_DD_SIGNAL_HANDLING=y
236 CONFIG_FEATURE_DD_THIRD_STATUS_LINE=y
237 CONFIG_FEATURE_DD_IBS_OBS=y
238 CONFIG_FEATURE_DD_STATUS=y
239 CONFIG_DF=y
240 CONFIG_FEATURE_DF_FANCY=y
241 CONFIG_FEATURE_SKIP_ROOTFS=y
242 CONFIG_DIRNAME=y
243 CONFIG_DOS2UNIX=y
244 CONFIG_UNIX2DOS=y
245 CONFIG_DU=y
246 CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K=y
247 # CONFIG_ECHO is not set
248 CONFIG_FEATURE_FANCY_ECHO=y
249 CONFIG_ENV=y
250 CONFIG_EXPAND=y
251 CONFIG_UNEXPAND=y
252 CONFIG_EXPR=y
253 CONFIG_EXPR_MATH_SUPPORT_64=y
254 # CONFIG_FACTOR is not set
255 CONFIG_FALSE=y
256 CONFIG_FOLD=y
257 CONFIG_HEAD=y
258 CONFIG_FEATURE_FANCY_HEAD=y
259 CONFIG_HOSTID=y
260 CONFIG_ID=y
261 CONFIG_GROUPS=y
262 CONFIG_INSTALL=y
263 CONFIG_FEATURE_INSTALL_LONG_OPTIONS=y
264 CONFIG_LINK=y
265 CONFIG_LN=y
266 # CONFIG_LOGNAME is not set
267 CONFIG_LS=y
268 CONFIG_FEATURE_LS_FILETYPES=y
269 CONFIG_FEATURE_LS_FOLLOWLINKS=y
270 CONFIG_FEATURE_LS_RECURSIVE=y
271 CONFIG_FEATURE_LS_WIDTH=y
272 CONFIG_FEATURE_LS_SORTFILES=y
273 CONFIG_FEATURE_LS_TIMESTAMPS=y
274 CONFIG_FEATURE_LS_USERNAME=y
275 CONFIG_FEATURE_LS_COLOR=y
276 CONFIG_FEATURE_LS_COLOR_IS_DEFAULT=y
277 # CONFIG_MD5SUM is not set
278 # CONFIG_SHA1SUM is not set
279 # CONFIG_SHA256SUM is not set
280 # CONFIG_SHA512SUM is not set
281 # CONFIG_SHA3SUM is not set
282 # CONFIG_FEATURE_MD5_SHA1_SUM_CHECK is not set
283 CONFIG_MKDIR=y
284 CONFIG_MKFIFO=y
285 CONFIG_MKNOD=y
286 CONFIG_MKTEMP=y
287 CONFIG_MV=y
288 CONFIG_NICE=y
289 CONFIG_NL=y
290 CONFIG_NOHUP=y
291 CONFIG_NPROC=y
292 CONFIG_OD=y
293 CONFIG_PASTE=y
294 # CONFIG_PRINTENV is not set
295 # CONFIG_PRINTF is not set
296 CONFIG_PWD=y
297 CONFIG_READLINK=y
298 CONFIG_FEATURE_READLINK_FOLLOW=y
299 CONFIG_REALPATH=y
300 CONFIG_RM=y
301 CONFIG_RMDIR=y
302 CONFIG_SEQ=y
303 CONFIG_SHRED=y
304 CONFIG_SHUF=y
305 CONFIG_SLEEP=y
306 CONFIG_FEATURE_FANCY_SLEEP=y
307 CONFIG_SORT=y
308 # CONFIG_FEATURE_SORT_BIG is not set
309 # CONFIG_FEATURE_SORT_OPTIMIZE_MEMORY is not set
310 CONFIG_SPLIT=y
311 CONFIG_FEATURE_SPLIT_FANCY=y
312 CONFIG_STAT=y
313 CONFIG_FEATURE_STAT_FORMAT=y
314 CONFIG_FEATURE_STAT_FILESYSTEM=y
315 CONFIG_STTY=y
316 # CONFIG_SUM is not set
317 CONFIG_SYNC=y
318 CONFIG_FEATURE_SYNC_FANCY=y
319 CONFIG_FSYNC=y
320 CONFIG_TAC=y
321 CONFIG_TAIL=y
322 CONFIG_FEATURE_FANCY_TAIL=y
323 CONFIG_TEE=y
324 CONFIG_FEATURE_TEE_USE_BLOCK_IO=y
325 # CONFIG_TEST is not set
326 # CONFIG_TEST1 is not set
327 # CONFIG_TEST2 is not set
328 # CONFIG_FEATURE_TEST_64 is not set
329 CONFIG_TIMEOUT=y
330 CONFIG_TOUCH=y
331 CONFIG_FEATURE_TOUCH_SUSV3=y
332 CONFIG_TR=y
333 CONFIG_FEATURE_TR_CLASSES=y
334 CONFIG_FEATURE_TR_EQUIV=y
335 CONFIG_TRUE=y
336 CONFIG_TRUNCATE=y
337 CONFIG_TTY=y
338 CONFIG_UNAME=y
339 CONFIG_UNAME_OSNAME="GNU/Linux"
340 CONFIG_BB_ARCH=y
341 CONFIG_UNIQ=y
342 CONFIG_UNLINK=y
343 CONFIG_USLEEP=y
344 CONFIG_UUDECODE=y
345 CONFIG_BASE32=y
346 CONFIG_BASE64=y
347 CONFIG_UUENCODE=y
348 CONFIG_WC=y
349 CONFIG_FEATURE_WC_LARGE=y
350 CONFIG_WHO=y
351 CONFIG_W=y
352 CONFIG_USERS=y
353 CONFIG_WHOAMI=y
354 CONFIG_YES=y
355
356 #
357 # Console Utilities
358 #
359 # CONFIG_CHVT is not set
360 CONFIG_CLEAR=y
361 # CONFIG_DEALLOCVT is not set
362 # CONFIG_DUMPKMAP is not set
363 # CONFIG_FGCONSOLE is not set
364 # CONFIG_KBD_MODE is not set
365 # CONFIG_LOADFONT is not set
366 # CONFIG_SETFONT is not set
367 # CONFIG_FEATURE_SETFONT_TEXTUAL_MAP is not set
368 CONFIG_DEFAULT_SETFONT_DIR=""
369 # CONFIG_FEATURE_LOADFONT_PSF2 is not set
370 # CONFIG_FEATURE_LOADFONT_RAW is not set
371 # CONFIG_LOADKMAP is not set
372 # CONFIG_OPENVT is not set
373 # CONFIG_RESET is not set
374 # CONFIG_RESIZE is not set
375 # CONFIG_FEATURE_RESIZE_PRINT is not set
376 # CONFIG_SETCONSOLE is not set
377 # CONFIG_FEATURE_SETCONSOLE_LONG_OPTIONS is not set
378 # CONFIG_SETKEYCODES is not set
379 # CONFIG_SETLOGCONS is not set
380 # CONFIG_SHOWKEY is not set
381
382 #
383 # Debian Utilities
384 #
385 # CONFIG_PIPE_PROGRESS is not set
386 # CONFIG_RUN_PARTS is not set
387 # CONFIG_FEATURE_RUN_PARTS_LONG_OPTIONS is not set
388 # CONFIG_FEATURE_RUN_PARTS_FANCY is not set
389 # CONFIG_START_STOP_DAEMON is not set
390 # CONFIG_FEATURE_START_STOP_DAEMON_LONG_OPTIONS is not set
391 # CONFIG_FEATURE_START_STOP_DAEMON_FANCY is not set
392 CONFIG_WHICH=y
393
394 #
395 # klibc-utils
396 #
397 # CONFIG_MINIPS is not set
398 # CONFIG_NUKE is not set
399 # CONFIG_RESUME is not set
400 # CONFIG_RUN_INIT is not set
401
402 #
403 # Editors
404 #
405 # CONFIG_AWK is not set
406 # CONFIG_FEATURE_AWK_LIBM is not set
407 # CONFIG_FEATURE_AWK_GNU_EXTENSIONS is not set
408 # CONFIG_CMP is not set
409 CONFIG_DIFF=y
410 CONFIG_FEATURE_DIFF_LONG_OPTIONS=y
411 CONFIG_FEATURE_DIFF_DIR=y
412 # CONFIG_ED is not set
413 CONFIG_PATCH=y
414 CONFIG_SED=y
415 CONFIG_VI=y
416 CONFIG_FEATURE_VI_MAX_LEN=4096
417 # CONFIG_FEATURE_VI_8BIT is not set
418 CONFIG_FEATURE_VI_COLON=y
419 CONFIG_FEATURE_VI_COLON_EXPAND=y
420 CONFIG_FEATURE_VI_YANKMARK=y
421 CONFIG_FEATURE_VI_SEARCH=y
422 # CONFIG_FEATURE_VI_REGEX_SEARCH is not set
423 CONFIG_FEATURE_VI_USE_SIGNALS=y
424 CONFIG_FEATURE_VI_DOT_CMD=y
425 CONFIG_FEATURE_VI_READONLY=y
426 CONFIG_FEATURE_VI_SETOPTS=y
427 CONFIG_FEATURE_VI_SET=y
428 CONFIG_FEATURE_VI_WIN_RESIZE=y
429 CONFIG_FEATURE_VI_ASK_TERMINAL=y
430 CONFIG_FEATURE_VI_UNDO=y
431 CONFIG_FEATURE_VI_UNDO_QUEUE=y
432 CONFIG_FEATURE_VI_UNDO_QUEUE_MAX=256
433 CONFIG_FEATURE_VI_VERBOSE_STATUS=y
434 CONFIG_FEATURE_ALLOW_EXEC=y
435
436 #
437 # Finding Utilities
438 #
439 CONFIG_FIND=y
440 CONFIG_FEATURE_FIND_PRINT0=y
441 CONFIG_FEATURE_FIND_MTIME=y
442 CONFIG_FEATURE_FIND_ATIME=y
443 CONFIG_FEATURE_FIND_CTIME=y
444 CONFIG_FEATURE_FIND_MMIN=y
445 CONFIG_FEATURE_FIND_AMIN=y
446 CONFIG_FEATURE_FIND_CMIN=y
447 CONFIG_FEATURE_FIND_PERM=y
448 CONFIG_FEATURE_FIND_TYPE=y
449 CONFIG_FEATURE_FIND_EXECUTABLE=y
450 CONFIG_FEATURE_FIND_XDEV=y
451 CONFIG_FEATURE_FIND_MAXDEPTH=y
452 CONFIG_FEATURE_FIND_NEWER=y
453 CONFIG_FEATURE_FIND_INUM=y
454 CONFIG_FEATURE_FIND_SAMEFILE=y
455 CONFIG_FEATURE_FIND_EXEC=y
456 CONFIG_FEATURE_FIND_EXEC_PLUS=y
457 CONFIG_FEATURE_FIND_USER=y
458 CONFIG_FEATURE_FIND_GROUP=y
459 CONFIG_FEATURE_FIND_NOT=y
460 CONFIG_FEATURE_FIND_DEPTH=y
461 CONFIG_FEATURE_FIND_PAREN=y
462 CONFIG_FEATURE_FIND_SIZE=y
463 CONFIG_FEATURE_FIND_PRUNE=y
464 CONFIG_FEATURE_FIND_QUIT=y
465 CONFIG_FEATURE_FIND_DELETE=y
466 CONFIG_FEATURE_FIND_EMPTY=y
467 CONFIG_FEATURE_FIND_PATH=y
468 CONFIG_FEATURE_FIND_REGEX=y
469 # CONFIG_FEATURE_FIND_CONTEXT is not set
470 CONFIG_FEATURE_FIND_LINKS=y
471 CONFIG_GREP=y
472 # CONFIG_EGREP is not set
473 # CONFIG_FGREP is not set
474 CONFIG_FEATURE_GREP_CONTEXT=y
475 CONFIG_XARGS=y
476 CONFIG_FEATURE_XARGS_SUPPORT_CONFIRMATION=y
477 CONFIG_FEATURE_XARGS_SUPPORT_QUOTES=y
478 CONFIG_FEATURE_XARGS_SUPPORT_TERMOPT=y
479 CONFIG_FEATURE_XARGS_SUPPORT_ZERO_TERM=y
480 CONFIG_FEATURE_XARGS_SUPPORT_REPL_STR=y
481 CONFIG_FEATURE_XARGS_SUPPORT_PARALLEL=y
482 CONFIG_FEATURE_XARGS_SUPPORT_ARGS_FILE=y
483
484 #
485 # Init Utilities
486 #
487 # CONFIG_BOOTCHARTD is not set
488 # CONFIG_FEATURE_BOOTCHARTD_BLOATED_HEADER is not set
489 # CONFIG_FEATURE_BOOTCHARTD_CONFIG_FILE is not set
490 # CONFIG_HALT is not set
491 # CONFIG_POWEROFF is not set
492 # CONFIG_REBOOT is not set
493 # CONFIG_FEATURE_WAIT_FOR_INIT is not set
494 # CONFIG_FEATURE_CALL_TELINIT is not set
495 CONFIG_TELINIT_PATH=""
496 # CONFIG_INIT is not set
497 # CONFIG_LINUXRC is not set
498 # CONFIG_FEATURE_USE_INITTAB is not set
499 # CONFIG_FEATURE_KILL_REMOVED is not set
500 CONFIG_FEATURE_KILL_DELAY=0
501 # CONFIG_FEATURE_INIT_SCTTY is not set
502 # CONFIG_FEATURE_INIT_SYSLOG is not set
503 # CONFIG_FEATURE_INIT_QUIET is not set
504 # CONFIG_FEATURE_INIT_COREDUMPS is not set
505 CONFIG_INIT_TERMINAL_TYPE=""
506 # CONFIG_FEATURE_INIT_MODIFY_CMDLINE is not set
507
508 #
509 # Login/Password Management Utilities
510 #
511 # CONFIG_FEATURE_SHADOWPASSWDS is not set
512 CONFIG_USE_BB_PWD_GRP=y
513 # CONFIG_USE_BB_SHADOW is not set
514 CONFIG_USE_BB_CRYPT=y
515 CONFIG_USE_BB_CRYPT_SHA=y
516 # CONFIG_ADD_SHELL is not set
517 # CONFIG_REMOVE_SHELL is not set
518 CONFIG_ADDGROUP=y
519 # CONFIG_FEATURE_ADDUSER_TO_GROUP is not set
520 CONFIG_ADDUSER=y
521 # CONFIG_FEATURE_CHECK_NAMES is not set
522 CONFIG_LAST_ID=60000
523 CONFIG_FIRST_SYSTEM_ID=100
524 CONFIG_LAST_SYSTEM_ID=999
525 # CONFIG_CHPASSWD is not set
526 CONFIG_FEATURE_DEFAULT_PASSWD_ALGO=""
527 # CONFIG_CRYPTPW is not set
528 # CONFIG_MKPASSWD is not set
529 # CONFIG_DELUSER is not set
530 # CONFIG_DELGROUP is not set
531 # CONFIG_FEATURE_DEL_USER_FROM_GROUP is not set
532 # CONFIG_GETTY is not set
533 # CONFIG_LOGIN is not set
534 # CONFIG_LOGIN_SESSION_AS_CHILD is not set
535 # CONFIG_LOGIN_SCRIPTS is not set
536 # CONFIG_FEATURE_NOLOGIN is not set
537 # CONFIG_FEATURE_SECURETTY is not set
538 # CONFIG_PASSWD is not set
539 # CONFIG_FEATURE_PASSWD_WEAK_CHECK is not set
540 # CONFIG_SU is not set
541 # CONFIG_FEATURE_SU_SYSLOG is not set
542 # CONFIG_FEATURE_SU_CHECKS_SHELLS is not set
543 # CONFIG_FEATURE_SU_BLANK_PW_NEEDS_SECURE_TTY is not set
544 # CONFIG_SULOGIN is not set
545 # CONFIG_VLOCK is not set
546
547 #
548 # Linux Ext2 FS Progs
549 #
550 # CONFIG_CHATTR is not set
551 # CONFIG_FSCK is not set
552 # CONFIG_LSATTR is not set
553 # CONFIG_TUNE2FS is not set
554
555 #
556 # Linux Module Utilities
557 #
558 # CONFIG_MODPROBE_SMALL is not set
559 # CONFIG_DEPMOD is not set
560 # CONFIG_INSMOD is not set
561 # CONFIG_LSMOD is not set
562 # CONFIG_FEATURE_LSMOD_PRETTY_2_6_OUTPUT is not set
563 # CONFIG_MODINFO is not set
564 # CONFIG_MODPROBE is not set
565 # CONFIG_FEATURE_MODPROBE_BLACKLIST is not set
566 # CONFIG_RMMOD is not set
567
568 #
569 # Options common to multiple modutils
570 #
571 # CONFIG_FEATURE_CMDLINE_MODULE_OPTIONS is not set
572 # CONFIG_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED is not set
573 # CONFIG_FEATURE_2_4_MODULES is not set
574 # CONFIG_FEATURE_INSMOD_VERSION_CHECKING is not set
575 # CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS is not set
576 # CONFIG_FEATURE_INSMOD_LOADINKMEM is not set
577 # CONFIG_FEATURE_INSMOD_LOAD_MAP is not set
578 # CONFIG_FEATURE_INSMOD_LOAD_MAP_FULL is not set
579 # CONFIG_FEATURE_CHECK_TAINTED_MODULE is not set
580 # CONFIG_FEATURE_INSMOD_TRY_MMAP is not set
581 # CONFIG_FEATURE_MODUTILS_ALIAS is not set
582 # CONFIG_FEATURE_MODUTILS_SYMBOLS is not set
583 CONFIG_DEFAULT_MODULES_DIR=""
584 CONFIG_DEFAULT_DEPMOD_FILE=""
585
586 #
587 # Linux System Utilities
588 #
589 # CONFIG_ACPID is not set
590 # CONFIG_FEATURE_ACPID_COMPAT is not set
591 # CONFIG_BLKDISCARD is not set
592 # CONFIG_BLKID is not set
593 # CONFIG_FEATURE_BLKID_TYPE is not set
594 # CONFIG_BLOCKDEV is not set
595 # CONFIG_CAL is not set
596 # CONFIG_CHRT is not set
597 # CONFIG_DMESG is not set
598 # CONFIG_FEATURE_DMESG_PRETTY is not set
599 # CONFIG_EJECT is not set
600 # CONFIG_FEATURE_EJECT_SCSI is not set
601 # CONFIG_FALLOCATE is not set
602 # CONFIG_FATATTR is not set
603 # CONFIG_FBSET is not set
604 # CONFIG_FEATURE_FBSET_FANCY is not set
605 # CONFIG_FEATURE_FBSET_READMODE is not set
606 # CONFIG_FDFORMAT is not set
607 # CONFIG_FDISK is not set
608 # CONFIG_FDISK_SUPPORT_LARGE_DISKS is not set
609 # CONFIG_FEATURE_FDISK_WRITABLE is not set
610 # CONFIG_FEATURE_AIX_LABEL is not set
611 # CONFIG_FEATURE_SGI_LABEL is not set
612 # CONFIG_FEATURE_SUN_LABEL is not set
613 # CONFIG_FEATURE_OSF_LABEL is not set
614 # CONFIG_FEATURE_GPT_LABEL is not set
615 # CONFIG_FEATURE_FDISK_ADVANCED is not set
616 # CONFIG_FINDFS is not set
617 # CONFIG_FLOCK is not set
618 # CONFIG_FDFLUSH is not set
619 # CONFIG_FREERAMDISK is not set
620 # CONFIG_FSCK_MINIX is not set
621 # CONFIG_FSFREEZE is not set
622 # CONFIG_FSTRIM is not set
623 # CONFIG_GETOPT is not set
624 # CONFIG_FEATURE_GETOPT_LONG is not set
625 CONFIG_HEXDUMP=y
626 CONFIG_HD=y
627 CONFIG_XXD=y
628 # CONFIG_HWCLOCK is not set
629 # CONFIG_FEATURE_HWCLOCK_ADJTIME_FHS is not set
630 # CONFIG_IONICE is not set
631 # CONFIG_IPCRM is not set
632 # CONFIG_IPCS is not set
633 # CONFIG_LAST is not set
634 # CONFIG_FEATURE_LAST_FANCY is not set
635 # CONFIG_LOSETUP is not set
636 # CONFIG_LSPCI is not set
637 # CONFIG_LSUSB is not set
638 # CONFIG_MDEV is not set
639 # CONFIG_FEATURE_MDEV_CONF is not set
640 # CONFIG_FEATURE_MDEV_RENAME is not set
641 # CONFIG_FEATURE_MDEV_RENAME_REGEXP is not set
642 # CONFIG_FEATURE_MDEV_EXEC is not set
643 # CONFIG_FEATURE_MDEV_LOAD_FIRMWARE is not set
644 # CONFIG_FEATURE_MDEV_DAEMON is not set
645 # CONFIG_MESG is not set
646 # CONFIG_FEATURE_MESG_ENABLE_ONLY_GROUP is not set
647 # CONFIG_MKE2FS is not set
648 # CONFIG_MKFS_EXT2 is not set
649 # CONFIG_MKFS_MINIX is not set
650 # CONFIG_FEATURE_MINIX2 is not set
651 # CONFIG_MKFS_REISER is not set
652 # CONFIG_MKDOSFS is not set
653 # CONFIG_MKFS_VFAT is not set
654 # CONFIG_MKSWAP is not set
655 # CONFIG_FEATURE_MKSWAP_UUID is not set
656 CONFIG_MORE=y
657 CONFIG_MOUNT=y
658 CONFIG_FEATURE_MOUNT_FAKE=y
659 CONFIG_FEATURE_MOUNT_VERBOSE=y
660 # CONFIG_FEATURE_MOUNT_HELPERS is not set
661 # CONFIG_FEATURE_MOUNT_LABEL is not set
662 # CONFIG_FEATURE_MOUNT_NFS is not set
663 # CONFIG_FEATURE_MOUNT_CIFS is not set
664 CONFIG_FEATURE_MOUNT_FLAGS=y
665 CONFIG_FEATURE_MOUNT_FSTAB=y
666 CONFIG_FEATURE_MOUNT_OTHERTAB=y
667 # CONFIG_MOUNTPOINT is not set
668 CONFIG_NOLOGIN=y
669 # CONFIG_NOLOGIN_DEPENDENCIES is not set
670 # CONFIG_NSENTER is not set
671 # CONFIG_PIVOT_ROOT is not set
672 # CONFIG_RDATE is not set
673 # CONFIG_RDEV is not set
674 # CONFIG_READPROFILE is not set
675 CONFIG_RENICE=y
676 CONFIG_REV=y
677 # CONFIG_RTCWAKE is not set
678 # CONFIG_SCRIPT is not set
679 # CONFIG_SCRIPTREPLAY is not set
680 # CONFIG_SETARCH is not set
681 # CONFIG_LINUX32 is not set
682 # CONFIG_LINUX64 is not set
683 # CONFIG_SETPRIV is not set
684 # CONFIG_FEATURE_SETPRIV_DUMP is not set
685 # CONFIG_FEATURE_SETPRIV_CAPABILITIES is not set
686 # CONFIG_FEATURE_SETPRIV_CAPABILITY_NAMES is not set
687 # CONFIG_SETSID is not set
688 # CONFIG_SWAPON is not set
689 # CONFIG_FEATURE_SWAPON_DISCARD is not set
690 # CONFIG_FEATURE_SWAPON_PRI is not set
691 # CONFIG_SWAPOFF is not set
692 # CONFIG_FEATURE_SWAPONOFF_LABEL is not set
693 # CONFIG_SWITCH_ROOT is not set
694 # CONFIG_TASKSET is not set
695 # CONFIG_FEATURE_TASKSET_FANCY is not set
696 # CONFIG_FEATURE_TASKSET_CPULIST is not set
697 # CONFIG_UEVENT is not set
698 CONFIG_UMOUNT=y
699 CONFIG_FEATURE_UMOUNT_ALL=y
700 # CONFIG_UNSHARE is not set
701 # CONFIG_WALL is not set
702
703 #
704 # Common options for mount/umount
705 #
706 # CONFIG_FEATURE_MOUNT_LOOP is not set
707 # CONFIG_FEATURE_MOUNT_LOOP_CREATE is not set
708 # CONFIG_FEATURE_MTAB_SUPPORT is not set
709 # CONFIG_VOLUMEID is not set
710 # CONFIG_FEATURE_VOLUMEID_BCACHE is not set
711 # CONFIG_FEATURE_VOLUMEID_BTRFS is not set
712 # CONFIG_FEATURE_VOLUMEID_CRAMFS is not set
713 # CONFIG_FEATURE_VOLUMEID_EROFS is not set
714 # CONFIG_FEATURE_VOLUMEID_EXFAT is not set
715 # CONFIG_FEATURE_VOLUMEID_EXT is not set
716 # CONFIG_FEATURE_VOLUMEID_F2FS is not set
717 # CONFIG_FEATURE_VOLUMEID_FAT is not set
718 # CONFIG_FEATURE_VOLUMEID_HFS is not set
719 # CONFIG_FEATURE_VOLUMEID_ISO9660 is not set
720 # CONFIG_FEATURE_VOLUMEID_JFS is not set
721 # CONFIG_FEATURE_VOLUMEID_LFS is not set
722 # CONFIG_FEATURE_VOLUMEID_LINUXRAID is not set
723 # CONFIG_FEATURE_VOLUMEID_LINUXSWAP is not set
724 # CONFIG_FEATURE_VOLUMEID_LUKS is not set
725 # CONFIG_FEATURE_VOLUMEID_MINIX is not set
726 # CONFIG_FEATURE_VOLUMEID_NILFS is not set
727 # CONFIG_FEATURE_VOLUMEID_NTFS is not set
728 # CONFIG_FEATURE_VOLUMEID_OCFS2 is not set
729 # CONFIG_FEATURE_VOLUMEID_REISERFS is not set
730 # CONFIG_FEATURE_VOLUMEID_ROMFS is not set
731 # CONFIG_FEATURE_VOLUMEID_SQUASHFS is not set
732 # CONFIG_FEATURE_VOLUMEID_SYSV is not set
733 # CONFIG_FEATURE_VOLUMEID_UBIFS is not set
734 # CONFIG_FEATURE_VOLUMEID_UDF is not set
735 # CONFIG_FEATURE_VOLUMEID_XFS is not set
736
737 #
738 # Miscellaneous Utilities
739 #
740 # CONFIG_ADJTIMEX is not set
741 # CONFIG_ASCII is not set
742 # CONFIG_BBCONFIG is not set
743 # CONFIG_FEATURE_COMPRESS_BBCONFIG is not set
744 CONFIG_BC=y
745 # CONFIG_DC is not set
746 CONFIG_FEATURE_DC_BIG=y
747 # CONFIG_FEATURE_DC_LIBM is not set
748 # CONFIG_FEATURE_BC_INTERACTIVE is not set
749 # CONFIG_FEATURE_BC_LONG_OPTIONS is not set
750 # CONFIG_BEEP is not set
751 CONFIG_FEATURE_BEEP_FREQ=0
752 CONFIG_FEATURE_BEEP_LENGTH_MS=0
753 # CONFIG_CHAT is not set
754 # CONFIG_FEATURE_CHAT_NOFAIL is not set
755 # CONFIG_FEATURE_CHAT_TTY_HIFI is not set
756 # CONFIG_FEATURE_CHAT_IMPLICIT_CR is not set
757 # CONFIG_FEATURE_CHAT_SWALLOW_OPTS is not set
758 # CONFIG_FEATURE_CHAT_SEND_ESCAPES is not set
759 # CONFIG_FEATURE_CHAT_VAR_ABORT_LEN is not set
760 # CONFIG_FEATURE_CHAT_CLR_ABORT is not set
761 # CONFIG_CONSPY is not set
762 CONFIG_CROND=y
763 CONFIG_FEATURE_CROND_D=y
764 CONFIG_FEATURE_CROND_CALL_SENDMAIL=y
765 CONFIG_FEATURE_CROND_SPECIAL_TIMES=y
766 CONFIG_FEATURE_CROND_DIR="/var/spool/cron"
767 CONFIG_CRONTAB=y
768 # CONFIG_DEVFSD is not set
769 # CONFIG_DEVFSD_MODLOAD is not set
770 # CONFIG_DEVFSD_FG_NP is not set
771 # CONFIG_DEVFSD_VERBOSE is not set
772 # CONFIG_FEATURE_DEVFS is not set
773 # CONFIG_DEVMEM is not set
774 # CONFIG_FBSPLASH is not set
775 # CONFIG_FLASH_ERASEALL is not set
776 # CONFIG_FLASH_LOCK is not set
777 # CONFIG_FLASH_UNLOCK is not set
778 # CONFIG_FLASHCP is not set
779 # CONFIG_HDPARM is not set
780 # CONFIG_FEATURE_HDPARM_GET_IDENTITY is not set
781 # CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF is not set
782 # CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF is not set
783 # CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET is not set
784 # CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF is not set
785 # CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA is not set
786 CONFIG_HEXEDIT=y
787 # CONFIG_I2CGET is not set
788 # CONFIG_I2CSET is not set
789 # CONFIG_I2CDUMP is not set
790 # CONFIG_I2CDETECT is not set
791 # CONFIG_I2CTRANSFER is not set
792 # CONFIG_INOTIFYD is not set
793 CONFIG_LESS=y
794 CONFIG_FEATURE_LESS_MAXLINES=9999999
795 CONFIG_FEATURE_LESS_BRACKETS=y
796 CONFIG_FEATURE_LESS_FLAGS=y
797 CONFIG_FEATURE_LESS_TRUNCATE=y
798 CONFIG_FEATURE_LESS_MARKS=y
799 CONFIG_FEATURE_LESS_REGEXP=y
800 CONFIG_FEATURE_LESS_WINCH=y
801 CONFIG_FEATURE_LESS_ASK_TERMINAL=y
802 CONFIG_FEATURE_LESS_DASHCMD=y
803 CONFIG_FEATURE_LESS_LINENUMS=y
804 CONFIG_FEATURE_LESS_RAW=y
805 CONFIG_FEATURE_LESS_ENV=y
806 # CONFIG_LSSCSI is not set
807 # CONFIG_MAKEDEVS is not set
808 # CONFIG_FEATURE_MAKEDEVS_LEAF is not set
809 # CONFIG_FEATURE_MAKEDEVS_TABLE is not set
810 # CONFIG_MAN is not set
811 # CONFIG_MICROCOM is not set
812 # CONFIG_MIM is not set
813 # CONFIG_MT is not set
814 # CONFIG_NANDWRITE is not set
815 # CONFIG_NANDDUMP is not set
816 # CONFIG_PARTPROBE is not set
817 # CONFIG_RAIDAUTORUN is not set
818 # CONFIG_READAHEAD is not set
819 # CONFIG_RFKILL is not set
820 # CONFIG_RUNLEVEL is not set
821 # CONFIG_RX is not set
822 # CONFIG_SETFATTR is not set
823 # CONFIG_SETSERIAL is not set
824 CONFIG_STRINGS=y
825 CONFIG_TIME=y
826 # CONFIG_TS is not set
827 # CONFIG_TTYSIZE is not set
828 # CONFIG_UBIATTACH is not set
829 # CONFIG_UBIDETACH is not set
830 # CONFIG_UBIMKVOL is not set
831 # CONFIG_UBIRMVOL is not set
832 # CONFIG_UBIRSVOL is not set
833 # CONFIG_UBIUPDATEVOL is not set
834 # CONFIG_UBIRENAME is not set
835 # CONFIG_VOLNAME is not set
836 # CONFIG_WATCHDOG is not set
837 # CONFIG_FEATURE_WATCHDOG_OPEN_TWICE is not set
838
839 #
840 # Networking Utilities
841 #
842 CONFIG_FEATURE_IPV6=y
843 # CONFIG_FEATURE_UNIX_LOCAL is not set
844 CONFIG_FEATURE_PREFER_IPV4_ADDRESS=y
845 # CONFIG_VERBOSE_RESOLUTION_ERRORS is not set
846 # CONFIG_FEATURE_ETC_NETWORKS is not set
847 # CONFIG_FEATURE_ETC_SERVICES is not set
848 # CONFIG_FEATURE_HWIB is not set
849 # CONFIG_FEATURE_TLS_SHA1 is not set
850 # CONFIG_ARP is not set
851 # CONFIG_ARPING is not set
852 # CONFIG_BRCTL is not set
853 # CONFIG_FEATURE_BRCTL_FANCY is not set
854 # CONFIG_FEATURE_BRCTL_SHOW is not set
855 # CONFIG_DNSD is not set
856 # CONFIG_ETHER_WAKE is not set
857 # CONFIG_FTPD is not set
858 # CONFIG_FEATURE_FTPD_WRITE is not set
859 # CONFIG_FEATURE_FTPD_ACCEPT_BROKEN_LIST is not set
860 # CONFIG_FEATURE_FTPD_AUTHENTICATION is not set
861 # CONFIG_FTPGET is not set
862 # CONFIG_FTPPUT is not set
863 # CONFIG_FEATURE_FTPGETPUT_LONG_OPTIONS is not set
864 # CONFIG_HOSTNAME is not set
865 # CONFIG_DNSDOMAINNAME is not set
866 # CONFIG_HTTPD is not set
867 CONFIG_FEATURE_HTTPD_PORT_DEFAULT=0
868 # CONFIG_FEATURE_HTTPD_RANGES is not set
869 # CONFIG_FEATURE_HTTPD_SETUID is not set
870 # CONFIG_FEATURE_HTTPD_BASIC_AUTH is not set
871 # CONFIG_FEATURE_HTTPD_AUTH_MD5 is not set
872 # CONFIG_FEATURE_HTTPD_CGI is not set
873 # CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR is not set
874 # CONFIG_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV is not set
875 # CONFIG_FEATURE_HTTPD_ENCODE_URL_STR is not set
876 # CONFIG_FEATURE_HTTPD_ERROR_PAGES is not set
877 # CONFIG_FEATURE_HTTPD_PROXY is not set
878 # CONFIG_FEATURE_HTTPD_GZIP is not set
879 # CONFIG_FEATURE_HTTPD_ETAG is not set
880 # CONFIG_FEATURE_HTTPD_LAST_MODIFIED is not set
881 # CONFIG_FEATURE_HTTPD_DATE is not set
882 # CONFIG_FEATURE_HTTPD_ACL_IP is not set
883 CONFIG_IFCONFIG=y
884 CONFIG_FEATURE_IFCONFIG_STATUS=y
885 # CONFIG_FEATURE_IFCONFIG_SLIP is not set
886 CONFIG_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ=y
887 CONFIG_FEATURE_IFCONFIG_HW=y
888 CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS=y
889 # CONFIG_IFENSLAVE is not set
890 # CONFIG_IFPLUGD is not set
891 # CONFIG_IFUP is not set
892 # CONFIG_IFDOWN is not set
893 CONFIG_IFUPDOWN_IFSTATE_PATH=""
894 # CONFIG_FEATURE_IFUPDOWN_IP is not set
895 # CONFIG_FEATURE_IFUPDOWN_IPV4 is not set
896 # CONFIG_FEATURE_IFUPDOWN_IPV6 is not set
897 # CONFIG_FEATURE_IFUPDOWN_MAPPING is not set
898 # CONFIG_FEATURE_IFUPDOWN_EXTERNAL_DHCP is not set
899 CONFIG_INETD=y
900 # CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_ECHO is not set
901 # CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DISCARD is not set
902 # CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_TIME is not set
903 # CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DAYTIME is not set
904 # CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_CHARGEN is not set
905 # CONFIG_FEATURE_INETD_RPC is not set
906 CONFIG_IP=y
907 # CONFIG_IPADDR is not set
908 # CONFIG_IPLINK is not set
909 # CONFIG_IPROUTE is not set
910 # CONFIG_IPTUNNEL is not set
911 # CONFIG_IPRULE is not set
912 # CONFIG_IPNEIGH is not set
913 CONFIG_FEATURE_IP_ADDRESS=y
914 CONFIG_FEATURE_IP_LINK=y
915 CONFIG_FEATURE_IP_ROUTE=y
916 CONFIG_FEATURE_IP_ROUTE_DIR="/etc/iproute2"
917 # CONFIG_FEATURE_IP_TUNNEL is not set
918 # CONFIG_FEATURE_IP_RULE is not set
919 CONFIG_FEATURE_IP_NEIGH=y
920 # CONFIG_FEATURE_IP_RARE_PROTOCOLS is not set
921 CONFIG_IPCALC=y
922 CONFIG_FEATURE_IPCALC_LONG_OPTIONS=y
923 CONFIG_FEATURE_IPCALC_FANCY=y
924 # CONFIG_FAKEIDENTD is not set
925 # CONFIG_NAMEIF is not set
926 # CONFIG_FEATURE_NAMEIF_EXTENDED is not set
927 # CONFIG_NBDCLIENT is not set
928 CONFIG_NC=y
929 # CONFIG_NETCAT is not set
930 CONFIG_NC_SERVER=y
931 CONFIG_NC_EXTRA=y
932 CONFIG_NC_110_COMPAT=y
933 # CONFIG_NETSTAT is not set
934 # CONFIG_FEATURE_NETSTAT_WIDE is not set
935 # CONFIG_FEATURE_NETSTAT_PRG is not set
936 # CONFIG_NSLOOKUP is not set
937 # CONFIG_FEATURE_NSLOOKUP_BIG is not set
938 # CONFIG_FEATURE_NSLOOKUP_LONG_OPTIONS is not set
939 # CONFIG_NTPD is not set
940 # CONFIG_FEATURE_NTPD_SERVER is not set
941 # CONFIG_FEATURE_NTPD_CONF is not set
942 # CONFIG_FEATURE_NTP_AUTH is not set
943 # CONFIG_PING is not set
944 # CONFIG_PING6 is not set
945 # CONFIG_FEATURE_FANCY_PING is not set
946 # CONFIG_PSCAN is not set
947 CONFIG_ROUTE=y
948 # CONFIG_SLATTACH is not set
949 CONFIG_SSL_CLIENT=y
950 # CONFIG_TC is not set
951 # CONFIG_FEATURE_TC_INGRESS is not set
952 # CONFIG_TCPSVD is not set
953 # CONFIG_UDPSVD is not set
954 # CONFIG_TELNET is not set
955 # CONFIG_FEATURE_TELNET_TTYPE is not set
956 # CONFIG_FEATURE_TELNET_AUTOLOGIN is not set
957 # CONFIG_FEATURE_TELNET_WIDTH is not set
958 # CONFIG_TELNETD is not set
959 # CONFIG_FEATURE_TELNETD_STANDALONE is not set
960 CONFIG_FEATURE_TELNETD_PORT_DEFAULT=0
961 # CONFIG_FEATURE_TELNETD_INETD_WAIT is not set
962 # CONFIG_TFTP is not set
963 # CONFIG_FEATURE_TFTP_PROGRESS_BAR is not set
964 # CONFIG_FEATURE_TFTP_HPA_COMPAT is not set
965 # CONFIG_TFTPD is not set
966 # CONFIG_FEATURE_TFTP_GET is not set
967 # CONFIG_FEATURE_TFTP_PUT is not set
968 # CONFIG_FEATURE_TFTP_BLOCKSIZE is not set
969 # CONFIG_TFTP_DEBUG is not set
970 CONFIG_TLS=y
971 # CONFIG_TRACEROUTE is not set
972 # CONFIG_TRACEROUTE6 is not set
973 # CONFIG_FEATURE_TRACEROUTE_VERBOSE is not set
974 # CONFIG_FEATURE_TRACEROUTE_USE_ICMP is not set
975 # CONFIG_TUNCTL is not set
976 # CONFIG_FEATURE_TUNCTL_UG is not set
977 # CONFIG_VCONFIG is not set
978 CONFIG_WGET=y
979 CONFIG_FEATURE_WGET_LONG_OPTIONS=y
980 CONFIG_FEATURE_WGET_STATUSBAR=y
981 CONFIG_FEATURE_WGET_FTP=y
982 CONFIG_FEATURE_WGET_AUTHENTICATION=y
983 CONFIG_FEATURE_WGET_TIMEOUT=y
984 CONFIG_FEATURE_WGET_HTTPS=y
985 CONFIG_FEATURE_WGET_OPENSSL=y
986 CONFIG_WHOIS=y
987 # CONFIG_ZCIP is not set
988 # CONFIG_UDHCPD is not set
989 # CONFIG_FEATURE_UDHCPD_BASE_IP_ON_MAC is not set
990 # CONFIG_FEATURE_UDHCPD_WRITE_LEASES_EARLY is not set
991 CONFIG_DHCPD_LEASES_FILE=""
992 # CONFIG_DUMPLEASES is not set
993 # CONFIG_DHCPRELAY is not set
994 # CONFIG_UDHCPC is not set
995 # CONFIG_FEATURE_UDHCPC_ARPING is not set
996 # CONFIG_FEATURE_UDHCPC_SANITIZEOPT is not set
997 CONFIG_UDHCPC_DEFAULT_SCRIPT=""
998 # CONFIG_UDHCPC6 is not set
999 # CONFIG_FEATURE_UDHCPC6_RFC3646 is not set
1000 # CONFIG_FEATURE_UDHCPC6_RFC4704 is not set
1001 # CONFIG_FEATURE_UDHCPC6_RFC4833 is not set
1002 # CONFIG_FEATURE_UDHCPC6_RFC5970 is not set
1003 CONFIG_UDHCPC_DEFAULT_INTERFACE=""
1004 # CONFIG_FEATURE_UDHCP_PORT is not set
1005 CONFIG_UDHCP_DEBUG=0
1006 CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS=0
1007 # CONFIG_FEATURE_UDHCP_RFC3397 is not set
1008 # CONFIG_FEATURE_UDHCP_8021Q is not set
1009 CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS=""
1010
1011 #
1012 # Print Utilities
1013 #
1014 # CONFIG_LPD is not set
1015 # CONFIG_LPR is not set
1016 # CONFIG_LPQ is not set
1017
1018 #
1019 # Mail Utilities
1020 #
1021 CONFIG_FEATURE_MIME_CHARSET="utf-8"
1022 # CONFIG_MAKEMIME is not set
1023 # CONFIG_POPMAILDIR is not set
1024 # CONFIG_FEATURE_POPMAILDIR_DELIVERY is not set
1025 # CONFIG_REFORMIME is not set
1026 # CONFIG_FEATURE_REFORMIME_COMPAT is not set
1027 CONFIG_SENDMAIL=y
1028
1029 #
1030 # Process Utilities
1031 #
1032 # CONFIG_FEATURE_FAST_TOP is not set
1033 CONFIG_FEATURE_SHOW_THREADS=y
1034 CONFIG_FREE=y
1035 CONFIG_FUSER=y
1036 CONFIG_IOSTAT=y
1037 CONFIG_KILL=y
1038 CONFIG_KILLALL=y
1039 # CONFIG_KILLALL5 is not set
1040 CONFIG_LSOF=y
1041 CONFIG_MPSTAT=y
1042 CONFIG_NMETER=y
1043 CONFIG_PGREP=y
1044 CONFIG_PKILL=y
1045 CONFIG_PIDOF=y
1046 CONFIG_FEATURE_PIDOF_SINGLE=y
1047 CONFIG_FEATURE_PIDOF_OMIT=y
1048 CONFIG_PMAP=y
1049 # CONFIG_POWERTOP is not set
1050 # CONFIG_FEATURE_POWERTOP_INTERACTIVE is not set
1051 CONFIG_PS=y
1052 # CONFIG_FEATURE_PS_WIDE is not set
1053 # CONFIG_FEATURE_PS_LONG is not set
1054 CONFIG_FEATURE_PS_TIME=y
1055 # CONFIG_FEATURE_PS_UNUSUAL_SYSTEMS is not set
1056 CONFIG_FEATURE_PS_ADDITIONAL_COLUMNS=y
1057 CONFIG_PSTREE=y
1058 CONFIG_PWDX=y
1059 CONFIG_SMEMCAP=y
1060 CONFIG_BB_SYSCTL=y
1061 CONFIG_TOP=y
1062 CONFIG_FEATURE_TOP_INTERACTIVE=y
1063 CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE=y
1064 CONFIG_FEATURE_TOP_CPU_GLOBAL_PERCENTS=y
1065 CONFIG_FEATURE_TOP_SMP_CPU=y
1066 CONFIG_FEATURE_TOP_DECIMALS=y
1067 CONFIG_FEATURE_TOP_SMP_PROCESS=y
1068 CONFIG_FEATURE_TOPMEM=y
1069 CONFIG_UPTIME=y
1070 CONFIG_FEATURE_UPTIME_UTMP_SUPPORT=y
1071 CONFIG_WATCH=y
1072
1073 #
1074 # Runit Utilities
1075 #
1076 CONFIG_CHPST=y
1077 CONFIG_SETUIDGID=y
1078 CONFIG_ENVUIDGID=y
1079 CONFIG_ENVDIR=y
1080 CONFIG_SOFTLIMIT=y
1081 CONFIG_RUNSV=y
1082 CONFIG_RUNSVDIR=y
1083 # CONFIG_FEATURE_RUNSVDIR_LOG is not set
1084 CONFIG_SV=y
1085 CONFIG_SV_DEFAULT_SERVICE_DIR="/var/service"
1086 CONFIG_SVC=y
1087 CONFIG_SVOK=y
1088 CONFIG_SVLOGD=y
1089 # CONFIG_CHCON is not set
1090 # CONFIG_GETENFORCE is not set
1091 # CONFIG_GETSEBOOL is not set
1092 # CONFIG_LOAD_POLICY is not set
1093 # CONFIG_MATCHPATHCON is not set
1094 # CONFIG_RUNCON is not set
1095 # CONFIG_SELINUXENABLED is not set
1096 # CONFIG_SESTATUS is not set
1097 # CONFIG_SETENFORCE is not set
1098 # CONFIG_SETFILES is not set
1099 # CONFIG_FEATURE_SETFILES_CHECK_OPTION is not set
1100 # CONFIG_RESTORECON is not set
1101 # CONFIG_SETSEBOOL is not set
1102
1103 #
1104 # Shells
1105 #
1106 CONFIG_SH_IS_ASH=y
1107 # CONFIG_SH_IS_HUSH is not set
1108 # CONFIG_SH_IS_NONE is not set
1109 # CONFIG_BASH_IS_ASH is not set
1110 # CONFIG_BASH_IS_HUSH is not set
1111 CONFIG_BASH_IS_NONE=y
1112 CONFIG_SHELL_ASH=y
1113 CONFIG_ASH=y
1114 CONFIG_ASH_OPTIMIZE_FOR_SIZE=y
1115 CONFIG_ASH_INTERNAL_GLOB=y
1116 CONFIG_ASH_BASH_COMPAT=y
1117 # CONFIG_ASH_BASH_SOURCE_CURDIR is not set
1118 CONFIG_ASH_BASH_NOT_FOUND_HOOK=y
1119 CONFIG_ASH_JOB_CONTROL=y
1120 CONFIG_ASH_ALIAS=y
1121 CONFIG_ASH_RANDOM_SUPPORT=y
1122 CONFIG_ASH_EXPAND_PRMT=y
1123 CONFIG_ASH_IDLE_TIMEOUT=y
1124 CONFIG_ASH_MAIL=y
1125 CONFIG_ASH_ECHO=y
1126 CONFIG_ASH_PRINTF=y
1127 CONFIG_ASH_TEST=y
1128 CONFIG_ASH_HELP=y
1129 CONFIG_ASH_GETOPTS=y
1130 CONFIG_ASH_CMDCMD=y
1131 # CONFIG_CTTYHACK is not set
1132 # CONFIG_HUSH is not set
1133 # CONFIG_SHELL_HUSH is not set
1134 # CONFIG_HUSH_BASH_COMPAT is not set
1135 # CONFIG_HUSH_BRACE_EXPANSION is not set
1136 # CONFIG_HUSH_BASH_SOURCE_CURDIR is not set
1137 # CONFIG_HUSH_LINENO_VAR is not set
1138 # CONFIG_HUSH_INTERACTIVE is not set
1139 # CONFIG_HUSH_SAVEHISTORY is not set
1140 # CONFIG_HUSH_JOB is not set
1141 # CONFIG_HUSH_TICK is not set
1142 # CONFIG_HUSH_IF is not set
1143 # CONFIG_HUSH_LOOPS is not set
1144 # CONFIG_HUSH_CASE is not set
1145 # CONFIG_HUSH_FUNCTIONS is not set
1146 # CONFIG_HUSH_LOCAL is not set
1147 # CONFIG_HUSH_RANDOM_SUPPORT is not set
1148 # CONFIG_HUSH_MODE_X is not set
1149 # CONFIG_HUSH_ECHO is not set
1150 # CONFIG_HUSH_PRINTF is not set
1151 # CONFIG_HUSH_TEST is not set
1152 # CONFIG_HUSH_HELP is not set
1153 # CONFIG_HUSH_EXPORT is not set
1154 # CONFIG_HUSH_EXPORT_N is not set
1155 # CONFIG_HUSH_READONLY is not set
1156 # CONFIG_HUSH_KILL is not set
1157 # CONFIG_HUSH_WAIT is not set
1158 # CONFIG_HUSH_COMMAND is not set
1159 # CONFIG_HUSH_TRAP is not set
1160 # CONFIG_HUSH_TYPE is not set
1161 # CONFIG_HUSH_TIMES is not set
1162 # CONFIG_HUSH_READ is not set
1163 # CONFIG_HUSH_SET is not set
1164 # CONFIG_HUSH_UNSET is not set
1165 # CONFIG_HUSH_ULIMIT is not set
1166 # CONFIG_HUSH_UMASK is not set
1167 # CONFIG_HUSH_GETOPTS is not set
1168 # CONFIG_HUSH_MEMLEAK is not set
1169
1170 #
1171 # Options common to all shells
1172 #
1173 CONFIG_FEATURE_SH_MATH=y
1174 CONFIG_FEATURE_SH_MATH_64=y
1175 CONFIG_FEATURE_SH_MATH_BASE=y
1176 CONFIG_FEATURE_SH_EXTRA_QUIET=y
1177 # CONFIG_FEATURE_SH_STANDALONE is not set
1178 # CONFIG_FEATURE_SH_NOFORK is not set
1179 CONFIG_FEATURE_SH_READ_FRAC=y
1180 CONFIG_FEATURE_SH_HISTFILESIZE=y
1181 CONFIG_FEATURE_SH_EMBEDDED_SCRIPTS=y
1182
1183 #
1184 # System Logging Utilities
1185 #
1186 # CONFIG_KLOGD is not set
1187 # CONFIG_FEATURE_KLOGD_KLOGCTL is not set
1188 # CONFIG_LOGGER is not set
1189 # CONFIG_LOGREAD is not set
1190 # CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING is not set
1191 # CONFIG_SYSLOGD is not set
1192 # CONFIG_FEATURE_ROTATE_LOGFILE is not set
1193 # CONFIG_FEATURE_REMOTE_LOG is not set
1194 # CONFIG_FEATURE_SYSLOGD_DUP is not set
1195 # CONFIG_FEATURE_SYSLOGD_CFG is not set
1196 # CONFIG_FEATURE_SYSLOGD_PRECISE_TIMESTAMPS is not set
1197 CONFIG_FEATURE_SYSLOGD_READ_BUFFER_SIZE=0
1198 # CONFIG_FEATURE_IPC_SYSLOG is not set
1199 CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE=0
1200 # CONFIG_FEATURE_KMSG_SYSLOG is not set
+232 -88
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -53,10 +53,19 @@
5353
*/
5454
#if !defined(SQLITE_OS_WINRT)
5555
# define SQLITE_OS_WINRT 0
5656
#endif
5757
58
+/*
59
+** If SQLITE_SHELL_FIDDLE is defined then the shell is modified
60
+** somewhat for use as a WASM module in a web browser. This flag
61
+** should only be used when building the "fiddle" web application, as
62
+** the browser-mode build has much different user input requirements
63
+** and this build mode rewires the user input subsystem to account for
64
+** that.
65
+*/
66
+
5867
/*
5968
** Warning pragmas copied from msvc.h in the core.
6069
*/
6170
#if defined(_MSC_VER)
6271
#pragma warning(disable : 4054)
@@ -245,21 +254,10 @@
245254
#else
246255
# define setBinaryMode(X,Y)
247256
# define setTextMode(X,Y)
248257
#endif
249258
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
-
261259
/* True if the timer is enabled */
262260
static int enableTimer = 0;
263261
264262
/* Return the current wall-clock time */
265263
static sqlite3_int64 timeOfDay(void){
@@ -717,11 +715,11 @@
717715
**
718716
** The result is stored in space obtained from malloc() and must either
719717
** be freed by the caller or else passed back into this routine via the
720718
** zPrior argument for reuse.
721719
*/
722
-#ifndef SQLITE_SHELL_WASM_MODE
720
+#ifndef SQLITE_SHELL_FIDDLE
723721
static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
724722
char *zPrompt;
725723
char *zResult;
726724
if( in!=0 ){
727725
zResult = local_getline(zPrior, in);
@@ -737,11 +735,11 @@
737735
if( zResult && *zResult ) shell_add_history(zResult);
738736
#endif
739737
}
740738
return zResult;
741739
}
742
-#endif /* !SQLITE_SHELL_WASM_MODE */
740
+#endif /* !SQLITE_SHELL_FIDDLE */
743741
744742
/*
745743
** Return the value of a hexadecimal digit. Return -1 if the input
746744
** is not a hex digit.
747745
*/
@@ -3794,10 +3792,11 @@
37943792
#define re_compile sqlite3re_compile
37953793
#define re_free sqlite3re_free
37963794
37973795
/* The end-of-input character */
37983796
#define RE_EOF 0 /* End of input */
3797
+#define RE_START 0xfffffff /* Start of input - larger than an UTF-8 */
37993798
38003799
/* The NFA is implemented as sequence of opcodes taken from the following
38013800
** set. Each opcode has a single integer argument.
38023801
*/
38033802
#define RE_OP_MATCH 1 /* Match the one character in the argument */
@@ -3815,10 +3814,37 @@
38153814
#define RE_OP_DIGIT 13 /* digit: [0-9] */
38163815
#define RE_OP_NOTDIGIT 14 /* Not a digit */
38173816
#define RE_OP_SPACE 15 /* space: [ \t\n\r\v\f] */
38183817
#define RE_OP_NOTSPACE 16 /* Not a digit */
38193818
#define RE_OP_BOUNDARY 17 /* Boundary between word and non-word */
3819
+#define RE_OP_ATSTART 18 /* Currently at the start of the string */
3820
+
3821
+#if defined(SQLITE_DEBUG)
3822
+/* Opcode names used for symbolic debugging */
3823
+static const char *ReOpName[] = {
3824
+ "EOF",
3825
+ "MATCH",
3826
+ "ANY",
3827
+ "ANYSTAR",
3828
+ "FORK",
3829
+ "GOTO",
3830
+ "ACCEPT",
3831
+ "CC_INC",
3832
+ "CC_EXC",
3833
+ "CC_VALUE",
3834
+ "CC_RANGE",
3835
+ "WORD",
3836
+ "NOTWORD",
3837
+ "DIGIT",
3838
+ "NOTDIGIT",
3839
+ "SPACE",
3840
+ "NOTSPACE",
3841
+ "BOUNDARY",
3842
+ "ATSTART",
3843
+};
3844
+#endif /* SQLITE_DEBUG */
3845
+
38203846
38213847
/* Each opcode is a "state" in the NFA */
38223848
typedef unsigned short ReStateNumber;
38233849
38243850
/* Because this is an NFA and not a DFA, multiple states can be active at
@@ -3849,11 +3875,11 @@
38493875
const char *zErr; /* Error message to return */
38503876
char *aOp; /* Operators for the virtual machine */
38513877
int *aArg; /* Arguments to each operator */
38523878
unsigned (*xNextChar)(ReInput*); /* Next character function */
38533879
unsigned char zInit[12]; /* Initial text to match */
3854
- int nInit; /* Number of characters in zInit */
3880
+ int nInit; /* Number of bytes in zInit */
38553881
unsigned nState; /* Number of entries in aOp[] and aArg[] */
38563882
unsigned nAlloc; /* Slots allocated for aOp[] and aArg[] */
38573883
};
38583884
38593885
/* Add a state to the given state set if it is not already there */
@@ -3922,11 +3948,11 @@
39223948
ReStateSet aStateSet[2], *pThis, *pNext;
39233949
ReStateNumber aSpace[100];
39243950
ReStateNumber *pToFree;
39253951
unsigned int i = 0;
39263952
unsigned int iSwap = 0;
3927
- int c = RE_EOF+1;
3953
+ int c = RE_START;
39283954
int cPrev = 0;
39293955
int rc = 0;
39303956
ReInput in;
39313957
39323958
in.z = zIn;
@@ -3941,10 +3967,11 @@
39413967
strncmp((const char*)zIn+in.i, (const char*)pRe->zInit, pRe->nInit)!=0)
39423968
){
39433969
in.i++;
39443970
}
39453971
if( in.i+pRe->nInit>in.mx ) return 0;
3972
+ c = RE_START-1;
39463973
}
39473974
39483975
if( pRe->nState<=(sizeof(aSpace)/(sizeof(aSpace[0])*2)) ){
39493976
pToFree = 0;
39503977
aStateSet[0].aState = aSpace;
@@ -3968,10 +3995,14 @@
39683995
int x = pThis->aState[i];
39693996
switch( pRe->aOp[x] ){
39703997
case RE_OP_MATCH: {
39713998
if( pRe->aArg[x]==c ) re_add_state(pNext, x+1);
39723999
break;
4000
+ }
4001
+ case RE_OP_ATSTART: {
4002
+ if( cPrev==RE_START ) re_add_state(pThis, x+1);
4003
+ break;
39734004
}
39744005
case RE_OP_ANY: {
39754006
if( c!=0 ) re_add_state(pNext, x+1);
39764007
break;
39774008
}
@@ -4050,11 +4081,13 @@
40504081
}
40514082
}
40524083
}
40534084
}
40544085
for(i=0; i<pNext->nState; i++){
4055
- if( pRe->aOp[pNext->aState[i]]==RE_OP_ACCEPT ){ rc = 1; break; }
4086
+ int x = pNext->aState[i];
4087
+ while( pRe->aOp[x]==RE_OP_GOTO ) x += pRe->aArg[x];
4088
+ if( pRe->aOp[x]==RE_OP_ACCEPT ){ rc = 1; break; }
40564089
}
40574090
re_match_end:
40584091
sqlite3_free(pToFree);
40594092
return rc;
40604093
}
@@ -4205,11 +4238,10 @@
42054238
const char *zErr;
42064239
while( (c = p->xNextChar(&p->sIn))!=0 ){
42074240
iStart = p->nState;
42084241
switch( c ){
42094242
case '|':
4210
- case '$':
42114243
case ')': {
42124244
p->sIn.i--;
42134245
return 0;
42144246
}
42154247
case '(': {
@@ -4241,10 +4273,18 @@
42414273
}
42424274
case '?': {
42434275
if( iPrev<0 ) return "'?' without operand";
42444276
re_insert(p, iPrev, RE_OP_FORK, p->nState - iPrev+1);
42454277
break;
4278
+ }
4279
+ case '$': {
4280
+ re_append(p, RE_OP_MATCH, RE_EOF);
4281
+ break;
4282
+ }
4283
+ case '^': {
4284
+ re_append(p, RE_OP_ATSTART, 0);
4285
+ break;
42464286
}
42474287
case '{': {
42484288
int m = 0, n = 0;
42494289
int sz, j;
42504290
if( iPrev<0 ) return "'{m,n}' without operand";
@@ -4260,10 +4300,11 @@
42604300
p->sIn.i++;
42614301
sz = p->nState - iPrev;
42624302
if( m==0 ){
42634303
if( n==0 ) return "both m and n are zero in '{m,n}'";
42644304
re_insert(p, iPrev, RE_OP_FORK, sz+1);
4305
+ iPrev++;
42654306
n--;
42664307
}else{
42674308
for(j=1; j<m; j++) re_copy(p, iPrev, sz);
42684309
}
42694310
for(j=m; j<n; j++){
@@ -4378,15 +4419,11 @@
43784419
zErr = re_subcompile_re(pRe);
43794420
if( zErr ){
43804421
re_free(pRe);
43814422
return zErr;
43824423
}
4383
- if( rePeek(pRe)=='$' && pRe->sIn.i+1>=pRe->sIn.mx ){
4384
- re_append(pRe, RE_OP_MATCH, RE_EOF);
4385
- re_append(pRe, RE_OP_ACCEPT, 0);
4386
- *ppRe = pRe;
4387
- }else if( pRe->sIn.i>=pRe->sIn.mx ){
4424
+ if( pRe->sIn.i>=pRe->sIn.mx ){
43884425
re_append(pRe, RE_OP_ACCEPT, 0);
43894426
*ppRe = pRe;
43904427
}else{
43914428
re_free(pRe);
43924429
return "unrecognized character";
@@ -4465,10 +4502,71 @@
44654502
}
44664503
if( setAux ){
44674504
sqlite3_set_auxdata(context, 0, pRe, (void(*)(void*))re_free);
44684505
}
44694506
}
4507
+
4508
+#if defined(SQLITE_DEBUG)
4509
+/*
4510
+** This function is used for testing and debugging only. It is only available
4511
+** if the SQLITE_DEBUG compile-time option is used.
4512
+**
4513
+** Compile a regular expression and then convert the compiled expression into
4514
+** text and return that text.
4515
+*/
4516
+static void re_bytecode_func(
4517
+ sqlite3_context *context,
4518
+ int argc,
4519
+ sqlite3_value **argv
4520
+){
4521
+ const char *zPattern;
4522
+ const char *zErr;
4523
+ ReCompiled *pRe;
4524
+ sqlite3_str *pStr;
4525
+ int i;
4526
+ int n;
4527
+ char *z;
4528
+
4529
+ zPattern = (const char*)sqlite3_value_text(argv[0]);
4530
+ if( zPattern==0 ) return;
4531
+ zErr = re_compile(&pRe, zPattern, sqlite3_user_data(context)!=0);
4532
+ if( zErr ){
4533
+ re_free(pRe);
4534
+ sqlite3_result_error(context, zErr, -1);
4535
+ return;
4536
+ }
4537
+ if( pRe==0 ){
4538
+ sqlite3_result_error_nomem(context);
4539
+ return;
4540
+ }
4541
+ pStr = sqlite3_str_new(0);
4542
+ if( pStr==0 ) goto re_bytecode_func_err;
4543
+ if( pRe->nInit>0 ){
4544
+ sqlite3_str_appendf(pStr, "INIT ");
4545
+ for(i=0; i<pRe->nInit; i++){
4546
+ sqlite3_str_appendf(pStr, "%02x", pRe->zInit[i]);
4547
+ }
4548
+ sqlite3_str_appendf(pStr, "\n");
4549
+ }
4550
+ for(i=0; (unsigned)i<pRe->nState; i++){
4551
+ sqlite3_str_appendf(pStr, "%-8s %4d\n",
4552
+ ReOpName[(unsigned char)pRe->aOp[i]], pRe->aArg[i]);
4553
+ }
4554
+ n = sqlite3_str_length(pStr);
4555
+ z = sqlite3_str_finish(pStr);
4556
+ if( n==0 ){
4557
+ sqlite3_free(z);
4558
+ }else{
4559
+ sqlite3_result_text(context, z, n-1, sqlite3_free);
4560
+ }
4561
+
4562
+re_bytecode_func_err:
4563
+ re_free(pRe);
4564
+}
4565
+
4566
+#endif /* SQLITE_DEBUG */
4567
+
44704568
44714569
/*
44724570
** Invoke this routine to register the regexp() function with the
44734571
** SQLite database connection.
44744572
*/
@@ -4490,16 +4588,23 @@
44904588
/* The regexpi(PATTERN,STRING) function is a case-insensitive version
44914589
** of regexp(PATTERN,STRING). */
44924590
rc = sqlite3_create_function(db, "regexpi", 2,
44934591
SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
44944592
(void*)db, re_sql_func, 0, 0);
4593
+#if defined(SQLITE_DEBUG)
4594
+ if( rc==SQLITE_OK ){
4595
+ rc = sqlite3_create_function(db, "regexp_bytecode", 1,
4596
+ SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
4597
+ 0, re_bytecode_func, 0, 0);
4598
+ }
4599
+#endif /* SQLITE_DEBUG */
44954600
}
44964601
return rc;
44974602
}
44984603
44994604
/************************* End ../ext/misc/regexp.c ********************/
4500
-#ifndef SQLITE_SHELL_WASM_MODE
4605
+#ifndef SQLITE_SHELL_FIDDLE
45014606
/************************* Begin ../ext/misc/fileio.c ******************/
45024607
/*
45034608
** 2014-06-13
45044609
**
45054610
** The author disclaims copyright to this source code. In place of
@@ -10047,10 +10152,14 @@
1004710152
** Return true if zId must be quoted in order to use it as an SQL
1004810153
** identifier, or false otherwise.
1004910154
*/
1005010155
static int idxIdentifierRequiresQuotes(const char *zId){
1005110156
int i;
10157
+ int nId = STRLEN(zId);
10158
+
10159
+ if( sqlite3_keyword_check(zId, nId) ) return 1;
10160
+
1005210161
for(i=0; zId[i]; i++){
1005310162
if( !(zId[i]=='_')
1005410163
&& !(zId[i]>='0' && zId[i]<='9')
1005510164
&& !(zId[i]>='a' && zId[i]<='z')
1005610165
&& !(zId[i]>='A' && zId[i]<='Z')
@@ -12248,19 +12357,19 @@
1224812357
int nIndent; /* Size of array aiIndent[] */
1224912358
int iIndent; /* Index of current op in aiIndent[] */
1225012359
char *zNonce; /* Nonce for temporary safe-mode excapes */
1225112360
EQPGraph sGraph; /* Information for the graphical EXPLAIN QUERY PLAN */
1225212361
ExpertInfo expert; /* Valid if previous command was ".expert OPT..." */
12253
-#ifdef SQLITE_SHELL_WASM_MODE
12362
+#ifdef SQLITE_SHELL_FIDDLE
1225412363
struct {
1225512364
const char * zInput; /* Input string from wasm/JS proxy */
1225612365
const char * zPos; /* Cursor pos into zInput */
1225712366
} wasm;
1225812367
#endif
1225912368
};
1226012369
12261
-#ifdef SQLITE_SHELL_WASM_MODE
12370
+#ifdef SQLITE_SHELL_FIDDLE
1226212371
static ShellState shellState;
1226312372
#endif
1226412373
1226512374
1226612375
/* Allowed values for ShellState.autoEQP
@@ -12588,14 +12697,27 @@
1258812697
/*
1258912698
** Output the given string as a hex-encoded blob (eg. X'1234' )
1259012699
*/
1259112700
static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){
1259212701
int i;
12593
- char *zBlob = (char *)pBlob;
12594
- raw_printf(out,"X'");
12595
- for(i=0; i<nBlob; i++){ raw_printf(out,"%02x",zBlob[i]&0xff); }
12596
- raw_printf(out,"'");
12702
+ unsigned char *aBlob = (unsigned char*)pBlob;
12703
+
12704
+ char *zStr = sqlite3_malloc(nBlob*2 + 1);
12705
+ shell_check_oom(zStr);
12706
+
12707
+ for(i=0; i<nBlob; i++){
12708
+ static const char aHex[] = {
12709
+ '0', '1', '2', '3', '4', '5', '6', '7',
12710
+ '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
12711
+ };
12712
+ zStr[i*2] = aHex[ (aBlob[i] >> 4) ];
12713
+ zStr[i*2+1] = aHex[ (aBlob[i] & 0x0F) ];
12714
+ }
12715
+ zStr[i*2] = '\0';
12716
+
12717
+ raw_printf(out,"X'%s'", zStr);
12718
+ sqlite3_free(zStr);
1259712719
}
1259812720
1259912721
/*
1260012722
** Find a string that is not found anywhere in z[]. Return a pointer
1260112723
** to that string.
@@ -12924,11 +13046,11 @@
1292413046
UNUSED_PARAMETER(zA2);
1292513047
UNUSED_PARAMETER(zA3);
1292613048
UNUSED_PARAMETER(zA4);
1292713049
switch( op ){
1292813050
case SQLITE_ATTACH: {
12929
-#ifndef SQLITE_SHELL_WASM_MODE
13051
+#ifndef SQLITE_SHELL_FIDDLE
1293013052
/* In WASM builds the filesystem is a virtual sandbox, so
1293113053
** there's no harm in using ATTACH. */
1293213054
failIfSafeMode(p, "cannot run ATTACH in safe mode");
1293313055
#endif
1293413056
break;
@@ -12997,19 +13119,41 @@
1299713119
/*
1299813120
** Print a schema statement. Part of MODE_Semi and MODE_Pretty output.
1299913121
**
1300013122
** This routine converts some CREATE TABLE statements for shadow tables
1300113123
** in FTS3/4/5 into CREATE TABLE IF NOT EXISTS statements.
13124
+**
13125
+** If the schema statement in z[] contains a start-of-comment and if
13126
+** sqlite3_complete() returns false, try to terminate the comment before
13127
+** printing the result. https://sqlite.org/forum/forumpost/d7be961c5c
1300213128
*/
1300313129
static void printSchemaLine(FILE *out, const char *z, const char *zTail){
13130
+ char *zToFree = 0;
1300413131
if( z==0 ) return;
1300513132
if( zTail==0 ) return;
13133
+ if( zTail[0]==';' && (strstr(z, "/*")!=0 || strstr(z,"--")!=0) ){
13134
+ const char *zOrig = z;
13135
+ static const char *azTerm[] = { "", "*/", "\n" };
13136
+ int i;
13137
+ for(i=0; i<ArraySize(azTerm); i++){
13138
+ char *zNew = sqlite3_mprintf("%s%s;", zOrig, azTerm[i]);
13139
+ if( sqlite3_complete(zNew) ){
13140
+ size_t n = strlen(zNew);
13141
+ zNew[n-1] = 0;
13142
+ zToFree = zNew;
13143
+ z = zNew;
13144
+ break;
13145
+ }
13146
+ sqlite3_free(zNew);
13147
+ }
13148
+ }
1300613149
if( sqlite3_strglob("CREATE TABLE ['\"]*", z)==0 ){
1300713150
utf8_printf(out, "CREATE TABLE IF NOT EXISTS %s%s", z+13, zTail);
1300813151
}else{
1300913152
utf8_printf(out, "%s%s", z, zTail);
1301013153
}
13154
+ sqlite3_free(zToFree);
1301113155
}
1301213156
static void printSchemaLineN(FILE *out, char *z, int n, const char *zTail){
1301313157
char c = z[n];
1301413158
z[n] = 0;
1301513159
printSchemaLine(out, z, zTail);
@@ -15338,11 +15482,11 @@
1533815482
** There must be two or more spaces between the end of the command and the
1533915483
** start of the description of what that command does.
1534015484
*/
1534115485
static const char *(azHelp[]) = {
1534215486
#if defined(SQLITE_HAVE_ZLIB) && !defined(SQLITE_OMIT_VIRTUALTABLE) \
15343
- && !defined(SQLITE_SHELL_WASM_MODE)
15487
+ && !defined(SQLITE_SHELL_FIDDLE)
1534415488
".archive ... Manage SQL archives",
1534515489
" Each command must have exactly one of the following options:",
1534615490
" -c, --create Create a new archive",
1534715491
" -u, --update Add or update files with changed mtime",
1534815492
" -i, --insert Like -u but always add even if unchanged",
@@ -15364,23 +15508,23 @@
1536415508
" http://sqlite.org/cli.html#sqlite_archive_support",
1536515509
#endif
1536615510
#ifndef SQLITE_OMIT_AUTHORIZATION
1536715511
".auth ON|OFF Show authorizer callbacks",
1536815512
#endif
15369
-#ifndef SQLITE_SHELL_WASM_MODE
15513
+#ifndef SQLITE_SHELL_FIDDLE
1537015514
".backup ?DB? FILE Backup DB (default \"main\") to FILE",
1537115515
" Options:",
1537215516
" --append Use the appendvfs",
1537315517
" --async Write to FILE without journal and fsync()",
1537415518
#endif
1537515519
".bail on|off Stop after hitting an error. Default OFF",
1537615520
".binary on|off Turn binary output on or off. Default OFF",
15377
-#ifndef SQLITE_SHELL_WASM_MODE
15521
+#ifndef SQLITE_SHELL_FIDDLE
1537815522
".cd DIRECTORY Change the working directory to DIRECTORY",
1537915523
#endif
1538015524
".changes on|off Show number of rows changed by SQL",
15381
-#ifndef SQLITE_SHELL_WASM_MODE
15525
+#ifndef SQLITE_SHELL_FIDDLE
1538215526
".check GLOB Fail if output since .testcase does not match",
1538315527
".clone NEWDB Clone data into NEWDB from the existing database",
1538415528
#endif
1538515529
".connection [close] [#] Open or close an auxiliary database connection",
1538615530
".databases List names and files of attached databases",
@@ -15402,15 +15546,15 @@
1540215546
#ifdef SQLITE_DEBUG
1540315547
" test Show raw EXPLAIN QUERY PLAN output",
1540415548
" trace Like \"full\" but enable \"PRAGMA vdbe_trace\"",
1540515549
#endif
1540615550
" trigger Like \"full\" but also show trigger bytecode",
15407
-#ifndef SQLITE_SHELL_WASM_MODE
15551
+#ifndef SQLITE_SHELL_FIDDLE
1540815552
".excel Display the output of next command in spreadsheet",
1540915553
" --bom Put a UTF8 byte-order mark on intermediate file",
1541015554
#endif
15411
-#ifndef SQLITE_SHELL_WASM_MODE
15555
+#ifndef SQLITE_SHELL_FIDDLE
1541215556
".exit ?CODE? Exit this program with return-code CODE",
1541315557
#endif
1541415558
".expert EXPERIMENTAL. Suggest indexes for queries",
1541515559
".explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto",
1541615560
".filectrl CMD ... Run various sqlite3_file_control() operations",
@@ -15417,11 +15561,11 @@
1541715561
" --schema SCHEMA Use SCHEMA instead of \"main\"",
1541815562
" --help Show CMD details",
1541915563
".fullschema ?--indent? Show schema and the content of sqlite_stat tables",
1542015564
".headers on|off Turn display of headers on or off",
1542115565
".help ?-all? ?PATTERN? Show help text for PATTERN",
15422
-#ifndef SQLITE_SHELL_WASM_MODE
15566
+#ifndef SQLITE_SHELL_FIDDLE
1542315567
".import FILE TABLE Import data from FILE into TABLE",
1542415568
" Options:",
1542515569
" --ascii Use \\037 and \\036 as column and row separators",
1542615570
" --csv Use , and \\n as column and row separators",
1542715571
" --skip N Skip the first N rows of input",
@@ -15446,14 +15590,14 @@
1544615590
#endif
1544715591
".limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT",
1544815592
".lint OPTIONS Report potential schema issues.",
1544915593
" Options:",
1545015594
" fkey-indexes Find missing foreign key indexes",
15451
-#if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_WASM_MODE)
15595
+#if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_FIDDLE)
1545215596
".load FILE ?ENTRY? Load an extension library",
1545315597
#endif
15454
-#ifndef SQLITE_SHELL_WASM_MODE
15598
+#ifndef SQLITE_SHELL_FIDDLE
1545515599
".log FILE|off Turn logging on or off. FILE can be stderr/stdout",
1545615600
#endif
1545715601
".mode MODE ?OPTIONS? Set output mode",
1545815602
" MODE is one of:",
1545915603
" ascii Columns/rows delimited by 0x1F and 0x1E",
@@ -15476,15 +15620,15 @@
1547615620
" --wordwrap B Wrap or not at word boundaries per B (on/off)",
1547715621
" --ww Shorthand for \"--wordwrap 1\"",
1547815622
" --quote Quote output text as SQL literals",
1547915623
" --noquote Do not quote output text",
1548015624
" TABLE The name of SQL table used for \"insert\" mode",
15481
-#ifndef SQLITE_SHELL_WASM_MODE
15625
+#ifndef SQLITE_SHELL_FIDDLE
1548215626
".nonce STRING Suspend safe mode for one command if nonce matches",
1548315627
#endif
1548415628
".nullvalue STRING Use STRING in place of NULL values",
15485
-#ifndef SQLITE_SHELL_WASM_MODE
15629
+#ifndef SQLITE_SHELL_FIDDLE
1548615630
".once ?OPTIONS? ?FILE? Output for the next SQL command only to FILE",
1548715631
" If FILE begins with '|' then open as a pipe",
1548815632
" --bom Put a UTF8 byte-order mark at the beginning",
1548915633
" -e Send output to the system text editor",
1549015634
" -x Send output as CSV to a spreadsheet (same as \".excel\")",
@@ -15502,11 +15646,11 @@
1550215646
#endif
1550315647
" --new Initialize FILE to an empty database",
1550415648
" --nofollow Do not follow symbolic links",
1550515649
" --readonly Open FILE readonly",
1550615650
" --zip FILE is a ZIP archive",
15507
-#ifndef SQLITE_SHELL_WASM_MODE
15651
+#ifndef SQLITE_SHELL_FIDDLE
1550815652
".output ?FILE? Send output to FILE or stdout if FILE is omitted",
1550915653
" If FILE begins with '|' then open it as a pipe.",
1551015654
" Options:",
1551115655
" --bom Prefix output with a UTF8 byte-order mark",
1551215656
" -e Send output to the system text editor",
@@ -15526,11 +15670,11 @@
1552615670
" --once Do no more than one progress interrupt",
1552715671
" --quiet|-q No output except at interrupts",
1552815672
" --reset Reset the count for each input and interrupt",
1552915673
#endif
1553015674
".prompt MAIN CONTINUE Replace the standard prompts",
15531
-#ifndef SQLITE_SHELL_WASM_MODE
15675
+#ifndef SQLITE_SHELL_FIDDLE
1553215676
".quit Exit this program",
1553315677
".read FILE Read input from FILE or command output",
1553415678
" If FILE begins with \"|\", it is a command that generates the input.",
1553515679
#endif
1553615680
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
@@ -15539,11 +15683,11 @@
1553915683
" --recovery-db NAME Store recovery metadata in database file NAME",
1554015684
" --lost-and-found TABLE Alternative name for the lost-and-found table",
1554115685
" --no-rowids Do not attempt to recover rowid values",
1554215686
" that are not also INTEGER PRIMARY KEYs",
1554315687
#endif
15544
-#ifndef SQLITE_SHELL_WASM_MODE
15688
+#ifndef SQLITE_SHELL_FIDDLE
1554515689
".restore ?DB? FILE Restore content of DB (default \"main\") from FILE",
1554615690
".save ?OPTIONS? FILE Write database to FILE (an alias for .backup ...)",
1554715691
#endif
1554815692
".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off",
1554915693
".schema ?PATTERN? Show the CREATE statements matching PATTERN",
@@ -15576,24 +15720,24 @@
1557615720
" --sha3-224 Use the sha3-224 algorithm",
1557715721
" --sha3-256 Use the sha3-256 algorithm (default)",
1557815722
" --sha3-384 Use the sha3-384 algorithm",
1557915723
" --sha3-512 Use the sha3-512 algorithm",
1558015724
" Any other argument is a LIKE pattern for tables to hash",
15581
-#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE)
15725
+#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
1558215726
".shell CMD ARGS... Run CMD ARGS... in a system shell",
1558315727
#endif
1558415728
".show Show the current values for various settings",
1558515729
".stats ?ARG? Show stats or turn stats on or off",
1558615730
" off Turn off automatic stat display",
1558715731
" on Turn on automatic stat display",
1558815732
" stmt Show statement stats",
1558915733
" vmstep Show the virtual machine step count only",
15590
-#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE)
15734
+#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
1559115735
".system CMD ARGS... Run CMD ARGS... in a system shell",
1559215736
#endif
1559315737
".tables ?TABLE? List names of tables matching LIKE pattern TABLE",
15594
-#ifndef SQLITE_SHELL_WASM_MODE
15738
+#ifndef SQLITE_SHELL_FIDDLE
1559515739
".testcase NAME Begin redirecting output to 'testcase-out.txt'",
1559615740
#endif
1559715741
".testctrl CMD ... Run various sqlite3_test_control() operations",
1559815742
" Run \".testctrl\" with no arguments for details",
1559915743
".timeout MS Try opening locked tables for MS milliseconds",
@@ -16142,11 +16286,11 @@
1614216286
sqlite3_uint_init(p->db, 0, 0);
1614316287
sqlite3_decimal_init(p->db, 0, 0);
1614416288
sqlite3_regexp_init(p->db, 0, 0);
1614516289
sqlite3_ieee_init(p->db, 0, 0);
1614616290
sqlite3_series_init(p->db, 0, 0);
16147
-#ifndef SQLITE_SHELL_WASM_MODE
16291
+#ifndef SQLITE_SHELL_FIDDLE
1614816292
sqlite3_fileio_init(p->db, 0, 0);
1614916293
sqlite3_completion_init(p->db, 0, 0);
1615016294
#endif
1615116295
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
1615216296
sqlite3_dbdata_init(p->db, 0, 0);
@@ -19272,19 +19416,19 @@
1927219416
}
1927319417
}else
1927419418
#endif
1927519419
1927619420
#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB) \
19277
- && !defined(SQLITE_SHELL_WASM_MODE)
19421
+ && !defined(SQLITE_SHELL_FIDDLE)
1927819422
if( c=='a' && strncmp(azArg[0], "archive", n)==0 ){
1927919423
open_db(p, 0);
1928019424
failIfSafeMode(p, "cannot run .archive in safe mode");
1928119425
rc = arDotCommand(p, 0, azArg, nArg);
1928219426
}else
1928319427
#endif
1928419428
19285
-#ifndef SQLITE_SHELL_WASM_MODE
19429
+#ifndef SQLITE_SHELL_FIDDLE
1928619430
if( (c=='b' && n>=3 && strncmp(azArg[0], "backup", n)==0)
1928719431
|| (c=='s' && n>=3 && strncmp(azArg[0], "save", n)==0)
1928819432
){
1928919433
const char *zDestFile = 0;
1929019434
const char *zDb = 0;
@@ -19349,11 +19493,11 @@
1934919493
utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
1935019494
rc = 1;
1935119495
}
1935219496
close_db(pDest);
1935319497
}else
19354
-#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
19498
+#endif /* !defined(SQLITE_SHELL_FIDDLE) */
1935519499
1935619500
if( c=='b' && n>=3 && strncmp(azArg[0], "bail", n)==0 ){
1935719501
if( nArg==2 ){
1935819502
bail_on_error = booleanValue(azArg[1]);
1935919503
}else{
@@ -19380,11 +19524,11 @@
1938019524
*/
1938119525
if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
1938219526
test_breakpoint();
1938319527
}else
1938419528
19385
-#ifndef SQLITE_SHELL_WASM_MODE
19529
+#ifndef SQLITE_SHELL_FIDDLE
1938619530
if( c=='c' && strcmp(azArg[0],"cd")==0 ){
1938719531
failIfSafeMode(p, "cannot run .cd in safe mode");
1938819532
if( nArg==2 ){
1938919533
#if defined(_WIN32) || defined(WIN32)
1939019534
wchar_t *z = sqlite3_win32_utf8_to_unicode(azArg[1]);
@@ -19400,11 +19544,11 @@
1940019544
}else{
1940119545
raw_printf(stderr, "Usage: .cd DIRECTORY\n");
1940219546
rc = 1;
1940319547
}
1940419548
}else
19405
-#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
19549
+#endif /* !defined(SQLITE_SHELL_FIDDLE) */
1940619550
1940719551
if( c=='c' && n>=3 && strncmp(azArg[0], "changes", n)==0 ){
1940819552
if( nArg==2 ){
1940919553
setOrClearFlag(p, SHFLG_CountChanges, azArg[1]);
1941019554
}else{
@@ -19411,11 +19555,11 @@
1941119555
raw_printf(stderr, "Usage: .changes on|off\n");
1941219556
rc = 1;
1941319557
}
1941419558
}else
1941519559
19416
-#ifndef SQLITE_SHELL_WASM_MODE
19560
+#ifndef SQLITE_SHELL_FIDDLE
1941719561
/* Cancel output redirection, if it is currently set (by .testcase)
1941819562
** Then read the content of the testcase-out.txt file and compare against
1941919563
** azArg[1]. If there are differences, report an error and exit.
1942019564
*/
1942119565
if( c=='c' && n>=3 && strncmp(azArg[0], "check", n)==0 ){
@@ -19436,23 +19580,23 @@
1943619580
utf8_printf(stdout, "testcase-%s ok\n", p->zTestcase);
1943719581
p->nCheck++;
1943819582
}
1943919583
sqlite3_free(zRes);
1944019584
}else
19441
-#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
19585
+#endif /* !defined(SQLITE_SHELL_FIDDLE) */
1944219586
19443
-#ifndef SQLITE_SHELL_WASM_MODE
19587
+#ifndef SQLITE_SHELL_FIDDLE
1944419588
if( c=='c' && strncmp(azArg[0], "clone", n)==0 ){
1944519589
failIfSafeMode(p, "cannot run .clone in safe mode");
1944619590
if( nArg==2 ){
1944719591
tryToClone(p, azArg[1]);
1944819592
}else{
1944919593
raw_printf(stderr, "Usage: .clone FILENAME\n");
1945019594
rc = 1;
1945119595
}
1945219596
}else
19453
-#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
19597
+#endif /* !defined(SQLITE_SHELL_FIDDLE) */
1945419598
1945519599
if( c=='c' && strncmp(azArg[0], "connection", n)==0 ){
1945619600
if( nArg==1 ){
1945719601
/* List available connections */
1945819602
int i;
@@ -19737,11 +19881,11 @@
1973719881
raw_printf(stderr, "Usage: .eqp off|on|trace|trigger|full\n");
1973819882
rc = 1;
1973919883
}
1974019884
}else
1974119885
19742
-#ifndef SQLITE_SHELL_WASM_MODE
19886
+#ifndef SQLITE_SHELL_FIDDLE
1974319887
if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
1974419888
if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
1974519889
rc = 2;
1974619890
}else
1974719891
#endif
@@ -19997,11 +20141,11 @@
1999720141
}else{
1999820142
showHelp(p->out, 0);
1999920143
}
2000020144
}else
2000120145
20002
-#ifndef SQLITE_SHELL_WASM_MODE
20146
+#ifndef SQLITE_SHELL_FIDDLE
2000320147
if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
2000420148
char *zTable = 0; /* Insert data into this table */
2000520149
char *zSchema = 0; /* within this schema (may default to "main") */
2000620150
char *zFile = 0; /* Name of file to extra content from */
2000720151
sqlite3_stmt *pStmt = NULL; /* A statement */
@@ -20288,11 +20432,11 @@
2028820432
utf8_printf(p->out,
2028920433
"Added %d rows with %d errors using %d lines of input\n",
2029020434
sCtx.nRow, sCtx.nErr, sCtx.nLine-1);
2029120435
}
2029220436
}else
20293
-#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
20437
+#endif /* !defined(SQLITE_SHELL_FIDDLE) */
2029420438
2029520439
#ifndef SQLITE_UNTESTABLE
2029620440
if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
2029720441
char *zSql;
2029820442
char *zCollist = 0;
@@ -20478,11 +20622,11 @@
2047820622
if( c=='l' && n>2 && strncmp(azArg[0], "lint", n)==0 ){
2047920623
open_db(p, 0);
2048020624
lintDotCommand(p, azArg, nArg);
2048120625
}else
2048220626
20483
-#if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_WASM_MODE)
20627
+#if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_FIDDLE)
2048420628
if( c=='l' && strncmp(azArg[0], "load", n)==0 ){
2048520629
const char *zFile, *zProc;
2048620630
char *zErrMsg = 0;
2048720631
failIfSafeMode(p, "cannot run .load in safe mode");
2048820632
if( nArg<2 ){
@@ -20500,11 +20644,11 @@
2050020644
rc = 1;
2050120645
}
2050220646
}else
2050320647
#endif
2050420648
20505
-#ifndef SQLITE_SHELL_WASM_MODE
20649
+#ifndef SQLITE_SHELL_FIDDLE
2050620650
if( c=='l' && strncmp(azArg[0], "log", n)==0 ){
2050720651
failIfSafeMode(p, "cannot run .log in safe mode");
2050820652
if( nArg!=2 ){
2050920653
raw_printf(stderr, "Usage: .log FILENAME\n");
2051020654
rc = 1;
@@ -20637,11 +20781,11 @@
2063720781
rc = 1;
2063820782
}
2063920783
p->cMode = p->mode;
2064020784
}else
2064120785
20642
-#ifndef SQLITE_SHELL_WASM_MODE
20786
+#ifndef SQLITE_SHELL_FIDDLE
2064320787
if( c=='n' && strcmp(azArg[0], "nonce")==0 ){
2064420788
if( nArg!=2 ){
2064520789
raw_printf(stderr, "Usage: .nonce NONCE\n");
2064620790
rc = 1;
2064720791
}else if( p->zNonce==0 || strcmp(azArg[1],p->zNonce)!=0 ){
@@ -20652,11 +20796,11 @@
2065220796
p->bSafeMode = 0;
2065320797
return 0; /* Return immediately to bypass the safe mode reset
2065420798
** at the end of this procedure */
2065520799
}
2065620800
}else
20657
-#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
20801
+#endif /* !defined(SQLITE_SHELL_FIDDLE) */
2065820802
2065920803
if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 ){
2066020804
if( nArg==2 ){
2066120805
sqlite3_snprintf(sizeof(p->nullValue), p->nullValue,
2066220806
"%.*s", (int)ArraySize(p->nullValue)-1, azArg[1]);
@@ -20674,11 +20818,11 @@
2067420818
int openMode = SHELL_OPEN_UNSPEC;
2067520819
2067620820
/* Check for command-line arguments */
2067720821
for(iName=1; iName<nArg; iName++){
2067820822
const char *z = azArg[iName];
20679
-#ifndef SQLITE_SHELL_WASM_MODE
20823
+#ifndef SQLITE_SHELL_FIDDLE
2068020824
if( optionMatch(z,"new") ){
2068120825
newFlag = 1;
2068220826
#ifdef SQLITE_HAVE_ZLIB
2068320827
}else if( optionMatch(z, "zip") ){
2068420828
openMode = SHELL_OPEN_ZIPFILE;
@@ -20696,11 +20840,11 @@
2069620840
openMode = SHELL_OPEN_HEXDB;
2069720841
}else if( optionMatch(z, "maxsize") && iName+1<nArg ){
2069820842
p->szMax = integerValue(azArg[++iName]);
2069920843
#endif /* SQLITE_OMIT_DESERIALIZE */
2070020844
}else
20701
-#endif /* !SQLITE_SHELL_WASM_MODE */
20845
+#endif /* !SQLITE_SHELL_FIDDLE */
2070220846
if( z[0]=='-' ){
2070320847
utf8_printf(stderr, "unknown option: %s\n", z);
2070420848
rc = 1;
2070520849
goto meta_command_exit;
2070620850
}else if( zFN ){
@@ -20724,11 +20868,11 @@
2072420868
p->szMax = 0;
2072520869
2072620870
/* If a filename is specified, try to open it first */
2072720871
if( zFN || p->openMode==SHELL_OPEN_HEXDB ){
2072820872
if( newFlag && zFN && !p->bSafeMode ) shellDeleteFile(zFN);
20729
-#ifndef SQLITE_SHELL_WASM_MODE
20873
+#ifndef SQLITE_SHELL_FIDDLE
2073020874
if( p->bSafeMode
2073120875
&& p->openMode!=SHELL_OPEN_HEXDB
2073220876
&& zFN
2073320877
&& strcmp(zFN,":memory:")!=0
2073420878
){
@@ -20757,11 +20901,11 @@
2075720901
p->pAuxDb->zDbFilename = 0;
2075820902
open_db(p, 0);
2075920903
}
2076020904
}else
2076120905
20762
-#ifndef SQLITE_SHELL_WASM_MODE
20906
+#ifndef SQLITE_SHELL_FIDDLE
2076320907
if( (c=='o'
2076420908
&& (strncmp(azArg[0], "output", n)==0||strncmp(azArg[0], "once", n)==0))
2076520909
|| (c=='e' && n==5 && strcmp(azArg[0],"excel")==0)
2076620910
){
2076720911
char *zFile = 0;
@@ -20873,11 +21017,11 @@
2087321017
sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
2087421018
}
2087521019
}
2087621020
sqlite3_free(zFile);
2087721021
}else
20878
-#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
21022
+#endif /* !defined(SQLITE_SHELL_FIDDLE) */
2087921023
2088021024
if( c=='p' && n>=3 && strncmp(azArg[0], "parameter", n)==0 ){
2088121025
open_db(p,0);
2088221026
if( nArg<=1 ) goto parameter_syntax_error;
2088321027
@@ -21043,17 +21187,17 @@
2104321187
if( nArg >= 3) {
2104421188
strncpy(continuePrompt,azArg[2],(int)ArraySize(continuePrompt)-1);
2104521189
}
2104621190
}else
2104721191
21048
-#ifndef SQLITE_SHELL_WASM_MODE
21192
+#ifndef SQLITE_SHELL_FIDDLE
2104921193
if( c=='q' && strncmp(azArg[0], "quit", n)==0 ){
2105021194
rc = 2;
2105121195
}else
2105221196
#endif
2105321197
21054
-#ifndef SQLITE_SHELL_WASM_MODE
21198
+#ifndef SQLITE_SHELL_FIDDLE
2105521199
if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 ){
2105621200
FILE *inSaved = p->in;
2105721201
int savedLineno = p->lineno;
2105821202
failIfSafeMode(p, "cannot run .read in safe mode");
2105921203
if( nArg!=2 ){
@@ -21084,13 +21228,13 @@
2108421228
fclose(p->in);
2108521229
}
2108621230
p->in = inSaved;
2108721231
p->lineno = savedLineno;
2108821232
}else
21089
-#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
21233
+#endif /* !defined(SQLITE_SHELL_FIDDLE) */
2109021234
21091
-#ifndef SQLITE_SHELL_WASM_MODE
21235
+#ifndef SQLITE_SHELL_FIDDLE
2109221236
if( c=='r' && n>=3 && strncmp(azArg[0], "restore", n)==0 ){
2109321237
const char *zSrcFile;
2109421238
const char *zDb;
2109521239
sqlite3 *pSrc;
2109621240
sqlite3_backup *pBackup;
@@ -21138,11 +21282,11 @@
2113821282
utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
2113921283
rc = 1;
2114021284
}
2114121285
close_db(pSrc);
2114221286
}else
21143
-#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
21287
+#endif /* !defined(SQLITE_SHELL_FIDDLE) */
2114421288
2114521289
if( c=='s' && strncmp(azArg[0], "scanstats", n)==0 ){
2114621290
if( nArg==2 ){
2114721291
p->scanstatsOn = (u8)booleanValue(azArg[1]);
2114821292
#ifndef SQLITE_ENABLE_STMT_SCANSTATUS
@@ -21764,11 +21908,11 @@
2176421908
shell_exec(p, zSql, 0);
2176521909
}
2176621910
sqlite3_free(zSql);
2176721911
}else
2176821912
21769
-#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE)
21913
+#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
2177021914
if( c=='s'
2177121915
&& (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
2177221916
){
2177321917
char *zCmd;
2177421918
int i, x;
@@ -21785,11 +21929,11 @@
2178521929
}
2178621930
x = zCmd!=0 ? system(zCmd) : 1;
2178721931
sqlite3_free(zCmd);
2178821932
if( x ) raw_printf(stderr, "System command returns %d\n", x);
2178921933
}else
21790
-#endif /* !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE) */
21934
+#endif /* !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE) */
2179121935
2179221936
if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
2179321937
static const char *azBool[] = { "off", "on", "trigger", "full"};
2179421938
const char *zOut;
2179521939
int i;
@@ -21965,11 +22109,11 @@
2196522109
2196622110
for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
2196722111
sqlite3_free(azResult);
2196822112
}else
2196922113
21970
-#ifndef SQLITE_SHELL_WASM_MODE
22114
+#ifndef SQLITE_SHELL_FIDDLE
2197122115
/* Begin redirecting output to the file "testcase-out.txt" */
2197222116
if( c=='t' && strcmp(azArg[0],"testcase")==0 ){
2197322117
output_reset(p);
2197422118
p->out = output_file_open("testcase-out.txt", 0);
2197522119
if( p->out==0 ){
@@ -21979,11 +22123,11 @@
2197922123
sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
2198022124
}else{
2198122125
sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?");
2198222126
}
2198322127
}else
21984
-#endif /* !defined(SQLITE_SHELL_WASM_MODE) */
22128
+#endif /* !defined(SQLITE_SHELL_FIDDLE) */
2198522129
2198622130
#ifndef SQLITE_UNTESTABLE
2198722131
if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 ){
2198822132
static const struct {
2198922133
const char *zCtrlName; /* Name of a test-control option */
@@ -22651,11 +22795,11 @@
2265122795
2265222796
static void echo_group_input(ShellState *p, const char *zDo){
2265322797
if( ShellHasFlag(p, SHFLG_Echo) ) utf8_printf(p->out, "%s\n", zDo);
2265422798
}
2265522799
22656
-#ifdef SQLITE_SHELL_WASM_MODE
22800
+#ifdef SQLITE_SHELL_FIDDLE
2265722801
/*
2265822802
** Alternate one_input_line() impl for wasm mode. This is not in the primary impl
2265922803
** because we need the global shellState and cannot access it from that function
2266022804
** without moving lots of code around (creating a larger/messier diff).
2266122805
*/
@@ -22682,11 +22826,11 @@
2268222826
shell_check_oom(zLine);
2268322827
memcpy(zLine, zBegin, (size_t)nZ);
2268422828
zLine[nZ] = 0;
2268522829
return zLine;
2268622830
}
22687
-#endif /* SQLITE_SHELL_WASM_MODE */
22831
+#endif /* SQLITE_SHELL_FIDDLE */
2268822832
2268922833
/*
2269022834
** Read input from *in and process it. If *in==0 then input
2269122835
** is interactive - the user is typing it it. Otherwise, input
2269222836
** is coming from a file or device. A prompt is issued and history
@@ -23065,11 +23209,11 @@
2306523209
# else
2306623210
# define SQLITE_SHELL_IS_UTF8 (1)
2306723211
# endif
2306823212
#endif
2306923213
23070
-#ifdef SQLITE_SHELL_WASM_MODE
23214
+#ifdef SQLITE_SHELL_FIDDLE
2307123215
# define main fiddle_main
2307223216
#endif
2307323217
2307423218
#if SQLITE_SHELL_IS_UTF8
2307523219
int SQLITE_CDECL main(int argc, char **argv){
@@ -23079,11 +23223,11 @@
2307923223
#endif
2308023224
#ifdef SQLITE_DEBUG
2308123225
sqlite3_int64 mem_main_enter = sqlite3_memory_used();
2308223226
#endif
2308323227
char *zErrMsg = 0;
23084
-#ifdef SQLITE_SHELL_WASM_MODE
23228
+#ifdef SQLITE_SHELL_FIDDLE
2308523229
# define data shellState
2308623230
#else
2308723231
ShellState data;
2308823232
#endif
2308923233
const char *zInitFile = 0;
@@ -23099,11 +23243,11 @@
2309923243
int argcToFree = 0;
2310023244
#endif
2310123245
2310223246
setBinaryMode(stdin, 0);
2310323247
setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
23104
-#ifdef SQLITE_SHELL_WASM_MODE
23248
+#ifdef SQLITE_SHELL_FIDDLE
2310523249
stdin_is_interactive = 0;
2310623250
stdout_is_console = 1;
2310723251
#else
2310823252
stdin_is_interactive = isatty(0);
2310923253
stdout_is_console = isatty(1);
@@ -23361,11 +23505,11 @@
2336123505
utf8_printf(stderr,"%s: Error: no database filename specified\n", Argv0);
2336223506
return 1;
2336323507
#endif
2336423508
}
2336523509
data.out = stdout;
23366
-#ifndef SQLITE_SHELL_WASM_MODE
23510
+#ifndef SQLITE_SHELL_FIDDLE
2336723511
sqlite3_appendvfs_init(0,0,0);
2336823512
#endif
2336923513
2337023514
/* Go ahead and open the database file if it already exists. If the
2337123515
** file does not exist, delay opening it. This prevents empty database
@@ -23629,11 +23773,11 @@
2362923773
}else{
2363023774
data.in = stdin;
2363123775
rc = process_input(&data);
2363223776
}
2363323777
}
23634
-#ifndef SQLITE_SHELL_WASM_MODE
23778
+#ifndef SQLITE_SHELL_FIDDLE
2363523779
/* In WASM mode we have to leave the db state in place so that
2363623780
** client code can "push" SQL into it after this call returns. */
2363723781
free(azCmd);
2363823782
set_table_name(&data, 0);
2363923783
if( data.db ){
@@ -23664,16 +23808,16 @@
2366423808
if( sqlite3_memory_used()>mem_main_enter ){
2366523809
utf8_printf(stderr, "Memory leaked: %u bytes\n",
2366623810
(unsigned int)(sqlite3_memory_used()-mem_main_enter));
2366723811
}
2366823812
#endif
23669
-#endif /* !SQLITE_SHELL_WASM_MODE */
23813
+#endif /* !SQLITE_SHELL_FIDDLE */
2367023814
return rc;
2367123815
}
2367223816
2367323817
23674
-#ifdef SQLITE_SHELL_WASM_MODE
23818
+#ifdef SQLITE_SHELL_FIDDLE
2367523819
/* Only for emcc experimentation purposes. */
2367623820
int fiddle_experiment(int a,int b){
2367723821
return a + b;
2367823822
}
2367923823
@@ -23790,6 +23934,6 @@
2379023934
shellState.wasm.zPos = zSql;
2379123935
process_input(&shellState);
2379223936
memset(&shellState.wasm, 0, sizeof(shellState.wasm));
2379323937
}
2379423938
}
23795
-#endif /* SQLITE_SHELL_WASM_MODE */
23939
+#endif /* SQLITE_SHELL_FIDDLE */
2379623940
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -53,10 +53,19 @@
53 */
54 #if !defined(SQLITE_OS_WINRT)
55 # define SQLITE_OS_WINRT 0
56 #endif
57
 
 
 
 
 
 
 
 
 
58 /*
59 ** Warning pragmas copied from msvc.h in the core.
60 */
61 #if defined(_MSC_VER)
62 #pragma warning(disable : 4054)
@@ -245,21 +254,10 @@
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 */
265 static sqlite3_int64 timeOfDay(void){
@@ -717,11 +715,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);
@@ -737,11 +735,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 */
@@ -3794,10 +3792,11 @@
3794 #define re_compile sqlite3re_compile
3795 #define re_free sqlite3re_free
3796
3797 /* The end-of-input character */
3798 #define RE_EOF 0 /* End of input */
 
3799
3800 /* The NFA is implemented as sequence of opcodes taken from the following
3801 ** set. Each opcode has a single integer argument.
3802 */
3803 #define RE_OP_MATCH 1 /* Match the one character in the argument */
@@ -3815,10 +3814,37 @@
3815 #define RE_OP_DIGIT 13 /* digit: [0-9] */
3816 #define RE_OP_NOTDIGIT 14 /* Not a digit */
3817 #define RE_OP_SPACE 15 /* space: [ \t\n\r\v\f] */
3818 #define RE_OP_NOTSPACE 16 /* Not a digit */
3819 #define RE_OP_BOUNDARY 17 /* Boundary between word and non-word */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3820
3821 /* Each opcode is a "state" in the NFA */
3822 typedef unsigned short ReStateNumber;
3823
3824 /* Because this is an NFA and not a DFA, multiple states can be active at
@@ -3849,11 +3875,11 @@
3849 const char *zErr; /* Error message to return */
3850 char *aOp; /* Operators for the virtual machine */
3851 int *aArg; /* Arguments to each operator */
3852 unsigned (*xNextChar)(ReInput*); /* Next character function */
3853 unsigned char zInit[12]; /* Initial text to match */
3854 int nInit; /* Number of characters in zInit */
3855 unsigned nState; /* Number of entries in aOp[] and aArg[] */
3856 unsigned nAlloc; /* Slots allocated for aOp[] and aArg[] */
3857 };
3858
3859 /* Add a state to the given state set if it is not already there */
@@ -3922,11 +3948,11 @@
3922 ReStateSet aStateSet[2], *pThis, *pNext;
3923 ReStateNumber aSpace[100];
3924 ReStateNumber *pToFree;
3925 unsigned int i = 0;
3926 unsigned int iSwap = 0;
3927 int c = RE_EOF+1;
3928 int cPrev = 0;
3929 int rc = 0;
3930 ReInput in;
3931
3932 in.z = zIn;
@@ -3941,10 +3967,11 @@
3941 strncmp((const char*)zIn+in.i, (const char*)pRe->zInit, pRe->nInit)!=0)
3942 ){
3943 in.i++;
3944 }
3945 if( in.i+pRe->nInit>in.mx ) return 0;
 
3946 }
3947
3948 if( pRe->nState<=(sizeof(aSpace)/(sizeof(aSpace[0])*2)) ){
3949 pToFree = 0;
3950 aStateSet[0].aState = aSpace;
@@ -3968,10 +3995,14 @@
3968 int x = pThis->aState[i];
3969 switch( pRe->aOp[x] ){
3970 case RE_OP_MATCH: {
3971 if( pRe->aArg[x]==c ) re_add_state(pNext, x+1);
3972 break;
 
 
 
 
3973 }
3974 case RE_OP_ANY: {
3975 if( c!=0 ) re_add_state(pNext, x+1);
3976 break;
3977 }
@@ -4050,11 +4081,13 @@
4050 }
4051 }
4052 }
4053 }
4054 for(i=0; i<pNext->nState; i++){
4055 if( pRe->aOp[pNext->aState[i]]==RE_OP_ACCEPT ){ rc = 1; break; }
 
 
4056 }
4057 re_match_end:
4058 sqlite3_free(pToFree);
4059 return rc;
4060 }
@@ -4205,11 +4238,10 @@
4205 const char *zErr;
4206 while( (c = p->xNextChar(&p->sIn))!=0 ){
4207 iStart = p->nState;
4208 switch( c ){
4209 case '|':
4210 case '$':
4211 case ')': {
4212 p->sIn.i--;
4213 return 0;
4214 }
4215 case '(': {
@@ -4241,10 +4273,18 @@
4241 }
4242 case '?': {
4243 if( iPrev<0 ) return "'?' without operand";
4244 re_insert(p, iPrev, RE_OP_FORK, p->nState - iPrev+1);
4245 break;
 
 
 
 
 
 
 
 
4246 }
4247 case '{': {
4248 int m = 0, n = 0;
4249 int sz, j;
4250 if( iPrev<0 ) return "'{m,n}' without operand";
@@ -4260,10 +4300,11 @@
4260 p->sIn.i++;
4261 sz = p->nState - iPrev;
4262 if( m==0 ){
4263 if( n==0 ) return "both m and n are zero in '{m,n}'";
4264 re_insert(p, iPrev, RE_OP_FORK, sz+1);
 
4265 n--;
4266 }else{
4267 for(j=1; j<m; j++) re_copy(p, iPrev, sz);
4268 }
4269 for(j=m; j<n; j++){
@@ -4378,15 +4419,11 @@
4378 zErr = re_subcompile_re(pRe);
4379 if( zErr ){
4380 re_free(pRe);
4381 return zErr;
4382 }
4383 if( rePeek(pRe)=='$' && pRe->sIn.i+1>=pRe->sIn.mx ){
4384 re_append(pRe, RE_OP_MATCH, RE_EOF);
4385 re_append(pRe, RE_OP_ACCEPT, 0);
4386 *ppRe = pRe;
4387 }else if( pRe->sIn.i>=pRe->sIn.mx ){
4388 re_append(pRe, RE_OP_ACCEPT, 0);
4389 *ppRe = pRe;
4390 }else{
4391 re_free(pRe);
4392 return "unrecognized character";
@@ -4465,10 +4502,71 @@
4465 }
4466 if( setAux ){
4467 sqlite3_set_auxdata(context, 0, pRe, (void(*)(void*))re_free);
4468 }
4469 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4470
4471 /*
4472 ** Invoke this routine to register the regexp() function with the
4473 ** SQLite database connection.
4474 */
@@ -4490,16 +4588,23 @@
4490 /* The regexpi(PATTERN,STRING) function is a case-insensitive version
4491 ** of regexp(PATTERN,STRING). */
4492 rc = sqlite3_create_function(db, "regexpi", 2,
4493 SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
4494 (void*)db, re_sql_func, 0, 0);
 
 
 
 
 
 
 
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
@@ -10047,10 +10152,14 @@
10047 ** Return true if zId must be quoted in order to use it as an SQL
10048 ** identifier, or false otherwise.
10049 */
10050 static int idxIdentifierRequiresQuotes(const char *zId){
10051 int i;
 
 
 
 
10052 for(i=0; zId[i]; i++){
10053 if( !(zId[i]=='_')
10054 && !(zId[i]>='0' && zId[i]<='9')
10055 && !(zId[i]>='a' && zId[i]<='z')
10056 && !(zId[i]>='A' && zId[i]<='Z')
@@ -12248,19 +12357,19 @@
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
@@ -12588,14 +12697,27 @@
12588 /*
12589 ** Output the given string as a hex-encoded blob (eg. X'1234' )
12590 */
12591 static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){
12592 int i;
12593 char *zBlob = (char *)pBlob;
12594 raw_printf(out,"X'");
12595 for(i=0; i<nBlob; i++){ raw_printf(out,"%02x",zBlob[i]&0xff); }
12596 raw_printf(out,"'");
 
 
 
 
 
 
 
 
 
 
 
 
 
12597 }
12598
12599 /*
12600 ** Find a string that is not found anywhere in z[]. Return a pointer
12601 ** to that string.
@@ -12924,11 +13046,11 @@
12924 UNUSED_PARAMETER(zA2);
12925 UNUSED_PARAMETER(zA3);
12926 UNUSED_PARAMETER(zA4);
12927 switch( op ){
12928 case SQLITE_ATTACH: {
12929 #ifndef SQLITE_SHELL_WASM_MODE
12930 /* In WASM builds the filesystem is a virtual sandbox, so
12931 ** there's no harm in using ATTACH. */
12932 failIfSafeMode(p, "cannot run ATTACH in safe mode");
12933 #endif
12934 break;
@@ -12997,19 +13119,41 @@
12997 /*
12998 ** Print a schema statement. Part of MODE_Semi and MODE_Pretty output.
12999 **
13000 ** This routine converts some CREATE TABLE statements for shadow tables
13001 ** in FTS3/4/5 into CREATE TABLE IF NOT EXISTS statements.
 
 
 
 
13002 */
13003 static void printSchemaLine(FILE *out, const char *z, const char *zTail){
 
13004 if( z==0 ) return;
13005 if( zTail==0 ) return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13006 if( sqlite3_strglob("CREATE TABLE ['\"]*", z)==0 ){
13007 utf8_printf(out, "CREATE TABLE IF NOT EXISTS %s%s", z+13, zTail);
13008 }else{
13009 utf8_printf(out, "%s%s", z, zTail);
13010 }
 
13011 }
13012 static void printSchemaLineN(FILE *out, char *z, int n, const char *zTail){
13013 char c = z[n];
13014 z[n] = 0;
13015 printSchemaLine(out, z, zTail);
@@ -15338,11 +15482,11 @@
15338 ** There must be two or more spaces between the end of the command and the
15339 ** start of the description of what that command does.
15340 */
15341 static const char *(azHelp[]) = {
15342 #if defined(SQLITE_HAVE_ZLIB) && !defined(SQLITE_OMIT_VIRTUALTABLE) \
15343 && !defined(SQLITE_SHELL_WASM_MODE)
15344 ".archive ... Manage SQL archives",
15345 " Each command must have exactly one of the following options:",
15346 " -c, --create Create a new archive",
15347 " -u, --update Add or update files with changed mtime",
15348 " -i, --insert Like -u but always add even if unchanged",
@@ -15364,23 +15508,23 @@
15364 " http://sqlite.org/cli.html#sqlite_archive_support",
15365 #endif
15366 #ifndef SQLITE_OMIT_AUTHORIZATION
15367 ".auth ON|OFF Show authorizer callbacks",
15368 #endif
15369 #ifndef SQLITE_SHELL_WASM_MODE
15370 ".backup ?DB? FILE Backup DB (default \"main\") to FILE",
15371 " Options:",
15372 " --append Use the appendvfs",
15373 " --async Write to FILE without journal and fsync()",
15374 #endif
15375 ".bail on|off Stop after hitting an error. Default OFF",
15376 ".binary on|off Turn binary output on or off. Default OFF",
15377 #ifndef SQLITE_SHELL_WASM_MODE
15378 ".cd DIRECTORY Change the working directory to DIRECTORY",
15379 #endif
15380 ".changes on|off Show number of rows changed by SQL",
15381 #ifndef SQLITE_SHELL_WASM_MODE
15382 ".check GLOB Fail if output since .testcase does not match",
15383 ".clone NEWDB Clone data into NEWDB from the existing database",
15384 #endif
15385 ".connection [close] [#] Open or close an auxiliary database connection",
15386 ".databases List names and files of attached databases",
@@ -15402,15 +15546,15 @@
15402 #ifdef SQLITE_DEBUG
15403 " test Show raw EXPLAIN QUERY PLAN output",
15404 " trace Like \"full\" but enable \"PRAGMA vdbe_trace\"",
15405 #endif
15406 " trigger Like \"full\" but also show trigger bytecode",
15407 #ifndef SQLITE_SHELL_WASM_MODE
15408 ".excel Display the output of next command in spreadsheet",
15409 " --bom Put a UTF8 byte-order mark on intermediate file",
15410 #endif
15411 #ifndef SQLITE_SHELL_WASM_MODE
15412 ".exit ?CODE? Exit this program with return-code CODE",
15413 #endif
15414 ".expert EXPERIMENTAL. Suggest indexes for queries",
15415 ".explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto",
15416 ".filectrl CMD ... Run various sqlite3_file_control() operations",
@@ -15417,11 +15561,11 @@
15417 " --schema SCHEMA Use SCHEMA instead of \"main\"",
15418 " --help Show CMD details",
15419 ".fullschema ?--indent? Show schema and the content of sqlite_stat tables",
15420 ".headers on|off Turn display of headers on or off",
15421 ".help ?-all? ?PATTERN? Show help text for PATTERN",
15422 #ifndef SQLITE_SHELL_WASM_MODE
15423 ".import FILE TABLE Import data from FILE into TABLE",
15424 " Options:",
15425 " --ascii Use \\037 and \\036 as column and row separators",
15426 " --csv Use , and \\n as column and row separators",
15427 " --skip N Skip the first N rows of input",
@@ -15446,14 +15590,14 @@
15446 #endif
15447 ".limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT",
15448 ".lint OPTIONS Report potential schema issues.",
15449 " Options:",
15450 " fkey-indexes Find missing foreign key indexes",
15451 #if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_WASM_MODE)
15452 ".load FILE ?ENTRY? Load an extension library",
15453 #endif
15454 #ifndef SQLITE_SHELL_WASM_MODE
15455 ".log FILE|off Turn logging on or off. FILE can be stderr/stdout",
15456 #endif
15457 ".mode MODE ?OPTIONS? Set output mode",
15458 " MODE is one of:",
15459 " ascii Columns/rows delimited by 0x1F and 0x1E",
@@ -15476,15 +15620,15 @@
15476 " --wordwrap B Wrap or not at word boundaries per B (on/off)",
15477 " --ww Shorthand for \"--wordwrap 1\"",
15478 " --quote Quote output text as SQL literals",
15479 " --noquote Do not quote output text",
15480 " TABLE The name of SQL table used for \"insert\" mode",
15481 #ifndef SQLITE_SHELL_WASM_MODE
15482 ".nonce STRING Suspend safe mode for one command if nonce matches",
15483 #endif
15484 ".nullvalue STRING Use STRING in place of NULL values",
15485 #ifndef SQLITE_SHELL_WASM_MODE
15486 ".once ?OPTIONS? ?FILE? Output for the next SQL command only to FILE",
15487 " If FILE begins with '|' then open as a pipe",
15488 " --bom Put a UTF8 byte-order mark at the beginning",
15489 " -e Send output to the system text editor",
15490 " -x Send output as CSV to a spreadsheet (same as \".excel\")",
@@ -15502,11 +15646,11 @@
15502 #endif
15503 " --new Initialize FILE to an empty database",
15504 " --nofollow Do not follow symbolic links",
15505 " --readonly Open FILE readonly",
15506 " --zip FILE is a ZIP archive",
15507 #ifndef SQLITE_SHELL_WASM_MODE
15508 ".output ?FILE? Send output to FILE or stdout if FILE is omitted",
15509 " If FILE begins with '|' then open it as a pipe.",
15510 " Options:",
15511 " --bom Prefix output with a UTF8 byte-order mark",
15512 " -e Send output to the system text editor",
@@ -15526,11 +15670,11 @@
15526 " --once Do no more than one progress interrupt",
15527 " --quiet|-q No output except at interrupts",
15528 " --reset Reset the count for each input and interrupt",
15529 #endif
15530 ".prompt MAIN CONTINUE Replace the standard prompts",
15531 #ifndef SQLITE_SHELL_WASM_MODE
15532 ".quit Exit this program",
15533 ".read FILE Read input from FILE or command output",
15534 " If FILE begins with \"|\", it is a command that generates the input.",
15535 #endif
15536 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
@@ -15539,11 +15683,11 @@
15539 " --recovery-db NAME Store recovery metadata in database file NAME",
15540 " --lost-and-found TABLE Alternative name for the lost-and-found table",
15541 " --no-rowids Do not attempt to recover rowid values",
15542 " that are not also INTEGER PRIMARY KEYs",
15543 #endif
15544 #ifndef SQLITE_SHELL_WASM_MODE
15545 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE",
15546 ".save ?OPTIONS? FILE Write database to FILE (an alias for .backup ...)",
15547 #endif
15548 ".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off",
15549 ".schema ?PATTERN? Show the CREATE statements matching PATTERN",
@@ -15576,24 +15720,24 @@
15576 " --sha3-224 Use the sha3-224 algorithm",
15577 " --sha3-256 Use the sha3-256 algorithm (default)",
15578 " --sha3-384 Use the sha3-384 algorithm",
15579 " --sha3-512 Use the sha3-512 algorithm",
15580 " Any other argument is a LIKE pattern for tables to hash",
15581 #if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE)
15582 ".shell CMD ARGS... Run CMD ARGS... in a system shell",
15583 #endif
15584 ".show Show the current values for various settings",
15585 ".stats ?ARG? Show stats or turn stats on or off",
15586 " off Turn off automatic stat display",
15587 " on Turn on automatic stat display",
15588 " stmt Show statement stats",
15589 " vmstep Show the virtual machine step count only",
15590 #if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE)
15591 ".system CMD ARGS... Run CMD ARGS... in a system shell",
15592 #endif
15593 ".tables ?TABLE? List names of tables matching LIKE pattern TABLE",
15594 #ifndef SQLITE_SHELL_WASM_MODE
15595 ".testcase NAME Begin redirecting output to 'testcase-out.txt'",
15596 #endif
15597 ".testctrl CMD ... Run various sqlite3_test_control() operations",
15598 " Run \".testctrl\" with no arguments for details",
15599 ".timeout MS Try opening locked tables for MS milliseconds",
@@ -16142,11 +16286,11 @@
16142 sqlite3_uint_init(p->db, 0, 0);
16143 sqlite3_decimal_init(p->db, 0, 0);
16144 sqlite3_regexp_init(p->db, 0, 0);
16145 sqlite3_ieee_init(p->db, 0, 0);
16146 sqlite3_series_init(p->db, 0, 0);
16147 #ifndef SQLITE_SHELL_WASM_MODE
16148 sqlite3_fileio_init(p->db, 0, 0);
16149 sqlite3_completion_init(p->db, 0, 0);
16150 #endif
16151 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
16152 sqlite3_dbdata_init(p->db, 0, 0);
@@ -19272,19 +19416,19 @@
19272 }
19273 }else
19274 #endif
19275
19276 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB) \
19277 && !defined(SQLITE_SHELL_WASM_MODE)
19278 if( c=='a' && strncmp(azArg[0], "archive", n)==0 ){
19279 open_db(p, 0);
19280 failIfSafeMode(p, "cannot run .archive in safe mode");
19281 rc = arDotCommand(p, 0, azArg, nArg);
19282 }else
19283 #endif
19284
19285 #ifndef SQLITE_SHELL_WASM_MODE
19286 if( (c=='b' && n>=3 && strncmp(azArg[0], "backup", n)==0)
19287 || (c=='s' && n>=3 && strncmp(azArg[0], "save", n)==0)
19288 ){
19289 const char *zDestFile = 0;
19290 const char *zDb = 0;
@@ -19349,11 +19493,11 @@
19349 utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
19350 rc = 1;
19351 }
19352 close_db(pDest);
19353 }else
19354 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
19355
19356 if( c=='b' && n>=3 && strncmp(azArg[0], "bail", n)==0 ){
19357 if( nArg==2 ){
19358 bail_on_error = booleanValue(azArg[1]);
19359 }else{
@@ -19380,11 +19524,11 @@
19380 */
19381 if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
19382 test_breakpoint();
19383 }else
19384
19385 #ifndef SQLITE_SHELL_WASM_MODE
19386 if( c=='c' && strcmp(azArg[0],"cd")==0 ){
19387 failIfSafeMode(p, "cannot run .cd in safe mode");
19388 if( nArg==2 ){
19389 #if defined(_WIN32) || defined(WIN32)
19390 wchar_t *z = sqlite3_win32_utf8_to_unicode(azArg[1]);
@@ -19400,11 +19544,11 @@
19400 }else{
19401 raw_printf(stderr, "Usage: .cd DIRECTORY\n");
19402 rc = 1;
19403 }
19404 }else
19405 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
19406
19407 if( c=='c' && n>=3 && strncmp(azArg[0], "changes", n)==0 ){
19408 if( nArg==2 ){
19409 setOrClearFlag(p, SHFLG_CountChanges, azArg[1]);
19410 }else{
@@ -19411,11 +19555,11 @@
19411 raw_printf(stderr, "Usage: .changes on|off\n");
19412 rc = 1;
19413 }
19414 }else
19415
19416 #ifndef SQLITE_SHELL_WASM_MODE
19417 /* Cancel output redirection, if it is currently set (by .testcase)
19418 ** Then read the content of the testcase-out.txt file and compare against
19419 ** azArg[1]. If there are differences, report an error and exit.
19420 */
19421 if( c=='c' && n>=3 && strncmp(azArg[0], "check", n)==0 ){
@@ -19436,23 +19580,23 @@
19436 utf8_printf(stdout, "testcase-%s ok\n", p->zTestcase);
19437 p->nCheck++;
19438 }
19439 sqlite3_free(zRes);
19440 }else
19441 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
19442
19443 #ifndef SQLITE_SHELL_WASM_MODE
19444 if( c=='c' && strncmp(azArg[0], "clone", n)==0 ){
19445 failIfSafeMode(p, "cannot run .clone in safe mode");
19446 if( nArg==2 ){
19447 tryToClone(p, azArg[1]);
19448 }else{
19449 raw_printf(stderr, "Usage: .clone FILENAME\n");
19450 rc = 1;
19451 }
19452 }else
19453 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
19454
19455 if( c=='c' && strncmp(azArg[0], "connection", n)==0 ){
19456 if( nArg==1 ){
19457 /* List available connections */
19458 int i;
@@ -19737,11 +19881,11 @@
19737 raw_printf(stderr, "Usage: .eqp off|on|trace|trigger|full\n");
19738 rc = 1;
19739 }
19740 }else
19741
19742 #ifndef SQLITE_SHELL_WASM_MODE
19743 if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
19744 if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
19745 rc = 2;
19746 }else
19747 #endif
@@ -19997,11 +20141,11 @@
19997 }else{
19998 showHelp(p->out, 0);
19999 }
20000 }else
20001
20002 #ifndef SQLITE_SHELL_WASM_MODE
20003 if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
20004 char *zTable = 0; /* Insert data into this table */
20005 char *zSchema = 0; /* within this schema (may default to "main") */
20006 char *zFile = 0; /* Name of file to extra content from */
20007 sqlite3_stmt *pStmt = NULL; /* A statement */
@@ -20288,11 +20432,11 @@
20288 utf8_printf(p->out,
20289 "Added %d rows with %d errors using %d lines of input\n",
20290 sCtx.nRow, sCtx.nErr, sCtx.nLine-1);
20291 }
20292 }else
20293 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
20294
20295 #ifndef SQLITE_UNTESTABLE
20296 if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
20297 char *zSql;
20298 char *zCollist = 0;
@@ -20478,11 +20622,11 @@
20478 if( c=='l' && n>2 && strncmp(azArg[0], "lint", n)==0 ){
20479 open_db(p, 0);
20480 lintDotCommand(p, azArg, nArg);
20481 }else
20482
20483 #if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_WASM_MODE)
20484 if( c=='l' && strncmp(azArg[0], "load", n)==0 ){
20485 const char *zFile, *zProc;
20486 char *zErrMsg = 0;
20487 failIfSafeMode(p, "cannot run .load in safe mode");
20488 if( nArg<2 ){
@@ -20500,11 +20644,11 @@
20500 rc = 1;
20501 }
20502 }else
20503 #endif
20504
20505 #ifndef SQLITE_SHELL_WASM_MODE
20506 if( c=='l' && strncmp(azArg[0], "log", n)==0 ){
20507 failIfSafeMode(p, "cannot run .log in safe mode");
20508 if( nArg!=2 ){
20509 raw_printf(stderr, "Usage: .log FILENAME\n");
20510 rc = 1;
@@ -20637,11 +20781,11 @@
20637 rc = 1;
20638 }
20639 p->cMode = p->mode;
20640 }else
20641
20642 #ifndef SQLITE_SHELL_WASM_MODE
20643 if( c=='n' && strcmp(azArg[0], "nonce")==0 ){
20644 if( nArg!=2 ){
20645 raw_printf(stderr, "Usage: .nonce NONCE\n");
20646 rc = 1;
20647 }else if( p->zNonce==0 || strcmp(azArg[1],p->zNonce)!=0 ){
@@ -20652,11 +20796,11 @@
20652 p->bSafeMode = 0;
20653 return 0; /* Return immediately to bypass the safe mode reset
20654 ** at the end of this procedure */
20655 }
20656 }else
20657 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
20658
20659 if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 ){
20660 if( nArg==2 ){
20661 sqlite3_snprintf(sizeof(p->nullValue), p->nullValue,
20662 "%.*s", (int)ArraySize(p->nullValue)-1, azArg[1]);
@@ -20674,11 +20818,11 @@
20674 int openMode = SHELL_OPEN_UNSPEC;
20675
20676 /* Check for command-line arguments */
20677 for(iName=1; iName<nArg; iName++){
20678 const char *z = azArg[iName];
20679 #ifndef SQLITE_SHELL_WASM_MODE
20680 if( optionMatch(z,"new") ){
20681 newFlag = 1;
20682 #ifdef SQLITE_HAVE_ZLIB
20683 }else if( optionMatch(z, "zip") ){
20684 openMode = SHELL_OPEN_ZIPFILE;
@@ -20696,11 +20840,11 @@
20696 openMode = SHELL_OPEN_HEXDB;
20697 }else if( optionMatch(z, "maxsize") && iName+1<nArg ){
20698 p->szMax = integerValue(azArg[++iName]);
20699 #endif /* SQLITE_OMIT_DESERIALIZE */
20700 }else
20701 #endif /* !SQLITE_SHELL_WASM_MODE */
20702 if( z[0]=='-' ){
20703 utf8_printf(stderr, "unknown option: %s\n", z);
20704 rc = 1;
20705 goto meta_command_exit;
20706 }else if( zFN ){
@@ -20724,11 +20868,11 @@
20724 p->szMax = 0;
20725
20726 /* If a filename is specified, try to open it first */
20727 if( zFN || p->openMode==SHELL_OPEN_HEXDB ){
20728 if( newFlag && zFN && !p->bSafeMode ) shellDeleteFile(zFN);
20729 #ifndef SQLITE_SHELL_WASM_MODE
20730 if( p->bSafeMode
20731 && p->openMode!=SHELL_OPEN_HEXDB
20732 && zFN
20733 && strcmp(zFN,":memory:")!=0
20734 ){
@@ -20757,11 +20901,11 @@
20757 p->pAuxDb->zDbFilename = 0;
20758 open_db(p, 0);
20759 }
20760 }else
20761
20762 #ifndef SQLITE_SHELL_WASM_MODE
20763 if( (c=='o'
20764 && (strncmp(azArg[0], "output", n)==0||strncmp(azArg[0], "once", n)==0))
20765 || (c=='e' && n==5 && strcmp(azArg[0],"excel")==0)
20766 ){
20767 char *zFile = 0;
@@ -20873,11 +21017,11 @@
20873 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
20874 }
20875 }
20876 sqlite3_free(zFile);
20877 }else
20878 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
20879
20880 if( c=='p' && n>=3 && strncmp(azArg[0], "parameter", n)==0 ){
20881 open_db(p,0);
20882 if( nArg<=1 ) goto parameter_syntax_error;
20883
@@ -21043,17 +21187,17 @@
21043 if( nArg >= 3) {
21044 strncpy(continuePrompt,azArg[2],(int)ArraySize(continuePrompt)-1);
21045 }
21046 }else
21047
21048 #ifndef SQLITE_SHELL_WASM_MODE
21049 if( c=='q' && strncmp(azArg[0], "quit", n)==0 ){
21050 rc = 2;
21051 }else
21052 #endif
21053
21054 #ifndef SQLITE_SHELL_WASM_MODE
21055 if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 ){
21056 FILE *inSaved = p->in;
21057 int savedLineno = p->lineno;
21058 failIfSafeMode(p, "cannot run .read in safe mode");
21059 if( nArg!=2 ){
@@ -21084,13 +21228,13 @@
21084 fclose(p->in);
21085 }
21086 p->in = inSaved;
21087 p->lineno = savedLineno;
21088 }else
21089 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
21090
21091 #ifndef SQLITE_SHELL_WASM_MODE
21092 if( c=='r' && n>=3 && strncmp(azArg[0], "restore", n)==0 ){
21093 const char *zSrcFile;
21094 const char *zDb;
21095 sqlite3 *pSrc;
21096 sqlite3_backup *pBackup;
@@ -21138,11 +21282,11 @@
21138 utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
21139 rc = 1;
21140 }
21141 close_db(pSrc);
21142 }else
21143 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
21144
21145 if( c=='s' && strncmp(azArg[0], "scanstats", n)==0 ){
21146 if( nArg==2 ){
21147 p->scanstatsOn = (u8)booleanValue(azArg[1]);
21148 #ifndef SQLITE_ENABLE_STMT_SCANSTATUS
@@ -21764,11 +21908,11 @@
21764 shell_exec(p, zSql, 0);
21765 }
21766 sqlite3_free(zSql);
21767 }else
21768
21769 #if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE)
21770 if( c=='s'
21771 && (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
21772 ){
21773 char *zCmd;
21774 int i, x;
@@ -21785,11 +21929,11 @@
21785 }
21786 x = zCmd!=0 ? system(zCmd) : 1;
21787 sqlite3_free(zCmd);
21788 if( x ) raw_printf(stderr, "System command returns %d\n", x);
21789 }else
21790 #endif /* !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_WASM_MODE) */
21791
21792 if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
21793 static const char *azBool[] = { "off", "on", "trigger", "full"};
21794 const char *zOut;
21795 int i;
@@ -21965,11 +22109,11 @@
21965
21966 for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
21967 sqlite3_free(azResult);
21968 }else
21969
21970 #ifndef SQLITE_SHELL_WASM_MODE
21971 /* Begin redirecting output to the file "testcase-out.txt" */
21972 if( c=='t' && strcmp(azArg[0],"testcase")==0 ){
21973 output_reset(p);
21974 p->out = output_file_open("testcase-out.txt", 0);
21975 if( p->out==0 ){
@@ -21979,11 +22123,11 @@
21979 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
21980 }else{
21981 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?");
21982 }
21983 }else
21984 #endif /* !defined(SQLITE_SHELL_WASM_MODE) */
21985
21986 #ifndef SQLITE_UNTESTABLE
21987 if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 ){
21988 static const struct {
21989 const char *zCtrlName; /* Name of a test-control option */
@@ -22651,11 +22795,11 @@
22651
22652 static void echo_group_input(ShellState *p, const char *zDo){
22653 if( ShellHasFlag(p, SHFLG_Echo) ) utf8_printf(p->out, "%s\n", zDo);
22654 }
22655
22656 #ifdef SQLITE_SHELL_WASM_MODE
22657 /*
22658 ** Alternate one_input_line() impl for wasm mode. This is not in the primary impl
22659 ** because we need the global shellState and cannot access it from that function
22660 ** without moving lots of code around (creating a larger/messier diff).
22661 */
@@ -22682,11 +22826,11 @@
22682 shell_check_oom(zLine);
22683 memcpy(zLine, zBegin, (size_t)nZ);
22684 zLine[nZ] = 0;
22685 return zLine;
22686 }
22687 #endif /* SQLITE_SHELL_WASM_MODE */
22688
22689 /*
22690 ** Read input from *in and process it. If *in==0 then input
22691 ** is interactive - the user is typing it it. Otherwise, input
22692 ** is coming from a file or device. A prompt is issued and history
@@ -23065,11 +23209,11 @@
23065 # else
23066 # define SQLITE_SHELL_IS_UTF8 (1)
23067 # endif
23068 #endif
23069
23070 #ifdef SQLITE_SHELL_WASM_MODE
23071 # define main fiddle_main
23072 #endif
23073
23074 #if SQLITE_SHELL_IS_UTF8
23075 int SQLITE_CDECL main(int argc, char **argv){
@@ -23079,11 +23223,11 @@
23079 #endif
23080 #ifdef SQLITE_DEBUG
23081 sqlite3_int64 mem_main_enter = sqlite3_memory_used();
23082 #endif
23083 char *zErrMsg = 0;
23084 #ifdef SQLITE_SHELL_WASM_MODE
23085 # define data shellState
23086 #else
23087 ShellState data;
23088 #endif
23089 const char *zInitFile = 0;
@@ -23099,11 +23243,11 @@
23099 int argcToFree = 0;
23100 #endif
23101
23102 setBinaryMode(stdin, 0);
23103 setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
23104 #ifdef SQLITE_SHELL_WASM_MODE
23105 stdin_is_interactive = 0;
23106 stdout_is_console = 1;
23107 #else
23108 stdin_is_interactive = isatty(0);
23109 stdout_is_console = isatty(1);
@@ -23361,11 +23505,11 @@
23361 utf8_printf(stderr,"%s: Error: no database filename specified\n", Argv0);
23362 return 1;
23363 #endif
23364 }
23365 data.out = stdout;
23366 #ifndef SQLITE_SHELL_WASM_MODE
23367 sqlite3_appendvfs_init(0,0,0);
23368 #endif
23369
23370 /* Go ahead and open the database file if it already exists. If the
23371 ** file does not exist, delay opening it. This prevents empty database
@@ -23629,11 +23773,11 @@
23629 }else{
23630 data.in = stdin;
23631 rc = process_input(&data);
23632 }
23633 }
23634 #ifndef SQLITE_SHELL_WASM_MODE
23635 /* In WASM mode we have to leave the db state in place so that
23636 ** client code can "push" SQL into it after this call returns. */
23637 free(azCmd);
23638 set_table_name(&data, 0);
23639 if( data.db ){
@@ -23664,16 +23808,16 @@
23664 if( sqlite3_memory_used()>mem_main_enter ){
23665 utf8_printf(stderr, "Memory leaked: %u bytes\n",
23666 (unsigned int)(sqlite3_memory_used()-mem_main_enter));
23667 }
23668 #endif
23669 #endif /* !SQLITE_SHELL_WASM_MODE */
23670 return rc;
23671 }
23672
23673
23674 #ifdef SQLITE_SHELL_WASM_MODE
23675 /* Only for emcc experimentation purposes. */
23676 int fiddle_experiment(int a,int b){
23677 return a + b;
23678 }
23679
@@ -23790,6 +23934,6 @@
23790 shellState.wasm.zPos = zSql;
23791 process_input(&shellState);
23792 memset(&shellState.wasm, 0, sizeof(shellState.wasm));
23793 }
23794 }
23795 #endif /* SQLITE_SHELL_WASM_MODE */
23796
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -53,10 +53,19 @@
53 */
54 #if !defined(SQLITE_OS_WINRT)
55 # define SQLITE_OS_WINRT 0
56 #endif
57
58 /*
59 ** If SQLITE_SHELL_FIDDLE is defined then the shell is modified
60 ** somewhat for use as a WASM module in a web browser. This flag
61 ** should only be used when building the "fiddle" web application, as
62 ** the browser-mode build has much different user input requirements
63 ** and this build mode rewires the user input subsystem to account for
64 ** that.
65 */
66
67 /*
68 ** Warning pragmas copied from msvc.h in the core.
69 */
70 #if defined(_MSC_VER)
71 #pragma warning(disable : 4054)
@@ -245,21 +254,10 @@
254 #else
255 # define setBinaryMode(X,Y)
256 # define setTextMode(X,Y)
257 #endif
258
 
 
 
 
 
 
 
 
 
 
 
259 /* True if the timer is enabled */
260 static int enableTimer = 0;
261
262 /* Return the current wall-clock time */
263 static sqlite3_int64 timeOfDay(void){
@@ -717,11 +715,11 @@
715 **
716 ** The result is stored in space obtained from malloc() and must either
717 ** be freed by the caller or else passed back into this routine via the
718 ** zPrior argument for reuse.
719 */
720 #ifndef SQLITE_SHELL_FIDDLE
721 static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
722 char *zPrompt;
723 char *zResult;
724 if( in!=0 ){
725 zResult = local_getline(zPrior, in);
@@ -737,11 +735,11 @@
735 if( zResult && *zResult ) shell_add_history(zResult);
736 #endif
737 }
738 return zResult;
739 }
740 #endif /* !SQLITE_SHELL_FIDDLE */
741
742 /*
743 ** Return the value of a hexadecimal digit. Return -1 if the input
744 ** is not a hex digit.
745 */
@@ -3794,10 +3792,11 @@
3792 #define re_compile sqlite3re_compile
3793 #define re_free sqlite3re_free
3794
3795 /* The end-of-input character */
3796 #define RE_EOF 0 /* End of input */
3797 #define RE_START 0xfffffff /* Start of input - larger than an UTF-8 */
3798
3799 /* The NFA is implemented as sequence of opcodes taken from the following
3800 ** set. Each opcode has a single integer argument.
3801 */
3802 #define RE_OP_MATCH 1 /* Match the one character in the argument */
@@ -3815,10 +3814,37 @@
3814 #define RE_OP_DIGIT 13 /* digit: [0-9] */
3815 #define RE_OP_NOTDIGIT 14 /* Not a digit */
3816 #define RE_OP_SPACE 15 /* space: [ \t\n\r\v\f] */
3817 #define RE_OP_NOTSPACE 16 /* Not a digit */
3818 #define RE_OP_BOUNDARY 17 /* Boundary between word and non-word */
3819 #define RE_OP_ATSTART 18 /* Currently at the start of the string */
3820
3821 #if defined(SQLITE_DEBUG)
3822 /* Opcode names used for symbolic debugging */
3823 static const char *ReOpName[] = {
3824 "EOF",
3825 "MATCH",
3826 "ANY",
3827 "ANYSTAR",
3828 "FORK",
3829 "GOTO",
3830 "ACCEPT",
3831 "CC_INC",
3832 "CC_EXC",
3833 "CC_VALUE",
3834 "CC_RANGE",
3835 "WORD",
3836 "NOTWORD",
3837 "DIGIT",
3838 "NOTDIGIT",
3839 "SPACE",
3840 "NOTSPACE",
3841 "BOUNDARY",
3842 "ATSTART",
3843 };
3844 #endif /* SQLITE_DEBUG */
3845
3846
3847 /* Each opcode is a "state" in the NFA */
3848 typedef unsigned short ReStateNumber;
3849
3850 /* Because this is an NFA and not a DFA, multiple states can be active at
@@ -3849,11 +3875,11 @@
3875 const char *zErr; /* Error message to return */
3876 char *aOp; /* Operators for the virtual machine */
3877 int *aArg; /* Arguments to each operator */
3878 unsigned (*xNextChar)(ReInput*); /* Next character function */
3879 unsigned char zInit[12]; /* Initial text to match */
3880 int nInit; /* Number of bytes in zInit */
3881 unsigned nState; /* Number of entries in aOp[] and aArg[] */
3882 unsigned nAlloc; /* Slots allocated for aOp[] and aArg[] */
3883 };
3884
3885 /* Add a state to the given state set if it is not already there */
@@ -3922,11 +3948,11 @@
3948 ReStateSet aStateSet[2], *pThis, *pNext;
3949 ReStateNumber aSpace[100];
3950 ReStateNumber *pToFree;
3951 unsigned int i = 0;
3952 unsigned int iSwap = 0;
3953 int c = RE_START;
3954 int cPrev = 0;
3955 int rc = 0;
3956 ReInput in;
3957
3958 in.z = zIn;
@@ -3941,10 +3967,11 @@
3967 strncmp((const char*)zIn+in.i, (const char*)pRe->zInit, pRe->nInit)!=0)
3968 ){
3969 in.i++;
3970 }
3971 if( in.i+pRe->nInit>in.mx ) return 0;
3972 c = RE_START-1;
3973 }
3974
3975 if( pRe->nState<=(sizeof(aSpace)/(sizeof(aSpace[0])*2)) ){
3976 pToFree = 0;
3977 aStateSet[0].aState = aSpace;
@@ -3968,10 +3995,14 @@
3995 int x = pThis->aState[i];
3996 switch( pRe->aOp[x] ){
3997 case RE_OP_MATCH: {
3998 if( pRe->aArg[x]==c ) re_add_state(pNext, x+1);
3999 break;
4000 }
4001 case RE_OP_ATSTART: {
4002 if( cPrev==RE_START ) re_add_state(pThis, x+1);
4003 break;
4004 }
4005 case RE_OP_ANY: {
4006 if( c!=0 ) re_add_state(pNext, x+1);
4007 break;
4008 }
@@ -4050,11 +4081,13 @@
4081 }
4082 }
4083 }
4084 }
4085 for(i=0; i<pNext->nState; i++){
4086 int x = pNext->aState[i];
4087 while( pRe->aOp[x]==RE_OP_GOTO ) x += pRe->aArg[x];
4088 if( pRe->aOp[x]==RE_OP_ACCEPT ){ rc = 1; break; }
4089 }
4090 re_match_end:
4091 sqlite3_free(pToFree);
4092 return rc;
4093 }
@@ -4205,11 +4238,10 @@
4238 const char *zErr;
4239 while( (c = p->xNextChar(&p->sIn))!=0 ){
4240 iStart = p->nState;
4241 switch( c ){
4242 case '|':
 
4243 case ')': {
4244 p->sIn.i--;
4245 return 0;
4246 }
4247 case '(': {
@@ -4241,10 +4273,18 @@
4273 }
4274 case '?': {
4275 if( iPrev<0 ) return "'?' without operand";
4276 re_insert(p, iPrev, RE_OP_FORK, p->nState - iPrev+1);
4277 break;
4278 }
4279 case '$': {
4280 re_append(p, RE_OP_MATCH, RE_EOF);
4281 break;
4282 }
4283 case '^': {
4284 re_append(p, RE_OP_ATSTART, 0);
4285 break;
4286 }
4287 case '{': {
4288 int m = 0, n = 0;
4289 int sz, j;
4290 if( iPrev<0 ) return "'{m,n}' without operand";
@@ -4260,10 +4300,11 @@
4300 p->sIn.i++;
4301 sz = p->nState - iPrev;
4302 if( m==0 ){
4303 if( n==0 ) return "both m and n are zero in '{m,n}'";
4304 re_insert(p, iPrev, RE_OP_FORK, sz+1);
4305 iPrev++;
4306 n--;
4307 }else{
4308 for(j=1; j<m; j++) re_copy(p, iPrev, sz);
4309 }
4310 for(j=m; j<n; j++){
@@ -4378,15 +4419,11 @@
4419 zErr = re_subcompile_re(pRe);
4420 if( zErr ){
4421 re_free(pRe);
4422 return zErr;
4423 }
4424 if( pRe->sIn.i>=pRe->sIn.mx ){
 
 
 
 
4425 re_append(pRe, RE_OP_ACCEPT, 0);
4426 *ppRe = pRe;
4427 }else{
4428 re_free(pRe);
4429 return "unrecognized character";
@@ -4465,10 +4502,71 @@
4502 }
4503 if( setAux ){
4504 sqlite3_set_auxdata(context, 0, pRe, (void(*)(void*))re_free);
4505 }
4506 }
4507
4508 #if defined(SQLITE_DEBUG)
4509 /*
4510 ** This function is used for testing and debugging only. It is only available
4511 ** if the SQLITE_DEBUG compile-time option is used.
4512 **
4513 ** Compile a regular expression and then convert the compiled expression into
4514 ** text and return that text.
4515 */
4516 static void re_bytecode_func(
4517 sqlite3_context *context,
4518 int argc,
4519 sqlite3_value **argv
4520 ){
4521 const char *zPattern;
4522 const char *zErr;
4523 ReCompiled *pRe;
4524 sqlite3_str *pStr;
4525 int i;
4526 int n;
4527 char *z;
4528
4529 zPattern = (const char*)sqlite3_value_text(argv[0]);
4530 if( zPattern==0 ) return;
4531 zErr = re_compile(&pRe, zPattern, sqlite3_user_data(context)!=0);
4532 if( zErr ){
4533 re_free(pRe);
4534 sqlite3_result_error(context, zErr, -1);
4535 return;
4536 }
4537 if( pRe==0 ){
4538 sqlite3_result_error_nomem(context);
4539 return;
4540 }
4541 pStr = sqlite3_str_new(0);
4542 if( pStr==0 ) goto re_bytecode_func_err;
4543 if( pRe->nInit>0 ){
4544 sqlite3_str_appendf(pStr, "INIT ");
4545 for(i=0; i<pRe->nInit; i++){
4546 sqlite3_str_appendf(pStr, "%02x", pRe->zInit[i]);
4547 }
4548 sqlite3_str_appendf(pStr, "\n");
4549 }
4550 for(i=0; (unsigned)i<pRe->nState; i++){
4551 sqlite3_str_appendf(pStr, "%-8s %4d\n",
4552 ReOpName[(unsigned char)pRe->aOp[i]], pRe->aArg[i]);
4553 }
4554 n = sqlite3_str_length(pStr);
4555 z = sqlite3_str_finish(pStr);
4556 if( n==0 ){
4557 sqlite3_free(z);
4558 }else{
4559 sqlite3_result_text(context, z, n-1, sqlite3_free);
4560 }
4561
4562 re_bytecode_func_err:
4563 re_free(pRe);
4564 }
4565
4566 #endif /* SQLITE_DEBUG */
4567
4568
4569 /*
4570 ** Invoke this routine to register the regexp() function with the
4571 ** SQLite database connection.
4572 */
@@ -4490,16 +4588,23 @@
4588 /* The regexpi(PATTERN,STRING) function is a case-insensitive version
4589 ** of regexp(PATTERN,STRING). */
4590 rc = sqlite3_create_function(db, "regexpi", 2,
4591 SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
4592 (void*)db, re_sql_func, 0, 0);
4593 #if defined(SQLITE_DEBUG)
4594 if( rc==SQLITE_OK ){
4595 rc = sqlite3_create_function(db, "regexp_bytecode", 1,
4596 SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
4597 0, re_bytecode_func, 0, 0);
4598 }
4599 #endif /* SQLITE_DEBUG */
4600 }
4601 return rc;
4602 }
4603
4604 /************************* End ../ext/misc/regexp.c ********************/
4605 #ifndef SQLITE_SHELL_FIDDLE
4606 /************************* Begin ../ext/misc/fileio.c ******************/
4607 /*
4608 ** 2014-06-13
4609 **
4610 ** The author disclaims copyright to this source code. In place of
@@ -10047,10 +10152,14 @@
10152 ** Return true if zId must be quoted in order to use it as an SQL
10153 ** identifier, or false otherwise.
10154 */
10155 static int idxIdentifierRequiresQuotes(const char *zId){
10156 int i;
10157 int nId = STRLEN(zId);
10158
10159 if( sqlite3_keyword_check(zId, nId) ) return 1;
10160
10161 for(i=0; zId[i]; i++){
10162 if( !(zId[i]=='_')
10163 && !(zId[i]>='0' && zId[i]<='9')
10164 && !(zId[i]>='a' && zId[i]<='z')
10165 && !(zId[i]>='A' && zId[i]<='Z')
@@ -12248,19 +12357,19 @@
12357 int nIndent; /* Size of array aiIndent[] */
12358 int iIndent; /* Index of current op in aiIndent[] */
12359 char *zNonce; /* Nonce for temporary safe-mode excapes */
12360 EQPGraph sGraph; /* Information for the graphical EXPLAIN QUERY PLAN */
12361 ExpertInfo expert; /* Valid if previous command was ".expert OPT..." */
12362 #ifdef SQLITE_SHELL_FIDDLE
12363 struct {
12364 const char * zInput; /* Input string from wasm/JS proxy */
12365 const char * zPos; /* Cursor pos into zInput */
12366 } wasm;
12367 #endif
12368 };
12369
12370 #ifdef SQLITE_SHELL_FIDDLE
12371 static ShellState shellState;
12372 #endif
12373
12374
12375 /* Allowed values for ShellState.autoEQP
@@ -12588,14 +12697,27 @@
12697 /*
12698 ** Output the given string as a hex-encoded blob (eg. X'1234' )
12699 */
12700 static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){
12701 int i;
12702 unsigned char *aBlob = (unsigned char*)pBlob;
12703
12704 char *zStr = sqlite3_malloc(nBlob*2 + 1);
12705 shell_check_oom(zStr);
12706
12707 for(i=0; i<nBlob; i++){
12708 static const char aHex[] = {
12709 '0', '1', '2', '3', '4', '5', '6', '7',
12710 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
12711 };
12712 zStr[i*2] = aHex[ (aBlob[i] >> 4) ];
12713 zStr[i*2+1] = aHex[ (aBlob[i] & 0x0F) ];
12714 }
12715 zStr[i*2] = '\0';
12716
12717 raw_printf(out,"X'%s'", zStr);
12718 sqlite3_free(zStr);
12719 }
12720
12721 /*
12722 ** Find a string that is not found anywhere in z[]. Return a pointer
12723 ** to that string.
@@ -12924,11 +13046,11 @@
13046 UNUSED_PARAMETER(zA2);
13047 UNUSED_PARAMETER(zA3);
13048 UNUSED_PARAMETER(zA4);
13049 switch( op ){
13050 case SQLITE_ATTACH: {
13051 #ifndef SQLITE_SHELL_FIDDLE
13052 /* In WASM builds the filesystem is a virtual sandbox, so
13053 ** there's no harm in using ATTACH. */
13054 failIfSafeMode(p, "cannot run ATTACH in safe mode");
13055 #endif
13056 break;
@@ -12997,19 +13119,41 @@
13119 /*
13120 ** Print a schema statement. Part of MODE_Semi and MODE_Pretty output.
13121 **
13122 ** This routine converts some CREATE TABLE statements for shadow tables
13123 ** in FTS3/4/5 into CREATE TABLE IF NOT EXISTS statements.
13124 **
13125 ** If the schema statement in z[] contains a start-of-comment and if
13126 ** sqlite3_complete() returns false, try to terminate the comment before
13127 ** printing the result. https://sqlite.org/forum/forumpost/d7be961c5c
13128 */
13129 static void printSchemaLine(FILE *out, const char *z, const char *zTail){
13130 char *zToFree = 0;
13131 if( z==0 ) return;
13132 if( zTail==0 ) return;
13133 if( zTail[0]==';' && (strstr(z, "/*")!=0 || strstr(z,"--")!=0) ){
13134 const char *zOrig = z;
13135 static const char *azTerm[] = { "", "*/", "\n" };
13136 int i;
13137 for(i=0; i<ArraySize(azTerm); i++){
13138 char *zNew = sqlite3_mprintf("%s%s;", zOrig, azTerm[i]);
13139 if( sqlite3_complete(zNew) ){
13140 size_t n = strlen(zNew);
13141 zNew[n-1] = 0;
13142 zToFree = zNew;
13143 z = zNew;
13144 break;
13145 }
13146 sqlite3_free(zNew);
13147 }
13148 }
13149 if( sqlite3_strglob("CREATE TABLE ['\"]*", z)==0 ){
13150 utf8_printf(out, "CREATE TABLE IF NOT EXISTS %s%s", z+13, zTail);
13151 }else{
13152 utf8_printf(out, "%s%s", z, zTail);
13153 }
13154 sqlite3_free(zToFree);
13155 }
13156 static void printSchemaLineN(FILE *out, char *z, int n, const char *zTail){
13157 char c = z[n];
13158 z[n] = 0;
13159 printSchemaLine(out, z, zTail);
@@ -15338,11 +15482,11 @@
15482 ** There must be two or more spaces between the end of the command and the
15483 ** start of the description of what that command does.
15484 */
15485 static const char *(azHelp[]) = {
15486 #if defined(SQLITE_HAVE_ZLIB) && !defined(SQLITE_OMIT_VIRTUALTABLE) \
15487 && !defined(SQLITE_SHELL_FIDDLE)
15488 ".archive ... Manage SQL archives",
15489 " Each command must have exactly one of the following options:",
15490 " -c, --create Create a new archive",
15491 " -u, --update Add or update files with changed mtime",
15492 " -i, --insert Like -u but always add even if unchanged",
@@ -15364,23 +15508,23 @@
15508 " http://sqlite.org/cli.html#sqlite_archive_support",
15509 #endif
15510 #ifndef SQLITE_OMIT_AUTHORIZATION
15511 ".auth ON|OFF Show authorizer callbacks",
15512 #endif
15513 #ifndef SQLITE_SHELL_FIDDLE
15514 ".backup ?DB? FILE Backup DB (default \"main\") to FILE",
15515 " Options:",
15516 " --append Use the appendvfs",
15517 " --async Write to FILE without journal and fsync()",
15518 #endif
15519 ".bail on|off Stop after hitting an error. Default OFF",
15520 ".binary on|off Turn binary output on or off. Default OFF",
15521 #ifndef SQLITE_SHELL_FIDDLE
15522 ".cd DIRECTORY Change the working directory to DIRECTORY",
15523 #endif
15524 ".changes on|off Show number of rows changed by SQL",
15525 #ifndef SQLITE_SHELL_FIDDLE
15526 ".check GLOB Fail if output since .testcase does not match",
15527 ".clone NEWDB Clone data into NEWDB from the existing database",
15528 #endif
15529 ".connection [close] [#] Open or close an auxiliary database connection",
15530 ".databases List names and files of attached databases",
@@ -15402,15 +15546,15 @@
15546 #ifdef SQLITE_DEBUG
15547 " test Show raw EXPLAIN QUERY PLAN output",
15548 " trace Like \"full\" but enable \"PRAGMA vdbe_trace\"",
15549 #endif
15550 " trigger Like \"full\" but also show trigger bytecode",
15551 #ifndef SQLITE_SHELL_FIDDLE
15552 ".excel Display the output of next command in spreadsheet",
15553 " --bom Put a UTF8 byte-order mark on intermediate file",
15554 #endif
15555 #ifndef SQLITE_SHELL_FIDDLE
15556 ".exit ?CODE? Exit this program with return-code CODE",
15557 #endif
15558 ".expert EXPERIMENTAL. Suggest indexes for queries",
15559 ".explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto",
15560 ".filectrl CMD ... Run various sqlite3_file_control() operations",
@@ -15417,11 +15561,11 @@
15561 " --schema SCHEMA Use SCHEMA instead of \"main\"",
15562 " --help Show CMD details",
15563 ".fullschema ?--indent? Show schema and the content of sqlite_stat tables",
15564 ".headers on|off Turn display of headers on or off",
15565 ".help ?-all? ?PATTERN? Show help text for PATTERN",
15566 #ifndef SQLITE_SHELL_FIDDLE
15567 ".import FILE TABLE Import data from FILE into TABLE",
15568 " Options:",
15569 " --ascii Use \\037 and \\036 as column and row separators",
15570 " --csv Use , and \\n as column and row separators",
15571 " --skip N Skip the first N rows of input",
@@ -15446,14 +15590,14 @@
15590 #endif
15591 ".limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT",
15592 ".lint OPTIONS Report potential schema issues.",
15593 " Options:",
15594 " fkey-indexes Find missing foreign key indexes",
15595 #if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_FIDDLE)
15596 ".load FILE ?ENTRY? Load an extension library",
15597 #endif
15598 #ifndef SQLITE_SHELL_FIDDLE
15599 ".log FILE|off Turn logging on or off. FILE can be stderr/stdout",
15600 #endif
15601 ".mode MODE ?OPTIONS? Set output mode",
15602 " MODE is one of:",
15603 " ascii Columns/rows delimited by 0x1F and 0x1E",
@@ -15476,15 +15620,15 @@
15620 " --wordwrap B Wrap or not at word boundaries per B (on/off)",
15621 " --ww Shorthand for \"--wordwrap 1\"",
15622 " --quote Quote output text as SQL literals",
15623 " --noquote Do not quote output text",
15624 " TABLE The name of SQL table used for \"insert\" mode",
15625 #ifndef SQLITE_SHELL_FIDDLE
15626 ".nonce STRING Suspend safe mode for one command if nonce matches",
15627 #endif
15628 ".nullvalue STRING Use STRING in place of NULL values",
15629 #ifndef SQLITE_SHELL_FIDDLE
15630 ".once ?OPTIONS? ?FILE? Output for the next SQL command only to FILE",
15631 " If FILE begins with '|' then open as a pipe",
15632 " --bom Put a UTF8 byte-order mark at the beginning",
15633 " -e Send output to the system text editor",
15634 " -x Send output as CSV to a spreadsheet (same as \".excel\")",
@@ -15502,11 +15646,11 @@
15646 #endif
15647 " --new Initialize FILE to an empty database",
15648 " --nofollow Do not follow symbolic links",
15649 " --readonly Open FILE readonly",
15650 " --zip FILE is a ZIP archive",
15651 #ifndef SQLITE_SHELL_FIDDLE
15652 ".output ?FILE? Send output to FILE or stdout if FILE is omitted",
15653 " If FILE begins with '|' then open it as a pipe.",
15654 " Options:",
15655 " --bom Prefix output with a UTF8 byte-order mark",
15656 " -e Send output to the system text editor",
@@ -15526,11 +15670,11 @@
15670 " --once Do no more than one progress interrupt",
15671 " --quiet|-q No output except at interrupts",
15672 " --reset Reset the count for each input and interrupt",
15673 #endif
15674 ".prompt MAIN CONTINUE Replace the standard prompts",
15675 #ifndef SQLITE_SHELL_FIDDLE
15676 ".quit Exit this program",
15677 ".read FILE Read input from FILE or command output",
15678 " If FILE begins with \"|\", it is a command that generates the input.",
15679 #endif
15680 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
@@ -15539,11 +15683,11 @@
15683 " --recovery-db NAME Store recovery metadata in database file NAME",
15684 " --lost-and-found TABLE Alternative name for the lost-and-found table",
15685 " --no-rowids Do not attempt to recover rowid values",
15686 " that are not also INTEGER PRIMARY KEYs",
15687 #endif
15688 #ifndef SQLITE_SHELL_FIDDLE
15689 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE",
15690 ".save ?OPTIONS? FILE Write database to FILE (an alias for .backup ...)",
15691 #endif
15692 ".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off",
15693 ".schema ?PATTERN? Show the CREATE statements matching PATTERN",
@@ -15576,24 +15720,24 @@
15720 " --sha3-224 Use the sha3-224 algorithm",
15721 " --sha3-256 Use the sha3-256 algorithm (default)",
15722 " --sha3-384 Use the sha3-384 algorithm",
15723 " --sha3-512 Use the sha3-512 algorithm",
15724 " Any other argument is a LIKE pattern for tables to hash",
15725 #if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
15726 ".shell CMD ARGS... Run CMD ARGS... in a system shell",
15727 #endif
15728 ".show Show the current values for various settings",
15729 ".stats ?ARG? Show stats or turn stats on or off",
15730 " off Turn off automatic stat display",
15731 " on Turn on automatic stat display",
15732 " stmt Show statement stats",
15733 " vmstep Show the virtual machine step count only",
15734 #if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
15735 ".system CMD ARGS... Run CMD ARGS... in a system shell",
15736 #endif
15737 ".tables ?TABLE? List names of tables matching LIKE pattern TABLE",
15738 #ifndef SQLITE_SHELL_FIDDLE
15739 ".testcase NAME Begin redirecting output to 'testcase-out.txt'",
15740 #endif
15741 ".testctrl CMD ... Run various sqlite3_test_control() operations",
15742 " Run \".testctrl\" with no arguments for details",
15743 ".timeout MS Try opening locked tables for MS milliseconds",
@@ -16142,11 +16286,11 @@
16286 sqlite3_uint_init(p->db, 0, 0);
16287 sqlite3_decimal_init(p->db, 0, 0);
16288 sqlite3_regexp_init(p->db, 0, 0);
16289 sqlite3_ieee_init(p->db, 0, 0);
16290 sqlite3_series_init(p->db, 0, 0);
16291 #ifndef SQLITE_SHELL_FIDDLE
16292 sqlite3_fileio_init(p->db, 0, 0);
16293 sqlite3_completion_init(p->db, 0, 0);
16294 #endif
16295 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_ENABLE_DBPAGE_VTAB)
16296 sqlite3_dbdata_init(p->db, 0, 0);
@@ -19272,19 +19416,19 @@
19416 }
19417 }else
19418 #endif
19419
19420 #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB) \
19421 && !defined(SQLITE_SHELL_FIDDLE)
19422 if( c=='a' && strncmp(azArg[0], "archive", n)==0 ){
19423 open_db(p, 0);
19424 failIfSafeMode(p, "cannot run .archive in safe mode");
19425 rc = arDotCommand(p, 0, azArg, nArg);
19426 }else
19427 #endif
19428
19429 #ifndef SQLITE_SHELL_FIDDLE
19430 if( (c=='b' && n>=3 && strncmp(azArg[0], "backup", n)==0)
19431 || (c=='s' && n>=3 && strncmp(azArg[0], "save", n)==0)
19432 ){
19433 const char *zDestFile = 0;
19434 const char *zDb = 0;
@@ -19349,11 +19493,11 @@
19493 utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
19494 rc = 1;
19495 }
19496 close_db(pDest);
19497 }else
19498 #endif /* !defined(SQLITE_SHELL_FIDDLE) */
19499
19500 if( c=='b' && n>=3 && strncmp(azArg[0], "bail", n)==0 ){
19501 if( nArg==2 ){
19502 bail_on_error = booleanValue(azArg[1]);
19503 }else{
@@ -19380,11 +19524,11 @@
19524 */
19525 if( c=='b' && n>=3 && strncmp(azArg[0], "breakpoint", n)==0 ){
19526 test_breakpoint();
19527 }else
19528
19529 #ifndef SQLITE_SHELL_FIDDLE
19530 if( c=='c' && strcmp(azArg[0],"cd")==0 ){
19531 failIfSafeMode(p, "cannot run .cd in safe mode");
19532 if( nArg==2 ){
19533 #if defined(_WIN32) || defined(WIN32)
19534 wchar_t *z = sqlite3_win32_utf8_to_unicode(azArg[1]);
@@ -19400,11 +19544,11 @@
19544 }else{
19545 raw_printf(stderr, "Usage: .cd DIRECTORY\n");
19546 rc = 1;
19547 }
19548 }else
19549 #endif /* !defined(SQLITE_SHELL_FIDDLE) */
19550
19551 if( c=='c' && n>=3 && strncmp(azArg[0], "changes", n)==0 ){
19552 if( nArg==2 ){
19553 setOrClearFlag(p, SHFLG_CountChanges, azArg[1]);
19554 }else{
@@ -19411,11 +19555,11 @@
19555 raw_printf(stderr, "Usage: .changes on|off\n");
19556 rc = 1;
19557 }
19558 }else
19559
19560 #ifndef SQLITE_SHELL_FIDDLE
19561 /* Cancel output redirection, if it is currently set (by .testcase)
19562 ** Then read the content of the testcase-out.txt file and compare against
19563 ** azArg[1]. If there are differences, report an error and exit.
19564 */
19565 if( c=='c' && n>=3 && strncmp(azArg[0], "check", n)==0 ){
@@ -19436,23 +19580,23 @@
19580 utf8_printf(stdout, "testcase-%s ok\n", p->zTestcase);
19581 p->nCheck++;
19582 }
19583 sqlite3_free(zRes);
19584 }else
19585 #endif /* !defined(SQLITE_SHELL_FIDDLE) */
19586
19587 #ifndef SQLITE_SHELL_FIDDLE
19588 if( c=='c' && strncmp(azArg[0], "clone", n)==0 ){
19589 failIfSafeMode(p, "cannot run .clone in safe mode");
19590 if( nArg==2 ){
19591 tryToClone(p, azArg[1]);
19592 }else{
19593 raw_printf(stderr, "Usage: .clone FILENAME\n");
19594 rc = 1;
19595 }
19596 }else
19597 #endif /* !defined(SQLITE_SHELL_FIDDLE) */
19598
19599 if( c=='c' && strncmp(azArg[0], "connection", n)==0 ){
19600 if( nArg==1 ){
19601 /* List available connections */
19602 int i;
@@ -19737,11 +19881,11 @@
19881 raw_printf(stderr, "Usage: .eqp off|on|trace|trigger|full\n");
19882 rc = 1;
19883 }
19884 }else
19885
19886 #ifndef SQLITE_SHELL_FIDDLE
19887 if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
19888 if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
19889 rc = 2;
19890 }else
19891 #endif
@@ -19997,11 +20141,11 @@
20141 }else{
20142 showHelp(p->out, 0);
20143 }
20144 }else
20145
20146 #ifndef SQLITE_SHELL_FIDDLE
20147 if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
20148 char *zTable = 0; /* Insert data into this table */
20149 char *zSchema = 0; /* within this schema (may default to "main") */
20150 char *zFile = 0; /* Name of file to extra content from */
20151 sqlite3_stmt *pStmt = NULL; /* A statement */
@@ -20288,11 +20432,11 @@
20432 utf8_printf(p->out,
20433 "Added %d rows with %d errors using %d lines of input\n",
20434 sCtx.nRow, sCtx.nErr, sCtx.nLine-1);
20435 }
20436 }else
20437 #endif /* !defined(SQLITE_SHELL_FIDDLE) */
20438
20439 #ifndef SQLITE_UNTESTABLE
20440 if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
20441 char *zSql;
20442 char *zCollist = 0;
@@ -20478,11 +20622,11 @@
20622 if( c=='l' && n>2 && strncmp(azArg[0], "lint", n)==0 ){
20623 open_db(p, 0);
20624 lintDotCommand(p, azArg, nArg);
20625 }else
20626
20627 #if !defined(SQLITE_OMIT_LOAD_EXTENSION) && !defined(SQLITE_SHELL_FIDDLE)
20628 if( c=='l' && strncmp(azArg[0], "load", n)==0 ){
20629 const char *zFile, *zProc;
20630 char *zErrMsg = 0;
20631 failIfSafeMode(p, "cannot run .load in safe mode");
20632 if( nArg<2 ){
@@ -20500,11 +20644,11 @@
20644 rc = 1;
20645 }
20646 }else
20647 #endif
20648
20649 #ifndef SQLITE_SHELL_FIDDLE
20650 if( c=='l' && strncmp(azArg[0], "log", n)==0 ){
20651 failIfSafeMode(p, "cannot run .log in safe mode");
20652 if( nArg!=2 ){
20653 raw_printf(stderr, "Usage: .log FILENAME\n");
20654 rc = 1;
@@ -20637,11 +20781,11 @@
20781 rc = 1;
20782 }
20783 p->cMode = p->mode;
20784 }else
20785
20786 #ifndef SQLITE_SHELL_FIDDLE
20787 if( c=='n' && strcmp(azArg[0], "nonce")==0 ){
20788 if( nArg!=2 ){
20789 raw_printf(stderr, "Usage: .nonce NONCE\n");
20790 rc = 1;
20791 }else if( p->zNonce==0 || strcmp(azArg[1],p->zNonce)!=0 ){
@@ -20652,11 +20796,11 @@
20796 p->bSafeMode = 0;
20797 return 0; /* Return immediately to bypass the safe mode reset
20798 ** at the end of this procedure */
20799 }
20800 }else
20801 #endif /* !defined(SQLITE_SHELL_FIDDLE) */
20802
20803 if( c=='n' && strncmp(azArg[0], "nullvalue", n)==0 ){
20804 if( nArg==2 ){
20805 sqlite3_snprintf(sizeof(p->nullValue), p->nullValue,
20806 "%.*s", (int)ArraySize(p->nullValue)-1, azArg[1]);
@@ -20674,11 +20818,11 @@
20818 int openMode = SHELL_OPEN_UNSPEC;
20819
20820 /* Check for command-line arguments */
20821 for(iName=1; iName<nArg; iName++){
20822 const char *z = azArg[iName];
20823 #ifndef SQLITE_SHELL_FIDDLE
20824 if( optionMatch(z,"new") ){
20825 newFlag = 1;
20826 #ifdef SQLITE_HAVE_ZLIB
20827 }else if( optionMatch(z, "zip") ){
20828 openMode = SHELL_OPEN_ZIPFILE;
@@ -20696,11 +20840,11 @@
20840 openMode = SHELL_OPEN_HEXDB;
20841 }else if( optionMatch(z, "maxsize") && iName+1<nArg ){
20842 p->szMax = integerValue(azArg[++iName]);
20843 #endif /* SQLITE_OMIT_DESERIALIZE */
20844 }else
20845 #endif /* !SQLITE_SHELL_FIDDLE */
20846 if( z[0]=='-' ){
20847 utf8_printf(stderr, "unknown option: %s\n", z);
20848 rc = 1;
20849 goto meta_command_exit;
20850 }else if( zFN ){
@@ -20724,11 +20868,11 @@
20868 p->szMax = 0;
20869
20870 /* If a filename is specified, try to open it first */
20871 if( zFN || p->openMode==SHELL_OPEN_HEXDB ){
20872 if( newFlag && zFN && !p->bSafeMode ) shellDeleteFile(zFN);
20873 #ifndef SQLITE_SHELL_FIDDLE
20874 if( p->bSafeMode
20875 && p->openMode!=SHELL_OPEN_HEXDB
20876 && zFN
20877 && strcmp(zFN,":memory:")!=0
20878 ){
@@ -20757,11 +20901,11 @@
20901 p->pAuxDb->zDbFilename = 0;
20902 open_db(p, 0);
20903 }
20904 }else
20905
20906 #ifndef SQLITE_SHELL_FIDDLE
20907 if( (c=='o'
20908 && (strncmp(azArg[0], "output", n)==0||strncmp(azArg[0], "once", n)==0))
20909 || (c=='e' && n==5 && strcmp(azArg[0],"excel")==0)
20910 ){
20911 char *zFile = 0;
@@ -20873,11 +21017,11 @@
21017 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
21018 }
21019 }
21020 sqlite3_free(zFile);
21021 }else
21022 #endif /* !defined(SQLITE_SHELL_FIDDLE) */
21023
21024 if( c=='p' && n>=3 && strncmp(azArg[0], "parameter", n)==0 ){
21025 open_db(p,0);
21026 if( nArg<=1 ) goto parameter_syntax_error;
21027
@@ -21043,17 +21187,17 @@
21187 if( nArg >= 3) {
21188 strncpy(continuePrompt,azArg[2],(int)ArraySize(continuePrompt)-1);
21189 }
21190 }else
21191
21192 #ifndef SQLITE_SHELL_FIDDLE
21193 if( c=='q' && strncmp(azArg[0], "quit", n)==0 ){
21194 rc = 2;
21195 }else
21196 #endif
21197
21198 #ifndef SQLITE_SHELL_FIDDLE
21199 if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 ){
21200 FILE *inSaved = p->in;
21201 int savedLineno = p->lineno;
21202 failIfSafeMode(p, "cannot run .read in safe mode");
21203 if( nArg!=2 ){
@@ -21084,13 +21228,13 @@
21228 fclose(p->in);
21229 }
21230 p->in = inSaved;
21231 p->lineno = savedLineno;
21232 }else
21233 #endif /* !defined(SQLITE_SHELL_FIDDLE) */
21234
21235 #ifndef SQLITE_SHELL_FIDDLE
21236 if( c=='r' && n>=3 && strncmp(azArg[0], "restore", n)==0 ){
21237 const char *zSrcFile;
21238 const char *zDb;
21239 sqlite3 *pSrc;
21240 sqlite3_backup *pBackup;
@@ -21138,11 +21282,11 @@
21282 utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
21283 rc = 1;
21284 }
21285 close_db(pSrc);
21286 }else
21287 #endif /* !defined(SQLITE_SHELL_FIDDLE) */
21288
21289 if( c=='s' && strncmp(azArg[0], "scanstats", n)==0 ){
21290 if( nArg==2 ){
21291 p->scanstatsOn = (u8)booleanValue(azArg[1]);
21292 #ifndef SQLITE_ENABLE_STMT_SCANSTATUS
@@ -21764,11 +21908,11 @@
21908 shell_exec(p, zSql, 0);
21909 }
21910 sqlite3_free(zSql);
21911 }else
21912
21913 #if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
21914 if( c=='s'
21915 && (strncmp(azArg[0], "shell", n)==0 || strncmp(azArg[0],"system",n)==0)
21916 ){
21917 char *zCmd;
21918 int i, x;
@@ -21785,11 +21929,11 @@
21929 }
21930 x = zCmd!=0 ? system(zCmd) : 1;
21931 sqlite3_free(zCmd);
21932 if( x ) raw_printf(stderr, "System command returns %d\n", x);
21933 }else
21934 #endif /* !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE) */
21935
21936 if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
21937 static const char *azBool[] = { "off", "on", "trigger", "full"};
21938 const char *zOut;
21939 int i;
@@ -21965,11 +22109,11 @@
22109
22110 for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
22111 sqlite3_free(azResult);
22112 }else
22113
22114 #ifndef SQLITE_SHELL_FIDDLE
22115 /* Begin redirecting output to the file "testcase-out.txt" */
22116 if( c=='t' && strcmp(azArg[0],"testcase")==0 ){
22117 output_reset(p);
22118 p->out = output_file_open("testcase-out.txt", 0);
22119 if( p->out==0 ){
@@ -21979,11 +22123,11 @@
22123 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
22124 }else{
22125 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?");
22126 }
22127 }else
22128 #endif /* !defined(SQLITE_SHELL_FIDDLE) */
22129
22130 #ifndef SQLITE_UNTESTABLE
22131 if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 ){
22132 static const struct {
22133 const char *zCtrlName; /* Name of a test-control option */
@@ -22651,11 +22795,11 @@
22795
22796 static void echo_group_input(ShellState *p, const char *zDo){
22797 if( ShellHasFlag(p, SHFLG_Echo) ) utf8_printf(p->out, "%s\n", zDo);
22798 }
22799
22800 #ifdef SQLITE_SHELL_FIDDLE
22801 /*
22802 ** Alternate one_input_line() impl for wasm mode. This is not in the primary impl
22803 ** because we need the global shellState and cannot access it from that function
22804 ** without moving lots of code around (creating a larger/messier diff).
22805 */
@@ -22682,11 +22826,11 @@
22826 shell_check_oom(zLine);
22827 memcpy(zLine, zBegin, (size_t)nZ);
22828 zLine[nZ] = 0;
22829 return zLine;
22830 }
22831 #endif /* SQLITE_SHELL_FIDDLE */
22832
22833 /*
22834 ** Read input from *in and process it. If *in==0 then input
22835 ** is interactive - the user is typing it it. Otherwise, input
22836 ** is coming from a file or device. A prompt is issued and history
@@ -23065,11 +23209,11 @@
23209 # else
23210 # define SQLITE_SHELL_IS_UTF8 (1)
23211 # endif
23212 #endif
23213
23214 #ifdef SQLITE_SHELL_FIDDLE
23215 # define main fiddle_main
23216 #endif
23217
23218 #if SQLITE_SHELL_IS_UTF8
23219 int SQLITE_CDECL main(int argc, char **argv){
@@ -23079,11 +23223,11 @@
23223 #endif
23224 #ifdef SQLITE_DEBUG
23225 sqlite3_int64 mem_main_enter = sqlite3_memory_used();
23226 #endif
23227 char *zErrMsg = 0;
23228 #ifdef SQLITE_SHELL_FIDDLE
23229 # define data shellState
23230 #else
23231 ShellState data;
23232 #endif
23233 const char *zInitFile = 0;
@@ -23099,11 +23243,11 @@
23243 int argcToFree = 0;
23244 #endif
23245
23246 setBinaryMode(stdin, 0);
23247 setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
23248 #ifdef SQLITE_SHELL_FIDDLE
23249 stdin_is_interactive = 0;
23250 stdout_is_console = 1;
23251 #else
23252 stdin_is_interactive = isatty(0);
23253 stdout_is_console = isatty(1);
@@ -23361,11 +23505,11 @@
23505 utf8_printf(stderr,"%s: Error: no database filename specified\n", Argv0);
23506 return 1;
23507 #endif
23508 }
23509 data.out = stdout;
23510 #ifndef SQLITE_SHELL_FIDDLE
23511 sqlite3_appendvfs_init(0,0,0);
23512 #endif
23513
23514 /* Go ahead and open the database file if it already exists. If the
23515 ** file does not exist, delay opening it. This prevents empty database
@@ -23629,11 +23773,11 @@
23773 }else{
23774 data.in = stdin;
23775 rc = process_input(&data);
23776 }
23777 }
23778 #ifndef SQLITE_SHELL_FIDDLE
23779 /* In WASM mode we have to leave the db state in place so that
23780 ** client code can "push" SQL into it after this call returns. */
23781 free(azCmd);
23782 set_table_name(&data, 0);
23783 if( data.db ){
@@ -23664,16 +23808,16 @@
23808 if( sqlite3_memory_used()>mem_main_enter ){
23809 utf8_printf(stderr, "Memory leaked: %u bytes\n",
23810 (unsigned int)(sqlite3_memory_used()-mem_main_enter));
23811 }
23812 #endif
23813 #endif /* !SQLITE_SHELL_FIDDLE */
23814 return rc;
23815 }
23816
23817
23818 #ifdef SQLITE_SHELL_FIDDLE
23819 /* Only for emcc experimentation purposes. */
23820 int fiddle_experiment(int a,int b){
23821 return a + b;
23822 }
23823
@@ -23790,6 +23934,6 @@
23934 shellState.wasm.zPos = zSql;
23935 process_input(&shellState);
23936 memset(&shellState.wasm, 0, sizeof(shellState.wasm));
23937 }
23938 }
23939 #endif /* SQLITE_SHELL_FIDDLE */
23940
+1008 -640
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.39.2. By combining all the individual C code files into this
3
+** version 3.40.0. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -450,13 +450,13 @@
450450
**
451451
** See also: [sqlite3_libversion()],
452452
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453
** [sqlite_version()] and [sqlite_source_id()].
454454
*/
455
-#define SQLITE_VERSION "3.39.2"
456
-#define SQLITE_VERSION_NUMBER 3039002
457
-#define SQLITE_SOURCE_ID "2022-07-21 12:26:01 9141e873c575b049ce7aeaf313d05966f1966087caf33a6c80d2416a28571a21"
455
+#define SQLITE_VERSION "3.40.0"
456
+#define SQLITE_VERSION_NUMBER 3040000
457
+#define SQLITE_SOURCE_ID "2022-09-02 21:19:24 da7af290960ab8a04a1f55cdc5eeac36b47fa194edf67f0a05daa4b7f2a4071c"
458458
459459
/*
460460
** CAPI3REF: Run-Time Library Version Numbers
461461
** KEYWORDS: sqlite3_version sqlite3_sourceid
462462
**
@@ -3728,10 +3728,13 @@
37283728
**
37293729
** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt>
37303730
** <dd>The database is opened [shared cache] enabled, overriding
37313731
** the default shared cache setting provided by
37323732
** [sqlite3_enable_shared_cache()].)^
3733
+** The [use of shared cache mode is discouraged] and hence shared cache
3734
+** capabilities may be omitted from many builds of SQLite. In such cases,
3735
+** this option is a no-op.
37333736
**
37343737
** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt>
37353738
** <dd>The database is opened [shared cache] disabled, overriding
37363739
** the default shared cache setting provided by
37373740
** [sqlite3_enable_shared_cache()].)^
@@ -3743,11 +3746,11 @@
37433746
** connection as soon as the connection is created. In addition to setting
37443747
** the extended result code mode, this flag also causes [sqlite3_open_v2()]
37453748
** to return an extended result code.</dd>
37463749
**
37473750
** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>
3748
-** <dd>The database filename is not allowed to be a symbolic link</dd>
3751
+** <dd>The database filename is not allowed to contain a symbolic link</dd>
37493752
** </dl>)^
37503753
**
37513754
** If the 3rd parameter to sqlite3_open_v2() is not one of the
37523755
** required combinations shown above optionally combined with other
37533756
** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
@@ -6769,11 +6772,11 @@
67696772
**
67706773
** ^The sqlite3_autovacuum_pages(D,C,P,X) interface registers a callback
67716774
** function C that is invoked prior to each autovacuum of the database
67726775
** file. ^The callback is passed a copy of the generic data pointer (P),
67736776
** the schema-name of the attached database that is being autovacuumed,
6774
-** the the size of the database file in pages, the number of free pages,
6777
+** the size of the database file in pages, the number of free pages,
67756778
** and the number of bytes per page, respectively. The callback should
67766779
** return the number of free pages that should be removed by the
67776780
** autovacuum. ^If the callback returns zero, then no autovacuum happens.
67786781
** ^If the value returned is greater than or equal to the number of
67796782
** free pages, then a complete autovacuum happens.
@@ -6889,10 +6892,15 @@
68896892
**
68906893
** ^(This routine enables or disables the sharing of the database cache
68916894
** and schema data structures between [database connection | connections]
68926895
** to the same database. Sharing is enabled if the argument is true
68936896
** and disabled if the argument is false.)^
6897
+**
6898
+** This interface is omitted if SQLite is compiled with
6899
+** [-DSQLITE_OMIT_SHARED_CACHE]. The [-DSQLITE_OMIT_SHARED_CACHE]
6900
+** compile-time option is recommended because the
6901
+** [use of shared cache mode is discouraged].
68946902
**
68956903
** ^Cache sharing is enabled and disabled for an entire process.
68966904
** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]).
68976905
** In prior versions of SQLite,
68986906
** sharing was enabled or disabled for each thread separately.
@@ -6988,11 +6996,11 @@
69886996
** ^Setting the heap limits to zero disables the heap limiter mechanism.
69896997
**
69906998
** ^The soft heap limit may not be greater than the hard heap limit.
69916999
** ^If the hard heap limit is enabled and if sqlite3_soft_heap_limit(N)
69927000
** is invoked with a value of N that is greater than the hard heap limit,
6993
-** the the soft heap limit is set to the value of the hard heap limit.
7001
+** the soft heap limit is set to the value of the hard heap limit.
69947002
** ^The soft heap limit is automatically enabled whenever the hard heap
69957003
** limit is enabled. ^When sqlite3_hard_heap_limit64(N) is invoked and
69967004
** the soft heap limit is outside the range of 1..N, then the soft heap
69977005
** limit is set to N. ^Invoking sqlite3_soft_heap_limit64(0) when the
69987006
** hard heap limit is enabled makes the soft heap limit equal to the
@@ -9283,11 +9291,11 @@
92839291
** sqlite3_backup_init() is called and before the corresponding call to
92849292
** sqlite3_backup_finish(). SQLite does not currently check to see
92859293
** if the application incorrectly accesses the destination [database connection]
92869294
** and so no error code is reported, but the operations may malfunction
92879295
** nevertheless. Use of the destination database connection while a
9288
-** backup is in progress might also also cause a mutex deadlock.
9296
+** backup is in progress might also cause a mutex deadlock.
92899297
**
92909298
** If running in [shared cache mode], the application must
92919299
** guarantee that the shared cache used by the destination database
92929300
** is not accessed while the backup is running. In practice this means
92939301
** that the application must guarantee that the disk file being
@@ -9711,11 +9719,11 @@
97119719
** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the
97129720
** meaning of each of these checkpoint modes.
97139721
*/
97149722
#define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */
97159723
#define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */
9716
-#define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for for readers */
9724
+#define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for readers */
97179725
#define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */
97189726
97199727
/*
97209728
** CAPI3REF: Virtual Table Interface Configuration
97219729
**
@@ -13142,10 +13150,15 @@
1314213150
/******** End of fts5.h *********/
1314313151
1314413152
/************** End of sqlite3.h *********************************************/
1314513153
/************** Continuing where we left off in sqliteInt.h ******************/
1314613154
13155
+/*
13156
+** Reuse the STATIC_LRU for mutex access to sqlite3_temp_directory.
13157
+*/
13158
+#define SQLITE_MUTEX_STATIC_TEMPDIR SQLITE_MUTEX_STATIC_VFS1
13159
+
1314713160
/*
1314813161
** Include the configuration header output by 'configure' if we're using the
1314913162
** autoconf-based build
1315013163
*/
1315113164
#if defined(_HAVE_SQLITE_CONFIG_H) && !defined(SQLITECONFIG_H)
@@ -15553,67 +15566,67 @@
1555315566
#define OP_Checkpoint 3
1555415567
#define OP_JournalMode 4
1555515568
#define OP_Vacuum 5
1555615569
#define OP_VFilter 6 /* jump, synopsis: iplan=r[P3] zplan='P4' */
1555715570
#define OP_VUpdate 7 /* synopsis: data=r[P3@P2] */
15558
-#define OP_Goto 8 /* jump */
15559
-#define OP_Gosub 9 /* jump */
15560
-#define OP_InitCoroutine 10 /* jump */
15561
-#define OP_Yield 11 /* jump */
15562
-#define OP_MustBeInt 12 /* jump */
15563
-#define OP_Jump 13 /* jump */
15564
-#define OP_Once 14 /* jump */
15565
-#define OP_If 15 /* jump */
15566
-#define OP_IfNot 16 /* jump */
15567
-#define OP_IsNullOrType 17 /* jump, synopsis: if typeof(r[P1]) IN (P3,5) goto P2 */
15568
-#define OP_IfNullRow 18 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
15571
+#define OP_Init 8 /* jump, synopsis: Start at P2 */
15572
+#define OP_Goto 9 /* jump */
15573
+#define OP_Gosub 10 /* jump */
15574
+#define OP_InitCoroutine 11 /* jump */
15575
+#define OP_Yield 12 /* jump */
15576
+#define OP_MustBeInt 13 /* jump */
15577
+#define OP_Jump 14 /* jump */
15578
+#define OP_Once 15 /* jump */
15579
+#define OP_If 16 /* jump */
15580
+#define OP_IfNot 17 /* jump */
15581
+#define OP_IsNullOrType 18 /* jump, synopsis: if typeof(r[P1]) IN (P3,5) goto P2 */
1556915582
#define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
15570
-#define OP_SeekLT 20 /* jump, synopsis: key=r[P3@P4] */
15571
-#define OP_SeekLE 21 /* jump, synopsis: key=r[P3@P4] */
15572
-#define OP_SeekGE 22 /* jump, synopsis: key=r[P3@P4] */
15573
-#define OP_SeekGT 23 /* jump, synopsis: key=r[P3@P4] */
15574
-#define OP_IfNotOpen 24 /* jump, synopsis: if( !csr[P1] ) goto P2 */
15575
-#define OP_IfNoHope 25 /* jump, synopsis: key=r[P3@P4] */
15576
-#define OP_NoConflict 26 /* jump, synopsis: key=r[P3@P4] */
15577
-#define OP_NotFound 27 /* jump, synopsis: key=r[P3@P4] */
15578
-#define OP_Found 28 /* jump, synopsis: key=r[P3@P4] */
15579
-#define OP_SeekRowid 29 /* jump, synopsis: intkey=r[P3] */
15580
-#define OP_NotExists 30 /* jump, synopsis: intkey=r[P3] */
15581
-#define OP_Last 31 /* jump */
15582
-#define OP_IfSmaller 32 /* jump */
15583
-#define OP_SorterSort 33 /* jump */
15584
-#define OP_Sort 34 /* jump */
15585
-#define OP_Rewind 35 /* jump */
15586
-#define OP_SorterNext 36 /* jump */
15587
-#define OP_Prev 37 /* jump */
15588
-#define OP_Next 38 /* jump */
15589
-#define OP_IdxLE 39 /* jump, synopsis: key=r[P3@P4] */
15590
-#define OP_IdxGT 40 /* jump, synopsis: key=r[P3@P4] */
15591
-#define OP_IdxLT 41 /* jump, synopsis: key=r[P3@P4] */
15592
-#define OP_IdxGE 42 /* jump, synopsis: key=r[P3@P4] */
15583
+#define OP_IfNullRow 20 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
15584
+#define OP_SeekLT 21 /* jump, synopsis: key=r[P3@P4] */
15585
+#define OP_SeekLE 22 /* jump, synopsis: key=r[P3@P4] */
15586
+#define OP_SeekGE 23 /* jump, synopsis: key=r[P3@P4] */
15587
+#define OP_SeekGT 24 /* jump, synopsis: key=r[P3@P4] */
15588
+#define OP_IfNotOpen 25 /* jump, synopsis: if( !csr[P1] ) goto P2 */
15589
+#define OP_IfNoHope 26 /* jump, synopsis: key=r[P3@P4] */
15590
+#define OP_NoConflict 27 /* jump, synopsis: key=r[P3@P4] */
15591
+#define OP_NotFound 28 /* jump, synopsis: key=r[P3@P4] */
15592
+#define OP_Found 29 /* jump, synopsis: key=r[P3@P4] */
15593
+#define OP_SeekRowid 30 /* jump, synopsis: intkey=r[P3] */
15594
+#define OP_NotExists 31 /* jump, synopsis: intkey=r[P3] */
15595
+#define OP_Last 32 /* jump */
15596
+#define OP_IfSmaller 33 /* jump */
15597
+#define OP_SorterSort 34 /* jump */
15598
+#define OP_Sort 35 /* jump */
15599
+#define OP_Rewind 36 /* jump */
15600
+#define OP_SorterNext 37 /* jump */
15601
+#define OP_Prev 38 /* jump */
15602
+#define OP_Next 39 /* jump */
15603
+#define OP_IdxLE 40 /* jump, synopsis: key=r[P3@P4] */
15604
+#define OP_IdxGT 41 /* jump, synopsis: key=r[P3@P4] */
15605
+#define OP_IdxLT 42 /* jump, synopsis: key=r[P3@P4] */
1559315606
#define OP_Or 43 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
1559415607
#define OP_And 44 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
15595
-#define OP_RowSetRead 45 /* jump, synopsis: r[P3]=rowset(P1) */
15596
-#define OP_RowSetTest 46 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */
15597
-#define OP_Program 47 /* jump */
15598
-#define OP_FkIfZero 48 /* jump, synopsis: if fkctr[P1]==0 goto P2 */
15599
-#define OP_IfPos 49 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
15608
+#define OP_IdxGE 45 /* jump, synopsis: key=r[P3@P4] */
15609
+#define OP_RowSetRead 46 /* jump, synopsis: r[P3]=rowset(P1) */
15610
+#define OP_RowSetTest 47 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */
15611
+#define OP_Program 48 /* jump */
15612
+#define OP_FkIfZero 49 /* jump, synopsis: if fkctr[P1]==0 goto P2 */
1560015613
#define OP_IsNull 50 /* jump, same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
1560115614
#define OP_NotNull 51 /* jump, same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
1560215615
#define OP_Ne 52 /* jump, same as TK_NE, synopsis: IF r[P3]!=r[P1] */
1560315616
#define OP_Eq 53 /* jump, same as TK_EQ, synopsis: IF r[P3]==r[P1] */
1560415617
#define OP_Gt 54 /* jump, same as TK_GT, synopsis: IF r[P3]>r[P1] */
1560515618
#define OP_Le 55 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */
1560615619
#define OP_Lt 56 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */
1560715620
#define OP_Ge 57 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */
1560815621
#define OP_ElseEq 58 /* jump, same as TK_ESCAPE */
15609
-#define OP_IfNotZero 59 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
15610
-#define OP_DecrJumpZero 60 /* jump, synopsis: if (--r[P1])==0 goto P2 */
15611
-#define OP_IncrVacuum 61 /* jump */
15612
-#define OP_VNext 62 /* jump */
15613
-#define OP_Filter 63 /* jump, synopsis: if key(P3@P4) not in filter(P1) goto P2 */
15614
-#define OP_Init 64 /* jump, synopsis: Start at P2 */
15622
+#define OP_IfPos 59 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
15623
+#define OP_IfNotZero 60 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
15624
+#define OP_DecrJumpZero 61 /* jump, synopsis: if (--r[P1])==0 goto P2 */
15625
+#define OP_IncrVacuum 62 /* jump */
15626
+#define OP_VNext 63 /* jump */
15627
+#define OP_Filter 64 /* jump, synopsis: if key(P3@P4) not in filter(P1) goto P2 */
1561515628
#define OP_PureFunc 65 /* synopsis: r[P3]=func(r[P2@NP]) */
1561615629
#define OP_Function 66 /* synopsis: r[P3]=func(r[P2@NP]) */
1561715630
#define OP_Return 67
1561815631
#define OP_EndCoroutine 68
1561915632
#define OP_HaltIfNull 69 /* synopsis: if r[P3]=null halt */
@@ -15745,17 +15758,17 @@
1574515758
#define OPFLG_IN3 0x08 /* in3: P3 is an input */
1574615759
#define OPFLG_OUT2 0x10 /* out2: P2 is an output */
1574715760
#define OPFLG_OUT3 0x20 /* out3: P3 is an output */
1574815761
#define OPFLG_INITIALIZER {\
1574915762
/* 0 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00,\
15750
-/* 8 */ 0x01, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01, 0x03,\
15751
-/* 16 */ 0x03, 0x03, 0x01, 0x12, 0x09, 0x09, 0x09, 0x09,\
15752
-/* 24 */ 0x01, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x01,\
15763
+/* 8 */ 0x01, 0x01, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01,\
15764
+/* 16 */ 0x03, 0x03, 0x03, 0x12, 0x01, 0x09, 0x09, 0x09,\
15765
+/* 24 */ 0x09, 0x01, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
1575315766
/* 32 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
15754
-/* 40 */ 0x01, 0x01, 0x01, 0x26, 0x26, 0x23, 0x0b, 0x01,\
15755
-/* 48 */ 0x01, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
15756
-/* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x01, 0x01, 0x01,\
15767
+/* 40 */ 0x01, 0x01, 0x01, 0x26, 0x26, 0x01, 0x23, 0x0b,\
15768
+/* 48 */ 0x01, 0x01, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
15769
+/* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x03, 0x01, 0x01,\
1575715770
/* 64 */ 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10,\
1575815771
/* 72 */ 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10, 0x00,\
1575915772
/* 80 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x02, 0x02,\
1576015773
/* 88 */ 0x02, 0x00, 0x00, 0x12, 0x1e, 0x20, 0x00, 0x00,\
1576115774
/* 96 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x26, 0x26,\
@@ -15857,10 +15870,11 @@
1585715870
SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
1585815871
SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
1585915872
SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
1586015873
SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
1586115874
SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
15875
+SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetLastOp(Vdbe*);
1586215876
SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Parse*);
1586315877
SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce(Vdbe*);
1586415878
SQLITE_PRIVATE void sqlite3VdbeReusable(Vdbe*);
1586515879
SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe*);
1586615880
SQLITE_PRIVATE void sqlite3VdbeMakeReady(Vdbe*,Parse*);
@@ -16741,10 +16755,11 @@
1674116755
void *pMiddle; /* First byte past end of full-size buffers and
1674216756
** the first byte of LOOKASIDE_SMALL buffers */
1674316757
#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
1674416758
void *pStart; /* First byte of available memory space */
1674516759
void *pEnd; /* First byte past end of available space */
16760
+ void *pTrueEnd; /* True value of pEnd, when db->pnBytesFreed!=0 */
1674616761
};
1674716762
struct LookasideSlot {
1674816763
LookasideSlot *pNext; /* Next buffer in the list of free buffers */
1674916764
};
1675016765
@@ -18189,11 +18204,11 @@
1818918204
#define EP_xIsSelect 0x001000 /* x.pSelect is valid (otherwise x.pList is) */
1819018205
#define EP_Skip 0x002000 /* Operator does not contribute to affinity */
1819118206
#define EP_Reduced 0x004000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
1819218207
#define EP_Win 0x008000 /* Contains window functions */
1819318208
#define EP_TokenOnly 0x010000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
18194
-#define EP_MemToken 0x020000 /* Need to sqlite3DbFree() Expr.zToken */
18209
+ /* 0x020000 // Available for reuse */
1819518210
#define EP_IfNullRow 0x040000 /* The TK_IF_NULL_ROW opcode */
1819618211
#define EP_Unlikely 0x080000 /* unlikely() or likelihood() function */
1819718212
#define EP_ConstFunc 0x100000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
1819818213
#define EP_CanBeNull 0x200000 /* Can be null despite NOT NULL constraint */
1819918214
#define EP_Subquery 0x400000 /* Tree contains a TK_SELECT operator */
@@ -19667,10 +19682,11 @@
1966719682
SQLITE_PRIVATE void *sqlite3Realloc(void*, u64);
1966819683
SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64);
1966919684
SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64);
1967019685
SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*);
1967119686
SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3*, void*);
19687
+SQLITE_PRIVATE void sqlite3DbNNFreeNN(sqlite3*, void*);
1967219688
SQLITE_PRIVATE int sqlite3MallocSize(const void*);
1967319689
SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, const void*);
1967419690
SQLITE_PRIVATE void *sqlite3PageMalloc(int);
1967519691
SQLITE_PRIVATE void sqlite3PageFree(void*);
1967619692
SQLITE_PRIVATE void sqlite3MemSetDefault(void);
@@ -20191,10 +20207,11 @@
2019120207
SQLITE_PRIVATE int sqlite3FixSrcList(DbFixer*, SrcList*);
2019220208
SQLITE_PRIVATE int sqlite3FixSelect(DbFixer*, Select*);
2019320209
SQLITE_PRIVATE int sqlite3FixExpr(DbFixer*, Expr*);
2019420210
SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
2019520211
SQLITE_PRIVATE int sqlite3RealSameAsInt(double,sqlite3_int64);
20212
+SQLITE_PRIVATE i64 sqlite3RealToI64(double);
2019620213
SQLITE_PRIVATE void sqlite3Int64ToText(i64,char*);
2019720214
SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*, int, u8);
2019820215
SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*);
2019920216
SQLITE_PRIVATE int sqlite3GetUInt32(const char*, u32*);
2020020217
SQLITE_PRIVATE int sqlite3Atoi(const char*);
@@ -21637,13 +21654,10 @@
2163721654
"OMIT_WSD",
2163821655
#endif
2163921656
#ifdef SQLITE_OMIT_XFER_OPT
2164021657
"OMIT_XFER_OPT",
2164121658
#endif
21642
-#ifdef SQLITE_PCACHE_SEPARATE_HEADER
21643
- "PCACHE_SEPARATE_HEADER",
21644
-#endif
2164521659
#ifdef SQLITE_PERFORMANCE_TRACE
2164621660
"PERFORMANCE_TRACE",
2164721661
#endif
2164821662
#ifdef SQLITE_POWERSAFE_OVERWRITE
2164921663
# if SQLITE_POWERSAFE_OVERWRITE != 1
@@ -22592,11 +22606,11 @@
2259222606
** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()
2259322607
** is really a pointer to an instance of this structure.
2259422608
*/
2259522609
struct Vdbe {
2259622610
sqlite3 *db; /* The database connection that owns this statement */
22597
- Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
22611
+ Vdbe **ppVPrev,*pVNext; /* Linked list of VDBEs with the same Vdbe.db */
2259822612
Parse *pParse; /* Parsing context used to create this Vdbe */
2259922613
ynVar nVar; /* Number of entries in aVar[] */
2260022614
int nMem; /* Number of memory locations currently allocated */
2260122615
int nCursor; /* Number of slots in apCsr[] */
2260222616
u32 cacheCtr; /* VdbeCursor row cache generation counter */
@@ -23150,10 +23164,12 @@
2315023164
int i; /* Used to iterate through schemas */
2315123165
int nByte = 0; /* Used to accumulate return value */
2315223166
2315323167
sqlite3BtreeEnterAll(db);
2315423168
db->pnBytesFreed = &nByte;
23169
+ assert( db->lookaside.pEnd==db->lookaside.pTrueEnd );
23170
+ db->lookaside.pEnd = db->lookaside.pStart;
2315523171
for(i=0; i<db->nDb; i++){
2315623172
Schema *pSchema = db->aDb[i].pSchema;
2315723173
if( ALWAYS(pSchema!=0) ){
2315823174
HashElem *p;
2315923175
@@ -23175,10 +23191,11 @@
2317523191
sqlite3DeleteTable(db, (Table *)sqliteHashData(p));
2317623192
}
2317723193
}
2317823194
}
2317923195
db->pnBytesFreed = 0;
23196
+ db->lookaside.pEnd = db->lookaside.pTrueEnd;
2318023197
sqlite3BtreeLeaveAll(db);
2318123198
2318223199
*pHighwater = 0;
2318323200
*pCurrent = nByte;
2318423201
break;
@@ -23192,13 +23209,16 @@
2319223209
case SQLITE_DBSTATUS_STMT_USED: {
2319323210
struct Vdbe *pVdbe; /* Used to iterate through VMs */
2319423211
int nByte = 0; /* Used to accumulate return value */
2319523212
2319623213
db->pnBytesFreed = &nByte;
23197
- for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pNext){
23214
+ assert( db->lookaside.pEnd==db->lookaside.pTrueEnd );
23215
+ db->lookaside.pEnd = db->lookaside.pStart;
23216
+ for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pVNext){
2319823217
sqlite3VdbeDelete(pVdbe);
2319923218
}
23219
+ db->lookaside.pEnd = db->lookaside.pTrueEnd;
2320023220
db->pnBytesFreed = 0;
2320123221
2320223222
*pHighwater = 0; /* IMP: R-64479-57858 */
2320323223
*pCurrent = nByte;
2320423224
@@ -23530,11 +23550,11 @@
2353023550
X1 = 36525*(Y+4716)/100;
2353123551
X2 = 306001*(M+1)/10000;
2353223552
p->iJD = (sqlite3_int64)((X1 + X2 + D + B - 1524.5 ) * 86400000);
2353323553
p->validJD = 1;
2353423554
if( p->validHMS ){
23535
- p->iJD += p->h*3600000 + p->m*60000 + (sqlite3_int64)(p->s*1000);
23555
+ p->iJD += p->h*3600000 + p->m*60000 + (sqlite3_int64)(p->s*1000 + 0.5);
2353623556
if( p->validTZ ){
2353723557
p->iJD -= p->tz*60000;
2353823558
p->validYMD = 0;
2353923559
p->validHMS = 0;
2354023560
p->validTZ = 0;
@@ -24039,11 +24059,11 @@
2403924059
** weekday N where 0==Sunday, 1==Monday, and so forth. If the
2404024060
** date is already on the appropriate weekday, this is a no-op.
2404124061
*/
2404224062
if( sqlite3_strnicmp(z, "weekday ", 8)==0
2404324063
&& sqlite3AtoF(&z[8], &r, sqlite3Strlen30(&z[8]), SQLITE_UTF8)>0
24044
- && (n=(int)r)==r && n>=0 && r<7 ){
24064
+ && r>=0.0 && r<7.0 && (n=(int)r)==r ){
2404524065
sqlite3_int64 Z;
2404624066
computeYMD_HMS(p);
2404724067
p->validTZ = 0;
2404824068
p->validJD = 0;
2404924069
computeJD(p);
@@ -24837,10 +24857,11 @@
2483724857
DO_OS_MALLOC_TEST(0);
2483824858
/* 0x87f7f is a mask of SQLITE_OPEN_ flags that are valid to be passed
2483924859
** down into the VFS layer. Some SQLITE_OPEN_ flags (for example,
2484024860
** SQLITE_OPEN_FULLMUTEX or SQLITE_OPEN_SHAREDCACHE) are blocked before
2484124861
** reaching the VFS. */
24862
+ assert( zPath || (flags & SQLITE_OPEN_EXCLUSIVE) );
2484224863
rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x1087f7f, pFlagsOut);
2484324864
assert( rc==SQLITE_OK || pFile->pMethods==0 );
2484424865
return rc;
2484524866
}
2484624867
SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
@@ -29102,11 +29123,11 @@
2910229123
/*
2910329124
** TRUE if p is a lookaside memory allocation from db
2910429125
*/
2910529126
#ifndef SQLITE_OMIT_LOOKASIDE
2910629127
static int isLookaside(sqlite3 *db, const void *p){
29107
- return SQLITE_WITHIN(p, db->lookaside.pStart, db->lookaside.pEnd);
29128
+ return SQLITE_WITHIN(p, db->lookaside.pStart, db->lookaside.pTrueEnd);
2910829129
}
2910929130
#else
2911029131
#define isLookaside(A,B) 0
2911129132
#endif
2911229133
@@ -29126,22 +29147,20 @@
2912629147
#endif
2912729148
}
2912829149
SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, const void *p){
2912929150
assert( p!=0 );
2913029151
#ifdef SQLITE_DEBUG
29131
- if( db==0 || !isLookaside(db,p) ){
29132
- if( db==0 ){
29133
- assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
29134
- assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
29135
- }else{
29136
- assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
29137
- assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
29138
- }
29152
+ if( db==0 ){
29153
+ assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
29154
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
29155
+ }else if( !isLookaside(db,p) ){
29156
+ assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
29157
+ assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2913929158
}
2914029159
#endif
2914129160
if( db ){
29142
- if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){
29161
+ if( ((uptr)p)<(uptr)(db->lookaside.pTrueEnd) ){
2914329162
#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
2914429163
if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){
2914529164
assert( sqlite3_mutex_held(db->mutex) );
2914629165
return LOOKASIDE_SMALL;
2914729166
}
@@ -29193,18 +29212,15 @@
2919329212
*/
2919429213
SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3 *db, void *p){
2919529214
assert( db==0 || sqlite3_mutex_held(db->mutex) );
2919629215
assert( p!=0 );
2919729216
if( db ){
29198
- if( db->pnBytesFreed ){
29199
- measureAllocationSize(db, p);
29200
- return;
29201
- }
2920229217
if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){
2920329218
#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
2920429219
if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){
2920529220
LookasideSlot *pBuf = (LookasideSlot*)p;
29221
+ assert( db->pnBytesFreed==0 );
2920629222
#ifdef SQLITE_DEBUG
2920729223
memset(p, 0xaa, LOOKASIDE_SMALL); /* Trash freed content */
2920829224
#endif
2920929225
pBuf->pNext = db->lookaside.pSmallFree;
2921029226
db->lookaside.pSmallFree = pBuf;
@@ -29211,24 +29227,66 @@
2921129227
return;
2921229228
}
2921329229
#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
2921429230
if( ((uptr)p)>=(uptr)(db->lookaside.pStart) ){
2921529231
LookasideSlot *pBuf = (LookasideSlot*)p;
29232
+ assert( db->pnBytesFreed==0 );
2921629233
#ifdef SQLITE_DEBUG
2921729234
memset(p, 0xaa, db->lookaside.szTrue); /* Trash freed content */
2921829235
#endif
2921929236
pBuf->pNext = db->lookaside.pFree;
2922029237
db->lookaside.pFree = pBuf;
2922129238
return;
2922229239
}
2922329240
}
29241
+ if( db->pnBytesFreed ){
29242
+ measureAllocationSize(db, p);
29243
+ return;
29244
+ }
2922429245
}
2922529246
assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2922629247
assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2922729248
assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
2922829249
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
2922929250
sqlite3_free(p);
29251
+}
29252
+SQLITE_PRIVATE void sqlite3DbNNFreeNN(sqlite3 *db, void *p){
29253
+ assert( db!=0 );
29254
+ assert( sqlite3_mutex_held(db->mutex) );
29255
+ assert( p!=0 );
29256
+ if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){
29257
+#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
29258
+ if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){
29259
+ LookasideSlot *pBuf = (LookasideSlot*)p;
29260
+ assert( db->pnBytesFreed==0 );
29261
+#ifdef SQLITE_DEBUG
29262
+ memset(p, 0xaa, LOOKASIDE_SMALL); /* Trash freed content */
29263
+#endif
29264
+ pBuf->pNext = db->lookaside.pSmallFree;
29265
+ db->lookaside.pSmallFree = pBuf;
29266
+ return;
29267
+ }
29268
+#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
29269
+ if( ((uptr)p)>=(uptr)(db->lookaside.pStart) ){
29270
+ LookasideSlot *pBuf = (LookasideSlot*)p;
29271
+ assert( db->pnBytesFreed==0 );
29272
+#ifdef SQLITE_DEBUG
29273
+ memset(p, 0xaa, db->lookaside.szTrue); /* Trash freed content */
29274
+#endif
29275
+ pBuf->pNext = db->lookaside.pFree;
29276
+ db->lookaside.pFree = pBuf;
29277
+ return;
29278
+ }
29279
+ }
29280
+ if( db->pnBytesFreed ){
29281
+ measureAllocationSize(db, p);
29282
+ return;
29283
+ }
29284
+ assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
29285
+ assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
29286
+ sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
29287
+ sqlite3_free(p);
2923029288
}
2923129289
SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
2923229290
assert( db==0 || sqlite3_mutex_held(db->mutex) );
2923329291
if( p ) sqlite3DbFreeNN(db, p);
2923429292
}
@@ -29561,12 +29619,17 @@
2956129619
if( db->nVdbeExec>0 ){
2956229620
AtomicStore(&db->u1.isInterrupted, 1);
2956329621
}
2956429622
DisableLookaside;
2956529623
if( db->pParse ){
29624
+ Parse *pParse;
2956629625
sqlite3ErrorMsg(db->pParse, "out of memory");
2956729626
db->pParse->rc = SQLITE_NOMEM_BKPT;
29627
+ for(pParse=db->pParse->pOuterParse; pParse; pParse = pParse->pOuterParse){
29628
+ pParse->nErr++;
29629
+ pParse->rc = SQLITE_NOMEM;
29630
+ }
2956829631
}
2956929632
}
2957029633
return 0;
2957129634
}
2957229635
@@ -32332,20 +32395,45 @@
3233232395
3233332396
/* All threads share a single random number generator.
3233432397
** This structure is the current state of the generator.
3233532398
*/
3233632399
static SQLITE_WSD struct sqlite3PrngType {
32337
- unsigned char isInit; /* True if initialized */
32338
- unsigned char i, j; /* State variables */
32339
- unsigned char s[256]; /* State variables */
32400
+ u32 s[16]; /* 64 bytes of chacha20 state */
32401
+ u8 out[64]; /* Output bytes */
32402
+ u8 n; /* Output bytes remaining */
3234032403
} sqlite3Prng;
3234132404
32405
+
32406
+/* The RFC-7539 ChaCha20 block function
32407
+*/
32408
+#define ROTL(a,b) (((a) << (b)) | ((a) >> (32 - (b))))
32409
+#define QR(a, b, c, d) ( \
32410
+ a += b, d ^= a, d = ROTL(d,16), \
32411
+ c += d, b ^= c, b = ROTL(b,12), \
32412
+ a += b, d ^= a, d = ROTL(d, 8), \
32413
+ c += d, b ^= c, b = ROTL(b, 7))
32414
+static void chacha_block(u32 *out, const u32 *in){
32415
+ int i;
32416
+ u32 x[16];
32417
+ memcpy(x, in, 64);
32418
+ for(i=0; i<10; i++){
32419
+ QR(x[0], x[4], x[ 8], x[12]);
32420
+ QR(x[1], x[5], x[ 9], x[13]);
32421
+ QR(x[2], x[6], x[10], x[14]);
32422
+ QR(x[3], x[7], x[11], x[15]);
32423
+ QR(x[0], x[5], x[10], x[15]);
32424
+ QR(x[1], x[6], x[11], x[12]);
32425
+ QR(x[2], x[7], x[ 8], x[13]);
32426
+ QR(x[3], x[4], x[ 9], x[14]);
32427
+ }
32428
+ for(i=0; i<16; i++) out[i] = x[i]+in[i];
32429
+}
32430
+
3234232431
/*
3234332432
** Return N random bytes.
3234432433
*/
3234532434
SQLITE_API void sqlite3_randomness(int N, void *pBuf){
32346
- unsigned char t;
3234732435
unsigned char *zBuf = pBuf;
3234832436
3234932437
/* The "wsdPrng" macro will resolve to the pseudo-random number generator
3235032438
** state vector. If writable static data is unsupported on the target,
3235132439
** we have to locate the state vector at run-time. In the more common
@@ -32371,57 +32459,50 @@
3237132459
mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
3237232460
#endif
3237332461
3237432462
sqlite3_mutex_enter(mutex);
3237532463
if( N<=0 || pBuf==0 ){
32376
- wsdPrng.isInit = 0;
32464
+ wsdPrng.s[0] = 0;
3237732465
sqlite3_mutex_leave(mutex);
3237832466
return;
3237932467
}
3238032468
3238132469
/* Initialize the state of the random number generator once,
32382
- ** the first time this routine is called. The seed value does
32383
- ** not need to contain a lot of randomness since we are not
32384
- ** trying to do secure encryption or anything like that...
32385
- **
32386
- ** Nothing in this file or anywhere else in SQLite does any kind of
32387
- ** encryption. The RC4 algorithm is being used as a PRNG (pseudo-random
32388
- ** number generator) not as an encryption device.
32470
+ ** the first time this routine is called.
3238932471
*/
32390
- if( !wsdPrng.isInit ){
32472
+ if( wsdPrng.s[0]==0 ){
3239132473
sqlite3_vfs *pVfs = sqlite3_vfs_find(0);
32392
- int i;
32393
- char k[256];
32394
- wsdPrng.j = 0;
32395
- wsdPrng.i = 0;
32474
+ static const u32 chacha20_init[] = {
32475
+ 0x61707865, 0x3320646e, 0x79622d32, 0x6b206574
32476
+ };
32477
+ memcpy(&wsdPrng.s[0], chacha20_init, 16);
3239632478
if( NEVER(pVfs==0) ){
32397
- memset(k, 0, sizeof(k));
32479
+ memset(&wsdPrng.s[4], 0, 44);
3239832480
}else{
32399
- sqlite3OsRandomness(pVfs, 256, k);
32400
- }
32401
- for(i=0; i<256; i++){
32402
- wsdPrng.s[i] = (u8)i;
32403
- }
32404
- for(i=0; i<256; i++){
32405
- wsdPrng.j += wsdPrng.s[i] + k[i];
32406
- t = wsdPrng.s[wsdPrng.j];
32407
- wsdPrng.s[wsdPrng.j] = wsdPrng.s[i];
32408
- wsdPrng.s[i] = t;
32409
- }
32410
- wsdPrng.isInit = 1;
32481
+ sqlite3OsRandomness(pVfs, 44, (char*)&wsdPrng.s[4]);
32482
+ }
32483
+ wsdPrng.s[15] = wsdPrng.s[12];
32484
+ wsdPrng.s[12] = 0;
32485
+ wsdPrng.n = 0;
3241132486
}
3241232487
3241332488
assert( N>0 );
32414
- do{
32415
- wsdPrng.i++;
32416
- t = wsdPrng.s[wsdPrng.i];
32417
- wsdPrng.j += t;
32418
- wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j];
32419
- wsdPrng.s[wsdPrng.j] = t;
32420
- t += wsdPrng.s[wsdPrng.i];
32421
- *(zBuf++) = wsdPrng.s[t];
32422
- }while( --N );
32489
+ while( 1 /* exit by break */ ){
32490
+ if( N<=wsdPrng.n ){
32491
+ memcpy(zBuf, &wsdPrng.out[wsdPrng.n-N], N);
32492
+ wsdPrng.n -= N;
32493
+ break;
32494
+ }
32495
+ if( wsdPrng.n>0 ){
32496
+ memcpy(zBuf, wsdPrng.out, wsdPrng.n);
32497
+ N -= wsdPrng.n;
32498
+ zBuf += wsdPrng.n;
32499
+ }
32500
+ wsdPrng.s[12]++;
32501
+ chacha_block((u32*)wsdPrng.out, wsdPrng.s);
32502
+ wsdPrng.n = 64;
32503
+ }
3242332504
sqlite3_mutex_leave(mutex);
3242432505
}
3242532506
3242632507
#ifndef SQLITE_UNTESTABLE
3242732508
/*
@@ -33457,11 +33538,11 @@
3345733538
SQLITE_PRIVATE void sqlite3ErrorMsg(Parse *pParse, const char *zFormat, ...){
3345833539
char *zMsg;
3345933540
va_list ap;
3346033541
sqlite3 *db = pParse->db;
3346133542
assert( db!=0 );
33462
- assert( db->pParse==pParse );
33543
+ assert( db->pParse==pParse || db->pParse->pToplevel==pParse );
3346333544
db->errByteOffset = -2;
3346433545
va_start(ap, zFormat);
3346533546
zMsg = sqlite3VMPrintf(db, zFormat, ap);
3346633547
va_end(ap);
3346733548
if( db->errByteOffset<-1 ) db->errByteOffset = -1;
@@ -35275,67 +35356,67 @@
3527535356
/* 3 */ "Checkpoint" OpHelp(""),
3527635357
/* 4 */ "JournalMode" OpHelp(""),
3527735358
/* 5 */ "Vacuum" OpHelp(""),
3527835359
/* 6 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"),
3527935360
/* 7 */ "VUpdate" OpHelp("data=r[P3@P2]"),
35280
- /* 8 */ "Goto" OpHelp(""),
35281
- /* 9 */ "Gosub" OpHelp(""),
35282
- /* 10 */ "InitCoroutine" OpHelp(""),
35283
- /* 11 */ "Yield" OpHelp(""),
35284
- /* 12 */ "MustBeInt" OpHelp(""),
35285
- /* 13 */ "Jump" OpHelp(""),
35286
- /* 14 */ "Once" OpHelp(""),
35287
- /* 15 */ "If" OpHelp(""),
35288
- /* 16 */ "IfNot" OpHelp(""),
35289
- /* 17 */ "IsNullOrType" OpHelp("if typeof(r[P1]) IN (P3,5) goto P2"),
35290
- /* 18 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
35361
+ /* 8 */ "Init" OpHelp("Start at P2"),
35362
+ /* 9 */ "Goto" OpHelp(""),
35363
+ /* 10 */ "Gosub" OpHelp(""),
35364
+ /* 11 */ "InitCoroutine" OpHelp(""),
35365
+ /* 12 */ "Yield" OpHelp(""),
35366
+ /* 13 */ "MustBeInt" OpHelp(""),
35367
+ /* 14 */ "Jump" OpHelp(""),
35368
+ /* 15 */ "Once" OpHelp(""),
35369
+ /* 16 */ "If" OpHelp(""),
35370
+ /* 17 */ "IfNot" OpHelp(""),
35371
+ /* 18 */ "IsNullOrType" OpHelp("if typeof(r[P1]) IN (P3,5) goto P2"),
3529135372
/* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
35292
- /* 20 */ "SeekLT" OpHelp("key=r[P3@P4]"),
35293
- /* 21 */ "SeekLE" OpHelp("key=r[P3@P4]"),
35294
- /* 22 */ "SeekGE" OpHelp("key=r[P3@P4]"),
35295
- /* 23 */ "SeekGT" OpHelp("key=r[P3@P4]"),
35296
- /* 24 */ "IfNotOpen" OpHelp("if( !csr[P1] ) goto P2"),
35297
- /* 25 */ "IfNoHope" OpHelp("key=r[P3@P4]"),
35298
- /* 26 */ "NoConflict" OpHelp("key=r[P3@P4]"),
35299
- /* 27 */ "NotFound" OpHelp("key=r[P3@P4]"),
35300
- /* 28 */ "Found" OpHelp("key=r[P3@P4]"),
35301
- /* 29 */ "SeekRowid" OpHelp("intkey=r[P3]"),
35302
- /* 30 */ "NotExists" OpHelp("intkey=r[P3]"),
35303
- /* 31 */ "Last" OpHelp(""),
35304
- /* 32 */ "IfSmaller" OpHelp(""),
35305
- /* 33 */ "SorterSort" OpHelp(""),
35306
- /* 34 */ "Sort" OpHelp(""),
35307
- /* 35 */ "Rewind" OpHelp(""),
35308
- /* 36 */ "SorterNext" OpHelp(""),
35309
- /* 37 */ "Prev" OpHelp(""),
35310
- /* 38 */ "Next" OpHelp(""),
35311
- /* 39 */ "IdxLE" OpHelp("key=r[P3@P4]"),
35312
- /* 40 */ "IdxGT" OpHelp("key=r[P3@P4]"),
35313
- /* 41 */ "IdxLT" OpHelp("key=r[P3@P4]"),
35314
- /* 42 */ "IdxGE" OpHelp("key=r[P3@P4]"),
35373
+ /* 20 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
35374
+ /* 21 */ "SeekLT" OpHelp("key=r[P3@P4]"),
35375
+ /* 22 */ "SeekLE" OpHelp("key=r[P3@P4]"),
35376
+ /* 23 */ "SeekGE" OpHelp("key=r[P3@P4]"),
35377
+ /* 24 */ "SeekGT" OpHelp("key=r[P3@P4]"),
35378
+ /* 25 */ "IfNotOpen" OpHelp("if( !csr[P1] ) goto P2"),
35379
+ /* 26 */ "IfNoHope" OpHelp("key=r[P3@P4]"),
35380
+ /* 27 */ "NoConflict" OpHelp("key=r[P3@P4]"),
35381
+ /* 28 */ "NotFound" OpHelp("key=r[P3@P4]"),
35382
+ /* 29 */ "Found" OpHelp("key=r[P3@P4]"),
35383
+ /* 30 */ "SeekRowid" OpHelp("intkey=r[P3]"),
35384
+ /* 31 */ "NotExists" OpHelp("intkey=r[P3]"),
35385
+ /* 32 */ "Last" OpHelp(""),
35386
+ /* 33 */ "IfSmaller" OpHelp(""),
35387
+ /* 34 */ "SorterSort" OpHelp(""),
35388
+ /* 35 */ "Sort" OpHelp(""),
35389
+ /* 36 */ "Rewind" OpHelp(""),
35390
+ /* 37 */ "SorterNext" OpHelp(""),
35391
+ /* 38 */ "Prev" OpHelp(""),
35392
+ /* 39 */ "Next" OpHelp(""),
35393
+ /* 40 */ "IdxLE" OpHelp("key=r[P3@P4]"),
35394
+ /* 41 */ "IdxGT" OpHelp("key=r[P3@P4]"),
35395
+ /* 42 */ "IdxLT" OpHelp("key=r[P3@P4]"),
3531535396
/* 43 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
3531635397
/* 44 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
35317
- /* 45 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
35318
- /* 46 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
35319
- /* 47 */ "Program" OpHelp(""),
35320
- /* 48 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
35321
- /* 49 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
35398
+ /* 45 */ "IdxGE" OpHelp("key=r[P3@P4]"),
35399
+ /* 46 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
35400
+ /* 47 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
35401
+ /* 48 */ "Program" OpHelp(""),
35402
+ /* 49 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
3532235403
/* 50 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
3532335404
/* 51 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
3532435405
/* 52 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
3532535406
/* 53 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
3532635407
/* 54 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
3532735408
/* 55 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
3532835409
/* 56 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
3532935410
/* 57 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
3533035411
/* 58 */ "ElseEq" OpHelp(""),
35331
- /* 59 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
35332
- /* 60 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
35333
- /* 61 */ "IncrVacuum" OpHelp(""),
35334
- /* 62 */ "VNext" OpHelp(""),
35335
- /* 63 */ "Filter" OpHelp("if key(P3@P4) not in filter(P1) goto P2"),
35336
- /* 64 */ "Init" OpHelp("Start at P2"),
35412
+ /* 59 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
35413
+ /* 60 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
35414
+ /* 61 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
35415
+ /* 62 */ "IncrVacuum" OpHelp(""),
35416
+ /* 63 */ "VNext" OpHelp(""),
35417
+ /* 64 */ "Filter" OpHelp("if key(P3@P4) not in filter(P1) goto P2"),
3533735418
/* 65 */ "PureFunc" OpHelp("r[P3]=func(r[P2@NP])"),
3533835419
/* 66 */ "Function" OpHelp("r[P3]=func(r[P2@NP])"),
3533935420
/* 67 */ "Return" OpHelp(""),
3534035421
/* 68 */ "EndCoroutine" OpHelp(""),
3534135422
/* 69 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
@@ -41318,30 +41399,39 @@
4131841399
** pVfs->mxPathname bytes.
4131941400
*/
4132041401
static int unixGetTempname(int nBuf, char *zBuf){
4132141402
const char *zDir;
4132241403
int iLimit = 0;
41404
+ int rc = SQLITE_OK;
4132341405
4132441406
/* It's odd to simulate an io-error here, but really this is just
4132541407
** using the io-error infrastructure to test that SQLite handles this
4132641408
** function failing.
4132741409
*/
4132841410
zBuf[0] = 0;
4132941411
SimulateIOError( return SQLITE_IOERR );
4133041412
41413
+ sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
4133141414
zDir = unixTempFileDir();
41332
- if( zDir==0 ) return SQLITE_IOERR_GETTEMPPATH;
41333
- do{
41334
- u64 r;
41335
- sqlite3_randomness(sizeof(r), &r);
41336
- assert( nBuf>2 );
41337
- zBuf[nBuf-2] = 0;
41338
- sqlite3_snprintf(nBuf, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX"%llx%c",
41339
- zDir, r, 0);
41340
- if( zBuf[nBuf-2]!=0 || (iLimit++)>10 ) return SQLITE_ERROR;
41341
- }while( osAccess(zBuf,0)==0 );
41342
- return SQLITE_OK;
41415
+ if( zDir==0 ){
41416
+ rc = SQLITE_IOERR_GETTEMPPATH;
41417
+ }else{
41418
+ do{
41419
+ u64 r;
41420
+ sqlite3_randomness(sizeof(r), &r);
41421
+ assert( nBuf>2 );
41422
+ zBuf[nBuf-2] = 0;
41423
+ sqlite3_snprintf(nBuf, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX"%llx%c",
41424
+ zDir, r, 0);
41425
+ if( zBuf[nBuf-2]!=0 || (iLimit++)>10 ){
41426
+ rc = SQLITE_ERROR;
41427
+ break;
41428
+ }
41429
+ }while( osAccess(zBuf,0)==0 );
41430
+ }
41431
+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
41432
+ return rc;
4134341433
}
4134441434
4134541435
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
4134641436
/*
4134741437
** Routine to transform a unixFile into a proxy-locking unixFile.
@@ -43512,11 +43602,16 @@
4351243602
** correctly. See ticket [bb3a86e890c8e96ab] */
4351343603
assert( ArraySize(aSyscall)==29 );
4351443604
4351543605
/* Register all VFSes defined in the aVfs[] array */
4351643606
for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){
43607
+#ifdef SQLITE_DEFAULT_UNIX_VFS
43608
+ sqlite3_vfs_register(&aVfs[i],
43609
+ 0==strcmp(aVfs[i].zName,SQLITE_DEFAULT_UNIX_VFS));
43610
+#else
4351743611
sqlite3_vfs_register(&aVfs[i], i==0);
43612
+#endif
4351843613
}
4351943614
unixBigLock = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
4352043615
4352143616
#ifndef SQLITE_OMIT_WAL
4352243617
/* Validate lock assumptions */
@@ -45480,10 +45575,11 @@
4548045575
char **ppDirectory = 0;
4548145576
#ifndef SQLITE_OMIT_AUTOINIT
4548245577
int rc = sqlite3_initialize();
4548345578
if( rc ) return rc;
4548445579
#endif
45580
+ sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
4548545581
if( type==SQLITE_WIN32_DATA_DIRECTORY_TYPE ){
4548645582
ppDirectory = &sqlite3_data_directory;
4548745583
}else if( type==SQLITE_WIN32_TEMP_DIRECTORY_TYPE ){
4548845584
ppDirectory = &sqlite3_temp_directory;
4548945585
}
@@ -45494,18 +45590,23 @@
4549445590
if( ppDirectory ){
4549545591
char *zCopy = 0;
4549645592
if( zValue && zValue[0] ){
4549745593
zCopy = sqlite3_mprintf("%s", zValue);
4549845594
if ( zCopy==0 ){
45499
- return SQLITE_NOMEM_BKPT;
45595
+ rc = SQLITE_NOMEM_BKPT;
45596
+ goto set_directory8_done;
4550045597
}
4550145598
}
4550245599
sqlite3_free(*ppDirectory);
4550345600
*ppDirectory = zCopy;
45504
- return SQLITE_OK;
45601
+ rc = SQLITE_OK;
45602
+ }else{
45603
+ rc = SQLITE_ERROR;
4550545604
}
45506
- return SQLITE_ERROR;
45605
+set_directory8_done:
45606
+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
45607
+ return rc;
4550745608
}
4550845609
4550945610
/*
4551045611
** This function is the same as sqlite3_win32_set_directory (below); however,
4551145612
** it accepts a UTF-16 string.
@@ -48274,10 +48375,22 @@
4827448375
}
4827548376
}
4827648377
}
4827748378
return 0;
4827848379
}
48380
+
48381
+/*
48382
+** If sqlite3_temp_directory is not, take the mutex and return true.
48383
+**
48384
+** If sqlite3_temp_directory is NULL, omit the mutex and return false.
48385
+*/
48386
+static int winTempDirDefined(void){
48387
+ sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
48388
+ if( sqlite3_temp_directory!=0 ) return 1;
48389
+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
48390
+ return 0;
48391
+}
4827948392
4828048393
/*
4828148394
** Create a temporary file name and store the resulting pointer into pzBuf.
4828248395
** The pointer returned in pzBuf must be freed via sqlite3_free().
4828348396
*/
@@ -48311,24 +48424,27 @@
4831148424
** has been explicitly set by the application; otherwise, use the one
4831248425
** configured by the operating system.
4831348426
*/
4831448427
nDir = nMax - (nPre + 15);
4831548428
assert( nDir>0 );
48316
- if( sqlite3_temp_directory ){
48429
+ if( winTempDirDefined() ){
4831748430
int nDirLen = sqlite3Strlen30(sqlite3_temp_directory);
4831848431
if( nDirLen>0 ){
4831948432
if( !winIsDirSep(sqlite3_temp_directory[nDirLen-1]) ){
4832048433
nDirLen++;
4832148434
}
4832248435
if( nDirLen>nDir ){
48436
+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
4832348437
sqlite3_free(zBuf);
4832448438
OSTRACE(("TEMP-FILENAME rc=SQLITE_ERROR\n"));
4832548439
return winLogError(SQLITE_ERROR, 0, "winGetTempname1", 0);
4832648440
}
4832748441
sqlite3_snprintf(nMax, zBuf, "%s", sqlite3_temp_directory);
4832848442
}
48443
+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
4832948444
}
48445
+
4833048446
#if defined(__CYGWIN__)
4833148447
else{
4833248448
static const char *azDirs[] = {
4833348449
0, /* getenv("SQLITE_TMPDIR") */
4833448450
0, /* getenv("TMPDIR") */
@@ -49113,11 +49229,11 @@
4911349229
/*
4911449230
** Turn a relative pathname into a full pathname. Write the full
4911549231
** pathname into zOut[]. zOut[] will be at least pVfs->mxPathname
4911649232
** bytes in size.
4911749233
*/
49118
-static int winFullPathname(
49234
+static int winFullPathnameNoMutex(
4911949235
sqlite3_vfs *pVfs, /* Pointer to vfs object */
4912049236
const char *zRelative, /* Possibly relative input path */
4912149237
int nFull, /* Size of output buffer in bytes */
4912249238
char *zFull /* Output buffer */
4912349239
){
@@ -49291,10 +49407,23 @@
4929149407
return SQLITE_OK;
4929249408
}else{
4929349409
return SQLITE_IOERR_NOMEM_BKPT;
4929449410
}
4929549411
#endif
49412
+}
49413
+static int winFullPathname(
49414
+ sqlite3_vfs *pVfs, /* Pointer to vfs object */
49415
+ const char *zRelative, /* Possibly relative input path */
49416
+ int nFull, /* Size of output buffer in bytes */
49417
+ char *zFull /* Output buffer */
49418
+){
49419
+ int rc;
49420
+ sqlite3_mutex *pMutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR);
49421
+ sqlite3_mutex_enter(pMutex);
49422
+ rc = winFullPathnameNoMutex(pVfs, zRelative, nFull, zFull);
49423
+ sqlite3_mutex_leave(pMutex);
49424
+ return rc;
4929649425
}
4929749426
4929849427
#ifndef SQLITE_OMIT_LOAD_EXTENSION
4929949428
/*
4930049429
** Interfaces for opening a shared library, finding entry points
@@ -51080,39 +51209,58 @@
5108051209
*/
5108151210
#if defined(SQLITE_DEBUG) && 0
5108251211
int sqlite3PcacheTrace = 2; /* 0: off 1: simple 2: cache dumps */
5108351212
int sqlite3PcacheMxDump = 9999; /* Max cache entries for pcacheDump() */
5108451213
# define pcacheTrace(X) if(sqlite3PcacheTrace){sqlite3DebugPrintf X;}
51085
- void pcacheDump(PCache *pCache){
51086
- int N;
51087
- int i, j;
51088
- sqlite3_pcache_page *pLower;
51214
+ static void pcachePageTrace(int i, sqlite3_pcache_page *pLower){
5108951215
PgHdr *pPg;
5109051216
unsigned char *a;
51217
+ int j;
51218
+ pPg = (PgHdr*)pLower->pExtra;
51219
+ printf("%3d: nRef %2d flgs %02x data ", i, pPg->nRef, pPg->flags);
51220
+ a = (unsigned char *)pLower->pBuf;
51221
+ for(j=0; j<12; j++) printf("%02x", a[j]);
51222
+ printf(" ptr %p\n", pPg);
51223
+ }
51224
+ static void pcacheDump(PCache *pCache){
51225
+ int N;
51226
+ int i;
51227
+ sqlite3_pcache_page *pLower;
5109151228
5109251229
if( sqlite3PcacheTrace<2 ) return;
5109351230
if( pCache->pCache==0 ) return;
5109451231
N = sqlite3PcachePagecount(pCache);
5109551232
if( N>sqlite3PcacheMxDump ) N = sqlite3PcacheMxDump;
5109651233
for(i=1; i<=N; i++){
5109751234
pLower = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, i, 0);
5109851235
if( pLower==0 ) continue;
51099
- pPg = (PgHdr*)pLower->pExtra;
51100
- printf("%3d: nRef %2d flgs %02x data ", i, pPg->nRef, pPg->flags);
51101
- a = (unsigned char *)pLower->pBuf;
51102
- for(j=0; j<12; j++) printf("%02x", a[j]);
51103
- printf("\n");
51104
- if( pPg->pPage==0 ){
51236
+ pcachePageTrace(i, pLower);
51237
+ if( ((PgHdr*)pLower)->pPage==0 ){
5110551238
sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pLower, 0);
5110651239
}
5110751240
}
5110851241
}
51109
- #else
51242
+#else
5111051243
# define pcacheTrace(X)
51244
+# define pcachePageTrace(PGNO, X)
5111151245
# define pcacheDump(X)
5111251246
#endif
5111351247
51248
+/*
51249
+** Return 1 if pPg is on the dirty list for pCache. Return 0 if not.
51250
+** This routine runs inside of assert() statements only.
51251
+*/
51252
+#ifdef SQLITE_DEBUG
51253
+static int pageOnDirtyList(PCache *pCache, PgHdr *pPg){
51254
+ PgHdr *p;
51255
+ for(p=pCache->pDirty; p; p=p->pDirtyNext){
51256
+ if( p==pPg ) return 1;
51257
+ }
51258
+ return 0;
51259
+}
51260
+#endif
51261
+
5111451262
/*
5111551263
** Check invariants on a PgHdr entry. Return true if everything is OK.
5111651264
** Return false if any invariant is violated.
5111751265
**
5111851266
** This routine is for use inside of assert() statements only. For
@@ -51127,12 +51275,17 @@
5112751275
assert( pPg->pgno>0 || pPg->pPager==0 ); /* Page number is 1 or more */
5112851276
pCache = pPg->pCache;
5112951277
assert( pCache!=0 ); /* Every page has an associated PCache */
5113051278
if( pPg->flags & PGHDR_CLEAN ){
5113151279
assert( (pPg->flags & PGHDR_DIRTY)==0 );/* Cannot be both CLEAN and DIRTY */
51132
- assert( pCache->pDirty!=pPg ); /* CLEAN pages not on dirty list */
51133
- assert( pCache->pDirtyTail!=pPg );
51280
+ assert( !pageOnDirtyList(pCache, pPg) );/* CLEAN pages not on dirty list */
51281
+ }else{
51282
+ assert( (pPg->flags & PGHDR_DIRTY)!=0 );/* If not CLEAN must be DIRTY */
51283
+ assert( pPg->pDirtyNext==0 || pPg->pDirtyNext->pDirtyPrev==pPg );
51284
+ assert( pPg->pDirtyPrev==0 || pPg->pDirtyPrev->pDirtyNext==pPg );
51285
+ assert( pPg->pDirtyPrev!=0 || pCache->pDirty==pPg );
51286
+ assert( pageOnDirtyList(pCache, pPg) );
5113451287
}
5113551288
/* WRITEABLE pages must also be DIRTY */
5113651289
if( pPg->flags & PGHDR_WRITEABLE ){
5113751290
assert( pPg->flags & PGHDR_DIRTY ); /* WRITEABLE implies DIRTY */
5113851291
}
@@ -51402,12 +51555,13 @@
5140251555
eCreate = createFlag & pCache->eCreate;
5140351556
assert( eCreate==0 || eCreate==1 || eCreate==2 );
5140451557
assert( createFlag==0 || pCache->eCreate==eCreate );
5140551558
assert( createFlag==0 || eCreate==1+(!pCache->bPurgeable||!pCache->pDirty) );
5140651559
pRes = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
51407
- pcacheTrace(("%p.FETCH %d%s (result: %p)\n",pCache,pgno,
51560
+ pcacheTrace(("%p.FETCH %d%s (result: %p) ",pCache,pgno,
5140851561
createFlag?" create":"",pRes));
51562
+ pcachePageTrace(pgno, pRes);
5140951563
return pRes;
5141051564
}
5141151565
5141251566
/*
5141351567
** If the sqlite3PcacheFetch() routine is unable to allocate a new
@@ -51531,10 +51685,11 @@
5153151685
if( (--p->nRef)==0 ){
5153251686
if( p->flags&PGHDR_CLEAN ){
5153351687
pcacheUnpin(p);
5153451688
}else{
5153551689
pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
51690
+ assert( sqlite3PcachePageSanity(p) );
5153651691
}
5153751692
}
5153851693
}
5153951694
5154051695
/*
@@ -51574,10 +51729,11 @@
5157451729
if( p->flags & PGHDR_CLEAN ){
5157551730
p->flags ^= (PGHDR_DIRTY|PGHDR_CLEAN);
5157651731
pcacheTrace(("%p.DIRTY %d\n",p->pCache,p->pgno));
5157751732
assert( (p->flags & (PGHDR_DIRTY|PGHDR_CLEAN))==PGHDR_DIRTY );
5157851733
pcacheManageDirtyList(p, PCACHE_DIRTYLIST_ADD);
51734
+ assert( sqlite3PcachePageSanity(p) );
5157951735
}
5158051736
assert( sqlite3PcachePageSanity(p) );
5158151737
}
5158251738
}
5158351739
@@ -51636,18 +51792,28 @@
5163651792
/*
5163751793
** Change the page number of page p to newPgno.
5163851794
*/
5163951795
SQLITE_PRIVATE void sqlite3PcacheMove(PgHdr *p, Pgno newPgno){
5164051796
PCache *pCache = p->pCache;
51797
+ sqlite3_pcache_page *pOther;
5164151798
assert( p->nRef>0 );
5164251799
assert( newPgno>0 );
5164351800
assert( sqlite3PcachePageSanity(p) );
5164451801
pcacheTrace(("%p.MOVE %d -> %d\n",pCache,p->pgno,newPgno));
51802
+ pOther = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, newPgno, 0);
5164551803
sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
51804
+ if( pOther ){
51805
+ PgHdr *pPg = (PgHdr*)pOther->pExtra;
51806
+ pPg->pgno = p->pgno;
51807
+ if( pPg->pPage==0 ){
51808
+ sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pOther, 0);
51809
+ }
51810
+ }
5164651811
p->pgno = newPgno;
5164751812
if( (p->flags&PGHDR_DIRTY) && (p->flags&PGHDR_NEED_SYNC) ){
5164851813
pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
51814
+ assert( sqlite3PcachePageSanity(p) );
5164951815
}
5165051816
}
5165151817
5165251818
/*
5165351819
** Drop every cache entry whose page number is greater than "pgno". The
@@ -51941,16 +52107,17 @@
5194152107
** runtime using sqlite3_config(SQLITE_CONFIG_PCACHE_HDRSZ, &size). The
5194252108
** sizes of the extensions sum to 272 bytes on x64 for 3.8.10, but this
5194352109
** size can vary according to architecture, compile-time options, and
5194452110
** SQLite library version number.
5194552111
**
51946
-** If SQLITE_PCACHE_SEPARATE_HEADER is defined, then the extension is obtained
51947
-** using a separate memory allocation from the database page content. This
51948
-** seeks to overcome the "clownshoe" problem (also called "internal
51949
-** fragmentation" in academic literature) of allocating a few bytes more
51950
-** than a power of two with the memory allocator rounding up to the next
51951
-** power of two, and leaving the rounded-up space unused.
52112
+** Historical note: It used to be that if the SQLITE_PCACHE_SEPARATE_HEADER
52113
+** was defined, then the page content would be held in a separate memory
52114
+** allocation from the PgHdr1. This was intended to avoid clownshoe memory
52115
+** allocations. However, the btree layer needs a small (16-byte) overrun
52116
+** area after the page content buffer. The header serves as that overrun
52117
+** area. Therefore SQLITE_PCACHE_SEPARATE_HEADER was discontinued to avoid
52118
+** any possibility of a memory error.
5195252119
**
5195352120
** This module tracks pointers to PgHdr1 objects. Only pcache.c communicates
5195452121
** with this module. Information is passed back and forth as PgHdr1 pointers.
5195552122
**
5195652123
** The pcache.c and pager.c modules deal pointers to PgHdr objects.
@@ -51991,34 +52158,44 @@
5199152158
typedef struct PgFreeslot PgFreeslot;
5199252159
typedef struct PGroup PGroup;
5199352160
5199452161
/*
5199552162
** Each cache entry is represented by an instance of the following
51996
-** structure. Unless SQLITE_PCACHE_SEPARATE_HEADER is defined, a buffer of
51997
-** PgHdr1.pCache->szPage bytes is allocated directly before this structure
51998
-** in memory.
52163
+** structure. A buffer of PgHdr1.pCache->szPage bytes is allocated
52164
+** directly before this structure and is used to cache the page content.
5199952165
**
52000
-** Note: Variables isBulkLocal and isAnchor were once type "u8". That works,
52166
+** When reading a corrupt database file, it is possible that SQLite might
52167
+** read a few bytes (no more than 16 bytes) past the end of the page buffer.
52168
+** It will only read past the end of the page buffer, never write. This
52169
+** object is positioned immediately after the page buffer to serve as an
52170
+** overrun area, so that overreads are harmless.
52171
+**
52172
+** Variables isBulkLocal and isAnchor were once type "u8". That works,
5200152173
** but causes a 2-byte gap in the structure for most architectures (since
5200252174
** pointers must be either 4 or 8-byte aligned). As this structure is located
5200352175
** in memory directly after the associated page data, if the database is
5200452176
** corrupt, code at the b-tree layer may overread the page buffer and
5200552177
** read part of this structure before the corruption is detected. This
5200652178
** can cause a valgrind error if the unitialized gap is accessed. Using u16
52007
-** ensures there is no such gap, and therefore no bytes of unitialized memory
52008
-** in the structure.
52179
+** ensures there is no such gap, and therefore no bytes of uninitialized
52180
+** memory in the structure.
52181
+**
52182
+** The pLruNext and pLruPrev pointers form a double-linked circular list
52183
+** of all pages that are unpinned. The PGroup.lru element (which should be
52184
+** the only element on the list with PgHdr1.isAnchor set to 1) forms the
52185
+** beginning and the end of the list.
5200952186
*/
5201052187
struct PgHdr1 {
52011
- sqlite3_pcache_page page; /* Base class. Must be first. pBuf & pExtra */
52012
- unsigned int iKey; /* Key value (page number) */
52013
- u16 isBulkLocal; /* This page from bulk local storage */
52014
- u16 isAnchor; /* This is the PGroup.lru element */
52015
- PgHdr1 *pNext; /* Next in hash table chain */
52016
- PCache1 *pCache; /* Cache that currently owns this page */
52017
- PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
52018
- PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
52019
- /* NB: pLruPrev is only valid if pLruNext!=0 */
52188
+ sqlite3_pcache_page page; /* Base class. Must be first. pBuf & pExtra */
52189
+ unsigned int iKey; /* Key value (page number) */
52190
+ u16 isBulkLocal; /* This page from bulk local storage */
52191
+ u16 isAnchor; /* This is the PGroup.lru element */
52192
+ PgHdr1 *pNext; /* Next in hash table chain */
52193
+ PCache1 *pCache; /* Cache that currently owns this page */
52194
+ PgHdr1 *pLruNext; /* Next in circular LRU list of unpinned pages */
52195
+ PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
52196
+ /* NB: pLruPrev is only valid if pLruNext!=0 */
5202052197
};
5202152198
5202252199
/*
5202352200
** A page is pinned if it is not on the LRU list. To be "pinned" means
5202452201
** that the page is in active use and must not be deallocated.
@@ -52340,29 +52517,17 @@
5234052517
assert( pcache1.separateCache==0 );
5234152518
assert( pCache->pGroup==&pcache1.grp );
5234252519
pcache1LeaveMutex(pCache->pGroup);
5234352520
#endif
5234452521
if( benignMalloc ){ sqlite3BeginBenignMalloc(); }
52345
-#ifdef SQLITE_PCACHE_SEPARATE_HEADER
52346
- pPg = pcache1Alloc(pCache->szPage);
52347
- p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);
52348
- if( !pPg || !p ){
52349
- pcache1Free(pPg);
52350
- sqlite3_free(p);
52351
- pPg = 0;
52352
- }
52353
-#else
5235452522
pPg = pcache1Alloc(pCache->szAlloc);
52355
-#endif
5235652523
if( benignMalloc ){ sqlite3EndBenignMalloc(); }
5235752524
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
5235852525
pcache1EnterMutex(pCache->pGroup);
5235952526
#endif
5236052527
if( pPg==0 ) return 0;
52361
-#ifndef SQLITE_PCACHE_SEPARATE_HEADER
5236252528
p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
52363
-#endif
5236452529
p->page.pBuf = pPg;
5236552530
p->page.pExtra = &p[1];
5236652531
p->isBulkLocal = 0;
5236752532
p->isAnchor = 0;
5236852533
p->pLruPrev = 0; /* Initializing this saves a valgrind error */
@@ -52382,13 +52547,10 @@
5238252547
if( p->isBulkLocal ){
5238352548
p->pNext = pCache->pFree;
5238452549
pCache->pFree = p;
5238552550
}else{
5238652551
pcache1Free(p->page.pBuf);
52387
-#ifdef SQLITE_PCACHE_SEPARATE_HEADER
52388
- sqlite3_free(p);
52389
-#endif
5239052552
}
5239152553
(*pCache->pnPurgeable)--;
5239252554
}
5239352555
5239452556
/*
@@ -53025,27 +53187,45 @@
5302553187
unsigned int iNew
5302653188
){
5302753189
PCache1 *pCache = (PCache1 *)p;
5302853190
PgHdr1 *pPage = (PgHdr1 *)pPg;
5302953191
PgHdr1 **pp;
53030
- unsigned int h;
53192
+ unsigned int hOld, hNew;
5303153193
assert( pPage->iKey==iOld );
5303253194
assert( pPage->pCache==pCache );
53195
+ assert( iOld!=iNew ); /* The page number really is changing */
5303353196
5303453197
pcache1EnterMutex(pCache->pGroup);
5303553198
53036
- h = iOld%pCache->nHash;
53037
- pp = &pCache->apHash[h];
53199
+ assert( pcache1FetchNoMutex(p, iOld, 0)==pPage ); /* pPg really is iOld */
53200
+ hOld = iOld%pCache->nHash;
53201
+ pp = &pCache->apHash[hOld];
5303853202
while( (*pp)!=pPage ){
5303953203
pp = &(*pp)->pNext;
5304053204
}
5304153205
*pp = pPage->pNext;
5304253206
53043
- h = iNew%pCache->nHash;
53207
+ hNew = iNew%pCache->nHash;
53208
+ pp = &pCache->apHash[hNew];
53209
+ while( *pp ){
53210
+ if( (*pp)->iKey==iNew ){
53211
+ /* If there is already another pcache entry at iNew, change it to iOld,
53212
+ ** thus swapping the positions of iNew and iOld */
53213
+ PgHdr1 *pOld = *pp;
53214
+ *pp = pOld->pNext;
53215
+ pOld->pNext = pCache->apHash[hOld];
53216
+ pCache->apHash[hOld] = pOld;
53217
+ pOld->iKey = iOld;
53218
+ break;
53219
+ }else{
53220
+ pp = &(*pp)->pNext;
53221
+ }
53222
+ }
53223
+
5304453224
pPage->iKey = iNew;
53045
- pPage->pNext = pCache->apHash[h];
53046
- pCache->apHash[h] = pPage;
53225
+ pPage->pNext = pCache->apHash[hNew];
53226
+ pCache->apHash[hNew] = pPage;
5304753227
if( iNew>pCache->iMaxKey ){
5304853228
pCache->iMaxKey = iNew;
5304953229
}
5305053230
5305153231
pcache1LeaveMutex(pCache->pGroup);
@@ -53148,13 +53328,10 @@
5314853328
while( (nReq<0 || nFree<nReq)
5314953329
&& (p=pcache1.grp.lru.pLruPrev)!=0
5315053330
&& p->isAnchor==0
5315153331
){
5315253332
nFree += pcache1MemSize(p->page.pBuf);
53153
-#ifdef SQLITE_PCACHE_SEPARATE_HEADER
53154
- nFree += sqlite3MemSize(p);
53155
-#endif
5315653333
assert( PAGE_IS_UNPINNED(p) );
5315753334
pcache1PinPage(p);
5315853335
pcache1RemoveFromHash(p, 1);
5315953336
}
5316053337
pcache1LeaveMutex(&pcache1.grp);
@@ -59639,10 +59816,11 @@
5963959816
int flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
5964059817
int nSpill;
5964159818
5964259819
if( pPager->tempFile ){
5964359820
flags |= (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL);
59821
+ flags |= SQLITE_OPEN_EXCLUSIVE;
5964459822
nSpill = sqlite3Config.nStmtSpill;
5964559823
}else{
5964659824
flags |= SQLITE_OPEN_MAIN_JOURNAL;
5964759825
nSpill = jrnlBufferSize(pPager);
5964859826
}
@@ -59674,10 +59852,11 @@
5967459852
}
5967559853
5967659854
if( rc!=SQLITE_OK ){
5967759855
sqlite3BitvecDestroy(pPager->pInJournal);
5967859856
pPager->pInJournal = 0;
59857
+ pPager->journalOff = 0;
5967959858
}else{
5968059859
assert( pPager->eState==PAGER_WRITER_LOCKED );
5968159860
pPager->eState = PAGER_WRITER_CACHEMOD;
5968259861
}
5968359862
@@ -66737,10 +66916,11 @@
6673766916
** db using sqlite3SchemaToIndex().
6673866917
*/
6673966918
SQLITE_PRIVATE int sqlite3SchemaMutexHeld(sqlite3 *db, int iDb, Schema *pSchema){
6674066919
Btree *p;
6674166920
assert( db!=0 );
66921
+ if( db->pVfs==0 && db->nDb==0 ) return 1;
6674266922
if( pSchema ) iDb = sqlite3SchemaToIndex(db, pSchema);
6674366923
assert( iDb>=0 && iDb<db->nDb );
6674466924
if( !sqlite3_mutex_held(db->mutex) ) return 0;
6674566925
if( iDb==1 ) return 1;
6674666926
p = db->aDb[iDb].pBt;
@@ -68309,12 +68489,11 @@
6830968489
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
6831068490
assert( pPage->pBt!=0 );
6831168491
assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
6831268492
assert( pPage->nOverflow==0 );
6831368493
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
68314
- temp = 0;
68315
- src = data = pPage->aData;
68494
+ data = pPage->aData;
6831668495
hdr = pPage->hdrOffset;
6831768496
cellOffset = pPage->cellOffset;
6831868497
nCell = pPage->nCell;
6831968498
assert( nCell==get2byte(&data[hdr+3]) || CORRUPT_DB );
6832068499
iCellFirst = cellOffset + 2*nCell;
@@ -68364,43 +68543,42 @@
6836468543
}
6836568544
6836668545
cbrk = usableSize;
6836768546
iCellLast = usableSize - 4;
6836868547
iCellStart = get2byte(&data[hdr+5]);
68369
- for(i=0; i<nCell; i++){
68370
- u8 *pAddr; /* The i-th cell pointer */
68371
- pAddr = &data[cellOffset + i*2];
68372
- pc = get2byte(pAddr);
68373
- testcase( pc==iCellFirst );
68374
- testcase( pc==iCellLast );
68375
- /* These conditions have already been verified in btreeInitPage()
68376
- ** if PRAGMA cell_size_check=ON.
68377
- */
68378
- if( pc<iCellStart || pc>iCellLast ){
68379
- return SQLITE_CORRUPT_PAGE(pPage);
68380
- }
68381
- assert( pc>=iCellStart && pc<=iCellLast );
68382
- size = pPage->xCellSize(pPage, &src[pc]);
68383
- cbrk -= size;
68384
- if( cbrk<iCellStart || pc+size>usableSize ){
68385
- return SQLITE_CORRUPT_PAGE(pPage);
68386
- }
68387
- assert( cbrk+size<=usableSize && cbrk>=iCellStart );
68388
- testcase( cbrk+size==usableSize );
68389
- testcase( pc+size==usableSize );
68390
- put2byte(pAddr, cbrk);
68391
- if( temp==0 ){
68392
- if( cbrk==pc ) continue;
68393
- temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
68394
- memcpy(&temp[iCellStart], &data[iCellStart], usableSize - iCellStart);
68395
- src = temp;
68396
- }
68397
- memcpy(&data[cbrk], &src[pc], size);
68548
+ if( nCell>0 ){
68549
+ temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
68550
+ memcpy(&temp[iCellStart], &data[iCellStart], usableSize - iCellStart);
68551
+ src = temp;
68552
+ for(i=0; i<nCell; i++){
68553
+ u8 *pAddr; /* The i-th cell pointer */
68554
+ pAddr = &data[cellOffset + i*2];
68555
+ pc = get2byte(pAddr);
68556
+ testcase( pc==iCellFirst );
68557
+ testcase( pc==iCellLast );
68558
+ /* These conditions have already been verified in btreeInitPage()
68559
+ ** if PRAGMA cell_size_check=ON.
68560
+ */
68561
+ if( pc<iCellStart || pc>iCellLast ){
68562
+ return SQLITE_CORRUPT_PAGE(pPage);
68563
+ }
68564
+ assert( pc>=iCellStart && pc<=iCellLast );
68565
+ size = pPage->xCellSize(pPage, &src[pc]);
68566
+ cbrk -= size;
68567
+ if( cbrk<iCellStart || pc+size>usableSize ){
68568
+ return SQLITE_CORRUPT_PAGE(pPage);
68569
+ }
68570
+ assert( cbrk+size<=usableSize && cbrk>=iCellStart );
68571
+ testcase( cbrk+size==usableSize );
68572
+ testcase( pc+size==usableSize );
68573
+ put2byte(pAddr, cbrk);
68574
+ memcpy(&data[cbrk], &src[pc], size);
68575
+ }
6839868576
}
6839968577
data[hdr+7] = 0;
6840068578
68401
- defragment_out:
68579
+defragment_out:
6840268580
assert( pPage->nFree>=0 );
6840368581
if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){
6840468582
return SQLITE_CORRUPT_PAGE(pPage);
6840568583
}
6840668584
assert( cbrk>=iCellFirst );
@@ -68469,13 +68647,13 @@
6846968647
return &aData[pc + x];
6847068648
}
6847168649
iAddr = pc;
6847268650
pTmp = &aData[pc];
6847368651
pc = get2byte(pTmp);
68474
- if( pc<=iAddr+size ){
68652
+ if( pc<=iAddr ){
6847568653
if( pc ){
68476
- /* The next slot in the chain is not past the end of the current slot */
68654
+ /* The next slot in the chain comes before the current slot */
6847768655
*pRc = SQLITE_CORRUPT_PAGE(pPg);
6847868656
}
6847968657
return 0;
6848068658
}
6848168659
}
@@ -68623,11 +68801,11 @@
6862368801
iPtr = hdr + 1;
6862468802
if( data[iPtr+1]==0 && data[iPtr]==0 ){
6862568803
iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */
6862668804
}else{
6862768805
while( (iFreeBlk = get2byte(&data[iPtr]))<iStart ){
68628
- if( iFreeBlk<iPtr+4 ){
68806
+ if( iFreeBlk<=iPtr ){
6862968807
if( iFreeBlk==0 ) break; /* TH3: corrupt082.100 */
6863068808
return SQLITE_CORRUPT_PAGE(pPage);
6863168809
}
6863268810
iPtr = iFreeBlk;
6863368811
}
@@ -69105,13 +69283,11 @@
6910569283
if( pCur ){
6910669284
pCur->iPage--;
6910769285
pCur->pPage = pCur->apPage[pCur->iPage];
6910869286
}
6910969287
testcase( pgno==0 );
69110
- assert( pgno!=0 || rc==SQLITE_CORRUPT
69111
- || rc==SQLITE_IOERR_NOMEM
69112
- || rc==SQLITE_NOMEM );
69288
+ assert( pgno!=0 || rc!=SQLITE_OK );
6911369289
return rc;
6911469290
}
6911569291
6911669292
/*
6911769293
** Release a MemPage. This should be called once for each prior
@@ -72049,12 +72225,10 @@
7204972225
** the new child page does not match the flags field of the parent (i.e.
7205072226
** if an intkey page appears to be the parent of a non-intkey page, or
7205172227
** vice-versa).
7205272228
*/
7205372229
static int moveToChild(BtCursor *pCur, u32 newPgno){
72054
- BtShared *pBt = pCur->pBt;
72055
-
7205672230
assert( cursorOwnsBtShared(pCur) );
7205772231
assert( pCur->eState==CURSOR_VALID );
7205872232
assert( pCur->iPage<BTCURSOR_MAX_DEPTH );
7205972233
assert( pCur->iPage>=0 );
7206072234
if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
@@ -72064,11 +72238,12 @@
7206472238
pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
7206572239
pCur->aiIdx[pCur->iPage] = pCur->ix;
7206672240
pCur->apPage[pCur->iPage] = pCur->pPage;
7206772241
pCur->ix = 0;
7206872242
pCur->iPage++;
72069
- return getAndInitPage(pBt, newPgno, &pCur->pPage, pCur, pCur->curPagerFlags);
72243
+ return getAndInitPage(pCur->pBt, newPgno, &pCur->pPage, pCur,
72244
+ pCur->curPagerFlags);
7207072245
}
7207172246
7207272247
#ifdef SQLITE_DEBUG
7207372248
/*
7207472249
** Page pParent is an internal (non-leaf) tree page. This function
@@ -72170,11 +72345,11 @@
7217072345
assert( pCur->skipNext!=SQLITE_OK );
7217172346
return pCur->skipNext;
7217272347
}
7217372348
sqlite3BtreeClearCursor(pCur);
7217472349
}
72175
- rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->pPage,
72350
+ rc = getAndInitPage(pCur->pBt, pCur->pgnoRoot, &pCur->pPage,
7217672351
0, pCur->curPagerFlags);
7217772352
if( rc!=SQLITE_OK ){
7217872353
pCur->eState = CURSOR_INVALID;
7217972354
return rc;
7218072355
}
@@ -73811,16 +73986,10 @@
7381173986
data = pPage->aData;
7381273987
ptr = &pPage->aCellIdx[2*idx];
7381373988
assert( pPage->pBt->usableSize > (u32)(ptr-data) );
7381473989
pc = get2byte(ptr);
7381573990
hdr = pPage->hdrOffset;
73816
-#if 0 /* Not required. Omit for efficiency */
73817
- if( pc<hdr+pPage->nCell*2 ){
73818
- *pRC = SQLITE_CORRUPT_BKPT;
73819
- return;
73820
- }
73821
-#endif
7382273991
testcase( pc==(u32)get2byte(&data[hdr+5]) );
7382373992
testcase( pc+sz==pPage->pBt->usableSize );
7382473993
if( pc+sz > pPage->pBt->usableSize ){
7382573994
*pRC = SQLITE_CORRUPT_BKPT;
7382673995
return;
@@ -74700,12 +74869,10 @@
7470074869
int szNew[NB+2]; /* Combined size of cells placed on i-th page */
7470174870
u8 *aSpace1; /* Space for copies of dividers cells */
7470274871
Pgno pgno; /* Temp var to store a page number in */
7470374872
u8 abDone[NB+2]; /* True after i'th new page is populated */
7470474873
Pgno aPgno[NB+2]; /* Page numbers of new pages before shuffling */
74705
- Pgno aPgOrder[NB+2]; /* Copy of aPgno[] used for sorting pages */
74706
- u16 aPgFlags[NB+2]; /* flags field of new pages before shuffling */
7470774874
CellArray b; /* Parsed information on cells being balanced */
7470874875
7470974876
memset(abDone, 0, sizeof(abDone));
7471074877
memset(&b, 0, sizeof(b));
7471174878
pBt = pParent->pBt;
@@ -75125,46 +75292,43 @@
7512575292
** Reassign page numbers so that the new pages are in ascending order.
7512675293
** This helps to keep entries in the disk file in order so that a scan
7512775294
** of the table is closer to a linear scan through the file. That in turn
7512875295
** helps the operating system to deliver pages from the disk more rapidly.
7512975296
**
75130
- ** An O(n^2) insertion sort algorithm is used, but since n is never more
75131
- ** than (NB+2) (a small constant), that should not be a problem.
75297
+ ** An O(N*N) sort algorithm is used, but since N is never more than NB+2
75298
+ ** (5), that is not a performance concern.
7513275299
**
7513375300
** When NB==3, this one optimization makes the database about 25% faster
7513475301
** for large insertions and deletions.
7513575302
*/
7513675303
for(i=0; i<nNew; i++){
75137
- aPgOrder[i] = aPgno[i] = apNew[i]->pgno;
75138
- aPgFlags[i] = apNew[i]->pDbPage->flags;
75139
- for(j=0; j<i; j++){
75140
- if( NEVER(aPgno[j]==aPgno[i]) ){
75141
- /* This branch is taken if the set of sibling pages somehow contains
75142
- ** duplicate entries. This can happen if the database is corrupt.
75143
- ** It would be simpler to detect this as part of the loop below, but
75144
- ** we do the detection here in order to avoid populating the pager
75145
- ** cache with two separate objects associated with the same
75146
- ** page number. */
75147
- assert( CORRUPT_DB );
75148
- rc = SQLITE_CORRUPT_BKPT;
75149
- goto balance_cleanup;
75150
- }
75151
- }
75152
- }
75153
- for(i=0; i<nNew; i++){
75154
- int iBest = 0; /* aPgno[] index of page number to use */
75155
- for(j=1; j<nNew; j++){
75156
- if( aPgOrder[j]<aPgOrder[iBest] ) iBest = j;
75157
- }
75158
- pgno = aPgOrder[iBest];
75159
- aPgOrder[iBest] = 0xffffffff;
75160
- if( iBest!=i ){
75161
- if( iBest>i ){
75162
- sqlite3PagerRekey(apNew[iBest]->pDbPage, pBt->nPage+iBest+1, 0);
75163
- }
75164
- sqlite3PagerRekey(apNew[i]->pDbPage, pgno, aPgFlags[iBest]);
75165
- apNew[i]->pgno = pgno;
75304
+ aPgno[i] = apNew[i]->pgno;
75305
+ assert( apNew[i]->pDbPage->flags & PGHDR_WRITEABLE );
75306
+ assert( apNew[i]->pDbPage->flags & PGHDR_DIRTY );
75307
+ }
75308
+ for(i=0; i<nNew-1; i++){
75309
+ int iB = i;
75310
+ for(j=i+1; j<nNew; j++){
75311
+ if( apNew[j]->pgno < apNew[iB]->pgno ) iB = j;
75312
+ }
75313
+
75314
+ /* If apNew[i] has a page number that is bigger than any of the
75315
+ ** subsequence apNew[i] entries, then swap apNew[i] with the subsequent
75316
+ ** entry that has the smallest page number (which we know to be
75317
+ ** entry apNew[iB]).
75318
+ */
75319
+ if( iB!=i ){
75320
+ Pgno pgnoA = apNew[i]->pgno;
75321
+ Pgno pgnoB = apNew[iB]->pgno;
75322
+ Pgno pgnoTemp = (PENDING_BYTE/pBt->pageSize)+1;
75323
+ u16 fgA = apNew[i]->pDbPage->flags;
75324
+ u16 fgB = apNew[iB]->pDbPage->flags;
75325
+ sqlite3PagerRekey(apNew[i]->pDbPage, pgnoTemp, fgB);
75326
+ sqlite3PagerRekey(apNew[iB]->pDbPage, pgnoA, fgA);
75327
+ sqlite3PagerRekey(apNew[i]->pDbPage, pgnoB, fgB);
75328
+ apNew[i]->pgno = pgnoB;
75329
+ apNew[iB]->pgno = pgnoA;
7516675330
}
7516775331
}
7516875332
7516975333
TRACE(("BALANCE: new: %d(%d nc=%d) %d(%d nc=%d) %d(%d nc=%d) "
7517075334
"%d(%d nc=%d) %d(%d nc=%d)\n",
@@ -79428,10 +79592,20 @@
7942879592
double r2 = (double)i;
7942979593
return r1==0.0
7943079594
|| (memcmp(&r1, &r2, sizeof(r1))==0
7943179595
&& i >= -2251799813685248LL && i < 2251799813685248LL);
7943279596
}
79597
+
79598
+/* Convert a floating point value to its closest integer. Do so in
79599
+** a way that avoids 'outside the range of representable values' warnings
79600
+** from UBSAN.
79601
+*/
79602
+SQLITE_PRIVATE i64 sqlite3RealToI64(double r){
79603
+ if( r<=(double)SMALLEST_INT64 ) return SMALLEST_INT64;
79604
+ if( r>=(double)LARGEST_INT64) return LARGEST_INT64;
79605
+ return (i64)r;
79606
+}
7943379607
7943479608
/*
7943579609
** Convert pMem so that it has type MEM_Real or MEM_Int.
7943679610
** Invalidate any prior representations.
7943779611
**
@@ -79450,11 +79624,11 @@
7945079624
sqlite3_int64 ix;
7945179625
assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
7945279626
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
7945379627
rc = sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc);
7945479628
if( ((rc==0 || rc==1) && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1)
79455
- || sqlite3RealSameAsInt(pMem->u.r, (ix = (i64)pMem->u.r))
79629
+ || sqlite3RealSameAsInt(pMem->u.r, (ix = sqlite3RealToI64(pMem->u.r)))
7945679630
){
7945779631
pMem->u.i = ix;
7945879632
MemSetTypeFlag(pMem, MEM_Int);
7945979633
}else{
7946079634
MemSetTypeFlag(pMem, MEM_Real);
@@ -80682,14 +80856,14 @@
8068280856
p = sqlite3DbMallocRawNN(db, sizeof(Vdbe) );
8068380857
if( p==0 ) return 0;
8068480858
memset(&p->aOp, 0, sizeof(Vdbe)-offsetof(Vdbe,aOp));
8068580859
p->db = db;
8068680860
if( db->pVdbe ){
80687
- db->pVdbe->pPrev = p;
80861
+ db->pVdbe->ppVPrev = &p->pVNext;
8068880862
}
80689
- p->pNext = db->pVdbe;
80690
- p->pPrev = 0;
80863
+ p->pVNext = db->pVdbe;
80864
+ p->ppVPrev = &db->pVdbe;
8069180865
db->pVdbe = p;
8069280866
assert( p->eVdbeState==VDBE_INIT_STATE );
8069380867
p->pParse = pParse;
8069480868
pParse->pVdbe = p;
8069580869
assert( pParse->aLabel==0 );
@@ -80767,25 +80941,32 @@
8076780941
return 0;
8076880942
}
8076980943
#endif
8077080944
8077180945
/*
80772
-** Swap all content between two VDBE structures.
80946
+** Swap byte-code between two VDBE structures.
80947
+**
80948
+** This happens after pB was previously run and returned
80949
+** SQLITE_SCHEMA. The statement was then reprepared in pA.
80950
+** This routine transfers the new bytecode in pA over to pB
80951
+** so that pB can be run again. The old pB byte code is
80952
+** moved back to pA so that it will be cleaned up when pA is
80953
+** finalized.
8077380954
*/
8077480955
SQLITE_PRIVATE void sqlite3VdbeSwap(Vdbe *pA, Vdbe *pB){
80775
- Vdbe tmp, *pTmp;
80956
+ Vdbe tmp, *pTmp, **ppTmp;
8077680957
char *zTmp;
8077780958
assert( pA->db==pB->db );
8077880959
tmp = *pA;
8077980960
*pA = *pB;
8078080961
*pB = tmp;
80781
- pTmp = pA->pNext;
80782
- pA->pNext = pB->pNext;
80783
- pB->pNext = pTmp;
80784
- pTmp = pA->pPrev;
80785
- pA->pPrev = pB->pPrev;
80786
- pB->pPrev = pTmp;
80962
+ pTmp = pA->pVNext;
80963
+ pA->pVNext = pB->pVNext;
80964
+ pB->pVNext = pTmp;
80965
+ ppTmp = pA->ppVPrev;
80966
+ pA->ppVPrev = pB->ppVPrev;
80967
+ pB->ppVPrev = ppTmp;
8078780968
zTmp = pA->zSql;
8078880969
pA->zSql = pB->zSql;
8078980970
pB->zSql = zTmp;
8079080971
#ifdef SQLITE_ENABLE_NORMALIZE
8079180972
zTmp = pA->zNormSql;
@@ -81033,10 +81214,11 @@
8103381214
pCtx->argc = nArg;
8103481215
pCtx->iOp = sqlite3VdbeCurrentAddr(v);
8103581216
addr = sqlite3VdbeAddOp4(v, eCallCtx ? OP_PureFunc : OP_Function,
8103681217
p1, p2, p3, (char*)pCtx, P4_FUNCCTX);
8103781218
sqlite3VdbeChangeP5(v, eCallCtx & NC_SelfRef);
81219
+ sqlite3MayAbort(pParse);
8103881220
return addr;
8103981221
}
8104081222
8104181223
/*
8104281224
** Add an opcode that includes the p4 value with a P4_INT64 or
@@ -81101,11 +81283,11 @@
8110181283
va_end(ap);
8110281284
v = pParse->pVdbe;
8110381285
iThis = v->nOp;
8110481286
sqlite3VdbeAddOp4(v, OP_Explain, iThis, pParse->addrExplain, 0,
8110581287
zMsg, P4_DYNAMIC);
81106
- sqlite3ExplainBreakpoint(bPush?"PUSH":"", sqlite3VdbeGetOp(v,-1)->p4.z);
81288
+ sqlite3ExplainBreakpoint(bPush?"PUSH":"", sqlite3VdbeGetLastOp(v)->p4.z);
8110781289
if( bPush){
8110881290
pParse->addrExplain = iThis;
8110981291
}
8111081292
}
8111181293
}
@@ -81368,10 +81550,11 @@
8136881550
int opcode = pOp->opcode;
8136981551
if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename
8137081552
|| opcode==OP_VDestroy
8137181553
|| opcode==OP_VCreate
8137281554
|| opcode==OP_ParseSchema
81555
+ || opcode==OP_Function || opcode==OP_PureFunc
8137381556
|| ((opcode==OP_Halt || opcode==OP_HaltIfNull)
8137481557
&& ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
8137581558
){
8137681559
hasAbort = 1;
8137781560
break;
@@ -81458,12 +81641,12 @@
8145881641
Parse *pParse = p->pParse;
8145981642
int *aLabel = pParse->aLabel;
8146081643
p->readOnly = 1;
8146181644
p->bIsReader = 0;
8146281645
pOp = &p->aOp[p->nOp-1];
81463
- while(1){
81464
-
81646
+ assert( p->aOp[0].opcode==OP_Init );
81647
+ while( 1 /* Loop termates when it reaches the OP_Init opcode */ ){
8146581648
/* Only JUMP opcodes and the short list of special opcodes in the switch
8146681649
** below need to be considered. The mkopcodeh.tcl generator script groups
8146781650
** all these opcodes together near the front of the opcode list. Skip
8146881651
** any opcode that does not need processing by virtual of the fact that
8146981652
** it is larger than SQLITE_MX_JUMP_OPCODE, as a performance optimization.
@@ -81488,10 +81671,14 @@
8148881671
case OP_JournalMode: {
8148981672
p->readOnly = 0;
8149081673
p->bIsReader = 1;
8149181674
break;
8149281675
}
81676
+ case OP_Init: {
81677
+ assert( pOp->p2>=0 );
81678
+ goto resolve_p2_values_loop_exit;
81679
+ }
8149381680
#ifndef SQLITE_OMIT_VIRTUALTABLE
8149481681
case OP_VUpdate: {
8149581682
if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
8149681683
break;
8149781684
}
@@ -81520,15 +81707,16 @@
8152081707
/* The mkopcodeh.tcl script has so arranged things that the only
8152181708
** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to
8152281709
** have non-negative values for P2. */
8152381710
assert( (sqlite3OpcodeProperty[pOp->opcode]&OPFLG_JUMP)==0 || pOp->p2>=0);
8152481711
}
81525
- if( pOp==p->aOp ) break;
81712
+ assert( pOp>p->aOp );
8152681713
pOp--;
8152781714
}
81715
+resolve_p2_values_loop_exit:
8152881716
if( aLabel ){
81529
- sqlite3DbFreeNN(p->db, pParse->aLabel);
81717
+ sqlite3DbNNFreeNN(p->db, pParse->aLabel);
8153081718
pParse->aLabel = 0;
8153181719
}
8153281720
pParse->nLabel = 0;
8153381721
*pMaxFuncArgs = nMaxArgs;
8153481722
assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) );
@@ -81773,19 +81961,23 @@
8177381961
/*
8177481962
** Change the value of the opcode, or P1, P2, P3, or P5 operands
8177581963
** for a specific instruction.
8177681964
*/
8177781965
SQLITE_PRIVATE void sqlite3VdbeChangeOpcode(Vdbe *p, int addr, u8 iNewOpcode){
81966
+ assert( addr>=0 );
8177881967
sqlite3VdbeGetOp(p,addr)->opcode = iNewOpcode;
8177981968
}
8178081969
SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe *p, int addr, int val){
81970
+ assert( addr>=0 );
8178181971
sqlite3VdbeGetOp(p,addr)->p1 = val;
8178281972
}
8178381973
SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe *p, int addr, int val){
81974
+ assert( addr>=0 || p->db->mallocFailed );
8178481975
sqlite3VdbeGetOp(p,addr)->p2 = val;
8178581976
}
8178681977
SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe *p, int addr, int val){
81978
+ assert( addr>=0 );
8178781979
sqlite3VdbeGetOp(p,addr)->p3 = val;
8178881980
}
8178981981
SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe *p, u16 p5){
8179081982
assert( p->nOp>0 || p->db->mallocFailed );
8179181983
if( p->nOp>0 ) p->aOp[p->nOp-1].p5 = p5;
@@ -81817,11 +82009,11 @@
8181782009
assert( p->aOp[addr].opcode==OP_Once
8181882010
|| p->aOp[addr].opcode==OP_If
8181982011
|| p->aOp[addr].opcode==OP_FkIfZero );
8182082012
assert( p->aOp[addr].p4type==0 );
8182182013
#ifdef SQLITE_VDBE_COVERAGE
81822
- sqlite3VdbeGetOp(p,-1)->iSrcLine = 0; /* Erase VdbeCoverage() macros */
82014
+ sqlite3VdbeGetLastOp(p)->iSrcLine = 0; /* Erase VdbeCoverage() macros */
8182382015
#endif
8182482016
p->nOp--;
8182582017
}else{
8182682018
sqlite3VdbeChangeP2(p, addr, p->nOp);
8182782019
}
@@ -81831,25 +82023,27 @@
8183182023
/*
8183282024
** If the input FuncDef structure is ephemeral, then free it. If
8183382025
** the FuncDef is not ephermal, then do nothing.
8183482026
*/
8183582027
static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
82028
+ assert( db!=0 );
8183682029
if( (pDef->funcFlags & SQLITE_FUNC_EPHEM)!=0 ){
81837
- sqlite3DbFreeNN(db, pDef);
82030
+ sqlite3DbNNFreeNN(db, pDef);
8183882031
}
8183982032
}
8184082033
8184182034
/*
8184282035
** Delete a P4 value if necessary.
8184382036
*/
8184482037
static SQLITE_NOINLINE void freeP4Mem(sqlite3 *db, Mem *p){
8184582038
if( p->szMalloc ) sqlite3DbFree(db, p->zMalloc);
81846
- sqlite3DbFreeNN(db, p);
82039
+ sqlite3DbNNFreeNN(db, p);
8184782040
}
8184882041
static SQLITE_NOINLINE void freeP4FuncCtx(sqlite3 *db, sqlite3_context *p){
82042
+ assert( db!=0 );
8184982043
freeEphemeralFunction(db, p->pFunc);
81850
- sqlite3DbFreeNN(db, p);
82044
+ sqlite3DbNNFreeNN(db, p);
8185182045
}
8185282046
static void freeP4(sqlite3 *db, int p4type, void *p4){
8185382047
assert( db );
8185482048
switch( p4type ){
8185582049
case P4_FUNCCTX: {
@@ -81858,11 +82052,11 @@
8185882052
}
8185982053
case P4_REAL:
8186082054
case P4_INT64:
8186182055
case P4_DYNAMIC:
8186282056
case P4_INTARRAY: {
81863
- sqlite3DbFree(db, p4);
82057
+ if( p4 ) sqlite3DbNNFreeNN(db, p4);
8186482058
break;
8186582059
}
8186682060
case P4_KEYINFO: {
8186782061
if( db->pnBytesFreed==0 ) sqlite3KeyInfoUnref((KeyInfo*)p4);
8186882062
break;
@@ -81897,10 +82091,11 @@
8189782091
** opcodes contained within. If aOp is not NULL it is assumed to contain
8189882092
** nOp entries.
8189982093
*/
8190082094
static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){
8190182095
assert( nOp>=0 );
82096
+ assert( db!=0 );
8190282097
if( aOp ){
8190382098
Op *pOp = &aOp[nOp-1];
8190482099
while(1){ /* Exit via break */
8190582100
if( pOp->p4type <= P4_FREE_IF_LE ) freeP4(db, pOp->p4type, pOp->p4.p);
8190682101
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
@@ -81907,11 +82102,11 @@
8190782102
sqlite3DbFree(db, pOp->zComment);
8190882103
#endif
8190982104
if( pOp==aOp ) break;
8191082105
pOp--;
8191182106
}
81912
- sqlite3DbFreeNN(db, aOp);
82107
+ sqlite3DbNNFreeNN(db, aOp);
8191382108
}
8191482109
}
8191582110
8191682111
/*
8191782112
** Link the SubProgram object passed as the second argument into the linked
@@ -82138,17 +82333,17 @@
8213882333
#ifdef SQLITE_VDBE_COVERAGE
8213982334
/*
8214082335
** Set the value if the iSrcLine field for the previously coded instruction.
8214182336
*/
8214282337
SQLITE_PRIVATE void sqlite3VdbeSetLineNumber(Vdbe *v, int iLine){
82143
- sqlite3VdbeGetOp(v,-1)->iSrcLine = iLine;
82338
+ sqlite3VdbeGetLastOp(v)->iSrcLine = iLine;
8214482339
}
8214582340
#endif /* SQLITE_VDBE_COVERAGE */
8214682341
8214782342
/*
82148
-** Return the opcode for a given address. If the address is -1, then
82149
-** return the most recently inserted opcode.
82343
+** Return the opcode for a given address. The address must be non-negative.
82344
+** See sqlite3VdbeGetLastOp() to get the most recently added opcode.
8215082345
**
8215182346
** If a memory allocation error has occurred prior to the calling of this
8215282347
** routine, then a pointer to a dummy VdbeOp will be returned. That opcode
8215382348
** is readable but not writable, though it is cast to a writable value.
8215482349
** The return of a dummy opcode allows the call to continue functioning
@@ -82160,20 +82355,23 @@
8216082355
SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){
8216182356
/* C89 specifies that the constant "dummy" will be initialized to all
8216282357
** zeros, which is correct. MSVC generates a warning, nevertheless. */
8216382358
static VdbeOp dummy; /* Ignore the MSVC warning about no initializer */
8216482359
assert( p->eVdbeState==VDBE_INIT_STATE );
82165
- if( addr<0 ){
82166
- addr = p->nOp - 1;
82167
- }
8216882360
assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );
8216982361
if( p->db->mallocFailed ){
8217082362
return (VdbeOp*)&dummy;
8217182363
}else{
8217282364
return &p->aOp[addr];
8217382365
}
8217482366
}
82367
+
82368
+/* Return the most recently added opcode
82369
+*/
82370
+VdbeOp * sqlite3VdbeGetLastOp(Vdbe *p){
82371
+ return sqlite3VdbeGetOp(p, p->nOp - 1);
82372
+}
8217582373
8217682374
#if defined(SQLITE_ENABLE_EXPLAIN_COMMENTS)
8217782375
/*
8217882376
** Return an integer value for one of the parameters to the opcode pOp
8217982377
** determined by character c.
@@ -82658,11 +82856,11 @@
8265882856
if( p->flags&(MEM_Agg|MEM_Dyn) ){
8265982857
testcase( (p->flags & MEM_Dyn)!=0 && p->xDel==sqlite3VdbeFrameMemDel );
8266082858
sqlite3VdbeMemRelease(p);
8266182859
p->flags = MEM_Undefined;
8266282860
}else if( p->szMalloc ){
82663
- sqlite3DbFreeNN(db, p->zMalloc);
82861
+ sqlite3DbNNFreeNN(db, p->zMalloc);
8266482862
p->szMalloc = 0;
8266582863
p->flags = MEM_Undefined;
8266682864
}
8266782865
#ifdef SQLITE_DEBUG
8266882866
else{
@@ -83650,11 +83848,11 @@
8365083848
if( sqlite3_stmt_busy((sqlite3_stmt*)p) ){
8365183849
cnt++;
8365283850
if( p->readOnly==0 ) nWrite++;
8365383851
if( p->bIsReader ) nRead++;
8365483852
}
83655
- p = p->pNext;
83853
+ p = p->pVNext;
8365683854
}
8365783855
assert( cnt==db->nVdbeActive );
8365883856
assert( nWrite==db->nVdbeWrite );
8365983857
assert( nRead==db->nVdbeRead );
8366083858
}
@@ -84179,27 +84377,28 @@
8417984377
** VdbeDelete() also unlinks the Vdbe from the list of VMs associated with
8418084378
** the database connection and frees the object itself.
8418184379
*/
8418284380
static void sqlite3VdbeClearObject(sqlite3 *db, Vdbe *p){
8418384381
SubProgram *pSub, *pNext;
84382
+ assert( db!=0 );
8418484383
assert( p->db==0 || p->db==db );
8418584384
if( p->aColName ){
8418684385
releaseMemArray(p->aColName, p->nResColumn*COLNAME_N);
84187
- sqlite3DbFreeNN(db, p->aColName);
84386
+ sqlite3DbNNFreeNN(db, p->aColName);
8418884387
}
8418984388
for(pSub=p->pProgram; pSub; pSub=pNext){
8419084389
pNext = pSub->pNext;
8419184390
vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
8419284391
sqlite3DbFree(db, pSub);
8419384392
}
8419484393
if( p->eVdbeState!=VDBE_INIT_STATE ){
8419584394
releaseMemArray(p->aVar, p->nVar);
84196
- if( p->pVList ) sqlite3DbFreeNN(db, p->pVList);
84197
- if( p->pFree ) sqlite3DbFreeNN(db, p->pFree);
84395
+ if( p->pVList ) sqlite3DbNNFreeNN(db, p->pVList);
84396
+ if( p->pFree ) sqlite3DbNNFreeNN(db, p->pFree);
8419884397
}
8419984398
vdbeFreeOpArray(db, p->aOp, p->nOp);
84200
- sqlite3DbFree(db, p->zSql);
84399
+ if( p->zSql ) sqlite3DbNNFreeNN(db, p->zSql);
8420184400
#ifdef SQLITE_ENABLE_NORMALIZE
8420284401
sqlite3DbFree(db, p->zNormSql);
8420384402
{
8420484403
DblquoteStr *pThis, *pNext;
8420584404
for(pThis=p->pDblStr; pThis; pThis=pNext){
@@ -84225,24 +84424,21 @@
8422584424
SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe *p){
8422684425
sqlite3 *db;
8422784426
8422884427
assert( p!=0 );
8422984428
db = p->db;
84429
+ assert( db!=0 );
8423084430
assert( sqlite3_mutex_held(db->mutex) );
8423184431
sqlite3VdbeClearObject(db, p);
8423284432
if( db->pnBytesFreed==0 ){
84233
- if( p->pPrev ){
84234
- p->pPrev->pNext = p->pNext;
84235
- }else{
84236
- assert( db->pVdbe==p );
84237
- db->pVdbe = p->pNext;
84238
- }
84239
- if( p->pNext ){
84240
- p->pNext->pPrev = p->pPrev;
84433
+ assert( p->ppVPrev!=0 );
84434
+ *p->ppVPrev = p->pVNext;
84435
+ if( p->pVNext ){
84436
+ p->pVNext->ppVPrev = p->ppVPrev;
8424184437
}
8424284438
}
84243
- sqlite3DbFreeNN(db, p);
84439
+ sqlite3DbNNFreeNN(db, p);
8424484440
}
8424584441
8424684442
/*
8424784443
** The cursor "p" has a pending seek operation that has not yet been
8424884444
** carried out. Seek the cursor now. If an error occurs, return
@@ -85733,11 +85929,11 @@
8573385929
** prepared statements. The flag is set to 1 for an immediate expiration
8573485930
** and set to 2 for an advisory expiration.
8573585931
*/
8573685932
SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3 *db, int iCode){
8573785933
Vdbe *p;
85738
- for(p = db->pVdbe; p; p=p->pNext){
85934
+ for(p = db->pVdbe; p; p=p->pVNext){
8573985935
p->expired = iCode+1;
8574085936
}
8574185937
}
8574285938
8574385939
/*
@@ -85854,17 +86050,18 @@
8585486050
**
8585586051
** This function is used to free UnpackedRecord structures allocated by
8585686052
** the vdbeUnpackRecord() function found in vdbeapi.c.
8585786053
*/
8585886054
static void vdbeFreeUnpacked(sqlite3 *db, int nField, UnpackedRecord *p){
86055
+ assert( db!=0 );
8585986056
if( p ){
8586086057
int i;
8586186058
for(i=0; i<nField; i++){
8586286059
Mem *pMem = &p->aMem[i];
8586386060
if( pMem->zMalloc ) sqlite3VdbeMemReleaseMalloc(pMem);
8586486061
}
85865
- sqlite3DbFreeNN(db, p);
86062
+ sqlite3DbNNFreeNN(db, p);
8586686063
}
8586786064
}
8586886065
#endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
8586986066
8587086067
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
@@ -85931,11 +86128,11 @@
8593186128
if( preupdate.aNew ){
8593286129
int i;
8593386130
for(i=0; i<pCsr->nField; i++){
8593486131
sqlite3VdbeMemRelease(&preupdate.aNew[i]);
8593586132
}
85936
- sqlite3DbFreeNN(db, preupdate.aNew);
86133
+ sqlite3DbNNFreeNN(db, preupdate.aNew);
8593786134
}
8593886135
}
8593986136
#endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
8594086137
8594186138
/************** End of vdbeaux.c *********************************************/
@@ -86048,11 +86245,13 @@
8604886245
Vdbe *v = (Vdbe*)pStmt;
8604986246
sqlite3 *db = v->db;
8605086247
if( vdbeSafety(v) ) return SQLITE_MISUSE_BKPT;
8605186248
sqlite3_mutex_enter(db->mutex);
8605286249
checkProfileCallback(db, v);
86053
- rc = sqlite3VdbeFinalize(v);
86250
+ assert( v->eVdbeState>=VDBE_READY_STATE );
86251
+ rc = sqlite3VdbeReset(v);
86252
+ sqlite3VdbeDelete(v);
8605486253
rc = sqlite3ApiExit(db, rc);
8605586254
sqlite3LeaveMutexAndCloseZombie(db);
8605686255
}
8605786256
return rc;
8605886257
}
@@ -87370,11 +87569,11 @@
8737087569
** the mutex is released if any kind of error occurs.
8737187570
**
8737287571
** The error code stored in database p->db is overwritten with the return
8737387572
** value in any case.
8737487573
*/
87375
-static int vdbeUnbind(Vdbe *p, int i){
87574
+static int vdbeUnbind(Vdbe *p, unsigned int i){
8737687575
Mem *pVar;
8737787576
if( vdbeSafetyNotNull(p) ){
8737887577
return SQLITE_MISUSE_BKPT;
8737987578
}
8738087579
sqlite3_mutex_enter(p->db->mutex);
@@ -87383,16 +87582,15 @@
8738387582
sqlite3_mutex_leave(p->db->mutex);
8738487583
sqlite3_log(SQLITE_MISUSE,
8738587584
"bind on a busy prepared statement: [%s]", p->zSql);
8738687585
return SQLITE_MISUSE_BKPT;
8738787586
}
87388
- if( i<1 || i>p->nVar ){
87587
+ if( i>=(unsigned int)p->nVar ){
8738987588
sqlite3Error(p->db, SQLITE_RANGE);
8739087589
sqlite3_mutex_leave(p->db->mutex);
8739187590
return SQLITE_RANGE;
8739287591
}
87393
- i--;
8739487592
pVar = &p->aVar[i];
8739587593
sqlite3VdbeMemRelease(pVar);
8739687594
pVar->flags = MEM_Null;
8739787595
p->db->errCode = SQLITE_OK;
8739887596
@@ -87425,11 +87623,11 @@
8742587623
){
8742687624
Vdbe *p = (Vdbe *)pStmt;
8742787625
Mem *pVar;
8742887626
int rc;
8742987627
87430
- rc = vdbeUnbind(p, i);
87628
+ rc = vdbeUnbind(p, (u32)(i-1));
8743187629
if( rc==SQLITE_OK ){
8743287630
if( zData!=0 ){
8743387631
pVar = &p->aVar[i-1];
8743487632
rc = sqlite3VdbeMemSetStr(pVar, zData, nData, encoding, xDel);
8743587633
if( rc==SQLITE_OK && encoding!=0 ){
@@ -87474,11 +87672,11 @@
8747487672
return bindText(pStmt, i, zData, nData, xDel, 0);
8747587673
}
8747687674
SQLITE_API int sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){
8747787675
int rc;
8747887676
Vdbe *p = (Vdbe *)pStmt;
87479
- rc = vdbeUnbind(p, i);
87677
+ rc = vdbeUnbind(p, (u32)(i-1));
8748087678
if( rc==SQLITE_OK ){
8748187679
sqlite3VdbeMemSetDouble(&p->aVar[i-1], rValue);
8748287680
sqlite3_mutex_leave(p->db->mutex);
8748387681
}
8748487682
return rc;
@@ -87487,21 +87685,21 @@
8748787685
return sqlite3_bind_int64(p, i, (i64)iValue);
8748887686
}
8748987687
SQLITE_API int sqlite3_bind_int64(sqlite3_stmt *pStmt, int i, sqlite_int64 iValue){
8749087688
int rc;
8749187689
Vdbe *p = (Vdbe *)pStmt;
87492
- rc = vdbeUnbind(p, i);
87690
+ rc = vdbeUnbind(p, (u32)(i-1));
8749387691
if( rc==SQLITE_OK ){
8749487692
sqlite3VdbeMemSetInt64(&p->aVar[i-1], iValue);
8749587693
sqlite3_mutex_leave(p->db->mutex);
8749687694
}
8749787695
return rc;
8749887696
}
8749987697
SQLITE_API int sqlite3_bind_null(sqlite3_stmt *pStmt, int i){
8750087698
int rc;
8750187699
Vdbe *p = (Vdbe*)pStmt;
87502
- rc = vdbeUnbind(p, i);
87700
+ rc = vdbeUnbind(p, (u32)(i-1));
8750387701
if( rc==SQLITE_OK ){
8750487702
sqlite3_mutex_leave(p->db->mutex);
8750587703
}
8750687704
return rc;
8750787705
}
@@ -87512,11 +87710,11 @@
8751287710
const char *zPTtype,
8751387711
void (*xDestructor)(void*)
8751487712
){
8751587713
int rc;
8751687714
Vdbe *p = (Vdbe*)pStmt;
87517
- rc = vdbeUnbind(p, i);
87715
+ rc = vdbeUnbind(p, (u32)(i-1));
8751887716
if( rc==SQLITE_OK ){
8751987717
sqlite3VdbeMemSetPointer(&p->aVar[i-1], pPtr, zPTtype, xDestructor);
8752087718
sqlite3_mutex_leave(p->db->mutex);
8752187719
}else if( xDestructor ){
8752287720
xDestructor(pPtr);
@@ -87590,11 +87788,11 @@
8759087788
return rc;
8759187789
}
8759287790
SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt *pStmt, int i, int n){
8759387791
int rc;
8759487792
Vdbe *p = (Vdbe *)pStmt;
87595
- rc = vdbeUnbind(p, i);
87793
+ rc = vdbeUnbind(p, (u32)(i-1));
8759687794
if( rc==SQLITE_OK ){
8759787795
#ifndef SQLITE_OMIT_INCRBLOB
8759887796
sqlite3VdbeMemSetZeroBlob(&p->aVar[i-1], n);
8759987797
#else
8760087798
rc = sqlite3VdbeMemSetZeroBlob(&p->aVar[i-1], n);
@@ -87750,11 +87948,11 @@
8775087948
#endif
8775187949
sqlite3_mutex_enter(pDb->mutex);
8775287950
if( pStmt==0 ){
8775387951
pNext = (sqlite3_stmt*)pDb->pVdbe;
8775487952
}else{
87755
- pNext = (sqlite3_stmt*)((Vdbe*)pStmt)->pNext;
87953
+ pNext = (sqlite3_stmt*)((Vdbe*)pStmt)->pVNext;
8775687954
}
8775787955
sqlite3_mutex_leave(pDb->mutex);
8775887956
return pNext;
8775987957
}
8776087958
@@ -87775,12 +87973,15 @@
8777587973
if( op==SQLITE_STMTSTATUS_MEMUSED ){
8777687974
sqlite3 *db = pVdbe->db;
8777787975
sqlite3_mutex_enter(db->mutex);
8777887976
v = 0;
8777987977
db->pnBytesFreed = (int*)&v;
87978
+ assert( db->lookaside.pEnd==db->lookaside.pTrueEnd );
87979
+ db->lookaside.pEnd = db->lookaside.pStart;
8778087980
sqlite3VdbeDelete(pVdbe);
8778187981
db->pnBytesFreed = 0;
87982
+ db->lookaside.pEnd = db->lookaside.pTrueEnd;
8778287983
sqlite3_mutex_leave(db->mutex);
8778387984
}else{
8778487985
v = pVdbe->aCounter[op];
8778587986
if( resetFlag ) pVdbe->aCounter[op] = 0;
8778687987
}
@@ -88616,11 +88817,12 @@
8861688817
** floating point value of rValue. Return true and set *piValue to the
8861788818
** integer value if the string is in range to be an integer. Otherwise,
8861888819
** return false.
8861988820
*/
8862088821
static int alsoAnInt(Mem *pRec, double rValue, i64 *piValue){
88621
- i64 iValue = (double)rValue;
88822
+ i64 iValue;
88823
+ iValue = sqlite3RealToI64(rValue);
8862288824
if( sqlite3RealSameAsInt(rValue,iValue) ){
8862388825
*piValue = iValue;
8862488826
return 1;
8862588827
}
8862688828
return 0==sqlite3Atoi64(pRec->z, piValue, pRec->n, pRec->enc);
@@ -88778,21 +88980,22 @@
8877888980
**
8877988981
** Unlike applyNumericAffinity(), this routine does not modify pMem->flags.
8878088982
** But it does set pMem->u.r and pMem->u.i appropriately.
8878188983
*/
8878288984
static u16 numericType(Mem *pMem){
88783
- if( pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal) ){
88985
+ assert( (pMem->flags & MEM_Null)==0
88986
+ || pMem->db==0 || pMem->db->mallocFailed );
88987
+ if( pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Null) ){
8878488988
testcase( pMem->flags & MEM_Int );
8878588989
testcase( pMem->flags & MEM_Real );
8878688990
testcase( pMem->flags & MEM_IntReal );
88787
- return pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal);
88991
+ return pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Null);
8878888992
}
88789
- if( pMem->flags & (MEM_Str|MEM_Blob) ){
88790
- testcase( pMem->flags & MEM_Str );
88791
- testcase( pMem->flags & MEM_Blob );
88792
- return computeNumericType(pMem);
88793
- }
88993
+ assert( pMem->flags & (MEM_Str|MEM_Blob) );
88994
+ testcase( pMem->flags & MEM_Str );
88995
+ testcase( pMem->flags & MEM_Blob );
88996
+ return computeNumericType(pMem);
8879488997
return 0;
8879588998
}
8879688999
8879789000
#ifdef SQLITE_DEBUG
8879889001
/*
@@ -90033,25 +90236,24 @@
9003390236
case OP_Add: /* same as TK_PLUS, in1, in2, out3 */
9003490237
case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */
9003590238
case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */
9003690239
case OP_Divide: /* same as TK_SLASH, in1, in2, out3 */
9003790240
case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */
90038
- u16 flags; /* Combined MEM_* flags from both inputs */
9003990241
u16 type1; /* Numeric type of left operand */
9004090242
u16 type2; /* Numeric type of right operand */
9004190243
i64 iA; /* Integer value of left operand */
9004290244
i64 iB; /* Integer value of right operand */
9004390245
double rA; /* Real value of left operand */
9004490246
double rB; /* Real value of right operand */
9004590247
9004690248
pIn1 = &aMem[pOp->p1];
90047
- type1 = numericType(pIn1);
90249
+ type1 = pIn1->flags;
9004890250
pIn2 = &aMem[pOp->p2];
90049
- type2 = numericType(pIn2);
90251
+ type2 = pIn2->flags;
9005090252
pOut = &aMem[pOp->p3];
90051
- flags = pIn1->flags | pIn2->flags;
9005290253
if( (type1 & type2 & MEM_Int)!=0 ){
90254
+int_math:
9005390255
iA = pIn1->u.i;
9005490256
iB = pIn2->u.i;
9005590257
switch( pOp->opcode ){
9005690258
case OP_Add: if( sqlite3AddInt64(&iB,iA) ) goto fp_math; break;
9005790259
case OP_Subtract: if( sqlite3SubInt64(&iB,iA) ) goto fp_math; break;
@@ -90069,13 +90271,16 @@
9006990271
break;
9007090272
}
9007190273
}
9007290274
pOut->u.i = iB;
9007390275
MemSetTypeFlag(pOut, MEM_Int);
90074
- }else if( (flags & MEM_Null)!=0 ){
90276
+ }else if( ((type1 | type2) & MEM_Null)!=0 ){
9007590277
goto arithmetic_result_is_null;
9007690278
}else{
90279
+ type1 = numericType(pIn1);
90280
+ type2 = numericType(pIn2);
90281
+ if( (type1 & type2 & MEM_Int)!=0 ) goto int_math;
9007790282
fp_math:
9007890283
rA = sqlite3VdbeRealValue(pIn1);
9007990284
rB = sqlite3VdbeRealValue(pIn2);
9008090285
switch( pOp->opcode ){
9008190286
case OP_Add: rB += rA; break;
@@ -90941,15 +91146,18 @@
9094191146
**
9094291147
** Check the cursor P1 to see if it is currently pointing at a NULL row.
9094391148
** If it is, then set register P3 to NULL and jump immediately to P2.
9094491149
** If P1 is not on a NULL row, then fall through without making any
9094591150
** changes.
91151
+**
91152
+** If P1 is not an open cursor, then this opcode is a no-op.
9094691153
*/
9094791154
case OP_IfNullRow: { /* jump */
91155
+ VdbeCursor *pC;
9094891156
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90949
- assert( p->apCsr[pOp->p1]!=0 );
90950
- if( p->apCsr[pOp->p1]->nullRow ){
91157
+ pC = p->apCsr[pOp->p1];
91158
+ if( ALWAYS(pC) && pC->nullRow ){
9095191159
sqlite3VdbeMemSetNull(aMem + pOp->p3);
9095291160
goto jump_to_p2;
9095391161
}
9095491162
break;
9095591163
}
@@ -93052,11 +93260,11 @@
9305293260
**
9305393261
** <li> If the cursor is successfully moved to the target row by 0 or more
9305493262
** sqlite3BtreeNext() calls, then jump to This.P2, which will land just
9305593263
** past the OP_IdxGT or OP_IdxGE opcode that follows the OP_SeekGE.
9305693264
**
93057
-** <li> If the cursor ends up past the target row (indicating the the target
93265
+** <li> If the cursor ends up past the target row (indicating that the target
9305893266
** row does not exist in the btree) then jump to SeekOP.P2.
9305993267
** </ol>
9306093268
*/
9306193269
case OP_SeekScan: {
9306293270
VdbeCursor *pC;
@@ -94388,11 +94596,13 @@
9438894596
rc = sqlite3VdbeSorterNext(db, pC);
9438994597
goto next_tail;
9439094598
9439194599
case OP_Prev: /* jump */
9439294600
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
94393
- assert( pOp->p5<ArraySize(p->aCounter) );
94601
+ assert( pOp->p5==0
94602
+ || pOp->p5==SQLITE_STMTSTATUS_FULLSCAN_STEP
94603
+ || pOp->p5==SQLITE_STMTSTATUS_AUTOINDEX);
9439494604
pC = p->apCsr[pOp->p1];
9439594605
assert( pC!=0 );
9439694606
assert( pC->deferredMoveto==0 );
9439794607
assert( pC->eCurType==CURTYPE_BTREE );
9439894608
assert( pC->seekOp==OP_SeekLT || pC->seekOp==OP_SeekLE
@@ -94401,11 +94611,13 @@
9440194611
rc = sqlite3BtreePrevious(pC->uc.pCursor, pOp->p3);
9440294612
goto next_tail;
9440394613
9440494614
case OP_Next: /* jump */
9440594615
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
94406
- assert( pOp->p5<ArraySize(p->aCounter) );
94616
+ assert( pOp->p5==0
94617
+ || pOp->p5==SQLITE_STMTSTATUS_FULLSCAN_STEP
94618
+ || pOp->p5==SQLITE_STMTSTATUS_AUTOINDEX);
9440794619
pC = p->apCsr[pOp->p1];
9440894620
assert( pC!=0 );
9440994621
assert( pC->deferredMoveto==0 );
9441094622
assert( pC->eCurType==CURTYPE_BTREE );
9441194623
assert( pC->seekOp==OP_SeekGT || pC->seekOp==OP_SeekGE
@@ -94608,14 +94820,14 @@
9460894820
9460994821
/* The IdxRowid and Seek opcodes are combined because of the commonality
9461094822
** of sqlite3VdbeCursorRestore() and sqlite3VdbeIdxRowid(). */
9461194823
rc = sqlite3VdbeCursorRestore(pC);
9461294824
94613
- /* sqlite3VbeCursorRestore() can only fail if the record has been deleted
94614
- ** out from under the cursor. That will never happens for an IdxRowid
94615
- ** or Seek opcode */
94616
- if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
94825
+ /* sqlite3VdbeCursorRestore() may fail if the cursor has been disturbed
94826
+ ** since it was last positioned and an error (e.g. OOM or an IO error)
94827
+ ** occurs while trying to reposition it. */
94828
+ if( rc!=SQLITE_OK ) goto abort_due_to_error;
9461794829
9461894830
if( !pC->nullRow ){
9461994831
rowid = 0; /* Not needed. Only used to silence a warning. */
9462094832
rc = sqlite3VdbeIdxRowid(db, pC->uc.pCursor, &rowid);
9462194833
if( rc!=SQLITE_OK ){
@@ -95513,11 +95725,11 @@
9551395725
9551495726
/* Opcode: OffsetLimit P1 P2 P3 * *
9551595727
** Synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)
9551695728
**
9551795729
** This opcode performs a commonly used computation associated with
95518
-** LIMIT and OFFSET process. r[P1] holds the limit counter. r[P3]
95730
+** LIMIT and OFFSET processing. r[P1] holds the limit counter. r[P3]
9551995731
** holds the offset counter. The opcode computes the combined value
9552095732
** of the LIMIT and OFFSET and stores that value in r[P2]. The r[P2]
9552195733
** value computed is the total number of rows that will need to be
9552295734
** visited in order to complete the query.
9552395735
**
@@ -101110,10 +101322,12 @@
101110101322
sqlite3_file *pJfd, /* Preallocated, blank file handle */
101111101323
int flags, /* Opening flags */
101112101324
int nSpill /* Bytes buffered before opening the file */
101113101325
){
101114101326
MemJournal *p = (MemJournal*)pJfd;
101327
+
101328
+ assert( zName || nSpill<0 || (flags & SQLITE_OPEN_EXCLUSIVE) );
101115101329
101116101330
/* Zero the file-handle object. If nSpill was passed zero, initialize
101117101331
** it using the sqlite3OsOpen() function of the underlying VFS. In this
101118101332
** case none of the code in this module is executed as a result of calls
101119101333
** made on the journal file-handle. */
@@ -101552,13 +101766,11 @@
101552101766
if( ExprHasProperty(pExpr, EP_WinFunc) ){
101553101767
if( ALWAYS(pExpr->y.pWin!=0) ){
101554101768
pExpr->y.pWin->pOwner = pExpr;
101555101769
}
101556101770
}
101557
- sqlite3ParserAddCleanup(pParse,
101558
- (void(*)(sqlite3*,void*))sqlite3ExprDelete,
101559
- pDup);
101771
+ sqlite3ExprDeferredDelete(pParse, pDup);
101560101772
}
101561101773
}
101562101774
101563101775
/*
101564101776
** Subqueries stores the original database, table and column names for their
@@ -104363,11 +104575,13 @@
104363104575
** Also propagate EP_Propagate flags up from Expr.x.pList to Expr.flags,
104364104576
** if appropriate.
104365104577
*/
104366104578
static void exprSetHeight(Expr *p){
104367104579
int nHeight = p->pLeft ? p->pLeft->nHeight : 0;
104368
- if( p->pRight && p->pRight->nHeight>nHeight ) nHeight = p->pRight->nHeight;
104580
+ if( NEVER(p->pRight) && p->pRight->nHeight>nHeight ){
104581
+ nHeight = p->pRight->nHeight;
104582
+ }
104369104583
if( ExprUseXSelect(p) ){
104370104584
heightOfSelect(p->x.pSelect, &nHeight);
104371104585
}else if( p->x.pList ){
104372104586
heightOfExprList(p->x.pList, &nHeight);
104373104587
p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList);
@@ -104506,19 +104720,30 @@
104506104720
if( pRoot==0 ){
104507104721
assert( db->mallocFailed );
104508104722
sqlite3ExprDelete(db, pLeft);
104509104723
sqlite3ExprDelete(db, pRight);
104510104724
}else{
104725
+ assert( ExprUseXList(pRoot) );
104726
+ assert( pRoot->x.pSelect==0 );
104511104727
if( pRight ){
104512104728
pRoot->pRight = pRight;
104513104729
pRoot->flags |= EP_Propagate & pRight->flags;
104730
+#if SQLITE_MAX_EXPR_DEPTH>0
104731
+ pRoot->nHeight = pRight->nHeight+1;
104732
+ }else{
104733
+ pRoot->nHeight = 1;
104734
+#endif
104514104735
}
104515104736
if( pLeft ){
104516104737
pRoot->pLeft = pLeft;
104517104738
pRoot->flags |= EP_Propagate & pLeft->flags;
104739
+#if SQLITE_MAX_EXPR_DEPTH>0
104740
+ if( pLeft->nHeight>=pRoot->nHeight ){
104741
+ pRoot->nHeight = pLeft->nHeight+1;
104742
+ }
104743
+#endif
104518104744
}
104519
- exprSetHeight(pRoot);
104520104745
}
104521104746
}
104522104747
104523104748
/*
104524104749
** Allocate an Expr node which joins as many as two subtrees.
@@ -104800,10 +105025,11 @@
104800105025
/*
104801105026
** Recursively delete an expression tree.
104802105027
*/
104803105028
static SQLITE_NOINLINE void sqlite3ExprDeleteNN(sqlite3 *db, Expr *p){
104804105029
assert( p!=0 );
105030
+ assert( db!=0 );
104805105031
assert( !ExprUseUValue(p) || p->u.iValue>=0 );
104806105032
assert( !ExprUseYWin(p) || !ExprUseYSub(p) );
104807105033
assert( !ExprUseYWin(p) || p->y.pWin!=0 || db->mallocFailed );
104808105034
assert( p->op!=TK_FUNCTION || !ExprUseYSub(p) );
104809105035
#ifdef SQLITE_DEBUG
@@ -104831,16 +105057,12 @@
104831105057
sqlite3WindowDelete(db, p->y.pWin);
104832105058
}
104833105059
#endif
104834105060
}
104835105061
}
104836
- if( ExprHasProperty(p, EP_MemToken) ){
104837
- assert( !ExprHasProperty(p, EP_IntValue) );
104838
- sqlite3DbFree(db, p->u.zToken);
104839
- }
104840105062
if( !ExprHasProperty(p, EP_Static) ){
104841
- sqlite3DbFreeNN(db, p);
105063
+ sqlite3DbNNFreeNN(db, p);
104842105064
}
104843105065
}
104844105066
SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
104845105067
if( p ) sqlite3ExprDeleteNN(db, p);
104846105068
}
@@ -104867,12 +105089,13 @@
104867105089
**
104868105090
** The deferred delete is (currently) implemented by adding the
104869105091
** pExpr to the pParse->pConstExpr list with a register number of 0.
104870105092
*/
104871105093
SQLITE_PRIVATE void sqlite3ExprDeferredDelete(Parse *pParse, Expr *pExpr){
104872
- pParse->pConstExpr =
104873
- sqlite3ExprListAppend(pParse, pParse->pConstExpr, pExpr);
105094
+ sqlite3ParserAddCleanup(pParse,
105095
+ (void(*)(sqlite3*,void*))sqlite3ExprDelete,
105096
+ pExpr);
104874105097
}
104875105098
104876105099
/* Invoke sqlite3RenameExprUnmap() and sqlite3ExprDelete() on the
104877105100
** expression.
104878105101
*/
@@ -104942,11 +105165,10 @@
104942105165
){
104943105166
nSize = EXPR_FULLSIZE;
104944105167
}else{
104945105168
assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
104946105169
assert( !ExprHasProperty(p, EP_OuterON) );
104947
- assert( !ExprHasProperty(p, EP_MemToken) );
104948105170
assert( !ExprHasVVAProperty(p, EP_NoReduce) );
104949105171
if( p->pLeft || p->x.pList ){
104950105172
nSize = EXPR_REDUCEDSIZE | EP_Reduced;
104951105173
}else{
104952105174
assert( p->pRight==0 );
@@ -105046,11 +105268,11 @@
105046105268
memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
105047105269
}
105048105270
}
105049105271
105050105272
/* Set the EP_Reduced, EP_TokenOnly, and EP_Static flags appropriately. */
105051
- pNew->flags &= ~(EP_Reduced|EP_TokenOnly|EP_Static|EP_MemToken);
105273
+ pNew->flags &= ~(EP_Reduced|EP_TokenOnly|EP_Static);
105052105274
pNew->flags |= nStructSize & (EP_Reduced|EP_TokenOnly);
105053105275
pNew->flags |= staticFlag;
105054105276
ExprClearVVAProperties(pNew);
105055105277
if( dupFlags ){
105056105278
ExprSetVVAProperty(pNew, EP_Immutable);
@@ -105622,16 +105844,17 @@
105622105844
*/
105623105845
static SQLITE_NOINLINE void exprListDeleteNN(sqlite3 *db, ExprList *pList){
105624105846
int i = pList->nExpr;
105625105847
struct ExprList_item *pItem = pList->a;
105626105848
assert( pList->nExpr>0 );
105849
+ assert( db!=0 );
105627105850
do{
105628105851
sqlite3ExprDelete(db, pItem->pExpr);
105629
- sqlite3DbFree(db, pItem->zEName);
105852
+ if( pItem->zEName ) sqlite3DbNNFreeNN(db, pItem->zEName);
105630105853
pItem++;
105631105854
}while( --i>0 );
105632
- sqlite3DbFreeNN(db, pList);
105855
+ sqlite3DbNNFreeNN(db, pList);
105633105856
}
105634105857
SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
105635105858
if( pList ) exprListDeleteNN(db, pList);
105636105859
}
105637105860
@@ -106918,11 +107141,11 @@
106918107141
if( pLimit ){
106919107142
pLimit->affExpr = SQLITE_AFF_NUMERIC;
106920107143
pLimit = sqlite3PExpr(pParse, TK_NE,
106921107144
sqlite3ExprDup(db, pSel->pLimit->pLeft, 0), pLimit);
106922107145
}
106923
- sqlite3ExprDelete(db, pSel->pLimit->pLeft);
107146
+ sqlite3ExprDeferredDelete(pParse, pSel->pLimit->pLeft);
106924107147
pSel->pLimit->pLeft = pLimit;
106925107148
}else{
106926107149
/* If there is no pre-existing limit add a limit of 1 */
106927107150
pLimit = sqlite3Expr(pParse->db, TK_INTEGER, "1");
106928107151
pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
@@ -107432,11 +107655,11 @@
107432107655
u8 p5 /* P5 value for OP_Column + FLAGS */
107433107656
){
107434107657
assert( pParse->pVdbe!=0 );
107435107658
sqlite3ExprCodeGetColumnOfTable(pParse->pVdbe, pTab, iTable, iColumn, iReg);
107436107659
if( p5 ){
107437
- VdbeOp *pOp = sqlite3VdbeGetOp(pParse->pVdbe,-1);
107660
+ VdbeOp *pOp = sqlite3VdbeGetLastOp(pParse->pVdbe);
107438107661
if( pOp->opcode==OP_Column ) pOp->p5 = p5;
107439107662
}
107440107663
return iReg;
107441107664
}
107442107665
@@ -107501,11 +107724,11 @@
107501107724
/*
107502107725
** If the last opcode is a OP_Copy, then set the do-not-merge flag (p5)
107503107726
** so that a subsequent copy will not be merged into this one.
107504107727
*/
107505107728
static void setDoNotMergeFlagOnCopy(Vdbe *v){
107506
- if( sqlite3VdbeGetOp(v, -1)->opcode==OP_Copy ){
107729
+ if( sqlite3VdbeGetLastOp(v)->opcode==OP_Copy ){
107507107730
sqlite3VdbeChangeP5(v, 1); /* Tag trailing OP_Copy as not mergable */
107508107731
}
107509107732
}
107510107733
107511107734
/*
@@ -107672,11 +107895,11 @@
107672107895
Table *pTab = pCol->pTab;
107673107896
sqlite3VdbeAddOp3(v, OP_Column, pAggInfo->sortingIdxPTab,
107674107897
pCol->iSorterColumn, target);
107675107898
if( pCol->iColumn<0 ){
107676107899
VdbeComment((v,"%s.rowid",pTab->zName));
107677
- }else{
107900
+ }else if( ALWAYS(pTab!=0) ){
107678107901
VdbeComment((v,"%s.%s",
107679107902
pTab->zName, pTab->aCol[pCol->iColumn].zCnName));
107680107903
if( pTab->aCol[pCol->iColumn].affinity==SQLITE_AFF_REAL ){
107681107904
sqlite3VdbeAddOp1(v, OP_RealAffinity, target);
107682107905
}
@@ -108267,10 +108490,25 @@
108267108490
** on a LEFT JOIN NULL row.
108268108491
*/
108269108492
case TK_IF_NULL_ROW: {
108270108493
int addrINR;
108271108494
u8 okConstFactor = pParse->okConstFactor;
108495
+ AggInfo *pAggInfo = pExpr->pAggInfo;
108496
+ if( pAggInfo ){
108497
+ assert( pExpr->iAgg>=0 && pExpr->iAgg<pAggInfo->nColumn );
108498
+ if( !pAggInfo->directMode ){
108499
+ inReg = pAggInfo->aCol[pExpr->iAgg].iMem;
108500
+ break;
108501
+ }
108502
+ if( pExpr->pAggInfo->useSortingIdx ){
108503
+ sqlite3VdbeAddOp3(v, OP_Column, pAggInfo->sortingIdxPTab,
108504
+ pAggInfo->aCol[pExpr->iAgg].iSorterColumn,
108505
+ target);
108506
+ inReg = target;
108507
+ break;
108508
+ }
108509
+ }
108272108510
addrINR = sqlite3VdbeAddOp1(v, OP_IfNullRow, pExpr->iTable);
108273108511
/* Temporarily disable factoring of constant expressions, since
108274108512
** even though expressions may appear to be constant, they are not
108275108513
** really constant because they originate from the right-hand side
108276108514
** of a LEFT JOIN. */
@@ -108608,11 +108846,11 @@
108608108846
}else{
108609108847
int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
108610108848
if( inReg!=target+i ){
108611108849
VdbeOp *pOp;
108612108850
if( copyOp==OP_Copy
108613
- && (pOp=sqlite3VdbeGetOp(v, -1))->opcode==OP_Copy
108851
+ && (pOp=sqlite3VdbeGetLastOp(v))->opcode==OP_Copy
108614108852
&& pOp->p1+pOp->p3+1==inReg
108615108853
&& pOp->p2+pOp->p3+1==target+i
108616108854
&& pOp->p5==0 /* The do-not-merge flag must be clear */
108617108855
){
108618108856
pOp->p3++;
@@ -109644,10 +109882,11 @@
109644109882
** fact is exploited for efficiency.
109645109883
*/
109646109884
SQLITE_PRIVATE int sqlite3ReferencesSrcList(Parse *pParse, Expr *pExpr, SrcList *pSrcList){
109647109885
Walker w;
109648109886
struct RefSrcList x;
109887
+ assert( pParse->db!=0 );
109649109888
memset(&w, 0, sizeof(w));
109650109889
memset(&x, 0, sizeof(x));
109651109890
w.xExprCallback = exprRefToSrcList;
109652109891
w.xSelectCallback = selectRefEnter;
109653109892
w.xSelectCallback2 = selectRefLeave;
@@ -109660,11 +109899,11 @@
109660109899
#ifndef SQLITE_OMIT_WINDOWFUNC
109661109900
if( ExprHasProperty(pExpr, EP_WinFunc) ){
109662109901
sqlite3WalkExpr(&w, pExpr->y.pWin->pFilter);
109663109902
}
109664109903
#endif
109665
- sqlite3DbFree(pParse->db, x.aiExclude);
109904
+ if( x.aiExclude ) sqlite3DbNNFreeNN(pParse->db, x.aiExclude);
109666109905
if( w.eCode & 0x01 ){
109667109906
return 1;
109668109907
}else if( w.eCode ){
109669109908
return 0;
109670109909
}else{
@@ -109691,21 +109930,22 @@
109691109930
){
109692109931
AggInfo *pAggInfo = pExpr->pAggInfo;
109693109932
int iAgg = pExpr->iAgg;
109694109933
Parse *pParse = pWalker->pParse;
109695109934
sqlite3 *db = pParse->db;
109696
- assert( pExpr->op==TK_AGG_COLUMN || pExpr->op==TK_AGG_FUNCTION );
109697
- if( pExpr->op==TK_AGG_COLUMN ){
109935
+ if( pExpr->op!=TK_AGG_FUNCTION ){
109936
+ assert( pExpr->op==TK_AGG_COLUMN || pExpr->op==TK_IF_NULL_ROW );
109698109937
assert( iAgg>=0 && iAgg<pAggInfo->nColumn );
109699109938
if( pAggInfo->aCol[iAgg].pCExpr==pExpr ){
109700109939
pExpr = sqlite3ExprDup(db, pExpr, 0);
109701109940
if( pExpr ){
109702109941
pAggInfo->aCol[iAgg].pCExpr = pExpr;
109703109942
sqlite3ExprDeferredDelete(pParse, pExpr);
109704109943
}
109705109944
}
109706109945
}else{
109946
+ assert( pExpr->op==TK_AGG_FUNCTION );
109707109947
assert( iAgg>=0 && iAgg<pAggInfo->nFunc );
109708109948
if( pAggInfo->aFunc[iAgg].pFExpr==pExpr ){
109709109949
pExpr = sqlite3ExprDup(db, pExpr, 0);
109710109950
if( pExpr ){
109711109951
pAggInfo->aFunc[iAgg].pFExpr = pExpr;
@@ -109772,14 +110012,16 @@
109772110012
SrcList *pSrcList = pNC->pSrcList;
109773110013
AggInfo *pAggInfo = pNC->uNC.pAggInfo;
109774110014
109775110015
assert( pNC->ncFlags & NC_UAggInfo );
109776110016
switch( pExpr->op ){
110017
+ case TK_IF_NULL_ROW:
109777110018
case TK_AGG_COLUMN:
109778110019
case TK_COLUMN: {
109779110020
testcase( pExpr->op==TK_AGG_COLUMN );
109780110021
testcase( pExpr->op==TK_COLUMN );
110022
+ testcase( pExpr->op==TK_IF_NULL_ROW );
109781110023
/* Check to see if the column is in one of the tables in the FROM
109782110024
** clause of the aggregate query */
109783110025
if( ALWAYS(pSrcList!=0) ){
109784110026
SrcItem *pItem = pSrcList->a;
109785110027
for(i=0; i<pSrcList->nSrc; i++, pItem++){
@@ -109793,12 +110035,14 @@
109793110035
** is not an entry there already.
109794110036
*/
109795110037
int k;
109796110038
pCol = pAggInfo->aCol;
109797110039
for(k=0; k<pAggInfo->nColumn; k++, pCol++){
109798
- if( pCol->iTable==pExpr->iTable &&
109799
- pCol->iColumn==pExpr->iColumn ){
110040
+ if( pCol->iTable==pExpr->iTable
110041
+ && pCol->iColumn==pExpr->iColumn
110042
+ && pExpr->op!=TK_IF_NULL_ROW
110043
+ ){
109800110044
break;
109801110045
}
109802110046
}
109803110047
if( (k>=pAggInfo->nColumn)
109804110048
&& (k = addAggInfoColumn(pParse->db, pAggInfo))>=0
@@ -109809,19 +110053,21 @@
109809110053
pCol->iTable = pExpr->iTable;
109810110054
pCol->iColumn = pExpr->iColumn;
109811110055
pCol->iMem = ++pParse->nMem;
109812110056
pCol->iSorterColumn = -1;
109813110057
pCol->pCExpr = pExpr;
109814
- if( pAggInfo->pGroupBy ){
110058
+ if( pAggInfo->pGroupBy && pExpr->op!=TK_IF_NULL_ROW ){
109815110059
int j, n;
109816110060
ExprList *pGB = pAggInfo->pGroupBy;
109817110061
struct ExprList_item *pTerm = pGB->a;
109818110062
n = pGB->nExpr;
109819110063
for(j=0; j<n; j++, pTerm++){
109820110064
Expr *pE = pTerm->pExpr;
109821
- if( pE->op==TK_COLUMN && pE->iTable==pExpr->iTable &&
109822
- pE->iColumn==pExpr->iColumn ){
110065
+ if( pE->op==TK_COLUMN
110066
+ && pE->iTable==pExpr->iTable
110067
+ && pE->iColumn==pExpr->iColumn
110068
+ ){
109823110069
pCol->iSorterColumn = j;
109824110070
break;
109825110071
}
109826110072
}
109827110073
}
@@ -109834,11 +110080,13 @@
109834110080
** Convert the pExpr to be a TK_AGG_COLUMN referring to that
109835110081
** pAggInfo->aCol[] entry.
109836110082
*/
109837110083
ExprSetVVAProperty(pExpr, EP_NoReduce);
109838110084
pExpr->pAggInfo = pAggInfo;
109839
- pExpr->op = TK_AGG_COLUMN;
110085
+ if( pExpr->op==TK_COLUMN ){
110086
+ pExpr->op = TK_AGG_COLUMN;
110087
+ }
109840110088
pExpr->iAgg = (i16)k;
109841110089
break;
109842110090
} /* endif pExpr->iTable==pItem->iCursor */
109843110091
} /* end loop over pSrcList */
109844110092
}
@@ -115256,10 +115504,11 @@
115256115504
** no VDBE code was generated.
115257115505
*/
115258115506
SQLITE_PRIVATE void sqlite3FinishCoding(Parse *pParse){
115259115507
sqlite3 *db;
115260115508
Vdbe *v;
115509
+ int iDb, i;
115261115510
115262115511
assert( pParse->pToplevel==0 );
115263115512
db = pParse->db;
115264115513
assert( db->pParse==pParse );
115265115514
if( pParse->nested ) return;
@@ -115285,11 +115534,10 @@
115285115534
|| sqlite3VdbeAssertMayAbort(v, pParse->mayAbort));
115286115535
if( v ){
115287115536
if( pParse->bReturning ){
115288115537
Returning *pReturning = pParse->u1.pReturning;
115289115538
int addrRewind;
115290
- int i;
115291115539
int reg;
115292115540
115293115541
if( pReturning->nRetCol ){
115294115542
sqlite3VdbeAddOp0(v, OP_FkCheck);
115295115543
addrRewind =
@@ -115322,80 +115570,73 @@
115322115570
** (Bit 0 is for main, bit 1 is for temp, and so forth.) Bits are
115323115571
** set for each database that is used. Generate code to start a
115324115572
** transaction on each used database and to verify the schema cookie
115325115573
** on each used database.
115326115574
*/
115327
- if( db->mallocFailed==0
115328
- && (DbMaskNonZero(pParse->cookieMask) || pParse->pConstExpr)
115329
- ){
115330
- int iDb, i;
115331
- assert( sqlite3VdbeGetOp(v, 0)->opcode==OP_Init );
115332
- sqlite3VdbeJumpHere(v, 0);
115333
- assert( db->nDb>0 );
115334
- iDb = 0;
115335
- do{
115336
- Schema *pSchema;
115337
- if( DbMaskTest(pParse->cookieMask, iDb)==0 ) continue;
115338
- sqlite3VdbeUsesBtree(v, iDb);
115339
- pSchema = db->aDb[iDb].pSchema;
115340
- sqlite3VdbeAddOp4Int(v,
115341
- OP_Transaction, /* Opcode */
115342
- iDb, /* P1 */
115343
- DbMaskTest(pParse->writeMask,iDb), /* P2 */
115344
- pSchema->schema_cookie, /* P3 */
115345
- pSchema->iGeneration /* P4 */
115346
- );
115347
- if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1);
115348
- VdbeComment((v,
115349
- "usesStmtJournal=%d", pParse->mayAbort && pParse->isMultiWrite));
115350
- }while( ++iDb<db->nDb );
115575
+ assert( pParse->nErr>0 || sqlite3VdbeGetOp(v, 0)->opcode==OP_Init );
115576
+ sqlite3VdbeJumpHere(v, 0);
115577
+ assert( db->nDb>0 );
115578
+ iDb = 0;
115579
+ do{
115580
+ Schema *pSchema;
115581
+ if( DbMaskTest(pParse->cookieMask, iDb)==0 ) continue;
115582
+ sqlite3VdbeUsesBtree(v, iDb);
115583
+ pSchema = db->aDb[iDb].pSchema;
115584
+ sqlite3VdbeAddOp4Int(v,
115585
+ OP_Transaction, /* Opcode */
115586
+ iDb, /* P1 */
115587
+ DbMaskTest(pParse->writeMask,iDb), /* P2 */
115588
+ pSchema->schema_cookie, /* P3 */
115589
+ pSchema->iGeneration /* P4 */
115590
+ );
115591
+ if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1);
115592
+ VdbeComment((v,
115593
+ "usesStmtJournal=%d", pParse->mayAbort && pParse->isMultiWrite));
115594
+ }while( ++iDb<db->nDb );
115351115595
#ifndef SQLITE_OMIT_VIRTUALTABLE
115352
- for(i=0; i<pParse->nVtabLock; i++){
115353
- char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
115354
- sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
115355
- }
115356
- pParse->nVtabLock = 0;
115596
+ for(i=0; i<pParse->nVtabLock; i++){
115597
+ char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
115598
+ sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
115599
+ }
115600
+ pParse->nVtabLock = 0;
115357115601
#endif
115358115602
115359
- /* Once all the cookies have been verified and transactions opened,
115360
- ** obtain the required table-locks. This is a no-op unless the
115361
- ** shared-cache feature is enabled.
115362
- */
115363
- codeTableLocks(pParse);
115364
-
115365
- /* Initialize any AUTOINCREMENT data structures required.
115366
- */
115367
- sqlite3AutoincrementBegin(pParse);
115368
-
115369
- /* Code constant expressions that where factored out of inner loops.
115370
- **
115371
- ** The pConstExpr list might also contain expressions that we simply
115372
- ** want to keep around until the Parse object is deleted. Such
115373
- ** expressions have iConstExprReg==0. Do not generate code for
115374
- ** those expressions, of course.
115375
- */
115376
- if( pParse->pConstExpr ){
115377
- ExprList *pEL = pParse->pConstExpr;
115378
- pParse->okConstFactor = 0;
115379
- for(i=0; i<pEL->nExpr; i++){
115380
- int iReg = pEL->a[i].u.iConstExprReg;
115381
- if( iReg>0 ){
115382
- sqlite3ExprCode(pParse, pEL->a[i].pExpr, iReg);
115383
- }
115384
- }
115385
- }
115386
-
115387
- if( pParse->bReturning ){
115388
- Returning *pRet = pParse->u1.pReturning;
115389
- if( pRet->nRetCol ){
115390
- sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
115391
- }
115392
- }
115393
-
115394
- /* Finally, jump back to the beginning of the executable code. */
115395
- sqlite3VdbeGoto(v, 1);
115396
- }
115603
+ /* Once all the cookies have been verified and transactions opened,
115604
+ ** obtain the required table-locks. This is a no-op unless the
115605
+ ** shared-cache feature is enabled.
115606
+ */
115607
+ codeTableLocks(pParse);
115608
+
115609
+ /* Initialize any AUTOINCREMENT data structures required.
115610
+ */
115611
+ sqlite3AutoincrementBegin(pParse);
115612
+
115613
+ /* Code constant expressions that where factored out of inner loops.
115614
+ **
115615
+ ** The pConstExpr list might also contain expressions that we simply
115616
+ ** want to keep around until the Parse object is deleted. Such
115617
+ ** expressions have iConstExprReg==0. Do not generate code for
115618
+ ** those expressions, of course.
115619
+ */
115620
+ if( pParse->pConstExpr ){
115621
+ ExprList *pEL = pParse->pConstExpr;
115622
+ pParse->okConstFactor = 0;
115623
+ for(i=0; i<pEL->nExpr; i++){
115624
+ int iReg = pEL->a[i].u.iConstExprReg;
115625
+ sqlite3ExprCode(pParse, pEL->a[i].pExpr, iReg);
115626
+ }
115627
+ }
115628
+
115629
+ if( pParse->bReturning ){
115630
+ Returning *pRet = pParse->u1.pReturning;
115631
+ if( pRet->nRetCol ){
115632
+ sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
115633
+ }
115634
+ }
115635
+
115636
+ /* Finally, jump back to the beginning of the executable code. */
115637
+ sqlite3VdbeGoto(v, 1);
115397115638
}
115398115639
115399115640
/* Get the VDBE program ready for execution
115400115641
*/
115401115642
assert( v!=0 || pParse->nErr );
@@ -115898,20 +116139,21 @@
115898116139
*/
115899116140
SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3 *db, Table *pTable){
115900116141
int i;
115901116142
Column *pCol;
115902116143
assert( pTable!=0 );
116144
+ assert( db!=0 );
115903116145
if( (pCol = pTable->aCol)!=0 ){
115904116146
for(i=0; i<pTable->nCol; i++, pCol++){
115905116147
assert( pCol->zCnName==0 || pCol->hName==sqlite3StrIHash(pCol->zCnName) );
115906116148
sqlite3DbFree(db, pCol->zCnName);
115907116149
}
115908
- sqlite3DbFree(db, pTable->aCol);
116150
+ sqlite3DbNNFreeNN(db, pTable->aCol);
115909116151
if( IsOrdinaryTable(pTable) ){
115910116152
sqlite3ExprListDelete(db, pTable->u.tab.pDfltList);
115911116153
}
115912
- if( db==0 || db->pnBytesFreed==0 ){
116154
+ if( db->pnBytesFreed==0 ){
115913116155
pTable->aCol = 0;
115914116156
pTable->nCol = 0;
115915116157
if( IsOrdinaryTable(pTable) ){
115916116158
pTable->u.tab.pDfltList = 0;
115917116159
}
@@ -115944,21 +116186,22 @@
115944116186
**
115945116187
** If malloc has already failed, it may be that it failed while allocating
115946116188
** a Table object that was going to be marked ephemeral. So do not check
115947116189
** that no lookaside memory is used in this case either. */
115948116190
int nLookaside = 0;
115949
- if( db && !db->mallocFailed && (pTable->tabFlags & TF_Ephemeral)==0 ){
116191
+ assert( db!=0 );
116192
+ if( !db->mallocFailed && (pTable->tabFlags & TF_Ephemeral)==0 ){
115950116193
nLookaside = sqlite3LookasideUsed(db, 0);
115951116194
}
115952116195
#endif
115953116196
115954116197
/* Delete all indices associated with this table. */
115955116198
for(pIndex = pTable->pIndex; pIndex; pIndex=pNext){
115956116199
pNext = pIndex->pNext;
115957116200
assert( pIndex->pSchema==pTable->pSchema
115958116201
|| (IsVirtual(pTable) && pIndex->idxType!=SQLITE_IDXTYPE_APPDEF) );
115959
- if( (db==0 || db->pnBytesFreed==0) && !IsVirtual(pTable) ){
116202
+ if( db->pnBytesFreed==0 && !IsVirtual(pTable) ){
115960116203
char *zName = pIndex->zName;
115961116204
TESTONLY ( Index *pOld = ) sqlite3HashInsert(
115962116205
&pIndex->pSchema->idxHash, zName, 0
115963116206
);
115964116207
assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
@@ -115991,12 +116234,13 @@
115991116234
/* Verify that no lookaside memory was used by schema tables */
115992116235
assert( nLookaside==0 || nLookaside==sqlite3LookasideUsed(db,0) );
115993116236
}
115994116237
SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
115995116238
/* Do not delete the table until the reference count reaches zero. */
116239
+ assert( db!=0 );
115996116240
if( !pTable ) return;
115997
- if( ((!db || db->pnBytesFreed==0) && (--pTable->nTabRef)>0) ) return;
116241
+ if( db->pnBytesFreed==0 && (--pTable->nTabRef)>0 ) return;
115998116242
deleteTable(db, pTable);
115999116243
}
116000116244
116001116245
116002116246
/*
@@ -118165,11 +118409,11 @@
118165118409
/*
118166118410
** The Table structure pTable is really a VIEW. Fill in the names of
118167118411
** the columns of the view in the pTable structure. Return the number
118168118412
** of errors. If an error is seen leave an error message in pParse->zErrMsg.
118169118413
*/
118170
-SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
118414
+static SQLITE_NOINLINE int viewGetColumnNames(Parse *pParse, Table *pTable){
118171118415
Table *pSelTab; /* A fake table from which we get the result set */
118172118416
Select *pSel; /* Copy of the SELECT that implements the view */
118173118417
int nErr = 0; /* Number of errors encountered */
118174118418
sqlite3 *db = pParse->db; /* Database connection for malloc errors */
118175118419
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -118190,13 +118434,14 @@
118190118434
}
118191118435
#endif
118192118436
118193118437
#ifndef SQLITE_OMIT_VIEW
118194118438
/* A positive nCol means the columns names for this view are
118195
- ** already known.
118439
+ ** already known. This routine is not called unless either the
118440
+ ** table is virtual or nCol is zero.
118196118441
*/
118197
- if( pTable->nCol>0 ) return 0;
118442
+ assert( pTable->nCol<=0 );
118198118443
118199118444
/* A negative nCol is a special marker meaning that we are currently
118200118445
** trying to compute the column names. If we enter this routine with
118201118446
** a negative nCol, it means two or more views form a loop, like this:
118202118447
**
@@ -118287,10 +118532,15 @@
118287118532
if( db->mallocFailed ){
118288118533
sqlite3DeleteColumnNames(db, pTable);
118289118534
}
118290118535
#endif /* SQLITE_OMIT_VIEW */
118291118536
return nErr;
118537
+}
118538
+SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
118539
+ assert( pTable!=0 );
118540
+ if( !IsVirtual(pTable) && pTable->nCol>0 ) return 0;
118541
+ return viewGetColumnNames(pParse, pTable);
118292118542
}
118293118543
#endif /* !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) */
118294118544
118295118545
#ifndef SQLITE_OMIT_VIEW
118296118546
/*
@@ -119153,11 +119403,11 @@
119153119403
if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName,"index",pTab->zName) ){
119154119404
goto exit_create_index;
119155119405
}
119156119406
if( !IN_RENAME_OBJECT ){
119157119407
if( !db->init.busy ){
119158
- if( sqlite3FindTable(db, zName, 0)!=0 ){
119408
+ if( sqlite3FindTable(db, zName, pDb->zDbSName)!=0 ){
119159119409
sqlite3ErrorMsg(pParse, "there is already a table named %s", zName);
119160119410
goto exit_create_index;
119161119411
}
119162119412
}
119163119413
if( sqlite3FindIndex(db, zName, pDb->zDbSName)!=0 ){
@@ -119806,16 +120056,17 @@
119806120056
/*
119807120057
** Delete an IdList.
119808120058
*/
119809120059
SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3 *db, IdList *pList){
119810120060
int i;
120061
+ assert( db!=0 );
119811120062
if( pList==0 ) return;
119812120063
assert( pList->eU4!=EU4_EXPR ); /* EU4_EXPR mode is not currently used */
119813120064
for(i=0; i<pList->nId; i++){
119814120065
sqlite3DbFree(db, pList->a[i].zName);
119815120066
}
119816
- sqlite3DbFreeNN(db, pList);
120067
+ sqlite3DbNNFreeNN(db, pList);
119817120068
}
119818120069
119819120070
/*
119820120071
** Return the index in pList of the identifier named zId. Return -1
119821120072
** if not found.
@@ -120014,15 +120265,16 @@
120014120265
** Delete an entire SrcList including all its substructure.
120015120266
*/
120016120267
SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3 *db, SrcList *pList){
120017120268
int i;
120018120269
SrcItem *pItem;
120270
+ assert( db!=0 );
120019120271
if( pList==0 ) return;
120020120272
for(pItem=pList->a, i=0; i<pList->nSrc; i++, pItem++){
120021
- if( pItem->zDatabase ) sqlite3DbFreeNN(db, pItem->zDatabase);
120022
- sqlite3DbFree(db, pItem->zName);
120023
- if( pItem->zAlias ) sqlite3DbFreeNN(db, pItem->zAlias);
120273
+ if( pItem->zDatabase ) sqlite3DbNNFreeNN(db, pItem->zDatabase);
120274
+ if( pItem->zName ) sqlite3DbNNFreeNN(db, pItem->zName);
120275
+ if( pItem->zAlias ) sqlite3DbNNFreeNN(db, pItem->zAlias);
120024120276
if( pItem->fg.isIndexedBy ) sqlite3DbFree(db, pItem->u1.zIndexedBy);
120025120277
if( pItem->fg.isTabFunc ) sqlite3ExprListDelete(db, pItem->u1.pFuncArg);
120026120278
sqlite3DeleteTable(db, pItem->pTab);
120027120279
if( pItem->pSelect ) sqlite3SelectDelete(db, pItem->pSelect);
120028120280
if( pItem->fg.isUsing ){
@@ -120029,11 +120281,11 @@
120029120281
sqlite3IdListDelete(db, pItem->u3.pUsing);
120030120282
}else if( pItem->u3.pOn ){
120031120283
sqlite3ExprDelete(db, pItem->u3.pOn);
120032120284
}
120033120285
}
120034
- sqlite3DbFreeNN(db, pList);
120286
+ sqlite3DbNNFreeNN(db, pList);
120035120287
}
120036120288
120037120289
/*
120038120290
** This routine is called by the parser to add a new term to the
120039120291
** end of a growing FROM clause. The "p" parameter is the part of
@@ -121281,23 +121533,25 @@
121281121533
SQLITE_PRIVATE void sqlite3SchemaClear(void *p){
121282121534
Hash temp1;
121283121535
Hash temp2;
121284121536
HashElem *pElem;
121285121537
Schema *pSchema = (Schema *)p;
121538
+ sqlite3 xdb;
121286121539
121540
+ memset(&xdb, 0, sizeof(xdb));
121287121541
temp1 = pSchema->tblHash;
121288121542
temp2 = pSchema->trigHash;
121289121543
sqlite3HashInit(&pSchema->trigHash);
121290121544
sqlite3HashClear(&pSchema->idxHash);
121291121545
for(pElem=sqliteHashFirst(&temp2); pElem; pElem=sqliteHashNext(pElem)){
121292
- sqlite3DeleteTrigger(0, (Trigger*)sqliteHashData(pElem));
121546
+ sqlite3DeleteTrigger(&xdb, (Trigger*)sqliteHashData(pElem));
121293121547
}
121294121548
sqlite3HashClear(&temp2);
121295121549
sqlite3HashInit(&pSchema->tblHash);
121296121550
for(pElem=sqliteHashFirst(&temp1); pElem; pElem=sqliteHashNext(pElem)){
121297121551
Table *pTab = sqliteHashData(pElem);
121298
- sqlite3DeleteTable(0, pTab);
121552
+ sqlite3DeleteTable(&xdb, pTab);
121299121553
}
121300121554
sqlite3HashClear(&temp1);
121301121555
sqlite3HashClear(&pSchema->fkeyHash);
121302121556
pSchema->pSeqTab = 0;
121303121557
if( pSchema->schemaFlags & DB_SchemaLoaded ){
@@ -121392,22 +121646,46 @@
121392121646
** A table is read-only if any of the following are true:
121393121647
**
121394121648
** 1) It is a virtual table and no implementation of the xUpdate method
121395121649
** has been provided
121396121650
**
121397
-** 2) It is a system table (i.e. sqlite_schema), this call is not
121651
+** 2) A trigger is currently being coded and the table is a virtual table
121652
+** that is SQLITE_VTAB_DIRECTONLY or if PRAGMA trusted_schema=OFF and
121653
+** the table is not SQLITE_VTAB_INNOCUOUS.
121654
+**
121655
+** 3) It is a system table (i.e. sqlite_schema), this call is not
121398121656
** part of a nested parse and writable_schema pragma has not
121399121657
** been specified
121400121658
**
121401
-** 3) The table is a shadow table, the database connection is in
121659
+** 4) The table is a shadow table, the database connection is in
121402121660
** defensive mode, and the current sqlite3_prepare()
121403121661
** is for a top-level SQL statement.
121404121662
*/
121663
+static int vtabIsReadOnly(Parse *pParse, Table *pTab){
121664
+ if( sqlite3GetVTable(pParse->db, pTab)->pMod->pModule->xUpdate==0 ){
121665
+ return 1;
121666
+ }
121667
+
121668
+ /* Within triggers:
121669
+ ** * Do not allow DELETE, INSERT, or UPDATE of SQLITE_VTAB_DIRECTONLY
121670
+ ** virtual tables
121671
+ ** * Only allow DELETE, INSERT, or UPDATE of non-SQLITE_VTAB_INNOCUOUS
121672
+ ** virtual tables if PRAGMA trusted_schema=ON.
121673
+ */
121674
+ if( pParse->pToplevel!=0
121675
+ && pTab->u.vtab.p->eVtabRisk >
121676
+ ((pParse->db->flags & SQLITE_TrustedSchema)!=0)
121677
+ ){
121678
+ sqlite3ErrorMsg(pParse, "unsafe use of virtual table \"%s\"",
121679
+ pTab->zName);
121680
+ }
121681
+ return 0;
121682
+}
121405121683
static int tabIsReadOnly(Parse *pParse, Table *pTab){
121406121684
sqlite3 *db;
121407121685
if( IsVirtual(pTab) ){
121408
- return sqlite3GetVTable(pParse->db, pTab)->pMod->pModule->xUpdate==0;
121686
+ return vtabIsReadOnly(pParse, pTab);
121409121687
}
121410121688
if( (pTab->tabFlags & (TF_Readonly|TF_Shadow))==0 ) return 0;
121411121689
db = pParse->db;
121412121690
if( (pTab->tabFlags & TF_Readonly)!=0 ){
121413121691
return sqlite3WritableSchema(db)==0 && pParse->nested==0;
@@ -121415,13 +121693,15 @@
121415121693
assert( pTab->tabFlags & TF_Shadow );
121416121694
return sqlite3ReadOnlyShadowTables(db);
121417121695
}
121418121696
121419121697
/*
121420
-** Check to make sure the given table is writable. If it is not
121421
-** writable, generate an error message and return 1. If it is
121422
-** writable return 0;
121698
+** Check to make sure the given table is writable.
121699
+**
121700
+** If pTab is not writable -> generate an error message and return 1.
121701
+** If pTab is writable but other errors have occurred -> return 1.
121702
+** If pTab is writable and no prior errors -> return 0;
121423121703
*/
121424121704
SQLITE_PRIVATE int sqlite3IsReadOnly(Parse *pParse, Table *pTab, int viewOk){
121425121705
if( tabIsReadOnly(pParse, pTab) ){
121426121706
sqlite3ErrorMsg(pParse, "table %s may not be modified", pTab->zName);
121427121707
return 1;
@@ -121778,13 +122058,14 @@
121778122058
sqlite3VdbeAddOp4(v, OP_Clear, pTab->tnum, iDb, memCnt ? memCnt : -1,
121779122059
pTab->zName, P4_STATIC);
121780122060
}
121781122061
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
121782122062
assert( pIdx->pSchema==pTab->pSchema );
121783
- sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
121784122063
if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
121785
- sqlite3VdbeChangeP3(v, -1, memCnt ? memCnt : -1);
122064
+ sqlite3VdbeAddOp3(v, OP_Clear, pIdx->tnum, iDb, memCnt ? memCnt : -1);
122065
+ }else{
122066
+ sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
121786122067
}
121787122068
}
121788122069
}else
121789122070
#endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
121790122071
{
@@ -121980,11 +122261,11 @@
121980122261
sqlite3ExprDelete(db, pWhere);
121981122262
#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT)
121982122263
sqlite3ExprListDelete(db, pOrderBy);
121983122264
sqlite3ExprDelete(db, pLimit);
121984122265
#endif
121985
- sqlite3DbFree(db, aToOpen);
122266
+ if( aToOpen ) sqlite3DbNNFreeNN(db, aToOpen);
121986122267
return;
121987122268
}
121988122269
/* Make sure "isView" and other macros defined above are undefined. Otherwise
121989122270
** they may interfere with compilation of other functions in this file
121990122271
** (or in another file, if this file becomes part of the amalgamation). */
@@ -126148,15 +126429,16 @@
126148126429
SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
126149126430
FKey *pFKey; /* Iterator variable */
126150126431
FKey *pNext; /* Copy of pFKey->pNextFrom */
126151126432
126152126433
assert( IsOrdinaryTable(pTab) );
126434
+ assert( db!=0 );
126153126435
for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pNext){
126154126436
assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
126155126437
126156126438
/* Remove the FK from the fkeyHash hash table. */
126157
- if( !db || db->pnBytesFreed==0 ){
126439
+ if( db->pnBytesFreed==0 ){
126158126440
if( pFKey->pPrevTo ){
126159126441
pFKey->pPrevTo->pNextTo = pFKey->pNextTo;
126160126442
}else{
126161126443
void *p = (void *)pFKey->pNextTo;
126162126444
const char *z = (p ? pFKey->pNextTo->zTo : pFKey->zTo);
@@ -126345,11 +126627,11 @@
126345126627
/* Move the previous opcode (which should be OP_MakeRecord) forward
126346126628
** by one slot and insert a new OP_TypeCheck where the current
126347126629
** OP_MakeRecord is found */
126348126630
VdbeOp *pPrev;
126349126631
sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
126350
- pPrev = sqlite3VdbeGetOp(v, -1);
126632
+ pPrev = sqlite3VdbeGetLastOp(v);
126351126633
assert( pPrev!=0 );
126352126634
assert( pPrev->opcode==OP_MakeRecord || sqlite3VdbeDb(v)->mallocFailed );
126353126635
pPrev->opcode = OP_TypeCheck;
126354126636
sqlite3VdbeAddOp3(v, OP_MakeRecord, pPrev->p1, pPrev->p2, pPrev->p3);
126355126637
}else{
@@ -126383,11 +126665,11 @@
126383126665
i = sqlite3Strlen30NN(zColAff);
126384126666
if( i ){
126385126667
if( iReg ){
126386126668
sqlite3VdbeAddOp4(v, OP_Affinity, iReg, i, 0, zColAff, i);
126387126669
}else{
126388
- assert( sqlite3VdbeGetOp(v, -1)->opcode==OP_MakeRecord
126670
+ assert( sqlite3VdbeGetLastOp(v)->opcode==OP_MakeRecord
126389126671
|| sqlite3VdbeDb(v)->mallocFailed );
126390126672
sqlite3VdbeChangeP4(v, -1, zColAff, i);
126391126673
}
126392126674
}
126393126675
}
@@ -126469,11 +126751,11 @@
126469126751
/* Before computing generated columns, first go through and make sure
126470126752
** that appropriate affinity has been applied to the regular columns
126471126753
*/
126472126754
sqlite3TableAffinity(pParse->pVdbe, pTab, iRegStore);
126473126755
if( (pTab->tabFlags & TF_HasStored)!=0 ){
126474
- pOp = sqlite3VdbeGetOp(pParse->pVdbe,-1);
126756
+ pOp = sqlite3VdbeGetLastOp(pParse->pVdbe);
126475126757
if( pOp->opcode==OP_Affinity ){
126476126758
/* Change the OP_Affinity argument to '@' (NONE) for all stored
126477126759
** columns. '@' is the no-op affinity and those columns have not
126478126760
** yet been computed. */
126479126761
int ii, jj;
@@ -127375,11 +127657,16 @@
127375127657
}else if( pSelect ){
127376127658
if( regFromSelect!=regData ){
127377127659
sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+k, iRegStore);
127378127660
}
127379127661
}else{
127380
- sqlite3ExprCode(pParse, pList->a[k].pExpr, iRegStore);
127662
+ Expr *pX = pList->a[k].pExpr;
127663
+ int y = sqlite3ExprCodeTarget(pParse, pX, iRegStore);
127664
+ if( y!=iRegStore ){
127665
+ sqlite3VdbeAddOp2(v,
127666
+ ExprHasProperty(pX, EP_Subquery) ? OP_Copy : OP_SCopy, y, iRegStore);
127667
+ }
127381127668
}
127382127669
}
127383127670
127384127671
127385127672
/* Run the BEFORE and INSTEAD OF triggers, if there are any
@@ -127512,11 +127799,13 @@
127512127799
int isReplace = 0;/* Set to true if constraints may cause a replace */
127513127800
int bUseSeek; /* True to use OPFLAG_SEEKRESULT */
127514127801
sqlite3GenerateConstraintChecks(pParse, pTab, aRegIdx, iDataCur, iIdxCur,
127515127802
regIns, 0, ipkColumn>=0, onError, endOfLoop, &isReplace, 0, pUpsert
127516127803
);
127517
- sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0);
127804
+ if( db->flags & SQLITE_ForeignKeys ){
127805
+ sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0);
127806
+ }
127518127807
127519127808
/* Set the OPFLAG_USESEEKRESULT flag if either (a) there are no REPLACE
127520127809
** constraints or (b) there are no triggers and this table is not a
127521127810
** parent table in a foreign key constraint. It is safe to set the
127522127811
** flag in the second case as if any REPLACE constraint is hit, an
@@ -127596,11 +127885,11 @@
127596127885
sqlite3SrcListDelete(db, pTabList);
127597127886
sqlite3ExprListDelete(db, pList);
127598127887
sqlite3UpsertDelete(db, pUpsert);
127599127888
sqlite3SelectDelete(db, pSelect);
127600127889
sqlite3IdListDelete(db, pColumn);
127601
- sqlite3DbFree(db, aRegIdx);
127890
+ if( aRegIdx ) sqlite3DbNNFreeNN(db, aRegIdx);
127602127891
}
127603127892
127604127893
/* Make sure "isView" and other macros defined above are undefined. Otherwise
127605127894
** they may interfere with compilation of other functions in this file
127606127895
** (or in another file, if this file becomes part of the amalgamation). */
@@ -132702,19 +132991,21 @@
132702132991
** Setting to a null string reverts to the default temporary directory search.
132703132992
** If temporary directory is changed, then invalidateTempStorage.
132704132993
**
132705132994
*/
132706132995
case PragTyp_TEMP_STORE_DIRECTORY: {
132996
+ sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
132707132997
if( !zRight ){
132708132998
returnSingleText(v, sqlite3_temp_directory);
132709132999
}else{
132710133000
#ifndef SQLITE_OMIT_WSD
132711133001
if( zRight[0] ){
132712133002
int res;
132713133003
rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
132714133004
if( rc!=SQLITE_OK || res==0 ){
132715133005
sqlite3ErrorMsg(pParse, "not a writable directory");
133006
+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
132716133007
goto pragma_out;
132717133008
}
132718133009
}
132719133010
if( SQLITE_TEMP_STORE==0
132720133011
|| (SQLITE_TEMP_STORE==1 && db->temp_store<=1)
@@ -132728,10 +133019,11 @@
132728133019
}else{
132729133020
sqlite3_temp_directory = 0;
132730133021
}
132731133022
#endif /* SQLITE_OMIT_WSD */
132732133023
}
133024
+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
132733133025
break;
132734133026
}
132735133027
132736133028
#if SQLITE_OS_WIN
132737133029
/*
@@ -132746,19 +133038,21 @@
132746133038
** process. Database file specified with an absolute path are not impacted
132747133039
** by this setting, regardless of its value.
132748133040
**
132749133041
*/
132750133042
case PragTyp_DATA_STORE_DIRECTORY: {
133043
+ sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
132751133044
if( !zRight ){
132752133045
returnSingleText(v, sqlite3_data_directory);
132753133046
}else{
132754133047
#ifndef SQLITE_OMIT_WSD
132755133048
if( zRight[0] ){
132756133049
int res;
132757133050
rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
132758133051
if( rc!=SQLITE_OK || res==0 ){
132759133052
sqlite3ErrorMsg(pParse, "not a writable directory");
133053
+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
132760133054
goto pragma_out;
132761133055
}
132762133056
}
132763133057
sqlite3_free(sqlite3_data_directory);
132764133058
if( zRight[0] ){
@@ -132766,10 +133060,11 @@
132766133060
}else{
132767133061
sqlite3_data_directory = 0;
132768133062
}
132769133063
#endif /* SQLITE_OMIT_WSD */
132770133064
}
133065
+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
132771133066
break;
132772133067
}
132773133068
#endif
132774133069
132775133070
#if SQLITE_ENABLE_LOCKING_STYLE
@@ -133479,19 +133774,27 @@
133479133774
/* Make sure all the indices are constructed correctly.
133480133775
*/
133481133776
for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
133482133777
Table *pTab = sqliteHashData(x);
133483133778
Index *pIdx, *pPk;
133484
- Index *pPrior = 0;
133779
+ Index *pPrior = 0; /* Previous index */
133485133780
int loopTop;
133486133781
int iDataCur, iIdxCur;
133487133782
int r1 = -1;
133488133783
int bStrict;
133784
+ int r2; /* Previous key for WITHOUT ROWID tables */
133489133785
133490133786
if( !IsOrdinaryTable(pTab) ) continue;
133491133787
if( pObjTab && pObjTab!=pTab ) continue;
133492
- pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
133788
+ if( isQuick || HasRowid(pTab) ){
133789
+ pPk = 0;
133790
+ r2 = 0;
133791
+ }else{
133792
+ pPk = sqlite3PrimaryKeyIndex(pTab);
133793
+ r2 = sqlite3GetTempRange(pParse, pPk->nKeyCol);
133794
+ sqlite3VdbeAddOp3(v, OP_Null, 1, r2, r2+pPk->nKeyCol-1);
133795
+ }
133493133796
sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
133494133797
1, 0, &iDataCur, &iIdxCur);
133495133798
/* reg[7] counts the number of entries in the table.
133496133799
** reg[8+i] counts the number of entries in the i-th index
133497133800
*/
@@ -133506,10 +133809,28 @@
133506133809
if( !isQuick ){
133507133810
/* Sanity check on record header decoding */
133508133811
sqlite3VdbeAddOp3(v, OP_Column, iDataCur, pTab->nNVCol-1,3);
133509133812
sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
133510133813
VdbeComment((v, "(right-most column)"));
133814
+ if( pPk ){
133815
+ /* Verify WITHOUT ROWID keys are in ascending order */
133816
+ int a1;
133817
+ char *zErr;
133818
+ a1 = sqlite3VdbeAddOp4Int(v, OP_IdxGT, iDataCur, 0,r2,pPk->nKeyCol);
133819
+ VdbeCoverage(v);
133820
+ sqlite3VdbeAddOp1(v, OP_IsNull, r2); VdbeCoverage(v);
133821
+ zErr = sqlite3MPrintf(db,
133822
+ "row not in PRIMARY KEY order for %s",
133823
+ pTab->zName);
133824
+ sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
133825
+ integrityCheckResultRow(v);
133826
+ sqlite3VdbeJumpHere(v, a1);
133827
+ sqlite3VdbeJumpHere(v, a1+1);
133828
+ for(j=0; j<pPk->nKeyCol; j++){
133829
+ sqlite3ExprCodeLoadIndexColumn(pParse, pPk, iDataCur, j, r2+j);
133830
+ }
133831
+ }
133511133832
}
133512133833
/* Verify that all NOT NULL columns really are NOT NULL. At the
133513133834
** same time verify the type of the content of STRICT tables */
133514133835
bStrict = (pTab->tabFlags & TF_Strict)!=0;
133515133836
for(j=0; j<pTab->nCol; j++){
@@ -133518,11 +133839,11 @@
133518133839
int doError, jmp2;
133519133840
if( j==pTab->iPKey ) continue;
133520133841
if( pCol->notNull==0 && !bStrict ) continue;
133521133842
doError = bStrict ? sqlite3VdbeMakeLabel(pParse) : 0;
133522133843
sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, j, 3);
133523
- if( sqlite3VdbeGetOp(v,-1)->opcode==OP_Column ){
133844
+ if( sqlite3VdbeGetLastOp(v)->opcode==OP_Column ){
133524133845
sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
133525133846
}
133526133847
if( pCol->notNull ){
133527133848
jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v);
133528133849
zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
@@ -133533,13 +133854,11 @@
133533133854
}else{
133534133855
integrityCheckResultRow(v);
133535133856
}
133536133857
sqlite3VdbeJumpHere(v, jmp2);
133537133858
}
133538
- if( (pTab->tabFlags & TF_Strict)!=0
133539
- && pCol->eCType!=COLTYPE_ANY
133540
- ){
133859
+ if( bStrict && pCol->eCType!=COLTYPE_ANY ){
133541133860
jmp2 = sqlite3VdbeAddOp3(v, OP_IsNullOrType, 3, 0,
133542133861
sqlite3StdTypeMap[pCol->eCType-1]);
133543133862
VdbeCoverage(v);
133544133863
zErr = sqlite3MPrintf(db, "non-%s value in %s.%s",
133545133864
sqlite3StdType[pCol->eCType-1],
@@ -133634,10 +133953,13 @@
133634133953
sqlite3VdbeLoadString(v, 4, pIdx->zName);
133635133954
sqlite3VdbeAddOp3(v, OP_Concat, 4, 2, 3);
133636133955
integrityCheckResultRow(v);
133637133956
sqlite3VdbeJumpHere(v, addr);
133638133957
}
133958
+ if( pPk ){
133959
+ sqlite3ReleaseTempRange(pParse, r2, pPk->nKeyCol);
133960
+ }
133639133961
}
133640133962
}
133641133963
}
133642133964
{
133643133965
static const int iLn = VDBE_OFFSET_LINENO(2);
@@ -135032,19 +135354,19 @@
135032135354
sqlite3 *db = pParse->db;
135033135355
assert( db!=0 );
135034135356
assert( db->pParse==pParse );
135035135357
assert( pParse->nested==0 );
135036135358
#ifndef SQLITE_OMIT_SHARED_CACHE
135037
- sqlite3DbFree(db, pParse->aTableLock);
135359
+ if( pParse->aTableLock ) sqlite3DbNNFreeNN(db, pParse->aTableLock);
135038135360
#endif
135039135361
while( pParse->pCleanup ){
135040135362
ParseCleanup *pCleanup = pParse->pCleanup;
135041135363
pParse->pCleanup = pCleanup->pNext;
135042135364
pCleanup->xCleanup(db, pCleanup->pPtr);
135043
- sqlite3DbFreeNN(db, pCleanup);
135365
+ sqlite3DbNNFreeNN(db, pCleanup);
135044135366
}
135045
- sqlite3DbFree(db, pParse->aLabel);
135367
+ if( pParse->aLabel ) sqlite3DbNNFreeNN(db, pParse->aLabel);
135046135368
if( pParse->pConstExpr ){
135047135369
sqlite3ExprListDelete(db, pParse->pConstExpr);
135048135370
}
135049135371
assert( db->lookaside.bDisable >= pParse->disableLookaside );
135050135372
db->lookaside.bDisable -= pParse->disableLookaside;
@@ -135599,10 +135921,11 @@
135599135921
**
135600135922
** If bFree==1, call sqlite3DbFree() on the p object.
135601135923
** If bFree==0, Leave the first Select object unfreed
135602135924
*/
135603135925
static void clearSelect(sqlite3 *db, Select *p, int bFree){
135926
+ assert( db!=0 );
135604135927
while( p ){
135605135928
Select *pPrior = p->pPrior;
135606135929
sqlite3ExprListDelete(db, p->pEList);
135607135930
sqlite3SrcListDelete(db, p->pSrc);
135608135931
sqlite3ExprDelete(db, p->pWhere);
@@ -135618,11 +135941,11 @@
135618135941
while( p->pWin ){
135619135942
assert( p->pWin->ppThis==&p->pWin );
135620135943
sqlite3WindowUnlinkFromSelect(p->pWin);
135621135944
}
135622135945
#endif
135623
- if( bFree ) sqlite3DbFreeNN(db, p);
135946
+ if( bFree ) sqlite3DbNNFreeNN(db, p);
135624135947
p = pPrior;
135625135948
bFree = 1;
135626135949
}
135627135950
}
135628135951
@@ -137024,13 +137347,14 @@
137024137347
/*
137025137348
** Deallocate a KeyInfo object
137026137349
*/
137027137350
SQLITE_PRIVATE void sqlite3KeyInfoUnref(KeyInfo *p){
137028137351
if( p ){
137352
+ assert( p->db!=0 );
137029137353
assert( p->nRef>0 );
137030137354
p->nRef--;
137031
- if( p->nRef==0 ) sqlite3DbFreeNN(p->db, p);
137355
+ if( p->nRef==0 ) sqlite3DbNNFreeNN(p->db, p);
137032137356
}
137033137357
}
137034137358
137035137359
/*
137036137360
** Make a new pointer to a KeyInfo object
@@ -137211,18 +137535,21 @@
137211137535
sqlite3VdbeAddOp3(v, OP_OpenPseudo, iSortTab, regSortOut,
137212137536
nKey+1+nColumn+nRefKey);
137213137537
if( addrOnce ) sqlite3VdbeJumpHere(v, addrOnce);
137214137538
addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
137215137539
VdbeCoverage(v);
137216
- codeOffset(v, p->iOffset, addrContinue);
137540
+ assert( p->iLimit==0 && p->iOffset==0 );
137217137541
sqlite3VdbeAddOp3(v, OP_SorterData, iTab, regSortOut, iSortTab);
137218137542
bSeq = 0;
137219137543
}else{
137220137544
addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v);
137221137545
codeOffset(v, p->iOffset, addrContinue);
137222137546
iSortTab = iTab;
137223137547
bSeq = 1;
137548
+ if( p->iOffset>0 ){
137549
+ sqlite3VdbeAddOp2(v, OP_AddImm, p->iLimit, -1);
137550
+ }
137224137551
}
137225137552
for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){
137226137553
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
137227137554
if( aOutEx[i].fg.bSorterRef ) continue;
137228137555
#endif
@@ -137343,13 +137670,10 @@
137343137670
137344137671
/*
137345137672
** Return a pointer to a string containing the 'declaration type' of the
137346137673
** expression pExpr. The string may be treated as static by the caller.
137347137674
**
137348
-** Also try to estimate the size of the returned value and return that
137349
-** result in *pEstWidth.
137350
-**
137351137675
** The declaration type is the exact datatype definition extracted from the
137352137676
** original CREATE TABLE statement if the expression is a column. The
137353137677
** declaration type for a ROWID field is INTEGER. Exactly when an expression
137354137678
** is considered a column can be complex in the presence of subqueries. The
137355137679
** result-set expression in all of the following SELECT statements is
@@ -139211,14 +139535,15 @@
139211139535
139212139536
/* Jump to the this point in order to terminate the query.
139213139537
*/
139214139538
sqlite3VdbeResolveLabel(v, labelEnd);
139215139539
139216
- /* Reassembly the compound query so that it will be freed correctly
139540
+ /* Reassemble the compound query so that it will be freed correctly
139217139541
** by the calling function */
139218139542
if( pSplit->pPrior ){
139219
- sqlite3SelectDelete(db, pSplit->pPrior);
139543
+ sqlite3ParserAddCleanup(pParse,
139544
+ (void(*)(sqlite3*,void*))sqlite3SelectDelete, pSplit->pPrior);
139220139545
}
139221139546
pSplit->pPrior = pPrior;
139222139547
pPrior->pNext = pSplit;
139223139548
sqlite3ExprListDelete(db, pPrior->pOrderBy);
139224139549
pPrior->pOrderBy = 0;
@@ -139324,10 +139649,11 @@
139324139649
if( pSubst->isOuterJoin && pCopy->op!=TK_COLUMN ){
139325139650
memset(&ifNullRow, 0, sizeof(ifNullRow));
139326139651
ifNullRow.op = TK_IF_NULL_ROW;
139327139652
ifNullRow.pLeft = pCopy;
139328139653
ifNullRow.iTable = pSubst->iNewTable;
139654
+ ifNullRow.iColumn = -99;
139329139655
ifNullRow.flags = EP_IfNullRow;
139330139656
pCopy = &ifNullRow;
139331139657
}
139332139658
testcase( ExprHasProperty(pCopy, EP_Subquery) );
139333139659
pNew = sqlite3ExprDup(db, pCopy, 0);
@@ -139591,11 +139917,12 @@
139591139917
**
139592139918
** (3) If the subquery is the right operand of a LEFT JOIN then
139593139919
** (3a) the subquery may not be a join and
139594139920
** (3b) the FROM clause of the subquery may not contain a virtual
139595139921
** table and
139596
-** (3c) the outer query may not be an aggregate.
139922
+** (**) Was: "The outer query may not have a GROUP BY." This case
139923
+** is now managed correctly
139597139924
** (3d) the outer query may not be DISTINCT.
139598139925
** See also (26) for restrictions on RIGHT JOIN.
139599139926
**
139600139927
** (4) The subquery can not be DISTINCT.
139601139928
**
@@ -139803,20 +140130,14 @@
139803140130
**
139804140131
** (t1 LEFT OUTER JOIN t2) JOIN t3
139805140132
**
139806140133
** which is not at all the same thing.
139807140134
**
139808
- ** If the subquery is the right operand of a LEFT JOIN, then the outer
139809
- ** query cannot be an aggregate. (3c) This is an artifact of the way
139810
- ** aggregates are processed - there is no mechanism to determine if
139811
- ** the LEFT JOIN table should be all-NULL.
139812
- **
139813140135
** See also tickets #306, #350, and #3300.
139814140136
*/
139815140137
if( (pSubitem->fg.jointype & (JT_OUTER|JT_LTORJ))!=0 ){
139816140138
if( pSubSrc->nSrc>1 /* (3a) */
139817
- || isAgg /* (3c) */
139818140139
|| IsVirtual(pSubSrc->a[0].pTab) /* (3b) */
139819140140
|| (p->selFlags & SF_Distinct)!=0 /* (3d) */
139820140141
|| (pSubitem->fg.jointype & JT_RIGHT)!=0 /* (26) */
139821140142
){
139822140143
return 0;
@@ -140733,10 +141054,11 @@
140733141054
if( p->pWhere
140734141055
|| p->pEList->nExpr!=1
140735141056
|| p->pSrc->nSrc!=1
140736141057
|| p->pSrc->a[0].pSelect
140737141058
|| pAggInfo->nFunc!=1
141059
+ || p->pHaving
140738141060
){
140739141061
return 0;
140740141062
}
140741141063
pTab = p->pSrc->a[0].pTab;
140742141064
assert( pTab!=0 );
@@ -142726,11 +143048,11 @@
142726143048
*/
142727143049
iEnd = sqlite3VdbeMakeLabel(pParse);
142728143050
if( (p->selFlags & SF_FixedLimit)==0 ){
142729143051
p->nSelectRow = 320; /* 4 billion rows */
142730143052
}
142731
- computeLimitRegisters(pParse, p, iEnd);
143053
+ if( p->pLimit ) computeLimitRegisters(pParse, p, iEnd);
142732143054
if( p->iLimit==0 && sSort.addrSortIndex>=0 ){
142733143055
sqlite3VdbeChangeOpcode(v, sSort.addrSortIndex, OP_SorterOpen);
142734143056
sSort.sortFlags |= SORTFLAG_UseSorter;
142735143057
}
142736143058
@@ -142948,12 +143270,17 @@
142948143270
if( minMaxFlag ){
142949143271
sqlite3DebugPrintf("MIN/MAX Optimization (0x%02x) adds:\n", minMaxFlag);
142950143272
sqlite3TreeViewExprList(0, pMinMaxOrderBy, 0, "ORDERBY");
142951143273
}
142952143274
for(ii=0; ii<pAggInfo->nColumn; ii++){
142953
- sqlite3DebugPrintf("agg-column[%d] iMem=%d\n",
142954
- ii, pAggInfo->aCol[ii].iMem);
143275
+ struct AggInfo_col *pCol = &pAggInfo->aCol[ii];
143276
+ sqlite3DebugPrintf(
143277
+ "agg-column[%d] pTab=%s iTable=%d iColumn=%d iMem=%d"
143278
+ " iSorterColumn=%d\n",
143279
+ ii, pCol->pTab ? pCol->pTab->zName : "NULL",
143280
+ pCol->iTable, pCol->iColumn, pCol->iMem,
143281
+ pCol->iSorterColumn);
142955143282
sqlite3TreeViewExpr(0, pAggInfo->aCol[ii].pCExpr, 0);
142956143283
}
142957143284
for(ii=0; ii<pAggInfo->nFunc; ii++){
142958143285
sqlite3DebugPrintf("agg-func[%d]: iMem=%d\n",
142959143286
ii, pAggInfo->aFunc[ii].iMem);
@@ -143070,19 +143397,19 @@
143070143397
}
143071143398
}
143072143399
regBase = sqlite3GetTempRange(pParse, nCol);
143073143400
sqlite3ExprCodeExprList(pParse, pGroupBy, regBase, 0, 0);
143074143401
j = nGroupBy;
143402
+ pAggInfo->directMode = 1;
143075143403
for(i=0; i<pAggInfo->nColumn; i++){
143076143404
struct AggInfo_col *pCol = &pAggInfo->aCol[i];
143077143405
if( pCol->iSorterColumn>=j ){
143078
- int r1 = j + regBase;
143079
- sqlite3ExprCodeGetColumnOfTable(v,
143080
- pCol->pTab, pCol->iTable, pCol->iColumn, r1);
143406
+ sqlite3ExprCode(pParse, pCol->pCExpr, j + regBase);
143081143407
j++;
143082143408
}
143083143409
}
143410
+ pAggInfo->directMode = 0;
143084143411
regRecord = sqlite3GetTempReg(pParse);
143085143412
sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regRecord);
143086143413
sqlite3VdbeAddOp2(v, OP_SorterInsert, pAggInfo->sortingIdx, regRecord);
143087143414
sqlite3ReleaseTempReg(pParse, regRecord);
143088143415
sqlite3ReleaseTempRange(pParse, regBase, nCol);
@@ -147496,11 +147823,12 @@
147496147823
** in the list are moved to the sqlite3.pDisconnect list of the associated
147497147824
** database connection.
147498147825
*/
147499147826
SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){
147500147827
assert( IsVirtual(p) );
147501
- if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
147828
+ assert( db!=0 );
147829
+ if( db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
147502147830
if( p->u.vtab.azArg ){
147503147831
int i;
147504147832
for(i=0; i<p->u.vtab.nArg; i++){
147505147833
if( i!=1 ) sqlite3DbFree(db, p->u.vtab.azArg[i]);
147506147834
}
@@ -149173,10 +149501,11 @@
149173149501
#define WHERE_IN_SEEKSCAN 0x00100000 /* Seek-scan optimization for IN */
149174149502
#define WHERE_TRANSCONS 0x00200000 /* Uses a transitive constraint */
149175149503
#define WHERE_BLOOMFILTER 0x00400000 /* Consider using a Bloom-filter */
149176149504
#define WHERE_SELFCULL 0x00800000 /* nOut reduced by extra WHERE terms */
149177149505
#define WHERE_OMIT_OFFSET 0x01000000 /* Set offset counter to zero */
149506
+#define WHERE_VIEWSCAN 0x02000000 /* A full-scan of a VIEW or subquery */
149178149507
149179149508
#endif /* !defined(SQLITE_WHEREINT_H) */
149180149509
149181149510
/************** End of whereInt.h ********************************************/
149182149511
/************** Continuing where we left off in wherecode.c ******************/
@@ -149781,11 +150110,12 @@
149781150110
eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap,&iTab);
149782150111
pExpr->iTable = iTab;
149783150112
}
149784150113
sqlite3ExprDelete(db, pX);
149785150114
}else{
149786
- aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq);
150115
+ int n = sqlite3ExprVectorSize(pX->pLeft);
150116
+ aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*MAX(nEq,n));
149787150117
eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap, &iTab);
149788150118
}
149789150119
pX = pExpr;
149790150120
}
149791150121
@@ -150051,11 +150381,11 @@
150051150381
WhereTerm *pTerm /* The upper or lower bound just coded */
150052150382
){
150053150383
if( pTerm->wtFlags & TERM_LIKEOPT ){
150054150384
VdbeOp *pOp;
150055150385
assert( pLevel->iLikeRepCntr>0 );
150056
- pOp = sqlite3VdbeGetOp(v, -1);
150386
+ pOp = sqlite3VdbeGetLastOp(v);
150057150387
assert( pOp!=0 );
150058150388
assert( pOp->opcode==OP_String8
150059150389
|| pTerm->pWC->pWInfo->pParse->db->mallocFailed );
150060150390
pOp->p3 = (int)(pLevel->iLikeRepCntr>>1); /* Register holding counter */
150061150391
pOp->p5 = (u8)(pLevel->iLikeRepCntr&1); /* ASC or DESC */
@@ -151267,12 +151597,12 @@
151267151597
sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
151268151598
endEq = 0;
151269151599
}
151270151600
nConstraint++;
151271151601
}
151272
- sqlite3DbFree(db, zStartAff);
151273
- sqlite3DbFree(db, zEndAff);
151602
+ if( zStartAff ) sqlite3DbNNFreeNN(db, zStartAff);
151603
+ if( zEndAff ) sqlite3DbNNFreeNN(db, zEndAff);
151274151604
151275151605
/* Top of the loop body */
151276151606
if( pLevel->p2==0 ) pLevel->p2 = sqlite3VdbeCurrentAddr(v);
151277151607
151278151608
/* Check if the index cursor is past the end of the range. */
@@ -155499,11 +155829,11 @@
155499155829
/* At this point, the (iCol+1) field prefix of aSample[i] is the first
155500155830
** sample that is greater than pRec. Or, if i==pIdx->nSample then pRec
155501155831
** is larger than all samples in the array. */
155502155832
tRowcnt iUpper, iGap;
155503155833
if( i>=pIdx->nSample ){
155504
- iUpper = sqlite3LogEstToInt(pIdx->aiRowLogEst[0]);
155834
+ iUpper = pIdx->nRowEst0;
155505155835
}else{
155506155836
iUpper = aSample[i].anLt[iCol];
155507155837
}
155508155838
155509155839
if( iLower>=iUpper ){
@@ -156128,16 +156458,22 @@
156128156458
}
156129156459
}
156130156460
}
156131156461
156132156462
/*
156133
-** Deallocate internal memory used by a WhereLoop object
156463
+** Deallocate internal memory used by a WhereLoop object. Leave the
156464
+** object in an initialized state, as if it had been newly allocated.
156134156465
*/
156135156466
static void whereLoopClear(sqlite3 *db, WhereLoop *p){
156136
- if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFreeNN(db, p->aLTerm);
156467
+ if( p->aLTerm!=p->aLTermSpace ){
156468
+ sqlite3DbFreeNN(db, p->aLTerm);
156469
+ p->aLTerm = p->aLTermSpace;
156470
+ p->nLSlot = ArraySize(p->aLTermSpace);
156471
+ }
156137156472
whereLoopClearUnion(db, p);
156138
- whereLoopInit(p);
156473
+ p->nLTerm = 0;
156474
+ p->wsFlags = 0;
156139156475
}
156140156476
156141156477
/*
156142156478
** Increase the memory allocation for pLoop->aLTerm[] to be at least n.
156143156479
*/
@@ -156157,11 +156493,13 @@
156157156493
/*
156158156494
** Transfer content from the second pLoop into the first.
156159156495
*/
156160156496
static int whereLoopXfer(sqlite3 *db, WhereLoop *pTo, WhereLoop *pFrom){
156161156497
whereLoopClearUnion(db, pTo);
156162
- if( whereLoopResize(db, pTo, pFrom->nLTerm) ){
156498
+ if( pFrom->nLTerm > pTo->nLSlot
156499
+ && whereLoopResize(db, pTo, pFrom->nLTerm)
156500
+ ){
156163156501
memset(pTo, 0, WHERE_LOOP_XFER_SZ);
156164156502
return SQLITE_NOMEM_BKPT;
156165156503
}
156166156504
memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);
156167156505
memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
@@ -156175,32 +156513,34 @@
156175156513
156176156514
/*
156177156515
** Delete a WhereLoop object
156178156516
*/
156179156517
static void whereLoopDelete(sqlite3 *db, WhereLoop *p){
156518
+ assert( db!=0 );
156180156519
whereLoopClear(db, p);
156181
- sqlite3DbFreeNN(db, p);
156520
+ sqlite3DbNNFreeNN(db, p);
156182156521
}
156183156522
156184156523
/*
156185156524
** Free a WhereInfo structure
156186156525
*/
156187156526
static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
156188156527
assert( pWInfo!=0 );
156528
+ assert( db!=0 );
156189156529
sqlite3WhereClauseClear(&pWInfo->sWC);
156190156530
while( pWInfo->pLoops ){
156191156531
WhereLoop *p = pWInfo->pLoops;
156192156532
pWInfo->pLoops = p->pNextLoop;
156193156533
whereLoopDelete(db, p);
156194156534
}
156195156535
assert( pWInfo->pExprMods==0 );
156196156536
while( pWInfo->pMemToFree ){
156197156537
WhereMemBlock *pNext = pWInfo->pMemToFree->pNext;
156198
- sqlite3DbFreeNN(db, pWInfo->pMemToFree);
156538
+ sqlite3DbNNFreeNN(db, pWInfo->pMemToFree);
156199156539
pWInfo->pMemToFree = pNext;
156200156540
}
156201
- sqlite3DbFreeNN(db, pWInfo);
156541
+ sqlite3DbNNFreeNN(db, pWInfo);
156202156542
}
156203156543
156204156544
/* Undo all Expr node modifications
156205156545
*/
156206156546
static void whereUndoExprMods(WhereInfo *pWInfo){
@@ -156810,11 +157150,15 @@
156810157150
pNew->wsFlags = saved_wsFlags;
156811157151
pNew->u.btree.nEq = saved_nEq;
156812157152
pNew->u.btree.nBtm = saved_nBtm;
156813157153
pNew->u.btree.nTop = saved_nTop;
156814157154
pNew->nLTerm = saved_nLTerm;
156815
- if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
157155
+ if( pNew->nLTerm>=pNew->nLSlot
157156
+ && whereLoopResize(db, pNew, pNew->nLTerm+1)
157157
+ ){
157158
+ break; /* OOM while trying to enlarge the pNew->aLTerm array */
157159
+ }
156816157160
pNew->aLTerm[pNew->nLTerm++] = pTerm;
156817157161
pNew->prereq = (saved_prereq | pTerm->prereqRight) & ~pNew->maskSelf;
156818157162
156819157163
assert( nInMul==0
156820157164
|| (pNew->wsFlags & WHERE_COLUMN_NULL)!=0
@@ -156903,42 +157247,43 @@
156903157247
}
156904157248
}
156905157249
if( scan.iEquiv>1 ) pNew->wsFlags |= WHERE_TRANSCONS;
156906157250
}else if( eOp & WO_ISNULL ){
156907157251
pNew->wsFlags |= WHERE_COLUMN_NULL;
156908
- }else if( eOp & (WO_GT|WO_GE) ){
156909
- testcase( eOp & WO_GT );
156910
- testcase( eOp & WO_GE );
156911
- pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_BTM_LIMIT;
156912
- pNew->u.btree.nBtm = whereRangeVectorLen(
156913
- pParse, pSrc->iCursor, pProbe, saved_nEq, pTerm
156914
- );
156915
- pBtm = pTerm;
156916
- pTop = 0;
156917
- if( pTerm->wtFlags & TERM_LIKEOPT ){
156918
- /* Range constraints that come from the LIKE optimization are
156919
- ** always used in pairs. */
156920
- pTop = &pTerm[1];
156921
- assert( (pTop-(pTerm->pWC->a))<pTerm->pWC->nTerm );
156922
- assert( pTop->wtFlags & TERM_LIKEOPT );
156923
- assert( pTop->eOperator==WO_LT );
156924
- if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
156925
- pNew->aLTerm[pNew->nLTerm++] = pTop;
156926
- pNew->wsFlags |= WHERE_TOP_LIMIT;
156927
- pNew->u.btree.nTop = 1;
156928
- }
156929
- }else{
156930
- assert( eOp & (WO_LT|WO_LE) );
156931
- testcase( eOp & WO_LT );
156932
- testcase( eOp & WO_LE );
156933
- pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_TOP_LIMIT;
156934
- pNew->u.btree.nTop = whereRangeVectorLen(
156935
- pParse, pSrc->iCursor, pProbe, saved_nEq, pTerm
156936
- );
156937
- pTop = pTerm;
156938
- pBtm = (pNew->wsFlags & WHERE_BTM_LIMIT)!=0 ?
156939
- pNew->aLTerm[pNew->nLTerm-2] : 0;
157252
+ }else{
157253
+ int nVecLen = whereRangeVectorLen(
157254
+ pParse, pSrc->iCursor, pProbe, saved_nEq, pTerm
157255
+ );
157256
+ if( eOp & (WO_GT|WO_GE) ){
157257
+ testcase( eOp & WO_GT );
157258
+ testcase( eOp & WO_GE );
157259
+ pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_BTM_LIMIT;
157260
+ pNew->u.btree.nBtm = nVecLen;
157261
+ pBtm = pTerm;
157262
+ pTop = 0;
157263
+ if( pTerm->wtFlags & TERM_LIKEOPT ){
157264
+ /* Range constraints that come from the LIKE optimization are
157265
+ ** always used in pairs. */
157266
+ pTop = &pTerm[1];
157267
+ assert( (pTop-(pTerm->pWC->a))<pTerm->pWC->nTerm );
157268
+ assert( pTop->wtFlags & TERM_LIKEOPT );
157269
+ assert( pTop->eOperator==WO_LT );
157270
+ if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
157271
+ pNew->aLTerm[pNew->nLTerm++] = pTop;
157272
+ pNew->wsFlags |= WHERE_TOP_LIMIT;
157273
+ pNew->u.btree.nTop = 1;
157274
+ }
157275
+ }else{
157276
+ assert( eOp & (WO_LT|WO_LE) );
157277
+ testcase( eOp & WO_LT );
157278
+ testcase( eOp & WO_LE );
157279
+ pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_TOP_LIMIT;
157280
+ pNew->u.btree.nTop = nVecLen;
157281
+ pTop = pTerm;
157282
+ pBtm = (pNew->wsFlags & WHERE_BTM_LIMIT)!=0 ?
157283
+ pNew->aLTerm[pNew->nLTerm-2] : 0;
157284
+ }
156940157285
}
156941157286
156942157287
/* At this point pNew->nOut is set to the number of rows expected to
156943157288
** be visited by the index scan before considering term pTerm, or the
156944157289
** values of nIn and nInMul. In other words, assuming that all
@@ -157380,10 +157725,13 @@
157380157725
#ifdef SQLITE_ENABLE_STAT4
157381157726
pNew->rRun = rSize + 16 - 2*((pTab->tabFlags & TF_HasStat4)!=0);
157382157727
#else
157383157728
pNew->rRun = rSize + 16;
157384157729
#endif
157730
+ if( IsView(pTab) || (pTab->tabFlags & TF_Ephemeral)!=0 ){
157731
+ pNew->wsFlags |= WHERE_VIEWSCAN;
157732
+ }
157385157733
ApplyCostMultiplier(pNew->rRun, pTab->costMult);
157386157734
whereLoopOutputAdjust(pWC, pNew, rSize);
157387157735
rc = whereLoopInsert(pBuilder, pNew);
157388157736
pNew->nOut = rSize;
157389157737
if( rc ) break;
@@ -158106,11 +158454,17 @@
158106158454
WhereLoop *pNew;
158107158455
158108158456
158109158457
/* Loop over the tables in the join, from left to right */
158110158458
pNew = pBuilder->pNew;
158111
- whereLoopInit(pNew);
158459
+
158460
+ /* Verify that pNew has already been initialized */
158461
+ assert( pNew->nLTerm==0 );
158462
+ assert( pNew->wsFlags==0 );
158463
+ assert( pNew->nLSlot>=ArraySize(pNew->aLTermSpace) );
158464
+ assert( pNew->aLTerm!=0 );
158465
+
158112158466
pBuilder->iPlanLimit = SQLITE_QUERY_PLANNER_LIMIT;
158113158467
for(iTab=0, pItem=pTabList->a; pItem<pEnd; iTab++, pItem++){
158114158468
Bitmask mUnusable = 0;
158115158469
pNew->iTab = iTab;
158116158470
pBuilder->iPlanLimit += SQLITE_QUERY_PLANNER_LIMIT_INCR;
@@ -158703,13 +159057,13 @@
158703159057
for(ii=0, pFrom=aFrom; ii<nFrom; ii++, pFrom++){
158704159058
for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
158705159059
LogEst nOut; /* Rows visited by (pFrom+pWLoop) */
158706159060
LogEst rCost; /* Cost of path (pFrom+pWLoop) */
158707159061
LogEst rUnsorted; /* Unsorted cost of (pFrom+pWLoop) */
158708
- i8 isOrdered = pFrom->isOrdered; /* isOrdered for (pFrom+pWLoop) */
159062
+ i8 isOrdered; /* isOrdered for (pFrom+pWLoop) */
158709159063
Bitmask maskNew; /* Mask of src visited by (..) */
158710
- Bitmask revMask = 0; /* Mask of rev-order loops for (..) */
159064
+ Bitmask revMask; /* Mask of rev-order loops for (..) */
158711159065
158712159066
if( (pWLoop->prereq & ~pFrom->maskLoop)!=0 ) continue;
158713159067
if( (pWLoop->maskSelf & pFrom->maskLoop)!=0 ) continue;
158714159068
if( (pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 && pFrom->nRow<3 ){
158715159069
/* Do not use an automatic index if the this loop is expected
@@ -158724,11 +159078,13 @@
158724159078
** Compute its cost */
158725159079
rUnsorted = sqlite3LogEstAdd(pWLoop->rSetup,pWLoop->rRun + pFrom->nRow);
158726159080
rUnsorted = sqlite3LogEstAdd(rUnsorted, pFrom->rUnsorted);
158727159081
nOut = pFrom->nRow + pWLoop->nOut;
158728159082
maskNew = pFrom->maskLoop | pWLoop->maskSelf;
159083
+ isOrdered = pFrom->isOrdered;
158729159084
if( isOrdered<0 ){
159085
+ revMask = 0;
158730159086
isOrdered = wherePathSatisfiesOrderBy(pWInfo,
158731159087
pWInfo->pOrderBy, pFrom, pWInfo->wctrlFlags,
158732159088
iLoop, pWLoop, &revMask);
158733159089
}else{
158734159090
revMask = pFrom->revLoop;
@@ -158751,10 +159107,17 @@
158751159107
rUnsorted, rCost));
158752159108
}else{
158753159109
rCost = rUnsorted;
158754159110
rUnsorted -= 2; /* TUNING: Slight bias in favor of no-sort plans */
158755159111
}
159112
+
159113
+ /* TUNING: A full-scan of a VIEW or subquery in the outer loop
159114
+ ** is not so bad. */
159115
+ if( iLoop==0 && (pWLoop->wsFlags & WHERE_VIEWSCAN)!=0 ){
159116
+ rCost += -10;
159117
+ nOut += -30;
159118
+ }
158756159119
158757159120
/* Check to see if pWLoop should be added to the set of
158758159121
** mxChoice best-so-far paths.
158759159122
**
158760159123
** First look for an existing path among best-so-far paths
@@ -158984,11 +159347,12 @@
158984159347
158985159348
158986159349
pWInfo->nRowOut = pFrom->nRow;
158987159350
158988159351
/* Free temporary memory and return success */
158989
- sqlite3DbFreeNN(db, pSpace);
159352
+ assert( db!=0 );
159353
+ sqlite3DbNNFreeNN(db, pSpace);
158990159354
return SQLITE_OK;
158991159355
}
158992159356
158993159357
/*
158994159358
** Most queries use only a single table (they are not joins) and have
@@ -161217,11 +161581,10 @@
161217161581
int i;
161218161582
int nInit = pList ? pList->nExpr : 0;
161219161583
for(i=0; i<pAppend->nExpr; i++){
161220161584
sqlite3 *db = pParse->db;
161221161585
Expr *pDup = sqlite3ExprDup(db, pAppend->a[i].pExpr, 0);
161222
- assert( pDup==0 || !ExprHasProperty(pDup, EP_MemToken) );
161223161586
if( db->mallocFailed ){
161224161587
sqlite3ExprDelete(db, pDup);
161225161588
break;
161226161589
}
161227161590
if( bIntToNull ){
@@ -162488,14 +162851,13 @@
162488162851
}
162489162852
sqlite3VdbeAddOp2(v, OP_Goto, 0, addrDone);
162490162853
162491162854
/* This block runs if reg1 is not NULL, but reg2 is. */
162492162855
sqlite3VdbeJumpHere(v, addr);
162493
- sqlite3VdbeAddOp2(v, OP_IsNull, reg2, lbl); VdbeCoverage(v);
162494
- if( op==OP_Gt || op==OP_Ge ){
162495
- sqlite3VdbeChangeP2(v, -1, addrDone);
162496
- }
162856
+ sqlite3VdbeAddOp2(v, OP_IsNull, reg2,
162857
+ (op==OP_Gt || op==OP_Ge) ? addrDone : lbl);
162858
+ VdbeCoverage(v);
162497162859
}
162498162860
162499162861
/* Register reg1 currently contains csr1.peerVal (the peer-value from csr1).
162500162862
** This block adds (or subtracts for DESC) the numeric value in regVal
162501162863
** from it. Or, if reg1 is not numeric (it is a NULL, a text value or a blob),
@@ -170068,11 +170430,11 @@
170068170430
sqlite3DeleteTable(db, pParse->pNewTable);
170069170431
}
170070170432
if( pParse->pNewTrigger && !IN_RENAME_OBJECT ){
170071170433
sqlite3DeleteTrigger(db, pParse->pNewTrigger);
170072170434
}
170073
- if( pParse->pVList ) sqlite3DbFreeNN(db, pParse->pVList);
170435
+ if( pParse->pVList ) sqlite3DbNNFreeNN(db, pParse->pVList);
170074170436
db->pParse = pParentParse;
170075170437
assert( nErr==0 || pParse->rc!=SQLITE_OK );
170076170438
return nErr;
170077170439
}
170078170440
@@ -171424,22 +171786,23 @@
171424171786
db->lookaside.pEnd = p;
171425171787
db->lookaside.bDisable = 0;
171426171788
db->lookaside.bMalloced = pBuf==0 ?1:0;
171427171789
db->lookaside.nSlot = nBig+nSm;
171428171790
}else{
171429
- db->lookaside.pStart = db;
171791
+ db->lookaside.pStart = 0;
171430171792
#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
171431171793
db->lookaside.pSmallInit = 0;
171432171794
db->lookaside.pSmallFree = 0;
171433
- db->lookaside.pMiddle = db;
171795
+ db->lookaside.pMiddle = 0;
171434171796
#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
171435
- db->lookaside.pEnd = db;
171797
+ db->lookaside.pEnd = 0;
171436171798
db->lookaside.bDisable = 1;
171437171799
db->lookaside.sz = 0;
171438171800
db->lookaside.bMalloced = 0;
171439171801
db->lookaside.nSlot = 0;
171440171802
}
171803
+ db->lookaside.pTrueEnd = db->lookaside.pEnd;
171441171804
assert( sqlite3LookasideUsed(db,0)==0 );
171442171805
#endif /* SQLITE_OMIT_LOOKASIDE */
171443171806
return SQLITE_OK;
171444171807
}
171445171808
@@ -171514,10 +171877,11 @@
171514171877
** Configuration settings for an individual database connection
171515171878
*/
171516171879
SQLITE_API int sqlite3_db_config(sqlite3 *db, int op, ...){
171517171880
va_list ap;
171518171881
int rc;
171882
+ sqlite3_mutex_enter(db->mutex);
171519171883
va_start(ap, op);
171520171884
switch( op ){
171521171885
case SQLITE_DBCONFIG_MAINDBNAME: {
171522171886
/* IMP: R-06824-28531 */
171523171887
/* IMP: R-36257-52125 */
@@ -171579,10 +171943,11 @@
171579171943
}
171580171944
break;
171581171945
}
171582171946
}
171583171947
va_end(ap);
171948
+ sqlite3_mutex_leave(db->mutex);
171584171949
return rc;
171585171950
}
171586171951
171587171952
/*
171588171953
** This is the default collating function named "BINARY" which is always
@@ -181118,11 +181483,11 @@
181118181483
p1 = pPhrase->doclist.pList;
181119181484
p2 = aPoslist;
181120181485
nDistance = iPrev - nMaxUndeferred;
181121181486
}
181122181487
181123
- aOut = (char *)sqlite3_malloc(nPoslist+8);
181488
+ aOut = (char *)sqlite3Fts3MallocZero(nPoslist+FTS3_BUFFER_PADDING);
181124181489
if( !aOut ){
181125181490
sqlite3_free(aPoslist);
181126181491
return SQLITE_NOMEM;
181127181492
}
181128181493
@@ -204144,11 +204509,11 @@
204144204509
sqlite3_bind_value(pUp, 2, aData[2]);
204145204510
}
204146204511
sqlite3_free(p);
204147204512
nChange = 1;
204148204513
}
204149
- for(jj=1; jj<pRtree->nAux; jj++){
204514
+ for(jj=1; jj<nData-2; jj++){
204150204515
nChange++;
204151204516
sqlite3_bind_value(pUp, jj+2, aData[jj+2]);
204152204517
}
204153204518
if( nChange ){
204154204519
sqlite3_step(pUp);
@@ -212503,15 +212868,16 @@
212503212868
*/
212504212869
static int dbpageBegin(sqlite3_vtab *pVtab){
212505212870
DbpageTable *pTab = (DbpageTable *)pVtab;
212506212871
sqlite3 *db = pTab->db;
212507212872
int i;
212508
- for(i=0; i<db->nDb; i++){
212873
+ int rc = SQLITE_OK;
212874
+ for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
212509212875
Btree *pBt = db->aDb[i].pBt;
212510
- if( pBt ) sqlite3BtreeBeginTrans(pBt, 1, 0);
212876
+ if( pBt ) rc = sqlite3BtreeBeginTrans(pBt, 1, 0);
212511212877
}
212512
- return SQLITE_OK;
212878
+ return rc;
212513212879
}
212514212880
212515212881
212516212882
/*
212517212883
** Invoke this routine to register the "dbpage" virtual table module
@@ -219231,11 +219597,11 @@
219231219597
static void sqlite3Fts5BufferAppendPrintf(int *, Fts5Buffer*, char *zFmt, ...);
219232219598
219233219599
static char *sqlite3Fts5Mprintf(int *pRc, const char *zFmt, ...);
219234219600
219235219601
#define fts5BufferZero(x) sqlite3Fts5BufferZero(x)
219236
-#define fts5BufferAppendVarint(a,b,c) sqlite3Fts5BufferAppendVarint(a,b,c)
219602
+#define fts5BufferAppendVarint(a,b,c) sqlite3Fts5BufferAppendVarint(a,b,(i64)c)
219237219603
#define fts5BufferFree(a) sqlite3Fts5BufferFree(a)
219238219604
#define fts5BufferAppendBlob(a,b,c,d) sqlite3Fts5BufferAppendBlob(a,b,c,d)
219239219605
#define fts5BufferSet(a,b,c,d) sqlite3Fts5BufferSet(a,b,c,d)
219240219606
219241219607
#define fts5BufferGrow(pRc,pBuf,nn) ( \
@@ -231108,11 +231474,13 @@
231108231474
/* Write the rowid. */
231109231475
if( pWriter->bFirstRowidInDoclist || pWriter->bFirstRowidInPage ){
231110231476
fts5BufferAppendVarint(&p->rc, &pPage->buf, iRowid);
231111231477
}else{
231112231478
assert_nc( p->rc || iRowid>pWriter->iPrevRowid );
231113
- fts5BufferAppendVarint(&p->rc, &pPage->buf, iRowid - pWriter->iPrevRowid);
231479
+ fts5BufferAppendVarint(&p->rc, &pPage->buf,
231480
+ (u64)iRowid - (u64)pWriter->iPrevRowid
231481
+ );
231114231482
}
231115231483
pWriter->iPrevRowid = iRowid;
231116231484
pWriter->bFirstRowidInDoclist = 0;
231117231485
pWriter->bFirstRowidInPage = 0;
231118231486
}
@@ -231872,21 +232240,21 @@
231872232240
return fts5IndexReturn(p);
231873232241
}
231874232242
231875232243
static void fts5AppendRowid(
231876232244
Fts5Index *p,
231877
- i64 iDelta,
232245
+ u64 iDelta,
231878232246
Fts5Iter *pUnused,
231879232247
Fts5Buffer *pBuf
231880232248
){
231881232249
UNUSED_PARAM(pUnused);
231882232250
fts5BufferAppendVarint(&p->rc, pBuf, iDelta);
231883232251
}
231884232252
231885232253
static void fts5AppendPoslist(
231886232254
Fts5Index *p,
231887
- i64 iDelta,
232255
+ u64 iDelta,
231888232256
Fts5Iter *pMulti,
231889232257
Fts5Buffer *pBuf
231890232258
){
231891232259
int nData = pMulti->base.nData;
231892232260
int nByte = nData + 9 + 9 + FTS5_DATA_ZERO_PADDING;
@@ -231957,14 +232325,14 @@
231957232325
fts5BufferSafeAppendVarint(pBuf, iRowid - *piLastRowid);
231958232326
*piLastRowid = iRowid;
231959232327
}
231960232328
#endif
231961232329
231962
-#define fts5MergeAppendDocid(pBuf, iLastRowid, iRowid) { \
231963
- assert( (pBuf)->n!=0 || (iLastRowid)==0 ); \
231964
- fts5BufferSafeAppendVarint((pBuf), (iRowid) - (iLastRowid)); \
231965
- (iLastRowid) = (iRowid); \
232330
+#define fts5MergeAppendDocid(pBuf, iLastRowid, iRowid) { \
232331
+ assert( (pBuf)->n!=0 || (iLastRowid)==0 ); \
232332
+ fts5BufferSafeAppendVarint((pBuf), (u64)(iRowid) - (u64)(iLastRowid)); \
232333
+ (iLastRowid) = (iRowid); \
231966232334
}
231967232335
231968232336
/*
231969232337
** Swap the contents of buffer *p1 with that of *p2.
231970232338
*/
@@ -232231,11 +232599,11 @@
232231232599
Fts5Buffer *aBuf;
232232232600
int nBuf = 32;
232233232601
int nMerge = 1;
232234232602
232235232603
void (*xMerge)(Fts5Index*, Fts5Buffer*, int, Fts5Buffer*);
232236
- void (*xAppend)(Fts5Index*, i64, Fts5Iter*, Fts5Buffer*);
232604
+ void (*xAppend)(Fts5Index*, u64, Fts5Iter*, Fts5Buffer*);
232237232605
if( p->pConfig->eDetail==FTS5_DETAIL_NONE ){
232238232606
xMerge = fts5MergeRowidLists;
232239232607
xAppend = fts5AppendRowid;
232240232608
}else{
232241232609
nMerge = FTS5_MERGE_NLIST-1;
@@ -232270,11 +232638,11 @@
232270232638
fts5MultiIterNext2(p, p1, &dummy)
232271232639
){
232272232640
Fts5SegIter *pSeg = &p1->aSeg[ p1->aFirst[1].iFirst ];
232273232641
p1->xSetOutputs(p1, pSeg);
232274232642
if( p1->base.nData ){
232275
- xAppend(p, p1->base.iRowid-iLastRowid, p1, &doclist);
232643
+ xAppend(p, (u64)p1->base.iRowid-(u64)iLastRowid, p1, &doclist);
232276232644
iLastRowid = p1->base.iRowid;
232277232645
}
232278232646
}
232279232647
fts5MultiIterFree(p1);
232280232648
}
@@ -232318,11 +232686,11 @@
232318232686
}
232319232687
}
232320232688
iLastRowid = 0;
232321232689
}
232322232690
232323
- xAppend(p, p1->base.iRowid-iLastRowid, p1, &doclist);
232691
+ xAppend(p, (u64)p1->base.iRowid-(u64)iLastRowid, p1, &doclist);
232324232692
iLastRowid = p1->base.iRowid;
232325232693
}
232326232694
232327232695
assert( (nBuf%nMerge)==0 );
232328232696
for(i=0; i<nBuf; i+=nMerge){
@@ -236634,11 +237002,11 @@
236634237002
int nArg, /* Number of args */
236635237003
sqlite3_value **apUnused /* Function arguments */
236636237004
){
236637237005
assert( nArg==0 );
236638237006
UNUSED_PARAM2(nArg, apUnused);
236639
- sqlite3_result_text(pCtx, "fts5: 2022-07-21 12:26:01 9141e873c575b049ce7aeaf313d05966f1966087caf33a6c80d2416a28571a21", -1, SQLITE_TRANSIENT);
237007
+ sqlite3_result_text(pCtx, "fts5: 2022-09-02 21:19:24 da7af290960ab8a04a1f55cdc5eeac36b47fa194edf67f0a05daa4b7f2a4071c", -1, SQLITE_TRANSIENT);
236640237008
}
236641237009
236642237010
/*
236643237011
** Return true if zName is the extension on one of the shadow tables used
236644237012
** by this module.
236645237013
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.39.2. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -450,13 +450,13 @@
450 **
451 ** See also: [sqlite3_libversion()],
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.39.2"
456 #define SQLITE_VERSION_NUMBER 3039002
457 #define SQLITE_SOURCE_ID "2022-07-21 12:26:01 9141e873c575b049ce7aeaf313d05966f1966087caf33a6c80d2416a28571a21"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -3728,10 +3728,13 @@
3728 **
3729 ** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt>
3730 ** <dd>The database is opened [shared cache] enabled, overriding
3731 ** the default shared cache setting provided by
3732 ** [sqlite3_enable_shared_cache()].)^
 
 
 
3733 **
3734 ** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt>
3735 ** <dd>The database is opened [shared cache] disabled, overriding
3736 ** the default shared cache setting provided by
3737 ** [sqlite3_enable_shared_cache()].)^
@@ -3743,11 +3746,11 @@
3743 ** connection as soon as the connection is created. In addition to setting
3744 ** the extended result code mode, this flag also causes [sqlite3_open_v2()]
3745 ** to return an extended result code.</dd>
3746 **
3747 ** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>
3748 ** <dd>The database filename is not allowed to be a symbolic link</dd>
3749 ** </dl>)^
3750 **
3751 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
3752 ** required combinations shown above optionally combined with other
3753 ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
@@ -6769,11 +6772,11 @@
6769 **
6770 ** ^The sqlite3_autovacuum_pages(D,C,P,X) interface registers a callback
6771 ** function C that is invoked prior to each autovacuum of the database
6772 ** file. ^The callback is passed a copy of the generic data pointer (P),
6773 ** the schema-name of the attached database that is being autovacuumed,
6774 ** the the size of the database file in pages, the number of free pages,
6775 ** and the number of bytes per page, respectively. The callback should
6776 ** return the number of free pages that should be removed by the
6777 ** autovacuum. ^If the callback returns zero, then no autovacuum happens.
6778 ** ^If the value returned is greater than or equal to the number of
6779 ** free pages, then a complete autovacuum happens.
@@ -6889,10 +6892,15 @@
6889 **
6890 ** ^(This routine enables or disables the sharing of the database cache
6891 ** and schema data structures between [database connection | connections]
6892 ** to the same database. Sharing is enabled if the argument is true
6893 ** and disabled if the argument is false.)^
 
 
 
 
 
6894 **
6895 ** ^Cache sharing is enabled and disabled for an entire process.
6896 ** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]).
6897 ** In prior versions of SQLite,
6898 ** sharing was enabled or disabled for each thread separately.
@@ -6988,11 +6996,11 @@
6988 ** ^Setting the heap limits to zero disables the heap limiter mechanism.
6989 **
6990 ** ^The soft heap limit may not be greater than the hard heap limit.
6991 ** ^If the hard heap limit is enabled and if sqlite3_soft_heap_limit(N)
6992 ** is invoked with a value of N that is greater than the hard heap limit,
6993 ** the the soft heap limit is set to the value of the hard heap limit.
6994 ** ^The soft heap limit is automatically enabled whenever the hard heap
6995 ** limit is enabled. ^When sqlite3_hard_heap_limit64(N) is invoked and
6996 ** the soft heap limit is outside the range of 1..N, then the soft heap
6997 ** limit is set to N. ^Invoking sqlite3_soft_heap_limit64(0) when the
6998 ** hard heap limit is enabled makes the soft heap limit equal to the
@@ -9283,11 +9291,11 @@
9283 ** sqlite3_backup_init() is called and before the corresponding call to
9284 ** sqlite3_backup_finish(). SQLite does not currently check to see
9285 ** if the application incorrectly accesses the destination [database connection]
9286 ** and so no error code is reported, but the operations may malfunction
9287 ** nevertheless. Use of the destination database connection while a
9288 ** backup is in progress might also also cause a mutex deadlock.
9289 **
9290 ** If running in [shared cache mode], the application must
9291 ** guarantee that the shared cache used by the destination database
9292 ** is not accessed while the backup is running. In practice this means
9293 ** that the application must guarantee that the disk file being
@@ -9711,11 +9719,11 @@
9711 ** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the
9712 ** meaning of each of these checkpoint modes.
9713 */
9714 #define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */
9715 #define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */
9716 #define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for for readers */
9717 #define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */
9718
9719 /*
9720 ** CAPI3REF: Virtual Table Interface Configuration
9721 **
@@ -13142,10 +13150,15 @@
13142 /******** End of fts5.h *********/
13143
13144 /************** End of sqlite3.h *********************************************/
13145 /************** Continuing where we left off in sqliteInt.h ******************/
13146
 
 
 
 
 
13147 /*
13148 ** Include the configuration header output by 'configure' if we're using the
13149 ** autoconf-based build
13150 */
13151 #if defined(_HAVE_SQLITE_CONFIG_H) && !defined(SQLITECONFIG_H)
@@ -15553,67 +15566,67 @@
15553 #define OP_Checkpoint 3
15554 #define OP_JournalMode 4
15555 #define OP_Vacuum 5
15556 #define OP_VFilter 6 /* jump, synopsis: iplan=r[P3] zplan='P4' */
15557 #define OP_VUpdate 7 /* synopsis: data=r[P3@P2] */
15558 #define OP_Goto 8 /* jump */
15559 #define OP_Gosub 9 /* jump */
15560 #define OP_InitCoroutine 10 /* jump */
15561 #define OP_Yield 11 /* jump */
15562 #define OP_MustBeInt 12 /* jump */
15563 #define OP_Jump 13 /* jump */
15564 #define OP_Once 14 /* jump */
15565 #define OP_If 15 /* jump */
15566 #define OP_IfNot 16 /* jump */
15567 #define OP_IsNullOrType 17 /* jump, synopsis: if typeof(r[P1]) IN (P3,5) goto P2 */
15568 #define OP_IfNullRow 18 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
15569 #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
15570 #define OP_SeekLT 20 /* jump, synopsis: key=r[P3@P4] */
15571 #define OP_SeekLE 21 /* jump, synopsis: key=r[P3@P4] */
15572 #define OP_SeekGE 22 /* jump, synopsis: key=r[P3@P4] */
15573 #define OP_SeekGT 23 /* jump, synopsis: key=r[P3@P4] */
15574 #define OP_IfNotOpen 24 /* jump, synopsis: if( !csr[P1] ) goto P2 */
15575 #define OP_IfNoHope 25 /* jump, synopsis: key=r[P3@P4] */
15576 #define OP_NoConflict 26 /* jump, synopsis: key=r[P3@P4] */
15577 #define OP_NotFound 27 /* jump, synopsis: key=r[P3@P4] */
15578 #define OP_Found 28 /* jump, synopsis: key=r[P3@P4] */
15579 #define OP_SeekRowid 29 /* jump, synopsis: intkey=r[P3] */
15580 #define OP_NotExists 30 /* jump, synopsis: intkey=r[P3] */
15581 #define OP_Last 31 /* jump */
15582 #define OP_IfSmaller 32 /* jump */
15583 #define OP_SorterSort 33 /* jump */
15584 #define OP_Sort 34 /* jump */
15585 #define OP_Rewind 35 /* jump */
15586 #define OP_SorterNext 36 /* jump */
15587 #define OP_Prev 37 /* jump */
15588 #define OP_Next 38 /* jump */
15589 #define OP_IdxLE 39 /* jump, synopsis: key=r[P3@P4] */
15590 #define OP_IdxGT 40 /* jump, synopsis: key=r[P3@P4] */
15591 #define OP_IdxLT 41 /* jump, synopsis: key=r[P3@P4] */
15592 #define OP_IdxGE 42 /* jump, synopsis: key=r[P3@P4] */
15593 #define OP_Or 43 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
15594 #define OP_And 44 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
15595 #define OP_RowSetRead 45 /* jump, synopsis: r[P3]=rowset(P1) */
15596 #define OP_RowSetTest 46 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */
15597 #define OP_Program 47 /* jump */
15598 #define OP_FkIfZero 48 /* jump, synopsis: if fkctr[P1]==0 goto P2 */
15599 #define OP_IfPos 49 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
15600 #define OP_IsNull 50 /* jump, same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
15601 #define OP_NotNull 51 /* jump, same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
15602 #define OP_Ne 52 /* jump, same as TK_NE, synopsis: IF r[P3]!=r[P1] */
15603 #define OP_Eq 53 /* jump, same as TK_EQ, synopsis: IF r[P3]==r[P1] */
15604 #define OP_Gt 54 /* jump, same as TK_GT, synopsis: IF r[P3]>r[P1] */
15605 #define OP_Le 55 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */
15606 #define OP_Lt 56 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */
15607 #define OP_Ge 57 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */
15608 #define OP_ElseEq 58 /* jump, same as TK_ESCAPE */
15609 #define OP_IfNotZero 59 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
15610 #define OP_DecrJumpZero 60 /* jump, synopsis: if (--r[P1])==0 goto P2 */
15611 #define OP_IncrVacuum 61 /* jump */
15612 #define OP_VNext 62 /* jump */
15613 #define OP_Filter 63 /* jump, synopsis: if key(P3@P4) not in filter(P1) goto P2 */
15614 #define OP_Init 64 /* jump, synopsis: Start at P2 */
15615 #define OP_PureFunc 65 /* synopsis: r[P3]=func(r[P2@NP]) */
15616 #define OP_Function 66 /* synopsis: r[P3]=func(r[P2@NP]) */
15617 #define OP_Return 67
15618 #define OP_EndCoroutine 68
15619 #define OP_HaltIfNull 69 /* synopsis: if r[P3]=null halt */
@@ -15745,17 +15758,17 @@
15745 #define OPFLG_IN3 0x08 /* in3: P3 is an input */
15746 #define OPFLG_OUT2 0x10 /* out2: P2 is an output */
15747 #define OPFLG_OUT3 0x20 /* out3: P3 is an output */
15748 #define OPFLG_INITIALIZER {\
15749 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00,\
15750 /* 8 */ 0x01, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01, 0x03,\
15751 /* 16 */ 0x03, 0x03, 0x01, 0x12, 0x09, 0x09, 0x09, 0x09,\
15752 /* 24 */ 0x01, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x01,\
15753 /* 32 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
15754 /* 40 */ 0x01, 0x01, 0x01, 0x26, 0x26, 0x23, 0x0b, 0x01,\
15755 /* 48 */ 0x01, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
15756 /* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x01, 0x01, 0x01,\
15757 /* 64 */ 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10,\
15758 /* 72 */ 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10, 0x00,\
15759 /* 80 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x02, 0x02,\
15760 /* 88 */ 0x02, 0x00, 0x00, 0x12, 0x1e, 0x20, 0x00, 0x00,\
15761 /* 96 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x26, 0x26,\
@@ -15857,10 +15870,11 @@
15857 SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
15858 SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
15859 SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
15860 SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
15861 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
 
15862 SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Parse*);
15863 SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce(Vdbe*);
15864 SQLITE_PRIVATE void sqlite3VdbeReusable(Vdbe*);
15865 SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe*);
15866 SQLITE_PRIVATE void sqlite3VdbeMakeReady(Vdbe*,Parse*);
@@ -16741,10 +16755,11 @@
16741 void *pMiddle; /* First byte past end of full-size buffers and
16742 ** the first byte of LOOKASIDE_SMALL buffers */
16743 #endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
16744 void *pStart; /* First byte of available memory space */
16745 void *pEnd; /* First byte past end of available space */
 
16746 };
16747 struct LookasideSlot {
16748 LookasideSlot *pNext; /* Next buffer in the list of free buffers */
16749 };
16750
@@ -18189,11 +18204,11 @@
18189 #define EP_xIsSelect 0x001000 /* x.pSelect is valid (otherwise x.pList is) */
18190 #define EP_Skip 0x002000 /* Operator does not contribute to affinity */
18191 #define EP_Reduced 0x004000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
18192 #define EP_Win 0x008000 /* Contains window functions */
18193 #define EP_TokenOnly 0x010000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
18194 #define EP_MemToken 0x020000 /* Need to sqlite3DbFree() Expr.zToken */
18195 #define EP_IfNullRow 0x040000 /* The TK_IF_NULL_ROW opcode */
18196 #define EP_Unlikely 0x080000 /* unlikely() or likelihood() function */
18197 #define EP_ConstFunc 0x100000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
18198 #define EP_CanBeNull 0x200000 /* Can be null despite NOT NULL constraint */
18199 #define EP_Subquery 0x400000 /* Tree contains a TK_SELECT operator */
@@ -19667,10 +19682,11 @@
19667 SQLITE_PRIVATE void *sqlite3Realloc(void*, u64);
19668 SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64);
19669 SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64);
19670 SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*);
19671 SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3*, void*);
 
19672 SQLITE_PRIVATE int sqlite3MallocSize(const void*);
19673 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, const void*);
19674 SQLITE_PRIVATE void *sqlite3PageMalloc(int);
19675 SQLITE_PRIVATE void sqlite3PageFree(void*);
19676 SQLITE_PRIVATE void sqlite3MemSetDefault(void);
@@ -20191,10 +20207,11 @@
20191 SQLITE_PRIVATE int sqlite3FixSrcList(DbFixer*, SrcList*);
20192 SQLITE_PRIVATE int sqlite3FixSelect(DbFixer*, Select*);
20193 SQLITE_PRIVATE int sqlite3FixExpr(DbFixer*, Expr*);
20194 SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
20195 SQLITE_PRIVATE int sqlite3RealSameAsInt(double,sqlite3_int64);
 
20196 SQLITE_PRIVATE void sqlite3Int64ToText(i64,char*);
20197 SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*, int, u8);
20198 SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*);
20199 SQLITE_PRIVATE int sqlite3GetUInt32(const char*, u32*);
20200 SQLITE_PRIVATE int sqlite3Atoi(const char*);
@@ -21637,13 +21654,10 @@
21637 "OMIT_WSD",
21638 #endif
21639 #ifdef SQLITE_OMIT_XFER_OPT
21640 "OMIT_XFER_OPT",
21641 #endif
21642 #ifdef SQLITE_PCACHE_SEPARATE_HEADER
21643 "PCACHE_SEPARATE_HEADER",
21644 #endif
21645 #ifdef SQLITE_PERFORMANCE_TRACE
21646 "PERFORMANCE_TRACE",
21647 #endif
21648 #ifdef SQLITE_POWERSAFE_OVERWRITE
21649 # if SQLITE_POWERSAFE_OVERWRITE != 1
@@ -22592,11 +22606,11 @@
22592 ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()
22593 ** is really a pointer to an instance of this structure.
22594 */
22595 struct Vdbe {
22596 sqlite3 *db; /* The database connection that owns this statement */
22597 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
22598 Parse *pParse; /* Parsing context used to create this Vdbe */
22599 ynVar nVar; /* Number of entries in aVar[] */
22600 int nMem; /* Number of memory locations currently allocated */
22601 int nCursor; /* Number of slots in apCsr[] */
22602 u32 cacheCtr; /* VdbeCursor row cache generation counter */
@@ -23150,10 +23164,12 @@
23150 int i; /* Used to iterate through schemas */
23151 int nByte = 0; /* Used to accumulate return value */
23152
23153 sqlite3BtreeEnterAll(db);
23154 db->pnBytesFreed = &nByte;
 
 
23155 for(i=0; i<db->nDb; i++){
23156 Schema *pSchema = db->aDb[i].pSchema;
23157 if( ALWAYS(pSchema!=0) ){
23158 HashElem *p;
23159
@@ -23175,10 +23191,11 @@
23175 sqlite3DeleteTable(db, (Table *)sqliteHashData(p));
23176 }
23177 }
23178 }
23179 db->pnBytesFreed = 0;
 
23180 sqlite3BtreeLeaveAll(db);
23181
23182 *pHighwater = 0;
23183 *pCurrent = nByte;
23184 break;
@@ -23192,13 +23209,16 @@
23192 case SQLITE_DBSTATUS_STMT_USED: {
23193 struct Vdbe *pVdbe; /* Used to iterate through VMs */
23194 int nByte = 0; /* Used to accumulate return value */
23195
23196 db->pnBytesFreed = &nByte;
23197 for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pNext){
 
 
23198 sqlite3VdbeDelete(pVdbe);
23199 }
 
23200 db->pnBytesFreed = 0;
23201
23202 *pHighwater = 0; /* IMP: R-64479-57858 */
23203 *pCurrent = nByte;
23204
@@ -23530,11 +23550,11 @@
23530 X1 = 36525*(Y+4716)/100;
23531 X2 = 306001*(M+1)/10000;
23532 p->iJD = (sqlite3_int64)((X1 + X2 + D + B - 1524.5 ) * 86400000);
23533 p->validJD = 1;
23534 if( p->validHMS ){
23535 p->iJD += p->h*3600000 + p->m*60000 + (sqlite3_int64)(p->s*1000);
23536 if( p->validTZ ){
23537 p->iJD -= p->tz*60000;
23538 p->validYMD = 0;
23539 p->validHMS = 0;
23540 p->validTZ = 0;
@@ -24039,11 +24059,11 @@
24039 ** weekday N where 0==Sunday, 1==Monday, and so forth. If the
24040 ** date is already on the appropriate weekday, this is a no-op.
24041 */
24042 if( sqlite3_strnicmp(z, "weekday ", 8)==0
24043 && sqlite3AtoF(&z[8], &r, sqlite3Strlen30(&z[8]), SQLITE_UTF8)>0
24044 && (n=(int)r)==r && n>=0 && r<7 ){
24045 sqlite3_int64 Z;
24046 computeYMD_HMS(p);
24047 p->validTZ = 0;
24048 p->validJD = 0;
24049 computeJD(p);
@@ -24837,10 +24857,11 @@
24837 DO_OS_MALLOC_TEST(0);
24838 /* 0x87f7f is a mask of SQLITE_OPEN_ flags that are valid to be passed
24839 ** down into the VFS layer. Some SQLITE_OPEN_ flags (for example,
24840 ** SQLITE_OPEN_FULLMUTEX or SQLITE_OPEN_SHAREDCACHE) are blocked before
24841 ** reaching the VFS. */
 
24842 rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x1087f7f, pFlagsOut);
24843 assert( rc==SQLITE_OK || pFile->pMethods==0 );
24844 return rc;
24845 }
24846 SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
@@ -29102,11 +29123,11 @@
29102 /*
29103 ** TRUE if p is a lookaside memory allocation from db
29104 */
29105 #ifndef SQLITE_OMIT_LOOKASIDE
29106 static int isLookaside(sqlite3 *db, const void *p){
29107 return SQLITE_WITHIN(p, db->lookaside.pStart, db->lookaside.pEnd);
29108 }
29109 #else
29110 #define isLookaside(A,B) 0
29111 #endif
29112
@@ -29126,22 +29147,20 @@
29126 #endif
29127 }
29128 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, const void *p){
29129 assert( p!=0 );
29130 #ifdef SQLITE_DEBUG
29131 if( db==0 || !isLookaside(db,p) ){
29132 if( db==0 ){
29133 assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
29134 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
29135 }else{
29136 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
29137 assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
29138 }
29139 }
29140 #endif
29141 if( db ){
29142 if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){
29143 #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
29144 if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){
29145 assert( sqlite3_mutex_held(db->mutex) );
29146 return LOOKASIDE_SMALL;
29147 }
@@ -29193,18 +29212,15 @@
29193 */
29194 SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3 *db, void *p){
29195 assert( db==0 || sqlite3_mutex_held(db->mutex) );
29196 assert( p!=0 );
29197 if( db ){
29198 if( db->pnBytesFreed ){
29199 measureAllocationSize(db, p);
29200 return;
29201 }
29202 if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){
29203 #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
29204 if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){
29205 LookasideSlot *pBuf = (LookasideSlot*)p;
 
29206 #ifdef SQLITE_DEBUG
29207 memset(p, 0xaa, LOOKASIDE_SMALL); /* Trash freed content */
29208 #endif
29209 pBuf->pNext = db->lookaside.pSmallFree;
29210 db->lookaside.pSmallFree = pBuf;
@@ -29211,24 +29227,66 @@
29211 return;
29212 }
29213 #endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
29214 if( ((uptr)p)>=(uptr)(db->lookaside.pStart) ){
29215 LookasideSlot *pBuf = (LookasideSlot*)p;
 
29216 #ifdef SQLITE_DEBUG
29217 memset(p, 0xaa, db->lookaside.szTrue); /* Trash freed content */
29218 #endif
29219 pBuf->pNext = db->lookaside.pFree;
29220 db->lookaside.pFree = pBuf;
29221 return;
29222 }
29223 }
 
 
 
 
29224 }
29225 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
29226 assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
29227 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
29228 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
29229 sqlite3_free(p);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29230 }
29231 SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
29232 assert( db==0 || sqlite3_mutex_held(db->mutex) );
29233 if( p ) sqlite3DbFreeNN(db, p);
29234 }
@@ -29561,12 +29619,17 @@
29561 if( db->nVdbeExec>0 ){
29562 AtomicStore(&db->u1.isInterrupted, 1);
29563 }
29564 DisableLookaside;
29565 if( db->pParse ){
 
29566 sqlite3ErrorMsg(db->pParse, "out of memory");
29567 db->pParse->rc = SQLITE_NOMEM_BKPT;
 
 
 
 
29568 }
29569 }
29570 return 0;
29571 }
29572
@@ -32332,20 +32395,45 @@
32332
32333 /* All threads share a single random number generator.
32334 ** This structure is the current state of the generator.
32335 */
32336 static SQLITE_WSD struct sqlite3PrngType {
32337 unsigned char isInit; /* True if initialized */
32338 unsigned char i, j; /* State variables */
32339 unsigned char s[256]; /* State variables */
32340 } sqlite3Prng;
32341
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32342 /*
32343 ** Return N random bytes.
32344 */
32345 SQLITE_API void sqlite3_randomness(int N, void *pBuf){
32346 unsigned char t;
32347 unsigned char *zBuf = pBuf;
32348
32349 /* The "wsdPrng" macro will resolve to the pseudo-random number generator
32350 ** state vector. If writable static data is unsupported on the target,
32351 ** we have to locate the state vector at run-time. In the more common
@@ -32371,57 +32459,50 @@
32371 mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
32372 #endif
32373
32374 sqlite3_mutex_enter(mutex);
32375 if( N<=0 || pBuf==0 ){
32376 wsdPrng.isInit = 0;
32377 sqlite3_mutex_leave(mutex);
32378 return;
32379 }
32380
32381 /* Initialize the state of the random number generator once,
32382 ** the first time this routine is called. The seed value does
32383 ** not need to contain a lot of randomness since we are not
32384 ** trying to do secure encryption or anything like that...
32385 **
32386 ** Nothing in this file or anywhere else in SQLite does any kind of
32387 ** encryption. The RC4 algorithm is being used as a PRNG (pseudo-random
32388 ** number generator) not as an encryption device.
32389 */
32390 if( !wsdPrng.isInit ){
32391 sqlite3_vfs *pVfs = sqlite3_vfs_find(0);
32392 int i;
32393 char k[256];
32394 wsdPrng.j = 0;
32395 wsdPrng.i = 0;
32396 if( NEVER(pVfs==0) ){
32397 memset(k, 0, sizeof(k));
32398 }else{
32399 sqlite3OsRandomness(pVfs, 256, k);
32400 }
32401 for(i=0; i<256; i++){
32402 wsdPrng.s[i] = (u8)i;
32403 }
32404 for(i=0; i<256; i++){
32405 wsdPrng.j += wsdPrng.s[i] + k[i];
32406 t = wsdPrng.s[wsdPrng.j];
32407 wsdPrng.s[wsdPrng.j] = wsdPrng.s[i];
32408 wsdPrng.s[i] = t;
32409 }
32410 wsdPrng.isInit = 1;
32411 }
32412
32413 assert( N>0 );
32414 do{
32415 wsdPrng.i++;
32416 t = wsdPrng.s[wsdPrng.i];
32417 wsdPrng.j += t;
32418 wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j];
32419 wsdPrng.s[wsdPrng.j] = t;
32420 t += wsdPrng.s[wsdPrng.i];
32421 *(zBuf++) = wsdPrng.s[t];
32422 }while( --N );
 
 
 
 
 
 
32423 sqlite3_mutex_leave(mutex);
32424 }
32425
32426 #ifndef SQLITE_UNTESTABLE
32427 /*
@@ -33457,11 +33538,11 @@
33457 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse *pParse, const char *zFormat, ...){
33458 char *zMsg;
33459 va_list ap;
33460 sqlite3 *db = pParse->db;
33461 assert( db!=0 );
33462 assert( db->pParse==pParse );
33463 db->errByteOffset = -2;
33464 va_start(ap, zFormat);
33465 zMsg = sqlite3VMPrintf(db, zFormat, ap);
33466 va_end(ap);
33467 if( db->errByteOffset<-1 ) db->errByteOffset = -1;
@@ -35275,67 +35356,67 @@
35275 /* 3 */ "Checkpoint" OpHelp(""),
35276 /* 4 */ "JournalMode" OpHelp(""),
35277 /* 5 */ "Vacuum" OpHelp(""),
35278 /* 6 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"),
35279 /* 7 */ "VUpdate" OpHelp("data=r[P3@P2]"),
35280 /* 8 */ "Goto" OpHelp(""),
35281 /* 9 */ "Gosub" OpHelp(""),
35282 /* 10 */ "InitCoroutine" OpHelp(""),
35283 /* 11 */ "Yield" OpHelp(""),
35284 /* 12 */ "MustBeInt" OpHelp(""),
35285 /* 13 */ "Jump" OpHelp(""),
35286 /* 14 */ "Once" OpHelp(""),
35287 /* 15 */ "If" OpHelp(""),
35288 /* 16 */ "IfNot" OpHelp(""),
35289 /* 17 */ "IsNullOrType" OpHelp("if typeof(r[P1]) IN (P3,5) goto P2"),
35290 /* 18 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
35291 /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
35292 /* 20 */ "SeekLT" OpHelp("key=r[P3@P4]"),
35293 /* 21 */ "SeekLE" OpHelp("key=r[P3@P4]"),
35294 /* 22 */ "SeekGE" OpHelp("key=r[P3@P4]"),
35295 /* 23 */ "SeekGT" OpHelp("key=r[P3@P4]"),
35296 /* 24 */ "IfNotOpen" OpHelp("if( !csr[P1] ) goto P2"),
35297 /* 25 */ "IfNoHope" OpHelp("key=r[P3@P4]"),
35298 /* 26 */ "NoConflict" OpHelp("key=r[P3@P4]"),
35299 /* 27 */ "NotFound" OpHelp("key=r[P3@P4]"),
35300 /* 28 */ "Found" OpHelp("key=r[P3@P4]"),
35301 /* 29 */ "SeekRowid" OpHelp("intkey=r[P3]"),
35302 /* 30 */ "NotExists" OpHelp("intkey=r[P3]"),
35303 /* 31 */ "Last" OpHelp(""),
35304 /* 32 */ "IfSmaller" OpHelp(""),
35305 /* 33 */ "SorterSort" OpHelp(""),
35306 /* 34 */ "Sort" OpHelp(""),
35307 /* 35 */ "Rewind" OpHelp(""),
35308 /* 36 */ "SorterNext" OpHelp(""),
35309 /* 37 */ "Prev" OpHelp(""),
35310 /* 38 */ "Next" OpHelp(""),
35311 /* 39 */ "IdxLE" OpHelp("key=r[P3@P4]"),
35312 /* 40 */ "IdxGT" OpHelp("key=r[P3@P4]"),
35313 /* 41 */ "IdxLT" OpHelp("key=r[P3@P4]"),
35314 /* 42 */ "IdxGE" OpHelp("key=r[P3@P4]"),
35315 /* 43 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
35316 /* 44 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
35317 /* 45 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
35318 /* 46 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
35319 /* 47 */ "Program" OpHelp(""),
35320 /* 48 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
35321 /* 49 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
35322 /* 50 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
35323 /* 51 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
35324 /* 52 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
35325 /* 53 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
35326 /* 54 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
35327 /* 55 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
35328 /* 56 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
35329 /* 57 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
35330 /* 58 */ "ElseEq" OpHelp(""),
35331 /* 59 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
35332 /* 60 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
35333 /* 61 */ "IncrVacuum" OpHelp(""),
35334 /* 62 */ "VNext" OpHelp(""),
35335 /* 63 */ "Filter" OpHelp("if key(P3@P4) not in filter(P1) goto P2"),
35336 /* 64 */ "Init" OpHelp("Start at P2"),
35337 /* 65 */ "PureFunc" OpHelp("r[P3]=func(r[P2@NP])"),
35338 /* 66 */ "Function" OpHelp("r[P3]=func(r[P2@NP])"),
35339 /* 67 */ "Return" OpHelp(""),
35340 /* 68 */ "EndCoroutine" OpHelp(""),
35341 /* 69 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
@@ -41318,30 +41399,39 @@
41318 ** pVfs->mxPathname bytes.
41319 */
41320 static int unixGetTempname(int nBuf, char *zBuf){
41321 const char *zDir;
41322 int iLimit = 0;
 
41323
41324 /* It's odd to simulate an io-error here, but really this is just
41325 ** using the io-error infrastructure to test that SQLite handles this
41326 ** function failing.
41327 */
41328 zBuf[0] = 0;
41329 SimulateIOError( return SQLITE_IOERR );
41330
 
41331 zDir = unixTempFileDir();
41332 if( zDir==0 ) return SQLITE_IOERR_GETTEMPPATH;
41333 do{
41334 u64 r;
41335 sqlite3_randomness(sizeof(r), &r);
41336 assert( nBuf>2 );
41337 zBuf[nBuf-2] = 0;
41338 sqlite3_snprintf(nBuf, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX"%llx%c",
41339 zDir, r, 0);
41340 if( zBuf[nBuf-2]!=0 || (iLimit++)>10 ) return SQLITE_ERROR;
41341 }while( osAccess(zBuf,0)==0 );
41342 return SQLITE_OK;
 
 
 
 
 
 
 
41343 }
41344
41345 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
41346 /*
41347 ** Routine to transform a unixFile into a proxy-locking unixFile.
@@ -43512,11 +43602,16 @@
43512 ** correctly. See ticket [bb3a86e890c8e96ab] */
43513 assert( ArraySize(aSyscall)==29 );
43514
43515 /* Register all VFSes defined in the aVfs[] array */
43516 for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){
 
 
 
 
43517 sqlite3_vfs_register(&aVfs[i], i==0);
 
43518 }
43519 unixBigLock = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
43520
43521 #ifndef SQLITE_OMIT_WAL
43522 /* Validate lock assumptions */
@@ -45480,10 +45575,11 @@
45480 char **ppDirectory = 0;
45481 #ifndef SQLITE_OMIT_AUTOINIT
45482 int rc = sqlite3_initialize();
45483 if( rc ) return rc;
45484 #endif
 
45485 if( type==SQLITE_WIN32_DATA_DIRECTORY_TYPE ){
45486 ppDirectory = &sqlite3_data_directory;
45487 }else if( type==SQLITE_WIN32_TEMP_DIRECTORY_TYPE ){
45488 ppDirectory = &sqlite3_temp_directory;
45489 }
@@ -45494,18 +45590,23 @@
45494 if( ppDirectory ){
45495 char *zCopy = 0;
45496 if( zValue && zValue[0] ){
45497 zCopy = sqlite3_mprintf("%s", zValue);
45498 if ( zCopy==0 ){
45499 return SQLITE_NOMEM_BKPT;
 
45500 }
45501 }
45502 sqlite3_free(*ppDirectory);
45503 *ppDirectory = zCopy;
45504 return SQLITE_OK;
 
 
45505 }
45506 return SQLITE_ERROR;
 
 
45507 }
45508
45509 /*
45510 ** This function is the same as sqlite3_win32_set_directory (below); however,
45511 ** it accepts a UTF-16 string.
@@ -48274,10 +48375,22 @@
48274 }
48275 }
48276 }
48277 return 0;
48278 }
 
 
 
 
 
 
 
 
 
 
 
 
48279
48280 /*
48281 ** Create a temporary file name and store the resulting pointer into pzBuf.
48282 ** The pointer returned in pzBuf must be freed via sqlite3_free().
48283 */
@@ -48311,24 +48424,27 @@
48311 ** has been explicitly set by the application; otherwise, use the one
48312 ** configured by the operating system.
48313 */
48314 nDir = nMax - (nPre + 15);
48315 assert( nDir>0 );
48316 if( sqlite3_temp_directory ){
48317 int nDirLen = sqlite3Strlen30(sqlite3_temp_directory);
48318 if( nDirLen>0 ){
48319 if( !winIsDirSep(sqlite3_temp_directory[nDirLen-1]) ){
48320 nDirLen++;
48321 }
48322 if( nDirLen>nDir ){
 
48323 sqlite3_free(zBuf);
48324 OSTRACE(("TEMP-FILENAME rc=SQLITE_ERROR\n"));
48325 return winLogError(SQLITE_ERROR, 0, "winGetTempname1", 0);
48326 }
48327 sqlite3_snprintf(nMax, zBuf, "%s", sqlite3_temp_directory);
48328 }
 
48329 }
 
48330 #if defined(__CYGWIN__)
48331 else{
48332 static const char *azDirs[] = {
48333 0, /* getenv("SQLITE_TMPDIR") */
48334 0, /* getenv("TMPDIR") */
@@ -49113,11 +49229,11 @@
49113 /*
49114 ** Turn a relative pathname into a full pathname. Write the full
49115 ** pathname into zOut[]. zOut[] will be at least pVfs->mxPathname
49116 ** bytes in size.
49117 */
49118 static int winFullPathname(
49119 sqlite3_vfs *pVfs, /* Pointer to vfs object */
49120 const char *zRelative, /* Possibly relative input path */
49121 int nFull, /* Size of output buffer in bytes */
49122 char *zFull /* Output buffer */
49123 ){
@@ -49291,10 +49407,23 @@
49291 return SQLITE_OK;
49292 }else{
49293 return SQLITE_IOERR_NOMEM_BKPT;
49294 }
49295 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
49296 }
49297
49298 #ifndef SQLITE_OMIT_LOAD_EXTENSION
49299 /*
49300 ** Interfaces for opening a shared library, finding entry points
@@ -51080,39 +51209,58 @@
51080 */
51081 #if defined(SQLITE_DEBUG) && 0
51082 int sqlite3PcacheTrace = 2; /* 0: off 1: simple 2: cache dumps */
51083 int sqlite3PcacheMxDump = 9999; /* Max cache entries for pcacheDump() */
51084 # define pcacheTrace(X) if(sqlite3PcacheTrace){sqlite3DebugPrintf X;}
51085 void pcacheDump(PCache *pCache){
51086 int N;
51087 int i, j;
51088 sqlite3_pcache_page *pLower;
51089 PgHdr *pPg;
51090 unsigned char *a;
 
 
 
 
 
 
 
 
 
 
 
51091
51092 if( sqlite3PcacheTrace<2 ) return;
51093 if( pCache->pCache==0 ) return;
51094 N = sqlite3PcachePagecount(pCache);
51095 if( N>sqlite3PcacheMxDump ) N = sqlite3PcacheMxDump;
51096 for(i=1; i<=N; i++){
51097 pLower = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, i, 0);
51098 if( pLower==0 ) continue;
51099 pPg = (PgHdr*)pLower->pExtra;
51100 printf("%3d: nRef %2d flgs %02x data ", i, pPg->nRef, pPg->flags);
51101 a = (unsigned char *)pLower->pBuf;
51102 for(j=0; j<12; j++) printf("%02x", a[j]);
51103 printf("\n");
51104 if( pPg->pPage==0 ){
51105 sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pLower, 0);
51106 }
51107 }
51108 }
51109 #else
51110 # define pcacheTrace(X)
 
51111 # define pcacheDump(X)
51112 #endif
51113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51114 /*
51115 ** Check invariants on a PgHdr entry. Return true if everything is OK.
51116 ** Return false if any invariant is violated.
51117 **
51118 ** This routine is for use inside of assert() statements only. For
@@ -51127,12 +51275,17 @@
51127 assert( pPg->pgno>0 || pPg->pPager==0 ); /* Page number is 1 or more */
51128 pCache = pPg->pCache;
51129 assert( pCache!=0 ); /* Every page has an associated PCache */
51130 if( pPg->flags & PGHDR_CLEAN ){
51131 assert( (pPg->flags & PGHDR_DIRTY)==0 );/* Cannot be both CLEAN and DIRTY */
51132 assert( pCache->pDirty!=pPg ); /* CLEAN pages not on dirty list */
51133 assert( pCache->pDirtyTail!=pPg );
 
 
 
 
 
51134 }
51135 /* WRITEABLE pages must also be DIRTY */
51136 if( pPg->flags & PGHDR_WRITEABLE ){
51137 assert( pPg->flags & PGHDR_DIRTY ); /* WRITEABLE implies DIRTY */
51138 }
@@ -51402,12 +51555,13 @@
51402 eCreate = createFlag & pCache->eCreate;
51403 assert( eCreate==0 || eCreate==1 || eCreate==2 );
51404 assert( createFlag==0 || pCache->eCreate==eCreate );
51405 assert( createFlag==0 || eCreate==1+(!pCache->bPurgeable||!pCache->pDirty) );
51406 pRes = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
51407 pcacheTrace(("%p.FETCH %d%s (result: %p)\n",pCache,pgno,
51408 createFlag?" create":"",pRes));
 
51409 return pRes;
51410 }
51411
51412 /*
51413 ** If the sqlite3PcacheFetch() routine is unable to allocate a new
@@ -51531,10 +51685,11 @@
51531 if( (--p->nRef)==0 ){
51532 if( p->flags&PGHDR_CLEAN ){
51533 pcacheUnpin(p);
51534 }else{
51535 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
 
51536 }
51537 }
51538 }
51539
51540 /*
@@ -51574,10 +51729,11 @@
51574 if( p->flags & PGHDR_CLEAN ){
51575 p->flags ^= (PGHDR_DIRTY|PGHDR_CLEAN);
51576 pcacheTrace(("%p.DIRTY %d\n",p->pCache,p->pgno));
51577 assert( (p->flags & (PGHDR_DIRTY|PGHDR_CLEAN))==PGHDR_DIRTY );
51578 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_ADD);
 
51579 }
51580 assert( sqlite3PcachePageSanity(p) );
51581 }
51582 }
51583
@@ -51636,18 +51792,28 @@
51636 /*
51637 ** Change the page number of page p to newPgno.
51638 */
51639 SQLITE_PRIVATE void sqlite3PcacheMove(PgHdr *p, Pgno newPgno){
51640 PCache *pCache = p->pCache;
 
51641 assert( p->nRef>0 );
51642 assert( newPgno>0 );
51643 assert( sqlite3PcachePageSanity(p) );
51644 pcacheTrace(("%p.MOVE %d -> %d\n",pCache,p->pgno,newPgno));
 
51645 sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
 
 
 
 
 
 
 
51646 p->pgno = newPgno;
51647 if( (p->flags&PGHDR_DIRTY) && (p->flags&PGHDR_NEED_SYNC) ){
51648 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
 
51649 }
51650 }
51651
51652 /*
51653 ** Drop every cache entry whose page number is greater than "pgno". The
@@ -51941,16 +52107,17 @@
51941 ** runtime using sqlite3_config(SQLITE_CONFIG_PCACHE_HDRSZ, &size). The
51942 ** sizes of the extensions sum to 272 bytes on x64 for 3.8.10, but this
51943 ** size can vary according to architecture, compile-time options, and
51944 ** SQLite library version number.
51945 **
51946 ** If SQLITE_PCACHE_SEPARATE_HEADER is defined, then the extension is obtained
51947 ** using a separate memory allocation from the database page content. This
51948 ** seeks to overcome the "clownshoe" problem (also called "internal
51949 ** fragmentation" in academic literature) of allocating a few bytes more
51950 ** than a power of two with the memory allocator rounding up to the next
51951 ** power of two, and leaving the rounded-up space unused.
 
51952 **
51953 ** This module tracks pointers to PgHdr1 objects. Only pcache.c communicates
51954 ** with this module. Information is passed back and forth as PgHdr1 pointers.
51955 **
51956 ** The pcache.c and pager.c modules deal pointers to PgHdr objects.
@@ -51991,34 +52158,44 @@
51991 typedef struct PgFreeslot PgFreeslot;
51992 typedef struct PGroup PGroup;
51993
51994 /*
51995 ** Each cache entry is represented by an instance of the following
51996 ** structure. Unless SQLITE_PCACHE_SEPARATE_HEADER is defined, a buffer of
51997 ** PgHdr1.pCache->szPage bytes is allocated directly before this structure
51998 ** in memory.
51999 **
52000 ** Note: Variables isBulkLocal and isAnchor were once type "u8". That works,
 
 
 
 
 
 
52001 ** but causes a 2-byte gap in the structure for most architectures (since
52002 ** pointers must be either 4 or 8-byte aligned). As this structure is located
52003 ** in memory directly after the associated page data, if the database is
52004 ** corrupt, code at the b-tree layer may overread the page buffer and
52005 ** read part of this structure before the corruption is detected. This
52006 ** can cause a valgrind error if the unitialized gap is accessed. Using u16
52007 ** ensures there is no such gap, and therefore no bytes of unitialized memory
52008 ** in the structure.
 
 
 
 
 
52009 */
52010 struct PgHdr1 {
52011 sqlite3_pcache_page page; /* Base class. Must be first. pBuf & pExtra */
52012 unsigned int iKey; /* Key value (page number) */
52013 u16 isBulkLocal; /* This page from bulk local storage */
52014 u16 isAnchor; /* This is the PGroup.lru element */
52015 PgHdr1 *pNext; /* Next in hash table chain */
52016 PCache1 *pCache; /* Cache that currently owns this page */
52017 PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
52018 PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
52019 /* NB: pLruPrev is only valid if pLruNext!=0 */
52020 };
52021
52022 /*
52023 ** A page is pinned if it is not on the LRU list. To be "pinned" means
52024 ** that the page is in active use and must not be deallocated.
@@ -52340,29 +52517,17 @@
52340 assert( pcache1.separateCache==0 );
52341 assert( pCache->pGroup==&pcache1.grp );
52342 pcache1LeaveMutex(pCache->pGroup);
52343 #endif
52344 if( benignMalloc ){ sqlite3BeginBenignMalloc(); }
52345 #ifdef SQLITE_PCACHE_SEPARATE_HEADER
52346 pPg = pcache1Alloc(pCache->szPage);
52347 p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);
52348 if( !pPg || !p ){
52349 pcache1Free(pPg);
52350 sqlite3_free(p);
52351 pPg = 0;
52352 }
52353 #else
52354 pPg = pcache1Alloc(pCache->szAlloc);
52355 #endif
52356 if( benignMalloc ){ sqlite3EndBenignMalloc(); }
52357 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
52358 pcache1EnterMutex(pCache->pGroup);
52359 #endif
52360 if( pPg==0 ) return 0;
52361 #ifndef SQLITE_PCACHE_SEPARATE_HEADER
52362 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
52363 #endif
52364 p->page.pBuf = pPg;
52365 p->page.pExtra = &p[1];
52366 p->isBulkLocal = 0;
52367 p->isAnchor = 0;
52368 p->pLruPrev = 0; /* Initializing this saves a valgrind error */
@@ -52382,13 +52547,10 @@
52382 if( p->isBulkLocal ){
52383 p->pNext = pCache->pFree;
52384 pCache->pFree = p;
52385 }else{
52386 pcache1Free(p->page.pBuf);
52387 #ifdef SQLITE_PCACHE_SEPARATE_HEADER
52388 sqlite3_free(p);
52389 #endif
52390 }
52391 (*pCache->pnPurgeable)--;
52392 }
52393
52394 /*
@@ -53025,27 +53187,45 @@
53025 unsigned int iNew
53026 ){
53027 PCache1 *pCache = (PCache1 *)p;
53028 PgHdr1 *pPage = (PgHdr1 *)pPg;
53029 PgHdr1 **pp;
53030 unsigned int h;
53031 assert( pPage->iKey==iOld );
53032 assert( pPage->pCache==pCache );
 
53033
53034 pcache1EnterMutex(pCache->pGroup);
53035
53036 h = iOld%pCache->nHash;
53037 pp = &pCache->apHash[h];
 
53038 while( (*pp)!=pPage ){
53039 pp = &(*pp)->pNext;
53040 }
53041 *pp = pPage->pNext;
53042
53043 h = iNew%pCache->nHash;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53044 pPage->iKey = iNew;
53045 pPage->pNext = pCache->apHash[h];
53046 pCache->apHash[h] = pPage;
53047 if( iNew>pCache->iMaxKey ){
53048 pCache->iMaxKey = iNew;
53049 }
53050
53051 pcache1LeaveMutex(pCache->pGroup);
@@ -53148,13 +53328,10 @@
53148 while( (nReq<0 || nFree<nReq)
53149 && (p=pcache1.grp.lru.pLruPrev)!=0
53150 && p->isAnchor==0
53151 ){
53152 nFree += pcache1MemSize(p->page.pBuf);
53153 #ifdef SQLITE_PCACHE_SEPARATE_HEADER
53154 nFree += sqlite3MemSize(p);
53155 #endif
53156 assert( PAGE_IS_UNPINNED(p) );
53157 pcache1PinPage(p);
53158 pcache1RemoveFromHash(p, 1);
53159 }
53160 pcache1LeaveMutex(&pcache1.grp);
@@ -59639,10 +59816,11 @@
59639 int flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
59640 int nSpill;
59641
59642 if( pPager->tempFile ){
59643 flags |= (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL);
 
59644 nSpill = sqlite3Config.nStmtSpill;
59645 }else{
59646 flags |= SQLITE_OPEN_MAIN_JOURNAL;
59647 nSpill = jrnlBufferSize(pPager);
59648 }
@@ -59674,10 +59852,11 @@
59674 }
59675
59676 if( rc!=SQLITE_OK ){
59677 sqlite3BitvecDestroy(pPager->pInJournal);
59678 pPager->pInJournal = 0;
 
59679 }else{
59680 assert( pPager->eState==PAGER_WRITER_LOCKED );
59681 pPager->eState = PAGER_WRITER_CACHEMOD;
59682 }
59683
@@ -66737,10 +66916,11 @@
66737 ** db using sqlite3SchemaToIndex().
66738 */
66739 SQLITE_PRIVATE int sqlite3SchemaMutexHeld(sqlite3 *db, int iDb, Schema *pSchema){
66740 Btree *p;
66741 assert( db!=0 );
 
66742 if( pSchema ) iDb = sqlite3SchemaToIndex(db, pSchema);
66743 assert( iDb>=0 && iDb<db->nDb );
66744 if( !sqlite3_mutex_held(db->mutex) ) return 0;
66745 if( iDb==1 ) return 1;
66746 p = db->aDb[iDb].pBt;
@@ -68309,12 +68489,11 @@
68309 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
68310 assert( pPage->pBt!=0 );
68311 assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
68312 assert( pPage->nOverflow==0 );
68313 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
68314 temp = 0;
68315 src = data = pPage->aData;
68316 hdr = pPage->hdrOffset;
68317 cellOffset = pPage->cellOffset;
68318 nCell = pPage->nCell;
68319 assert( nCell==get2byte(&data[hdr+3]) || CORRUPT_DB );
68320 iCellFirst = cellOffset + 2*nCell;
@@ -68364,43 +68543,42 @@
68364 }
68365
68366 cbrk = usableSize;
68367 iCellLast = usableSize - 4;
68368 iCellStart = get2byte(&data[hdr+5]);
68369 for(i=0; i<nCell; i++){
68370 u8 *pAddr; /* The i-th cell pointer */
68371 pAddr = &data[cellOffset + i*2];
68372 pc = get2byte(pAddr);
68373 testcase( pc==iCellFirst );
68374 testcase( pc==iCellLast );
68375 /* These conditions have already been verified in btreeInitPage()
68376 ** if PRAGMA cell_size_check=ON.
68377 */
68378 if( pc<iCellStart || pc>iCellLast ){
68379 return SQLITE_CORRUPT_PAGE(pPage);
68380 }
68381 assert( pc>=iCellStart && pc<=iCellLast );
68382 size = pPage->xCellSize(pPage, &src[pc]);
68383 cbrk -= size;
68384 if( cbrk<iCellStart || pc+size>usableSize ){
68385 return SQLITE_CORRUPT_PAGE(pPage);
68386 }
68387 assert( cbrk+size<=usableSize && cbrk>=iCellStart );
68388 testcase( cbrk+size==usableSize );
68389 testcase( pc+size==usableSize );
68390 put2byte(pAddr, cbrk);
68391 if( temp==0 ){
68392 if( cbrk==pc ) continue;
68393 temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
68394 memcpy(&temp[iCellStart], &data[iCellStart], usableSize - iCellStart);
68395 src = temp;
68396 }
68397 memcpy(&data[cbrk], &src[pc], size);
68398 }
68399 data[hdr+7] = 0;
68400
68401 defragment_out:
68402 assert( pPage->nFree>=0 );
68403 if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){
68404 return SQLITE_CORRUPT_PAGE(pPage);
68405 }
68406 assert( cbrk>=iCellFirst );
@@ -68469,13 +68647,13 @@
68469 return &aData[pc + x];
68470 }
68471 iAddr = pc;
68472 pTmp = &aData[pc];
68473 pc = get2byte(pTmp);
68474 if( pc<=iAddr+size ){
68475 if( pc ){
68476 /* The next slot in the chain is not past the end of the current slot */
68477 *pRc = SQLITE_CORRUPT_PAGE(pPg);
68478 }
68479 return 0;
68480 }
68481 }
@@ -68623,11 +68801,11 @@
68623 iPtr = hdr + 1;
68624 if( data[iPtr+1]==0 && data[iPtr]==0 ){
68625 iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */
68626 }else{
68627 while( (iFreeBlk = get2byte(&data[iPtr]))<iStart ){
68628 if( iFreeBlk<iPtr+4 ){
68629 if( iFreeBlk==0 ) break; /* TH3: corrupt082.100 */
68630 return SQLITE_CORRUPT_PAGE(pPage);
68631 }
68632 iPtr = iFreeBlk;
68633 }
@@ -69105,13 +69283,11 @@
69105 if( pCur ){
69106 pCur->iPage--;
69107 pCur->pPage = pCur->apPage[pCur->iPage];
69108 }
69109 testcase( pgno==0 );
69110 assert( pgno!=0 || rc==SQLITE_CORRUPT
69111 || rc==SQLITE_IOERR_NOMEM
69112 || rc==SQLITE_NOMEM );
69113 return rc;
69114 }
69115
69116 /*
69117 ** Release a MemPage. This should be called once for each prior
@@ -72049,12 +72225,10 @@
72049 ** the new child page does not match the flags field of the parent (i.e.
72050 ** if an intkey page appears to be the parent of a non-intkey page, or
72051 ** vice-versa).
72052 */
72053 static int moveToChild(BtCursor *pCur, u32 newPgno){
72054 BtShared *pBt = pCur->pBt;
72055
72056 assert( cursorOwnsBtShared(pCur) );
72057 assert( pCur->eState==CURSOR_VALID );
72058 assert( pCur->iPage<BTCURSOR_MAX_DEPTH );
72059 assert( pCur->iPage>=0 );
72060 if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
@@ -72064,11 +72238,12 @@
72064 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
72065 pCur->aiIdx[pCur->iPage] = pCur->ix;
72066 pCur->apPage[pCur->iPage] = pCur->pPage;
72067 pCur->ix = 0;
72068 pCur->iPage++;
72069 return getAndInitPage(pBt, newPgno, &pCur->pPage, pCur, pCur->curPagerFlags);
 
72070 }
72071
72072 #ifdef SQLITE_DEBUG
72073 /*
72074 ** Page pParent is an internal (non-leaf) tree page. This function
@@ -72170,11 +72345,11 @@
72170 assert( pCur->skipNext!=SQLITE_OK );
72171 return pCur->skipNext;
72172 }
72173 sqlite3BtreeClearCursor(pCur);
72174 }
72175 rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->pPage,
72176 0, pCur->curPagerFlags);
72177 if( rc!=SQLITE_OK ){
72178 pCur->eState = CURSOR_INVALID;
72179 return rc;
72180 }
@@ -73811,16 +73986,10 @@
73811 data = pPage->aData;
73812 ptr = &pPage->aCellIdx[2*idx];
73813 assert( pPage->pBt->usableSize > (u32)(ptr-data) );
73814 pc = get2byte(ptr);
73815 hdr = pPage->hdrOffset;
73816 #if 0 /* Not required. Omit for efficiency */
73817 if( pc<hdr+pPage->nCell*2 ){
73818 *pRC = SQLITE_CORRUPT_BKPT;
73819 return;
73820 }
73821 #endif
73822 testcase( pc==(u32)get2byte(&data[hdr+5]) );
73823 testcase( pc+sz==pPage->pBt->usableSize );
73824 if( pc+sz > pPage->pBt->usableSize ){
73825 *pRC = SQLITE_CORRUPT_BKPT;
73826 return;
@@ -74700,12 +74869,10 @@
74700 int szNew[NB+2]; /* Combined size of cells placed on i-th page */
74701 u8 *aSpace1; /* Space for copies of dividers cells */
74702 Pgno pgno; /* Temp var to store a page number in */
74703 u8 abDone[NB+2]; /* True after i'th new page is populated */
74704 Pgno aPgno[NB+2]; /* Page numbers of new pages before shuffling */
74705 Pgno aPgOrder[NB+2]; /* Copy of aPgno[] used for sorting pages */
74706 u16 aPgFlags[NB+2]; /* flags field of new pages before shuffling */
74707 CellArray b; /* Parsed information on cells being balanced */
74708
74709 memset(abDone, 0, sizeof(abDone));
74710 memset(&b, 0, sizeof(b));
74711 pBt = pParent->pBt;
@@ -75125,46 +75292,43 @@
75125 ** Reassign page numbers so that the new pages are in ascending order.
75126 ** This helps to keep entries in the disk file in order so that a scan
75127 ** of the table is closer to a linear scan through the file. That in turn
75128 ** helps the operating system to deliver pages from the disk more rapidly.
75129 **
75130 ** An O(n^2) insertion sort algorithm is used, but since n is never more
75131 ** than (NB+2) (a small constant), that should not be a problem.
75132 **
75133 ** When NB==3, this one optimization makes the database about 25% faster
75134 ** for large insertions and deletions.
75135 */
75136 for(i=0; i<nNew; i++){
75137 aPgOrder[i] = aPgno[i] = apNew[i]->pgno;
75138 aPgFlags[i] = apNew[i]->pDbPage->flags;
75139 for(j=0; j<i; j++){
75140 if( NEVER(aPgno[j]==aPgno[i]) ){
75141 /* This branch is taken if the set of sibling pages somehow contains
75142 ** duplicate entries. This can happen if the database is corrupt.
75143 ** It would be simpler to detect this as part of the loop below, but
75144 ** we do the detection here in order to avoid populating the pager
75145 ** cache with two separate objects associated with the same
75146 ** page number. */
75147 assert( CORRUPT_DB );
75148 rc = SQLITE_CORRUPT_BKPT;
75149 goto balance_cleanup;
75150 }
75151 }
75152 }
75153 for(i=0; i<nNew; i++){
75154 int iBest = 0; /* aPgno[] index of page number to use */
75155 for(j=1; j<nNew; j++){
75156 if( aPgOrder[j]<aPgOrder[iBest] ) iBest = j;
75157 }
75158 pgno = aPgOrder[iBest];
75159 aPgOrder[iBest] = 0xffffffff;
75160 if( iBest!=i ){
75161 if( iBest>i ){
75162 sqlite3PagerRekey(apNew[iBest]->pDbPage, pBt->nPage+iBest+1, 0);
75163 }
75164 sqlite3PagerRekey(apNew[i]->pDbPage, pgno, aPgFlags[iBest]);
75165 apNew[i]->pgno = pgno;
75166 }
75167 }
75168
75169 TRACE(("BALANCE: new: %d(%d nc=%d) %d(%d nc=%d) %d(%d nc=%d) "
75170 "%d(%d nc=%d) %d(%d nc=%d)\n",
@@ -79428,10 +79592,20 @@
79428 double r2 = (double)i;
79429 return r1==0.0
79430 || (memcmp(&r1, &r2, sizeof(r1))==0
79431 && i >= -2251799813685248LL && i < 2251799813685248LL);
79432 }
 
 
 
 
 
 
 
 
 
 
79433
79434 /*
79435 ** Convert pMem so that it has type MEM_Real or MEM_Int.
79436 ** Invalidate any prior representations.
79437 **
@@ -79450,11 +79624,11 @@
79450 sqlite3_int64 ix;
79451 assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
79452 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
79453 rc = sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc);
79454 if( ((rc==0 || rc==1) && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1)
79455 || sqlite3RealSameAsInt(pMem->u.r, (ix = (i64)pMem->u.r))
79456 ){
79457 pMem->u.i = ix;
79458 MemSetTypeFlag(pMem, MEM_Int);
79459 }else{
79460 MemSetTypeFlag(pMem, MEM_Real);
@@ -80682,14 +80856,14 @@
80682 p = sqlite3DbMallocRawNN(db, sizeof(Vdbe) );
80683 if( p==0 ) return 0;
80684 memset(&p->aOp, 0, sizeof(Vdbe)-offsetof(Vdbe,aOp));
80685 p->db = db;
80686 if( db->pVdbe ){
80687 db->pVdbe->pPrev = p;
80688 }
80689 p->pNext = db->pVdbe;
80690 p->pPrev = 0;
80691 db->pVdbe = p;
80692 assert( p->eVdbeState==VDBE_INIT_STATE );
80693 p->pParse = pParse;
80694 pParse->pVdbe = p;
80695 assert( pParse->aLabel==0 );
@@ -80767,25 +80941,32 @@
80767 return 0;
80768 }
80769 #endif
80770
80771 /*
80772 ** Swap all content between two VDBE structures.
 
 
 
 
 
 
 
80773 */
80774 SQLITE_PRIVATE void sqlite3VdbeSwap(Vdbe *pA, Vdbe *pB){
80775 Vdbe tmp, *pTmp;
80776 char *zTmp;
80777 assert( pA->db==pB->db );
80778 tmp = *pA;
80779 *pA = *pB;
80780 *pB = tmp;
80781 pTmp = pA->pNext;
80782 pA->pNext = pB->pNext;
80783 pB->pNext = pTmp;
80784 pTmp = pA->pPrev;
80785 pA->pPrev = pB->pPrev;
80786 pB->pPrev = pTmp;
80787 zTmp = pA->zSql;
80788 pA->zSql = pB->zSql;
80789 pB->zSql = zTmp;
80790 #ifdef SQLITE_ENABLE_NORMALIZE
80791 zTmp = pA->zNormSql;
@@ -81033,10 +81214,11 @@
81033 pCtx->argc = nArg;
81034 pCtx->iOp = sqlite3VdbeCurrentAddr(v);
81035 addr = sqlite3VdbeAddOp4(v, eCallCtx ? OP_PureFunc : OP_Function,
81036 p1, p2, p3, (char*)pCtx, P4_FUNCCTX);
81037 sqlite3VdbeChangeP5(v, eCallCtx & NC_SelfRef);
 
81038 return addr;
81039 }
81040
81041 /*
81042 ** Add an opcode that includes the p4 value with a P4_INT64 or
@@ -81101,11 +81283,11 @@
81101 va_end(ap);
81102 v = pParse->pVdbe;
81103 iThis = v->nOp;
81104 sqlite3VdbeAddOp4(v, OP_Explain, iThis, pParse->addrExplain, 0,
81105 zMsg, P4_DYNAMIC);
81106 sqlite3ExplainBreakpoint(bPush?"PUSH":"", sqlite3VdbeGetOp(v,-1)->p4.z);
81107 if( bPush){
81108 pParse->addrExplain = iThis;
81109 }
81110 }
81111 }
@@ -81368,10 +81550,11 @@
81368 int opcode = pOp->opcode;
81369 if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename
81370 || opcode==OP_VDestroy
81371 || opcode==OP_VCreate
81372 || opcode==OP_ParseSchema
 
81373 || ((opcode==OP_Halt || opcode==OP_HaltIfNull)
81374 && ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
81375 ){
81376 hasAbort = 1;
81377 break;
@@ -81458,12 +81641,12 @@
81458 Parse *pParse = p->pParse;
81459 int *aLabel = pParse->aLabel;
81460 p->readOnly = 1;
81461 p->bIsReader = 0;
81462 pOp = &p->aOp[p->nOp-1];
81463 while(1){
81464
81465 /* Only JUMP opcodes and the short list of special opcodes in the switch
81466 ** below need to be considered. The mkopcodeh.tcl generator script groups
81467 ** all these opcodes together near the front of the opcode list. Skip
81468 ** any opcode that does not need processing by virtual of the fact that
81469 ** it is larger than SQLITE_MX_JUMP_OPCODE, as a performance optimization.
@@ -81488,10 +81671,14 @@
81488 case OP_JournalMode: {
81489 p->readOnly = 0;
81490 p->bIsReader = 1;
81491 break;
81492 }
 
 
 
 
81493 #ifndef SQLITE_OMIT_VIRTUALTABLE
81494 case OP_VUpdate: {
81495 if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
81496 break;
81497 }
@@ -81520,15 +81707,16 @@
81520 /* The mkopcodeh.tcl script has so arranged things that the only
81521 ** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to
81522 ** have non-negative values for P2. */
81523 assert( (sqlite3OpcodeProperty[pOp->opcode]&OPFLG_JUMP)==0 || pOp->p2>=0);
81524 }
81525 if( pOp==p->aOp ) break;
81526 pOp--;
81527 }
 
81528 if( aLabel ){
81529 sqlite3DbFreeNN(p->db, pParse->aLabel);
81530 pParse->aLabel = 0;
81531 }
81532 pParse->nLabel = 0;
81533 *pMaxFuncArgs = nMaxArgs;
81534 assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) );
@@ -81773,19 +81961,23 @@
81773 /*
81774 ** Change the value of the opcode, or P1, P2, P3, or P5 operands
81775 ** for a specific instruction.
81776 */
81777 SQLITE_PRIVATE void sqlite3VdbeChangeOpcode(Vdbe *p, int addr, u8 iNewOpcode){
 
81778 sqlite3VdbeGetOp(p,addr)->opcode = iNewOpcode;
81779 }
81780 SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe *p, int addr, int val){
 
81781 sqlite3VdbeGetOp(p,addr)->p1 = val;
81782 }
81783 SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe *p, int addr, int val){
 
81784 sqlite3VdbeGetOp(p,addr)->p2 = val;
81785 }
81786 SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe *p, int addr, int val){
 
81787 sqlite3VdbeGetOp(p,addr)->p3 = val;
81788 }
81789 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe *p, u16 p5){
81790 assert( p->nOp>0 || p->db->mallocFailed );
81791 if( p->nOp>0 ) p->aOp[p->nOp-1].p5 = p5;
@@ -81817,11 +82009,11 @@
81817 assert( p->aOp[addr].opcode==OP_Once
81818 || p->aOp[addr].opcode==OP_If
81819 || p->aOp[addr].opcode==OP_FkIfZero );
81820 assert( p->aOp[addr].p4type==0 );
81821 #ifdef SQLITE_VDBE_COVERAGE
81822 sqlite3VdbeGetOp(p,-1)->iSrcLine = 0; /* Erase VdbeCoverage() macros */
81823 #endif
81824 p->nOp--;
81825 }else{
81826 sqlite3VdbeChangeP2(p, addr, p->nOp);
81827 }
@@ -81831,25 +82023,27 @@
81831 /*
81832 ** If the input FuncDef structure is ephemeral, then free it. If
81833 ** the FuncDef is not ephermal, then do nothing.
81834 */
81835 static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
 
81836 if( (pDef->funcFlags & SQLITE_FUNC_EPHEM)!=0 ){
81837 sqlite3DbFreeNN(db, pDef);
81838 }
81839 }
81840
81841 /*
81842 ** Delete a P4 value if necessary.
81843 */
81844 static SQLITE_NOINLINE void freeP4Mem(sqlite3 *db, Mem *p){
81845 if( p->szMalloc ) sqlite3DbFree(db, p->zMalloc);
81846 sqlite3DbFreeNN(db, p);
81847 }
81848 static SQLITE_NOINLINE void freeP4FuncCtx(sqlite3 *db, sqlite3_context *p){
 
81849 freeEphemeralFunction(db, p->pFunc);
81850 sqlite3DbFreeNN(db, p);
81851 }
81852 static void freeP4(sqlite3 *db, int p4type, void *p4){
81853 assert( db );
81854 switch( p4type ){
81855 case P4_FUNCCTX: {
@@ -81858,11 +82052,11 @@
81858 }
81859 case P4_REAL:
81860 case P4_INT64:
81861 case P4_DYNAMIC:
81862 case P4_INTARRAY: {
81863 sqlite3DbFree(db, p4);
81864 break;
81865 }
81866 case P4_KEYINFO: {
81867 if( db->pnBytesFreed==0 ) sqlite3KeyInfoUnref((KeyInfo*)p4);
81868 break;
@@ -81897,10 +82091,11 @@
81897 ** opcodes contained within. If aOp is not NULL it is assumed to contain
81898 ** nOp entries.
81899 */
81900 static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){
81901 assert( nOp>=0 );
 
81902 if( aOp ){
81903 Op *pOp = &aOp[nOp-1];
81904 while(1){ /* Exit via break */
81905 if( pOp->p4type <= P4_FREE_IF_LE ) freeP4(db, pOp->p4type, pOp->p4.p);
81906 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
@@ -81907,11 +82102,11 @@
81907 sqlite3DbFree(db, pOp->zComment);
81908 #endif
81909 if( pOp==aOp ) break;
81910 pOp--;
81911 }
81912 sqlite3DbFreeNN(db, aOp);
81913 }
81914 }
81915
81916 /*
81917 ** Link the SubProgram object passed as the second argument into the linked
@@ -82138,17 +82333,17 @@
82138 #ifdef SQLITE_VDBE_COVERAGE
82139 /*
82140 ** Set the value if the iSrcLine field for the previously coded instruction.
82141 */
82142 SQLITE_PRIVATE void sqlite3VdbeSetLineNumber(Vdbe *v, int iLine){
82143 sqlite3VdbeGetOp(v,-1)->iSrcLine = iLine;
82144 }
82145 #endif /* SQLITE_VDBE_COVERAGE */
82146
82147 /*
82148 ** Return the opcode for a given address. If the address is -1, then
82149 ** return the most recently inserted opcode.
82150 **
82151 ** If a memory allocation error has occurred prior to the calling of this
82152 ** routine, then a pointer to a dummy VdbeOp will be returned. That opcode
82153 ** is readable but not writable, though it is cast to a writable value.
82154 ** The return of a dummy opcode allows the call to continue functioning
@@ -82160,20 +82355,23 @@
82160 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){
82161 /* C89 specifies that the constant "dummy" will be initialized to all
82162 ** zeros, which is correct. MSVC generates a warning, nevertheless. */
82163 static VdbeOp dummy; /* Ignore the MSVC warning about no initializer */
82164 assert( p->eVdbeState==VDBE_INIT_STATE );
82165 if( addr<0 ){
82166 addr = p->nOp - 1;
82167 }
82168 assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );
82169 if( p->db->mallocFailed ){
82170 return (VdbeOp*)&dummy;
82171 }else{
82172 return &p->aOp[addr];
82173 }
82174 }
 
 
 
 
 
 
82175
82176 #if defined(SQLITE_ENABLE_EXPLAIN_COMMENTS)
82177 /*
82178 ** Return an integer value for one of the parameters to the opcode pOp
82179 ** determined by character c.
@@ -82658,11 +82856,11 @@
82658 if( p->flags&(MEM_Agg|MEM_Dyn) ){
82659 testcase( (p->flags & MEM_Dyn)!=0 && p->xDel==sqlite3VdbeFrameMemDel );
82660 sqlite3VdbeMemRelease(p);
82661 p->flags = MEM_Undefined;
82662 }else if( p->szMalloc ){
82663 sqlite3DbFreeNN(db, p->zMalloc);
82664 p->szMalloc = 0;
82665 p->flags = MEM_Undefined;
82666 }
82667 #ifdef SQLITE_DEBUG
82668 else{
@@ -83650,11 +83848,11 @@
83650 if( sqlite3_stmt_busy((sqlite3_stmt*)p) ){
83651 cnt++;
83652 if( p->readOnly==0 ) nWrite++;
83653 if( p->bIsReader ) nRead++;
83654 }
83655 p = p->pNext;
83656 }
83657 assert( cnt==db->nVdbeActive );
83658 assert( nWrite==db->nVdbeWrite );
83659 assert( nRead==db->nVdbeRead );
83660 }
@@ -84179,27 +84377,28 @@
84179 ** VdbeDelete() also unlinks the Vdbe from the list of VMs associated with
84180 ** the database connection and frees the object itself.
84181 */
84182 static void sqlite3VdbeClearObject(sqlite3 *db, Vdbe *p){
84183 SubProgram *pSub, *pNext;
 
84184 assert( p->db==0 || p->db==db );
84185 if( p->aColName ){
84186 releaseMemArray(p->aColName, p->nResColumn*COLNAME_N);
84187 sqlite3DbFreeNN(db, p->aColName);
84188 }
84189 for(pSub=p->pProgram; pSub; pSub=pNext){
84190 pNext = pSub->pNext;
84191 vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
84192 sqlite3DbFree(db, pSub);
84193 }
84194 if( p->eVdbeState!=VDBE_INIT_STATE ){
84195 releaseMemArray(p->aVar, p->nVar);
84196 if( p->pVList ) sqlite3DbFreeNN(db, p->pVList);
84197 if( p->pFree ) sqlite3DbFreeNN(db, p->pFree);
84198 }
84199 vdbeFreeOpArray(db, p->aOp, p->nOp);
84200 sqlite3DbFree(db, p->zSql);
84201 #ifdef SQLITE_ENABLE_NORMALIZE
84202 sqlite3DbFree(db, p->zNormSql);
84203 {
84204 DblquoteStr *pThis, *pNext;
84205 for(pThis=p->pDblStr; pThis; pThis=pNext){
@@ -84225,24 +84424,21 @@
84225 SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe *p){
84226 sqlite3 *db;
84227
84228 assert( p!=0 );
84229 db = p->db;
 
84230 assert( sqlite3_mutex_held(db->mutex) );
84231 sqlite3VdbeClearObject(db, p);
84232 if( db->pnBytesFreed==0 ){
84233 if( p->pPrev ){
84234 p->pPrev->pNext = p->pNext;
84235 }else{
84236 assert( db->pVdbe==p );
84237 db->pVdbe = p->pNext;
84238 }
84239 if( p->pNext ){
84240 p->pNext->pPrev = p->pPrev;
84241 }
84242 }
84243 sqlite3DbFreeNN(db, p);
84244 }
84245
84246 /*
84247 ** The cursor "p" has a pending seek operation that has not yet been
84248 ** carried out. Seek the cursor now. If an error occurs, return
@@ -85733,11 +85929,11 @@
85733 ** prepared statements. The flag is set to 1 for an immediate expiration
85734 ** and set to 2 for an advisory expiration.
85735 */
85736 SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3 *db, int iCode){
85737 Vdbe *p;
85738 for(p = db->pVdbe; p; p=p->pNext){
85739 p->expired = iCode+1;
85740 }
85741 }
85742
85743 /*
@@ -85854,17 +86050,18 @@
85854 **
85855 ** This function is used to free UnpackedRecord structures allocated by
85856 ** the vdbeUnpackRecord() function found in vdbeapi.c.
85857 */
85858 static void vdbeFreeUnpacked(sqlite3 *db, int nField, UnpackedRecord *p){
 
85859 if( p ){
85860 int i;
85861 for(i=0; i<nField; i++){
85862 Mem *pMem = &p->aMem[i];
85863 if( pMem->zMalloc ) sqlite3VdbeMemReleaseMalloc(pMem);
85864 }
85865 sqlite3DbFreeNN(db, p);
85866 }
85867 }
85868 #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
85869
85870 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
@@ -85931,11 +86128,11 @@
85931 if( preupdate.aNew ){
85932 int i;
85933 for(i=0; i<pCsr->nField; i++){
85934 sqlite3VdbeMemRelease(&preupdate.aNew[i]);
85935 }
85936 sqlite3DbFreeNN(db, preupdate.aNew);
85937 }
85938 }
85939 #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
85940
85941 /************** End of vdbeaux.c *********************************************/
@@ -86048,11 +86245,13 @@
86048 Vdbe *v = (Vdbe*)pStmt;
86049 sqlite3 *db = v->db;
86050 if( vdbeSafety(v) ) return SQLITE_MISUSE_BKPT;
86051 sqlite3_mutex_enter(db->mutex);
86052 checkProfileCallback(db, v);
86053 rc = sqlite3VdbeFinalize(v);
 
 
86054 rc = sqlite3ApiExit(db, rc);
86055 sqlite3LeaveMutexAndCloseZombie(db);
86056 }
86057 return rc;
86058 }
@@ -87370,11 +87569,11 @@
87370 ** the mutex is released if any kind of error occurs.
87371 **
87372 ** The error code stored in database p->db is overwritten with the return
87373 ** value in any case.
87374 */
87375 static int vdbeUnbind(Vdbe *p, int i){
87376 Mem *pVar;
87377 if( vdbeSafetyNotNull(p) ){
87378 return SQLITE_MISUSE_BKPT;
87379 }
87380 sqlite3_mutex_enter(p->db->mutex);
@@ -87383,16 +87582,15 @@
87383 sqlite3_mutex_leave(p->db->mutex);
87384 sqlite3_log(SQLITE_MISUSE,
87385 "bind on a busy prepared statement: [%s]", p->zSql);
87386 return SQLITE_MISUSE_BKPT;
87387 }
87388 if( i<1 || i>p->nVar ){
87389 sqlite3Error(p->db, SQLITE_RANGE);
87390 sqlite3_mutex_leave(p->db->mutex);
87391 return SQLITE_RANGE;
87392 }
87393 i--;
87394 pVar = &p->aVar[i];
87395 sqlite3VdbeMemRelease(pVar);
87396 pVar->flags = MEM_Null;
87397 p->db->errCode = SQLITE_OK;
87398
@@ -87425,11 +87623,11 @@
87425 ){
87426 Vdbe *p = (Vdbe *)pStmt;
87427 Mem *pVar;
87428 int rc;
87429
87430 rc = vdbeUnbind(p, i);
87431 if( rc==SQLITE_OK ){
87432 if( zData!=0 ){
87433 pVar = &p->aVar[i-1];
87434 rc = sqlite3VdbeMemSetStr(pVar, zData, nData, encoding, xDel);
87435 if( rc==SQLITE_OK && encoding!=0 ){
@@ -87474,11 +87672,11 @@
87474 return bindText(pStmt, i, zData, nData, xDel, 0);
87475 }
87476 SQLITE_API int sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){
87477 int rc;
87478 Vdbe *p = (Vdbe *)pStmt;
87479 rc = vdbeUnbind(p, i);
87480 if( rc==SQLITE_OK ){
87481 sqlite3VdbeMemSetDouble(&p->aVar[i-1], rValue);
87482 sqlite3_mutex_leave(p->db->mutex);
87483 }
87484 return rc;
@@ -87487,21 +87685,21 @@
87487 return sqlite3_bind_int64(p, i, (i64)iValue);
87488 }
87489 SQLITE_API int sqlite3_bind_int64(sqlite3_stmt *pStmt, int i, sqlite_int64 iValue){
87490 int rc;
87491 Vdbe *p = (Vdbe *)pStmt;
87492 rc = vdbeUnbind(p, i);
87493 if( rc==SQLITE_OK ){
87494 sqlite3VdbeMemSetInt64(&p->aVar[i-1], iValue);
87495 sqlite3_mutex_leave(p->db->mutex);
87496 }
87497 return rc;
87498 }
87499 SQLITE_API int sqlite3_bind_null(sqlite3_stmt *pStmt, int i){
87500 int rc;
87501 Vdbe *p = (Vdbe*)pStmt;
87502 rc = vdbeUnbind(p, i);
87503 if( rc==SQLITE_OK ){
87504 sqlite3_mutex_leave(p->db->mutex);
87505 }
87506 return rc;
87507 }
@@ -87512,11 +87710,11 @@
87512 const char *zPTtype,
87513 void (*xDestructor)(void*)
87514 ){
87515 int rc;
87516 Vdbe *p = (Vdbe*)pStmt;
87517 rc = vdbeUnbind(p, i);
87518 if( rc==SQLITE_OK ){
87519 sqlite3VdbeMemSetPointer(&p->aVar[i-1], pPtr, zPTtype, xDestructor);
87520 sqlite3_mutex_leave(p->db->mutex);
87521 }else if( xDestructor ){
87522 xDestructor(pPtr);
@@ -87590,11 +87788,11 @@
87590 return rc;
87591 }
87592 SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt *pStmt, int i, int n){
87593 int rc;
87594 Vdbe *p = (Vdbe *)pStmt;
87595 rc = vdbeUnbind(p, i);
87596 if( rc==SQLITE_OK ){
87597 #ifndef SQLITE_OMIT_INCRBLOB
87598 sqlite3VdbeMemSetZeroBlob(&p->aVar[i-1], n);
87599 #else
87600 rc = sqlite3VdbeMemSetZeroBlob(&p->aVar[i-1], n);
@@ -87750,11 +87948,11 @@
87750 #endif
87751 sqlite3_mutex_enter(pDb->mutex);
87752 if( pStmt==0 ){
87753 pNext = (sqlite3_stmt*)pDb->pVdbe;
87754 }else{
87755 pNext = (sqlite3_stmt*)((Vdbe*)pStmt)->pNext;
87756 }
87757 sqlite3_mutex_leave(pDb->mutex);
87758 return pNext;
87759 }
87760
@@ -87775,12 +87973,15 @@
87775 if( op==SQLITE_STMTSTATUS_MEMUSED ){
87776 sqlite3 *db = pVdbe->db;
87777 sqlite3_mutex_enter(db->mutex);
87778 v = 0;
87779 db->pnBytesFreed = (int*)&v;
 
 
87780 sqlite3VdbeDelete(pVdbe);
87781 db->pnBytesFreed = 0;
 
87782 sqlite3_mutex_leave(db->mutex);
87783 }else{
87784 v = pVdbe->aCounter[op];
87785 if( resetFlag ) pVdbe->aCounter[op] = 0;
87786 }
@@ -88616,11 +88817,12 @@
88616 ** floating point value of rValue. Return true and set *piValue to the
88617 ** integer value if the string is in range to be an integer. Otherwise,
88618 ** return false.
88619 */
88620 static int alsoAnInt(Mem *pRec, double rValue, i64 *piValue){
88621 i64 iValue = (double)rValue;
 
88622 if( sqlite3RealSameAsInt(rValue,iValue) ){
88623 *piValue = iValue;
88624 return 1;
88625 }
88626 return 0==sqlite3Atoi64(pRec->z, piValue, pRec->n, pRec->enc);
@@ -88778,21 +88980,22 @@
88778 **
88779 ** Unlike applyNumericAffinity(), this routine does not modify pMem->flags.
88780 ** But it does set pMem->u.r and pMem->u.i appropriately.
88781 */
88782 static u16 numericType(Mem *pMem){
88783 if( pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal) ){
 
 
88784 testcase( pMem->flags & MEM_Int );
88785 testcase( pMem->flags & MEM_Real );
88786 testcase( pMem->flags & MEM_IntReal );
88787 return pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal);
88788 }
88789 if( pMem->flags & (MEM_Str|MEM_Blob) ){
88790 testcase( pMem->flags & MEM_Str );
88791 testcase( pMem->flags & MEM_Blob );
88792 return computeNumericType(pMem);
88793 }
88794 return 0;
88795 }
88796
88797 #ifdef SQLITE_DEBUG
88798 /*
@@ -90033,25 +90236,24 @@
90033 case OP_Add: /* same as TK_PLUS, in1, in2, out3 */
90034 case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */
90035 case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */
90036 case OP_Divide: /* same as TK_SLASH, in1, in2, out3 */
90037 case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */
90038 u16 flags; /* Combined MEM_* flags from both inputs */
90039 u16 type1; /* Numeric type of left operand */
90040 u16 type2; /* Numeric type of right operand */
90041 i64 iA; /* Integer value of left operand */
90042 i64 iB; /* Integer value of right operand */
90043 double rA; /* Real value of left operand */
90044 double rB; /* Real value of right operand */
90045
90046 pIn1 = &aMem[pOp->p1];
90047 type1 = numericType(pIn1);
90048 pIn2 = &aMem[pOp->p2];
90049 type2 = numericType(pIn2);
90050 pOut = &aMem[pOp->p3];
90051 flags = pIn1->flags | pIn2->flags;
90052 if( (type1 & type2 & MEM_Int)!=0 ){
 
90053 iA = pIn1->u.i;
90054 iB = pIn2->u.i;
90055 switch( pOp->opcode ){
90056 case OP_Add: if( sqlite3AddInt64(&iB,iA) ) goto fp_math; break;
90057 case OP_Subtract: if( sqlite3SubInt64(&iB,iA) ) goto fp_math; break;
@@ -90069,13 +90271,16 @@
90069 break;
90070 }
90071 }
90072 pOut->u.i = iB;
90073 MemSetTypeFlag(pOut, MEM_Int);
90074 }else if( (flags & MEM_Null)!=0 ){
90075 goto arithmetic_result_is_null;
90076 }else{
 
 
 
90077 fp_math:
90078 rA = sqlite3VdbeRealValue(pIn1);
90079 rB = sqlite3VdbeRealValue(pIn2);
90080 switch( pOp->opcode ){
90081 case OP_Add: rB += rA; break;
@@ -90941,15 +91146,18 @@
90941 **
90942 ** Check the cursor P1 to see if it is currently pointing at a NULL row.
90943 ** If it is, then set register P3 to NULL and jump immediately to P2.
90944 ** If P1 is not on a NULL row, then fall through without making any
90945 ** changes.
 
 
90946 */
90947 case OP_IfNullRow: { /* jump */
 
90948 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
90949 assert( p->apCsr[pOp->p1]!=0 );
90950 if( p->apCsr[pOp->p1]->nullRow ){
90951 sqlite3VdbeMemSetNull(aMem + pOp->p3);
90952 goto jump_to_p2;
90953 }
90954 break;
90955 }
@@ -93052,11 +93260,11 @@
93052 **
93053 ** <li> If the cursor is successfully moved to the target row by 0 or more
93054 ** sqlite3BtreeNext() calls, then jump to This.P2, which will land just
93055 ** past the OP_IdxGT or OP_IdxGE opcode that follows the OP_SeekGE.
93056 **
93057 ** <li> If the cursor ends up past the target row (indicating the the target
93058 ** row does not exist in the btree) then jump to SeekOP.P2.
93059 ** </ol>
93060 */
93061 case OP_SeekScan: {
93062 VdbeCursor *pC;
@@ -94388,11 +94596,13 @@
94388 rc = sqlite3VdbeSorterNext(db, pC);
94389 goto next_tail;
94390
94391 case OP_Prev: /* jump */
94392 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
94393 assert( pOp->p5<ArraySize(p->aCounter) );
 
 
94394 pC = p->apCsr[pOp->p1];
94395 assert( pC!=0 );
94396 assert( pC->deferredMoveto==0 );
94397 assert( pC->eCurType==CURTYPE_BTREE );
94398 assert( pC->seekOp==OP_SeekLT || pC->seekOp==OP_SeekLE
@@ -94401,11 +94611,13 @@
94401 rc = sqlite3BtreePrevious(pC->uc.pCursor, pOp->p3);
94402 goto next_tail;
94403
94404 case OP_Next: /* jump */
94405 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
94406 assert( pOp->p5<ArraySize(p->aCounter) );
 
 
94407 pC = p->apCsr[pOp->p1];
94408 assert( pC!=0 );
94409 assert( pC->deferredMoveto==0 );
94410 assert( pC->eCurType==CURTYPE_BTREE );
94411 assert( pC->seekOp==OP_SeekGT || pC->seekOp==OP_SeekGE
@@ -94608,14 +94820,14 @@
94608
94609 /* The IdxRowid and Seek opcodes are combined because of the commonality
94610 ** of sqlite3VdbeCursorRestore() and sqlite3VdbeIdxRowid(). */
94611 rc = sqlite3VdbeCursorRestore(pC);
94612
94613 /* sqlite3VbeCursorRestore() can only fail if the record has been deleted
94614 ** out from under the cursor. That will never happens for an IdxRowid
94615 ** or Seek opcode */
94616 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
94617
94618 if( !pC->nullRow ){
94619 rowid = 0; /* Not needed. Only used to silence a warning. */
94620 rc = sqlite3VdbeIdxRowid(db, pC->uc.pCursor, &rowid);
94621 if( rc!=SQLITE_OK ){
@@ -95513,11 +95725,11 @@
95513
95514 /* Opcode: OffsetLimit P1 P2 P3 * *
95515 ** Synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)
95516 **
95517 ** This opcode performs a commonly used computation associated with
95518 ** LIMIT and OFFSET process. r[P1] holds the limit counter. r[P3]
95519 ** holds the offset counter. The opcode computes the combined value
95520 ** of the LIMIT and OFFSET and stores that value in r[P2]. The r[P2]
95521 ** value computed is the total number of rows that will need to be
95522 ** visited in order to complete the query.
95523 **
@@ -101110,10 +101322,12 @@
101110 sqlite3_file *pJfd, /* Preallocated, blank file handle */
101111 int flags, /* Opening flags */
101112 int nSpill /* Bytes buffered before opening the file */
101113 ){
101114 MemJournal *p = (MemJournal*)pJfd;
 
 
101115
101116 /* Zero the file-handle object. If nSpill was passed zero, initialize
101117 ** it using the sqlite3OsOpen() function of the underlying VFS. In this
101118 ** case none of the code in this module is executed as a result of calls
101119 ** made on the journal file-handle. */
@@ -101552,13 +101766,11 @@
101552 if( ExprHasProperty(pExpr, EP_WinFunc) ){
101553 if( ALWAYS(pExpr->y.pWin!=0) ){
101554 pExpr->y.pWin->pOwner = pExpr;
101555 }
101556 }
101557 sqlite3ParserAddCleanup(pParse,
101558 (void(*)(sqlite3*,void*))sqlite3ExprDelete,
101559 pDup);
101560 }
101561 }
101562
101563 /*
101564 ** Subqueries stores the original database, table and column names for their
@@ -104363,11 +104575,13 @@
104363 ** Also propagate EP_Propagate flags up from Expr.x.pList to Expr.flags,
104364 ** if appropriate.
104365 */
104366 static void exprSetHeight(Expr *p){
104367 int nHeight = p->pLeft ? p->pLeft->nHeight : 0;
104368 if( p->pRight && p->pRight->nHeight>nHeight ) nHeight = p->pRight->nHeight;
 
 
104369 if( ExprUseXSelect(p) ){
104370 heightOfSelect(p->x.pSelect, &nHeight);
104371 }else if( p->x.pList ){
104372 heightOfExprList(p->x.pList, &nHeight);
104373 p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList);
@@ -104506,19 +104720,30 @@
104506 if( pRoot==0 ){
104507 assert( db->mallocFailed );
104508 sqlite3ExprDelete(db, pLeft);
104509 sqlite3ExprDelete(db, pRight);
104510 }else{
 
 
104511 if( pRight ){
104512 pRoot->pRight = pRight;
104513 pRoot->flags |= EP_Propagate & pRight->flags;
 
 
 
 
 
104514 }
104515 if( pLeft ){
104516 pRoot->pLeft = pLeft;
104517 pRoot->flags |= EP_Propagate & pLeft->flags;
 
 
 
 
 
104518 }
104519 exprSetHeight(pRoot);
104520 }
104521 }
104522
104523 /*
104524 ** Allocate an Expr node which joins as many as two subtrees.
@@ -104800,10 +105025,11 @@
104800 /*
104801 ** Recursively delete an expression tree.
104802 */
104803 static SQLITE_NOINLINE void sqlite3ExprDeleteNN(sqlite3 *db, Expr *p){
104804 assert( p!=0 );
 
104805 assert( !ExprUseUValue(p) || p->u.iValue>=0 );
104806 assert( !ExprUseYWin(p) || !ExprUseYSub(p) );
104807 assert( !ExprUseYWin(p) || p->y.pWin!=0 || db->mallocFailed );
104808 assert( p->op!=TK_FUNCTION || !ExprUseYSub(p) );
104809 #ifdef SQLITE_DEBUG
@@ -104831,16 +105057,12 @@
104831 sqlite3WindowDelete(db, p->y.pWin);
104832 }
104833 #endif
104834 }
104835 }
104836 if( ExprHasProperty(p, EP_MemToken) ){
104837 assert( !ExprHasProperty(p, EP_IntValue) );
104838 sqlite3DbFree(db, p->u.zToken);
104839 }
104840 if( !ExprHasProperty(p, EP_Static) ){
104841 sqlite3DbFreeNN(db, p);
104842 }
104843 }
104844 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
104845 if( p ) sqlite3ExprDeleteNN(db, p);
104846 }
@@ -104867,12 +105089,13 @@
104867 **
104868 ** The deferred delete is (currently) implemented by adding the
104869 ** pExpr to the pParse->pConstExpr list with a register number of 0.
104870 */
104871 SQLITE_PRIVATE void sqlite3ExprDeferredDelete(Parse *pParse, Expr *pExpr){
104872 pParse->pConstExpr =
104873 sqlite3ExprListAppend(pParse, pParse->pConstExpr, pExpr);
 
104874 }
104875
104876 /* Invoke sqlite3RenameExprUnmap() and sqlite3ExprDelete() on the
104877 ** expression.
104878 */
@@ -104942,11 +105165,10 @@
104942 ){
104943 nSize = EXPR_FULLSIZE;
104944 }else{
104945 assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
104946 assert( !ExprHasProperty(p, EP_OuterON) );
104947 assert( !ExprHasProperty(p, EP_MemToken) );
104948 assert( !ExprHasVVAProperty(p, EP_NoReduce) );
104949 if( p->pLeft || p->x.pList ){
104950 nSize = EXPR_REDUCEDSIZE | EP_Reduced;
104951 }else{
104952 assert( p->pRight==0 );
@@ -105046,11 +105268,11 @@
105046 memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
105047 }
105048 }
105049
105050 /* Set the EP_Reduced, EP_TokenOnly, and EP_Static flags appropriately. */
105051 pNew->flags &= ~(EP_Reduced|EP_TokenOnly|EP_Static|EP_MemToken);
105052 pNew->flags |= nStructSize & (EP_Reduced|EP_TokenOnly);
105053 pNew->flags |= staticFlag;
105054 ExprClearVVAProperties(pNew);
105055 if( dupFlags ){
105056 ExprSetVVAProperty(pNew, EP_Immutable);
@@ -105622,16 +105844,17 @@
105622 */
105623 static SQLITE_NOINLINE void exprListDeleteNN(sqlite3 *db, ExprList *pList){
105624 int i = pList->nExpr;
105625 struct ExprList_item *pItem = pList->a;
105626 assert( pList->nExpr>0 );
 
105627 do{
105628 sqlite3ExprDelete(db, pItem->pExpr);
105629 sqlite3DbFree(db, pItem->zEName);
105630 pItem++;
105631 }while( --i>0 );
105632 sqlite3DbFreeNN(db, pList);
105633 }
105634 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
105635 if( pList ) exprListDeleteNN(db, pList);
105636 }
105637
@@ -106918,11 +107141,11 @@
106918 if( pLimit ){
106919 pLimit->affExpr = SQLITE_AFF_NUMERIC;
106920 pLimit = sqlite3PExpr(pParse, TK_NE,
106921 sqlite3ExprDup(db, pSel->pLimit->pLeft, 0), pLimit);
106922 }
106923 sqlite3ExprDelete(db, pSel->pLimit->pLeft);
106924 pSel->pLimit->pLeft = pLimit;
106925 }else{
106926 /* If there is no pre-existing limit add a limit of 1 */
106927 pLimit = sqlite3Expr(pParse->db, TK_INTEGER, "1");
106928 pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
@@ -107432,11 +107655,11 @@
107432 u8 p5 /* P5 value for OP_Column + FLAGS */
107433 ){
107434 assert( pParse->pVdbe!=0 );
107435 sqlite3ExprCodeGetColumnOfTable(pParse->pVdbe, pTab, iTable, iColumn, iReg);
107436 if( p5 ){
107437 VdbeOp *pOp = sqlite3VdbeGetOp(pParse->pVdbe,-1);
107438 if( pOp->opcode==OP_Column ) pOp->p5 = p5;
107439 }
107440 return iReg;
107441 }
107442
@@ -107501,11 +107724,11 @@
107501 /*
107502 ** If the last opcode is a OP_Copy, then set the do-not-merge flag (p5)
107503 ** so that a subsequent copy will not be merged into this one.
107504 */
107505 static void setDoNotMergeFlagOnCopy(Vdbe *v){
107506 if( sqlite3VdbeGetOp(v, -1)->opcode==OP_Copy ){
107507 sqlite3VdbeChangeP5(v, 1); /* Tag trailing OP_Copy as not mergable */
107508 }
107509 }
107510
107511 /*
@@ -107672,11 +107895,11 @@
107672 Table *pTab = pCol->pTab;
107673 sqlite3VdbeAddOp3(v, OP_Column, pAggInfo->sortingIdxPTab,
107674 pCol->iSorterColumn, target);
107675 if( pCol->iColumn<0 ){
107676 VdbeComment((v,"%s.rowid",pTab->zName));
107677 }else{
107678 VdbeComment((v,"%s.%s",
107679 pTab->zName, pTab->aCol[pCol->iColumn].zCnName));
107680 if( pTab->aCol[pCol->iColumn].affinity==SQLITE_AFF_REAL ){
107681 sqlite3VdbeAddOp1(v, OP_RealAffinity, target);
107682 }
@@ -108267,10 +108490,25 @@
108267 ** on a LEFT JOIN NULL row.
108268 */
108269 case TK_IF_NULL_ROW: {
108270 int addrINR;
108271 u8 okConstFactor = pParse->okConstFactor;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108272 addrINR = sqlite3VdbeAddOp1(v, OP_IfNullRow, pExpr->iTable);
108273 /* Temporarily disable factoring of constant expressions, since
108274 ** even though expressions may appear to be constant, they are not
108275 ** really constant because they originate from the right-hand side
108276 ** of a LEFT JOIN. */
@@ -108608,11 +108846,11 @@
108608 }else{
108609 int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
108610 if( inReg!=target+i ){
108611 VdbeOp *pOp;
108612 if( copyOp==OP_Copy
108613 && (pOp=sqlite3VdbeGetOp(v, -1))->opcode==OP_Copy
108614 && pOp->p1+pOp->p3+1==inReg
108615 && pOp->p2+pOp->p3+1==target+i
108616 && pOp->p5==0 /* The do-not-merge flag must be clear */
108617 ){
108618 pOp->p3++;
@@ -109644,10 +109882,11 @@
109644 ** fact is exploited for efficiency.
109645 */
109646 SQLITE_PRIVATE int sqlite3ReferencesSrcList(Parse *pParse, Expr *pExpr, SrcList *pSrcList){
109647 Walker w;
109648 struct RefSrcList x;
 
109649 memset(&w, 0, sizeof(w));
109650 memset(&x, 0, sizeof(x));
109651 w.xExprCallback = exprRefToSrcList;
109652 w.xSelectCallback = selectRefEnter;
109653 w.xSelectCallback2 = selectRefLeave;
@@ -109660,11 +109899,11 @@
109660 #ifndef SQLITE_OMIT_WINDOWFUNC
109661 if( ExprHasProperty(pExpr, EP_WinFunc) ){
109662 sqlite3WalkExpr(&w, pExpr->y.pWin->pFilter);
109663 }
109664 #endif
109665 sqlite3DbFree(pParse->db, x.aiExclude);
109666 if( w.eCode & 0x01 ){
109667 return 1;
109668 }else if( w.eCode ){
109669 return 0;
109670 }else{
@@ -109691,21 +109930,22 @@
109691 ){
109692 AggInfo *pAggInfo = pExpr->pAggInfo;
109693 int iAgg = pExpr->iAgg;
109694 Parse *pParse = pWalker->pParse;
109695 sqlite3 *db = pParse->db;
109696 assert( pExpr->op==TK_AGG_COLUMN || pExpr->op==TK_AGG_FUNCTION );
109697 if( pExpr->op==TK_AGG_COLUMN ){
109698 assert( iAgg>=0 && iAgg<pAggInfo->nColumn );
109699 if( pAggInfo->aCol[iAgg].pCExpr==pExpr ){
109700 pExpr = sqlite3ExprDup(db, pExpr, 0);
109701 if( pExpr ){
109702 pAggInfo->aCol[iAgg].pCExpr = pExpr;
109703 sqlite3ExprDeferredDelete(pParse, pExpr);
109704 }
109705 }
109706 }else{
 
109707 assert( iAgg>=0 && iAgg<pAggInfo->nFunc );
109708 if( pAggInfo->aFunc[iAgg].pFExpr==pExpr ){
109709 pExpr = sqlite3ExprDup(db, pExpr, 0);
109710 if( pExpr ){
109711 pAggInfo->aFunc[iAgg].pFExpr = pExpr;
@@ -109772,14 +110012,16 @@
109772 SrcList *pSrcList = pNC->pSrcList;
109773 AggInfo *pAggInfo = pNC->uNC.pAggInfo;
109774
109775 assert( pNC->ncFlags & NC_UAggInfo );
109776 switch( pExpr->op ){
 
109777 case TK_AGG_COLUMN:
109778 case TK_COLUMN: {
109779 testcase( pExpr->op==TK_AGG_COLUMN );
109780 testcase( pExpr->op==TK_COLUMN );
 
109781 /* Check to see if the column is in one of the tables in the FROM
109782 ** clause of the aggregate query */
109783 if( ALWAYS(pSrcList!=0) ){
109784 SrcItem *pItem = pSrcList->a;
109785 for(i=0; i<pSrcList->nSrc; i++, pItem++){
@@ -109793,12 +110035,14 @@
109793 ** is not an entry there already.
109794 */
109795 int k;
109796 pCol = pAggInfo->aCol;
109797 for(k=0; k<pAggInfo->nColumn; k++, pCol++){
109798 if( pCol->iTable==pExpr->iTable &&
109799 pCol->iColumn==pExpr->iColumn ){
 
 
109800 break;
109801 }
109802 }
109803 if( (k>=pAggInfo->nColumn)
109804 && (k = addAggInfoColumn(pParse->db, pAggInfo))>=0
@@ -109809,19 +110053,21 @@
109809 pCol->iTable = pExpr->iTable;
109810 pCol->iColumn = pExpr->iColumn;
109811 pCol->iMem = ++pParse->nMem;
109812 pCol->iSorterColumn = -1;
109813 pCol->pCExpr = pExpr;
109814 if( pAggInfo->pGroupBy ){
109815 int j, n;
109816 ExprList *pGB = pAggInfo->pGroupBy;
109817 struct ExprList_item *pTerm = pGB->a;
109818 n = pGB->nExpr;
109819 for(j=0; j<n; j++, pTerm++){
109820 Expr *pE = pTerm->pExpr;
109821 if( pE->op==TK_COLUMN && pE->iTable==pExpr->iTable &&
109822 pE->iColumn==pExpr->iColumn ){
 
 
109823 pCol->iSorterColumn = j;
109824 break;
109825 }
109826 }
109827 }
@@ -109834,11 +110080,13 @@
109834 ** Convert the pExpr to be a TK_AGG_COLUMN referring to that
109835 ** pAggInfo->aCol[] entry.
109836 */
109837 ExprSetVVAProperty(pExpr, EP_NoReduce);
109838 pExpr->pAggInfo = pAggInfo;
109839 pExpr->op = TK_AGG_COLUMN;
 
 
109840 pExpr->iAgg = (i16)k;
109841 break;
109842 } /* endif pExpr->iTable==pItem->iCursor */
109843 } /* end loop over pSrcList */
109844 }
@@ -115256,10 +115504,11 @@
115256 ** no VDBE code was generated.
115257 */
115258 SQLITE_PRIVATE void sqlite3FinishCoding(Parse *pParse){
115259 sqlite3 *db;
115260 Vdbe *v;
 
115261
115262 assert( pParse->pToplevel==0 );
115263 db = pParse->db;
115264 assert( db->pParse==pParse );
115265 if( pParse->nested ) return;
@@ -115285,11 +115534,10 @@
115285 || sqlite3VdbeAssertMayAbort(v, pParse->mayAbort));
115286 if( v ){
115287 if( pParse->bReturning ){
115288 Returning *pReturning = pParse->u1.pReturning;
115289 int addrRewind;
115290 int i;
115291 int reg;
115292
115293 if( pReturning->nRetCol ){
115294 sqlite3VdbeAddOp0(v, OP_FkCheck);
115295 addrRewind =
@@ -115322,80 +115570,73 @@
115322 ** (Bit 0 is for main, bit 1 is for temp, and so forth.) Bits are
115323 ** set for each database that is used. Generate code to start a
115324 ** transaction on each used database and to verify the schema cookie
115325 ** on each used database.
115326 */
115327 if( db->mallocFailed==0
115328 && (DbMaskNonZero(pParse->cookieMask) || pParse->pConstExpr)
115329 ){
115330 int iDb, i;
115331 assert( sqlite3VdbeGetOp(v, 0)->opcode==OP_Init );
115332 sqlite3VdbeJumpHere(v, 0);
115333 assert( db->nDb>0 );
115334 iDb = 0;
115335 do{
115336 Schema *pSchema;
115337 if( DbMaskTest(pParse->cookieMask, iDb)==0 ) continue;
115338 sqlite3VdbeUsesBtree(v, iDb);
115339 pSchema = db->aDb[iDb].pSchema;
115340 sqlite3VdbeAddOp4Int(v,
115341 OP_Transaction, /* Opcode */
115342 iDb, /* P1 */
115343 DbMaskTest(pParse->writeMask,iDb), /* P2 */
115344 pSchema->schema_cookie, /* P3 */
115345 pSchema->iGeneration /* P4 */
115346 );
115347 if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1);
115348 VdbeComment((v,
115349 "usesStmtJournal=%d", pParse->mayAbort && pParse->isMultiWrite));
115350 }while( ++iDb<db->nDb );
115351 #ifndef SQLITE_OMIT_VIRTUALTABLE
115352 for(i=0; i<pParse->nVtabLock; i++){
115353 char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
115354 sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
115355 }
115356 pParse->nVtabLock = 0;
115357 #endif
115358
115359 /* Once all the cookies have been verified and transactions opened,
115360 ** obtain the required table-locks. This is a no-op unless the
115361 ** shared-cache feature is enabled.
115362 */
115363 codeTableLocks(pParse);
115364
115365 /* Initialize any AUTOINCREMENT data structures required.
115366 */
115367 sqlite3AutoincrementBegin(pParse);
115368
115369 /* Code constant expressions that where factored out of inner loops.
115370 **
115371 ** The pConstExpr list might also contain expressions that we simply
115372 ** want to keep around until the Parse object is deleted. Such
115373 ** expressions have iConstExprReg==0. Do not generate code for
115374 ** those expressions, of course.
115375 */
115376 if( pParse->pConstExpr ){
115377 ExprList *pEL = pParse->pConstExpr;
115378 pParse->okConstFactor = 0;
115379 for(i=0; i<pEL->nExpr; i++){
115380 int iReg = pEL->a[i].u.iConstExprReg;
115381 if( iReg>0 ){
115382 sqlite3ExprCode(pParse, pEL->a[i].pExpr, iReg);
115383 }
115384 }
115385 }
115386
115387 if( pParse->bReturning ){
115388 Returning *pRet = pParse->u1.pReturning;
115389 if( pRet->nRetCol ){
115390 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
115391 }
115392 }
115393
115394 /* Finally, jump back to the beginning of the executable code. */
115395 sqlite3VdbeGoto(v, 1);
115396 }
115397 }
115398
115399 /* Get the VDBE program ready for execution
115400 */
115401 assert( v!=0 || pParse->nErr );
@@ -115898,20 +116139,21 @@
115898 */
115899 SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3 *db, Table *pTable){
115900 int i;
115901 Column *pCol;
115902 assert( pTable!=0 );
 
115903 if( (pCol = pTable->aCol)!=0 ){
115904 for(i=0; i<pTable->nCol; i++, pCol++){
115905 assert( pCol->zCnName==0 || pCol->hName==sqlite3StrIHash(pCol->zCnName) );
115906 sqlite3DbFree(db, pCol->zCnName);
115907 }
115908 sqlite3DbFree(db, pTable->aCol);
115909 if( IsOrdinaryTable(pTable) ){
115910 sqlite3ExprListDelete(db, pTable->u.tab.pDfltList);
115911 }
115912 if( db==0 || db->pnBytesFreed==0 ){
115913 pTable->aCol = 0;
115914 pTable->nCol = 0;
115915 if( IsOrdinaryTable(pTable) ){
115916 pTable->u.tab.pDfltList = 0;
115917 }
@@ -115944,21 +116186,22 @@
115944 **
115945 ** If malloc has already failed, it may be that it failed while allocating
115946 ** a Table object that was going to be marked ephemeral. So do not check
115947 ** that no lookaside memory is used in this case either. */
115948 int nLookaside = 0;
115949 if( db && !db->mallocFailed && (pTable->tabFlags & TF_Ephemeral)==0 ){
 
115950 nLookaside = sqlite3LookasideUsed(db, 0);
115951 }
115952 #endif
115953
115954 /* Delete all indices associated with this table. */
115955 for(pIndex = pTable->pIndex; pIndex; pIndex=pNext){
115956 pNext = pIndex->pNext;
115957 assert( pIndex->pSchema==pTable->pSchema
115958 || (IsVirtual(pTable) && pIndex->idxType!=SQLITE_IDXTYPE_APPDEF) );
115959 if( (db==0 || db->pnBytesFreed==0) && !IsVirtual(pTable) ){
115960 char *zName = pIndex->zName;
115961 TESTONLY ( Index *pOld = ) sqlite3HashInsert(
115962 &pIndex->pSchema->idxHash, zName, 0
115963 );
115964 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
@@ -115991,12 +116234,13 @@
115991 /* Verify that no lookaside memory was used by schema tables */
115992 assert( nLookaside==0 || nLookaside==sqlite3LookasideUsed(db,0) );
115993 }
115994 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
115995 /* Do not delete the table until the reference count reaches zero. */
 
115996 if( !pTable ) return;
115997 if( ((!db || db->pnBytesFreed==0) && (--pTable->nTabRef)>0) ) return;
115998 deleteTable(db, pTable);
115999 }
116000
116001
116002 /*
@@ -118165,11 +118409,11 @@
118165 /*
118166 ** The Table structure pTable is really a VIEW. Fill in the names of
118167 ** the columns of the view in the pTable structure. Return the number
118168 ** of errors. If an error is seen leave an error message in pParse->zErrMsg.
118169 */
118170 SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
118171 Table *pSelTab; /* A fake table from which we get the result set */
118172 Select *pSel; /* Copy of the SELECT that implements the view */
118173 int nErr = 0; /* Number of errors encountered */
118174 sqlite3 *db = pParse->db; /* Database connection for malloc errors */
118175 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -118190,13 +118434,14 @@
118190 }
118191 #endif
118192
118193 #ifndef SQLITE_OMIT_VIEW
118194 /* A positive nCol means the columns names for this view are
118195 ** already known.
 
118196 */
118197 if( pTable->nCol>0 ) return 0;
118198
118199 /* A negative nCol is a special marker meaning that we are currently
118200 ** trying to compute the column names. If we enter this routine with
118201 ** a negative nCol, it means two or more views form a loop, like this:
118202 **
@@ -118287,10 +118532,15 @@
118287 if( db->mallocFailed ){
118288 sqlite3DeleteColumnNames(db, pTable);
118289 }
118290 #endif /* SQLITE_OMIT_VIEW */
118291 return nErr;
 
 
 
 
 
118292 }
118293 #endif /* !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) */
118294
118295 #ifndef SQLITE_OMIT_VIEW
118296 /*
@@ -119153,11 +119403,11 @@
119153 if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName,"index",pTab->zName) ){
119154 goto exit_create_index;
119155 }
119156 if( !IN_RENAME_OBJECT ){
119157 if( !db->init.busy ){
119158 if( sqlite3FindTable(db, zName, 0)!=0 ){
119159 sqlite3ErrorMsg(pParse, "there is already a table named %s", zName);
119160 goto exit_create_index;
119161 }
119162 }
119163 if( sqlite3FindIndex(db, zName, pDb->zDbSName)!=0 ){
@@ -119806,16 +120056,17 @@
119806 /*
119807 ** Delete an IdList.
119808 */
119809 SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3 *db, IdList *pList){
119810 int i;
 
119811 if( pList==0 ) return;
119812 assert( pList->eU4!=EU4_EXPR ); /* EU4_EXPR mode is not currently used */
119813 for(i=0; i<pList->nId; i++){
119814 sqlite3DbFree(db, pList->a[i].zName);
119815 }
119816 sqlite3DbFreeNN(db, pList);
119817 }
119818
119819 /*
119820 ** Return the index in pList of the identifier named zId. Return -1
119821 ** if not found.
@@ -120014,15 +120265,16 @@
120014 ** Delete an entire SrcList including all its substructure.
120015 */
120016 SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3 *db, SrcList *pList){
120017 int i;
120018 SrcItem *pItem;
 
120019 if( pList==0 ) return;
120020 for(pItem=pList->a, i=0; i<pList->nSrc; i++, pItem++){
120021 if( pItem->zDatabase ) sqlite3DbFreeNN(db, pItem->zDatabase);
120022 sqlite3DbFree(db, pItem->zName);
120023 if( pItem->zAlias ) sqlite3DbFreeNN(db, pItem->zAlias);
120024 if( pItem->fg.isIndexedBy ) sqlite3DbFree(db, pItem->u1.zIndexedBy);
120025 if( pItem->fg.isTabFunc ) sqlite3ExprListDelete(db, pItem->u1.pFuncArg);
120026 sqlite3DeleteTable(db, pItem->pTab);
120027 if( pItem->pSelect ) sqlite3SelectDelete(db, pItem->pSelect);
120028 if( pItem->fg.isUsing ){
@@ -120029,11 +120281,11 @@
120029 sqlite3IdListDelete(db, pItem->u3.pUsing);
120030 }else if( pItem->u3.pOn ){
120031 sqlite3ExprDelete(db, pItem->u3.pOn);
120032 }
120033 }
120034 sqlite3DbFreeNN(db, pList);
120035 }
120036
120037 /*
120038 ** This routine is called by the parser to add a new term to the
120039 ** end of a growing FROM clause. The "p" parameter is the part of
@@ -121281,23 +121533,25 @@
121281 SQLITE_PRIVATE void sqlite3SchemaClear(void *p){
121282 Hash temp1;
121283 Hash temp2;
121284 HashElem *pElem;
121285 Schema *pSchema = (Schema *)p;
 
121286
 
121287 temp1 = pSchema->tblHash;
121288 temp2 = pSchema->trigHash;
121289 sqlite3HashInit(&pSchema->trigHash);
121290 sqlite3HashClear(&pSchema->idxHash);
121291 for(pElem=sqliteHashFirst(&temp2); pElem; pElem=sqliteHashNext(pElem)){
121292 sqlite3DeleteTrigger(0, (Trigger*)sqliteHashData(pElem));
121293 }
121294 sqlite3HashClear(&temp2);
121295 sqlite3HashInit(&pSchema->tblHash);
121296 for(pElem=sqliteHashFirst(&temp1); pElem; pElem=sqliteHashNext(pElem)){
121297 Table *pTab = sqliteHashData(pElem);
121298 sqlite3DeleteTable(0, pTab);
121299 }
121300 sqlite3HashClear(&temp1);
121301 sqlite3HashClear(&pSchema->fkeyHash);
121302 pSchema->pSeqTab = 0;
121303 if( pSchema->schemaFlags & DB_SchemaLoaded ){
@@ -121392,22 +121646,46 @@
121392 ** A table is read-only if any of the following are true:
121393 **
121394 ** 1) It is a virtual table and no implementation of the xUpdate method
121395 ** has been provided
121396 **
121397 ** 2) It is a system table (i.e. sqlite_schema), this call is not
 
 
 
 
121398 ** part of a nested parse and writable_schema pragma has not
121399 ** been specified
121400 **
121401 ** 3) The table is a shadow table, the database connection is in
121402 ** defensive mode, and the current sqlite3_prepare()
121403 ** is for a top-level SQL statement.
121404 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121405 static int tabIsReadOnly(Parse *pParse, Table *pTab){
121406 sqlite3 *db;
121407 if( IsVirtual(pTab) ){
121408 return sqlite3GetVTable(pParse->db, pTab)->pMod->pModule->xUpdate==0;
121409 }
121410 if( (pTab->tabFlags & (TF_Readonly|TF_Shadow))==0 ) return 0;
121411 db = pParse->db;
121412 if( (pTab->tabFlags & TF_Readonly)!=0 ){
121413 return sqlite3WritableSchema(db)==0 && pParse->nested==0;
@@ -121415,13 +121693,15 @@
121415 assert( pTab->tabFlags & TF_Shadow );
121416 return sqlite3ReadOnlyShadowTables(db);
121417 }
121418
121419 /*
121420 ** Check to make sure the given table is writable. If it is not
121421 ** writable, generate an error message and return 1. If it is
121422 ** writable return 0;
 
 
121423 */
121424 SQLITE_PRIVATE int sqlite3IsReadOnly(Parse *pParse, Table *pTab, int viewOk){
121425 if( tabIsReadOnly(pParse, pTab) ){
121426 sqlite3ErrorMsg(pParse, "table %s may not be modified", pTab->zName);
121427 return 1;
@@ -121778,13 +122058,14 @@
121778 sqlite3VdbeAddOp4(v, OP_Clear, pTab->tnum, iDb, memCnt ? memCnt : -1,
121779 pTab->zName, P4_STATIC);
121780 }
121781 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
121782 assert( pIdx->pSchema==pTab->pSchema );
121783 sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
121784 if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
121785 sqlite3VdbeChangeP3(v, -1, memCnt ? memCnt : -1);
 
 
121786 }
121787 }
121788 }else
121789 #endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
121790 {
@@ -121980,11 +122261,11 @@
121980 sqlite3ExprDelete(db, pWhere);
121981 #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT)
121982 sqlite3ExprListDelete(db, pOrderBy);
121983 sqlite3ExprDelete(db, pLimit);
121984 #endif
121985 sqlite3DbFree(db, aToOpen);
121986 return;
121987 }
121988 /* Make sure "isView" and other macros defined above are undefined. Otherwise
121989 ** they may interfere with compilation of other functions in this file
121990 ** (or in another file, if this file becomes part of the amalgamation). */
@@ -126148,15 +126429,16 @@
126148 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
126149 FKey *pFKey; /* Iterator variable */
126150 FKey *pNext; /* Copy of pFKey->pNextFrom */
126151
126152 assert( IsOrdinaryTable(pTab) );
 
126153 for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pNext){
126154 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
126155
126156 /* Remove the FK from the fkeyHash hash table. */
126157 if( !db || db->pnBytesFreed==0 ){
126158 if( pFKey->pPrevTo ){
126159 pFKey->pPrevTo->pNextTo = pFKey->pNextTo;
126160 }else{
126161 void *p = (void *)pFKey->pNextTo;
126162 const char *z = (p ? pFKey->pNextTo->zTo : pFKey->zTo);
@@ -126345,11 +126627,11 @@
126345 /* Move the previous opcode (which should be OP_MakeRecord) forward
126346 ** by one slot and insert a new OP_TypeCheck where the current
126347 ** OP_MakeRecord is found */
126348 VdbeOp *pPrev;
126349 sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
126350 pPrev = sqlite3VdbeGetOp(v, -1);
126351 assert( pPrev!=0 );
126352 assert( pPrev->opcode==OP_MakeRecord || sqlite3VdbeDb(v)->mallocFailed );
126353 pPrev->opcode = OP_TypeCheck;
126354 sqlite3VdbeAddOp3(v, OP_MakeRecord, pPrev->p1, pPrev->p2, pPrev->p3);
126355 }else{
@@ -126383,11 +126665,11 @@
126383 i = sqlite3Strlen30NN(zColAff);
126384 if( i ){
126385 if( iReg ){
126386 sqlite3VdbeAddOp4(v, OP_Affinity, iReg, i, 0, zColAff, i);
126387 }else{
126388 assert( sqlite3VdbeGetOp(v, -1)->opcode==OP_MakeRecord
126389 || sqlite3VdbeDb(v)->mallocFailed );
126390 sqlite3VdbeChangeP4(v, -1, zColAff, i);
126391 }
126392 }
126393 }
@@ -126469,11 +126751,11 @@
126469 /* Before computing generated columns, first go through and make sure
126470 ** that appropriate affinity has been applied to the regular columns
126471 */
126472 sqlite3TableAffinity(pParse->pVdbe, pTab, iRegStore);
126473 if( (pTab->tabFlags & TF_HasStored)!=0 ){
126474 pOp = sqlite3VdbeGetOp(pParse->pVdbe,-1);
126475 if( pOp->opcode==OP_Affinity ){
126476 /* Change the OP_Affinity argument to '@' (NONE) for all stored
126477 ** columns. '@' is the no-op affinity and those columns have not
126478 ** yet been computed. */
126479 int ii, jj;
@@ -127375,11 +127657,16 @@
127375 }else if( pSelect ){
127376 if( regFromSelect!=regData ){
127377 sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+k, iRegStore);
127378 }
127379 }else{
127380 sqlite3ExprCode(pParse, pList->a[k].pExpr, iRegStore);
 
 
 
 
 
127381 }
127382 }
127383
127384
127385 /* Run the BEFORE and INSTEAD OF triggers, if there are any
@@ -127512,11 +127799,13 @@
127512 int isReplace = 0;/* Set to true if constraints may cause a replace */
127513 int bUseSeek; /* True to use OPFLAG_SEEKRESULT */
127514 sqlite3GenerateConstraintChecks(pParse, pTab, aRegIdx, iDataCur, iIdxCur,
127515 regIns, 0, ipkColumn>=0, onError, endOfLoop, &isReplace, 0, pUpsert
127516 );
127517 sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0);
 
 
127518
127519 /* Set the OPFLAG_USESEEKRESULT flag if either (a) there are no REPLACE
127520 ** constraints or (b) there are no triggers and this table is not a
127521 ** parent table in a foreign key constraint. It is safe to set the
127522 ** flag in the second case as if any REPLACE constraint is hit, an
@@ -127596,11 +127885,11 @@
127596 sqlite3SrcListDelete(db, pTabList);
127597 sqlite3ExprListDelete(db, pList);
127598 sqlite3UpsertDelete(db, pUpsert);
127599 sqlite3SelectDelete(db, pSelect);
127600 sqlite3IdListDelete(db, pColumn);
127601 sqlite3DbFree(db, aRegIdx);
127602 }
127603
127604 /* Make sure "isView" and other macros defined above are undefined. Otherwise
127605 ** they may interfere with compilation of other functions in this file
127606 ** (or in another file, if this file becomes part of the amalgamation). */
@@ -132702,19 +132991,21 @@
132702 ** Setting to a null string reverts to the default temporary directory search.
132703 ** If temporary directory is changed, then invalidateTempStorage.
132704 **
132705 */
132706 case PragTyp_TEMP_STORE_DIRECTORY: {
 
132707 if( !zRight ){
132708 returnSingleText(v, sqlite3_temp_directory);
132709 }else{
132710 #ifndef SQLITE_OMIT_WSD
132711 if( zRight[0] ){
132712 int res;
132713 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
132714 if( rc!=SQLITE_OK || res==0 ){
132715 sqlite3ErrorMsg(pParse, "not a writable directory");
 
132716 goto pragma_out;
132717 }
132718 }
132719 if( SQLITE_TEMP_STORE==0
132720 || (SQLITE_TEMP_STORE==1 && db->temp_store<=1)
@@ -132728,10 +133019,11 @@
132728 }else{
132729 sqlite3_temp_directory = 0;
132730 }
132731 #endif /* SQLITE_OMIT_WSD */
132732 }
 
132733 break;
132734 }
132735
132736 #if SQLITE_OS_WIN
132737 /*
@@ -132746,19 +133038,21 @@
132746 ** process. Database file specified with an absolute path are not impacted
132747 ** by this setting, regardless of its value.
132748 **
132749 */
132750 case PragTyp_DATA_STORE_DIRECTORY: {
 
132751 if( !zRight ){
132752 returnSingleText(v, sqlite3_data_directory);
132753 }else{
132754 #ifndef SQLITE_OMIT_WSD
132755 if( zRight[0] ){
132756 int res;
132757 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
132758 if( rc!=SQLITE_OK || res==0 ){
132759 sqlite3ErrorMsg(pParse, "not a writable directory");
 
132760 goto pragma_out;
132761 }
132762 }
132763 sqlite3_free(sqlite3_data_directory);
132764 if( zRight[0] ){
@@ -132766,10 +133060,11 @@
132766 }else{
132767 sqlite3_data_directory = 0;
132768 }
132769 #endif /* SQLITE_OMIT_WSD */
132770 }
 
132771 break;
132772 }
132773 #endif
132774
132775 #if SQLITE_ENABLE_LOCKING_STYLE
@@ -133479,19 +133774,27 @@
133479 /* Make sure all the indices are constructed correctly.
133480 */
133481 for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
133482 Table *pTab = sqliteHashData(x);
133483 Index *pIdx, *pPk;
133484 Index *pPrior = 0;
133485 int loopTop;
133486 int iDataCur, iIdxCur;
133487 int r1 = -1;
133488 int bStrict;
 
133489
133490 if( !IsOrdinaryTable(pTab) ) continue;
133491 if( pObjTab && pObjTab!=pTab ) continue;
133492 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
 
 
 
 
 
 
 
133493 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
133494 1, 0, &iDataCur, &iIdxCur);
133495 /* reg[7] counts the number of entries in the table.
133496 ** reg[8+i] counts the number of entries in the i-th index
133497 */
@@ -133506,10 +133809,28 @@
133506 if( !isQuick ){
133507 /* Sanity check on record header decoding */
133508 sqlite3VdbeAddOp3(v, OP_Column, iDataCur, pTab->nNVCol-1,3);
133509 sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
133510 VdbeComment((v, "(right-most column)"));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133511 }
133512 /* Verify that all NOT NULL columns really are NOT NULL. At the
133513 ** same time verify the type of the content of STRICT tables */
133514 bStrict = (pTab->tabFlags & TF_Strict)!=0;
133515 for(j=0; j<pTab->nCol; j++){
@@ -133518,11 +133839,11 @@
133518 int doError, jmp2;
133519 if( j==pTab->iPKey ) continue;
133520 if( pCol->notNull==0 && !bStrict ) continue;
133521 doError = bStrict ? sqlite3VdbeMakeLabel(pParse) : 0;
133522 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, j, 3);
133523 if( sqlite3VdbeGetOp(v,-1)->opcode==OP_Column ){
133524 sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
133525 }
133526 if( pCol->notNull ){
133527 jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v);
133528 zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
@@ -133533,13 +133854,11 @@
133533 }else{
133534 integrityCheckResultRow(v);
133535 }
133536 sqlite3VdbeJumpHere(v, jmp2);
133537 }
133538 if( (pTab->tabFlags & TF_Strict)!=0
133539 && pCol->eCType!=COLTYPE_ANY
133540 ){
133541 jmp2 = sqlite3VdbeAddOp3(v, OP_IsNullOrType, 3, 0,
133542 sqlite3StdTypeMap[pCol->eCType-1]);
133543 VdbeCoverage(v);
133544 zErr = sqlite3MPrintf(db, "non-%s value in %s.%s",
133545 sqlite3StdType[pCol->eCType-1],
@@ -133634,10 +133953,13 @@
133634 sqlite3VdbeLoadString(v, 4, pIdx->zName);
133635 sqlite3VdbeAddOp3(v, OP_Concat, 4, 2, 3);
133636 integrityCheckResultRow(v);
133637 sqlite3VdbeJumpHere(v, addr);
133638 }
 
 
 
133639 }
133640 }
133641 }
133642 {
133643 static const int iLn = VDBE_OFFSET_LINENO(2);
@@ -135032,19 +135354,19 @@
135032 sqlite3 *db = pParse->db;
135033 assert( db!=0 );
135034 assert( db->pParse==pParse );
135035 assert( pParse->nested==0 );
135036 #ifndef SQLITE_OMIT_SHARED_CACHE
135037 sqlite3DbFree(db, pParse->aTableLock);
135038 #endif
135039 while( pParse->pCleanup ){
135040 ParseCleanup *pCleanup = pParse->pCleanup;
135041 pParse->pCleanup = pCleanup->pNext;
135042 pCleanup->xCleanup(db, pCleanup->pPtr);
135043 sqlite3DbFreeNN(db, pCleanup);
135044 }
135045 sqlite3DbFree(db, pParse->aLabel);
135046 if( pParse->pConstExpr ){
135047 sqlite3ExprListDelete(db, pParse->pConstExpr);
135048 }
135049 assert( db->lookaside.bDisable >= pParse->disableLookaside );
135050 db->lookaside.bDisable -= pParse->disableLookaside;
@@ -135599,10 +135921,11 @@
135599 **
135600 ** If bFree==1, call sqlite3DbFree() on the p object.
135601 ** If bFree==0, Leave the first Select object unfreed
135602 */
135603 static void clearSelect(sqlite3 *db, Select *p, int bFree){
 
135604 while( p ){
135605 Select *pPrior = p->pPrior;
135606 sqlite3ExprListDelete(db, p->pEList);
135607 sqlite3SrcListDelete(db, p->pSrc);
135608 sqlite3ExprDelete(db, p->pWhere);
@@ -135618,11 +135941,11 @@
135618 while( p->pWin ){
135619 assert( p->pWin->ppThis==&p->pWin );
135620 sqlite3WindowUnlinkFromSelect(p->pWin);
135621 }
135622 #endif
135623 if( bFree ) sqlite3DbFreeNN(db, p);
135624 p = pPrior;
135625 bFree = 1;
135626 }
135627 }
135628
@@ -137024,13 +137347,14 @@
137024 /*
137025 ** Deallocate a KeyInfo object
137026 */
137027 SQLITE_PRIVATE void sqlite3KeyInfoUnref(KeyInfo *p){
137028 if( p ){
 
137029 assert( p->nRef>0 );
137030 p->nRef--;
137031 if( p->nRef==0 ) sqlite3DbFreeNN(p->db, p);
137032 }
137033 }
137034
137035 /*
137036 ** Make a new pointer to a KeyInfo object
@@ -137211,18 +137535,21 @@
137211 sqlite3VdbeAddOp3(v, OP_OpenPseudo, iSortTab, regSortOut,
137212 nKey+1+nColumn+nRefKey);
137213 if( addrOnce ) sqlite3VdbeJumpHere(v, addrOnce);
137214 addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
137215 VdbeCoverage(v);
137216 codeOffset(v, p->iOffset, addrContinue);
137217 sqlite3VdbeAddOp3(v, OP_SorterData, iTab, regSortOut, iSortTab);
137218 bSeq = 0;
137219 }else{
137220 addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v);
137221 codeOffset(v, p->iOffset, addrContinue);
137222 iSortTab = iTab;
137223 bSeq = 1;
 
 
 
137224 }
137225 for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){
137226 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
137227 if( aOutEx[i].fg.bSorterRef ) continue;
137228 #endif
@@ -137343,13 +137670,10 @@
137343
137344 /*
137345 ** Return a pointer to a string containing the 'declaration type' of the
137346 ** expression pExpr. The string may be treated as static by the caller.
137347 **
137348 ** Also try to estimate the size of the returned value and return that
137349 ** result in *pEstWidth.
137350 **
137351 ** The declaration type is the exact datatype definition extracted from the
137352 ** original CREATE TABLE statement if the expression is a column. The
137353 ** declaration type for a ROWID field is INTEGER. Exactly when an expression
137354 ** is considered a column can be complex in the presence of subqueries. The
137355 ** result-set expression in all of the following SELECT statements is
@@ -139211,14 +139535,15 @@
139211
139212 /* Jump to the this point in order to terminate the query.
139213 */
139214 sqlite3VdbeResolveLabel(v, labelEnd);
139215
139216 /* Reassembly the compound query so that it will be freed correctly
139217 ** by the calling function */
139218 if( pSplit->pPrior ){
139219 sqlite3SelectDelete(db, pSplit->pPrior);
 
139220 }
139221 pSplit->pPrior = pPrior;
139222 pPrior->pNext = pSplit;
139223 sqlite3ExprListDelete(db, pPrior->pOrderBy);
139224 pPrior->pOrderBy = 0;
@@ -139324,10 +139649,11 @@
139324 if( pSubst->isOuterJoin && pCopy->op!=TK_COLUMN ){
139325 memset(&ifNullRow, 0, sizeof(ifNullRow));
139326 ifNullRow.op = TK_IF_NULL_ROW;
139327 ifNullRow.pLeft = pCopy;
139328 ifNullRow.iTable = pSubst->iNewTable;
 
139329 ifNullRow.flags = EP_IfNullRow;
139330 pCopy = &ifNullRow;
139331 }
139332 testcase( ExprHasProperty(pCopy, EP_Subquery) );
139333 pNew = sqlite3ExprDup(db, pCopy, 0);
@@ -139591,11 +139917,12 @@
139591 **
139592 ** (3) If the subquery is the right operand of a LEFT JOIN then
139593 ** (3a) the subquery may not be a join and
139594 ** (3b) the FROM clause of the subquery may not contain a virtual
139595 ** table and
139596 ** (3c) the outer query may not be an aggregate.
 
139597 ** (3d) the outer query may not be DISTINCT.
139598 ** See also (26) for restrictions on RIGHT JOIN.
139599 **
139600 ** (4) The subquery can not be DISTINCT.
139601 **
@@ -139803,20 +140130,14 @@
139803 **
139804 ** (t1 LEFT OUTER JOIN t2) JOIN t3
139805 **
139806 ** which is not at all the same thing.
139807 **
139808 ** If the subquery is the right operand of a LEFT JOIN, then the outer
139809 ** query cannot be an aggregate. (3c) This is an artifact of the way
139810 ** aggregates are processed - there is no mechanism to determine if
139811 ** the LEFT JOIN table should be all-NULL.
139812 **
139813 ** See also tickets #306, #350, and #3300.
139814 */
139815 if( (pSubitem->fg.jointype & (JT_OUTER|JT_LTORJ))!=0 ){
139816 if( pSubSrc->nSrc>1 /* (3a) */
139817 || isAgg /* (3c) */
139818 || IsVirtual(pSubSrc->a[0].pTab) /* (3b) */
139819 || (p->selFlags & SF_Distinct)!=0 /* (3d) */
139820 || (pSubitem->fg.jointype & JT_RIGHT)!=0 /* (26) */
139821 ){
139822 return 0;
@@ -140733,10 +141054,11 @@
140733 if( p->pWhere
140734 || p->pEList->nExpr!=1
140735 || p->pSrc->nSrc!=1
140736 || p->pSrc->a[0].pSelect
140737 || pAggInfo->nFunc!=1
 
140738 ){
140739 return 0;
140740 }
140741 pTab = p->pSrc->a[0].pTab;
140742 assert( pTab!=0 );
@@ -142726,11 +143048,11 @@
142726 */
142727 iEnd = sqlite3VdbeMakeLabel(pParse);
142728 if( (p->selFlags & SF_FixedLimit)==0 ){
142729 p->nSelectRow = 320; /* 4 billion rows */
142730 }
142731 computeLimitRegisters(pParse, p, iEnd);
142732 if( p->iLimit==0 && sSort.addrSortIndex>=0 ){
142733 sqlite3VdbeChangeOpcode(v, sSort.addrSortIndex, OP_SorterOpen);
142734 sSort.sortFlags |= SORTFLAG_UseSorter;
142735 }
142736
@@ -142948,12 +143270,17 @@
142948 if( minMaxFlag ){
142949 sqlite3DebugPrintf("MIN/MAX Optimization (0x%02x) adds:\n", minMaxFlag);
142950 sqlite3TreeViewExprList(0, pMinMaxOrderBy, 0, "ORDERBY");
142951 }
142952 for(ii=0; ii<pAggInfo->nColumn; ii++){
142953 sqlite3DebugPrintf("agg-column[%d] iMem=%d\n",
142954 ii, pAggInfo->aCol[ii].iMem);
 
 
 
 
 
142955 sqlite3TreeViewExpr(0, pAggInfo->aCol[ii].pCExpr, 0);
142956 }
142957 for(ii=0; ii<pAggInfo->nFunc; ii++){
142958 sqlite3DebugPrintf("agg-func[%d]: iMem=%d\n",
142959 ii, pAggInfo->aFunc[ii].iMem);
@@ -143070,19 +143397,19 @@
143070 }
143071 }
143072 regBase = sqlite3GetTempRange(pParse, nCol);
143073 sqlite3ExprCodeExprList(pParse, pGroupBy, regBase, 0, 0);
143074 j = nGroupBy;
 
143075 for(i=0; i<pAggInfo->nColumn; i++){
143076 struct AggInfo_col *pCol = &pAggInfo->aCol[i];
143077 if( pCol->iSorterColumn>=j ){
143078 int r1 = j + regBase;
143079 sqlite3ExprCodeGetColumnOfTable(v,
143080 pCol->pTab, pCol->iTable, pCol->iColumn, r1);
143081 j++;
143082 }
143083 }
 
143084 regRecord = sqlite3GetTempReg(pParse);
143085 sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regRecord);
143086 sqlite3VdbeAddOp2(v, OP_SorterInsert, pAggInfo->sortingIdx, regRecord);
143087 sqlite3ReleaseTempReg(pParse, regRecord);
143088 sqlite3ReleaseTempRange(pParse, regBase, nCol);
@@ -147496,11 +147823,12 @@
147496 ** in the list are moved to the sqlite3.pDisconnect list of the associated
147497 ** database connection.
147498 */
147499 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){
147500 assert( IsVirtual(p) );
147501 if( !db || db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
 
147502 if( p->u.vtab.azArg ){
147503 int i;
147504 for(i=0; i<p->u.vtab.nArg; i++){
147505 if( i!=1 ) sqlite3DbFree(db, p->u.vtab.azArg[i]);
147506 }
@@ -149173,10 +149501,11 @@
149173 #define WHERE_IN_SEEKSCAN 0x00100000 /* Seek-scan optimization for IN */
149174 #define WHERE_TRANSCONS 0x00200000 /* Uses a transitive constraint */
149175 #define WHERE_BLOOMFILTER 0x00400000 /* Consider using a Bloom-filter */
149176 #define WHERE_SELFCULL 0x00800000 /* nOut reduced by extra WHERE terms */
149177 #define WHERE_OMIT_OFFSET 0x01000000 /* Set offset counter to zero */
 
149178
149179 #endif /* !defined(SQLITE_WHEREINT_H) */
149180
149181 /************** End of whereInt.h ********************************************/
149182 /************** Continuing where we left off in wherecode.c ******************/
@@ -149781,11 +150110,12 @@
149781 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap,&iTab);
149782 pExpr->iTable = iTab;
149783 }
149784 sqlite3ExprDelete(db, pX);
149785 }else{
149786 aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq);
 
149787 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap, &iTab);
149788 }
149789 pX = pExpr;
149790 }
149791
@@ -150051,11 +150381,11 @@
150051 WhereTerm *pTerm /* The upper or lower bound just coded */
150052 ){
150053 if( pTerm->wtFlags & TERM_LIKEOPT ){
150054 VdbeOp *pOp;
150055 assert( pLevel->iLikeRepCntr>0 );
150056 pOp = sqlite3VdbeGetOp(v, -1);
150057 assert( pOp!=0 );
150058 assert( pOp->opcode==OP_String8
150059 || pTerm->pWC->pWInfo->pParse->db->mallocFailed );
150060 pOp->p3 = (int)(pLevel->iLikeRepCntr>>1); /* Register holding counter */
150061 pOp->p5 = (u8)(pLevel->iLikeRepCntr&1); /* ASC or DESC */
@@ -151267,12 +151597,12 @@
151267 sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
151268 endEq = 0;
151269 }
151270 nConstraint++;
151271 }
151272 sqlite3DbFree(db, zStartAff);
151273 sqlite3DbFree(db, zEndAff);
151274
151275 /* Top of the loop body */
151276 if( pLevel->p2==0 ) pLevel->p2 = sqlite3VdbeCurrentAddr(v);
151277
151278 /* Check if the index cursor is past the end of the range. */
@@ -155499,11 +155829,11 @@
155499 /* At this point, the (iCol+1) field prefix of aSample[i] is the first
155500 ** sample that is greater than pRec. Or, if i==pIdx->nSample then pRec
155501 ** is larger than all samples in the array. */
155502 tRowcnt iUpper, iGap;
155503 if( i>=pIdx->nSample ){
155504 iUpper = sqlite3LogEstToInt(pIdx->aiRowLogEst[0]);
155505 }else{
155506 iUpper = aSample[i].anLt[iCol];
155507 }
155508
155509 if( iLower>=iUpper ){
@@ -156128,16 +156458,22 @@
156128 }
156129 }
156130 }
156131
156132 /*
156133 ** Deallocate internal memory used by a WhereLoop object
 
156134 */
156135 static void whereLoopClear(sqlite3 *db, WhereLoop *p){
156136 if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFreeNN(db, p->aLTerm);
 
 
 
 
156137 whereLoopClearUnion(db, p);
156138 whereLoopInit(p);
 
156139 }
156140
156141 /*
156142 ** Increase the memory allocation for pLoop->aLTerm[] to be at least n.
156143 */
@@ -156157,11 +156493,13 @@
156157 /*
156158 ** Transfer content from the second pLoop into the first.
156159 */
156160 static int whereLoopXfer(sqlite3 *db, WhereLoop *pTo, WhereLoop *pFrom){
156161 whereLoopClearUnion(db, pTo);
156162 if( whereLoopResize(db, pTo, pFrom->nLTerm) ){
 
 
156163 memset(pTo, 0, WHERE_LOOP_XFER_SZ);
156164 return SQLITE_NOMEM_BKPT;
156165 }
156166 memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);
156167 memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
@@ -156175,32 +156513,34 @@
156175
156176 /*
156177 ** Delete a WhereLoop object
156178 */
156179 static void whereLoopDelete(sqlite3 *db, WhereLoop *p){
 
156180 whereLoopClear(db, p);
156181 sqlite3DbFreeNN(db, p);
156182 }
156183
156184 /*
156185 ** Free a WhereInfo structure
156186 */
156187 static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
156188 assert( pWInfo!=0 );
 
156189 sqlite3WhereClauseClear(&pWInfo->sWC);
156190 while( pWInfo->pLoops ){
156191 WhereLoop *p = pWInfo->pLoops;
156192 pWInfo->pLoops = p->pNextLoop;
156193 whereLoopDelete(db, p);
156194 }
156195 assert( pWInfo->pExprMods==0 );
156196 while( pWInfo->pMemToFree ){
156197 WhereMemBlock *pNext = pWInfo->pMemToFree->pNext;
156198 sqlite3DbFreeNN(db, pWInfo->pMemToFree);
156199 pWInfo->pMemToFree = pNext;
156200 }
156201 sqlite3DbFreeNN(db, pWInfo);
156202 }
156203
156204 /* Undo all Expr node modifications
156205 */
156206 static void whereUndoExprMods(WhereInfo *pWInfo){
@@ -156810,11 +157150,15 @@
156810 pNew->wsFlags = saved_wsFlags;
156811 pNew->u.btree.nEq = saved_nEq;
156812 pNew->u.btree.nBtm = saved_nBtm;
156813 pNew->u.btree.nTop = saved_nTop;
156814 pNew->nLTerm = saved_nLTerm;
156815 if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
 
 
 
 
156816 pNew->aLTerm[pNew->nLTerm++] = pTerm;
156817 pNew->prereq = (saved_prereq | pTerm->prereqRight) & ~pNew->maskSelf;
156818
156819 assert( nInMul==0
156820 || (pNew->wsFlags & WHERE_COLUMN_NULL)!=0
@@ -156903,42 +157247,43 @@
156903 }
156904 }
156905 if( scan.iEquiv>1 ) pNew->wsFlags |= WHERE_TRANSCONS;
156906 }else if( eOp & WO_ISNULL ){
156907 pNew->wsFlags |= WHERE_COLUMN_NULL;
156908 }else if( eOp & (WO_GT|WO_GE) ){
156909 testcase( eOp & WO_GT );
156910 testcase( eOp & WO_GE );
156911 pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_BTM_LIMIT;
156912 pNew->u.btree.nBtm = whereRangeVectorLen(
156913 pParse, pSrc->iCursor, pProbe, saved_nEq, pTerm
156914 );
156915 pBtm = pTerm;
156916 pTop = 0;
156917 if( pTerm->wtFlags & TERM_LIKEOPT ){
156918 /* Range constraints that come from the LIKE optimization are
156919 ** always used in pairs. */
156920 pTop = &pTerm[1];
156921 assert( (pTop-(pTerm->pWC->a))<pTerm->pWC->nTerm );
156922 assert( pTop->wtFlags & TERM_LIKEOPT );
156923 assert( pTop->eOperator==WO_LT );
156924 if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
156925 pNew->aLTerm[pNew->nLTerm++] = pTop;
156926 pNew->wsFlags |= WHERE_TOP_LIMIT;
156927 pNew->u.btree.nTop = 1;
156928 }
156929 }else{
156930 assert( eOp & (WO_LT|WO_LE) );
156931 testcase( eOp & WO_LT );
156932 testcase( eOp & WO_LE );
156933 pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_TOP_LIMIT;
156934 pNew->u.btree.nTop = whereRangeVectorLen(
156935 pParse, pSrc->iCursor, pProbe, saved_nEq, pTerm
156936 );
156937 pTop = pTerm;
156938 pBtm = (pNew->wsFlags & WHERE_BTM_LIMIT)!=0 ?
156939 pNew->aLTerm[pNew->nLTerm-2] : 0;
 
156940 }
156941
156942 /* At this point pNew->nOut is set to the number of rows expected to
156943 ** be visited by the index scan before considering term pTerm, or the
156944 ** values of nIn and nInMul. In other words, assuming that all
@@ -157380,10 +157725,13 @@
157380 #ifdef SQLITE_ENABLE_STAT4
157381 pNew->rRun = rSize + 16 - 2*((pTab->tabFlags & TF_HasStat4)!=0);
157382 #else
157383 pNew->rRun = rSize + 16;
157384 #endif
 
 
 
157385 ApplyCostMultiplier(pNew->rRun, pTab->costMult);
157386 whereLoopOutputAdjust(pWC, pNew, rSize);
157387 rc = whereLoopInsert(pBuilder, pNew);
157388 pNew->nOut = rSize;
157389 if( rc ) break;
@@ -158106,11 +158454,17 @@
158106 WhereLoop *pNew;
158107
158108
158109 /* Loop over the tables in the join, from left to right */
158110 pNew = pBuilder->pNew;
158111 whereLoopInit(pNew);
 
 
 
 
 
 
158112 pBuilder->iPlanLimit = SQLITE_QUERY_PLANNER_LIMIT;
158113 for(iTab=0, pItem=pTabList->a; pItem<pEnd; iTab++, pItem++){
158114 Bitmask mUnusable = 0;
158115 pNew->iTab = iTab;
158116 pBuilder->iPlanLimit += SQLITE_QUERY_PLANNER_LIMIT_INCR;
@@ -158703,13 +159057,13 @@
158703 for(ii=0, pFrom=aFrom; ii<nFrom; ii++, pFrom++){
158704 for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
158705 LogEst nOut; /* Rows visited by (pFrom+pWLoop) */
158706 LogEst rCost; /* Cost of path (pFrom+pWLoop) */
158707 LogEst rUnsorted; /* Unsorted cost of (pFrom+pWLoop) */
158708 i8 isOrdered = pFrom->isOrdered; /* isOrdered for (pFrom+pWLoop) */
158709 Bitmask maskNew; /* Mask of src visited by (..) */
158710 Bitmask revMask = 0; /* Mask of rev-order loops for (..) */
158711
158712 if( (pWLoop->prereq & ~pFrom->maskLoop)!=0 ) continue;
158713 if( (pWLoop->maskSelf & pFrom->maskLoop)!=0 ) continue;
158714 if( (pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 && pFrom->nRow<3 ){
158715 /* Do not use an automatic index if the this loop is expected
@@ -158724,11 +159078,13 @@
158724 ** Compute its cost */
158725 rUnsorted = sqlite3LogEstAdd(pWLoop->rSetup,pWLoop->rRun + pFrom->nRow);
158726 rUnsorted = sqlite3LogEstAdd(rUnsorted, pFrom->rUnsorted);
158727 nOut = pFrom->nRow + pWLoop->nOut;
158728 maskNew = pFrom->maskLoop | pWLoop->maskSelf;
 
158729 if( isOrdered<0 ){
 
158730 isOrdered = wherePathSatisfiesOrderBy(pWInfo,
158731 pWInfo->pOrderBy, pFrom, pWInfo->wctrlFlags,
158732 iLoop, pWLoop, &revMask);
158733 }else{
158734 revMask = pFrom->revLoop;
@@ -158751,10 +159107,17 @@
158751 rUnsorted, rCost));
158752 }else{
158753 rCost = rUnsorted;
158754 rUnsorted -= 2; /* TUNING: Slight bias in favor of no-sort plans */
158755 }
 
 
 
 
 
 
 
158756
158757 /* Check to see if pWLoop should be added to the set of
158758 ** mxChoice best-so-far paths.
158759 **
158760 ** First look for an existing path among best-so-far paths
@@ -158984,11 +159347,12 @@
158984
158985
158986 pWInfo->nRowOut = pFrom->nRow;
158987
158988 /* Free temporary memory and return success */
158989 sqlite3DbFreeNN(db, pSpace);
 
158990 return SQLITE_OK;
158991 }
158992
158993 /*
158994 ** Most queries use only a single table (they are not joins) and have
@@ -161217,11 +161581,10 @@
161217 int i;
161218 int nInit = pList ? pList->nExpr : 0;
161219 for(i=0; i<pAppend->nExpr; i++){
161220 sqlite3 *db = pParse->db;
161221 Expr *pDup = sqlite3ExprDup(db, pAppend->a[i].pExpr, 0);
161222 assert( pDup==0 || !ExprHasProperty(pDup, EP_MemToken) );
161223 if( db->mallocFailed ){
161224 sqlite3ExprDelete(db, pDup);
161225 break;
161226 }
161227 if( bIntToNull ){
@@ -162488,14 +162851,13 @@
162488 }
162489 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrDone);
162490
162491 /* This block runs if reg1 is not NULL, but reg2 is. */
162492 sqlite3VdbeJumpHere(v, addr);
162493 sqlite3VdbeAddOp2(v, OP_IsNull, reg2, lbl); VdbeCoverage(v);
162494 if( op==OP_Gt || op==OP_Ge ){
162495 sqlite3VdbeChangeP2(v, -1, addrDone);
162496 }
162497 }
162498
162499 /* Register reg1 currently contains csr1.peerVal (the peer-value from csr1).
162500 ** This block adds (or subtracts for DESC) the numeric value in regVal
162501 ** from it. Or, if reg1 is not numeric (it is a NULL, a text value or a blob),
@@ -170068,11 +170430,11 @@
170068 sqlite3DeleteTable(db, pParse->pNewTable);
170069 }
170070 if( pParse->pNewTrigger && !IN_RENAME_OBJECT ){
170071 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
170072 }
170073 if( pParse->pVList ) sqlite3DbFreeNN(db, pParse->pVList);
170074 db->pParse = pParentParse;
170075 assert( nErr==0 || pParse->rc!=SQLITE_OK );
170076 return nErr;
170077 }
170078
@@ -171424,22 +171786,23 @@
171424 db->lookaside.pEnd = p;
171425 db->lookaside.bDisable = 0;
171426 db->lookaside.bMalloced = pBuf==0 ?1:0;
171427 db->lookaside.nSlot = nBig+nSm;
171428 }else{
171429 db->lookaside.pStart = db;
171430 #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
171431 db->lookaside.pSmallInit = 0;
171432 db->lookaside.pSmallFree = 0;
171433 db->lookaside.pMiddle = db;
171434 #endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
171435 db->lookaside.pEnd = db;
171436 db->lookaside.bDisable = 1;
171437 db->lookaside.sz = 0;
171438 db->lookaside.bMalloced = 0;
171439 db->lookaside.nSlot = 0;
171440 }
 
171441 assert( sqlite3LookasideUsed(db,0)==0 );
171442 #endif /* SQLITE_OMIT_LOOKASIDE */
171443 return SQLITE_OK;
171444 }
171445
@@ -171514,10 +171877,11 @@
171514 ** Configuration settings for an individual database connection
171515 */
171516 SQLITE_API int sqlite3_db_config(sqlite3 *db, int op, ...){
171517 va_list ap;
171518 int rc;
 
171519 va_start(ap, op);
171520 switch( op ){
171521 case SQLITE_DBCONFIG_MAINDBNAME: {
171522 /* IMP: R-06824-28531 */
171523 /* IMP: R-36257-52125 */
@@ -171579,10 +171943,11 @@
171579 }
171580 break;
171581 }
171582 }
171583 va_end(ap);
 
171584 return rc;
171585 }
171586
171587 /*
171588 ** This is the default collating function named "BINARY" which is always
@@ -181118,11 +181483,11 @@
181118 p1 = pPhrase->doclist.pList;
181119 p2 = aPoslist;
181120 nDistance = iPrev - nMaxUndeferred;
181121 }
181122
181123 aOut = (char *)sqlite3_malloc(nPoslist+8);
181124 if( !aOut ){
181125 sqlite3_free(aPoslist);
181126 return SQLITE_NOMEM;
181127 }
181128
@@ -204144,11 +204509,11 @@
204144 sqlite3_bind_value(pUp, 2, aData[2]);
204145 }
204146 sqlite3_free(p);
204147 nChange = 1;
204148 }
204149 for(jj=1; jj<pRtree->nAux; jj++){
204150 nChange++;
204151 sqlite3_bind_value(pUp, jj+2, aData[jj+2]);
204152 }
204153 if( nChange ){
204154 sqlite3_step(pUp);
@@ -212503,15 +212868,16 @@
212503 */
212504 static int dbpageBegin(sqlite3_vtab *pVtab){
212505 DbpageTable *pTab = (DbpageTable *)pVtab;
212506 sqlite3 *db = pTab->db;
212507 int i;
212508 for(i=0; i<db->nDb; i++){
 
212509 Btree *pBt = db->aDb[i].pBt;
212510 if( pBt ) sqlite3BtreeBeginTrans(pBt, 1, 0);
212511 }
212512 return SQLITE_OK;
212513 }
212514
212515
212516 /*
212517 ** Invoke this routine to register the "dbpage" virtual table module
@@ -219231,11 +219597,11 @@
219231 static void sqlite3Fts5BufferAppendPrintf(int *, Fts5Buffer*, char *zFmt, ...);
219232
219233 static char *sqlite3Fts5Mprintf(int *pRc, const char *zFmt, ...);
219234
219235 #define fts5BufferZero(x) sqlite3Fts5BufferZero(x)
219236 #define fts5BufferAppendVarint(a,b,c) sqlite3Fts5BufferAppendVarint(a,b,c)
219237 #define fts5BufferFree(a) sqlite3Fts5BufferFree(a)
219238 #define fts5BufferAppendBlob(a,b,c,d) sqlite3Fts5BufferAppendBlob(a,b,c,d)
219239 #define fts5BufferSet(a,b,c,d) sqlite3Fts5BufferSet(a,b,c,d)
219240
219241 #define fts5BufferGrow(pRc,pBuf,nn) ( \
@@ -231108,11 +231474,13 @@
231108 /* Write the rowid. */
231109 if( pWriter->bFirstRowidInDoclist || pWriter->bFirstRowidInPage ){
231110 fts5BufferAppendVarint(&p->rc, &pPage->buf, iRowid);
231111 }else{
231112 assert_nc( p->rc || iRowid>pWriter->iPrevRowid );
231113 fts5BufferAppendVarint(&p->rc, &pPage->buf, iRowid - pWriter->iPrevRowid);
 
 
231114 }
231115 pWriter->iPrevRowid = iRowid;
231116 pWriter->bFirstRowidInDoclist = 0;
231117 pWriter->bFirstRowidInPage = 0;
231118 }
@@ -231872,21 +232240,21 @@
231872 return fts5IndexReturn(p);
231873 }
231874
231875 static void fts5AppendRowid(
231876 Fts5Index *p,
231877 i64 iDelta,
231878 Fts5Iter *pUnused,
231879 Fts5Buffer *pBuf
231880 ){
231881 UNUSED_PARAM(pUnused);
231882 fts5BufferAppendVarint(&p->rc, pBuf, iDelta);
231883 }
231884
231885 static void fts5AppendPoslist(
231886 Fts5Index *p,
231887 i64 iDelta,
231888 Fts5Iter *pMulti,
231889 Fts5Buffer *pBuf
231890 ){
231891 int nData = pMulti->base.nData;
231892 int nByte = nData + 9 + 9 + FTS5_DATA_ZERO_PADDING;
@@ -231957,14 +232325,14 @@
231957 fts5BufferSafeAppendVarint(pBuf, iRowid - *piLastRowid);
231958 *piLastRowid = iRowid;
231959 }
231960 #endif
231961
231962 #define fts5MergeAppendDocid(pBuf, iLastRowid, iRowid) { \
231963 assert( (pBuf)->n!=0 || (iLastRowid)==0 ); \
231964 fts5BufferSafeAppendVarint((pBuf), (iRowid) - (iLastRowid)); \
231965 (iLastRowid) = (iRowid); \
231966 }
231967
231968 /*
231969 ** Swap the contents of buffer *p1 with that of *p2.
231970 */
@@ -232231,11 +232599,11 @@
232231 Fts5Buffer *aBuf;
232232 int nBuf = 32;
232233 int nMerge = 1;
232234
232235 void (*xMerge)(Fts5Index*, Fts5Buffer*, int, Fts5Buffer*);
232236 void (*xAppend)(Fts5Index*, i64, Fts5Iter*, Fts5Buffer*);
232237 if( p->pConfig->eDetail==FTS5_DETAIL_NONE ){
232238 xMerge = fts5MergeRowidLists;
232239 xAppend = fts5AppendRowid;
232240 }else{
232241 nMerge = FTS5_MERGE_NLIST-1;
@@ -232270,11 +232638,11 @@
232270 fts5MultiIterNext2(p, p1, &dummy)
232271 ){
232272 Fts5SegIter *pSeg = &p1->aSeg[ p1->aFirst[1].iFirst ];
232273 p1->xSetOutputs(p1, pSeg);
232274 if( p1->base.nData ){
232275 xAppend(p, p1->base.iRowid-iLastRowid, p1, &doclist);
232276 iLastRowid = p1->base.iRowid;
232277 }
232278 }
232279 fts5MultiIterFree(p1);
232280 }
@@ -232318,11 +232686,11 @@
232318 }
232319 }
232320 iLastRowid = 0;
232321 }
232322
232323 xAppend(p, p1->base.iRowid-iLastRowid, p1, &doclist);
232324 iLastRowid = p1->base.iRowid;
232325 }
232326
232327 assert( (nBuf%nMerge)==0 );
232328 for(i=0; i<nBuf; i+=nMerge){
@@ -236634,11 +237002,11 @@
236634 int nArg, /* Number of args */
236635 sqlite3_value **apUnused /* Function arguments */
236636 ){
236637 assert( nArg==0 );
236638 UNUSED_PARAM2(nArg, apUnused);
236639 sqlite3_result_text(pCtx, "fts5: 2022-07-21 12:26:01 9141e873c575b049ce7aeaf313d05966f1966087caf33a6c80d2416a28571a21", -1, SQLITE_TRANSIENT);
236640 }
236641
236642 /*
236643 ** Return true if zName is the extension on one of the shadow tables used
236644 ** by this module.
236645
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.40.0. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -450,13 +450,13 @@
450 **
451 ** See also: [sqlite3_libversion()],
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.40.0"
456 #define SQLITE_VERSION_NUMBER 3040000
457 #define SQLITE_SOURCE_ID "2022-09-02 21:19:24 da7af290960ab8a04a1f55cdc5eeac36b47fa194edf67f0a05daa4b7f2a4071c"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -3728,10 +3728,13 @@
3728 **
3729 ** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt>
3730 ** <dd>The database is opened [shared cache] enabled, overriding
3731 ** the default shared cache setting provided by
3732 ** [sqlite3_enable_shared_cache()].)^
3733 ** The [use of shared cache mode is discouraged] and hence shared cache
3734 ** capabilities may be omitted from many builds of SQLite. In such cases,
3735 ** this option is a no-op.
3736 **
3737 ** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt>
3738 ** <dd>The database is opened [shared cache] disabled, overriding
3739 ** the default shared cache setting provided by
3740 ** [sqlite3_enable_shared_cache()].)^
@@ -3743,11 +3746,11 @@
3746 ** connection as soon as the connection is created. In addition to setting
3747 ** the extended result code mode, this flag also causes [sqlite3_open_v2()]
3748 ** to return an extended result code.</dd>
3749 **
3750 ** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>
3751 ** <dd>The database filename is not allowed to contain a symbolic link</dd>
3752 ** </dl>)^
3753 **
3754 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
3755 ** required combinations shown above optionally combined with other
3756 ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
@@ -6769,11 +6772,11 @@
6772 **
6773 ** ^The sqlite3_autovacuum_pages(D,C,P,X) interface registers a callback
6774 ** function C that is invoked prior to each autovacuum of the database
6775 ** file. ^The callback is passed a copy of the generic data pointer (P),
6776 ** the schema-name of the attached database that is being autovacuumed,
6777 ** the size of the database file in pages, the number of free pages,
6778 ** and the number of bytes per page, respectively. The callback should
6779 ** return the number of free pages that should be removed by the
6780 ** autovacuum. ^If the callback returns zero, then no autovacuum happens.
6781 ** ^If the value returned is greater than or equal to the number of
6782 ** free pages, then a complete autovacuum happens.
@@ -6889,10 +6892,15 @@
6892 **
6893 ** ^(This routine enables or disables the sharing of the database cache
6894 ** and schema data structures between [database connection | connections]
6895 ** to the same database. Sharing is enabled if the argument is true
6896 ** and disabled if the argument is false.)^
6897 **
6898 ** This interface is omitted if SQLite is compiled with
6899 ** [-DSQLITE_OMIT_SHARED_CACHE]. The [-DSQLITE_OMIT_SHARED_CACHE]
6900 ** compile-time option is recommended because the
6901 ** [use of shared cache mode is discouraged].
6902 **
6903 ** ^Cache sharing is enabled and disabled for an entire process.
6904 ** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]).
6905 ** In prior versions of SQLite,
6906 ** sharing was enabled or disabled for each thread separately.
@@ -6988,11 +6996,11 @@
6996 ** ^Setting the heap limits to zero disables the heap limiter mechanism.
6997 **
6998 ** ^The soft heap limit may not be greater than the hard heap limit.
6999 ** ^If the hard heap limit is enabled and if sqlite3_soft_heap_limit(N)
7000 ** is invoked with a value of N that is greater than the hard heap limit,
7001 ** the soft heap limit is set to the value of the hard heap limit.
7002 ** ^The soft heap limit is automatically enabled whenever the hard heap
7003 ** limit is enabled. ^When sqlite3_hard_heap_limit64(N) is invoked and
7004 ** the soft heap limit is outside the range of 1..N, then the soft heap
7005 ** limit is set to N. ^Invoking sqlite3_soft_heap_limit64(0) when the
7006 ** hard heap limit is enabled makes the soft heap limit equal to the
@@ -9283,11 +9291,11 @@
9291 ** sqlite3_backup_init() is called and before the corresponding call to
9292 ** sqlite3_backup_finish(). SQLite does not currently check to see
9293 ** if the application incorrectly accesses the destination [database connection]
9294 ** and so no error code is reported, but the operations may malfunction
9295 ** nevertheless. Use of the destination database connection while a
9296 ** backup is in progress might also cause a mutex deadlock.
9297 **
9298 ** If running in [shared cache mode], the application must
9299 ** guarantee that the shared cache used by the destination database
9300 ** is not accessed while the backup is running. In practice this means
9301 ** that the application must guarantee that the disk file being
@@ -9711,11 +9719,11 @@
9719 ** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the
9720 ** meaning of each of these checkpoint modes.
9721 */
9722 #define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */
9723 #define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */
9724 #define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for readers */
9725 #define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */
9726
9727 /*
9728 ** CAPI3REF: Virtual Table Interface Configuration
9729 **
@@ -13142,10 +13150,15 @@
13150 /******** End of fts5.h *********/
13151
13152 /************** End of sqlite3.h *********************************************/
13153 /************** Continuing where we left off in sqliteInt.h ******************/
13154
13155 /*
13156 ** Reuse the STATIC_LRU for mutex access to sqlite3_temp_directory.
13157 */
13158 #define SQLITE_MUTEX_STATIC_TEMPDIR SQLITE_MUTEX_STATIC_VFS1
13159
13160 /*
13161 ** Include the configuration header output by 'configure' if we're using the
13162 ** autoconf-based build
13163 */
13164 #if defined(_HAVE_SQLITE_CONFIG_H) && !defined(SQLITECONFIG_H)
@@ -15553,67 +15566,67 @@
15566 #define OP_Checkpoint 3
15567 #define OP_JournalMode 4
15568 #define OP_Vacuum 5
15569 #define OP_VFilter 6 /* jump, synopsis: iplan=r[P3] zplan='P4' */
15570 #define OP_VUpdate 7 /* synopsis: data=r[P3@P2] */
15571 #define OP_Init 8 /* jump, synopsis: Start at P2 */
15572 #define OP_Goto 9 /* jump */
15573 #define OP_Gosub 10 /* jump */
15574 #define OP_InitCoroutine 11 /* jump */
15575 #define OP_Yield 12 /* jump */
15576 #define OP_MustBeInt 13 /* jump */
15577 #define OP_Jump 14 /* jump */
15578 #define OP_Once 15 /* jump */
15579 #define OP_If 16 /* jump */
15580 #define OP_IfNot 17 /* jump */
15581 #define OP_IsNullOrType 18 /* jump, synopsis: if typeof(r[P1]) IN (P3,5) goto P2 */
15582 #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
15583 #define OP_IfNullRow 20 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
15584 #define OP_SeekLT 21 /* jump, synopsis: key=r[P3@P4] */
15585 #define OP_SeekLE 22 /* jump, synopsis: key=r[P3@P4] */
15586 #define OP_SeekGE 23 /* jump, synopsis: key=r[P3@P4] */
15587 #define OP_SeekGT 24 /* jump, synopsis: key=r[P3@P4] */
15588 #define OP_IfNotOpen 25 /* jump, synopsis: if( !csr[P1] ) goto P2 */
15589 #define OP_IfNoHope 26 /* jump, synopsis: key=r[P3@P4] */
15590 #define OP_NoConflict 27 /* jump, synopsis: key=r[P3@P4] */
15591 #define OP_NotFound 28 /* jump, synopsis: key=r[P3@P4] */
15592 #define OP_Found 29 /* jump, synopsis: key=r[P3@P4] */
15593 #define OP_SeekRowid 30 /* jump, synopsis: intkey=r[P3] */
15594 #define OP_NotExists 31 /* jump, synopsis: intkey=r[P3] */
15595 #define OP_Last 32 /* jump */
15596 #define OP_IfSmaller 33 /* jump */
15597 #define OP_SorterSort 34 /* jump */
15598 #define OP_Sort 35 /* jump */
15599 #define OP_Rewind 36 /* jump */
15600 #define OP_SorterNext 37 /* jump */
15601 #define OP_Prev 38 /* jump */
15602 #define OP_Next 39 /* jump */
15603 #define OP_IdxLE 40 /* jump, synopsis: key=r[P3@P4] */
15604 #define OP_IdxGT 41 /* jump, synopsis: key=r[P3@P4] */
15605 #define OP_IdxLT 42 /* jump, synopsis: key=r[P3@P4] */
15606 #define OP_Or 43 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
15607 #define OP_And 44 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
15608 #define OP_IdxGE 45 /* jump, synopsis: key=r[P3@P4] */
15609 #define OP_RowSetRead 46 /* jump, synopsis: r[P3]=rowset(P1) */
15610 #define OP_RowSetTest 47 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */
15611 #define OP_Program 48 /* jump */
15612 #define OP_FkIfZero 49 /* jump, synopsis: if fkctr[P1]==0 goto P2 */
15613 #define OP_IsNull 50 /* jump, same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
15614 #define OP_NotNull 51 /* jump, same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
15615 #define OP_Ne 52 /* jump, same as TK_NE, synopsis: IF r[P3]!=r[P1] */
15616 #define OP_Eq 53 /* jump, same as TK_EQ, synopsis: IF r[P3]==r[P1] */
15617 #define OP_Gt 54 /* jump, same as TK_GT, synopsis: IF r[P3]>r[P1] */
15618 #define OP_Le 55 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */
15619 #define OP_Lt 56 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */
15620 #define OP_Ge 57 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */
15621 #define OP_ElseEq 58 /* jump, same as TK_ESCAPE */
15622 #define OP_IfPos 59 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
15623 #define OP_IfNotZero 60 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
15624 #define OP_DecrJumpZero 61 /* jump, synopsis: if (--r[P1])==0 goto P2 */
15625 #define OP_IncrVacuum 62 /* jump */
15626 #define OP_VNext 63 /* jump */
15627 #define OP_Filter 64 /* jump, synopsis: if key(P3@P4) not in filter(P1) goto P2 */
15628 #define OP_PureFunc 65 /* synopsis: r[P3]=func(r[P2@NP]) */
15629 #define OP_Function 66 /* synopsis: r[P3]=func(r[P2@NP]) */
15630 #define OP_Return 67
15631 #define OP_EndCoroutine 68
15632 #define OP_HaltIfNull 69 /* synopsis: if r[P3]=null halt */
@@ -15745,17 +15758,17 @@
15758 #define OPFLG_IN3 0x08 /* in3: P3 is an input */
15759 #define OPFLG_OUT2 0x10 /* out2: P2 is an output */
15760 #define OPFLG_OUT3 0x20 /* out3: P3 is an output */
15761 #define OPFLG_INITIALIZER {\
15762 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00,\
15763 /* 8 */ 0x01, 0x01, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01,\
15764 /* 16 */ 0x03, 0x03, 0x03, 0x12, 0x01, 0x09, 0x09, 0x09,\
15765 /* 24 */ 0x09, 0x01, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
15766 /* 32 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
15767 /* 40 */ 0x01, 0x01, 0x01, 0x26, 0x26, 0x01, 0x23, 0x0b,\
15768 /* 48 */ 0x01, 0x01, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
15769 /* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x03, 0x01, 0x01,\
15770 /* 64 */ 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10,\
15771 /* 72 */ 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10, 0x00,\
15772 /* 80 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x02, 0x02,\
15773 /* 88 */ 0x02, 0x00, 0x00, 0x12, 0x1e, 0x20, 0x00, 0x00,\
15774 /* 96 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x26, 0x26,\
@@ -15857,10 +15870,11 @@
15870 SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
15871 SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
15872 SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
15873 SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int);
15874 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
15875 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetLastOp(Vdbe*);
15876 SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Parse*);
15877 SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce(Vdbe*);
15878 SQLITE_PRIVATE void sqlite3VdbeReusable(Vdbe*);
15879 SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe*);
15880 SQLITE_PRIVATE void sqlite3VdbeMakeReady(Vdbe*,Parse*);
@@ -16741,10 +16755,11 @@
16755 void *pMiddle; /* First byte past end of full-size buffers and
16756 ** the first byte of LOOKASIDE_SMALL buffers */
16757 #endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
16758 void *pStart; /* First byte of available memory space */
16759 void *pEnd; /* First byte past end of available space */
16760 void *pTrueEnd; /* True value of pEnd, when db->pnBytesFreed!=0 */
16761 };
16762 struct LookasideSlot {
16763 LookasideSlot *pNext; /* Next buffer in the list of free buffers */
16764 };
16765
@@ -18189,11 +18204,11 @@
18204 #define EP_xIsSelect 0x001000 /* x.pSelect is valid (otherwise x.pList is) */
18205 #define EP_Skip 0x002000 /* Operator does not contribute to affinity */
18206 #define EP_Reduced 0x004000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
18207 #define EP_Win 0x008000 /* Contains window functions */
18208 #define EP_TokenOnly 0x010000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
18209 /* 0x020000 // Available for reuse */
18210 #define EP_IfNullRow 0x040000 /* The TK_IF_NULL_ROW opcode */
18211 #define EP_Unlikely 0x080000 /* unlikely() or likelihood() function */
18212 #define EP_ConstFunc 0x100000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
18213 #define EP_CanBeNull 0x200000 /* Can be null despite NOT NULL constraint */
18214 #define EP_Subquery 0x400000 /* Tree contains a TK_SELECT operator */
@@ -19667,10 +19682,11 @@
19682 SQLITE_PRIVATE void *sqlite3Realloc(void*, u64);
19683 SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64);
19684 SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64);
19685 SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*);
19686 SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3*, void*);
19687 SQLITE_PRIVATE void sqlite3DbNNFreeNN(sqlite3*, void*);
19688 SQLITE_PRIVATE int sqlite3MallocSize(const void*);
19689 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, const void*);
19690 SQLITE_PRIVATE void *sqlite3PageMalloc(int);
19691 SQLITE_PRIVATE void sqlite3PageFree(void*);
19692 SQLITE_PRIVATE void sqlite3MemSetDefault(void);
@@ -20191,10 +20207,11 @@
20207 SQLITE_PRIVATE int sqlite3FixSrcList(DbFixer*, SrcList*);
20208 SQLITE_PRIVATE int sqlite3FixSelect(DbFixer*, Select*);
20209 SQLITE_PRIVATE int sqlite3FixExpr(DbFixer*, Expr*);
20210 SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
20211 SQLITE_PRIVATE int sqlite3RealSameAsInt(double,sqlite3_int64);
20212 SQLITE_PRIVATE i64 sqlite3RealToI64(double);
20213 SQLITE_PRIVATE void sqlite3Int64ToText(i64,char*);
20214 SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*, int, u8);
20215 SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*);
20216 SQLITE_PRIVATE int sqlite3GetUInt32(const char*, u32*);
20217 SQLITE_PRIVATE int sqlite3Atoi(const char*);
@@ -21637,13 +21654,10 @@
21654 "OMIT_WSD",
21655 #endif
21656 #ifdef SQLITE_OMIT_XFER_OPT
21657 "OMIT_XFER_OPT",
21658 #endif
 
 
 
21659 #ifdef SQLITE_PERFORMANCE_TRACE
21660 "PERFORMANCE_TRACE",
21661 #endif
21662 #ifdef SQLITE_POWERSAFE_OVERWRITE
21663 # if SQLITE_POWERSAFE_OVERWRITE != 1
@@ -22592,11 +22606,11 @@
22606 ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()
22607 ** is really a pointer to an instance of this structure.
22608 */
22609 struct Vdbe {
22610 sqlite3 *db; /* The database connection that owns this statement */
22611 Vdbe **ppVPrev,*pVNext; /* Linked list of VDBEs with the same Vdbe.db */
22612 Parse *pParse; /* Parsing context used to create this Vdbe */
22613 ynVar nVar; /* Number of entries in aVar[] */
22614 int nMem; /* Number of memory locations currently allocated */
22615 int nCursor; /* Number of slots in apCsr[] */
22616 u32 cacheCtr; /* VdbeCursor row cache generation counter */
@@ -23150,10 +23164,12 @@
23164 int i; /* Used to iterate through schemas */
23165 int nByte = 0; /* Used to accumulate return value */
23166
23167 sqlite3BtreeEnterAll(db);
23168 db->pnBytesFreed = &nByte;
23169 assert( db->lookaside.pEnd==db->lookaside.pTrueEnd );
23170 db->lookaside.pEnd = db->lookaside.pStart;
23171 for(i=0; i<db->nDb; i++){
23172 Schema *pSchema = db->aDb[i].pSchema;
23173 if( ALWAYS(pSchema!=0) ){
23174 HashElem *p;
23175
@@ -23175,10 +23191,11 @@
23191 sqlite3DeleteTable(db, (Table *)sqliteHashData(p));
23192 }
23193 }
23194 }
23195 db->pnBytesFreed = 0;
23196 db->lookaside.pEnd = db->lookaside.pTrueEnd;
23197 sqlite3BtreeLeaveAll(db);
23198
23199 *pHighwater = 0;
23200 *pCurrent = nByte;
23201 break;
@@ -23192,13 +23209,16 @@
23209 case SQLITE_DBSTATUS_STMT_USED: {
23210 struct Vdbe *pVdbe; /* Used to iterate through VMs */
23211 int nByte = 0; /* Used to accumulate return value */
23212
23213 db->pnBytesFreed = &nByte;
23214 assert( db->lookaside.pEnd==db->lookaside.pTrueEnd );
23215 db->lookaside.pEnd = db->lookaside.pStart;
23216 for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pVNext){
23217 sqlite3VdbeDelete(pVdbe);
23218 }
23219 db->lookaside.pEnd = db->lookaside.pTrueEnd;
23220 db->pnBytesFreed = 0;
23221
23222 *pHighwater = 0; /* IMP: R-64479-57858 */
23223 *pCurrent = nByte;
23224
@@ -23530,11 +23550,11 @@
23550 X1 = 36525*(Y+4716)/100;
23551 X2 = 306001*(M+1)/10000;
23552 p->iJD = (sqlite3_int64)((X1 + X2 + D + B - 1524.5 ) * 86400000);
23553 p->validJD = 1;
23554 if( p->validHMS ){
23555 p->iJD += p->h*3600000 + p->m*60000 + (sqlite3_int64)(p->s*1000 + 0.5);
23556 if( p->validTZ ){
23557 p->iJD -= p->tz*60000;
23558 p->validYMD = 0;
23559 p->validHMS = 0;
23560 p->validTZ = 0;
@@ -24039,11 +24059,11 @@
24059 ** weekday N where 0==Sunday, 1==Monday, and so forth. If the
24060 ** date is already on the appropriate weekday, this is a no-op.
24061 */
24062 if( sqlite3_strnicmp(z, "weekday ", 8)==0
24063 && sqlite3AtoF(&z[8], &r, sqlite3Strlen30(&z[8]), SQLITE_UTF8)>0
24064 && r>=0.0 && r<7.0 && (n=(int)r)==r ){
24065 sqlite3_int64 Z;
24066 computeYMD_HMS(p);
24067 p->validTZ = 0;
24068 p->validJD = 0;
24069 computeJD(p);
@@ -24837,10 +24857,11 @@
24857 DO_OS_MALLOC_TEST(0);
24858 /* 0x87f7f is a mask of SQLITE_OPEN_ flags that are valid to be passed
24859 ** down into the VFS layer. Some SQLITE_OPEN_ flags (for example,
24860 ** SQLITE_OPEN_FULLMUTEX or SQLITE_OPEN_SHAREDCACHE) are blocked before
24861 ** reaching the VFS. */
24862 assert( zPath || (flags & SQLITE_OPEN_EXCLUSIVE) );
24863 rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x1087f7f, pFlagsOut);
24864 assert( rc==SQLITE_OK || pFile->pMethods==0 );
24865 return rc;
24866 }
24867 SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
@@ -29102,11 +29123,11 @@
29123 /*
29124 ** TRUE if p is a lookaside memory allocation from db
29125 */
29126 #ifndef SQLITE_OMIT_LOOKASIDE
29127 static int isLookaside(sqlite3 *db, const void *p){
29128 return SQLITE_WITHIN(p, db->lookaside.pStart, db->lookaside.pTrueEnd);
29129 }
29130 #else
29131 #define isLookaside(A,B) 0
29132 #endif
29133
@@ -29126,22 +29147,20 @@
29147 #endif
29148 }
29149 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, const void *p){
29150 assert( p!=0 );
29151 #ifdef SQLITE_DEBUG
29152 if( db==0 ){
29153 assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
29154 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
29155 }else if( !isLookaside(db,p) ){
29156 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
29157 assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
 
 
29158 }
29159 #endif
29160 if( db ){
29161 if( ((uptr)p)<(uptr)(db->lookaside.pTrueEnd) ){
29162 #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
29163 if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){
29164 assert( sqlite3_mutex_held(db->mutex) );
29165 return LOOKASIDE_SMALL;
29166 }
@@ -29193,18 +29212,15 @@
29212 */
29213 SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3 *db, void *p){
29214 assert( db==0 || sqlite3_mutex_held(db->mutex) );
29215 assert( p!=0 );
29216 if( db ){
 
 
 
 
29217 if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){
29218 #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
29219 if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){
29220 LookasideSlot *pBuf = (LookasideSlot*)p;
29221 assert( db->pnBytesFreed==0 );
29222 #ifdef SQLITE_DEBUG
29223 memset(p, 0xaa, LOOKASIDE_SMALL); /* Trash freed content */
29224 #endif
29225 pBuf->pNext = db->lookaside.pSmallFree;
29226 db->lookaside.pSmallFree = pBuf;
@@ -29211,24 +29227,66 @@
29227 return;
29228 }
29229 #endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
29230 if( ((uptr)p)>=(uptr)(db->lookaside.pStart) ){
29231 LookasideSlot *pBuf = (LookasideSlot*)p;
29232 assert( db->pnBytesFreed==0 );
29233 #ifdef SQLITE_DEBUG
29234 memset(p, 0xaa, db->lookaside.szTrue); /* Trash freed content */
29235 #endif
29236 pBuf->pNext = db->lookaside.pFree;
29237 db->lookaside.pFree = pBuf;
29238 return;
29239 }
29240 }
29241 if( db->pnBytesFreed ){
29242 measureAllocationSize(db, p);
29243 return;
29244 }
29245 }
29246 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
29247 assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
29248 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
29249 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
29250 sqlite3_free(p);
29251 }
29252 SQLITE_PRIVATE void sqlite3DbNNFreeNN(sqlite3 *db, void *p){
29253 assert( db!=0 );
29254 assert( sqlite3_mutex_held(db->mutex) );
29255 assert( p!=0 );
29256 if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){
29257 #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
29258 if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){
29259 LookasideSlot *pBuf = (LookasideSlot*)p;
29260 assert( db->pnBytesFreed==0 );
29261 #ifdef SQLITE_DEBUG
29262 memset(p, 0xaa, LOOKASIDE_SMALL); /* Trash freed content */
29263 #endif
29264 pBuf->pNext = db->lookaside.pSmallFree;
29265 db->lookaside.pSmallFree = pBuf;
29266 return;
29267 }
29268 #endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
29269 if( ((uptr)p)>=(uptr)(db->lookaside.pStart) ){
29270 LookasideSlot *pBuf = (LookasideSlot*)p;
29271 assert( db->pnBytesFreed==0 );
29272 #ifdef SQLITE_DEBUG
29273 memset(p, 0xaa, db->lookaside.szTrue); /* Trash freed content */
29274 #endif
29275 pBuf->pNext = db->lookaside.pFree;
29276 db->lookaside.pFree = pBuf;
29277 return;
29278 }
29279 }
29280 if( db->pnBytesFreed ){
29281 measureAllocationSize(db, p);
29282 return;
29283 }
29284 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
29285 assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
29286 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
29287 sqlite3_free(p);
29288 }
29289 SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
29290 assert( db==0 || sqlite3_mutex_held(db->mutex) );
29291 if( p ) sqlite3DbFreeNN(db, p);
29292 }
@@ -29561,12 +29619,17 @@
29619 if( db->nVdbeExec>0 ){
29620 AtomicStore(&db->u1.isInterrupted, 1);
29621 }
29622 DisableLookaside;
29623 if( db->pParse ){
29624 Parse *pParse;
29625 sqlite3ErrorMsg(db->pParse, "out of memory");
29626 db->pParse->rc = SQLITE_NOMEM_BKPT;
29627 for(pParse=db->pParse->pOuterParse; pParse; pParse = pParse->pOuterParse){
29628 pParse->nErr++;
29629 pParse->rc = SQLITE_NOMEM;
29630 }
29631 }
29632 }
29633 return 0;
29634 }
29635
@@ -32332,20 +32395,45 @@
32395
32396 /* All threads share a single random number generator.
32397 ** This structure is the current state of the generator.
32398 */
32399 static SQLITE_WSD struct sqlite3PrngType {
32400 u32 s[16]; /* 64 bytes of chacha20 state */
32401 u8 out[64]; /* Output bytes */
32402 u8 n; /* Output bytes remaining */
32403 } sqlite3Prng;
32404
32405
32406 /* The RFC-7539 ChaCha20 block function
32407 */
32408 #define ROTL(a,b) (((a) << (b)) | ((a) >> (32 - (b))))
32409 #define QR(a, b, c, d) ( \
32410 a += b, d ^= a, d = ROTL(d,16), \
32411 c += d, b ^= c, b = ROTL(b,12), \
32412 a += b, d ^= a, d = ROTL(d, 8), \
32413 c += d, b ^= c, b = ROTL(b, 7))
32414 static void chacha_block(u32 *out, const u32 *in){
32415 int i;
32416 u32 x[16];
32417 memcpy(x, in, 64);
32418 for(i=0; i<10; i++){
32419 QR(x[0], x[4], x[ 8], x[12]);
32420 QR(x[1], x[5], x[ 9], x[13]);
32421 QR(x[2], x[6], x[10], x[14]);
32422 QR(x[3], x[7], x[11], x[15]);
32423 QR(x[0], x[5], x[10], x[15]);
32424 QR(x[1], x[6], x[11], x[12]);
32425 QR(x[2], x[7], x[ 8], x[13]);
32426 QR(x[3], x[4], x[ 9], x[14]);
32427 }
32428 for(i=0; i<16; i++) out[i] = x[i]+in[i];
32429 }
32430
32431 /*
32432 ** Return N random bytes.
32433 */
32434 SQLITE_API void sqlite3_randomness(int N, void *pBuf){
 
32435 unsigned char *zBuf = pBuf;
32436
32437 /* The "wsdPrng" macro will resolve to the pseudo-random number generator
32438 ** state vector. If writable static data is unsupported on the target,
32439 ** we have to locate the state vector at run-time. In the more common
@@ -32371,57 +32459,50 @@
32459 mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
32460 #endif
32461
32462 sqlite3_mutex_enter(mutex);
32463 if( N<=0 || pBuf==0 ){
32464 wsdPrng.s[0] = 0;
32465 sqlite3_mutex_leave(mutex);
32466 return;
32467 }
32468
32469 /* Initialize the state of the random number generator once,
32470 ** the first time this routine is called.
 
 
 
 
 
 
32471 */
32472 if( wsdPrng.s[0]==0 ){
32473 sqlite3_vfs *pVfs = sqlite3_vfs_find(0);
32474 static const u32 chacha20_init[] = {
32475 0x61707865, 0x3320646e, 0x79622d32, 0x6b206574
32476 };
32477 memcpy(&wsdPrng.s[0], chacha20_init, 16);
32478 if( NEVER(pVfs==0) ){
32479 memset(&wsdPrng.s[4], 0, 44);
32480 }else{
32481 sqlite3OsRandomness(pVfs, 44, (char*)&wsdPrng.s[4]);
32482 }
32483 wsdPrng.s[15] = wsdPrng.s[12];
32484 wsdPrng.s[12] = 0;
32485 wsdPrng.n = 0;
 
 
 
 
 
 
 
32486 }
32487
32488 assert( N>0 );
32489 while( 1 /* exit by break */ ){
32490 if( N<=wsdPrng.n ){
32491 memcpy(zBuf, &wsdPrng.out[wsdPrng.n-N], N);
32492 wsdPrng.n -= N;
32493 break;
32494 }
32495 if( wsdPrng.n>0 ){
32496 memcpy(zBuf, wsdPrng.out, wsdPrng.n);
32497 N -= wsdPrng.n;
32498 zBuf += wsdPrng.n;
32499 }
32500 wsdPrng.s[12]++;
32501 chacha_block((u32*)wsdPrng.out, wsdPrng.s);
32502 wsdPrng.n = 64;
32503 }
32504 sqlite3_mutex_leave(mutex);
32505 }
32506
32507 #ifndef SQLITE_UNTESTABLE
32508 /*
@@ -33457,11 +33538,11 @@
33538 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse *pParse, const char *zFormat, ...){
33539 char *zMsg;
33540 va_list ap;
33541 sqlite3 *db = pParse->db;
33542 assert( db!=0 );
33543 assert( db->pParse==pParse || db->pParse->pToplevel==pParse );
33544 db->errByteOffset = -2;
33545 va_start(ap, zFormat);
33546 zMsg = sqlite3VMPrintf(db, zFormat, ap);
33547 va_end(ap);
33548 if( db->errByteOffset<-1 ) db->errByteOffset = -1;
@@ -35275,67 +35356,67 @@
35356 /* 3 */ "Checkpoint" OpHelp(""),
35357 /* 4 */ "JournalMode" OpHelp(""),
35358 /* 5 */ "Vacuum" OpHelp(""),
35359 /* 6 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"),
35360 /* 7 */ "VUpdate" OpHelp("data=r[P3@P2]"),
35361 /* 8 */ "Init" OpHelp("Start at P2"),
35362 /* 9 */ "Goto" OpHelp(""),
35363 /* 10 */ "Gosub" OpHelp(""),
35364 /* 11 */ "InitCoroutine" OpHelp(""),
35365 /* 12 */ "Yield" OpHelp(""),
35366 /* 13 */ "MustBeInt" OpHelp(""),
35367 /* 14 */ "Jump" OpHelp(""),
35368 /* 15 */ "Once" OpHelp(""),
35369 /* 16 */ "If" OpHelp(""),
35370 /* 17 */ "IfNot" OpHelp(""),
35371 /* 18 */ "IsNullOrType" OpHelp("if typeof(r[P1]) IN (P3,5) goto P2"),
35372 /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
35373 /* 20 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
35374 /* 21 */ "SeekLT" OpHelp("key=r[P3@P4]"),
35375 /* 22 */ "SeekLE" OpHelp("key=r[P3@P4]"),
35376 /* 23 */ "SeekGE" OpHelp("key=r[P3@P4]"),
35377 /* 24 */ "SeekGT" OpHelp("key=r[P3@P4]"),
35378 /* 25 */ "IfNotOpen" OpHelp("if( !csr[P1] ) goto P2"),
35379 /* 26 */ "IfNoHope" OpHelp("key=r[P3@P4]"),
35380 /* 27 */ "NoConflict" OpHelp("key=r[P3@P4]"),
35381 /* 28 */ "NotFound" OpHelp("key=r[P3@P4]"),
35382 /* 29 */ "Found" OpHelp("key=r[P3@P4]"),
35383 /* 30 */ "SeekRowid" OpHelp("intkey=r[P3]"),
35384 /* 31 */ "NotExists" OpHelp("intkey=r[P3]"),
35385 /* 32 */ "Last" OpHelp(""),
35386 /* 33 */ "IfSmaller" OpHelp(""),
35387 /* 34 */ "SorterSort" OpHelp(""),
35388 /* 35 */ "Sort" OpHelp(""),
35389 /* 36 */ "Rewind" OpHelp(""),
35390 /* 37 */ "SorterNext" OpHelp(""),
35391 /* 38 */ "Prev" OpHelp(""),
35392 /* 39 */ "Next" OpHelp(""),
35393 /* 40 */ "IdxLE" OpHelp("key=r[P3@P4]"),
35394 /* 41 */ "IdxGT" OpHelp("key=r[P3@P4]"),
35395 /* 42 */ "IdxLT" OpHelp("key=r[P3@P4]"),
35396 /* 43 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
35397 /* 44 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
35398 /* 45 */ "IdxGE" OpHelp("key=r[P3@P4]"),
35399 /* 46 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
35400 /* 47 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
35401 /* 48 */ "Program" OpHelp(""),
35402 /* 49 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
35403 /* 50 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
35404 /* 51 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
35405 /* 52 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
35406 /* 53 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
35407 /* 54 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
35408 /* 55 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
35409 /* 56 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
35410 /* 57 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
35411 /* 58 */ "ElseEq" OpHelp(""),
35412 /* 59 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
35413 /* 60 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
35414 /* 61 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
35415 /* 62 */ "IncrVacuum" OpHelp(""),
35416 /* 63 */ "VNext" OpHelp(""),
35417 /* 64 */ "Filter" OpHelp("if key(P3@P4) not in filter(P1) goto P2"),
35418 /* 65 */ "PureFunc" OpHelp("r[P3]=func(r[P2@NP])"),
35419 /* 66 */ "Function" OpHelp("r[P3]=func(r[P2@NP])"),
35420 /* 67 */ "Return" OpHelp(""),
35421 /* 68 */ "EndCoroutine" OpHelp(""),
35422 /* 69 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
@@ -41318,30 +41399,39 @@
41399 ** pVfs->mxPathname bytes.
41400 */
41401 static int unixGetTempname(int nBuf, char *zBuf){
41402 const char *zDir;
41403 int iLimit = 0;
41404 int rc = SQLITE_OK;
41405
41406 /* It's odd to simulate an io-error here, but really this is just
41407 ** using the io-error infrastructure to test that SQLite handles this
41408 ** function failing.
41409 */
41410 zBuf[0] = 0;
41411 SimulateIOError( return SQLITE_IOERR );
41412
41413 sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
41414 zDir = unixTempFileDir();
41415 if( zDir==0 ){
41416 rc = SQLITE_IOERR_GETTEMPPATH;
41417 }else{
41418 do{
41419 u64 r;
41420 sqlite3_randomness(sizeof(r), &r);
41421 assert( nBuf>2 );
41422 zBuf[nBuf-2] = 0;
41423 sqlite3_snprintf(nBuf, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX"%llx%c",
41424 zDir, r, 0);
41425 if( zBuf[nBuf-2]!=0 || (iLimit++)>10 ){
41426 rc = SQLITE_ERROR;
41427 break;
41428 }
41429 }while( osAccess(zBuf,0)==0 );
41430 }
41431 sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
41432 return rc;
41433 }
41434
41435 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
41436 /*
41437 ** Routine to transform a unixFile into a proxy-locking unixFile.
@@ -43512,11 +43602,16 @@
43602 ** correctly. See ticket [bb3a86e890c8e96ab] */
43603 assert( ArraySize(aSyscall)==29 );
43604
43605 /* Register all VFSes defined in the aVfs[] array */
43606 for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){
43607 #ifdef SQLITE_DEFAULT_UNIX_VFS
43608 sqlite3_vfs_register(&aVfs[i],
43609 0==strcmp(aVfs[i].zName,SQLITE_DEFAULT_UNIX_VFS));
43610 #else
43611 sqlite3_vfs_register(&aVfs[i], i==0);
43612 #endif
43613 }
43614 unixBigLock = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
43615
43616 #ifndef SQLITE_OMIT_WAL
43617 /* Validate lock assumptions */
@@ -45480,10 +45575,11 @@
45575 char **ppDirectory = 0;
45576 #ifndef SQLITE_OMIT_AUTOINIT
45577 int rc = sqlite3_initialize();
45578 if( rc ) return rc;
45579 #endif
45580 sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
45581 if( type==SQLITE_WIN32_DATA_DIRECTORY_TYPE ){
45582 ppDirectory = &sqlite3_data_directory;
45583 }else if( type==SQLITE_WIN32_TEMP_DIRECTORY_TYPE ){
45584 ppDirectory = &sqlite3_temp_directory;
45585 }
@@ -45494,18 +45590,23 @@
45590 if( ppDirectory ){
45591 char *zCopy = 0;
45592 if( zValue && zValue[0] ){
45593 zCopy = sqlite3_mprintf("%s", zValue);
45594 if ( zCopy==0 ){
45595 rc = SQLITE_NOMEM_BKPT;
45596 goto set_directory8_done;
45597 }
45598 }
45599 sqlite3_free(*ppDirectory);
45600 *ppDirectory = zCopy;
45601 rc = SQLITE_OK;
45602 }else{
45603 rc = SQLITE_ERROR;
45604 }
45605 set_directory8_done:
45606 sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
45607 return rc;
45608 }
45609
45610 /*
45611 ** This function is the same as sqlite3_win32_set_directory (below); however,
45612 ** it accepts a UTF-16 string.
@@ -48274,10 +48375,22 @@
48375 }
48376 }
48377 }
48378 return 0;
48379 }
48380
48381 /*
48382 ** If sqlite3_temp_directory is not, take the mutex and return true.
48383 **
48384 ** If sqlite3_temp_directory is NULL, omit the mutex and return false.
48385 */
48386 static int winTempDirDefined(void){
48387 sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
48388 if( sqlite3_temp_directory!=0 ) return 1;
48389 sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
48390 return 0;
48391 }
48392
48393 /*
48394 ** Create a temporary file name and store the resulting pointer into pzBuf.
48395 ** The pointer returned in pzBuf must be freed via sqlite3_free().
48396 */
@@ -48311,24 +48424,27 @@
48424 ** has been explicitly set by the application; otherwise, use the one
48425 ** configured by the operating system.
48426 */
48427 nDir = nMax - (nPre + 15);
48428 assert( nDir>0 );
48429 if( winTempDirDefined() ){
48430 int nDirLen = sqlite3Strlen30(sqlite3_temp_directory);
48431 if( nDirLen>0 ){
48432 if( !winIsDirSep(sqlite3_temp_directory[nDirLen-1]) ){
48433 nDirLen++;
48434 }
48435 if( nDirLen>nDir ){
48436 sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
48437 sqlite3_free(zBuf);
48438 OSTRACE(("TEMP-FILENAME rc=SQLITE_ERROR\n"));
48439 return winLogError(SQLITE_ERROR, 0, "winGetTempname1", 0);
48440 }
48441 sqlite3_snprintf(nMax, zBuf, "%s", sqlite3_temp_directory);
48442 }
48443 sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
48444 }
48445
48446 #if defined(__CYGWIN__)
48447 else{
48448 static const char *azDirs[] = {
48449 0, /* getenv("SQLITE_TMPDIR") */
48450 0, /* getenv("TMPDIR") */
@@ -49113,11 +49229,11 @@
49229 /*
49230 ** Turn a relative pathname into a full pathname. Write the full
49231 ** pathname into zOut[]. zOut[] will be at least pVfs->mxPathname
49232 ** bytes in size.
49233 */
49234 static int winFullPathnameNoMutex(
49235 sqlite3_vfs *pVfs, /* Pointer to vfs object */
49236 const char *zRelative, /* Possibly relative input path */
49237 int nFull, /* Size of output buffer in bytes */
49238 char *zFull /* Output buffer */
49239 ){
@@ -49291,10 +49407,23 @@
49407 return SQLITE_OK;
49408 }else{
49409 return SQLITE_IOERR_NOMEM_BKPT;
49410 }
49411 #endif
49412 }
49413 static int winFullPathname(
49414 sqlite3_vfs *pVfs, /* Pointer to vfs object */
49415 const char *zRelative, /* Possibly relative input path */
49416 int nFull, /* Size of output buffer in bytes */
49417 char *zFull /* Output buffer */
49418 ){
49419 int rc;
49420 sqlite3_mutex *pMutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR);
49421 sqlite3_mutex_enter(pMutex);
49422 rc = winFullPathnameNoMutex(pVfs, zRelative, nFull, zFull);
49423 sqlite3_mutex_leave(pMutex);
49424 return rc;
49425 }
49426
49427 #ifndef SQLITE_OMIT_LOAD_EXTENSION
49428 /*
49429 ** Interfaces for opening a shared library, finding entry points
@@ -51080,39 +51209,58 @@
51209 */
51210 #if defined(SQLITE_DEBUG) && 0
51211 int sqlite3PcacheTrace = 2; /* 0: off 1: simple 2: cache dumps */
51212 int sqlite3PcacheMxDump = 9999; /* Max cache entries for pcacheDump() */
51213 # define pcacheTrace(X) if(sqlite3PcacheTrace){sqlite3DebugPrintf X;}
51214 static void pcachePageTrace(int i, sqlite3_pcache_page *pLower){
 
 
 
51215 PgHdr *pPg;
51216 unsigned char *a;
51217 int j;
51218 pPg = (PgHdr*)pLower->pExtra;
51219 printf("%3d: nRef %2d flgs %02x data ", i, pPg->nRef, pPg->flags);
51220 a = (unsigned char *)pLower->pBuf;
51221 for(j=0; j<12; j++) printf("%02x", a[j]);
51222 printf(" ptr %p\n", pPg);
51223 }
51224 static void pcacheDump(PCache *pCache){
51225 int N;
51226 int i;
51227 sqlite3_pcache_page *pLower;
51228
51229 if( sqlite3PcacheTrace<2 ) return;
51230 if( pCache->pCache==0 ) return;
51231 N = sqlite3PcachePagecount(pCache);
51232 if( N>sqlite3PcacheMxDump ) N = sqlite3PcacheMxDump;
51233 for(i=1; i<=N; i++){
51234 pLower = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, i, 0);
51235 if( pLower==0 ) continue;
51236 pcachePageTrace(i, pLower);
51237 if( ((PgHdr*)pLower)->pPage==0 ){
 
 
 
 
51238 sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pLower, 0);
51239 }
51240 }
51241 }
51242 #else
51243 # define pcacheTrace(X)
51244 # define pcachePageTrace(PGNO, X)
51245 # define pcacheDump(X)
51246 #endif
51247
51248 /*
51249 ** Return 1 if pPg is on the dirty list for pCache. Return 0 if not.
51250 ** This routine runs inside of assert() statements only.
51251 */
51252 #ifdef SQLITE_DEBUG
51253 static int pageOnDirtyList(PCache *pCache, PgHdr *pPg){
51254 PgHdr *p;
51255 for(p=pCache->pDirty; p; p=p->pDirtyNext){
51256 if( p==pPg ) return 1;
51257 }
51258 return 0;
51259 }
51260 #endif
51261
51262 /*
51263 ** Check invariants on a PgHdr entry. Return true if everything is OK.
51264 ** Return false if any invariant is violated.
51265 **
51266 ** This routine is for use inside of assert() statements only. For
@@ -51127,12 +51275,17 @@
51275 assert( pPg->pgno>0 || pPg->pPager==0 ); /* Page number is 1 or more */
51276 pCache = pPg->pCache;
51277 assert( pCache!=0 ); /* Every page has an associated PCache */
51278 if( pPg->flags & PGHDR_CLEAN ){
51279 assert( (pPg->flags & PGHDR_DIRTY)==0 );/* Cannot be both CLEAN and DIRTY */
51280 assert( !pageOnDirtyList(pCache, pPg) );/* CLEAN pages not on dirty list */
51281 }else{
51282 assert( (pPg->flags & PGHDR_DIRTY)!=0 );/* If not CLEAN must be DIRTY */
51283 assert( pPg->pDirtyNext==0 || pPg->pDirtyNext->pDirtyPrev==pPg );
51284 assert( pPg->pDirtyPrev==0 || pPg->pDirtyPrev->pDirtyNext==pPg );
51285 assert( pPg->pDirtyPrev!=0 || pCache->pDirty==pPg );
51286 assert( pageOnDirtyList(pCache, pPg) );
51287 }
51288 /* WRITEABLE pages must also be DIRTY */
51289 if( pPg->flags & PGHDR_WRITEABLE ){
51290 assert( pPg->flags & PGHDR_DIRTY ); /* WRITEABLE implies DIRTY */
51291 }
@@ -51402,12 +51555,13 @@
51555 eCreate = createFlag & pCache->eCreate;
51556 assert( eCreate==0 || eCreate==1 || eCreate==2 );
51557 assert( createFlag==0 || pCache->eCreate==eCreate );
51558 assert( createFlag==0 || eCreate==1+(!pCache->bPurgeable||!pCache->pDirty) );
51559 pRes = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
51560 pcacheTrace(("%p.FETCH %d%s (result: %p) ",pCache,pgno,
51561 createFlag?" create":"",pRes));
51562 pcachePageTrace(pgno, pRes);
51563 return pRes;
51564 }
51565
51566 /*
51567 ** If the sqlite3PcacheFetch() routine is unable to allocate a new
@@ -51531,10 +51685,11 @@
51685 if( (--p->nRef)==0 ){
51686 if( p->flags&PGHDR_CLEAN ){
51687 pcacheUnpin(p);
51688 }else{
51689 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
51690 assert( sqlite3PcachePageSanity(p) );
51691 }
51692 }
51693 }
51694
51695 /*
@@ -51574,10 +51729,11 @@
51729 if( p->flags & PGHDR_CLEAN ){
51730 p->flags ^= (PGHDR_DIRTY|PGHDR_CLEAN);
51731 pcacheTrace(("%p.DIRTY %d\n",p->pCache,p->pgno));
51732 assert( (p->flags & (PGHDR_DIRTY|PGHDR_CLEAN))==PGHDR_DIRTY );
51733 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_ADD);
51734 assert( sqlite3PcachePageSanity(p) );
51735 }
51736 assert( sqlite3PcachePageSanity(p) );
51737 }
51738 }
51739
@@ -51636,18 +51792,28 @@
51792 /*
51793 ** Change the page number of page p to newPgno.
51794 */
51795 SQLITE_PRIVATE void sqlite3PcacheMove(PgHdr *p, Pgno newPgno){
51796 PCache *pCache = p->pCache;
51797 sqlite3_pcache_page *pOther;
51798 assert( p->nRef>0 );
51799 assert( newPgno>0 );
51800 assert( sqlite3PcachePageSanity(p) );
51801 pcacheTrace(("%p.MOVE %d -> %d\n",pCache,p->pgno,newPgno));
51802 pOther = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, newPgno, 0);
51803 sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
51804 if( pOther ){
51805 PgHdr *pPg = (PgHdr*)pOther->pExtra;
51806 pPg->pgno = p->pgno;
51807 if( pPg->pPage==0 ){
51808 sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pOther, 0);
51809 }
51810 }
51811 p->pgno = newPgno;
51812 if( (p->flags&PGHDR_DIRTY) && (p->flags&PGHDR_NEED_SYNC) ){
51813 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
51814 assert( sqlite3PcachePageSanity(p) );
51815 }
51816 }
51817
51818 /*
51819 ** Drop every cache entry whose page number is greater than "pgno". The
@@ -51941,16 +52107,17 @@
52107 ** runtime using sqlite3_config(SQLITE_CONFIG_PCACHE_HDRSZ, &size). The
52108 ** sizes of the extensions sum to 272 bytes on x64 for 3.8.10, but this
52109 ** size can vary according to architecture, compile-time options, and
52110 ** SQLite library version number.
52111 **
52112 ** Historical note: It used to be that if the SQLITE_PCACHE_SEPARATE_HEADER
52113 ** was defined, then the page content would be held in a separate memory
52114 ** allocation from the PgHdr1. This was intended to avoid clownshoe memory
52115 ** allocations. However, the btree layer needs a small (16-byte) overrun
52116 ** area after the page content buffer. The header serves as that overrun
52117 ** area. Therefore SQLITE_PCACHE_SEPARATE_HEADER was discontinued to avoid
52118 ** any possibility of a memory error.
52119 **
52120 ** This module tracks pointers to PgHdr1 objects. Only pcache.c communicates
52121 ** with this module. Information is passed back and forth as PgHdr1 pointers.
52122 **
52123 ** The pcache.c and pager.c modules deal pointers to PgHdr objects.
@@ -51991,34 +52158,44 @@
52158 typedef struct PgFreeslot PgFreeslot;
52159 typedef struct PGroup PGroup;
52160
52161 /*
52162 ** Each cache entry is represented by an instance of the following
52163 ** structure. A buffer of PgHdr1.pCache->szPage bytes is allocated
52164 ** directly before this structure and is used to cache the page content.
 
52165 **
52166 ** When reading a corrupt database file, it is possible that SQLite might
52167 ** read a few bytes (no more than 16 bytes) past the end of the page buffer.
52168 ** It will only read past the end of the page buffer, never write. This
52169 ** object is positioned immediately after the page buffer to serve as an
52170 ** overrun area, so that overreads are harmless.
52171 **
52172 ** Variables isBulkLocal and isAnchor were once type "u8". That works,
52173 ** but causes a 2-byte gap in the structure for most architectures (since
52174 ** pointers must be either 4 or 8-byte aligned). As this structure is located
52175 ** in memory directly after the associated page data, if the database is
52176 ** corrupt, code at the b-tree layer may overread the page buffer and
52177 ** read part of this structure before the corruption is detected. This
52178 ** can cause a valgrind error if the unitialized gap is accessed. Using u16
52179 ** ensures there is no such gap, and therefore no bytes of uninitialized
52180 ** memory in the structure.
52181 **
52182 ** The pLruNext and pLruPrev pointers form a double-linked circular list
52183 ** of all pages that are unpinned. The PGroup.lru element (which should be
52184 ** the only element on the list with PgHdr1.isAnchor set to 1) forms the
52185 ** beginning and the end of the list.
52186 */
52187 struct PgHdr1 {
52188 sqlite3_pcache_page page; /* Base class. Must be first. pBuf & pExtra */
52189 unsigned int iKey; /* Key value (page number) */
52190 u16 isBulkLocal; /* This page from bulk local storage */
52191 u16 isAnchor; /* This is the PGroup.lru element */
52192 PgHdr1 *pNext; /* Next in hash table chain */
52193 PCache1 *pCache; /* Cache that currently owns this page */
52194 PgHdr1 *pLruNext; /* Next in circular LRU list of unpinned pages */
52195 PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
52196 /* NB: pLruPrev is only valid if pLruNext!=0 */
52197 };
52198
52199 /*
52200 ** A page is pinned if it is not on the LRU list. To be "pinned" means
52201 ** that the page is in active use and must not be deallocated.
@@ -52340,29 +52517,17 @@
52517 assert( pcache1.separateCache==0 );
52518 assert( pCache->pGroup==&pcache1.grp );
52519 pcache1LeaveMutex(pCache->pGroup);
52520 #endif
52521 if( benignMalloc ){ sqlite3BeginBenignMalloc(); }
 
 
 
 
 
 
 
 
 
52522 pPg = pcache1Alloc(pCache->szAlloc);
 
52523 if( benignMalloc ){ sqlite3EndBenignMalloc(); }
52524 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
52525 pcache1EnterMutex(pCache->pGroup);
52526 #endif
52527 if( pPg==0 ) return 0;
 
52528 p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
 
52529 p->page.pBuf = pPg;
52530 p->page.pExtra = &p[1];
52531 p->isBulkLocal = 0;
52532 p->isAnchor = 0;
52533 p->pLruPrev = 0; /* Initializing this saves a valgrind error */
@@ -52382,13 +52547,10 @@
52547 if( p->isBulkLocal ){
52548 p->pNext = pCache->pFree;
52549 pCache->pFree = p;
52550 }else{
52551 pcache1Free(p->page.pBuf);
 
 
 
52552 }
52553 (*pCache->pnPurgeable)--;
52554 }
52555
52556 /*
@@ -53025,27 +53187,45 @@
53187 unsigned int iNew
53188 ){
53189 PCache1 *pCache = (PCache1 *)p;
53190 PgHdr1 *pPage = (PgHdr1 *)pPg;
53191 PgHdr1 **pp;
53192 unsigned int hOld, hNew;
53193 assert( pPage->iKey==iOld );
53194 assert( pPage->pCache==pCache );
53195 assert( iOld!=iNew ); /* The page number really is changing */
53196
53197 pcache1EnterMutex(pCache->pGroup);
53198
53199 assert( pcache1FetchNoMutex(p, iOld, 0)==pPage ); /* pPg really is iOld */
53200 hOld = iOld%pCache->nHash;
53201 pp = &pCache->apHash[hOld];
53202 while( (*pp)!=pPage ){
53203 pp = &(*pp)->pNext;
53204 }
53205 *pp = pPage->pNext;
53206
53207 hNew = iNew%pCache->nHash;
53208 pp = &pCache->apHash[hNew];
53209 while( *pp ){
53210 if( (*pp)->iKey==iNew ){
53211 /* If there is already another pcache entry at iNew, change it to iOld,
53212 ** thus swapping the positions of iNew and iOld */
53213 PgHdr1 *pOld = *pp;
53214 *pp = pOld->pNext;
53215 pOld->pNext = pCache->apHash[hOld];
53216 pCache->apHash[hOld] = pOld;
53217 pOld->iKey = iOld;
53218 break;
53219 }else{
53220 pp = &(*pp)->pNext;
53221 }
53222 }
53223
53224 pPage->iKey = iNew;
53225 pPage->pNext = pCache->apHash[hNew];
53226 pCache->apHash[hNew] = pPage;
53227 if( iNew>pCache->iMaxKey ){
53228 pCache->iMaxKey = iNew;
53229 }
53230
53231 pcache1LeaveMutex(pCache->pGroup);
@@ -53148,13 +53328,10 @@
53328 while( (nReq<0 || nFree<nReq)
53329 && (p=pcache1.grp.lru.pLruPrev)!=0
53330 && p->isAnchor==0
53331 ){
53332 nFree += pcache1MemSize(p->page.pBuf);
 
 
 
53333 assert( PAGE_IS_UNPINNED(p) );
53334 pcache1PinPage(p);
53335 pcache1RemoveFromHash(p, 1);
53336 }
53337 pcache1LeaveMutex(&pcache1.grp);
@@ -59639,10 +59816,11 @@
59816 int flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
59817 int nSpill;
59818
59819 if( pPager->tempFile ){
59820 flags |= (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL);
59821 flags |= SQLITE_OPEN_EXCLUSIVE;
59822 nSpill = sqlite3Config.nStmtSpill;
59823 }else{
59824 flags |= SQLITE_OPEN_MAIN_JOURNAL;
59825 nSpill = jrnlBufferSize(pPager);
59826 }
@@ -59674,10 +59852,11 @@
59852 }
59853
59854 if( rc!=SQLITE_OK ){
59855 sqlite3BitvecDestroy(pPager->pInJournal);
59856 pPager->pInJournal = 0;
59857 pPager->journalOff = 0;
59858 }else{
59859 assert( pPager->eState==PAGER_WRITER_LOCKED );
59860 pPager->eState = PAGER_WRITER_CACHEMOD;
59861 }
59862
@@ -66737,10 +66916,11 @@
66916 ** db using sqlite3SchemaToIndex().
66917 */
66918 SQLITE_PRIVATE int sqlite3SchemaMutexHeld(sqlite3 *db, int iDb, Schema *pSchema){
66919 Btree *p;
66920 assert( db!=0 );
66921 if( db->pVfs==0 && db->nDb==0 ) return 1;
66922 if( pSchema ) iDb = sqlite3SchemaToIndex(db, pSchema);
66923 assert( iDb>=0 && iDb<db->nDb );
66924 if( !sqlite3_mutex_held(db->mutex) ) return 0;
66925 if( iDb==1 ) return 1;
66926 p = db->aDb[iDb].pBt;
@@ -68309,12 +68489,11 @@
68489 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
68490 assert( pPage->pBt!=0 );
68491 assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
68492 assert( pPage->nOverflow==0 );
68493 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
68494 data = pPage->aData;
 
68495 hdr = pPage->hdrOffset;
68496 cellOffset = pPage->cellOffset;
68497 nCell = pPage->nCell;
68498 assert( nCell==get2byte(&data[hdr+3]) || CORRUPT_DB );
68499 iCellFirst = cellOffset + 2*nCell;
@@ -68364,43 +68543,42 @@
68543 }
68544
68545 cbrk = usableSize;
68546 iCellLast = usableSize - 4;
68547 iCellStart = get2byte(&data[hdr+5]);
68548 if( nCell>0 ){
68549 temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
68550 memcpy(&temp[iCellStart], &data[iCellStart], usableSize - iCellStart);
68551 src = temp;
68552 for(i=0; i<nCell; i++){
68553 u8 *pAddr; /* The i-th cell pointer */
68554 pAddr = &data[cellOffset + i*2];
68555 pc = get2byte(pAddr);
68556 testcase( pc==iCellFirst );
68557 testcase( pc==iCellLast );
68558 /* These conditions have already been verified in btreeInitPage()
68559 ** if PRAGMA cell_size_check=ON.
68560 */
68561 if( pc<iCellStart || pc>iCellLast ){
68562 return SQLITE_CORRUPT_PAGE(pPage);
68563 }
68564 assert( pc>=iCellStart && pc<=iCellLast );
68565 size = pPage->xCellSize(pPage, &src[pc]);
68566 cbrk -= size;
68567 if( cbrk<iCellStart || pc+size>usableSize ){
68568 return SQLITE_CORRUPT_PAGE(pPage);
68569 }
68570 assert( cbrk+size<=usableSize && cbrk>=iCellStart );
68571 testcase( cbrk+size==usableSize );
68572 testcase( pc+size==usableSize );
68573 put2byte(pAddr, cbrk);
68574 memcpy(&data[cbrk], &src[pc], size);
68575 }
 
68576 }
68577 data[hdr+7] = 0;
68578
68579 defragment_out:
68580 assert( pPage->nFree>=0 );
68581 if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){
68582 return SQLITE_CORRUPT_PAGE(pPage);
68583 }
68584 assert( cbrk>=iCellFirst );
@@ -68469,13 +68647,13 @@
68647 return &aData[pc + x];
68648 }
68649 iAddr = pc;
68650 pTmp = &aData[pc];
68651 pc = get2byte(pTmp);
68652 if( pc<=iAddr ){
68653 if( pc ){
68654 /* The next slot in the chain comes before the current slot */
68655 *pRc = SQLITE_CORRUPT_PAGE(pPg);
68656 }
68657 return 0;
68658 }
68659 }
@@ -68623,11 +68801,11 @@
68801 iPtr = hdr + 1;
68802 if( data[iPtr+1]==0 && data[iPtr]==0 ){
68803 iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */
68804 }else{
68805 while( (iFreeBlk = get2byte(&data[iPtr]))<iStart ){
68806 if( iFreeBlk<=iPtr ){
68807 if( iFreeBlk==0 ) break; /* TH3: corrupt082.100 */
68808 return SQLITE_CORRUPT_PAGE(pPage);
68809 }
68810 iPtr = iFreeBlk;
68811 }
@@ -69105,13 +69283,11 @@
69283 if( pCur ){
69284 pCur->iPage--;
69285 pCur->pPage = pCur->apPage[pCur->iPage];
69286 }
69287 testcase( pgno==0 );
69288 assert( pgno!=0 || rc!=SQLITE_OK );
 
 
69289 return rc;
69290 }
69291
69292 /*
69293 ** Release a MemPage. This should be called once for each prior
@@ -72049,12 +72225,10 @@
72225 ** the new child page does not match the flags field of the parent (i.e.
72226 ** if an intkey page appears to be the parent of a non-intkey page, or
72227 ** vice-versa).
72228 */
72229 static int moveToChild(BtCursor *pCur, u32 newPgno){
 
 
72230 assert( cursorOwnsBtShared(pCur) );
72231 assert( pCur->eState==CURSOR_VALID );
72232 assert( pCur->iPage<BTCURSOR_MAX_DEPTH );
72233 assert( pCur->iPage>=0 );
72234 if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
@@ -72064,11 +72238,12 @@
72238 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
72239 pCur->aiIdx[pCur->iPage] = pCur->ix;
72240 pCur->apPage[pCur->iPage] = pCur->pPage;
72241 pCur->ix = 0;
72242 pCur->iPage++;
72243 return getAndInitPage(pCur->pBt, newPgno, &pCur->pPage, pCur,
72244 pCur->curPagerFlags);
72245 }
72246
72247 #ifdef SQLITE_DEBUG
72248 /*
72249 ** Page pParent is an internal (non-leaf) tree page. This function
@@ -72170,11 +72345,11 @@
72345 assert( pCur->skipNext!=SQLITE_OK );
72346 return pCur->skipNext;
72347 }
72348 sqlite3BtreeClearCursor(pCur);
72349 }
72350 rc = getAndInitPage(pCur->pBt, pCur->pgnoRoot, &pCur->pPage,
72351 0, pCur->curPagerFlags);
72352 if( rc!=SQLITE_OK ){
72353 pCur->eState = CURSOR_INVALID;
72354 return rc;
72355 }
@@ -73811,16 +73986,10 @@
73986 data = pPage->aData;
73987 ptr = &pPage->aCellIdx[2*idx];
73988 assert( pPage->pBt->usableSize > (u32)(ptr-data) );
73989 pc = get2byte(ptr);
73990 hdr = pPage->hdrOffset;
 
 
 
 
 
 
73991 testcase( pc==(u32)get2byte(&data[hdr+5]) );
73992 testcase( pc+sz==pPage->pBt->usableSize );
73993 if( pc+sz > pPage->pBt->usableSize ){
73994 *pRC = SQLITE_CORRUPT_BKPT;
73995 return;
@@ -74700,12 +74869,10 @@
74869 int szNew[NB+2]; /* Combined size of cells placed on i-th page */
74870 u8 *aSpace1; /* Space for copies of dividers cells */
74871 Pgno pgno; /* Temp var to store a page number in */
74872 u8 abDone[NB+2]; /* True after i'th new page is populated */
74873 Pgno aPgno[NB+2]; /* Page numbers of new pages before shuffling */
 
 
74874 CellArray b; /* Parsed information on cells being balanced */
74875
74876 memset(abDone, 0, sizeof(abDone));
74877 memset(&b, 0, sizeof(b));
74878 pBt = pParent->pBt;
@@ -75125,46 +75292,43 @@
75292 ** Reassign page numbers so that the new pages are in ascending order.
75293 ** This helps to keep entries in the disk file in order so that a scan
75294 ** of the table is closer to a linear scan through the file. That in turn
75295 ** helps the operating system to deliver pages from the disk more rapidly.
75296 **
75297 ** An O(N*N) sort algorithm is used, but since N is never more than NB+2
75298 ** (5), that is not a performance concern.
75299 **
75300 ** When NB==3, this one optimization makes the database about 25% faster
75301 ** for large insertions and deletions.
75302 */
75303 for(i=0; i<nNew; i++){
75304 aPgno[i] = apNew[i]->pgno;
75305 assert( apNew[i]->pDbPage->flags & PGHDR_WRITEABLE );
75306 assert( apNew[i]->pDbPage->flags & PGHDR_DIRTY );
75307 }
75308 for(i=0; i<nNew-1; i++){
75309 int iB = i;
75310 for(j=i+1; j<nNew; j++){
75311 if( apNew[j]->pgno < apNew[iB]->pgno ) iB = j;
75312 }
75313
75314 /* If apNew[i] has a page number that is bigger than any of the
75315 ** subsequence apNew[i] entries, then swap apNew[i] with the subsequent
75316 ** entry that has the smallest page number (which we know to be
75317 ** entry apNew[iB]).
75318 */
75319 if( iB!=i ){
75320 Pgno pgnoA = apNew[i]->pgno;
75321 Pgno pgnoB = apNew[iB]->pgno;
75322 Pgno pgnoTemp = (PENDING_BYTE/pBt->pageSize)+1;
75323 u16 fgA = apNew[i]->pDbPage->flags;
75324 u16 fgB = apNew[iB]->pDbPage->flags;
75325 sqlite3PagerRekey(apNew[i]->pDbPage, pgnoTemp, fgB);
75326 sqlite3PagerRekey(apNew[iB]->pDbPage, pgnoA, fgA);
75327 sqlite3PagerRekey(apNew[i]->pDbPage, pgnoB, fgB);
75328 apNew[i]->pgno = pgnoB;
75329 apNew[iB]->pgno = pgnoA;
 
 
 
75330 }
75331 }
75332
75333 TRACE(("BALANCE: new: %d(%d nc=%d) %d(%d nc=%d) %d(%d nc=%d) "
75334 "%d(%d nc=%d) %d(%d nc=%d)\n",
@@ -79428,10 +79592,20 @@
79592 double r2 = (double)i;
79593 return r1==0.0
79594 || (memcmp(&r1, &r2, sizeof(r1))==0
79595 && i >= -2251799813685248LL && i < 2251799813685248LL);
79596 }
79597
79598 /* Convert a floating point value to its closest integer. Do so in
79599 ** a way that avoids 'outside the range of representable values' warnings
79600 ** from UBSAN.
79601 */
79602 SQLITE_PRIVATE i64 sqlite3RealToI64(double r){
79603 if( r<=(double)SMALLEST_INT64 ) return SMALLEST_INT64;
79604 if( r>=(double)LARGEST_INT64) return LARGEST_INT64;
79605 return (i64)r;
79606 }
79607
79608 /*
79609 ** Convert pMem so that it has type MEM_Real or MEM_Int.
79610 ** Invalidate any prior representations.
79611 **
@@ -79450,11 +79624,11 @@
79624 sqlite3_int64 ix;
79625 assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
79626 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
79627 rc = sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc);
79628 if( ((rc==0 || rc==1) && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1)
79629 || sqlite3RealSameAsInt(pMem->u.r, (ix = sqlite3RealToI64(pMem->u.r)))
79630 ){
79631 pMem->u.i = ix;
79632 MemSetTypeFlag(pMem, MEM_Int);
79633 }else{
79634 MemSetTypeFlag(pMem, MEM_Real);
@@ -80682,14 +80856,14 @@
80856 p = sqlite3DbMallocRawNN(db, sizeof(Vdbe) );
80857 if( p==0 ) return 0;
80858 memset(&p->aOp, 0, sizeof(Vdbe)-offsetof(Vdbe,aOp));
80859 p->db = db;
80860 if( db->pVdbe ){
80861 db->pVdbe->ppVPrev = &p->pVNext;
80862 }
80863 p->pVNext = db->pVdbe;
80864 p->ppVPrev = &db->pVdbe;
80865 db->pVdbe = p;
80866 assert( p->eVdbeState==VDBE_INIT_STATE );
80867 p->pParse = pParse;
80868 pParse->pVdbe = p;
80869 assert( pParse->aLabel==0 );
@@ -80767,25 +80941,32 @@
80941 return 0;
80942 }
80943 #endif
80944
80945 /*
80946 ** Swap byte-code between two VDBE structures.
80947 **
80948 ** This happens after pB was previously run and returned
80949 ** SQLITE_SCHEMA. The statement was then reprepared in pA.
80950 ** This routine transfers the new bytecode in pA over to pB
80951 ** so that pB can be run again. The old pB byte code is
80952 ** moved back to pA so that it will be cleaned up when pA is
80953 ** finalized.
80954 */
80955 SQLITE_PRIVATE void sqlite3VdbeSwap(Vdbe *pA, Vdbe *pB){
80956 Vdbe tmp, *pTmp, **ppTmp;
80957 char *zTmp;
80958 assert( pA->db==pB->db );
80959 tmp = *pA;
80960 *pA = *pB;
80961 *pB = tmp;
80962 pTmp = pA->pVNext;
80963 pA->pVNext = pB->pVNext;
80964 pB->pVNext = pTmp;
80965 ppTmp = pA->ppVPrev;
80966 pA->ppVPrev = pB->ppVPrev;
80967 pB->ppVPrev = ppTmp;
80968 zTmp = pA->zSql;
80969 pA->zSql = pB->zSql;
80970 pB->zSql = zTmp;
80971 #ifdef SQLITE_ENABLE_NORMALIZE
80972 zTmp = pA->zNormSql;
@@ -81033,10 +81214,11 @@
81214 pCtx->argc = nArg;
81215 pCtx->iOp = sqlite3VdbeCurrentAddr(v);
81216 addr = sqlite3VdbeAddOp4(v, eCallCtx ? OP_PureFunc : OP_Function,
81217 p1, p2, p3, (char*)pCtx, P4_FUNCCTX);
81218 sqlite3VdbeChangeP5(v, eCallCtx & NC_SelfRef);
81219 sqlite3MayAbort(pParse);
81220 return addr;
81221 }
81222
81223 /*
81224 ** Add an opcode that includes the p4 value with a P4_INT64 or
@@ -81101,11 +81283,11 @@
81283 va_end(ap);
81284 v = pParse->pVdbe;
81285 iThis = v->nOp;
81286 sqlite3VdbeAddOp4(v, OP_Explain, iThis, pParse->addrExplain, 0,
81287 zMsg, P4_DYNAMIC);
81288 sqlite3ExplainBreakpoint(bPush?"PUSH":"", sqlite3VdbeGetLastOp(v)->p4.z);
81289 if( bPush){
81290 pParse->addrExplain = iThis;
81291 }
81292 }
81293 }
@@ -81368,10 +81550,11 @@
81550 int opcode = pOp->opcode;
81551 if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename
81552 || opcode==OP_VDestroy
81553 || opcode==OP_VCreate
81554 || opcode==OP_ParseSchema
81555 || opcode==OP_Function || opcode==OP_PureFunc
81556 || ((opcode==OP_Halt || opcode==OP_HaltIfNull)
81557 && ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
81558 ){
81559 hasAbort = 1;
81560 break;
@@ -81458,12 +81641,12 @@
81641 Parse *pParse = p->pParse;
81642 int *aLabel = pParse->aLabel;
81643 p->readOnly = 1;
81644 p->bIsReader = 0;
81645 pOp = &p->aOp[p->nOp-1];
81646 assert( p->aOp[0].opcode==OP_Init );
81647 while( 1 /* Loop termates when it reaches the OP_Init opcode */ ){
81648 /* Only JUMP opcodes and the short list of special opcodes in the switch
81649 ** below need to be considered. The mkopcodeh.tcl generator script groups
81650 ** all these opcodes together near the front of the opcode list. Skip
81651 ** any opcode that does not need processing by virtual of the fact that
81652 ** it is larger than SQLITE_MX_JUMP_OPCODE, as a performance optimization.
@@ -81488,10 +81671,14 @@
81671 case OP_JournalMode: {
81672 p->readOnly = 0;
81673 p->bIsReader = 1;
81674 break;
81675 }
81676 case OP_Init: {
81677 assert( pOp->p2>=0 );
81678 goto resolve_p2_values_loop_exit;
81679 }
81680 #ifndef SQLITE_OMIT_VIRTUALTABLE
81681 case OP_VUpdate: {
81682 if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
81683 break;
81684 }
@@ -81520,15 +81707,16 @@
81707 /* The mkopcodeh.tcl script has so arranged things that the only
81708 ** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to
81709 ** have non-negative values for P2. */
81710 assert( (sqlite3OpcodeProperty[pOp->opcode]&OPFLG_JUMP)==0 || pOp->p2>=0);
81711 }
81712 assert( pOp>p->aOp );
81713 pOp--;
81714 }
81715 resolve_p2_values_loop_exit:
81716 if( aLabel ){
81717 sqlite3DbNNFreeNN(p->db, pParse->aLabel);
81718 pParse->aLabel = 0;
81719 }
81720 pParse->nLabel = 0;
81721 *pMaxFuncArgs = nMaxArgs;
81722 assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) );
@@ -81773,19 +81961,23 @@
81961 /*
81962 ** Change the value of the opcode, or P1, P2, P3, or P5 operands
81963 ** for a specific instruction.
81964 */
81965 SQLITE_PRIVATE void sqlite3VdbeChangeOpcode(Vdbe *p, int addr, u8 iNewOpcode){
81966 assert( addr>=0 );
81967 sqlite3VdbeGetOp(p,addr)->opcode = iNewOpcode;
81968 }
81969 SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe *p, int addr, int val){
81970 assert( addr>=0 );
81971 sqlite3VdbeGetOp(p,addr)->p1 = val;
81972 }
81973 SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe *p, int addr, int val){
81974 assert( addr>=0 || p->db->mallocFailed );
81975 sqlite3VdbeGetOp(p,addr)->p2 = val;
81976 }
81977 SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe *p, int addr, int val){
81978 assert( addr>=0 );
81979 sqlite3VdbeGetOp(p,addr)->p3 = val;
81980 }
81981 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe *p, u16 p5){
81982 assert( p->nOp>0 || p->db->mallocFailed );
81983 if( p->nOp>0 ) p->aOp[p->nOp-1].p5 = p5;
@@ -81817,11 +82009,11 @@
82009 assert( p->aOp[addr].opcode==OP_Once
82010 || p->aOp[addr].opcode==OP_If
82011 || p->aOp[addr].opcode==OP_FkIfZero );
82012 assert( p->aOp[addr].p4type==0 );
82013 #ifdef SQLITE_VDBE_COVERAGE
82014 sqlite3VdbeGetLastOp(p)->iSrcLine = 0; /* Erase VdbeCoverage() macros */
82015 #endif
82016 p->nOp--;
82017 }else{
82018 sqlite3VdbeChangeP2(p, addr, p->nOp);
82019 }
@@ -81831,25 +82023,27 @@
82023 /*
82024 ** If the input FuncDef structure is ephemeral, then free it. If
82025 ** the FuncDef is not ephermal, then do nothing.
82026 */
82027 static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
82028 assert( db!=0 );
82029 if( (pDef->funcFlags & SQLITE_FUNC_EPHEM)!=0 ){
82030 sqlite3DbNNFreeNN(db, pDef);
82031 }
82032 }
82033
82034 /*
82035 ** Delete a P4 value if necessary.
82036 */
82037 static SQLITE_NOINLINE void freeP4Mem(sqlite3 *db, Mem *p){
82038 if( p->szMalloc ) sqlite3DbFree(db, p->zMalloc);
82039 sqlite3DbNNFreeNN(db, p);
82040 }
82041 static SQLITE_NOINLINE void freeP4FuncCtx(sqlite3 *db, sqlite3_context *p){
82042 assert( db!=0 );
82043 freeEphemeralFunction(db, p->pFunc);
82044 sqlite3DbNNFreeNN(db, p);
82045 }
82046 static void freeP4(sqlite3 *db, int p4type, void *p4){
82047 assert( db );
82048 switch( p4type ){
82049 case P4_FUNCCTX: {
@@ -81858,11 +82052,11 @@
82052 }
82053 case P4_REAL:
82054 case P4_INT64:
82055 case P4_DYNAMIC:
82056 case P4_INTARRAY: {
82057 if( p4 ) sqlite3DbNNFreeNN(db, p4);
82058 break;
82059 }
82060 case P4_KEYINFO: {
82061 if( db->pnBytesFreed==0 ) sqlite3KeyInfoUnref((KeyInfo*)p4);
82062 break;
@@ -81897,10 +82091,11 @@
82091 ** opcodes contained within. If aOp is not NULL it is assumed to contain
82092 ** nOp entries.
82093 */
82094 static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){
82095 assert( nOp>=0 );
82096 assert( db!=0 );
82097 if( aOp ){
82098 Op *pOp = &aOp[nOp-1];
82099 while(1){ /* Exit via break */
82100 if( pOp->p4type <= P4_FREE_IF_LE ) freeP4(db, pOp->p4type, pOp->p4.p);
82101 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
@@ -81907,11 +82102,11 @@
82102 sqlite3DbFree(db, pOp->zComment);
82103 #endif
82104 if( pOp==aOp ) break;
82105 pOp--;
82106 }
82107 sqlite3DbNNFreeNN(db, aOp);
82108 }
82109 }
82110
82111 /*
82112 ** Link the SubProgram object passed as the second argument into the linked
@@ -82138,17 +82333,17 @@
82333 #ifdef SQLITE_VDBE_COVERAGE
82334 /*
82335 ** Set the value if the iSrcLine field for the previously coded instruction.
82336 */
82337 SQLITE_PRIVATE void sqlite3VdbeSetLineNumber(Vdbe *v, int iLine){
82338 sqlite3VdbeGetLastOp(v)->iSrcLine = iLine;
82339 }
82340 #endif /* SQLITE_VDBE_COVERAGE */
82341
82342 /*
82343 ** Return the opcode for a given address. The address must be non-negative.
82344 ** See sqlite3VdbeGetLastOp() to get the most recently added opcode.
82345 **
82346 ** If a memory allocation error has occurred prior to the calling of this
82347 ** routine, then a pointer to a dummy VdbeOp will be returned. That opcode
82348 ** is readable but not writable, though it is cast to a writable value.
82349 ** The return of a dummy opcode allows the call to continue functioning
@@ -82160,20 +82355,23 @@
82355 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){
82356 /* C89 specifies that the constant "dummy" will be initialized to all
82357 ** zeros, which is correct. MSVC generates a warning, nevertheless. */
82358 static VdbeOp dummy; /* Ignore the MSVC warning about no initializer */
82359 assert( p->eVdbeState==VDBE_INIT_STATE );
 
 
 
82360 assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );
82361 if( p->db->mallocFailed ){
82362 return (VdbeOp*)&dummy;
82363 }else{
82364 return &p->aOp[addr];
82365 }
82366 }
82367
82368 /* Return the most recently added opcode
82369 */
82370 VdbeOp * sqlite3VdbeGetLastOp(Vdbe *p){
82371 return sqlite3VdbeGetOp(p, p->nOp - 1);
82372 }
82373
82374 #if defined(SQLITE_ENABLE_EXPLAIN_COMMENTS)
82375 /*
82376 ** Return an integer value for one of the parameters to the opcode pOp
82377 ** determined by character c.
@@ -82658,11 +82856,11 @@
82856 if( p->flags&(MEM_Agg|MEM_Dyn) ){
82857 testcase( (p->flags & MEM_Dyn)!=0 && p->xDel==sqlite3VdbeFrameMemDel );
82858 sqlite3VdbeMemRelease(p);
82859 p->flags = MEM_Undefined;
82860 }else if( p->szMalloc ){
82861 sqlite3DbNNFreeNN(db, p->zMalloc);
82862 p->szMalloc = 0;
82863 p->flags = MEM_Undefined;
82864 }
82865 #ifdef SQLITE_DEBUG
82866 else{
@@ -83650,11 +83848,11 @@
83848 if( sqlite3_stmt_busy((sqlite3_stmt*)p) ){
83849 cnt++;
83850 if( p->readOnly==0 ) nWrite++;
83851 if( p->bIsReader ) nRead++;
83852 }
83853 p = p->pVNext;
83854 }
83855 assert( cnt==db->nVdbeActive );
83856 assert( nWrite==db->nVdbeWrite );
83857 assert( nRead==db->nVdbeRead );
83858 }
@@ -84179,27 +84377,28 @@
84377 ** VdbeDelete() also unlinks the Vdbe from the list of VMs associated with
84378 ** the database connection and frees the object itself.
84379 */
84380 static void sqlite3VdbeClearObject(sqlite3 *db, Vdbe *p){
84381 SubProgram *pSub, *pNext;
84382 assert( db!=0 );
84383 assert( p->db==0 || p->db==db );
84384 if( p->aColName ){
84385 releaseMemArray(p->aColName, p->nResColumn*COLNAME_N);
84386 sqlite3DbNNFreeNN(db, p->aColName);
84387 }
84388 for(pSub=p->pProgram; pSub; pSub=pNext){
84389 pNext = pSub->pNext;
84390 vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
84391 sqlite3DbFree(db, pSub);
84392 }
84393 if( p->eVdbeState!=VDBE_INIT_STATE ){
84394 releaseMemArray(p->aVar, p->nVar);
84395 if( p->pVList ) sqlite3DbNNFreeNN(db, p->pVList);
84396 if( p->pFree ) sqlite3DbNNFreeNN(db, p->pFree);
84397 }
84398 vdbeFreeOpArray(db, p->aOp, p->nOp);
84399 if( p->zSql ) sqlite3DbNNFreeNN(db, p->zSql);
84400 #ifdef SQLITE_ENABLE_NORMALIZE
84401 sqlite3DbFree(db, p->zNormSql);
84402 {
84403 DblquoteStr *pThis, *pNext;
84404 for(pThis=p->pDblStr; pThis; pThis=pNext){
@@ -84225,24 +84424,21 @@
84424 SQLITE_PRIVATE void sqlite3VdbeDelete(Vdbe *p){
84425 sqlite3 *db;
84426
84427 assert( p!=0 );
84428 db = p->db;
84429 assert( db!=0 );
84430 assert( sqlite3_mutex_held(db->mutex) );
84431 sqlite3VdbeClearObject(db, p);
84432 if( db->pnBytesFreed==0 ){
84433 assert( p->ppVPrev!=0 );
84434 *p->ppVPrev = p->pVNext;
84435 if( p->pVNext ){
84436 p->pVNext->ppVPrev = p->ppVPrev;
 
 
 
 
84437 }
84438 }
84439 sqlite3DbNNFreeNN(db, p);
84440 }
84441
84442 /*
84443 ** The cursor "p" has a pending seek operation that has not yet been
84444 ** carried out. Seek the cursor now. If an error occurs, return
@@ -85733,11 +85929,11 @@
85929 ** prepared statements. The flag is set to 1 for an immediate expiration
85930 ** and set to 2 for an advisory expiration.
85931 */
85932 SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3 *db, int iCode){
85933 Vdbe *p;
85934 for(p = db->pVdbe; p; p=p->pVNext){
85935 p->expired = iCode+1;
85936 }
85937 }
85938
85939 /*
@@ -85854,17 +86050,18 @@
86050 **
86051 ** This function is used to free UnpackedRecord structures allocated by
86052 ** the vdbeUnpackRecord() function found in vdbeapi.c.
86053 */
86054 static void vdbeFreeUnpacked(sqlite3 *db, int nField, UnpackedRecord *p){
86055 assert( db!=0 );
86056 if( p ){
86057 int i;
86058 for(i=0; i<nField; i++){
86059 Mem *pMem = &p->aMem[i];
86060 if( pMem->zMalloc ) sqlite3VdbeMemReleaseMalloc(pMem);
86061 }
86062 sqlite3DbNNFreeNN(db, p);
86063 }
86064 }
86065 #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
86066
86067 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
@@ -85931,11 +86128,11 @@
86128 if( preupdate.aNew ){
86129 int i;
86130 for(i=0; i<pCsr->nField; i++){
86131 sqlite3VdbeMemRelease(&preupdate.aNew[i]);
86132 }
86133 sqlite3DbNNFreeNN(db, preupdate.aNew);
86134 }
86135 }
86136 #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
86137
86138 /************** End of vdbeaux.c *********************************************/
@@ -86048,11 +86245,13 @@
86245 Vdbe *v = (Vdbe*)pStmt;
86246 sqlite3 *db = v->db;
86247 if( vdbeSafety(v) ) return SQLITE_MISUSE_BKPT;
86248 sqlite3_mutex_enter(db->mutex);
86249 checkProfileCallback(db, v);
86250 assert( v->eVdbeState>=VDBE_READY_STATE );
86251 rc = sqlite3VdbeReset(v);
86252 sqlite3VdbeDelete(v);
86253 rc = sqlite3ApiExit(db, rc);
86254 sqlite3LeaveMutexAndCloseZombie(db);
86255 }
86256 return rc;
86257 }
@@ -87370,11 +87569,11 @@
87569 ** the mutex is released if any kind of error occurs.
87570 **
87571 ** The error code stored in database p->db is overwritten with the return
87572 ** value in any case.
87573 */
87574 static int vdbeUnbind(Vdbe *p, unsigned int i){
87575 Mem *pVar;
87576 if( vdbeSafetyNotNull(p) ){
87577 return SQLITE_MISUSE_BKPT;
87578 }
87579 sqlite3_mutex_enter(p->db->mutex);
@@ -87383,16 +87582,15 @@
87582 sqlite3_mutex_leave(p->db->mutex);
87583 sqlite3_log(SQLITE_MISUSE,
87584 "bind on a busy prepared statement: [%s]", p->zSql);
87585 return SQLITE_MISUSE_BKPT;
87586 }
87587 if( i>=(unsigned int)p->nVar ){
87588 sqlite3Error(p->db, SQLITE_RANGE);
87589 sqlite3_mutex_leave(p->db->mutex);
87590 return SQLITE_RANGE;
87591 }
 
87592 pVar = &p->aVar[i];
87593 sqlite3VdbeMemRelease(pVar);
87594 pVar->flags = MEM_Null;
87595 p->db->errCode = SQLITE_OK;
87596
@@ -87425,11 +87623,11 @@
87623 ){
87624 Vdbe *p = (Vdbe *)pStmt;
87625 Mem *pVar;
87626 int rc;
87627
87628 rc = vdbeUnbind(p, (u32)(i-1));
87629 if( rc==SQLITE_OK ){
87630 if( zData!=0 ){
87631 pVar = &p->aVar[i-1];
87632 rc = sqlite3VdbeMemSetStr(pVar, zData, nData, encoding, xDel);
87633 if( rc==SQLITE_OK && encoding!=0 ){
@@ -87474,11 +87672,11 @@
87672 return bindText(pStmt, i, zData, nData, xDel, 0);
87673 }
87674 SQLITE_API int sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){
87675 int rc;
87676 Vdbe *p = (Vdbe *)pStmt;
87677 rc = vdbeUnbind(p, (u32)(i-1));
87678 if( rc==SQLITE_OK ){
87679 sqlite3VdbeMemSetDouble(&p->aVar[i-1], rValue);
87680 sqlite3_mutex_leave(p->db->mutex);
87681 }
87682 return rc;
@@ -87487,21 +87685,21 @@
87685 return sqlite3_bind_int64(p, i, (i64)iValue);
87686 }
87687 SQLITE_API int sqlite3_bind_int64(sqlite3_stmt *pStmt, int i, sqlite_int64 iValue){
87688 int rc;
87689 Vdbe *p = (Vdbe *)pStmt;
87690 rc = vdbeUnbind(p, (u32)(i-1));
87691 if( rc==SQLITE_OK ){
87692 sqlite3VdbeMemSetInt64(&p->aVar[i-1], iValue);
87693 sqlite3_mutex_leave(p->db->mutex);
87694 }
87695 return rc;
87696 }
87697 SQLITE_API int sqlite3_bind_null(sqlite3_stmt *pStmt, int i){
87698 int rc;
87699 Vdbe *p = (Vdbe*)pStmt;
87700 rc = vdbeUnbind(p, (u32)(i-1));
87701 if( rc==SQLITE_OK ){
87702 sqlite3_mutex_leave(p->db->mutex);
87703 }
87704 return rc;
87705 }
@@ -87512,11 +87710,11 @@
87710 const char *zPTtype,
87711 void (*xDestructor)(void*)
87712 ){
87713 int rc;
87714 Vdbe *p = (Vdbe*)pStmt;
87715 rc = vdbeUnbind(p, (u32)(i-1));
87716 if( rc==SQLITE_OK ){
87717 sqlite3VdbeMemSetPointer(&p->aVar[i-1], pPtr, zPTtype, xDestructor);
87718 sqlite3_mutex_leave(p->db->mutex);
87719 }else if( xDestructor ){
87720 xDestructor(pPtr);
@@ -87590,11 +87788,11 @@
87788 return rc;
87789 }
87790 SQLITE_API int sqlite3_bind_zeroblob(sqlite3_stmt *pStmt, int i, int n){
87791 int rc;
87792 Vdbe *p = (Vdbe *)pStmt;
87793 rc = vdbeUnbind(p, (u32)(i-1));
87794 if( rc==SQLITE_OK ){
87795 #ifndef SQLITE_OMIT_INCRBLOB
87796 sqlite3VdbeMemSetZeroBlob(&p->aVar[i-1], n);
87797 #else
87798 rc = sqlite3VdbeMemSetZeroBlob(&p->aVar[i-1], n);
@@ -87750,11 +87948,11 @@
87948 #endif
87949 sqlite3_mutex_enter(pDb->mutex);
87950 if( pStmt==0 ){
87951 pNext = (sqlite3_stmt*)pDb->pVdbe;
87952 }else{
87953 pNext = (sqlite3_stmt*)((Vdbe*)pStmt)->pVNext;
87954 }
87955 sqlite3_mutex_leave(pDb->mutex);
87956 return pNext;
87957 }
87958
@@ -87775,12 +87973,15 @@
87973 if( op==SQLITE_STMTSTATUS_MEMUSED ){
87974 sqlite3 *db = pVdbe->db;
87975 sqlite3_mutex_enter(db->mutex);
87976 v = 0;
87977 db->pnBytesFreed = (int*)&v;
87978 assert( db->lookaside.pEnd==db->lookaside.pTrueEnd );
87979 db->lookaside.pEnd = db->lookaside.pStart;
87980 sqlite3VdbeDelete(pVdbe);
87981 db->pnBytesFreed = 0;
87982 db->lookaside.pEnd = db->lookaside.pTrueEnd;
87983 sqlite3_mutex_leave(db->mutex);
87984 }else{
87985 v = pVdbe->aCounter[op];
87986 if( resetFlag ) pVdbe->aCounter[op] = 0;
87987 }
@@ -88616,11 +88817,12 @@
88817 ** floating point value of rValue. Return true and set *piValue to the
88818 ** integer value if the string is in range to be an integer. Otherwise,
88819 ** return false.
88820 */
88821 static int alsoAnInt(Mem *pRec, double rValue, i64 *piValue){
88822 i64 iValue;
88823 iValue = sqlite3RealToI64(rValue);
88824 if( sqlite3RealSameAsInt(rValue,iValue) ){
88825 *piValue = iValue;
88826 return 1;
88827 }
88828 return 0==sqlite3Atoi64(pRec->z, piValue, pRec->n, pRec->enc);
@@ -88778,21 +88980,22 @@
88980 **
88981 ** Unlike applyNumericAffinity(), this routine does not modify pMem->flags.
88982 ** But it does set pMem->u.r and pMem->u.i appropriately.
88983 */
88984 static u16 numericType(Mem *pMem){
88985 assert( (pMem->flags & MEM_Null)==0
88986 || pMem->db==0 || pMem->db->mallocFailed );
88987 if( pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Null) ){
88988 testcase( pMem->flags & MEM_Int );
88989 testcase( pMem->flags & MEM_Real );
88990 testcase( pMem->flags & MEM_IntReal );
88991 return pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Null);
88992 }
88993 assert( pMem->flags & (MEM_Str|MEM_Blob) );
88994 testcase( pMem->flags & MEM_Str );
88995 testcase( pMem->flags & MEM_Blob );
88996 return computeNumericType(pMem);
 
88997 return 0;
88998 }
88999
89000 #ifdef SQLITE_DEBUG
89001 /*
@@ -90033,25 +90236,24 @@
90236 case OP_Add: /* same as TK_PLUS, in1, in2, out3 */
90237 case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */
90238 case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */
90239 case OP_Divide: /* same as TK_SLASH, in1, in2, out3 */
90240 case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */
 
90241 u16 type1; /* Numeric type of left operand */
90242 u16 type2; /* Numeric type of right operand */
90243 i64 iA; /* Integer value of left operand */
90244 i64 iB; /* Integer value of right operand */
90245 double rA; /* Real value of left operand */
90246 double rB; /* Real value of right operand */
90247
90248 pIn1 = &aMem[pOp->p1];
90249 type1 = pIn1->flags;
90250 pIn2 = &aMem[pOp->p2];
90251 type2 = pIn2->flags;
90252 pOut = &aMem[pOp->p3];
 
90253 if( (type1 & type2 & MEM_Int)!=0 ){
90254 int_math:
90255 iA = pIn1->u.i;
90256 iB = pIn2->u.i;
90257 switch( pOp->opcode ){
90258 case OP_Add: if( sqlite3AddInt64(&iB,iA) ) goto fp_math; break;
90259 case OP_Subtract: if( sqlite3SubInt64(&iB,iA) ) goto fp_math; break;
@@ -90069,13 +90271,16 @@
90271 break;
90272 }
90273 }
90274 pOut->u.i = iB;
90275 MemSetTypeFlag(pOut, MEM_Int);
90276 }else if( ((type1 | type2) & MEM_Null)!=0 ){
90277 goto arithmetic_result_is_null;
90278 }else{
90279 type1 = numericType(pIn1);
90280 type2 = numericType(pIn2);
90281 if( (type1 & type2 & MEM_Int)!=0 ) goto int_math;
90282 fp_math:
90283 rA = sqlite3VdbeRealValue(pIn1);
90284 rB = sqlite3VdbeRealValue(pIn2);
90285 switch( pOp->opcode ){
90286 case OP_Add: rB += rA; break;
@@ -90941,15 +91146,18 @@
91146 **
91147 ** Check the cursor P1 to see if it is currently pointing at a NULL row.
91148 ** If it is, then set register P3 to NULL and jump immediately to P2.
91149 ** If P1 is not on a NULL row, then fall through without making any
91150 ** changes.
91151 **
91152 ** If P1 is not an open cursor, then this opcode is a no-op.
91153 */
91154 case OP_IfNullRow: { /* jump */
91155 VdbeCursor *pC;
91156 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
91157 pC = p->apCsr[pOp->p1];
91158 if( ALWAYS(pC) && pC->nullRow ){
91159 sqlite3VdbeMemSetNull(aMem + pOp->p3);
91160 goto jump_to_p2;
91161 }
91162 break;
91163 }
@@ -93052,11 +93260,11 @@
93260 **
93261 ** <li> If the cursor is successfully moved to the target row by 0 or more
93262 ** sqlite3BtreeNext() calls, then jump to This.P2, which will land just
93263 ** past the OP_IdxGT or OP_IdxGE opcode that follows the OP_SeekGE.
93264 **
93265 ** <li> If the cursor ends up past the target row (indicating that the target
93266 ** row does not exist in the btree) then jump to SeekOP.P2.
93267 ** </ol>
93268 */
93269 case OP_SeekScan: {
93270 VdbeCursor *pC;
@@ -94388,11 +94596,13 @@
94596 rc = sqlite3VdbeSorterNext(db, pC);
94597 goto next_tail;
94598
94599 case OP_Prev: /* jump */
94600 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
94601 assert( pOp->p5==0
94602 || pOp->p5==SQLITE_STMTSTATUS_FULLSCAN_STEP
94603 || pOp->p5==SQLITE_STMTSTATUS_AUTOINDEX);
94604 pC = p->apCsr[pOp->p1];
94605 assert( pC!=0 );
94606 assert( pC->deferredMoveto==0 );
94607 assert( pC->eCurType==CURTYPE_BTREE );
94608 assert( pC->seekOp==OP_SeekLT || pC->seekOp==OP_SeekLE
@@ -94401,11 +94611,13 @@
94611 rc = sqlite3BtreePrevious(pC->uc.pCursor, pOp->p3);
94612 goto next_tail;
94613
94614 case OP_Next: /* jump */
94615 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
94616 assert( pOp->p5==0
94617 || pOp->p5==SQLITE_STMTSTATUS_FULLSCAN_STEP
94618 || pOp->p5==SQLITE_STMTSTATUS_AUTOINDEX);
94619 pC = p->apCsr[pOp->p1];
94620 assert( pC!=0 );
94621 assert( pC->deferredMoveto==0 );
94622 assert( pC->eCurType==CURTYPE_BTREE );
94623 assert( pC->seekOp==OP_SeekGT || pC->seekOp==OP_SeekGE
@@ -94608,14 +94820,14 @@
94820
94821 /* The IdxRowid and Seek opcodes are combined because of the commonality
94822 ** of sqlite3VdbeCursorRestore() and sqlite3VdbeIdxRowid(). */
94823 rc = sqlite3VdbeCursorRestore(pC);
94824
94825 /* sqlite3VdbeCursorRestore() may fail if the cursor has been disturbed
94826 ** since it was last positioned and an error (e.g. OOM or an IO error)
94827 ** occurs while trying to reposition it. */
94828 if( rc!=SQLITE_OK ) goto abort_due_to_error;
94829
94830 if( !pC->nullRow ){
94831 rowid = 0; /* Not needed. Only used to silence a warning. */
94832 rc = sqlite3VdbeIdxRowid(db, pC->uc.pCursor, &rowid);
94833 if( rc!=SQLITE_OK ){
@@ -95513,11 +95725,11 @@
95725
95726 /* Opcode: OffsetLimit P1 P2 P3 * *
95727 ** Synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)
95728 **
95729 ** This opcode performs a commonly used computation associated with
95730 ** LIMIT and OFFSET processing. r[P1] holds the limit counter. r[P3]
95731 ** holds the offset counter. The opcode computes the combined value
95732 ** of the LIMIT and OFFSET and stores that value in r[P2]. The r[P2]
95733 ** value computed is the total number of rows that will need to be
95734 ** visited in order to complete the query.
95735 **
@@ -101110,10 +101322,12 @@
101322 sqlite3_file *pJfd, /* Preallocated, blank file handle */
101323 int flags, /* Opening flags */
101324 int nSpill /* Bytes buffered before opening the file */
101325 ){
101326 MemJournal *p = (MemJournal*)pJfd;
101327
101328 assert( zName || nSpill<0 || (flags & SQLITE_OPEN_EXCLUSIVE) );
101329
101330 /* Zero the file-handle object. If nSpill was passed zero, initialize
101331 ** it using the sqlite3OsOpen() function of the underlying VFS. In this
101332 ** case none of the code in this module is executed as a result of calls
101333 ** made on the journal file-handle. */
@@ -101552,13 +101766,11 @@
101766 if( ExprHasProperty(pExpr, EP_WinFunc) ){
101767 if( ALWAYS(pExpr->y.pWin!=0) ){
101768 pExpr->y.pWin->pOwner = pExpr;
101769 }
101770 }
101771 sqlite3ExprDeferredDelete(pParse, pDup);
 
 
101772 }
101773 }
101774
101775 /*
101776 ** Subqueries stores the original database, table and column names for their
@@ -104363,11 +104575,13 @@
104575 ** Also propagate EP_Propagate flags up from Expr.x.pList to Expr.flags,
104576 ** if appropriate.
104577 */
104578 static void exprSetHeight(Expr *p){
104579 int nHeight = p->pLeft ? p->pLeft->nHeight : 0;
104580 if( NEVER(p->pRight) && p->pRight->nHeight>nHeight ){
104581 nHeight = p->pRight->nHeight;
104582 }
104583 if( ExprUseXSelect(p) ){
104584 heightOfSelect(p->x.pSelect, &nHeight);
104585 }else if( p->x.pList ){
104586 heightOfExprList(p->x.pList, &nHeight);
104587 p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList);
@@ -104506,19 +104720,30 @@
104720 if( pRoot==0 ){
104721 assert( db->mallocFailed );
104722 sqlite3ExprDelete(db, pLeft);
104723 sqlite3ExprDelete(db, pRight);
104724 }else{
104725 assert( ExprUseXList(pRoot) );
104726 assert( pRoot->x.pSelect==0 );
104727 if( pRight ){
104728 pRoot->pRight = pRight;
104729 pRoot->flags |= EP_Propagate & pRight->flags;
104730 #if SQLITE_MAX_EXPR_DEPTH>0
104731 pRoot->nHeight = pRight->nHeight+1;
104732 }else{
104733 pRoot->nHeight = 1;
104734 #endif
104735 }
104736 if( pLeft ){
104737 pRoot->pLeft = pLeft;
104738 pRoot->flags |= EP_Propagate & pLeft->flags;
104739 #if SQLITE_MAX_EXPR_DEPTH>0
104740 if( pLeft->nHeight>=pRoot->nHeight ){
104741 pRoot->nHeight = pLeft->nHeight+1;
104742 }
104743 #endif
104744 }
 
104745 }
104746 }
104747
104748 /*
104749 ** Allocate an Expr node which joins as many as two subtrees.
@@ -104800,10 +105025,11 @@
105025 /*
105026 ** Recursively delete an expression tree.
105027 */
105028 static SQLITE_NOINLINE void sqlite3ExprDeleteNN(sqlite3 *db, Expr *p){
105029 assert( p!=0 );
105030 assert( db!=0 );
105031 assert( !ExprUseUValue(p) || p->u.iValue>=0 );
105032 assert( !ExprUseYWin(p) || !ExprUseYSub(p) );
105033 assert( !ExprUseYWin(p) || p->y.pWin!=0 || db->mallocFailed );
105034 assert( p->op!=TK_FUNCTION || !ExprUseYSub(p) );
105035 #ifdef SQLITE_DEBUG
@@ -104831,16 +105057,12 @@
105057 sqlite3WindowDelete(db, p->y.pWin);
105058 }
105059 #endif
105060 }
105061 }
 
 
 
 
105062 if( !ExprHasProperty(p, EP_Static) ){
105063 sqlite3DbNNFreeNN(db, p);
105064 }
105065 }
105066 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
105067 if( p ) sqlite3ExprDeleteNN(db, p);
105068 }
@@ -104867,12 +105089,13 @@
105089 **
105090 ** The deferred delete is (currently) implemented by adding the
105091 ** pExpr to the pParse->pConstExpr list with a register number of 0.
105092 */
105093 SQLITE_PRIVATE void sqlite3ExprDeferredDelete(Parse *pParse, Expr *pExpr){
105094 sqlite3ParserAddCleanup(pParse,
105095 (void(*)(sqlite3*,void*))sqlite3ExprDelete,
105096 pExpr);
105097 }
105098
105099 /* Invoke sqlite3RenameExprUnmap() and sqlite3ExprDelete() on the
105100 ** expression.
105101 */
@@ -104942,11 +105165,10 @@
105165 ){
105166 nSize = EXPR_FULLSIZE;
105167 }else{
105168 assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
105169 assert( !ExprHasProperty(p, EP_OuterON) );
 
105170 assert( !ExprHasVVAProperty(p, EP_NoReduce) );
105171 if( p->pLeft || p->x.pList ){
105172 nSize = EXPR_REDUCEDSIZE | EP_Reduced;
105173 }else{
105174 assert( p->pRight==0 );
@@ -105046,11 +105268,11 @@
105268 memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
105269 }
105270 }
105271
105272 /* Set the EP_Reduced, EP_TokenOnly, and EP_Static flags appropriately. */
105273 pNew->flags &= ~(EP_Reduced|EP_TokenOnly|EP_Static);
105274 pNew->flags |= nStructSize & (EP_Reduced|EP_TokenOnly);
105275 pNew->flags |= staticFlag;
105276 ExprClearVVAProperties(pNew);
105277 if( dupFlags ){
105278 ExprSetVVAProperty(pNew, EP_Immutable);
@@ -105622,16 +105844,17 @@
105844 */
105845 static SQLITE_NOINLINE void exprListDeleteNN(sqlite3 *db, ExprList *pList){
105846 int i = pList->nExpr;
105847 struct ExprList_item *pItem = pList->a;
105848 assert( pList->nExpr>0 );
105849 assert( db!=0 );
105850 do{
105851 sqlite3ExprDelete(db, pItem->pExpr);
105852 if( pItem->zEName ) sqlite3DbNNFreeNN(db, pItem->zEName);
105853 pItem++;
105854 }while( --i>0 );
105855 sqlite3DbNNFreeNN(db, pList);
105856 }
105857 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
105858 if( pList ) exprListDeleteNN(db, pList);
105859 }
105860
@@ -106918,11 +107141,11 @@
107141 if( pLimit ){
107142 pLimit->affExpr = SQLITE_AFF_NUMERIC;
107143 pLimit = sqlite3PExpr(pParse, TK_NE,
107144 sqlite3ExprDup(db, pSel->pLimit->pLeft, 0), pLimit);
107145 }
107146 sqlite3ExprDeferredDelete(pParse, pSel->pLimit->pLeft);
107147 pSel->pLimit->pLeft = pLimit;
107148 }else{
107149 /* If there is no pre-existing limit add a limit of 1 */
107150 pLimit = sqlite3Expr(pParse->db, TK_INTEGER, "1");
107151 pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
@@ -107432,11 +107655,11 @@
107655 u8 p5 /* P5 value for OP_Column + FLAGS */
107656 ){
107657 assert( pParse->pVdbe!=0 );
107658 sqlite3ExprCodeGetColumnOfTable(pParse->pVdbe, pTab, iTable, iColumn, iReg);
107659 if( p5 ){
107660 VdbeOp *pOp = sqlite3VdbeGetLastOp(pParse->pVdbe);
107661 if( pOp->opcode==OP_Column ) pOp->p5 = p5;
107662 }
107663 return iReg;
107664 }
107665
@@ -107501,11 +107724,11 @@
107724 /*
107725 ** If the last opcode is a OP_Copy, then set the do-not-merge flag (p5)
107726 ** so that a subsequent copy will not be merged into this one.
107727 */
107728 static void setDoNotMergeFlagOnCopy(Vdbe *v){
107729 if( sqlite3VdbeGetLastOp(v)->opcode==OP_Copy ){
107730 sqlite3VdbeChangeP5(v, 1); /* Tag trailing OP_Copy as not mergable */
107731 }
107732 }
107733
107734 /*
@@ -107672,11 +107895,11 @@
107895 Table *pTab = pCol->pTab;
107896 sqlite3VdbeAddOp3(v, OP_Column, pAggInfo->sortingIdxPTab,
107897 pCol->iSorterColumn, target);
107898 if( pCol->iColumn<0 ){
107899 VdbeComment((v,"%s.rowid",pTab->zName));
107900 }else if( ALWAYS(pTab!=0) ){
107901 VdbeComment((v,"%s.%s",
107902 pTab->zName, pTab->aCol[pCol->iColumn].zCnName));
107903 if( pTab->aCol[pCol->iColumn].affinity==SQLITE_AFF_REAL ){
107904 sqlite3VdbeAddOp1(v, OP_RealAffinity, target);
107905 }
@@ -108267,10 +108490,25 @@
108490 ** on a LEFT JOIN NULL row.
108491 */
108492 case TK_IF_NULL_ROW: {
108493 int addrINR;
108494 u8 okConstFactor = pParse->okConstFactor;
108495 AggInfo *pAggInfo = pExpr->pAggInfo;
108496 if( pAggInfo ){
108497 assert( pExpr->iAgg>=0 && pExpr->iAgg<pAggInfo->nColumn );
108498 if( !pAggInfo->directMode ){
108499 inReg = pAggInfo->aCol[pExpr->iAgg].iMem;
108500 break;
108501 }
108502 if( pExpr->pAggInfo->useSortingIdx ){
108503 sqlite3VdbeAddOp3(v, OP_Column, pAggInfo->sortingIdxPTab,
108504 pAggInfo->aCol[pExpr->iAgg].iSorterColumn,
108505 target);
108506 inReg = target;
108507 break;
108508 }
108509 }
108510 addrINR = sqlite3VdbeAddOp1(v, OP_IfNullRow, pExpr->iTable);
108511 /* Temporarily disable factoring of constant expressions, since
108512 ** even though expressions may appear to be constant, they are not
108513 ** really constant because they originate from the right-hand side
108514 ** of a LEFT JOIN. */
@@ -108608,11 +108846,11 @@
108846 }else{
108847 int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
108848 if( inReg!=target+i ){
108849 VdbeOp *pOp;
108850 if( copyOp==OP_Copy
108851 && (pOp=sqlite3VdbeGetLastOp(v))->opcode==OP_Copy
108852 && pOp->p1+pOp->p3+1==inReg
108853 && pOp->p2+pOp->p3+1==target+i
108854 && pOp->p5==0 /* The do-not-merge flag must be clear */
108855 ){
108856 pOp->p3++;
@@ -109644,10 +109882,11 @@
109882 ** fact is exploited for efficiency.
109883 */
109884 SQLITE_PRIVATE int sqlite3ReferencesSrcList(Parse *pParse, Expr *pExpr, SrcList *pSrcList){
109885 Walker w;
109886 struct RefSrcList x;
109887 assert( pParse->db!=0 );
109888 memset(&w, 0, sizeof(w));
109889 memset(&x, 0, sizeof(x));
109890 w.xExprCallback = exprRefToSrcList;
109891 w.xSelectCallback = selectRefEnter;
109892 w.xSelectCallback2 = selectRefLeave;
@@ -109660,11 +109899,11 @@
109899 #ifndef SQLITE_OMIT_WINDOWFUNC
109900 if( ExprHasProperty(pExpr, EP_WinFunc) ){
109901 sqlite3WalkExpr(&w, pExpr->y.pWin->pFilter);
109902 }
109903 #endif
109904 if( x.aiExclude ) sqlite3DbNNFreeNN(pParse->db, x.aiExclude);
109905 if( w.eCode & 0x01 ){
109906 return 1;
109907 }else if( w.eCode ){
109908 return 0;
109909 }else{
@@ -109691,21 +109930,22 @@
109930 ){
109931 AggInfo *pAggInfo = pExpr->pAggInfo;
109932 int iAgg = pExpr->iAgg;
109933 Parse *pParse = pWalker->pParse;
109934 sqlite3 *db = pParse->db;
109935 if( pExpr->op!=TK_AGG_FUNCTION ){
109936 assert( pExpr->op==TK_AGG_COLUMN || pExpr->op==TK_IF_NULL_ROW );
109937 assert( iAgg>=0 && iAgg<pAggInfo->nColumn );
109938 if( pAggInfo->aCol[iAgg].pCExpr==pExpr ){
109939 pExpr = sqlite3ExprDup(db, pExpr, 0);
109940 if( pExpr ){
109941 pAggInfo->aCol[iAgg].pCExpr = pExpr;
109942 sqlite3ExprDeferredDelete(pParse, pExpr);
109943 }
109944 }
109945 }else{
109946 assert( pExpr->op==TK_AGG_FUNCTION );
109947 assert( iAgg>=0 && iAgg<pAggInfo->nFunc );
109948 if( pAggInfo->aFunc[iAgg].pFExpr==pExpr ){
109949 pExpr = sqlite3ExprDup(db, pExpr, 0);
109950 if( pExpr ){
109951 pAggInfo->aFunc[iAgg].pFExpr = pExpr;
@@ -109772,14 +110012,16 @@
110012 SrcList *pSrcList = pNC->pSrcList;
110013 AggInfo *pAggInfo = pNC->uNC.pAggInfo;
110014
110015 assert( pNC->ncFlags & NC_UAggInfo );
110016 switch( pExpr->op ){
110017 case TK_IF_NULL_ROW:
110018 case TK_AGG_COLUMN:
110019 case TK_COLUMN: {
110020 testcase( pExpr->op==TK_AGG_COLUMN );
110021 testcase( pExpr->op==TK_COLUMN );
110022 testcase( pExpr->op==TK_IF_NULL_ROW );
110023 /* Check to see if the column is in one of the tables in the FROM
110024 ** clause of the aggregate query */
110025 if( ALWAYS(pSrcList!=0) ){
110026 SrcItem *pItem = pSrcList->a;
110027 for(i=0; i<pSrcList->nSrc; i++, pItem++){
@@ -109793,12 +110035,14 @@
110035 ** is not an entry there already.
110036 */
110037 int k;
110038 pCol = pAggInfo->aCol;
110039 for(k=0; k<pAggInfo->nColumn; k++, pCol++){
110040 if( pCol->iTable==pExpr->iTable
110041 && pCol->iColumn==pExpr->iColumn
110042 && pExpr->op!=TK_IF_NULL_ROW
110043 ){
110044 break;
110045 }
110046 }
110047 if( (k>=pAggInfo->nColumn)
110048 && (k = addAggInfoColumn(pParse->db, pAggInfo))>=0
@@ -109809,19 +110053,21 @@
110053 pCol->iTable = pExpr->iTable;
110054 pCol->iColumn = pExpr->iColumn;
110055 pCol->iMem = ++pParse->nMem;
110056 pCol->iSorterColumn = -1;
110057 pCol->pCExpr = pExpr;
110058 if( pAggInfo->pGroupBy && pExpr->op!=TK_IF_NULL_ROW ){
110059 int j, n;
110060 ExprList *pGB = pAggInfo->pGroupBy;
110061 struct ExprList_item *pTerm = pGB->a;
110062 n = pGB->nExpr;
110063 for(j=0; j<n; j++, pTerm++){
110064 Expr *pE = pTerm->pExpr;
110065 if( pE->op==TK_COLUMN
110066 && pE->iTable==pExpr->iTable
110067 && pE->iColumn==pExpr->iColumn
110068 ){
110069 pCol->iSorterColumn = j;
110070 break;
110071 }
110072 }
110073 }
@@ -109834,11 +110080,13 @@
110080 ** Convert the pExpr to be a TK_AGG_COLUMN referring to that
110081 ** pAggInfo->aCol[] entry.
110082 */
110083 ExprSetVVAProperty(pExpr, EP_NoReduce);
110084 pExpr->pAggInfo = pAggInfo;
110085 if( pExpr->op==TK_COLUMN ){
110086 pExpr->op = TK_AGG_COLUMN;
110087 }
110088 pExpr->iAgg = (i16)k;
110089 break;
110090 } /* endif pExpr->iTable==pItem->iCursor */
110091 } /* end loop over pSrcList */
110092 }
@@ -115256,10 +115504,11 @@
115504 ** no VDBE code was generated.
115505 */
115506 SQLITE_PRIVATE void sqlite3FinishCoding(Parse *pParse){
115507 sqlite3 *db;
115508 Vdbe *v;
115509 int iDb, i;
115510
115511 assert( pParse->pToplevel==0 );
115512 db = pParse->db;
115513 assert( db->pParse==pParse );
115514 if( pParse->nested ) return;
@@ -115285,11 +115534,10 @@
115534 || sqlite3VdbeAssertMayAbort(v, pParse->mayAbort));
115535 if( v ){
115536 if( pParse->bReturning ){
115537 Returning *pReturning = pParse->u1.pReturning;
115538 int addrRewind;
 
115539 int reg;
115540
115541 if( pReturning->nRetCol ){
115542 sqlite3VdbeAddOp0(v, OP_FkCheck);
115543 addrRewind =
@@ -115322,80 +115570,73 @@
115570 ** (Bit 0 is for main, bit 1 is for temp, and so forth.) Bits are
115571 ** set for each database that is used. Generate code to start a
115572 ** transaction on each used database and to verify the schema cookie
115573 ** on each used database.
115574 */
115575 assert( pParse->nErr>0 || sqlite3VdbeGetOp(v, 0)->opcode==OP_Init );
115576 sqlite3VdbeJumpHere(v, 0);
115577 assert( db->nDb>0 );
115578 iDb = 0;
115579 do{
115580 Schema *pSchema;
115581 if( DbMaskTest(pParse->cookieMask, iDb)==0 ) continue;
115582 sqlite3VdbeUsesBtree(v, iDb);
115583 pSchema = db->aDb[iDb].pSchema;
115584 sqlite3VdbeAddOp4Int(v,
115585 OP_Transaction, /* Opcode */
115586 iDb, /* P1 */
115587 DbMaskTest(pParse->writeMask,iDb), /* P2 */
115588 pSchema->schema_cookie, /* P3 */
115589 pSchema->iGeneration /* P4 */
115590 );
115591 if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1);
115592 VdbeComment((v,
115593 "usesStmtJournal=%d", pParse->mayAbort && pParse->isMultiWrite));
115594 }while( ++iDb<db->nDb );
 
 
 
 
115595 #ifndef SQLITE_OMIT_VIRTUALTABLE
115596 for(i=0; i<pParse->nVtabLock; i++){
115597 char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
115598 sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
115599 }
115600 pParse->nVtabLock = 0;
115601 #endif
115602
115603 /* Once all the cookies have been verified and transactions opened,
115604 ** obtain the required table-locks. This is a no-op unless the
115605 ** shared-cache feature is enabled.
115606 */
115607 codeTableLocks(pParse);
115608
115609 /* Initialize any AUTOINCREMENT data structures required.
115610 */
115611 sqlite3AutoincrementBegin(pParse);
115612
115613 /* Code constant expressions that where factored out of inner loops.
115614 **
115615 ** The pConstExpr list might also contain expressions that we simply
115616 ** want to keep around until the Parse object is deleted. Such
115617 ** expressions have iConstExprReg==0. Do not generate code for
115618 ** those expressions, of course.
115619 */
115620 if( pParse->pConstExpr ){
115621 ExprList *pEL = pParse->pConstExpr;
115622 pParse->okConstFactor = 0;
115623 for(i=0; i<pEL->nExpr; i++){
115624 int iReg = pEL->a[i].u.iConstExprReg;
115625 sqlite3ExprCode(pParse, pEL->a[i].pExpr, iReg);
115626 }
115627 }
115628
115629 if( pParse->bReturning ){
115630 Returning *pRet = pParse->u1.pReturning;
115631 if( pRet->nRetCol ){
115632 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol);
115633 }
115634 }
115635
115636 /* Finally, jump back to the beginning of the executable code. */
115637 sqlite3VdbeGoto(v, 1);
 
 
 
115638 }
115639
115640 /* Get the VDBE program ready for execution
115641 */
115642 assert( v!=0 || pParse->nErr );
@@ -115898,20 +116139,21 @@
116139 */
116140 SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3 *db, Table *pTable){
116141 int i;
116142 Column *pCol;
116143 assert( pTable!=0 );
116144 assert( db!=0 );
116145 if( (pCol = pTable->aCol)!=0 ){
116146 for(i=0; i<pTable->nCol; i++, pCol++){
116147 assert( pCol->zCnName==0 || pCol->hName==sqlite3StrIHash(pCol->zCnName) );
116148 sqlite3DbFree(db, pCol->zCnName);
116149 }
116150 sqlite3DbNNFreeNN(db, pTable->aCol);
116151 if( IsOrdinaryTable(pTable) ){
116152 sqlite3ExprListDelete(db, pTable->u.tab.pDfltList);
116153 }
116154 if( db->pnBytesFreed==0 ){
116155 pTable->aCol = 0;
116156 pTable->nCol = 0;
116157 if( IsOrdinaryTable(pTable) ){
116158 pTable->u.tab.pDfltList = 0;
116159 }
@@ -115944,21 +116186,22 @@
116186 **
116187 ** If malloc has already failed, it may be that it failed while allocating
116188 ** a Table object that was going to be marked ephemeral. So do not check
116189 ** that no lookaside memory is used in this case either. */
116190 int nLookaside = 0;
116191 assert( db!=0 );
116192 if( !db->mallocFailed && (pTable->tabFlags & TF_Ephemeral)==0 ){
116193 nLookaside = sqlite3LookasideUsed(db, 0);
116194 }
116195 #endif
116196
116197 /* Delete all indices associated with this table. */
116198 for(pIndex = pTable->pIndex; pIndex; pIndex=pNext){
116199 pNext = pIndex->pNext;
116200 assert( pIndex->pSchema==pTable->pSchema
116201 || (IsVirtual(pTable) && pIndex->idxType!=SQLITE_IDXTYPE_APPDEF) );
116202 if( db->pnBytesFreed==0 && !IsVirtual(pTable) ){
116203 char *zName = pIndex->zName;
116204 TESTONLY ( Index *pOld = ) sqlite3HashInsert(
116205 &pIndex->pSchema->idxHash, zName, 0
116206 );
116207 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
@@ -115991,12 +116234,13 @@
116234 /* Verify that no lookaside memory was used by schema tables */
116235 assert( nLookaside==0 || nLookaside==sqlite3LookasideUsed(db,0) );
116236 }
116237 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
116238 /* Do not delete the table until the reference count reaches zero. */
116239 assert( db!=0 );
116240 if( !pTable ) return;
116241 if( db->pnBytesFreed==0 && (--pTable->nTabRef)>0 ) return;
116242 deleteTable(db, pTable);
116243 }
116244
116245
116246 /*
@@ -118165,11 +118409,11 @@
118409 /*
118410 ** The Table structure pTable is really a VIEW. Fill in the names of
118411 ** the columns of the view in the pTable structure. Return the number
118412 ** of errors. If an error is seen leave an error message in pParse->zErrMsg.
118413 */
118414 static SQLITE_NOINLINE int viewGetColumnNames(Parse *pParse, Table *pTable){
118415 Table *pSelTab; /* A fake table from which we get the result set */
118416 Select *pSel; /* Copy of the SELECT that implements the view */
118417 int nErr = 0; /* Number of errors encountered */
118418 sqlite3 *db = pParse->db; /* Database connection for malloc errors */
118419 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -118190,13 +118434,14 @@
118434 }
118435 #endif
118436
118437 #ifndef SQLITE_OMIT_VIEW
118438 /* A positive nCol means the columns names for this view are
118439 ** already known. This routine is not called unless either the
118440 ** table is virtual or nCol is zero.
118441 */
118442 assert( pTable->nCol<=0 );
118443
118444 /* A negative nCol is a special marker meaning that we are currently
118445 ** trying to compute the column names. If we enter this routine with
118446 ** a negative nCol, it means two or more views form a loop, like this:
118447 **
@@ -118287,10 +118532,15 @@
118532 if( db->mallocFailed ){
118533 sqlite3DeleteColumnNames(db, pTable);
118534 }
118535 #endif /* SQLITE_OMIT_VIEW */
118536 return nErr;
118537 }
118538 SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){
118539 assert( pTable!=0 );
118540 if( !IsVirtual(pTable) && pTable->nCol>0 ) return 0;
118541 return viewGetColumnNames(pParse, pTable);
118542 }
118543 #endif /* !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE) */
118544
118545 #ifndef SQLITE_OMIT_VIEW
118546 /*
@@ -119153,11 +119403,11 @@
119403 if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName,"index",pTab->zName) ){
119404 goto exit_create_index;
119405 }
119406 if( !IN_RENAME_OBJECT ){
119407 if( !db->init.busy ){
119408 if( sqlite3FindTable(db, zName, pDb->zDbSName)!=0 ){
119409 sqlite3ErrorMsg(pParse, "there is already a table named %s", zName);
119410 goto exit_create_index;
119411 }
119412 }
119413 if( sqlite3FindIndex(db, zName, pDb->zDbSName)!=0 ){
@@ -119806,16 +120056,17 @@
120056 /*
120057 ** Delete an IdList.
120058 */
120059 SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3 *db, IdList *pList){
120060 int i;
120061 assert( db!=0 );
120062 if( pList==0 ) return;
120063 assert( pList->eU4!=EU4_EXPR ); /* EU4_EXPR mode is not currently used */
120064 for(i=0; i<pList->nId; i++){
120065 sqlite3DbFree(db, pList->a[i].zName);
120066 }
120067 sqlite3DbNNFreeNN(db, pList);
120068 }
120069
120070 /*
120071 ** Return the index in pList of the identifier named zId. Return -1
120072 ** if not found.
@@ -120014,15 +120265,16 @@
120265 ** Delete an entire SrcList including all its substructure.
120266 */
120267 SQLITE_PRIVATE void sqlite3SrcListDelete(sqlite3 *db, SrcList *pList){
120268 int i;
120269 SrcItem *pItem;
120270 assert( db!=0 );
120271 if( pList==0 ) return;
120272 for(pItem=pList->a, i=0; i<pList->nSrc; i++, pItem++){
120273 if( pItem->zDatabase ) sqlite3DbNNFreeNN(db, pItem->zDatabase);
120274 if( pItem->zName ) sqlite3DbNNFreeNN(db, pItem->zName);
120275 if( pItem->zAlias ) sqlite3DbNNFreeNN(db, pItem->zAlias);
120276 if( pItem->fg.isIndexedBy ) sqlite3DbFree(db, pItem->u1.zIndexedBy);
120277 if( pItem->fg.isTabFunc ) sqlite3ExprListDelete(db, pItem->u1.pFuncArg);
120278 sqlite3DeleteTable(db, pItem->pTab);
120279 if( pItem->pSelect ) sqlite3SelectDelete(db, pItem->pSelect);
120280 if( pItem->fg.isUsing ){
@@ -120029,11 +120281,11 @@
120281 sqlite3IdListDelete(db, pItem->u3.pUsing);
120282 }else if( pItem->u3.pOn ){
120283 sqlite3ExprDelete(db, pItem->u3.pOn);
120284 }
120285 }
120286 sqlite3DbNNFreeNN(db, pList);
120287 }
120288
120289 /*
120290 ** This routine is called by the parser to add a new term to the
120291 ** end of a growing FROM clause. The "p" parameter is the part of
@@ -121281,23 +121533,25 @@
121533 SQLITE_PRIVATE void sqlite3SchemaClear(void *p){
121534 Hash temp1;
121535 Hash temp2;
121536 HashElem *pElem;
121537 Schema *pSchema = (Schema *)p;
121538 sqlite3 xdb;
121539
121540 memset(&xdb, 0, sizeof(xdb));
121541 temp1 = pSchema->tblHash;
121542 temp2 = pSchema->trigHash;
121543 sqlite3HashInit(&pSchema->trigHash);
121544 sqlite3HashClear(&pSchema->idxHash);
121545 for(pElem=sqliteHashFirst(&temp2); pElem; pElem=sqliteHashNext(pElem)){
121546 sqlite3DeleteTrigger(&xdb, (Trigger*)sqliteHashData(pElem));
121547 }
121548 sqlite3HashClear(&temp2);
121549 sqlite3HashInit(&pSchema->tblHash);
121550 for(pElem=sqliteHashFirst(&temp1); pElem; pElem=sqliteHashNext(pElem)){
121551 Table *pTab = sqliteHashData(pElem);
121552 sqlite3DeleteTable(&xdb, pTab);
121553 }
121554 sqlite3HashClear(&temp1);
121555 sqlite3HashClear(&pSchema->fkeyHash);
121556 pSchema->pSeqTab = 0;
121557 if( pSchema->schemaFlags & DB_SchemaLoaded ){
@@ -121392,22 +121646,46 @@
121646 ** A table is read-only if any of the following are true:
121647 **
121648 ** 1) It is a virtual table and no implementation of the xUpdate method
121649 ** has been provided
121650 **
121651 ** 2) A trigger is currently being coded and the table is a virtual table
121652 ** that is SQLITE_VTAB_DIRECTONLY or if PRAGMA trusted_schema=OFF and
121653 ** the table is not SQLITE_VTAB_INNOCUOUS.
121654 **
121655 ** 3) It is a system table (i.e. sqlite_schema), this call is not
121656 ** part of a nested parse and writable_schema pragma has not
121657 ** been specified
121658 **
121659 ** 4) The table is a shadow table, the database connection is in
121660 ** defensive mode, and the current sqlite3_prepare()
121661 ** is for a top-level SQL statement.
121662 */
121663 static int vtabIsReadOnly(Parse *pParse, Table *pTab){
121664 if( sqlite3GetVTable(pParse->db, pTab)->pMod->pModule->xUpdate==0 ){
121665 return 1;
121666 }
121667
121668 /* Within triggers:
121669 ** * Do not allow DELETE, INSERT, or UPDATE of SQLITE_VTAB_DIRECTONLY
121670 ** virtual tables
121671 ** * Only allow DELETE, INSERT, or UPDATE of non-SQLITE_VTAB_INNOCUOUS
121672 ** virtual tables if PRAGMA trusted_schema=ON.
121673 */
121674 if( pParse->pToplevel!=0
121675 && pTab->u.vtab.p->eVtabRisk >
121676 ((pParse->db->flags & SQLITE_TrustedSchema)!=0)
121677 ){
121678 sqlite3ErrorMsg(pParse, "unsafe use of virtual table \"%s\"",
121679 pTab->zName);
121680 }
121681 return 0;
121682 }
121683 static int tabIsReadOnly(Parse *pParse, Table *pTab){
121684 sqlite3 *db;
121685 if( IsVirtual(pTab) ){
121686 return vtabIsReadOnly(pParse, pTab);
121687 }
121688 if( (pTab->tabFlags & (TF_Readonly|TF_Shadow))==0 ) return 0;
121689 db = pParse->db;
121690 if( (pTab->tabFlags & TF_Readonly)!=0 ){
121691 return sqlite3WritableSchema(db)==0 && pParse->nested==0;
@@ -121415,13 +121693,15 @@
121693 assert( pTab->tabFlags & TF_Shadow );
121694 return sqlite3ReadOnlyShadowTables(db);
121695 }
121696
121697 /*
121698 ** Check to make sure the given table is writable.
121699 **
121700 ** If pTab is not writable -> generate an error message and return 1.
121701 ** If pTab is writable but other errors have occurred -> return 1.
121702 ** If pTab is writable and no prior errors -> return 0;
121703 */
121704 SQLITE_PRIVATE int sqlite3IsReadOnly(Parse *pParse, Table *pTab, int viewOk){
121705 if( tabIsReadOnly(pParse, pTab) ){
121706 sqlite3ErrorMsg(pParse, "table %s may not be modified", pTab->zName);
121707 return 1;
@@ -121778,13 +122058,14 @@
122058 sqlite3VdbeAddOp4(v, OP_Clear, pTab->tnum, iDb, memCnt ? memCnt : -1,
122059 pTab->zName, P4_STATIC);
122060 }
122061 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
122062 assert( pIdx->pSchema==pTab->pSchema );
 
122063 if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
122064 sqlite3VdbeAddOp3(v, OP_Clear, pIdx->tnum, iDb, memCnt ? memCnt : -1);
122065 }else{
122066 sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
122067 }
122068 }
122069 }else
122070 #endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
122071 {
@@ -121980,11 +122261,11 @@
122261 sqlite3ExprDelete(db, pWhere);
122262 #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT)
122263 sqlite3ExprListDelete(db, pOrderBy);
122264 sqlite3ExprDelete(db, pLimit);
122265 #endif
122266 if( aToOpen ) sqlite3DbNNFreeNN(db, aToOpen);
122267 return;
122268 }
122269 /* Make sure "isView" and other macros defined above are undefined. Otherwise
122270 ** they may interfere with compilation of other functions in this file
122271 ** (or in another file, if this file becomes part of the amalgamation). */
@@ -126148,15 +126429,16 @@
126429 SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *db, Table *pTab){
126430 FKey *pFKey; /* Iterator variable */
126431 FKey *pNext; /* Copy of pFKey->pNextFrom */
126432
126433 assert( IsOrdinaryTable(pTab) );
126434 assert( db!=0 );
126435 for(pFKey=pTab->u.tab.pFKey; pFKey; pFKey=pNext){
126436 assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pTab->pSchema) );
126437
126438 /* Remove the FK from the fkeyHash hash table. */
126439 if( db->pnBytesFreed==0 ){
126440 if( pFKey->pPrevTo ){
126441 pFKey->pPrevTo->pNextTo = pFKey->pNextTo;
126442 }else{
126443 void *p = (void *)pFKey->pNextTo;
126444 const char *z = (p ? pFKey->pNextTo->zTo : pFKey->zTo);
@@ -126345,11 +126627,11 @@
126627 /* Move the previous opcode (which should be OP_MakeRecord) forward
126628 ** by one slot and insert a new OP_TypeCheck where the current
126629 ** OP_MakeRecord is found */
126630 VdbeOp *pPrev;
126631 sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
126632 pPrev = sqlite3VdbeGetLastOp(v);
126633 assert( pPrev!=0 );
126634 assert( pPrev->opcode==OP_MakeRecord || sqlite3VdbeDb(v)->mallocFailed );
126635 pPrev->opcode = OP_TypeCheck;
126636 sqlite3VdbeAddOp3(v, OP_MakeRecord, pPrev->p1, pPrev->p2, pPrev->p3);
126637 }else{
@@ -126383,11 +126665,11 @@
126665 i = sqlite3Strlen30NN(zColAff);
126666 if( i ){
126667 if( iReg ){
126668 sqlite3VdbeAddOp4(v, OP_Affinity, iReg, i, 0, zColAff, i);
126669 }else{
126670 assert( sqlite3VdbeGetLastOp(v)->opcode==OP_MakeRecord
126671 || sqlite3VdbeDb(v)->mallocFailed );
126672 sqlite3VdbeChangeP4(v, -1, zColAff, i);
126673 }
126674 }
126675 }
@@ -126469,11 +126751,11 @@
126751 /* Before computing generated columns, first go through and make sure
126752 ** that appropriate affinity has been applied to the regular columns
126753 */
126754 sqlite3TableAffinity(pParse->pVdbe, pTab, iRegStore);
126755 if( (pTab->tabFlags & TF_HasStored)!=0 ){
126756 pOp = sqlite3VdbeGetLastOp(pParse->pVdbe);
126757 if( pOp->opcode==OP_Affinity ){
126758 /* Change the OP_Affinity argument to '@' (NONE) for all stored
126759 ** columns. '@' is the no-op affinity and those columns have not
126760 ** yet been computed. */
126761 int ii, jj;
@@ -127375,11 +127657,16 @@
127657 }else if( pSelect ){
127658 if( regFromSelect!=regData ){
127659 sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+k, iRegStore);
127660 }
127661 }else{
127662 Expr *pX = pList->a[k].pExpr;
127663 int y = sqlite3ExprCodeTarget(pParse, pX, iRegStore);
127664 if( y!=iRegStore ){
127665 sqlite3VdbeAddOp2(v,
127666 ExprHasProperty(pX, EP_Subquery) ? OP_Copy : OP_SCopy, y, iRegStore);
127667 }
127668 }
127669 }
127670
127671
127672 /* Run the BEFORE and INSTEAD OF triggers, if there are any
@@ -127512,11 +127799,13 @@
127799 int isReplace = 0;/* Set to true if constraints may cause a replace */
127800 int bUseSeek; /* True to use OPFLAG_SEEKRESULT */
127801 sqlite3GenerateConstraintChecks(pParse, pTab, aRegIdx, iDataCur, iIdxCur,
127802 regIns, 0, ipkColumn>=0, onError, endOfLoop, &isReplace, 0, pUpsert
127803 );
127804 if( db->flags & SQLITE_ForeignKeys ){
127805 sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0);
127806 }
127807
127808 /* Set the OPFLAG_USESEEKRESULT flag if either (a) there are no REPLACE
127809 ** constraints or (b) there are no triggers and this table is not a
127810 ** parent table in a foreign key constraint. It is safe to set the
127811 ** flag in the second case as if any REPLACE constraint is hit, an
@@ -127596,11 +127885,11 @@
127885 sqlite3SrcListDelete(db, pTabList);
127886 sqlite3ExprListDelete(db, pList);
127887 sqlite3UpsertDelete(db, pUpsert);
127888 sqlite3SelectDelete(db, pSelect);
127889 sqlite3IdListDelete(db, pColumn);
127890 if( aRegIdx ) sqlite3DbNNFreeNN(db, aRegIdx);
127891 }
127892
127893 /* Make sure "isView" and other macros defined above are undefined. Otherwise
127894 ** they may interfere with compilation of other functions in this file
127895 ** (or in another file, if this file becomes part of the amalgamation). */
@@ -132702,19 +132991,21 @@
132991 ** Setting to a null string reverts to the default temporary directory search.
132992 ** If temporary directory is changed, then invalidateTempStorage.
132993 **
132994 */
132995 case PragTyp_TEMP_STORE_DIRECTORY: {
132996 sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
132997 if( !zRight ){
132998 returnSingleText(v, sqlite3_temp_directory);
132999 }else{
133000 #ifndef SQLITE_OMIT_WSD
133001 if( zRight[0] ){
133002 int res;
133003 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
133004 if( rc!=SQLITE_OK || res==0 ){
133005 sqlite3ErrorMsg(pParse, "not a writable directory");
133006 sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
133007 goto pragma_out;
133008 }
133009 }
133010 if( SQLITE_TEMP_STORE==0
133011 || (SQLITE_TEMP_STORE==1 && db->temp_store<=1)
@@ -132728,10 +133019,11 @@
133019 }else{
133020 sqlite3_temp_directory = 0;
133021 }
133022 #endif /* SQLITE_OMIT_WSD */
133023 }
133024 sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
133025 break;
133026 }
133027
133028 #if SQLITE_OS_WIN
133029 /*
@@ -132746,19 +133038,21 @@
133038 ** process. Database file specified with an absolute path are not impacted
133039 ** by this setting, regardless of its value.
133040 **
133041 */
133042 case PragTyp_DATA_STORE_DIRECTORY: {
133043 sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
133044 if( !zRight ){
133045 returnSingleText(v, sqlite3_data_directory);
133046 }else{
133047 #ifndef SQLITE_OMIT_WSD
133048 if( zRight[0] ){
133049 int res;
133050 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
133051 if( rc!=SQLITE_OK || res==0 ){
133052 sqlite3ErrorMsg(pParse, "not a writable directory");
133053 sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
133054 goto pragma_out;
133055 }
133056 }
133057 sqlite3_free(sqlite3_data_directory);
133058 if( zRight[0] ){
@@ -132766,10 +133060,11 @@
133060 }else{
133061 sqlite3_data_directory = 0;
133062 }
133063 #endif /* SQLITE_OMIT_WSD */
133064 }
133065 sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
133066 break;
133067 }
133068 #endif
133069
133070 #if SQLITE_ENABLE_LOCKING_STYLE
@@ -133479,19 +133774,27 @@
133774 /* Make sure all the indices are constructed correctly.
133775 */
133776 for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
133777 Table *pTab = sqliteHashData(x);
133778 Index *pIdx, *pPk;
133779 Index *pPrior = 0; /* Previous index */
133780 int loopTop;
133781 int iDataCur, iIdxCur;
133782 int r1 = -1;
133783 int bStrict;
133784 int r2; /* Previous key for WITHOUT ROWID tables */
133785
133786 if( !IsOrdinaryTable(pTab) ) continue;
133787 if( pObjTab && pObjTab!=pTab ) continue;
133788 if( isQuick || HasRowid(pTab) ){
133789 pPk = 0;
133790 r2 = 0;
133791 }else{
133792 pPk = sqlite3PrimaryKeyIndex(pTab);
133793 r2 = sqlite3GetTempRange(pParse, pPk->nKeyCol);
133794 sqlite3VdbeAddOp3(v, OP_Null, 1, r2, r2+pPk->nKeyCol-1);
133795 }
133796 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
133797 1, 0, &iDataCur, &iIdxCur);
133798 /* reg[7] counts the number of entries in the table.
133799 ** reg[8+i] counts the number of entries in the i-th index
133800 */
@@ -133506,10 +133809,28 @@
133809 if( !isQuick ){
133810 /* Sanity check on record header decoding */
133811 sqlite3VdbeAddOp3(v, OP_Column, iDataCur, pTab->nNVCol-1,3);
133812 sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
133813 VdbeComment((v, "(right-most column)"));
133814 if( pPk ){
133815 /* Verify WITHOUT ROWID keys are in ascending order */
133816 int a1;
133817 char *zErr;
133818 a1 = sqlite3VdbeAddOp4Int(v, OP_IdxGT, iDataCur, 0,r2,pPk->nKeyCol);
133819 VdbeCoverage(v);
133820 sqlite3VdbeAddOp1(v, OP_IsNull, r2); VdbeCoverage(v);
133821 zErr = sqlite3MPrintf(db,
133822 "row not in PRIMARY KEY order for %s",
133823 pTab->zName);
133824 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
133825 integrityCheckResultRow(v);
133826 sqlite3VdbeJumpHere(v, a1);
133827 sqlite3VdbeJumpHere(v, a1+1);
133828 for(j=0; j<pPk->nKeyCol; j++){
133829 sqlite3ExprCodeLoadIndexColumn(pParse, pPk, iDataCur, j, r2+j);
133830 }
133831 }
133832 }
133833 /* Verify that all NOT NULL columns really are NOT NULL. At the
133834 ** same time verify the type of the content of STRICT tables */
133835 bStrict = (pTab->tabFlags & TF_Strict)!=0;
133836 for(j=0; j<pTab->nCol; j++){
@@ -133518,11 +133839,11 @@
133839 int doError, jmp2;
133840 if( j==pTab->iPKey ) continue;
133841 if( pCol->notNull==0 && !bStrict ) continue;
133842 doError = bStrict ? sqlite3VdbeMakeLabel(pParse) : 0;
133843 sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, j, 3);
133844 if( sqlite3VdbeGetLastOp(v)->opcode==OP_Column ){
133845 sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
133846 }
133847 if( pCol->notNull ){
133848 jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v);
133849 zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
@@ -133533,13 +133854,11 @@
133854 }else{
133855 integrityCheckResultRow(v);
133856 }
133857 sqlite3VdbeJumpHere(v, jmp2);
133858 }
133859 if( bStrict && pCol->eCType!=COLTYPE_ANY ){
 
 
133860 jmp2 = sqlite3VdbeAddOp3(v, OP_IsNullOrType, 3, 0,
133861 sqlite3StdTypeMap[pCol->eCType-1]);
133862 VdbeCoverage(v);
133863 zErr = sqlite3MPrintf(db, "non-%s value in %s.%s",
133864 sqlite3StdType[pCol->eCType-1],
@@ -133634,10 +133953,13 @@
133953 sqlite3VdbeLoadString(v, 4, pIdx->zName);
133954 sqlite3VdbeAddOp3(v, OP_Concat, 4, 2, 3);
133955 integrityCheckResultRow(v);
133956 sqlite3VdbeJumpHere(v, addr);
133957 }
133958 if( pPk ){
133959 sqlite3ReleaseTempRange(pParse, r2, pPk->nKeyCol);
133960 }
133961 }
133962 }
133963 }
133964 {
133965 static const int iLn = VDBE_OFFSET_LINENO(2);
@@ -135032,19 +135354,19 @@
135354 sqlite3 *db = pParse->db;
135355 assert( db!=0 );
135356 assert( db->pParse==pParse );
135357 assert( pParse->nested==0 );
135358 #ifndef SQLITE_OMIT_SHARED_CACHE
135359 if( pParse->aTableLock ) sqlite3DbNNFreeNN(db, pParse->aTableLock);
135360 #endif
135361 while( pParse->pCleanup ){
135362 ParseCleanup *pCleanup = pParse->pCleanup;
135363 pParse->pCleanup = pCleanup->pNext;
135364 pCleanup->xCleanup(db, pCleanup->pPtr);
135365 sqlite3DbNNFreeNN(db, pCleanup);
135366 }
135367 if( pParse->aLabel ) sqlite3DbNNFreeNN(db, pParse->aLabel);
135368 if( pParse->pConstExpr ){
135369 sqlite3ExprListDelete(db, pParse->pConstExpr);
135370 }
135371 assert( db->lookaside.bDisable >= pParse->disableLookaside );
135372 db->lookaside.bDisable -= pParse->disableLookaside;
@@ -135599,10 +135921,11 @@
135921 **
135922 ** If bFree==1, call sqlite3DbFree() on the p object.
135923 ** If bFree==0, Leave the first Select object unfreed
135924 */
135925 static void clearSelect(sqlite3 *db, Select *p, int bFree){
135926 assert( db!=0 );
135927 while( p ){
135928 Select *pPrior = p->pPrior;
135929 sqlite3ExprListDelete(db, p->pEList);
135930 sqlite3SrcListDelete(db, p->pSrc);
135931 sqlite3ExprDelete(db, p->pWhere);
@@ -135618,11 +135941,11 @@
135941 while( p->pWin ){
135942 assert( p->pWin->ppThis==&p->pWin );
135943 sqlite3WindowUnlinkFromSelect(p->pWin);
135944 }
135945 #endif
135946 if( bFree ) sqlite3DbNNFreeNN(db, p);
135947 p = pPrior;
135948 bFree = 1;
135949 }
135950 }
135951
@@ -137024,13 +137347,14 @@
137347 /*
137348 ** Deallocate a KeyInfo object
137349 */
137350 SQLITE_PRIVATE void sqlite3KeyInfoUnref(KeyInfo *p){
137351 if( p ){
137352 assert( p->db!=0 );
137353 assert( p->nRef>0 );
137354 p->nRef--;
137355 if( p->nRef==0 ) sqlite3DbNNFreeNN(p->db, p);
137356 }
137357 }
137358
137359 /*
137360 ** Make a new pointer to a KeyInfo object
@@ -137211,18 +137535,21 @@
137535 sqlite3VdbeAddOp3(v, OP_OpenPseudo, iSortTab, regSortOut,
137536 nKey+1+nColumn+nRefKey);
137537 if( addrOnce ) sqlite3VdbeJumpHere(v, addrOnce);
137538 addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
137539 VdbeCoverage(v);
137540 assert( p->iLimit==0 && p->iOffset==0 );
137541 sqlite3VdbeAddOp3(v, OP_SorterData, iTab, regSortOut, iSortTab);
137542 bSeq = 0;
137543 }else{
137544 addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v);
137545 codeOffset(v, p->iOffset, addrContinue);
137546 iSortTab = iTab;
137547 bSeq = 1;
137548 if( p->iOffset>0 ){
137549 sqlite3VdbeAddOp2(v, OP_AddImm, p->iLimit, -1);
137550 }
137551 }
137552 for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){
137553 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
137554 if( aOutEx[i].fg.bSorterRef ) continue;
137555 #endif
@@ -137343,13 +137670,10 @@
137670
137671 /*
137672 ** Return a pointer to a string containing the 'declaration type' of the
137673 ** expression pExpr. The string may be treated as static by the caller.
137674 **
 
 
 
137675 ** The declaration type is the exact datatype definition extracted from the
137676 ** original CREATE TABLE statement if the expression is a column. The
137677 ** declaration type for a ROWID field is INTEGER. Exactly when an expression
137678 ** is considered a column can be complex in the presence of subqueries. The
137679 ** result-set expression in all of the following SELECT statements is
@@ -139211,14 +139535,15 @@
139535
139536 /* Jump to the this point in order to terminate the query.
139537 */
139538 sqlite3VdbeResolveLabel(v, labelEnd);
139539
139540 /* Reassemble the compound query so that it will be freed correctly
139541 ** by the calling function */
139542 if( pSplit->pPrior ){
139543 sqlite3ParserAddCleanup(pParse,
139544 (void(*)(sqlite3*,void*))sqlite3SelectDelete, pSplit->pPrior);
139545 }
139546 pSplit->pPrior = pPrior;
139547 pPrior->pNext = pSplit;
139548 sqlite3ExprListDelete(db, pPrior->pOrderBy);
139549 pPrior->pOrderBy = 0;
@@ -139324,10 +139649,11 @@
139649 if( pSubst->isOuterJoin && pCopy->op!=TK_COLUMN ){
139650 memset(&ifNullRow, 0, sizeof(ifNullRow));
139651 ifNullRow.op = TK_IF_NULL_ROW;
139652 ifNullRow.pLeft = pCopy;
139653 ifNullRow.iTable = pSubst->iNewTable;
139654 ifNullRow.iColumn = -99;
139655 ifNullRow.flags = EP_IfNullRow;
139656 pCopy = &ifNullRow;
139657 }
139658 testcase( ExprHasProperty(pCopy, EP_Subquery) );
139659 pNew = sqlite3ExprDup(db, pCopy, 0);
@@ -139591,11 +139917,12 @@
139917 **
139918 ** (3) If the subquery is the right operand of a LEFT JOIN then
139919 ** (3a) the subquery may not be a join and
139920 ** (3b) the FROM clause of the subquery may not contain a virtual
139921 ** table and
139922 ** (**) Was: "The outer query may not have a GROUP BY." This case
139923 ** is now managed correctly
139924 ** (3d) the outer query may not be DISTINCT.
139925 ** See also (26) for restrictions on RIGHT JOIN.
139926 **
139927 ** (4) The subquery can not be DISTINCT.
139928 **
@@ -139803,20 +140130,14 @@
140130 **
140131 ** (t1 LEFT OUTER JOIN t2) JOIN t3
140132 **
140133 ** which is not at all the same thing.
140134 **
 
 
 
 
 
140135 ** See also tickets #306, #350, and #3300.
140136 */
140137 if( (pSubitem->fg.jointype & (JT_OUTER|JT_LTORJ))!=0 ){
140138 if( pSubSrc->nSrc>1 /* (3a) */
 
140139 || IsVirtual(pSubSrc->a[0].pTab) /* (3b) */
140140 || (p->selFlags & SF_Distinct)!=0 /* (3d) */
140141 || (pSubitem->fg.jointype & JT_RIGHT)!=0 /* (26) */
140142 ){
140143 return 0;
@@ -140733,10 +141054,11 @@
141054 if( p->pWhere
141055 || p->pEList->nExpr!=1
141056 || p->pSrc->nSrc!=1
141057 || p->pSrc->a[0].pSelect
141058 || pAggInfo->nFunc!=1
141059 || p->pHaving
141060 ){
141061 return 0;
141062 }
141063 pTab = p->pSrc->a[0].pTab;
141064 assert( pTab!=0 );
@@ -142726,11 +143048,11 @@
143048 */
143049 iEnd = sqlite3VdbeMakeLabel(pParse);
143050 if( (p->selFlags & SF_FixedLimit)==0 ){
143051 p->nSelectRow = 320; /* 4 billion rows */
143052 }
143053 if( p->pLimit ) computeLimitRegisters(pParse, p, iEnd);
143054 if( p->iLimit==0 && sSort.addrSortIndex>=0 ){
143055 sqlite3VdbeChangeOpcode(v, sSort.addrSortIndex, OP_SorterOpen);
143056 sSort.sortFlags |= SORTFLAG_UseSorter;
143057 }
143058
@@ -142948,12 +143270,17 @@
143270 if( minMaxFlag ){
143271 sqlite3DebugPrintf("MIN/MAX Optimization (0x%02x) adds:\n", minMaxFlag);
143272 sqlite3TreeViewExprList(0, pMinMaxOrderBy, 0, "ORDERBY");
143273 }
143274 for(ii=0; ii<pAggInfo->nColumn; ii++){
143275 struct AggInfo_col *pCol = &pAggInfo->aCol[ii];
143276 sqlite3DebugPrintf(
143277 "agg-column[%d] pTab=%s iTable=%d iColumn=%d iMem=%d"
143278 " iSorterColumn=%d\n",
143279 ii, pCol->pTab ? pCol->pTab->zName : "NULL",
143280 pCol->iTable, pCol->iColumn, pCol->iMem,
143281 pCol->iSorterColumn);
143282 sqlite3TreeViewExpr(0, pAggInfo->aCol[ii].pCExpr, 0);
143283 }
143284 for(ii=0; ii<pAggInfo->nFunc; ii++){
143285 sqlite3DebugPrintf("agg-func[%d]: iMem=%d\n",
143286 ii, pAggInfo->aFunc[ii].iMem);
@@ -143070,19 +143397,19 @@
143397 }
143398 }
143399 regBase = sqlite3GetTempRange(pParse, nCol);
143400 sqlite3ExprCodeExprList(pParse, pGroupBy, regBase, 0, 0);
143401 j = nGroupBy;
143402 pAggInfo->directMode = 1;
143403 for(i=0; i<pAggInfo->nColumn; i++){
143404 struct AggInfo_col *pCol = &pAggInfo->aCol[i];
143405 if( pCol->iSorterColumn>=j ){
143406 sqlite3ExprCode(pParse, pCol->pCExpr, j + regBase);
 
 
143407 j++;
143408 }
143409 }
143410 pAggInfo->directMode = 0;
143411 regRecord = sqlite3GetTempReg(pParse);
143412 sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regRecord);
143413 sqlite3VdbeAddOp2(v, OP_SorterInsert, pAggInfo->sortingIdx, regRecord);
143414 sqlite3ReleaseTempReg(pParse, regRecord);
143415 sqlite3ReleaseTempRange(pParse, regBase, nCol);
@@ -147496,11 +147823,12 @@
147823 ** in the list are moved to the sqlite3.pDisconnect list of the associated
147824 ** database connection.
147825 */
147826 SQLITE_PRIVATE void sqlite3VtabClear(sqlite3 *db, Table *p){
147827 assert( IsVirtual(p) );
147828 assert( db!=0 );
147829 if( db->pnBytesFreed==0 ) vtabDisconnectAll(0, p);
147830 if( p->u.vtab.azArg ){
147831 int i;
147832 for(i=0; i<p->u.vtab.nArg; i++){
147833 if( i!=1 ) sqlite3DbFree(db, p->u.vtab.azArg[i]);
147834 }
@@ -149173,10 +149501,11 @@
149501 #define WHERE_IN_SEEKSCAN 0x00100000 /* Seek-scan optimization for IN */
149502 #define WHERE_TRANSCONS 0x00200000 /* Uses a transitive constraint */
149503 #define WHERE_BLOOMFILTER 0x00400000 /* Consider using a Bloom-filter */
149504 #define WHERE_SELFCULL 0x00800000 /* nOut reduced by extra WHERE terms */
149505 #define WHERE_OMIT_OFFSET 0x01000000 /* Set offset counter to zero */
149506 #define WHERE_VIEWSCAN 0x02000000 /* A full-scan of a VIEW or subquery */
149507
149508 #endif /* !defined(SQLITE_WHEREINT_H) */
149509
149510 /************** End of whereInt.h ********************************************/
149511 /************** Continuing where we left off in wherecode.c ******************/
@@ -149781,11 +150110,12 @@
150110 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap,&iTab);
150111 pExpr->iTable = iTab;
150112 }
150113 sqlite3ExprDelete(db, pX);
150114 }else{
150115 int n = sqlite3ExprVectorSize(pX->pLeft);
150116 aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*MAX(nEq,n));
150117 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap, &iTab);
150118 }
150119 pX = pExpr;
150120 }
150121
@@ -150051,11 +150381,11 @@
150381 WhereTerm *pTerm /* The upper or lower bound just coded */
150382 ){
150383 if( pTerm->wtFlags & TERM_LIKEOPT ){
150384 VdbeOp *pOp;
150385 assert( pLevel->iLikeRepCntr>0 );
150386 pOp = sqlite3VdbeGetLastOp(v);
150387 assert( pOp!=0 );
150388 assert( pOp->opcode==OP_String8
150389 || pTerm->pWC->pWInfo->pParse->db->mallocFailed );
150390 pOp->p3 = (int)(pLevel->iLikeRepCntr>>1); /* Register holding counter */
150391 pOp->p5 = (u8)(pLevel->iLikeRepCntr&1); /* ASC or DESC */
@@ -151267,12 +151597,12 @@
151597 sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
151598 endEq = 0;
151599 }
151600 nConstraint++;
151601 }
151602 if( zStartAff ) sqlite3DbNNFreeNN(db, zStartAff);
151603 if( zEndAff ) sqlite3DbNNFreeNN(db, zEndAff);
151604
151605 /* Top of the loop body */
151606 if( pLevel->p2==0 ) pLevel->p2 = sqlite3VdbeCurrentAddr(v);
151607
151608 /* Check if the index cursor is past the end of the range. */
@@ -155499,11 +155829,11 @@
155829 /* At this point, the (iCol+1) field prefix of aSample[i] is the first
155830 ** sample that is greater than pRec. Or, if i==pIdx->nSample then pRec
155831 ** is larger than all samples in the array. */
155832 tRowcnt iUpper, iGap;
155833 if( i>=pIdx->nSample ){
155834 iUpper = pIdx->nRowEst0;
155835 }else{
155836 iUpper = aSample[i].anLt[iCol];
155837 }
155838
155839 if( iLower>=iUpper ){
@@ -156128,16 +156458,22 @@
156458 }
156459 }
156460 }
156461
156462 /*
156463 ** Deallocate internal memory used by a WhereLoop object. Leave the
156464 ** object in an initialized state, as if it had been newly allocated.
156465 */
156466 static void whereLoopClear(sqlite3 *db, WhereLoop *p){
156467 if( p->aLTerm!=p->aLTermSpace ){
156468 sqlite3DbFreeNN(db, p->aLTerm);
156469 p->aLTerm = p->aLTermSpace;
156470 p->nLSlot = ArraySize(p->aLTermSpace);
156471 }
156472 whereLoopClearUnion(db, p);
156473 p->nLTerm = 0;
156474 p->wsFlags = 0;
156475 }
156476
156477 /*
156478 ** Increase the memory allocation for pLoop->aLTerm[] to be at least n.
156479 */
@@ -156157,11 +156493,13 @@
156493 /*
156494 ** Transfer content from the second pLoop into the first.
156495 */
156496 static int whereLoopXfer(sqlite3 *db, WhereLoop *pTo, WhereLoop *pFrom){
156497 whereLoopClearUnion(db, pTo);
156498 if( pFrom->nLTerm > pTo->nLSlot
156499 && whereLoopResize(db, pTo, pFrom->nLTerm)
156500 ){
156501 memset(pTo, 0, WHERE_LOOP_XFER_SZ);
156502 return SQLITE_NOMEM_BKPT;
156503 }
156504 memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);
156505 memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
@@ -156175,32 +156513,34 @@
156513
156514 /*
156515 ** Delete a WhereLoop object
156516 */
156517 static void whereLoopDelete(sqlite3 *db, WhereLoop *p){
156518 assert( db!=0 );
156519 whereLoopClear(db, p);
156520 sqlite3DbNNFreeNN(db, p);
156521 }
156522
156523 /*
156524 ** Free a WhereInfo structure
156525 */
156526 static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
156527 assert( pWInfo!=0 );
156528 assert( db!=0 );
156529 sqlite3WhereClauseClear(&pWInfo->sWC);
156530 while( pWInfo->pLoops ){
156531 WhereLoop *p = pWInfo->pLoops;
156532 pWInfo->pLoops = p->pNextLoop;
156533 whereLoopDelete(db, p);
156534 }
156535 assert( pWInfo->pExprMods==0 );
156536 while( pWInfo->pMemToFree ){
156537 WhereMemBlock *pNext = pWInfo->pMemToFree->pNext;
156538 sqlite3DbNNFreeNN(db, pWInfo->pMemToFree);
156539 pWInfo->pMemToFree = pNext;
156540 }
156541 sqlite3DbNNFreeNN(db, pWInfo);
156542 }
156543
156544 /* Undo all Expr node modifications
156545 */
156546 static void whereUndoExprMods(WhereInfo *pWInfo){
@@ -156810,11 +157150,15 @@
157150 pNew->wsFlags = saved_wsFlags;
157151 pNew->u.btree.nEq = saved_nEq;
157152 pNew->u.btree.nBtm = saved_nBtm;
157153 pNew->u.btree.nTop = saved_nTop;
157154 pNew->nLTerm = saved_nLTerm;
157155 if( pNew->nLTerm>=pNew->nLSlot
157156 && whereLoopResize(db, pNew, pNew->nLTerm+1)
157157 ){
157158 break; /* OOM while trying to enlarge the pNew->aLTerm array */
157159 }
157160 pNew->aLTerm[pNew->nLTerm++] = pTerm;
157161 pNew->prereq = (saved_prereq | pTerm->prereqRight) & ~pNew->maskSelf;
157162
157163 assert( nInMul==0
157164 || (pNew->wsFlags & WHERE_COLUMN_NULL)!=0
@@ -156903,42 +157247,43 @@
157247 }
157248 }
157249 if( scan.iEquiv>1 ) pNew->wsFlags |= WHERE_TRANSCONS;
157250 }else if( eOp & WO_ISNULL ){
157251 pNew->wsFlags |= WHERE_COLUMN_NULL;
157252 }else{
157253 int nVecLen = whereRangeVectorLen(
157254 pParse, pSrc->iCursor, pProbe, saved_nEq, pTerm
157255 );
157256 if( eOp & (WO_GT|WO_GE) ){
157257 testcase( eOp & WO_GT );
157258 testcase( eOp & WO_GE );
157259 pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_BTM_LIMIT;
157260 pNew->u.btree.nBtm = nVecLen;
157261 pBtm = pTerm;
157262 pTop = 0;
157263 if( pTerm->wtFlags & TERM_LIKEOPT ){
157264 /* Range constraints that come from the LIKE optimization are
157265 ** always used in pairs. */
157266 pTop = &pTerm[1];
157267 assert( (pTop-(pTerm->pWC->a))<pTerm->pWC->nTerm );
157268 assert( pTop->wtFlags & TERM_LIKEOPT );
157269 assert( pTop->eOperator==WO_LT );
157270 if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
157271 pNew->aLTerm[pNew->nLTerm++] = pTop;
157272 pNew->wsFlags |= WHERE_TOP_LIMIT;
157273 pNew->u.btree.nTop = 1;
157274 }
157275 }else{
157276 assert( eOp & (WO_LT|WO_LE) );
157277 testcase( eOp & WO_LT );
157278 testcase( eOp & WO_LE );
157279 pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_TOP_LIMIT;
157280 pNew->u.btree.nTop = nVecLen;
157281 pTop = pTerm;
157282 pBtm = (pNew->wsFlags & WHERE_BTM_LIMIT)!=0 ?
157283 pNew->aLTerm[pNew->nLTerm-2] : 0;
157284 }
157285 }
157286
157287 /* At this point pNew->nOut is set to the number of rows expected to
157288 ** be visited by the index scan before considering term pTerm, or the
157289 ** values of nIn and nInMul. In other words, assuming that all
@@ -157380,10 +157725,13 @@
157725 #ifdef SQLITE_ENABLE_STAT4
157726 pNew->rRun = rSize + 16 - 2*((pTab->tabFlags & TF_HasStat4)!=0);
157727 #else
157728 pNew->rRun = rSize + 16;
157729 #endif
157730 if( IsView(pTab) || (pTab->tabFlags & TF_Ephemeral)!=0 ){
157731 pNew->wsFlags |= WHERE_VIEWSCAN;
157732 }
157733 ApplyCostMultiplier(pNew->rRun, pTab->costMult);
157734 whereLoopOutputAdjust(pWC, pNew, rSize);
157735 rc = whereLoopInsert(pBuilder, pNew);
157736 pNew->nOut = rSize;
157737 if( rc ) break;
@@ -158106,11 +158454,17 @@
158454 WhereLoop *pNew;
158455
158456
158457 /* Loop over the tables in the join, from left to right */
158458 pNew = pBuilder->pNew;
158459
158460 /* Verify that pNew has already been initialized */
158461 assert( pNew->nLTerm==0 );
158462 assert( pNew->wsFlags==0 );
158463 assert( pNew->nLSlot>=ArraySize(pNew->aLTermSpace) );
158464 assert( pNew->aLTerm!=0 );
158465
158466 pBuilder->iPlanLimit = SQLITE_QUERY_PLANNER_LIMIT;
158467 for(iTab=0, pItem=pTabList->a; pItem<pEnd; iTab++, pItem++){
158468 Bitmask mUnusable = 0;
158469 pNew->iTab = iTab;
158470 pBuilder->iPlanLimit += SQLITE_QUERY_PLANNER_LIMIT_INCR;
@@ -158703,13 +159057,13 @@
159057 for(ii=0, pFrom=aFrom; ii<nFrom; ii++, pFrom++){
159058 for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){
159059 LogEst nOut; /* Rows visited by (pFrom+pWLoop) */
159060 LogEst rCost; /* Cost of path (pFrom+pWLoop) */
159061 LogEst rUnsorted; /* Unsorted cost of (pFrom+pWLoop) */
159062 i8 isOrdered; /* isOrdered for (pFrom+pWLoop) */
159063 Bitmask maskNew; /* Mask of src visited by (..) */
159064 Bitmask revMask; /* Mask of rev-order loops for (..) */
159065
159066 if( (pWLoop->prereq & ~pFrom->maskLoop)!=0 ) continue;
159067 if( (pWLoop->maskSelf & pFrom->maskLoop)!=0 ) continue;
159068 if( (pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 && pFrom->nRow<3 ){
159069 /* Do not use an automatic index if the this loop is expected
@@ -158724,11 +159078,13 @@
159078 ** Compute its cost */
159079 rUnsorted = sqlite3LogEstAdd(pWLoop->rSetup,pWLoop->rRun + pFrom->nRow);
159080 rUnsorted = sqlite3LogEstAdd(rUnsorted, pFrom->rUnsorted);
159081 nOut = pFrom->nRow + pWLoop->nOut;
159082 maskNew = pFrom->maskLoop | pWLoop->maskSelf;
159083 isOrdered = pFrom->isOrdered;
159084 if( isOrdered<0 ){
159085 revMask = 0;
159086 isOrdered = wherePathSatisfiesOrderBy(pWInfo,
159087 pWInfo->pOrderBy, pFrom, pWInfo->wctrlFlags,
159088 iLoop, pWLoop, &revMask);
159089 }else{
159090 revMask = pFrom->revLoop;
@@ -158751,10 +159107,17 @@
159107 rUnsorted, rCost));
159108 }else{
159109 rCost = rUnsorted;
159110 rUnsorted -= 2; /* TUNING: Slight bias in favor of no-sort plans */
159111 }
159112
159113 /* TUNING: A full-scan of a VIEW or subquery in the outer loop
159114 ** is not so bad. */
159115 if( iLoop==0 && (pWLoop->wsFlags & WHERE_VIEWSCAN)!=0 ){
159116 rCost += -10;
159117 nOut += -30;
159118 }
159119
159120 /* Check to see if pWLoop should be added to the set of
159121 ** mxChoice best-so-far paths.
159122 **
159123 ** First look for an existing path among best-so-far paths
@@ -158984,11 +159347,12 @@
159347
159348
159349 pWInfo->nRowOut = pFrom->nRow;
159350
159351 /* Free temporary memory and return success */
159352 assert( db!=0 );
159353 sqlite3DbNNFreeNN(db, pSpace);
159354 return SQLITE_OK;
159355 }
159356
159357 /*
159358 ** Most queries use only a single table (they are not joins) and have
@@ -161217,11 +161581,10 @@
161581 int i;
161582 int nInit = pList ? pList->nExpr : 0;
161583 for(i=0; i<pAppend->nExpr; i++){
161584 sqlite3 *db = pParse->db;
161585 Expr *pDup = sqlite3ExprDup(db, pAppend->a[i].pExpr, 0);
 
161586 if( db->mallocFailed ){
161587 sqlite3ExprDelete(db, pDup);
161588 break;
161589 }
161590 if( bIntToNull ){
@@ -162488,14 +162851,13 @@
162851 }
162852 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrDone);
162853
162854 /* This block runs if reg1 is not NULL, but reg2 is. */
162855 sqlite3VdbeJumpHere(v, addr);
162856 sqlite3VdbeAddOp2(v, OP_IsNull, reg2,
162857 (op==OP_Gt || op==OP_Ge) ? addrDone : lbl);
162858 VdbeCoverage(v);
 
162859 }
162860
162861 /* Register reg1 currently contains csr1.peerVal (the peer-value from csr1).
162862 ** This block adds (or subtracts for DESC) the numeric value in regVal
162863 ** from it. Or, if reg1 is not numeric (it is a NULL, a text value or a blob),
@@ -170068,11 +170430,11 @@
170430 sqlite3DeleteTable(db, pParse->pNewTable);
170431 }
170432 if( pParse->pNewTrigger && !IN_RENAME_OBJECT ){
170433 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
170434 }
170435 if( pParse->pVList ) sqlite3DbNNFreeNN(db, pParse->pVList);
170436 db->pParse = pParentParse;
170437 assert( nErr==0 || pParse->rc!=SQLITE_OK );
170438 return nErr;
170439 }
170440
@@ -171424,22 +171786,23 @@
171786 db->lookaside.pEnd = p;
171787 db->lookaside.bDisable = 0;
171788 db->lookaside.bMalloced = pBuf==0 ?1:0;
171789 db->lookaside.nSlot = nBig+nSm;
171790 }else{
171791 db->lookaside.pStart = 0;
171792 #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE
171793 db->lookaside.pSmallInit = 0;
171794 db->lookaside.pSmallFree = 0;
171795 db->lookaside.pMiddle = 0;
171796 #endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */
171797 db->lookaside.pEnd = 0;
171798 db->lookaside.bDisable = 1;
171799 db->lookaside.sz = 0;
171800 db->lookaside.bMalloced = 0;
171801 db->lookaside.nSlot = 0;
171802 }
171803 db->lookaside.pTrueEnd = db->lookaside.pEnd;
171804 assert( sqlite3LookasideUsed(db,0)==0 );
171805 #endif /* SQLITE_OMIT_LOOKASIDE */
171806 return SQLITE_OK;
171807 }
171808
@@ -171514,10 +171877,11 @@
171877 ** Configuration settings for an individual database connection
171878 */
171879 SQLITE_API int sqlite3_db_config(sqlite3 *db, int op, ...){
171880 va_list ap;
171881 int rc;
171882 sqlite3_mutex_enter(db->mutex);
171883 va_start(ap, op);
171884 switch( op ){
171885 case SQLITE_DBCONFIG_MAINDBNAME: {
171886 /* IMP: R-06824-28531 */
171887 /* IMP: R-36257-52125 */
@@ -171579,10 +171943,11 @@
171943 }
171944 break;
171945 }
171946 }
171947 va_end(ap);
171948 sqlite3_mutex_leave(db->mutex);
171949 return rc;
171950 }
171951
171952 /*
171953 ** This is the default collating function named "BINARY" which is always
@@ -181118,11 +181483,11 @@
181483 p1 = pPhrase->doclist.pList;
181484 p2 = aPoslist;
181485 nDistance = iPrev - nMaxUndeferred;
181486 }
181487
181488 aOut = (char *)sqlite3Fts3MallocZero(nPoslist+FTS3_BUFFER_PADDING);
181489 if( !aOut ){
181490 sqlite3_free(aPoslist);
181491 return SQLITE_NOMEM;
181492 }
181493
@@ -204144,11 +204509,11 @@
204509 sqlite3_bind_value(pUp, 2, aData[2]);
204510 }
204511 sqlite3_free(p);
204512 nChange = 1;
204513 }
204514 for(jj=1; jj<nData-2; jj++){
204515 nChange++;
204516 sqlite3_bind_value(pUp, jj+2, aData[jj+2]);
204517 }
204518 if( nChange ){
204519 sqlite3_step(pUp);
@@ -212503,15 +212868,16 @@
212868 */
212869 static int dbpageBegin(sqlite3_vtab *pVtab){
212870 DbpageTable *pTab = (DbpageTable *)pVtab;
212871 sqlite3 *db = pTab->db;
212872 int i;
212873 int rc = SQLITE_OK;
212874 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
212875 Btree *pBt = db->aDb[i].pBt;
212876 if( pBt ) rc = sqlite3BtreeBeginTrans(pBt, 1, 0);
212877 }
212878 return rc;
212879 }
212880
212881
212882 /*
212883 ** Invoke this routine to register the "dbpage" virtual table module
@@ -219231,11 +219597,11 @@
219597 static void sqlite3Fts5BufferAppendPrintf(int *, Fts5Buffer*, char *zFmt, ...);
219598
219599 static char *sqlite3Fts5Mprintf(int *pRc, const char *zFmt, ...);
219600
219601 #define fts5BufferZero(x) sqlite3Fts5BufferZero(x)
219602 #define fts5BufferAppendVarint(a,b,c) sqlite3Fts5BufferAppendVarint(a,b,(i64)c)
219603 #define fts5BufferFree(a) sqlite3Fts5BufferFree(a)
219604 #define fts5BufferAppendBlob(a,b,c,d) sqlite3Fts5BufferAppendBlob(a,b,c,d)
219605 #define fts5BufferSet(a,b,c,d) sqlite3Fts5BufferSet(a,b,c,d)
219606
219607 #define fts5BufferGrow(pRc,pBuf,nn) ( \
@@ -231108,11 +231474,13 @@
231474 /* Write the rowid. */
231475 if( pWriter->bFirstRowidInDoclist || pWriter->bFirstRowidInPage ){
231476 fts5BufferAppendVarint(&p->rc, &pPage->buf, iRowid);
231477 }else{
231478 assert_nc( p->rc || iRowid>pWriter->iPrevRowid );
231479 fts5BufferAppendVarint(&p->rc, &pPage->buf,
231480 (u64)iRowid - (u64)pWriter->iPrevRowid
231481 );
231482 }
231483 pWriter->iPrevRowid = iRowid;
231484 pWriter->bFirstRowidInDoclist = 0;
231485 pWriter->bFirstRowidInPage = 0;
231486 }
@@ -231872,21 +232240,21 @@
232240 return fts5IndexReturn(p);
232241 }
232242
232243 static void fts5AppendRowid(
232244 Fts5Index *p,
232245 u64 iDelta,
232246 Fts5Iter *pUnused,
232247 Fts5Buffer *pBuf
232248 ){
232249 UNUSED_PARAM(pUnused);
232250 fts5BufferAppendVarint(&p->rc, pBuf, iDelta);
232251 }
232252
232253 static void fts5AppendPoslist(
232254 Fts5Index *p,
232255 u64 iDelta,
232256 Fts5Iter *pMulti,
232257 Fts5Buffer *pBuf
232258 ){
232259 int nData = pMulti->base.nData;
232260 int nByte = nData + 9 + 9 + FTS5_DATA_ZERO_PADDING;
@@ -231957,14 +232325,14 @@
232325 fts5BufferSafeAppendVarint(pBuf, iRowid - *piLastRowid);
232326 *piLastRowid = iRowid;
232327 }
232328 #endif
232329
232330 #define fts5MergeAppendDocid(pBuf, iLastRowid, iRowid) { \
232331 assert( (pBuf)->n!=0 || (iLastRowid)==0 ); \
232332 fts5BufferSafeAppendVarint((pBuf), (u64)(iRowid) - (u64)(iLastRowid)); \
232333 (iLastRowid) = (iRowid); \
232334 }
232335
232336 /*
232337 ** Swap the contents of buffer *p1 with that of *p2.
232338 */
@@ -232231,11 +232599,11 @@
232599 Fts5Buffer *aBuf;
232600 int nBuf = 32;
232601 int nMerge = 1;
232602
232603 void (*xMerge)(Fts5Index*, Fts5Buffer*, int, Fts5Buffer*);
232604 void (*xAppend)(Fts5Index*, u64, Fts5Iter*, Fts5Buffer*);
232605 if( p->pConfig->eDetail==FTS5_DETAIL_NONE ){
232606 xMerge = fts5MergeRowidLists;
232607 xAppend = fts5AppendRowid;
232608 }else{
232609 nMerge = FTS5_MERGE_NLIST-1;
@@ -232270,11 +232638,11 @@
232638 fts5MultiIterNext2(p, p1, &dummy)
232639 ){
232640 Fts5SegIter *pSeg = &p1->aSeg[ p1->aFirst[1].iFirst ];
232641 p1->xSetOutputs(p1, pSeg);
232642 if( p1->base.nData ){
232643 xAppend(p, (u64)p1->base.iRowid-(u64)iLastRowid, p1, &doclist);
232644 iLastRowid = p1->base.iRowid;
232645 }
232646 }
232647 fts5MultiIterFree(p1);
232648 }
@@ -232318,11 +232686,11 @@
232686 }
232687 }
232688 iLastRowid = 0;
232689 }
232690
232691 xAppend(p, (u64)p1->base.iRowid-(u64)iLastRowid, p1, &doclist);
232692 iLastRowid = p1->base.iRowid;
232693 }
232694
232695 assert( (nBuf%nMerge)==0 );
232696 for(i=0; i<nBuf; i+=nMerge){
@@ -236634,11 +237002,11 @@
237002 int nArg, /* Number of args */
237003 sqlite3_value **apUnused /* Function arguments */
237004 ){
237005 assert( nArg==0 );
237006 UNUSED_PARAM2(nArg, apUnused);
237007 sqlite3_result_text(pCtx, "fts5: 2022-09-02 21:19:24 da7af290960ab8a04a1f55cdc5eeac36b47fa194edf67f0a05daa4b7f2a4071c", -1, SQLITE_TRANSIENT);
237008 }
237009
237010 /*
237011 ** Return true if zName is the extension on one of the shadow tables used
237012 ** by this module.
237013
+16 -8
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,13 +144,13 @@
144144
**
145145
** See also: [sqlite3_libversion()],
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149
-#define SQLITE_VERSION "3.39.2"
150
-#define SQLITE_VERSION_NUMBER 3039002
151
-#define SQLITE_SOURCE_ID "2022-07-21 12:26:01 9141e873c575b049ce7aeaf313d05966f1966087caf33a6c80d2416a28571a21"
149
+#define SQLITE_VERSION "3.40.0"
150
+#define SQLITE_VERSION_NUMBER 3040000
151
+#define SQLITE_SOURCE_ID "2022-09-02 21:19:24 da7af290960ab8a04a1f55cdc5eeac36b47fa194edf67f0a05daa4b7f2a4071c"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -3422,10 +3422,13 @@
34223422
**
34233423
** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt>
34243424
** <dd>The database is opened [shared cache] enabled, overriding
34253425
** the default shared cache setting provided by
34263426
** [sqlite3_enable_shared_cache()].)^
3427
+** The [use of shared cache mode is discouraged] and hence shared cache
3428
+** capabilities may be omitted from many builds of SQLite. In such cases,
3429
+** this option is a no-op.
34273430
**
34283431
** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt>
34293432
** <dd>The database is opened [shared cache] disabled, overriding
34303433
** the default shared cache setting provided by
34313434
** [sqlite3_enable_shared_cache()].)^
@@ -3437,11 +3440,11 @@
34373440
** connection as soon as the connection is created. In addition to setting
34383441
** the extended result code mode, this flag also causes [sqlite3_open_v2()]
34393442
** to return an extended result code.</dd>
34403443
**
34413444
** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>
3442
-** <dd>The database filename is not allowed to be a symbolic link</dd>
3445
+** <dd>The database filename is not allowed to contain a symbolic link</dd>
34433446
** </dl>)^
34443447
**
34453448
** If the 3rd parameter to sqlite3_open_v2() is not one of the
34463449
** required combinations shown above optionally combined with other
34473450
** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
@@ -6463,11 +6466,11 @@
64636466
**
64646467
** ^The sqlite3_autovacuum_pages(D,C,P,X) interface registers a callback
64656468
** function C that is invoked prior to each autovacuum of the database
64666469
** file. ^The callback is passed a copy of the generic data pointer (P),
64676470
** the schema-name of the attached database that is being autovacuumed,
6468
-** the the size of the database file in pages, the number of free pages,
6471
+** the size of the database file in pages, the number of free pages,
64696472
** and the number of bytes per page, respectively. The callback should
64706473
** return the number of free pages that should be removed by the
64716474
** autovacuum. ^If the callback returns zero, then no autovacuum happens.
64726475
** ^If the value returned is greater than or equal to the number of
64736476
** free pages, then a complete autovacuum happens.
@@ -6583,10 +6586,15 @@
65836586
**
65846587
** ^(This routine enables or disables the sharing of the database cache
65856588
** and schema data structures between [database connection | connections]
65866589
** to the same database. Sharing is enabled if the argument is true
65876590
** and disabled if the argument is false.)^
6591
+**
6592
+** This interface is omitted if SQLite is compiled with
6593
+** [-DSQLITE_OMIT_SHARED_CACHE]. The [-DSQLITE_OMIT_SHARED_CACHE]
6594
+** compile-time option is recommended because the
6595
+** [use of shared cache mode is discouraged].
65886596
**
65896597
** ^Cache sharing is enabled and disabled for an entire process.
65906598
** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]).
65916599
** In prior versions of SQLite,
65926600
** sharing was enabled or disabled for each thread separately.
@@ -6682,11 +6690,11 @@
66826690
** ^Setting the heap limits to zero disables the heap limiter mechanism.
66836691
**
66846692
** ^The soft heap limit may not be greater than the hard heap limit.
66856693
** ^If the hard heap limit is enabled and if sqlite3_soft_heap_limit(N)
66866694
** is invoked with a value of N that is greater than the hard heap limit,
6687
-** the the soft heap limit is set to the value of the hard heap limit.
6695
+** the soft heap limit is set to the value of the hard heap limit.
66886696
** ^The soft heap limit is automatically enabled whenever the hard heap
66896697
** limit is enabled. ^When sqlite3_hard_heap_limit64(N) is invoked and
66906698
** the soft heap limit is outside the range of 1..N, then the soft heap
66916699
** limit is set to N. ^Invoking sqlite3_soft_heap_limit64(0) when the
66926700
** hard heap limit is enabled makes the soft heap limit equal to the
@@ -8977,11 +8985,11 @@
89778985
** sqlite3_backup_init() is called and before the corresponding call to
89788986
** sqlite3_backup_finish(). SQLite does not currently check to see
89798987
** if the application incorrectly accesses the destination [database connection]
89808988
** and so no error code is reported, but the operations may malfunction
89818989
** nevertheless. Use of the destination database connection while a
8982
-** backup is in progress might also also cause a mutex deadlock.
8990
+** backup is in progress might also cause a mutex deadlock.
89838991
**
89848992
** If running in [shared cache mode], the application must
89858993
** guarantee that the shared cache used by the destination database
89868994
** is not accessed while the backup is running. In practice this means
89878995
** that the application must guarantee that the disk file being
@@ -9405,11 +9413,11 @@
94059413
** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the
94069414
** meaning of each of these checkpoint modes.
94079415
*/
94089416
#define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */
94099417
#define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */
9410
-#define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for for readers */
9418
+#define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for readers */
94119419
#define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */
94129420
94139421
/*
94149422
** CAPI3REF: Virtual Table Interface Configuration
94159423
**
94169424
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,13 +144,13 @@
144 **
145 ** See also: [sqlite3_libversion()],
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.39.2"
150 #define SQLITE_VERSION_NUMBER 3039002
151 #define SQLITE_SOURCE_ID "2022-07-21 12:26:01 9141e873c575b049ce7aeaf313d05966f1966087caf33a6c80d2416a28571a21"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -3422,10 +3422,13 @@
3422 **
3423 ** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt>
3424 ** <dd>The database is opened [shared cache] enabled, overriding
3425 ** the default shared cache setting provided by
3426 ** [sqlite3_enable_shared_cache()].)^
 
 
 
3427 **
3428 ** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt>
3429 ** <dd>The database is opened [shared cache] disabled, overriding
3430 ** the default shared cache setting provided by
3431 ** [sqlite3_enable_shared_cache()].)^
@@ -3437,11 +3440,11 @@
3437 ** connection as soon as the connection is created. In addition to setting
3438 ** the extended result code mode, this flag also causes [sqlite3_open_v2()]
3439 ** to return an extended result code.</dd>
3440 **
3441 ** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>
3442 ** <dd>The database filename is not allowed to be a symbolic link</dd>
3443 ** </dl>)^
3444 **
3445 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
3446 ** required combinations shown above optionally combined with other
3447 ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
@@ -6463,11 +6466,11 @@
6463 **
6464 ** ^The sqlite3_autovacuum_pages(D,C,P,X) interface registers a callback
6465 ** function C that is invoked prior to each autovacuum of the database
6466 ** file. ^The callback is passed a copy of the generic data pointer (P),
6467 ** the schema-name of the attached database that is being autovacuumed,
6468 ** the the size of the database file in pages, the number of free pages,
6469 ** and the number of bytes per page, respectively. The callback should
6470 ** return the number of free pages that should be removed by the
6471 ** autovacuum. ^If the callback returns zero, then no autovacuum happens.
6472 ** ^If the value returned is greater than or equal to the number of
6473 ** free pages, then a complete autovacuum happens.
@@ -6583,10 +6586,15 @@
6583 **
6584 ** ^(This routine enables or disables the sharing of the database cache
6585 ** and schema data structures between [database connection | connections]
6586 ** to the same database. Sharing is enabled if the argument is true
6587 ** and disabled if the argument is false.)^
 
 
 
 
 
6588 **
6589 ** ^Cache sharing is enabled and disabled for an entire process.
6590 ** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]).
6591 ** In prior versions of SQLite,
6592 ** sharing was enabled or disabled for each thread separately.
@@ -6682,11 +6690,11 @@
6682 ** ^Setting the heap limits to zero disables the heap limiter mechanism.
6683 **
6684 ** ^The soft heap limit may not be greater than the hard heap limit.
6685 ** ^If the hard heap limit is enabled and if sqlite3_soft_heap_limit(N)
6686 ** is invoked with a value of N that is greater than the hard heap limit,
6687 ** the the soft heap limit is set to the value of the hard heap limit.
6688 ** ^The soft heap limit is automatically enabled whenever the hard heap
6689 ** limit is enabled. ^When sqlite3_hard_heap_limit64(N) is invoked and
6690 ** the soft heap limit is outside the range of 1..N, then the soft heap
6691 ** limit is set to N. ^Invoking sqlite3_soft_heap_limit64(0) when the
6692 ** hard heap limit is enabled makes the soft heap limit equal to the
@@ -8977,11 +8985,11 @@
8977 ** sqlite3_backup_init() is called and before the corresponding call to
8978 ** sqlite3_backup_finish(). SQLite does not currently check to see
8979 ** if the application incorrectly accesses the destination [database connection]
8980 ** and so no error code is reported, but the operations may malfunction
8981 ** nevertheless. Use of the destination database connection while a
8982 ** backup is in progress might also also cause a mutex deadlock.
8983 **
8984 ** If running in [shared cache mode], the application must
8985 ** guarantee that the shared cache used by the destination database
8986 ** is not accessed while the backup is running. In practice this means
8987 ** that the application must guarantee that the disk file being
@@ -9405,11 +9413,11 @@
9405 ** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the
9406 ** meaning of each of these checkpoint modes.
9407 */
9408 #define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */
9409 #define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */
9410 #define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for for readers */
9411 #define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */
9412
9413 /*
9414 ** CAPI3REF: Virtual Table Interface Configuration
9415 **
9416
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -144,13 +144,13 @@
144 **
145 ** See also: [sqlite3_libversion()],
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.40.0"
150 #define SQLITE_VERSION_NUMBER 3040000
151 #define SQLITE_SOURCE_ID "2022-09-02 21:19:24 da7af290960ab8a04a1f55cdc5eeac36b47fa194edf67f0a05daa4b7f2a4071c"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -3422,10 +3422,13 @@
3422 **
3423 ** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt>
3424 ** <dd>The database is opened [shared cache] enabled, overriding
3425 ** the default shared cache setting provided by
3426 ** [sqlite3_enable_shared_cache()].)^
3427 ** The [use of shared cache mode is discouraged] and hence shared cache
3428 ** capabilities may be omitted from many builds of SQLite. In such cases,
3429 ** this option is a no-op.
3430 **
3431 ** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt>
3432 ** <dd>The database is opened [shared cache] disabled, overriding
3433 ** the default shared cache setting provided by
3434 ** [sqlite3_enable_shared_cache()].)^
@@ -3437,11 +3440,11 @@
3440 ** connection as soon as the connection is created. In addition to setting
3441 ** the extended result code mode, this flag also causes [sqlite3_open_v2()]
3442 ** to return an extended result code.</dd>
3443 **
3444 ** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>
3445 ** <dd>The database filename is not allowed to contain a symbolic link</dd>
3446 ** </dl>)^
3447 **
3448 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
3449 ** required combinations shown above optionally combined with other
3450 ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
@@ -6463,11 +6466,11 @@
6466 **
6467 ** ^The sqlite3_autovacuum_pages(D,C,P,X) interface registers a callback
6468 ** function C that is invoked prior to each autovacuum of the database
6469 ** file. ^The callback is passed a copy of the generic data pointer (P),
6470 ** the schema-name of the attached database that is being autovacuumed,
6471 ** the size of the database file in pages, the number of free pages,
6472 ** and the number of bytes per page, respectively. The callback should
6473 ** return the number of free pages that should be removed by the
6474 ** autovacuum. ^If the callback returns zero, then no autovacuum happens.
6475 ** ^If the value returned is greater than or equal to the number of
6476 ** free pages, then a complete autovacuum happens.
@@ -6583,10 +6586,15 @@
6586 **
6587 ** ^(This routine enables or disables the sharing of the database cache
6588 ** and schema data structures between [database connection | connections]
6589 ** to the same database. Sharing is enabled if the argument is true
6590 ** and disabled if the argument is false.)^
6591 **
6592 ** This interface is omitted if SQLite is compiled with
6593 ** [-DSQLITE_OMIT_SHARED_CACHE]. The [-DSQLITE_OMIT_SHARED_CACHE]
6594 ** compile-time option is recommended because the
6595 ** [use of shared cache mode is discouraged].
6596 **
6597 ** ^Cache sharing is enabled and disabled for an entire process.
6598 ** This is a change as of SQLite [version 3.5.0] ([dateof:3.5.0]).
6599 ** In prior versions of SQLite,
6600 ** sharing was enabled or disabled for each thread separately.
@@ -6682,11 +6690,11 @@
6690 ** ^Setting the heap limits to zero disables the heap limiter mechanism.
6691 **
6692 ** ^The soft heap limit may not be greater than the hard heap limit.
6693 ** ^If the hard heap limit is enabled and if sqlite3_soft_heap_limit(N)
6694 ** is invoked with a value of N that is greater than the hard heap limit,
6695 ** the soft heap limit is set to the value of the hard heap limit.
6696 ** ^The soft heap limit is automatically enabled whenever the hard heap
6697 ** limit is enabled. ^When sqlite3_hard_heap_limit64(N) is invoked and
6698 ** the soft heap limit is outside the range of 1..N, then the soft heap
6699 ** limit is set to N. ^Invoking sqlite3_soft_heap_limit64(0) when the
6700 ** hard heap limit is enabled makes the soft heap limit equal to the
@@ -8977,11 +8985,11 @@
8985 ** sqlite3_backup_init() is called and before the corresponding call to
8986 ** sqlite3_backup_finish(). SQLite does not currently check to see
8987 ** if the application incorrectly accesses the destination [database connection]
8988 ** and so no error code is reported, but the operations may malfunction
8989 ** nevertheless. Use of the destination database connection while a
8990 ** backup is in progress might also cause a mutex deadlock.
8991 **
8992 ** If running in [shared cache mode], the application must
8993 ** guarantee that the shared cache used by the destination database
8994 ** is not accessed while the backup is running. In practice this means
8995 ** that the application must guarantee that the disk file being
@@ -9405,11 +9413,11 @@
9413 ** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the
9414 ** meaning of each of these checkpoint modes.
9415 */
9416 #define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */
9417 #define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */
9418 #define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for readers */
9419 #define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */
9420
9421 /*
9422 ** CAPI3REF: Virtual Table Interface Configuration
9423 **
9424
+2 -2
--- src/builtin.c
+++ src/builtin.c
@@ -148,12 +148,12 @@
148148
if( i>0 && i<=count(aBuiltinFiles) ){
149149
blob_appendf(pOut, "/* %s */\n", aBuiltinFiles[i-1].zName);
150150
blob_append(pOut, (const char*)aBuiltinFiles[i-1].pData,
151151
aBuiltinFiles[i-1].nByte);
152152
}
153
- while( fossil_isdigit(zList[0]) ) zList++;
154
- if( zList[0]==',' ) zList++;
153
+ while( zList[0] && fossil_isdigit(zList[0]) ) zList++;
154
+ while( zList[0] && !fossil_isdigit(zList[0]) ) zList++;
155155
}
156156
return;
157157
}
158158
159159
/*
160160
--- src/builtin.c
+++ src/builtin.c
@@ -148,12 +148,12 @@
148 if( i>0 && i<=count(aBuiltinFiles) ){
149 blob_appendf(pOut, "/* %s */\n", aBuiltinFiles[i-1].zName);
150 blob_append(pOut, (const char*)aBuiltinFiles[i-1].pData,
151 aBuiltinFiles[i-1].nByte);
152 }
153 while( fossil_isdigit(zList[0]) ) zList++;
154 if( zList[0]==',' ) zList++;
155 }
156 return;
157 }
158
159 /*
160
--- src/builtin.c
+++ src/builtin.c
@@ -148,12 +148,12 @@
148 if( i>0 && i<=count(aBuiltinFiles) ){
149 blob_appendf(pOut, "/* %s */\n", aBuiltinFiles[i-1].zName);
150 blob_append(pOut, (const char*)aBuiltinFiles[i-1].pData,
151 aBuiltinFiles[i-1].nByte);
152 }
153 while( zList[0] && fossil_isdigit(zList[0]) ) zList++;
154 while( zList[0] && !fossil_isdigit(zList[0]) ) zList++;
155 }
156 return;
157 }
158
159 /*
160
+1 -1
--- src/checkin.c
+++ src/checkin.c
@@ -2088,11 +2088,11 @@
20882088
char **pB = (char**)b;
20892089
return fossil_strcmp(pA[0], pB[0]);
20902090
}
20912091
20922092
/*
2093
-** COMMAND: ci*
2093
+** COMMAND: ci#
20942094
** COMMAND: commit
20952095
**
20962096
** Usage: %fossil commit ?OPTIONS? ?FILE...?
20972097
** or: %fossil ci ?OPTIONS? ?FILE...?
20982098
**
20992099
--- src/checkin.c
+++ src/checkin.c
@@ -2088,11 +2088,11 @@
2088 char **pB = (char**)b;
2089 return fossil_strcmp(pA[0], pB[0]);
2090 }
2091
2092 /*
2093 ** COMMAND: ci*
2094 ** COMMAND: commit
2095 **
2096 ** Usage: %fossil commit ?OPTIONS? ?FILE...?
2097 ** or: %fossil ci ?OPTIONS? ?FILE...?
2098 **
2099
--- src/checkin.c
+++ src/checkin.c
@@ -2088,11 +2088,11 @@
2088 char **pB = (char**)b;
2089 return fossil_strcmp(pA[0], pB[0]);
2090 }
2091
2092 /*
2093 ** COMMAND: ci#
2094 ** COMMAND: commit
2095 **
2096 ** Usage: %fossil commit ?OPTIONS? ?FILE...?
2097 ** or: %fossil ci ?OPTIONS? ?FILE...?
2098 **
2099
+1 -1
--- src/checkout.c
+++ src/checkout.c
@@ -257,11 +257,11 @@
257257
}
258258
259259
260260
/*
261261
** COMMAND: checkout*
262
-** COMMAND: co*
262
+** COMMAND: co#
263263
**
264264
** Usage: %fossil checkout ?VERSION | --latest? ?OPTIONS?
265265
** or: %fossil co ?VERSION | --latest? ?OPTIONS?
266266
**
267267
** NOTE: Most people use "fossil update" instead of "fossil checkout" for
268268
--- src/checkout.c
+++ src/checkout.c
@@ -257,11 +257,11 @@
257 }
258
259
260 /*
261 ** COMMAND: checkout*
262 ** COMMAND: co*
263 **
264 ** Usage: %fossil checkout ?VERSION | --latest? ?OPTIONS?
265 ** or: %fossil co ?VERSION | --latest? ?OPTIONS?
266 **
267 ** NOTE: Most people use "fossil update" instead of "fossil checkout" for
268
--- src/checkout.c
+++ src/checkout.c
@@ -257,11 +257,11 @@
257 }
258
259
260 /*
261 ** COMMAND: checkout*
262 ** COMMAND: co#
263 **
264 ** Usage: %fossil checkout ?VERSION | --latest? ?OPTIONS?
265 ** or: %fossil co ?VERSION | --latest? ?OPTIONS?
266 **
267 ** NOTE: Most people use "fossil update" instead of "fossil checkout" for
268
+1 -1
--- src/db.c
+++ src/db.c
@@ -2803,11 +2803,11 @@
28032803
manifest_crosslink(rid, &manifest, MC_NONE);
28042804
}
28052805
}
28062806
28072807
/*
2808
-** COMMAND: new*
2808
+** COMMAND: new#
28092809
** COMMAND: init
28102810
**
28112811
** Usage: %fossil new ?OPTIONS? FILENAME
28122812
** or: %fossil init ?OPTIONS? FILENAME
28132813
**
28142814
--- src/db.c
+++ src/db.c
@@ -2803,11 +2803,11 @@
2803 manifest_crosslink(rid, &manifest, MC_NONE);
2804 }
2805 }
2806
2807 /*
2808 ** COMMAND: new*
2809 ** COMMAND: init
2810 **
2811 ** Usage: %fossil new ?OPTIONS? FILENAME
2812 ** or: %fossil init ?OPTIONS? FILENAME
2813 **
2814
--- src/db.c
+++ src/db.c
@@ -2803,11 +2803,11 @@
2803 manifest_crosslink(rid, &manifest, MC_NONE);
2804 }
2805 }
2806
2807 /*
2808 ** COMMAND: new#
2809 ** COMMAND: init
2810 **
2811 ** Usage: %fossil new ?OPTIONS? FILENAME
2812 ** or: %fossil init ?OPTIONS? FILENAME
2813 **
2814
--- src/default.css
+++ src/default.css
@@ -236,10 +236,13 @@
236236
}
237237
.columns li {
238238
break-inside: avoid;
239239
page-break-inside: avoid;
240240
}
241
+body.help .columns li {
242
+ white-space: nowrap /* keep command name aliases from wrapping */;
243
+}
241244
.filetree {
242245
margin: 1em 0;
243246
line-height: 1.5;
244247
}
245248
.filetree > ul {
246249
--- src/default.css
+++ src/default.css
@@ -236,10 +236,13 @@
236 }
237 .columns li {
238 break-inside: avoid;
239 page-break-inside: avoid;
240 }
 
 
 
241 .filetree {
242 margin: 1em 0;
243 line-height: 1.5;
244 }
245 .filetree > ul {
246
--- src/default.css
+++ src/default.css
@@ -236,10 +236,13 @@
236 }
237 .columns li {
238 break-inside: avoid;
239 page-break-inside: avoid;
240 }
241 body.help .columns li {
242 white-space: nowrap /* keep command name aliases from wrapping */;
243 }
244 .filetree {
245 margin: 1em 0;
246 line-height: 1.5;
247 }
248 .filetree > ul {
249
+124 -31
--- src/dispatch.c
+++ src/dispatch.c
@@ -31,10 +31,11 @@
3131
*/
3232
struct CmdOrPage {
3333
const char *zName; /* Name. Webpages start with "/". Commands do not */
3434
void (*xFunc)(void); /* Implementation function, or NULL for settings */
3535
const char *zHelp; /* Raw help text */
36
+ int iHelp; /* Index of help variable */
3637
unsigned int eCmdFlags; /* Flags */
3738
};
3839
3940
/***************************************************************************
4041
** These macros must match similar macros in mkindex.c
@@ -51,10 +52,11 @@
5152
#define CMDFLAG_BOOLEAN 0x0100 /* A boolean setting */
5253
#define CMDFLAG_RAWCONTENT 0x0200 /* Do not interpret POST content */
5354
/* NOTE: 0x0400 = CMDFLAG_SENSITIVE in mkindex.c! */
5455
#define CMDFLAG_HIDDEN 0x0800 /* Elide from most listings */
5556
#define CMDFLAG_LDAVG_EXEMPT 0x1000 /* Exempt from load_control() */
57
+#define CMDFLAG_ALIAS 0x2000 /* Command aliases */
5658
/**************************************************************************/
5759
5860
/* Values for the 2nd parameter to dispatch_name_search() */
5961
#define CMDFLAG_ANY 0x0038 /* Match anything */
6062
#define CMDFLAG_PREFIX 0x0200 /* Prefix match is ok */
@@ -77,10 +79,11 @@
7779
** source code files looking for header comments on the functions that
7880
** implement command and webpages.
7981
*/
8082
#include "page_index.h"
8183
#define MX_COMMAND count(aCommand)
84
+#define MX_HELP_DUP 5 /* Upper bound estimate on help string duplication */
8285
8386
/*
8487
** Given a command, webpage, or setting name in zName, find the corresponding
8588
** CmdOrPage object and return a pointer to that object in *ppCmd.
8689
**
@@ -546,45 +549,65 @@
546549
/*
547550
** Display help for all commands based on provided flags.
548551
*/
549552
static void display_all_help(int mask, int useHtml, int rawOut){
550553
int i;
554
+ unsigned char occHelp[FOSSIL_MX_CMDIDX] = {0}; /* Help string occurrences */
555
+ int bktHelp[FOSSIL_MX_CMDIDX][MX_HELP_DUP] = {0};/* Help strings -> commands*/
551556
if( useHtml ) fossil_print("<!--\n");
552557
fossil_print("Help text for:\n");
553558
if( mask & CMDFLAG_1ST_TIER ) fossil_print(" * Commands\n");
554559
if( mask & CMDFLAG_2ND_TIER ) fossil_print(" * Auxiliary commands\n");
560
+ if( mask & CMDFLAG_ALIAS ) fossil_print(" * Aliases\n");
555561
if( mask & CMDFLAG_TEST ) fossil_print(" * Test commands\n");
556562
if( mask & CMDFLAG_WEBPAGE ) fossil_print(" * Web pages\n");
557563
if( mask & CMDFLAG_SETTING ) fossil_print(" * Settings\n");
558564
if( useHtml ){
559565
fossil_print("-->\n");
560566
fossil_print("<!-- start_all_help -->\n");
561567
}else{
562568
fossil_print("---\n");
563569
}
570
+ /* Fill in help string buckets */
571
+ for(i=0; i<MX_COMMAND; i++){
572
+ if( (aCommand[i].eCmdFlags & mask)==0 ) continue;
573
+ else if(aCommand[i].eCmdFlags & CMDFLAG_HIDDEN) continue;
574
+ bktHelp[aCommand[i].iHelp][occHelp[aCommand[i].iHelp]++] = i;
575
+ }
564576
for(i=0; i<MX_COMMAND; i++){
565577
if( (aCommand[i].eCmdFlags & mask)==0 ) continue;
566578
else if(aCommand[i].eCmdFlags & CMDFLAG_HIDDEN) continue;
567
- if( useHtml ){
568
- Blob html;
569
- blob_init(&html, 0, 0);
570
- help_to_html(aCommand[i].zHelp, &html);
571
- fossil_print("<h1>%h</h1>\n", aCommand[i].zName);
572
- fossil_print("%s\n<hr>\n", blob_str(&html));
573
- blob_reset(&html);
574
- }else if( rawOut ){
575
- fossil_print("# %s\n", aCommand[i].zName);
576
- fossil_print("%s\n\n", aCommand[i].zHelp);
577
- }else{
578
- Blob txt;
579
- blob_init(&txt, 0, 0);
580
- help_to_text(aCommand[i].zHelp, &txt);
581
- fossil_print("# %s%s\n", aCommand[i].zName,
582
- (aCommand[i].eCmdFlags & CMDFLAG_VERSIONABLE)!=0 ?
583
- " (versionable)" : "");
584
- fossil_print("%s\n\n", blob_str(&txt));
585
- blob_reset(&txt);
579
+ if( occHelp[aCommand[i].iHelp] > 0 ){
580
+ int j;
581
+ if( useHtml ){
582
+ Blob html;
583
+ blob_init(&html, 0, 0);
584
+ help_to_html(aCommand[i].zHelp, &html);
585
+ for(j=0; j<occHelp[aCommand[i].iHelp]; j++){
586
+ fossil_print("<h1>%h</h1>\n",
587
+ aCommand[bktHelp[aCommand[i].iHelp][j]].zName);
588
+ }
589
+ fossil_print("%s\n<hr>\n", blob_str(&html));
590
+ blob_reset(&html);
591
+ }else if( rawOut ){
592
+ for(j=0; j<occHelp[aCommand[i].iHelp]; j++)
593
+ fossil_print("# %s\n", aCommand[bktHelp[aCommand[i].iHelp][j]].zName);
594
+ fossil_print("%s\n\n", aCommand[i].zHelp);
595
+ }else{
596
+ Blob txt;
597
+ blob_init(&txt, 0, 0);
598
+ help_to_text(aCommand[i].zHelp, &txt);
599
+ for(j=0; j<occHelp[aCommand[i].iHelp]; j++){
600
+ fossil_print("# %s%s\n",
601
+ aCommand[bktHelp[aCommand[i].iHelp][j]].zName,
602
+ (aCommand[i].eCmdFlags & CMDFLAG_VERSIONABLE)!=0 ?
603
+ " (versionable)" : "");
604
+ }
605
+ fossil_print("%s\n\n", blob_str(&txt));
606
+ blob_reset(&txt);
607
+ }
608
+ occHelp[aCommand[i].iHelp] = 0;
586609
}
587610
}
588611
if( useHtml ){
589612
fossil_print("<!-- end_all_help -->\n");
590613
}else{
@@ -601,17 +624,19 @@
601624
** Show help text for commands and pages. Useful for proof-reading.
602625
** Defaults to just the CLI commands. Specify --www to see only the
603626
** web pages, or --everything to see both commands and pages.
604627
**
605628
** Options:
606
-** -e|--everything Show all commands and pages.
629
+** -a|--aliases Show aliases.
630
+** -e|--everything Show all commands and pages. Omit aliases to
631
+** avoid duplicates.
632
+** -h|--html Transform output to HTML.
633
+** -o|--options Show global options.
634
+** -r|--raw No output formatting.
635
+** -s|--settings Show settings.
607636
** -t|--test Include test- commands.
608637
** -w|--www Show WWW pages.
609
-** -s|--settings Show settings.
610
-** -h|--html Transform output to HTML.
611
-** -r|--raw No output formatting.
612
-** -o|--options Show global options.
613638
*/
614639
void test_all_help_cmd(void){
615640
int mask = CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER;
616641
int useHtml = find_option("html","h",0)!=0;
617642
int rawOut = find_option("raw","r",0)!=0;
@@ -619,15 +644,18 @@
619644
if( find_option("www","w",0) ){
620645
mask = CMDFLAG_WEBPAGE;
621646
}
622647
if( find_option("everything","e",0) ){
623648
mask = CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER | CMDFLAG_WEBPAGE |
624
- CMDFLAG_SETTING | CMDFLAG_TEST;
649
+ CMDFLAG_ALIAS | CMDFLAG_SETTING | CMDFLAG_TEST;
625650
}
626651
if( find_option("settings","s",0) ){
627652
mask = CMDFLAG_SETTING;
628653
}
654
+ if( find_option("aliases","a",0) ){
655
+ mask = CMDFLAG_ALIAS;
656
+ }
629657
if( find_option("test","t",0) ){
630658
mask |= CMDFLAG_TEST;
631659
}
632660
display_all_help(mask, useHtml, rawOut);
633661
}
@@ -655,10 +683,12 @@
655683
countCmds( CMDFLAG_COMMAND ));
656684
fossil_print(" 1st tier %4d\n",
657685
countCmds( CMDFLAG_1ST_TIER ));
658686
fossil_print(" 2nd tier %4d\n",
659687
countCmds( CMDFLAG_2ND_TIER ));
688
+ fossil_print(" alias %4d\n",
689
+ countCmds( CMDFLAG_ALIAS ));
660690
fossil_print(" test %4d\n",
661691
countCmds( CMDFLAG_TEST ));
662692
fossil_print("web-pages: %4d\n",
663693
countCmds( CMDFLAG_WEBPAGE ));
664694
fossil_print("settings: %4d\n",
@@ -828,26 +858,56 @@
828858
@ </div>
829859
}
830860
}
831861
}else{
832862
int i;
833
-
863
+ unsigned char occHelp[FOSSIL_MX_CMDIDX] = {0}; /* Help str occurrences */
864
+ int bktHelp[FOSSIL_MX_CMDIDX][MX_HELP_DUP] = {0};/* Help str -> commands */
834865
style_header("Help");
835866
836867
@ <a name='commands'></a>
837868
@ <h1>Available commands:</h1>
838869
@ <div class="columns" style="column-width: 12ex;">
839870
@ <ul>
871
+ /* Fill in help string buckets */
872
+ for(i=0; i<MX_COMMAND; i++){
873
+ if(aCommand[i].eCmdFlags & CMDFLAG_HIDDEN) continue;
874
+ bktHelp[aCommand[i].iHelp][occHelp[aCommand[i].iHelp]++] = i;
875
+ }
840876
for(i=0; i<MX_COMMAND; i++){
841877
const char *z = aCommand[i].zName;
842878
const char *zBoldOn = aCommand[i].eCmdFlags&CMDFLAG_1ST_TIER?"<b>" :"";
843879
const char *zBoldOff = aCommand[i].eCmdFlags&CMDFLAG_1ST_TIER?"</b>":"";
844880
if( '/'==*z || strncmp(z,"test",4)==0 ) continue;
845881
if( (aCommand[i].eCmdFlags & CMDFLAG_SETTING)!=0 ) continue;
846882
else if( (aCommand[i].eCmdFlags & CMDFLAG_HIDDEN)!=0 ) continue;
847
- @ <li><a href="%R/help?cmd=%s(z)">%s(zBoldOn)%s(z)%s(zBoldOff)</a></li>
883
+ else if( (aCommand[i].eCmdFlags & CMDFLAG_ALIAS)!=0 ) continue;
884
+ @ <li><a href="%R/help?cmd=%s(z)">%s(zBoldOn)%s(z)%s(zBoldOff)</a>
885
+ /* Output aliases */
886
+ if( occHelp[aCommand[i].iHelp] > 1 ){
887
+ int j;
888
+ int aliases[MX_HELP_DUP], nAliases=0;
889
+ for(j=0; j<occHelp[aCommand[i].iHelp]; j++){
890
+ if( bktHelp[aCommand[i].iHelp][j] != i ){
891
+ if( aCommand[bktHelp[aCommand[i].iHelp][j]].eCmdFlags & CMDFLAG_ALIAS ){
892
+ aliases[nAliases++] = bktHelp[aCommand[i].iHelp][j];
893
+ }
894
+ }
895
+ }
896
+ if( nAliases>0 ){
897
+ int k;
898
+ @(\
899
+ for(k=0; k<nAliases; k++){
900
+ @<a href="%R/help?cmd=%s(aCommand[aliases[k]].zName)">\
901
+ @%s(aCommand[aliases[k]].zName)</a>%s((k<nAliases-1)?", ":"")\
902
+ }
903
+ @)\
904
+ }
905
+ }
906
+ @ </li>
848907
}
908
+
849909
@ </ul></div>
850910
851911
@ <a name='webpages'></a>
852912
@ <h1>Available web UI pages:</h1>
853913
@ <div class="columns" style="column-width: 18ex;">
@@ -905,22 +965,31 @@
905965
**
906966
** Show all help text on a single page. Useful for proof-reading.
907967
*/
908968
void test_all_help_page(void){
909969
int i;
970
+ unsigned char occHelp[FOSSIL_MX_CMDIDX] = {0}; /* Help string occurrences */
971
+ int bktHelp[FOSSIL_MX_CMDIDX][MX_HELP_DUP] = {0};/* Help strings -> commands*/
910972
Blob buf;
911973
blob_init(&buf,0,0);
912974
style_set_current_feature("test");
913975
style_header("All Help Text");
914976
@ <dl>
977
+ /* Fill in help string buckets */
978
+ for(i=0; i<MX_COMMAND; i++){
979
+ if(aCommand[i].eCmdFlags & CMDFLAG_HIDDEN) continue;
980
+ bktHelp[aCommand[i].iHelp][occHelp[aCommand[i].iHelp]++] = i;
981
+ }
915982
for(i=0; i<MX_COMMAND; i++){
916983
const char *zDesc;
917984
unsigned int e = aCommand[i].eCmdFlags;
918985
if( e & CMDFLAG_1ST_TIER ){
919986
zDesc = "1st tier command";
920987
}else if( e & CMDFLAG_2ND_TIER ){
921988
zDesc = "2nd tier command";
989
+ }else if( e & CMDFLAG_ALIAS ){
990
+ zDesc = "alias";
922991
}else if( e & CMDFLAG_TEST ){
923992
zDesc = "test command";
924993
}else if( e & CMDFLAG_WEBPAGE ){
925994
if( e & CMDFLAG_RAWCONTENT ){
926995
zDesc = "raw-content web page";
@@ -940,14 +1009,38 @@
9401009
}
9411010
blob_appendf(&buf,"setting");
9421011
zDesc = blob_str(&buf);
9431012
}
9441013
if( memcmp(aCommand[i].zName, "test", 4)==0 ) continue;
945
- @ <dt><big><b>%s(aCommand[i].zName)</b></big> (%s(zDesc))</dt>
946
- @ <dd>
947
- help_to_html(aCommand[i].zHelp, cgi_output_blob());
948
- @ </dd>
1014
+ if( occHelp[aCommand[i].iHelp] > 0 ){
1015
+ int j;
1016
+ for(j=0; j<occHelp[aCommand[i].iHelp]; j++){
1017
+ unsigned int e = aCommand[bktHelp[aCommand[i].iHelp][j]].eCmdFlags;
1018
+ if( e & CMDFLAG_1ST_TIER ){
1019
+ zDesc = "1st tier command";
1020
+ }else if( e & CMDFLAG_2ND_TIER ){
1021
+ zDesc = "2nd tier command";
1022
+ }else if( e & CMDFLAG_ALIAS ){
1023
+ zDesc = "alias";
1024
+ }else if( e & CMDFLAG_TEST ){
1025
+ zDesc = "test command";
1026
+ }else if( e & CMDFLAG_WEBPAGE ){
1027
+ if( e & CMDFLAG_RAWCONTENT ){
1028
+ zDesc = "raw-content web page";
1029
+ }else{
1030
+ zDesc = "web page";
1031
+ }
1032
+ }
1033
+
1034
+ @ <dt><big><b>%s(aCommand[bktHelp[aCommand[i].iHelp][j]].zName)</b>
1035
+ @</big> (%s(zDesc))</dt>
1036
+ }
1037
+ @ <dd>
1038
+ help_to_html(aCommand[i].zHelp, cgi_output_blob());
1039
+ @ </dd>
1040
+ occHelp[aCommand[i].iHelp] = 0;
1041
+ }
9491042
}
9501043
@ </dl>
9511044
blob_reset(&buf);
9521045
style_finish_page();
9531046
}
9541047
--- src/dispatch.c
+++ src/dispatch.c
@@ -31,10 +31,11 @@
31 */
32 struct CmdOrPage {
33 const char *zName; /* Name. Webpages start with "/". Commands do not */
34 void (*xFunc)(void); /* Implementation function, or NULL for settings */
35 const char *zHelp; /* Raw help text */
 
36 unsigned int eCmdFlags; /* Flags */
37 };
38
39 /***************************************************************************
40 ** These macros must match similar macros in mkindex.c
@@ -51,10 +52,11 @@
51 #define CMDFLAG_BOOLEAN 0x0100 /* A boolean setting */
52 #define CMDFLAG_RAWCONTENT 0x0200 /* Do not interpret POST content */
53 /* NOTE: 0x0400 = CMDFLAG_SENSITIVE in mkindex.c! */
54 #define CMDFLAG_HIDDEN 0x0800 /* Elide from most listings */
55 #define CMDFLAG_LDAVG_EXEMPT 0x1000 /* Exempt from load_control() */
 
56 /**************************************************************************/
57
58 /* Values for the 2nd parameter to dispatch_name_search() */
59 #define CMDFLAG_ANY 0x0038 /* Match anything */
60 #define CMDFLAG_PREFIX 0x0200 /* Prefix match is ok */
@@ -77,10 +79,11 @@
77 ** source code files looking for header comments on the functions that
78 ** implement command and webpages.
79 */
80 #include "page_index.h"
81 #define MX_COMMAND count(aCommand)
 
82
83 /*
84 ** Given a command, webpage, or setting name in zName, find the corresponding
85 ** CmdOrPage object and return a pointer to that object in *ppCmd.
86 **
@@ -546,45 +549,65 @@
546 /*
547 ** Display help for all commands based on provided flags.
548 */
549 static void display_all_help(int mask, int useHtml, int rawOut){
550 int i;
 
 
551 if( useHtml ) fossil_print("<!--\n");
552 fossil_print("Help text for:\n");
553 if( mask & CMDFLAG_1ST_TIER ) fossil_print(" * Commands\n");
554 if( mask & CMDFLAG_2ND_TIER ) fossil_print(" * Auxiliary commands\n");
 
555 if( mask & CMDFLAG_TEST ) fossil_print(" * Test commands\n");
556 if( mask & CMDFLAG_WEBPAGE ) fossil_print(" * Web pages\n");
557 if( mask & CMDFLAG_SETTING ) fossil_print(" * Settings\n");
558 if( useHtml ){
559 fossil_print("-->\n");
560 fossil_print("<!-- start_all_help -->\n");
561 }else{
562 fossil_print("---\n");
563 }
 
 
 
 
 
 
564 for(i=0; i<MX_COMMAND; i++){
565 if( (aCommand[i].eCmdFlags & mask)==0 ) continue;
566 else if(aCommand[i].eCmdFlags & CMDFLAG_HIDDEN) continue;
567 if( useHtml ){
568 Blob html;
569 blob_init(&html, 0, 0);
570 help_to_html(aCommand[i].zHelp, &html);
571 fossil_print("<h1>%h</h1>\n", aCommand[i].zName);
572 fossil_print("%s\n<hr>\n", blob_str(&html));
573 blob_reset(&html);
574 }else if( rawOut ){
575 fossil_print("# %s\n", aCommand[i].zName);
576 fossil_print("%s\n\n", aCommand[i].zHelp);
577 }else{
578 Blob txt;
579 blob_init(&txt, 0, 0);
580 help_to_text(aCommand[i].zHelp, &txt);
581 fossil_print("# %s%s\n", aCommand[i].zName,
582 (aCommand[i].eCmdFlags & CMDFLAG_VERSIONABLE)!=0 ?
583 " (versionable)" : "");
584 fossil_print("%s\n\n", blob_str(&txt));
585 blob_reset(&txt);
 
 
 
 
 
 
 
 
 
 
 
586 }
587 }
588 if( useHtml ){
589 fossil_print("<!-- end_all_help -->\n");
590 }else{
@@ -601,17 +624,19 @@
601 ** Show help text for commands and pages. Useful for proof-reading.
602 ** Defaults to just the CLI commands. Specify --www to see only the
603 ** web pages, or --everything to see both commands and pages.
604 **
605 ** Options:
606 ** -e|--everything Show all commands and pages.
 
 
 
 
 
 
607 ** -t|--test Include test- commands.
608 ** -w|--www Show WWW pages.
609 ** -s|--settings Show settings.
610 ** -h|--html Transform output to HTML.
611 ** -r|--raw No output formatting.
612 ** -o|--options Show global options.
613 */
614 void test_all_help_cmd(void){
615 int mask = CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER;
616 int useHtml = find_option("html","h",0)!=0;
617 int rawOut = find_option("raw","r",0)!=0;
@@ -619,15 +644,18 @@
619 if( find_option("www","w",0) ){
620 mask = CMDFLAG_WEBPAGE;
621 }
622 if( find_option("everything","e",0) ){
623 mask = CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER | CMDFLAG_WEBPAGE |
624 CMDFLAG_SETTING | CMDFLAG_TEST;
625 }
626 if( find_option("settings","s",0) ){
627 mask = CMDFLAG_SETTING;
628 }
 
 
 
629 if( find_option("test","t",0) ){
630 mask |= CMDFLAG_TEST;
631 }
632 display_all_help(mask, useHtml, rawOut);
633 }
@@ -655,10 +683,12 @@
655 countCmds( CMDFLAG_COMMAND ));
656 fossil_print(" 1st tier %4d\n",
657 countCmds( CMDFLAG_1ST_TIER ));
658 fossil_print(" 2nd tier %4d\n",
659 countCmds( CMDFLAG_2ND_TIER ));
 
 
660 fossil_print(" test %4d\n",
661 countCmds( CMDFLAG_TEST ));
662 fossil_print("web-pages: %4d\n",
663 countCmds( CMDFLAG_WEBPAGE ));
664 fossil_print("settings: %4d\n",
@@ -828,26 +858,56 @@
828 @ </div>
829 }
830 }
831 }else{
832 int i;
833
 
834 style_header("Help");
835
836 @ <a name='commands'></a>
837 @ <h1>Available commands:</h1>
838 @ <div class="columns" style="column-width: 12ex;">
839 @ <ul>
 
 
 
 
 
840 for(i=0; i<MX_COMMAND; i++){
841 const char *z = aCommand[i].zName;
842 const char *zBoldOn = aCommand[i].eCmdFlags&CMDFLAG_1ST_TIER?"<b>" :"";
843 const char *zBoldOff = aCommand[i].eCmdFlags&CMDFLAG_1ST_TIER?"</b>":"";
844 if( '/'==*z || strncmp(z,"test",4)==0 ) continue;
845 if( (aCommand[i].eCmdFlags & CMDFLAG_SETTING)!=0 ) continue;
846 else if( (aCommand[i].eCmdFlags & CMDFLAG_HIDDEN)!=0 ) continue;
847 @ <li><a href="%R/help?cmd=%s(z)">%s(zBoldOn)%s(z)%s(zBoldOff)</a></li>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
848 }
 
849 @ </ul></div>
850
851 @ <a name='webpages'></a>
852 @ <h1>Available web UI pages:</h1>
853 @ <div class="columns" style="column-width: 18ex;">
@@ -905,22 +965,31 @@
905 **
906 ** Show all help text on a single page. Useful for proof-reading.
907 */
908 void test_all_help_page(void){
909 int i;
 
 
910 Blob buf;
911 blob_init(&buf,0,0);
912 style_set_current_feature("test");
913 style_header("All Help Text");
914 @ <dl>
 
 
 
 
 
915 for(i=0; i<MX_COMMAND; i++){
916 const char *zDesc;
917 unsigned int e = aCommand[i].eCmdFlags;
918 if( e & CMDFLAG_1ST_TIER ){
919 zDesc = "1st tier command";
920 }else if( e & CMDFLAG_2ND_TIER ){
921 zDesc = "2nd tier command";
 
 
922 }else if( e & CMDFLAG_TEST ){
923 zDesc = "test command";
924 }else if( e & CMDFLAG_WEBPAGE ){
925 if( e & CMDFLAG_RAWCONTENT ){
926 zDesc = "raw-content web page";
@@ -940,14 +1009,38 @@
940 }
941 blob_appendf(&buf,"setting");
942 zDesc = blob_str(&buf);
943 }
944 if( memcmp(aCommand[i].zName, "test", 4)==0 ) continue;
945 @ <dt><big><b>%s(aCommand[i].zName)</b></big> (%s(zDesc))</dt>
946 @ <dd>
947 help_to_html(aCommand[i].zHelp, cgi_output_blob());
948 @ </dd>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
949 }
950 @ </dl>
951 blob_reset(&buf);
952 style_finish_page();
953 }
954
--- src/dispatch.c
+++ src/dispatch.c
@@ -31,10 +31,11 @@
31 */
32 struct CmdOrPage {
33 const char *zName; /* Name. Webpages start with "/". Commands do not */
34 void (*xFunc)(void); /* Implementation function, or NULL for settings */
35 const char *zHelp; /* Raw help text */
36 int iHelp; /* Index of help variable */
37 unsigned int eCmdFlags; /* Flags */
38 };
39
40 /***************************************************************************
41 ** These macros must match similar macros in mkindex.c
@@ -51,10 +52,11 @@
52 #define CMDFLAG_BOOLEAN 0x0100 /* A boolean setting */
53 #define CMDFLAG_RAWCONTENT 0x0200 /* Do not interpret POST content */
54 /* NOTE: 0x0400 = CMDFLAG_SENSITIVE in mkindex.c! */
55 #define CMDFLAG_HIDDEN 0x0800 /* Elide from most listings */
56 #define CMDFLAG_LDAVG_EXEMPT 0x1000 /* Exempt from load_control() */
57 #define CMDFLAG_ALIAS 0x2000 /* Command aliases */
58 /**************************************************************************/
59
60 /* Values for the 2nd parameter to dispatch_name_search() */
61 #define CMDFLAG_ANY 0x0038 /* Match anything */
62 #define CMDFLAG_PREFIX 0x0200 /* Prefix match is ok */
@@ -77,10 +79,11 @@
79 ** source code files looking for header comments on the functions that
80 ** implement command and webpages.
81 */
82 #include "page_index.h"
83 #define MX_COMMAND count(aCommand)
84 #define MX_HELP_DUP 5 /* Upper bound estimate on help string duplication */
85
86 /*
87 ** Given a command, webpage, or setting name in zName, find the corresponding
88 ** CmdOrPage object and return a pointer to that object in *ppCmd.
89 **
@@ -546,45 +549,65 @@
549 /*
550 ** Display help for all commands based on provided flags.
551 */
552 static void display_all_help(int mask, int useHtml, int rawOut){
553 int i;
554 unsigned char occHelp[FOSSIL_MX_CMDIDX] = {0}; /* Help string occurrences */
555 int bktHelp[FOSSIL_MX_CMDIDX][MX_HELP_DUP] = {0};/* Help strings -> commands*/
556 if( useHtml ) fossil_print("<!--\n");
557 fossil_print("Help text for:\n");
558 if( mask & CMDFLAG_1ST_TIER ) fossil_print(" * Commands\n");
559 if( mask & CMDFLAG_2ND_TIER ) fossil_print(" * Auxiliary commands\n");
560 if( mask & CMDFLAG_ALIAS ) fossil_print(" * Aliases\n");
561 if( mask & CMDFLAG_TEST ) fossil_print(" * Test commands\n");
562 if( mask & CMDFLAG_WEBPAGE ) fossil_print(" * Web pages\n");
563 if( mask & CMDFLAG_SETTING ) fossil_print(" * Settings\n");
564 if( useHtml ){
565 fossil_print("-->\n");
566 fossil_print("<!-- start_all_help -->\n");
567 }else{
568 fossil_print("---\n");
569 }
570 /* Fill in help string buckets */
571 for(i=0; i<MX_COMMAND; i++){
572 if( (aCommand[i].eCmdFlags & mask)==0 ) continue;
573 else if(aCommand[i].eCmdFlags & CMDFLAG_HIDDEN) continue;
574 bktHelp[aCommand[i].iHelp][occHelp[aCommand[i].iHelp]++] = i;
575 }
576 for(i=0; i<MX_COMMAND; i++){
577 if( (aCommand[i].eCmdFlags & mask)==0 ) continue;
578 else if(aCommand[i].eCmdFlags & CMDFLAG_HIDDEN) continue;
579 if( occHelp[aCommand[i].iHelp] > 0 ){
580 int j;
581 if( useHtml ){
582 Blob html;
583 blob_init(&html, 0, 0);
584 help_to_html(aCommand[i].zHelp, &html);
585 for(j=0; j<occHelp[aCommand[i].iHelp]; j++){
586 fossil_print("<h1>%h</h1>\n",
587 aCommand[bktHelp[aCommand[i].iHelp][j]].zName);
588 }
589 fossil_print("%s\n<hr>\n", blob_str(&html));
590 blob_reset(&html);
591 }else if( rawOut ){
592 for(j=0; j<occHelp[aCommand[i].iHelp]; j++)
593 fossil_print("# %s\n", aCommand[bktHelp[aCommand[i].iHelp][j]].zName);
594 fossil_print("%s\n\n", aCommand[i].zHelp);
595 }else{
596 Blob txt;
597 blob_init(&txt, 0, 0);
598 help_to_text(aCommand[i].zHelp, &txt);
599 for(j=0; j<occHelp[aCommand[i].iHelp]; j++){
600 fossil_print("# %s%s\n",
601 aCommand[bktHelp[aCommand[i].iHelp][j]].zName,
602 (aCommand[i].eCmdFlags & CMDFLAG_VERSIONABLE)!=0 ?
603 " (versionable)" : "");
604 }
605 fossil_print("%s\n\n", blob_str(&txt));
606 blob_reset(&txt);
607 }
608 occHelp[aCommand[i].iHelp] = 0;
609 }
610 }
611 if( useHtml ){
612 fossil_print("<!-- end_all_help -->\n");
613 }else{
@@ -601,17 +624,19 @@
624 ** Show help text for commands and pages. Useful for proof-reading.
625 ** Defaults to just the CLI commands. Specify --www to see only the
626 ** web pages, or --everything to see both commands and pages.
627 **
628 ** Options:
629 ** -a|--aliases Show aliases.
630 ** -e|--everything Show all commands and pages. Omit aliases to
631 ** avoid duplicates.
632 ** -h|--html Transform output to HTML.
633 ** -o|--options Show global options.
634 ** -r|--raw No output formatting.
635 ** -s|--settings Show settings.
636 ** -t|--test Include test- commands.
637 ** -w|--www Show WWW pages.
 
 
 
 
638 */
639 void test_all_help_cmd(void){
640 int mask = CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER;
641 int useHtml = find_option("html","h",0)!=0;
642 int rawOut = find_option("raw","r",0)!=0;
@@ -619,15 +644,18 @@
644 if( find_option("www","w",0) ){
645 mask = CMDFLAG_WEBPAGE;
646 }
647 if( find_option("everything","e",0) ){
648 mask = CMDFLAG_1ST_TIER | CMDFLAG_2ND_TIER | CMDFLAG_WEBPAGE |
649 CMDFLAG_ALIAS | CMDFLAG_SETTING | CMDFLAG_TEST;
650 }
651 if( find_option("settings","s",0) ){
652 mask = CMDFLAG_SETTING;
653 }
654 if( find_option("aliases","a",0) ){
655 mask = CMDFLAG_ALIAS;
656 }
657 if( find_option("test","t",0) ){
658 mask |= CMDFLAG_TEST;
659 }
660 display_all_help(mask, useHtml, rawOut);
661 }
@@ -655,10 +683,12 @@
683 countCmds( CMDFLAG_COMMAND ));
684 fossil_print(" 1st tier %4d\n",
685 countCmds( CMDFLAG_1ST_TIER ));
686 fossil_print(" 2nd tier %4d\n",
687 countCmds( CMDFLAG_2ND_TIER ));
688 fossil_print(" alias %4d\n",
689 countCmds( CMDFLAG_ALIAS ));
690 fossil_print(" test %4d\n",
691 countCmds( CMDFLAG_TEST ));
692 fossil_print("web-pages: %4d\n",
693 countCmds( CMDFLAG_WEBPAGE ));
694 fossil_print("settings: %4d\n",
@@ -828,26 +858,56 @@
858 @ </div>
859 }
860 }
861 }else{
862 int i;
863 unsigned char occHelp[FOSSIL_MX_CMDIDX] = {0}; /* Help str occurrences */
864 int bktHelp[FOSSIL_MX_CMDIDX][MX_HELP_DUP] = {0};/* Help str -> commands */
865 style_header("Help");
866
867 @ <a name='commands'></a>
868 @ <h1>Available commands:</h1>
869 @ <div class="columns" style="column-width: 12ex;">
870 @ <ul>
871 /* Fill in help string buckets */
872 for(i=0; i<MX_COMMAND; i++){
873 if(aCommand[i].eCmdFlags & CMDFLAG_HIDDEN) continue;
874 bktHelp[aCommand[i].iHelp][occHelp[aCommand[i].iHelp]++] = i;
875 }
876 for(i=0; i<MX_COMMAND; i++){
877 const char *z = aCommand[i].zName;
878 const char *zBoldOn = aCommand[i].eCmdFlags&CMDFLAG_1ST_TIER?"<b>" :"";
879 const char *zBoldOff = aCommand[i].eCmdFlags&CMDFLAG_1ST_TIER?"</b>":"";
880 if( '/'==*z || strncmp(z,"test",4)==0 ) continue;
881 if( (aCommand[i].eCmdFlags & CMDFLAG_SETTING)!=0 ) continue;
882 else if( (aCommand[i].eCmdFlags & CMDFLAG_HIDDEN)!=0 ) continue;
883 else if( (aCommand[i].eCmdFlags & CMDFLAG_ALIAS)!=0 ) continue;
884 @ <li><a href="%R/help?cmd=%s(z)">%s(zBoldOn)%s(z)%s(zBoldOff)</a>
885 /* Output aliases */
886 if( occHelp[aCommand[i].iHelp] > 1 ){
887 int j;
888 int aliases[MX_HELP_DUP], nAliases=0;
889 for(j=0; j<occHelp[aCommand[i].iHelp]; j++){
890 if( bktHelp[aCommand[i].iHelp][j] != i ){
891 if( aCommand[bktHelp[aCommand[i].iHelp][j]].eCmdFlags & CMDFLAG_ALIAS ){
892 aliases[nAliases++] = bktHelp[aCommand[i].iHelp][j];
893 }
894 }
895 }
896 if( nAliases>0 ){
897 int k;
898 @(\
899 for(k=0; k<nAliases; k++){
900 @<a href="%R/help?cmd=%s(aCommand[aliases[k]].zName)">\
901 @%s(aCommand[aliases[k]].zName)</a>%s((k<nAliases-1)?", ":"")\
902 }
903 @)\
904 }
905 }
906 @ </li>
907 }
908
909 @ </ul></div>
910
911 @ <a name='webpages'></a>
912 @ <h1>Available web UI pages:</h1>
913 @ <div class="columns" style="column-width: 18ex;">
@@ -905,22 +965,31 @@
965 **
966 ** Show all help text on a single page. Useful for proof-reading.
967 */
968 void test_all_help_page(void){
969 int i;
970 unsigned char occHelp[FOSSIL_MX_CMDIDX] = {0}; /* Help string occurrences */
971 int bktHelp[FOSSIL_MX_CMDIDX][MX_HELP_DUP] = {0};/* Help strings -> commands*/
972 Blob buf;
973 blob_init(&buf,0,0);
974 style_set_current_feature("test");
975 style_header("All Help Text");
976 @ <dl>
977 /* Fill in help string buckets */
978 for(i=0; i<MX_COMMAND; i++){
979 if(aCommand[i].eCmdFlags & CMDFLAG_HIDDEN) continue;
980 bktHelp[aCommand[i].iHelp][occHelp[aCommand[i].iHelp]++] = i;
981 }
982 for(i=0; i<MX_COMMAND; i++){
983 const char *zDesc;
984 unsigned int e = aCommand[i].eCmdFlags;
985 if( e & CMDFLAG_1ST_TIER ){
986 zDesc = "1st tier command";
987 }else if( e & CMDFLAG_2ND_TIER ){
988 zDesc = "2nd tier command";
989 }else if( e & CMDFLAG_ALIAS ){
990 zDesc = "alias";
991 }else if( e & CMDFLAG_TEST ){
992 zDesc = "test command";
993 }else if( e & CMDFLAG_WEBPAGE ){
994 if( e & CMDFLAG_RAWCONTENT ){
995 zDesc = "raw-content web page";
@@ -940,14 +1009,38 @@
1009 }
1010 blob_appendf(&buf,"setting");
1011 zDesc = blob_str(&buf);
1012 }
1013 if( memcmp(aCommand[i].zName, "test", 4)==0 ) continue;
1014 if( occHelp[aCommand[i].iHelp] > 0 ){
1015 int j;
1016 for(j=0; j<occHelp[aCommand[i].iHelp]; j++){
1017 unsigned int e = aCommand[bktHelp[aCommand[i].iHelp][j]].eCmdFlags;
1018 if( e & CMDFLAG_1ST_TIER ){
1019 zDesc = "1st tier command";
1020 }else if( e & CMDFLAG_2ND_TIER ){
1021 zDesc = "2nd tier command";
1022 }else if( e & CMDFLAG_ALIAS ){
1023 zDesc = "alias";
1024 }else if( e & CMDFLAG_TEST ){
1025 zDesc = "test command";
1026 }else if( e & CMDFLAG_WEBPAGE ){
1027 if( e & CMDFLAG_RAWCONTENT ){
1028 zDesc = "raw-content web page";
1029 }else{
1030 zDesc = "web page";
1031 }
1032 }
1033
1034 @ <dt><big><b>%s(aCommand[bktHelp[aCommand[i].iHelp][j]].zName)</b>
1035 @</big> (%s(zDesc))</dt>
1036 }
1037 @ <dd>
1038 help_to_html(aCommand[i].zHelp, cgi_output_blob());
1039 @ </dd>
1040 occHelp[aCommand[i].iHelp] = 0;
1041 }
1042 }
1043 @ </dl>
1044 blob_reset(&buf);
1045 style_finish_page();
1046 }
1047
--- src/json_branch.c
+++ src/json_branch.c
@@ -128,11 +128,11 @@
128128
cson_object_set(pay,"current",json_new_string(zCurrent));
129129
}
130130
}
131131
132132
133
- branch_prepare_list_query(&q, branchListFlags, 0);
133
+ branch_prepare_list_query(&q, branchListFlags, 0, 0);
134134
cson_object_set(pay,"branches",listV);
135135
while((SQLITE_ROW==db_step(&q))){
136136
cson_value * v = cson_sqlite3_column_to_value(q.pStmt,0);
137137
if(v){
138138
cson_array_append(list,v);
139139
--- src/json_branch.c
+++ src/json_branch.c
@@ -128,11 +128,11 @@
128 cson_object_set(pay,"current",json_new_string(zCurrent));
129 }
130 }
131
132
133 branch_prepare_list_query(&q, branchListFlags, 0);
134 cson_object_set(pay,"branches",listV);
135 while((SQLITE_ROW==db_step(&q))){
136 cson_value * v = cson_sqlite3_column_to_value(q.pStmt,0);
137 if(v){
138 cson_array_append(list,v);
139
--- src/json_branch.c
+++ src/json_branch.c
@@ -128,11 +128,11 @@
128 cson_object_set(pay,"current",json_new_string(zCurrent));
129 }
130 }
131
132
133 branch_prepare_list_query(&q, branchListFlags, 0, 0);
134 cson_object_set(pay,"branches",listV);
135 while((SQLITE_ROW==db_step(&q))){
136 cson_value * v = cson_sqlite3_column_to_value(q.pStmt,0);
137 if(v){
138 cson_array_append(list,v);
139
+40 -16
--- src/main.c
+++ src/main.c
@@ -1471,21 +1471,24 @@
14711471
/*
14721472
** If running as root, chroot to the directory containing the
14731473
** repository zRepo and then drop root privileges. Return the
14741474
** new repository name.
14751475
**
1476
-** zRepo might be a directory itself. In that case chroot into
1477
-** the directory zRepo.
1476
+** zRepo can be a directory. If so and if the repo name was saved
1477
+** to g.zRepositoryName before we were called, we canonicalize the
1478
+** two paths and check that one is the prefix of the other, else you
1479
+** won't be able to open the repo inside the jail. If it all works
1480
+** out, we return the "jailed" version of the repo name.
14781481
**
14791482
** Assume the user-id and group-id of the repository, or if zRepo
14801483
** is a directory, of that directory.
14811484
**
14821485
** The noJail flag means that the chroot jail is not entered. But
14831486
** privileges are still lowered to that of the user-id and group-id
14841487
** of the repository file.
14851488
*/
1486
-char *enter_chroot_jail(char *zRepo, int noJail){
1489
+static char *enter_chroot_jail(const char *zRepo, int noJail){
14871490
#if !defined(_WIN32)
14881491
if( getuid()==0 ){
14891492
int i;
14901493
struct stat sStat;
14911494
Blob dir;
@@ -1496,15 +1499,27 @@
14961499
14971500
file_canonical_name(zRepo, &dir, 0);
14981501
zDir = blob_str(&dir);
14991502
if( !noJail ){
15001503
if( file_isdir(zDir, ExtFILE)==1 ){
1504
+ if( g.zRepositoryName ){
1505
+ size_t n = strlen(zDir);
1506
+ Blob repo;
1507
+ file_canonical_name(g.zRepositoryName, &repo, 0);
1508
+ zRepo = blob_str(&repo);
1509
+ if( strncmp(zRepo, zDir, n)!=0 ){
1510
+ fossil_fatal("repo %s not under chroot dir %s", zRepo, zDir);
1511
+ }
1512
+ zRepo += n;
1513
+ if( *zRepo == '\0' ) zRepo = "/";
1514
+ }else {
1515
+ zRepo = "/";
1516
+ g.fJail = 1;
1517
+ }
15011518
if( file_chdir(zDir, 1) ){
15021519
fossil_panic("unable to chroot into %s", zDir);
15031520
}
1504
- g.fJail = 1;
1505
- zRepo = "/";
15061521
}else{
15071522
for(i=strlen(zDir)-1; i>0 && zDir[i]!='/'; i--){}
15081523
if( zDir[i]!='/' ) fossil_fatal("bad repository name: %s", zRepo);
15091524
if( i>0 ){
15101525
zDir[i] = 0;
@@ -1527,11 +1542,11 @@
15271542
if( g.db==0 && file_isfile(zRepo, ExtFILE) ){
15281543
db_open_repository(zRepo);
15291544
}
15301545
}
15311546
#endif
1532
- return zRepo;
1547
+ return (char*)zRepo; /* no longer const: always reassigned from blob_str() */
15331548
}
15341549
15351550
/*
15361551
** Called whenever a crash is encountered while processing a webpage.
15371552
*/
@@ -2814,15 +2829,12 @@
28142829
zIpAddr = cgi_ssh_remote_addr(0);
28152830
if( zIpAddr && zIpAddr[0] ){
28162831
g.fSshClient |= CGI_SSH_CLIENT;
28172832
}
28182833
}
2819
- if( zChRoot ){
2820
- enter_chroot_jail((char*)zChRoot, noJail);
2821
- }else{
2822
- g.zRepositoryName = enter_chroot_jail(g.zRepositoryName, noJail);
2823
- }
2834
+ g.zRepositoryName = enter_chroot_jail(
2835
+ zChRoot ? zChRoot : g.zRepositoryName, noJail);
28242836
if( useSCGI ){
28252837
cgi_handle_scgi_request();
28262838
}else if( g.fSshClient & CGI_SSH_CLIENT ){
28272839
ssh_request_loop(zIpAddr, glob_create(zFileGlob));
28282840
}else{
@@ -3283,10 +3295,25 @@
32833295
return;
32843296
}
32853297
if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
32863298
if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
32873299
db_close(1);
3300
+#if !defined(_WIN32)
3301
+ if( getpid()==1 ){
3302
+ /* Modern kernels suppress SIGTERM to PID 1 to prevent root from
3303
+ ** rebooting the system by nuking the init system. The only way
3304
+ ** Fossil becomes that PID 1 is when it's running solo in a Linux
3305
+ ** container or similar, so we do want to exit immediately, to
3306
+ ** allow the container to shut down quickly.
3307
+ **
3308
+ ** This has to happen ahead of the other signal() calls below.
3309
+ ** They apply after the HTTP hit is handled, but this one needs
3310
+ ** to be registered while we're waiting for that to occur.
3311
+ **/
3312
+ signal(SIGTERM, fossil_exit);
3313
+ }
3314
+#endif /* !WIN32 */
32883315
32893316
/* Start up an HTTP server
32903317
*/
32913318
fossil_setenv("SERVER_SOFTWARE", "fossil version " RELEASE_VERSION
32923319
" " MANIFEST_VERSION " " MANIFEST_DATE);
@@ -3319,15 +3346,12 @@
33193346
g.cgiOutput = 1;
33203347
find_server_repository(2, 0);
33213348
if( fossil_strcmp(g.zRepositoryName,"/")==0 ){
33223349
allowRepoList = 1;
33233350
}else{
3324
- if( zChRoot ){
3325
- enter_chroot_jail((char*)zChRoot, noJail);
3326
- }else{
3327
- g.zRepositoryName = enter_chroot_jail(g.zRepositoryName, noJail);
3328
- }
3351
+ g.zRepositoryName = enter_chroot_jail(
3352
+ zChRoot ? zChRoot : g.zRepositoryName, noJail);
33293353
}
33303354
if( flags & HTTP_SERVER_SCGI ){
33313355
cgi_handle_scgi_request();
33323356
}else if( g.httpUseSSL ){
33333357
#if FOSSIL_ENABLE_SSL
33343358
--- src/main.c
+++ src/main.c
@@ -1471,21 +1471,24 @@
1471 /*
1472 ** If running as root, chroot to the directory containing the
1473 ** repository zRepo and then drop root privileges. Return the
1474 ** new repository name.
1475 **
1476 ** zRepo might be a directory itself. In that case chroot into
1477 ** the directory zRepo.
 
 
 
1478 **
1479 ** Assume the user-id and group-id of the repository, or if zRepo
1480 ** is a directory, of that directory.
1481 **
1482 ** The noJail flag means that the chroot jail is not entered. But
1483 ** privileges are still lowered to that of the user-id and group-id
1484 ** of the repository file.
1485 */
1486 char *enter_chroot_jail(char *zRepo, int noJail){
1487 #if !defined(_WIN32)
1488 if( getuid()==0 ){
1489 int i;
1490 struct stat sStat;
1491 Blob dir;
@@ -1496,15 +1499,27 @@
1496
1497 file_canonical_name(zRepo, &dir, 0);
1498 zDir = blob_str(&dir);
1499 if( !noJail ){
1500 if( file_isdir(zDir, ExtFILE)==1 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1501 if( file_chdir(zDir, 1) ){
1502 fossil_panic("unable to chroot into %s", zDir);
1503 }
1504 g.fJail = 1;
1505 zRepo = "/";
1506 }else{
1507 for(i=strlen(zDir)-1; i>0 && zDir[i]!='/'; i--){}
1508 if( zDir[i]!='/' ) fossil_fatal("bad repository name: %s", zRepo);
1509 if( i>0 ){
1510 zDir[i] = 0;
@@ -1527,11 +1542,11 @@
1527 if( g.db==0 && file_isfile(zRepo, ExtFILE) ){
1528 db_open_repository(zRepo);
1529 }
1530 }
1531 #endif
1532 return zRepo;
1533 }
1534
1535 /*
1536 ** Called whenever a crash is encountered while processing a webpage.
1537 */
@@ -2814,15 +2829,12 @@
2814 zIpAddr = cgi_ssh_remote_addr(0);
2815 if( zIpAddr && zIpAddr[0] ){
2816 g.fSshClient |= CGI_SSH_CLIENT;
2817 }
2818 }
2819 if( zChRoot ){
2820 enter_chroot_jail((char*)zChRoot, noJail);
2821 }else{
2822 g.zRepositoryName = enter_chroot_jail(g.zRepositoryName, noJail);
2823 }
2824 if( useSCGI ){
2825 cgi_handle_scgi_request();
2826 }else if( g.fSshClient & CGI_SSH_CLIENT ){
2827 ssh_request_loop(zIpAddr, glob_create(zFileGlob));
2828 }else{
@@ -3283,10 +3295,25 @@
3283 return;
3284 }
3285 if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
3286 if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
3287 db_close(1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3288
3289 /* Start up an HTTP server
3290 */
3291 fossil_setenv("SERVER_SOFTWARE", "fossil version " RELEASE_VERSION
3292 " " MANIFEST_VERSION " " MANIFEST_DATE);
@@ -3319,15 +3346,12 @@
3319 g.cgiOutput = 1;
3320 find_server_repository(2, 0);
3321 if( fossil_strcmp(g.zRepositoryName,"/")==0 ){
3322 allowRepoList = 1;
3323 }else{
3324 if( zChRoot ){
3325 enter_chroot_jail((char*)zChRoot, noJail);
3326 }else{
3327 g.zRepositoryName = enter_chroot_jail(g.zRepositoryName, noJail);
3328 }
3329 }
3330 if( flags & HTTP_SERVER_SCGI ){
3331 cgi_handle_scgi_request();
3332 }else if( g.httpUseSSL ){
3333 #if FOSSIL_ENABLE_SSL
3334
--- src/main.c
+++ src/main.c
@@ -1471,21 +1471,24 @@
1471 /*
1472 ** If running as root, chroot to the directory containing the
1473 ** repository zRepo and then drop root privileges. Return the
1474 ** new repository name.
1475 **
1476 ** zRepo can be a directory. If so and if the repo name was saved
1477 ** to g.zRepositoryName before we were called, we canonicalize the
1478 ** two paths and check that one is the prefix of the other, else you
1479 ** won't be able to open the repo inside the jail. If it all works
1480 ** out, we return the "jailed" version of the repo name.
1481 **
1482 ** Assume the user-id and group-id of the repository, or if zRepo
1483 ** is a directory, of that directory.
1484 **
1485 ** The noJail flag means that the chroot jail is not entered. But
1486 ** privileges are still lowered to that of the user-id and group-id
1487 ** of the repository file.
1488 */
1489 static char *enter_chroot_jail(const char *zRepo, int noJail){
1490 #if !defined(_WIN32)
1491 if( getuid()==0 ){
1492 int i;
1493 struct stat sStat;
1494 Blob dir;
@@ -1496,15 +1499,27 @@
1499
1500 file_canonical_name(zRepo, &dir, 0);
1501 zDir = blob_str(&dir);
1502 if( !noJail ){
1503 if( file_isdir(zDir, ExtFILE)==1 ){
1504 if( g.zRepositoryName ){
1505 size_t n = strlen(zDir);
1506 Blob repo;
1507 file_canonical_name(g.zRepositoryName, &repo, 0);
1508 zRepo = blob_str(&repo);
1509 if( strncmp(zRepo, zDir, n)!=0 ){
1510 fossil_fatal("repo %s not under chroot dir %s", zRepo, zDir);
1511 }
1512 zRepo += n;
1513 if( *zRepo == '\0' ) zRepo = "/";
1514 }else {
1515 zRepo = "/";
1516 g.fJail = 1;
1517 }
1518 if( file_chdir(zDir, 1) ){
1519 fossil_panic("unable to chroot into %s", zDir);
1520 }
 
 
1521 }else{
1522 for(i=strlen(zDir)-1; i>0 && zDir[i]!='/'; i--){}
1523 if( zDir[i]!='/' ) fossil_fatal("bad repository name: %s", zRepo);
1524 if( i>0 ){
1525 zDir[i] = 0;
@@ -1527,11 +1542,11 @@
1542 if( g.db==0 && file_isfile(zRepo, ExtFILE) ){
1543 db_open_repository(zRepo);
1544 }
1545 }
1546 #endif
1547 return (char*)zRepo; /* no longer const: always reassigned from blob_str() */
1548 }
1549
1550 /*
1551 ** Called whenever a crash is encountered while processing a webpage.
1552 */
@@ -2814,15 +2829,12 @@
2829 zIpAddr = cgi_ssh_remote_addr(0);
2830 if( zIpAddr && zIpAddr[0] ){
2831 g.fSshClient |= CGI_SSH_CLIENT;
2832 }
2833 }
2834 g.zRepositoryName = enter_chroot_jail(
2835 zChRoot ? zChRoot : g.zRepositoryName, noJail);
 
 
 
2836 if( useSCGI ){
2837 cgi_handle_scgi_request();
2838 }else if( g.fSshClient & CGI_SSH_CLIENT ){
2839 ssh_request_loop(zIpAddr, glob_create(zFileGlob));
2840 }else{
@@ -3283,10 +3295,25 @@
3295 return;
3296 }
3297 if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
3298 if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
3299 db_close(1);
3300 #if !defined(_WIN32)
3301 if( getpid()==1 ){
3302 /* Modern kernels suppress SIGTERM to PID 1 to prevent root from
3303 ** rebooting the system by nuking the init system. The only way
3304 ** Fossil becomes that PID 1 is when it's running solo in a Linux
3305 ** container or similar, so we do want to exit immediately, to
3306 ** allow the container to shut down quickly.
3307 **
3308 ** This has to happen ahead of the other signal() calls below.
3309 ** They apply after the HTTP hit is handled, but this one needs
3310 ** to be registered while we're waiting for that to occur.
3311 **/
3312 signal(SIGTERM, fossil_exit);
3313 }
3314 #endif /* !WIN32 */
3315
3316 /* Start up an HTTP server
3317 */
3318 fossil_setenv("SERVER_SOFTWARE", "fossil version " RELEASE_VERSION
3319 " " MANIFEST_VERSION " " MANIFEST_DATE);
@@ -3319,15 +3346,12 @@
3346 g.cgiOutput = 1;
3347 find_server_repository(2, 0);
3348 if( fossil_strcmp(g.zRepositoryName,"/")==0 ){
3349 allowRepoList = 1;
3350 }else{
3351 g.zRepositoryName = enter_chroot_jail(
3352 zChRoot ? zChRoot : g.zRepositoryName, noJail);
 
 
 
3353 }
3354 if( flags & HTTP_SERVER_SCGI ){
3355 cgi_handle_scgi_request();
3356 }else if( g.httpUseSSL ){
3357 #if FOSSIL_ENABLE_SSL
3358
+4 -1
--- src/setupuser.c
+++ src/setupuser.c
@@ -586,11 +586,14 @@
586586
/* Begin generating the page
587587
*/
588588
style_submenu_element("Cancel", "%s", cgi_referer("setup_ulist"));
589589
if( uid ){
590590
style_header("Edit User %h", zLogin);
591
- style_submenu_element("Access Log", "%R/access_log?u=%t", zLogin);
591
+ if( !login_is_special(zLogin) ){
592
+ style_submenu_element("Access Log", "%R/access_log?u=%t", zLogin);
593
+ style_submenu_element("Timeline","%R/timeline?u=%t", zLogin);
594
+ }
592595
}else{
593596
style_header("Add A New User");
594597
}
595598
@ <div class="ueditCapBox">
596599
@ <form action="%s(g.zPath)" method="post"><div>
597600
--- src/setupuser.c
+++ src/setupuser.c
@@ -586,11 +586,14 @@
586 /* Begin generating the page
587 */
588 style_submenu_element("Cancel", "%s", cgi_referer("setup_ulist"));
589 if( uid ){
590 style_header("Edit User %h", zLogin);
591 style_submenu_element("Access Log", "%R/access_log?u=%t", zLogin);
 
 
 
592 }else{
593 style_header("Add A New User");
594 }
595 @ <div class="ueditCapBox">
596 @ <form action="%s(g.zPath)" method="post"><div>
597
--- src/setupuser.c
+++ src/setupuser.c
@@ -586,11 +586,14 @@
586 /* Begin generating the page
587 */
588 style_submenu_element("Cancel", "%s", cgi_referer("setup_ulist"));
589 if( uid ){
590 style_header("Edit User %h", zLogin);
591 if( !login_is_special(zLogin) ){
592 style_submenu_element("Access Log", "%R/access_log?u=%t", zLogin);
593 style_submenu_element("Timeline","%R/timeline?u=%t", zLogin);
594 }
595 }else{
596 style_header("Add A New User");
597 }
598 @ <div class="ueditCapBox">
599 @ <form action="%s(g.zPath)" method="post"><div>
600
+1 -1
--- src/skins.c
+++ src/skins.c
@@ -849,11 +849,11 @@
849849
@ <form action="%R/setup_skinedit" method="post"><div>
850850
login_insert_csrf_secret();
851851
@ <input type='hidden' name='w' value='%d(ii)'>
852852
@ <input type='hidden' name='sk' value='%d(iSkin)'>
853853
@ <h2>Edit %s(zTitle):</h2>
854
- if( P("submit") && cgi_csrf_safe(0) && strcmp(zOrig,zContent)!=0 ){
854
+ if( P("submit") && cgi_csrf_safe(0) && (zOrig==0 || strcmp(zOrig,zContent)!=0) ){
855855
db_set_mprintf(zContent, 0, "draft%d-%s",iSkin,zFile);
856856
}
857857
@ <textarea name="%s(zFile)" rows="10" cols="80">\
858858
@ %h(zContent)</textarea>
859859
@ <br />
860860
--- src/skins.c
+++ src/skins.c
@@ -849,11 +849,11 @@
849 @ <form action="%R/setup_skinedit" method="post"><div>
850 login_insert_csrf_secret();
851 @ <input type='hidden' name='w' value='%d(ii)'>
852 @ <input type='hidden' name='sk' value='%d(iSkin)'>
853 @ <h2>Edit %s(zTitle):</h2>
854 if( P("submit") && cgi_csrf_safe(0) && strcmp(zOrig,zContent)!=0 ){
855 db_set_mprintf(zContent, 0, "draft%d-%s",iSkin,zFile);
856 }
857 @ <textarea name="%s(zFile)" rows="10" cols="80">\
858 @ %h(zContent)</textarea>
859 @ <br />
860
--- src/skins.c
+++ src/skins.c
@@ -849,11 +849,11 @@
849 @ <form action="%R/setup_skinedit" method="post"><div>
850 login_insert_csrf_secret();
851 @ <input type='hidden' name='w' value='%d(ii)'>
852 @ <input type='hidden' name='sk' value='%d(iSkin)'>
853 @ <h2>Edit %s(zTitle):</h2>
854 if( P("submit") && cgi_csrf_safe(0) && (zOrig==0 || strcmp(zOrig,zContent)!=0) ){
855 db_set_mprintf(zContent, 0, "draft%d-%s",iSkin,zFile);
856 }
857 @ <textarea name="%s(zFile)" rows="10" cols="80">\
858 @ %h(zContent)</textarea>
859 @ <br />
860
--- src/timeline.c
+++ src/timeline.c
@@ -2777,10 +2777,14 @@
27772777
){
27782778
Blob r, co;
27792779
int i, j;
27802780
blob_init(&r, 0, 0);
27812781
blob_init(&co, 0, 0);
2782
+
2783
+ if( 0==zCom ){
2784
+ zCom = "(NULL)";
2785
+ }
27822786
27832787
/* Replace LF and tab with space, delete CR */
27842788
while( zCom[0] ){
27852789
for(j=0; zCom[j] && zCom[j]!='\r' && zCom[j]!='\n' && zCom[j]!='\t'; j++){}
27862790
blob_append(&co, zCom, j);
27872791
--- src/timeline.c
+++ src/timeline.c
@@ -2777,10 +2777,14 @@
2777 ){
2778 Blob r, co;
2779 int i, j;
2780 blob_init(&r, 0, 0);
2781 blob_init(&co, 0, 0);
 
 
 
 
2782
2783 /* Replace LF and tab with space, delete CR */
2784 while( zCom[0] ){
2785 for(j=0; zCom[j] && zCom[j]!='\r' && zCom[j]!='\n' && zCom[j]!='\t'; j++){}
2786 blob_append(&co, zCom, j);
2787
--- src/timeline.c
+++ src/timeline.c
@@ -2777,10 +2777,14 @@
2777 ){
2778 Blob r, co;
2779 int i, j;
2780 blob_init(&r, 0, 0);
2781 blob_init(&co, 0, 0);
2782
2783 if( 0==zCom ){
2784 zCom = "(NULL)";
2785 }
2786
2787 /* Replace LF and tab with space, delete CR */
2788 while( zCom[0] ){
2789 for(j=0; zCom[j] && zCom[j]!='\r' && zCom[j]!='\n' && zCom[j]!='\t'; j++){}
2790 blob_append(&co, zCom, j);
2791
--- src/unversioned.c
+++ src/unversioned.c
@@ -218,11 +218,11 @@
218218
}
219219
return 0;
220220
}
221221
222222
/*
223
-** COMMAND: uv*
223
+** COMMAND: uv#
224224
** COMMAND: unversioned
225225
**
226226
** Usage: %fossil unversioned SUBCOMMAND ARGS...
227227
** or: %fossil uv SUBCOMMAND ARGS..
228228
**
229229
--- src/unversioned.c
+++ src/unversioned.c
@@ -218,11 +218,11 @@
218 }
219 return 0;
220 }
221
222 /*
223 ** COMMAND: uv*
224 ** COMMAND: unversioned
225 **
226 ** Usage: %fossil unversioned SUBCOMMAND ARGS...
227 ** or: %fossil uv SUBCOMMAND ARGS..
228 **
229
--- src/unversioned.c
+++ src/unversioned.c
@@ -218,11 +218,11 @@
218 }
219 return 0;
220 }
221
222 /*
223 ** COMMAND: uv#
224 ** COMMAND: unversioned
225 **
226 ** Usage: %fossil unversioned SUBCOMMAND ARGS...
227 ** or: %fossil uv SUBCOMMAND ARGS..
228 **
229
+20 -5
--- tools/mkindex.c
+++ tools/mkindex.c
@@ -37,14 +37,18 @@
3737
** and analysis only.
3838
**
3939
** Commands are 1st-tier by default. If the command name begins with
4040
** "test-" or if the command name has a "test" argument, then it becomes
4141
** a test command. If the command name has a "2nd-tier" argument or ends
42
-** with a "*" character, it is second tier. Examples:
42
+** with a "*" character, it is second tier. If the command name has an "alias"
43
+** argument or ends with a "#" character, it is an alias: another name
44
+** (a one-to-one replacement) for a command. Examples:
4345
**
4446
** COMMAND: abcde*
4547
** COMMAND: fghij 2nd-tier
48
+** COMMAND: mnopq#
49
+** COMMAND: rstuv alias
4650
** COMMAND: test-xyzzy
4751
** COMMAND: xyzzy test
4852
**
4953
** A SETTING: may be followed by arguments that give additional attributes
5054
** to that setting:
@@ -93,10 +97,11 @@
9397
#define CMDFLAG_BOOLEAN 0x0100 /* A boolean setting */
9498
#define CMDFLAG_RAWCONTENT 0x0200 /* Do not interpret webpage content */
9599
#define CMDFLAG_SENSITIVE 0x0400 /* Security-sensitive setting */
96100
#define CMDFLAG_HIDDEN 0x0800 /* Elide from most listings */
97101
#define CMDFLAG_LDAVG_EXEMPT 0x1000 /* Exempt from load_control() */
102
+#define CMDFLAG_ALIAS 0x2000 /* Command aliases */
98103
/**************************************************************************/
99104
100105
/*
101106
** Each entry looks like this:
102107
*/
@@ -219,10 +224,15 @@
219224
}else if( zLine[i+j-1]=='*' ){
220225
/* If the command name ends in '*', remove the '*' from the name
221226
** but move the command into the second tier */
222227
aEntry[nUsed].zPath[j-1] = 0;
223228
aEntry[nUsed].eType |= CMDFLAG_2ND_TIER;
229
+ }else if( zLine[i+j-1]=='#' ){
230
+ /* If the command name ends in '#', remove the '#' from the name
231
+ ** but move the command into aliases */
232
+ aEntry[nUsed].zPath[j-1] = 0;
233
+ aEntry[nUsed].eType |= CMDFLAG_ALIAS;
224234
}else{
225235
/* Otherwise, this is a first-tier command */
226236
aEntry[nUsed].eType |= CMDFLAG_1ST_TIER;
227237
}
228238
}
@@ -232,18 +242,21 @@
232242
i += j;
233243
while( fossil_isspace(zLine[i]) ){ i++; }
234244
if( zLine[i]==0 ) break;
235245
for(j=0; zLine[i+j] && !fossil_isspace(zLine[i+j]); j++){}
236246
if( j==8 && strncmp(&zLine[i], "1st-tier", j)==0 ){
237
- aEntry[nUsed].eType &= ~(CMDFLAG_2ND_TIER|CMDFLAG_TEST);
247
+ aEntry[nUsed].eType &= ~(CMDFLAG_2ND_TIER|CMDFLAG_TEST|CMDFLAG_ALIAS);
238248
aEntry[nUsed].eType |= CMDFLAG_1ST_TIER;
239249
}else if( j==8 && strncmp(&zLine[i], "2nd-tier", j)==0 ){
240
- aEntry[nUsed].eType &= ~(CMDFLAG_1ST_TIER|CMDFLAG_TEST);
250
+ aEntry[nUsed].eType &= ~(CMDFLAG_1ST_TIER|CMDFLAG_TEST|CMDFLAG_ALIAS);
241251
aEntry[nUsed].eType |= CMDFLAG_2ND_TIER;
242252
}else if( j==4 && strncmp(&zLine[i], "test", j)==0 ){
243
- aEntry[nUsed].eType &= ~(CMDFLAG_1ST_TIER|CMDFLAG_2ND_TIER);
253
+ aEntry[nUsed].eType &= ~(CMDFLAG_1ST_TIER|CMDFLAG_2ND_TIER|CMDFLAG_ALIAS);
244254
aEntry[nUsed].eType |= CMDFLAG_TEST;
255
+ }else if( j==5 && strncmp(&zLine[i], "alias", j)==0 ){
256
+ aEntry[nUsed].eType &= ~(CMDFLAG_1ST_TIER|CMDFLAG_2ND_TIER|CMDFLAG_TEST);
257
+ aEntry[nUsed].eType |= CMDFLAG_ALIAS;
245258
}else if( j==11 && strncmp(&zLine[i], "raw-content", j)==0 ){
246259
aEntry[nUsed].eType |= CMDFLAG_RAWCONTENT;
247260
}else if( j==7 && strncmp(&zLine[i], "boolean", j)==0 ){
248261
aEntry[nUsed].eType &= ~(CMDFLAG_BLOCKTEXT);
249262
aEntry[nUsed].iWidth = 0;
@@ -453,24 +466,26 @@
453466
if( aEntry[i].zIf ){
454467
printf("%s", aEntry[i].zIf);
455468
}else if( (aEntry[i].eType & CMDFLAG_WEBPAGE)!=0 ){
456469
nWeb++;
457470
}
458
- printf(" { \"%.*s\",%*s%s,%*szHelp%03d, 0x%03x },\n",
471
+ printf(" { \"%.*s\",%*s%s,%*szHelp%03d, %3d, 0x%03x },\n",
459472
n, z,
460473
25-n, "",
461474
aEntry[i].zFunc,
462475
(int)(29-strlen(aEntry[i].zFunc)), "",
476
+ aEntry[i].iHelp,
463477
aEntry[i].iHelp,
464478
aEntry[i].eType
465479
);
466480
if( aEntry[i].zIf ) printf("#endif\n");
467481
}
468482
printf("};\n");
469483
printf("#define FOSSIL_FIRST_CMD %d\n", nWeb);
470484
printf("#define FOSSIL_MX_CMDNAME %d /* max length of any command name */\n",
471485
mxLen);
486
+ printf("#define FOSSIL_MX_CMDIDX %d /* max index for commands */\n", nFixed);
472487
473488
/* Generate the aSetting[] table */
474489
printf("const Setting aSetting[] = {\n");
475490
for(i=0; i<nFixed; i++){
476491
const char *z;
477492
--- tools/mkindex.c
+++ tools/mkindex.c
@@ -37,14 +37,18 @@
37 ** and analysis only.
38 **
39 ** Commands are 1st-tier by default. If the command name begins with
40 ** "test-" or if the command name has a "test" argument, then it becomes
41 ** a test command. If the command name has a "2nd-tier" argument or ends
42 ** with a "*" character, it is second tier. Examples:
 
 
43 **
44 ** COMMAND: abcde*
45 ** COMMAND: fghij 2nd-tier
 
 
46 ** COMMAND: test-xyzzy
47 ** COMMAND: xyzzy test
48 **
49 ** A SETTING: may be followed by arguments that give additional attributes
50 ** to that setting:
@@ -93,10 +97,11 @@
93 #define CMDFLAG_BOOLEAN 0x0100 /* A boolean setting */
94 #define CMDFLAG_RAWCONTENT 0x0200 /* Do not interpret webpage content */
95 #define CMDFLAG_SENSITIVE 0x0400 /* Security-sensitive setting */
96 #define CMDFLAG_HIDDEN 0x0800 /* Elide from most listings */
97 #define CMDFLAG_LDAVG_EXEMPT 0x1000 /* Exempt from load_control() */
 
98 /**************************************************************************/
99
100 /*
101 ** Each entry looks like this:
102 */
@@ -219,10 +224,15 @@
219 }else if( zLine[i+j-1]=='*' ){
220 /* If the command name ends in '*', remove the '*' from the name
221 ** but move the command into the second tier */
222 aEntry[nUsed].zPath[j-1] = 0;
223 aEntry[nUsed].eType |= CMDFLAG_2ND_TIER;
 
 
 
 
 
224 }else{
225 /* Otherwise, this is a first-tier command */
226 aEntry[nUsed].eType |= CMDFLAG_1ST_TIER;
227 }
228 }
@@ -232,18 +242,21 @@
232 i += j;
233 while( fossil_isspace(zLine[i]) ){ i++; }
234 if( zLine[i]==0 ) break;
235 for(j=0; zLine[i+j] && !fossil_isspace(zLine[i+j]); j++){}
236 if( j==8 && strncmp(&zLine[i], "1st-tier", j)==0 ){
237 aEntry[nUsed].eType &= ~(CMDFLAG_2ND_TIER|CMDFLAG_TEST);
238 aEntry[nUsed].eType |= CMDFLAG_1ST_TIER;
239 }else if( j==8 && strncmp(&zLine[i], "2nd-tier", j)==0 ){
240 aEntry[nUsed].eType &= ~(CMDFLAG_1ST_TIER|CMDFLAG_TEST);
241 aEntry[nUsed].eType |= CMDFLAG_2ND_TIER;
242 }else if( j==4 && strncmp(&zLine[i], "test", j)==0 ){
243 aEntry[nUsed].eType &= ~(CMDFLAG_1ST_TIER|CMDFLAG_2ND_TIER);
244 aEntry[nUsed].eType |= CMDFLAG_TEST;
 
 
 
245 }else if( j==11 && strncmp(&zLine[i], "raw-content", j)==0 ){
246 aEntry[nUsed].eType |= CMDFLAG_RAWCONTENT;
247 }else if( j==7 && strncmp(&zLine[i], "boolean", j)==0 ){
248 aEntry[nUsed].eType &= ~(CMDFLAG_BLOCKTEXT);
249 aEntry[nUsed].iWidth = 0;
@@ -453,24 +466,26 @@
453 if( aEntry[i].zIf ){
454 printf("%s", aEntry[i].zIf);
455 }else if( (aEntry[i].eType & CMDFLAG_WEBPAGE)!=0 ){
456 nWeb++;
457 }
458 printf(" { \"%.*s\",%*s%s,%*szHelp%03d, 0x%03x },\n",
459 n, z,
460 25-n, "",
461 aEntry[i].zFunc,
462 (int)(29-strlen(aEntry[i].zFunc)), "",
 
463 aEntry[i].iHelp,
464 aEntry[i].eType
465 );
466 if( aEntry[i].zIf ) printf("#endif\n");
467 }
468 printf("};\n");
469 printf("#define FOSSIL_FIRST_CMD %d\n", nWeb);
470 printf("#define FOSSIL_MX_CMDNAME %d /* max length of any command name */\n",
471 mxLen);
 
472
473 /* Generate the aSetting[] table */
474 printf("const Setting aSetting[] = {\n");
475 for(i=0; i<nFixed; i++){
476 const char *z;
477
--- tools/mkindex.c
+++ tools/mkindex.c
@@ -37,14 +37,18 @@
37 ** and analysis only.
38 **
39 ** Commands are 1st-tier by default. If the command name begins with
40 ** "test-" or if the command name has a "test" argument, then it becomes
41 ** a test command. If the command name has a "2nd-tier" argument or ends
42 ** with a "*" character, it is second tier. If the command name has an "alias"
43 ** argument or ends with a "#" character, it is an alias: another name
44 ** (a one-to-one replacement) for a command. Examples:
45 **
46 ** COMMAND: abcde*
47 ** COMMAND: fghij 2nd-tier
48 ** COMMAND: mnopq#
49 ** COMMAND: rstuv alias
50 ** COMMAND: test-xyzzy
51 ** COMMAND: xyzzy test
52 **
53 ** A SETTING: may be followed by arguments that give additional attributes
54 ** to that setting:
@@ -93,10 +97,11 @@
97 #define CMDFLAG_BOOLEAN 0x0100 /* A boolean setting */
98 #define CMDFLAG_RAWCONTENT 0x0200 /* Do not interpret webpage content */
99 #define CMDFLAG_SENSITIVE 0x0400 /* Security-sensitive setting */
100 #define CMDFLAG_HIDDEN 0x0800 /* Elide from most listings */
101 #define CMDFLAG_LDAVG_EXEMPT 0x1000 /* Exempt from load_control() */
102 #define CMDFLAG_ALIAS 0x2000 /* Command aliases */
103 /**************************************************************************/
104
105 /*
106 ** Each entry looks like this:
107 */
@@ -219,10 +224,15 @@
224 }else if( zLine[i+j-1]=='*' ){
225 /* If the command name ends in '*', remove the '*' from the name
226 ** but move the command into the second tier */
227 aEntry[nUsed].zPath[j-1] = 0;
228 aEntry[nUsed].eType |= CMDFLAG_2ND_TIER;
229 }else if( zLine[i+j-1]=='#' ){
230 /* If the command name ends in '#', remove the '#' from the name
231 ** but move the command into aliases */
232 aEntry[nUsed].zPath[j-1] = 0;
233 aEntry[nUsed].eType |= CMDFLAG_ALIAS;
234 }else{
235 /* Otherwise, this is a first-tier command */
236 aEntry[nUsed].eType |= CMDFLAG_1ST_TIER;
237 }
238 }
@@ -232,18 +242,21 @@
242 i += j;
243 while( fossil_isspace(zLine[i]) ){ i++; }
244 if( zLine[i]==0 ) break;
245 for(j=0; zLine[i+j] && !fossil_isspace(zLine[i+j]); j++){}
246 if( j==8 && strncmp(&zLine[i], "1st-tier", j)==0 ){
247 aEntry[nUsed].eType &= ~(CMDFLAG_2ND_TIER|CMDFLAG_TEST|CMDFLAG_ALIAS);
248 aEntry[nUsed].eType |= CMDFLAG_1ST_TIER;
249 }else if( j==8 && strncmp(&zLine[i], "2nd-tier", j)==0 ){
250 aEntry[nUsed].eType &= ~(CMDFLAG_1ST_TIER|CMDFLAG_TEST|CMDFLAG_ALIAS);
251 aEntry[nUsed].eType |= CMDFLAG_2ND_TIER;
252 }else if( j==4 && strncmp(&zLine[i], "test", j)==0 ){
253 aEntry[nUsed].eType &= ~(CMDFLAG_1ST_TIER|CMDFLAG_2ND_TIER|CMDFLAG_ALIAS);
254 aEntry[nUsed].eType |= CMDFLAG_TEST;
255 }else if( j==5 && strncmp(&zLine[i], "alias", j)==0 ){
256 aEntry[nUsed].eType &= ~(CMDFLAG_1ST_TIER|CMDFLAG_2ND_TIER|CMDFLAG_TEST);
257 aEntry[nUsed].eType |= CMDFLAG_ALIAS;
258 }else if( j==11 && strncmp(&zLine[i], "raw-content", j)==0 ){
259 aEntry[nUsed].eType |= CMDFLAG_RAWCONTENT;
260 }else if( j==7 && strncmp(&zLine[i], "boolean", j)==0 ){
261 aEntry[nUsed].eType &= ~(CMDFLAG_BLOCKTEXT);
262 aEntry[nUsed].iWidth = 0;
@@ -453,24 +466,26 @@
466 if( aEntry[i].zIf ){
467 printf("%s", aEntry[i].zIf);
468 }else if( (aEntry[i].eType & CMDFLAG_WEBPAGE)!=0 ){
469 nWeb++;
470 }
471 printf(" { \"%.*s\",%*s%s,%*szHelp%03d, %3d, 0x%03x },\n",
472 n, z,
473 25-n, "",
474 aEntry[i].zFunc,
475 (int)(29-strlen(aEntry[i].zFunc)), "",
476 aEntry[i].iHelp,
477 aEntry[i].iHelp,
478 aEntry[i].eType
479 );
480 if( aEntry[i].zIf ) printf("#endif\n");
481 }
482 printf("};\n");
483 printf("#define FOSSIL_FIRST_CMD %d\n", nWeb);
484 printf("#define FOSSIL_MX_CMDNAME %d /* max length of any command name */\n",
485 mxLen);
486 printf("#define FOSSIL_MX_CMDIDX %d /* max index for commands */\n", nFixed);
487
488 /* Generate the aSetting[] table */
489 printf("const Setting aSetting[] = {\n");
490 for(i=0; i<nFixed; i++){
491 const char *z;
492
+9 -72
--- www/build.wiki
+++ www/build.wiki
@@ -250,83 +250,19 @@
250250
TCC += -DSQLITE_MAX_MMAP_SIZE=0
251251
</pre></blockquote>
252252
</ul>
253253
254254
255
-<h2 id="docker">5.0 Building a Docker Container</h2>
256
-
257
-Fossil ships a <tt>Dockerfile</tt> at the top of its source tree which
258
-you can build like so:
259
-
260
-<pre><code> $ docker build -t fossil --no-cache .</code></pre>
261
-
262
-If the image built successfully, you can create a container from it and
263
-test that it runs:
264
-
265
-<pre><code> $ docker run --name fossil -p 9999:8080/tcp fossil</code></pre>
266
-
267
-This shows us remapping the internal TCP listening port as 9999 on the
268
-host. As a rule, there's little point to using the "<tt>fossil server
---port</tt>" feature inside a Docker container. Let it default to 8080
269
-internally, then remap it to wherever you want it on the host instead.
270
-
271
-Our stock <tt>Dockerfile</tt> configures Fossil with the default feature
272
-set, so you may wish to modify the <tt>Dockerfile</tt> to add
273
-configuration options, add APK packages to support those options, and so
274
-forth.
275
-
276
-It builds tip-of-trunk. To get a release version instead, append
277
-"<tt>?r=release</tt>" to the URL in the <tt>Dockerfile</tt>, then
278
-(re)build it.
279
-
280
-You may wish to direct Docker to copy an existing repo into the image at
281
-build time, rather than let it create a blank one automatically. Simply
282
-add this to the <tt>Dockerfile</tt> before the first "RUN" directive:
283
-
284
-<pre><code> COPY /local/path/to/my-project.fossil /jail/repo.fossil</code></pre>
285
-
286
-A potentially surprising feature of this container is that it runs
287
-Fossil as root, which causes [./chroot.md | Fossil's chroot jail
288
-feature] to kick in. Since a Docker container is a type of über-jail
289
-already, you may be wondering why we don't either:
290
-
291
- # run <tt>fossil server --nojail</tt> to skip the internal chroot; or
292
- # create a non-root user and force Docker to use that instead
293
-
294
-The reason is, although this container is quite stripped-down by today's
295
-standards, it's based on the [https://www.busybox.net/BusyBox.html |
296
-surprisingly powerful Busybox project]. (This author made a living for
297
-years in the early 1990s using Unix systems that were less powerful than
298
-this container.) If someone ever figured out how to make a Fossil binary
299
-execute arbitrary commands on the host or to open up a remote shell,
300
-they'd likely be able to island-hop from there into the rest of your
301
-network. We need this cute double-jail dance to keep the Fossil instance
302
-from accessing the Busybox features.
303
-
304
-We deem this risk low since a) it's never happened, that we know of;
305
-and b) we've turned off all of the risky features like TH1 docs.
306
-Nevertheless, we believe in defense-in-depth.
307
-
308
-Our 2-stage build process uses Alpine Linux only as a build host. Once
309
-we've got everything reduced to the two key static binaries — Fossil and
310
-Busybox — we throw all the rest of it away.
311
-
312
-A secondary benefit falls out of this process for free: it's arguably
313
-the easiest way to build a purely static Fossil binary for Linux. Most
314
-modern Linux distros make this surprisingly difficult, but Alpine's
315
-back-to-basics nature makes static builds work the way they used to,
316
-back in the day. If that's what you're after, you can skip the "run"
317
-command above and create a temporary container from the image, then
318
-extract the executable from it instead:
319
-
320
-<pre><code> $ docker create --name fossil-static-tmp fossil
321
- $ docker cp fossil-static-tmp:/jail/bin/fossil .
322
- $ docker container rm fossil-static-tmp
323
-</code></pre>
324
-
325
-The resulting binary is the single largest file inside that container,
326
-at about 6 MiB. (It's built stripped.)
255
+<h2 id="docker" name="oci">5.0 Building a Docker Container</h2>
256
+
257
+The information on building Fossil inside an
258
+[https://opencontainers.org/ | OCI container] is now in
259
+[./containers.md | a separate document].
260
+
261
+This includes the instructions on using the OCI container as an
262
+expedient intermediary for building a statically-linked Fossil binary on
263
+modern Linux platforms, which otherwise make this difficult.
327264
328265
329266
<h2>6.0 Building on/for Android</h2>
330267
331268
<h3>6.1 Cross-compiling from Linux</h3>
332269
333270
ADDED www/containers.md
--- www/build.wiki
+++ www/build.wiki
@@ -250,83 +250,19 @@
250 TCC += -DSQLITE_MAX_MMAP_SIZE=0
251 </pre></blockquote>
252 </ul>
253
254
255 <h2 id="docker">5.0 Building a Docker Container</h2>
256
257 Fossil ships a <tt>Dockerfile</tt> at the top of its source tree which
258 you can build like so:
259
260 <pre><code> $ docker build -t fossil --no-cache .</code></pre>
261
262 If the image built successfully, you can create a container from it and
263 test that it runs:
264
265 <pre><code> $ docker run --name fossil -p 9999:8080/tcp fossil</code></pre>
266
267 This shows us remapping the internal TCP listening port as 9999 on the
268 host. As a rule, there's little point to using the "<tt>fossil server
---port</tt>" feature inside a Docker container. Let it default to 8080
269 internally, then remap it to wherever you want it on the host instead.
270
271 Our stock <tt>Dockerfile</tt> configures Fossil with the default feature
272 set, so you may wish to modify the <tt>Dockerfile</tt> to add
273 configuration options, add APK packages to support those options, and so
274 forth.
275
276 It builds tip-of-trunk. To get a release version instead, append
277 "<tt>?r=release</tt>" to the URL in the <tt>Dockerfile</tt>, then
278 (re)build it.
279
280 You may wish to direct Docker to copy an existing repo into the image at
281 build time, rather than let it create a blank one automatically. Simply
282 add this to the <tt>Dockerfile</tt> before the first "RUN" directive:
283
284 <pre><code> COPY /local/path/to/my-project.fossil /jail/repo.fossil</code></pre>
285
286 A potentially surprising feature of this container is that it runs
287 Fossil as root, which causes [./chroot.md | Fossil's chroot jail
288 feature] to kick in. Since a Docker container is a type of über-jail
289 already, you may be wondering why we don't either:
290
291 # run <tt>fossil server --nojail</tt> to skip the internal chroot; or
292 # create a non-root user and force Docker to use that instead
293
294 The reason is, although this container is quite stripped-down by today's
295 standards, it's based on the [https://www.busybox.net/BusyBox.html |
296 surprisingly powerful Busybox project]. (This author made a living for
297 years in the early 1990s using Unix systems that were less powerful than
298 this container.) If someone ever figured out how to make a Fossil binary
299 execute arbitrary commands on the host or to open up a remote shell,
300 they'd likely be able to island-hop from there into the rest of your
301 network. We need this cute double-jail dance to keep the Fossil instance
302 from accessing the Busybox features.
303
304 We deem this risk low since a) it's never happened, that we know of;
305 and b) we've turned off all of the risky features like TH1 docs.
306 Nevertheless, we believe in defense-in-depth.
307
308 Our 2-stage build process uses Alpine Linux only as a build host. Once
309 we've got everything reduced to the two key static binaries — Fossil and
310 Busybox — we throw all the rest of it away.
311
312 A secondary benefit falls out of this process for free: it's arguably
313 the easiest way to build a purely static Fossil binary for Linux. Most
314 modern Linux distros make this surprisingly difficult, but Alpine's
315 back-to-basics nature makes static builds work the way they used to,
316 back in the day. If that's what you're after, you can skip the "run"
317 command above and create a temporary container from the image, then
318 extract the executable from it instead:
319
320 <pre><code> $ docker create --name fossil-static-tmp fossil
321 $ docker cp fossil-static-tmp:/jail/bin/fossil .
322 $ docker container rm fossil-static-tmp
323 </code></pre>
324
325 The resulting binary is the single largest file inside that container,
326 at about 6 MiB. (It's built stripped.)
327
328
329 <h2>6.0 Building on/for Android</h2>
330
331 <h3>6.1 Cross-compiling from Linux</h3>
332
333 DDED www/containers.md
--- www/build.wiki
+++ www/build.wiki
@@ -250,83 +250,19 @@
250 TCC += -DSQLITE_MAX_MMAP_SIZE=0
251 </pre></blockquote>
252 </ul>
253
254
 
 
 
 
 
 
 
 
 
 
 
 
 
 
---port</tt>" feature inside a Docker container. Let it default to 8080
255 <h2 id="docker" name="oci">5.0 Building a Docker Container</h2>
256
257 The information on building Fossil inside an
258 [https://opencontainers.org/ | OCI container] is now in
259 [./containers.md | a separate document].
260
261 This includes the instructions on using the OCI container as an
262 expedient intermediary for building a statically-linked Fossil binary on
263 modern Linux platforms, which otherwise make this difficult.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
265
266 <h2>6.0 Building on/for Android</h2>
267
268 <h3>6.1 Cross-compiling from Linux</h3>
269
270 DDED www/containers.md
--- a/www/containers.md
+++ b/www/containers.md
@@ -0,0 +1,885 @@
1
+surprisingly difficulte make reconfig # re-generate Dockerfile from the changed .in filem at that point would make ngly difficulte remains the same as in the distroless Python example
2
+because even AlpineN@2yP,1R: way we set up core Linux
3
+directories like `/etc` and `/tmp` in the absence of any OS imageAs@3LR,L@3XT,f:github.com/GoogleContainerTools/distrolesChroot?
4
+
5
+A potentially surprising feature of this container is that it runs
6
+Fossil as root. Sin
7
+to kick in, and a Docker container is a type of über-jail already, you
8
+may be wondering why we bother. Instead, why not either:
9
+
10
+* run f][whatso it starts Fossil as
11
+ that user instead
12
+
13
+The reason is, although this container is quite stripped-down by today’s
14
+standards, it’s based on the [surprising(This author made a
15
+ that were less
16
+powerful than this container.) If someone ever figured out how to make a
17
+Fossil binary execute arbitrary commands on the host or to open up a
18
+remote shell, the power available to them at that point would make it
19
+likely that they’d be able to island-hop from there into the rest of
20
+your network. That power is there for you as the system administrator
21
+alone, to let you inspectquire them.
22
+ Altour build
23
+ process leaves out all the BusyBox utilities that require them.
24
+ Although that set includes common tools like `ping`, we It also strips
25
+out all but the default and darkmode skins to save executable space foresee no
26
+ use that or any of these other elided utilities
27
+ — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
28
+fetched in the build step. To get the latest-and-greatest of everything,
29
+you could say\
30
+ trunk \
31
+ --build-arg BBXVER=master .
32
+```
33
+
34
+(But don’t, for reasons we will getwR ship was created with and
35
+tested R
36
+ific stable release, tharun`”.) ration
37
+settings iput a line like this into the first stage:
38
+
39
+```
40
+ COPY containers/os-releaseR/etc/os-release
41
+```
42
+
43
+That will let you produce a `systemd` “m” This is generally better for
44
+security, but there’s something you need to be aware of: each user has
45
+their own local. Let’s say you’re following, so even though it did build the image, you
46
+can’t create the actual container from that image since that needs to be
47
+done as root.
48
+
49
+The simple way to deal with this is to bounce the container through a
50
+registry that both users can see, such as [Docker
51
+Hub](https://hub.docker.tag fossil:latest mydockername/fossil:latest
52
+ $ podman image push mydockername/fossil:latest
53
+```
54
+
55
+That will push the image up to your accound
56
+ process leaves out all the BusyBox utilities that require them.
57
+ Although that set includes common tools like `ping`, we foresee no
58
+ use that or any of these other elided utilities
59
+ — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
60
+fetched in the build step. To get the latest-and-greatest of everything,
61
+you could say\
62
+ trunk \
63
+ --build-arg BBXVER=master .
64
+```
65
+
66
+(But don’t, for reasons we will getwe ship was created with and
67
+tested against a specific stable release, that’s the version we pull by
68
+default. It does try to merge the defaults for any new configuration
69
+settings into the stock set, but since it’s possible this will fail, we
70
+don’t blindly update the BusyBox version merely because a new release
71
+came out. Someone needs to get around to vetting it against our stock
72
+configuration first.
73
+
74
+As for Fossil, it defaults to fetching the same version as the checkout
75
+you’re running the build command from, based on checkin ID. You could
76
+use this to get a release build, for instance\
77
+ our build
78
+ process leaves out all the BusyBox utilities that require them.
79
+ Although that set includes common tools like `ping`, we foresee no
80
+ use that or any of these other elided utilities
81
+ — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
82
+fetched in the build step. To get the latest-and-greatest of everything,
83
+you could say\
84
+ trunk \
85
+ it lets you build on a local system that might be a lot faster
86
+than your remote one, as when the remote is a small VPS. Even with the
87
+overhead of schlepping container images across the Internet, it can be a
88
+net win in terms of build time.
89
+
90
+Another oddity compared to DockerY@760,6: same
91
+h@76d,M:. The changes distill3WC@78M,3SS6XH;One way to can remove the installation of `busybox-static` in STAGE 1 since
92
+Alpine is already based on BusyBox.(^We can’t do “`FROM busybox`” since
93
+we need `apk` in this new second stage. Although this means we end up
94
+with back-to-back Alpine stages, it isn’t redundant; the second one
95
+starts fresh, allowing us to copy in only what we absolutely need from
96
+AWKbecausewe haveRelative to, the change from “`alpmeans we have no BusyBox environment to execute
97
+the `RUN` command with, so we have to copy the `busybox.static` binary
98
+in from STAGE 1 and install
99
+the stock does.(^This is the main reason we change `USER`
100
+temporarily to `root` here.) There are a few other steps required to
101
+avoid causing a conflict between our previously bare-bonerename
102
+il binary executl popular, we have
103
+that ijust a suitable
104
+. Because this will conflict with the
105
+bare-bones “`os`” layer we createulte remains the same as in the distroless Python example
106
+because even AlpineN@2yP,1R: way we set up core Linux
107
+directories like `/etc` and `/tmp` in the absence of any OS imageAs@3LR,L@3XT,f:github.com/GoogleContainerTools/distrolesChroot?
108
+
109
+A potentially surprising feature of this container is that it runs
110
+Fossil as root. Sin
111
+to kick in, and a Docker container is a type of über-jail already, you
112
+may be wondering why we bother. Instead, why not either:
113
+
114
+* run f][whatso it starts Fossil as
115
+ that user instead
116
+
117
+The reason is, although this container is quite stripped-down by today’s
118
+standards, it’s based on the [surprising(This author made a
119
+ that were less
120
+powerful than this container.) If someone ever figured out how to make a
121
+Fossil binary execute arbitrary commands on the host or to open up a
122
+remote shell, the power available to them at that point would make it
123
+likely that they’d be able to island-hop from there into the rest of
124
+your network. That power is there for you as the system administrator
125
+alone, to let you inspectquire them.
126
+ Altour build
127
+ process leaves out all the BusyBox utilities that require them.
128
+ Although that set includes common tools like `ping`, we It also strips
129
+out all but the default and darkmode skins to save executable space foresee no
130
+ use that or any of these other elided utilities
131
+ — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
132
+fetched in the build step. To get the latest-and-greatest of everything,
133
+you could say\
134
+ trunk \
135
+ --build-arg BBXVER=master .
136
+```
137
+
138
+(But don’t, for reasons we will getwR ship was created with and
139
+tested R
140
+ific stable release, tharun`”.) ration
141
+settings iput a line like this into the first stage:
142
+
143
+```
144
+ COPY containers/os-releaseR/etc/os-release
145
+```
146
+
147
+That will let you produce a `systemd` “m” This is generally better for
148
+security, but there’s something you need to be aware of: each user has
149
+their own local. Let’s say you’re following, so even though it did build the image, you
150
+can’t create the actual container from that image since that needs to be
151
+done as root.
152
+
153
+The simple way to deal with this is to bounce the container through a
154
+registry that both users can see, such as [Docker
155
+Hub](https://hub.docker.tag fossil:latest mydockername/fossil:latest
156
+ $ podman image push mydockername/fossil:latest
157
+```
158
+
159
+That will push the image up to your accound
160
+ process leaves out all the BusyBox utilities that require them.
161
+ Although that set includes common tools like `ping`, we foresee no
162
+ use that or any of these other elided utilities
163
+ — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
164
+fetched in the build step. To get the latest-and-greatest of everything,
165
+you could say\
166
+ trunk \
167
+ --build-arg BBXVER=master .
168
+```
169
+
170
+(But don’t, for reasons we will getwe ship was created with and
171
+tested against a specific stable release, that’s the version we pull by
172
+default. It does try to merge the defaults for any new configuration
173
+settings into the stock set, but since it’s possible this will fail, we
174
+don’t blindly update the BusyBox version merely because a new release
175
+came out. Someone needs to get around to vetting it against our stock
176
+configuration first.
177
+
178
+As for Fossil, it defaults to fetching the same version as the checkout
179
+you’re running the build command from, based on checkin ID. You could
180
+use this to get a release build, for instance\
181
+ our build
182
+ process leaves out all the BusyBox utilities that require them.
183
+ Although that set includes common tools like `ping`, we foresee no
184
+ use that or any of these other elided utilities
185
+ — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
186
+fetched in the build step. To get the latest-and-greatest of everything,
187
+you could say\
188
+ trunk \
189
+ it lets you build on a local system that might be a lot faster
190
+than your remote one, as when the remote is a small VPS. Even with the
191
+overhead of schlepping container images across the Internet, it can be a
192
+net win in terms of build time.
193
+
194
+Another oddity compared to DockerY@760,6: same
195
+h@76d,M:. The changes distill3WC@78M,3SS6XH;One way to can remove the installation of `busybox-static` in STAGE 1 since
196
+Alpine is already based on BusyBox.(^We can’t do “`FROM busybox`” since
197
+we need `apk` in this new second stage. Although this means we end up
198
+with back-to-back Alpine stages, it isn’t redundant; the second one
199
+starts fresh, allowing us to copy in only what we absolutely need from
200
+AWKbecausewe haveRelative to, the change from “`alpmeans we have no BusyBox environment to execute
201
+the `RUN` command with, so we have to copy the `busybox.static` binary
202
+in from STAGE 1 and install
203
+the stock does.(^This is the main reason we change `USER`
204
+temporarily to `root` here.) There are a few other steps required to
205
+avoid causing a conflict between our previously bare-bonerename
206
+il binary executl popular, we have
207
+that ijust a suitable
208
+. Because this will conflict with the
209
+bare-bones “`os`” layer we create, thePython the `RUN`
210
+ in from
211
+ the stock
212
+ temporarily to
213
+`root` here.) The compensating bonus is huge: we don’t leave a package
214
+ image, waiting to be abusedhow much the über-jail nature of
215
+c run yous can save you when
216
+like this. For instance, you might have enabled Fossil’s [risky TH1 docs
217
+feature][th1docrisk] along with the Tcl integration feature, which
218
+effectively gives anyone with check-in rights on your repo the ability
219
+to run arbitrary Tcl code on the host when that document is rendered.
220
+The container layer should stop that script
221
+on the host
222
+namespace, but it *can* still make network connect,
223
+so there is at least a *hope* that WAL will work properly across that
224
+boundary. The success of the scheme depends on the `mmap()` and shared
225
+memory system calls being coordinated properly by the OS kernel the two
226
+worlde network cAt some point, someone should perform tests in the hopes of *failing* to
227
+create database corruption in this scenario.
228
+
229
+Why the tortured grammar? Because you cannot prove a negative, being in
230
+this case “SQLite will not corrupt the database in WAL mode if there’s a
231
+container barrier in the way.” All you can prove is that a given test
232
+didn’t cause corruption. With enough tests of sufficient power, you can
233
+begin to make definitive statements, but even then, science is always
234
+provisional, awaiting a single disproving with the Tcl ints give the sysadmin freedom to impose barriers between
235
+the two worlds, so even if you convince yourself that WAL mode is safe
236
+in a given setup, it’s possible to configure it to fail. As if that
237
+weren’t enough, differentg with the Tcl ints have different defaults,
238
+including details like whether shared memory is truly shared between
239
+the host and its containers.
240
+
241
+Until someone gets around to establishing this ground truth and scoping
242
+its applicable range` with:
243
+
244
+ FROM grc.io/distroless/python3-debian11
245
+
246
+Another case
247
+
248
+
249
+Method 2to
250
+ bind-mounted
251
+ `netstat`, `tYou our build
252
+ process leaves out all the BusyBox utilities that require them.
253
+ Although that set includes common tools like `ping`, we
254
+
255
+ R@2VU,5: RUNN@2bU,1Q:
256
+
257
+Everything else remains the same as in the distroless Python example
258
+because even AlpineN@2yP,1R: way we set up core Linux
259
+directories like `/etc` and `/tmp` in the absence of any OS imageAs@3LR,L@3XT,f:github.com/GoogleContainerTools/distroless7Xz@3Z4,qTTBs;exec -it -u fossil fossil sh
260
+```s to get a release build, for instance\
261
+ alternativeAlthough Podman [bills itself][whatis] as a drop-in replacement for the
262
+`docker` command and everything that sits behind it, some of the tool’s
263
+desis run, as compared to
264
+using Docker.
265
+
266
+The most important of these is that, by default, Podman wants to build
267
+and run your container “[rootless].” This is generally better for
268
+security, but there’s something you need to be aware of: each user has
269
+their own local. Let’s say you’re following, so even though it did build the image, you
270
+can’t create the actual container from that image since that needs to be
271
+done as root.
272
+
273
+The simple way to deal with this is to bounce the container through a
274
+registry that both users can see, such as [Docker
275
+Hub](https://hub.docker.tag fossil:latest mydockername/fossil:latest
276
+ $ podman image push mydockername/fossil:latest
277
+```
278
+
279
+That will push the image up to your accound
280
+ process leaves out all the BusyBox utilities that require them.
281
+ Although that set includes common tools like `ping`, we foresee no
282
+ use that or any of these other elided utilities
283
+ — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
284
+fetched in the build step. To get the latest-and-greatest of everything,
285
+you could say\
286
+ trunk \
287
+ --build-arg BBXVER=master .
288
+```
289
+
290
+(But don’t, for reasons we will getwe ship was created with and
291
+tested against a specific stable release, that’s the version we pull by
292
+default. It does try to merge the defaults for any new configuration
293
+settings into the stock set, but since it’s possible this will fail, we
294
+don’t blindly update the BusyBox version merely because a new release
295
+came out. Someone needs to get around to vetting it against our stock
296
+configuration first.
297
+
298
+As for Fossil, it defaults to fetching the same version as the checkout
299
+you’re running the build command from, based on checkin ID. You could
300
+use this to get a release build, for instance\
301
+ our build
302
+ process leaves out all the BusyBox utilities that require them.
303
+ Although that set includes common tools like `ping`, we foresee no
304
+ use that or any of these other elijail��s [risky TH1 docsh user has
305
+their own local. Let’sjailthe image, you
306
+can’t create the actual container from that image since that needs to be
307
+done as root.
308
+
309
+The simple way to deal with this is to bounce the container through a
310
+registry that both users can see, such as [Docker
311
+Hub](https://hub.docker.tag fossil:latest mydockername/fossil:latest
312
+ $ podman image push mydockername/fossil:latest
313
+```
314
+
315
+That will push the image up to your accound
316
+ process leaves out all the BusyBox utilities that require them.
317
+ Although that set includes common tools like `ping`, we foresee no
318
+ use that or any of these other elided utilities
319
+ — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
320
+fetched in the build step. To get the latest-and-greatest of everything,
321
+you could say\
322
+ trunk \
323
+ --build-arg BBXVER=master .
324
+```
325
+
326
+(But don’t, for reasons we will getwe ship was created with and
327
+tested against a specific stable release, that’s the version we pull by
328
+default. It does try to merge the defaults for any new configuration
329
+settings into the stock set, but since it’s possible this will fail, we
330
+don’t blindly update the BusyBox version merely because a new release
331
+came out. Someone needs to get around to vetting it against our stock
332
+configuration first.
333
+
334
+As for Fossil, it defaults to fetching the same version as the checkout
335
+you’re running the build command from, based on checkin ID. You could
336
+use this to get a release build, for instance\
337
+ our build
338
+ process leaves out all the BusyBox utilities that require them.
339
+ Although that set includes common tools like `ping`, we foresee no
340
+ use that or any of these other elided utilities
341
+ — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
342
+fetched in the build step. To get the latest-and-greatest of everything,
343
+you could say\
344
+ trunk \
345
+ it lets you build on a local system that might be a lot faster
346
+than your remote one, as when the remote is a small VPjailAlthough that set includes common tools like `ping`, we foresee no
347
+ use that or any of these other elided utilities
348
+ — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
349
+fetched in the build step. To get the latest-and-greatest of everything,
350
+you could say\
351
+ trunk \
352
+ --build-arg BBXVER=master .
353
+```
354
+
355
+(But don’t, for reasons we will getwe ship was created with and
356
+tested against a specific stable release, that’s the version we pull by
357
+default. It does try to merge the defaults for any new configuration
358
+settings into the stock set, but since it’s possible this will fail, we
359
+don’t blindly update the BusyBox version merely because a new release
360
+came out. Someone needs to get around to vetting it against our stock
361
+configuration first.
362
+
363
+As for Fossil, it defaults to fetching the same version as the checkout
364
+you’re running the build command from, based on checkin ID. You could
365
+use this to get a release build, for instance\
366
+ alternativeAlthough Podman [bills itself][whatis] as a drop-in replacement for the
367
+`docker` command and everything that sits behind it, some of the tool’s
368
+desis run, as compared to
369
+using Docker.
370
+
371
+The most important of thesour ��s [risky TH1 docs
372
+feature][th1docrisk] along with the Tcl integration feature, which
373
+effectively gives anyone with check-in rights on your repo the ability
374
+to run arbitrary Tcl code on the host when that document is rendered.
375
+The container layer should stop that script
376
+on the host
377
+namespace, but it *can* still make network connections, modify the repo
378
+, and who knows what else//fossil-scm.org/forum/forumpost/42e0c165447Vw@3X~,25L~sx;adviceYou could inject that into
379
+one of s. Because this will
380
+
381
+complicated. Essentially, you replace everything in STAGE 2 and 3 inside
382
+the `Dockerfile` with:
383
+
384
+ FROM grc.io/distroless/python3-debian11
385
+
386
+Another case
387
+
388
+
389
+Method 2to
390
+ bind-mounted
391
+ `netstat`, `tYou our build
392
+ process leaves out all the BusyBox utilities that require them.
393
+ Although that set includes common tools like `ping`, we
394
+
395
+ R@2VU,5: RUNN@2bU,1Q:
396
+
397
+Everything else remains the same as in the distroless Python example
398
+because even AlpineN@2yP,1R: way we set up core Linux
399
+directories like `/etc` and `/tmp` in the absence of any OS imageAs@3LR,L@3XT,f:github.com/GoogleContainerTools/distroless7Xz@3Z4,qTTBs; bonus is huge: we don’t leave a package
400
+ image, waiting to be abusedhow much the über-jail nature of
401
+c run yous can save you when
402
+like this. For instance, you might have enabled Fossil’s [risky TH1 docs
403
+feature][th1docrisk] along with the Tcl integration feature, which
404
+effectively gives anyone with check-in rights on your repo the ability
405
+to run arbitrary Tcl code on the hThe first configurationtainer is that it runs
406
+Fossil as root. Sin
407
+to kick in, and a Docker container is a type of über-jail already, you
408
+may be wondering why we bother. Instead, why not either:
409
+
410
+* run nojail` to skip the internal chroot; or
411
+* set “`USER fossil`” inbills itself][whatso it starts Fossil as
412
+ that user instead
413
+
414
+The reason is, although this container is quite stripped-down by today’s
415
+standards, it’s based on the [surprising(This author made a
416
+ that were less
417
+powerful than this container.) If someone ever figured out how to make a
418
+Fossil binary execute arbitrary commands on the host or to open up a
419
+remote shell, the power available to them at that point would make it
420
+likely that they’d be able to island-hop from there into the rest of
421
+your network. That power is there for you as the system administrator
422
+alone, to let you inspectinto
423
+a “machine,” as `systemd` calls it. The easiest method ishese other elided utilitiile/Dockerfile)we ship was created with and
424
+tested against a specific stable release, that’s the version we pull by
425
+default. It does try to merge theour build
426
+ process leave`tYou our build
427
+ process leaves out all the BusyBox utilities that require them.
428
+ Although that set includes common tools like `ping`, we
429
+
430
+ R@2VU,5: RUNN@2bU,1Q:
431
+
432
+Everything else remains the same as in the distroless Python example
433
+because even AlpineN@2yP,1R: way we set up core Linux
434
+directories like `/etc` and `/tmp` in the absence of any OS imageAs@3LR,L@3XT,f:github.com/GoogleContainerTools/distrolesChroot?
435
+
436
+A potentially surprising feature of this container is that it runs
437
+Fossil as root. Sin
438
+to kick in, and a Docker container is a type of über-jail already, you
439
+may be wondering why we bother. Instead, why not either:
440
+
441
+* run nojail` to skip the internal chroot; or
442
+* set “`USER fossil`” inbills itself][whatso it starts Fossil as
443
+ that user instead
444
+
445
+The reason is, although this container is quite stripped-down by today’s
446
+standards, it’s based on the [surprising(This author made a
447
+ that were less
448
+powerful than this container.) If someone ever figured out how to make a
449
+Fossil binary execute arbitrary commands on the host or to open up a
450
+remote shell, the power available to them at that point would make it
451
+likely that they’d be able to island-hop from there into the rest of
452
+your network. That power is thercess leaves out alainst a specific stable release, that’s the version we pull by
453
+default. It does try to merge the defaults for any new configuration
454
+settiy new configuration
455
+settings i:noja
456
+
457
+A potentially surprissurprisingly difficulte remains the same as in the distroless Python example
458
+because even AlpineN@2yP,1R: way we set up core Linux
459
+directories like `/etc` and `/tmp` in the absence of any OS imageAs@3LR,L@3XT,f:github.com/GoogleContainerTools/distrolesChroot?
460
+
461
+A potentially surprising feature of this container is that it runs
462
+Fossil as root. Sin
463
+to kick in, and a Docker container is a type of über-jail already, you
464
+may be wondering why we bother. Instead, why not either:
465
+
466
+* run f][whatso it starts Fossil as
467
+ that user instead
468
+
469
+The reason is, although this container is quite stripped-down by today’s
470
+standards, it’s base4 on the [surprising(This auth and packed with [UPX].)
471
+
472
+[U//upx.github.io/6gF@488,2Ne3im;ofetgly difficulte remains the same as in the distroless Python example
473
+because even AlpineN@2yP,1R: way we set up core Linux
474
+directories like `/etc` and `/tmp` in the absence of any OS imageAs@3LR,L@3XT,f:github.com/GoogleContainerTools/distrolesChroot?
475
+
476
+A potentially surprisinculte ripped-down by today’s
477
+standards, it’s based on the [surprising(This author made a
478
+ that were less
479
+powerful than this container.) If someone ever figured out how to make a
480
+Fossil binary execute arbitrary commands on the host or to open up a
481
+remote shell, the power available to them at that point would make it
482
+likely that they’d be able to island-hop from there into the rest of
483
+your network. That power is there for you as the system administrator
484
+alone, to let you inspectquire them.
485
+ Altour build
486
+ process leaves out all the BusyBox utilities that require them.
487
+ Although that set includes common tools like `ping`, we foresee no
488
+ use that or any of these other elided utilities
489
+ — `ether-wake`, `netstat`, `tYou can override The most
490
+common reason to override this is to get a release versionns of Fossil and Bstep. To get the latest-19 .
491
+```
492
+
493
+It’s bestguration
494
+settings iput a line lik rather thanversion we pull by
495
+default. It dobecauss into the first stage:
496
+
497
+```
498
+ COPY containers/os-release /etc/os-release
499
+```
500
+
501
+That will let you pway to can remove the installation of `busybox-static` in STAGE 1 since
502
+Alpine is already based on BusyBox.(^We can’t do “`FURL hasn’t changed, if you hav Alpine stages, it isn’t redundant; the second one
503
+starts fresh, allowing us to copy in only what we absolutely need from
504
+AWKbecausewe haveRelative to, the change from “`alpmeans we have no BusyBox environment to execute
505
+the `RUN` command with, so we have to copy the `busybox.static` binary
506
+in from STAGE 1 and install
507
+the stock does.(^This is the main reason we change `USER`
508
+temporarily to `root` here.) There are a few other steps required to
509
+avoid causing a conflict between our previously bare-bones “OS” layer
510
+and what the is hassleinTcl popular, we have
511
+that intovia a suitable
512
+. Because this will conflict with the
513
+bare-bones “`os`” laye(./server/)create, thePython the `RUN`
514
+ in from
515
+ the stock
516
+ temporarily to
517
+`root` here.) The compensating bonus is huge: we don’t leave a package
518
+ image, waiting to be abusedhow much the über-jail nature of
519
+c run yous can save you when
520
+like this. For instance, you might have enabled Fossil’s [risky TH1 docs
521
+feature][th1docrisk] along with the Tcl integration feature, which
522
+effectively gives anyone with check-in rights on your repo the ability
523
+to run arbitrary Tcl code on the host when that document is rendered.
524
+The container layer should stop that script
525
+on the host
526
+namespace, but it *can* still make network connections, modify the repo
527
+, and who knows what else//fossil-scm.org/forum/forumpost/42e0c165447Vw@3X~,25L~sx;adviceYou could inject that into
528
+one of s. Because this will
529
+
530
+complicated. Essentially, you replace everything in STAGE 2 and 3 inside
531
+the `Dockerfile` with:
532
+
533
+ FROM grc.io/distroless/python3-debian11
534
+
535
+Another case
536
+
537
+
538
+Method 2to
539
+ bind-mounted
540
+ `netstat`, `tYou our build
541
+ process leaves out all the BusyBox utilities that require them.
542
+ Although that set includes common tools like `ping`, we
543
+
544
+ R@2VU,5: RUNN@2bU,1Q:
545
+
546
+Everything else remains the same as in the distroless Python example
547
+because even AlpineN@2yP,1R: way we set up core Linux
548
+directories like `/etc` and `/tmp` in the absence of any OS imageAs@3LR,L@3XT,f:github.com/GoogleContainerTools/distroless7Xz@3Z4,qTTBs;exec -it -u fossil fossil sh
549
+```s to get a release build, for instance\
550
+ alternativeAlthough Podman [bills itself][whatis] as a drop-in replachassleinTcl popular, we have
551
+that intovia a suitable
552
+. Because this will conflict with the
553
+bare-bones “`os`” layer we create, thePython the `RUN`
554
+ in from
555
+ the stock
556
+ temporarily to
557
+`root` here.) The compensating bonus is huge: we don’t leave a package
558
+ image, waiting to be abusedhow much the über-jail nature of
559
+c run yous can save you when
560
+like this. For instance, you might have enabled Fossil’s [risky TH1 docs
561
+feature][th1docrisk] along with the Tcl integration feature, which
562
+effectively gives anyone with check-in rights on your repo the ability
563
+to run arbitrary Tcl code on the host when that document is rendered.
564
+The container layer should stop that script
565
+on the host
566
+namespace, but it *can* still makerunck connections, modify the repo
567
+, and who knows what else//fossil-scm.org/forum/forumpost/42e0c165447Vw@3X~,25L~sx;adviceYou could inject that into
568
+one of s.It’s possible to dig into the subtree
569
+managed by `containerd` on the build host and se other elided utilities
570
+ — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
571
+fetched in the build step. To get the latest-and-greatest of everything,
572
+you could say\
573
+ trunk \
574
+ --build-arg BBXVER=master .
575
+```
576
+
577
+(But don’t, for reasons we will getwe ship was created with and
578
+tested against a specific stable release, that’s the version we pull by
579
+default. It does try to merge the defaults for any new configuration
580
+settings into the stock set, but since it’s possible this will fail, we
581
+don’t blindly update the BusyBox version merely because a new release
582
+came out. Someone needs to get around to vetting it against our stock
583
+configuration first.
584
+
585
+As for Fossil, it defaults to fetching the same version as the checkout
586
+you’re running the build command from, based on checkin ID. You could
587
+use this to get a release build, for instance\
588
+ alternativeAlthough Podman [bills itself][whatis] as a drop-in replacement for the
589
+`docker` command and everything that sits behind it, some of the tool’s
590
+desis run, as compared to
591
+using Docker.
592
+
593
+The most important of thesour ��s [risky TH1 docs
594
+feature][th1docrisk] along with the Tcl integration feature, which
595
+effectively gives anyone with check-in rights on your repo the ability
596
+to run arbitrary Tcl code on the host when that document is rendered.
597
+The container layer should stop that script
598
+on the host
599
+namespace, but it *can* still make network connections, modify the repo
600
+, and who knows what else//fossil-scm.org/forum/forumpost/42e0c165447Vw@3X~,25L~sx;adviceYou could inject that into
601
+one of s. Because this will
602
+
603
+complicated. Essentially, you replace everything in STAGE 2 and 3 inside
604
+the `Dockerfile` with:
605
+
606
+ FROM grc.io/distroless/python3-debian11
607
+
608
+Another case
609
+
610
+
611
+Method 2to
612
+ bind-mounted
613
+ `netstat`, `tYou our build
614
+ process leaves out all the BusyBox utilities that require them.
615
+ Although that set includes common tools like `ping`, we
616
+
617
+ R@2VU,5: RUNN@2bU,1Q:
618
+
619
+Everythin (g else remains the same as in the distroless Pytrhon example
620
+because even AlpineN@2yP,1R: way we set up core Linux
621
+directories like `/etc` and `/)”, as systemdIt’s important that the name of the machine you create &mdash;in this example &mdash; matches tason is, although tsand it will contain. For one[SCGI proxying via nginx][DNT]. For
622
+other use cases, see our collection of [Fossil server configuration
623
+guides][srv], then adjust the command to your local needs.
624
+For another, you will likely have to adjust the `
625
+in the command.
626
+
627
+W.
628
+
629
+S,ngly diffiemains the same as incert /path/to/my/fullchainhas no option for installneeds for so, the
630
+. Thus,-rune reason is, although this containesurprisingly Fossil server configuration
631
+guides][srv], then adjust the command to your local needs.
632
+For another, you will likely have to adjust the `
633
+in the command.
634
+
635
+W.
636
+
637
+S,ngly diffiemains the same as incert /path/to/my/fullchainhas no option for installneeds for so, the
638
+. Thus,Copy the container name from the first step to the second. Yours will
639
+almost certainly be named after a different Fossil commit ID.en adjust the command to your local needs.
640
+For another, you will likely have to adjust the `
641
+in the command.
642
+
643
+W.
644
+
645
+S,ngly diffiemains the same barebones"></a>Bahas no option for installneeds for so, the
646
+. Thus,virtual net
647
+ it wants to hide the service entirely.
648
+
649
+ Another way to put this is thatthing* of what pped-down by today’s
650
+s` does
651
+ despite their superficial similarities.
652
+
653
+ For this container, it doesn’t much matter, since it exposes
654
+ only a single port, and we do want that one port exposed, one way
655
+ or another. Beyond that, weby today’s
656
+standards, it’surprisingly difficulte remains the same as in the distroless Python example
657
+because even AlpineN@2yP,1R: way we set up core Linux
658
+directories like `/etc` and `/tmp` in the absence of any OS imageAs@3LR,L@3XT,f:github.com/GoogleContainerTools/distrolesChroot?
659
+
660
+A potentially surprising feature of this container is that it runs
661
+Fossil as root. Sin
662
+to kick in, and a Docker container is a type of über-jail already, you
663
+may be wondering why we bother.I:
664
+
665
+1. `systemd-nspawn` works best with `machinectl`, but if you haven’t
666
+ got `btrfs` available, you run into [trouble](#nspawn-rhel).
667
+
668
+2. O@760,6: same
669
+h@76d
670
+ a strip
671
+ image, causing ly difficulte remains the same as in the distroless Python exampleemains the same as in the distroless Python example
672
+because even Al tutorial][medtut].)
673
+
674
+3. We disable the “private networking” feature since the whole
675
+ point of this container is to expose a network service to the
676
+ public, one way or another. If you do things the way the defaults
677
+ (and thus the official docs) expect, you must push through
678
+ [a whole lot of complexity][ndcmp] to re-expose this single
679
+ network port. That complexity is justified only if your service
680
+ is itself complex, having both privatyou still have options for
681
+running containers that are considerably slimmer, at a high cost to
682
+administration complexity and loss of features.
683
+
684
+Part of the OCI standard is the notion of a “bundle,” being a consistent
685
+way to present a pre-built and configured container to the runtime.
686
+Essentially, it consists of a directory containing a `config.json` file
687
+and a `rootfs/` subdirectory containing the root filesystem image. Many
688
+tools can produce these for you. We’ll show only one method in the first
689
+section below, then reuse that in the following sections.
690
+
691
+
692
+#### 6.3.1 <a id="runc"></a>`runc`
693
+
694
+We mentioned `runc` [above](#nerdctl), but it’s possible to use it
695
+standalone, without `containerd` or its CLI frontend `nerdctl`. You also
696
+lose the build engine, intelligent image layer sharing, image registry
697
+connections, and much more. The plus side is that `runc` alone is
698
+18 MiB.
699
+
700
+Using it without stable release, that’s the version we pull by
701
+default. It does try to merge the defaults for any new configuration
702
+settings into the stock set, but since it’s possible this will fail, we
703
+don’t blindly update the BusyBox version merely because a new release
704
+came out. Someone needs to get around to vetting it against our stock
705
+configuration first.
706
+
707
+As for Fossil, it defaults to fetching the same version as the checkout
708
+you’re running the build command from, based on checkin ID. You could
709
+use this to get a release build, for instance\
710
+ our build
711
+ process leaves out all the BusyBox utilities that require them.
712
+ Although that set includes common tools like `ping`, we foresee no
713
+ use that or any of these other elided utilities
714
+ — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
715
+fetched in the build step. To get the latest-and-greatest of everything,
716
+you could say\
717
+ trunk \
718
+ it lets you build on a local system that might be a lot faster
719
+than your remote one, as when the remote is a small VPjailAlthough that set includes common tools like `ping`, we foresee no
720
+ use that or any of these other elided utilities
721
+ — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
722
+fetched in the build step. To get the latest-and-greatest of everything,
723
+you could say\
724
+ trunk \
725
+ --build-arg BBXVER=master .
726
+```
727
+
728
+(But don’t, for reasons we will getwe ship was created with and
729
+tested against a specific stable release, that’s the version we pull by
730
+default. It does try to merge the defaults for any new configuration
731
+settings into the stock set, but since it’s possible this will fail, we
732
+don’t blindly update the BusyBox version merely because a new release
733
+came out. Someone needs to get around to vetting it against our stock
734
+configuration first.
735
+
736
+As for Fossil, it defaults to fetching the same version as the checkout
737
+you’re running the build command from, based on checkin ID. You could
738
+use this to get a release build, for instance\
739
+ alternativeAlthough Podman [bills itself][whatis] as a drop-in replacement for the
740
+`docker` command and everything that sits behind it, some of the tool’s
741
+desis run, as compared to
742
+using Docker.
743
+
744
+The most important of thesour ��s [risky TH1 docs
745
+feature][th1docrisk] along with the Tcl integration feature, which
746
+effectively gives anyone with check-in rights on your repo the ability
747
+to run arbitrary Tcl code on the host when that document is rendered.
748
+The container layer should stop that script
749
+on the host
750
+namespace, but it *can* still make network connections, modify the repo
751
+, and who knows what else//fossil-scm.org/forum/forumpost/42e0c165447Vw@3X~,25L~sx;adviceYou could inject that into
752
+one of s. Because this will
753
+
754
+complicated. Essentially, you replace everything in STAGE 2 and 3 inside
755
+the `Dockerfile` with:
756
+
757
+ FROM grc.io/distroless/python3-debian11
758
+
759
+Another case
760
+
761
+
762
+Method 2to
763
+ bind-mounted
764
+ `netstat`, `tYou our build
765
+ process leaves out all the BusyBox utilities that require them.
766
+ Although that set includes common tools like `ping`, we
767
+
768
+ R@2VU,5: RUNN@2bU,1Q:
769
+
770
+Everythin (g else remains the same as in the distroless Pytrhon example
771
+because even AlpineN@2yP,1R: way we set up core Linux
772
+directories like `/etc` and `/)”, as systemdIt’s important that the name of the machine you create &mdash;in this example &mdash; matches tason is, although tsand it will contain. For one[SCGI proxying via nginx][DNT]. For
773
+other use cases, see our collection of [Fossil server configuration
774
+guides][srv], then adjust the command to your local needs.
775
+For another, you will likely have to adjust the `
776
+in the command.
777
+
778
+W.
779
+
780
+S,ngly diffiemains the same as incert /path/to/my/fullchainhas no option for installneeds for so, the
781
+. Thus,-rune reason is, although this containesurprisingly Fossil server configuration
782
+guides][srv], then adjust the command to your local needs.
783
+For another, you will likely have to adjust the `
784
+in the command.
785
+
786
+W.
787
+
788
+S,ngly diffiemains the same as incert /path/to/my/fullchainhas no option for installneeds for so, the
789
+. Thus,Copy the container name from the first step to the second. Yours will
790
+almost certainly be named after a different Fossil commit ID.en adjust the command to your local needs.
791
+For another, you will likely have to adjust the `
792
+in the command.
793
+
794
+W.
795
+
796
+S,ngly diffiemains the same as incert /path/to/my/fullchainhas no option for installneeds for so, the
797
+. Thus,virtual net
798
+ it wants to hide the service entirely.
799
+
800
+ Another way to put this is thatthing* of what pped-down by today’s
801
+s` does
802
+ despite their superficial similarities.
803
+
804
+ For this container, it doesn’t much matter, since it exposes
805
+ only a single port, and we do want that one port exposed, one way
806
+ or another. Beyond that, weby today’s
807
+standards, it’surprisingly difficulte remains the same as in the distroless Python example
808
+because even AlpineN@2yP,1R: way we set up core Linux
809
+directories like `/etc` and `/tmp` in the absence of any OS imageAs@3LR,L@3XT,f:github.com/GoogleContainerTools/distrolesChroot?
810
+
811
+A potentially surprising feature of this container is that it runs
812
+Fossil as root. Sin
813
+to kick in, and a Docker container is a type of über-jail already, you
814
+may be wondering why we bother.I:
815
+
816
+1. `systemd-nspawn` works best with `machinectl`, but if you haven’t
817
+ , you’ll get the old versionstages, it isn’t redundant; the second one
818
+starts fresh, allowing us to copy in only what we absolutely need from
819
+AWKbecausewe haveRelative to, the change from “`alpmeans we have no BusyBox environment to execute
820
+the `RUN` command with, so we have to copy the `busybox.static` binary
821
+in from STAGE 1 and install
822
+the stock does.(^This is the main reason we change `USER`
823
+temporarily to `root` here.) There are a few other steps required to
824
+avoid causing a conflict between our previously bare-bones “OS” layer
825
+and what the is hassleinTcl popular, we have
826
+that int elsewhere with `runc`, leaving out all the
827
+rest. `runc` alone is about 18 MiB, and you can do without `containerd`
828
+entirely, if you want.
829
+
830
+The methode options for
831
+running containers ns for
832
+running containers that
833
+script:
834
+
835
+----
836
+
837
+```shell
838
+#!/bin/sh
839
+c=fossil
840
+b=$HOME/containers/$c
841
+r=$b/rootfst includes common tools lik
842
+if [ -d "$t" ] && mkdir -p $r— `ether-wake`, `netstat`, `tYou can override the default versions| sudo tar -C $r -xf -BusyBox that get
843
+fetched in the build step. To get the latest-and-greatest of ev|
844
+ jq '.ro that user instead
845
+
846
+The reasurprisingly diff a specific stable release, that |
847
+ ly update the BusyBox versiname"))' |
848
+ ly update the BusyBox vresolv.conf"))' |
849
+ ly update the BusyBox version me |
850
+ jq 'dethe build command from, based on checkin ID. You could
851
+use this to get a release build, for instance\
852
+ alternativeAlthough Podman [bills itself][whatis] as a drop-in replacement for the
853
+`docker` command and everything that sits behind it, some of the tool’s
854
+desis run, as compared to
855
+using Docker.
856
+
857
+The most important of thesour ��s [risky TH1 docs
858
+feature][th1docrisk] along with the Tcl integration feature, which
859
+effectively gives anyone with check-in rights on your repo the ability
860
+to run arbitrary Tcl code on the host when that document is rendered.
861
+The container layer should stop that script
862
+on the host
863
+namespace, but it *can* still make network connections, modify the repo
864
+, and who knows what else//fossil-scm.org/forum/forumpost/42e0c165447Vw@3X~,25L~sx;adviceYou could inject that into
865
+one of s. Because this will
866
+
867
+complicated. Essentially, you replace everything in STAGE 2 and 3 inside
868
+the `Dockerfile` with:
869
+
870
+ FROM grc.io/distroless/python3-debian11
871
+
872
+Another case
873
+
874
+
875
+Method 2to
876
+ bind-mounted
877
+ `netstat`, `tYou our build
878
+ process leaves out all the BusyBox utilities that require them.
879
+ Although that set includes common tools like `ping`, we
880
+
881
+ R@2VU,5: RUNN@2bU,1Q:
882
+
883
+Everythin (g else remains the same as in the distroless Pytrhon example
884
+because even AlpineN@2yP,1R: way we set up core Linux
885
+directories like `/etc` and `/)”, as systemdIt’s important that the name of the machine you create &mdash;in this example &mdash; matches tason is, although tsand it will contain. For one[SCGI p
--- a/www/containers.md
+++ b/www/containers.md
@@ -0,0 +1,885 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/www/containers.md
+++ b/www/containers.md
@@ -0,0 +1,885 @@
1 surprisingly difficulte make reconfig # re-generate Dockerfile from the changed .in filem at that point would make ngly difficulte remains the same as in the distroless Python example
2 because even AlpineN@2yP,1R: way we set up core Linux
3 directories like `/etc` and `/tmp` in the absence of any OS imageAs@3LR,L@3XT,f:github.com/GoogleContainerTools/distrolesChroot?
4
5 A potentially surprising feature of this container is that it runs
6 Fossil as root. Sin
7 to kick in, and a Docker container is a type of über-jail already, you
8 may be wondering why we bother. Instead, why not either:
9
10 * run f][whatso it starts Fossil as
11 that user instead
12
13 The reason is, although this container is quite stripped-down by today’s
14 standards, it’s based on the [surprising(This author made a
15 that were less
16 powerful than this container.) If someone ever figured out how to make a
17 Fossil binary execute arbitrary commands on the host or to open up a
18 remote shell, the power available to them at that point would make it
19 likely that they’d be able to island-hop from there into the rest of
20 your network. That power is there for you as the system administrator
21 alone, to let you inspectquire them.
22 Altour build
23 process leaves out all the BusyBox utilities that require them.
24 Although that set includes common tools like `ping`, we It also strips
25 out all but the default and darkmode skins to save executable space foresee no
26 use that or any of these other elided utilities
27 — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
28 fetched in the build step. To get the latest-and-greatest of everything,
29 you could say\
30 trunk \
31 --build-arg BBXVER=master .
32 ```
33
34 (But don’t, for reasons we will getwR ship was created with and
35 tested R
36 ific stable release, tharun`”.) ration
37 settings iput a line like this into the first stage:
38
39 ```
40 COPY containers/os-releaseR/etc/os-release
41 ```
42
43 That will let you produce a `systemd` “m” This is generally better for
44 security, but there’s something you need to be aware of: each user has
45 their own local. Let’s say you’re following, so even though it did build the image, you
46 can’t create the actual container from that image since that needs to be
47 done as root.
48
49 The simple way to deal with this is to bounce the container through a
50 registry that both users can see, such as [Docker
51 Hub](https://hub.docker.tag fossil:latest mydockername/fossil:latest
52 $ podman image push mydockername/fossil:latest
53 ```
54
55 That will push the image up to your accound
56 process leaves out all the BusyBox utilities that require them.
57 Although that set includes common tools like `ping`, we foresee no
58 use that or any of these other elided utilities
59 — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
60 fetched in the build step. To get the latest-and-greatest of everything,
61 you could say\
62 trunk \
63 --build-arg BBXVER=master .
64 ```
65
66 (But don’t, for reasons we will getwe ship was created with and
67 tested against a specific stable release, that’s the version we pull by
68 default. It does try to merge the defaults for any new configuration
69 settings into the stock set, but since it’s possible this will fail, we
70 don’t blindly update the BusyBox version merely because a new release
71 came out. Someone needs to get around to vetting it against our stock
72 configuration first.
73
74 As for Fossil, it defaults to fetching the same version as the checkout
75 you’re running the build command from, based on checkin ID. You could
76 use this to get a release build, for instance\
77 our build
78 process leaves out all the BusyBox utilities that require them.
79 Although that set includes common tools like `ping`, we foresee no
80 use that or any of these other elided utilities
81 — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
82 fetched in the build step. To get the latest-and-greatest of everything,
83 you could say\
84 trunk \
85 it lets you build on a local system that might be a lot faster
86 than your remote one, as when the remote is a small VPS. Even with the
87 overhead of schlepping container images across the Internet, it can be a
88 net win in terms of build time.
89
90 Another oddity compared to DockerY@760,6: same
91 h@76d,M:. The changes distill3WC@78M,3SS6XH;One way to can remove the installation of `busybox-static` in STAGE 1 since
92 Alpine is already based on BusyBox.(^We can’t do “`FROM busybox`” since
93 we need `apk` in this new second stage. Although this means we end up
94 with back-to-back Alpine stages, it isn’t redundant; the second one
95 starts fresh, allowing us to copy in only what we absolutely need from
96 AWKbecausewe haveRelative to, the change from “`alpmeans we have no BusyBox environment to execute
97 the `RUN` command with, so we have to copy the `busybox.static` binary
98 in from STAGE 1 and install
99 the stock does.(^This is the main reason we change `USER`
100 temporarily to `root` here.) There are a few other steps required to
101 avoid causing a conflict between our previously bare-bonerename
102 il binary executl popular, we have
103 that ijust a suitable
104 . Because this will conflict with the
105 bare-bones “`os`” layer we createulte remains the same as in the distroless Python example
106 because even AlpineN@2yP,1R: way we set up core Linux
107 directories like `/etc` and `/tmp` in the absence of any OS imageAs@3LR,L@3XT,f:github.com/GoogleContainerTools/distrolesChroot?
108
109 A potentially surprising feature of this container is that it runs
110 Fossil as root. Sin
111 to kick in, and a Docker container is a type of über-jail already, you
112 may be wondering why we bother. Instead, why not either:
113
114 * run f][whatso it starts Fossil as
115 that user instead
116
117 The reason is, although this container is quite stripped-down by today’s
118 standards, it’s based on the [surprising(This author made a
119 that were less
120 powerful than this container.) If someone ever figured out how to make a
121 Fossil binary execute arbitrary commands on the host or to open up a
122 remote shell, the power available to them at that point would make it
123 likely that they’d be able to island-hop from there into the rest of
124 your network. That power is there for you as the system administrator
125 alone, to let you inspectquire them.
126 Altour build
127 process leaves out all the BusyBox utilities that require them.
128 Although that set includes common tools like `ping`, we It also strips
129 out all but the default and darkmode skins to save executable space foresee no
130 use that or any of these other elided utilities
131 — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
132 fetched in the build step. To get the latest-and-greatest of everything,
133 you could say\
134 trunk \
135 --build-arg BBXVER=master .
136 ```
137
138 (But don’t, for reasons we will getwR ship was created with and
139 tested R
140 ific stable release, tharun`”.) ration
141 settings iput a line like this into the first stage:
142
143 ```
144 COPY containers/os-releaseR/etc/os-release
145 ```
146
147 That will let you produce a `systemd` “m” This is generally better for
148 security, but there’s something you need to be aware of: each user has
149 their own local. Let’s say you’re following, so even though it did build the image, you
150 can’t create the actual container from that image since that needs to be
151 done as root.
152
153 The simple way to deal with this is to bounce the container through a
154 registry that both users can see, such as [Docker
155 Hub](https://hub.docker.tag fossil:latest mydockername/fossil:latest
156 $ podman image push mydockername/fossil:latest
157 ```
158
159 That will push the image up to your accound
160 process leaves out all the BusyBox utilities that require them.
161 Although that set includes common tools like `ping`, we foresee no
162 use that or any of these other elided utilities
163 — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
164 fetched in the build step. To get the latest-and-greatest of everything,
165 you could say\
166 trunk \
167 --build-arg BBXVER=master .
168 ```
169
170 (But don’t, for reasons we will getwe ship was created with and
171 tested against a specific stable release, that’s the version we pull by
172 default. It does try to merge the defaults for any new configuration
173 settings into the stock set, but since it’s possible this will fail, we
174 don’t blindly update the BusyBox version merely because a new release
175 came out. Someone needs to get around to vetting it against our stock
176 configuration first.
177
178 As for Fossil, it defaults to fetching the same version as the checkout
179 you’re running the build command from, based on checkin ID. You could
180 use this to get a release build, for instance\
181 our build
182 process leaves out all the BusyBox utilities that require them.
183 Although that set includes common tools like `ping`, we foresee no
184 use that or any of these other elided utilities
185 — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
186 fetched in the build step. To get the latest-and-greatest of everything,
187 you could say\
188 trunk \
189 it lets you build on a local system that might be a lot faster
190 than your remote one, as when the remote is a small VPS. Even with the
191 overhead of schlepping container images across the Internet, it can be a
192 net win in terms of build time.
193
194 Another oddity compared to DockerY@760,6: same
195 h@76d,M:. The changes distill3WC@78M,3SS6XH;One way to can remove the installation of `busybox-static` in STAGE 1 since
196 Alpine is already based on BusyBox.(^We can’t do “`FROM busybox`” since
197 we need `apk` in this new second stage. Although this means we end up
198 with back-to-back Alpine stages, it isn’t redundant; the second one
199 starts fresh, allowing us to copy in only what we absolutely need from
200 AWKbecausewe haveRelative to, the change from “`alpmeans we have no BusyBox environment to execute
201 the `RUN` command with, so we have to copy the `busybox.static` binary
202 in from STAGE 1 and install
203 the stock does.(^This is the main reason we change `USER`
204 temporarily to `root` here.) There are a few other steps required to
205 avoid causing a conflict between our previously bare-bonerename
206 il binary executl popular, we have
207 that ijust a suitable
208 . Because this will conflict with the
209 bare-bones “`os`” layer we create, thePython the `RUN`
210 in from
211 the stock
212 temporarily to
213 `root` here.) The compensating bonus is huge: we don’t leave a package
214 image, waiting to be abusedhow much the über-jail nature of
215 c run yous can save you when
216 like this. For instance, you might have enabled Fossil’s [risky TH1 docs
217 feature][th1docrisk] along with the Tcl integration feature, which
218 effectively gives anyone with check-in rights on your repo the ability
219 to run arbitrary Tcl code on the host when that document is rendered.
220 The container layer should stop that script
221 on the host
222 namespace, but it *can* still make network connect,
223 so there is at least a *hope* that WAL will work properly across that
224 boundary. The success of the scheme depends on the `mmap()` and shared
225 memory system calls being coordinated properly by the OS kernel the two
226 worlde network cAt some point, someone should perform tests in the hopes of *failing* to
227 create database corruption in this scenario.
228
229 Why the tortured grammar? Because you cannot prove a negative, being in
230 this case “SQLite will not corrupt the database in WAL mode if there’s a
231 container barrier in the way.” All you can prove is that a given test
232 didn’t cause corruption. With enough tests of sufficient power, you can
233 begin to make definitive statements, but even then, science is always
234 provisional, awaiting a single disproving with the Tcl ints give the sysadmin freedom to impose barriers between
235 the two worlds, so even if you convince yourself that WAL mode is safe
236 in a given setup, it’s possible to configure it to fail. As if that
237 weren’t enough, differentg with the Tcl ints have different defaults,
238 including details like whether shared memory is truly shared between
239 the host and its containers.
240
241 Until someone gets around to establishing this ground truth and scoping
242 its applicable range` with:
243
244 FROM grc.io/distroless/python3-debian11
245
246 Another case
247
248
249 Method 2to
250 bind-mounted
251 `netstat`, `tYou our build
252 process leaves out all the BusyBox utilities that require them.
253 Although that set includes common tools like `ping`, we
254
255 R@2VU,5: RUNN@2bU,1Q:
256
257 Everything else remains the same as in the distroless Python example
258 because even AlpineN@2yP,1R: way we set up core Linux
259 directories like `/etc` and `/tmp` in the absence of any OS imageAs@3LR,L@3XT,f:github.com/GoogleContainerTools/distroless7Xz@3Z4,qTTBs;exec -it -u fossil fossil sh
260 ```s to get a release build, for instance\
261 alternativeAlthough Podman [bills itself][whatis] as a drop-in replacement for the
262 `docker` command and everything that sits behind it, some of the tool’s
263 desis run, as compared to
264 using Docker.
265
266 The most important of these is that, by default, Podman wants to build
267 and run your container “[rootless].” This is generally better for
268 security, but there’s something you need to be aware of: each user has
269 their own local. Let’s say you’re following, so even though it did build the image, you
270 can’t create the actual container from that image since that needs to be
271 done as root.
272
273 The simple way to deal with this is to bounce the container through a
274 registry that both users can see, such as [Docker
275 Hub](https://hub.docker.tag fossil:latest mydockername/fossil:latest
276 $ podman image push mydockername/fossil:latest
277 ```
278
279 That will push the image up to your accound
280 process leaves out all the BusyBox utilities that require them.
281 Although that set includes common tools like `ping`, we foresee no
282 use that or any of these other elided utilities
283 — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
284 fetched in the build step. To get the latest-and-greatest of everything,
285 you could say\
286 trunk \
287 --build-arg BBXVER=master .
288 ```
289
290 (But don’t, for reasons we will getwe ship was created with and
291 tested against a specific stable release, that’s the version we pull by
292 default. It does try to merge the defaults for any new configuration
293 settings into the stock set, but since it’s possible this will fail, we
294 don’t blindly update the BusyBox version merely because a new release
295 came out. Someone needs to get around to vetting it against our stock
296 configuration first.
297
298 As for Fossil, it defaults to fetching the same version as the checkout
299 you’re running the build command from, based on checkin ID. You could
300 use this to get a release build, for instance\
301 our build
302 process leaves out all the BusyBox utilities that require them.
303 Although that set includes common tools like `ping`, we foresee no
304 use that or any of these other elijail��s [risky TH1 docsh user has
305 their own local. Let’sjailthe image, you
306 can’t create the actual container from that image since that needs to be
307 done as root.
308
309 The simple way to deal with this is to bounce the container through a
310 registry that both users can see, such as [Docker
311 Hub](https://hub.docker.tag fossil:latest mydockername/fossil:latest
312 $ podman image push mydockername/fossil:latest
313 ```
314
315 That will push the image up to your accound
316 process leaves out all the BusyBox utilities that require them.
317 Although that set includes common tools like `ping`, we foresee no
318 use that or any of these other elided utilities
319 — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
320 fetched in the build step. To get the latest-and-greatest of everything,
321 you could say\
322 trunk \
323 --build-arg BBXVER=master .
324 ```
325
326 (But don’t, for reasons we will getwe ship was created with and
327 tested against a specific stable release, that’s the version we pull by
328 default. It does try to merge the defaults for any new configuration
329 settings into the stock set, but since it’s possible this will fail, we
330 don’t blindly update the BusyBox version merely because a new release
331 came out. Someone needs to get around to vetting it against our stock
332 configuration first.
333
334 As for Fossil, it defaults to fetching the same version as the checkout
335 you’re running the build command from, based on checkin ID. You could
336 use this to get a release build, for instance\
337 our build
338 process leaves out all the BusyBox utilities that require them.
339 Although that set includes common tools like `ping`, we foresee no
340 use that or any of these other elided utilities
341 — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
342 fetched in the build step. To get the latest-and-greatest of everything,
343 you could say\
344 trunk \
345 it lets you build on a local system that might be a lot faster
346 than your remote one, as when the remote is a small VPjailAlthough that set includes common tools like `ping`, we foresee no
347 use that or any of these other elided utilities
348 — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
349 fetched in the build step. To get the latest-and-greatest of everything,
350 you could say\
351 trunk \
352 --build-arg BBXVER=master .
353 ```
354
355 (But don’t, for reasons we will getwe ship was created with and
356 tested against a specific stable release, that’s the version we pull by
357 default. It does try to merge the defaults for any new configuration
358 settings into the stock set, but since it’s possible this will fail, we
359 don’t blindly update the BusyBox version merely because a new release
360 came out. Someone needs to get around to vetting it against our stock
361 configuration first.
362
363 As for Fossil, it defaults to fetching the same version as the checkout
364 you’re running the build command from, based on checkin ID. You could
365 use this to get a release build, for instance\
366 alternativeAlthough Podman [bills itself][whatis] as a drop-in replacement for the
367 `docker` command and everything that sits behind it, some of the tool’s
368 desis run, as compared to
369 using Docker.
370
371 The most important of thesour ��s [risky TH1 docs
372 feature][th1docrisk] along with the Tcl integration feature, which
373 effectively gives anyone with check-in rights on your repo the ability
374 to run arbitrary Tcl code on the host when that document is rendered.
375 The container layer should stop that script
376 on the host
377 namespace, but it *can* still make network connections, modify the repo
378 , and who knows what else//fossil-scm.org/forum/forumpost/42e0c165447Vw@3X~,25L~sx;adviceYou could inject that into
379 one of s. Because this will
380
381 complicated. Essentially, you replace everything in STAGE 2 and 3 inside
382 the `Dockerfile` with:
383
384 FROM grc.io/distroless/python3-debian11
385
386 Another case
387
388
389 Method 2to
390 bind-mounted
391 `netstat`, `tYou our build
392 process leaves out all the BusyBox utilities that require them.
393 Although that set includes common tools like `ping`, we
394
395 R@2VU,5: RUNN@2bU,1Q:
396
397 Everything else remains the same as in the distroless Python example
398 because even AlpineN@2yP,1R: way we set up core Linux
399 directories like `/etc` and `/tmp` in the absence of any OS imageAs@3LR,L@3XT,f:github.com/GoogleContainerTools/distroless7Xz@3Z4,qTTBs; bonus is huge: we don’t leave a package
400 image, waiting to be abusedhow much the über-jail nature of
401 c run yous can save you when
402 like this. For instance, you might have enabled Fossil’s [risky TH1 docs
403 feature][th1docrisk] along with the Tcl integration feature, which
404 effectively gives anyone with check-in rights on your repo the ability
405 to run arbitrary Tcl code on the hThe first configurationtainer is that it runs
406 Fossil as root. Sin
407 to kick in, and a Docker container is a type of über-jail already, you
408 may be wondering why we bother. Instead, why not either:
409
410 * run nojail` to skip the internal chroot; or
411 * set “`USER fossil`” inbills itself][whatso it starts Fossil as
412 that user instead
413
414 The reason is, although this container is quite stripped-down by today’s
415 standards, it’s based on the [surprising(This author made a
416 that were less
417 powerful than this container.) If someone ever figured out how to make a
418 Fossil binary execute arbitrary commands on the host or to open up a
419 remote shell, the power available to them at that point would make it
420 likely that they’d be able to island-hop from there into the rest of
421 your network. That power is there for you as the system administrator
422 alone, to let you inspectinto
423 a “machine,” as `systemd` calls it. The easiest method ishese other elided utilitiile/Dockerfile)we ship was created with and
424 tested against a specific stable release, that’s the version we pull by
425 default. It does try to merge theour build
426 process leave`tYou our build
427 process leaves out all the BusyBox utilities that require them.
428 Although that set includes common tools like `ping`, we
429
430 R@2VU,5: RUNN@2bU,1Q:
431
432 Everything else remains the same as in the distroless Python example
433 because even AlpineN@2yP,1R: way we set up core Linux
434 directories like `/etc` and `/tmp` in the absence of any OS imageAs@3LR,L@3XT,f:github.com/GoogleContainerTools/distrolesChroot?
435
436 A potentially surprising feature of this container is that it runs
437 Fossil as root. Sin
438 to kick in, and a Docker container is a type of über-jail already, you
439 may be wondering why we bother. Instead, why not either:
440
441 * run nojail` to skip the internal chroot; or
442 * set “`USER fossil`” inbills itself][whatso it starts Fossil as
443 that user instead
444
445 The reason is, although this container is quite stripped-down by today’s
446 standards, it’s based on the [surprising(This author made a
447 that were less
448 powerful than this container.) If someone ever figured out how to make a
449 Fossil binary execute arbitrary commands on the host or to open up a
450 remote shell, the power available to them at that point would make it
451 likely that they’d be able to island-hop from there into the rest of
452 your network. That power is thercess leaves out alainst a specific stable release, that’s the version we pull by
453 default. It does try to merge the defaults for any new configuration
454 settiy new configuration
455 settings i:noja
456
457 A potentially surprissurprisingly difficulte remains the same as in the distroless Python example
458 because even AlpineN@2yP,1R: way we set up core Linux
459 directories like `/etc` and `/tmp` in the absence of any OS imageAs@3LR,L@3XT,f:github.com/GoogleContainerTools/distrolesChroot?
460
461 A potentially surprising feature of this container is that it runs
462 Fossil as root. Sin
463 to kick in, and a Docker container is a type of über-jail already, you
464 may be wondering why we bother. Instead, why not either:
465
466 * run f][whatso it starts Fossil as
467 that user instead
468
469 The reason is, although this container is quite stripped-down by today’s
470 standards, it’s base4 on the [surprising(This auth and packed with [UPX].)
471
472 [U//upx.github.io/6gF@488,2Ne3im;ofetgly difficulte remains the same as in the distroless Python example
473 because even AlpineN@2yP,1R: way we set up core Linux
474 directories like `/etc` and `/tmp` in the absence of any OS imageAs@3LR,L@3XT,f:github.com/GoogleContainerTools/distrolesChroot?
475
476 A potentially surprisinculte ripped-down by today’s
477 standards, it’s based on the [surprising(This author made a
478 that were less
479 powerful than this container.) If someone ever figured out how to make a
480 Fossil binary execute arbitrary commands on the host or to open up a
481 remote shell, the power available to them at that point would make it
482 likely that they’d be able to island-hop from there into the rest of
483 your network. That power is there for you as the system administrator
484 alone, to let you inspectquire them.
485 Altour build
486 process leaves out all the BusyBox utilities that require them.
487 Although that set includes common tools like `ping`, we foresee no
488 use that or any of these other elided utilities
489 — `ether-wake`, `netstat`, `tYou can override The most
490 common reason to override this is to get a release versionns of Fossil and Bstep. To get the latest-19 .
491 ```
492
493 It’s bestguration
494 settings iput a line lik rather thanversion we pull by
495 default. It dobecauss into the first stage:
496
497 ```
498 COPY containers/os-release /etc/os-release
499 ```
500
501 That will let you pway to can remove the installation of `busybox-static` in STAGE 1 since
502 Alpine is already based on BusyBox.(^We can’t do “`FURL hasn’t changed, if you hav Alpine stages, it isn’t redundant; the second one
503 starts fresh, allowing us to copy in only what we absolutely need from
504 AWKbecausewe haveRelative to, the change from “`alpmeans we have no BusyBox environment to execute
505 the `RUN` command with, so we have to copy the `busybox.static` binary
506 in from STAGE 1 and install
507 the stock does.(^This is the main reason we change `USER`
508 temporarily to `root` here.) There are a few other steps required to
509 avoid causing a conflict between our previously bare-bones “OS” layer
510 and what the is hassleinTcl popular, we have
511 that intovia a suitable
512 . Because this will conflict with the
513 bare-bones “`os`” laye(./server/)create, thePython the `RUN`
514 in from
515 the stock
516 temporarily to
517 `root` here.) The compensating bonus is huge: we don’t leave a package
518 image, waiting to be abusedhow much the über-jail nature of
519 c run yous can save you when
520 like this. For instance, you might have enabled Fossil’s [risky TH1 docs
521 feature][th1docrisk] along with the Tcl integration feature, which
522 effectively gives anyone with check-in rights on your repo the ability
523 to run arbitrary Tcl code on the host when that document is rendered.
524 The container layer should stop that script
525 on the host
526 namespace, but it *can* still make network connections, modify the repo
527 , and who knows what else//fossil-scm.org/forum/forumpost/42e0c165447Vw@3X~,25L~sx;adviceYou could inject that into
528 one of s. Because this will
529
530 complicated. Essentially, you replace everything in STAGE 2 and 3 inside
531 the `Dockerfile` with:
532
533 FROM grc.io/distroless/python3-debian11
534
535 Another case
536
537
538 Method 2to
539 bind-mounted
540 `netstat`, `tYou our build
541 process leaves out all the BusyBox utilities that require them.
542 Although that set includes common tools like `ping`, we
543
544 R@2VU,5: RUNN@2bU,1Q:
545
546 Everything else remains the same as in the distroless Python example
547 because even AlpineN@2yP,1R: way we set up core Linux
548 directories like `/etc` and `/tmp` in the absence of any OS imageAs@3LR,L@3XT,f:github.com/GoogleContainerTools/distroless7Xz@3Z4,qTTBs;exec -it -u fossil fossil sh
549 ```s to get a release build, for instance\
550 alternativeAlthough Podman [bills itself][whatis] as a drop-in replachassleinTcl popular, we have
551 that intovia a suitable
552 . Because this will conflict with the
553 bare-bones “`os`” layer we create, thePython the `RUN`
554 in from
555 the stock
556 temporarily to
557 `root` here.) The compensating bonus is huge: we don’t leave a package
558 image, waiting to be abusedhow much the über-jail nature of
559 c run yous can save you when
560 like this. For instance, you might have enabled Fossil’s [risky TH1 docs
561 feature][th1docrisk] along with the Tcl integration feature, which
562 effectively gives anyone with check-in rights on your repo the ability
563 to run arbitrary Tcl code on the host when that document is rendered.
564 The container layer should stop that script
565 on the host
566 namespace, but it *can* still makerunck connections, modify the repo
567 , and who knows what else//fossil-scm.org/forum/forumpost/42e0c165447Vw@3X~,25L~sx;adviceYou could inject that into
568 one of s.It’s possible to dig into the subtree
569 managed by `containerd` on the build host and se other elided utilities
570 — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
571 fetched in the build step. To get the latest-and-greatest of everything,
572 you could say\
573 trunk \
574 --build-arg BBXVER=master .
575 ```
576
577 (But don’t, for reasons we will getwe ship was created with and
578 tested against a specific stable release, that’s the version we pull by
579 default. It does try to merge the defaults for any new configuration
580 settings into the stock set, but since it’s possible this will fail, we
581 don’t blindly update the BusyBox version merely because a new release
582 came out. Someone needs to get around to vetting it against our stock
583 configuration first.
584
585 As for Fossil, it defaults to fetching the same version as the checkout
586 you’re running the build command from, based on checkin ID. You could
587 use this to get a release build, for instance\
588 alternativeAlthough Podman [bills itself][whatis] as a drop-in replacement for the
589 `docker` command and everything that sits behind it, some of the tool’s
590 desis run, as compared to
591 using Docker.
592
593 The most important of thesour ��s [risky TH1 docs
594 feature][th1docrisk] along with the Tcl integration feature, which
595 effectively gives anyone with check-in rights on your repo the ability
596 to run arbitrary Tcl code on the host when that document is rendered.
597 The container layer should stop that script
598 on the host
599 namespace, but it *can* still make network connections, modify the repo
600 , and who knows what else//fossil-scm.org/forum/forumpost/42e0c165447Vw@3X~,25L~sx;adviceYou could inject that into
601 one of s. Because this will
602
603 complicated. Essentially, you replace everything in STAGE 2 and 3 inside
604 the `Dockerfile` with:
605
606 FROM grc.io/distroless/python3-debian11
607
608 Another case
609
610
611 Method 2to
612 bind-mounted
613 `netstat`, `tYou our build
614 process leaves out all the BusyBox utilities that require them.
615 Although that set includes common tools like `ping`, we
616
617 R@2VU,5: RUNN@2bU,1Q:
618
619 Everythin (g else remains the same as in the distroless Pytrhon example
620 because even AlpineN@2yP,1R: way we set up core Linux
621 directories like `/etc` and `/)”, as systemdIt’s important that the name of the machine you create &mdash;in this example &mdash; matches tason is, although tsand it will contain. For one[SCGI proxying via nginx][DNT]. For
622 other use cases, see our collection of [Fossil server configuration
623 guides][srv], then adjust the command to your local needs.
624 For another, you will likely have to adjust the `
625 in the command.
626
627 W.
628
629 S,ngly diffiemains the same as incert /path/to/my/fullchainhas no option for installneeds for so, the
630 . Thus,-rune reason is, although this containesurprisingly Fossil server configuration
631 guides][srv], then adjust the command to your local needs.
632 For another, you will likely have to adjust the `
633 in the command.
634
635 W.
636
637 S,ngly diffiemains the same as incert /path/to/my/fullchainhas no option for installneeds for so, the
638 . Thus,Copy the container name from the first step to the second. Yours will
639 almost certainly be named after a different Fossil commit ID.en adjust the command to your local needs.
640 For another, you will likely have to adjust the `
641 in the command.
642
643 W.
644
645 S,ngly diffiemains the same barebones"></a>Bahas no option for installneeds for so, the
646 . Thus,virtual net
647 it wants to hide the service entirely.
648
649 Another way to put this is thatthing* of what pped-down by today’s
650 s` does
651 despite their superficial similarities.
652
653 For this container, it doesn’t much matter, since it exposes
654 only a single port, and we do want that one port exposed, one way
655 or another. Beyond that, weby today’s
656 standards, it’surprisingly difficulte remains the same as in the distroless Python example
657 because even AlpineN@2yP,1R: way we set up core Linux
658 directories like `/etc` and `/tmp` in the absence of any OS imageAs@3LR,L@3XT,f:github.com/GoogleContainerTools/distrolesChroot?
659
660 A potentially surprising feature of this container is that it runs
661 Fossil as root. Sin
662 to kick in, and a Docker container is a type of über-jail already, you
663 may be wondering why we bother.I:
664
665 1. `systemd-nspawn` works best with `machinectl`, but if you haven’t
666 got `btrfs` available, you run into [trouble](#nspawn-rhel).
667
668 2. O@760,6: same
669 h@76d
670 a strip
671 image, causing ly difficulte remains the same as in the distroless Python exampleemains the same as in the distroless Python example
672 because even Al tutorial][medtut].)
673
674 3. We disable the “private networking” feature since the whole
675 point of this container is to expose a network service to the
676 public, one way or another. If you do things the way the defaults
677 (and thus the official docs) expect, you must push through
678 [a whole lot of complexity][ndcmp] to re-expose this single
679 network port. That complexity is justified only if your service
680 is itself complex, having both privatyou still have options for
681 running containers that are considerably slimmer, at a high cost to
682 administration complexity and loss of features.
683
684 Part of the OCI standard is the notion of a “bundle,” being a consistent
685 way to present a pre-built and configured container to the runtime.
686 Essentially, it consists of a directory containing a `config.json` file
687 and a `rootfs/` subdirectory containing the root filesystem image. Many
688 tools can produce these for you. We’ll show only one method in the first
689 section below, then reuse that in the following sections.
690
691
692 #### 6.3.1 <a id="runc"></a>`runc`
693
694 We mentioned `runc` [above](#nerdctl), but it’s possible to use it
695 standalone, without `containerd` or its CLI frontend `nerdctl`. You also
696 lose the build engine, intelligent image layer sharing, image registry
697 connections, and much more. The plus side is that `runc` alone is
698 18 MiB.
699
700 Using it without stable release, that’s the version we pull by
701 default. It does try to merge the defaults for any new configuration
702 settings into the stock set, but since it’s possible this will fail, we
703 don’t blindly update the BusyBox version merely because a new release
704 came out. Someone needs to get around to vetting it against our stock
705 configuration first.
706
707 As for Fossil, it defaults to fetching the same version as the checkout
708 you’re running the build command from, based on checkin ID. You could
709 use this to get a release build, for instance\
710 our build
711 process leaves out all the BusyBox utilities that require them.
712 Although that set includes common tools like `ping`, we foresee no
713 use that or any of these other elided utilities
714 — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
715 fetched in the build step. To get the latest-and-greatest of everything,
716 you could say\
717 trunk \
718 it lets you build on a local system that might be a lot faster
719 than your remote one, as when the remote is a small VPjailAlthough that set includes common tools like `ping`, we foresee no
720 use that or any of these other elided utilities
721 — `ether-wake`, `netstat`, `tYou can override the default versions of Fossil and BusyBox that get
722 fetched in the build step. To get the latest-and-greatest of everything,
723 you could say\
724 trunk \
725 --build-arg BBXVER=master .
726 ```
727
728 (But don’t, for reasons we will getwe ship was created with and
729 tested against a specific stable release, that’s the version we pull by
730 default. It does try to merge the defaults for any new configuration
731 settings into the stock set, but since it’s possible this will fail, we
732 don’t blindly update the BusyBox version merely because a new release
733 came out. Someone needs to get around to vetting it against our stock
734 configuration first.
735
736 As for Fossil, it defaults to fetching the same version as the checkout
737 you’re running the build command from, based on checkin ID. You could
738 use this to get a release build, for instance\
739 alternativeAlthough Podman [bills itself][whatis] as a drop-in replacement for the
740 `docker` command and everything that sits behind it, some of the tool’s
741 desis run, as compared to
742 using Docker.
743
744 The most important of thesour ��s [risky TH1 docs
745 feature][th1docrisk] along with the Tcl integration feature, which
746 effectively gives anyone with check-in rights on your repo the ability
747 to run arbitrary Tcl code on the host when that document is rendered.
748 The container layer should stop that script
749 on the host
750 namespace, but it *can* still make network connections, modify the repo
751 , and who knows what else//fossil-scm.org/forum/forumpost/42e0c165447Vw@3X~,25L~sx;adviceYou could inject that into
752 one of s. Because this will
753
754 complicated. Essentially, you replace everything in STAGE 2 and 3 inside
755 the `Dockerfile` with:
756
757 FROM grc.io/distroless/python3-debian11
758
759 Another case
760
761
762 Method 2to
763 bind-mounted
764 `netstat`, `tYou our build
765 process leaves out all the BusyBox utilities that require them.
766 Although that set includes common tools like `ping`, we
767
768 R@2VU,5: RUNN@2bU,1Q:
769
770 Everythin (g else remains the same as in the distroless Pytrhon example
771 because even AlpineN@2yP,1R: way we set up core Linux
772 directories like `/etc` and `/)”, as systemdIt’s important that the name of the machine you create &mdash;in this example &mdash; matches tason is, although tsand it will contain. For one[SCGI proxying via nginx][DNT]. For
773 other use cases, see our collection of [Fossil server configuration
774 guides][srv], then adjust the command to your local needs.
775 For another, you will likely have to adjust the `
776 in the command.
777
778 W.
779
780 S,ngly diffiemains the same as incert /path/to/my/fullchainhas no option for installneeds for so, the
781 . Thus,-rune reason is, although this containesurprisingly Fossil server configuration
782 guides][srv], then adjust the command to your local needs.
783 For another, you will likely have to adjust the `
784 in the command.
785
786 W.
787
788 S,ngly diffiemains the same as incert /path/to/my/fullchainhas no option for installneeds for so, the
789 . Thus,Copy the container name from the first step to the second. Yours will
790 almost certainly be named after a different Fossil commit ID.en adjust the command to your local needs.
791 For another, you will likely have to adjust the `
792 in the command.
793
794 W.
795
796 S,ngly diffiemains the same as incert /path/to/my/fullchainhas no option for installneeds for so, the
797 . Thus,virtual net
798 it wants to hide the service entirely.
799
800 Another way to put this is thatthing* of what pped-down by today’s
801 s` does
802 despite their superficial similarities.
803
804 For this container, it doesn’t much matter, since it exposes
805 only a single port, and we do want that one port exposed, one way
806 or another. Beyond that, weby today’s
807 standards, it’surprisingly difficulte remains the same as in the distroless Python example
808 because even AlpineN@2yP,1R: way we set up core Linux
809 directories like `/etc` and `/tmp` in the absence of any OS imageAs@3LR,L@3XT,f:github.com/GoogleContainerTools/distrolesChroot?
810
811 A potentially surprising feature of this container is that it runs
812 Fossil as root. Sin
813 to kick in, and a Docker container is a type of über-jail already, you
814 may be wondering why we bother.I:
815
816 1. `systemd-nspawn` works best with `machinectl`, but if you haven’t
817 , you’ll get the old versionstages, it isn’t redundant; the second one
818 starts fresh, allowing us to copy in only what we absolutely need from
819 AWKbecausewe haveRelative to, the change from “`alpmeans we have no BusyBox environment to execute
820 the `RUN` command with, so we have to copy the `busybox.static` binary
821 in from STAGE 1 and install
822 the stock does.(^This is the main reason we change `USER`
823 temporarily to `root` here.) There are a few other steps required to
824 avoid causing a conflict between our previously bare-bones “OS” layer
825 and what the is hassleinTcl popular, we have
826 that int elsewhere with `runc`, leaving out all the
827 rest. `runc` alone is about 18 MiB, and you can do without `containerd`
828 entirely, if you want.
829
830 The methode options for
831 running containers ns for
832 running containers that
833 script:
834
835 ----
836
837 ```shell
838 #!/bin/sh
839 c=fossil
840 b=$HOME/containers/$c
841 r=$b/rootfst includes common tools lik
842 if [ -d "$t" ] && mkdir -p $r— `ether-wake`, `netstat`, `tYou can override the default versions| sudo tar -C $r -xf -BusyBox that get
843 fetched in the build step. To get the latest-and-greatest of ev|
844 jq '.ro that user instead
845
846 The reasurprisingly diff a specific stable release, that |
847 ly update the BusyBox versiname"))' |
848 ly update the BusyBox vresolv.conf"))' |
849 ly update the BusyBox version me |
850 jq 'dethe build command from, based on checkin ID. You could
851 use this to get a release build, for instance\
852 alternativeAlthough Podman [bills itself][whatis] as a drop-in replacement for the
853 `docker` command and everything that sits behind it, some of the tool’s
854 desis run, as compared to
855 using Docker.
856
857 The most important of thesour ��s [risky TH1 docs
858 feature][th1docrisk] along with the Tcl integration feature, which
859 effectively gives anyone with check-in rights on your repo the ability
860 to run arbitrary Tcl code on the host when that document is rendered.
861 The container layer should stop that script
862 on the host
863 namespace, but it *can* still make network connections, modify the repo
864 , and who knows what else//fossil-scm.org/forum/forumpost/42e0c165447Vw@3X~,25L~sx;adviceYou could inject that into
865 one of s. Because this will
866
867 complicated. Essentially, you replace everything in STAGE 2 and 3 inside
868 the `Dockerfile` with:
869
870 FROM grc.io/distroless/python3-debian11
871
872 Another case
873
874
875 Method 2to
876 bind-mounted
877 `netstat`, `tYou our build
878 process leaves out all the BusyBox utilities that require them.
879 Although that set includes common tools like `ping`, we
880
881 R@2VU,5: RUNN@2bU,1Q:
882
883 Everythin (g else remains the same as in the distroless Pytrhon example
884 because even AlpineN@2yP,1R: way we set up core Linux
885 directories like `/etc` and `/)”, as systemdIt’s important that the name of the machine you create &mdash;in this example &mdash; matches tason is, although tsand it will contain. For one[SCGI p
--- www/fossil-v-git.wiki
+++ www/fossil-v-git.wiki
@@ -180,13 +180,14 @@
180180
181181
This policy is particularly useful when running Fossil inside a
182182
restrictive container, anything from [./chroot.md | classic chroot
183183
jails] to modern [https://en.wikipedia.org/wiki/OS-level_virtualization
184184
| OS-level virtualization mechanisms] such as
185
-[https://en.wikipedia.org/wiki/Docker_(software) | Docker]. Our
186
-[src:/file?name=Dockerfile&ci=trunk | stock <tt>Dockerfile</tt>]
187
-creates a container that's under 9 MiB on 64-bit Linux, including
185
+[https://en.wikipedia.org/wiki/Docker_(software) | Docker]. By using
186
+executable compression, our
187
+[/file?name=Dockerfile.in&ci=trunk | stock <tt>Dockerfile</tt>]
188
+creates a container that's under 4 MiB on 64-bit Linux, including
188189
a capable [https://www.busybox.net/ | Busybox] environment for live
189190
debugging of the container's innards.
190191
191192
Modern Linux systems tend to make full static linking
192193
[https://stackoverflow.com/questions/3430400/linux-static-linking-is-dead
193194
--- www/fossil-v-git.wiki
+++ www/fossil-v-git.wiki
@@ -180,13 +180,14 @@
180
181 This policy is particularly useful when running Fossil inside a
182 restrictive container, anything from [./chroot.md | classic chroot
183 jails] to modern [https://en.wikipedia.org/wiki/OS-level_virtualization
184 | OS-level virtualization mechanisms] such as
185 [https://en.wikipedia.org/wiki/Docker_(software) | Docker]. Our
186 [src:/file?name=Dockerfile&ci=trunk | stock <tt>Dockerfile</tt>]
187 creates a container that's under 9 MiB on 64-bit Linux, including
 
188 a capable [https://www.busybox.net/ | Busybox] environment for live
189 debugging of the container's innards.
190
191 Modern Linux systems tend to make full static linking
192 [https://stackoverflow.com/questions/3430400/linux-static-linking-is-dead
193
--- www/fossil-v-git.wiki
+++ www/fossil-v-git.wiki
@@ -180,13 +180,14 @@
180
181 This policy is particularly useful when running Fossil inside a
182 restrictive container, anything from [./chroot.md | classic chroot
183 jails] to modern [https://en.wikipedia.org/wiki/OS-level_virtualization
184 | OS-level virtualization mechanisms] such as
185 [https://en.wikipedia.org/wiki/Docker_(software) | Docker]. By using
186 executable compression, our
187 [/file?name=Dockerfile.in&ci=trunk | stock <tt>Dockerfile</tt>]
188 creates a container that's under 4 MiB on 64-bit Linux, including
189 a capable [https://www.busybox.net/ | Busybox] environment for live
190 debugging of the container's innards.
191
192 Modern Linux systems tend to make full static linking
193 [https://stackoverflow.com/questions/3430400/linux-static-linking-is-dead
194
+7 -19
--- www/gitusers.md
+++ www/gitusers.md
@@ -183,13 +183,13 @@
183183
git checkout foo-branch
184184
185185
The symlink trick has a number of problems, the largest being that
186186
symlinks weren’t available on Windows until Vista, and until the Windows
187187
10 Creators Update was released in spring of 2017, you had to be an
188
-Administrator to use the feature besides. ([Source][wsyml]) Git solved
188
+Administrator to use the feature besides. ([Source][wsyml]) Git 2.5 solved
189189
this problem back when Windows XP was Microsoft’s current offering
190
-with the `git-worktree` command, added in Git 2.5:
190
+by adding the `git-worktree` command:
191191
192192
git worktree add ../foo-branch foo-branch
193193
cd ../foo-branch
194194
195195
That is approximately equivalent to this in Fossil:
@@ -196,15 +196,15 @@
196196
197197
mkdir ../foo-branch
198198
cd ../foo-branch
199199
fossil open /path/to/repo.fossil foo-branch
200200
201
-The Fossil alternative is wordier, but this tends to be one-time setup,
202
-not something you do everyday. This author keeps a “scratch” check-out
203
-for cases where is isn’t appropriate to reuse the “trunk” check-out,
201
+The Fossil alternative is wordier, but since this tends to be one-time setup,
202
+not something you do everyday, the overhead is insignificant. This author keeps a “scratch” check-out
203
+for cases where it’s inappropriate to reuse the “trunk” check-out,
204204
isolating all of my expedient switch-in-place actions to that one
205
-working directory. Since the other peer check-out track long-lived
205
+working directory. Since the other peer check-outs track long-lived
206206
branches, and that set rarely changes once a development machine is set
207207
up, I rarely pay the cost of these wordier commands.
208208
209209
That then leads us to the closest equivalent in Git to [closing a Fossil
210210
check-out](#close):
@@ -222,27 +222,15 @@
222222
223223
This allows you to have your Git repository directory entirely separate
224224
from your working tree, with `.git` in the check-out directory being a
225225
file that points to `../repo.git`, in this example.
226226
227
-As of Fossil 2.14, there is a direct equivalent:
228
-
229
- fossil clone https://example.com/repo
230
-
231
-It’s a shorter command because we deduce `repo.fossil` and the `repo/`
232
-working directory from the last element of the path in the URI. If you
233
-wanted to override both deductions, you’d say:
234
-
235
- fossil clone --workdir foo https://example.com/repo/bar
236
-
237
-That gets you `bar.fossil` with a `foo/` working directory alongside it.
238
-
239227
[mcw]: ./ckout-workflows.md#mcw
240228
[wsyml]: https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/
241229
242230
243
-#### <a id="iip"></a> Init In Place
231
+#### <a id="iip"></a> Init in Place
244232
245233
To illustrate the differences that Fossil’s separation of repository
246234
from working directory creates in practice, consider this common Git “init in place”
247235
method for creating a new repository from an existing tree of files,
248236
perhaps because you are placing that project under version control for
249237
--- www/gitusers.md
+++ www/gitusers.md
@@ -183,13 +183,13 @@
183 git checkout foo-branch
184
185 The symlink trick has a number of problems, the largest being that
186 symlinks weren’t available on Windows until Vista, and until the Windows
187 10 Creators Update was released in spring of 2017, you had to be an
188 Administrator to use the feature besides. ([Source][wsyml]) Git solved
189 this problem back when Windows XP was Microsoft’s current offering
190 with the `git-worktree` command, added in Git 2.5:
191
192 git worktree add ../foo-branch foo-branch
193 cd ../foo-branch
194
195 That is approximately equivalent to this in Fossil:
@@ -196,15 +196,15 @@
196
197 mkdir ../foo-branch
198 cd ../foo-branch
199 fossil open /path/to/repo.fossil foo-branch
200
201 The Fossil alternative is wordier, but this tends to be one-time setup,
202 not something you do everyday. This author keeps a “scratch” check-out
203 for cases where is isn’t appropriate to reuse the “trunk” check-out,
204 isolating all of my expedient switch-in-place actions to that one
205 working directory. Since the other peer check-out track long-lived
206 branches, and that set rarely changes once a development machine is set
207 up, I rarely pay the cost of these wordier commands.
208
209 That then leads us to the closest equivalent in Git to [closing a Fossil
210 check-out](#close):
@@ -222,27 +222,15 @@
222
223 This allows you to have your Git repository directory entirely separate
224 from your working tree, with `.git` in the check-out directory being a
225 file that points to `../repo.git`, in this example.
226
227 As of Fossil 2.14, there is a direct equivalent:
228
229 fossil clone https://example.com/repo
230
231 It’s a shorter command because we deduce `repo.fossil` and the `repo/`
232 working directory from the last element of the path in the URI. If you
233 wanted to override both deductions, you’d say:
234
235 fossil clone --workdir foo https://example.com/repo/bar
236
237 That gets you `bar.fossil` with a `foo/` working directory alongside it.
238
239 [mcw]: ./ckout-workflows.md#mcw
240 [wsyml]: https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/
241
242
243 #### <a id="iip"></a> Init In Place
244
245 To illustrate the differences that Fossil’s separation of repository
246 from working directory creates in practice, consider this common Git “init in place”
247 method for creating a new repository from an existing tree of files,
248 perhaps because you are placing that project under version control for
249
--- www/gitusers.md
+++ www/gitusers.md
@@ -183,13 +183,13 @@
183 git checkout foo-branch
184
185 The symlink trick has a number of problems, the largest being that
186 symlinks weren’t available on Windows until Vista, and until the Windows
187 10 Creators Update was released in spring of 2017, you had to be an
188 Administrator to use the feature besides. ([Source][wsyml]) Git 2.5 solved
189 this problem back when Windows XP was Microsoft’s current offering
190 by adding the `git-worktree` command:
191
192 git worktree add ../foo-branch foo-branch
193 cd ../foo-branch
194
195 That is approximately equivalent to this in Fossil:
@@ -196,15 +196,15 @@
196
197 mkdir ../foo-branch
198 cd ../foo-branch
199 fossil open /path/to/repo.fossil foo-branch
200
201 The Fossil alternative is wordier, but since this tends to be one-time setup,
202 not something you do everyday, the overhead is insignificant. This author keeps a “scratch” check-out
203 for cases where it’s inappropriate to reuse the “trunk” check-out,
204 isolating all of my expedient switch-in-place actions to that one
205 working directory. Since the other peer check-outs track long-lived
206 branches, and that set rarely changes once a development machine is set
207 up, I rarely pay the cost of these wordier commands.
208
209 That then leads us to the closest equivalent in Git to [closing a Fossil
210 check-out](#close):
@@ -222,27 +222,15 @@
222
223 This allows you to have your Git repository directory entirely separate
224 from your working tree, with `.git` in the check-out directory being a
225 file that points to `../repo.git`, in this example.
226
 
 
 
 
 
 
 
 
 
 
 
 
227 [mcw]: ./ckout-workflows.md#mcw
228 [wsyml]: https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/
229
230
231 #### <a id="iip"></a> Init in Place
232
233 To illustrate the differences that Fossil’s separation of repository
234 from working directory creates in practice, consider this common Git “init in place”
235 method for creating a new repository from an existing tree of files,
236 perhaps because you are placing that project under version control for
237

Keyboard Shortcuts

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