Fossil SCM

Merge updates from trunk

jmoger 2015-03-26 13:23 differentiate-timeline merge
Commit f8832feb39d2e13dbb7fc12a161bfa13c95a6460
+1 -3
--- Dockerfile
+++ Dockerfile
@@ -20,10 +20,8 @@
2020
2121
USER fossil
2222
2323
ENV HOME /opt/fossil
2424
25
-RUN fossil new --docker -A admin /opt/fossil/repository.fossil && fossil user password -R /opt/fossil/repository.fossil admin admin && fossil cache init -R /opt/fossil/repository.fossil
26
-
2725
EXPOSE 8080
2826
29
-CMD ["/usr/bin/fossil", "server", "/opt/fossil/repository.fossil"]
27
+CMD ["/usr/bin/fossil", "server", "--create", "--user", "admin", "/opt/fossil/repository.fossil"]
3028
--- Dockerfile
+++ Dockerfile
@@ -20,10 +20,8 @@
20
21 USER fossil
22
23 ENV HOME /opt/fossil
24
25 RUN fossil new --docker -A admin /opt/fossil/repository.fossil && fossil user password -R /opt/fossil/repository.fossil admin admin && fossil cache init -R /opt/fossil/repository.fossil
26
27 EXPOSE 8080
28
29 CMD ["/usr/bin/fossil", "server", "/opt/fossil/repository.fossil"]
30
--- Dockerfile
+++ Dockerfile
@@ -20,10 +20,8 @@
20
21 USER fossil
22
23 ENV HOME /opt/fossil
24
 
 
25 EXPOSE 8080
26
27 CMD ["/usr/bin/fossil", "server", "--create", "--user", "admin", "/opt/fossil/repository.fossil"]
28
--- skins/blitz/css.txt
+++ skins/blitz/css.txt
@@ -891,11 +891,11 @@
891891
padding: 10px 0px;
892892
border-bottom: 1px solid #ddd;
893893
}
894894
895895
.submenu input, .submenu select {
896
- margin: 0;
896
+ margin: 0 0 0 5px;
897897
}
898898
899899
.submenu a {
900900
color: #3b5c6b;
901901
padding: 5px 15px;
902902
--- skins/blitz/css.txt
+++ skins/blitz/css.txt
@@ -891,11 +891,11 @@
891 padding: 10px 0px;
892 border-bottom: 1px solid #ddd;
893 }
894
895 .submenu input, .submenu select {
896 margin: 0;
897 }
898
899 .submenu a {
900 color: #3b5c6b;
901 padding: 5px 15px;
902
--- skins/blitz/css.txt
+++ skins/blitz/css.txt
@@ -891,11 +891,11 @@
891 padding: 10px 0px;
892 border-bottom: 1px solid #ddd;
893 }
894
895 .submenu input, .submenu select {
896 margin: 0 0 0 5px;
897 }
898
899 .submenu a {
900 color: #3b5c6b;
901 padding: 5px 15px;
902
--- skins/blitz_no_logo/css.txt
+++ skins/blitz_no_logo/css.txt
@@ -891,11 +891,11 @@
891891
padding: 10px 0px;
892892
border-bottom: 1px solid #ddd;
893893
}
894894
895895
.submenu input, .submenu select {
896
- margin: 0;
896
+ margin: 0 0 0 5px;
897897
}
898898
899899
.submenu a {
900900
color: #3b5c6b;
901901
padding: 5px 15px;
902902
--- skins/blitz_no_logo/css.txt
+++ skins/blitz_no_logo/css.txt
@@ -891,11 +891,11 @@
891 padding: 10px 0px;
892 border-bottom: 1px solid #ddd;
893 }
894
895 .submenu input, .submenu select {
896 margin: 0;
897 }
898
899 .submenu a {
900 color: #3b5c6b;
901 padding: 5px 15px;
902
--- skins/blitz_no_logo/css.txt
+++ skins/blitz_no_logo/css.txt
@@ -891,11 +891,11 @@
891 padding: 10px 0px;
892 border-bottom: 1px solid #ddd;
893 }
894
895 .submenu input, .submenu select {
896 margin: 0 0 0 5px;
897 }
898
899 .submenu a {
900 color: #3b5c6b;
901 padding: 5px 15px;
902
--- skins/xekri/css.txt
+++ skins/xekri/css.txt
@@ -1,7 +1,13 @@
1
-/**************************************
1
+/******************************************************************************
22
* Xekri
3
+ *
4
+ * To adjust the width of the contents for this skin, look for the "max-width"
5
+ * property and change its value. (It's in the "Main Area" section) The value
6
+ * determines how much of the browser window to use. Some like 100%, so that
7
+ * the entire window is used. Others prefer 80%, which makes the contents
8
+ * easier to read for them.
39
*/
410
511
612
/**************************************
713
* General HTML
@@ -16,10 +22,13 @@
1622
}
1723
1824
body {
1925
margin: 0;
2026
padding: 0;
27
+ -moz-text-size-adjust: none;
28
+ -ms-text-size-adjust: none;
29
+ -webkit-text-size-adjust: none;
2130
}
2231
2332
a {
2433
color: #07e;
2534
}
@@ -58,19 +67,24 @@
5867
}
5968
6069
span[style^=background-color] {
6170
color: #000;
6271
}
72
+
73
+td[style^=background-color] {
74
+ color: #000;
75
+}
76
+
6377
6478
/**************************************
6579
* Main Area
6680
*/
6781
6882
div.header, div.mainmenu, div.submenu, div.content, div.footer {
6983
clear: both;
7084
margin: 0 auto;
71
- max-width: 80%;
85
+ max-width: 90%;
7286
padding: 0.25rem 1rem;
7387
}
7488
7589
7690
/**************************************
@@ -134,34 +148,46 @@
134148
font-size: 1.1rem;
135149
text-align: center;
136150
}
137151
138152
div.mainmenu {
153
+ padding-top: 0.33rem;
139154
padding-bottom: 0.25rem;
140155
}
141156
142157
div.submenu {
143158
border-top: 1px solid #0a0;
144159
border-radius: 0;
145
- display: flex;
146
- justify-content: space-around;
160
+ display: block;
147161
}
148162
149163
div.mainmenu a, div.submenu a {
150164
color: #000;
151165
padding: 0 0.75rem;
152166
text-decoration: none;
153
- vertical-align: middle;
154167
}
155168
156169
div.mainmenu a:hover, div.submenu a:hover {
157170
color: #fff;
158171
text-shadow: 0px 0px 6px #0f0;
159172
}
173
+
174
+div.submenu * {
175
+ margin: 0 0.5rem;
176
+ vertical-align: middle;
177
+}
178
+
179
+div.submenu select, div.submenu input {
180
+ background-color: #222;
181
+ border: 1px inset #080;
182
+ color: #eee;
183
+ cursor: pointer;
184
+ font-size: 0.9rem;
185
+}
160186
161187
div.submenu select {
162
- background-color: #090;
188
+ height: 1.75rem;
163189
}
164190
165191
/**************************************
166192
* Main Area: Content
167193
*/
@@ -338,10 +364,19 @@
338364
339365
ul.browser li.dir {
340366
font-style: italic
341367
}
342368
369
+
370
+/**************************************
371
+ * File List : Age
372
+ */
373
+
374
+.fileage tr:hover td {
375
+ background-color: #225;
376
+}
377
+
343378
344379
/**************************************
345380
* File List : Tree
346381
*/
347382
@@ -416,10 +451,18 @@
416451
.filetree .dir > a {
417452
background-image: url(data:image/gif;base64,R0lGODlhEAAQAJEAAP/WVCIiIv\/\/\/wAAACH5BAEHAAIALAAAAAAQABAAAAInlI9pwa3XYniCgQtkrAFfLXkiFo1jaXpo+jUs6b5Z/K4siDu5RPUFADs=);
418453
font-style: italic
419454
}
420455
456
+.filetreeline:hover {
457
+ color: #000;
458
+ font-weight: bold;
459
+}
460
+
461
+.filetreeline .filetreeage {
462
+ padding-right: 0.5rem;
463
+}
421464
422465
/**************************************
423466
* Logout
424467
*/
425468
@@ -483,10 +526,19 @@
483526
484527
.statistics-report-week-of-year-list {
485528
font-size: 0.8rem;
486529
}
487530
531
+
532
+/**************************************
533
+ * Search
534
+ */
535
+
536
+.searchResult .snippet mark {
537
+ color: #ee0;
538
+}
539
+
488540
489541
/**************************************
490542
* Sections
491543
*/
492544
@@ -649,14 +701,12 @@
649701
/**************************************
650702
* Timeline
651703
*/
652704
653705
#canvas {
654
- color: darkGray; /* default rail/line color */
655
- border-color: black; /* default branch node/box color */
656
- outline-color: white; /* leaf indicator color */
657
- background-color: #0a0; /* node/box border color */
706
+ color: #000;
707
+ background-color: #fff;
658708
}
659709
660710
div.divider {
661711
color: #ee0;
662712
font-size: 1.2rem;
663713
--- skins/xekri/css.txt
+++ skins/xekri/css.txt
@@ -1,7 +1,13 @@
1 /**************************************
2 * Xekri
 
 
 
 
 
 
3 */
4
5
6 /**************************************
7 * General HTML
@@ -16,10 +22,13 @@
16 }
17
18 body {
19 margin: 0;
20 padding: 0;
 
 
 
21 }
22
23 a {
24 color: #07e;
25 }
@@ -58,19 +67,24 @@
58 }
59
60 span[style^=background-color] {
61 color: #000;
62 }
 
 
 
 
 
63
64 /**************************************
65 * Main Area
66 */
67
68 div.header, div.mainmenu, div.submenu, div.content, div.footer {
69 clear: both;
70 margin: 0 auto;
71 max-width: 80%;
72 padding: 0.25rem 1rem;
73 }
74
75
76 /**************************************
@@ -134,34 +148,46 @@
134 font-size: 1.1rem;
135 text-align: center;
136 }
137
138 div.mainmenu {
 
139 padding-bottom: 0.25rem;
140 }
141
142 div.submenu {
143 border-top: 1px solid #0a0;
144 border-radius: 0;
145 display: flex;
146 justify-content: space-around;
147 }
148
149 div.mainmenu a, div.submenu a {
150 color: #000;
151 padding: 0 0.75rem;
152 text-decoration: none;
153 vertical-align: middle;
154 }
155
156 div.mainmenu a:hover, div.submenu a:hover {
157 color: #fff;
158 text-shadow: 0px 0px 6px #0f0;
159 }
 
 
 
 
 
 
 
 
 
 
 
 
 
160
161 div.submenu select {
162 background-color: #090;
163 }
164
165 /**************************************
166 * Main Area: Content
167 */
@@ -338,10 +364,19 @@
338
339 ul.browser li.dir {
340 font-style: italic
341 }
342
 
 
 
 
 
 
 
 
 
343
344 /**************************************
345 * File List : Tree
346 */
347
@@ -416,10 +451,18 @@
416 .filetree .dir > a {
417 background-image: url(data:image/gif;base64,R0lGODlhEAAQAJEAAP/WVCIiIv\/\/\/wAAACH5BAEHAAIALAAAAAAQABAAAAInlI9pwa3XYniCgQtkrAFfLXkiFo1jaXpo+jUs6b5Z/K4siDu5RPUFADs=);
418 font-style: italic
419 }
420
 
 
 
 
 
 
 
 
421
422 /**************************************
423 * Logout
424 */
425
@@ -483,10 +526,19 @@
483
484 .statistics-report-week-of-year-list {
485 font-size: 0.8rem;
486 }
487
 
 
 
 
 
 
 
 
 
488
489 /**************************************
490 * Sections
491 */
492
@@ -649,14 +701,12 @@
649 /**************************************
650 * Timeline
651 */
652
653 #canvas {
654 color: darkGray; /* default rail/line color */
655 border-color: black; /* default branch node/box color */
656 outline-color: white; /* leaf indicator color */
657 background-color: #0a0; /* node/box border color */
658 }
659
660 div.divider {
661 color: #ee0;
662 font-size: 1.2rem;
663
--- skins/xekri/css.txt
+++ skins/xekri/css.txt
@@ -1,7 +1,13 @@
1 /******************************************************************************
2 * Xekri
3 *
4 * To adjust the width of the contents for this skin, look for the "max-width"
5 * property and change its value. (It's in the "Main Area" section) The value
6 * determines how much of the browser window to use. Some like 100%, so that
7 * the entire window is used. Others prefer 80%, which makes the contents
8 * easier to read for them.
9 */
10
11
12 /**************************************
13 * General HTML
@@ -16,10 +22,13 @@
22 }
23
24 body {
25 margin: 0;
26 padding: 0;
27 -moz-text-size-adjust: none;
28 -ms-text-size-adjust: none;
29 -webkit-text-size-adjust: none;
30 }
31
32 a {
33 color: #07e;
34 }
@@ -58,19 +67,24 @@
67 }
68
69 span[style^=background-color] {
70 color: #000;
71 }
72
73 td[style^=background-color] {
74 color: #000;
75 }
76
77
78 /**************************************
79 * Main Area
80 */
81
82 div.header, div.mainmenu, div.submenu, div.content, div.footer {
83 clear: both;
84 margin: 0 auto;
85 max-width: 90%;
86 padding: 0.25rem 1rem;
87 }
88
89
90 /**************************************
@@ -134,34 +148,46 @@
148 font-size: 1.1rem;
149 text-align: center;
150 }
151
152 div.mainmenu {
153 padding-top: 0.33rem;
154 padding-bottom: 0.25rem;
155 }
156
157 div.submenu {
158 border-top: 1px solid #0a0;
159 border-radius: 0;
160 display: block;
 
161 }
162
163 div.mainmenu a, div.submenu a {
164 color: #000;
165 padding: 0 0.75rem;
166 text-decoration: none;
 
167 }
168
169 div.mainmenu a:hover, div.submenu a:hover {
170 color: #fff;
171 text-shadow: 0px 0px 6px #0f0;
172 }
173
174 div.submenu * {
175 margin: 0 0.5rem;
176 vertical-align: middle;
177 }
178
179 div.submenu select, div.submenu input {
180 background-color: #222;
181 border: 1px inset #080;
182 color: #eee;
183 cursor: pointer;
184 font-size: 0.9rem;
185 }
186
187 div.submenu select {
188 height: 1.75rem;
189 }
190
191 /**************************************
192 * Main Area: Content
193 */
@@ -338,10 +364,19 @@
364
365 ul.browser li.dir {
366 font-style: italic
367 }
368
369
370 /**************************************
371 * File List : Age
372 */
373
374 .fileage tr:hover td {
375 background-color: #225;
376 }
377
378
379 /**************************************
380 * File List : Tree
381 */
382
@@ -416,10 +451,18 @@
451 .filetree .dir > a {
452 background-image: url(data:image/gif;base64,R0lGODlhEAAQAJEAAP/WVCIiIv\/\/\/wAAACH5BAEHAAIALAAAAAAQABAAAAInlI9pwa3XYniCgQtkrAFfLXkiFo1jaXpo+jUs6b5Z/K4siDu5RPUFADs=);
453 font-style: italic
454 }
455
456 .filetreeline:hover {
457 color: #000;
458 font-weight: bold;
459 }
460
461 .filetreeline .filetreeage {
462 padding-right: 0.5rem;
463 }
464
465 /**************************************
466 * Logout
467 */
468
@@ -483,10 +526,19 @@
526
527 .statistics-report-week-of-year-list {
528 font-size: 0.8rem;
529 }
530
531
532 /**************************************
533 * Search
534 */
535
536 .searchResult .snippet mark {
537 color: #ee0;
538 }
539
540
541 /**************************************
542 * Sections
543 */
544
@@ -649,14 +701,12 @@
701 /**************************************
702 * Timeline
703 */
704
705 #canvas {
706 color: #000;
707 background-color: #fff;
 
 
708 }
709
710 div.divider {
711 color: #ee0;
712 font-size: 1.2rem;
713
--- skins/xekri/css.txt
+++ skins/xekri/css.txt
@@ -1,7 +1,13 @@
1
-/**************************************
1
+/******************************************************************************
22
* Xekri
3
+ *
4
+ * To adjust the width of the contents for this skin, look for the "max-width"
5
+ * property and change its value. (It's in the "Main Area" section) The value
6
+ * determines how much of the browser window to use. Some like 100%, so that
7
+ * the entire window is used. Others prefer 80%, which makes the contents
8
+ * easier to read for them.
39
*/
410
511
612
/**************************************
713
* General HTML
@@ -16,10 +22,13 @@
1622
}
1723
1824
body {
1925
margin: 0;
2026
padding: 0;
27
+ -moz-text-size-adjust: none;
28
+ -ms-text-size-adjust: none;
29
+ -webkit-text-size-adjust: none;
2130
}
2231
2332
a {
2433
color: #07e;
2534
}
@@ -58,19 +67,24 @@
5867
}
5968
6069
span[style^=background-color] {
6170
color: #000;
6271
}
72
+
73
+td[style^=background-color] {
74
+ color: #000;
75
+}
76
+
6377
6478
/**************************************
6579
* Main Area
6680
*/
6781
6882
div.header, div.mainmenu, div.submenu, div.content, div.footer {
6983
clear: both;
7084
margin: 0 auto;
71
- max-width: 80%;
85
+ max-width: 90%;
7286
padding: 0.25rem 1rem;
7387
}
7488
7589
7690
/**************************************
@@ -134,34 +148,46 @@
134148
font-size: 1.1rem;
135149
text-align: center;
136150
}
137151
138152
div.mainmenu {
153
+ padding-top: 0.33rem;
139154
padding-bottom: 0.25rem;
140155
}
141156
142157
div.submenu {
143158
border-top: 1px solid #0a0;
144159
border-radius: 0;
145
- display: flex;
146
- justify-content: space-around;
160
+ display: block;
147161
}
148162
149163
div.mainmenu a, div.submenu a {
150164
color: #000;
151165
padding: 0 0.75rem;
152166
text-decoration: none;
153
- vertical-align: middle;
154167
}
155168
156169
div.mainmenu a:hover, div.submenu a:hover {
157170
color: #fff;
158171
text-shadow: 0px 0px 6px #0f0;
159172
}
173
+
174
+div.submenu * {
175
+ margin: 0 0.5rem;
176
+ vertical-align: middle;
177
+}
178
+
179
+div.submenu select, div.submenu input {
180
+ background-color: #222;
181
+ border: 1px inset #080;
182
+ color: #eee;
183
+ cursor: pointer;
184
+ font-size: 0.9rem;
185
+}
160186
161187
div.submenu select {
162
- background-color: #090;
188
+ height: 1.75rem;
163189
}
164190
165191
/**************************************
166192
* Main Area: Content
167193
*/
@@ -338,10 +364,19 @@
338364
339365
ul.browser li.dir {
340366
font-style: italic
341367
}
342368
369
+
370
+/**************************************
371
+ * File List : Age
372
+ */
373
+
374
+.fileage tr:hover td {
375
+ background-color: #225;
376
+}
377
+
343378
344379
/**************************************
345380
* File List : Tree
346381
*/
347382
@@ -416,10 +451,18 @@
416451
.filetree .dir > a {
417452
background-image: url(data:image/gif;base64,R0lGODlhEAAQAJEAAP/WVCIiIv\/\/\/wAAACH5BAEHAAIALAAAAAAQABAAAAInlI9pwa3XYniCgQtkrAFfLXkiFo1jaXpo+jUs6b5Z/K4siDu5RPUFADs=);
418453
font-style: italic
419454
}
420455
456
+.filetreeline:hover {
457
+ color: #000;
458
+ font-weight: bold;
459
+}
460
+
461
+.filetreeline .filetreeage {
462
+ padding-right: 0.5rem;
463
+}
421464
422465
/**************************************
423466
* Logout
424467
*/
425468
@@ -483,10 +526,19 @@
483526
484527
.statistics-report-week-of-year-list {
485528
font-size: 0.8rem;
486529
}
487530
531
+
532
+/**************************************
533
+ * Search
534
+ */
535
+
536
+.searchResult .snippet mark {
537
+ color: #ee0;
538
+}
539
+
488540
489541
/**************************************
490542
* Sections
491543
*/
492544
@@ -649,14 +701,12 @@
649701
/**************************************
650702
* Timeline
651703
*/
652704
653705
#canvas {
654
- color: darkGray; /* default rail/line color */
655
- border-color: black; /* default branch node/box color */
656
- outline-color: white; /* leaf indicator color */
657
- background-color: #0a0; /* node/box border color */
706
+ color: #000;
707
+ background-color: #fff;
658708
}
659709
660710
div.divider {
661711
color: #ee0;
662712
font-size: 1.2rem;
663713
--- skins/xekri/css.txt
+++ skins/xekri/css.txt
@@ -1,7 +1,13 @@
1 /**************************************
2 * Xekri
 
 
 
 
 
 
3 */
4
5
6 /**************************************
7 * General HTML
@@ -16,10 +22,13 @@
16 }
17
18 body {
19 margin: 0;
20 padding: 0;
 
 
 
21 }
22
23 a {
24 color: #07e;
25 }
@@ -58,19 +67,24 @@
58 }
59
60 span[style^=background-color] {
61 color: #000;
62 }
 
 
 
 
 
63
64 /**************************************
65 * Main Area
66 */
67
68 div.header, div.mainmenu, div.submenu, div.content, div.footer {
69 clear: both;
70 margin: 0 auto;
71 max-width: 80%;
72 padding: 0.25rem 1rem;
73 }
74
75
76 /**************************************
@@ -134,34 +148,46 @@
134 font-size: 1.1rem;
135 text-align: center;
136 }
137
138 div.mainmenu {
 
139 padding-bottom: 0.25rem;
140 }
141
142 div.submenu {
143 border-top: 1px solid #0a0;
144 border-radius: 0;
145 display: flex;
146 justify-content: space-around;
147 }
148
149 div.mainmenu a, div.submenu a {
150 color: #000;
151 padding: 0 0.75rem;
152 text-decoration: none;
153 vertical-align: middle;
154 }
155
156 div.mainmenu a:hover, div.submenu a:hover {
157 color: #fff;
158 text-shadow: 0px 0px 6px #0f0;
159 }
 
 
 
 
 
 
 
 
 
 
 
 
 
160
161 div.submenu select {
162 background-color: #090;
163 }
164
165 /**************************************
166 * Main Area: Content
167 */
@@ -338,10 +364,19 @@
338
339 ul.browser li.dir {
340 font-style: italic
341 }
342
 
 
 
 
 
 
 
 
 
343
344 /**************************************
345 * File List : Tree
346 */
347
@@ -416,10 +451,18 @@
416 .filetree .dir > a {
417 background-image: url(data:image/gif;base64,R0lGODlhEAAQAJEAAP/WVCIiIv\/\/\/wAAACH5BAEHAAIALAAAAAAQABAAAAInlI9pwa3XYniCgQtkrAFfLXkiFo1jaXpo+jUs6b5Z/K4siDu5RPUFADs=);
418 font-style: italic
419 }
420
 
 
 
 
 
 
 
 
421
422 /**************************************
423 * Logout
424 */
425
@@ -483,10 +526,19 @@
483
484 .statistics-report-week-of-year-list {
485 font-size: 0.8rem;
486 }
487
 
 
 
 
 
 
 
 
 
488
489 /**************************************
490 * Sections
491 */
492
@@ -649,14 +701,12 @@
649 /**************************************
650 * Timeline
651 */
652
653 #canvas {
654 color: darkGray; /* default rail/line color */
655 border-color: black; /* default branch node/box color */
656 outline-color: white; /* leaf indicator color */
657 background-color: #0a0; /* node/box border color */
658 }
659
660 div.divider {
661 color: #ee0;
662 font-size: 1.2rem;
663
--- skins/xekri/css.txt
+++ skins/xekri/css.txt
@@ -1,7 +1,13 @@
1 /******************************************************************************
2 * Xekri
3 *
4 * To adjust the width of the contents for this skin, look for the "max-width"
5 * property and change its value. (It's in the "Main Area" section) The value
6 * determines how much of the browser window to use. Some like 100%, so that
7 * the entire window is used. Others prefer 80%, which makes the contents
8 * easier to read for them.
9 */
10
11
12 /**************************************
13 * General HTML
@@ -16,10 +22,13 @@
22 }
23
24 body {
25 margin: 0;
26 padding: 0;
27 -moz-text-size-adjust: none;
28 -ms-text-size-adjust: none;
29 -webkit-text-size-adjust: none;
30 }
31
32 a {
33 color: #07e;
34 }
@@ -58,19 +67,24 @@
67 }
68
69 span[style^=background-color] {
70 color: #000;
71 }
72
73 td[style^=background-color] {
74 color: #000;
75 }
76
77
78 /**************************************
79 * Main Area
80 */
81
82 div.header, div.mainmenu, div.submenu, div.content, div.footer {
83 clear: both;
84 margin: 0 auto;
85 max-width: 90%;
86 padding: 0.25rem 1rem;
87 }
88
89
90 /**************************************
@@ -134,34 +148,46 @@
148 font-size: 1.1rem;
149 text-align: center;
150 }
151
152 div.mainmenu {
153 padding-top: 0.33rem;
154 padding-bottom: 0.25rem;
155 }
156
157 div.submenu {
158 border-top: 1px solid #0a0;
159 border-radius: 0;
160 display: block;
 
161 }
162
163 div.mainmenu a, div.submenu a {
164 color: #000;
165 padding: 0 0.75rem;
166 text-decoration: none;
 
167 }
168
169 div.mainmenu a:hover, div.submenu a:hover {
170 color: #fff;
171 text-shadow: 0px 0px 6px #0f0;
172 }
173
174 div.submenu * {
175 margin: 0 0.5rem;
176 vertical-align: middle;
177 }
178
179 div.submenu select, div.submenu input {
180 background-color: #222;
181 border: 1px inset #080;
182 color: #eee;
183 cursor: pointer;
184 font-size: 0.9rem;
185 }
186
187 div.submenu select {
188 height: 1.75rem;
189 }
190
191 /**************************************
192 * Main Area: Content
193 */
@@ -338,10 +364,19 @@
364
365 ul.browser li.dir {
366 font-style: italic
367 }
368
369
370 /**************************************
371 * File List : Age
372 */
373
374 .fileage tr:hover td {
375 background-color: #225;
376 }
377
378
379 /**************************************
380 * File List : Tree
381 */
382
@@ -416,10 +451,18 @@
451 .filetree .dir > a {
452 background-image: url(data:image/gif;base64,R0lGODlhEAAQAJEAAP/WVCIiIv\/\/\/wAAACH5BAEHAAIALAAAAAAQABAAAAInlI9pwa3XYniCgQtkrAFfLXkiFo1jaXpo+jUs6b5Z/K4siDu5RPUFADs=);
453 font-style: italic
454 }
455
456 .filetreeline:hover {
457 color: #000;
458 font-weight: bold;
459 }
460
461 .filetreeline .filetreeage {
462 padding-right: 0.5rem;
463 }
464
465 /**************************************
466 * Logout
467 */
468
@@ -483,10 +526,19 @@
526
527 .statistics-report-week-of-year-list {
528 font-size: 0.8rem;
529 }
530
531
532 /**************************************
533 * Search
534 */
535
536 .searchResult .snippet mark {
537 color: #ee0;
538 }
539
540
541 /**************************************
542 * Sections
543 */
544
@@ -649,14 +701,12 @@
701 /**************************************
702 * Timeline
703 */
704
705 #canvas {
706 color: #000;
707 background-color: #fff;
 
 
708 }
709
710 div.divider {
711 color: #ee0;
712 font-size: 1.2rem;
713
--- skins/xekri/header.txt
+++ skins/xekri/header.txt
@@ -114,21 +114,21 @@
114114
}
115115
menulink $index_page Home
116116
if {[anycap jor]} {
117117
menulink /timeline Timeline
118118
}
119
-if {[hascap oh]} {
119
+if {[anoncap oh]} {
120120
menulink /dir?ci=tip Files
121121
}
122
-if {[hascap o]} {
122
+if {[anoncap o]} {
123123
menulink /brlist Branches
124124
menulink /taglist Tags
125125
}
126
-if {[hascap r]} {
126
+if {[anoncap r]} {
127127
menulink /ticket Tickets
128128
}
129
-if {[hascap j]} {
129
+if {[anoncap j]} {
130130
menulink /wiki Wiki
131131
}
132132
if {[hascap s]} {
133133
menulink /setup Admin
134134
} elseif {[hascap a]} {
135135
--- skins/xekri/header.txt
+++ skins/xekri/header.txt
@@ -114,21 +114,21 @@
114 }
115 menulink $index_page Home
116 if {[anycap jor]} {
117 menulink /timeline Timeline
118 }
119 if {[hascap oh]} {
120 menulink /dir?ci=tip Files
121 }
122 if {[hascap o]} {
123 menulink /brlist Branches
124 menulink /taglist Tags
125 }
126 if {[hascap r]} {
127 menulink /ticket Tickets
128 }
129 if {[hascap j]} {
130 menulink /wiki Wiki
131 }
132 if {[hascap s]} {
133 menulink /setup Admin
134 } elseif {[hascap a]} {
135
--- skins/xekri/header.txt
+++ skins/xekri/header.txt
@@ -114,21 +114,21 @@
114 }
115 menulink $index_page Home
116 if {[anycap jor]} {
117 menulink /timeline Timeline
118 }
119 if {[anoncap oh]} {
120 menulink /dir?ci=tip Files
121 }
122 if {[anoncap o]} {
123 menulink /brlist Branches
124 menulink /taglist Tags
125 }
126 if {[anoncap r]} {
127 menulink /ticket Tickets
128 }
129 if {[anoncap j]} {
130 menulink /wiki Wiki
131 }
132 if {[hascap s]} {
133 menulink /setup Admin
134 } elseif {[hascap a]} {
135
--- src/cache.c
+++ src/cache.c
@@ -226,10 +226,18 @@
226226
cache_read_done:
227227
sqlite3_exec(db, "COMMIT", 0, 0, 0);
228228
sqlite3_close(db);
229229
return rc;
230230
}
231
+
232
+/*
233
+** Create a cache database for the current repository if no such
234
+** database already exists.
235
+*/
236
+void cache_initialize(void){
237
+ sqlite3_close(cacheOpen(1));
238
+}
231239
232240
/*
233241
** COMMAND: cache*
234242
** Usage: %fossil cache SUBCOMMAND
235243
**
236244
--- src/cache.c
+++ src/cache.c
@@ -226,10 +226,18 @@
226 cache_read_done:
227 sqlite3_exec(db, "COMMIT", 0, 0, 0);
228 sqlite3_close(db);
229 return rc;
230 }
 
 
 
 
 
 
 
 
231
232 /*
233 ** COMMAND: cache*
234 ** Usage: %fossil cache SUBCOMMAND
235 **
236
--- src/cache.c
+++ src/cache.c
@@ -226,10 +226,18 @@
226 cache_read_done:
227 sqlite3_exec(db, "COMMIT", 0, 0, 0);
228 sqlite3_close(db);
229 return rc;
230 }
231
232 /*
233 ** Create a cache database for the current repository if no such
234 ** database already exists.
235 */
236 void cache_initialize(void){
237 sqlite3_close(cacheOpen(1));
238 }
239
240 /*
241 ** COMMAND: cache*
242 ** Usage: %fossil cache SUBCOMMAND
243 **
244
--- src/checkin.c
+++ src/checkin.c
@@ -1809,10 +1809,14 @@
18091809
** or --force flags is used, or unless this is a private check-in.
18101810
** The initial commit MUST have tags "trunk" and "sym-trunk".
18111811
*/
18121812
if( !vid ){
18131813
if( sCiInfo.zBranch==0 ){
1814
+ if( allowFork==0 && forceFlag==0 && g.markPrivate==0
1815
+ && db_exists("SELECT 1 from event where type='ci'") ){
1816
+ fossil_fatal("would fork. \"update\" first or use --allow-fork.");
1817
+ }
18141818
sCiInfo.zBranch = db_get("main-branch", "trunk");
18151819
}
18161820
}else if( sCiInfo.zBranch==0 && allowFork==0 && forceFlag==0
18171821
&& g.markPrivate==0 && !is_a_leaf(vid)
18181822
){
18191823
--- src/checkin.c
+++ src/checkin.c
@@ -1809,10 +1809,14 @@
1809 ** or --force flags is used, or unless this is a private check-in.
1810 ** The initial commit MUST have tags "trunk" and "sym-trunk".
1811 */
1812 if( !vid ){
1813 if( sCiInfo.zBranch==0 ){
 
 
 
 
1814 sCiInfo.zBranch = db_get("main-branch", "trunk");
1815 }
1816 }else if( sCiInfo.zBranch==0 && allowFork==0 && forceFlag==0
1817 && g.markPrivate==0 && !is_a_leaf(vid)
1818 ){
1819
--- src/checkin.c
+++ src/checkin.c
@@ -1809,10 +1809,14 @@
1809 ** or --force flags is used, or unless this is a private check-in.
1810 ** The initial commit MUST have tags "trunk" and "sym-trunk".
1811 */
1812 if( !vid ){
1813 if( sCiInfo.zBranch==0 ){
1814 if( allowFork==0 && forceFlag==0 && g.markPrivate==0
1815 && db_exists("SELECT 1 from event where type='ci'") ){
1816 fossil_fatal("would fork. \"update\" first or use --allow-fork.");
1817 }
1818 sCiInfo.zBranch = db_get("main-branch", "trunk");
1819 }
1820 }else if( sCiInfo.zBranch==0 && allowFork==0 && forceFlag==0
1821 && g.markPrivate==0 && !is_a_leaf(vid)
1822 ){
1823
+2 -1
--- src/clone.c
+++ src/clone.c
@@ -164,11 +164,11 @@
164164
}else{
165165
db_create_repository(g.argv[3]);
166166
db_open_repository(g.argv[3]);
167167
db_begin_transaction();
168168
db_record_repository_filename(g.argv[3]);
169
- db_initial_setup(0, 0, zDefaultUser, 0);
169
+ db_initial_setup(0, 0, zDefaultUser);
170170
user_select();
171171
db_set("content-schema", CONTENT_SCHEMA, 0);
172172
db_set("aux-schema", AUX_SCHEMA_MAX, 0);
173173
db_set("rebuilt", get_version(), 0);
174174
remember_or_get_http_auth(zHttpAuth, urlFlags & URL_REMEMBER, g.argv[2]);
@@ -182,10 +182,11 @@
182182
blob_reset(&fn);
183183
}
184184
db_multi_exec(
185185
"REPLACE INTO config(name,value,mtime)"
186186
" VALUES('server-code', lower(hex(randomblob(20))), now());"
187
+ "DELETE FROM config WHERE name='project-code';"
187188
);
188189
url_enable_proxy(0);
189190
clone_ssh_db_set_options();
190191
url_get_password_if_needed();
191192
g.xlinkClusterOnly = 1;
192193
--- src/clone.c
+++ src/clone.c
@@ -164,11 +164,11 @@
164 }else{
165 db_create_repository(g.argv[3]);
166 db_open_repository(g.argv[3]);
167 db_begin_transaction();
168 db_record_repository_filename(g.argv[3]);
169 db_initial_setup(0, 0, zDefaultUser, 0);
170 user_select();
171 db_set("content-schema", CONTENT_SCHEMA, 0);
172 db_set("aux-schema", AUX_SCHEMA_MAX, 0);
173 db_set("rebuilt", get_version(), 0);
174 remember_or_get_http_auth(zHttpAuth, urlFlags & URL_REMEMBER, g.argv[2]);
@@ -182,10 +182,11 @@
182 blob_reset(&fn);
183 }
184 db_multi_exec(
185 "REPLACE INTO config(name,value,mtime)"
186 " VALUES('server-code', lower(hex(randomblob(20))), now());"
 
187 );
188 url_enable_proxy(0);
189 clone_ssh_db_set_options();
190 url_get_password_if_needed();
191 g.xlinkClusterOnly = 1;
192
--- src/clone.c
+++ src/clone.c
@@ -164,11 +164,11 @@
164 }else{
165 db_create_repository(g.argv[3]);
166 db_open_repository(g.argv[3]);
167 db_begin_transaction();
168 db_record_repository_filename(g.argv[3]);
169 db_initial_setup(0, 0, zDefaultUser);
170 user_select();
171 db_set("content-schema", CONTENT_SCHEMA, 0);
172 db_set("aux-schema", AUX_SCHEMA_MAX, 0);
173 db_set("rebuilt", get_version(), 0);
174 remember_or_get_http_auth(zHttpAuth, urlFlags & URL_REMEMBER, g.argv[2]);
@@ -182,10 +182,11 @@
182 blob_reset(&fn);
183 }
184 db_multi_exec(
185 "REPLACE INTO config(name,value,mtime)"
186 " VALUES('server-code', lower(hex(randomblob(20))), now());"
187 "DELETE FROM config WHERE name='project-code';"
188 );
189 url_enable_proxy(0);
190 clone_ssh_db_set_options();
191 url_get_password_if_needed();
192 g.xlinkClusterOnly = 1;
193
+3 -1
--- src/configure.c
+++ src/configure.c
@@ -100,10 +100,11 @@
100100
{ "timeline-rail-colors", CONFIGSET_SKIN },
101101
{ "adunit", CONFIGSET_SKIN },
102102
{ "adunit-omit-if-admin", CONFIGSET_SKIN },
103103
{ "adunit-omit-if-user", CONFIGSET_SKIN },
104104
{ "white-foreground", CONFIGSET_SKIN },
105
+
105106
#ifdef FOSSIL_ENABLE_TH1_DOCS
106107
{ "th1-docs", CONFIGSET_TH1 },
107108
#endif
108109
#ifdef FOSSIL_ENABLE_TH1_HOOKS
109110
{ "th1-hooks", CONFIGSET_TH1 },
@@ -127,10 +128,11 @@
127128
{ "keep-glob", CONFIGSET_PROJ },
128129
{ "crnl-glob", CONFIGSET_PROJ },
129130
{ "encoding-glob", CONFIGSET_PROJ },
130131
{ "empty-dirs", CONFIGSET_PROJ },
131132
{ "allow-symlinks", CONFIGSET_PROJ },
133
+ { "dotfiles", CONFIGSET_PROJ },
132134
133135
{ "ticket-table", CONFIGSET_TKT },
134136
{ "ticket-common", CONFIGSET_TKT },
135137
{ "ticket-change", CONFIGSET_TKT },
136138
{ "ticket-newpage", CONFIGSET_TKT },
@@ -860,11 +862,11 @@
860862
**
861863
** Push the local configuration into the remote server identified
862864
** by URL. Admin privilege is required on the remote server for
863865
** this to work. When the same record exists both locally and on
864866
** the remote end, the one that was most recently changed wins.
865
-** Use the --legacy flag when talking to holder servers.
867
+** Use the --legacy flag when talking to older servers.
866868
**
867869
** %fossil configuration reset AREA
868870
**
869871
** Restore the configuration to the default. AREA as above.
870872
**
871873
--- src/configure.c
+++ src/configure.c
@@ -100,10 +100,11 @@
100 { "timeline-rail-colors", CONFIGSET_SKIN },
101 { "adunit", CONFIGSET_SKIN },
102 { "adunit-omit-if-admin", CONFIGSET_SKIN },
103 { "adunit-omit-if-user", CONFIGSET_SKIN },
104 { "white-foreground", CONFIGSET_SKIN },
 
105 #ifdef FOSSIL_ENABLE_TH1_DOCS
106 { "th1-docs", CONFIGSET_TH1 },
107 #endif
108 #ifdef FOSSIL_ENABLE_TH1_HOOKS
109 { "th1-hooks", CONFIGSET_TH1 },
@@ -127,10 +128,11 @@
127 { "keep-glob", CONFIGSET_PROJ },
128 { "crnl-glob", CONFIGSET_PROJ },
129 { "encoding-glob", CONFIGSET_PROJ },
130 { "empty-dirs", CONFIGSET_PROJ },
131 { "allow-symlinks", CONFIGSET_PROJ },
 
132
133 { "ticket-table", CONFIGSET_TKT },
134 { "ticket-common", CONFIGSET_TKT },
135 { "ticket-change", CONFIGSET_TKT },
136 { "ticket-newpage", CONFIGSET_TKT },
@@ -860,11 +862,11 @@
860 **
861 ** Push the local configuration into the remote server identified
862 ** by URL. Admin privilege is required on the remote server for
863 ** this to work. When the same record exists both locally and on
864 ** the remote end, the one that was most recently changed wins.
865 ** Use the --legacy flag when talking to holder servers.
866 **
867 ** %fossil configuration reset AREA
868 **
869 ** Restore the configuration to the default. AREA as above.
870 **
871
--- src/configure.c
+++ src/configure.c
@@ -100,10 +100,11 @@
100 { "timeline-rail-colors", CONFIGSET_SKIN },
101 { "adunit", CONFIGSET_SKIN },
102 { "adunit-omit-if-admin", CONFIGSET_SKIN },
103 { "adunit-omit-if-user", CONFIGSET_SKIN },
104 { "white-foreground", CONFIGSET_SKIN },
105
106 #ifdef FOSSIL_ENABLE_TH1_DOCS
107 { "th1-docs", CONFIGSET_TH1 },
108 #endif
109 #ifdef FOSSIL_ENABLE_TH1_HOOKS
110 { "th1-hooks", CONFIGSET_TH1 },
@@ -127,10 +128,11 @@
128 { "keep-glob", CONFIGSET_PROJ },
129 { "crnl-glob", CONFIGSET_PROJ },
130 { "encoding-glob", CONFIGSET_PROJ },
131 { "empty-dirs", CONFIGSET_PROJ },
132 { "allow-symlinks", CONFIGSET_PROJ },
133 { "dotfiles", CONFIGSET_PROJ },
134
135 { "ticket-table", CONFIGSET_TKT },
136 { "ticket-common", CONFIGSET_TKT },
137 { "ticket-change", CONFIGSET_TKT },
138 { "ticket-newpage", CONFIGSET_TKT },
@@ -860,11 +862,11 @@
862 **
863 ** Push the local configuration into the remote server identified
864 ** by URL. Admin privilege is required on the remote server for
865 ** this to work. When the same record exists both locally and on
866 ** the remote end, the one that was most recently changed wins.
867 ** Use the --legacy flag when talking to older servers.
868 **
869 ** %fossil configuration reset AREA
870 **
871 ** Restore the configuration to the default. AREA as above.
872 **
873
+3 -1
--- src/configure.c
+++ src/configure.c
@@ -100,10 +100,11 @@
100100
{ "timeline-rail-colors", CONFIGSET_SKIN },
101101
{ "adunit", CONFIGSET_SKIN },
102102
{ "adunit-omit-if-admin", CONFIGSET_SKIN },
103103
{ "adunit-omit-if-user", CONFIGSET_SKIN },
104104
{ "white-foreground", CONFIGSET_SKIN },
105
+
105106
#ifdef FOSSIL_ENABLE_TH1_DOCS
106107
{ "th1-docs", CONFIGSET_TH1 },
107108
#endif
108109
#ifdef FOSSIL_ENABLE_TH1_HOOKS
109110
{ "th1-hooks", CONFIGSET_TH1 },
@@ -127,10 +128,11 @@
127128
{ "keep-glob", CONFIGSET_PROJ },
128129
{ "crnl-glob", CONFIGSET_PROJ },
129130
{ "encoding-glob", CONFIGSET_PROJ },
130131
{ "empty-dirs", CONFIGSET_PROJ },
131132
{ "allow-symlinks", CONFIGSET_PROJ },
133
+ { "dotfiles", CONFIGSET_PROJ },
132134
133135
{ "ticket-table", CONFIGSET_TKT },
134136
{ "ticket-common", CONFIGSET_TKT },
135137
{ "ticket-change", CONFIGSET_TKT },
136138
{ "ticket-newpage", CONFIGSET_TKT },
@@ -860,11 +862,11 @@
860862
**
861863
** Push the local configuration into the remote server identified
862864
** by URL. Admin privilege is required on the remote server for
863865
** this to work. When the same record exists both locally and on
864866
** the remote end, the one that was most recently changed wins.
865
-** Use the --legacy flag when talking to holder servers.
867
+** Use the --legacy flag when talking to older servers.
866868
**
867869
** %fossil configuration reset AREA
868870
**
869871
** Restore the configuration to the default. AREA as above.
870872
**
871873
--- src/configure.c
+++ src/configure.c
@@ -100,10 +100,11 @@
100 { "timeline-rail-colors", CONFIGSET_SKIN },
101 { "adunit", CONFIGSET_SKIN },
102 { "adunit-omit-if-admin", CONFIGSET_SKIN },
103 { "adunit-omit-if-user", CONFIGSET_SKIN },
104 { "white-foreground", CONFIGSET_SKIN },
 
105 #ifdef FOSSIL_ENABLE_TH1_DOCS
106 { "th1-docs", CONFIGSET_TH1 },
107 #endif
108 #ifdef FOSSIL_ENABLE_TH1_HOOKS
109 { "th1-hooks", CONFIGSET_TH1 },
@@ -127,10 +128,11 @@
127 { "keep-glob", CONFIGSET_PROJ },
128 { "crnl-glob", CONFIGSET_PROJ },
129 { "encoding-glob", CONFIGSET_PROJ },
130 { "empty-dirs", CONFIGSET_PROJ },
131 { "allow-symlinks", CONFIGSET_PROJ },
 
132
133 { "ticket-table", CONFIGSET_TKT },
134 { "ticket-common", CONFIGSET_TKT },
135 { "ticket-change", CONFIGSET_TKT },
136 { "ticket-newpage", CONFIGSET_TKT },
@@ -860,11 +862,11 @@
860 **
861 ** Push the local configuration into the remote server identified
862 ** by URL. Admin privilege is required on the remote server for
863 ** this to work. When the same record exists both locally and on
864 ** the remote end, the one that was most recently changed wins.
865 ** Use the --legacy flag when talking to holder servers.
866 **
867 ** %fossil configuration reset AREA
868 **
869 ** Restore the configuration to the default. AREA as above.
870 **
871
--- src/configure.c
+++ src/configure.c
@@ -100,10 +100,11 @@
100 { "timeline-rail-colors", CONFIGSET_SKIN },
101 { "adunit", CONFIGSET_SKIN },
102 { "adunit-omit-if-admin", CONFIGSET_SKIN },
103 { "adunit-omit-if-user", CONFIGSET_SKIN },
104 { "white-foreground", CONFIGSET_SKIN },
105
106 #ifdef FOSSIL_ENABLE_TH1_DOCS
107 { "th1-docs", CONFIGSET_TH1 },
108 #endif
109 #ifdef FOSSIL_ENABLE_TH1_HOOKS
110 { "th1-hooks", CONFIGSET_TH1 },
@@ -127,10 +128,11 @@
128 { "keep-glob", CONFIGSET_PROJ },
129 { "crnl-glob", CONFIGSET_PROJ },
130 { "encoding-glob", CONFIGSET_PROJ },
131 { "empty-dirs", CONFIGSET_PROJ },
132 { "allow-symlinks", CONFIGSET_PROJ },
133 { "dotfiles", CONFIGSET_PROJ },
134
135 { "ticket-table", CONFIGSET_TKT },
136 { "ticket-common", CONFIGSET_TKT },
137 { "ticket-change", CONFIGSET_TKT },
138 { "ticket-newpage", CONFIGSET_TKT },
@@ -860,11 +862,11 @@
862 **
863 ** Push the local configuration into the remote server identified
864 ** by URL. Admin privilege is required on the remote server for
865 ** this to work. When the same record exists both locally and on
866 ** the remote end, the one that was most recently changed wins.
867 ** Use the --legacy flag when talking to older servers.
868 **
869 ** %fossil configuration reset AREA
870 **
871 ** Restore the configuration to the default. AREA as above.
872 **
873
+8 -38
--- src/db.c
+++ src/db.c
@@ -1475,42 +1475,10 @@
14751475
" VALUES('reader','','kptw','Reader');"
14761476
);
14771477
}
14781478
}
14791479
1480
-/*
1481
-** This function sets the server and project codes if they do not already
1482
-** exist. Currently, it should be called only by the db_initial_setup()
1483
-** or cmd_webserver() functions, the latter being used to facilitate more
1484
-** robust integration with "canned image" environments (e.g. Docker).
1485
-*/
1486
-void db_setup_server_and_project_codes(
1487
- int optional
1488
-){
1489
- if( !optional ){
1490
- db_multi_exec(
1491
- "INSERT INTO config(name,value,mtime)"
1492
- " VALUES('server-code', lower(hex(randomblob(20))),now());"
1493
- "INSERT INTO config(name,value,mtime)"
1494
- " VALUES('project-code', lower(hex(randomblob(20))),now());"
1495
- );
1496
- }else if( db_is_writeable("repository") ){
1497
- if( db_get("server-code", 0)==0 ) {
1498
- db_multi_exec(
1499
- "INSERT INTO config(name,value,mtime)"
1500
- " VALUES('server-code', lower(hex(randomblob(20))),now());"
1501
- );
1502
- }
1503
- if( db_get("project-code", 0)==0 ) {
1504
- db_multi_exec(
1505
- "INSERT INTO config(name,value,mtime)"
1506
- " VALUES('project-code', lower(hex(randomblob(20))),now());"
1507
- );
1508
- }
1509
- }
1510
-}
1511
-
15121480
/*
15131481
** Return a pointer to a string that contains the RHS of an IN operator
15141482
** that will select CONFIG table names that are in the list of control
15151483
** settings.
15161484
*/
@@ -1548,23 +1516,25 @@
15481516
** not server and project codes are invented for this repository.
15491517
*/
15501518
void db_initial_setup(
15511519
const char *zTemplate, /* Repository from which to copy settings. */
15521520
const char *zInitialDate, /* Initial date of repository. (ex: "now") */
1553
- const char *zDefaultUser, /* Default user for the repository */
1554
- int makeServerCodes /* True to make new server & project codes */
1521
+ const char *zDefaultUser /* Default user for the repository */
15551522
){
15561523
char *zDate;
15571524
Blob hash;
15581525
Blob manifest;
15591526
15601527
db_set("content-schema", CONTENT_SCHEMA, 0);
15611528
db_set("aux-schema", AUX_SCHEMA_MAX, 0);
15621529
db_set("rebuilt", get_version(), 0);
1563
- if( makeServerCodes ){
1564
- db_setup_server_and_project_codes(0);
1565
- }
1530
+ db_multi_exec(
1531
+ "INSERT INTO config(name,value,mtime)"
1532
+ " VALUES('server-code', lower(hex(randomblob(20))),now());"
1533
+ "INSERT INTO config(name,value,mtime)"
1534
+ " VALUES('project-code', lower(hex(randomblob(20))),now());"
1535
+ );
15661536
if( !db_is_global("autosync") ) db_set_int("autosync", 1, 0);
15671537
if( !db_is_global("localauth") ) db_set_int("localauth", 0, 0);
15681538
if( !db_is_global("timeline-plaintext") ){
15691539
db_set_int("timeline-plaintext", 1, 0);
15701540
}
@@ -1687,11 +1657,11 @@
16871657
db_open_repository(g.argv[2]);
16881658
db_open_config(0);
16891659
if( zTemplate ) db_attach(zTemplate, "settingSrc");
16901660
db_begin_transaction();
16911661
if( zDate==0 ) zDate = "now";
1692
- db_initial_setup(zTemplate, zDate, zDefaultUser, 1);
1662
+ db_initial_setup(zTemplate, zDate, zDefaultUser);
16931663
db_end_transaction(0);
16941664
if( zTemplate ) db_detach("settingSrc");
16951665
fossil_print("project-id: %s\n", db_get("project-code", 0));
16961666
fossil_print("server-id: %s\n", db_get("server-code", 0));
16971667
zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
16981668
--- src/db.c
+++ src/db.c
@@ -1475,42 +1475,10 @@
1475 " VALUES('reader','','kptw','Reader');"
1476 );
1477 }
1478 }
1479
1480 /*
1481 ** This function sets the server and project codes if they do not already
1482 ** exist. Currently, it should be called only by the db_initial_setup()
1483 ** or cmd_webserver() functions, the latter being used to facilitate more
1484 ** robust integration with "canned image" environments (e.g. Docker).
1485 */
1486 void db_setup_server_and_project_codes(
1487 int optional
1488 ){
1489 if( !optional ){
1490 db_multi_exec(
1491 "INSERT INTO config(name,value,mtime)"
1492 " VALUES('server-code', lower(hex(randomblob(20))),now());"
1493 "INSERT INTO config(name,value,mtime)"
1494 " VALUES('project-code', lower(hex(randomblob(20))),now());"
1495 );
1496 }else if( db_is_writeable("repository") ){
1497 if( db_get("server-code", 0)==0 ) {
1498 db_multi_exec(
1499 "INSERT INTO config(name,value,mtime)"
1500 " VALUES('server-code', lower(hex(randomblob(20))),now());"
1501 );
1502 }
1503 if( db_get("project-code", 0)==0 ) {
1504 db_multi_exec(
1505 "INSERT INTO config(name,value,mtime)"
1506 " VALUES('project-code', lower(hex(randomblob(20))),now());"
1507 );
1508 }
1509 }
1510 }
1511
1512 /*
1513 ** Return a pointer to a string that contains the RHS of an IN operator
1514 ** that will select CONFIG table names that are in the list of control
1515 ** settings.
1516 */
@@ -1548,23 +1516,25 @@
1548 ** not server and project codes are invented for this repository.
1549 */
1550 void db_initial_setup(
1551 const char *zTemplate, /* Repository from which to copy settings. */
1552 const char *zInitialDate, /* Initial date of repository. (ex: "now") */
1553 const char *zDefaultUser, /* Default user for the repository */
1554 int makeServerCodes /* True to make new server & project codes */
1555 ){
1556 char *zDate;
1557 Blob hash;
1558 Blob manifest;
1559
1560 db_set("content-schema", CONTENT_SCHEMA, 0);
1561 db_set("aux-schema", AUX_SCHEMA_MAX, 0);
1562 db_set("rebuilt", get_version(), 0);
1563 if( makeServerCodes ){
1564 db_setup_server_and_project_codes(0);
1565 }
 
 
 
1566 if( !db_is_global("autosync") ) db_set_int("autosync", 1, 0);
1567 if( !db_is_global("localauth") ) db_set_int("localauth", 0, 0);
1568 if( !db_is_global("timeline-plaintext") ){
1569 db_set_int("timeline-plaintext", 1, 0);
1570 }
@@ -1687,11 +1657,11 @@
1687 db_open_repository(g.argv[2]);
1688 db_open_config(0);
1689 if( zTemplate ) db_attach(zTemplate, "settingSrc");
1690 db_begin_transaction();
1691 if( zDate==0 ) zDate = "now";
1692 db_initial_setup(zTemplate, zDate, zDefaultUser, 1);
1693 db_end_transaction(0);
1694 if( zTemplate ) db_detach("settingSrc");
1695 fossil_print("project-id: %s\n", db_get("project-code", 0));
1696 fossil_print("server-id: %s\n", db_get("server-code", 0));
1697 zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
1698
--- src/db.c
+++ src/db.c
@@ -1475,42 +1475,10 @@
1475 " VALUES('reader','','kptw','Reader');"
1476 );
1477 }
1478 }
1479
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1480 /*
1481 ** Return a pointer to a string that contains the RHS of an IN operator
1482 ** that will select CONFIG table names that are in the list of control
1483 ** settings.
1484 */
@@ -1548,23 +1516,25 @@
1516 ** not server and project codes are invented for this repository.
1517 */
1518 void db_initial_setup(
1519 const char *zTemplate, /* Repository from which to copy settings. */
1520 const char *zInitialDate, /* Initial date of repository. (ex: "now") */
1521 const char *zDefaultUser /* Default user for the repository */
 
1522 ){
1523 char *zDate;
1524 Blob hash;
1525 Blob manifest;
1526
1527 db_set("content-schema", CONTENT_SCHEMA, 0);
1528 db_set("aux-schema", AUX_SCHEMA_MAX, 0);
1529 db_set("rebuilt", get_version(), 0);
1530 db_multi_exec(
1531 "INSERT INTO config(name,value,mtime)"
1532 " VALUES('server-code', lower(hex(randomblob(20))),now());"
1533 "INSERT INTO config(name,value,mtime)"
1534 " VALUES('project-code', lower(hex(randomblob(20))),now());"
1535 );
1536 if( !db_is_global("autosync") ) db_set_int("autosync", 1, 0);
1537 if( !db_is_global("localauth") ) db_set_int("localauth", 0, 0);
1538 if( !db_is_global("timeline-plaintext") ){
1539 db_set_int("timeline-plaintext", 1, 0);
1540 }
@@ -1687,11 +1657,11 @@
1657 db_open_repository(g.argv[2]);
1658 db_open_config(0);
1659 if( zTemplate ) db_attach(zTemplate, "settingSrc");
1660 db_begin_transaction();
1661 if( zDate==0 ) zDate = "now";
1662 db_initial_setup(zTemplate, zDate, zDefaultUser);
1663 db_end_transaction(0);
1664 if( zTemplate ) db_detach("settingSrc");
1665 fossil_print("project-id: %s\n", db_get("project-code", 0));
1666 fossil_print("server-id: %s\n", db_get("server-code", 0));
1667 zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
1668
+1 -1
--- src/doc.c
+++ src/doc.c
@@ -640,11 +640,11 @@
640640
if( blob_size(&title)==0 ) blob_append(&title,zName,-1);
641641
style_header("%s", blob_str(&title));
642642
blob_append(cgi_output_blob(), blob_buffer(&filebody),blob_size(&filebody));
643643
style_footer();
644644
#ifdef FOSSIL_ENABLE_TH1_DOCS
645
- }else if( db_get_boolean("th1-docs", 0) &&
645
+ }else if( Th_AreDocsEnabled() &&
646646
fossil_strcmp(zMime, "application/x-th1")==0 ){
647647
style_header("%h", zName);
648648
Th_Render(blob_str(&filebody));
649649
style_footer();
650650
#endif
651651
--- src/doc.c
+++ src/doc.c
@@ -640,11 +640,11 @@
640 if( blob_size(&title)==0 ) blob_append(&title,zName,-1);
641 style_header("%s", blob_str(&title));
642 blob_append(cgi_output_blob(), blob_buffer(&filebody),blob_size(&filebody));
643 style_footer();
644 #ifdef FOSSIL_ENABLE_TH1_DOCS
645 }else if( db_get_boolean("th1-docs", 0) &&
646 fossil_strcmp(zMime, "application/x-th1")==0 ){
647 style_header("%h", zName);
648 Th_Render(blob_str(&filebody));
649 style_footer();
650 #endif
651
--- src/doc.c
+++ src/doc.c
@@ -640,11 +640,11 @@
640 if( blob_size(&title)==0 ) blob_append(&title,zName,-1);
641 style_header("%s", blob_str(&title));
642 blob_append(cgi_output_blob(), blob_buffer(&filebody),blob_size(&filebody));
643 style_footer();
644 #ifdef FOSSIL_ENABLE_TH1_DOCS
645 }else if( Th_AreDocsEnabled() &&
646 fossil_strcmp(zMime, "application/x-th1")==0 ){
647 style_header("%h", zName);
648 Th_Render(blob_str(&filebody));
649 style_footer();
650 #endif
651
+1 -1
--- src/import.c
+++ src/import.c
@@ -1543,11 +1543,11 @@
15431543
}
15441544
db_open_repository(g.argv[2]);
15451545
db_open_config(0);
15461546
15471547
db_begin_transaction();
1548
- if( !incrFlag ) db_initial_setup(0, 0, 0, 1);
1548
+ if( !incrFlag ) db_initial_setup(0, 0, 0);
15491549
15501550
if( svnFlag ){
15511551
db_multi_exec(
15521552
"CREATE TEMP TABLE xrevisions("
15531553
" trev INTEGER, tbranch INT, trid INT, tparent INT DEFAULT 0,"
15541554
--- src/import.c
+++ src/import.c
@@ -1543,11 +1543,11 @@
1543 }
1544 db_open_repository(g.argv[2]);
1545 db_open_config(0);
1546
1547 db_begin_transaction();
1548 if( !incrFlag ) db_initial_setup(0, 0, 0, 1);
1549
1550 if( svnFlag ){
1551 db_multi_exec(
1552 "CREATE TEMP TABLE xrevisions("
1553 " trev INTEGER, tbranch INT, trid INT, tparent INT DEFAULT 0,"
1554
--- src/import.c
+++ src/import.c
@@ -1543,11 +1543,11 @@
1543 }
1544 db_open_repository(g.argv[2]);
1545 db_open_config(0);
1546
1547 db_begin_transaction();
1548 if( !incrFlag ) db_initial_setup(0, 0, 0);
1549
1550 if( svnFlag ){
1551 db_multi_exec(
1552 "CREATE TEMP TABLE xrevisions("
1553 " trev INTEGER, tbranch INT, trid INT, tparent INT DEFAULT 0,"
1554
--- src/json_config.c
+++ src/json_config.c
@@ -84,10 +84,11 @@
8484
{ "keep-glob", CONFIGSET_PROJ },
8585
{ "crnl-glob", CONFIGSET_PROJ },
8686
{ "encoding-glob", CONFIGSET_PROJ },
8787
{ "empty-dirs", CONFIGSET_PROJ },
8888
{ "allow-symlinks", CONFIGSET_PROJ },
89
+{ "dotfiles", CONFIGSET_PROJ },
8990
9091
{ "ticket-table", CONFIGSET_TKT },
9192
{ "ticket-common", CONFIGSET_TKT },
9293
{ "ticket-change", CONFIGSET_TKT },
9394
{ "ticket-newpage", CONFIGSET_TKT },
9495
--- src/json_config.c
+++ src/json_config.c
@@ -84,10 +84,11 @@
84 { "keep-glob", CONFIGSET_PROJ },
85 { "crnl-glob", CONFIGSET_PROJ },
86 { "encoding-glob", CONFIGSET_PROJ },
87 { "empty-dirs", CONFIGSET_PROJ },
88 { "allow-symlinks", CONFIGSET_PROJ },
 
89
90 { "ticket-table", CONFIGSET_TKT },
91 { "ticket-common", CONFIGSET_TKT },
92 { "ticket-change", CONFIGSET_TKT },
93 { "ticket-newpage", CONFIGSET_TKT },
94
--- src/json_config.c
+++ src/json_config.c
@@ -84,10 +84,11 @@
84 { "keep-glob", CONFIGSET_PROJ },
85 { "crnl-glob", CONFIGSET_PROJ },
86 { "encoding-glob", CONFIGSET_PROJ },
87 { "empty-dirs", CONFIGSET_PROJ },
88 { "allow-symlinks", CONFIGSET_PROJ },
89 { "dotfiles", CONFIGSET_PROJ },
90
91 { "ticket-table", CONFIGSET_TKT },
92 { "ticket-common", CONFIGSET_TKT },
93 { "ticket-change", CONFIGSET_TKT },
94 { "ticket-newpage", CONFIGSET_TKT },
95
--- src/json_config.c
+++ src/json_config.c
@@ -84,10 +84,11 @@
8484
{ "keep-glob", CONFIGSET_PROJ },
8585
{ "crnl-glob", CONFIGSET_PROJ },
8686
{ "encoding-glob", CONFIGSET_PROJ },
8787
{ "empty-dirs", CONFIGSET_PROJ },
8888
{ "allow-symlinks", CONFIGSET_PROJ },
89
+{ "dotfiles", CONFIGSET_PROJ },
8990
9091
{ "ticket-table", CONFIGSET_TKT },
9192
{ "ticket-common", CONFIGSET_TKT },
9293
{ "ticket-change", CONFIGSET_TKT },
9394
{ "ticket-newpage", CONFIGSET_TKT },
9495
--- src/json_config.c
+++ src/json_config.c
@@ -84,10 +84,11 @@
84 { "keep-glob", CONFIGSET_PROJ },
85 { "crnl-glob", CONFIGSET_PROJ },
86 { "encoding-glob", CONFIGSET_PROJ },
87 { "empty-dirs", CONFIGSET_PROJ },
88 { "allow-symlinks", CONFIGSET_PROJ },
 
89
90 { "ticket-table", CONFIGSET_TKT },
91 { "ticket-common", CONFIGSET_TKT },
92 { "ticket-change", CONFIGSET_TKT },
93 { "ticket-newpage", CONFIGSET_TKT },
94
--- src/json_config.c
+++ src/json_config.c
@@ -84,10 +84,11 @@
84 { "keep-glob", CONFIGSET_PROJ },
85 { "crnl-glob", CONFIGSET_PROJ },
86 { "encoding-glob", CONFIGSET_PROJ },
87 { "empty-dirs", CONFIGSET_PROJ },
88 { "allow-symlinks", CONFIGSET_PROJ },
89 { "dotfiles", CONFIGSET_PROJ },
90
91 { "ticket-table", CONFIGSET_TKT },
92 { "ticket-common", CONFIGSET_TKT },
93 { "ticket-change", CONFIGSET_TKT },
94 { "ticket-newpage", CONFIGSET_TKT },
95
+39 -14
--- src/main.c
+++ src/main.c
@@ -2031,19 +2031,43 @@
20312031
** Open the repository to be served if it is known. If g.argv[arg] is
20322032
** a directory full of repositories, then set g.zRepositoryName to
20332033
** the name of that directory and the specific repository will be
20342034
** opened later by process_one_web_page() based on the content of
20352035
** the PATH_INFO variable.
2036
+**
2037
+** If the fCreate flag is set, then create the repository if it
2038
+** does not already exist.
20362039
*/
2037
-static void find_server_repository(int arg){
2040
+static void find_server_repository(int arg, int fCreate){
20382041
if( g.argc<=arg ){
20392042
db_must_be_within_tree();
2040
- }else if( file_isdir(g.argv[arg])==1 ){
2041
- g.zRepositoryName = mprintf("%s", g.argv[arg]);
2042
- file_simplify_name(g.zRepositoryName, -1, 0);
20432043
}else{
2044
- db_open_repository(g.argv[arg]);
2044
+ const char *zRepo = g.argv[arg];
2045
+ int isDir = file_isdir(zRepo);
2046
+ if( isDir==1 ){
2047
+ g.zRepositoryName = mprintf("%s", zRepo);
2048
+ file_simplify_name(g.zRepositoryName, -1, 0);
2049
+ }else{
2050
+ if( isDir==0 && fCreate ){
2051
+ const char *zPassword;
2052
+ db_create_repository(zRepo);
2053
+ db_open_repository(zRepo);
2054
+ db_begin_transaction();
2055
+ db_initial_setup(0, "now", g.zLogin);
2056
+ db_end_transaction(0);
2057
+ fossil_print("project-id: %s\n", db_get("project-code", 0));
2058
+ fossil_print("server-id: %s\n", db_get("server-code", 0));
2059
+ zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
2060
+ fossil_print("admin-user: %s (initial password is \"%s\")\n",
2061
+ g.zLogin, zPassword);
2062
+ cache_initialize();
2063
+ g.zLogin = 0;
2064
+ g.userUid = 0;
2065
+ }else{
2066
+ db_open_repository(zRepo);
2067
+ }
2068
+ }
20452069
}
20462070
}
20472071
20482072
/*
20492073
** undocumented format:
@@ -2146,15 +2170,15 @@
21462170
g.fullHttpReply = 1;
21472171
if( g.argc>=5 ){
21482172
g.httpIn = fossil_fopen(g.argv[2], "rb");
21492173
g.httpOut = fossil_fopen(g.argv[3], "wb");
21502174
zIpAddr = g.argv[4];
2151
- find_server_repository(5);
2175
+ find_server_repository(5, 0);
21522176
}else{
21532177
g.httpIn = stdin;
21542178
g.httpOut = stdout;
2155
- find_server_repository(2);
2179
+ find_server_repository(2, 0);
21562180
}
21572181
if( zIpAddr==0 ){
21582182
zIpAddr = cgi_ssh_remote_addr(0);
21592183
if( zIpAddr && zIpAddr[0] ){
21602184
g.fSshClient |= CGI_SSH_CLIENT;
@@ -2197,11 +2221,11 @@
21972221
Th_InitTraceLog();
21982222
login_set_capabilities("sx", 0);
21992223
g.useLocalauth = 1;
22002224
g.httpIn = stdin;
22012225
g.httpOut = stdout;
2202
- find_server_repository(2);
2226
+ find_server_repository(2, 0);
22032227
g.cgiOutput = 1;
22042228
g.fullHttpReply = 1;
22052229
zIpAddr = cgi_ssh_remote_addr(0);
22062230
if( zIpAddr && zIpAddr[0] ){
22072231
g.fSshClient |= CGI_SSH_CLIENT;
@@ -2254,12 +2278,12 @@
22542278
** The "ui" command automatically starts a web browser after initializing
22552279
** the web server. The "ui" command also binds to 127.0.0.1 and so will
22562280
** only process HTTP traffic from the local machine.
22572281
**
22582282
** The REPOSITORY can be a directory (aka folder) that contains one or
2259
-** more repositories with names ending in ".fossil". In this case, the
2260
-** a prefix of the URL pathname is used to search the directory for an
2283
+** more repositories with names ending in ".fossil". In this case, a
2284
+** prefix of the URL pathname is used to search the directory for an
22612285
** appropriate repository. To thwart mischief, the pathname in the URL must
22622286
** contain only alphanumerics, "_", "/", "-", and ".", and no "-" may
22632287
** occur after "/", and every "." must be surrounded on both sides by
22642288
** alphanumerics. Any pathname that does not satisfy these constraints
22652289
** results in a 404 error. Files in REPOSITORY that match the comma-separated
@@ -2276,10 +2300,11 @@
22762300
** connection is from localhost. The "ui" command also enables --repolist
22772301
** by default.
22782302
**
22792303
** Options:
22802304
** --baseurl URL Use URL as the base (useful for reverse proxies)
2305
+** --create Create a new REPOSITORY if it does not already exist
22812306
** --files GLOBLIST Comma-separated list of glob patterns for static files
22822307
** --localauth enable automatic login for requests from localhost
22832308
** --localhost listen on 127.0.0.1 only (always true for "ui")
22842309
** --nojail Drop root privileges but do not enter the chroot jail
22852310
** --notfound URL Redirect
@@ -2305,10 +2330,11 @@
23052330
#endif
23062331
int allowRepoList; /* List repositories on URL "/" */
23072332
const char *zAltBase; /* Argument to the --baseurl option */
23082333
const char *zFileGlob; /* Static content must match this */
23092334
char *zIpAddr = 0; /* Bind to this IP address */
2335
+ int fCreate = 0;
23102336
23112337
#if defined(_WIN32)
23122338
const char *zStopperFile; /* Name of file used to terminate server */
23132339
zStopperFile = find_option("stopper", 0, 1);
23142340
#endif
@@ -2329,10 +2355,11 @@
23292355
Th_InitTraceLog();
23302356
zPort = find_option("port", "P", 1);
23312357
zNotFound = find_option("notfound", 0, 1);
23322358
allowRepoList = find_option("repolist",0,0)!=0;
23332359
zAltBase = find_option("baseurl", 0, 1);
2360
+ fCreate = find_option("create",0,0)!=0;
23342361
if( find_option("scgi", 0, 0)!=0 ) flags |= HTTP_SERVER_SCGI;
23352362
if( zAltBase ){
23362363
set_base_url(zAltBase);
23372364
}
23382365
if( find_option("localhost", 0, 0)!=0 ){
@@ -2347,11 +2374,11 @@
23472374
if( isUiCmd ){
23482375
flags |= HTTP_SERVER_LOCALHOST|HTTP_SERVER_REPOLIST;
23492376
g.useLocalauth = 1;
23502377
allowRepoList = 1;
23512378
}
2352
- find_server_repository(2);
2379
+ find_server_repository(2, fCreate);
23532380
if( zPort ){
23542381
int i;
23552382
for(i=strlen(zPort)-1; i>=0 && zPort[i]!=':'; i--){}
23562383
if( i>0 ){
23572384
zIpAddr = mprintf("%.*s", i, zPort);
@@ -2387,12 +2414,10 @@
23872414
}else{
23882415
zBrowserCmd = mprintf("%s http://localhost:%%d/ &", zBrowser);
23892416
}
23902417
if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
23912418
if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
2392
- }else{
2393
- db_setup_server_and_project_codes(1);
23942419
}
23952420
db_close(1);
23962421
if( cgi_http_server(iPort, mxPort, zBrowserCmd, zIpAddr, flags) ){
23972422
fossil_fatal("unable to listen on TCP socket %d", iPort);
23982423
}
@@ -2401,11 +2426,11 @@
24012426
g.httpOut = stdout;
24022427
if( g.fHttpTrace || g.fSqlTrace ){
24032428
fprintf(stderr, "====== SERVER pid %d =======\n", getpid());
24042429
}
24052430
g.cgiOutput = 1;
2406
- find_server_repository(2);
2431
+ find_server_repository(2, 0);
24072432
g.zRepositoryName = enter_chroot_jail(g.zRepositoryName, noJail);
24082433
if( flags & HTTP_SERVER_SCGI ){
24092434
cgi_handle_scgi_request();
24102435
}else{
24112436
cgi_handle_http_request(0);
24122437
--- src/main.c
+++ src/main.c
@@ -2031,19 +2031,43 @@
2031 ** Open the repository to be served if it is known. If g.argv[arg] is
2032 ** a directory full of repositories, then set g.zRepositoryName to
2033 ** the name of that directory and the specific repository will be
2034 ** opened later by process_one_web_page() based on the content of
2035 ** the PATH_INFO variable.
 
 
 
2036 */
2037 static void find_server_repository(int arg){
2038 if( g.argc<=arg ){
2039 db_must_be_within_tree();
2040 }else if( file_isdir(g.argv[arg])==1 ){
2041 g.zRepositoryName = mprintf("%s", g.argv[arg]);
2042 file_simplify_name(g.zRepositoryName, -1, 0);
2043 }else{
2044 db_open_repository(g.argv[arg]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2045 }
2046 }
2047
2048 /*
2049 ** undocumented format:
@@ -2146,15 +2170,15 @@
2146 g.fullHttpReply = 1;
2147 if( g.argc>=5 ){
2148 g.httpIn = fossil_fopen(g.argv[2], "rb");
2149 g.httpOut = fossil_fopen(g.argv[3], "wb");
2150 zIpAddr = g.argv[4];
2151 find_server_repository(5);
2152 }else{
2153 g.httpIn = stdin;
2154 g.httpOut = stdout;
2155 find_server_repository(2);
2156 }
2157 if( zIpAddr==0 ){
2158 zIpAddr = cgi_ssh_remote_addr(0);
2159 if( zIpAddr && zIpAddr[0] ){
2160 g.fSshClient |= CGI_SSH_CLIENT;
@@ -2197,11 +2221,11 @@
2197 Th_InitTraceLog();
2198 login_set_capabilities("sx", 0);
2199 g.useLocalauth = 1;
2200 g.httpIn = stdin;
2201 g.httpOut = stdout;
2202 find_server_repository(2);
2203 g.cgiOutput = 1;
2204 g.fullHttpReply = 1;
2205 zIpAddr = cgi_ssh_remote_addr(0);
2206 if( zIpAddr && zIpAddr[0] ){
2207 g.fSshClient |= CGI_SSH_CLIENT;
@@ -2254,12 +2278,12 @@
2254 ** The "ui" command automatically starts a web browser after initializing
2255 ** the web server. The "ui" command also binds to 127.0.0.1 and so will
2256 ** only process HTTP traffic from the local machine.
2257 **
2258 ** The REPOSITORY can be a directory (aka folder) that contains one or
2259 ** more repositories with names ending in ".fossil". In this case, the
2260 ** a prefix of the URL pathname is used to search the directory for an
2261 ** appropriate repository. To thwart mischief, the pathname in the URL must
2262 ** contain only alphanumerics, "_", "/", "-", and ".", and no "-" may
2263 ** occur after "/", and every "." must be surrounded on both sides by
2264 ** alphanumerics. Any pathname that does not satisfy these constraints
2265 ** results in a 404 error. Files in REPOSITORY that match the comma-separated
@@ -2276,10 +2300,11 @@
2276 ** connection is from localhost. The "ui" command also enables --repolist
2277 ** by default.
2278 **
2279 ** Options:
2280 ** --baseurl URL Use URL as the base (useful for reverse proxies)
 
2281 ** --files GLOBLIST Comma-separated list of glob patterns for static files
2282 ** --localauth enable automatic login for requests from localhost
2283 ** --localhost listen on 127.0.0.1 only (always true for "ui")
2284 ** --nojail Drop root privileges but do not enter the chroot jail
2285 ** --notfound URL Redirect
@@ -2305,10 +2330,11 @@
2305 #endif
2306 int allowRepoList; /* List repositories on URL "/" */
2307 const char *zAltBase; /* Argument to the --baseurl option */
2308 const char *zFileGlob; /* Static content must match this */
2309 char *zIpAddr = 0; /* Bind to this IP address */
 
2310
2311 #if defined(_WIN32)
2312 const char *zStopperFile; /* Name of file used to terminate server */
2313 zStopperFile = find_option("stopper", 0, 1);
2314 #endif
@@ -2329,10 +2355,11 @@
2329 Th_InitTraceLog();
2330 zPort = find_option("port", "P", 1);
2331 zNotFound = find_option("notfound", 0, 1);
2332 allowRepoList = find_option("repolist",0,0)!=0;
2333 zAltBase = find_option("baseurl", 0, 1);
 
2334 if( find_option("scgi", 0, 0)!=0 ) flags |= HTTP_SERVER_SCGI;
2335 if( zAltBase ){
2336 set_base_url(zAltBase);
2337 }
2338 if( find_option("localhost", 0, 0)!=0 ){
@@ -2347,11 +2374,11 @@
2347 if( isUiCmd ){
2348 flags |= HTTP_SERVER_LOCALHOST|HTTP_SERVER_REPOLIST;
2349 g.useLocalauth = 1;
2350 allowRepoList = 1;
2351 }
2352 find_server_repository(2);
2353 if( zPort ){
2354 int i;
2355 for(i=strlen(zPort)-1; i>=0 && zPort[i]!=':'; i--){}
2356 if( i>0 ){
2357 zIpAddr = mprintf("%.*s", i, zPort);
@@ -2387,12 +2414,10 @@
2387 }else{
2388 zBrowserCmd = mprintf("%s http://localhost:%%d/ &", zBrowser);
2389 }
2390 if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
2391 if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
2392 }else{
2393 db_setup_server_and_project_codes(1);
2394 }
2395 db_close(1);
2396 if( cgi_http_server(iPort, mxPort, zBrowserCmd, zIpAddr, flags) ){
2397 fossil_fatal("unable to listen on TCP socket %d", iPort);
2398 }
@@ -2401,11 +2426,11 @@
2401 g.httpOut = stdout;
2402 if( g.fHttpTrace || g.fSqlTrace ){
2403 fprintf(stderr, "====== SERVER pid %d =======\n", getpid());
2404 }
2405 g.cgiOutput = 1;
2406 find_server_repository(2);
2407 g.zRepositoryName = enter_chroot_jail(g.zRepositoryName, noJail);
2408 if( flags & HTTP_SERVER_SCGI ){
2409 cgi_handle_scgi_request();
2410 }else{
2411 cgi_handle_http_request(0);
2412
--- src/main.c
+++ src/main.c
@@ -2031,19 +2031,43 @@
2031 ** Open the repository to be served if it is known. If g.argv[arg] is
2032 ** a directory full of repositories, then set g.zRepositoryName to
2033 ** the name of that directory and the specific repository will be
2034 ** opened later by process_one_web_page() based on the content of
2035 ** the PATH_INFO variable.
2036 **
2037 ** If the fCreate flag is set, then create the repository if it
2038 ** does not already exist.
2039 */
2040 static void find_server_repository(int arg, int fCreate){
2041 if( g.argc<=arg ){
2042 db_must_be_within_tree();
 
 
 
2043 }else{
2044 const char *zRepo = g.argv[arg];
2045 int isDir = file_isdir(zRepo);
2046 if( isDir==1 ){
2047 g.zRepositoryName = mprintf("%s", zRepo);
2048 file_simplify_name(g.zRepositoryName, -1, 0);
2049 }else{
2050 if( isDir==0 && fCreate ){
2051 const char *zPassword;
2052 db_create_repository(zRepo);
2053 db_open_repository(zRepo);
2054 db_begin_transaction();
2055 db_initial_setup(0, "now", g.zLogin);
2056 db_end_transaction(0);
2057 fossil_print("project-id: %s\n", db_get("project-code", 0));
2058 fossil_print("server-id: %s\n", db_get("server-code", 0));
2059 zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
2060 fossil_print("admin-user: %s (initial password is \"%s\")\n",
2061 g.zLogin, zPassword);
2062 cache_initialize();
2063 g.zLogin = 0;
2064 g.userUid = 0;
2065 }else{
2066 db_open_repository(zRepo);
2067 }
2068 }
2069 }
2070 }
2071
2072 /*
2073 ** undocumented format:
@@ -2146,15 +2170,15 @@
2170 g.fullHttpReply = 1;
2171 if( g.argc>=5 ){
2172 g.httpIn = fossil_fopen(g.argv[2], "rb");
2173 g.httpOut = fossil_fopen(g.argv[3], "wb");
2174 zIpAddr = g.argv[4];
2175 find_server_repository(5, 0);
2176 }else{
2177 g.httpIn = stdin;
2178 g.httpOut = stdout;
2179 find_server_repository(2, 0);
2180 }
2181 if( zIpAddr==0 ){
2182 zIpAddr = cgi_ssh_remote_addr(0);
2183 if( zIpAddr && zIpAddr[0] ){
2184 g.fSshClient |= CGI_SSH_CLIENT;
@@ -2197,11 +2221,11 @@
2221 Th_InitTraceLog();
2222 login_set_capabilities("sx", 0);
2223 g.useLocalauth = 1;
2224 g.httpIn = stdin;
2225 g.httpOut = stdout;
2226 find_server_repository(2, 0);
2227 g.cgiOutput = 1;
2228 g.fullHttpReply = 1;
2229 zIpAddr = cgi_ssh_remote_addr(0);
2230 if( zIpAddr && zIpAddr[0] ){
2231 g.fSshClient |= CGI_SSH_CLIENT;
@@ -2254,12 +2278,12 @@
2278 ** The "ui" command automatically starts a web browser after initializing
2279 ** the web server. The "ui" command also binds to 127.0.0.1 and so will
2280 ** only process HTTP traffic from the local machine.
2281 **
2282 ** The REPOSITORY can be a directory (aka folder) that contains one or
2283 ** more repositories with names ending in ".fossil". In this case, a
2284 ** prefix of the URL pathname is used to search the directory for an
2285 ** appropriate repository. To thwart mischief, the pathname in the URL must
2286 ** contain only alphanumerics, "_", "/", "-", and ".", and no "-" may
2287 ** occur after "/", and every "." must be surrounded on both sides by
2288 ** alphanumerics. Any pathname that does not satisfy these constraints
2289 ** results in a 404 error. Files in REPOSITORY that match the comma-separated
@@ -2276,10 +2300,11 @@
2300 ** connection is from localhost. The "ui" command also enables --repolist
2301 ** by default.
2302 **
2303 ** Options:
2304 ** --baseurl URL Use URL as the base (useful for reverse proxies)
2305 ** --create Create a new REPOSITORY if it does not already exist
2306 ** --files GLOBLIST Comma-separated list of glob patterns for static files
2307 ** --localauth enable automatic login for requests from localhost
2308 ** --localhost listen on 127.0.0.1 only (always true for "ui")
2309 ** --nojail Drop root privileges but do not enter the chroot jail
2310 ** --notfound URL Redirect
@@ -2305,10 +2330,11 @@
2330 #endif
2331 int allowRepoList; /* List repositories on URL "/" */
2332 const char *zAltBase; /* Argument to the --baseurl option */
2333 const char *zFileGlob; /* Static content must match this */
2334 char *zIpAddr = 0; /* Bind to this IP address */
2335 int fCreate = 0;
2336
2337 #if defined(_WIN32)
2338 const char *zStopperFile; /* Name of file used to terminate server */
2339 zStopperFile = find_option("stopper", 0, 1);
2340 #endif
@@ -2329,10 +2355,11 @@
2355 Th_InitTraceLog();
2356 zPort = find_option("port", "P", 1);
2357 zNotFound = find_option("notfound", 0, 1);
2358 allowRepoList = find_option("repolist",0,0)!=0;
2359 zAltBase = find_option("baseurl", 0, 1);
2360 fCreate = find_option("create",0,0)!=0;
2361 if( find_option("scgi", 0, 0)!=0 ) flags |= HTTP_SERVER_SCGI;
2362 if( zAltBase ){
2363 set_base_url(zAltBase);
2364 }
2365 if( find_option("localhost", 0, 0)!=0 ){
@@ -2347,11 +2374,11 @@
2374 if( isUiCmd ){
2375 flags |= HTTP_SERVER_LOCALHOST|HTTP_SERVER_REPOLIST;
2376 g.useLocalauth = 1;
2377 allowRepoList = 1;
2378 }
2379 find_server_repository(2, fCreate);
2380 if( zPort ){
2381 int i;
2382 for(i=strlen(zPort)-1; i>=0 && zPort[i]!=':'; i--){}
2383 if( i>0 ){
2384 zIpAddr = mprintf("%.*s", i, zPort);
@@ -2387,12 +2414,10 @@
2414 }else{
2415 zBrowserCmd = mprintf("%s http://localhost:%%d/ &", zBrowser);
2416 }
2417 if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
2418 if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
 
 
2419 }
2420 db_close(1);
2421 if( cgi_http_server(iPort, mxPort, zBrowserCmd, zIpAddr, flags) ){
2422 fossil_fatal("unable to listen on TCP socket %d", iPort);
2423 }
@@ -2401,11 +2426,11 @@
2426 g.httpOut = stdout;
2427 if( g.fHttpTrace || g.fSqlTrace ){
2428 fprintf(stderr, "====== SERVER pid %d =======\n", getpid());
2429 }
2430 g.cgiOutput = 1;
2431 find_server_repository(2, 0);
2432 g.zRepositoryName = enter_chroot_jail(g.zRepositoryName, noJail);
2433 if( flags & HTTP_SERVER_SCGI ){
2434 cgi_handle_scgi_request();
2435 }else{
2436 cgi_handle_http_request(0);
2437
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -587,11 +587,11 @@
587587
#### The directories where the OpenSSL include and library files are located.
588588
# The recommended usage here is to use the Sysinternals junction tool
589589
# to create a hard link between an "openssl-1.x" sub-directory of the
590590
# Fossil source code directory and the target OpenSSL source directory.
591591
#
592
-OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2
592
+OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2a
593593
OPENSSLINCDIR = $(OPENSSLDIR)/include
594594
OPENSSLLIBDIR = $(OPENSSLDIR)
595595
596596
#### Either the directory where the Tcl library is installed or the Tcl
597597
# source code directory resides (depending on the value of the macro
@@ -1320,11 +1320,11 @@
13201320
13211321
# Uncomment to enable Tcl support
13221322
# FOSSIL_ENABLE_TCL = 1
13231323
13241324
!ifdef FOSSIL_ENABLE_SSL
1325
-SSLDIR = $(B)\compat\openssl-1.0.2
1325
+SSLDIR = $(B)\compat\openssl-1.0.2a
13261326
SSLINCDIR = $(SSLDIR)\inc32
13271327
SSLLIBDIR = $(SSLDIR)\out32
13281328
SSLLFLAGS = /nologo /opt:ref /debug
13291329
SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
13301330
!if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
13311331
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -587,11 +587,11 @@
587 #### The directories where the OpenSSL include and library files are located.
588 # The recommended usage here is to use the Sysinternals junction tool
589 # to create a hard link between an "openssl-1.x" sub-directory of the
590 # Fossil source code directory and the target OpenSSL source directory.
591 #
592 OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2
593 OPENSSLINCDIR = $(OPENSSLDIR)/include
594 OPENSSLLIBDIR = $(OPENSSLDIR)
595
596 #### Either the directory where the Tcl library is installed or the Tcl
597 # source code directory resides (depending on the value of the macro
@@ -1320,11 +1320,11 @@
1320
1321 # Uncomment to enable Tcl support
1322 # FOSSIL_ENABLE_TCL = 1
1323
1324 !ifdef FOSSIL_ENABLE_SSL
1325 SSLDIR = $(B)\compat\openssl-1.0.2
1326 SSLINCDIR = $(SSLDIR)\inc32
1327 SSLLIBDIR = $(SSLDIR)\out32
1328 SSLLFLAGS = /nologo /opt:ref /debug
1329 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
1330 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
1331
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -587,11 +587,11 @@
587 #### The directories where the OpenSSL include and library files are located.
588 # The recommended usage here is to use the Sysinternals junction tool
589 # to create a hard link between an "openssl-1.x" sub-directory of the
590 # Fossil source code directory and the target OpenSSL source directory.
591 #
592 OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2a
593 OPENSSLINCDIR = $(OPENSSLDIR)/include
594 OPENSSLLIBDIR = $(OPENSSLDIR)
595
596 #### Either the directory where the Tcl library is installed or the Tcl
597 # source code directory resides (depending on the value of the macro
@@ -1320,11 +1320,11 @@
1320
1321 # Uncomment to enable Tcl support
1322 # FOSSIL_ENABLE_TCL = 1
1323
1324 !ifdef FOSSIL_ENABLE_SSL
1325 SSLDIR = $(B)\compat\openssl-1.0.2a
1326 SSLINCDIR = $(SSLDIR)\inc32
1327 SSLLIBDIR = $(SSLDIR)\out32
1328 SSLLFLAGS = /nologo /opt:ref /debug
1329 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
1330 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
1331
+1 -1
--- src/rebuild.c
+++ src/rebuild.c
@@ -953,11 +953,11 @@
953953
/* We should be done with options.. */
954954
verify_all_options();
955955
956956
db_open_config(0);
957957
db_begin_transaction();
958
- db_initial_setup(0, 0, 0, 1);
958
+ db_initial_setup(0, 0, 0);
959959
960960
fossil_print("Reading files from directory \"%s\"...\n", g.argv[3]);
961961
recon_read_dir(g.argv[3]);
962962
fossil_print("\nBuilding the Fossil repository...\n");
963963
964964
--- src/rebuild.c
+++ src/rebuild.c
@@ -953,11 +953,11 @@
953 /* We should be done with options.. */
954 verify_all_options();
955
956 db_open_config(0);
957 db_begin_transaction();
958 db_initial_setup(0, 0, 0, 1);
959
960 fossil_print("Reading files from directory \"%s\"...\n", g.argv[3]);
961 recon_read_dir(g.argv[3]);
962 fossil_print("\nBuilding the Fossil repository...\n");
963
964
--- src/rebuild.c
+++ src/rebuild.c
@@ -953,11 +953,11 @@
953 /* We should be done with options.. */
954 verify_all_options();
955
956 db_open_config(0);
957 db_begin_transaction();
958 db_initial_setup(0, 0, 0);
959
960 fossil_print("Reading files from directory \"%s\"...\n", g.argv[3]);
961 recon_read_dir(g.argv[3]);
962 fossil_print("\nBuilding the Fossil repository...\n");
963
964
+52 -25
--- src/shell.c
+++ src/shell.c
@@ -22,10 +22,17 @@
2222
*/
2323
#if defined(INCLUDE_MSVC_H)
2424
#include "msvc.h"
2525
#endif
2626
27
+/*
28
+** No support for loadable extensions in VxWorks.
29
+*/
30
+#if (defined(__RTP__) || defined(_WRS_KERNEL)) && !SQLITE_OMIT_LOAD_EXTENSION
31
+# define SQLITE_OMIT_LOAD_EXTENSION 1
32
+#endif
33
+
2734
/*
2835
** Enable large-file support for fopen() and friends on unix.
2936
*/
3037
#ifndef SQLITE_DISABLE_LFS
3138
# define _LARGE_FILE 1
@@ -105,14 +112,19 @@
105112
#else
106113
/* Make sure isatty() has a prototype.
107114
*/
108115
extern int isatty(int);
109116
110
-/* popen and pclose are not C89 functions and so are sometimes omitted from
111
-** the <stdio.h> header */
112
-extern FILE *popen(const char*,const char*);
113
-extern int pclose(FILE*);
117
+#if !defined(__RTP__) && !defined(_WRS_KERNEL)
118
+ /* popen and pclose are not C89 functions and so are sometimes omitted from
119
+ ** the <stdio.h> header */
120
+ extern FILE *popen(const char*,const char*);
121
+ extern int pclose(FILE*);
122
+#else
123
+# define SQLITE_OMIT_POPEN 1
124
+#endif
125
+
114126
#endif
115127
116128
#if defined(_WIN32_WCE)
117129
/* Windows CE (arm-wince-mingw32ce-gcc) does not provide isatty()
118130
* thus we always assume that we have a console. That can be
@@ -163,14 +175,22 @@
163175
t = (sqlite3_int64)(r*86400000.0);
164176
}
165177
return t;
166178
}
167179
168
-#if !defined(_WIN32) && !defined(WIN32) && !defined(_WRS_KERNEL) \
169
- && !defined(__minux)
180
+#if !defined(_WIN32) && !defined(WIN32) && !defined(__minux)
170181
#include <sys/time.h>
171182
#include <sys/resource.h>
183
+
184
+/* VxWorks does not support getrusage() as far as we can determine */
185
+#if defined(_WRS_KERNEL) || defined(__RTP__)
186
+struct rusage {
187
+ struct timeval ru_utime; /* user CPU time used */
188
+ struct timeval ru_stime; /* system CPU time used */
189
+};
190
+#define getrusage(A,B) memset(B,0,sizeof(*B))
191
+#endif
172192
173193
/* Saved resource information for the beginning of an operation */
174194
static struct rusage sBegin; /* CPU time at start */
175195
static sqlite3_int64 iBegin; /* Wall-clock time at start */
176196
@@ -193,12 +213,12 @@
193213
/*
194214
** Print the timing results.
195215
*/
196216
static void endTimer(void){
197217
if( enableTimer ){
198
- struct rusage sEnd;
199218
sqlite3_int64 iEnd = timeOfDay();
219
+ struct rusage sEnd;
200220
getrusage(RUSAGE_SELF, &sEnd);
201221
printf("Run Time: real %.3f user %f sys %f\n",
202222
(iEnd - iBegin)*0.001,
203223
timeDiff(&sBegin.ru_utime, &sEnd.ru_utime),
204224
timeDiff(&sBegin.ru_stime, &sEnd.ru_stime));
@@ -2121,11 +2141,11 @@
21212141
** + Keep track of the line number in p->nLine.
21222142
** + Store the character that terminates the field in p->cTerm. Store
21232143
** EOF on end-of-file.
21242144
** + Report syntax errors on stderr
21252145
*/
2126
-static char *csv_read_one_field(ImportCtx *p){
2146
+static char *SQLITE_CDECL csv_read_one_field(ImportCtx *p){
21272147
int c;
21282148
int cSep = p->cColSep;
21292149
int rSep = p->cRowSep;
21302150
p->n = 0;
21312151
c = fgetc(p->in);
@@ -2195,11 +2215,11 @@
21952215
** + Keep track of the row number in p->nLine.
21962216
** + Store the character that terminates the field in p->cTerm. Store
21972217
** EOF on end-of-file.
21982218
** + Report syntax errors on stderr
21992219
*/
2200
-static char *ascii_read_one_field(ImportCtx *p){
2220
+static char *SQLITE_CDECL ascii_read_one_field(ImportCtx *p){
22012221
int c;
22022222
int cSep = p->cColSep;
22032223
int rSep = p->cRowSep;
22042224
p->n = 0;
22052225
c = fgetc(p->in);
@@ -2437,11 +2457,13 @@
24372457
/*
24382458
** Change the output file back to stdout
24392459
*/
24402460
static void output_reset(ShellState *p){
24412461
if( p->outfile[0]=='|' ){
2462
+#ifndef SQLITE_OMIT_POPEN
24422463
pclose(p->out);
2464
+#endif
24432465
}else{
24442466
output_file_close(p->out);
24452467
}
24462468
p->outfile[0] = 0;
24472469
p->out = stdout;
@@ -2887,12 +2909,12 @@
28872909
int i, j; /* Loop counters */
28882910
int needCommit; /* True to COMMIT or ROLLBACK at end */
28892911
int nSep; /* Number of bytes in p->colSeparator[] */
28902912
char *zSql; /* An SQL statement */
28912913
ImportCtx sCtx; /* Reader context */
2892
- char *(*xRead)(ImportCtx*); /* Procedure to read one value */
2893
- int (*xCloser)(FILE*); /* Procedure to close th3 connection */
2914
+ char *(SQLITE_CDECL *xRead)(ImportCtx*); /* Func to read one value */
2915
+ int (SQLITE_CDECL *xCloser)(FILE*); /* Func to close file */
28942916
28952917
if( nArg!=3 ){
28962918
fprintf(stderr, "Usage: .import FILE TABLE\n");
28972919
goto meta_command_exit;
28982920
}
@@ -2930,13 +2952,18 @@
29302952
return 1;
29312953
}
29322954
sCtx.zFile = zFile;
29332955
sCtx.nLine = 1;
29342956
if( sCtx.zFile[0]=='|' ){
2957
+#ifdef SQLITE_OMIT_POPEN
2958
+ fprintf(stderr, "Error: pipes are not supported in this OS\n");
2959
+ return 1;
2960
+#else
29352961
sCtx.in = popen(sCtx.zFile+1, "r");
29362962
sCtx.zFile = "<pipe>";
29372963
xCloser = pclose;
2964
+#endif
29382965
}else{
29392966
sCtx.in = fopen(sCtx.zFile, "rb");
29402967
xCloser = fclose;
29412968
}
29422969
if( p->mode==MODE_Ascii ){
@@ -3255,18 +3282,24 @@
32553282
}else{
32563283
p->outCount = 0;
32573284
}
32583285
output_reset(p);
32593286
if( zFile[0]=='|' ){
3287
+#ifdef SQLITE_OMIT_POPEN
3288
+ fprintf(stderr,"Error: pipes are not supported in this OS\n");
3289
+ rc = 1;
3290
+ p->out = stdout;
3291
+#else
32603292
p->out = popen(zFile + 1, "w");
32613293
if( p->out==0 ){
32623294
fprintf(stderr,"Error: cannot open pipe \"%s\"\n", zFile + 1);
32633295
p->out = stdout;
32643296
rc = 1;
32653297
}else{
32663298
sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
32673299
}
3300
+#endif
32683301
}else{
32693302
p->out = output_file_open(zFile);
32703303
if( p->out==0 ){
32713304
if( strcmp(zFile,"off")!=0 ){
32723305
fprintf(stderr,"Error: cannot write to \"%s\"\n", zFile);
@@ -3806,16 +3839,16 @@
38063839
}
38073840
}else
38083841
38093842
if( c=='t' && strncmp(azArg[0], "trace", n)==0 ){
38103843
open_db(p, 0);
3811
- output_file_close(p->traceOut);
38123844
if( nArg!=2 ){
38133845
fprintf(stderr, "Usage: .trace FILE|off\n");
38143846
rc = 1;
38153847
goto meta_command_exit;
38163848
}
3849
+ output_file_close(p->traceOut);
38173850
p->traceOut = output_file_open(azArg[1]);
38183851
#if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT)
38193852
if( p->traceOut==0 ){
38203853
sqlite3_trace(p->db, 0, 0);
38213854
}else{
@@ -4187,27 +4220,25 @@
41874220
** Read input from the file given by sqliterc_override. Or if that
41884221
** parameter is NULL, take input from ~/.sqliterc
41894222
**
41904223
** Returns the number of errors.
41914224
*/
4192
-static int process_sqliterc(
4225
+static void process_sqliterc(
41934226
ShellState *p, /* Configuration data */
41944227
const char *sqliterc_override /* Name of config file. NULL to use default */
41954228
){
41964229
char *home_dir = NULL;
41974230
const char *sqliterc = sqliterc_override;
41984231
char *zBuf = 0;
41994232
FILE *in = NULL;
4200
- int rc = 0;
42014233
42024234
if (sqliterc == NULL) {
42034235
home_dir = find_home_dir();
42044236
if( home_dir==0 ){
4205
-#if !defined(__RTP__) && !defined(_WRS_KERNEL)
4206
- fprintf(stderr,"%s: Error: cannot locate your home directory\n", Argv0);
4207
-#endif
4208
- return 1;
4237
+ fprintf(stderr, "-- warning: cannot find home directory;"
4238
+ " cannot read ~/.sqliterc\n");
4239
+ return;
42094240
}
42104241
sqlite3_initialize();
42114242
zBuf = sqlite3_mprintf("%s/.sqliterc",home_dir);
42124243
sqliterc = zBuf;
42134244
}
@@ -4214,15 +4245,14 @@
42144245
in = fopen(sqliterc,"rb");
42154246
if( in ){
42164247
if( stdin_is_interactive ){
42174248
fprintf(stderr,"-- Loading resources from %s\n",sqliterc);
42184249
}
4219
- rc = process_input(p,in);
4250
+ process_input(p,in);
42204251
fclose(in);
42214252
}
42224253
sqlite3_free(zBuf);
4223
- return rc;
42244254
}
42254255
42264256
/*
42274257
** Show available command line options
42284258
*/
@@ -4322,11 +4352,11 @@
43224352
exit(1);
43234353
}
43244354
return argv[i];
43254355
}
43264356
4327
-int main(int argc, char **argv){
4357
+int SQLITE_CDECL main(int argc, char **argv){
43284358
char *zErrMsg = 0;
43294359
ShellState data;
43304360
const char *zInitFile = 0;
43314361
int i;
43324362
int rc = 0;
@@ -4494,14 +4524,11 @@
44944524
44954525
/* Process the initialization file if there is one. If no -init option
44964526
** is given on the command line, look for a file named ~/.sqliterc and
44974527
** try to process it.
44984528
*/
4499
- rc = process_sqliterc(&data,zInitFile);
4500
- if( rc>0 ){
4501
- return rc;
4502
- }
4529
+ process_sqliterc(&data,zInitFile);
45034530
45044531
/* Make a second pass through the command-line argument and set
45054532
** options. This second pass is delayed until after the initialization
45064533
** file is processed so that the command-line arguments will override
45074534
** settings in the initialization file.
45084535
--- src/shell.c
+++ src/shell.c
@@ -22,10 +22,17 @@
22 */
23 #if defined(INCLUDE_MSVC_H)
24 #include "msvc.h"
25 #endif
26
 
 
 
 
 
 
 
27 /*
28 ** Enable large-file support for fopen() and friends on unix.
29 */
30 #ifndef SQLITE_DISABLE_LFS
31 # define _LARGE_FILE 1
@@ -105,14 +112,19 @@
105 #else
106 /* Make sure isatty() has a prototype.
107 */
108 extern int isatty(int);
109
110 /* popen and pclose are not C89 functions and so are sometimes omitted from
111 ** the <stdio.h> header */
112 extern FILE *popen(const char*,const char*);
113 extern int pclose(FILE*);
 
 
 
 
 
114 #endif
115
116 #if defined(_WIN32_WCE)
117 /* Windows CE (arm-wince-mingw32ce-gcc) does not provide isatty()
118 * thus we always assume that we have a console. That can be
@@ -163,14 +175,22 @@
163 t = (sqlite3_int64)(r*86400000.0);
164 }
165 return t;
166 }
167
168 #if !defined(_WIN32) && !defined(WIN32) && !defined(_WRS_KERNEL) \
169 && !defined(__minux)
170 #include <sys/time.h>
171 #include <sys/resource.h>
 
 
 
 
 
 
 
 
 
172
173 /* Saved resource information for the beginning of an operation */
174 static struct rusage sBegin; /* CPU time at start */
175 static sqlite3_int64 iBegin; /* Wall-clock time at start */
176
@@ -193,12 +213,12 @@
193 /*
194 ** Print the timing results.
195 */
196 static void endTimer(void){
197 if( enableTimer ){
198 struct rusage sEnd;
199 sqlite3_int64 iEnd = timeOfDay();
 
200 getrusage(RUSAGE_SELF, &sEnd);
201 printf("Run Time: real %.3f user %f sys %f\n",
202 (iEnd - iBegin)*0.001,
203 timeDiff(&sBegin.ru_utime, &sEnd.ru_utime),
204 timeDiff(&sBegin.ru_stime, &sEnd.ru_stime));
@@ -2121,11 +2141,11 @@
2121 ** + Keep track of the line number in p->nLine.
2122 ** + Store the character that terminates the field in p->cTerm. Store
2123 ** EOF on end-of-file.
2124 ** + Report syntax errors on stderr
2125 */
2126 static char *csv_read_one_field(ImportCtx *p){
2127 int c;
2128 int cSep = p->cColSep;
2129 int rSep = p->cRowSep;
2130 p->n = 0;
2131 c = fgetc(p->in);
@@ -2195,11 +2215,11 @@
2195 ** + Keep track of the row number in p->nLine.
2196 ** + Store the character that terminates the field in p->cTerm. Store
2197 ** EOF on end-of-file.
2198 ** + Report syntax errors on stderr
2199 */
2200 static char *ascii_read_one_field(ImportCtx *p){
2201 int c;
2202 int cSep = p->cColSep;
2203 int rSep = p->cRowSep;
2204 p->n = 0;
2205 c = fgetc(p->in);
@@ -2437,11 +2457,13 @@
2437 /*
2438 ** Change the output file back to stdout
2439 */
2440 static void output_reset(ShellState *p){
2441 if( p->outfile[0]=='|' ){
 
2442 pclose(p->out);
 
2443 }else{
2444 output_file_close(p->out);
2445 }
2446 p->outfile[0] = 0;
2447 p->out = stdout;
@@ -2887,12 +2909,12 @@
2887 int i, j; /* Loop counters */
2888 int needCommit; /* True to COMMIT or ROLLBACK at end */
2889 int nSep; /* Number of bytes in p->colSeparator[] */
2890 char *zSql; /* An SQL statement */
2891 ImportCtx sCtx; /* Reader context */
2892 char *(*xRead)(ImportCtx*); /* Procedure to read one value */
2893 int (*xCloser)(FILE*); /* Procedure to close th3 connection */
2894
2895 if( nArg!=3 ){
2896 fprintf(stderr, "Usage: .import FILE TABLE\n");
2897 goto meta_command_exit;
2898 }
@@ -2930,13 +2952,18 @@
2930 return 1;
2931 }
2932 sCtx.zFile = zFile;
2933 sCtx.nLine = 1;
2934 if( sCtx.zFile[0]=='|' ){
 
 
 
 
2935 sCtx.in = popen(sCtx.zFile+1, "r");
2936 sCtx.zFile = "<pipe>";
2937 xCloser = pclose;
 
2938 }else{
2939 sCtx.in = fopen(sCtx.zFile, "rb");
2940 xCloser = fclose;
2941 }
2942 if( p->mode==MODE_Ascii ){
@@ -3255,18 +3282,24 @@
3255 }else{
3256 p->outCount = 0;
3257 }
3258 output_reset(p);
3259 if( zFile[0]=='|' ){
 
 
 
 
 
3260 p->out = popen(zFile + 1, "w");
3261 if( p->out==0 ){
3262 fprintf(stderr,"Error: cannot open pipe \"%s\"\n", zFile + 1);
3263 p->out = stdout;
3264 rc = 1;
3265 }else{
3266 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
3267 }
 
3268 }else{
3269 p->out = output_file_open(zFile);
3270 if( p->out==0 ){
3271 if( strcmp(zFile,"off")!=0 ){
3272 fprintf(stderr,"Error: cannot write to \"%s\"\n", zFile);
@@ -3806,16 +3839,16 @@
3806 }
3807 }else
3808
3809 if( c=='t' && strncmp(azArg[0], "trace", n)==0 ){
3810 open_db(p, 0);
3811 output_file_close(p->traceOut);
3812 if( nArg!=2 ){
3813 fprintf(stderr, "Usage: .trace FILE|off\n");
3814 rc = 1;
3815 goto meta_command_exit;
3816 }
 
3817 p->traceOut = output_file_open(azArg[1]);
3818 #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT)
3819 if( p->traceOut==0 ){
3820 sqlite3_trace(p->db, 0, 0);
3821 }else{
@@ -4187,27 +4220,25 @@
4187 ** Read input from the file given by sqliterc_override. Or if that
4188 ** parameter is NULL, take input from ~/.sqliterc
4189 **
4190 ** Returns the number of errors.
4191 */
4192 static int process_sqliterc(
4193 ShellState *p, /* Configuration data */
4194 const char *sqliterc_override /* Name of config file. NULL to use default */
4195 ){
4196 char *home_dir = NULL;
4197 const char *sqliterc = sqliterc_override;
4198 char *zBuf = 0;
4199 FILE *in = NULL;
4200 int rc = 0;
4201
4202 if (sqliterc == NULL) {
4203 home_dir = find_home_dir();
4204 if( home_dir==0 ){
4205 #if !defined(__RTP__) && !defined(_WRS_KERNEL)
4206 fprintf(stderr,"%s: Error: cannot locate your home directory\n", Argv0);
4207 #endif
4208 return 1;
4209 }
4210 sqlite3_initialize();
4211 zBuf = sqlite3_mprintf("%s/.sqliterc",home_dir);
4212 sqliterc = zBuf;
4213 }
@@ -4214,15 +4245,14 @@
4214 in = fopen(sqliterc,"rb");
4215 if( in ){
4216 if( stdin_is_interactive ){
4217 fprintf(stderr,"-- Loading resources from %s\n",sqliterc);
4218 }
4219 rc = process_input(p,in);
4220 fclose(in);
4221 }
4222 sqlite3_free(zBuf);
4223 return rc;
4224 }
4225
4226 /*
4227 ** Show available command line options
4228 */
@@ -4322,11 +4352,11 @@
4322 exit(1);
4323 }
4324 return argv[i];
4325 }
4326
4327 int main(int argc, char **argv){
4328 char *zErrMsg = 0;
4329 ShellState data;
4330 const char *zInitFile = 0;
4331 int i;
4332 int rc = 0;
@@ -4494,14 +4524,11 @@
4494
4495 /* Process the initialization file if there is one. If no -init option
4496 ** is given on the command line, look for a file named ~/.sqliterc and
4497 ** try to process it.
4498 */
4499 rc = process_sqliterc(&data,zInitFile);
4500 if( rc>0 ){
4501 return rc;
4502 }
4503
4504 /* Make a second pass through the command-line argument and set
4505 ** options. This second pass is delayed until after the initialization
4506 ** file is processed so that the command-line arguments will override
4507 ** settings in the initialization file.
4508
--- src/shell.c
+++ src/shell.c
@@ -22,10 +22,17 @@
22 */
23 #if defined(INCLUDE_MSVC_H)
24 #include "msvc.h"
25 #endif
26
27 /*
28 ** No support for loadable extensions in VxWorks.
29 */
30 #if (defined(__RTP__) || defined(_WRS_KERNEL)) && !SQLITE_OMIT_LOAD_EXTENSION
31 # define SQLITE_OMIT_LOAD_EXTENSION 1
32 #endif
33
34 /*
35 ** Enable large-file support for fopen() and friends on unix.
36 */
37 #ifndef SQLITE_DISABLE_LFS
38 # define _LARGE_FILE 1
@@ -105,14 +112,19 @@
112 #else
113 /* Make sure isatty() has a prototype.
114 */
115 extern int isatty(int);
116
117 #if !defined(__RTP__) && !defined(_WRS_KERNEL)
118 /* popen and pclose are not C89 functions and so are sometimes omitted from
119 ** the <stdio.h> header */
120 extern FILE *popen(const char*,const char*);
121 extern int pclose(FILE*);
122 #else
123 # define SQLITE_OMIT_POPEN 1
124 #endif
125
126 #endif
127
128 #if defined(_WIN32_WCE)
129 /* Windows CE (arm-wince-mingw32ce-gcc) does not provide isatty()
130 * thus we always assume that we have a console. That can be
@@ -163,14 +175,22 @@
175 t = (sqlite3_int64)(r*86400000.0);
176 }
177 return t;
178 }
179
180 #if !defined(_WIN32) && !defined(WIN32) && !defined(__minux)
 
181 #include <sys/time.h>
182 #include <sys/resource.h>
183
184 /* VxWorks does not support getrusage() as far as we can determine */
185 #if defined(_WRS_KERNEL) || defined(__RTP__)
186 struct rusage {
187 struct timeval ru_utime; /* user CPU time used */
188 struct timeval ru_stime; /* system CPU time used */
189 };
190 #define getrusage(A,B) memset(B,0,sizeof(*B))
191 #endif
192
193 /* Saved resource information for the beginning of an operation */
194 static struct rusage sBegin; /* CPU time at start */
195 static sqlite3_int64 iBegin; /* Wall-clock time at start */
196
@@ -193,12 +213,12 @@
213 /*
214 ** Print the timing results.
215 */
216 static void endTimer(void){
217 if( enableTimer ){
 
218 sqlite3_int64 iEnd = timeOfDay();
219 struct rusage sEnd;
220 getrusage(RUSAGE_SELF, &sEnd);
221 printf("Run Time: real %.3f user %f sys %f\n",
222 (iEnd - iBegin)*0.001,
223 timeDiff(&sBegin.ru_utime, &sEnd.ru_utime),
224 timeDiff(&sBegin.ru_stime, &sEnd.ru_stime));
@@ -2121,11 +2141,11 @@
2141 ** + Keep track of the line number in p->nLine.
2142 ** + Store the character that terminates the field in p->cTerm. Store
2143 ** EOF on end-of-file.
2144 ** + Report syntax errors on stderr
2145 */
2146 static char *SQLITE_CDECL csv_read_one_field(ImportCtx *p){
2147 int c;
2148 int cSep = p->cColSep;
2149 int rSep = p->cRowSep;
2150 p->n = 0;
2151 c = fgetc(p->in);
@@ -2195,11 +2215,11 @@
2215 ** + Keep track of the row number in p->nLine.
2216 ** + Store the character that terminates the field in p->cTerm. Store
2217 ** EOF on end-of-file.
2218 ** + Report syntax errors on stderr
2219 */
2220 static char *SQLITE_CDECL ascii_read_one_field(ImportCtx *p){
2221 int c;
2222 int cSep = p->cColSep;
2223 int rSep = p->cRowSep;
2224 p->n = 0;
2225 c = fgetc(p->in);
@@ -2437,11 +2457,13 @@
2457 /*
2458 ** Change the output file back to stdout
2459 */
2460 static void output_reset(ShellState *p){
2461 if( p->outfile[0]=='|' ){
2462 #ifndef SQLITE_OMIT_POPEN
2463 pclose(p->out);
2464 #endif
2465 }else{
2466 output_file_close(p->out);
2467 }
2468 p->outfile[0] = 0;
2469 p->out = stdout;
@@ -2887,12 +2909,12 @@
2909 int i, j; /* Loop counters */
2910 int needCommit; /* True to COMMIT or ROLLBACK at end */
2911 int nSep; /* Number of bytes in p->colSeparator[] */
2912 char *zSql; /* An SQL statement */
2913 ImportCtx sCtx; /* Reader context */
2914 char *(SQLITE_CDECL *xRead)(ImportCtx*); /* Func to read one value */
2915 int (SQLITE_CDECL *xCloser)(FILE*); /* Func to close file */
2916
2917 if( nArg!=3 ){
2918 fprintf(stderr, "Usage: .import FILE TABLE\n");
2919 goto meta_command_exit;
2920 }
@@ -2930,13 +2952,18 @@
2952 return 1;
2953 }
2954 sCtx.zFile = zFile;
2955 sCtx.nLine = 1;
2956 if( sCtx.zFile[0]=='|' ){
2957 #ifdef SQLITE_OMIT_POPEN
2958 fprintf(stderr, "Error: pipes are not supported in this OS\n");
2959 return 1;
2960 #else
2961 sCtx.in = popen(sCtx.zFile+1, "r");
2962 sCtx.zFile = "<pipe>";
2963 xCloser = pclose;
2964 #endif
2965 }else{
2966 sCtx.in = fopen(sCtx.zFile, "rb");
2967 xCloser = fclose;
2968 }
2969 if( p->mode==MODE_Ascii ){
@@ -3255,18 +3282,24 @@
3282 }else{
3283 p->outCount = 0;
3284 }
3285 output_reset(p);
3286 if( zFile[0]=='|' ){
3287 #ifdef SQLITE_OMIT_POPEN
3288 fprintf(stderr,"Error: pipes are not supported in this OS\n");
3289 rc = 1;
3290 p->out = stdout;
3291 #else
3292 p->out = popen(zFile + 1, "w");
3293 if( p->out==0 ){
3294 fprintf(stderr,"Error: cannot open pipe \"%s\"\n", zFile + 1);
3295 p->out = stdout;
3296 rc = 1;
3297 }else{
3298 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
3299 }
3300 #endif
3301 }else{
3302 p->out = output_file_open(zFile);
3303 if( p->out==0 ){
3304 if( strcmp(zFile,"off")!=0 ){
3305 fprintf(stderr,"Error: cannot write to \"%s\"\n", zFile);
@@ -3806,16 +3839,16 @@
3839 }
3840 }else
3841
3842 if( c=='t' && strncmp(azArg[0], "trace", n)==0 ){
3843 open_db(p, 0);
 
3844 if( nArg!=2 ){
3845 fprintf(stderr, "Usage: .trace FILE|off\n");
3846 rc = 1;
3847 goto meta_command_exit;
3848 }
3849 output_file_close(p->traceOut);
3850 p->traceOut = output_file_open(azArg[1]);
3851 #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT)
3852 if( p->traceOut==0 ){
3853 sqlite3_trace(p->db, 0, 0);
3854 }else{
@@ -4187,27 +4220,25 @@
4220 ** Read input from the file given by sqliterc_override. Or if that
4221 ** parameter is NULL, take input from ~/.sqliterc
4222 **
4223 ** Returns the number of errors.
4224 */
4225 static void process_sqliterc(
4226 ShellState *p, /* Configuration data */
4227 const char *sqliterc_override /* Name of config file. NULL to use default */
4228 ){
4229 char *home_dir = NULL;
4230 const char *sqliterc = sqliterc_override;
4231 char *zBuf = 0;
4232 FILE *in = NULL;
 
4233
4234 if (sqliterc == NULL) {
4235 home_dir = find_home_dir();
4236 if( home_dir==0 ){
4237 fprintf(stderr, "-- warning: cannot find home directory;"
4238 " cannot read ~/.sqliterc\n");
4239 return;
 
4240 }
4241 sqlite3_initialize();
4242 zBuf = sqlite3_mprintf("%s/.sqliterc",home_dir);
4243 sqliterc = zBuf;
4244 }
@@ -4214,15 +4245,14 @@
4245 in = fopen(sqliterc,"rb");
4246 if( in ){
4247 if( stdin_is_interactive ){
4248 fprintf(stderr,"-- Loading resources from %s\n",sqliterc);
4249 }
4250 process_input(p,in);
4251 fclose(in);
4252 }
4253 sqlite3_free(zBuf);
 
4254 }
4255
4256 /*
4257 ** Show available command line options
4258 */
@@ -4322,11 +4352,11 @@
4352 exit(1);
4353 }
4354 return argv[i];
4355 }
4356
4357 int SQLITE_CDECL main(int argc, char **argv){
4358 char *zErrMsg = 0;
4359 ShellState data;
4360 const char *zInitFile = 0;
4361 int i;
4362 int rc = 0;
@@ -4494,14 +4524,11 @@
4524
4525 /* Process the initialization file if there is one. If no -init option
4526 ** is given on the command line, look for a file named ~/.sqliterc and
4527 ** try to process it.
4528 */
4529 process_sqliterc(&data,zInitFile);
 
 
 
4530
4531 /* Make a second pass through the command-line argument and set
4532 ** options. This second pass is delayed until after the initialization
4533 ** file is processed so that the command-line arguments will override
4534 ** settings in the initialization file.
4535
+1284 -443
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.8.8. By combining all the individual C code files into this
3
+** version 3.8.9. 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.
@@ -88,10 +88,48 @@
8888
#endif /* _MSVC_H_ */
8989
9090
/************** End of msvc.h ************************************************/
9191
/************** Continuing where we left off in sqliteInt.h ******************/
9292
93
+/*
94
+** Special setup for VxWorks
95
+*/
96
+/************** Include vxworks.h in the middle of sqliteInt.h ***************/
97
+/************** Begin file vxworks.h *****************************************/
98
+/*
99
+** 2015-03-02
100
+**
101
+** The author disclaims copyright to this source code. In place of
102
+** a legal notice, here is a blessing:
103
+**
104
+** May you do good and not evil.
105
+** May you find forgiveness for yourself and forgive others.
106
+** May you share freely, never taking more than you give.
107
+**
108
+******************************************************************************
109
+**
110
+** This file contains code that is specific to Wind River's VxWorks
111
+*/
112
+#if defined(__RTP__) || defined(_WRS_KERNEL)
113
+/* This is VxWorks. Set up things specially for that OS
114
+*/
115
+#include <vxWorks.h>
116
+#include <pthread.h> /* amalgamator: dontcache */
117
+#define OS_VXWORKS 1
118
+#define SQLITE_OS_OTHER 0
119
+#define SQLITE_HOMEGROWN_RECURSIVE_MUTEX 1
120
+#define SQLITE_OMIT_LOAD_EXTENSION 1
121
+#define SQLITE_ENABLE_LOCKING_STYLE 0
122
+#define HAVE_UTIME 1
123
+#else
124
+/* This is not VxWorks. */
125
+#define OS_VXWORKS 0
126
+#endif /* defined(_WRS_KERNEL) */
127
+
128
+/************** End of vxworks.h *********************************************/
129
+/************** Continuing where we left off in sqliteInt.h ******************/
130
+
93131
/*
94132
** These #defines should enable >2GB file support on POSIX if the
95133
** underlying operating system supports it. If the OS lacks
96134
** large file support, or if the OS is windows, these should be no-ops.
97135
**
@@ -223,10 +261,17 @@
223261
#ifndef SQLITE_API
224262
# define SQLITE_API
225263
#endif
226264
227265
266
+/*
267
+** Add the ability to override 'cdecl'
268
+*/
269
+#ifndef SQLITE_CDECL
270
+# define SQLITE_CDECL
271
+#endif
272
+
228273
/*
229274
** These no-op macros are used in front of interfaces to mark those
230275
** interfaces as either deprecated or experimental. New applications
231276
** should not use deprecated interfaces - they are supported for backwards
232277
** compatibility only. Application writers should be aware that
@@ -276,13 +321,13 @@
276321
**
277322
** See also: [sqlite3_libversion()],
278323
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
279324
** [sqlite_version()] and [sqlite_source_id()].
280325
*/
281
-#define SQLITE_VERSION "3.8.8"
282
-#define SQLITE_VERSION_NUMBER 3008008
283
-#define SQLITE_SOURCE_ID "2015-02-25 14:25:31 6d132e7a224ee68b5cefe9222944aac5760ffc20"
326
+#define SQLITE_VERSION "3.8.9"
327
+#define SQLITE_VERSION_NUMBER 3008009
328
+#define SQLITE_SOURCE_ID "2015-03-24 18:19:39 436314b5728c9413f9ac2d837e1c19364f31be72"
284329
285330
/*
286331
** CAPI3REF: Run-Time Library Version Numbers
287332
** KEYWORDS: sqlite3_version, sqlite3_sourceid
288333
**
@@ -925,18 +970,20 @@
925970
**
926971
** These integer constants are opcodes for the xFileControl method
927972
** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
928973
** interface.
929974
**
975
+** <ul>
976
+** <li>[[SQLITE_FCNTL_LOCKSTATE]]
930977
** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This
931978
** opcode causes the xFileControl method to write the current state of
932979
** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
933980
** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
934981
** into an integer that the pArg argument points to. This capability
935
-** is used during testing and only needs to be supported when SQLITE_TEST
936
-** is defined.
937
-** <ul>
982
+** is used during testing and is only available when the SQLITE_TEST
983
+** compile-time option is used.
984
+**
938985
** <li>[[SQLITE_FCNTL_SIZE_HINT]]
939986
** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
940987
** layer a hint of how large the database file will grow to be during the
941988
** current transaction. This hint is not guaranteed to be accurate but it
942989
** is often close. The underlying VFS might choose to preallocate database
@@ -1057,11 +1104,13 @@
10571104
** the error message if the pragma fails. ^If the
10581105
** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal
10591106
** [PRAGMA] processing continues. ^If the [SQLITE_FCNTL_PRAGMA]
10601107
** file control returns [SQLITE_OK], then the parser assumes that the
10611108
** VFS has handled the PRAGMA itself and the parser generates a no-op
1062
-** prepared statement. ^If the [SQLITE_FCNTL_PRAGMA] file control returns
1109
+** prepared statement if result string is NULL, or that returns a copy
1110
+** of the result string if the string is non-NULL.
1111
+** ^If the [SQLITE_FCNTL_PRAGMA] file control returns
10631112
** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means
10641113
** that the VFS encountered an error while handling the [PRAGMA] and the
10651114
** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA]
10661115
** file control occurs at the beginning of pragma statement analysis and so
10671116
** it is able to override built-in [PRAGMA] statements.
@@ -1115,10 +1164,17 @@
11151164
** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This
11161165
** opcode causes the xFileControl method to swap the file handle with the one
11171166
** pointed to by the pArg argument. This capability is used during testing
11181167
** and only needs to be supported when SQLITE_TEST is defined.
11191168
**
1169
+** <li>[[SQLITE_FCNTL_WAL_BLOCK]]
1170
+** The [SQLITE_FCNTL_WAL_BLOCK] is a signal to the VFS layer that it might
1171
+** be advantageous to block on the next WAL lock if the lock is not immediately
1172
+** available. The WAL subsystem issues this signal during rare
1173
+** circumstances in order to fix a problem with priority inversion.
1174
+** Applications should <em>not</em> use this file-control.
1175
+**
11201176
** </ul>
11211177
*/
11221178
#define SQLITE_FCNTL_LOCKSTATE 1
11231179
#define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
11241180
#define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
@@ -1139,10 +1195,11 @@
11391195
#define SQLITE_FCNTL_TRACE 19
11401196
#define SQLITE_FCNTL_HAS_MOVED 20
11411197
#define SQLITE_FCNTL_SYNC 21
11421198
#define SQLITE_FCNTL_COMMIT_PHASETWO 22
11431199
#define SQLITE_FCNTL_WIN32_SET_HANDLE 23
1200
+#define SQLITE_FCNTL_WAL_BLOCK 24
11441201
11451202
/* deprecated names */
11461203
#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
11471204
#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
11481205
#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -1705,11 +1762,11 @@
17051762
** disabled, the following SQLite interfaces become non-operational:
17061763
** <ul>
17071764
** <li> [sqlite3_memory_used()]
17081765
** <li> [sqlite3_memory_highwater()]
17091766
** <li> [sqlite3_soft_heap_limit64()]
1710
-** <li> [sqlite3_status()]
1767
+** <li> [sqlite3_status64()]
17111768
** </ul>)^
17121769
** ^Memory allocation statistics are enabled by default unless SQLite is
17131770
** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
17141771
** allocation statistics are disabled by default.
17151772
** </dd>
@@ -1916,11 +1973,10 @@
19161973
** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
19171974
** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is
19181975
** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro
19191976
** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
19201977
** that specifies the maximum size of the created heap.
1921
-** </dl>
19221978
**
19231979
** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
19241980
** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
19251981
** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
19261982
** is a pointer to an integer and writes into that integer the number of extra
@@ -3163,15 +3219,17 @@
31633219
31643220
31653221
/*
31663222
** CAPI3REF: Error Codes And Messages
31673223
**
3168
-** ^The sqlite3_errcode() interface returns the numeric [result code] or
3169
-** [extended result code] for the most recent failed sqlite3_* API call
3170
-** associated with a [database connection]. If a prior API call failed
3171
-** but the most recent API call succeeded, the return value from
3172
-** sqlite3_errcode() is undefined. ^The sqlite3_extended_errcode()
3224
+** ^If the most recent sqlite3_* API call associated with
3225
+** [database connection] D failed, then the sqlite3_errcode(D) interface
3226
+** returns the numeric [result code] or [extended result code] for that
3227
+** API call.
3228
+** If the most recent API call was successful,
3229
+** then the return value from sqlite3_errcode() is undefined.
3230
+** ^The sqlite3_extended_errcode()
31733231
** interface is the same except that it always returns the
31743232
** [extended result code] even when extended result codes are
31753233
** disabled.
31763234
**
31773235
** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
@@ -3356,20 +3414,18 @@
33563414
** The second argument, "zSql", is the statement to be compiled, encoded
33573415
** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2()
33583416
** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2()
33593417
** use UTF-16.
33603418
**
3361
-** ^If the nByte argument is less than zero, then zSql is read up to the
3362
-** first zero terminator. ^If nByte is non-negative, then it is the maximum
3363
-** number of bytes read from zSql. ^When nByte is non-negative, the
3364
-** zSql string ends at either the first '\000' or '\u0000' character or
3365
-** the nByte-th byte, whichever comes first. If the caller knows
3366
-** that the supplied string is nul-terminated, then there is a small
3367
-** performance advantage to be gained by passing an nByte parameter that
3368
-** is equal to the number of bytes in the input string <i>including</i>
3369
-** the nul-terminator bytes as this saves SQLite from having to
3370
-** make a copy of the input string.
3419
+** ^If the nByte argument is negative, then zSql is read up to the
3420
+** first zero terminator. ^If nByte is positive, then it is the
3421
+** number of bytes read from zSql. ^If nByte is zero, then no prepared
3422
+** statement is generated.
3423
+** If the caller knows that the supplied string is nul-terminated, then
3424
+** there is a small performance advantage to passing an nByte parameter that
3425
+** is the number of bytes in the input string <i>including</i>
3426
+** the nul-terminator.
33713427
**
33723428
** ^If pzTail is not NULL then *pzTail is made to point to the first byte
33733429
** past the end of the first SQL statement in zSql. These routines only
33743430
** compile the first statement in zSql, so *pzTail is left pointing to
33753431
** what remains uncompiled.
@@ -4394,12 +4450,12 @@
43944450
** DEPRECATED
43954451
**
43964452
** These functions are [deprecated]. In order to maintain
43974453
** backwards compatibility with older code, these functions continue
43984454
** to be supported. However, new applications should avoid
4399
-** the use of these functions. To help encourage people to avoid
4400
-** using these functions, we are not going to tell you what they do.
4455
+** the use of these functions. To encourage programmers to avoid
4456
+** these functions, we will not explain what they do.
44014457
*/
44024458
#ifndef SQLITE_OMIT_DEPRECATED
44034459
SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
44044460
SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
44054461
SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
@@ -5783,11 +5839,11 @@
57835839
** is delivered up to the client application, the string will be automatically
57845840
** freed by sqlite3_free() and the zErrMsg field will be zeroed.
57855841
*/
57865842
struct sqlite3_vtab {
57875843
const sqlite3_module *pModule; /* The module for this virtual table */
5788
- int nRef; /* NO LONGER USED */
5844
+ int nRef; /* Number of open cursors */
57895845
char *zErrMsg; /* Error message from sqlite3_mprintf() */
57905846
/* Virtual table implementations will typically add additional fields */
57915847
};
57925848
57935849
/*
@@ -6461,11 +6517,11 @@
64616517
#define SQLITE_TESTCTRL_LAST 25
64626518
64636519
/*
64646520
** CAPI3REF: SQLite Runtime Status
64656521
**
6466
-** ^This interface is used to retrieve runtime status information
6522
+** ^These interfaces are used to retrieve runtime status information
64676523
** about the performance of SQLite, and optionally to reset various
64686524
** highwater marks. ^The first argument is an integer code for
64696525
** the specific parameter to measure. ^(Recognized integer codes
64706526
** are of the form [status parameters | SQLITE_STATUS_...].)^
64716527
** ^The current value of the parameter is returned into *pCurrent.
@@ -6475,23 +6531,26 @@
64756531
** value. For those parameters
64766532
** nothing is written into *pHighwater and the resetFlag is ignored.)^
64776533
** ^(Other parameters record only the highwater mark and not the current
64786534
** value. For these latter parameters nothing is written into *pCurrent.)^
64796535
**
6480
-** ^The sqlite3_status() routine returns SQLITE_OK on success and a
6481
-** non-zero [error code] on failure.
6536
+** ^The sqlite3_status() and sqlite3_status64() routines return
6537
+** SQLITE_OK on success and a non-zero [error code] on failure.
64826538
**
6483
-** This routine is threadsafe but is not atomic. This routine can be
6484
-** called while other threads are running the same or different SQLite
6485
-** interfaces. However the values returned in *pCurrent and
6486
-** *pHighwater reflect the status of SQLite at different points in time
6487
-** and it is possible that another thread might change the parameter
6488
-** in between the times when *pCurrent and *pHighwater are written.
6539
+** If either the current value or the highwater mark is too large to
6540
+** be represented by a 32-bit integer, then the values returned by
6541
+** sqlite3_status() are undefined.
64896542
**
64906543
** See also: [sqlite3_db_status()]
64916544
*/
64926545
SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
6546
+SQLITE_API int sqlite3_status64(
6547
+ int op,
6548
+ sqlite3_int64 *pCurrent,
6549
+ sqlite3_int64 *pHighwater,
6550
+ int resetFlag
6551
+);
64936552
64946553
64956554
/*
64966555
** CAPI3REF: Status Parameters
64976556
** KEYWORDS: {status parameters}
@@ -7157,24 +7216,24 @@
71577216
**
71587217
** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
71597218
** is not a permanent error and does not affect the return value of
71607219
** sqlite3_backup_finish().
71617220
**
7162
-** [[sqlite3_backup__remaining()]] [[sqlite3_backup_pagecount()]]
7221
+** [[sqlite3_backup_remaining()]] [[sqlite3_backup_pagecount()]]
71637222
** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b>
71647223
**
7165
-** ^Each call to sqlite3_backup_step() sets two values inside
7166
-** the [sqlite3_backup] object: the number of pages still to be backed
7167
-** up and the total number of pages in the source database file.
7168
-** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces
7169
-** retrieve these two values, respectively.
7170
-**
7171
-** ^The values returned by these functions are only updated by
7172
-** sqlite3_backup_step(). ^If the source database is modified during a backup
7173
-** operation, then the values are not updated to account for any extra
7174
-** pages that need to be updated or the size of the source database file
7175
-** changing.
7224
+** ^The sqlite3_backup_remaining() routine returns the number of pages still
7225
+** to be backed up at the conclusion of the most recent sqlite3_backup_step().
7226
+** ^The sqlite3_backup_pagecount() routine returns the total number of pages
7227
+** in the source database at the conclusion of the most recent
7228
+** sqlite3_backup_step().
7229
+** ^(The values returned by these functions are only updated by
7230
+** sqlite3_backup_step(). If the source database is modified in a way that
7231
+** changes the size of the source database or the number of pages remaining,
7232
+** those changes are not reflected in the output of sqlite3_backup_pagecount()
7233
+** and sqlite3_backup_remaining() until after the next
7234
+** sqlite3_backup_step().)^
71767235
**
71777236
** <b>Concurrent Usage of Database Handles</b>
71787237
**
71797238
** ^The source [database connection] may be used by the application for other
71807239
** purposes while a backup operation is underway or being initialized.
@@ -8018,19 +8077,21 @@
80188077
#ifndef SQLITE_MAX_FUNCTION_ARG
80198078
# define SQLITE_MAX_FUNCTION_ARG 127
80208079
#endif
80218080
80228081
/*
8023
-** The maximum number of in-memory pages to use for the main database
8024
-** table and for temporary tables. The SQLITE_DEFAULT_CACHE_SIZE
8082
+** The suggested maximum number of in-memory pages to use for
8083
+** the main database table and for temporary tables.
8084
+**
8085
+** IMPLEMENTATION-OF: R-31093-59126 The default suggested cache size
8086
+** is 2000 pages.
8087
+** IMPLEMENTATION-OF: R-48205-43578 The default suggested cache size can be
8088
+** altered using the SQLITE_DEFAULT_CACHE_SIZE compile-time options.
80258089
*/
80268090
#ifndef SQLITE_DEFAULT_CACHE_SIZE
80278091
# define SQLITE_DEFAULT_CACHE_SIZE 2000
80288092
#endif
8029
-#ifndef SQLITE_DEFAULT_TEMP_CACHE_SIZE
8030
-# define SQLITE_DEFAULT_TEMP_CACHE_SIZE 500
8031
-#endif
80328093
80338094
/*
80348095
** The default number of frames to accumulate in the log file before
80358096
** checkpointing the database in WAL mode.
80368097
*/
@@ -8870,10 +8931,24 @@
88708931
**
88718932
** 0.5 -> -10 0.1 -> -33 0.0625 -> -40
88728933
*/
88738934
typedef INT16_TYPE LogEst;
88748935
8936
+/*
8937
+** Set the SQLITE_PTRSIZE macro to the number of bytes in a pointer
8938
+*/
8939
+#ifndef SQLITE_PTRSIZE
8940
+# if defined(__SIZEOF_POINTER__)
8941
+# define SQLITE_PTRSIZE __SIZEOF_POINTER__
8942
+# elif defined(i386) || defined(__i386__) || defined(_M_IX86) || \
8943
+ defined(_M_ARM) || defined(__arm__) || defined(__x86)
8944
+# define SQLITE_PTRSIZE 4
8945
+# else
8946
+# define SQLITE_PTRSIZE 8
8947
+# endif
8948
+#endif
8949
+
88758950
/*
88768951
** Macros to determine whether the machine is big or little endian,
88778952
** and whether or not that determination is run-time or compile-time.
88788953
**
88798954
** For best performance, an attempt is made to guess at the byte-order
@@ -9320,12 +9395,22 @@
93209395
#define BTREE_DATA_VERSION 15 /* A virtual meta-value */
93219396
93229397
/*
93239398
** Values that may be OR'd together to form the second argument of an
93249399
** sqlite3BtreeCursorHints() call.
9400
+**
9401
+** The BTREE_BULKLOAD flag is set on index cursors when the index is going
9402
+** to be filled with content that is already in sorted order.
9403
+**
9404
+** The BTREE_SEEK_EQ flag is set on cursors that will get OP_SeekGE or
9405
+** OP_SeekLE opcodes for a range search, but where the range of entries
9406
+** selected will all have the same key. In other words, the cursor will
9407
+** be used only for equality key searches.
9408
+**
93259409
*/
9326
-#define BTREE_BULKLOAD 0x00000001
9410
+#define BTREE_BULKLOAD 0x00000001 /* Used to full index in sorted order */
9411
+#define BTREE_SEEK_EQ 0x00000002 /* EQ seeks only - no range seeks */
93279412
93289413
SQLITE_PRIVATE int sqlite3BtreeCursor(
93299414
Btree*, /* BTree containing table to open */
93309415
int iTable, /* Index of root page */
93319416
int wrFlag, /* 1 for writing. 0 for read-only */
@@ -9367,10 +9452,13 @@
93679452
SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
93689453
SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *);
93699454
SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *);
93709455
SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion);
93719456
SQLITE_PRIVATE void sqlite3BtreeCursorHints(BtCursor *, unsigned int mask);
9457
+#ifdef SQLITE_DEBUG
9458
+SQLITE_PRIVATE int sqlite3BtreeCursorHasHint(BtCursor*, unsigned int mask);
9459
+#endif
93729460
SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *pBt);
93739461
SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void);
93749462
93759463
#ifndef NDEBUG
93769464
SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*);
@@ -9733,27 +9821,29 @@
97339821
#define OP_FkCounter 134 /* synopsis: fkctr[P1]+=P2 */
97349822
#define OP_FkIfZero 135 /* synopsis: if fkctr[P1]==0 goto P2 */
97359823
#define OP_MemMax 136 /* synopsis: r[P1]=max(r[P1],r[P2]) */
97369824
#define OP_IfPos 137 /* synopsis: if r[P1]>0 goto P2 */
97379825
#define OP_IfNeg 138 /* synopsis: r[P1]+=P3, if r[P1]<0 goto P2 */
9738
-#define OP_IfZero 139 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */
9739
-#define OP_AggFinal 140 /* synopsis: accum=r[P1] N=P2 */
9740
-#define OP_IncrVacuum 141
9741
-#define OP_Expire 142
9742
-#define OP_TableLock 143 /* synopsis: iDb=P1 root=P2 write=P3 */
9743
-#define OP_VBegin 144
9744
-#define OP_VCreate 145
9745
-#define OP_VDestroy 146
9746
-#define OP_VOpen 147
9747
-#define OP_VColumn 148 /* synopsis: r[P3]=vcolumn(P2) */
9748
-#define OP_VNext 149
9749
-#define OP_VRename 150
9750
-#define OP_Pagecount 151
9751
-#define OP_MaxPgcnt 152
9752
-#define OP_Init 153 /* synopsis: Start at P2 */
9753
-#define OP_Noop 154
9754
-#define OP_Explain 155
9826
+#define OP_IfNotZero 139 /* synopsis: if r[P1]!=0 then r[P1]+=P3, goto P2 */
9827
+#define OP_DecrJumpZero 140 /* synopsis: if (--r[P1])==0 goto P2 */
9828
+#define OP_JumpZeroIncr 141 /* synopsis: if (r[P1]++)==0 ) goto P2 */
9829
+#define OP_AggFinal 142 /* synopsis: accum=r[P1] N=P2 */
9830
+#define OP_IncrVacuum 143
9831
+#define OP_Expire 144
9832
+#define OP_TableLock 145 /* synopsis: iDb=P1 root=P2 write=P3 */
9833
+#define OP_VBegin 146
9834
+#define OP_VCreate 147
9835
+#define OP_VDestroy 148
9836
+#define OP_VOpen 149
9837
+#define OP_VColumn 150 /* synopsis: r[P3]=vcolumn(P2) */
9838
+#define OP_VNext 151
9839
+#define OP_VRename 152
9840
+#define OP_Pagecount 153
9841
+#define OP_MaxPgcnt 154
9842
+#define OP_Init 155 /* synopsis: Start at P2 */
9843
+#define OP_Noop 156
9844
+#define OP_Explain 157
97559845
97569846
97579847
/* Properties such as "out2" or "jump" that are specified in
97589848
** comments following the "case" for each opcode in the vdbe.c
97599849
** are encoded into bitvectors as follows:
@@ -9781,13 +9871,13 @@
97819871
/* 96 */ 0x24, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,\
97829872
/* 104 */ 0x00, 0x01, 0x01, 0x01, 0x01, 0x08, 0x08, 0x00,\
97839873
/* 112 */ 0x02, 0x01, 0x01, 0x01, 0x01, 0x02, 0x00, 0x00,\
97849874
/* 120 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
97859875
/* 128 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x02, 0x00, 0x01,\
9786
-/* 136 */ 0x08, 0x05, 0x05, 0x05, 0x00, 0x01, 0x00, 0x00,\
9787
-/* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02,\
9788
-/* 152 */ 0x02, 0x01, 0x00, 0x00,}
9876
+/* 136 */ 0x08, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00, 0x01,\
9877
+/* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,\
9878
+/* 152 */ 0x00, 0x02, 0x02, 0x01, 0x00, 0x00,}
97899879
97909880
/************** End of opcodes.h *********************************************/
97919881
/************** Continuing where we left off in vdbe.h ***********************/
97929882
97939883
/*
@@ -10865,10 +10955,11 @@
1086510955
} init;
1086610956
int nVdbeActive; /* Number of VDBEs currently running */
1086710957
int nVdbeRead; /* Number of active VDBEs that read or write */
1086810958
int nVdbeWrite; /* Number of active VDBEs that read and write */
1086910959
int nVdbeExec; /* Number of nested calls to VdbeExec() */
10960
+ int nVDestroy; /* Number of active OP_VDestroy operations */
1087010961
int nExtension; /* Number of loaded extensions */
1087110962
void **aExtension; /* Array of shared library handles */
1087210963
void (*xTrace)(void*,const char*); /* Trace function */
1087310964
void *pTraceArg; /* Argument to the trace function */
1087410965
void (*xProfile)(void*,const char*,u64); /* Profiling function */
@@ -12022,11 +12113,11 @@
1202212113
#define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
1202312114
#define WHERE_DUPLICATES_OK 0x0008 /* Ok to return a row more than once */
1202412115
#define WHERE_OMIT_OPEN_CLOSE 0x0010 /* Table cursors are already open */
1202512116
#define WHERE_FORCE_TABLE 0x0020 /* Do not use an index-only search */
1202612117
#define WHERE_ONETABLE_ONLY 0x0040 /* Only code the 1st table in pTabList */
12027
- /* 0x0080 // not currently used */
12118
+#define WHERE_NO_AUTOINDEX 0x0080 /* Disallow automatic indexes */
1202812119
#define WHERE_GROUPBY 0x0100 /* pOrderBy is really a GROUP BY */
1202912120
#define WHERE_DISTINCTBY 0x0200 /* pOrderby is really a DISTINCT clause */
1203012121
#define WHERE_WANT_DISTINCT 0x0400 /* All output needs to be distinct */
1203112122
#define WHERE_SORTBYGROUP 0x0800 /* Support sqlite3WhereIsSorted() */
1203212123
#define WHERE_REOPEN_IDX 0x1000 /* Try to use OP_ReopenIdx */
@@ -12459,11 +12550,12 @@
1245912550
#define OPFLAG_APPEND 0x08 /* This is likely to be an append */
1246012551
#define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */
1246112552
#define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */
1246212553
#define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */
1246312554
#define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */
12464
-#define OPFLAG_P2ISREG 0x02 /* P2 to OP_Open** is a register number */
12555
+#define OPFLAG_SEEKEQ 0x02 /* OP_Open** cursor uses EQ seek only */
12556
+#define OPFLAG_P2ISREG 0x04 /* P2 to OP_Open** is a register number */
1246512557
#define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */
1246612558
1246712559
/*
1246812560
* Each trigger present in the database schema is stored as an instance of
1246912561
* struct Trigger.
@@ -12863,14 +12955,19 @@
1286312955
SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int);
1286412956
SQLITE_PRIVATE int sqlite3MutexInit(void);
1286512957
SQLITE_PRIVATE int sqlite3MutexEnd(void);
1286612958
#endif
1286712959
12868
-SQLITE_PRIVATE int sqlite3StatusValue(int);
12869
-SQLITE_PRIVATE void sqlite3StatusAdd(int, int);
12960
+SQLITE_PRIVATE sqlite3_int64 sqlite3StatusValue(int);
12961
+SQLITE_PRIVATE void sqlite3StatusUp(int, int);
12962
+SQLITE_PRIVATE void sqlite3StatusDown(int, int);
1287012963
SQLITE_PRIVATE void sqlite3StatusSet(int, int);
1287112964
12965
+/* Access to mutexes used by sqlite3_status() */
12966
+SQLITE_PRIVATE sqlite3_mutex *sqlite3Pcache1Mutex(void);
12967
+SQLITE_PRIVATE sqlite3_mutex *sqlite3MallocMutex(void);
12968
+
1287212969
#ifndef SQLITE_OMIT_FLOATING_POINT
1287312970
SQLITE_PRIVATE int sqlite3IsNaN(double);
1287412971
#else
1287512972
# define sqlite3IsNaN(X) 0
1287612973
#endif
@@ -13246,11 +13343,11 @@
1324613343
SQLITE_PRIVATE const char *sqlite3ErrStr(int);
1324713344
SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
1324813345
SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int);
1324913346
SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName);
1325013347
SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr);
13251
-SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr*, const Token*);
13348
+SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr*, const Token*, int);
1325213349
SQLITE_PRIVATE Expr *sqlite3ExprAddCollateString(Parse*,Expr*,const char*);
1325313350
SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr*);
1325413351
SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *);
1325513352
SQLITE_PRIVATE int sqlite3CheckObjectName(Parse *, const char *);
1325613353
SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int);
@@ -14633,18 +14730,10 @@
1463314730
** An instance of the virtual machine. This structure contains the complete
1463414731
** state of the virtual machine.
1463514732
**
1463614733
** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()
1463714734
** is really a pointer to an instance of this structure.
14638
-**
14639
-** The Vdbe.inVtabMethod variable is set to non-zero for the duration of
14640
-** any virtual table method invocations made by the vdbe program. It is
14641
-** set to 2 for xDestroy method calls and 1 for all other methods. This
14642
-** variable is used for two purposes: to allow xDestroy methods to execute
14643
-** "DROP TABLE" statements and to prevent some nasty side effects of
14644
-** malloc failure when SQLite is invoked recursively by a virtual table
14645
-** method function.
1464614735
*/
1464714736
struct Vdbe {
1464814737
sqlite3 *db; /* The database connection that owns this statement */
1464914738
Op *aOp; /* Space to hold the virtual machine's program */
1465014739
Mem *aMem; /* The memory locations */
@@ -14671,11 +14760,10 @@
1467114760
#endif
1467214761
u16 nResColumn; /* Number of columns in one row of the result set */
1467314762
u8 errorAction; /* Recovery action to do in case of an error */
1467414763
u8 minWriteFileFormat; /* Minimum file format for writable database files */
1467514764
bft explain:2; /* True if EXPLAIN present on SQL command */
14676
- bft inVtabMethod:2; /* See comments above */
1467714765
bft changeCntOn:1; /* True to update the change-counter */
1467814766
bft expired:1; /* True if the VM needs to be recompiled */
1467914767
bft runOnlyOnce:1; /* Automatically expire on reset */
1468014768
bft usesStmtJournal:1; /* True if uses a statement journal */
1468114769
bft readOnly:1; /* True for statements that do not write */
@@ -14831,13 +14919,35 @@
1483114919
/*
1483214920
** Variables in which to record status information.
1483314921
*/
1483414922
typedef struct sqlite3StatType sqlite3StatType;
1483514923
static SQLITE_WSD struct sqlite3StatType {
14836
- int nowValue[10]; /* Current value */
14837
- int mxValue[10]; /* Maximum value */
14924
+#if SQLITE_PTRSIZE>4
14925
+ sqlite3_int64 nowValue[10]; /* Current value */
14926
+ sqlite3_int64 mxValue[10]; /* Maximum value */
14927
+#else
14928
+ u32 nowValue[10]; /* Current value */
14929
+ u32 mxValue[10]; /* Maximum value */
14930
+#endif
1483814931
} sqlite3Stat = { {0,}, {0,} };
14932
+
14933
+/*
14934
+** Elements of sqlite3Stat[] are protected by either the memory allocator
14935
+** mutex, or by the pcache1 mutex. The following array determines which.
14936
+*/
14937
+static const char statMutex[] = {
14938
+ 0, /* SQLITE_STATUS_MEMORY_USED */
14939
+ 1, /* SQLITE_STATUS_PAGECACHE_USED */
14940
+ 1, /* SQLITE_STATUS_PAGECACHE_OVERFLOW */
14941
+ 0, /* SQLITE_STATUS_SCRATCH_USED */
14942
+ 0, /* SQLITE_STATUS_SCRATCH_OVERFLOW */
14943
+ 0, /* SQLITE_STATUS_MALLOC_SIZE */
14944
+ 0, /* SQLITE_STATUS_PARSER_STACK */
14945
+ 1, /* SQLITE_STATUS_PAGECACHE_SIZE */
14946
+ 0, /* SQLITE_STATUS_SCRATCH_SIZE */
14947
+ 0, /* SQLITE_STATUS_MALLOC_COUNT */
14948
+};
1483914949
1484014950
1484114951
/* The "wsdStat" macro will resolve to the status information
1484214952
** state vector. If writable static data is unsupported on the target,
1484314953
** we have to locate the state vector at run-time. In the more common
@@ -14851,64 +14961,110 @@
1485114961
# define wsdStatInit
1485214962
# define wsdStat sqlite3Stat
1485314963
#endif
1485414964
1485514965
/*
14856
-** Return the current value of a status parameter.
14966
+** Return the current value of a status parameter. The caller must
14967
+** be holding the appropriate mutex.
1485714968
*/
14858
-SQLITE_PRIVATE int sqlite3StatusValue(int op){
14969
+SQLITE_PRIVATE sqlite3_int64 sqlite3StatusValue(int op){
1485914970
wsdStatInit;
1486014971
assert( op>=0 && op<ArraySize(wsdStat.nowValue) );
14972
+ assert( op>=0 && op<ArraySize(statMutex) );
14973
+ assert( sqlite3_mutex_held(statMutex[op] ? sqlite3Pcache1Mutex()
14974
+ : sqlite3MallocMutex()) );
1486114975
return wsdStat.nowValue[op];
1486214976
}
1486314977
1486414978
/*
14865
-** Add N to the value of a status record. It is assumed that the
14866
-** caller holds appropriate locks.
14979
+** Add N to the value of a status record. The caller must hold the
14980
+** appropriate mutex. (Locking is checked by assert()).
14981
+**
14982
+** The StatusUp() routine can accept positive or negative values for N.
14983
+** The value of N is added to the current status value and the high-water
14984
+** mark is adjusted if necessary.
14985
+**
14986
+** The StatusDown() routine lowers the current value by N. The highwater
14987
+** mark is unchanged. N must be non-negative for StatusDown().
1486714988
*/
14868
-SQLITE_PRIVATE void sqlite3StatusAdd(int op, int N){
14989
+SQLITE_PRIVATE void sqlite3StatusUp(int op, int N){
1486914990
wsdStatInit;
1487014991
assert( op>=0 && op<ArraySize(wsdStat.nowValue) );
14992
+ assert( op>=0 && op<ArraySize(statMutex) );
14993
+ assert( sqlite3_mutex_held(statMutex[op] ? sqlite3Pcache1Mutex()
14994
+ : sqlite3MallocMutex()) );
1487114995
wsdStat.nowValue[op] += N;
1487214996
if( wsdStat.nowValue[op]>wsdStat.mxValue[op] ){
1487314997
wsdStat.mxValue[op] = wsdStat.nowValue[op];
1487414998
}
1487514999
}
15000
+SQLITE_PRIVATE void sqlite3StatusDown(int op, int N){
15001
+ wsdStatInit;
15002
+ assert( N>=0 );
15003
+ assert( op>=0 && op<ArraySize(statMutex) );
15004
+ assert( sqlite3_mutex_held(statMutex[op] ? sqlite3Pcache1Mutex()
15005
+ : sqlite3MallocMutex()) );
15006
+ assert( op>=0 && op<ArraySize(wsdStat.nowValue) );
15007
+ wsdStat.nowValue[op] -= N;
15008
+}
1487615009
1487715010
/*
14878
-** Set the value of a status to X.
15011
+** Set the value of a status to X. The highwater mark is adjusted if
15012
+** necessary. The caller must hold the appropriate mutex.
1487915013
*/
1488015014
SQLITE_PRIVATE void sqlite3StatusSet(int op, int X){
1488115015
wsdStatInit;
1488215016
assert( op>=0 && op<ArraySize(wsdStat.nowValue) );
15017
+ assert( op>=0 && op<ArraySize(statMutex) );
15018
+ assert( sqlite3_mutex_held(statMutex[op] ? sqlite3Pcache1Mutex()
15019
+ : sqlite3MallocMutex()) );
1488315020
wsdStat.nowValue[op] = X;
1488415021
if( wsdStat.nowValue[op]>wsdStat.mxValue[op] ){
1488515022
wsdStat.mxValue[op] = wsdStat.nowValue[op];
1488615023
}
1488715024
}
1488815025
1488915026
/*
1489015027
** Query status information.
14891
-**
14892
-** This implementation assumes that reading or writing an aligned
14893
-** 32-bit integer is an atomic operation. If that assumption is not true,
14894
-** then this routine is not threadsafe.
1489515028
*/
14896
-SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){
15029
+SQLITE_API int sqlite3_status64(
15030
+ int op,
15031
+ sqlite3_int64 *pCurrent,
15032
+ sqlite3_int64 *pHighwater,
15033
+ int resetFlag
15034
+){
15035
+ sqlite3_mutex *pMutex;
1489715036
wsdStatInit;
1489815037
if( op<0 || op>=ArraySize(wsdStat.nowValue) ){
1489915038
return SQLITE_MISUSE_BKPT;
1490015039
}
1490115040
#ifdef SQLITE_ENABLE_API_ARMOR
1490215041
if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT;
1490315042
#endif
15043
+ pMutex = statMutex[op] ? sqlite3Pcache1Mutex() : sqlite3MallocMutex();
15044
+ sqlite3_mutex_enter(pMutex);
1490415045
*pCurrent = wsdStat.nowValue[op];
1490515046
*pHighwater = wsdStat.mxValue[op];
1490615047
if( resetFlag ){
1490715048
wsdStat.mxValue[op] = wsdStat.nowValue[op];
1490815049
}
15050
+ sqlite3_mutex_leave(pMutex);
15051
+ (void)pMutex; /* Prevent warning when SQLITE_THREADSAFE=0 */
1490915052
return SQLITE_OK;
15053
+}
15054
+SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){
15055
+ sqlite3_int64 iCur, iHwtr;
15056
+ int rc;
15057
+#ifdef SQLITE_ENABLE_API_ARMOR
15058
+ if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT;
15059
+#endif
15060
+ rc = sqlite3_status64(op, &iCur, &iHwtr, resetFlag);
15061
+ if( rc==0 ){
15062
+ *pCurrent = (int)iCur;
15063
+ *pHighwater = (int)iHwtr;
15064
+ }
15065
+ return rc;
1491015066
}
1491115067
1491215068
/*
1491315069
** Query status information for a single database connection
1491415070
*/
@@ -20358,10 +20514,17 @@
2035820514
*/
2035920515
int nearlyFull;
2036020516
} mem0 = { 0, 0, 0, 0, 0, 0, 0, 0 };
2036120517
2036220518
#define mem0 GLOBAL(struct Mem0Global, mem0)
20519
+
20520
+/*
20521
+** Return the memory allocator mutex. sqlite3_status() needs it.
20522
+*/
20523
+SQLITE_PRIVATE sqlite3_mutex *sqlite3MallocMutex(void){
20524
+ return mem0.mutex;
20525
+}
2036320526
2036420527
/*
2036520528
** This routine runs when the memory allocator sees that the
2036620529
** total memory allocation is about to exceed the soft heap
2036720530
** limit.
@@ -20381,11 +20544,11 @@
2038120544
static int sqlite3MemoryAlarm(
2038220545
void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
2038320546
void *pArg,
2038420547
sqlite3_int64 iThreshold
2038520548
){
20386
- int nUsed;
20549
+ sqlite3_int64 nUsed;
2038720550
sqlite3_mutex_enter(mem0.mutex);
2038820551
mem0.alarmCallback = xCallback;
2038920552
mem0.alarmArg = pArg;
2039020553
mem0.alarmThreshold = iThreshold;
2039120554
nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
@@ -20550,11 +20713,11 @@
2055020713
void *p;
2055120714
assert( sqlite3_mutex_held(mem0.mutex) );
2055220715
nFull = sqlite3GlobalConfig.m.xRoundup(n);
2055320716
sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, n);
2055420717
if( mem0.alarmCallback!=0 ){
20555
- int nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
20718
+ sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
2055620719
if( nUsed >= mem0.alarmThreshold - nFull ){
2055720720
mem0.nearlyFull = 1;
2055820721
sqlite3MallocAlarm(nFull);
2055920722
}else{
2056020723
mem0.nearlyFull = 0;
@@ -20567,12 +20730,12 @@
2056720730
p = sqlite3GlobalConfig.m.xMalloc(nFull);
2056820731
}
2056920732
#endif
2057020733
if( p ){
2057120734
nFull = sqlite3MallocSize(p);
20572
- sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nFull);
20573
- sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, 1);
20735
+ sqlite3StatusUp(SQLITE_STATUS_MEMORY_USED, nFull);
20736
+ sqlite3StatusUp(SQLITE_STATUS_MALLOC_COUNT, 1);
2057420737
}
2057520738
*pp = p;
2057620739
return nFull;
2057720740
}
2057820741
@@ -20645,18 +20808,18 @@
2064520808
sqlite3StatusSet(SQLITE_STATUS_SCRATCH_SIZE, n);
2064620809
if( mem0.nScratchFree && sqlite3GlobalConfig.szScratch>=n ){
2064720810
p = mem0.pScratchFree;
2064820811
mem0.pScratchFree = mem0.pScratchFree->pNext;
2064920812
mem0.nScratchFree--;
20650
- sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, 1);
20813
+ sqlite3StatusUp(SQLITE_STATUS_SCRATCH_USED, 1);
2065120814
sqlite3_mutex_leave(mem0.mutex);
2065220815
}else{
2065320816
sqlite3_mutex_leave(mem0.mutex);
2065420817
p = sqlite3Malloc(n);
2065520818
if( sqlite3GlobalConfig.bMemstat && p ){
2065620819
sqlite3_mutex_enter(mem0.mutex);
20657
- sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, sqlite3MallocSize(p));
20820
+ sqlite3StatusUp(SQLITE_STATUS_SCRATCH_OVERFLOW, sqlite3MallocSize(p));
2065820821
sqlite3_mutex_leave(mem0.mutex);
2065920822
}
2066020823
sqlite3MemdebugSetType(p, MEMTYPE_SCRATCH);
2066120824
}
2066220825
assert( sqlite3_mutex_notheld(mem0.mutex) );
@@ -20693,23 +20856,23 @@
2069320856
sqlite3_mutex_enter(mem0.mutex);
2069420857
pSlot->pNext = mem0.pScratchFree;
2069520858
mem0.pScratchFree = pSlot;
2069620859
mem0.nScratchFree++;
2069720860
assert( mem0.nScratchFree <= (u32)sqlite3GlobalConfig.nScratch );
20698
- sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, -1);
20861
+ sqlite3StatusDown(SQLITE_STATUS_SCRATCH_USED, 1);
2069920862
sqlite3_mutex_leave(mem0.mutex);
2070020863
}else{
2070120864
/* Release memory back to the heap */
2070220865
assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) );
20703
- assert( sqlite3MemdebugNoType(p, ~MEMTYPE_SCRATCH) );
20866
+ assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_SCRATCH) );
2070420867
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
2070520868
if( sqlite3GlobalConfig.bMemstat ){
2070620869
int iSize = sqlite3MallocSize(p);
2070720870
sqlite3_mutex_enter(mem0.mutex);
20708
- sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, -iSize);
20709
- sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -iSize);
20710
- sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, -1);
20871
+ sqlite3StatusDown(SQLITE_STATUS_SCRATCH_OVERFLOW, iSize);
20872
+ sqlite3StatusDown(SQLITE_STATUS_MEMORY_USED, iSize);
20873
+ sqlite3StatusDown(SQLITE_STATUS_MALLOC_COUNT, 1);
2071120874
sqlite3GlobalConfig.m.xFree(p);
2071220875
sqlite3_mutex_leave(mem0.mutex);
2071320876
}else{
2071420877
sqlite3GlobalConfig.m.xFree(p);
2071520878
}
@@ -20736,26 +20899,26 @@
2073620899
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
2073720900
return sqlite3GlobalConfig.m.xSize(p);
2073820901
}
2073920902
SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
2074020903
if( db==0 ){
20741
- assert( sqlite3MemdebugNoType(p, ~MEMTYPE_HEAP) );
20904
+ assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
2074220905
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
2074320906
return sqlite3MallocSize(p);
2074420907
}else{
2074520908
assert( sqlite3_mutex_held(db->mutex) );
2074620909
if( isLookaside(db, p) ){
2074720910
return db->lookaside.sz;
2074820911
}else{
2074920912
assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20750
- assert( sqlite3MemdebugNoType(p, ~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20913
+ assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2075120914
return sqlite3GlobalConfig.m.xSize(p);
2075220915
}
2075320916
}
2075420917
}
2075520918
SQLITE_API sqlite3_uint64 sqlite3_msize(void *p){
20756
- assert( sqlite3MemdebugNoType(p, ~MEMTYPE_HEAP) );
20919
+ assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
2075720920
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
2075820921
return (sqlite3_uint64)sqlite3GlobalConfig.m.xSize(p);
2075920922
}
2076020923
2076120924
/*
@@ -20762,15 +20925,15 @@
2076220925
** Free memory previously obtained from sqlite3Malloc().
2076320926
*/
2076420927
SQLITE_API void sqlite3_free(void *p){
2076520928
if( p==0 ) return; /* IMP: R-49053-54554 */
2076620929
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
20767
- assert( sqlite3MemdebugNoType(p, ~MEMTYPE_HEAP) );
20930
+ assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
2076820931
if( sqlite3GlobalConfig.bMemstat ){
2076920932
sqlite3_mutex_enter(mem0.mutex);
20770
- sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p));
20771
- sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, -1);
20933
+ sqlite3StatusDown(SQLITE_STATUS_MEMORY_USED, sqlite3MallocSize(p));
20934
+ sqlite3StatusDown(SQLITE_STATUS_MALLOC_COUNT, 1);
2077220935
sqlite3GlobalConfig.m.xFree(p);
2077320936
sqlite3_mutex_leave(mem0.mutex);
2077420937
}else{
2077520938
sqlite3GlobalConfig.m.xFree(p);
2077620939
}
@@ -20807,11 +20970,11 @@
2080720970
db->lookaside.nOut--;
2080820971
return;
2080920972
}
2081020973
}
2081120974
assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20812
- assert( sqlite3MemdebugNoType(p, ~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20975
+ assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2081320976
assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
2081420977
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
2081520978
sqlite3_free(p);
2081620979
}
2081720980
@@ -20820,11 +20983,11 @@
2082020983
*/
2082120984
SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, u64 nBytes){
2082220985
int nOld, nNew, nDiff;
2082320986
void *pNew;
2082420987
assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
20825
- assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) );
20988
+ assert( sqlite3MemdebugNoType(pOld, (u8)~MEMTYPE_HEAP) );
2082620989
if( pOld==0 ){
2082720990
return sqlite3Malloc(nBytes); /* IMP: R-04300-56712 */
2082820991
}
2082920992
if( nBytes==0 ){
2083020993
sqlite3_free(pOld); /* IMP: R-26507-47431 */
@@ -20854,11 +21017,11 @@
2085421017
sqlite3MallocAlarm((int)nBytes);
2085521018
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
2085621019
}
2085721020
if( pNew ){
2085821021
nNew = sqlite3MallocSize(pNew);
20859
- sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nNew-nOld);
21022
+ sqlite3StatusUp(SQLITE_STATUS_MEMORY_USED, nNew-nOld);
2086021023
}
2086121024
sqlite3_mutex_leave(mem0.mutex);
2086221025
}else{
2086321026
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
2086421027
}
@@ -20987,11 +21150,11 @@
2098721150
memcpy(pNew, p, db->lookaside.sz);
2098821151
sqlite3DbFree(db, p);
2098921152
}
2099021153
}else{
2099121154
assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20992
- assert( sqlite3MemdebugNoType(p, ~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
21155
+ assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2099321156
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
2099421157
pNew = sqlite3_realloc64(p, n);
2099521158
if( !pNew ){
2099621159
db->mallocFailed = 1;
2099721160
}
@@ -24969,27 +25132,29 @@
2496925132
/* 134 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
2497025133
/* 135 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
2497125134
/* 136 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
2497225135
/* 137 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
2497325136
/* 138 */ "IfNeg" OpHelp("r[P1]+=P3, if r[P1]<0 goto P2"),
24974
- /* 139 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),
24975
- /* 140 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
24976
- /* 141 */ "IncrVacuum" OpHelp(""),
24977
- /* 142 */ "Expire" OpHelp(""),
24978
- /* 143 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
24979
- /* 144 */ "VBegin" OpHelp(""),
24980
- /* 145 */ "VCreate" OpHelp(""),
24981
- /* 146 */ "VDestroy" OpHelp(""),
24982
- /* 147 */ "VOpen" OpHelp(""),
24983
- /* 148 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
24984
- /* 149 */ "VNext" OpHelp(""),
24985
- /* 150 */ "VRename" OpHelp(""),
24986
- /* 151 */ "Pagecount" OpHelp(""),
24987
- /* 152 */ "MaxPgcnt" OpHelp(""),
24988
- /* 153 */ "Init" OpHelp("Start at P2"),
24989
- /* 154 */ "Noop" OpHelp(""),
24990
- /* 155 */ "Explain" OpHelp(""),
25137
+ /* 139 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]+=P3, goto P2"),
25138
+ /* 140 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
25139
+ /* 141 */ "JumpZeroIncr" OpHelp("if (r[P1]++)==0 ) goto P2"),
25140
+ /* 142 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
25141
+ /* 143 */ "IncrVacuum" OpHelp(""),
25142
+ /* 144 */ "Expire" OpHelp(""),
25143
+ /* 145 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
25144
+ /* 146 */ "VBegin" OpHelp(""),
25145
+ /* 147 */ "VCreate" OpHelp(""),
25146
+ /* 148 */ "VDestroy" OpHelp(""),
25147
+ /* 149 */ "VOpen" OpHelp(""),
25148
+ /* 150 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
25149
+ /* 151 */ "VNext" OpHelp(""),
25150
+ /* 152 */ "VRename" OpHelp(""),
25151
+ /* 153 */ "Pagecount" OpHelp(""),
25152
+ /* 154 */ "MaxPgcnt" OpHelp(""),
25153
+ /* 155 */ "Init" OpHelp("Start at P2"),
25154
+ /* 156 */ "Noop" OpHelp(""),
25155
+ /* 157 */ "Explain" OpHelp(""),
2499125156
};
2499225157
return azName[i];
2499325158
}
2499425159
#endif
2499525160
@@ -25065,22 +25230,10 @@
2506525230
# else
2506625231
# define SQLITE_ENABLE_LOCKING_STYLE 0
2506725232
# endif
2506825233
#endif
2506925234
25070
-/*
25071
-** Define the OS_VXWORKS pre-processor macro to 1 if building on
25072
-** vxworks, or 0 otherwise.
25073
-*/
25074
-#ifndef OS_VXWORKS
25075
-# if defined(__RTP__) || defined(_WRS_KERNEL)
25076
-# define OS_VXWORKS 1
25077
-# else
25078
-# define OS_VXWORKS 0
25079
-# endif
25080
-#endif
25081
-
2508225235
/*
2508325236
** standard include files.
2508425237
*/
2508525238
#include <sys/types.h>
2508625239
#include <sys/stat.h>
@@ -25091,22 +25244,23 @@
2509125244
#include <errno.h>
2509225245
#if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
2509325246
# include <sys/mman.h>
2509425247
#endif
2509525248
25096
-#if SQLITE_ENABLE_LOCKING_STYLE || OS_VXWORKS
25249
+#if SQLITE_ENABLE_LOCKING_STYLE
2509725250
# include <sys/ioctl.h>
25098
-# if OS_VXWORKS
25099
-# include <semaphore.h>
25100
-# include <limits.h>
25101
-# else
25102
-# include <sys/file.h>
25103
-# include <sys/param.h>
25104
-# endif
25251
+# include <sys/file.h>
25252
+# include <sys/param.h>
2510525253
#endif /* SQLITE_ENABLE_LOCKING_STYLE */
2510625254
25107
-#if defined(__APPLE__) || (SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS)
25255
+#if OS_VXWORKS
25256
+/* # include <sys/ioctl.h> */
25257
+# include <semaphore.h>
25258
+# include <limits.h>
25259
+#endif /* OS_VXWORKS */
25260
+
25261
+#if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE
2510825262
# include <sys/mount.h>
2510925263
#endif
2511025264
2511125265
#ifdef HAVE_UTIME
2511225266
# include <utime.h>
@@ -25142,10 +25296,14 @@
2514225296
2514325297
/*
2514425298
** Maximum supported path-length.
2514525299
*/
2514625300
#define MAX_PATHNAME 512
25301
+
25302
+/* Always cast the getpid() return type for compatibility with
25303
+** kernel modules in VxWorks. */
25304
+#define osGetpid(X) (pid_t)getpid()
2514725305
2514825306
/*
2514925307
** Only set the lastErrno if the error code is a real error and not
2515025308
** a normal expected return code of SQLITE_BUSY or SQLITE_OK
2515125309
*/
@@ -25231,11 +25389,11 @@
2523125389
2523225390
/* This variable holds the process id (pid) from when the xRandomness()
2523325391
** method was called. If xOpen() is called from a different process id,
2523425392
** indicating that a fork() has occurred, the PRNG will be reset.
2523525393
*/
25236
-static int randomnessPid = 0;
25394
+static pid_t randomnessPid = 0;
2523725395
2523825396
/*
2523925397
** Allowed values for the unixFile.ctrlFlags bitmask:
2524025398
*/
2524125399
#define UNIXFILE_EXCL 0x01 /* Connections from one process only */
@@ -25249,10 +25407,11 @@
2524925407
#define UNIXFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
2525025408
#define UNIXFILE_DELETE 0x20 /* Delete on close */
2525125409
#define UNIXFILE_URI 0x40 /* Filename might have query parameters */
2525225410
#define UNIXFILE_NOLOCK 0x80 /* Do no file locking */
2525325411
#define UNIXFILE_WARNED 0x0100 /* verifyDbFile() warnings issued */
25412
+#define UNIXFILE_BLOCK 0x0200 /* Next SHM lock might block */
2525425413
2525525414
/*
2525625415
** Include code that is common to all os_*.c files
2525725416
*/
2525825417
/************** Include os_common.h in the middle of os_unix.c ***************/
@@ -25587,11 +25746,11 @@
2558725746
#define osFcntl ((int(*)(int,int,...))aSyscall[7].pCurrent)
2558825747
2558925748
{ "read", (sqlite3_syscall_ptr)read, 0 },
2559025749
#define osRead ((ssize_t(*)(int,void*,size_t))aSyscall[8].pCurrent)
2559125750
25592
-#if defined(USE_PREAD) || (SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS)
25751
+#if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE
2559325752
{ "pread", (sqlite3_syscall_ptr)pread, 0 },
2559425753
#else
2559525754
{ "pread", (sqlite3_syscall_ptr)0, 0 },
2559625755
#endif
2559725756
#define osPread ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[9].pCurrent)
@@ -25604,11 +25763,11 @@
2560425763
#define osPread64 ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].pCurrent)
2560525764
2560625765
{ "write", (sqlite3_syscall_ptr)write, 0 },
2560725766
#define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent)
2560825767
25609
-#if defined(USE_PREAD) || (SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS)
25768
+#if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE
2561025769
{ "pwrite", (sqlite3_syscall_ptr)pwrite, 0 },
2561125770
#else
2561225771
{ "pwrite", (sqlite3_syscall_ptr)0, 0 },
2561325772
#endif
2561425773
#define osPwrite ((ssize_t(*)(int,const void*,size_t,off_t))\
@@ -26743,11 +26902,12 @@
2674326902
int tErrno = 0;
2674426903
2674526904
assert( pFile );
2674626905
OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (unix)\n", pFile->h,
2674726906
azFileLock(eFileLock), azFileLock(pFile->eFileLock),
26748
- azFileLock(pFile->pInode->eFileLock), pFile->pInode->nShared , getpid()));
26907
+ azFileLock(pFile->pInode->eFileLock), pFile->pInode->nShared,
26908
+ osGetpid(0)));
2674926909
2675026910
/* If there is already a lock of this type or more restrictive on the
2675126911
** unixFile, do nothing. Don't use the end_lock: exit path, as
2675226912
** unixEnterMutex() hasn't been called yet.
2675326913
*/
@@ -26951,11 +27111,11 @@
2695127111
int rc = SQLITE_OK;
2695227112
2695327113
assert( pFile );
2695427114
OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (unix)\n", pFile->h, eFileLock,
2695527115
pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared,
26956
- getpid()));
27116
+ osGetpid(0)));
2695727117
2695827118
assert( eFileLock<=SHARED_LOCK );
2695927119
if( pFile->eFileLock<=eFileLock ){
2696027120
return SQLITE_OK;
2696127121
}
@@ -27378,11 +27538,11 @@
2737827538
char *zLockFile = (char *)pFile->lockingContext;
2737927539
int rc;
2738027540
2738127541
assert( pFile );
2738227542
OSTRACE(("UNLOCK %d %d was %d pid=%d (dotlock)\n", pFile->h, eFileLock,
27383
- pFile->eFileLock, getpid()));
27543
+ pFile->eFileLock, osGetpid(0)));
2738427544
assert( eFileLock<=SHARED_LOCK );
2738527545
2738627546
/* no-op if possible */
2738727547
if( pFile->eFileLock==eFileLock ){
2738827548
return SQLITE_OK;
@@ -27441,14 +27601,13 @@
2744127601
** a single exclusive lock. In other words, SHARED, RESERVED, and
2744227602
** PENDING locks are the same thing as an EXCLUSIVE lock. SQLite
2744327603
** still works when you do this, but concurrency is reduced since
2744427604
** only a single process can be reading the database at a time.
2744527605
**
27446
-** Omit this section if SQLITE_ENABLE_LOCKING_STYLE is turned off or if
27447
-** compiling for VXWORKS.
27606
+** Omit this section if SQLITE_ENABLE_LOCKING_STYLE is turned off
2744827607
*/
27449
-#if SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS
27608
+#if SQLITE_ENABLE_LOCKING_STYLE
2745027609
2745127610
/*
2745227611
** Retry flock() calls that fail with EINTR
2745327612
*/
2745427613
#ifdef EINTR
@@ -27597,11 +27756,11 @@
2759727756
static int flockUnlock(sqlite3_file *id, int eFileLock) {
2759827757
unixFile *pFile = (unixFile*)id;
2759927758
2760027759
assert( pFile );
2760127760
OSTRACE(("UNLOCK %d %d was %d pid=%d (flock)\n", pFile->h, eFileLock,
27602
- pFile->eFileLock, getpid()));
27761
+ pFile->eFileLock, osGetpid(0)));
2760327762
assert( eFileLock<=SHARED_LOCK );
2760427763
2760527764
/* no-op if possible */
2760627765
if( pFile->eFileLock==eFileLock ){
2760727766
return SQLITE_OK;
@@ -27658,11 +27817,11 @@
2765827817
** This routine checks if there is a RESERVED lock held on the specified
2765927818
** file by this or any other process. If such a lock is held, set *pResOut
2766027819
** to a non-zero value otherwise *pResOut is set to zero. The return value
2766127820
** is set to SQLITE_OK unless an I/O error occurs during lock checking.
2766227821
*/
27663
-static int semCheckReservedLock(sqlite3_file *id, int *pResOut) {
27822
+static int semXCheckReservedLock(sqlite3_file *id, int *pResOut) {
2766427823
int rc = SQLITE_OK;
2766527824
int reserved = 0;
2766627825
unixFile *pFile = (unixFile*)id;
2766727826
2766827827
SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; );
@@ -27725,11 +27884,11 @@
2772527884
** access the file.
2772627885
**
2772727886
** This routine will only increase a lock. Use the sqlite3OsUnlock()
2772827887
** routine to lower a locking level.
2772927888
*/
27730
-static int semLock(sqlite3_file *id, int eFileLock) {
27889
+static int semXLock(sqlite3_file *id, int eFileLock) {
2773127890
unixFile *pFile = (unixFile*)id;
2773227891
sem_t *pSem = pFile->pInode->pSem;
2773327892
int rc = SQLITE_OK;
2773427893
2773527894
/* if we already have a lock, it is exclusive.
@@ -27758,18 +27917,18 @@
2775827917
** must be either NO_LOCK or SHARED_LOCK.
2775927918
**
2776027919
** If the locking level of the file descriptor is already at or below
2776127920
** the requested locking level, this routine is a no-op.
2776227921
*/
27763
-static int semUnlock(sqlite3_file *id, int eFileLock) {
27922
+static int semXUnlock(sqlite3_file *id, int eFileLock) {
2776427923
unixFile *pFile = (unixFile*)id;
2776527924
sem_t *pSem = pFile->pInode->pSem;
2776627925
2776727926
assert( pFile );
2776827927
assert( pSem );
2776927928
OSTRACE(("UNLOCK %d %d was %d pid=%d (sem)\n", pFile->h, eFileLock,
27770
- pFile->eFileLock, getpid()));
27929
+ pFile->eFileLock, osGetpid(0)));
2777127930
assert( eFileLock<=SHARED_LOCK );
2777227931
2777327932
/* no-op if possible */
2777427933
if( pFile->eFileLock==eFileLock ){
2777527934
return SQLITE_OK;
@@ -27795,14 +27954,14 @@
2779527954
}
2779627955
2779727956
/*
2779827957
** Close a file.
2779927958
*/
27800
-static int semClose(sqlite3_file *id) {
27959
+static int semXClose(sqlite3_file *id) {
2780127960
if( id ){
2780227961
unixFile *pFile = (unixFile*)id;
27803
- semUnlock(id, NO_LOCK);
27962
+ semXUnlock(id, NO_LOCK);
2780427963
assert( pFile );
2780527964
unixEnterMutex();
2780627965
releaseInodeInfo(pFile);
2780727966
unixLeaveMutex();
2780827967
closeUnixFile(id);
@@ -27979,11 +28138,11 @@
2797928138
afpLockingContext *context = (afpLockingContext *) pFile->lockingContext;
2798028139
2798128140
assert( pFile );
2798228141
OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (afp)\n", pFile->h,
2798328142
azFileLock(eFileLock), azFileLock(pFile->eFileLock),
27984
- azFileLock(pInode->eFileLock), pInode->nShared , getpid()));
28143
+ azFileLock(pInode->eFileLock), pInode->nShared , osGetpid(0)));
2798528144
2798628145
/* If there is already a lock of this type or more restrictive on the
2798728146
** unixFile, do nothing. Don't use the afp_end_lock: exit path, as
2798828147
** unixEnterMutex() hasn't been called yet.
2798928148
*/
@@ -28165,11 +28324,11 @@
2816528324
#endif
2816628325
2816728326
assert( pFile );
2816828327
OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (afp)\n", pFile->h, eFileLock,
2816928328
pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared,
28170
- getpid()));
28329
+ osGetpid(0)));
2817128330
2817228331
assert( eFileLock<=SHARED_LOCK );
2817328332
if( pFile->eFileLock<=eFileLock ){
2817428333
return SQLITE_OK;
2817528334
}
@@ -28990,10 +29149,14 @@
2899029149
** Information and control of an open file handle.
2899129150
*/
2899229151
static int unixFileControl(sqlite3_file *id, int op, void *pArg){
2899329152
unixFile *pFile = (unixFile*)id;
2899429153
switch( op ){
29154
+ case SQLITE_FCNTL_WAL_BLOCK: {
29155
+ pFile->ctrlFlags |= UNIXFILE_BLOCK;
29156
+ return SQLITE_OK;
29157
+ }
2899529158
case SQLITE_FCNTL_LOCKSTATE: {
2899629159
*(int*)pArg = pFile->eFileLock;
2899729160
return SQLITE_OK;
2899829161
}
2899929162
case SQLITE_FCNTL_LAST_ERRNO: {
@@ -29204,11 +29367,13 @@
2920429367
**
2920529368
** This function should not be called directly by other code in this file.
2920629369
** Instead, it should be called via macro osGetpagesize().
2920729370
*/
2920829371
static int unixGetpagesize(void){
29209
-#if defined(_BSD_SOURCE)
29372
+#if OS_VXWORKS
29373
+ return 1024;
29374
+#elif defined(_BSD_SOURCE)
2921029375
return getpagesize();
2921129376
#else
2921229377
return (int)sysconf(_SC_PAGESIZE);
2921329378
#endif
2921429379
}
@@ -29297,37 +29462,42 @@
2929729462
**
2929829463
** Locks block if the mask is exactly UNIX_SHM_C and are non-blocking
2929929464
** otherwise.
2930029465
*/
2930129466
static int unixShmSystemLock(
29302
- unixShmNode *pShmNode, /* Apply locks to this open shared-memory segment */
29467
+ unixFile *pFile, /* Open connection to the WAL file */
2930329468
int lockType, /* F_UNLCK, F_RDLCK, or F_WRLCK */
2930429469
int ofst, /* First byte of the locking range */
2930529470
int n /* Number of bytes to lock */
2930629471
){
29307
- struct flock f; /* The posix advisory locking structure */
29308
- int rc = SQLITE_OK; /* Result code form fcntl() */
29472
+ unixShmNode *pShmNode; /* Apply locks to this open shared-memory segment */
29473
+ struct flock f; /* The posix advisory locking structure */
29474
+ int rc = SQLITE_OK; /* Result code form fcntl() */
2930929475
2931029476
/* Access to the unixShmNode object is serialized by the caller */
29477
+ pShmNode = pFile->pInode->pShmNode;
2931129478
assert( sqlite3_mutex_held(pShmNode->mutex) || pShmNode->nRef==0 );
2931229479
2931329480
/* Shared locks never span more than one byte */
2931429481
assert( n==1 || lockType!=F_RDLCK );
2931529482
2931629483
/* Locks are within range */
2931729484
assert( n>=1 && n<SQLITE_SHM_NLOCK );
2931829485
2931929486
if( pShmNode->h>=0 ){
29487
+ int lkType;
2932029488
/* Initialize the locking parameters */
2932129489
memset(&f, 0, sizeof(f));
2932229490
f.l_type = lockType;
2932329491
f.l_whence = SEEK_SET;
2932429492
f.l_start = ofst;
2932529493
f.l_len = n;
2932629494
29327
- rc = osFcntl(pShmNode->h, F_SETLK, &f);
29495
+ lkType = (pFile->ctrlFlags & UNIXFILE_BLOCK)!=0 ? F_SETLKW : F_SETLK;
29496
+ rc = osFcntl(pShmNode->h, lkType, &f);
2932829497
rc = (rc!=(-1)) ? SQLITE_OK : SQLITE_BUSY;
29498
+ pFile->ctrlFlags &= ~UNIXFILE_BLOCK;
2932929499
}
2933029500
2933129501
/* Update the global lock state and do debug tracing */
2933229502
#ifdef SQLITE_DEBUG
2933329503
{ u16 mask;
@@ -29533,17 +29703,17 @@
2953329703
2953429704
/* Check to see if another process is holding the dead-man switch.
2953529705
** If not, truncate the file to zero length.
2953629706
*/
2953729707
rc = SQLITE_OK;
29538
- if( unixShmSystemLock(pShmNode, F_WRLCK, UNIX_SHM_DMS, 1)==SQLITE_OK ){
29708
+ if( unixShmSystemLock(pDbFd, F_WRLCK, UNIX_SHM_DMS, 1)==SQLITE_OK ){
2953929709
if( robust_ftruncate(pShmNode->h, 0) ){
2954029710
rc = unixLogError(SQLITE_IOERR_SHMOPEN, "ftruncate", zShmFilename);
2954129711
}
2954229712
}
2954329713
if( rc==SQLITE_OK ){
29544
- rc = unixShmSystemLock(pShmNode, F_RDLCK, UNIX_SHM_DMS, 1);
29714
+ rc = unixShmSystemLock(pDbFd, F_RDLCK, UNIX_SHM_DMS, 1);
2954529715
}
2954629716
if( rc ) goto shm_open_err;
2954729717
}
2954829718
}
2954929719
@@ -29771,11 +29941,11 @@
2977129941
allMask |= pX->sharedMask;
2977229942
}
2977329943
2977429944
/* Unlock the system-level locks */
2977529945
if( (mask & allMask)==0 ){
29776
- rc = unixShmSystemLock(pShmNode, F_UNLCK, ofst+UNIX_SHM_BASE, n);
29946
+ rc = unixShmSystemLock(pDbFd, F_UNLCK, ofst+UNIX_SHM_BASE, n);
2977729947
}else{
2977829948
rc = SQLITE_OK;
2977929949
}
2978029950
2978129951
/* Undo the local locks */
@@ -29799,11 +29969,11 @@
2979929969
}
2980029970
2980129971
/* Get shared locks at the system level, if necessary */
2980229972
if( rc==SQLITE_OK ){
2980329973
if( (allShared & mask)==0 ){
29804
- rc = unixShmSystemLock(pShmNode, F_RDLCK, ofst+UNIX_SHM_BASE, n);
29974
+ rc = unixShmSystemLock(pDbFd, F_RDLCK, ofst+UNIX_SHM_BASE, n);
2980529975
}else{
2980629976
rc = SQLITE_OK;
2980729977
}
2980829978
}
2980929979
@@ -29824,20 +29994,20 @@
2982429994
2982529995
/* Get the exclusive locks at the system level. Then if successful
2982629996
** also mark the local connection as being locked.
2982729997
*/
2982829998
if( rc==SQLITE_OK ){
29829
- rc = unixShmSystemLock(pShmNode, F_WRLCK, ofst+UNIX_SHM_BASE, n);
29999
+ rc = unixShmSystemLock(pDbFd, F_WRLCK, ofst+UNIX_SHM_BASE, n);
2983030000
if( rc==SQLITE_OK ){
2983130001
assert( (p->sharedMask & mask)==0 );
2983230002
p->exclMask |= mask;
2983330003
}
2983430004
}
2983530005
}
2983630006
sqlite3_mutex_leave(pShmNode->mutex);
2983730007
OSTRACE(("SHM-LOCK shmid-%d, pid-%d got %03x,%03x\n",
29838
- p->id, getpid(), p->sharedMask, p->exclMask));
30008
+ p->id, osGetpid(0), p->sharedMask, p->exclMask));
2983930009
return rc;
2984030010
}
2984130011
2984230012
/*
2984330013
** Implement a memory barrier or memory fence on shared memory.
@@ -30236,11 +30406,11 @@
3023630406
dotlockUnlock, /* xUnlock method */
3023730407
dotlockCheckReservedLock, /* xCheckReservedLock method */
3023830408
0 /* xShmMap method */
3023930409
)
3024030410
30241
-#if SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS
30411
+#if SQLITE_ENABLE_LOCKING_STYLE
3024230412
IOMETHODS(
3024330413
flockIoFinder, /* Finder function name */
3024430414
flockIoMethods, /* sqlite3_io_methods object name */
3024530415
1, /* shared memory is disabled */
3024630416
flockClose, /* xClose method */
@@ -30254,14 +30424,14 @@
3025430424
#if OS_VXWORKS
3025530425
IOMETHODS(
3025630426
semIoFinder, /* Finder function name */
3025730427
semIoMethods, /* sqlite3_io_methods object name */
3025830428
1, /* shared memory is disabled */
30259
- semClose, /* xClose method */
30260
- semLock, /* xLock method */
30261
- semUnlock, /* xUnlock method */
30262
- semCheckReservedLock, /* xCheckReservedLock method */
30429
+ semXClose, /* xClose method */
30430
+ semXLock, /* xLock method */
30431
+ semXUnlock, /* xUnlock method */
30432
+ semXCheckReservedLock, /* xCheckReservedLock method */
3026330433
0 /* xShmMap method */
3026430434
)
3026530435
#endif
3026630436
3026730437
#if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
@@ -30381,19 +30551,17 @@
3038130551
static const sqlite3_io_methods
3038230552
*(*const autolockIoFinder)(const char*,unixFile*) = autolockIoFinderImpl;
3038330553
3038430554
#endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */
3038530555
30386
-#if OS_VXWORKS && SQLITE_ENABLE_LOCKING_STYLE
30387
-/*
30388
-** This "finder" function attempts to determine the best locking strategy
30389
-** for the database file "filePath". It then returns the sqlite3_io_methods
30390
-** object that implements that strategy.
30391
-**
30392
-** This is for VXWorks only.
30556
+#if OS_VXWORKS
30557
+/*
30558
+** This "finder" function for VxWorks checks to see if posix advisory
30559
+** locking works. If it does, then that is what is used. If it does not
30560
+** work, then fallback to named semaphore locking.
3039330561
*/
30394
-static const sqlite3_io_methods *autolockIoFinderImpl(
30562
+static const sqlite3_io_methods *vxworksIoFinderImpl(
3039530563
const char *filePath, /* name of the database file */
3039630564
unixFile *pNew /* the open file object */
3039730565
){
3039830566
struct flock lockInfo;
3039930567
@@ -30415,13 +30583,13 @@
3041530583
}else{
3041630584
return &semIoMethods;
3041730585
}
3041830586
}
3041930587
static const sqlite3_io_methods
30420
- *(*const autolockIoFinder)(const char*,unixFile*) = autolockIoFinderImpl;
30588
+ *(*const vxworksIoFinder)(const char*,unixFile*) = vxworksIoFinderImpl;
3042130589
30422
-#endif /* OS_VXWORKS && SQLITE_ENABLE_LOCKING_STYLE */
30590
+#endif /* OS_VXWORKS */
3042330591
3042430592
/*
3042530593
** An abstract type for a pointer to an IO method finder function:
3042630594
*/
3042730595
typedef const sqlite3_io_methods *(*finder_type)(const char*,unixFile*);
@@ -30930,12 +31098,12 @@
3093031098
/* Detect a pid change and reset the PRNG. There is a race condition
3093131099
** here such that two or more threads all trying to open databases at
3093231100
** the same instant might all reset the PRNG. But multiple resets
3093331101
** are harmless.
3093431102
*/
30935
- if( randomnessPid!=getpid() ){
30936
- randomnessPid = getpid();
31103
+ if( randomnessPid!=osGetpid(0) ){
31104
+ randomnessPid = osGetpid(0);
3093731105
sqlite3_randomness(0,0);
3093831106
}
3093931107
3094031108
memset(p, 0, sizeof(unixFile));
3094131109
@@ -31322,11 +31490,11 @@
3132231490
** When testing, initializing zBuf[] to zero is all we do. That means
3132331491
** that we always use the same random number sequence. This makes the
3132431492
** tests repeatable.
3132531493
*/
3132631494
memset(zBuf, 0, nBuf);
31327
- randomnessPid = getpid();
31495
+ randomnessPid = osGetpid(0);
3132831496
#if !defined(SQLITE_TEST)
3132931497
{
3133031498
int fd, got;
3133131499
fd = robust_open("/dev/urandom", O_RDONLY, 0);
3133231500
if( fd<0 ){
@@ -31643,11 +31811,11 @@
3164331811
#else
3164431812
# ifdef _CS_DARWIN_USER_TEMP_DIR
3164531813
{
3164631814
if( !confstr(_CS_DARWIN_USER_TEMP_DIR, lPath, maxLen) ){
3164731815
OSTRACE(("GETLOCKPATH failed %s errno=%d pid=%d\n",
31648
- lPath, errno, getpid()));
31816
+ lPath, errno, osGetpid(0)));
3164931817
return SQLITE_IOERR_LOCK;
3165031818
}
3165131819
len = strlcat(lPath, "sqliteplocks", maxLen);
3165231820
}
3165331821
# else
@@ -31665,11 +31833,11 @@
3166531833
char c = dbPath[i];
3166631834
lPath[i+len] = (c=='/')?'_':c;
3166731835
}
3166831836
lPath[i+len]='\0';
3166931837
strlcat(lPath, ":auto:", maxLen);
31670
- OSTRACE(("GETLOCKPATH proxy lock path=%s pid=%d\n", lPath, getpid()));
31838
+ OSTRACE(("GETLOCKPATH proxy lock path=%s pid=%d\n", lPath, osGetpid(0)));
3167131839
return SQLITE_OK;
3167231840
}
3167331841
3167431842
/*
3167531843
** Creates the lock file and any missing directories in lockPath
@@ -31692,20 +31860,20 @@
3169231860
if( osMkdir(buf, SQLITE_DEFAULT_PROXYDIR_PERMISSIONS) ){
3169331861
int err=errno;
3169431862
if( err!=EEXIST ) {
3169531863
OSTRACE(("CREATELOCKPATH FAILED creating %s, "
3169631864
"'%s' proxy lock path=%s pid=%d\n",
31697
- buf, strerror(err), lockPath, getpid()));
31865
+ buf, strerror(err), lockPath, osGetpid(0)));
3169831866
return err;
3169931867
}
3170031868
}
3170131869
}
3170231870
start=i+1;
3170331871
}
3170431872
buf[i] = lockPath[i];
3170531873
}
31706
- OSTRACE(("CREATELOCKPATH proxy lock path=%s pid=%d\n", lockPath, getpid()));
31874
+ OSTRACE(("CREATELOCKPATH proxy lock path=%s pid=%d\n", lockPath, osGetpid(0)));
3170731875
return 0;
3170831876
}
3170931877
3171031878
/*
3171131879
** Create a new VFS file descriptor (stored in memory obtained from
@@ -32006,11 +32174,12 @@
3200632174
int readLen = 0;
3200732175
int tryOldLockPath = 0;
3200832176
int forceNewLockPath = 0;
3200932177
3201032178
OSTRACE(("TAKECONCH %d for %s pid=%d\n", conchFile->h,
32011
- (pCtx->lockProxyPath ? pCtx->lockProxyPath : ":auto:"), getpid()));
32179
+ (pCtx->lockProxyPath ? pCtx->lockProxyPath : ":auto:"),
32180
+ osGetpid(0)));
3201232181
3201332182
rc = proxyGetHostID(myHostID, &pError);
3201432183
if( (rc&0xff)==SQLITE_IOERR ){
3201532184
storeLastErrno(pFile, pError);
3201632185
goto end_takeconch;
@@ -32216,11 +32385,11 @@
3221632385
3221732386
pCtx = (proxyLockingContext *)pFile->lockingContext;
3221832387
conchFile = pCtx->conchFile;
3221932388
OSTRACE(("RELEASECONCH %d for %s pid=%d\n", conchFile->h,
3222032389
(pCtx->lockProxyPath ? pCtx->lockProxyPath : ":auto:"),
32221
- getpid()));
32390
+ osGetpid(0)));
3222232391
if( pCtx->conchHeld>0 ){
3222332392
rc = conchFile->pMethod->xUnlock((sqlite3_file*)conchFile, NO_LOCK);
3222432393
}
3222532394
pCtx->conchHeld = 0;
3222632395
OSTRACE(("RELEASECONCH %d %s\n", conchFile->h,
@@ -32358,11 +32527,11 @@
3235832527
}else{
3235932528
lockPath=(char *)path;
3236032529
}
3236132530
3236232531
OSTRACE(("TRANSPROXY %d for %s pid=%d\n", pFile->h,
32363
- (lockPath ? lockPath : ":auto:"), getpid()));
32532
+ (lockPath ? lockPath : ":auto:"), osGetpid(0)));
3236432533
3236532534
pCtx = sqlite3_malloc( sizeof(*pCtx) );
3236632535
if( pCtx==0 ){
3236732536
return SQLITE_NOMEM;
3236832537
}
@@ -32699,26 +32868,28 @@
3269932868
** Note that the sqlite3_vfs.pNext field of the VFS object is modified
3270032869
** by the SQLite core when the VFS is registered. So the following
3270132870
** array cannot be const.
3270232871
*/
3270332872
static sqlite3_vfs aVfs[] = {
32704
-#if SQLITE_ENABLE_LOCKING_STYLE && (OS_VXWORKS || defined(__APPLE__))
32873
+#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
3270532874
UNIXVFS("unix", autolockIoFinder ),
32875
+#elif OS_VXWORKS
32876
+ UNIXVFS("unix", vxworksIoFinder ),
3270632877
#else
3270732878
UNIXVFS("unix", posixIoFinder ),
3270832879
#endif
3270932880
UNIXVFS("unix-none", nolockIoFinder ),
3271032881
UNIXVFS("unix-dotfile", dotlockIoFinder ),
3271132882
UNIXVFS("unix-excl", posixIoFinder ),
3271232883
#if OS_VXWORKS
3271332884
UNIXVFS("unix-namedsem", semIoFinder ),
3271432885
#endif
32715
-#if SQLITE_ENABLE_LOCKING_STYLE
32886
+#if SQLITE_ENABLE_LOCKING_STYLE || OS_VXWORKS
3271632887
UNIXVFS("unix-posix", posixIoFinder ),
32717
-#if !OS_VXWORKS
32888
+#endif
32889
+#if SQLITE_ENABLE_LOCKING_STYLE
3271832890
UNIXVFS("unix-flock", flockIoFinder ),
32719
-#endif
3272032891
#endif
3272132892
#if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
3272232893
UNIXVFS("unix-afp", afpIoFinder ),
3272332894
UNIXVFS("unix-nfs", nfsIoFinder ),
3272432895
UNIXVFS("unix-proxy", proxyIoFinder ),
@@ -39072,16 +39243,24 @@
3907239243
sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0);
3907339244
}
3907439245
}
3907539246
3907639247
/*
39077
-** Compute the number of pages of cache requested.
39248
+** Compute the number of pages of cache requested. p->szCache is the
39249
+** cache size requested by the "PRAGMA cache_size" statement.
39250
+**
39251
+**
3907839252
*/
3907939253
static int numberOfCachePages(PCache *p){
3908039254
if( p->szCache>=0 ){
39255
+ /* IMPLEMENTATION-OF: R-42059-47211 If the argument N is positive then the
39256
+ ** suggested cache size is set to N. */
3908139257
return p->szCache;
3908239258
}else{
39259
+ /* IMPLEMENTATION-OF: R-61436-13639 If the argument N is negative, then
39260
+ ** the number of cache pages is adjusted to use approximately abs(N*1024)
39261
+ ** bytes of memory. */
3908339262
return (int)((-1024*(i64)p->szCache)/(p->szPage+p->szExtra));
3908439263
}
3908539264
}
3908639265
3908739266
/*************************************************** General Interfaces ******
@@ -39817,20 +39996,20 @@
3981739996
** in pcache1 need to be protected via mutex.
3981839997
*/
3981939998
static void *pcache1Alloc(int nByte){
3982039999
void *p = 0;
3982140000
assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
39822
- sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte);
3982340001
if( nByte<=pcache1.szSlot ){
3982440002
sqlite3_mutex_enter(pcache1.mutex);
3982540003
p = (PgHdr1 *)pcache1.pFree;
3982640004
if( p ){
3982740005
pcache1.pFree = pcache1.pFree->pNext;
3982840006
pcache1.nFreeSlot--;
3982940007
pcache1.bUnderPressure = pcache1.nFreeSlot<pcache1.nReserve;
3983040008
assert( pcache1.nFreeSlot>=0 );
39831
- sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, 1);
40009
+ sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte);
40010
+ sqlite3StatusUp(SQLITE_STATUS_PAGECACHE_USED, 1);
3983240011
}
3983340012
sqlite3_mutex_leave(pcache1.mutex);
3983440013
}
3983540014
if( p==0 ){
3983640015
/* Memory is not available in the SQLITE_CONFIG_PAGECACHE pool. Get
@@ -39839,11 +40018,12 @@
3983940018
p = sqlite3Malloc(nByte);
3984040019
#ifndef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
3984140020
if( p ){
3984240021
int sz = sqlite3MallocSize(p);
3984340022
sqlite3_mutex_enter(pcache1.mutex);
39844
- sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz);
40023
+ sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte);
40024
+ sqlite3StatusUp(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz);
3984540025
sqlite3_mutex_leave(pcache1.mutex);
3984640026
}
3984740027
#endif
3984840028
sqlite3MemdebugSetType(p, MEMTYPE_PCACHE);
3984940029
}
@@ -39857,11 +40037,11 @@
3985740037
int nFreed = 0;
3985840038
if( p==0 ) return 0;
3985940039
if( p>=pcache1.pStart && p<pcache1.pEnd ){
3986040040
PgFreeslot *pSlot;
3986140041
sqlite3_mutex_enter(pcache1.mutex);
39862
- sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, -1);
40042
+ sqlite3StatusDown(SQLITE_STATUS_PAGECACHE_USED, 1);
3986340043
pSlot = (PgFreeslot*)p;
3986440044
pSlot->pNext = pcache1.pFree;
3986540045
pcache1.pFree = pSlot;
3986640046
pcache1.nFreeSlot++;
3986740047
pcache1.bUnderPressure = pcache1.nFreeSlot<pcache1.nReserve;
@@ -39871,11 +40051,11 @@
3987140051
assert( sqlite3MemdebugHasType(p, MEMTYPE_PCACHE) );
3987240052
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
3987340053
nFreed = sqlite3MallocSize(p);
3987440054
#ifndef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
3987540055
sqlite3_mutex_enter(pcache1.mutex);
39876
- sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -nFreed);
40056
+ sqlite3StatusDown(SQLITE_STATUS_PAGECACHE_OVERFLOW, nFreed);
3987740057
sqlite3_mutex_leave(pcache1.mutex);
3987840058
#endif
3987940059
sqlite3_free(p);
3988040060
}
3988140061
return nFreed;
@@ -40607,10 +40787,18 @@
4060740787
4060840788
/*
4060940789
** Return the size of the header on each page of this PCACHE implementation.
4061040790
*/
4061140791
SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void){ return ROUND8(sizeof(PgHdr1)); }
40792
+
40793
+/*
40794
+** Return the global mutex used by this PCACHE implementation. The
40795
+** sqlite3_status() routine needs access to this mutex.
40796
+*/
40797
+SQLITE_PRIVATE sqlite3_mutex *sqlite3Pcache1Mutex(void){
40798
+ return pcache1.mutex;
40799
+}
4061240800
4061340801
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
4061440802
/*
4061540803
** This function is called to free superfluous dynamically allocated memory
4061640804
** held by the pager system. Memory in use by any SQLite pager allocated
@@ -49380,13 +49568,14 @@
4938049568
if( pWal->exclusiveMode ) return;
4938149569
(void)sqlite3OsShmLock(pWal->pDbFd, lockIdx, 1,
4938249570
SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED);
4938349571
WALTRACE(("WAL%p: release SHARED-%s\n", pWal, walLockName(lockIdx)));
4938449572
}
49385
-static int walLockExclusive(Wal *pWal, int lockIdx, int n){
49573
+static int walLockExclusive(Wal *pWal, int lockIdx, int n, int fBlock){
4938649574
int rc;
4938749575
if( pWal->exclusiveMode ) return SQLITE_OK;
49576
+ if( fBlock ) sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_WAL_BLOCK, 0);
4938849577
rc = sqlite3OsShmLock(pWal->pDbFd, lockIdx, n,
4938949578
SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE);
4939049579
WALTRACE(("WAL%p: acquire EXCLUSIVE-%s cnt=%d %s\n", pWal,
4939149580
walLockName(lockIdx), n, rc ? "failed" : "ok"));
4939249581
VVA_ONLY( pWal->lockError = (u8)(rc!=SQLITE_OK && rc!=SQLITE_BUSY); )
@@ -49668,11 +49857,11 @@
4966849857
assert( WAL_ALL_BUT_WRITE==WAL_WRITE_LOCK+1 );
4966949858
assert( WAL_CKPT_LOCK==WAL_ALL_BUT_WRITE );
4967049859
assert( pWal->writeLock );
4967149860
iLock = WAL_ALL_BUT_WRITE + pWal->ckptLock;
4967249861
nLock = SQLITE_SHM_NLOCK - iLock;
49673
- rc = walLockExclusive(pWal, iLock, nLock);
49862
+ rc = walLockExclusive(pWal, iLock, nLock, 0);
4967449863
if( rc ){
4967549864
return rc;
4967649865
}
4967749866
WALTRACE(("WAL%p: recovery begin...\n", pWal));
4967849867
@@ -50202,11 +50391,11 @@
5020250391
int lockIdx, /* Offset of first byte to lock */
5020350392
int n /* Number of bytes to lock */
5020450393
){
5020550394
int rc;
5020650395
do {
50207
- rc = walLockExclusive(pWal, lockIdx, n);
50396
+ rc = walLockExclusive(pWal, lockIdx, n, 0);
5020850397
}while( xBusy && rc==SQLITE_BUSY && xBusy(pBusyArg) );
5020950398
return rc;
5021050399
}
5021150400
5021250401
/*
@@ -50635,11 +50824,11 @@
5063550824
if( pWal->readOnly & WAL_SHM_RDONLY ){
5063650825
if( SQLITE_OK==(rc = walLockShared(pWal, WAL_WRITE_LOCK)) ){
5063750826
walUnlockShared(pWal, WAL_WRITE_LOCK);
5063850827
rc = SQLITE_READONLY_RECOVERY;
5063950828
}
50640
- }else if( SQLITE_OK==(rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1)) ){
50829
+ }else if( SQLITE_OK==(rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1, 1)) ){
5064150830
pWal->writeLock = 1;
5064250831
if( SQLITE_OK==(rc = walIndexPage(pWal, 0, &page0)) ){
5064350832
badHdr = walIndexTryHdr(pWal, pChanged);
5064450833
if( badHdr ){
5064550834
/* If the wal-index header is still malformed even while holding
@@ -50841,11 +51030,11 @@
5084151030
{
5084251031
if( (pWal->readOnly & WAL_SHM_RDONLY)==0
5084351032
&& (mxReadMark<pWal->hdr.mxFrame || mxI==0)
5084451033
){
5084551034
for(i=1; i<WAL_NREADER; i++){
50846
- rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
51035
+ rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1, 0);
5084751036
if( rc==SQLITE_OK ){
5084851037
mxReadMark = pInfo->aReadMark[i] = pWal->hdr.mxFrame;
5084951038
mxI = i;
5085051039
walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1);
5085151040
break;
@@ -51097,11 +51286,11 @@
5109751286
}
5109851287
5109951288
/* Only one writer allowed at a time. Get the write lock. Return
5110051289
** SQLITE_BUSY if unable.
5110151290
*/
51102
- rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1);
51291
+ rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1, 0);
5110351292
if( rc ){
5110451293
return rc;
5110551294
}
5110651295
pWal->writeLock = 1;
5110751296
@@ -51242,11 +51431,11 @@
5124251431
volatile WalCkptInfo *pInfo = walCkptInfo(pWal);
5124351432
assert( pInfo->nBackfill==pWal->hdr.mxFrame );
5124451433
if( pInfo->nBackfill>0 ){
5124551434
u32 salt1;
5124651435
sqlite3_randomness(4, &salt1);
51247
- rc = walLockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1);
51436
+ rc = walLockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1, 0);
5124851437
if( rc==SQLITE_OK ){
5124951438
/* If all readers are using WAL_READ_LOCK(0) (in other words if no
5125051439
** readers are currently using the WAL), then the transactions
5125151440
** frames will overwrite the start of the existing log. Update the
5125251441
** wal-index header to reflect this.
@@ -51567,11 +51756,11 @@
5156751756
if( pWal->readOnly ) return SQLITE_READONLY;
5156851757
WALTRACE(("WAL%p: checkpoint begins\n", pWal));
5156951758
5157051759
/* IMPLEMENTATION-OF: R-62028-47212 All calls obtain an exclusive
5157151760
** "checkpoint" lock on the database file. */
51572
- rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1);
51761
+ rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1, 0);
5157351762
if( rc ){
5157451763
/* EVIDENCE-OF: R-10421-19736 If any other process is running a
5157551764
** checkpoint operation at the same time, the lock cannot be obtained and
5157651765
** SQLITE_BUSY is returned.
5157751766
** EVIDENCE-OF: R-53820-33897 Even if there is a busy-handler configured,
@@ -52569,10 +52758,11 @@
5256952758
5257052759
/*
5257152760
** Exit the recursive mutex on a Btree.
5257252761
*/
5257352762
SQLITE_PRIVATE void sqlite3BtreeLeave(Btree *p){
52763
+ assert( sqlite3_mutex_held(p->db->mutex) );
5257452764
if( p->sharable ){
5257552765
assert( p->wantToLock>0 );
5257652766
p->wantToLock--;
5257752767
if( p->wantToLock==0 ){
5257852768
unlockBtreeMutex(p);
@@ -54747,12 +54937,12 @@
5474754937
/*
5474854938
** The following asserts make sure that structures used by the btree are
5474954939
** the right size. This is to guard against size changes that result
5475054940
** when compiling on a different architecture.
5475154941
*/
54752
- assert( sizeof(i64)==8 || sizeof(i64)==4 );
54753
- assert( sizeof(u64)==8 || sizeof(u64)==4 );
54942
+ assert( sizeof(i64)==8 );
54943
+ assert( sizeof(u64)==8 );
5475454944
assert( sizeof(u32)==4 );
5475554945
assert( sizeof(u16)==2 );
5475654946
assert( sizeof(Pgno)==4 );
5475754947
5475854948
pBt = sqlite3MallocZero( sizeof(*pBt) );
@@ -60210,11 +60400,12 @@
6021060400
** the previous call, as the overflow cell data will have been
6021160401
** copied either into the body of a database page or into the new
6021260402
** pSpace buffer passed to the latter call to balance_nonroot().
6021360403
*/
6021460404
u8 *pSpace = sqlite3PageMalloc(pCur->pBt->pageSize);
60215
- rc = balance_nonroot(pParent, iIdx, pSpace, iPage==1, pCur->hints);
60405
+ rc = balance_nonroot(pParent, iIdx, pSpace, iPage==1,
60406
+ pCur->hints&BTREE_BULKLOAD);
6021660407
if( pFree ){
6021760408
/* If pFree is not NULL, it points to the pSpace buffer used
6021860409
** by a previous call to balance_nonroot(). Its contents are
6021960410
** now stored either on real database pages or within the
6022060411
** new pSpace buffer, so it may be safely freed here. */
@@ -61873,17 +62064,26 @@
6187362064
pBt->btsFlags &= ~BTS_NO_WAL;
6187462065
return rc;
6187562066
}
6187662067
6187762068
/*
61878
-** set the mask of hint flags for cursor pCsr. Currently the only valid
61879
-** values are 0 and BTREE_BULKLOAD.
62069
+** set the mask of hint flags for cursor pCsr.
6188062070
*/
6188162071
SQLITE_PRIVATE void sqlite3BtreeCursorHints(BtCursor *pCsr, unsigned int mask){
61882
- assert( mask==BTREE_BULKLOAD || mask==0 );
62072
+ assert( mask==BTREE_BULKLOAD || mask==BTREE_SEEK_EQ || mask==0 );
6188362073
pCsr->hints = mask;
6188462074
}
62075
+
62076
+#ifdef SQLITE_DEBUG
62077
+/*
62078
+** Return true if the cursor has a hint specified. This routine is
62079
+** only used from within assert() statements
62080
+*/
62081
+SQLITE_PRIVATE int sqlite3BtreeCursorHasHint(BtCursor *pCsr, unsigned int mask){
62082
+ return (pCsr->hints & mask)!=0;
62083
+}
62084
+#endif
6188562085
6188662086
/*
6188762087
** Return true if the given Btree is read-only.
6188862088
*/
6188962089
SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *p){
@@ -63773,11 +63973,11 @@
6377363973
** by calling sqlite3ValueNew().
6377463974
**
6377563975
** Otherwise, if the second argument is non-zero, then this function is
6377663976
** being called indirectly by sqlite3Stat4ProbeSetValue(). If it has not
6377763977
** already been allocated, allocate the UnpackedRecord structure that
63778
-** that function will return to its caller here. Then return a pointer
63978
+** that function will return to its caller here. Then return a pointer to
6377963979
** an sqlite3_value within the UnpackedRecord.a[] array.
6378063980
*/
6378163981
static sqlite3_value *valueNew(sqlite3 *db, struct ValueNewStat4Ctx *p){
6378263982
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
6378363983
if( p ){
@@ -63817,10 +64017,117 @@
6381764017
UNUSED_PARAMETER(p);
6381864018
#endif /* defined(SQLITE_ENABLE_STAT3_OR_STAT4) */
6381964019
return sqlite3ValueNew(db);
6382064020
}
6382164021
64022
+/*
64023
+** The expression object indicated by the second argument is guaranteed
64024
+** to be a scalar SQL function. If
64025
+**
64026
+** * all function arguments are SQL literals,
64027
+** * the SQLITE_FUNC_CONSTANT function flag is set, and
64028
+** * the SQLITE_FUNC_NEEDCOLL function flag is not set,
64029
+**
64030
+** then this routine attempts to invoke the SQL function. Assuming no
64031
+** error occurs, output parameter (*ppVal) is set to point to a value
64032
+** object containing the result before returning SQLITE_OK.
64033
+**
64034
+** Affinity aff is applied to the result of the function before returning.
64035
+** If the result is a text value, the sqlite3_value object uses encoding
64036
+** enc.
64037
+**
64038
+** If the conditions above are not met, this function returns SQLITE_OK
64039
+** and sets (*ppVal) to NULL. Or, if an error occurs, (*ppVal) is set to
64040
+** NULL and an SQLite error code returned.
64041
+*/
64042
+#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
64043
+static int valueFromFunction(
64044
+ sqlite3 *db, /* The database connection */
64045
+ Expr *p, /* The expression to evaluate */
64046
+ u8 enc, /* Encoding to use */
64047
+ u8 aff, /* Affinity to use */
64048
+ sqlite3_value **ppVal, /* Write the new value here */
64049
+ struct ValueNewStat4Ctx *pCtx /* Second argument for valueNew() */
64050
+){
64051
+ sqlite3_context ctx; /* Context object for function invocation */
64052
+ sqlite3_value **apVal = 0; /* Function arguments */
64053
+ int nVal = 0; /* Size of apVal[] array */
64054
+ FuncDef *pFunc = 0; /* Function definition */
64055
+ sqlite3_value *pVal = 0; /* New value */
64056
+ int rc = SQLITE_OK; /* Return code */
64057
+ int nName; /* Size of function name in bytes */
64058
+ ExprList *pList = 0; /* Function arguments */
64059
+ int i; /* Iterator variable */
64060
+
64061
+ assert( pCtx!=0 );
64062
+ assert( (p->flags & EP_TokenOnly)==0 );
64063
+ pList = p->x.pList;
64064
+ if( pList ) nVal = pList->nExpr;
64065
+ nName = sqlite3Strlen30(p->u.zToken);
64066
+ pFunc = sqlite3FindFunction(db, p->u.zToken, nName, nVal, enc, 0);
64067
+ assert( pFunc );
64068
+ if( (pFunc->funcFlags & SQLITE_FUNC_CONSTANT)==0
64069
+ || (pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL)
64070
+ ){
64071
+ return SQLITE_OK;
64072
+ }
64073
+
64074
+ if( pList ){
64075
+ apVal = (sqlite3_value**)sqlite3DbMallocZero(db, sizeof(apVal[0]) * nVal);
64076
+ if( apVal==0 ){
64077
+ rc = SQLITE_NOMEM;
64078
+ goto value_from_function_out;
64079
+ }
64080
+ for(i=0; i<nVal; i++){
64081
+ rc = sqlite3ValueFromExpr(db, pList->a[i].pExpr, enc, aff, &apVal[i]);
64082
+ if( apVal[i]==0 || rc!=SQLITE_OK ) goto value_from_function_out;
64083
+ }
64084
+ }
64085
+
64086
+ pVal = valueNew(db, pCtx);
64087
+ if( pVal==0 ){
64088
+ rc = SQLITE_NOMEM;
64089
+ goto value_from_function_out;
64090
+ }
64091
+
64092
+ assert( pCtx->pParse->rc==SQLITE_OK );
64093
+ memset(&ctx, 0, sizeof(ctx));
64094
+ ctx.pOut = pVal;
64095
+ ctx.pFunc = pFunc;
64096
+ pFunc->xFunc(&ctx, nVal, apVal);
64097
+ if( ctx.isError ){
64098
+ rc = ctx.isError;
64099
+ sqlite3ErrorMsg(pCtx->pParse, "%s", sqlite3_value_text(pVal));
64100
+ }else{
64101
+ sqlite3ValueApplyAffinity(pVal, aff, SQLITE_UTF8);
64102
+ assert( rc==SQLITE_OK );
64103
+ rc = sqlite3VdbeChangeEncoding(pVal, enc);
64104
+ if( rc==SQLITE_OK && sqlite3VdbeMemTooBig(pVal) ){
64105
+ rc = SQLITE_TOOBIG;
64106
+ pCtx->pParse->nErr++;
64107
+ }
64108
+ }
64109
+ pCtx->pParse->rc = rc;
64110
+
64111
+ value_from_function_out:
64112
+ if( rc!=SQLITE_OK ){
64113
+ pVal = 0;
64114
+ }
64115
+ if( apVal ){
64116
+ for(i=0; i<nVal; i++){
64117
+ sqlite3ValueFree(apVal[i]);
64118
+ }
64119
+ sqlite3DbFree(db, apVal);
64120
+ }
64121
+
64122
+ *ppVal = pVal;
64123
+ return rc;
64124
+}
64125
+#else
64126
+# define valueFromFunction(a,b,c,d,e,f) SQLITE_OK
64127
+#endif /* defined(SQLITE_ENABLE_STAT3_OR_STAT4) */
64128
+
6382264129
/*
6382364130
** Extract a value from the supplied expression in the manner described
6382464131
** above sqlite3ValueFromExpr(). Allocate the sqlite3_value object
6382564132
** using valueNew().
6382664133
**
@@ -63848,10 +64155,16 @@
6384864155
*ppVal = 0;
6384964156
return SQLITE_OK;
6385064157
}
6385164158
while( (op = pExpr->op)==TK_UPLUS ) pExpr = pExpr->pLeft;
6385264159
if( NEVER(op==TK_REGISTER) ) op = pExpr->op2;
64160
+
64161
+ /* Compressed expressions only appear when parsing the DEFAULT clause
64162
+ ** on a table column definition, and hence only when pCtx==0. This
64163
+ ** check ensures that an EP_TokenOnly expression is never passed down
64164
+ ** into valueFromFunction(). */
64165
+ assert( (pExpr->flags & EP_TokenOnly)==0 || pCtx==0 );
6385364166
6385464167
if( op==TK_CAST ){
6385564168
u8 aff = sqlite3AffinityType(pExpr->u.zToken,0);
6385664169
rc = valueFromExpr(db, pExpr->pLeft, enc, aff, ppVal, pCtx);
6385764170
testcase( rc!=SQLITE_OK );
@@ -63924,10 +64237,16 @@
6392464237
assert( zVal[nVal]=='\'' );
6392564238
sqlite3VdbeMemSetStr(pVal, sqlite3HexToBlob(db, zVal, nVal), nVal/2,
6392664239
0, SQLITE_DYNAMIC);
6392764240
}
6392864241
#endif
64242
+
64243
+#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
64244
+ else if( op==TK_FUNCTION && pCtx!=0 ){
64245
+ rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx);
64246
+ }
64247
+#endif
6392964248
6393064249
*ppVal = pVal;
6393164250
return rc;
6393264251
6393364252
no_mem:
@@ -65377,11 +65696,11 @@
6537765696
break;
6537865697
}
6537965698
#ifndef SQLITE_OMIT_VIRTUALTABLE
6538065699
case P4_VTAB: {
6538165700
sqlite3_vtab *pVtab = pOp->p4.pVtab->pVtab;
65382
- sqlite3_snprintf(nTemp, zTemp, "vtab:%p:%p", pVtab, pVtab->pModule);
65701
+ sqlite3_snprintf(nTemp, zTemp, "vtab:%p", pVtab);
6538365702
break;
6538465703
}
6538565704
#endif
6538665705
case P4_INTARRAY: {
6538765706
sqlite3_snprintf(nTemp, zTemp, "intarray");
@@ -66041,13 +66360,13 @@
6604166360
}
6604266361
#ifndef SQLITE_OMIT_VIRTUALTABLE
6604366362
else if( pCx->pVtabCursor ){
6604466363
sqlite3_vtab_cursor *pVtabCursor = pCx->pVtabCursor;
6604566364
const sqlite3_module *pModule = pVtabCursor->pVtab->pModule;
66046
- p->inVtabMethod = 1;
66365
+ assert( pVtabCursor->pVtab->nRef>0 );
66366
+ pVtabCursor->pVtab->nRef--;
6604766367
pModule->xClose(pVtabCursor);
66048
- p->inVtabMethod = 0;
6604966368
}
6605066369
#endif
6605166370
}
6605266371
6605366372
/*
@@ -66402,11 +66721,11 @@
6640266721
6640366722
/* Delete the master journal file. This commits the transaction. After
6640466723
** doing this the directory is synced again before any individual
6640566724
** transaction files are deleted.
6640666725
*/
66407
- rc = sqlite3OsDelete(pVfs, zMaster, 1);
66726
+ rc = sqlite3OsDelete(pVfs, zMaster, needSync);
6640866727
sqlite3DbFree(db, zMaster);
6640966728
zMaster = 0;
6641066729
if( rc ){
6641166730
return rc;
6641266731
}
@@ -68615,10 +68934,14 @@
6861568934
}
6861668935
SQLITE_API const void *sqlite3_value_text16le(sqlite3_value *pVal){
6861768936
return sqlite3ValueText(pVal, SQLITE_UTF16LE);
6861868937
}
6861968938
#endif /* SQLITE_OMIT_UTF16 */
68939
+/* EVIDENCE-OF: R-12793-43283 Every value in SQLite has one of five
68940
+** fundamental datatypes: 64-bit signed integer 64-bit IEEE floating
68941
+** point number string BLOB NULL
68942
+*/
6862068943
SQLITE_API int sqlite3_value_type(sqlite3_value* pVal){
6862168944
static const u8 aType[] = {
6862268945
SQLITE_BLOB, /* 0x00 */
6862368946
SQLITE_NULL, /* 0x01 */
6862468947
SQLITE_TEXT, /* 0x02 */
@@ -68811,11 +69134,11 @@
6881169134
}
6881269135
SQLITE_API void sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){
6881369136
pCtx->isError = errCode;
6881469137
pCtx->fErrorOrAux = 1;
6881569138
#ifdef SQLITE_DEBUG
68816
- pCtx->pVdbe->rcApp = errCode;
69139
+ if( pCtx->pVdbe ) pCtx->pVdbe->rcApp = errCode;
6881769140
#endif
6881869141
if( pCtx->pOut->flags & MEM_Null ){
6881969142
sqlite3VdbeMemSetStr(pCtx->pOut, sqlite3ErrStr(errCode), -1,
6882069143
SQLITE_UTF8, SQLITE_STATIC);
6882169144
}
@@ -69074,20 +69397,30 @@
6907469397
assert( p && p->pFunc );
6907569398
return p->pOut->db;
6907669399
}
6907769400
6907869401
/*
69079
-** Return the current time for a statement
69402
+** Return the current time for a statement. If the current time
69403
+** is requested more than once within the same run of a single prepared
69404
+** statement, the exact same time is returned for each invocation regardless
69405
+** of the amount of time that elapses between invocations. In other words,
69406
+** the time returned is always the time of the first call.
6908069407
*/
6908169408
SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context *p){
69082
- Vdbe *v = p->pVdbe;
6908369409
int rc;
69084
- if( v->iCurrentTime==0 ){
69085
- rc = sqlite3OsCurrentTimeInt64(p->pOut->db->pVfs, &v->iCurrentTime);
69086
- if( rc ) v->iCurrentTime = 0;
69410
+#ifndef SQLITE_ENABLE_STAT3_OR_STAT4
69411
+ sqlite3_int64 *piTime = &p->pVdbe->iCurrentTime;
69412
+ assert( p->pVdbe!=0 );
69413
+#else
69414
+ sqlite3_int64 iTime = 0;
69415
+ sqlite3_int64 *piTime = p->pVdbe!=0 ? &p->pVdbe->iCurrentTime : &iTime;
69416
+#endif
69417
+ if( *piTime==0 ){
69418
+ rc = sqlite3OsCurrentTimeInt64(p->pOut->db->pVfs, piTime);
69419
+ if( rc ) *piTime = 0;
6908769420
}
69088
- return v->iCurrentTime;
69421
+ return *piTime;
6908969422
}
6909069423
6909169424
/*
6909269425
** The following is the implementation of an SQL function that always
6909369426
** fails with an error message stating that the function is used in the
@@ -69153,10 +69486,15 @@
6915369486
*/
6915469487
SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
6915569488
AuxData *pAuxData;
6915669489
6915769490
assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
69491
+#if SQLITE_ENABLE_STAT3_OR_STAT4
69492
+ if( pCtx->pVdbe==0 ) return 0;
69493
+#else
69494
+ assert( pCtx->pVdbe!=0 );
69495
+#endif
6915869496
for(pAuxData=pCtx->pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){
6915969497
if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break;
6916069498
}
6916169499
6916269500
return (pAuxData ? pAuxData->pAux : 0);
@@ -69176,10 +69514,15 @@
6917669514
AuxData *pAuxData;
6917769515
Vdbe *pVdbe = pCtx->pVdbe;
6917869516
6917969517
assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
6918069518
if( iArg<0 ) goto failed;
69519
+#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
69520
+ if( pVdbe==0 ) goto failed;
69521
+#else
69522
+ assert( pVdbe!=0 );
69523
+#endif
6918169524
6918269525
for(pAuxData=pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){
6918369526
if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break;
6918469527
}
6918569528
if( pAuxData==0 ){
@@ -71290,11 +71633,11 @@
7129071633
7129171634
/* Opcode: String8 * P2 * P4 *
7129271635
** Synopsis: r[P2]='P4'
7129371636
**
7129471637
** P4 points to a nul terminated UTF-8 string. This opcode is transformed
71295
-** into a String before it is executed for the first time. During
71638
+** into a String opcode before it is executed for the first time. During
7129671639
** this transformation, the length of string P4 is computed and stored
7129771640
** as the P1 parameter.
7129871641
*/
7129971642
case OP_String8: { /* same as TK_STRING, out2-prerelease */
7130071643
assert( pOp->p4.z!=0 );
@@ -71322,22 +71665,34 @@
7132271665
goto too_big;
7132371666
}
7132471667
/* Fall through to the next case, OP_String */
7132571668
}
7132671669
71327
-/* Opcode: String P1 P2 * P4 *
71670
+/* Opcode: String P1 P2 P3 P4 P5
7132871671
** Synopsis: r[P2]='P4' (len=P1)
7132971672
**
7133071673
** The string value P4 of length P1 (bytes) is stored in register P2.
71674
+**
71675
+** If P5!=0 and the content of register P3 is greater than zero, then
71676
+** the datatype of the register P2 is converted to BLOB. The content is
71677
+** the same sequence of bytes, it is merely interpreted as a BLOB instead
71678
+** of a string, as if it had been CAST.
7133171679
*/
7133271680
case OP_String: { /* out2-prerelease */
7133371681
assert( pOp->p4.z!=0 );
7133471682
pOut->flags = MEM_Str|MEM_Static|MEM_Term;
7133571683
pOut->z = pOp->p4.z;
7133671684
pOut->n = pOp->p1;
7133771685
pOut->enc = encoding;
7133871686
UPDATE_MAX_BLOBSIZE(pOut);
71687
+ if( pOp->p5 ){
71688
+ assert( pOp->p3>0 );
71689
+ assert( pOp->p3<=(p->nMem-p->nCursor) );
71690
+ pIn3 = &aMem[pOp->p3];
71691
+ assert( pIn3->flags & MEM_Int );
71692
+ if( pIn3->u.i ) pOut->flags = MEM_Blob|MEM_Static|MEM_Term;
71693
+ }
7133971694
break;
7134071695
}
7134171696
7134271697
/* Opcode: Null P1 P2 P3 * *
7134371698
** Synopsis: r[P2..P3]=NULL
@@ -71780,11 +72135,11 @@
7178072135
** max() aggregate will set to 1 if the current row is not the minimum or
7178172136
** maximum. The P1 register is initialized to 0 by this instruction.
7178272137
**
7178372138
** The interface used by the implementation of the aforementioned functions
7178472139
** to retrieve the collation sequence set by this opcode is not available
71785
-** publicly, only to user functions defined in func.c.
72140
+** publicly. Only built-in functions have access to this feature.
7178672141
*/
7178772142
case OP_CollSeq: {
7178872143
assert( pOp->p4type==P4_COLLSEQ );
7178972144
if( pOp->p1 ){
7179072145
sqlite3VdbeMemSetInt64(&aMem[pOp->p1], 0);
@@ -73325,11 +73680,16 @@
7332573680
** the value of this counter needs to be restored too. */
7332673681
p->nStmtDefCons = db->nDeferredCons;
7332773682
p->nStmtDefImmCons = db->nDeferredImmCons;
7332873683
}
7332973684
73330
- /* Gather the schema version number for checking */
73685
+ /* Gather the schema version number for checking:
73686
+ ** IMPLEMENTATION-OF: R-32195-19465 The schema version is used by SQLite
73687
+ ** each time a query is executed to ensure that the internal cache of the
73688
+ ** schema used when compiling the SQL query matches the schema of the
73689
+ ** database against which the compiled query is actually executed.
73690
+ */
7333173691
sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta);
7333273692
iGen = db->aDb[pOp->p1].pSchema->iGeneration;
7333373693
}else{
7333473694
iGen = iMeta = 0;
7333573695
}
@@ -73493,35 +73853,33 @@
7349373853
** cursors or a single read/write cursor but not both.
7349473854
**
7349573855
** See also OpenRead.
7349673856
*/
7349773857
case OP_ReopenIdx: {
73498
- VdbeCursor *pCur;
73499
-
73500
- assert( pOp->p5==0 );
73501
- assert( pOp->p4type==P4_KEYINFO );
73502
- pCur = p->apCsr[pOp->p1];
73503
- if( pCur && pCur->pgnoRoot==(u32)pOp->p2 ){
73504
- assert( pCur->iDb==pOp->p3 ); /* Guaranteed by the code generator */
73505
- break;
73506
- }
73507
- /* If the cursor is not currently open or is open on a different
73508
- ** index, then fall through into OP_OpenRead to force a reopen */
73509
-}
73510
-case OP_OpenRead:
73511
-case OP_OpenWrite: {
7351273858
int nField;
7351373859
KeyInfo *pKeyInfo;
7351473860
int p2;
7351573861
int iDb;
7351673862
int wrFlag;
7351773863
Btree *pX;
7351873864
VdbeCursor *pCur;
7351973865
Db *pDb;
7352073866
73521
- assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 );
73522
- assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 );
73867
+ assert( pOp->p5==0 || pOp->p5==OPFLAG_SEEKEQ );
73868
+ assert( pOp->p4type==P4_KEYINFO );
73869
+ pCur = p->apCsr[pOp->p1];
73870
+ if( pCur && pCur->pgnoRoot==(u32)pOp->p2 ){
73871
+ assert( pCur->iDb==pOp->p3 ); /* Guaranteed by the code generator */
73872
+ goto open_cursor_set_hints;
73873
+ }
73874
+ /* If the cursor is not currently open or is open on a different
73875
+ ** index, then fall through into OP_OpenRead to force a reopen */
73876
+case OP_OpenRead:
73877
+case OP_OpenWrite:
73878
+
73879
+ assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR|OPFLAG_SEEKEQ))==pOp->p5 );
73880
+ assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 || pOp->p5==OPFLAG_SEEKEQ );
7352373881
assert( p->bIsReader );
7352473882
assert( pOp->opcode==OP_OpenRead || pOp->opcode==OP_ReopenIdx
7352573883
|| p->readOnly==0 );
7352673884
7352773885
if( p->expired ){
@@ -73580,18 +73938,21 @@
7358073938
pCur->nullRow = 1;
7358173939
pCur->isOrdered = 1;
7358273940
pCur->pgnoRoot = p2;
7358373941
rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->pCursor);
7358473942
pCur->pKeyInfo = pKeyInfo;
73585
- assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
73586
- sqlite3BtreeCursorHints(pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));
73587
-
7358873943
/* Set the VdbeCursor.isTable variable. Previous versions of
7358973944
** SQLite used to check if the root-page flags were sane at this point
7359073945
** and report database corruption if they were not, but this check has
7359173946
** since moved into the btree layer. */
7359273947
pCur->isTable = pOp->p4type!=P4_KEYINFO;
73948
+
73949
+open_cursor_set_hints:
73950
+ assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
73951
+ assert( OPFLAG_SEEKEQ==BTREE_SEEK_EQ );
73952
+ sqlite3BtreeCursorHints(pCur->pCursor,
73953
+ (pOp->p5 & (OPFLAG_BULKCSR|OPFLAG_SEEKEQ)));
7359373954
break;
7359473955
}
7359573956
7359673957
/* Opcode: OpenEphemeral P1 P2 * P4 P5
7359773958
** Synopsis: nColumn=P2
@@ -73848,10 +74209,26 @@
7384874209
oc = pOp->opcode;
7384974210
pC->nullRow = 0;
7385074211
#ifdef SQLITE_DEBUG
7385174212
pC->seekOp = pOp->opcode;
7385274213
#endif
74214
+
74215
+ /* For a cursor with the BTREE_SEEK_EQ hint, only the OP_SeekGE and
74216
+ ** OP_SeekLE opcodes are allowed, and these must be immediately followed
74217
+ ** by an OP_IdxGT or OP_IdxLT opcode, respectively, with the same key.
74218
+ */
74219
+#ifdef SQLITE_DEBUG
74220
+ if( sqlite3BtreeCursorHasHint(pC->pCursor, BTREE_SEEK_EQ) ){
74221
+ assert( pOp->opcode==OP_SeekGE || pOp->opcode==OP_SeekLE );
74222
+ assert( pOp[1].opcode==OP_IdxLT || pOp[1].opcode==OP_IdxGT );
74223
+ assert( pOp[1].p1==pOp[0].p1 );
74224
+ assert( pOp[1].p2==pOp[0].p2 );
74225
+ assert( pOp[1].p3==pOp[0].p3 );
74226
+ assert( pOp[1].p4.i==pOp[0].p4.i );
74227
+ }
74228
+#endif
74229
+
7385374230
if( pC->isTable ){
7385474231
/* The input value in P3 might be of any type: integer, real, string,
7385574232
** blob, or NULL. But it needs to be an integer before we can do
7385674233
** the seek, so convert it. */
7385774234
pIn3 = &aMem[pOp->p3];
@@ -75187,34 +75564,19 @@
7518775564
**
7518875565
** See also: Clear
7518975566
*/
7519075567
case OP_Destroy: { /* out2-prerelease */
7519175568
int iMoved;
75192
- int iCnt;
75193
- Vdbe *pVdbe;
7519475569
int iDb;
7519575570
7519675571
assert( p->readOnly==0 );
75197
-#ifndef SQLITE_OMIT_VIRTUALTABLE
75198
- iCnt = 0;
75199
- for(pVdbe=db->pVdbe; pVdbe; pVdbe = pVdbe->pNext){
75200
- if( pVdbe->magic==VDBE_MAGIC_RUN && pVdbe->bIsReader
75201
- && pVdbe->inVtabMethod<2 && pVdbe->pc>=0
75202
- ){
75203
- iCnt++;
75204
- }
75205
- }
75206
-#else
75207
- iCnt = db->nVdbeRead;
75208
-#endif
7520975572
pOut->flags = MEM_Null;
75210
- if( iCnt>1 ){
75573
+ if( db->nVdbeRead > db->nVDestroy+1 ){
7521175574
rc = SQLITE_LOCKED;
7521275575
p->errorAction = OE_Abort;
7521375576
}else{
7521475577
iDb = pOp->p3;
75215
- assert( iCnt==1 );
7521675578
assert( DbMaskTest(p->btreeMask, iDb) );
7521775579
iMoved = 0; /* Not needed. Only to silence a warning. */
7521875580
rc = sqlite3BtreeDropTable(db->aDb[iDb].pBt, pOp->p1, &iMoved);
7521975581
pOut->flags = MEM_Int;
7522075582
pOut->u.i = iMoved;
@@ -75843,14 +76205,16 @@
7584376205
#endif /* SQLITE_OMIT_AUTOINCREMENT */
7584476206
7584576207
/* Opcode: IfPos P1 P2 * * *
7584676208
** Synopsis: if r[P1]>0 goto P2
7584776209
**
75848
-** If the value of register P1 is 1 or greater, jump to P2.
76210
+** Register P1 must contain an integer.
76211
+** If the value of register P1 is 1 or greater, jump to P2 and
76212
+** add the literal value P3 to register P1.
7584976213
**
75850
-** It is illegal to use this instruction on a register that does
75851
-** not contain an integer. An assertion fault will result if you try.
76214
+** If the initial value of register P1 is less than 1, then the
76215
+** value is unchanged and control passes through to the next instruction.
7585276216
*/
7585376217
case OP_IfPos: { /* jump, in1 */
7585476218
pIn1 = &aMem[pOp->p1];
7585576219
assert( pIn1->flags&MEM_Int );
7585676220
VdbeBranchTaken( pIn1->u.i>0, 2);
@@ -75875,27 +76239,63 @@
7587576239
pc = pOp->p2 - 1;
7587676240
}
7587776241
break;
7587876242
}
7587976243
75880
-/* Opcode: IfZero P1 P2 P3 * *
75881
-** Synopsis: r[P1]+=P3, if r[P1]==0 goto P2
76244
+/* Opcode: IfNotZero P1 P2 P3 * *
76245
+** Synopsis: if r[P1]!=0 then r[P1]+=P3, goto P2
7588276246
**
75883
-** The register P1 must contain an integer. Add literal P3 to the
75884
-** value in register P1. If the result is exactly 0, jump to P2.
76247
+** Register P1 must contain an integer. If the content of register P1 is
76248
+** initially nonzero, then add P3 to P1 and jump to P2. If register P1 is
76249
+** initially zero, leave it unchanged and fall through.
7588576250
*/
75886
-case OP_IfZero: { /* jump, in1 */
76251
+case OP_IfNotZero: { /* jump, in1 */
76252
+ pIn1 = &aMem[pOp->p1];
76253
+ assert( pIn1->flags&MEM_Int );
76254
+ VdbeBranchTaken(pIn1->u.i<0, 2);
76255
+ if( pIn1->u.i ){
76256
+ pIn1->u.i += pOp->p3;
76257
+ pc = pOp->p2 - 1;
76258
+ }
76259
+ break;
76260
+}
76261
+
76262
+/* Opcode: DecrJumpZero P1 P2 * * *
76263
+** Synopsis: if (--r[P1])==0 goto P2
76264
+**
76265
+** Register P1 must hold an integer. Decrement the value in register P1
76266
+** then jump to P2 if the new value is exactly zero.
76267
+*/
76268
+case OP_DecrJumpZero: { /* jump, in1 */
7588776269
pIn1 = &aMem[pOp->p1];
7588876270
assert( pIn1->flags&MEM_Int );
75889
- pIn1->u.i += pOp->p3;
76271
+ pIn1->u.i--;
7589076272
VdbeBranchTaken(pIn1->u.i==0, 2);
7589176273
if( pIn1->u.i==0 ){
7589276274
pc = pOp->p2 - 1;
7589376275
}
7589476276
break;
7589576277
}
7589676278
76279
+
76280
+/* Opcode: JumpZeroIncr P1 P2 * * *
76281
+** Synopsis: if (r[P1]++)==0 ) goto P2
76282
+**
76283
+** The register P1 must contain an integer. If register P1 is initially
76284
+** zero, then jump to P2. Increment register P1 regardless of whether or
76285
+** not the jump is taken.
76286
+*/
76287
+case OP_JumpZeroIncr: { /* jump, in1 */
76288
+ pIn1 = &aMem[pOp->p1];
76289
+ assert( pIn1->flags&MEM_Int );
76290
+ VdbeBranchTaken(pIn1->u.i==0, 2);
76291
+ if( (pIn1->u.i++)==0 ){
76292
+ pc = pOp->p2 - 1;
76293
+ }
76294
+ break;
76295
+}
76296
+
7589776297
/* Opcode: AggStep * P2 P3 P4 P5
7589876298
** Synopsis: accum=r[P3] step(r[P2@P5])
7589976299
**
7590076300
** Execute the step function for an aggregate. The
7590176301
** function has P5 arguments. P4 is a pointer to the FuncDef
@@ -76229,17 +76629,33 @@
7622976629
break;
7623076630
}
7623176631
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7623276632
7623376633
#ifndef SQLITE_OMIT_VIRTUALTABLE
76234
-/* Opcode: VCreate P1 * * P4 *
76634
+/* Opcode: VCreate P1 P2 * * *
7623576635
**
76236
-** P4 is the name of a virtual table in database P1. Call the xCreate method
76237
-** for that table.
76636
+** P2 is a register that holds the name of a virtual table in database
76637
+** P1. Call the xCreate method for that table.
7623876638
*/
7623976639
case OP_VCreate: {
76240
- rc = sqlite3VtabCallCreate(db, pOp->p1, pOp->p4.z, &p->zErrMsg);
76640
+ Mem sMem; /* For storing the record being decoded */
76641
+ const char *zTab; /* Name of the virtual table */
76642
+
76643
+ memset(&sMem, 0, sizeof(sMem));
76644
+ sMem.db = db;
76645
+ /* Because P2 is always a static string, it is impossible for the
76646
+ ** sqlite3VdbeMemCopy() to fail */
76647
+ assert( (aMem[pOp->p2].flags & MEM_Str)!=0 );
76648
+ assert( (aMem[pOp->p2].flags & MEM_Static)!=0 );
76649
+ rc = sqlite3VdbeMemCopy(&sMem, &aMem[pOp->p2]);
76650
+ assert( rc==SQLITE_OK );
76651
+ zTab = (const char*)sqlite3_value_text(&sMem);
76652
+ assert( zTab || db->mallocFailed );
76653
+ if( zTab ){
76654
+ rc = sqlite3VtabCallCreate(db, pOp->p1, zTab, &p->zErrMsg);
76655
+ }
76656
+ sqlite3VdbeMemRelease(&sMem);
7624176657
break;
7624276658
}
7624376659
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7624476660
7624576661
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -76247,13 +76663,13 @@
7624776663
**
7624876664
** P4 is the name of a virtual table in database P1. Call the xDestroy method
7624976665
** of that table.
7625076666
*/
7625176667
case OP_VDestroy: {
76252
- p->inVtabMethod = 2;
76668
+ db->nVDestroy++;
7625376669
rc = sqlite3VtabCallDestroy(db, pOp->p1, pOp->p4.z);
76254
- p->inVtabMethod = 0;
76670
+ db->nVDestroy--;
7625576671
break;
7625676672
}
7625776673
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7625876674
7625976675
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -76265,18 +76681,21 @@
7626576681
*/
7626676682
case OP_VOpen: {
7626776683
VdbeCursor *pCur;
7626876684
sqlite3_vtab_cursor *pVtabCursor;
7626976685
sqlite3_vtab *pVtab;
76270
- sqlite3_module *pModule;
76686
+ const sqlite3_module *pModule;
7627176687
7627276688
assert( p->bIsReader );
7627376689
pCur = 0;
7627476690
pVtabCursor = 0;
7627576691
pVtab = pOp->p4.pVtab->pVtab;
76276
- pModule = (sqlite3_module *)pVtab->pModule;
76277
- assert(pVtab && pModule);
76692
+ if( pVtab==0 || NEVER(pVtab->pModule==0) ){
76693
+ rc = SQLITE_LOCKED;
76694
+ break;
76695
+ }
76696
+ pModule = pVtab->pModule;
7627876697
rc = pModule->xOpen(pVtab, &pVtabCursor);
7627976698
sqlite3VtabImportErrmsg(p, pVtab);
7628076699
if( SQLITE_OK==rc ){
7628176700
/* Initialize sqlite3_vtab_cursor base class */
7628276701
pVtabCursor->pVtab = pVtab;
@@ -76283,10 +76702,11 @@
7628376702
7628476703
/* Initialize vdbe cursor object */
7628576704
pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
7628676705
if( pCur ){
7628776706
pCur->pVtabCursor = pVtabCursor;
76707
+ pVtab->nRef++;
7628876708
}else{
7628976709
db->mallocFailed = 1;
7629076710
pModule->xClose(pVtabCursor);
7629176711
}
7629276712
}
@@ -76348,13 +76768,11 @@
7634876768
apArg = p->apArg;
7634976769
for(i = 0; i<nArg; i++){
7635076770
apArg[i] = &pArgc[i+1];
7635176771
}
7635276772
76353
- p->inVtabMethod = 1;
7635476773
rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg);
76355
- p->inVtabMethod = 0;
7635676774
sqlite3VtabImportErrmsg(p, pVtab);
7635776775
if( rc==SQLITE_OK ){
7635876776
res = pModule->xEof(pVtabCursor);
7635976777
}
7636076778
VdbeBranchTaken(res!=0,2);
@@ -76440,13 +76858,11 @@
7644076858
** underlying implementation to return an error if one occurs during
7644176859
** xNext(). Instead, if an error occurs, true is returned (indicating that
7644276860
** data is available) and the error code returned when xColumn or
7644376861
** some other method is next invoked on the save virtual table cursor.
7644476862
*/
76445
- p->inVtabMethod = 1;
7644676863
rc = pModule->xNext(pCur->pVtabCursor);
76447
- p->inVtabMethod = 0;
7644876864
sqlite3VtabImportErrmsg(p, pVtab);
7644976865
if( rc==SQLITE_OK ){
7645076866
res = pModule->xEof(pCur->pVtabCursor);
7645176867
}
7645276868
VdbeBranchTaken(!res,2);
@@ -76517,11 +76933,11 @@
7651776933
** P5 is the error actions (OE_Replace, OE_Fail, OE_Ignore, etc) to
7651876934
** apply in the case of a constraint failure on an insert or update.
7651976935
*/
7652076936
case OP_VUpdate: {
7652176937
sqlite3_vtab *pVtab;
76522
- sqlite3_module *pModule;
76938
+ const sqlite3_module *pModule;
7652376939
int nArg;
7652476940
int i;
7652576941
sqlite_int64 rowid;
7652676942
Mem **apArg;
7652776943
Mem *pX;
@@ -76529,11 +76945,15 @@
7652976945
assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback
7653076946
|| pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace
7653176947
);
7653276948
assert( p->readOnly==0 );
7653376949
pVtab = pOp->p4.pVtab->pVtab;
76534
- pModule = (sqlite3_module *)pVtab->pModule;
76950
+ if( pVtab==0 || NEVER(pVtab->pModule==0) ){
76951
+ rc = SQLITE_LOCKED;
76952
+ break;
76953
+ }
76954
+ pModule = pVtab->pModule;
7653576955
nArg = pOp->p2;
7653676956
assert( pOp->p4type==P4_VTAB );
7653776957
if( ALWAYS(pModule->xUpdate) ){
7653876958
u8 vtabOnConflict = db->vtabOnConflict;
7653976959
apArg = p->apArg;
@@ -78399,10 +78819,11 @@
7839978819
sqlite3 *db, /* Database handle doing sort */
7840078820
i64 nExtend, /* Attempt to extend file to this size */
7840178821
sqlite3_file **ppFd
7840278822
){
7840378823
int rc;
78824
+ if( sqlite3FaultSim(202) ) return SQLITE_IOERR_ACCESS;
7840478825
rc = sqlite3OsOpenMalloc(db->pVfs, 0, ppFd,
7840578826
SQLITE_OPEN_TEMP_JOURNAL |
7840678827
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE |
7840778828
SQLITE_OPEN_EXCLUSIVE | SQLITE_OPEN_DELETEONCLOSE, &rc
7840878829
);
@@ -81990,14 +82411,15 @@
8199082411
** and the pExpr parameter is returned unchanged.
8199182412
*/
8199282413
SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(
8199382414
Parse *pParse, /* Parsing context */
8199482415
Expr *pExpr, /* Add the "COLLATE" clause to this expression */
81995
- const Token *pCollName /* Name of collating sequence */
82416
+ const Token *pCollName, /* Name of collating sequence */
82417
+ int dequote /* True to dequote pCollName */
8199682418
){
8199782419
if( pCollName->n>0 ){
81998
- Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, 1);
82420
+ Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, dequote);
8199982421
if( pNew ){
8200082422
pNew->pLeft = pExpr;
8200182423
pNew->flags |= EP_Collate|EP_Skip;
8200282424
pExpr = pNew;
8200382425
}
@@ -82007,11 +82429,11 @@
8200782429
SQLITE_PRIVATE Expr *sqlite3ExprAddCollateString(Parse *pParse, Expr *pExpr, const char *zC){
8200882430
Token s;
8200982431
assert( zC!=0 );
8201082432
s.z = zC;
8201182433
s.n = sqlite3Strlen30(s.z);
82012
- return sqlite3ExprAddCollateToken(pParse, pExpr, &s);
82434
+ return sqlite3ExprAddCollateToken(pParse, pExpr, &s, 0);
8201382435
}
8201482436
8201582437
/*
8201682438
** Skip over any TK_COLLATE or TK_AS operators and any unlikely()
8201782439
** or likelihood() function at the root of an expression.
@@ -82317,10 +82739,11 @@
8231782739
**
8231882740
** Also propagate all EP_Propagate flags from the Expr.x.pList into
8231982741
** Expr.flags.
8232082742
*/
8232182743
SQLITE_PRIVATE void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){
82744
+ if( pParse->nErr ) return;
8232282745
exprSetHeight(p);
8232382746
sqlite3ExprCheckHeight(pParse, p->nHeight);
8232482747
}
8232582748
8232682749
/*
@@ -87031,11 +87454,14 @@
8703187454
/* Ensure the default expression is something that sqlite3ValueFromExpr()
8703287455
** can handle (i.e. not CURRENT_TIME etc.)
8703387456
*/
8703487457
if( pDflt ){
8703587458
sqlite3_value *pVal = 0;
87036
- if( sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal) ){
87459
+ int rc;
87460
+ rc = sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal);
87461
+ assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
87462
+ if( rc!=SQLITE_OK ){
8703787463
db->mallocFailed = 1;
8703887464
return;
8703987465
}
8704087466
if( !pVal ){
8704187467
sqlite3ErrorMsg(pParse, "Cannot add a column with non-constant default");
@@ -93094,10 +93520,11 @@
9309493520
}
9309593521
if( pIdx->onError==OE_Default ){
9309693522
pIdx->onError = pIndex->onError;
9309793523
}
9309893524
}
93525
+ pRet = pIdx;
9309993526
goto exit_create_index;
9310093527
}
9310193528
}
9310293529
}
9310393530
@@ -95553,11 +95980,13 @@
9555395980
9555495981
/*
9555595982
** Return the collating function associated with a function.
9555695983
*/
9555795984
static CollSeq *sqlite3GetFuncCollSeq(sqlite3_context *context){
95558
- VdbeOp *pOp = &context->pVdbe->aOp[context->iOp-1];
95985
+ VdbeOp *pOp;
95986
+ assert( context->pVdbe!=0 );
95987
+ pOp = &context->pVdbe->aOp[context->iOp-1];
9555995988
assert( pOp->opcode==OP_CollSeq );
9556095989
assert( pOp->p4type==P4_COLLSEQ );
9556195990
return pOp->p4.pColl;
9556295991
}
9556395992
@@ -97181,10 +97610,15 @@
9718197610
** pExpr points to an expression which implements a function. If
9718297611
** it is appropriate to apply the LIKE optimization to that function
9718397612
** then set aWc[0] through aWc[2] to the wildcard characters and
9718497613
** return TRUE. If the function is not a LIKE-style function then
9718597614
** return FALSE.
97615
+**
97616
+** *pIsNocase is set to true if uppercase and lowercase are equivalent for
97617
+** the function (default for LIKE). If the function makes the distinction
97618
+** between uppercase and lowercase (as does GLOB) then *pIsNocase is set to
97619
+** false.
9718697620
*/
9718797621
SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
9718897622
FuncDef *pDef;
9718997623
if( pExpr->op!=TK_FUNCTION
9719097624
|| !pExpr->x.pList
@@ -102972,10 +103406,21 @@
102972103406
}
102973103407
102974103408
/* Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS
102975103409
** connection. If it returns SQLITE_OK, then assume that the VFS
102976103410
** handled the pragma and generate a no-op prepared statement.
103411
+ **
103412
+ ** IMPLEMENTATION-OF: R-12238-55120 Whenever a PRAGMA statement is parsed,
103413
+ ** an SQLITE_FCNTL_PRAGMA file control is sent to the open sqlite3_file
103414
+ ** object corresponding to the database file to which the pragma
103415
+ ** statement refers.
103416
+ **
103417
+ ** IMPLEMENTATION-OF: R-29875-31678 The argument to the SQLITE_FCNTL_PRAGMA
103418
+ ** file control is an array of pointers to strings (char**) in which the
103419
+ ** second element of the array is the name of the pragma and the third
103420
+ ** element is the argument to the pragma or NULL if the pragma has no
103421
+ ** argument.
102977103422
*/
102978103423
aFcntl[0] = 0;
102979103424
aFcntl[1] = zLeft;
102980103425
aFcntl[2] = zRight;
102981103426
aFcntl[3] = 0;
@@ -103732,34 +104177,46 @@
103732104177
Index *pIdx;
103733104178
Table *pTab;
103734104179
pIdx = sqlite3FindIndex(db, zRight, zDb);
103735104180
if( pIdx ){
103736104181
int i;
103737
- int mx = pPragma->iArg ? pIdx->nColumn : pIdx->nKeyCol;
104182
+ int mx;
104183
+ if( pPragma->iArg ){
104184
+ /* PRAGMA index_xinfo (newer version with more rows and columns) */
104185
+ mx = pIdx->nColumn;
104186
+ pParse->nMem = 6;
104187
+ }else{
104188
+ /* PRAGMA index_info (legacy version) */
104189
+ mx = pIdx->nKeyCol;
104190
+ pParse->nMem = 3;
104191
+ }
103738104192
pTab = pIdx->pTable;
103739
- sqlite3VdbeSetNumCols(v, 6);
103740
- pParse->nMem = 6;
104193
+ sqlite3VdbeSetNumCols(v, pParse->nMem);
103741104194
sqlite3CodeVerifySchema(pParse, iDb);
103742104195
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", SQLITE_STATIC);
103743104196
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", SQLITE_STATIC);
103744104197
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", SQLITE_STATIC);
103745
- sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "desc", SQLITE_STATIC);
103746
- sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "coll", SQLITE_STATIC);
103747
- sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "key", SQLITE_STATIC);
104198
+ if( pPragma->iArg ){
104199
+ sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "desc", SQLITE_STATIC);
104200
+ sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "coll", SQLITE_STATIC);
104201
+ sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "key", SQLITE_STATIC);
104202
+ }
103748104203
for(i=0; i<mx; i++){
103749104204
i16 cnum = pIdx->aiColumn[i];
103750104205
sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
103751104206
sqlite3VdbeAddOp2(v, OP_Integer, cnum, 2);
103752104207
if( cnum<0 ){
103753104208
sqlite3VdbeAddOp2(v, OP_Null, 0, 3);
103754104209
}else{
103755104210
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0);
103756104211
}
103757
- sqlite3VdbeAddOp2(v, OP_Integer, pIdx->aSortOrder[i], 4);
103758
- sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, pIdx->azColl[i], 0);
103759
- sqlite3VdbeAddOp2(v, OP_Integer, i<pIdx->nKeyCol, 6);
103760
- sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
104212
+ if( pPragma->iArg ){
104213
+ sqlite3VdbeAddOp2(v, OP_Integer, pIdx->aSortOrder[i], 4);
104214
+ sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, pIdx->azColl[i], 0);
104215
+ sqlite3VdbeAddOp2(v, OP_Integer, i<pIdx->nKeyCol, 6);
104216
+ }
104217
+ sqlite3VdbeAddOp2(v, OP_ResultRow, 1, pParse->nMem);
103761104218
}
103762104219
}
103763104220
}
103764104221
break;
103765104222
@@ -104457,12 +104914,13 @@
104457104914
#endif
104458104915
104459104916
/*
104460104917
** PRAGMA shrink_memory
104461104918
**
104462
- ** This pragma attempts to free as much memory as possible from the
104463
- ** current database connection.
104919
+ ** IMPLEMENTATION-OF: R-23445-46109 This pragma causes the database
104920
+ ** connection on which it is invoked to free up as much memory as it
104921
+ ** can, by calling sqlite3_db_release_memory().
104464104922
*/
104465104923
case PragTyp_SHRINK_MEMORY: {
104466104924
sqlite3_db_release_memory(db);
104467104925
break;
104468104926
}
@@ -104487,12 +104945,16 @@
104487104945
104488104946
/*
104489104947
** PRAGMA soft_heap_limit
104490104948
** PRAGMA soft_heap_limit = N
104491104949
**
104492
- ** Call sqlite3_soft_heap_limit64(N). Return the result. If N is omitted,
104493
- ** use -1.
104950
+ ** IMPLEMENTATION-OF: R-26343-45930 This pragma invokes the
104951
+ ** sqlite3_soft_heap_limit64() interface with the argument N, if N is
104952
+ ** specified and is a non-negative integer.
104953
+ ** IMPLEMENTATION-OF: R-64451-07163 The soft_heap_limit pragma always
104954
+ ** returns the same integer that would be returned by the
104955
+ ** sqlite3_soft_heap_limit64(-1) C-language function.
104494104956
*/
104495104957
case PragTyp_SOFT_HEAP_LIMIT: {
104496104958
sqlite3_int64 N;
104497104959
if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){
104498104960
sqlite3_soft_heap_limit64(N);
@@ -106065,24 +106527,21 @@
106065106527
}else{
106066106528
op = OP_IdxInsert;
106067106529
}
106068106530
sqlite3VdbeAddOp2(v, op, pSort->iECursor, regRecord);
106069106531
if( pSelect->iLimit ){
106070
- int addr1, addr2;
106532
+ int addr;
106071106533
int iLimit;
106072106534
if( pSelect->iOffset ){
106073106535
iLimit = pSelect->iOffset+1;
106074106536
}else{
106075106537
iLimit = pSelect->iLimit;
106076106538
}
106077
- addr1 = sqlite3VdbeAddOp1(v, OP_IfZero, iLimit); VdbeCoverage(v);
106078
- sqlite3VdbeAddOp2(v, OP_AddImm, iLimit, -1);
106079
- addr2 = sqlite3VdbeAddOp0(v, OP_Goto);
106080
- sqlite3VdbeJumpHere(v, addr1);
106539
+ addr = sqlite3VdbeAddOp3(v, OP_IfNotZero, iLimit, 0, -1); VdbeCoverage(v);
106081106540
sqlite3VdbeAddOp1(v, OP_Last, pSort->iECursor);
106082106541
sqlite3VdbeAddOp1(v, OP_Delete, pSort->iECursor);
106083
- sqlite3VdbeJumpHere(v, addr2);
106542
+ sqlite3VdbeJumpHere(v, addr);
106084106543
}
106085106544
}
106086106545
106087106546
/*
106088106547
** Add code to implement the OFFSET
@@ -106475,11 +106934,11 @@
106475106934
/* Jump to the end of the loop if the LIMIT is reached. Except, if
106476106935
** there is a sorter, in which case the sorter has already limited
106477106936
** the output for us.
106478106937
*/
106479106938
if( pSort==0 && p->iLimit ){
106480
- sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1); VdbeCoverage(v);
106939
+ sqlite3VdbeAddOp2(v, OP_DecrJumpZero, p->iLimit, iBreak); VdbeCoverage(v);
106481106940
}
106482106941
}
106483106942
106484106943
/*
106485106944
** Allocate a KeyInfo object sufficient for an index of N key columns and
@@ -107328,11 +107787,11 @@
107328107787
}
107329107788
}else{
107330107789
sqlite3ExprCode(pParse, p->pLimit, iLimit);
107331107790
sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit); VdbeCoverage(v);
107332107791
VdbeComment((v, "LIMIT counter"));
107333
- sqlite3VdbeAddOp2(v, OP_IfZero, iLimit, iBreak); VdbeCoverage(v);
107792
+ sqlite3VdbeAddOp2(v, OP_IfNot, iLimit, iBreak); VdbeCoverage(v);
107334107793
}
107335107794
if( p->pOffset ){
107336107795
p->iOffset = iOffset = ++pParse->nMem;
107337107796
pParse->nMem++; /* Allocate an extra register for limit+offset */
107338107797
sqlite3ExprCode(pParse, p->pOffset, iOffset);
@@ -107547,11 +108006,11 @@
107547108006
addrCont = sqlite3VdbeMakeLabel(v);
107548108007
codeOffset(v, regOffset, addrCont);
107549108008
selectInnerLoop(pParse, p, p->pEList, iCurrent,
107550108009
0, 0, pDest, addrCont, addrBreak);
107551108010
if( regLimit ){
107552
- sqlite3VdbeAddOp3(v, OP_IfZero, regLimit, addrBreak, -1);
108011
+ sqlite3VdbeAddOp2(v, OP_DecrJumpZero, regLimit, addrBreak);
107553108012
VdbeCoverage(v);
107554108013
}
107555108014
sqlite3VdbeResolveLabel(v, addrCont);
107556108015
107557108016
/* Execute the recursive SELECT taking the single row in Current as
@@ -107772,11 +108231,11 @@
107772108231
}
107773108232
p->pPrior = 0;
107774108233
p->iLimit = pPrior->iLimit;
107775108234
p->iOffset = pPrior->iOffset;
107776108235
if( p->iLimit ){
107777
- addr = sqlite3VdbeAddOp1(v, OP_IfZero, p->iLimit); VdbeCoverage(v);
108236
+ addr = sqlite3VdbeAddOp1(v, OP_IfNot, p->iLimit); VdbeCoverage(v);
107778108237
VdbeComment((v, "Jump ahead if LIMIT reached"));
107779108238
}
107780108239
explainSetInteger(iSub2, pParse->iNextSelectId);
107781108240
rc = sqlite3Select(pParse, p, &dest);
107782108241
testcase( rc!=SQLITE_OK );
@@ -108173,11 +108632,11 @@
108173108632
}
108174108633
108175108634
/* Jump to the end of the loop if the LIMIT is reached.
108176108635
*/
108177108636
if( p->iLimit ){
108178
- sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1); VdbeCoverage(v);
108637
+ sqlite3VdbeAddOp2(v, OP_DecrJumpZero, p->iLimit, iBreak); VdbeCoverage(v);
108179108638
}
108180108639
108181108640
/* Generate the subroutine return
108182108641
*/
108183108642
sqlite3VdbeResolveLabel(v, iContinue);
@@ -109540,11 +109999,11 @@
109540109999
sqlite3WalkSelect(pWalker, bMayRecursive ? pSel->pPrior : pSel);
109541110000
109542110001
for(pLeft=pSel; pLeft->pPrior; pLeft=pLeft->pPrior);
109543110002
pEList = pLeft->pEList;
109544110003
if( pCte->pCols ){
109545
- if( pEList->nExpr!=pCte->pCols->nExpr ){
110004
+ if( pEList && pEList->nExpr!=pCte->pCols->nExpr ){
109546110005
sqlite3ErrorMsg(pParse, "table %s has %d values for %d columns",
109547110006
pCte->zName, pEList->nExpr, pCte->pCols->nExpr
109548110007
);
109549110008
pParse->pWith = pSavedWith;
109550110009
return SQLITE_ERROR;
@@ -113966,10 +114425,11 @@
113966114425
*/
113967114426
if( !db->init.busy ){
113968114427
char *zStmt;
113969114428
char *zWhere;
113970114429
int iDb;
114430
+ int iReg;
113971114431
Vdbe *v;
113972114432
113973114433
/* Compute the complete text of the CREATE VIRTUAL TABLE statement */
113974114434
if( pEnd ){
113975114435
pParse->sNameToken.n = (int)(pEnd->z - pParse->sNameToken.z) + pEnd->n;
@@ -114000,12 +114460,14 @@
114000114460
sqlite3ChangeCookie(pParse, iDb);
114001114461
114002114462
sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
114003114463
zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
114004114464
sqlite3VdbeAddParseSchemaOp(v, iDb, zWhere);
114005
- sqlite3VdbeAddOp4(v, OP_VCreate, iDb, 0, 0,
114006
- pTab->zName, sqlite3Strlen30(pTab->zName) + 1);
114465
+
114466
+ iReg = ++pParse->nMem;
114467
+ sqlite3VdbeAddOp4(v, OP_String8, 0, iReg, 0, pTab->zName, 0);
114468
+ sqlite3VdbeAddOp2(v, OP_VCreate, iDb, iReg);
114007114469
}
114008114470
114009114471
/* If we are rereading the sqlite_master table create the in-memory
114010114472
** record of the table. The xConnect() method is not called until
114011114473
** the first time the virtual table is used in an SQL statement. This
@@ -114354,15 +114816,19 @@
114354114816
int rc = SQLITE_OK;
114355114817
Table *pTab;
114356114818
114357114819
pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
114358114820
if( ALWAYS(pTab!=0 && pTab->pVTable!=0) ){
114359
- VTable *p = vtabDisconnectAll(db, pTab);
114360
-
114361
- assert( rc==SQLITE_OK );
114821
+ VTable *p;
114822
+ for(p=pTab->pVTable; p; p=p->pNext){
114823
+ assert( p->pVtab );
114824
+ if( p->pVtab->nRef>0 ){
114825
+ return SQLITE_LOCKED;
114826
+ }
114827
+ }
114828
+ p = vtabDisconnectAll(db, pTab);
114362114829
rc = p->pMod->pModule->xDestroy(p->pVtab);
114363
-
114364114830
/* Remove the sqlite3_vtab* from the aVTrans[] array, if applicable */
114365114831
if( rc==SQLITE_OK ){
114366114832
assert( pTab->pVTable==p && p->pNext==0 );
114367114833
p->pVtab = 0;
114368114834
pTab->pVTable = 0;
@@ -114787,10 +115253,12 @@
114787115253
int addrNxt; /* Jump here to start the next IN combination */
114788115254
int addrSkip; /* Jump here for next iteration of skip-scan */
114789115255
int addrCont; /* Jump here to continue with the next loop cycle */
114790115256
int addrFirst; /* First instruction of interior of the loop */
114791115257
int addrBody; /* Beginning of the body of this loop */
115258
+ int iLikeRepCntr; /* LIKE range processing counter register */
115259
+ int addrLikeRep; /* LIKE range processing address */
114792115260
u8 iFrom; /* Which entry in the FROM clause */
114793115261
u8 op, p3, p5; /* Opcode, P3 & P5 of the opcode that ends the loop */
114794115262
int p1, p2; /* Operands of the opcode used to ends the loop */
114795115263
union { /* Information that depends on pWLoop->wsFlags */
114796115264
struct {
@@ -114971,11 +115439,11 @@
114971115439
WhereOrInfo *pOrInfo; /* Extra information if (eOperator & WO_OR)!=0 */
114972115440
WhereAndInfo *pAndInfo; /* Extra information if (eOperator& WO_AND)!=0 */
114973115441
} u;
114974115442
LogEst truthProb; /* Probability of truth for this expression */
114975115443
u16 eOperator; /* A WO_xx value describing <op> */
114976
- u8 wtFlags; /* TERM_xxx bit flags. See below */
115444
+ u16 wtFlags; /* TERM_xxx bit flags. See below */
114977115445
u8 nChild; /* Number of children that must disable us */
114978115446
WhereClause *pWC; /* The clause this term is part of */
114979115447
Bitmask prereqRight; /* Bitmask of tables used by pExpr->pRight */
114980115448
Bitmask prereqAll; /* Bitmask of tables referenced by pExpr */
114981115449
};
@@ -114993,10 +115461,13 @@
114993115461
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
114994115462
# define TERM_VNULL 0x80 /* Manufactured x>NULL or x<=NULL term */
114995115463
#else
114996115464
# define TERM_VNULL 0x00 /* Disabled if not using stat3 */
114997115465
#endif
115466
+#define TERM_LIKEOPT 0x100 /* Virtual terms from the LIKE optimization */
115467
+#define TERM_LIKECOND 0x200 /* Conditionally this LIKE operator term */
115468
+#define TERM_LIKE 0x400 /* The original LIKE operator */
114998115469
114999115470
/*
115000115471
** An instance of the WhereScan object is used as an iterator for locating
115001115472
** terms in the WHERE clause that are useful to the query planner.
115002115473
*/
@@ -115368,11 +115839,11 @@
115368115839
** WARNING: This routine might reallocate the space used to store
115369115840
** WhereTerms. All pointers to WhereTerms should be invalidated after
115370115841
** calling this routine. Such pointers may be reinitialized by referencing
115371115842
** the pWC->a[] array.
115372115843
*/
115373
-static int whereClauseInsert(WhereClause *pWC, Expr *p, u8 wtFlags){
115844
+static int whereClauseInsert(WhereClause *pWC, Expr *p, u16 wtFlags){
115374115845
WhereTerm *pTerm;
115375115846
int idx;
115376115847
testcase( wtFlags & TERM_VIRTUAL );
115377115848
if( pWC->nTerm>=pWC->nSlot ){
115378115849
WhereTerm *pOld = pWC->a;
@@ -115793,11 +116264,15 @@
115793116264
** Check to see if the given expression is a LIKE or GLOB operator that
115794116265
** can be optimized using inequality constraints. Return TRUE if it is
115795116266
** so and false if not.
115796116267
**
115797116268
** In order for the operator to be optimizible, the RHS must be a string
115798
-** literal that does not begin with a wildcard.
116269
+** literal that does not begin with a wildcard. The LHS must be a column
116270
+** that may only be NULL, a string, or a BLOB, never a number. (This means
116271
+** that virtual tables cannot participate in the LIKE optimization.) If the
116272
+** collating sequence for the column on the LHS must be appropriate for
116273
+** the operator.
115799116274
*/
115800116275
static int isLikeOrGlob(
115801116276
Parse *pParse, /* Parsing and code generating context */
115802116277
Expr *pExpr, /* Test this expression */
115803116278
Expr **ppPrefix, /* Pointer to TK_STRING expression with pattern prefix */
@@ -115822,11 +116297,11 @@
115822116297
#endif
115823116298
pList = pExpr->x.pList;
115824116299
pLeft = pList->a[1].pExpr;
115825116300
if( pLeft->op!=TK_COLUMN
115826116301
|| sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT
115827
- || IsVirtual(pLeft->pTab)
116302
+ || IsVirtual(pLeft->pTab) /* Value might be numeric */
115828116303
){
115829116304
/* IMP: R-02065-49465 The left-hand side of the LIKE or GLOB operator must
115830116305
** be the name of an indexed column with TEXT affinity. */
115831116306
return 0;
115832116307
}
@@ -115931,10 +116406,83 @@
115931116406
static void markTermAsChild(WhereClause *pWC, int iChild, int iParent){
115932116407
pWC->a[iChild].iParent = iParent;
115933116408
pWC->a[iChild].truthProb = pWC->a[iParent].truthProb;
115934116409
pWC->a[iParent].nChild++;
115935116410
}
116411
+
116412
+/*
116413
+** Return the N-th AND-connected subterm of pTerm. Or if pTerm is not
116414
+** a conjunction, then return just pTerm when N==0. If N is exceeds
116415
+** the number of available subterms, return NULL.
116416
+*/
116417
+static WhereTerm *whereNthSubterm(WhereTerm *pTerm, int N){
116418
+ if( pTerm->eOperator!=WO_AND ){
116419
+ return N==0 ? pTerm : 0;
116420
+ }
116421
+ if( N<pTerm->u.pAndInfo->wc.nTerm ){
116422
+ return &pTerm->u.pAndInfo->wc.a[N];
116423
+ }
116424
+ return 0;
116425
+}
116426
+
116427
+/*
116428
+** Subterms pOne and pTwo are contained within WHERE clause pWC. The
116429
+** two subterms are in disjunction - they are OR-ed together.
116430
+**
116431
+** If these two terms are both of the form: "A op B" with the same
116432
+** A and B values but different operators and if the operators are
116433
+** compatible (if one is = and the other is <, for example) then
116434
+** add a new virtual AND term to pWC that is the combination of the
116435
+** two.
116436
+**
116437
+** Some examples:
116438
+**
116439
+** x<y OR x=y --> x<=y
116440
+** x=y OR x=y --> x=y
116441
+** x<=y OR x<y --> x<=y
116442
+**
116443
+** The following is NOT generated:
116444
+**
116445
+** x<y OR x>y --> x!=y
116446
+*/
116447
+static void whereCombineDisjuncts(
116448
+ SrcList *pSrc, /* the FROM clause */
116449
+ WhereClause *pWC, /* The complete WHERE clause */
116450
+ WhereTerm *pOne, /* First disjunct */
116451
+ WhereTerm *pTwo /* Second disjunct */
116452
+){
116453
+ u16 eOp = pOne->eOperator | pTwo->eOperator;
116454
+ sqlite3 *db; /* Database connection (for malloc) */
116455
+ Expr *pNew; /* New virtual expression */
116456
+ int op; /* Operator for the combined expression */
116457
+ int idxNew; /* Index in pWC of the next virtual term */
116458
+
116459
+ if( (pOne->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE))==0 ) return;
116460
+ if( (pTwo->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE))==0 ) return;
116461
+ if( (eOp & (WO_EQ|WO_LT|WO_LE))!=eOp
116462
+ && (eOp & (WO_EQ|WO_GT|WO_GE))!=eOp ) return;
116463
+ assert( pOne->pExpr->pLeft!=0 && pOne->pExpr->pRight!=0 );
116464
+ assert( pTwo->pExpr->pLeft!=0 && pTwo->pExpr->pRight!=0 );
116465
+ if( sqlite3ExprCompare(pOne->pExpr->pLeft, pTwo->pExpr->pLeft, -1) ) return;
116466
+ if( sqlite3ExprCompare(pOne->pExpr->pRight, pTwo->pExpr->pRight, -1) )return;
116467
+ /* If we reach this point, it means the two subterms can be combined */
116468
+ if( (eOp & (eOp-1))!=0 ){
116469
+ if( eOp & (WO_LT|WO_LE) ){
116470
+ eOp = WO_LE;
116471
+ }else{
116472
+ assert( eOp & (WO_GT|WO_GE) );
116473
+ eOp = WO_GE;
116474
+ }
116475
+ }
116476
+ db = pWC->pWInfo->pParse->db;
116477
+ pNew = sqlite3ExprDup(db, pOne->pExpr, 0);
116478
+ if( pNew==0 ) return;
116479
+ for(op=TK_EQ; eOp!=(WO_EQ<<(op-TK_EQ)); op++){ assert( op<TK_GE ); }
116480
+ pNew->op = op;
116481
+ idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC);
116482
+ exprAnalyze(pSrc, pWC, idxNew);
116483
+}
115936116484
115937116485
#if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
115938116486
/*
115939116487
** Analyze a term that consists of two or more OR-connected
115940116488
** subterms. So in:
@@ -115956,10 +116504,11 @@
115956116504
** (A) t1.x=t2.y OR t1.x=t2.z OR t1.y=15 OR t1.z=t3.a+5
115957116505
** (B) x=expr1 OR expr2=x OR x=expr3
115958116506
** (C) t1.x=t2.y OR (t1.x=t2.z AND t1.y=15)
115959116507
** (D) x=expr1 OR (y>11 AND y<22 AND z LIKE '*hello*')
115960116508
** (E) (p.a=1 AND q.b=2 AND r.c=3) OR (p.x=4 AND q.y=5 AND r.z=6)
116509
+** (F) x>A OR (x=A AND y>=B)
115961116510
**
115962116511
** CASE 1:
115963116512
**
115964116513
** If all subterms are of the form T.C=expr for some single column of C and
115965116514
** a single table T (as shown in example B above) then create a new virtual
@@ -115971,10 +116520,20 @@
115971116520
** then create a new virtual term like this:
115972116521
**
115973116522
** x IN (expr1,expr2,expr3)
115974116523
**
115975116524
** CASE 2:
116525
+**
116526
+** If there are exactly two disjuncts one side has x>A and the other side
116527
+** has x=A (for the same x and A) then add a new virtual conjunct term to the
116528
+** WHERE clause of the form "x>=A". Example:
116529
+**
116530
+** x>A OR (x=A AND y>B) adds: x>=A
116531
+**
116532
+** The added conjunct can sometimes be helpful in query planning.
116533
+**
116534
+** CASE 3:
115976116535
**
115977116536
** If all subterms are indexable by a single table T, then set
115978116537
**
115979116538
** WhereTerm.eOperator = WO_OR
115980116539
** WhereTerm.u.pOrInfo->indexable |= the cursor number for table T
@@ -116098,15 +116657,29 @@
116098116657
}
116099116658
}
116100116659
}
116101116660
116102116661
/*
116103
- ** Record the set of tables that satisfy case 2. The set might be
116662
+ ** Record the set of tables that satisfy case 3. The set might be
116104116663
** empty.
116105116664
*/
116106116665
pOrInfo->indexable = indexable;
116107116666
pTerm->eOperator = indexable==0 ? 0 : WO_OR;
116667
+
116668
+ /* For a two-way OR, attempt to implementation case 2.
116669
+ */
116670
+ if( indexable && pOrWc->nTerm==2 ){
116671
+ int iOne = 0;
116672
+ WhereTerm *pOne;
116673
+ while( (pOne = whereNthSubterm(&pOrWc->a[0],iOne++))!=0 ){
116674
+ int iTwo = 0;
116675
+ WhereTerm *pTwo;
116676
+ while( (pTwo = whereNthSubterm(&pOrWc->a[1],iTwo++))!=0 ){
116677
+ whereCombineDisjuncts(pSrc, pWC, pOne, pTwo);
116678
+ }
116679
+ }
116680
+ }
116108116681
116109116682
/*
116110116683
** chngToIN holds a set of tables that *might* satisfy case 1. But
116111116684
** we have to do some additional checking to see if case 1 really
116112116685
** is satisfied.
@@ -116233,11 +116806,11 @@
116233116806
pTerm = &pWC->a[idxTerm];
116234116807
markTermAsChild(pWC, idxNew, idxTerm);
116235116808
}else{
116236116809
sqlite3ExprListDelete(db, pList);
116237116810
}
116238
- pTerm->eOperator = WO_NOOP; /* case 1 trumps case 2 */
116811
+ pTerm->eOperator = WO_NOOP; /* case 1 trumps case 3 */
116239116812
}
116240116813
}
116241116814
}
116242116815
#endif /* !SQLITE_OMIT_OR_OPTIMIZATION && !SQLITE_OMIT_SUBQUERY */
116243116816
@@ -116271,11 +116844,11 @@
116271116844
Bitmask prereqLeft; /* Prerequesites of the pExpr->pLeft */
116272116845
Bitmask prereqAll; /* Prerequesites of pExpr */
116273116846
Bitmask extraRight = 0; /* Extra dependencies on LEFT JOIN */
116274116847
Expr *pStr1 = 0; /* RHS of LIKE/GLOB operator */
116275116848
int isComplete = 0; /* RHS of LIKE/GLOB ends with wildcard */
116276
- int noCase = 0; /* LIKE/GLOB distinguishes case */
116849
+ int noCase = 0; /* uppercase equivalent to lowercase */
116277116850
int op; /* Top-level operator. pExpr->op */
116278116851
Parse *pParse = pWInfo->pParse; /* Parsing context */
116279116852
sqlite3 *db = pParse->db; /* Database connection */
116280116853
116281116854
if( db->mallocFailed ){
@@ -116409,16 +116982,19 @@
116409116982
116410116983
#ifndef SQLITE_OMIT_LIKE_OPTIMIZATION
116411116984
/* Add constraints to reduce the search space on a LIKE or GLOB
116412116985
** operator.
116413116986
**
116414
- ** A like pattern of the form "x LIKE 'abc%'" is changed into constraints
116987
+ ** A like pattern of the form "x LIKE 'aBc%'" is changed into constraints
116415116988
**
116416
- ** x>='abc' AND x<'abd' AND x LIKE 'abc%'
116989
+ ** x>='ABC' AND x<'abd' AND x LIKE 'aBc%'
116417116990
**
116418116991
** The last character of the prefix "abc" is incremented to form the
116419
- ** termination condition "abd".
116992
+ ** termination condition "abd". If case is not significant (the default
116993
+ ** for LIKE) then the lower-bound is made all uppercase and the upper-
116994
+ ** bound is made all lowercase so that the bounds also work when comparing
116995
+ ** BLOBs.
116420116996
*/
116421116997
if( pWC->op==TK_AND
116422116998
&& isLikeOrGlob(pParse, pExpr, &pStr1, &isComplete, &noCase)
116423116999
){
116424117000
Expr *pLeft; /* LHS of LIKE/GLOB operator */
@@ -116425,14 +117001,30 @@
116425117001
Expr *pStr2; /* Copy of pStr1 - RHS of LIKE/GLOB operator */
116426117002
Expr *pNewExpr1;
116427117003
Expr *pNewExpr2;
116428117004
int idxNew1;
116429117005
int idxNew2;
116430
- Token sCollSeqName; /* Name of collating sequence */
117006
+ const char *zCollSeqName; /* Name of collating sequence */
117007
+ const u16 wtFlags = TERM_LIKEOPT | TERM_VIRTUAL | TERM_DYNAMIC;
116431117008
116432117009
pLeft = pExpr->x.pList->a[1].pExpr;
116433117010
pStr2 = sqlite3ExprDup(db, pStr1, 0);
117011
+
117012
+ /* Convert the lower bound to upper-case and the upper bound to
117013
+ ** lower-case (upper-case is less than lower-case in ASCII) so that
117014
+ ** the range constraints also work for BLOBs
117015
+ */
117016
+ if( noCase && !pParse->db->mallocFailed ){
117017
+ int i;
117018
+ char c;
117019
+ pTerm->wtFlags |= TERM_LIKE;
117020
+ for(i=0; (c = pStr1->u.zToken[i])!=0; i++){
117021
+ pStr1->u.zToken[i] = sqlite3Toupper(c);
117022
+ pStr2->u.zToken[i] = sqlite3Tolower(c);
117023
+ }
117024
+ }
117025
+
116434117026
if( !db->mallocFailed ){
116435117027
u8 c, *pC; /* Last character before the first wildcard */
116436117028
pC = (u8*)&pStr2->u.zToken[sqlite3Strlen30(pStr2->u.zToken)-1];
116437117029
c = *pC;
116438117030
if( noCase ){
@@ -116445,26 +117037,25 @@
116445117037
if( c=='A'-1 ) isComplete = 0;
116446117038
c = sqlite3UpperToLower[c];
116447117039
}
116448117040
*pC = c + 1;
116449117041
}
116450
- sCollSeqName.z = noCase ? "NOCASE" : "BINARY";
116451
- sCollSeqName.n = 6;
117042
+ zCollSeqName = noCase ? "NOCASE" : "BINARY";
116452117043
pNewExpr1 = sqlite3ExprDup(db, pLeft, 0);
116453
- pNewExpr1 = sqlite3PExpr(pParse, TK_GE,
116454
- sqlite3ExprAddCollateToken(pParse,pNewExpr1,&sCollSeqName),
117044
+ pNewExpr1 = sqlite3PExpr(pParse, TK_GE,
117045
+ sqlite3ExprAddCollateString(pParse,pNewExpr1,zCollSeqName),
116455117046
pStr1, 0);
116456117047
transferJoinMarkings(pNewExpr1, pExpr);
116457
- idxNew1 = whereClauseInsert(pWC, pNewExpr1, TERM_VIRTUAL|TERM_DYNAMIC);
117048
+ idxNew1 = whereClauseInsert(pWC, pNewExpr1, wtFlags);
116458117049
testcase( idxNew1==0 );
116459117050
exprAnalyze(pSrc, pWC, idxNew1);
116460117051
pNewExpr2 = sqlite3ExprDup(db, pLeft, 0);
116461117052
pNewExpr2 = sqlite3PExpr(pParse, TK_LT,
116462
- sqlite3ExprAddCollateToken(pParse,pNewExpr2,&sCollSeqName),
117053
+ sqlite3ExprAddCollateString(pParse,pNewExpr2,zCollSeqName),
116463117054
pStr2, 0);
116464117055
transferJoinMarkings(pNewExpr2, pExpr);
116465
- idxNew2 = whereClauseInsert(pWC, pNewExpr2, TERM_VIRTUAL|TERM_DYNAMIC);
117056
+ idxNew2 = whereClauseInsert(pWC, pNewExpr2, wtFlags);
116466117057
testcase( idxNew2==0 );
116467117058
exprAnalyze(pSrc, pWC, idxNew2);
116468117059
pTerm = &pWC->a[idxTerm];
116469117060
if( isComplete ){
116470117061
markTermAsChild(pWC, idxNew1, idxTerm);
@@ -117074,15 +117665,18 @@
117074117665
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
117075117666
/*
117076117667
** Estimate the location of a particular key among all keys in an
117077117668
** index. Store the results in aStat as follows:
117078117669
**
117079
-** aStat[0] Est. number of rows less than pVal
117080
-** aStat[1] Est. number of rows equal to pVal
117670
+** aStat[0] Est. number of rows less than pRec
117671
+** aStat[1] Est. number of rows equal to pRec
117081117672
**
117082117673
** Return the index of the sample that is the smallest sample that
117083
-** is greater than or equal to pRec.
117674
+** is greater than or equal to pRec. Note that this index is not an index
117675
+** into the aSample[] array - it is an index into a virtual set of samples
117676
+** based on the contents of aSample[] and the number of fields in record
117677
+** pRec.
117084117678
*/
117085117679
static int whereKeyStats(
117086117680
Parse *pParse, /* Database connection */
117087117681
Index *pIdx, /* Index to consider domain of */
117088117682
UnpackedRecord *pRec, /* Vector of values to consider */
@@ -117089,71 +117683,162 @@
117089117683
int roundUp, /* Round up if true. Round down if false */
117090117684
tRowcnt *aStat /* OUT: stats written here */
117091117685
){
117092117686
IndexSample *aSample = pIdx->aSample;
117093117687
int iCol; /* Index of required stats in anEq[] etc. */
117688
+ int i; /* Index of first sample >= pRec */
117689
+ int iSample; /* Smallest sample larger than or equal to pRec */
117094117690
int iMin = 0; /* Smallest sample not yet tested */
117095
- int i = pIdx->nSample; /* Smallest sample larger than or equal to pRec */
117096117691
int iTest; /* Next sample to test */
117097117692
int res; /* Result of comparison operation */
117693
+ int nField; /* Number of fields in pRec */
117694
+ tRowcnt iLower = 0; /* anLt[] + anEq[] of largest sample pRec is > */
117098117695
117099117696
#ifndef SQLITE_DEBUG
117100117697
UNUSED_PARAMETER( pParse );
117101117698
#endif
117102117699
assert( pRec!=0 );
117103
- iCol = pRec->nField - 1;
117104117700
assert( pIdx->nSample>0 );
117105
- assert( pRec->nField>0 && iCol<pIdx->nSampleCol );
117701
+ assert( pRec->nField>0 && pRec->nField<=pIdx->nSampleCol );
117702
+
117703
+ /* Do a binary search to find the first sample greater than or equal
117704
+ ** to pRec. If pRec contains a single field, the set of samples to search
117705
+ ** is simply the aSample[] array. If the samples in aSample[] contain more
117706
+ ** than one fields, all fields following the first are ignored.
117707
+ **
117708
+ ** If pRec contains N fields, where N is more than one, then as well as the
117709
+ ** samples in aSample[] (truncated to N fields), the search also has to
117710
+ ** consider prefixes of those samples. For example, if the set of samples
117711
+ ** in aSample is:
117712
+ **
117713
+ ** aSample[0] = (a, 5)
117714
+ ** aSample[1] = (a, 10)
117715
+ ** aSample[2] = (b, 5)
117716
+ ** aSample[3] = (c, 100)
117717
+ ** aSample[4] = (c, 105)
117718
+ **
117719
+ ** Then the search space should ideally be the samples above and the
117720
+ ** unique prefixes [a], [b] and [c]. But since that is hard to organize,
117721
+ ** the code actually searches this set:
117722
+ **
117723
+ ** 0: (a)
117724
+ ** 1: (a, 5)
117725
+ ** 2: (a, 10)
117726
+ ** 3: (a, 10)
117727
+ ** 4: (b)
117728
+ ** 5: (b, 5)
117729
+ ** 6: (c)
117730
+ ** 7: (c, 100)
117731
+ ** 8: (c, 105)
117732
+ ** 9: (c, 105)
117733
+ **
117734
+ ** For each sample in the aSample[] array, N samples are present in the
117735
+ ** effective sample array. In the above, samples 0 and 1 are based on
117736
+ ** sample aSample[0]. Samples 2 and 3 on aSample[1] etc.
117737
+ **
117738
+ ** Often, sample i of each block of N effective samples has (i+1) fields.
117739
+ ** Except, each sample may be extended to ensure that it is greater than or
117740
+ ** equal to the previous sample in the array. For example, in the above,
117741
+ ** sample 2 is the first sample of a block of N samples, so at first it
117742
+ ** appears that it should be 1 field in size. However, that would make it
117743
+ ** smaller than sample 1, so the binary search would not work. As a result,
117744
+ ** it is extended to two fields. The duplicates that this creates do not
117745
+ ** cause any problems.
117746
+ */
117747
+ nField = pRec->nField;
117748
+ iCol = 0;
117749
+ iSample = pIdx->nSample * nField;
117106117750
do{
117107
- iTest = (iMin+i)/2;
117108
- res = sqlite3VdbeRecordCompare(aSample[iTest].n, aSample[iTest].p, pRec);
117751
+ int iSamp; /* Index in aSample[] of test sample */
117752
+ int n; /* Number of fields in test sample */
117753
+
117754
+ iTest = (iMin+iSample)/2;
117755
+ iSamp = iTest / nField;
117756
+ if( iSamp>0 ){
117757
+ /* The proposed effective sample is a prefix of sample aSample[iSamp].
117758
+ ** Specifically, the shortest prefix of at least (1 + iTest%nField)
117759
+ ** fields that is greater than the previous effective sample. */
117760
+ for(n=(iTest % nField) + 1; n<nField; n++){
117761
+ if( aSample[iSamp-1].anLt[n-1]!=aSample[iSamp].anLt[n-1] ) break;
117762
+ }
117763
+ }else{
117764
+ n = iTest + 1;
117765
+ }
117766
+
117767
+ pRec->nField = n;
117768
+ res = sqlite3VdbeRecordCompare(aSample[iSamp].n, aSample[iSamp].p, pRec);
117109117769
if( res<0 ){
117770
+ iLower = aSample[iSamp].anLt[n-1] + aSample[iSamp].anEq[n-1];
117771
+ iMin = iTest+1;
117772
+ }else if( res==0 && n<nField ){
117773
+ iLower = aSample[iSamp].anLt[n-1];
117110117774
iMin = iTest+1;
117775
+ res = -1;
117111117776
}else{
117112
- i = iTest;
117777
+ iSample = iTest;
117778
+ iCol = n-1;
117113117779
}
117114
- }while( res && iMin<i );
117780
+ }while( res && iMin<iSample );
117781
+ i = iSample / nField;
117115117782
117116117783
#ifdef SQLITE_DEBUG
117117117784
/* The following assert statements check that the binary search code
117118117785
** above found the right answer. This block serves no purpose other
117119117786
** than to invoke the asserts. */
117120
- if( res==0 ){
117121
- /* If (res==0) is true, then sample $i must be equal to pRec */
117122
- assert( i<pIdx->nSample );
117123
- assert( 0==sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)
117124
- || pParse->db->mallocFailed );
117125
- }else{
117126
- /* Otherwise, pRec must be smaller than sample $i and larger than
117127
- ** sample ($i-1). */
117128
- assert( i==pIdx->nSample
117129
- || sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)>0
117130
- || pParse->db->mallocFailed );
117131
- assert( i==0
117132
- || sqlite3VdbeRecordCompare(aSample[i-1].n, aSample[i-1].p, pRec)<0
117133
- || pParse->db->mallocFailed );
117787
+ if( pParse->db->mallocFailed==0 ){
117788
+ if( res==0 ){
117789
+ /* If (res==0) is true, then pRec must be equal to sample i. */
117790
+ assert( i<pIdx->nSample );
117791
+ assert( iCol==nField-1 );
117792
+ pRec->nField = nField;
117793
+ assert( 0==sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)
117794
+ || pParse->db->mallocFailed
117795
+ );
117796
+ }else{
117797
+ /* Unless i==pIdx->nSample, indicating that pRec is larger than
117798
+ ** all samples in the aSample[] array, pRec must be smaller than the
117799
+ ** (iCol+1) field prefix of sample i. */
117800
+ assert( i<=pIdx->nSample && i>=0 );
117801
+ pRec->nField = iCol+1;
117802
+ assert( i==pIdx->nSample
117803
+ || sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)>0
117804
+ || pParse->db->mallocFailed );
117805
+
117806
+ /* if i==0 and iCol==0, then record pRec is smaller than all samples
117807
+ ** in the aSample[] array. Otherwise, if (iCol>0) then pRec must
117808
+ ** be greater than or equal to the (iCol) field prefix of sample i.
117809
+ ** If (i>0), then pRec must also be greater than sample (i-1). */
117810
+ if( iCol>0 ){
117811
+ pRec->nField = iCol;
117812
+ assert( sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)<=0
117813
+ || pParse->db->mallocFailed );
117814
+ }
117815
+ if( i>0 ){
117816
+ pRec->nField = nField;
117817
+ assert( sqlite3VdbeRecordCompare(aSample[i-1].n, aSample[i-1].p, pRec)<0
117818
+ || pParse->db->mallocFailed );
117819
+ }
117820
+ }
117134117821
}
117135117822
#endif /* ifdef SQLITE_DEBUG */
117136117823
117137
- /* At this point, aSample[i] is the first sample that is greater than
117138
- ** or equal to pVal. Or if i==pIdx->nSample, then all samples are less
117139
- ** than pVal. If aSample[i]==pVal, then res==0.
117140
- */
117141117824
if( res==0 ){
117825
+ /* Record pRec is equal to sample i */
117826
+ assert( iCol==nField-1 );
117142117827
aStat[0] = aSample[i].anLt[iCol];
117143117828
aStat[1] = aSample[i].anEq[iCol];
117144117829
}else{
117145
- tRowcnt iLower, iUpper, iGap;
117146
- if( i==0 ){
117147
- iLower = 0;
117148
- iUpper = aSample[0].anLt[iCol];
117830
+ /* At this point, the (iCol+1) field prefix of aSample[i] is the first
117831
+ ** sample that is greater than pRec. Or, if i==pIdx->nSample then pRec
117832
+ ** is larger than all samples in the array. */
117833
+ tRowcnt iUpper, iGap;
117834
+ if( i>=pIdx->nSample ){
117835
+ iUpper = sqlite3LogEstToInt(pIdx->aiRowLogEst[0]);
117149117836
}else{
117150
- i64 nRow0 = sqlite3LogEstToInt(pIdx->aiRowLogEst[0]);
117151
- iUpper = i>=pIdx->nSample ? nRow0 : aSample[i].anLt[iCol];
117152
- iLower = aSample[i-1].anEq[iCol] + aSample[i-1].anLt[iCol];
117837
+ iUpper = aSample[i].anLt[iCol];
117153117838
}
117154
- aStat[1] = pIdx->aAvgEq[iCol];
117839
+
117155117840
if( iLower>=iUpper ){
117156117841
iGap = 0;
117157117842
}else{
117158117843
iGap = iUpper - iLower;
117159117844
}
@@ -117161,11 +117846,15 @@
117161117846
iGap = (iGap*2)/3;
117162117847
}else{
117163117848
iGap = iGap/3;
117164117849
}
117165117850
aStat[0] = iLower + iGap;
117851
+ aStat[1] = pIdx->aAvgEq[iCol];
117166117852
}
117853
+
117854
+ /* Restore the pRec->nField value before returning. */
117855
+ pRec->nField = nField;
117167117856
return i;
117168117857
}
117169117858
#endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
117170117859
117171117860
/*
@@ -117635,24 +118324,47 @@
117635118324
** by indices, we disable them to prevent redundant tests in the inner
117636118325
** loop. We would get the correct results if nothing were ever disabled,
117637118326
** but joins might run a little slower. The trick is to disable as much
117638118327
** as we can without disabling too much. If we disabled in (1), we'd get
117639118328
** the wrong answer. See ticket #813.
118329
+**
118330
+** If all the children of a term are disabled, then that term is also
118331
+** automatically disabled. In this way, terms get disabled if derived
118332
+** virtual terms are tested first. For example:
118333
+**
118334
+** x GLOB 'abc*' AND x>='abc' AND x<'acd'
118335
+** \___________/ \______/ \_____/
118336
+** parent child1 child2
118337
+**
118338
+** Only the parent term was in the original WHERE clause. The child1
118339
+** and child2 terms were added by the LIKE optimization. If both of
118340
+** the virtual child terms are valid, then testing of the parent can be
118341
+** skipped.
118342
+**
118343
+** Usually the parent term is marked as TERM_CODED. But if the parent
118344
+** term was originally TERM_LIKE, then the parent gets TERM_LIKECOND instead.
118345
+** The TERM_LIKECOND marking indicates that the term should be coded inside
118346
+** a conditional such that is only evaluated on the second pass of a
118347
+** LIKE-optimization loop, when scanning BLOBs instead of strings.
117640118348
*/
117641118349
static void disableTerm(WhereLevel *pLevel, WhereTerm *pTerm){
117642
- if( pTerm
118350
+ int nLoop = 0;
118351
+ while( pTerm
117643118352
&& (pTerm->wtFlags & TERM_CODED)==0
117644118353
&& (pLevel->iLeftJoin==0 || ExprHasProperty(pTerm->pExpr, EP_FromJoin))
117645118354
&& (pLevel->notReady & pTerm->prereqAll)==0
117646118355
){
117647
- pTerm->wtFlags |= TERM_CODED;
117648
- if( pTerm->iParent>=0 ){
117649
- WhereTerm *pOther = &pTerm->pWC->a[pTerm->iParent];
117650
- if( (--pOther->nChild)==0 ){
117651
- disableTerm(pLevel, pOther);
117652
- }
118356
+ if( nLoop && (pTerm->wtFlags & TERM_LIKE)!=0 ){
118357
+ pTerm->wtFlags |= TERM_LIKECOND;
118358
+ }else{
118359
+ pTerm->wtFlags |= TERM_CODED;
117653118360
}
118361
+ if( pTerm->iParent<0 ) break;
118362
+ pTerm = &pTerm->pWC->a[pTerm->iParent];
118363
+ pTerm->nChild--;
118364
+ if( pTerm->nChild!=0 ) break;
118365
+ nLoop++;
117654118366
}
117655118367
}
117656118368
117657118369
/*
117658118370
** Code an OP_Affinity opcode to apply the column affinity string zAff
@@ -118132,11 +118844,38 @@
118132118844
}
118133118845
#else
118134118846
# define addScanStatus(a, b, c, d) ((void)d)
118135118847
#endif
118136118848
118137
-
118849
+/*
118850
+** If the most recently coded instruction is a constant range contraint
118851
+** that originated from the LIKE optimization, then change the P3 to be
118852
+** pLoop->iLikeRepCntr and set P5.
118853
+**
118854
+** The LIKE optimization trys to evaluate "x LIKE 'abc%'" as a range
118855
+** expression: "x>='ABC' AND x<'abd'". But this requires that the range
118856
+** scan loop run twice, once for strings and a second time for BLOBs.
118857
+** The OP_String opcodes on the second pass convert the upper and lower
118858
+** bound string contants to blobs. This routine makes the necessary changes
118859
+** to the OP_String opcodes for that to happen.
118860
+*/
118861
+static void whereLikeOptimizationStringFixup(
118862
+ Vdbe *v, /* prepared statement under construction */
118863
+ WhereLevel *pLevel, /* The loop that contains the LIKE operator */
118864
+ WhereTerm *pTerm /* The upper or lower bound just coded */
118865
+){
118866
+ if( pTerm->wtFlags & TERM_LIKEOPT ){
118867
+ VdbeOp *pOp;
118868
+ assert( pLevel->iLikeRepCntr>0 );
118869
+ pOp = sqlite3VdbeGetOp(v, -1);
118870
+ assert( pOp!=0 );
118871
+ assert( pOp->opcode==OP_String8
118872
+ || pTerm->pWC->pWInfo->pParse->db->mallocFailed );
118873
+ pOp->p3 = pLevel->iLikeRepCntr;
118874
+ pOp->p5 = 1;
118875
+ }
118876
+}
118138118877
118139118878
/*
118140118879
** Generate code for the start of the iLevel-th loop in the WHERE clause
118141118880
** implementation described by pWInfo.
118142118881
*/
@@ -118462,14 +119201,29 @@
118462119201
*/
118463119202
j = nEq;
118464119203
if( pLoop->wsFlags & WHERE_BTM_LIMIT ){
118465119204
pRangeStart = pLoop->aLTerm[j++];
118466119205
nExtraReg = 1;
119206
+ /* Like optimization range constraints always occur in pairs */
119207
+ assert( (pRangeStart->wtFlags & TERM_LIKEOPT)==0 ||
119208
+ (pLoop->wsFlags & WHERE_TOP_LIMIT)!=0 );
118467119209
}
118468119210
if( pLoop->wsFlags & WHERE_TOP_LIMIT ){
118469119211
pRangeEnd = pLoop->aLTerm[j++];
118470119212
nExtraReg = 1;
119213
+ if( (pRangeEnd->wtFlags & TERM_LIKEOPT)!=0 ){
119214
+ assert( pRangeStart!=0 ); /* LIKE opt constraints */
119215
+ assert( pRangeStart->wtFlags & TERM_LIKEOPT ); /* occur in pairs */
119216
+ pLevel->iLikeRepCntr = ++pParse->nMem;
119217
+ testcase( bRev );
119218
+ testcase( pIdx->aSortOrder[nEq]==SQLITE_SO_DESC );
119219
+ sqlite3VdbeAddOp2(v, OP_Integer,
119220
+ bRev ^ (pIdx->aSortOrder[nEq]==SQLITE_SO_DESC),
119221
+ pLevel->iLikeRepCntr);
119222
+ VdbeComment((v, "LIKE loop counter"));
119223
+ pLevel->addrLikeRep = sqlite3VdbeCurrentAddr(v);
119224
+ }
118471119225
if( pRangeStart==0
118472119226
&& (j = pIdx->aiColumn[nEq])>=0
118473119227
&& pIdx->pTable->aCol[j].notNull==0
118474119228
){
118475119229
bSeekPastNull = 1;
@@ -118508,10 +119262,11 @@
118508119262
/* Seek the index cursor to the start of the range. */
118509119263
nConstraint = nEq;
118510119264
if( pRangeStart ){
118511119265
Expr *pRight = pRangeStart->pExpr->pRight;
118512119266
sqlite3ExprCode(pParse, pRight, regBase+nEq);
119267
+ whereLikeOptimizationStringFixup(v, pLevel, pRangeStart);
118513119268
if( (pRangeStart->wtFlags & TERM_VNULL)==0
118514119269
&& sqlite3ExprCanBeNull(pRight)
118515119270
){
118516119271
sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
118517119272
VdbeCoverage(v);
@@ -118553,10 +119308,11 @@
118553119308
nConstraint = nEq;
118554119309
if( pRangeEnd ){
118555119310
Expr *pRight = pRangeEnd->pExpr->pRight;
118556119311
sqlite3ExprCacheRemove(pParse, regBase+nEq, 1);
118557119312
sqlite3ExprCode(pParse, pRight, regBase+nEq);
119313
+ whereLikeOptimizationStringFixup(v, pLevel, pRangeEnd);
118558119314
if( (pRangeEnd->wtFlags & TERM_VNULL)==0
118559119315
&& sqlite3ExprCanBeNull(pRight)
118560119316
){
118561119317
sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
118562119318
VdbeCoverage(v);
@@ -118780,11 +119536,12 @@
118780119536
** eliminating duplicates from other WHERE clauses, the action for each
118781119537
** sub-WHERE clause is to to invoke the main loop body as a subroutine.
118782119538
*/
118783119539
wctrlFlags = WHERE_OMIT_OPEN_CLOSE
118784119540
| WHERE_FORCE_TABLE
118785
- | WHERE_ONETABLE_ONLY;
119541
+ | WHERE_ONETABLE_ONLY
119542
+ | WHERE_NO_AUTOINDEX;
118786119543
for(ii=0; ii<pOrWc->nTerm; ii++){
118787119544
WhereTerm *pOrTerm = &pOrWc->a[ii];
118788119545
if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
118789119546
WhereInfo *pSubWInfo; /* Info for single OR-term scan */
118790119547
Expr *pOrExpr = pOrTerm->pExpr; /* Current OR clause term */
@@ -118942,10 +119699,11 @@
118942119699
/* Insert code to test every subexpression that can be completely
118943119700
** computed using the current set of tables.
118944119701
*/
118945119702
for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
118946119703
Expr *pE;
119704
+ int skipLikeAddr = 0;
118947119705
testcase( pTerm->wtFlags & TERM_VIRTUAL );
118948119706
testcase( pTerm->wtFlags & TERM_CODED );
118949119707
if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
118950119708
if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
118951119709
testcase( pWInfo->untestedTerms==0
@@ -118955,12 +119713,18 @@
118955119713
}
118956119714
pE = pTerm->pExpr;
118957119715
assert( pE!=0 );
118958119716
if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
118959119717
continue;
119718
+ }
119719
+ if( pTerm->wtFlags & TERM_LIKECOND ){
119720
+ assert( pLevel->iLikeRepCntr>0 );
119721
+ skipLikeAddr = sqlite3VdbeAddOp1(v, OP_IfNot, pLevel->iLikeRepCntr);
119722
+ VdbeCoverage(v);
118960119723
}
118961119724
sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
119725
+ if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr);
118962119726
pTerm->wtFlags |= TERM_CODED;
118963119727
}
118964119728
118965119729
/* Insert code to test for implied constraints based on transitivity
118966119730
** of the "==" operator.
@@ -119621,10 +120385,14 @@
119621120385
){
119622120386
continue; /* ignore IS [NOT] NULL constraints on NOT NULL columns */
119623120387
}
119624120388
if( pTerm->prereqRight & pNew->maskSelf ) continue;
119625120389
120390
+ /* Do not allow the upper bound of a LIKE optimization range constraint
120391
+ ** to mix with a lower range bound from some other source */
120392
+ if( pTerm->wtFlags & TERM_LIKEOPT && pTerm->eOperator==WO_LT ) continue;
120393
+
119626120394
pNew->wsFlags = saved_wsFlags;
119627120395
pNew->u.btree.nEq = saved_nEq;
119628120396
pNew->nLTerm = saved_nLTerm;
119629120397
if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
119630120398
pNew->aLTerm[pNew->nLTerm++] = pTerm;
@@ -119664,10 +120432,21 @@
119664120432
testcase( eOp & WO_GT );
119665120433
testcase( eOp & WO_GE );
119666120434
pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_BTM_LIMIT;
119667120435
pBtm = pTerm;
119668120436
pTop = 0;
120437
+ if( pTerm->wtFlags & TERM_LIKEOPT ){
120438
+ /* Range contraints that come from the LIKE optimization are
120439
+ ** always used in pairs. */
120440
+ pTop = &pTerm[1];
120441
+ assert( (pTop-(pTerm->pWC->a))<pTerm->pWC->nTerm );
120442
+ assert( pTop->wtFlags & TERM_LIKEOPT );
120443
+ assert( pTop->eOperator==WO_LT );
120444
+ if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
120445
+ pNew->aLTerm[pNew->nLTerm++] = pTop;
120446
+ pNew->wsFlags |= WHERE_TOP_LIMIT;
120447
+ }
119669120448
}else{
119670120449
assert( eOp & (WO_LT|WO_LE) );
119671120450
testcase( eOp & WO_LT );
119672120451
testcase( eOp & WO_LE );
119673120452
pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_TOP_LIMIT;
@@ -119974,10 +120753,11 @@
119974120753
rLogSize = estLog(rSize);
119975120754
119976120755
#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
119977120756
/* Automatic indexes */
119978120757
if( !pBuilder->pOrSet
120758
+ && (pWInfo->wctrlFlags & WHERE_NO_AUTOINDEX)==0
119979120759
&& (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
119980120760
&& pSrc->pIndex==0
119981120761
&& !pSrc->viaCoroutine
119982120762
&& !pSrc->notIndexed
119983120763
&& HasRowid(pTab)
@@ -120857,14 +121637,14 @@
120857121637
assert( aSortCost==0 || &pSpace[nSpace]==(char*)&aSortCost[nOrderBy] );
120858121638
assert( aSortCost!=0 || &pSpace[nSpace]==(char*)pX );
120859121639
120860121640
/* Seed the search with a single WherePath containing zero WhereLoops.
120861121641
**
120862
- ** TUNING: Do not let the number of iterations go above 25. If the cost
120863
- ** of computing an automatic index is not paid back within the first 25
121642
+ ** TUNING: Do not let the number of iterations go above 28. If the cost
121643
+ ** of computing an automatic index is not paid back within the first 28
120864121644
** rows, then do not use the automatic index. */
120865
- aFrom[0].nRow = MIN(pParse->nQueryLoop, 46); assert( 46==sqlite3LogEst(25) );
121645
+ aFrom[0].nRow = MIN(pParse->nQueryLoop, 48); assert( 48==sqlite3LogEst(28) );
120866121646
nFrom = 1;
120867121647
assert( aFrom[0].isOrdered==0 );
120868121648
if( nOrderBy ){
120869121649
/* If nLoop is zero, then there are no FROM terms in the query. Since
120870121650
** in this case the query may return a maximum of one row, the results
@@ -121658,10 +122438,16 @@
121658122438
assert( pIx->pSchema==pTab->pSchema );
121659122439
assert( iIndexCur>=0 );
121660122440
if( op ){
121661122441
sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
121662122442
sqlite3VdbeSetP4KeyInfo(pParse, pIx);
122443
+ if( (pLoop->wsFlags & WHERE_CONSTRAINT)!=0
122444
+ && (pLoop->wsFlags & (WHERE_COLUMN_RANGE|WHERE_SKIPSCAN))==0
122445
+ && (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0
122446
+ ){
122447
+ sqlite3VdbeChangeP5(v, OPFLAG_SEEKEQ); /* Hint to COMDB2 */
122448
+ }
121663122449
VdbeComment((v, "%s", pIx->zName));
121664122450
}
121665122451
}
121666122452
if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb);
121667122453
notReady &= ~getMask(&pWInfo->sMaskSet, pTabItem->iCursor);
@@ -121758,10 +122544,20 @@
121758122544
if( pLevel->addrSkip ){
121759122545
sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip);
121760122546
VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
121761122547
sqlite3VdbeJumpHere(v, pLevel->addrSkip);
121762122548
sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
122549
+ }
122550
+ if( pLevel->addrLikeRep ){
122551
+ int op;
122552
+ if( sqlite3VdbeGetOp(v, pLevel->addrLikeRep-1)->p1 ){
122553
+ op = OP_DecrJumpZero;
122554
+ }else{
122555
+ op = OP_JumpZeroIncr;
122556
+ }
122557
+ sqlite3VdbeAddOp2(v, op, pLevel->iLikeRepCntr, pLevel->addrLikeRep);
122558
+ VdbeCoverage(v);
121763122559
}
121764122560
if( pLevel->iLeftJoin ){
121765122561
addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v);
121766122562
assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
121767122563
|| (pLoop->wsFlags & WHERE_INDEXED)!=0 );
@@ -124649,11 +125445,11 @@
124649125445
spanSet(&yygotominor.yy346, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
124650125446
}
124651125447
break;
124652125448
case 193: /* expr ::= expr COLLATE ID|STRING */
124653125449
{
124654
- yygotominor.yy346.pExpr = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy346.pExpr, &yymsp[0].minor.yy0);
125450
+ yygotominor.yy346.pExpr = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy346.pExpr, &yymsp[0].minor.yy0, 1);
124655125451
yygotominor.yy346.zStart = yymsp[-2].minor.yy346.zStart;
124656125452
yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
124657125453
}
124658125454
break;
124659125455
case 194: /* expr ::= CAST LP expr AS typetoken RP */
@@ -124929,20 +125725,20 @@
124929125725
case 241: /* uniqueflag ::= */
124930125726
{yygotominor.yy328 = OE_None;}
124931125727
break;
124932125728
case 244: /* idxlist ::= idxlist COMMA nm collate sortorder */
124933125729
{
124934
- Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0);
125730
+ Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0, 1);
124935125731
yygotominor.yy14 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy14, p);
124936125732
sqlite3ExprListSetName(pParse,yygotominor.yy14,&yymsp[-2].minor.yy0,1);
124937125733
sqlite3ExprListCheckLength(pParse, yygotominor.yy14, "index");
124938125734
if( yygotominor.yy14 ) yygotominor.yy14->a[yygotominor.yy14->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy328;
124939125735
}
124940125736
break;
124941125737
case 245: /* idxlist ::= nm collate sortorder */
124942125738
{
124943
- Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0);
125739
+ Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0, 1);
124944125740
yygotominor.yy14 = sqlite3ExprListAppend(pParse,0, p);
124945125741
sqlite3ExprListSetName(pParse, yygotominor.yy14, &yymsp[-2].minor.yy0, 1);
124946125742
sqlite3ExprListCheckLength(pParse, yygotominor.yy14, "index");
124947125743
if( yygotominor.yy14 ) yygotominor.yy14->a[yygotominor.yy14->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy328;
124948125744
}
@@ -126197,13 +126993,15 @@
126197126993
pParse->zTail = &zSql[i];
126198126994
}
126199126995
sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
126200126996
}
126201126997
#ifdef YYTRACKMAXSTACKDEPTH
126998
+ sqlite3_mutex_enter(sqlite3MallocMutex());
126202126999
sqlite3StatusSet(SQLITE_STATUS_PARSER_STACK,
126203127000
sqlite3ParserStackPeak(pEngine)
126204127001
);
127002
+ sqlite3_mutex_leave(sqlite3MallocMutex());
126205127003
#endif /* YYDEBUG */
126206127004
sqlite3ParserFree(pEngine, sqlite3_free);
126207127005
db->lookaside.bEnabled = enableLookaside;
126208127006
if( db->mallocFailed ){
126209127007
pParse->rc = SQLITE_NOMEM;
@@ -126769,10 +127567,15 @@
126769127567
rc = sqlite3_wsd_init(4096, 24);
126770127568
if( rc!=SQLITE_OK ){
126771127569
return rc;
126772127570
}
126773127571
#endif
127572
+
127573
+ /* If the following assert() fails on some obscure processor/compiler
127574
+ ** combination, the work-around is to set the correct pointer
127575
+ ** size at compile-time using -DSQLITE_PTRSIZE=n compile-time option */
127576
+ assert( SQLITE_PTRSIZE==sizeof(char*) );
126774127577
126775127578
/* If SQLite is already completely initialized, then this call
126776127579
** to sqlite3_initialize() should be a no-op. But the initialization
126777127580
** must be complete. So isInit must not be set until the very end
126778127581
** of this routine.
@@ -126982,30 +127785,32 @@
126982127785
/* Mutex configuration options are only available in a threadsafe
126983127786
** compile.
126984127787
*/
126985127788
#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-54466-46756 */
126986127789
case SQLITE_CONFIG_SINGLETHREAD: {
126987
- /* Disable all mutexing */
126988
- sqlite3GlobalConfig.bCoreMutex = 0;
126989
- sqlite3GlobalConfig.bFullMutex = 0;
127790
+ /* EVIDENCE-OF: R-02748-19096 This option sets the threading mode to
127791
+ ** Single-thread. */
127792
+ sqlite3GlobalConfig.bCoreMutex = 0; /* Disable mutex on core */
127793
+ sqlite3GlobalConfig.bFullMutex = 0; /* Disable mutex on connections */
126990127794
break;
126991127795
}
126992127796
#endif
126993127797
#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-20520-54086 */
126994127798
case SQLITE_CONFIG_MULTITHREAD: {
126995
- /* Disable mutexing of database connections */
126996
- /* Enable mutexing of core data structures */
126997
- sqlite3GlobalConfig.bCoreMutex = 1;
126998
- sqlite3GlobalConfig.bFullMutex = 0;
127799
+ /* EVIDENCE-OF: R-14374-42468 This option sets the threading mode to
127800
+ ** Multi-thread. */
127801
+ sqlite3GlobalConfig.bCoreMutex = 1; /* Enable mutex on core */
127802
+ sqlite3GlobalConfig.bFullMutex = 0; /* Disable mutex on connections */
126999127803
break;
127000127804
}
127001127805
#endif
127002127806
#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-59593-21810 */
127003127807
case SQLITE_CONFIG_SERIALIZED: {
127004
- /* Enable all mutexing */
127005
- sqlite3GlobalConfig.bCoreMutex = 1;
127006
- sqlite3GlobalConfig.bFullMutex = 1;
127808
+ /* EVIDENCE-OF: R-41220-51800 This option sets the threading mode to
127809
+ ** Serialized. */
127810
+ sqlite3GlobalConfig.bCoreMutex = 1; /* Enable mutex on core */
127811
+ sqlite3GlobalConfig.bFullMutex = 1; /* Enable mutex on connections */
127007127812
break;
127008127813
}
127009127814
#endif
127010127815
#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-63666-48755 */
127011127816
case SQLITE_CONFIG_MUTEX: {
@@ -127113,11 +127918,12 @@
127113127918
** SQLITE_ENABLE_MEMSYS5 and returns SQLITE_ERROR if invoked otherwise. */
127114127919
#if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
127115127920
case SQLITE_CONFIG_HEAP: {
127116127921
/* EVIDENCE-OF: R-19854-42126 There are three arguments to
127117127922
** SQLITE_CONFIG_HEAP: An 8-byte aligned pointer to the memory, the
127118
- ** number of bytes in the memory buffer, and the minimum allocation size. */
127923
+ ** number of bytes in the memory buffer, and the minimum allocation size.
127924
+ */
127119127925
sqlite3GlobalConfig.pHeap = va_arg(ap, void*);
127120127926
sqlite3GlobalConfig.nHeap = va_arg(ap, int);
127121127927
sqlite3GlobalConfig.mnReq = va_arg(ap, int);
127122127928
127123127929
if( sqlite3GlobalConfig.mnReq<1 ){
@@ -127218,11 +128024,13 @@
127218128024
** EVIDENCE-OF: R-34993-45031 The maximum allowed mmap size will be
127219128025
** silently truncated if necessary so that it does not exceed the
127220128026
** compile-time maximum mmap size set by the SQLITE_MAX_MMAP_SIZE
127221128027
** compile-time option.
127222128028
*/
127223
- if( mxMmap<0 || mxMmap>SQLITE_MAX_MMAP_SIZE ) mxMmap = SQLITE_MAX_MMAP_SIZE;
128029
+ if( mxMmap<0 || mxMmap>SQLITE_MAX_MMAP_SIZE ){
128030
+ mxMmap = SQLITE_MAX_MMAP_SIZE;
128031
+ }
127224128032
if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE;
127225128033
if( szMmap>mxMmap) szMmap = mxMmap;
127226128034
sqlite3GlobalConfig.mxMmap = mxMmap;
127227128035
sqlite3GlobalConfig.szMmap = szMmap;
127228128036
break;
@@ -129062,11 +129870,23 @@
129062129870
for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
129063129871
zFile = sqlite3_malloc(nByte);
129064129872
if( !zFile ) return SQLITE_NOMEM;
129065129873
129066129874
iIn = 5;
129067
-#ifndef SQLITE_ALLOW_URI_AUTHORITY
129875
+#ifdef SQLITE_ALLOW_URI_AUTHORITY
129876
+ if( strncmp(zUri+5, "///", 3)==0 ){
129877
+ iIn = 7;
129878
+ /* The following condition causes URIs with five leading / characters
129879
+ ** like file://///host/path to be converted into UNCs like //host/path.
129880
+ ** The correct URI for that UNC has only two or four leading / characters
129881
+ ** file://host/path or file:////host/path. But 5 leading slashes is a
129882
+ ** common error, we are told, so we handle it as a special case. */
129883
+ if( strncmp(zUri+7, "///", 3)==0 ){ iIn++; }
129884
+ }else if( strncmp(zUri+5, "//localhost/", 12)==0 ){
129885
+ iIn = 16;
129886
+ }
129887
+#else
129068129888
/* Discard the scheme and authority segments of the URI. */
129069129889
if( zUri[5]=='/' && zUri[6]=='/' ){
129070129890
iIn = 7;
129071129891
while( zUri[iIn] && zUri[iIn]!='/' ) iIn++;
129072129892
if( iIn!=7 && (iIn!=16 || memcmp("localhost", &zUri[7], 9)) ){
@@ -129505,11 +130325,12 @@
129505130325
sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT);
129506130326
129507130327
opendb_out:
129508130328
sqlite3_free(zOpen);
129509130329
if( db ){
129510
- assert( db->mutex!=0 || isThreadsafe==0 || sqlite3GlobalConfig.bFullMutex==0 );
130330
+ assert( db->mutex!=0 || isThreadsafe==0
130331
+ || sqlite3GlobalConfig.bFullMutex==0 );
129511130332
sqlite3_mutex_leave(db->mutex);
129512130333
}
129513130334
rc = sqlite3_errcode(db);
129514130335
assert( db!=0 || rc==SQLITE_NOMEM );
129515130336
if( rc==SQLITE_NOMEM ){
@@ -130250,21 +131071,21 @@
130250131071
case SQLITE_TESTCTRL_ISINIT: {
130251131072
if( sqlite3GlobalConfig.isInit==0 ) rc = SQLITE_ERROR;
130252131073
break;
130253131074
}
130254131075
130255
- /* sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, dbName, onOff, tnum);
131076
+ /* sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, dbName, onOff, tnum);
130256131077
**
130257131078
** This test control is used to create imposter tables. "db" is a pointer
130258131079
** to the database connection. dbName is the database name (ex: "main" or
130259131080
** "temp") which will receive the imposter. "onOff" turns imposter mode on
130260131081
** or off. "tnum" is the root page of the b-tree to which the imposter
130261131082
** table should connect.
130262131083
**
130263131084
** Enable imposter mode only when the schema has already been parsed. Then
130264
- ** run a single CREATE TABLE statement to construct the imposter table in the
130265
- ** parsed schema. Then turn imposter mode back off again.
131085
+ ** run a single CREATE TABLE statement to construct the imposter table in
131086
+ ** the parsed schema. Then turn imposter mode back off again.
130266131087
**
130267131088
** If onOff==0 and tnum>0 then reset the schema for all databases, causing
130268131089
** the schema to be reparsed the next time it is needed. This has the
130269131090
** effect of erasing all imposter tables.
130270131091
*/
@@ -132506,15 +133327,20 @@
132506133327
** the output value undefined. Otherwise SQLITE_OK is returned.
132507133328
**
132508133329
** This function is used when parsing the "prefix=" FTS4 parameter.
132509133330
*/
132510133331
static int fts3GobbleInt(const char **pp, int *pnOut){
133332
+ const int MAX_NPREFIX = 10000000;
132511133333
const char *p; /* Iterator pointer */
132512133334
int nInt = 0; /* Output value */
132513133335
132514133336
for(p=*pp; p[0]>='0' && p[0]<='9'; p++){
132515133337
nInt = nInt * 10 + (p[0] - '0');
133338
+ if( nInt>MAX_NPREFIX ){
133339
+ nInt = 0;
133340
+ break;
133341
+ }
132516133342
}
132517133343
if( p==*pp ) return SQLITE_ERROR;
132518133344
*pnOut = nInt;
132519133345
*pp = p;
132520133346
return SQLITE_OK;
@@ -132553,27 +133379,33 @@
132553133379
}
132554133380
}
132555133381
132556133382
aIndex = sqlite3_malloc(sizeof(struct Fts3Index) * nIndex);
132557133383
*apIndex = aIndex;
132558
- *pnIndex = nIndex;
132559133384
if( !aIndex ){
132560133385
return SQLITE_NOMEM;
132561133386
}
132562133387
132563133388
memset(aIndex, 0, sizeof(struct Fts3Index) * nIndex);
132564133389
if( zParam ){
132565133390
const char *p = zParam;
132566133391
int i;
132567133392
for(i=1; i<nIndex; i++){
132568
- int nPrefix;
133393
+ int nPrefix = 0;
132569133394
if( fts3GobbleInt(&p, &nPrefix) ) return SQLITE_ERROR;
132570
- aIndex[i].nPrefix = nPrefix;
133395
+ assert( nPrefix>=0 );
133396
+ if( nPrefix==0 ){
133397
+ nIndex--;
133398
+ i--;
133399
+ }else{
133400
+ aIndex[i].nPrefix = nPrefix;
133401
+ }
132571133402
p++;
132572133403
}
132573133404
}
132574133405
133406
+ *pnIndex = nIndex;
132575133407
return SQLITE_OK;
132576133408
}
132577133409
132578133410
/*
132579133411
** This function is called when initializing an FTS4 table that uses the
@@ -140349,11 +141181,11 @@
140349141181
nName = sqlite3_value_bytes(argv[0])+1;
140350141182
140351141183
if( argc==2 ){
140352141184
void *pOld;
140353141185
int n = sqlite3_value_bytes(argv[1]);
140354
- if( n!=sizeof(pPtr) ){
141186
+ if( zName==0 || n!=sizeof(pPtr) ){
140355141187
sqlite3_result_error(context, "argument type mismatch", -1);
140356141188
return;
140357141189
}
140358141190
pPtr = *(void **)sqlite3_value_blob(argv[1]);
140359141191
pOld = sqlite3Fts3HashInsert(pHash, (void *)zName, nName, pPtr);
@@ -140360,11 +141192,13 @@
140360141192
if( pOld==pPtr ){
140361141193
sqlite3_result_error(context, "out of memory", -1);
140362141194
return;
140363141195
}
140364141196
}else{
140365
- pPtr = sqlite3Fts3HashFind(pHash, zName, nName);
141197
+ if( zName ){
141198
+ pPtr = sqlite3Fts3HashFind(pHash, zName, nName);
141199
+ }
140366141200
if( !pPtr ){
140367141201
char *zErr = sqlite3_mprintf("unknown tokenizer: %s", zName);
140368141202
sqlite3_result_error(context, zErr, -1);
140369141203
sqlite3_free(zErr);
140370141204
return;
@@ -140441,10 +141275,14 @@
140441141275
zCopy = sqlite3_mprintf("%s", zArg);
140442141276
if( !zCopy ) return SQLITE_NOMEM;
140443141277
zEnd = &zCopy[strlen(zCopy)];
140444141278
140445141279
z = (char *)sqlite3Fts3NextToken(zCopy, &n);
141280
+ if( z==0 ){
141281
+ assert( n==0 );
141282
+ z = zCopy;
141283
+ }
140446141284
z[n] = '\0';
140447141285
sqlite3Fts3Dequote(z);
140448141286
140449141287
m = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash,z,(int)strlen(z)+1);
140450141288
if( !m ){
@@ -143086,11 +143924,14 @@
143086143924
/*
143087143925
** This is a comparison function used as a qsort() callback when sorting
143088143926
** an array of pending terms by term. This occurs as part of flushing
143089143927
** the contents of the pending-terms hash table to the database.
143090143928
*/
143091
-static int fts3CompareElemByTerm(const void *lhs, const void *rhs){
143929
+static int SQLITE_CDECL fts3CompareElemByTerm(
143930
+ const void *lhs,
143931
+ const void *rhs
143932
+){
143092143933
char *z1 = fts3HashKey(*(Fts3HashElem **)lhs);
143093143934
char *z2 = fts3HashKey(*(Fts3HashElem **)rhs);
143094143935
int n1 = fts3HashKeysize(*(Fts3HashElem **)lhs);
143095143936
int n2 = fts3HashKeysize(*(Fts3HashElem **)rhs);
143096143937
143097143938
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.8.8. 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.
@@ -88,10 +88,48 @@
88 #endif /* _MSVC_H_ */
89
90 /************** End of msvc.h ************************************************/
91 /************** Continuing where we left off in sqliteInt.h ******************/
92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93 /*
94 ** These #defines should enable >2GB file support on POSIX if the
95 ** underlying operating system supports it. If the OS lacks
96 ** large file support, or if the OS is windows, these should be no-ops.
97 **
@@ -223,10 +261,17 @@
223 #ifndef SQLITE_API
224 # define SQLITE_API
225 #endif
226
227
 
 
 
 
 
 
 
228 /*
229 ** These no-op macros are used in front of interfaces to mark those
230 ** interfaces as either deprecated or experimental. New applications
231 ** should not use deprecated interfaces - they are supported for backwards
232 ** compatibility only. Application writers should be aware that
@@ -276,13 +321,13 @@
276 **
277 ** See also: [sqlite3_libversion()],
278 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
279 ** [sqlite_version()] and [sqlite_source_id()].
280 */
281 #define SQLITE_VERSION "3.8.8"
282 #define SQLITE_VERSION_NUMBER 3008008
283 #define SQLITE_SOURCE_ID "2015-02-25 14:25:31 6d132e7a224ee68b5cefe9222944aac5760ffc20"
284
285 /*
286 ** CAPI3REF: Run-Time Library Version Numbers
287 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
288 **
@@ -925,18 +970,20 @@
925 **
926 ** These integer constants are opcodes for the xFileControl method
927 ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
928 ** interface.
929 **
 
 
930 ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This
931 ** opcode causes the xFileControl method to write the current state of
932 ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
933 ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
934 ** into an integer that the pArg argument points to. This capability
935 ** is used during testing and only needs to be supported when SQLITE_TEST
936 ** is defined.
937 ** <ul>
938 ** <li>[[SQLITE_FCNTL_SIZE_HINT]]
939 ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
940 ** layer a hint of how large the database file will grow to be during the
941 ** current transaction. This hint is not guaranteed to be accurate but it
942 ** is often close. The underlying VFS might choose to preallocate database
@@ -1057,11 +1104,13 @@
1057 ** the error message if the pragma fails. ^If the
1058 ** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal
1059 ** [PRAGMA] processing continues. ^If the [SQLITE_FCNTL_PRAGMA]
1060 ** file control returns [SQLITE_OK], then the parser assumes that the
1061 ** VFS has handled the PRAGMA itself and the parser generates a no-op
1062 ** prepared statement. ^If the [SQLITE_FCNTL_PRAGMA] file control returns
 
 
1063 ** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means
1064 ** that the VFS encountered an error while handling the [PRAGMA] and the
1065 ** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA]
1066 ** file control occurs at the beginning of pragma statement analysis and so
1067 ** it is able to override built-in [PRAGMA] statements.
@@ -1115,10 +1164,17 @@
1115 ** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This
1116 ** opcode causes the xFileControl method to swap the file handle with the one
1117 ** pointed to by the pArg argument. This capability is used during testing
1118 ** and only needs to be supported when SQLITE_TEST is defined.
1119 **
 
 
 
 
 
 
 
1120 ** </ul>
1121 */
1122 #define SQLITE_FCNTL_LOCKSTATE 1
1123 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
1124 #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
@@ -1139,10 +1195,11 @@
1139 #define SQLITE_FCNTL_TRACE 19
1140 #define SQLITE_FCNTL_HAS_MOVED 20
1141 #define SQLITE_FCNTL_SYNC 21
1142 #define SQLITE_FCNTL_COMMIT_PHASETWO 22
1143 #define SQLITE_FCNTL_WIN32_SET_HANDLE 23
 
1144
1145 /* deprecated names */
1146 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
1147 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
1148 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -1705,11 +1762,11 @@
1705 ** disabled, the following SQLite interfaces become non-operational:
1706 ** <ul>
1707 ** <li> [sqlite3_memory_used()]
1708 ** <li> [sqlite3_memory_highwater()]
1709 ** <li> [sqlite3_soft_heap_limit64()]
1710 ** <li> [sqlite3_status()]
1711 ** </ul>)^
1712 ** ^Memory allocation statistics are enabled by default unless SQLite is
1713 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1714 ** allocation statistics are disabled by default.
1715 ** </dd>
@@ -1916,11 +1973,10 @@
1916 ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
1917 ** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is
1918 ** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro
1919 ** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
1920 ** that specifies the maximum size of the created heap.
1921 ** </dl>
1922 **
1923 ** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
1924 ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
1925 ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
1926 ** is a pointer to an integer and writes into that integer the number of extra
@@ -3163,15 +3219,17 @@
3163
3164
3165 /*
3166 ** CAPI3REF: Error Codes And Messages
3167 **
3168 ** ^The sqlite3_errcode() interface returns the numeric [result code] or
3169 ** [extended result code] for the most recent failed sqlite3_* API call
3170 ** associated with a [database connection]. If a prior API call failed
3171 ** but the most recent API call succeeded, the return value from
3172 ** sqlite3_errcode() is undefined. ^The sqlite3_extended_errcode()
 
 
3173 ** interface is the same except that it always returns the
3174 ** [extended result code] even when extended result codes are
3175 ** disabled.
3176 **
3177 ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
@@ -3356,20 +3414,18 @@
3356 ** The second argument, "zSql", is the statement to be compiled, encoded
3357 ** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2()
3358 ** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2()
3359 ** use UTF-16.
3360 **
3361 ** ^If the nByte argument is less than zero, then zSql is read up to the
3362 ** first zero terminator. ^If nByte is non-negative, then it is the maximum
3363 ** number of bytes read from zSql. ^When nByte is non-negative, the
3364 ** zSql string ends at either the first '\000' or '\u0000' character or
3365 ** the nByte-th byte, whichever comes first. If the caller knows
3366 ** that the supplied string is nul-terminated, then there is a small
3367 ** performance advantage to be gained by passing an nByte parameter that
3368 ** is equal to the number of bytes in the input string <i>including</i>
3369 ** the nul-terminator bytes as this saves SQLite from having to
3370 ** make a copy of the input string.
3371 **
3372 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
3373 ** past the end of the first SQL statement in zSql. These routines only
3374 ** compile the first statement in zSql, so *pzTail is left pointing to
3375 ** what remains uncompiled.
@@ -4394,12 +4450,12 @@
4394 ** DEPRECATED
4395 **
4396 ** These functions are [deprecated]. In order to maintain
4397 ** backwards compatibility with older code, these functions continue
4398 ** to be supported. However, new applications should avoid
4399 ** the use of these functions. To help encourage people to avoid
4400 ** using these functions, we are not going to tell you what they do.
4401 */
4402 #ifndef SQLITE_OMIT_DEPRECATED
4403 SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
4404 SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
4405 SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
@@ -5783,11 +5839,11 @@
5783 ** is delivered up to the client application, the string will be automatically
5784 ** freed by sqlite3_free() and the zErrMsg field will be zeroed.
5785 */
5786 struct sqlite3_vtab {
5787 const sqlite3_module *pModule; /* The module for this virtual table */
5788 int nRef; /* NO LONGER USED */
5789 char *zErrMsg; /* Error message from sqlite3_mprintf() */
5790 /* Virtual table implementations will typically add additional fields */
5791 };
5792
5793 /*
@@ -6461,11 +6517,11 @@
6461 #define SQLITE_TESTCTRL_LAST 25
6462
6463 /*
6464 ** CAPI3REF: SQLite Runtime Status
6465 **
6466 ** ^This interface is used to retrieve runtime status information
6467 ** about the performance of SQLite, and optionally to reset various
6468 ** highwater marks. ^The first argument is an integer code for
6469 ** the specific parameter to measure. ^(Recognized integer codes
6470 ** are of the form [status parameters | SQLITE_STATUS_...].)^
6471 ** ^The current value of the parameter is returned into *pCurrent.
@@ -6475,23 +6531,26 @@
6475 ** value. For those parameters
6476 ** nothing is written into *pHighwater and the resetFlag is ignored.)^
6477 ** ^(Other parameters record only the highwater mark and not the current
6478 ** value. For these latter parameters nothing is written into *pCurrent.)^
6479 **
6480 ** ^The sqlite3_status() routine returns SQLITE_OK on success and a
6481 ** non-zero [error code] on failure.
6482 **
6483 ** This routine is threadsafe but is not atomic. This routine can be
6484 ** called while other threads are running the same or different SQLite
6485 ** interfaces. However the values returned in *pCurrent and
6486 ** *pHighwater reflect the status of SQLite at different points in time
6487 ** and it is possible that another thread might change the parameter
6488 ** in between the times when *pCurrent and *pHighwater are written.
6489 **
6490 ** See also: [sqlite3_db_status()]
6491 */
6492 SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
 
 
 
 
 
 
6493
6494
6495 /*
6496 ** CAPI3REF: Status Parameters
6497 ** KEYWORDS: {status parameters}
@@ -7157,24 +7216,24 @@
7157 **
7158 ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
7159 ** is not a permanent error and does not affect the return value of
7160 ** sqlite3_backup_finish().
7161 **
7162 ** [[sqlite3_backup__remaining()]] [[sqlite3_backup_pagecount()]]
7163 ** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b>
7164 **
7165 ** ^Each call to sqlite3_backup_step() sets two values inside
7166 ** the [sqlite3_backup] object: the number of pages still to be backed
7167 ** up and the total number of pages in the source database file.
7168 ** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces
7169 ** retrieve these two values, respectively.
7170 **
7171 ** ^The values returned by these functions are only updated by
7172 ** sqlite3_backup_step(). ^If the source database is modified during a backup
7173 ** operation, then the values are not updated to account for any extra
7174 ** pages that need to be updated or the size of the source database file
7175 ** changing.
7176 **
7177 ** <b>Concurrent Usage of Database Handles</b>
7178 **
7179 ** ^The source [database connection] may be used by the application for other
7180 ** purposes while a backup operation is underway or being initialized.
@@ -8018,19 +8077,21 @@
8018 #ifndef SQLITE_MAX_FUNCTION_ARG
8019 # define SQLITE_MAX_FUNCTION_ARG 127
8020 #endif
8021
8022 /*
8023 ** The maximum number of in-memory pages to use for the main database
8024 ** table and for temporary tables. The SQLITE_DEFAULT_CACHE_SIZE
 
 
 
 
 
8025 */
8026 #ifndef SQLITE_DEFAULT_CACHE_SIZE
8027 # define SQLITE_DEFAULT_CACHE_SIZE 2000
8028 #endif
8029 #ifndef SQLITE_DEFAULT_TEMP_CACHE_SIZE
8030 # define SQLITE_DEFAULT_TEMP_CACHE_SIZE 500
8031 #endif
8032
8033 /*
8034 ** The default number of frames to accumulate in the log file before
8035 ** checkpointing the database in WAL mode.
8036 */
@@ -8870,10 +8931,24 @@
8870 **
8871 ** 0.5 -> -10 0.1 -> -33 0.0625 -> -40
8872 */
8873 typedef INT16_TYPE LogEst;
8874
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8875 /*
8876 ** Macros to determine whether the machine is big or little endian,
8877 ** and whether or not that determination is run-time or compile-time.
8878 **
8879 ** For best performance, an attempt is made to guess at the byte-order
@@ -9320,12 +9395,22 @@
9320 #define BTREE_DATA_VERSION 15 /* A virtual meta-value */
9321
9322 /*
9323 ** Values that may be OR'd together to form the second argument of an
9324 ** sqlite3BtreeCursorHints() call.
 
 
 
 
 
 
 
 
 
9325 */
9326 #define BTREE_BULKLOAD 0x00000001
 
9327
9328 SQLITE_PRIVATE int sqlite3BtreeCursor(
9329 Btree*, /* BTree containing table to open */
9330 int iTable, /* Index of root page */
9331 int wrFlag, /* 1 for writing. 0 for read-only */
@@ -9367,10 +9452,13 @@
9367 SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
9368 SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *);
9369 SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *);
9370 SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion);
9371 SQLITE_PRIVATE void sqlite3BtreeCursorHints(BtCursor *, unsigned int mask);
 
 
 
9372 SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *pBt);
9373 SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void);
9374
9375 #ifndef NDEBUG
9376 SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*);
@@ -9733,27 +9821,29 @@
9733 #define OP_FkCounter 134 /* synopsis: fkctr[P1]+=P2 */
9734 #define OP_FkIfZero 135 /* synopsis: if fkctr[P1]==0 goto P2 */
9735 #define OP_MemMax 136 /* synopsis: r[P1]=max(r[P1],r[P2]) */
9736 #define OP_IfPos 137 /* synopsis: if r[P1]>0 goto P2 */
9737 #define OP_IfNeg 138 /* synopsis: r[P1]+=P3, if r[P1]<0 goto P2 */
9738 #define OP_IfZero 139 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */
9739 #define OP_AggFinal 140 /* synopsis: accum=r[P1] N=P2 */
9740 #define OP_IncrVacuum 141
9741 #define OP_Expire 142
9742 #define OP_TableLock 143 /* synopsis: iDb=P1 root=P2 write=P3 */
9743 #define OP_VBegin 144
9744 #define OP_VCreate 145
9745 #define OP_VDestroy 146
9746 #define OP_VOpen 147
9747 #define OP_VColumn 148 /* synopsis: r[P3]=vcolumn(P2) */
9748 #define OP_VNext 149
9749 #define OP_VRename 150
9750 #define OP_Pagecount 151
9751 #define OP_MaxPgcnt 152
9752 #define OP_Init 153 /* synopsis: Start at P2 */
9753 #define OP_Noop 154
9754 #define OP_Explain 155
 
 
9755
9756
9757 /* Properties such as "out2" or "jump" that are specified in
9758 ** comments following the "case" for each opcode in the vdbe.c
9759 ** are encoded into bitvectors as follows:
@@ -9781,13 +9871,13 @@
9781 /* 96 */ 0x24, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,\
9782 /* 104 */ 0x00, 0x01, 0x01, 0x01, 0x01, 0x08, 0x08, 0x00,\
9783 /* 112 */ 0x02, 0x01, 0x01, 0x01, 0x01, 0x02, 0x00, 0x00,\
9784 /* 120 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9785 /* 128 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x02, 0x00, 0x01,\
9786 /* 136 */ 0x08, 0x05, 0x05, 0x05, 0x00, 0x01, 0x00, 0x00,\
9787 /* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02,\
9788 /* 152 */ 0x02, 0x01, 0x00, 0x00,}
9789
9790 /************** End of opcodes.h *********************************************/
9791 /************** Continuing where we left off in vdbe.h ***********************/
9792
9793 /*
@@ -10865,10 +10955,11 @@
10865 } init;
10866 int nVdbeActive; /* Number of VDBEs currently running */
10867 int nVdbeRead; /* Number of active VDBEs that read or write */
10868 int nVdbeWrite; /* Number of active VDBEs that read and write */
10869 int nVdbeExec; /* Number of nested calls to VdbeExec() */
 
10870 int nExtension; /* Number of loaded extensions */
10871 void **aExtension; /* Array of shared library handles */
10872 void (*xTrace)(void*,const char*); /* Trace function */
10873 void *pTraceArg; /* Argument to the trace function */
10874 void (*xProfile)(void*,const char*,u64); /* Profiling function */
@@ -12022,11 +12113,11 @@
12022 #define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
12023 #define WHERE_DUPLICATES_OK 0x0008 /* Ok to return a row more than once */
12024 #define WHERE_OMIT_OPEN_CLOSE 0x0010 /* Table cursors are already open */
12025 #define WHERE_FORCE_TABLE 0x0020 /* Do not use an index-only search */
12026 #define WHERE_ONETABLE_ONLY 0x0040 /* Only code the 1st table in pTabList */
12027 /* 0x0080 // not currently used */
12028 #define WHERE_GROUPBY 0x0100 /* pOrderBy is really a GROUP BY */
12029 #define WHERE_DISTINCTBY 0x0200 /* pOrderby is really a DISTINCT clause */
12030 #define WHERE_WANT_DISTINCT 0x0400 /* All output needs to be distinct */
12031 #define WHERE_SORTBYGROUP 0x0800 /* Support sqlite3WhereIsSorted() */
12032 #define WHERE_REOPEN_IDX 0x1000 /* Try to use OP_ReopenIdx */
@@ -12459,11 +12550,12 @@
12459 #define OPFLAG_APPEND 0x08 /* This is likely to be an append */
12460 #define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */
12461 #define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */
12462 #define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */
12463 #define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */
12464 #define OPFLAG_P2ISREG 0x02 /* P2 to OP_Open** is a register number */
 
12465 #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */
12466
12467 /*
12468 * Each trigger present in the database schema is stored as an instance of
12469 * struct Trigger.
@@ -12863,14 +12955,19 @@
12863 SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int);
12864 SQLITE_PRIVATE int sqlite3MutexInit(void);
12865 SQLITE_PRIVATE int sqlite3MutexEnd(void);
12866 #endif
12867
12868 SQLITE_PRIVATE int sqlite3StatusValue(int);
12869 SQLITE_PRIVATE void sqlite3StatusAdd(int, int);
 
12870 SQLITE_PRIVATE void sqlite3StatusSet(int, int);
12871
 
 
 
 
12872 #ifndef SQLITE_OMIT_FLOATING_POINT
12873 SQLITE_PRIVATE int sqlite3IsNaN(double);
12874 #else
12875 # define sqlite3IsNaN(X) 0
12876 #endif
@@ -13246,11 +13343,11 @@
13246 SQLITE_PRIVATE const char *sqlite3ErrStr(int);
13247 SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
13248 SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int);
13249 SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName);
13250 SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr);
13251 SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr*, const Token*);
13252 SQLITE_PRIVATE Expr *sqlite3ExprAddCollateString(Parse*,Expr*,const char*);
13253 SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr*);
13254 SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *);
13255 SQLITE_PRIVATE int sqlite3CheckObjectName(Parse *, const char *);
13256 SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int);
@@ -14633,18 +14730,10 @@
14633 ** An instance of the virtual machine. This structure contains the complete
14634 ** state of the virtual machine.
14635 **
14636 ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()
14637 ** is really a pointer to an instance of this structure.
14638 **
14639 ** The Vdbe.inVtabMethod variable is set to non-zero for the duration of
14640 ** any virtual table method invocations made by the vdbe program. It is
14641 ** set to 2 for xDestroy method calls and 1 for all other methods. This
14642 ** variable is used for two purposes: to allow xDestroy methods to execute
14643 ** "DROP TABLE" statements and to prevent some nasty side effects of
14644 ** malloc failure when SQLite is invoked recursively by a virtual table
14645 ** method function.
14646 */
14647 struct Vdbe {
14648 sqlite3 *db; /* The database connection that owns this statement */
14649 Op *aOp; /* Space to hold the virtual machine's program */
14650 Mem *aMem; /* The memory locations */
@@ -14671,11 +14760,10 @@
14671 #endif
14672 u16 nResColumn; /* Number of columns in one row of the result set */
14673 u8 errorAction; /* Recovery action to do in case of an error */
14674 u8 minWriteFileFormat; /* Minimum file format for writable database files */
14675 bft explain:2; /* True if EXPLAIN present on SQL command */
14676 bft inVtabMethod:2; /* See comments above */
14677 bft changeCntOn:1; /* True to update the change-counter */
14678 bft expired:1; /* True if the VM needs to be recompiled */
14679 bft runOnlyOnce:1; /* Automatically expire on reset */
14680 bft usesStmtJournal:1; /* True if uses a statement journal */
14681 bft readOnly:1; /* True for statements that do not write */
@@ -14831,13 +14919,35 @@
14831 /*
14832 ** Variables in which to record status information.
14833 */
14834 typedef struct sqlite3StatType sqlite3StatType;
14835 static SQLITE_WSD struct sqlite3StatType {
14836 int nowValue[10]; /* Current value */
14837 int mxValue[10]; /* Maximum value */
 
 
 
 
 
14838 } sqlite3Stat = { {0,}, {0,} };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14839
14840
14841 /* The "wsdStat" macro will resolve to the status information
14842 ** state vector. If writable static data is unsupported on the target,
14843 ** we have to locate the state vector at run-time. In the more common
@@ -14851,64 +14961,110 @@
14851 # define wsdStatInit
14852 # define wsdStat sqlite3Stat
14853 #endif
14854
14855 /*
14856 ** Return the current value of a status parameter.
 
14857 */
14858 SQLITE_PRIVATE int sqlite3StatusValue(int op){
14859 wsdStatInit;
14860 assert( op>=0 && op<ArraySize(wsdStat.nowValue) );
 
 
 
14861 return wsdStat.nowValue[op];
14862 }
14863
14864 /*
14865 ** Add N to the value of a status record. It is assumed that the
14866 ** caller holds appropriate locks.
 
 
 
 
 
 
 
14867 */
14868 SQLITE_PRIVATE void sqlite3StatusAdd(int op, int N){
14869 wsdStatInit;
14870 assert( op>=0 && op<ArraySize(wsdStat.nowValue) );
 
 
 
14871 wsdStat.nowValue[op] += N;
14872 if( wsdStat.nowValue[op]>wsdStat.mxValue[op] ){
14873 wsdStat.mxValue[op] = wsdStat.nowValue[op];
14874 }
14875 }
 
 
 
 
 
 
 
 
 
14876
14877 /*
14878 ** Set the value of a status to X.
 
14879 */
14880 SQLITE_PRIVATE void sqlite3StatusSet(int op, int X){
14881 wsdStatInit;
14882 assert( op>=0 && op<ArraySize(wsdStat.nowValue) );
 
 
 
14883 wsdStat.nowValue[op] = X;
14884 if( wsdStat.nowValue[op]>wsdStat.mxValue[op] ){
14885 wsdStat.mxValue[op] = wsdStat.nowValue[op];
14886 }
14887 }
14888
14889 /*
14890 ** Query status information.
14891 **
14892 ** This implementation assumes that reading or writing an aligned
14893 ** 32-bit integer is an atomic operation. If that assumption is not true,
14894 ** then this routine is not threadsafe.
14895 */
14896 SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){
 
 
 
 
 
 
14897 wsdStatInit;
14898 if( op<0 || op>=ArraySize(wsdStat.nowValue) ){
14899 return SQLITE_MISUSE_BKPT;
14900 }
14901 #ifdef SQLITE_ENABLE_API_ARMOR
14902 if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT;
14903 #endif
 
 
14904 *pCurrent = wsdStat.nowValue[op];
14905 *pHighwater = wsdStat.mxValue[op];
14906 if( resetFlag ){
14907 wsdStat.mxValue[op] = wsdStat.nowValue[op];
14908 }
 
 
14909 return SQLITE_OK;
 
 
 
 
 
 
 
 
 
 
 
 
 
14910 }
14911
14912 /*
14913 ** Query status information for a single database connection
14914 */
@@ -20358,10 +20514,17 @@
20358 */
20359 int nearlyFull;
20360 } mem0 = { 0, 0, 0, 0, 0, 0, 0, 0 };
20361
20362 #define mem0 GLOBAL(struct Mem0Global, mem0)
 
 
 
 
 
 
 
20363
20364 /*
20365 ** This routine runs when the memory allocator sees that the
20366 ** total memory allocation is about to exceed the soft heap
20367 ** limit.
@@ -20381,11 +20544,11 @@
20381 static int sqlite3MemoryAlarm(
20382 void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
20383 void *pArg,
20384 sqlite3_int64 iThreshold
20385 ){
20386 int nUsed;
20387 sqlite3_mutex_enter(mem0.mutex);
20388 mem0.alarmCallback = xCallback;
20389 mem0.alarmArg = pArg;
20390 mem0.alarmThreshold = iThreshold;
20391 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
@@ -20550,11 +20713,11 @@
20550 void *p;
20551 assert( sqlite3_mutex_held(mem0.mutex) );
20552 nFull = sqlite3GlobalConfig.m.xRoundup(n);
20553 sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, n);
20554 if( mem0.alarmCallback!=0 ){
20555 int nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
20556 if( nUsed >= mem0.alarmThreshold - nFull ){
20557 mem0.nearlyFull = 1;
20558 sqlite3MallocAlarm(nFull);
20559 }else{
20560 mem0.nearlyFull = 0;
@@ -20567,12 +20730,12 @@
20567 p = sqlite3GlobalConfig.m.xMalloc(nFull);
20568 }
20569 #endif
20570 if( p ){
20571 nFull = sqlite3MallocSize(p);
20572 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nFull);
20573 sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, 1);
20574 }
20575 *pp = p;
20576 return nFull;
20577 }
20578
@@ -20645,18 +20808,18 @@
20645 sqlite3StatusSet(SQLITE_STATUS_SCRATCH_SIZE, n);
20646 if( mem0.nScratchFree && sqlite3GlobalConfig.szScratch>=n ){
20647 p = mem0.pScratchFree;
20648 mem0.pScratchFree = mem0.pScratchFree->pNext;
20649 mem0.nScratchFree--;
20650 sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, 1);
20651 sqlite3_mutex_leave(mem0.mutex);
20652 }else{
20653 sqlite3_mutex_leave(mem0.mutex);
20654 p = sqlite3Malloc(n);
20655 if( sqlite3GlobalConfig.bMemstat && p ){
20656 sqlite3_mutex_enter(mem0.mutex);
20657 sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, sqlite3MallocSize(p));
20658 sqlite3_mutex_leave(mem0.mutex);
20659 }
20660 sqlite3MemdebugSetType(p, MEMTYPE_SCRATCH);
20661 }
20662 assert( sqlite3_mutex_notheld(mem0.mutex) );
@@ -20693,23 +20856,23 @@
20693 sqlite3_mutex_enter(mem0.mutex);
20694 pSlot->pNext = mem0.pScratchFree;
20695 mem0.pScratchFree = pSlot;
20696 mem0.nScratchFree++;
20697 assert( mem0.nScratchFree <= (u32)sqlite3GlobalConfig.nScratch );
20698 sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_USED, -1);
20699 sqlite3_mutex_leave(mem0.mutex);
20700 }else{
20701 /* Release memory back to the heap */
20702 assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) );
20703 assert( sqlite3MemdebugNoType(p, ~MEMTYPE_SCRATCH) );
20704 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
20705 if( sqlite3GlobalConfig.bMemstat ){
20706 int iSize = sqlite3MallocSize(p);
20707 sqlite3_mutex_enter(mem0.mutex);
20708 sqlite3StatusAdd(SQLITE_STATUS_SCRATCH_OVERFLOW, -iSize);
20709 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -iSize);
20710 sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, -1);
20711 sqlite3GlobalConfig.m.xFree(p);
20712 sqlite3_mutex_leave(mem0.mutex);
20713 }else{
20714 sqlite3GlobalConfig.m.xFree(p);
20715 }
@@ -20736,26 +20899,26 @@
20736 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
20737 return sqlite3GlobalConfig.m.xSize(p);
20738 }
20739 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
20740 if( db==0 ){
20741 assert( sqlite3MemdebugNoType(p, ~MEMTYPE_HEAP) );
20742 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
20743 return sqlite3MallocSize(p);
20744 }else{
20745 assert( sqlite3_mutex_held(db->mutex) );
20746 if( isLookaside(db, p) ){
20747 return db->lookaside.sz;
20748 }else{
20749 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20750 assert( sqlite3MemdebugNoType(p, ~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20751 return sqlite3GlobalConfig.m.xSize(p);
20752 }
20753 }
20754 }
20755 SQLITE_API sqlite3_uint64 sqlite3_msize(void *p){
20756 assert( sqlite3MemdebugNoType(p, ~MEMTYPE_HEAP) );
20757 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
20758 return (sqlite3_uint64)sqlite3GlobalConfig.m.xSize(p);
20759 }
20760
20761 /*
@@ -20762,15 +20925,15 @@
20762 ** Free memory previously obtained from sqlite3Malloc().
20763 */
20764 SQLITE_API void sqlite3_free(void *p){
20765 if( p==0 ) return; /* IMP: R-49053-54554 */
20766 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
20767 assert( sqlite3MemdebugNoType(p, ~MEMTYPE_HEAP) );
20768 if( sqlite3GlobalConfig.bMemstat ){
20769 sqlite3_mutex_enter(mem0.mutex);
20770 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, -sqlite3MallocSize(p));
20771 sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, -1);
20772 sqlite3GlobalConfig.m.xFree(p);
20773 sqlite3_mutex_leave(mem0.mutex);
20774 }else{
20775 sqlite3GlobalConfig.m.xFree(p);
20776 }
@@ -20807,11 +20970,11 @@
20807 db->lookaside.nOut--;
20808 return;
20809 }
20810 }
20811 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20812 assert( sqlite3MemdebugNoType(p, ~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20813 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
20814 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
20815 sqlite3_free(p);
20816 }
20817
@@ -20820,11 +20983,11 @@
20820 */
20821 SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, u64 nBytes){
20822 int nOld, nNew, nDiff;
20823 void *pNew;
20824 assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
20825 assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) );
20826 if( pOld==0 ){
20827 return sqlite3Malloc(nBytes); /* IMP: R-04300-56712 */
20828 }
20829 if( nBytes==0 ){
20830 sqlite3_free(pOld); /* IMP: R-26507-47431 */
@@ -20854,11 +21017,11 @@
20854 sqlite3MallocAlarm((int)nBytes);
20855 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
20856 }
20857 if( pNew ){
20858 nNew = sqlite3MallocSize(pNew);
20859 sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nNew-nOld);
20860 }
20861 sqlite3_mutex_leave(mem0.mutex);
20862 }else{
20863 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
20864 }
@@ -20987,11 +21150,11 @@
20987 memcpy(pNew, p, db->lookaside.sz);
20988 sqlite3DbFree(db, p);
20989 }
20990 }else{
20991 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20992 assert( sqlite3MemdebugNoType(p, ~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20993 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
20994 pNew = sqlite3_realloc64(p, n);
20995 if( !pNew ){
20996 db->mallocFailed = 1;
20997 }
@@ -24969,27 +25132,29 @@
24969 /* 134 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
24970 /* 135 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
24971 /* 136 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
24972 /* 137 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
24973 /* 138 */ "IfNeg" OpHelp("r[P1]+=P3, if r[P1]<0 goto P2"),
24974 /* 139 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),
24975 /* 140 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
24976 /* 141 */ "IncrVacuum" OpHelp(""),
24977 /* 142 */ "Expire" OpHelp(""),
24978 /* 143 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
24979 /* 144 */ "VBegin" OpHelp(""),
24980 /* 145 */ "VCreate" OpHelp(""),
24981 /* 146 */ "VDestroy" OpHelp(""),
24982 /* 147 */ "VOpen" OpHelp(""),
24983 /* 148 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
24984 /* 149 */ "VNext" OpHelp(""),
24985 /* 150 */ "VRename" OpHelp(""),
24986 /* 151 */ "Pagecount" OpHelp(""),
24987 /* 152 */ "MaxPgcnt" OpHelp(""),
24988 /* 153 */ "Init" OpHelp("Start at P2"),
24989 /* 154 */ "Noop" OpHelp(""),
24990 /* 155 */ "Explain" OpHelp(""),
 
 
24991 };
24992 return azName[i];
24993 }
24994 #endif
24995
@@ -25065,22 +25230,10 @@
25065 # else
25066 # define SQLITE_ENABLE_LOCKING_STYLE 0
25067 # endif
25068 #endif
25069
25070 /*
25071 ** Define the OS_VXWORKS pre-processor macro to 1 if building on
25072 ** vxworks, or 0 otherwise.
25073 */
25074 #ifndef OS_VXWORKS
25075 # if defined(__RTP__) || defined(_WRS_KERNEL)
25076 # define OS_VXWORKS 1
25077 # else
25078 # define OS_VXWORKS 0
25079 # endif
25080 #endif
25081
25082 /*
25083 ** standard include files.
25084 */
25085 #include <sys/types.h>
25086 #include <sys/stat.h>
@@ -25091,22 +25244,23 @@
25091 #include <errno.h>
25092 #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
25093 # include <sys/mman.h>
25094 #endif
25095
25096 #if SQLITE_ENABLE_LOCKING_STYLE || OS_VXWORKS
25097 # include <sys/ioctl.h>
25098 # if OS_VXWORKS
25099 # include <semaphore.h>
25100 # include <limits.h>
25101 # else
25102 # include <sys/file.h>
25103 # include <sys/param.h>
25104 # endif
25105 #endif /* SQLITE_ENABLE_LOCKING_STYLE */
25106
25107 #if defined(__APPLE__) || (SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS)
 
 
 
 
 
 
25108 # include <sys/mount.h>
25109 #endif
25110
25111 #ifdef HAVE_UTIME
25112 # include <utime.h>
@@ -25142,10 +25296,14 @@
25142
25143 /*
25144 ** Maximum supported path-length.
25145 */
25146 #define MAX_PATHNAME 512
 
 
 
 
25147
25148 /*
25149 ** Only set the lastErrno if the error code is a real error and not
25150 ** a normal expected return code of SQLITE_BUSY or SQLITE_OK
25151 */
@@ -25231,11 +25389,11 @@
25231
25232 /* This variable holds the process id (pid) from when the xRandomness()
25233 ** method was called. If xOpen() is called from a different process id,
25234 ** indicating that a fork() has occurred, the PRNG will be reset.
25235 */
25236 static int randomnessPid = 0;
25237
25238 /*
25239 ** Allowed values for the unixFile.ctrlFlags bitmask:
25240 */
25241 #define UNIXFILE_EXCL 0x01 /* Connections from one process only */
@@ -25249,10 +25407,11 @@
25249 #define UNIXFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
25250 #define UNIXFILE_DELETE 0x20 /* Delete on close */
25251 #define UNIXFILE_URI 0x40 /* Filename might have query parameters */
25252 #define UNIXFILE_NOLOCK 0x80 /* Do no file locking */
25253 #define UNIXFILE_WARNED 0x0100 /* verifyDbFile() warnings issued */
 
25254
25255 /*
25256 ** Include code that is common to all os_*.c files
25257 */
25258 /************** Include os_common.h in the middle of os_unix.c ***************/
@@ -25587,11 +25746,11 @@
25587 #define osFcntl ((int(*)(int,int,...))aSyscall[7].pCurrent)
25588
25589 { "read", (sqlite3_syscall_ptr)read, 0 },
25590 #define osRead ((ssize_t(*)(int,void*,size_t))aSyscall[8].pCurrent)
25591
25592 #if defined(USE_PREAD) || (SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS)
25593 { "pread", (sqlite3_syscall_ptr)pread, 0 },
25594 #else
25595 { "pread", (sqlite3_syscall_ptr)0, 0 },
25596 #endif
25597 #define osPread ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[9].pCurrent)
@@ -25604,11 +25763,11 @@
25604 #define osPread64 ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].pCurrent)
25605
25606 { "write", (sqlite3_syscall_ptr)write, 0 },
25607 #define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent)
25608
25609 #if defined(USE_PREAD) || (SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS)
25610 { "pwrite", (sqlite3_syscall_ptr)pwrite, 0 },
25611 #else
25612 { "pwrite", (sqlite3_syscall_ptr)0, 0 },
25613 #endif
25614 #define osPwrite ((ssize_t(*)(int,const void*,size_t,off_t))\
@@ -26743,11 +26902,12 @@
26743 int tErrno = 0;
26744
26745 assert( pFile );
26746 OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (unix)\n", pFile->h,
26747 azFileLock(eFileLock), azFileLock(pFile->eFileLock),
26748 azFileLock(pFile->pInode->eFileLock), pFile->pInode->nShared , getpid()));
 
26749
26750 /* If there is already a lock of this type or more restrictive on the
26751 ** unixFile, do nothing. Don't use the end_lock: exit path, as
26752 ** unixEnterMutex() hasn't been called yet.
26753 */
@@ -26951,11 +27111,11 @@
26951 int rc = SQLITE_OK;
26952
26953 assert( pFile );
26954 OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (unix)\n", pFile->h, eFileLock,
26955 pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared,
26956 getpid()));
26957
26958 assert( eFileLock<=SHARED_LOCK );
26959 if( pFile->eFileLock<=eFileLock ){
26960 return SQLITE_OK;
26961 }
@@ -27378,11 +27538,11 @@
27378 char *zLockFile = (char *)pFile->lockingContext;
27379 int rc;
27380
27381 assert( pFile );
27382 OSTRACE(("UNLOCK %d %d was %d pid=%d (dotlock)\n", pFile->h, eFileLock,
27383 pFile->eFileLock, getpid()));
27384 assert( eFileLock<=SHARED_LOCK );
27385
27386 /* no-op if possible */
27387 if( pFile->eFileLock==eFileLock ){
27388 return SQLITE_OK;
@@ -27441,14 +27601,13 @@
27441 ** a single exclusive lock. In other words, SHARED, RESERVED, and
27442 ** PENDING locks are the same thing as an EXCLUSIVE lock. SQLite
27443 ** still works when you do this, but concurrency is reduced since
27444 ** only a single process can be reading the database at a time.
27445 **
27446 ** Omit this section if SQLITE_ENABLE_LOCKING_STYLE is turned off or if
27447 ** compiling for VXWORKS.
27448 */
27449 #if SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS
27450
27451 /*
27452 ** Retry flock() calls that fail with EINTR
27453 */
27454 #ifdef EINTR
@@ -27597,11 +27756,11 @@
27597 static int flockUnlock(sqlite3_file *id, int eFileLock) {
27598 unixFile *pFile = (unixFile*)id;
27599
27600 assert( pFile );
27601 OSTRACE(("UNLOCK %d %d was %d pid=%d (flock)\n", pFile->h, eFileLock,
27602 pFile->eFileLock, getpid()));
27603 assert( eFileLock<=SHARED_LOCK );
27604
27605 /* no-op if possible */
27606 if( pFile->eFileLock==eFileLock ){
27607 return SQLITE_OK;
@@ -27658,11 +27817,11 @@
27658 ** This routine checks if there is a RESERVED lock held on the specified
27659 ** file by this or any other process. If such a lock is held, set *pResOut
27660 ** to a non-zero value otherwise *pResOut is set to zero. The return value
27661 ** is set to SQLITE_OK unless an I/O error occurs during lock checking.
27662 */
27663 static int semCheckReservedLock(sqlite3_file *id, int *pResOut) {
27664 int rc = SQLITE_OK;
27665 int reserved = 0;
27666 unixFile *pFile = (unixFile*)id;
27667
27668 SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; );
@@ -27725,11 +27884,11 @@
27725 ** access the file.
27726 **
27727 ** This routine will only increase a lock. Use the sqlite3OsUnlock()
27728 ** routine to lower a locking level.
27729 */
27730 static int semLock(sqlite3_file *id, int eFileLock) {
27731 unixFile *pFile = (unixFile*)id;
27732 sem_t *pSem = pFile->pInode->pSem;
27733 int rc = SQLITE_OK;
27734
27735 /* if we already have a lock, it is exclusive.
@@ -27758,18 +27917,18 @@
27758 ** must be either NO_LOCK or SHARED_LOCK.
27759 **
27760 ** If the locking level of the file descriptor is already at or below
27761 ** the requested locking level, this routine is a no-op.
27762 */
27763 static int semUnlock(sqlite3_file *id, int eFileLock) {
27764 unixFile *pFile = (unixFile*)id;
27765 sem_t *pSem = pFile->pInode->pSem;
27766
27767 assert( pFile );
27768 assert( pSem );
27769 OSTRACE(("UNLOCK %d %d was %d pid=%d (sem)\n", pFile->h, eFileLock,
27770 pFile->eFileLock, getpid()));
27771 assert( eFileLock<=SHARED_LOCK );
27772
27773 /* no-op if possible */
27774 if( pFile->eFileLock==eFileLock ){
27775 return SQLITE_OK;
@@ -27795,14 +27954,14 @@
27795 }
27796
27797 /*
27798 ** Close a file.
27799 */
27800 static int semClose(sqlite3_file *id) {
27801 if( id ){
27802 unixFile *pFile = (unixFile*)id;
27803 semUnlock(id, NO_LOCK);
27804 assert( pFile );
27805 unixEnterMutex();
27806 releaseInodeInfo(pFile);
27807 unixLeaveMutex();
27808 closeUnixFile(id);
@@ -27979,11 +28138,11 @@
27979 afpLockingContext *context = (afpLockingContext *) pFile->lockingContext;
27980
27981 assert( pFile );
27982 OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (afp)\n", pFile->h,
27983 azFileLock(eFileLock), azFileLock(pFile->eFileLock),
27984 azFileLock(pInode->eFileLock), pInode->nShared , getpid()));
27985
27986 /* If there is already a lock of this type or more restrictive on the
27987 ** unixFile, do nothing. Don't use the afp_end_lock: exit path, as
27988 ** unixEnterMutex() hasn't been called yet.
27989 */
@@ -28165,11 +28324,11 @@
28165 #endif
28166
28167 assert( pFile );
28168 OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (afp)\n", pFile->h, eFileLock,
28169 pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared,
28170 getpid()));
28171
28172 assert( eFileLock<=SHARED_LOCK );
28173 if( pFile->eFileLock<=eFileLock ){
28174 return SQLITE_OK;
28175 }
@@ -28990,10 +29149,14 @@
28990 ** Information and control of an open file handle.
28991 */
28992 static int unixFileControl(sqlite3_file *id, int op, void *pArg){
28993 unixFile *pFile = (unixFile*)id;
28994 switch( op ){
 
 
 
 
28995 case SQLITE_FCNTL_LOCKSTATE: {
28996 *(int*)pArg = pFile->eFileLock;
28997 return SQLITE_OK;
28998 }
28999 case SQLITE_FCNTL_LAST_ERRNO: {
@@ -29204,11 +29367,13 @@
29204 **
29205 ** This function should not be called directly by other code in this file.
29206 ** Instead, it should be called via macro osGetpagesize().
29207 */
29208 static int unixGetpagesize(void){
29209 #if defined(_BSD_SOURCE)
 
 
29210 return getpagesize();
29211 #else
29212 return (int)sysconf(_SC_PAGESIZE);
29213 #endif
29214 }
@@ -29297,37 +29462,42 @@
29297 **
29298 ** Locks block if the mask is exactly UNIX_SHM_C and are non-blocking
29299 ** otherwise.
29300 */
29301 static int unixShmSystemLock(
29302 unixShmNode *pShmNode, /* Apply locks to this open shared-memory segment */
29303 int lockType, /* F_UNLCK, F_RDLCK, or F_WRLCK */
29304 int ofst, /* First byte of the locking range */
29305 int n /* Number of bytes to lock */
29306 ){
29307 struct flock f; /* The posix advisory locking structure */
29308 int rc = SQLITE_OK; /* Result code form fcntl() */
 
29309
29310 /* Access to the unixShmNode object is serialized by the caller */
 
29311 assert( sqlite3_mutex_held(pShmNode->mutex) || pShmNode->nRef==0 );
29312
29313 /* Shared locks never span more than one byte */
29314 assert( n==1 || lockType!=F_RDLCK );
29315
29316 /* Locks are within range */
29317 assert( n>=1 && n<SQLITE_SHM_NLOCK );
29318
29319 if( pShmNode->h>=0 ){
 
29320 /* Initialize the locking parameters */
29321 memset(&f, 0, sizeof(f));
29322 f.l_type = lockType;
29323 f.l_whence = SEEK_SET;
29324 f.l_start = ofst;
29325 f.l_len = n;
29326
29327 rc = osFcntl(pShmNode->h, F_SETLK, &f);
 
29328 rc = (rc!=(-1)) ? SQLITE_OK : SQLITE_BUSY;
 
29329 }
29330
29331 /* Update the global lock state and do debug tracing */
29332 #ifdef SQLITE_DEBUG
29333 { u16 mask;
@@ -29533,17 +29703,17 @@
29533
29534 /* Check to see if another process is holding the dead-man switch.
29535 ** If not, truncate the file to zero length.
29536 */
29537 rc = SQLITE_OK;
29538 if( unixShmSystemLock(pShmNode, F_WRLCK, UNIX_SHM_DMS, 1)==SQLITE_OK ){
29539 if( robust_ftruncate(pShmNode->h, 0) ){
29540 rc = unixLogError(SQLITE_IOERR_SHMOPEN, "ftruncate", zShmFilename);
29541 }
29542 }
29543 if( rc==SQLITE_OK ){
29544 rc = unixShmSystemLock(pShmNode, F_RDLCK, UNIX_SHM_DMS, 1);
29545 }
29546 if( rc ) goto shm_open_err;
29547 }
29548 }
29549
@@ -29771,11 +29941,11 @@
29771 allMask |= pX->sharedMask;
29772 }
29773
29774 /* Unlock the system-level locks */
29775 if( (mask & allMask)==0 ){
29776 rc = unixShmSystemLock(pShmNode, F_UNLCK, ofst+UNIX_SHM_BASE, n);
29777 }else{
29778 rc = SQLITE_OK;
29779 }
29780
29781 /* Undo the local locks */
@@ -29799,11 +29969,11 @@
29799 }
29800
29801 /* Get shared locks at the system level, if necessary */
29802 if( rc==SQLITE_OK ){
29803 if( (allShared & mask)==0 ){
29804 rc = unixShmSystemLock(pShmNode, F_RDLCK, ofst+UNIX_SHM_BASE, n);
29805 }else{
29806 rc = SQLITE_OK;
29807 }
29808 }
29809
@@ -29824,20 +29994,20 @@
29824
29825 /* Get the exclusive locks at the system level. Then if successful
29826 ** also mark the local connection as being locked.
29827 */
29828 if( rc==SQLITE_OK ){
29829 rc = unixShmSystemLock(pShmNode, F_WRLCK, ofst+UNIX_SHM_BASE, n);
29830 if( rc==SQLITE_OK ){
29831 assert( (p->sharedMask & mask)==0 );
29832 p->exclMask |= mask;
29833 }
29834 }
29835 }
29836 sqlite3_mutex_leave(pShmNode->mutex);
29837 OSTRACE(("SHM-LOCK shmid-%d, pid-%d got %03x,%03x\n",
29838 p->id, getpid(), p->sharedMask, p->exclMask));
29839 return rc;
29840 }
29841
29842 /*
29843 ** Implement a memory barrier or memory fence on shared memory.
@@ -30236,11 +30406,11 @@
30236 dotlockUnlock, /* xUnlock method */
30237 dotlockCheckReservedLock, /* xCheckReservedLock method */
30238 0 /* xShmMap method */
30239 )
30240
30241 #if SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS
30242 IOMETHODS(
30243 flockIoFinder, /* Finder function name */
30244 flockIoMethods, /* sqlite3_io_methods object name */
30245 1, /* shared memory is disabled */
30246 flockClose, /* xClose method */
@@ -30254,14 +30424,14 @@
30254 #if OS_VXWORKS
30255 IOMETHODS(
30256 semIoFinder, /* Finder function name */
30257 semIoMethods, /* sqlite3_io_methods object name */
30258 1, /* shared memory is disabled */
30259 semClose, /* xClose method */
30260 semLock, /* xLock method */
30261 semUnlock, /* xUnlock method */
30262 semCheckReservedLock, /* xCheckReservedLock method */
30263 0 /* xShmMap method */
30264 )
30265 #endif
30266
30267 #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
@@ -30381,19 +30551,17 @@
30381 static const sqlite3_io_methods
30382 *(*const autolockIoFinder)(const char*,unixFile*) = autolockIoFinderImpl;
30383
30384 #endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */
30385
30386 #if OS_VXWORKS && SQLITE_ENABLE_LOCKING_STYLE
30387 /*
30388 ** This "finder" function attempts to determine the best locking strategy
30389 ** for the database file "filePath". It then returns the sqlite3_io_methods
30390 ** object that implements that strategy.
30391 **
30392 ** This is for VXWorks only.
30393 */
30394 static const sqlite3_io_methods *autolockIoFinderImpl(
30395 const char *filePath, /* name of the database file */
30396 unixFile *pNew /* the open file object */
30397 ){
30398 struct flock lockInfo;
30399
@@ -30415,13 +30583,13 @@
30415 }else{
30416 return &semIoMethods;
30417 }
30418 }
30419 static const sqlite3_io_methods
30420 *(*const autolockIoFinder)(const char*,unixFile*) = autolockIoFinderImpl;
30421
30422 #endif /* OS_VXWORKS && SQLITE_ENABLE_LOCKING_STYLE */
30423
30424 /*
30425 ** An abstract type for a pointer to an IO method finder function:
30426 */
30427 typedef const sqlite3_io_methods *(*finder_type)(const char*,unixFile*);
@@ -30930,12 +31098,12 @@
30930 /* Detect a pid change and reset the PRNG. There is a race condition
30931 ** here such that two or more threads all trying to open databases at
30932 ** the same instant might all reset the PRNG. But multiple resets
30933 ** are harmless.
30934 */
30935 if( randomnessPid!=getpid() ){
30936 randomnessPid = getpid();
30937 sqlite3_randomness(0,0);
30938 }
30939
30940 memset(p, 0, sizeof(unixFile));
30941
@@ -31322,11 +31490,11 @@
31322 ** When testing, initializing zBuf[] to zero is all we do. That means
31323 ** that we always use the same random number sequence. This makes the
31324 ** tests repeatable.
31325 */
31326 memset(zBuf, 0, nBuf);
31327 randomnessPid = getpid();
31328 #if !defined(SQLITE_TEST)
31329 {
31330 int fd, got;
31331 fd = robust_open("/dev/urandom", O_RDONLY, 0);
31332 if( fd<0 ){
@@ -31643,11 +31811,11 @@
31643 #else
31644 # ifdef _CS_DARWIN_USER_TEMP_DIR
31645 {
31646 if( !confstr(_CS_DARWIN_USER_TEMP_DIR, lPath, maxLen) ){
31647 OSTRACE(("GETLOCKPATH failed %s errno=%d pid=%d\n",
31648 lPath, errno, getpid()));
31649 return SQLITE_IOERR_LOCK;
31650 }
31651 len = strlcat(lPath, "sqliteplocks", maxLen);
31652 }
31653 # else
@@ -31665,11 +31833,11 @@
31665 char c = dbPath[i];
31666 lPath[i+len] = (c=='/')?'_':c;
31667 }
31668 lPath[i+len]='\0';
31669 strlcat(lPath, ":auto:", maxLen);
31670 OSTRACE(("GETLOCKPATH proxy lock path=%s pid=%d\n", lPath, getpid()));
31671 return SQLITE_OK;
31672 }
31673
31674 /*
31675 ** Creates the lock file and any missing directories in lockPath
@@ -31692,20 +31860,20 @@
31692 if( osMkdir(buf, SQLITE_DEFAULT_PROXYDIR_PERMISSIONS) ){
31693 int err=errno;
31694 if( err!=EEXIST ) {
31695 OSTRACE(("CREATELOCKPATH FAILED creating %s, "
31696 "'%s' proxy lock path=%s pid=%d\n",
31697 buf, strerror(err), lockPath, getpid()));
31698 return err;
31699 }
31700 }
31701 }
31702 start=i+1;
31703 }
31704 buf[i] = lockPath[i];
31705 }
31706 OSTRACE(("CREATELOCKPATH proxy lock path=%s pid=%d\n", lockPath, getpid()));
31707 return 0;
31708 }
31709
31710 /*
31711 ** Create a new VFS file descriptor (stored in memory obtained from
@@ -32006,11 +32174,12 @@
32006 int readLen = 0;
32007 int tryOldLockPath = 0;
32008 int forceNewLockPath = 0;
32009
32010 OSTRACE(("TAKECONCH %d for %s pid=%d\n", conchFile->h,
32011 (pCtx->lockProxyPath ? pCtx->lockProxyPath : ":auto:"), getpid()));
 
32012
32013 rc = proxyGetHostID(myHostID, &pError);
32014 if( (rc&0xff)==SQLITE_IOERR ){
32015 storeLastErrno(pFile, pError);
32016 goto end_takeconch;
@@ -32216,11 +32385,11 @@
32216
32217 pCtx = (proxyLockingContext *)pFile->lockingContext;
32218 conchFile = pCtx->conchFile;
32219 OSTRACE(("RELEASECONCH %d for %s pid=%d\n", conchFile->h,
32220 (pCtx->lockProxyPath ? pCtx->lockProxyPath : ":auto:"),
32221 getpid()));
32222 if( pCtx->conchHeld>0 ){
32223 rc = conchFile->pMethod->xUnlock((sqlite3_file*)conchFile, NO_LOCK);
32224 }
32225 pCtx->conchHeld = 0;
32226 OSTRACE(("RELEASECONCH %d %s\n", conchFile->h,
@@ -32358,11 +32527,11 @@
32358 }else{
32359 lockPath=(char *)path;
32360 }
32361
32362 OSTRACE(("TRANSPROXY %d for %s pid=%d\n", pFile->h,
32363 (lockPath ? lockPath : ":auto:"), getpid()));
32364
32365 pCtx = sqlite3_malloc( sizeof(*pCtx) );
32366 if( pCtx==0 ){
32367 return SQLITE_NOMEM;
32368 }
@@ -32699,26 +32868,28 @@
32699 ** Note that the sqlite3_vfs.pNext field of the VFS object is modified
32700 ** by the SQLite core when the VFS is registered. So the following
32701 ** array cannot be const.
32702 */
32703 static sqlite3_vfs aVfs[] = {
32704 #if SQLITE_ENABLE_LOCKING_STYLE && (OS_VXWORKS || defined(__APPLE__))
32705 UNIXVFS("unix", autolockIoFinder ),
 
 
32706 #else
32707 UNIXVFS("unix", posixIoFinder ),
32708 #endif
32709 UNIXVFS("unix-none", nolockIoFinder ),
32710 UNIXVFS("unix-dotfile", dotlockIoFinder ),
32711 UNIXVFS("unix-excl", posixIoFinder ),
32712 #if OS_VXWORKS
32713 UNIXVFS("unix-namedsem", semIoFinder ),
32714 #endif
32715 #if SQLITE_ENABLE_LOCKING_STYLE
32716 UNIXVFS("unix-posix", posixIoFinder ),
32717 #if !OS_VXWORKS
 
32718 UNIXVFS("unix-flock", flockIoFinder ),
32719 #endif
32720 #endif
32721 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
32722 UNIXVFS("unix-afp", afpIoFinder ),
32723 UNIXVFS("unix-nfs", nfsIoFinder ),
32724 UNIXVFS("unix-proxy", proxyIoFinder ),
@@ -39072,16 +39243,24 @@
39072 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0);
39073 }
39074 }
39075
39076 /*
39077 ** Compute the number of pages of cache requested.
 
 
 
39078 */
39079 static int numberOfCachePages(PCache *p){
39080 if( p->szCache>=0 ){
 
 
39081 return p->szCache;
39082 }else{
 
 
 
39083 return (int)((-1024*(i64)p->szCache)/(p->szPage+p->szExtra));
39084 }
39085 }
39086
39087 /*************************************************** General Interfaces ******
@@ -39817,20 +39996,20 @@
39817 ** in pcache1 need to be protected via mutex.
39818 */
39819 static void *pcache1Alloc(int nByte){
39820 void *p = 0;
39821 assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
39822 sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte);
39823 if( nByte<=pcache1.szSlot ){
39824 sqlite3_mutex_enter(pcache1.mutex);
39825 p = (PgHdr1 *)pcache1.pFree;
39826 if( p ){
39827 pcache1.pFree = pcache1.pFree->pNext;
39828 pcache1.nFreeSlot--;
39829 pcache1.bUnderPressure = pcache1.nFreeSlot<pcache1.nReserve;
39830 assert( pcache1.nFreeSlot>=0 );
39831 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, 1);
 
39832 }
39833 sqlite3_mutex_leave(pcache1.mutex);
39834 }
39835 if( p==0 ){
39836 /* Memory is not available in the SQLITE_CONFIG_PAGECACHE pool. Get
@@ -39839,11 +40018,12 @@
39839 p = sqlite3Malloc(nByte);
39840 #ifndef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
39841 if( p ){
39842 int sz = sqlite3MallocSize(p);
39843 sqlite3_mutex_enter(pcache1.mutex);
39844 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz);
 
39845 sqlite3_mutex_leave(pcache1.mutex);
39846 }
39847 #endif
39848 sqlite3MemdebugSetType(p, MEMTYPE_PCACHE);
39849 }
@@ -39857,11 +40037,11 @@
39857 int nFreed = 0;
39858 if( p==0 ) return 0;
39859 if( p>=pcache1.pStart && p<pcache1.pEnd ){
39860 PgFreeslot *pSlot;
39861 sqlite3_mutex_enter(pcache1.mutex);
39862 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, -1);
39863 pSlot = (PgFreeslot*)p;
39864 pSlot->pNext = pcache1.pFree;
39865 pcache1.pFree = pSlot;
39866 pcache1.nFreeSlot++;
39867 pcache1.bUnderPressure = pcache1.nFreeSlot<pcache1.nReserve;
@@ -39871,11 +40051,11 @@
39871 assert( sqlite3MemdebugHasType(p, MEMTYPE_PCACHE) );
39872 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
39873 nFreed = sqlite3MallocSize(p);
39874 #ifndef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
39875 sqlite3_mutex_enter(pcache1.mutex);
39876 sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -nFreed);
39877 sqlite3_mutex_leave(pcache1.mutex);
39878 #endif
39879 sqlite3_free(p);
39880 }
39881 return nFreed;
@@ -40607,10 +40787,18 @@
40607
40608 /*
40609 ** Return the size of the header on each page of this PCACHE implementation.
40610 */
40611 SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void){ return ROUND8(sizeof(PgHdr1)); }
 
 
 
 
 
 
 
 
40612
40613 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
40614 /*
40615 ** This function is called to free superfluous dynamically allocated memory
40616 ** held by the pager system. Memory in use by any SQLite pager allocated
@@ -49380,13 +49568,14 @@
49380 if( pWal->exclusiveMode ) return;
49381 (void)sqlite3OsShmLock(pWal->pDbFd, lockIdx, 1,
49382 SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED);
49383 WALTRACE(("WAL%p: release SHARED-%s\n", pWal, walLockName(lockIdx)));
49384 }
49385 static int walLockExclusive(Wal *pWal, int lockIdx, int n){
49386 int rc;
49387 if( pWal->exclusiveMode ) return SQLITE_OK;
 
49388 rc = sqlite3OsShmLock(pWal->pDbFd, lockIdx, n,
49389 SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE);
49390 WALTRACE(("WAL%p: acquire EXCLUSIVE-%s cnt=%d %s\n", pWal,
49391 walLockName(lockIdx), n, rc ? "failed" : "ok"));
49392 VVA_ONLY( pWal->lockError = (u8)(rc!=SQLITE_OK && rc!=SQLITE_BUSY); )
@@ -49668,11 +49857,11 @@
49668 assert( WAL_ALL_BUT_WRITE==WAL_WRITE_LOCK+1 );
49669 assert( WAL_CKPT_LOCK==WAL_ALL_BUT_WRITE );
49670 assert( pWal->writeLock );
49671 iLock = WAL_ALL_BUT_WRITE + pWal->ckptLock;
49672 nLock = SQLITE_SHM_NLOCK - iLock;
49673 rc = walLockExclusive(pWal, iLock, nLock);
49674 if( rc ){
49675 return rc;
49676 }
49677 WALTRACE(("WAL%p: recovery begin...\n", pWal));
49678
@@ -50202,11 +50391,11 @@
50202 int lockIdx, /* Offset of first byte to lock */
50203 int n /* Number of bytes to lock */
50204 ){
50205 int rc;
50206 do {
50207 rc = walLockExclusive(pWal, lockIdx, n);
50208 }while( xBusy && rc==SQLITE_BUSY && xBusy(pBusyArg) );
50209 return rc;
50210 }
50211
50212 /*
@@ -50635,11 +50824,11 @@
50635 if( pWal->readOnly & WAL_SHM_RDONLY ){
50636 if( SQLITE_OK==(rc = walLockShared(pWal, WAL_WRITE_LOCK)) ){
50637 walUnlockShared(pWal, WAL_WRITE_LOCK);
50638 rc = SQLITE_READONLY_RECOVERY;
50639 }
50640 }else if( SQLITE_OK==(rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1)) ){
50641 pWal->writeLock = 1;
50642 if( SQLITE_OK==(rc = walIndexPage(pWal, 0, &page0)) ){
50643 badHdr = walIndexTryHdr(pWal, pChanged);
50644 if( badHdr ){
50645 /* If the wal-index header is still malformed even while holding
@@ -50841,11 +51030,11 @@
50841 {
50842 if( (pWal->readOnly & WAL_SHM_RDONLY)==0
50843 && (mxReadMark<pWal->hdr.mxFrame || mxI==0)
50844 ){
50845 for(i=1; i<WAL_NREADER; i++){
50846 rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
50847 if( rc==SQLITE_OK ){
50848 mxReadMark = pInfo->aReadMark[i] = pWal->hdr.mxFrame;
50849 mxI = i;
50850 walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1);
50851 break;
@@ -51097,11 +51286,11 @@
51097 }
51098
51099 /* Only one writer allowed at a time. Get the write lock. Return
51100 ** SQLITE_BUSY if unable.
51101 */
51102 rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1);
51103 if( rc ){
51104 return rc;
51105 }
51106 pWal->writeLock = 1;
51107
@@ -51242,11 +51431,11 @@
51242 volatile WalCkptInfo *pInfo = walCkptInfo(pWal);
51243 assert( pInfo->nBackfill==pWal->hdr.mxFrame );
51244 if( pInfo->nBackfill>0 ){
51245 u32 salt1;
51246 sqlite3_randomness(4, &salt1);
51247 rc = walLockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1);
51248 if( rc==SQLITE_OK ){
51249 /* If all readers are using WAL_READ_LOCK(0) (in other words if no
51250 ** readers are currently using the WAL), then the transactions
51251 ** frames will overwrite the start of the existing log. Update the
51252 ** wal-index header to reflect this.
@@ -51567,11 +51756,11 @@
51567 if( pWal->readOnly ) return SQLITE_READONLY;
51568 WALTRACE(("WAL%p: checkpoint begins\n", pWal));
51569
51570 /* IMPLEMENTATION-OF: R-62028-47212 All calls obtain an exclusive
51571 ** "checkpoint" lock on the database file. */
51572 rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1);
51573 if( rc ){
51574 /* EVIDENCE-OF: R-10421-19736 If any other process is running a
51575 ** checkpoint operation at the same time, the lock cannot be obtained and
51576 ** SQLITE_BUSY is returned.
51577 ** EVIDENCE-OF: R-53820-33897 Even if there is a busy-handler configured,
@@ -52569,10 +52758,11 @@
52569
52570 /*
52571 ** Exit the recursive mutex on a Btree.
52572 */
52573 SQLITE_PRIVATE void sqlite3BtreeLeave(Btree *p){
 
52574 if( p->sharable ){
52575 assert( p->wantToLock>0 );
52576 p->wantToLock--;
52577 if( p->wantToLock==0 ){
52578 unlockBtreeMutex(p);
@@ -54747,12 +54937,12 @@
54747 /*
54748 ** The following asserts make sure that structures used by the btree are
54749 ** the right size. This is to guard against size changes that result
54750 ** when compiling on a different architecture.
54751 */
54752 assert( sizeof(i64)==8 || sizeof(i64)==4 );
54753 assert( sizeof(u64)==8 || sizeof(u64)==4 );
54754 assert( sizeof(u32)==4 );
54755 assert( sizeof(u16)==2 );
54756 assert( sizeof(Pgno)==4 );
54757
54758 pBt = sqlite3MallocZero( sizeof(*pBt) );
@@ -60210,11 +60400,12 @@
60210 ** the previous call, as the overflow cell data will have been
60211 ** copied either into the body of a database page or into the new
60212 ** pSpace buffer passed to the latter call to balance_nonroot().
60213 */
60214 u8 *pSpace = sqlite3PageMalloc(pCur->pBt->pageSize);
60215 rc = balance_nonroot(pParent, iIdx, pSpace, iPage==1, pCur->hints);
 
60216 if( pFree ){
60217 /* If pFree is not NULL, it points to the pSpace buffer used
60218 ** by a previous call to balance_nonroot(). Its contents are
60219 ** now stored either on real database pages or within the
60220 ** new pSpace buffer, so it may be safely freed here. */
@@ -61873,17 +62064,26 @@
61873 pBt->btsFlags &= ~BTS_NO_WAL;
61874 return rc;
61875 }
61876
61877 /*
61878 ** set the mask of hint flags for cursor pCsr. Currently the only valid
61879 ** values are 0 and BTREE_BULKLOAD.
61880 */
61881 SQLITE_PRIVATE void sqlite3BtreeCursorHints(BtCursor *pCsr, unsigned int mask){
61882 assert( mask==BTREE_BULKLOAD || mask==0 );
61883 pCsr->hints = mask;
61884 }
 
 
 
 
 
 
 
 
 
 
61885
61886 /*
61887 ** Return true if the given Btree is read-only.
61888 */
61889 SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *p){
@@ -63773,11 +63973,11 @@
63773 ** by calling sqlite3ValueNew().
63774 **
63775 ** Otherwise, if the second argument is non-zero, then this function is
63776 ** being called indirectly by sqlite3Stat4ProbeSetValue(). If it has not
63777 ** already been allocated, allocate the UnpackedRecord structure that
63778 ** that function will return to its caller here. Then return a pointer
63779 ** an sqlite3_value within the UnpackedRecord.a[] array.
63780 */
63781 static sqlite3_value *valueNew(sqlite3 *db, struct ValueNewStat4Ctx *p){
63782 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
63783 if( p ){
@@ -63817,10 +64017,117 @@
63817 UNUSED_PARAMETER(p);
63818 #endif /* defined(SQLITE_ENABLE_STAT3_OR_STAT4) */
63819 return sqlite3ValueNew(db);
63820 }
63821
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63822 /*
63823 ** Extract a value from the supplied expression in the manner described
63824 ** above sqlite3ValueFromExpr(). Allocate the sqlite3_value object
63825 ** using valueNew().
63826 **
@@ -63848,10 +64155,16 @@
63848 *ppVal = 0;
63849 return SQLITE_OK;
63850 }
63851 while( (op = pExpr->op)==TK_UPLUS ) pExpr = pExpr->pLeft;
63852 if( NEVER(op==TK_REGISTER) ) op = pExpr->op2;
 
 
 
 
 
 
63853
63854 if( op==TK_CAST ){
63855 u8 aff = sqlite3AffinityType(pExpr->u.zToken,0);
63856 rc = valueFromExpr(db, pExpr->pLeft, enc, aff, ppVal, pCtx);
63857 testcase( rc!=SQLITE_OK );
@@ -63924,10 +64237,16 @@
63924 assert( zVal[nVal]=='\'' );
63925 sqlite3VdbeMemSetStr(pVal, sqlite3HexToBlob(db, zVal, nVal), nVal/2,
63926 0, SQLITE_DYNAMIC);
63927 }
63928 #endif
 
 
 
 
 
 
63929
63930 *ppVal = pVal;
63931 return rc;
63932
63933 no_mem:
@@ -65377,11 +65696,11 @@
65377 break;
65378 }
65379 #ifndef SQLITE_OMIT_VIRTUALTABLE
65380 case P4_VTAB: {
65381 sqlite3_vtab *pVtab = pOp->p4.pVtab->pVtab;
65382 sqlite3_snprintf(nTemp, zTemp, "vtab:%p:%p", pVtab, pVtab->pModule);
65383 break;
65384 }
65385 #endif
65386 case P4_INTARRAY: {
65387 sqlite3_snprintf(nTemp, zTemp, "intarray");
@@ -66041,13 +66360,13 @@
66041 }
66042 #ifndef SQLITE_OMIT_VIRTUALTABLE
66043 else if( pCx->pVtabCursor ){
66044 sqlite3_vtab_cursor *pVtabCursor = pCx->pVtabCursor;
66045 const sqlite3_module *pModule = pVtabCursor->pVtab->pModule;
66046 p->inVtabMethod = 1;
 
66047 pModule->xClose(pVtabCursor);
66048 p->inVtabMethod = 0;
66049 }
66050 #endif
66051 }
66052
66053 /*
@@ -66402,11 +66721,11 @@
66402
66403 /* Delete the master journal file. This commits the transaction. After
66404 ** doing this the directory is synced again before any individual
66405 ** transaction files are deleted.
66406 */
66407 rc = sqlite3OsDelete(pVfs, zMaster, 1);
66408 sqlite3DbFree(db, zMaster);
66409 zMaster = 0;
66410 if( rc ){
66411 return rc;
66412 }
@@ -68615,10 +68934,14 @@
68615 }
68616 SQLITE_API const void *sqlite3_value_text16le(sqlite3_value *pVal){
68617 return sqlite3ValueText(pVal, SQLITE_UTF16LE);
68618 }
68619 #endif /* SQLITE_OMIT_UTF16 */
 
 
 
 
68620 SQLITE_API int sqlite3_value_type(sqlite3_value* pVal){
68621 static const u8 aType[] = {
68622 SQLITE_BLOB, /* 0x00 */
68623 SQLITE_NULL, /* 0x01 */
68624 SQLITE_TEXT, /* 0x02 */
@@ -68811,11 +69134,11 @@
68811 }
68812 SQLITE_API void sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){
68813 pCtx->isError = errCode;
68814 pCtx->fErrorOrAux = 1;
68815 #ifdef SQLITE_DEBUG
68816 pCtx->pVdbe->rcApp = errCode;
68817 #endif
68818 if( pCtx->pOut->flags & MEM_Null ){
68819 sqlite3VdbeMemSetStr(pCtx->pOut, sqlite3ErrStr(errCode), -1,
68820 SQLITE_UTF8, SQLITE_STATIC);
68821 }
@@ -69074,20 +69397,30 @@
69074 assert( p && p->pFunc );
69075 return p->pOut->db;
69076 }
69077
69078 /*
69079 ** Return the current time for a statement
 
 
 
 
69080 */
69081 SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context *p){
69082 Vdbe *v = p->pVdbe;
69083 int rc;
69084 if( v->iCurrentTime==0 ){
69085 rc = sqlite3OsCurrentTimeInt64(p->pOut->db->pVfs, &v->iCurrentTime);
69086 if( rc ) v->iCurrentTime = 0;
 
 
 
 
 
 
 
69087 }
69088 return v->iCurrentTime;
69089 }
69090
69091 /*
69092 ** The following is the implementation of an SQL function that always
69093 ** fails with an error message stating that the function is used in the
@@ -69153,10 +69486,15 @@
69153 */
69154 SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
69155 AuxData *pAuxData;
69156
69157 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
 
 
 
 
 
69158 for(pAuxData=pCtx->pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){
69159 if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break;
69160 }
69161
69162 return (pAuxData ? pAuxData->pAux : 0);
@@ -69176,10 +69514,15 @@
69176 AuxData *pAuxData;
69177 Vdbe *pVdbe = pCtx->pVdbe;
69178
69179 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
69180 if( iArg<0 ) goto failed;
 
 
 
 
 
69181
69182 for(pAuxData=pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){
69183 if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break;
69184 }
69185 if( pAuxData==0 ){
@@ -71290,11 +71633,11 @@
71290
71291 /* Opcode: String8 * P2 * P4 *
71292 ** Synopsis: r[P2]='P4'
71293 **
71294 ** P4 points to a nul terminated UTF-8 string. This opcode is transformed
71295 ** into a String before it is executed for the first time. During
71296 ** this transformation, the length of string P4 is computed and stored
71297 ** as the P1 parameter.
71298 */
71299 case OP_String8: { /* same as TK_STRING, out2-prerelease */
71300 assert( pOp->p4.z!=0 );
@@ -71322,22 +71665,34 @@
71322 goto too_big;
71323 }
71324 /* Fall through to the next case, OP_String */
71325 }
71326
71327 /* Opcode: String P1 P2 * P4 *
71328 ** Synopsis: r[P2]='P4' (len=P1)
71329 **
71330 ** The string value P4 of length P1 (bytes) is stored in register P2.
 
 
 
 
 
71331 */
71332 case OP_String: { /* out2-prerelease */
71333 assert( pOp->p4.z!=0 );
71334 pOut->flags = MEM_Str|MEM_Static|MEM_Term;
71335 pOut->z = pOp->p4.z;
71336 pOut->n = pOp->p1;
71337 pOut->enc = encoding;
71338 UPDATE_MAX_BLOBSIZE(pOut);
 
 
 
 
 
 
 
71339 break;
71340 }
71341
71342 /* Opcode: Null P1 P2 P3 * *
71343 ** Synopsis: r[P2..P3]=NULL
@@ -71780,11 +72135,11 @@
71780 ** max() aggregate will set to 1 if the current row is not the minimum or
71781 ** maximum. The P1 register is initialized to 0 by this instruction.
71782 **
71783 ** The interface used by the implementation of the aforementioned functions
71784 ** to retrieve the collation sequence set by this opcode is not available
71785 ** publicly, only to user functions defined in func.c.
71786 */
71787 case OP_CollSeq: {
71788 assert( pOp->p4type==P4_COLLSEQ );
71789 if( pOp->p1 ){
71790 sqlite3VdbeMemSetInt64(&aMem[pOp->p1], 0);
@@ -73325,11 +73680,16 @@
73325 ** the value of this counter needs to be restored too. */
73326 p->nStmtDefCons = db->nDeferredCons;
73327 p->nStmtDefImmCons = db->nDeferredImmCons;
73328 }
73329
73330 /* Gather the schema version number for checking */
 
 
 
 
 
73331 sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta);
73332 iGen = db->aDb[pOp->p1].pSchema->iGeneration;
73333 }else{
73334 iGen = iMeta = 0;
73335 }
@@ -73493,35 +73853,33 @@
73493 ** cursors or a single read/write cursor but not both.
73494 **
73495 ** See also OpenRead.
73496 */
73497 case OP_ReopenIdx: {
73498 VdbeCursor *pCur;
73499
73500 assert( pOp->p5==0 );
73501 assert( pOp->p4type==P4_KEYINFO );
73502 pCur = p->apCsr[pOp->p1];
73503 if( pCur && pCur->pgnoRoot==(u32)pOp->p2 ){
73504 assert( pCur->iDb==pOp->p3 ); /* Guaranteed by the code generator */
73505 break;
73506 }
73507 /* If the cursor is not currently open or is open on a different
73508 ** index, then fall through into OP_OpenRead to force a reopen */
73509 }
73510 case OP_OpenRead:
73511 case OP_OpenWrite: {
73512 int nField;
73513 KeyInfo *pKeyInfo;
73514 int p2;
73515 int iDb;
73516 int wrFlag;
73517 Btree *pX;
73518 VdbeCursor *pCur;
73519 Db *pDb;
73520
73521 assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 );
73522 assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 );
 
 
 
 
 
 
 
 
 
 
 
 
73523 assert( p->bIsReader );
73524 assert( pOp->opcode==OP_OpenRead || pOp->opcode==OP_ReopenIdx
73525 || p->readOnly==0 );
73526
73527 if( p->expired ){
@@ -73580,18 +73938,21 @@
73580 pCur->nullRow = 1;
73581 pCur->isOrdered = 1;
73582 pCur->pgnoRoot = p2;
73583 rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->pCursor);
73584 pCur->pKeyInfo = pKeyInfo;
73585 assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
73586 sqlite3BtreeCursorHints(pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR));
73587
73588 /* Set the VdbeCursor.isTable variable. Previous versions of
73589 ** SQLite used to check if the root-page flags were sane at this point
73590 ** and report database corruption if they were not, but this check has
73591 ** since moved into the btree layer. */
73592 pCur->isTable = pOp->p4type!=P4_KEYINFO;
 
 
 
 
 
 
73593 break;
73594 }
73595
73596 /* Opcode: OpenEphemeral P1 P2 * P4 P5
73597 ** Synopsis: nColumn=P2
@@ -73848,10 +74209,26 @@
73848 oc = pOp->opcode;
73849 pC->nullRow = 0;
73850 #ifdef SQLITE_DEBUG
73851 pC->seekOp = pOp->opcode;
73852 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73853 if( pC->isTable ){
73854 /* The input value in P3 might be of any type: integer, real, string,
73855 ** blob, or NULL. But it needs to be an integer before we can do
73856 ** the seek, so convert it. */
73857 pIn3 = &aMem[pOp->p3];
@@ -75187,34 +75564,19 @@
75187 **
75188 ** See also: Clear
75189 */
75190 case OP_Destroy: { /* out2-prerelease */
75191 int iMoved;
75192 int iCnt;
75193 Vdbe *pVdbe;
75194 int iDb;
75195
75196 assert( p->readOnly==0 );
75197 #ifndef SQLITE_OMIT_VIRTUALTABLE
75198 iCnt = 0;
75199 for(pVdbe=db->pVdbe; pVdbe; pVdbe = pVdbe->pNext){
75200 if( pVdbe->magic==VDBE_MAGIC_RUN && pVdbe->bIsReader
75201 && pVdbe->inVtabMethod<2 && pVdbe->pc>=0
75202 ){
75203 iCnt++;
75204 }
75205 }
75206 #else
75207 iCnt = db->nVdbeRead;
75208 #endif
75209 pOut->flags = MEM_Null;
75210 if( iCnt>1 ){
75211 rc = SQLITE_LOCKED;
75212 p->errorAction = OE_Abort;
75213 }else{
75214 iDb = pOp->p3;
75215 assert( iCnt==1 );
75216 assert( DbMaskTest(p->btreeMask, iDb) );
75217 iMoved = 0; /* Not needed. Only to silence a warning. */
75218 rc = sqlite3BtreeDropTable(db->aDb[iDb].pBt, pOp->p1, &iMoved);
75219 pOut->flags = MEM_Int;
75220 pOut->u.i = iMoved;
@@ -75843,14 +76205,16 @@
75843 #endif /* SQLITE_OMIT_AUTOINCREMENT */
75844
75845 /* Opcode: IfPos P1 P2 * * *
75846 ** Synopsis: if r[P1]>0 goto P2
75847 **
75848 ** If the value of register P1 is 1 or greater, jump to P2.
 
 
75849 **
75850 ** It is illegal to use this instruction on a register that does
75851 ** not contain an integer. An assertion fault will result if you try.
75852 */
75853 case OP_IfPos: { /* jump, in1 */
75854 pIn1 = &aMem[pOp->p1];
75855 assert( pIn1->flags&MEM_Int );
75856 VdbeBranchTaken( pIn1->u.i>0, 2);
@@ -75875,27 +76239,63 @@
75875 pc = pOp->p2 - 1;
75876 }
75877 break;
75878 }
75879
75880 /* Opcode: IfZero P1 P2 P3 * *
75881 ** Synopsis: r[P1]+=P3, if r[P1]==0 goto P2
75882 **
75883 ** The register P1 must contain an integer. Add literal P3 to the
75884 ** value in register P1. If the result is exactly 0, jump to P2.
 
75885 */
75886 case OP_IfZero: { /* jump, in1 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75887 pIn1 = &aMem[pOp->p1];
75888 assert( pIn1->flags&MEM_Int );
75889 pIn1->u.i += pOp->p3;
75890 VdbeBranchTaken(pIn1->u.i==0, 2);
75891 if( pIn1->u.i==0 ){
75892 pc = pOp->p2 - 1;
75893 }
75894 break;
75895 }
75896
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75897 /* Opcode: AggStep * P2 P3 P4 P5
75898 ** Synopsis: accum=r[P3] step(r[P2@P5])
75899 **
75900 ** Execute the step function for an aggregate. The
75901 ** function has P5 arguments. P4 is a pointer to the FuncDef
@@ -76229,17 +76629,33 @@
76229 break;
76230 }
76231 #endif /* SQLITE_OMIT_VIRTUALTABLE */
76232
76233 #ifndef SQLITE_OMIT_VIRTUALTABLE
76234 /* Opcode: VCreate P1 * * P4 *
76235 **
76236 ** P4 is the name of a virtual table in database P1. Call the xCreate method
76237 ** for that table.
76238 */
76239 case OP_VCreate: {
76240 rc = sqlite3VtabCallCreate(db, pOp->p1, pOp->p4.z, &p->zErrMsg);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76241 break;
76242 }
76243 #endif /* SQLITE_OMIT_VIRTUALTABLE */
76244
76245 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -76247,13 +76663,13 @@
76247 **
76248 ** P4 is the name of a virtual table in database P1. Call the xDestroy method
76249 ** of that table.
76250 */
76251 case OP_VDestroy: {
76252 p->inVtabMethod = 2;
76253 rc = sqlite3VtabCallDestroy(db, pOp->p1, pOp->p4.z);
76254 p->inVtabMethod = 0;
76255 break;
76256 }
76257 #endif /* SQLITE_OMIT_VIRTUALTABLE */
76258
76259 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -76265,18 +76681,21 @@
76265 */
76266 case OP_VOpen: {
76267 VdbeCursor *pCur;
76268 sqlite3_vtab_cursor *pVtabCursor;
76269 sqlite3_vtab *pVtab;
76270 sqlite3_module *pModule;
76271
76272 assert( p->bIsReader );
76273 pCur = 0;
76274 pVtabCursor = 0;
76275 pVtab = pOp->p4.pVtab->pVtab;
76276 pModule = (sqlite3_module *)pVtab->pModule;
76277 assert(pVtab && pModule);
 
 
 
76278 rc = pModule->xOpen(pVtab, &pVtabCursor);
76279 sqlite3VtabImportErrmsg(p, pVtab);
76280 if( SQLITE_OK==rc ){
76281 /* Initialize sqlite3_vtab_cursor base class */
76282 pVtabCursor->pVtab = pVtab;
@@ -76283,10 +76702,11 @@
76283
76284 /* Initialize vdbe cursor object */
76285 pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
76286 if( pCur ){
76287 pCur->pVtabCursor = pVtabCursor;
 
76288 }else{
76289 db->mallocFailed = 1;
76290 pModule->xClose(pVtabCursor);
76291 }
76292 }
@@ -76348,13 +76768,11 @@
76348 apArg = p->apArg;
76349 for(i = 0; i<nArg; i++){
76350 apArg[i] = &pArgc[i+1];
76351 }
76352
76353 p->inVtabMethod = 1;
76354 rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg);
76355 p->inVtabMethod = 0;
76356 sqlite3VtabImportErrmsg(p, pVtab);
76357 if( rc==SQLITE_OK ){
76358 res = pModule->xEof(pVtabCursor);
76359 }
76360 VdbeBranchTaken(res!=0,2);
@@ -76440,13 +76858,11 @@
76440 ** underlying implementation to return an error if one occurs during
76441 ** xNext(). Instead, if an error occurs, true is returned (indicating that
76442 ** data is available) and the error code returned when xColumn or
76443 ** some other method is next invoked on the save virtual table cursor.
76444 */
76445 p->inVtabMethod = 1;
76446 rc = pModule->xNext(pCur->pVtabCursor);
76447 p->inVtabMethod = 0;
76448 sqlite3VtabImportErrmsg(p, pVtab);
76449 if( rc==SQLITE_OK ){
76450 res = pModule->xEof(pCur->pVtabCursor);
76451 }
76452 VdbeBranchTaken(!res,2);
@@ -76517,11 +76933,11 @@
76517 ** P5 is the error actions (OE_Replace, OE_Fail, OE_Ignore, etc) to
76518 ** apply in the case of a constraint failure on an insert or update.
76519 */
76520 case OP_VUpdate: {
76521 sqlite3_vtab *pVtab;
76522 sqlite3_module *pModule;
76523 int nArg;
76524 int i;
76525 sqlite_int64 rowid;
76526 Mem **apArg;
76527 Mem *pX;
@@ -76529,11 +76945,15 @@
76529 assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback
76530 || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace
76531 );
76532 assert( p->readOnly==0 );
76533 pVtab = pOp->p4.pVtab->pVtab;
76534 pModule = (sqlite3_module *)pVtab->pModule;
 
 
 
 
76535 nArg = pOp->p2;
76536 assert( pOp->p4type==P4_VTAB );
76537 if( ALWAYS(pModule->xUpdate) ){
76538 u8 vtabOnConflict = db->vtabOnConflict;
76539 apArg = p->apArg;
@@ -78399,10 +78819,11 @@
78399 sqlite3 *db, /* Database handle doing sort */
78400 i64 nExtend, /* Attempt to extend file to this size */
78401 sqlite3_file **ppFd
78402 ){
78403 int rc;
 
78404 rc = sqlite3OsOpenMalloc(db->pVfs, 0, ppFd,
78405 SQLITE_OPEN_TEMP_JOURNAL |
78406 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE |
78407 SQLITE_OPEN_EXCLUSIVE | SQLITE_OPEN_DELETEONCLOSE, &rc
78408 );
@@ -81990,14 +82411,15 @@
81990 ** and the pExpr parameter is returned unchanged.
81991 */
81992 SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(
81993 Parse *pParse, /* Parsing context */
81994 Expr *pExpr, /* Add the "COLLATE" clause to this expression */
81995 const Token *pCollName /* Name of collating sequence */
 
81996 ){
81997 if( pCollName->n>0 ){
81998 Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, 1);
81999 if( pNew ){
82000 pNew->pLeft = pExpr;
82001 pNew->flags |= EP_Collate|EP_Skip;
82002 pExpr = pNew;
82003 }
@@ -82007,11 +82429,11 @@
82007 SQLITE_PRIVATE Expr *sqlite3ExprAddCollateString(Parse *pParse, Expr *pExpr, const char *zC){
82008 Token s;
82009 assert( zC!=0 );
82010 s.z = zC;
82011 s.n = sqlite3Strlen30(s.z);
82012 return sqlite3ExprAddCollateToken(pParse, pExpr, &s);
82013 }
82014
82015 /*
82016 ** Skip over any TK_COLLATE or TK_AS operators and any unlikely()
82017 ** or likelihood() function at the root of an expression.
@@ -82317,10 +82739,11 @@
82317 **
82318 ** Also propagate all EP_Propagate flags from the Expr.x.pList into
82319 ** Expr.flags.
82320 */
82321 SQLITE_PRIVATE void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){
 
82322 exprSetHeight(p);
82323 sqlite3ExprCheckHeight(pParse, p->nHeight);
82324 }
82325
82326 /*
@@ -87031,11 +87454,14 @@
87031 /* Ensure the default expression is something that sqlite3ValueFromExpr()
87032 ** can handle (i.e. not CURRENT_TIME etc.)
87033 */
87034 if( pDflt ){
87035 sqlite3_value *pVal = 0;
87036 if( sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal) ){
 
 
 
87037 db->mallocFailed = 1;
87038 return;
87039 }
87040 if( !pVal ){
87041 sqlite3ErrorMsg(pParse, "Cannot add a column with non-constant default");
@@ -93094,10 +93520,11 @@
93094 }
93095 if( pIdx->onError==OE_Default ){
93096 pIdx->onError = pIndex->onError;
93097 }
93098 }
 
93099 goto exit_create_index;
93100 }
93101 }
93102 }
93103
@@ -95553,11 +95980,13 @@
95553
95554 /*
95555 ** Return the collating function associated with a function.
95556 */
95557 static CollSeq *sqlite3GetFuncCollSeq(sqlite3_context *context){
95558 VdbeOp *pOp = &context->pVdbe->aOp[context->iOp-1];
 
 
95559 assert( pOp->opcode==OP_CollSeq );
95560 assert( pOp->p4type==P4_COLLSEQ );
95561 return pOp->p4.pColl;
95562 }
95563
@@ -97181,10 +97610,15 @@
97181 ** pExpr points to an expression which implements a function. If
97182 ** it is appropriate to apply the LIKE optimization to that function
97183 ** then set aWc[0] through aWc[2] to the wildcard characters and
97184 ** return TRUE. If the function is not a LIKE-style function then
97185 ** return FALSE.
 
 
 
 
 
97186 */
97187 SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
97188 FuncDef *pDef;
97189 if( pExpr->op!=TK_FUNCTION
97190 || !pExpr->x.pList
@@ -102972,10 +103406,21 @@
102972 }
102973
102974 /* Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS
102975 ** connection. If it returns SQLITE_OK, then assume that the VFS
102976 ** handled the pragma and generate a no-op prepared statement.
 
 
 
 
 
 
 
 
 
 
 
102977 */
102978 aFcntl[0] = 0;
102979 aFcntl[1] = zLeft;
102980 aFcntl[2] = zRight;
102981 aFcntl[3] = 0;
@@ -103732,34 +104177,46 @@
103732 Index *pIdx;
103733 Table *pTab;
103734 pIdx = sqlite3FindIndex(db, zRight, zDb);
103735 if( pIdx ){
103736 int i;
103737 int mx = pPragma->iArg ? pIdx->nColumn : pIdx->nKeyCol;
 
 
 
 
 
 
 
 
 
103738 pTab = pIdx->pTable;
103739 sqlite3VdbeSetNumCols(v, 6);
103740 pParse->nMem = 6;
103741 sqlite3CodeVerifySchema(pParse, iDb);
103742 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", SQLITE_STATIC);
103743 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", SQLITE_STATIC);
103744 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", SQLITE_STATIC);
103745 sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "desc", SQLITE_STATIC);
103746 sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "coll", SQLITE_STATIC);
103747 sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "key", SQLITE_STATIC);
 
 
103748 for(i=0; i<mx; i++){
103749 i16 cnum = pIdx->aiColumn[i];
103750 sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
103751 sqlite3VdbeAddOp2(v, OP_Integer, cnum, 2);
103752 if( cnum<0 ){
103753 sqlite3VdbeAddOp2(v, OP_Null, 0, 3);
103754 }else{
103755 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0);
103756 }
103757 sqlite3VdbeAddOp2(v, OP_Integer, pIdx->aSortOrder[i], 4);
103758 sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, pIdx->azColl[i], 0);
103759 sqlite3VdbeAddOp2(v, OP_Integer, i<pIdx->nKeyCol, 6);
103760 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
 
 
103761 }
103762 }
103763 }
103764 break;
103765
@@ -104457,12 +104914,13 @@
104457 #endif
104458
104459 /*
104460 ** PRAGMA shrink_memory
104461 **
104462 ** This pragma attempts to free as much memory as possible from the
104463 ** current database connection.
 
104464 */
104465 case PragTyp_SHRINK_MEMORY: {
104466 sqlite3_db_release_memory(db);
104467 break;
104468 }
@@ -104487,12 +104945,16 @@
104487
104488 /*
104489 ** PRAGMA soft_heap_limit
104490 ** PRAGMA soft_heap_limit = N
104491 **
104492 ** Call sqlite3_soft_heap_limit64(N). Return the result. If N is omitted,
104493 ** use -1.
 
 
 
 
104494 */
104495 case PragTyp_SOFT_HEAP_LIMIT: {
104496 sqlite3_int64 N;
104497 if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){
104498 sqlite3_soft_heap_limit64(N);
@@ -106065,24 +106527,21 @@
106065 }else{
106066 op = OP_IdxInsert;
106067 }
106068 sqlite3VdbeAddOp2(v, op, pSort->iECursor, regRecord);
106069 if( pSelect->iLimit ){
106070 int addr1, addr2;
106071 int iLimit;
106072 if( pSelect->iOffset ){
106073 iLimit = pSelect->iOffset+1;
106074 }else{
106075 iLimit = pSelect->iLimit;
106076 }
106077 addr1 = sqlite3VdbeAddOp1(v, OP_IfZero, iLimit); VdbeCoverage(v);
106078 sqlite3VdbeAddOp2(v, OP_AddImm, iLimit, -1);
106079 addr2 = sqlite3VdbeAddOp0(v, OP_Goto);
106080 sqlite3VdbeJumpHere(v, addr1);
106081 sqlite3VdbeAddOp1(v, OP_Last, pSort->iECursor);
106082 sqlite3VdbeAddOp1(v, OP_Delete, pSort->iECursor);
106083 sqlite3VdbeJumpHere(v, addr2);
106084 }
106085 }
106086
106087 /*
106088 ** Add code to implement the OFFSET
@@ -106475,11 +106934,11 @@
106475 /* Jump to the end of the loop if the LIMIT is reached. Except, if
106476 ** there is a sorter, in which case the sorter has already limited
106477 ** the output for us.
106478 */
106479 if( pSort==0 && p->iLimit ){
106480 sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1); VdbeCoverage(v);
106481 }
106482 }
106483
106484 /*
106485 ** Allocate a KeyInfo object sufficient for an index of N key columns and
@@ -107328,11 +107787,11 @@
107328 }
107329 }else{
107330 sqlite3ExprCode(pParse, p->pLimit, iLimit);
107331 sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit); VdbeCoverage(v);
107332 VdbeComment((v, "LIMIT counter"));
107333 sqlite3VdbeAddOp2(v, OP_IfZero, iLimit, iBreak); VdbeCoverage(v);
107334 }
107335 if( p->pOffset ){
107336 p->iOffset = iOffset = ++pParse->nMem;
107337 pParse->nMem++; /* Allocate an extra register for limit+offset */
107338 sqlite3ExprCode(pParse, p->pOffset, iOffset);
@@ -107547,11 +108006,11 @@
107547 addrCont = sqlite3VdbeMakeLabel(v);
107548 codeOffset(v, regOffset, addrCont);
107549 selectInnerLoop(pParse, p, p->pEList, iCurrent,
107550 0, 0, pDest, addrCont, addrBreak);
107551 if( regLimit ){
107552 sqlite3VdbeAddOp3(v, OP_IfZero, regLimit, addrBreak, -1);
107553 VdbeCoverage(v);
107554 }
107555 sqlite3VdbeResolveLabel(v, addrCont);
107556
107557 /* Execute the recursive SELECT taking the single row in Current as
@@ -107772,11 +108231,11 @@
107772 }
107773 p->pPrior = 0;
107774 p->iLimit = pPrior->iLimit;
107775 p->iOffset = pPrior->iOffset;
107776 if( p->iLimit ){
107777 addr = sqlite3VdbeAddOp1(v, OP_IfZero, p->iLimit); VdbeCoverage(v);
107778 VdbeComment((v, "Jump ahead if LIMIT reached"));
107779 }
107780 explainSetInteger(iSub2, pParse->iNextSelectId);
107781 rc = sqlite3Select(pParse, p, &dest);
107782 testcase( rc!=SQLITE_OK );
@@ -108173,11 +108632,11 @@
108173 }
108174
108175 /* Jump to the end of the loop if the LIMIT is reached.
108176 */
108177 if( p->iLimit ){
108178 sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1); VdbeCoverage(v);
108179 }
108180
108181 /* Generate the subroutine return
108182 */
108183 sqlite3VdbeResolveLabel(v, iContinue);
@@ -109540,11 +109999,11 @@
109540 sqlite3WalkSelect(pWalker, bMayRecursive ? pSel->pPrior : pSel);
109541
109542 for(pLeft=pSel; pLeft->pPrior; pLeft=pLeft->pPrior);
109543 pEList = pLeft->pEList;
109544 if( pCte->pCols ){
109545 if( pEList->nExpr!=pCte->pCols->nExpr ){
109546 sqlite3ErrorMsg(pParse, "table %s has %d values for %d columns",
109547 pCte->zName, pEList->nExpr, pCte->pCols->nExpr
109548 );
109549 pParse->pWith = pSavedWith;
109550 return SQLITE_ERROR;
@@ -113966,10 +114425,11 @@
113966 */
113967 if( !db->init.busy ){
113968 char *zStmt;
113969 char *zWhere;
113970 int iDb;
 
113971 Vdbe *v;
113972
113973 /* Compute the complete text of the CREATE VIRTUAL TABLE statement */
113974 if( pEnd ){
113975 pParse->sNameToken.n = (int)(pEnd->z - pParse->sNameToken.z) + pEnd->n;
@@ -114000,12 +114460,14 @@
114000 sqlite3ChangeCookie(pParse, iDb);
114001
114002 sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
114003 zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
114004 sqlite3VdbeAddParseSchemaOp(v, iDb, zWhere);
114005 sqlite3VdbeAddOp4(v, OP_VCreate, iDb, 0, 0,
114006 pTab->zName, sqlite3Strlen30(pTab->zName) + 1);
 
 
114007 }
114008
114009 /* If we are rereading the sqlite_master table create the in-memory
114010 ** record of the table. The xConnect() method is not called until
114011 ** the first time the virtual table is used in an SQL statement. This
@@ -114354,15 +114816,19 @@
114354 int rc = SQLITE_OK;
114355 Table *pTab;
114356
114357 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
114358 if( ALWAYS(pTab!=0 && pTab->pVTable!=0) ){
114359 VTable *p = vtabDisconnectAll(db, pTab);
114360
114361 assert( rc==SQLITE_OK );
 
 
 
 
 
114362 rc = p->pMod->pModule->xDestroy(p->pVtab);
114363
114364 /* Remove the sqlite3_vtab* from the aVTrans[] array, if applicable */
114365 if( rc==SQLITE_OK ){
114366 assert( pTab->pVTable==p && p->pNext==0 );
114367 p->pVtab = 0;
114368 pTab->pVTable = 0;
@@ -114787,10 +115253,12 @@
114787 int addrNxt; /* Jump here to start the next IN combination */
114788 int addrSkip; /* Jump here for next iteration of skip-scan */
114789 int addrCont; /* Jump here to continue with the next loop cycle */
114790 int addrFirst; /* First instruction of interior of the loop */
114791 int addrBody; /* Beginning of the body of this loop */
 
 
114792 u8 iFrom; /* Which entry in the FROM clause */
114793 u8 op, p3, p5; /* Opcode, P3 & P5 of the opcode that ends the loop */
114794 int p1, p2; /* Operands of the opcode used to ends the loop */
114795 union { /* Information that depends on pWLoop->wsFlags */
114796 struct {
@@ -114971,11 +115439,11 @@
114971 WhereOrInfo *pOrInfo; /* Extra information if (eOperator & WO_OR)!=0 */
114972 WhereAndInfo *pAndInfo; /* Extra information if (eOperator& WO_AND)!=0 */
114973 } u;
114974 LogEst truthProb; /* Probability of truth for this expression */
114975 u16 eOperator; /* A WO_xx value describing <op> */
114976 u8 wtFlags; /* TERM_xxx bit flags. See below */
114977 u8 nChild; /* Number of children that must disable us */
114978 WhereClause *pWC; /* The clause this term is part of */
114979 Bitmask prereqRight; /* Bitmask of tables used by pExpr->pRight */
114980 Bitmask prereqAll; /* Bitmask of tables referenced by pExpr */
114981 };
@@ -114993,10 +115461,13 @@
114993 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
114994 # define TERM_VNULL 0x80 /* Manufactured x>NULL or x<=NULL term */
114995 #else
114996 # define TERM_VNULL 0x00 /* Disabled if not using stat3 */
114997 #endif
 
 
 
114998
114999 /*
115000 ** An instance of the WhereScan object is used as an iterator for locating
115001 ** terms in the WHERE clause that are useful to the query planner.
115002 */
@@ -115368,11 +115839,11 @@
115368 ** WARNING: This routine might reallocate the space used to store
115369 ** WhereTerms. All pointers to WhereTerms should be invalidated after
115370 ** calling this routine. Such pointers may be reinitialized by referencing
115371 ** the pWC->a[] array.
115372 */
115373 static int whereClauseInsert(WhereClause *pWC, Expr *p, u8 wtFlags){
115374 WhereTerm *pTerm;
115375 int idx;
115376 testcase( wtFlags & TERM_VIRTUAL );
115377 if( pWC->nTerm>=pWC->nSlot ){
115378 WhereTerm *pOld = pWC->a;
@@ -115793,11 +116264,15 @@
115793 ** Check to see if the given expression is a LIKE or GLOB operator that
115794 ** can be optimized using inequality constraints. Return TRUE if it is
115795 ** so and false if not.
115796 **
115797 ** In order for the operator to be optimizible, the RHS must be a string
115798 ** literal that does not begin with a wildcard.
 
 
 
 
115799 */
115800 static int isLikeOrGlob(
115801 Parse *pParse, /* Parsing and code generating context */
115802 Expr *pExpr, /* Test this expression */
115803 Expr **ppPrefix, /* Pointer to TK_STRING expression with pattern prefix */
@@ -115822,11 +116297,11 @@
115822 #endif
115823 pList = pExpr->x.pList;
115824 pLeft = pList->a[1].pExpr;
115825 if( pLeft->op!=TK_COLUMN
115826 || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT
115827 || IsVirtual(pLeft->pTab)
115828 ){
115829 /* IMP: R-02065-49465 The left-hand side of the LIKE or GLOB operator must
115830 ** be the name of an indexed column with TEXT affinity. */
115831 return 0;
115832 }
@@ -115931,10 +116406,83 @@
115931 static void markTermAsChild(WhereClause *pWC, int iChild, int iParent){
115932 pWC->a[iChild].iParent = iParent;
115933 pWC->a[iChild].truthProb = pWC->a[iParent].truthProb;
115934 pWC->a[iParent].nChild++;
115935 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115936
115937 #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
115938 /*
115939 ** Analyze a term that consists of two or more OR-connected
115940 ** subterms. So in:
@@ -115956,10 +116504,11 @@
115956 ** (A) t1.x=t2.y OR t1.x=t2.z OR t1.y=15 OR t1.z=t3.a+5
115957 ** (B) x=expr1 OR expr2=x OR x=expr3
115958 ** (C) t1.x=t2.y OR (t1.x=t2.z AND t1.y=15)
115959 ** (D) x=expr1 OR (y>11 AND y<22 AND z LIKE '*hello*')
115960 ** (E) (p.a=1 AND q.b=2 AND r.c=3) OR (p.x=4 AND q.y=5 AND r.z=6)
 
115961 **
115962 ** CASE 1:
115963 **
115964 ** If all subterms are of the form T.C=expr for some single column of C and
115965 ** a single table T (as shown in example B above) then create a new virtual
@@ -115971,10 +116520,20 @@
115971 ** then create a new virtual term like this:
115972 **
115973 ** x IN (expr1,expr2,expr3)
115974 **
115975 ** CASE 2:
 
 
 
 
 
 
 
 
 
 
115976 **
115977 ** If all subterms are indexable by a single table T, then set
115978 **
115979 ** WhereTerm.eOperator = WO_OR
115980 ** WhereTerm.u.pOrInfo->indexable |= the cursor number for table T
@@ -116098,15 +116657,29 @@
116098 }
116099 }
116100 }
116101
116102 /*
116103 ** Record the set of tables that satisfy case 2. The set might be
116104 ** empty.
116105 */
116106 pOrInfo->indexable = indexable;
116107 pTerm->eOperator = indexable==0 ? 0 : WO_OR;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116108
116109 /*
116110 ** chngToIN holds a set of tables that *might* satisfy case 1. But
116111 ** we have to do some additional checking to see if case 1 really
116112 ** is satisfied.
@@ -116233,11 +116806,11 @@
116233 pTerm = &pWC->a[idxTerm];
116234 markTermAsChild(pWC, idxNew, idxTerm);
116235 }else{
116236 sqlite3ExprListDelete(db, pList);
116237 }
116238 pTerm->eOperator = WO_NOOP; /* case 1 trumps case 2 */
116239 }
116240 }
116241 }
116242 #endif /* !SQLITE_OMIT_OR_OPTIMIZATION && !SQLITE_OMIT_SUBQUERY */
116243
@@ -116271,11 +116844,11 @@
116271 Bitmask prereqLeft; /* Prerequesites of the pExpr->pLeft */
116272 Bitmask prereqAll; /* Prerequesites of pExpr */
116273 Bitmask extraRight = 0; /* Extra dependencies on LEFT JOIN */
116274 Expr *pStr1 = 0; /* RHS of LIKE/GLOB operator */
116275 int isComplete = 0; /* RHS of LIKE/GLOB ends with wildcard */
116276 int noCase = 0; /* LIKE/GLOB distinguishes case */
116277 int op; /* Top-level operator. pExpr->op */
116278 Parse *pParse = pWInfo->pParse; /* Parsing context */
116279 sqlite3 *db = pParse->db; /* Database connection */
116280
116281 if( db->mallocFailed ){
@@ -116409,16 +116982,19 @@
116409
116410 #ifndef SQLITE_OMIT_LIKE_OPTIMIZATION
116411 /* Add constraints to reduce the search space on a LIKE or GLOB
116412 ** operator.
116413 **
116414 ** A like pattern of the form "x LIKE 'abc%'" is changed into constraints
116415 **
116416 ** x>='abc' AND x<'abd' AND x LIKE 'abc%'
116417 **
116418 ** The last character of the prefix "abc" is incremented to form the
116419 ** termination condition "abd".
 
 
 
116420 */
116421 if( pWC->op==TK_AND
116422 && isLikeOrGlob(pParse, pExpr, &pStr1, &isComplete, &noCase)
116423 ){
116424 Expr *pLeft; /* LHS of LIKE/GLOB operator */
@@ -116425,14 +117001,30 @@
116425 Expr *pStr2; /* Copy of pStr1 - RHS of LIKE/GLOB operator */
116426 Expr *pNewExpr1;
116427 Expr *pNewExpr2;
116428 int idxNew1;
116429 int idxNew2;
116430 Token sCollSeqName; /* Name of collating sequence */
 
116431
116432 pLeft = pExpr->x.pList->a[1].pExpr;
116433 pStr2 = sqlite3ExprDup(db, pStr1, 0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116434 if( !db->mallocFailed ){
116435 u8 c, *pC; /* Last character before the first wildcard */
116436 pC = (u8*)&pStr2->u.zToken[sqlite3Strlen30(pStr2->u.zToken)-1];
116437 c = *pC;
116438 if( noCase ){
@@ -116445,26 +117037,25 @@
116445 if( c=='A'-1 ) isComplete = 0;
116446 c = sqlite3UpperToLower[c];
116447 }
116448 *pC = c + 1;
116449 }
116450 sCollSeqName.z = noCase ? "NOCASE" : "BINARY";
116451 sCollSeqName.n = 6;
116452 pNewExpr1 = sqlite3ExprDup(db, pLeft, 0);
116453 pNewExpr1 = sqlite3PExpr(pParse, TK_GE,
116454 sqlite3ExprAddCollateToken(pParse,pNewExpr1,&sCollSeqName),
116455 pStr1, 0);
116456 transferJoinMarkings(pNewExpr1, pExpr);
116457 idxNew1 = whereClauseInsert(pWC, pNewExpr1, TERM_VIRTUAL|TERM_DYNAMIC);
116458 testcase( idxNew1==0 );
116459 exprAnalyze(pSrc, pWC, idxNew1);
116460 pNewExpr2 = sqlite3ExprDup(db, pLeft, 0);
116461 pNewExpr2 = sqlite3PExpr(pParse, TK_LT,
116462 sqlite3ExprAddCollateToken(pParse,pNewExpr2,&sCollSeqName),
116463 pStr2, 0);
116464 transferJoinMarkings(pNewExpr2, pExpr);
116465 idxNew2 = whereClauseInsert(pWC, pNewExpr2, TERM_VIRTUAL|TERM_DYNAMIC);
116466 testcase( idxNew2==0 );
116467 exprAnalyze(pSrc, pWC, idxNew2);
116468 pTerm = &pWC->a[idxTerm];
116469 if( isComplete ){
116470 markTermAsChild(pWC, idxNew1, idxTerm);
@@ -117074,15 +117665,18 @@
117074 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
117075 /*
117076 ** Estimate the location of a particular key among all keys in an
117077 ** index. Store the results in aStat as follows:
117078 **
117079 ** aStat[0] Est. number of rows less than pVal
117080 ** aStat[1] Est. number of rows equal to pVal
117081 **
117082 ** Return the index of the sample that is the smallest sample that
117083 ** is greater than or equal to pRec.
 
 
 
117084 */
117085 static int whereKeyStats(
117086 Parse *pParse, /* Database connection */
117087 Index *pIdx, /* Index to consider domain of */
117088 UnpackedRecord *pRec, /* Vector of values to consider */
@@ -117089,71 +117683,162 @@
117089 int roundUp, /* Round up if true. Round down if false */
117090 tRowcnt *aStat /* OUT: stats written here */
117091 ){
117092 IndexSample *aSample = pIdx->aSample;
117093 int iCol; /* Index of required stats in anEq[] etc. */
 
 
117094 int iMin = 0; /* Smallest sample not yet tested */
117095 int i = pIdx->nSample; /* Smallest sample larger than or equal to pRec */
117096 int iTest; /* Next sample to test */
117097 int res; /* Result of comparison operation */
 
 
117098
117099 #ifndef SQLITE_DEBUG
117100 UNUSED_PARAMETER( pParse );
117101 #endif
117102 assert( pRec!=0 );
117103 iCol = pRec->nField - 1;
117104 assert( pIdx->nSample>0 );
117105 assert( pRec->nField>0 && iCol<pIdx->nSampleCol );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117106 do{
117107 iTest = (iMin+i)/2;
117108 res = sqlite3VdbeRecordCompare(aSample[iTest].n, aSample[iTest].p, pRec);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117109 if( res<0 ){
 
 
 
 
117110 iMin = iTest+1;
 
117111 }else{
117112 i = iTest;
 
117113 }
117114 }while( res && iMin<i );
 
117115
117116 #ifdef SQLITE_DEBUG
117117 /* The following assert statements check that the binary search code
117118 ** above found the right answer. This block serves no purpose other
117119 ** than to invoke the asserts. */
117120 if( res==0 ){
117121 /* If (res==0) is true, then sample $i must be equal to pRec */
117122 assert( i<pIdx->nSample );
117123 assert( 0==sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)
117124 || pParse->db->mallocFailed );
117125 }else{
117126 /* Otherwise, pRec must be smaller than sample $i and larger than
117127 ** sample ($i-1). */
117128 assert( i==pIdx->nSample
117129 || sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)>0
117130 || pParse->db->mallocFailed );
117131 assert( i==0
117132 || sqlite3VdbeRecordCompare(aSample[i-1].n, aSample[i-1].p, pRec)<0
117133 || pParse->db->mallocFailed );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117134 }
117135 #endif /* ifdef SQLITE_DEBUG */
117136
117137 /* At this point, aSample[i] is the first sample that is greater than
117138 ** or equal to pVal. Or if i==pIdx->nSample, then all samples are less
117139 ** than pVal. If aSample[i]==pVal, then res==0.
117140 */
117141 if( res==0 ){
 
 
117142 aStat[0] = aSample[i].anLt[iCol];
117143 aStat[1] = aSample[i].anEq[iCol];
117144 }else{
117145 tRowcnt iLower, iUpper, iGap;
117146 if( i==0 ){
117147 iLower = 0;
117148 iUpper = aSample[0].anLt[iCol];
 
 
117149 }else{
117150 i64 nRow0 = sqlite3LogEstToInt(pIdx->aiRowLogEst[0]);
117151 iUpper = i>=pIdx->nSample ? nRow0 : aSample[i].anLt[iCol];
117152 iLower = aSample[i-1].anEq[iCol] + aSample[i-1].anLt[iCol];
117153 }
117154 aStat[1] = pIdx->aAvgEq[iCol];
117155 if( iLower>=iUpper ){
117156 iGap = 0;
117157 }else{
117158 iGap = iUpper - iLower;
117159 }
@@ -117161,11 +117846,15 @@
117161 iGap = (iGap*2)/3;
117162 }else{
117163 iGap = iGap/3;
117164 }
117165 aStat[0] = iLower + iGap;
 
117166 }
 
 
 
117167 return i;
117168 }
117169 #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
117170
117171 /*
@@ -117635,24 +118324,47 @@
117635 ** by indices, we disable them to prevent redundant tests in the inner
117636 ** loop. We would get the correct results if nothing were ever disabled,
117637 ** but joins might run a little slower. The trick is to disable as much
117638 ** as we can without disabling too much. If we disabled in (1), we'd get
117639 ** the wrong answer. See ticket #813.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117640 */
117641 static void disableTerm(WhereLevel *pLevel, WhereTerm *pTerm){
117642 if( pTerm
 
117643 && (pTerm->wtFlags & TERM_CODED)==0
117644 && (pLevel->iLeftJoin==0 || ExprHasProperty(pTerm->pExpr, EP_FromJoin))
117645 && (pLevel->notReady & pTerm->prereqAll)==0
117646 ){
117647 pTerm->wtFlags |= TERM_CODED;
117648 if( pTerm->iParent>=0 ){
117649 WhereTerm *pOther = &pTerm->pWC->a[pTerm->iParent];
117650 if( (--pOther->nChild)==0 ){
117651 disableTerm(pLevel, pOther);
117652 }
117653 }
 
 
 
 
 
117654 }
117655 }
117656
117657 /*
117658 ** Code an OP_Affinity opcode to apply the column affinity string zAff
@@ -118132,11 +118844,38 @@
118132 }
118133 #else
118134 # define addScanStatus(a, b, c, d) ((void)d)
118135 #endif
118136
118137
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118138
118139 /*
118140 ** Generate code for the start of the iLevel-th loop in the WHERE clause
118141 ** implementation described by pWInfo.
118142 */
@@ -118462,14 +119201,29 @@
118462 */
118463 j = nEq;
118464 if( pLoop->wsFlags & WHERE_BTM_LIMIT ){
118465 pRangeStart = pLoop->aLTerm[j++];
118466 nExtraReg = 1;
 
 
 
118467 }
118468 if( pLoop->wsFlags & WHERE_TOP_LIMIT ){
118469 pRangeEnd = pLoop->aLTerm[j++];
118470 nExtraReg = 1;
 
 
 
 
 
 
 
 
 
 
 
 
118471 if( pRangeStart==0
118472 && (j = pIdx->aiColumn[nEq])>=0
118473 && pIdx->pTable->aCol[j].notNull==0
118474 ){
118475 bSeekPastNull = 1;
@@ -118508,10 +119262,11 @@
118508 /* Seek the index cursor to the start of the range. */
118509 nConstraint = nEq;
118510 if( pRangeStart ){
118511 Expr *pRight = pRangeStart->pExpr->pRight;
118512 sqlite3ExprCode(pParse, pRight, regBase+nEq);
 
118513 if( (pRangeStart->wtFlags & TERM_VNULL)==0
118514 && sqlite3ExprCanBeNull(pRight)
118515 ){
118516 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
118517 VdbeCoverage(v);
@@ -118553,10 +119308,11 @@
118553 nConstraint = nEq;
118554 if( pRangeEnd ){
118555 Expr *pRight = pRangeEnd->pExpr->pRight;
118556 sqlite3ExprCacheRemove(pParse, regBase+nEq, 1);
118557 sqlite3ExprCode(pParse, pRight, regBase+nEq);
 
118558 if( (pRangeEnd->wtFlags & TERM_VNULL)==0
118559 && sqlite3ExprCanBeNull(pRight)
118560 ){
118561 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
118562 VdbeCoverage(v);
@@ -118780,11 +119536,12 @@
118780 ** eliminating duplicates from other WHERE clauses, the action for each
118781 ** sub-WHERE clause is to to invoke the main loop body as a subroutine.
118782 */
118783 wctrlFlags = WHERE_OMIT_OPEN_CLOSE
118784 | WHERE_FORCE_TABLE
118785 | WHERE_ONETABLE_ONLY;
 
118786 for(ii=0; ii<pOrWc->nTerm; ii++){
118787 WhereTerm *pOrTerm = &pOrWc->a[ii];
118788 if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
118789 WhereInfo *pSubWInfo; /* Info for single OR-term scan */
118790 Expr *pOrExpr = pOrTerm->pExpr; /* Current OR clause term */
@@ -118942,10 +119699,11 @@
118942 /* Insert code to test every subexpression that can be completely
118943 ** computed using the current set of tables.
118944 */
118945 for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
118946 Expr *pE;
 
118947 testcase( pTerm->wtFlags & TERM_VIRTUAL );
118948 testcase( pTerm->wtFlags & TERM_CODED );
118949 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
118950 if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
118951 testcase( pWInfo->untestedTerms==0
@@ -118955,12 +119713,18 @@
118955 }
118956 pE = pTerm->pExpr;
118957 assert( pE!=0 );
118958 if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
118959 continue;
 
 
 
 
 
118960 }
118961 sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
 
118962 pTerm->wtFlags |= TERM_CODED;
118963 }
118964
118965 /* Insert code to test for implied constraints based on transitivity
118966 ** of the "==" operator.
@@ -119621,10 +120385,14 @@
119621 ){
119622 continue; /* ignore IS [NOT] NULL constraints on NOT NULL columns */
119623 }
119624 if( pTerm->prereqRight & pNew->maskSelf ) continue;
119625
 
 
 
 
119626 pNew->wsFlags = saved_wsFlags;
119627 pNew->u.btree.nEq = saved_nEq;
119628 pNew->nLTerm = saved_nLTerm;
119629 if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
119630 pNew->aLTerm[pNew->nLTerm++] = pTerm;
@@ -119664,10 +120432,21 @@
119664 testcase( eOp & WO_GT );
119665 testcase( eOp & WO_GE );
119666 pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_BTM_LIMIT;
119667 pBtm = pTerm;
119668 pTop = 0;
 
 
 
 
 
 
 
 
 
 
 
119669 }else{
119670 assert( eOp & (WO_LT|WO_LE) );
119671 testcase( eOp & WO_LT );
119672 testcase( eOp & WO_LE );
119673 pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_TOP_LIMIT;
@@ -119974,10 +120753,11 @@
119974 rLogSize = estLog(rSize);
119975
119976 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
119977 /* Automatic indexes */
119978 if( !pBuilder->pOrSet
 
119979 && (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
119980 && pSrc->pIndex==0
119981 && !pSrc->viaCoroutine
119982 && !pSrc->notIndexed
119983 && HasRowid(pTab)
@@ -120857,14 +121637,14 @@
120857 assert( aSortCost==0 || &pSpace[nSpace]==(char*)&aSortCost[nOrderBy] );
120858 assert( aSortCost!=0 || &pSpace[nSpace]==(char*)pX );
120859
120860 /* Seed the search with a single WherePath containing zero WhereLoops.
120861 **
120862 ** TUNING: Do not let the number of iterations go above 25. If the cost
120863 ** of computing an automatic index is not paid back within the first 25
120864 ** rows, then do not use the automatic index. */
120865 aFrom[0].nRow = MIN(pParse->nQueryLoop, 46); assert( 46==sqlite3LogEst(25) );
120866 nFrom = 1;
120867 assert( aFrom[0].isOrdered==0 );
120868 if( nOrderBy ){
120869 /* If nLoop is zero, then there are no FROM terms in the query. Since
120870 ** in this case the query may return a maximum of one row, the results
@@ -121658,10 +122438,16 @@
121658 assert( pIx->pSchema==pTab->pSchema );
121659 assert( iIndexCur>=0 );
121660 if( op ){
121661 sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
121662 sqlite3VdbeSetP4KeyInfo(pParse, pIx);
 
 
 
 
 
 
121663 VdbeComment((v, "%s", pIx->zName));
121664 }
121665 }
121666 if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb);
121667 notReady &= ~getMask(&pWInfo->sMaskSet, pTabItem->iCursor);
@@ -121758,10 +122544,20 @@
121758 if( pLevel->addrSkip ){
121759 sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip);
121760 VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
121761 sqlite3VdbeJumpHere(v, pLevel->addrSkip);
121762 sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
 
 
 
 
 
 
 
 
 
 
121763 }
121764 if( pLevel->iLeftJoin ){
121765 addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v);
121766 assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
121767 || (pLoop->wsFlags & WHERE_INDEXED)!=0 );
@@ -124649,11 +125445,11 @@
124649 spanSet(&yygotominor.yy346, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
124650 }
124651 break;
124652 case 193: /* expr ::= expr COLLATE ID|STRING */
124653 {
124654 yygotominor.yy346.pExpr = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy346.pExpr, &yymsp[0].minor.yy0);
124655 yygotominor.yy346.zStart = yymsp[-2].minor.yy346.zStart;
124656 yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
124657 }
124658 break;
124659 case 194: /* expr ::= CAST LP expr AS typetoken RP */
@@ -124929,20 +125725,20 @@
124929 case 241: /* uniqueflag ::= */
124930 {yygotominor.yy328 = OE_None;}
124931 break;
124932 case 244: /* idxlist ::= idxlist COMMA nm collate sortorder */
124933 {
124934 Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0);
124935 yygotominor.yy14 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy14, p);
124936 sqlite3ExprListSetName(pParse,yygotominor.yy14,&yymsp[-2].minor.yy0,1);
124937 sqlite3ExprListCheckLength(pParse, yygotominor.yy14, "index");
124938 if( yygotominor.yy14 ) yygotominor.yy14->a[yygotominor.yy14->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy328;
124939 }
124940 break;
124941 case 245: /* idxlist ::= nm collate sortorder */
124942 {
124943 Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0);
124944 yygotominor.yy14 = sqlite3ExprListAppend(pParse,0, p);
124945 sqlite3ExprListSetName(pParse, yygotominor.yy14, &yymsp[-2].minor.yy0, 1);
124946 sqlite3ExprListCheckLength(pParse, yygotominor.yy14, "index");
124947 if( yygotominor.yy14 ) yygotominor.yy14->a[yygotominor.yy14->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy328;
124948 }
@@ -126197,13 +126993,15 @@
126197 pParse->zTail = &zSql[i];
126198 }
126199 sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
126200 }
126201 #ifdef YYTRACKMAXSTACKDEPTH
 
126202 sqlite3StatusSet(SQLITE_STATUS_PARSER_STACK,
126203 sqlite3ParserStackPeak(pEngine)
126204 );
 
126205 #endif /* YYDEBUG */
126206 sqlite3ParserFree(pEngine, sqlite3_free);
126207 db->lookaside.bEnabled = enableLookaside;
126208 if( db->mallocFailed ){
126209 pParse->rc = SQLITE_NOMEM;
@@ -126769,10 +127567,15 @@
126769 rc = sqlite3_wsd_init(4096, 24);
126770 if( rc!=SQLITE_OK ){
126771 return rc;
126772 }
126773 #endif
 
 
 
 
 
126774
126775 /* If SQLite is already completely initialized, then this call
126776 ** to sqlite3_initialize() should be a no-op. But the initialization
126777 ** must be complete. So isInit must not be set until the very end
126778 ** of this routine.
@@ -126982,30 +127785,32 @@
126982 /* Mutex configuration options are only available in a threadsafe
126983 ** compile.
126984 */
126985 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-54466-46756 */
126986 case SQLITE_CONFIG_SINGLETHREAD: {
126987 /* Disable all mutexing */
126988 sqlite3GlobalConfig.bCoreMutex = 0;
126989 sqlite3GlobalConfig.bFullMutex = 0;
 
126990 break;
126991 }
126992 #endif
126993 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-20520-54086 */
126994 case SQLITE_CONFIG_MULTITHREAD: {
126995 /* Disable mutexing of database connections */
126996 /* Enable mutexing of core data structures */
126997 sqlite3GlobalConfig.bCoreMutex = 1;
126998 sqlite3GlobalConfig.bFullMutex = 0;
126999 break;
127000 }
127001 #endif
127002 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-59593-21810 */
127003 case SQLITE_CONFIG_SERIALIZED: {
127004 /* Enable all mutexing */
127005 sqlite3GlobalConfig.bCoreMutex = 1;
127006 sqlite3GlobalConfig.bFullMutex = 1;
 
127007 break;
127008 }
127009 #endif
127010 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-63666-48755 */
127011 case SQLITE_CONFIG_MUTEX: {
@@ -127113,11 +127918,12 @@
127113 ** SQLITE_ENABLE_MEMSYS5 and returns SQLITE_ERROR if invoked otherwise. */
127114 #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
127115 case SQLITE_CONFIG_HEAP: {
127116 /* EVIDENCE-OF: R-19854-42126 There are three arguments to
127117 ** SQLITE_CONFIG_HEAP: An 8-byte aligned pointer to the memory, the
127118 ** number of bytes in the memory buffer, and the minimum allocation size. */
 
127119 sqlite3GlobalConfig.pHeap = va_arg(ap, void*);
127120 sqlite3GlobalConfig.nHeap = va_arg(ap, int);
127121 sqlite3GlobalConfig.mnReq = va_arg(ap, int);
127122
127123 if( sqlite3GlobalConfig.mnReq<1 ){
@@ -127218,11 +128024,13 @@
127218 ** EVIDENCE-OF: R-34993-45031 The maximum allowed mmap size will be
127219 ** silently truncated if necessary so that it does not exceed the
127220 ** compile-time maximum mmap size set by the SQLITE_MAX_MMAP_SIZE
127221 ** compile-time option.
127222 */
127223 if( mxMmap<0 || mxMmap>SQLITE_MAX_MMAP_SIZE ) mxMmap = SQLITE_MAX_MMAP_SIZE;
 
 
127224 if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE;
127225 if( szMmap>mxMmap) szMmap = mxMmap;
127226 sqlite3GlobalConfig.mxMmap = mxMmap;
127227 sqlite3GlobalConfig.szMmap = szMmap;
127228 break;
@@ -129062,11 +129870,23 @@
129062 for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
129063 zFile = sqlite3_malloc(nByte);
129064 if( !zFile ) return SQLITE_NOMEM;
129065
129066 iIn = 5;
129067 #ifndef SQLITE_ALLOW_URI_AUTHORITY
 
 
 
 
 
 
 
 
 
 
 
 
129068 /* Discard the scheme and authority segments of the URI. */
129069 if( zUri[5]=='/' && zUri[6]=='/' ){
129070 iIn = 7;
129071 while( zUri[iIn] && zUri[iIn]!='/' ) iIn++;
129072 if( iIn!=7 && (iIn!=16 || memcmp("localhost", &zUri[7], 9)) ){
@@ -129505,11 +130325,12 @@
129505 sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT);
129506
129507 opendb_out:
129508 sqlite3_free(zOpen);
129509 if( db ){
129510 assert( db->mutex!=0 || isThreadsafe==0 || sqlite3GlobalConfig.bFullMutex==0 );
 
129511 sqlite3_mutex_leave(db->mutex);
129512 }
129513 rc = sqlite3_errcode(db);
129514 assert( db!=0 || rc==SQLITE_NOMEM );
129515 if( rc==SQLITE_NOMEM ){
@@ -130250,21 +131071,21 @@
130250 case SQLITE_TESTCTRL_ISINIT: {
130251 if( sqlite3GlobalConfig.isInit==0 ) rc = SQLITE_ERROR;
130252 break;
130253 }
130254
130255 /* sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, dbName, onOff, tnum);
130256 **
130257 ** This test control is used to create imposter tables. "db" is a pointer
130258 ** to the database connection. dbName is the database name (ex: "main" or
130259 ** "temp") which will receive the imposter. "onOff" turns imposter mode on
130260 ** or off. "tnum" is the root page of the b-tree to which the imposter
130261 ** table should connect.
130262 **
130263 ** Enable imposter mode only when the schema has already been parsed. Then
130264 ** run a single CREATE TABLE statement to construct the imposter table in the
130265 ** parsed schema. Then turn imposter mode back off again.
130266 **
130267 ** If onOff==0 and tnum>0 then reset the schema for all databases, causing
130268 ** the schema to be reparsed the next time it is needed. This has the
130269 ** effect of erasing all imposter tables.
130270 */
@@ -132506,15 +133327,20 @@
132506 ** the output value undefined. Otherwise SQLITE_OK is returned.
132507 **
132508 ** This function is used when parsing the "prefix=" FTS4 parameter.
132509 */
132510 static int fts3GobbleInt(const char **pp, int *pnOut){
 
132511 const char *p; /* Iterator pointer */
132512 int nInt = 0; /* Output value */
132513
132514 for(p=*pp; p[0]>='0' && p[0]<='9'; p++){
132515 nInt = nInt * 10 + (p[0] - '0');
 
 
 
 
132516 }
132517 if( p==*pp ) return SQLITE_ERROR;
132518 *pnOut = nInt;
132519 *pp = p;
132520 return SQLITE_OK;
@@ -132553,27 +133379,33 @@
132553 }
132554 }
132555
132556 aIndex = sqlite3_malloc(sizeof(struct Fts3Index) * nIndex);
132557 *apIndex = aIndex;
132558 *pnIndex = nIndex;
132559 if( !aIndex ){
132560 return SQLITE_NOMEM;
132561 }
132562
132563 memset(aIndex, 0, sizeof(struct Fts3Index) * nIndex);
132564 if( zParam ){
132565 const char *p = zParam;
132566 int i;
132567 for(i=1; i<nIndex; i++){
132568 int nPrefix;
132569 if( fts3GobbleInt(&p, &nPrefix) ) return SQLITE_ERROR;
132570 aIndex[i].nPrefix = nPrefix;
 
 
 
 
 
 
132571 p++;
132572 }
132573 }
132574
 
132575 return SQLITE_OK;
132576 }
132577
132578 /*
132579 ** This function is called when initializing an FTS4 table that uses the
@@ -140349,11 +141181,11 @@
140349 nName = sqlite3_value_bytes(argv[0])+1;
140350
140351 if( argc==2 ){
140352 void *pOld;
140353 int n = sqlite3_value_bytes(argv[1]);
140354 if( n!=sizeof(pPtr) ){
140355 sqlite3_result_error(context, "argument type mismatch", -1);
140356 return;
140357 }
140358 pPtr = *(void **)sqlite3_value_blob(argv[1]);
140359 pOld = sqlite3Fts3HashInsert(pHash, (void *)zName, nName, pPtr);
@@ -140360,11 +141192,13 @@
140360 if( pOld==pPtr ){
140361 sqlite3_result_error(context, "out of memory", -1);
140362 return;
140363 }
140364 }else{
140365 pPtr = sqlite3Fts3HashFind(pHash, zName, nName);
 
 
140366 if( !pPtr ){
140367 char *zErr = sqlite3_mprintf("unknown tokenizer: %s", zName);
140368 sqlite3_result_error(context, zErr, -1);
140369 sqlite3_free(zErr);
140370 return;
@@ -140441,10 +141275,14 @@
140441 zCopy = sqlite3_mprintf("%s", zArg);
140442 if( !zCopy ) return SQLITE_NOMEM;
140443 zEnd = &zCopy[strlen(zCopy)];
140444
140445 z = (char *)sqlite3Fts3NextToken(zCopy, &n);
 
 
 
 
140446 z[n] = '\0';
140447 sqlite3Fts3Dequote(z);
140448
140449 m = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash,z,(int)strlen(z)+1);
140450 if( !m ){
@@ -143086,11 +143924,14 @@
143086 /*
143087 ** This is a comparison function used as a qsort() callback when sorting
143088 ** an array of pending terms by term. This occurs as part of flushing
143089 ** the contents of the pending-terms hash table to the database.
143090 */
143091 static int fts3CompareElemByTerm(const void *lhs, const void *rhs){
 
 
 
143092 char *z1 = fts3HashKey(*(Fts3HashElem **)lhs);
143093 char *z2 = fts3HashKey(*(Fts3HashElem **)rhs);
143094 int n1 = fts3HashKeysize(*(Fts3HashElem **)lhs);
143095 int n2 = fts3HashKeysize(*(Fts3HashElem **)rhs);
143096
143097
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.8.9. 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.
@@ -88,10 +88,48 @@
88 #endif /* _MSVC_H_ */
89
90 /************** End of msvc.h ************************************************/
91 /************** Continuing where we left off in sqliteInt.h ******************/
92
93 /*
94 ** Special setup for VxWorks
95 */
96 /************** Include vxworks.h in the middle of sqliteInt.h ***************/
97 /************** Begin file vxworks.h *****************************************/
98 /*
99 ** 2015-03-02
100 **
101 ** The author disclaims copyright to this source code. In place of
102 ** a legal notice, here is a blessing:
103 **
104 ** May you do good and not evil.
105 ** May you find forgiveness for yourself and forgive others.
106 ** May you share freely, never taking more than you give.
107 **
108 ******************************************************************************
109 **
110 ** This file contains code that is specific to Wind River's VxWorks
111 */
112 #if defined(__RTP__) || defined(_WRS_KERNEL)
113 /* This is VxWorks. Set up things specially for that OS
114 */
115 #include <vxWorks.h>
116 #include <pthread.h> /* amalgamator: dontcache */
117 #define OS_VXWORKS 1
118 #define SQLITE_OS_OTHER 0
119 #define SQLITE_HOMEGROWN_RECURSIVE_MUTEX 1
120 #define SQLITE_OMIT_LOAD_EXTENSION 1
121 #define SQLITE_ENABLE_LOCKING_STYLE 0
122 #define HAVE_UTIME 1
123 #else
124 /* This is not VxWorks. */
125 #define OS_VXWORKS 0
126 #endif /* defined(_WRS_KERNEL) */
127
128 /************** End of vxworks.h *********************************************/
129 /************** Continuing where we left off in sqliteInt.h ******************/
130
131 /*
132 ** These #defines should enable >2GB file support on POSIX if the
133 ** underlying operating system supports it. If the OS lacks
134 ** large file support, or if the OS is windows, these should be no-ops.
135 **
@@ -223,10 +261,17 @@
261 #ifndef SQLITE_API
262 # define SQLITE_API
263 #endif
264
265
266 /*
267 ** Add the ability to override 'cdecl'
268 */
269 #ifndef SQLITE_CDECL
270 # define SQLITE_CDECL
271 #endif
272
273 /*
274 ** These no-op macros are used in front of interfaces to mark those
275 ** interfaces as either deprecated or experimental. New applications
276 ** should not use deprecated interfaces - they are supported for backwards
277 ** compatibility only. Application writers should be aware that
@@ -276,13 +321,13 @@
321 **
322 ** See also: [sqlite3_libversion()],
323 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
324 ** [sqlite_version()] and [sqlite_source_id()].
325 */
326 #define SQLITE_VERSION "3.8.9"
327 #define SQLITE_VERSION_NUMBER 3008009
328 #define SQLITE_SOURCE_ID "2015-03-24 18:19:39 436314b5728c9413f9ac2d837e1c19364f31be72"
329
330 /*
331 ** CAPI3REF: Run-Time Library Version Numbers
332 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
333 **
@@ -925,18 +970,20 @@
970 **
971 ** These integer constants are opcodes for the xFileControl method
972 ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
973 ** interface.
974 **
975 ** <ul>
976 ** <li>[[SQLITE_FCNTL_LOCKSTATE]]
977 ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This
978 ** opcode causes the xFileControl method to write the current state of
979 ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
980 ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
981 ** into an integer that the pArg argument points to. This capability
982 ** is used during testing and is only available when the SQLITE_TEST
983 ** compile-time option is used.
984 **
985 ** <li>[[SQLITE_FCNTL_SIZE_HINT]]
986 ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
987 ** layer a hint of how large the database file will grow to be during the
988 ** current transaction. This hint is not guaranteed to be accurate but it
989 ** is often close. The underlying VFS might choose to preallocate database
@@ -1057,11 +1104,13 @@
1104 ** the error message if the pragma fails. ^If the
1105 ** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal
1106 ** [PRAGMA] processing continues. ^If the [SQLITE_FCNTL_PRAGMA]
1107 ** file control returns [SQLITE_OK], then the parser assumes that the
1108 ** VFS has handled the PRAGMA itself and the parser generates a no-op
1109 ** prepared statement if result string is NULL, or that returns a copy
1110 ** of the result string if the string is non-NULL.
1111 ** ^If the [SQLITE_FCNTL_PRAGMA] file control returns
1112 ** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means
1113 ** that the VFS encountered an error while handling the [PRAGMA] and the
1114 ** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA]
1115 ** file control occurs at the beginning of pragma statement analysis and so
1116 ** it is able to override built-in [PRAGMA] statements.
@@ -1115,10 +1164,17 @@
1164 ** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This
1165 ** opcode causes the xFileControl method to swap the file handle with the one
1166 ** pointed to by the pArg argument. This capability is used during testing
1167 ** and only needs to be supported when SQLITE_TEST is defined.
1168 **
1169 ** <li>[[SQLITE_FCNTL_WAL_BLOCK]]
1170 ** The [SQLITE_FCNTL_WAL_BLOCK] is a signal to the VFS layer that it might
1171 ** be advantageous to block on the next WAL lock if the lock is not immediately
1172 ** available. The WAL subsystem issues this signal during rare
1173 ** circumstances in order to fix a problem with priority inversion.
1174 ** Applications should <em>not</em> use this file-control.
1175 **
1176 ** </ul>
1177 */
1178 #define SQLITE_FCNTL_LOCKSTATE 1
1179 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
1180 #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
@@ -1139,10 +1195,11 @@
1195 #define SQLITE_FCNTL_TRACE 19
1196 #define SQLITE_FCNTL_HAS_MOVED 20
1197 #define SQLITE_FCNTL_SYNC 21
1198 #define SQLITE_FCNTL_COMMIT_PHASETWO 22
1199 #define SQLITE_FCNTL_WIN32_SET_HANDLE 23
1200 #define SQLITE_FCNTL_WAL_BLOCK 24
1201
1202 /* deprecated names */
1203 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
1204 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
1205 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -1705,11 +1762,11 @@
1762 ** disabled, the following SQLite interfaces become non-operational:
1763 ** <ul>
1764 ** <li> [sqlite3_memory_used()]
1765 ** <li> [sqlite3_memory_highwater()]
1766 ** <li> [sqlite3_soft_heap_limit64()]
1767 ** <li> [sqlite3_status64()]
1768 ** </ul>)^
1769 ** ^Memory allocation statistics are enabled by default unless SQLite is
1770 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1771 ** allocation statistics are disabled by default.
1772 ** </dd>
@@ -1916,11 +1973,10 @@
1973 ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
1974 ** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is
1975 ** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro
1976 ** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
1977 ** that specifies the maximum size of the created heap.
 
1978 **
1979 ** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
1980 ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
1981 ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
1982 ** is a pointer to an integer and writes into that integer the number of extra
@@ -3163,15 +3219,17 @@
3219
3220
3221 /*
3222 ** CAPI3REF: Error Codes And Messages
3223 **
3224 ** ^If the most recent sqlite3_* API call associated with
3225 ** [database connection] D failed, then the sqlite3_errcode(D) interface
3226 ** returns the numeric [result code] or [extended result code] for that
3227 ** API call.
3228 ** If the most recent API call was successful,
3229 ** then the return value from sqlite3_errcode() is undefined.
3230 ** ^The sqlite3_extended_errcode()
3231 ** interface is the same except that it always returns the
3232 ** [extended result code] even when extended result codes are
3233 ** disabled.
3234 **
3235 ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
@@ -3356,20 +3414,18 @@
3414 ** The second argument, "zSql", is the statement to be compiled, encoded
3415 ** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2()
3416 ** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2()
3417 ** use UTF-16.
3418 **
3419 ** ^If the nByte argument is negative, then zSql is read up to the
3420 ** first zero terminator. ^If nByte is positive, then it is the
3421 ** number of bytes read from zSql. ^If nByte is zero, then no prepared
3422 ** statement is generated.
3423 ** If the caller knows that the supplied string is nul-terminated, then
3424 ** there is a small performance advantage to passing an nByte parameter that
3425 ** is the number of bytes in the input string <i>including</i>
3426 ** the nul-terminator.
 
 
3427 **
3428 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
3429 ** past the end of the first SQL statement in zSql. These routines only
3430 ** compile the first statement in zSql, so *pzTail is left pointing to
3431 ** what remains uncompiled.
@@ -4394,12 +4450,12 @@
4450 ** DEPRECATED
4451 **
4452 ** These functions are [deprecated]. In order to maintain
4453 ** backwards compatibility with older code, these functions continue
4454 ** to be supported. However, new applications should avoid
4455 ** the use of these functions. To encourage programmers to avoid
4456 ** these functions, we will not explain what they do.
4457 */
4458 #ifndef SQLITE_OMIT_DEPRECATED
4459 SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
4460 SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
4461 SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
@@ -5783,11 +5839,11 @@
5839 ** is delivered up to the client application, the string will be automatically
5840 ** freed by sqlite3_free() and the zErrMsg field will be zeroed.
5841 */
5842 struct sqlite3_vtab {
5843 const sqlite3_module *pModule; /* The module for this virtual table */
5844 int nRef; /* Number of open cursors */
5845 char *zErrMsg; /* Error message from sqlite3_mprintf() */
5846 /* Virtual table implementations will typically add additional fields */
5847 };
5848
5849 /*
@@ -6461,11 +6517,11 @@
6517 #define SQLITE_TESTCTRL_LAST 25
6518
6519 /*
6520 ** CAPI3REF: SQLite Runtime Status
6521 **
6522 ** ^These interfaces are used to retrieve runtime status information
6523 ** about the performance of SQLite, and optionally to reset various
6524 ** highwater marks. ^The first argument is an integer code for
6525 ** the specific parameter to measure. ^(Recognized integer codes
6526 ** are of the form [status parameters | SQLITE_STATUS_...].)^
6527 ** ^The current value of the parameter is returned into *pCurrent.
@@ -6475,23 +6531,26 @@
6531 ** value. For those parameters
6532 ** nothing is written into *pHighwater and the resetFlag is ignored.)^
6533 ** ^(Other parameters record only the highwater mark and not the current
6534 ** value. For these latter parameters nothing is written into *pCurrent.)^
6535 **
6536 ** ^The sqlite3_status() and sqlite3_status64() routines return
6537 ** SQLITE_OK on success and a non-zero [error code] on failure.
6538 **
6539 ** If either the current value or the highwater mark is too large to
6540 ** be represented by a 32-bit integer, then the values returned by
6541 ** sqlite3_status() are undefined.
 
 
 
6542 **
6543 ** See also: [sqlite3_db_status()]
6544 */
6545 SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
6546 SQLITE_API int sqlite3_status64(
6547 int op,
6548 sqlite3_int64 *pCurrent,
6549 sqlite3_int64 *pHighwater,
6550 int resetFlag
6551 );
6552
6553
6554 /*
6555 ** CAPI3REF: Status Parameters
6556 ** KEYWORDS: {status parameters}
@@ -7157,24 +7216,24 @@
7216 **
7217 ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
7218 ** is not a permanent error and does not affect the return value of
7219 ** sqlite3_backup_finish().
7220 **
7221 ** [[sqlite3_backup_remaining()]] [[sqlite3_backup_pagecount()]]
7222 ** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b>
7223 **
7224 ** ^The sqlite3_backup_remaining() routine returns the number of pages still
7225 ** to be backed up at the conclusion of the most recent sqlite3_backup_step().
7226 ** ^The sqlite3_backup_pagecount() routine returns the total number of pages
7227 ** in the source database at the conclusion of the most recent
7228 ** sqlite3_backup_step().
7229 ** ^(The values returned by these functions are only updated by
7230 ** sqlite3_backup_step(). If the source database is modified in a way that
7231 ** changes the size of the source database or the number of pages remaining,
7232 ** those changes are not reflected in the output of sqlite3_backup_pagecount()
7233 ** and sqlite3_backup_remaining() until after the next
7234 ** sqlite3_backup_step().)^
7235 **
7236 ** <b>Concurrent Usage of Database Handles</b>
7237 **
7238 ** ^The source [database connection] may be used by the application for other
7239 ** purposes while a backup operation is underway or being initialized.
@@ -8018,19 +8077,21 @@
8077 #ifndef SQLITE_MAX_FUNCTION_ARG
8078 # define SQLITE_MAX_FUNCTION_ARG 127
8079 #endif
8080
8081 /*
8082 ** The suggested maximum number of in-memory pages to use for
8083 ** the main database table and for temporary tables.
8084 **
8085 ** IMPLEMENTATION-OF: R-31093-59126 The default suggested cache size
8086 ** is 2000 pages.
8087 ** IMPLEMENTATION-OF: R-48205-43578 The default suggested cache size can be
8088 ** altered using the SQLITE_DEFAULT_CACHE_SIZE compile-time options.
8089 */
8090 #ifndef SQLITE_DEFAULT_CACHE_SIZE
8091 # define SQLITE_DEFAULT_CACHE_SIZE 2000
8092 #endif
 
 
 
8093
8094 /*
8095 ** The default number of frames to accumulate in the log file before
8096 ** checkpointing the database in WAL mode.
8097 */
@@ -8870,10 +8931,24 @@
8931 **
8932 ** 0.5 -> -10 0.1 -> -33 0.0625 -> -40
8933 */
8934 typedef INT16_TYPE LogEst;
8935
8936 /*
8937 ** Set the SQLITE_PTRSIZE macro to the number of bytes in a pointer
8938 */
8939 #ifndef SQLITE_PTRSIZE
8940 # if defined(__SIZEOF_POINTER__)
8941 # define SQLITE_PTRSIZE __SIZEOF_POINTER__
8942 # elif defined(i386) || defined(__i386__) || defined(_M_IX86) || \
8943 defined(_M_ARM) || defined(__arm__) || defined(__x86)
8944 # define SQLITE_PTRSIZE 4
8945 # else
8946 # define SQLITE_PTRSIZE 8
8947 # endif
8948 #endif
8949
8950 /*
8951 ** Macros to determine whether the machine is big or little endian,
8952 ** and whether or not that determination is run-time or compile-time.
8953 **
8954 ** For best performance, an attempt is made to guess at the byte-order
@@ -9320,12 +9395,22 @@
9395 #define BTREE_DATA_VERSION 15 /* A virtual meta-value */
9396
9397 /*
9398 ** Values that may be OR'd together to form the second argument of an
9399 ** sqlite3BtreeCursorHints() call.
9400 **
9401 ** The BTREE_BULKLOAD flag is set on index cursors when the index is going
9402 ** to be filled with content that is already in sorted order.
9403 **
9404 ** The BTREE_SEEK_EQ flag is set on cursors that will get OP_SeekGE or
9405 ** OP_SeekLE opcodes for a range search, but where the range of entries
9406 ** selected will all have the same key. In other words, the cursor will
9407 ** be used only for equality key searches.
9408 **
9409 */
9410 #define BTREE_BULKLOAD 0x00000001 /* Used to full index in sorted order */
9411 #define BTREE_SEEK_EQ 0x00000002 /* EQ seeks only - no range seeks */
9412
9413 SQLITE_PRIVATE int sqlite3BtreeCursor(
9414 Btree*, /* BTree containing table to open */
9415 int iTable, /* Index of root page */
9416 int wrFlag, /* 1 for writing. 0 for read-only */
@@ -9367,10 +9452,13 @@
9452 SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
9453 SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *);
9454 SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *);
9455 SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion);
9456 SQLITE_PRIVATE void sqlite3BtreeCursorHints(BtCursor *, unsigned int mask);
9457 #ifdef SQLITE_DEBUG
9458 SQLITE_PRIVATE int sqlite3BtreeCursorHasHint(BtCursor*, unsigned int mask);
9459 #endif
9460 SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *pBt);
9461 SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void);
9462
9463 #ifndef NDEBUG
9464 SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*);
@@ -9733,27 +9821,29 @@
9821 #define OP_FkCounter 134 /* synopsis: fkctr[P1]+=P2 */
9822 #define OP_FkIfZero 135 /* synopsis: if fkctr[P1]==0 goto P2 */
9823 #define OP_MemMax 136 /* synopsis: r[P1]=max(r[P1],r[P2]) */
9824 #define OP_IfPos 137 /* synopsis: if r[P1]>0 goto P2 */
9825 #define OP_IfNeg 138 /* synopsis: r[P1]+=P3, if r[P1]<0 goto P2 */
9826 #define OP_IfNotZero 139 /* synopsis: if r[P1]!=0 then r[P1]+=P3, goto P2 */
9827 #define OP_DecrJumpZero 140 /* synopsis: if (--r[P1])==0 goto P2 */
9828 #define OP_JumpZeroIncr 141 /* synopsis: if (r[P1]++)==0 ) goto P2 */
9829 #define OP_AggFinal 142 /* synopsis: accum=r[P1] N=P2 */
9830 #define OP_IncrVacuum 143
9831 #define OP_Expire 144
9832 #define OP_TableLock 145 /* synopsis: iDb=P1 root=P2 write=P3 */
9833 #define OP_VBegin 146
9834 #define OP_VCreate 147
9835 #define OP_VDestroy 148
9836 #define OP_VOpen 149
9837 #define OP_VColumn 150 /* synopsis: r[P3]=vcolumn(P2) */
9838 #define OP_VNext 151
9839 #define OP_VRename 152
9840 #define OP_Pagecount 153
9841 #define OP_MaxPgcnt 154
9842 #define OP_Init 155 /* synopsis: Start at P2 */
9843 #define OP_Noop 156
9844 #define OP_Explain 157
9845
9846
9847 /* Properties such as "out2" or "jump" that are specified in
9848 ** comments following the "case" for each opcode in the vdbe.c
9849 ** are encoded into bitvectors as follows:
@@ -9781,13 +9871,13 @@
9871 /* 96 */ 0x24, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,\
9872 /* 104 */ 0x00, 0x01, 0x01, 0x01, 0x01, 0x08, 0x08, 0x00,\
9873 /* 112 */ 0x02, 0x01, 0x01, 0x01, 0x01, 0x02, 0x00, 0x00,\
9874 /* 120 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9875 /* 128 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x02, 0x00, 0x01,\
9876 /* 136 */ 0x08, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00, 0x01,\
9877 /* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,\
9878 /* 152 */ 0x00, 0x02, 0x02, 0x01, 0x00, 0x00,}
9879
9880 /************** End of opcodes.h *********************************************/
9881 /************** Continuing where we left off in vdbe.h ***********************/
9882
9883 /*
@@ -10865,10 +10955,11 @@
10955 } init;
10956 int nVdbeActive; /* Number of VDBEs currently running */
10957 int nVdbeRead; /* Number of active VDBEs that read or write */
10958 int nVdbeWrite; /* Number of active VDBEs that read and write */
10959 int nVdbeExec; /* Number of nested calls to VdbeExec() */
10960 int nVDestroy; /* Number of active OP_VDestroy operations */
10961 int nExtension; /* Number of loaded extensions */
10962 void **aExtension; /* Array of shared library handles */
10963 void (*xTrace)(void*,const char*); /* Trace function */
10964 void *pTraceArg; /* Argument to the trace function */
10965 void (*xProfile)(void*,const char*,u64); /* Profiling function */
@@ -12022,11 +12113,11 @@
12113 #define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
12114 #define WHERE_DUPLICATES_OK 0x0008 /* Ok to return a row more than once */
12115 #define WHERE_OMIT_OPEN_CLOSE 0x0010 /* Table cursors are already open */
12116 #define WHERE_FORCE_TABLE 0x0020 /* Do not use an index-only search */
12117 #define WHERE_ONETABLE_ONLY 0x0040 /* Only code the 1st table in pTabList */
12118 #define WHERE_NO_AUTOINDEX 0x0080 /* Disallow automatic indexes */
12119 #define WHERE_GROUPBY 0x0100 /* pOrderBy is really a GROUP BY */
12120 #define WHERE_DISTINCTBY 0x0200 /* pOrderby is really a DISTINCT clause */
12121 #define WHERE_WANT_DISTINCT 0x0400 /* All output needs to be distinct */
12122 #define WHERE_SORTBYGROUP 0x0800 /* Support sqlite3WhereIsSorted() */
12123 #define WHERE_REOPEN_IDX 0x1000 /* Try to use OP_ReopenIdx */
@@ -12459,11 +12550,12 @@
12550 #define OPFLAG_APPEND 0x08 /* This is likely to be an append */
12551 #define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */
12552 #define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */
12553 #define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */
12554 #define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */
12555 #define OPFLAG_SEEKEQ 0x02 /* OP_Open** cursor uses EQ seek only */
12556 #define OPFLAG_P2ISREG 0x04 /* P2 to OP_Open** is a register number */
12557 #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */
12558
12559 /*
12560 * Each trigger present in the database schema is stored as an instance of
12561 * struct Trigger.
@@ -12863,14 +12955,19 @@
12955 SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int);
12956 SQLITE_PRIVATE int sqlite3MutexInit(void);
12957 SQLITE_PRIVATE int sqlite3MutexEnd(void);
12958 #endif
12959
12960 SQLITE_PRIVATE sqlite3_int64 sqlite3StatusValue(int);
12961 SQLITE_PRIVATE void sqlite3StatusUp(int, int);
12962 SQLITE_PRIVATE void sqlite3StatusDown(int, int);
12963 SQLITE_PRIVATE void sqlite3StatusSet(int, int);
12964
12965 /* Access to mutexes used by sqlite3_status() */
12966 SQLITE_PRIVATE sqlite3_mutex *sqlite3Pcache1Mutex(void);
12967 SQLITE_PRIVATE sqlite3_mutex *sqlite3MallocMutex(void);
12968
12969 #ifndef SQLITE_OMIT_FLOATING_POINT
12970 SQLITE_PRIVATE int sqlite3IsNaN(double);
12971 #else
12972 # define sqlite3IsNaN(X) 0
12973 #endif
@@ -13246,11 +13343,11 @@
13343 SQLITE_PRIVATE const char *sqlite3ErrStr(int);
13344 SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse);
13345 SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int);
13346 SQLITE_PRIVATE CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName);
13347 SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr);
13348 SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr*, const Token*, int);
13349 SQLITE_PRIVATE Expr *sqlite3ExprAddCollateString(Parse*,Expr*,const char*);
13350 SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr*);
13351 SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *);
13352 SQLITE_PRIVATE int sqlite3CheckObjectName(Parse *, const char *);
13353 SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int);
@@ -14633,18 +14730,10 @@
14730 ** An instance of the virtual machine. This structure contains the complete
14731 ** state of the virtual machine.
14732 **
14733 ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()
14734 ** is really a pointer to an instance of this structure.
 
 
 
 
 
 
 
 
14735 */
14736 struct Vdbe {
14737 sqlite3 *db; /* The database connection that owns this statement */
14738 Op *aOp; /* Space to hold the virtual machine's program */
14739 Mem *aMem; /* The memory locations */
@@ -14671,11 +14760,10 @@
14760 #endif
14761 u16 nResColumn; /* Number of columns in one row of the result set */
14762 u8 errorAction; /* Recovery action to do in case of an error */
14763 u8 minWriteFileFormat; /* Minimum file format for writable database files */
14764 bft explain:2; /* True if EXPLAIN present on SQL command */
 
14765 bft changeCntOn:1; /* True to update the change-counter */
14766 bft expired:1; /* True if the VM needs to be recompiled */
14767 bft runOnlyOnce:1; /* Automatically expire on reset */
14768 bft usesStmtJournal:1; /* True if uses a statement journal */
14769 bft readOnly:1; /* True for statements that do not write */
@@ -14831,13 +14919,35 @@
14919 /*
14920 ** Variables in which to record status information.
14921 */
14922 typedef struct sqlite3StatType sqlite3StatType;
14923 static SQLITE_WSD struct sqlite3StatType {
14924 #if SQLITE_PTRSIZE>4
14925 sqlite3_int64 nowValue[10]; /* Current value */
14926 sqlite3_int64 mxValue[10]; /* Maximum value */
14927 #else
14928 u32 nowValue[10]; /* Current value */
14929 u32 mxValue[10]; /* Maximum value */
14930 #endif
14931 } sqlite3Stat = { {0,}, {0,} };
14932
14933 /*
14934 ** Elements of sqlite3Stat[] are protected by either the memory allocator
14935 ** mutex, or by the pcache1 mutex. The following array determines which.
14936 */
14937 static const char statMutex[] = {
14938 0, /* SQLITE_STATUS_MEMORY_USED */
14939 1, /* SQLITE_STATUS_PAGECACHE_USED */
14940 1, /* SQLITE_STATUS_PAGECACHE_OVERFLOW */
14941 0, /* SQLITE_STATUS_SCRATCH_USED */
14942 0, /* SQLITE_STATUS_SCRATCH_OVERFLOW */
14943 0, /* SQLITE_STATUS_MALLOC_SIZE */
14944 0, /* SQLITE_STATUS_PARSER_STACK */
14945 1, /* SQLITE_STATUS_PAGECACHE_SIZE */
14946 0, /* SQLITE_STATUS_SCRATCH_SIZE */
14947 0, /* SQLITE_STATUS_MALLOC_COUNT */
14948 };
14949
14950
14951 /* The "wsdStat" macro will resolve to the status information
14952 ** state vector. If writable static data is unsupported on the target,
14953 ** we have to locate the state vector at run-time. In the more common
@@ -14851,64 +14961,110 @@
14961 # define wsdStatInit
14962 # define wsdStat sqlite3Stat
14963 #endif
14964
14965 /*
14966 ** Return the current value of a status parameter. The caller must
14967 ** be holding the appropriate mutex.
14968 */
14969 SQLITE_PRIVATE sqlite3_int64 sqlite3StatusValue(int op){
14970 wsdStatInit;
14971 assert( op>=0 && op<ArraySize(wsdStat.nowValue) );
14972 assert( op>=0 && op<ArraySize(statMutex) );
14973 assert( sqlite3_mutex_held(statMutex[op] ? sqlite3Pcache1Mutex()
14974 : sqlite3MallocMutex()) );
14975 return wsdStat.nowValue[op];
14976 }
14977
14978 /*
14979 ** Add N to the value of a status record. The caller must hold the
14980 ** appropriate mutex. (Locking is checked by assert()).
14981 **
14982 ** The StatusUp() routine can accept positive or negative values for N.
14983 ** The value of N is added to the current status value and the high-water
14984 ** mark is adjusted if necessary.
14985 **
14986 ** The StatusDown() routine lowers the current value by N. The highwater
14987 ** mark is unchanged. N must be non-negative for StatusDown().
14988 */
14989 SQLITE_PRIVATE void sqlite3StatusUp(int op, int N){
14990 wsdStatInit;
14991 assert( op>=0 && op<ArraySize(wsdStat.nowValue) );
14992 assert( op>=0 && op<ArraySize(statMutex) );
14993 assert( sqlite3_mutex_held(statMutex[op] ? sqlite3Pcache1Mutex()
14994 : sqlite3MallocMutex()) );
14995 wsdStat.nowValue[op] += N;
14996 if( wsdStat.nowValue[op]>wsdStat.mxValue[op] ){
14997 wsdStat.mxValue[op] = wsdStat.nowValue[op];
14998 }
14999 }
15000 SQLITE_PRIVATE void sqlite3StatusDown(int op, int N){
15001 wsdStatInit;
15002 assert( N>=0 );
15003 assert( op>=0 && op<ArraySize(statMutex) );
15004 assert( sqlite3_mutex_held(statMutex[op] ? sqlite3Pcache1Mutex()
15005 : sqlite3MallocMutex()) );
15006 assert( op>=0 && op<ArraySize(wsdStat.nowValue) );
15007 wsdStat.nowValue[op] -= N;
15008 }
15009
15010 /*
15011 ** Set the value of a status to X. The highwater mark is adjusted if
15012 ** necessary. The caller must hold the appropriate mutex.
15013 */
15014 SQLITE_PRIVATE void sqlite3StatusSet(int op, int X){
15015 wsdStatInit;
15016 assert( op>=0 && op<ArraySize(wsdStat.nowValue) );
15017 assert( op>=0 && op<ArraySize(statMutex) );
15018 assert( sqlite3_mutex_held(statMutex[op] ? sqlite3Pcache1Mutex()
15019 : sqlite3MallocMutex()) );
15020 wsdStat.nowValue[op] = X;
15021 if( wsdStat.nowValue[op]>wsdStat.mxValue[op] ){
15022 wsdStat.mxValue[op] = wsdStat.nowValue[op];
15023 }
15024 }
15025
15026 /*
15027 ** Query status information.
 
 
 
 
15028 */
15029 SQLITE_API int sqlite3_status64(
15030 int op,
15031 sqlite3_int64 *pCurrent,
15032 sqlite3_int64 *pHighwater,
15033 int resetFlag
15034 ){
15035 sqlite3_mutex *pMutex;
15036 wsdStatInit;
15037 if( op<0 || op>=ArraySize(wsdStat.nowValue) ){
15038 return SQLITE_MISUSE_BKPT;
15039 }
15040 #ifdef SQLITE_ENABLE_API_ARMOR
15041 if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT;
15042 #endif
15043 pMutex = statMutex[op] ? sqlite3Pcache1Mutex() : sqlite3MallocMutex();
15044 sqlite3_mutex_enter(pMutex);
15045 *pCurrent = wsdStat.nowValue[op];
15046 *pHighwater = wsdStat.mxValue[op];
15047 if( resetFlag ){
15048 wsdStat.mxValue[op] = wsdStat.nowValue[op];
15049 }
15050 sqlite3_mutex_leave(pMutex);
15051 (void)pMutex; /* Prevent warning when SQLITE_THREADSAFE=0 */
15052 return SQLITE_OK;
15053 }
15054 SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){
15055 sqlite3_int64 iCur, iHwtr;
15056 int rc;
15057 #ifdef SQLITE_ENABLE_API_ARMOR
15058 if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT;
15059 #endif
15060 rc = sqlite3_status64(op, &iCur, &iHwtr, resetFlag);
15061 if( rc==0 ){
15062 *pCurrent = (int)iCur;
15063 *pHighwater = (int)iHwtr;
15064 }
15065 return rc;
15066 }
15067
15068 /*
15069 ** Query status information for a single database connection
15070 */
@@ -20358,10 +20514,17 @@
20514 */
20515 int nearlyFull;
20516 } mem0 = { 0, 0, 0, 0, 0, 0, 0, 0 };
20517
20518 #define mem0 GLOBAL(struct Mem0Global, mem0)
20519
20520 /*
20521 ** Return the memory allocator mutex. sqlite3_status() needs it.
20522 */
20523 SQLITE_PRIVATE sqlite3_mutex *sqlite3MallocMutex(void){
20524 return mem0.mutex;
20525 }
20526
20527 /*
20528 ** This routine runs when the memory allocator sees that the
20529 ** total memory allocation is about to exceed the soft heap
20530 ** limit.
@@ -20381,11 +20544,11 @@
20544 static int sqlite3MemoryAlarm(
20545 void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
20546 void *pArg,
20547 sqlite3_int64 iThreshold
20548 ){
20549 sqlite3_int64 nUsed;
20550 sqlite3_mutex_enter(mem0.mutex);
20551 mem0.alarmCallback = xCallback;
20552 mem0.alarmArg = pArg;
20553 mem0.alarmThreshold = iThreshold;
20554 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
@@ -20550,11 +20713,11 @@
20713 void *p;
20714 assert( sqlite3_mutex_held(mem0.mutex) );
20715 nFull = sqlite3GlobalConfig.m.xRoundup(n);
20716 sqlite3StatusSet(SQLITE_STATUS_MALLOC_SIZE, n);
20717 if( mem0.alarmCallback!=0 ){
20718 sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
20719 if( nUsed >= mem0.alarmThreshold - nFull ){
20720 mem0.nearlyFull = 1;
20721 sqlite3MallocAlarm(nFull);
20722 }else{
20723 mem0.nearlyFull = 0;
@@ -20567,12 +20730,12 @@
20730 p = sqlite3GlobalConfig.m.xMalloc(nFull);
20731 }
20732 #endif
20733 if( p ){
20734 nFull = sqlite3MallocSize(p);
20735 sqlite3StatusUp(SQLITE_STATUS_MEMORY_USED, nFull);
20736 sqlite3StatusUp(SQLITE_STATUS_MALLOC_COUNT, 1);
20737 }
20738 *pp = p;
20739 return nFull;
20740 }
20741
@@ -20645,18 +20808,18 @@
20808 sqlite3StatusSet(SQLITE_STATUS_SCRATCH_SIZE, n);
20809 if( mem0.nScratchFree && sqlite3GlobalConfig.szScratch>=n ){
20810 p = mem0.pScratchFree;
20811 mem0.pScratchFree = mem0.pScratchFree->pNext;
20812 mem0.nScratchFree--;
20813 sqlite3StatusUp(SQLITE_STATUS_SCRATCH_USED, 1);
20814 sqlite3_mutex_leave(mem0.mutex);
20815 }else{
20816 sqlite3_mutex_leave(mem0.mutex);
20817 p = sqlite3Malloc(n);
20818 if( sqlite3GlobalConfig.bMemstat && p ){
20819 sqlite3_mutex_enter(mem0.mutex);
20820 sqlite3StatusUp(SQLITE_STATUS_SCRATCH_OVERFLOW, sqlite3MallocSize(p));
20821 sqlite3_mutex_leave(mem0.mutex);
20822 }
20823 sqlite3MemdebugSetType(p, MEMTYPE_SCRATCH);
20824 }
20825 assert( sqlite3_mutex_notheld(mem0.mutex) );
@@ -20693,23 +20856,23 @@
20856 sqlite3_mutex_enter(mem0.mutex);
20857 pSlot->pNext = mem0.pScratchFree;
20858 mem0.pScratchFree = pSlot;
20859 mem0.nScratchFree++;
20860 assert( mem0.nScratchFree <= (u32)sqlite3GlobalConfig.nScratch );
20861 sqlite3StatusDown(SQLITE_STATUS_SCRATCH_USED, 1);
20862 sqlite3_mutex_leave(mem0.mutex);
20863 }else{
20864 /* Release memory back to the heap */
20865 assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) );
20866 assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_SCRATCH) );
20867 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
20868 if( sqlite3GlobalConfig.bMemstat ){
20869 int iSize = sqlite3MallocSize(p);
20870 sqlite3_mutex_enter(mem0.mutex);
20871 sqlite3StatusDown(SQLITE_STATUS_SCRATCH_OVERFLOW, iSize);
20872 sqlite3StatusDown(SQLITE_STATUS_MEMORY_USED, iSize);
20873 sqlite3StatusDown(SQLITE_STATUS_MALLOC_COUNT, 1);
20874 sqlite3GlobalConfig.m.xFree(p);
20875 sqlite3_mutex_leave(mem0.mutex);
20876 }else{
20877 sqlite3GlobalConfig.m.xFree(p);
20878 }
@@ -20736,26 +20899,26 @@
20899 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
20900 return sqlite3GlobalConfig.m.xSize(p);
20901 }
20902 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){
20903 if( db==0 ){
20904 assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
20905 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
20906 return sqlite3MallocSize(p);
20907 }else{
20908 assert( sqlite3_mutex_held(db->mutex) );
20909 if( isLookaside(db, p) ){
20910 return db->lookaside.sz;
20911 }else{
20912 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20913 assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20914 return sqlite3GlobalConfig.m.xSize(p);
20915 }
20916 }
20917 }
20918 SQLITE_API sqlite3_uint64 sqlite3_msize(void *p){
20919 assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
20920 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
20921 return (sqlite3_uint64)sqlite3GlobalConfig.m.xSize(p);
20922 }
20923
20924 /*
@@ -20762,15 +20925,15 @@
20925 ** Free memory previously obtained from sqlite3Malloc().
20926 */
20927 SQLITE_API void sqlite3_free(void *p){
20928 if( p==0 ) return; /* IMP: R-49053-54554 */
20929 assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
20930 assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) );
20931 if( sqlite3GlobalConfig.bMemstat ){
20932 sqlite3_mutex_enter(mem0.mutex);
20933 sqlite3StatusDown(SQLITE_STATUS_MEMORY_USED, sqlite3MallocSize(p));
20934 sqlite3StatusDown(SQLITE_STATUS_MALLOC_COUNT, 1);
20935 sqlite3GlobalConfig.m.xFree(p);
20936 sqlite3_mutex_leave(mem0.mutex);
20937 }else{
20938 sqlite3GlobalConfig.m.xFree(p);
20939 }
@@ -20807,11 +20970,11 @@
20970 db->lookaside.nOut--;
20971 return;
20972 }
20973 }
20974 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20975 assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
20976 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
20977 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
20978 sqlite3_free(p);
20979 }
20980
@@ -20820,11 +20983,11 @@
20983 */
20984 SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, u64 nBytes){
20985 int nOld, nNew, nDiff;
20986 void *pNew;
20987 assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
20988 assert( sqlite3MemdebugNoType(pOld, (u8)~MEMTYPE_HEAP) );
20989 if( pOld==0 ){
20990 return sqlite3Malloc(nBytes); /* IMP: R-04300-56712 */
20991 }
20992 if( nBytes==0 ){
20993 sqlite3_free(pOld); /* IMP: R-26507-47431 */
@@ -20854,11 +21017,11 @@
21017 sqlite3MallocAlarm((int)nBytes);
21018 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
21019 }
21020 if( pNew ){
21021 nNew = sqlite3MallocSize(pNew);
21022 sqlite3StatusUp(SQLITE_STATUS_MEMORY_USED, nNew-nOld);
21023 }
21024 sqlite3_mutex_leave(mem0.mutex);
21025 }else{
21026 pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
21027 }
@@ -20987,11 +21150,11 @@
21150 memcpy(pNew, p, db->lookaside.sz);
21151 sqlite3DbFree(db, p);
21152 }
21153 }else{
21154 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
21155 assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
21156 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
21157 pNew = sqlite3_realloc64(p, n);
21158 if( !pNew ){
21159 db->mallocFailed = 1;
21160 }
@@ -24969,27 +25132,29 @@
25132 /* 134 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
25133 /* 135 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
25134 /* 136 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
25135 /* 137 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
25136 /* 138 */ "IfNeg" OpHelp("r[P1]+=P3, if r[P1]<0 goto P2"),
25137 /* 139 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]+=P3, goto P2"),
25138 /* 140 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
25139 /* 141 */ "JumpZeroIncr" OpHelp("if (r[P1]++)==0 ) goto P2"),
25140 /* 142 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
25141 /* 143 */ "IncrVacuum" OpHelp(""),
25142 /* 144 */ "Expire" OpHelp(""),
25143 /* 145 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
25144 /* 146 */ "VBegin" OpHelp(""),
25145 /* 147 */ "VCreate" OpHelp(""),
25146 /* 148 */ "VDestroy" OpHelp(""),
25147 /* 149 */ "VOpen" OpHelp(""),
25148 /* 150 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
25149 /* 151 */ "VNext" OpHelp(""),
25150 /* 152 */ "VRename" OpHelp(""),
25151 /* 153 */ "Pagecount" OpHelp(""),
25152 /* 154 */ "MaxPgcnt" OpHelp(""),
25153 /* 155 */ "Init" OpHelp("Start at P2"),
25154 /* 156 */ "Noop" OpHelp(""),
25155 /* 157 */ "Explain" OpHelp(""),
25156 };
25157 return azName[i];
25158 }
25159 #endif
25160
@@ -25065,22 +25230,10 @@
25230 # else
25231 # define SQLITE_ENABLE_LOCKING_STYLE 0
25232 # endif
25233 #endif
25234
 
 
 
 
 
 
 
 
 
 
 
 
25235 /*
25236 ** standard include files.
25237 */
25238 #include <sys/types.h>
25239 #include <sys/stat.h>
@@ -25091,22 +25244,23 @@
25244 #include <errno.h>
25245 #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
25246 # include <sys/mman.h>
25247 #endif
25248
25249 #if SQLITE_ENABLE_LOCKING_STYLE
25250 # include <sys/ioctl.h>
25251 # include <sys/file.h>
25252 # include <sys/param.h>
 
 
 
 
 
25253 #endif /* SQLITE_ENABLE_LOCKING_STYLE */
25254
25255 #if OS_VXWORKS
25256 /* # include <sys/ioctl.h> */
25257 # include <semaphore.h>
25258 # include <limits.h>
25259 #endif /* OS_VXWORKS */
25260
25261 #if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE
25262 # include <sys/mount.h>
25263 #endif
25264
25265 #ifdef HAVE_UTIME
25266 # include <utime.h>
@@ -25142,10 +25296,14 @@
25296
25297 /*
25298 ** Maximum supported path-length.
25299 */
25300 #define MAX_PATHNAME 512
25301
25302 /* Always cast the getpid() return type for compatibility with
25303 ** kernel modules in VxWorks. */
25304 #define osGetpid(X) (pid_t)getpid()
25305
25306 /*
25307 ** Only set the lastErrno if the error code is a real error and not
25308 ** a normal expected return code of SQLITE_BUSY or SQLITE_OK
25309 */
@@ -25231,11 +25389,11 @@
25389
25390 /* This variable holds the process id (pid) from when the xRandomness()
25391 ** method was called. If xOpen() is called from a different process id,
25392 ** indicating that a fork() has occurred, the PRNG will be reset.
25393 */
25394 static pid_t randomnessPid = 0;
25395
25396 /*
25397 ** Allowed values for the unixFile.ctrlFlags bitmask:
25398 */
25399 #define UNIXFILE_EXCL 0x01 /* Connections from one process only */
@@ -25249,10 +25407,11 @@
25407 #define UNIXFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
25408 #define UNIXFILE_DELETE 0x20 /* Delete on close */
25409 #define UNIXFILE_URI 0x40 /* Filename might have query parameters */
25410 #define UNIXFILE_NOLOCK 0x80 /* Do no file locking */
25411 #define UNIXFILE_WARNED 0x0100 /* verifyDbFile() warnings issued */
25412 #define UNIXFILE_BLOCK 0x0200 /* Next SHM lock might block */
25413
25414 /*
25415 ** Include code that is common to all os_*.c files
25416 */
25417 /************** Include os_common.h in the middle of os_unix.c ***************/
@@ -25587,11 +25746,11 @@
25746 #define osFcntl ((int(*)(int,int,...))aSyscall[7].pCurrent)
25747
25748 { "read", (sqlite3_syscall_ptr)read, 0 },
25749 #define osRead ((ssize_t(*)(int,void*,size_t))aSyscall[8].pCurrent)
25750
25751 #if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE
25752 { "pread", (sqlite3_syscall_ptr)pread, 0 },
25753 #else
25754 { "pread", (sqlite3_syscall_ptr)0, 0 },
25755 #endif
25756 #define osPread ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[9].pCurrent)
@@ -25604,11 +25763,11 @@
25763 #define osPread64 ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].pCurrent)
25764
25765 { "write", (sqlite3_syscall_ptr)write, 0 },
25766 #define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent)
25767
25768 #if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE
25769 { "pwrite", (sqlite3_syscall_ptr)pwrite, 0 },
25770 #else
25771 { "pwrite", (sqlite3_syscall_ptr)0, 0 },
25772 #endif
25773 #define osPwrite ((ssize_t(*)(int,const void*,size_t,off_t))\
@@ -26743,11 +26902,12 @@
26902 int tErrno = 0;
26903
26904 assert( pFile );
26905 OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (unix)\n", pFile->h,
26906 azFileLock(eFileLock), azFileLock(pFile->eFileLock),
26907 azFileLock(pFile->pInode->eFileLock), pFile->pInode->nShared,
26908 osGetpid(0)));
26909
26910 /* If there is already a lock of this type or more restrictive on the
26911 ** unixFile, do nothing. Don't use the end_lock: exit path, as
26912 ** unixEnterMutex() hasn't been called yet.
26913 */
@@ -26951,11 +27111,11 @@
27111 int rc = SQLITE_OK;
27112
27113 assert( pFile );
27114 OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (unix)\n", pFile->h, eFileLock,
27115 pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared,
27116 osGetpid(0)));
27117
27118 assert( eFileLock<=SHARED_LOCK );
27119 if( pFile->eFileLock<=eFileLock ){
27120 return SQLITE_OK;
27121 }
@@ -27378,11 +27538,11 @@
27538 char *zLockFile = (char *)pFile->lockingContext;
27539 int rc;
27540
27541 assert( pFile );
27542 OSTRACE(("UNLOCK %d %d was %d pid=%d (dotlock)\n", pFile->h, eFileLock,
27543 pFile->eFileLock, osGetpid(0)));
27544 assert( eFileLock<=SHARED_LOCK );
27545
27546 /* no-op if possible */
27547 if( pFile->eFileLock==eFileLock ){
27548 return SQLITE_OK;
@@ -27441,14 +27601,13 @@
27601 ** a single exclusive lock. In other words, SHARED, RESERVED, and
27602 ** PENDING locks are the same thing as an EXCLUSIVE lock. SQLite
27603 ** still works when you do this, but concurrency is reduced since
27604 ** only a single process can be reading the database at a time.
27605 **
27606 ** Omit this section if SQLITE_ENABLE_LOCKING_STYLE is turned off
 
27607 */
27608 #if SQLITE_ENABLE_LOCKING_STYLE
27609
27610 /*
27611 ** Retry flock() calls that fail with EINTR
27612 */
27613 #ifdef EINTR
@@ -27597,11 +27756,11 @@
27756 static int flockUnlock(sqlite3_file *id, int eFileLock) {
27757 unixFile *pFile = (unixFile*)id;
27758
27759 assert( pFile );
27760 OSTRACE(("UNLOCK %d %d was %d pid=%d (flock)\n", pFile->h, eFileLock,
27761 pFile->eFileLock, osGetpid(0)));
27762 assert( eFileLock<=SHARED_LOCK );
27763
27764 /* no-op if possible */
27765 if( pFile->eFileLock==eFileLock ){
27766 return SQLITE_OK;
@@ -27658,11 +27817,11 @@
27817 ** This routine checks if there is a RESERVED lock held on the specified
27818 ** file by this or any other process. If such a lock is held, set *pResOut
27819 ** to a non-zero value otherwise *pResOut is set to zero. The return value
27820 ** is set to SQLITE_OK unless an I/O error occurs during lock checking.
27821 */
27822 static int semXCheckReservedLock(sqlite3_file *id, int *pResOut) {
27823 int rc = SQLITE_OK;
27824 int reserved = 0;
27825 unixFile *pFile = (unixFile*)id;
27826
27827 SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; );
@@ -27725,11 +27884,11 @@
27884 ** access the file.
27885 **
27886 ** This routine will only increase a lock. Use the sqlite3OsUnlock()
27887 ** routine to lower a locking level.
27888 */
27889 static int semXLock(sqlite3_file *id, int eFileLock) {
27890 unixFile *pFile = (unixFile*)id;
27891 sem_t *pSem = pFile->pInode->pSem;
27892 int rc = SQLITE_OK;
27893
27894 /* if we already have a lock, it is exclusive.
@@ -27758,18 +27917,18 @@
27917 ** must be either NO_LOCK or SHARED_LOCK.
27918 **
27919 ** If the locking level of the file descriptor is already at or below
27920 ** the requested locking level, this routine is a no-op.
27921 */
27922 static int semXUnlock(sqlite3_file *id, int eFileLock) {
27923 unixFile *pFile = (unixFile*)id;
27924 sem_t *pSem = pFile->pInode->pSem;
27925
27926 assert( pFile );
27927 assert( pSem );
27928 OSTRACE(("UNLOCK %d %d was %d pid=%d (sem)\n", pFile->h, eFileLock,
27929 pFile->eFileLock, osGetpid(0)));
27930 assert( eFileLock<=SHARED_LOCK );
27931
27932 /* no-op if possible */
27933 if( pFile->eFileLock==eFileLock ){
27934 return SQLITE_OK;
@@ -27795,14 +27954,14 @@
27954 }
27955
27956 /*
27957 ** Close a file.
27958 */
27959 static int semXClose(sqlite3_file *id) {
27960 if( id ){
27961 unixFile *pFile = (unixFile*)id;
27962 semXUnlock(id, NO_LOCK);
27963 assert( pFile );
27964 unixEnterMutex();
27965 releaseInodeInfo(pFile);
27966 unixLeaveMutex();
27967 closeUnixFile(id);
@@ -27979,11 +28138,11 @@
28138 afpLockingContext *context = (afpLockingContext *) pFile->lockingContext;
28139
28140 assert( pFile );
28141 OSTRACE(("LOCK %d %s was %s(%s,%d) pid=%d (afp)\n", pFile->h,
28142 azFileLock(eFileLock), azFileLock(pFile->eFileLock),
28143 azFileLock(pInode->eFileLock), pInode->nShared , osGetpid(0)));
28144
28145 /* If there is already a lock of this type or more restrictive on the
28146 ** unixFile, do nothing. Don't use the afp_end_lock: exit path, as
28147 ** unixEnterMutex() hasn't been called yet.
28148 */
@@ -28165,11 +28324,11 @@
28324 #endif
28325
28326 assert( pFile );
28327 OSTRACE(("UNLOCK %d %d was %d(%d,%d) pid=%d (afp)\n", pFile->h, eFileLock,
28328 pFile->eFileLock, pFile->pInode->eFileLock, pFile->pInode->nShared,
28329 osGetpid(0)));
28330
28331 assert( eFileLock<=SHARED_LOCK );
28332 if( pFile->eFileLock<=eFileLock ){
28333 return SQLITE_OK;
28334 }
@@ -28990,10 +29149,14 @@
29149 ** Information and control of an open file handle.
29150 */
29151 static int unixFileControl(sqlite3_file *id, int op, void *pArg){
29152 unixFile *pFile = (unixFile*)id;
29153 switch( op ){
29154 case SQLITE_FCNTL_WAL_BLOCK: {
29155 pFile->ctrlFlags |= UNIXFILE_BLOCK;
29156 return SQLITE_OK;
29157 }
29158 case SQLITE_FCNTL_LOCKSTATE: {
29159 *(int*)pArg = pFile->eFileLock;
29160 return SQLITE_OK;
29161 }
29162 case SQLITE_FCNTL_LAST_ERRNO: {
@@ -29204,11 +29367,13 @@
29367 **
29368 ** This function should not be called directly by other code in this file.
29369 ** Instead, it should be called via macro osGetpagesize().
29370 */
29371 static int unixGetpagesize(void){
29372 #if OS_VXWORKS
29373 return 1024;
29374 #elif defined(_BSD_SOURCE)
29375 return getpagesize();
29376 #else
29377 return (int)sysconf(_SC_PAGESIZE);
29378 #endif
29379 }
@@ -29297,37 +29462,42 @@
29462 **
29463 ** Locks block if the mask is exactly UNIX_SHM_C and are non-blocking
29464 ** otherwise.
29465 */
29466 static int unixShmSystemLock(
29467 unixFile *pFile, /* Open connection to the WAL file */
29468 int lockType, /* F_UNLCK, F_RDLCK, or F_WRLCK */
29469 int ofst, /* First byte of the locking range */
29470 int n /* Number of bytes to lock */
29471 ){
29472 unixShmNode *pShmNode; /* Apply locks to this open shared-memory segment */
29473 struct flock f; /* The posix advisory locking structure */
29474 int rc = SQLITE_OK; /* Result code form fcntl() */
29475
29476 /* Access to the unixShmNode object is serialized by the caller */
29477 pShmNode = pFile->pInode->pShmNode;
29478 assert( sqlite3_mutex_held(pShmNode->mutex) || pShmNode->nRef==0 );
29479
29480 /* Shared locks never span more than one byte */
29481 assert( n==1 || lockType!=F_RDLCK );
29482
29483 /* Locks are within range */
29484 assert( n>=1 && n<SQLITE_SHM_NLOCK );
29485
29486 if( pShmNode->h>=0 ){
29487 int lkType;
29488 /* Initialize the locking parameters */
29489 memset(&f, 0, sizeof(f));
29490 f.l_type = lockType;
29491 f.l_whence = SEEK_SET;
29492 f.l_start = ofst;
29493 f.l_len = n;
29494
29495 lkType = (pFile->ctrlFlags & UNIXFILE_BLOCK)!=0 ? F_SETLKW : F_SETLK;
29496 rc = osFcntl(pShmNode->h, lkType, &f);
29497 rc = (rc!=(-1)) ? SQLITE_OK : SQLITE_BUSY;
29498 pFile->ctrlFlags &= ~UNIXFILE_BLOCK;
29499 }
29500
29501 /* Update the global lock state and do debug tracing */
29502 #ifdef SQLITE_DEBUG
29503 { u16 mask;
@@ -29533,17 +29703,17 @@
29703
29704 /* Check to see if another process is holding the dead-man switch.
29705 ** If not, truncate the file to zero length.
29706 */
29707 rc = SQLITE_OK;
29708 if( unixShmSystemLock(pDbFd, F_WRLCK, UNIX_SHM_DMS, 1)==SQLITE_OK ){
29709 if( robust_ftruncate(pShmNode->h, 0) ){
29710 rc = unixLogError(SQLITE_IOERR_SHMOPEN, "ftruncate", zShmFilename);
29711 }
29712 }
29713 if( rc==SQLITE_OK ){
29714 rc = unixShmSystemLock(pDbFd, F_RDLCK, UNIX_SHM_DMS, 1);
29715 }
29716 if( rc ) goto shm_open_err;
29717 }
29718 }
29719
@@ -29771,11 +29941,11 @@
29941 allMask |= pX->sharedMask;
29942 }
29943
29944 /* Unlock the system-level locks */
29945 if( (mask & allMask)==0 ){
29946 rc = unixShmSystemLock(pDbFd, F_UNLCK, ofst+UNIX_SHM_BASE, n);
29947 }else{
29948 rc = SQLITE_OK;
29949 }
29950
29951 /* Undo the local locks */
@@ -29799,11 +29969,11 @@
29969 }
29970
29971 /* Get shared locks at the system level, if necessary */
29972 if( rc==SQLITE_OK ){
29973 if( (allShared & mask)==0 ){
29974 rc = unixShmSystemLock(pDbFd, F_RDLCK, ofst+UNIX_SHM_BASE, n);
29975 }else{
29976 rc = SQLITE_OK;
29977 }
29978 }
29979
@@ -29824,20 +29994,20 @@
29994
29995 /* Get the exclusive locks at the system level. Then if successful
29996 ** also mark the local connection as being locked.
29997 */
29998 if( rc==SQLITE_OK ){
29999 rc = unixShmSystemLock(pDbFd, F_WRLCK, ofst+UNIX_SHM_BASE, n);
30000 if( rc==SQLITE_OK ){
30001 assert( (p->sharedMask & mask)==0 );
30002 p->exclMask |= mask;
30003 }
30004 }
30005 }
30006 sqlite3_mutex_leave(pShmNode->mutex);
30007 OSTRACE(("SHM-LOCK shmid-%d, pid-%d got %03x,%03x\n",
30008 p->id, osGetpid(0), p->sharedMask, p->exclMask));
30009 return rc;
30010 }
30011
30012 /*
30013 ** Implement a memory barrier or memory fence on shared memory.
@@ -30236,11 +30406,11 @@
30406 dotlockUnlock, /* xUnlock method */
30407 dotlockCheckReservedLock, /* xCheckReservedLock method */
30408 0 /* xShmMap method */
30409 )
30410
30411 #if SQLITE_ENABLE_LOCKING_STYLE
30412 IOMETHODS(
30413 flockIoFinder, /* Finder function name */
30414 flockIoMethods, /* sqlite3_io_methods object name */
30415 1, /* shared memory is disabled */
30416 flockClose, /* xClose method */
@@ -30254,14 +30424,14 @@
30424 #if OS_VXWORKS
30425 IOMETHODS(
30426 semIoFinder, /* Finder function name */
30427 semIoMethods, /* sqlite3_io_methods object name */
30428 1, /* shared memory is disabled */
30429 semXClose, /* xClose method */
30430 semXLock, /* xLock method */
30431 semXUnlock, /* xUnlock method */
30432 semXCheckReservedLock, /* xCheckReservedLock method */
30433 0 /* xShmMap method */
30434 )
30435 #endif
30436
30437 #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
@@ -30381,19 +30551,17 @@
30551 static const sqlite3_io_methods
30552 *(*const autolockIoFinder)(const char*,unixFile*) = autolockIoFinderImpl;
30553
30554 #endif /* defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE */
30555
30556 #if OS_VXWORKS
30557 /*
30558 ** This "finder" function for VxWorks checks to see if posix advisory
30559 ** locking works. If it does, then that is what is used. If it does not
30560 ** work, then fallback to named semaphore locking.
 
 
30561 */
30562 static const sqlite3_io_methods *vxworksIoFinderImpl(
30563 const char *filePath, /* name of the database file */
30564 unixFile *pNew /* the open file object */
30565 ){
30566 struct flock lockInfo;
30567
@@ -30415,13 +30583,13 @@
30583 }else{
30584 return &semIoMethods;
30585 }
30586 }
30587 static const sqlite3_io_methods
30588 *(*const vxworksIoFinder)(const char*,unixFile*) = vxworksIoFinderImpl;
30589
30590 #endif /* OS_VXWORKS */
30591
30592 /*
30593 ** An abstract type for a pointer to an IO method finder function:
30594 */
30595 typedef const sqlite3_io_methods *(*finder_type)(const char*,unixFile*);
@@ -30930,12 +31098,12 @@
31098 /* Detect a pid change and reset the PRNG. There is a race condition
31099 ** here such that two or more threads all trying to open databases at
31100 ** the same instant might all reset the PRNG. But multiple resets
31101 ** are harmless.
31102 */
31103 if( randomnessPid!=osGetpid(0) ){
31104 randomnessPid = osGetpid(0);
31105 sqlite3_randomness(0,0);
31106 }
31107
31108 memset(p, 0, sizeof(unixFile));
31109
@@ -31322,11 +31490,11 @@
31490 ** When testing, initializing zBuf[] to zero is all we do. That means
31491 ** that we always use the same random number sequence. This makes the
31492 ** tests repeatable.
31493 */
31494 memset(zBuf, 0, nBuf);
31495 randomnessPid = osGetpid(0);
31496 #if !defined(SQLITE_TEST)
31497 {
31498 int fd, got;
31499 fd = robust_open("/dev/urandom", O_RDONLY, 0);
31500 if( fd<0 ){
@@ -31643,11 +31811,11 @@
31811 #else
31812 # ifdef _CS_DARWIN_USER_TEMP_DIR
31813 {
31814 if( !confstr(_CS_DARWIN_USER_TEMP_DIR, lPath, maxLen) ){
31815 OSTRACE(("GETLOCKPATH failed %s errno=%d pid=%d\n",
31816 lPath, errno, osGetpid(0)));
31817 return SQLITE_IOERR_LOCK;
31818 }
31819 len = strlcat(lPath, "sqliteplocks", maxLen);
31820 }
31821 # else
@@ -31665,11 +31833,11 @@
31833 char c = dbPath[i];
31834 lPath[i+len] = (c=='/')?'_':c;
31835 }
31836 lPath[i+len]='\0';
31837 strlcat(lPath, ":auto:", maxLen);
31838 OSTRACE(("GETLOCKPATH proxy lock path=%s pid=%d\n", lPath, osGetpid(0)));
31839 return SQLITE_OK;
31840 }
31841
31842 /*
31843 ** Creates the lock file and any missing directories in lockPath
@@ -31692,20 +31860,20 @@
31860 if( osMkdir(buf, SQLITE_DEFAULT_PROXYDIR_PERMISSIONS) ){
31861 int err=errno;
31862 if( err!=EEXIST ) {
31863 OSTRACE(("CREATELOCKPATH FAILED creating %s, "
31864 "'%s' proxy lock path=%s pid=%d\n",
31865 buf, strerror(err), lockPath, osGetpid(0)));
31866 return err;
31867 }
31868 }
31869 }
31870 start=i+1;
31871 }
31872 buf[i] = lockPath[i];
31873 }
31874 OSTRACE(("CREATELOCKPATH proxy lock path=%s pid=%d\n", lockPath, osGetpid(0)));
31875 return 0;
31876 }
31877
31878 /*
31879 ** Create a new VFS file descriptor (stored in memory obtained from
@@ -32006,11 +32174,12 @@
32174 int readLen = 0;
32175 int tryOldLockPath = 0;
32176 int forceNewLockPath = 0;
32177
32178 OSTRACE(("TAKECONCH %d for %s pid=%d\n", conchFile->h,
32179 (pCtx->lockProxyPath ? pCtx->lockProxyPath : ":auto:"),
32180 osGetpid(0)));
32181
32182 rc = proxyGetHostID(myHostID, &pError);
32183 if( (rc&0xff)==SQLITE_IOERR ){
32184 storeLastErrno(pFile, pError);
32185 goto end_takeconch;
@@ -32216,11 +32385,11 @@
32385
32386 pCtx = (proxyLockingContext *)pFile->lockingContext;
32387 conchFile = pCtx->conchFile;
32388 OSTRACE(("RELEASECONCH %d for %s pid=%d\n", conchFile->h,
32389 (pCtx->lockProxyPath ? pCtx->lockProxyPath : ":auto:"),
32390 osGetpid(0)));
32391 if( pCtx->conchHeld>0 ){
32392 rc = conchFile->pMethod->xUnlock((sqlite3_file*)conchFile, NO_LOCK);
32393 }
32394 pCtx->conchHeld = 0;
32395 OSTRACE(("RELEASECONCH %d %s\n", conchFile->h,
@@ -32358,11 +32527,11 @@
32527 }else{
32528 lockPath=(char *)path;
32529 }
32530
32531 OSTRACE(("TRANSPROXY %d for %s pid=%d\n", pFile->h,
32532 (lockPath ? lockPath : ":auto:"), osGetpid(0)));
32533
32534 pCtx = sqlite3_malloc( sizeof(*pCtx) );
32535 if( pCtx==0 ){
32536 return SQLITE_NOMEM;
32537 }
@@ -32699,26 +32868,28 @@
32868 ** Note that the sqlite3_vfs.pNext field of the VFS object is modified
32869 ** by the SQLite core when the VFS is registered. So the following
32870 ** array cannot be const.
32871 */
32872 static sqlite3_vfs aVfs[] = {
32873 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
32874 UNIXVFS("unix", autolockIoFinder ),
32875 #elif OS_VXWORKS
32876 UNIXVFS("unix", vxworksIoFinder ),
32877 #else
32878 UNIXVFS("unix", posixIoFinder ),
32879 #endif
32880 UNIXVFS("unix-none", nolockIoFinder ),
32881 UNIXVFS("unix-dotfile", dotlockIoFinder ),
32882 UNIXVFS("unix-excl", posixIoFinder ),
32883 #if OS_VXWORKS
32884 UNIXVFS("unix-namedsem", semIoFinder ),
32885 #endif
32886 #if SQLITE_ENABLE_LOCKING_STYLE || OS_VXWORKS
32887 UNIXVFS("unix-posix", posixIoFinder ),
32888 #endif
32889 #if SQLITE_ENABLE_LOCKING_STYLE
32890 UNIXVFS("unix-flock", flockIoFinder ),
 
32891 #endif
32892 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
32893 UNIXVFS("unix-afp", afpIoFinder ),
32894 UNIXVFS("unix-nfs", nfsIoFinder ),
32895 UNIXVFS("unix-proxy", proxyIoFinder ),
@@ -39072,16 +39243,24 @@
39243 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0);
39244 }
39245 }
39246
39247 /*
39248 ** Compute the number of pages of cache requested. p->szCache is the
39249 ** cache size requested by the "PRAGMA cache_size" statement.
39250 **
39251 **
39252 */
39253 static int numberOfCachePages(PCache *p){
39254 if( p->szCache>=0 ){
39255 /* IMPLEMENTATION-OF: R-42059-47211 If the argument N is positive then the
39256 ** suggested cache size is set to N. */
39257 return p->szCache;
39258 }else{
39259 /* IMPLEMENTATION-OF: R-61436-13639 If the argument N is negative, then
39260 ** the number of cache pages is adjusted to use approximately abs(N*1024)
39261 ** bytes of memory. */
39262 return (int)((-1024*(i64)p->szCache)/(p->szPage+p->szExtra));
39263 }
39264 }
39265
39266 /*************************************************** General Interfaces ******
@@ -39817,20 +39996,20 @@
39996 ** in pcache1 need to be protected via mutex.
39997 */
39998 static void *pcache1Alloc(int nByte){
39999 void *p = 0;
40000 assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
 
40001 if( nByte<=pcache1.szSlot ){
40002 sqlite3_mutex_enter(pcache1.mutex);
40003 p = (PgHdr1 *)pcache1.pFree;
40004 if( p ){
40005 pcache1.pFree = pcache1.pFree->pNext;
40006 pcache1.nFreeSlot--;
40007 pcache1.bUnderPressure = pcache1.nFreeSlot<pcache1.nReserve;
40008 assert( pcache1.nFreeSlot>=0 );
40009 sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte);
40010 sqlite3StatusUp(SQLITE_STATUS_PAGECACHE_USED, 1);
40011 }
40012 sqlite3_mutex_leave(pcache1.mutex);
40013 }
40014 if( p==0 ){
40015 /* Memory is not available in the SQLITE_CONFIG_PAGECACHE pool. Get
@@ -39839,11 +40018,12 @@
40018 p = sqlite3Malloc(nByte);
40019 #ifndef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
40020 if( p ){
40021 int sz = sqlite3MallocSize(p);
40022 sqlite3_mutex_enter(pcache1.mutex);
40023 sqlite3StatusSet(SQLITE_STATUS_PAGECACHE_SIZE, nByte);
40024 sqlite3StatusUp(SQLITE_STATUS_PAGECACHE_OVERFLOW, sz);
40025 sqlite3_mutex_leave(pcache1.mutex);
40026 }
40027 #endif
40028 sqlite3MemdebugSetType(p, MEMTYPE_PCACHE);
40029 }
@@ -39857,11 +40037,11 @@
40037 int nFreed = 0;
40038 if( p==0 ) return 0;
40039 if( p>=pcache1.pStart && p<pcache1.pEnd ){
40040 PgFreeslot *pSlot;
40041 sqlite3_mutex_enter(pcache1.mutex);
40042 sqlite3StatusDown(SQLITE_STATUS_PAGECACHE_USED, 1);
40043 pSlot = (PgFreeslot*)p;
40044 pSlot->pNext = pcache1.pFree;
40045 pcache1.pFree = pSlot;
40046 pcache1.nFreeSlot++;
40047 pcache1.bUnderPressure = pcache1.nFreeSlot<pcache1.nReserve;
@@ -39871,11 +40051,11 @@
40051 assert( sqlite3MemdebugHasType(p, MEMTYPE_PCACHE) );
40052 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
40053 nFreed = sqlite3MallocSize(p);
40054 #ifndef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
40055 sqlite3_mutex_enter(pcache1.mutex);
40056 sqlite3StatusDown(SQLITE_STATUS_PAGECACHE_OVERFLOW, nFreed);
40057 sqlite3_mutex_leave(pcache1.mutex);
40058 #endif
40059 sqlite3_free(p);
40060 }
40061 return nFreed;
@@ -40607,10 +40787,18 @@
40787
40788 /*
40789 ** Return the size of the header on each page of this PCACHE implementation.
40790 */
40791 SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void){ return ROUND8(sizeof(PgHdr1)); }
40792
40793 /*
40794 ** Return the global mutex used by this PCACHE implementation. The
40795 ** sqlite3_status() routine needs access to this mutex.
40796 */
40797 SQLITE_PRIVATE sqlite3_mutex *sqlite3Pcache1Mutex(void){
40798 return pcache1.mutex;
40799 }
40800
40801 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
40802 /*
40803 ** This function is called to free superfluous dynamically allocated memory
40804 ** held by the pager system. Memory in use by any SQLite pager allocated
@@ -49380,13 +49568,14 @@
49568 if( pWal->exclusiveMode ) return;
49569 (void)sqlite3OsShmLock(pWal->pDbFd, lockIdx, 1,
49570 SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED);
49571 WALTRACE(("WAL%p: release SHARED-%s\n", pWal, walLockName(lockIdx)));
49572 }
49573 static int walLockExclusive(Wal *pWal, int lockIdx, int n, int fBlock){
49574 int rc;
49575 if( pWal->exclusiveMode ) return SQLITE_OK;
49576 if( fBlock ) sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_WAL_BLOCK, 0);
49577 rc = sqlite3OsShmLock(pWal->pDbFd, lockIdx, n,
49578 SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE);
49579 WALTRACE(("WAL%p: acquire EXCLUSIVE-%s cnt=%d %s\n", pWal,
49580 walLockName(lockIdx), n, rc ? "failed" : "ok"));
49581 VVA_ONLY( pWal->lockError = (u8)(rc!=SQLITE_OK && rc!=SQLITE_BUSY); )
@@ -49668,11 +49857,11 @@
49857 assert( WAL_ALL_BUT_WRITE==WAL_WRITE_LOCK+1 );
49858 assert( WAL_CKPT_LOCK==WAL_ALL_BUT_WRITE );
49859 assert( pWal->writeLock );
49860 iLock = WAL_ALL_BUT_WRITE + pWal->ckptLock;
49861 nLock = SQLITE_SHM_NLOCK - iLock;
49862 rc = walLockExclusive(pWal, iLock, nLock, 0);
49863 if( rc ){
49864 return rc;
49865 }
49866 WALTRACE(("WAL%p: recovery begin...\n", pWal));
49867
@@ -50202,11 +50391,11 @@
50391 int lockIdx, /* Offset of first byte to lock */
50392 int n /* Number of bytes to lock */
50393 ){
50394 int rc;
50395 do {
50396 rc = walLockExclusive(pWal, lockIdx, n, 0);
50397 }while( xBusy && rc==SQLITE_BUSY && xBusy(pBusyArg) );
50398 return rc;
50399 }
50400
50401 /*
@@ -50635,11 +50824,11 @@
50824 if( pWal->readOnly & WAL_SHM_RDONLY ){
50825 if( SQLITE_OK==(rc = walLockShared(pWal, WAL_WRITE_LOCK)) ){
50826 walUnlockShared(pWal, WAL_WRITE_LOCK);
50827 rc = SQLITE_READONLY_RECOVERY;
50828 }
50829 }else if( SQLITE_OK==(rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1, 1)) ){
50830 pWal->writeLock = 1;
50831 if( SQLITE_OK==(rc = walIndexPage(pWal, 0, &page0)) ){
50832 badHdr = walIndexTryHdr(pWal, pChanged);
50833 if( badHdr ){
50834 /* If the wal-index header is still malformed even while holding
@@ -50841,11 +51030,11 @@
51030 {
51031 if( (pWal->readOnly & WAL_SHM_RDONLY)==0
51032 && (mxReadMark<pWal->hdr.mxFrame || mxI==0)
51033 ){
51034 for(i=1; i<WAL_NREADER; i++){
51035 rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1, 0);
51036 if( rc==SQLITE_OK ){
51037 mxReadMark = pInfo->aReadMark[i] = pWal->hdr.mxFrame;
51038 mxI = i;
51039 walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1);
51040 break;
@@ -51097,11 +51286,11 @@
51286 }
51287
51288 /* Only one writer allowed at a time. Get the write lock. Return
51289 ** SQLITE_BUSY if unable.
51290 */
51291 rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1, 0);
51292 if( rc ){
51293 return rc;
51294 }
51295 pWal->writeLock = 1;
51296
@@ -51242,11 +51431,11 @@
51431 volatile WalCkptInfo *pInfo = walCkptInfo(pWal);
51432 assert( pInfo->nBackfill==pWal->hdr.mxFrame );
51433 if( pInfo->nBackfill>0 ){
51434 u32 salt1;
51435 sqlite3_randomness(4, &salt1);
51436 rc = walLockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1, 0);
51437 if( rc==SQLITE_OK ){
51438 /* If all readers are using WAL_READ_LOCK(0) (in other words if no
51439 ** readers are currently using the WAL), then the transactions
51440 ** frames will overwrite the start of the existing log. Update the
51441 ** wal-index header to reflect this.
@@ -51567,11 +51756,11 @@
51756 if( pWal->readOnly ) return SQLITE_READONLY;
51757 WALTRACE(("WAL%p: checkpoint begins\n", pWal));
51758
51759 /* IMPLEMENTATION-OF: R-62028-47212 All calls obtain an exclusive
51760 ** "checkpoint" lock on the database file. */
51761 rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1, 0);
51762 if( rc ){
51763 /* EVIDENCE-OF: R-10421-19736 If any other process is running a
51764 ** checkpoint operation at the same time, the lock cannot be obtained and
51765 ** SQLITE_BUSY is returned.
51766 ** EVIDENCE-OF: R-53820-33897 Even if there is a busy-handler configured,
@@ -52569,10 +52758,11 @@
52758
52759 /*
52760 ** Exit the recursive mutex on a Btree.
52761 */
52762 SQLITE_PRIVATE void sqlite3BtreeLeave(Btree *p){
52763 assert( sqlite3_mutex_held(p->db->mutex) );
52764 if( p->sharable ){
52765 assert( p->wantToLock>0 );
52766 p->wantToLock--;
52767 if( p->wantToLock==0 ){
52768 unlockBtreeMutex(p);
@@ -54747,12 +54937,12 @@
54937 /*
54938 ** The following asserts make sure that structures used by the btree are
54939 ** the right size. This is to guard against size changes that result
54940 ** when compiling on a different architecture.
54941 */
54942 assert( sizeof(i64)==8 );
54943 assert( sizeof(u64)==8 );
54944 assert( sizeof(u32)==4 );
54945 assert( sizeof(u16)==2 );
54946 assert( sizeof(Pgno)==4 );
54947
54948 pBt = sqlite3MallocZero( sizeof(*pBt) );
@@ -60210,11 +60400,12 @@
60400 ** the previous call, as the overflow cell data will have been
60401 ** copied either into the body of a database page or into the new
60402 ** pSpace buffer passed to the latter call to balance_nonroot().
60403 */
60404 u8 *pSpace = sqlite3PageMalloc(pCur->pBt->pageSize);
60405 rc = balance_nonroot(pParent, iIdx, pSpace, iPage==1,
60406 pCur->hints&BTREE_BULKLOAD);
60407 if( pFree ){
60408 /* If pFree is not NULL, it points to the pSpace buffer used
60409 ** by a previous call to balance_nonroot(). Its contents are
60410 ** now stored either on real database pages or within the
60411 ** new pSpace buffer, so it may be safely freed here. */
@@ -61873,17 +62064,26 @@
62064 pBt->btsFlags &= ~BTS_NO_WAL;
62065 return rc;
62066 }
62067
62068 /*
62069 ** set the mask of hint flags for cursor pCsr.
 
62070 */
62071 SQLITE_PRIVATE void sqlite3BtreeCursorHints(BtCursor *pCsr, unsigned int mask){
62072 assert( mask==BTREE_BULKLOAD || mask==BTREE_SEEK_EQ || mask==0 );
62073 pCsr->hints = mask;
62074 }
62075
62076 #ifdef SQLITE_DEBUG
62077 /*
62078 ** Return true if the cursor has a hint specified. This routine is
62079 ** only used from within assert() statements
62080 */
62081 SQLITE_PRIVATE int sqlite3BtreeCursorHasHint(BtCursor *pCsr, unsigned int mask){
62082 return (pCsr->hints & mask)!=0;
62083 }
62084 #endif
62085
62086 /*
62087 ** Return true if the given Btree is read-only.
62088 */
62089 SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *p){
@@ -63773,11 +63973,11 @@
63973 ** by calling sqlite3ValueNew().
63974 **
63975 ** Otherwise, if the second argument is non-zero, then this function is
63976 ** being called indirectly by sqlite3Stat4ProbeSetValue(). If it has not
63977 ** already been allocated, allocate the UnpackedRecord structure that
63978 ** that function will return to its caller here. Then return a pointer to
63979 ** an sqlite3_value within the UnpackedRecord.a[] array.
63980 */
63981 static sqlite3_value *valueNew(sqlite3 *db, struct ValueNewStat4Ctx *p){
63982 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
63983 if( p ){
@@ -63817,10 +64017,117 @@
64017 UNUSED_PARAMETER(p);
64018 #endif /* defined(SQLITE_ENABLE_STAT3_OR_STAT4) */
64019 return sqlite3ValueNew(db);
64020 }
64021
64022 /*
64023 ** The expression object indicated by the second argument is guaranteed
64024 ** to be a scalar SQL function. If
64025 **
64026 ** * all function arguments are SQL literals,
64027 ** * the SQLITE_FUNC_CONSTANT function flag is set, and
64028 ** * the SQLITE_FUNC_NEEDCOLL function flag is not set,
64029 **
64030 ** then this routine attempts to invoke the SQL function. Assuming no
64031 ** error occurs, output parameter (*ppVal) is set to point to a value
64032 ** object containing the result before returning SQLITE_OK.
64033 **
64034 ** Affinity aff is applied to the result of the function before returning.
64035 ** If the result is a text value, the sqlite3_value object uses encoding
64036 ** enc.
64037 **
64038 ** If the conditions above are not met, this function returns SQLITE_OK
64039 ** and sets (*ppVal) to NULL. Or, if an error occurs, (*ppVal) is set to
64040 ** NULL and an SQLite error code returned.
64041 */
64042 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
64043 static int valueFromFunction(
64044 sqlite3 *db, /* The database connection */
64045 Expr *p, /* The expression to evaluate */
64046 u8 enc, /* Encoding to use */
64047 u8 aff, /* Affinity to use */
64048 sqlite3_value **ppVal, /* Write the new value here */
64049 struct ValueNewStat4Ctx *pCtx /* Second argument for valueNew() */
64050 ){
64051 sqlite3_context ctx; /* Context object for function invocation */
64052 sqlite3_value **apVal = 0; /* Function arguments */
64053 int nVal = 0; /* Size of apVal[] array */
64054 FuncDef *pFunc = 0; /* Function definition */
64055 sqlite3_value *pVal = 0; /* New value */
64056 int rc = SQLITE_OK; /* Return code */
64057 int nName; /* Size of function name in bytes */
64058 ExprList *pList = 0; /* Function arguments */
64059 int i; /* Iterator variable */
64060
64061 assert( pCtx!=0 );
64062 assert( (p->flags & EP_TokenOnly)==0 );
64063 pList = p->x.pList;
64064 if( pList ) nVal = pList->nExpr;
64065 nName = sqlite3Strlen30(p->u.zToken);
64066 pFunc = sqlite3FindFunction(db, p->u.zToken, nName, nVal, enc, 0);
64067 assert( pFunc );
64068 if( (pFunc->funcFlags & SQLITE_FUNC_CONSTANT)==0
64069 || (pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL)
64070 ){
64071 return SQLITE_OK;
64072 }
64073
64074 if( pList ){
64075 apVal = (sqlite3_value**)sqlite3DbMallocZero(db, sizeof(apVal[0]) * nVal);
64076 if( apVal==0 ){
64077 rc = SQLITE_NOMEM;
64078 goto value_from_function_out;
64079 }
64080 for(i=0; i<nVal; i++){
64081 rc = sqlite3ValueFromExpr(db, pList->a[i].pExpr, enc, aff, &apVal[i]);
64082 if( apVal[i]==0 || rc!=SQLITE_OK ) goto value_from_function_out;
64083 }
64084 }
64085
64086 pVal = valueNew(db, pCtx);
64087 if( pVal==0 ){
64088 rc = SQLITE_NOMEM;
64089 goto value_from_function_out;
64090 }
64091
64092 assert( pCtx->pParse->rc==SQLITE_OK );
64093 memset(&ctx, 0, sizeof(ctx));
64094 ctx.pOut = pVal;
64095 ctx.pFunc = pFunc;
64096 pFunc->xFunc(&ctx, nVal, apVal);
64097 if( ctx.isError ){
64098 rc = ctx.isError;
64099 sqlite3ErrorMsg(pCtx->pParse, "%s", sqlite3_value_text(pVal));
64100 }else{
64101 sqlite3ValueApplyAffinity(pVal, aff, SQLITE_UTF8);
64102 assert( rc==SQLITE_OK );
64103 rc = sqlite3VdbeChangeEncoding(pVal, enc);
64104 if( rc==SQLITE_OK && sqlite3VdbeMemTooBig(pVal) ){
64105 rc = SQLITE_TOOBIG;
64106 pCtx->pParse->nErr++;
64107 }
64108 }
64109 pCtx->pParse->rc = rc;
64110
64111 value_from_function_out:
64112 if( rc!=SQLITE_OK ){
64113 pVal = 0;
64114 }
64115 if( apVal ){
64116 for(i=0; i<nVal; i++){
64117 sqlite3ValueFree(apVal[i]);
64118 }
64119 sqlite3DbFree(db, apVal);
64120 }
64121
64122 *ppVal = pVal;
64123 return rc;
64124 }
64125 #else
64126 # define valueFromFunction(a,b,c,d,e,f) SQLITE_OK
64127 #endif /* defined(SQLITE_ENABLE_STAT3_OR_STAT4) */
64128
64129 /*
64130 ** Extract a value from the supplied expression in the manner described
64131 ** above sqlite3ValueFromExpr(). Allocate the sqlite3_value object
64132 ** using valueNew().
64133 **
@@ -63848,10 +64155,16 @@
64155 *ppVal = 0;
64156 return SQLITE_OK;
64157 }
64158 while( (op = pExpr->op)==TK_UPLUS ) pExpr = pExpr->pLeft;
64159 if( NEVER(op==TK_REGISTER) ) op = pExpr->op2;
64160
64161 /* Compressed expressions only appear when parsing the DEFAULT clause
64162 ** on a table column definition, and hence only when pCtx==0. This
64163 ** check ensures that an EP_TokenOnly expression is never passed down
64164 ** into valueFromFunction(). */
64165 assert( (pExpr->flags & EP_TokenOnly)==0 || pCtx==0 );
64166
64167 if( op==TK_CAST ){
64168 u8 aff = sqlite3AffinityType(pExpr->u.zToken,0);
64169 rc = valueFromExpr(db, pExpr->pLeft, enc, aff, ppVal, pCtx);
64170 testcase( rc!=SQLITE_OK );
@@ -63924,10 +64237,16 @@
64237 assert( zVal[nVal]=='\'' );
64238 sqlite3VdbeMemSetStr(pVal, sqlite3HexToBlob(db, zVal, nVal), nVal/2,
64239 0, SQLITE_DYNAMIC);
64240 }
64241 #endif
64242
64243 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
64244 else if( op==TK_FUNCTION && pCtx!=0 ){
64245 rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx);
64246 }
64247 #endif
64248
64249 *ppVal = pVal;
64250 return rc;
64251
64252 no_mem:
@@ -65377,11 +65696,11 @@
65696 break;
65697 }
65698 #ifndef SQLITE_OMIT_VIRTUALTABLE
65699 case P4_VTAB: {
65700 sqlite3_vtab *pVtab = pOp->p4.pVtab->pVtab;
65701 sqlite3_snprintf(nTemp, zTemp, "vtab:%p", pVtab);
65702 break;
65703 }
65704 #endif
65705 case P4_INTARRAY: {
65706 sqlite3_snprintf(nTemp, zTemp, "intarray");
@@ -66041,13 +66360,13 @@
66360 }
66361 #ifndef SQLITE_OMIT_VIRTUALTABLE
66362 else if( pCx->pVtabCursor ){
66363 sqlite3_vtab_cursor *pVtabCursor = pCx->pVtabCursor;
66364 const sqlite3_module *pModule = pVtabCursor->pVtab->pModule;
66365 assert( pVtabCursor->pVtab->nRef>0 );
66366 pVtabCursor->pVtab->nRef--;
66367 pModule->xClose(pVtabCursor);
 
66368 }
66369 #endif
66370 }
66371
66372 /*
@@ -66402,11 +66721,11 @@
66721
66722 /* Delete the master journal file. This commits the transaction. After
66723 ** doing this the directory is synced again before any individual
66724 ** transaction files are deleted.
66725 */
66726 rc = sqlite3OsDelete(pVfs, zMaster, needSync);
66727 sqlite3DbFree(db, zMaster);
66728 zMaster = 0;
66729 if( rc ){
66730 return rc;
66731 }
@@ -68615,10 +68934,14 @@
68934 }
68935 SQLITE_API const void *sqlite3_value_text16le(sqlite3_value *pVal){
68936 return sqlite3ValueText(pVal, SQLITE_UTF16LE);
68937 }
68938 #endif /* SQLITE_OMIT_UTF16 */
68939 /* EVIDENCE-OF: R-12793-43283 Every value in SQLite has one of five
68940 ** fundamental datatypes: 64-bit signed integer 64-bit IEEE floating
68941 ** point number string BLOB NULL
68942 */
68943 SQLITE_API int sqlite3_value_type(sqlite3_value* pVal){
68944 static const u8 aType[] = {
68945 SQLITE_BLOB, /* 0x00 */
68946 SQLITE_NULL, /* 0x01 */
68947 SQLITE_TEXT, /* 0x02 */
@@ -68811,11 +69134,11 @@
69134 }
69135 SQLITE_API void sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){
69136 pCtx->isError = errCode;
69137 pCtx->fErrorOrAux = 1;
69138 #ifdef SQLITE_DEBUG
69139 if( pCtx->pVdbe ) pCtx->pVdbe->rcApp = errCode;
69140 #endif
69141 if( pCtx->pOut->flags & MEM_Null ){
69142 sqlite3VdbeMemSetStr(pCtx->pOut, sqlite3ErrStr(errCode), -1,
69143 SQLITE_UTF8, SQLITE_STATIC);
69144 }
@@ -69074,20 +69397,30 @@
69397 assert( p && p->pFunc );
69398 return p->pOut->db;
69399 }
69400
69401 /*
69402 ** Return the current time for a statement. If the current time
69403 ** is requested more than once within the same run of a single prepared
69404 ** statement, the exact same time is returned for each invocation regardless
69405 ** of the amount of time that elapses between invocations. In other words,
69406 ** the time returned is always the time of the first call.
69407 */
69408 SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context *p){
 
69409 int rc;
69410 #ifndef SQLITE_ENABLE_STAT3_OR_STAT4
69411 sqlite3_int64 *piTime = &p->pVdbe->iCurrentTime;
69412 assert( p->pVdbe!=0 );
69413 #else
69414 sqlite3_int64 iTime = 0;
69415 sqlite3_int64 *piTime = p->pVdbe!=0 ? &p->pVdbe->iCurrentTime : &iTime;
69416 #endif
69417 if( *piTime==0 ){
69418 rc = sqlite3OsCurrentTimeInt64(p->pOut->db->pVfs, piTime);
69419 if( rc ) *piTime = 0;
69420 }
69421 return *piTime;
69422 }
69423
69424 /*
69425 ** The following is the implementation of an SQL function that always
69426 ** fails with an error message stating that the function is used in the
@@ -69153,10 +69486,15 @@
69486 */
69487 SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
69488 AuxData *pAuxData;
69489
69490 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
69491 #if SQLITE_ENABLE_STAT3_OR_STAT4
69492 if( pCtx->pVdbe==0 ) return 0;
69493 #else
69494 assert( pCtx->pVdbe!=0 );
69495 #endif
69496 for(pAuxData=pCtx->pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){
69497 if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break;
69498 }
69499
69500 return (pAuxData ? pAuxData->pAux : 0);
@@ -69176,10 +69514,15 @@
69514 AuxData *pAuxData;
69515 Vdbe *pVdbe = pCtx->pVdbe;
69516
69517 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
69518 if( iArg<0 ) goto failed;
69519 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
69520 if( pVdbe==0 ) goto failed;
69521 #else
69522 assert( pVdbe!=0 );
69523 #endif
69524
69525 for(pAuxData=pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){
69526 if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break;
69527 }
69528 if( pAuxData==0 ){
@@ -71290,11 +71633,11 @@
71633
71634 /* Opcode: String8 * P2 * P4 *
71635 ** Synopsis: r[P2]='P4'
71636 **
71637 ** P4 points to a nul terminated UTF-8 string. This opcode is transformed
71638 ** into a String opcode before it is executed for the first time. During
71639 ** this transformation, the length of string P4 is computed and stored
71640 ** as the P1 parameter.
71641 */
71642 case OP_String8: { /* same as TK_STRING, out2-prerelease */
71643 assert( pOp->p4.z!=0 );
@@ -71322,22 +71665,34 @@
71665 goto too_big;
71666 }
71667 /* Fall through to the next case, OP_String */
71668 }
71669
71670 /* Opcode: String P1 P2 P3 P4 P5
71671 ** Synopsis: r[P2]='P4' (len=P1)
71672 **
71673 ** The string value P4 of length P1 (bytes) is stored in register P2.
71674 **
71675 ** If P5!=0 and the content of register P3 is greater than zero, then
71676 ** the datatype of the register P2 is converted to BLOB. The content is
71677 ** the same sequence of bytes, it is merely interpreted as a BLOB instead
71678 ** of a string, as if it had been CAST.
71679 */
71680 case OP_String: { /* out2-prerelease */
71681 assert( pOp->p4.z!=0 );
71682 pOut->flags = MEM_Str|MEM_Static|MEM_Term;
71683 pOut->z = pOp->p4.z;
71684 pOut->n = pOp->p1;
71685 pOut->enc = encoding;
71686 UPDATE_MAX_BLOBSIZE(pOut);
71687 if( pOp->p5 ){
71688 assert( pOp->p3>0 );
71689 assert( pOp->p3<=(p->nMem-p->nCursor) );
71690 pIn3 = &aMem[pOp->p3];
71691 assert( pIn3->flags & MEM_Int );
71692 if( pIn3->u.i ) pOut->flags = MEM_Blob|MEM_Static|MEM_Term;
71693 }
71694 break;
71695 }
71696
71697 /* Opcode: Null P1 P2 P3 * *
71698 ** Synopsis: r[P2..P3]=NULL
@@ -71780,11 +72135,11 @@
72135 ** max() aggregate will set to 1 if the current row is not the minimum or
72136 ** maximum. The P1 register is initialized to 0 by this instruction.
72137 **
72138 ** The interface used by the implementation of the aforementioned functions
72139 ** to retrieve the collation sequence set by this opcode is not available
72140 ** publicly. Only built-in functions have access to this feature.
72141 */
72142 case OP_CollSeq: {
72143 assert( pOp->p4type==P4_COLLSEQ );
72144 if( pOp->p1 ){
72145 sqlite3VdbeMemSetInt64(&aMem[pOp->p1], 0);
@@ -73325,11 +73680,16 @@
73680 ** the value of this counter needs to be restored too. */
73681 p->nStmtDefCons = db->nDeferredCons;
73682 p->nStmtDefImmCons = db->nDeferredImmCons;
73683 }
73684
73685 /* Gather the schema version number for checking:
73686 ** IMPLEMENTATION-OF: R-32195-19465 The schema version is used by SQLite
73687 ** each time a query is executed to ensure that the internal cache of the
73688 ** schema used when compiling the SQL query matches the schema of the
73689 ** database against which the compiled query is actually executed.
73690 */
73691 sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta);
73692 iGen = db->aDb[pOp->p1].pSchema->iGeneration;
73693 }else{
73694 iGen = iMeta = 0;
73695 }
@@ -73493,35 +73853,33 @@
73853 ** cursors or a single read/write cursor but not both.
73854 **
73855 ** See also OpenRead.
73856 */
73857 case OP_ReopenIdx: {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73858 int nField;
73859 KeyInfo *pKeyInfo;
73860 int p2;
73861 int iDb;
73862 int wrFlag;
73863 Btree *pX;
73864 VdbeCursor *pCur;
73865 Db *pDb;
73866
73867 assert( pOp->p5==0 || pOp->p5==OPFLAG_SEEKEQ );
73868 assert( pOp->p4type==P4_KEYINFO );
73869 pCur = p->apCsr[pOp->p1];
73870 if( pCur && pCur->pgnoRoot==(u32)pOp->p2 ){
73871 assert( pCur->iDb==pOp->p3 ); /* Guaranteed by the code generator */
73872 goto open_cursor_set_hints;
73873 }
73874 /* If the cursor is not currently open or is open on a different
73875 ** index, then fall through into OP_OpenRead to force a reopen */
73876 case OP_OpenRead:
73877 case OP_OpenWrite:
73878
73879 assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR|OPFLAG_SEEKEQ))==pOp->p5 );
73880 assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 || pOp->p5==OPFLAG_SEEKEQ );
73881 assert( p->bIsReader );
73882 assert( pOp->opcode==OP_OpenRead || pOp->opcode==OP_ReopenIdx
73883 || p->readOnly==0 );
73884
73885 if( p->expired ){
@@ -73580,18 +73938,21 @@
73938 pCur->nullRow = 1;
73939 pCur->isOrdered = 1;
73940 pCur->pgnoRoot = p2;
73941 rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->pCursor);
73942 pCur->pKeyInfo = pKeyInfo;
 
 
 
73943 /* Set the VdbeCursor.isTable variable. Previous versions of
73944 ** SQLite used to check if the root-page flags were sane at this point
73945 ** and report database corruption if they were not, but this check has
73946 ** since moved into the btree layer. */
73947 pCur->isTable = pOp->p4type!=P4_KEYINFO;
73948
73949 open_cursor_set_hints:
73950 assert( OPFLAG_BULKCSR==BTREE_BULKLOAD );
73951 assert( OPFLAG_SEEKEQ==BTREE_SEEK_EQ );
73952 sqlite3BtreeCursorHints(pCur->pCursor,
73953 (pOp->p5 & (OPFLAG_BULKCSR|OPFLAG_SEEKEQ)));
73954 break;
73955 }
73956
73957 /* Opcode: OpenEphemeral P1 P2 * P4 P5
73958 ** Synopsis: nColumn=P2
@@ -73848,10 +74209,26 @@
74209 oc = pOp->opcode;
74210 pC->nullRow = 0;
74211 #ifdef SQLITE_DEBUG
74212 pC->seekOp = pOp->opcode;
74213 #endif
74214
74215 /* For a cursor with the BTREE_SEEK_EQ hint, only the OP_SeekGE and
74216 ** OP_SeekLE opcodes are allowed, and these must be immediately followed
74217 ** by an OP_IdxGT or OP_IdxLT opcode, respectively, with the same key.
74218 */
74219 #ifdef SQLITE_DEBUG
74220 if( sqlite3BtreeCursorHasHint(pC->pCursor, BTREE_SEEK_EQ) ){
74221 assert( pOp->opcode==OP_SeekGE || pOp->opcode==OP_SeekLE );
74222 assert( pOp[1].opcode==OP_IdxLT || pOp[1].opcode==OP_IdxGT );
74223 assert( pOp[1].p1==pOp[0].p1 );
74224 assert( pOp[1].p2==pOp[0].p2 );
74225 assert( pOp[1].p3==pOp[0].p3 );
74226 assert( pOp[1].p4.i==pOp[0].p4.i );
74227 }
74228 #endif
74229
74230 if( pC->isTable ){
74231 /* The input value in P3 might be of any type: integer, real, string,
74232 ** blob, or NULL. But it needs to be an integer before we can do
74233 ** the seek, so convert it. */
74234 pIn3 = &aMem[pOp->p3];
@@ -75187,34 +75564,19 @@
75564 **
75565 ** See also: Clear
75566 */
75567 case OP_Destroy: { /* out2-prerelease */
75568 int iMoved;
 
 
75569 int iDb;
75570
75571 assert( p->readOnly==0 );
 
 
 
 
 
 
 
 
 
 
 
 
75572 pOut->flags = MEM_Null;
75573 if( db->nVdbeRead > db->nVDestroy+1 ){
75574 rc = SQLITE_LOCKED;
75575 p->errorAction = OE_Abort;
75576 }else{
75577 iDb = pOp->p3;
 
75578 assert( DbMaskTest(p->btreeMask, iDb) );
75579 iMoved = 0; /* Not needed. Only to silence a warning. */
75580 rc = sqlite3BtreeDropTable(db->aDb[iDb].pBt, pOp->p1, &iMoved);
75581 pOut->flags = MEM_Int;
75582 pOut->u.i = iMoved;
@@ -75843,14 +76205,16 @@
76205 #endif /* SQLITE_OMIT_AUTOINCREMENT */
76206
76207 /* Opcode: IfPos P1 P2 * * *
76208 ** Synopsis: if r[P1]>0 goto P2
76209 **
76210 ** Register P1 must contain an integer.
76211 ** If the value of register P1 is 1 or greater, jump to P2 and
76212 ** add the literal value P3 to register P1.
76213 **
76214 ** If the initial value of register P1 is less than 1, then the
76215 ** value is unchanged and control passes through to the next instruction.
76216 */
76217 case OP_IfPos: { /* jump, in1 */
76218 pIn1 = &aMem[pOp->p1];
76219 assert( pIn1->flags&MEM_Int );
76220 VdbeBranchTaken( pIn1->u.i>0, 2);
@@ -75875,27 +76239,63 @@
76239 pc = pOp->p2 - 1;
76240 }
76241 break;
76242 }
76243
76244 /* Opcode: IfNotZero P1 P2 P3 * *
76245 ** Synopsis: if r[P1]!=0 then r[P1]+=P3, goto P2
76246 **
76247 ** Register P1 must contain an integer. If the content of register P1 is
76248 ** initially nonzero, then add P3 to P1 and jump to P2. If register P1 is
76249 ** initially zero, leave it unchanged and fall through.
76250 */
76251 case OP_IfNotZero: { /* jump, in1 */
76252 pIn1 = &aMem[pOp->p1];
76253 assert( pIn1->flags&MEM_Int );
76254 VdbeBranchTaken(pIn1->u.i<0, 2);
76255 if( pIn1->u.i ){
76256 pIn1->u.i += pOp->p3;
76257 pc = pOp->p2 - 1;
76258 }
76259 break;
76260 }
76261
76262 /* Opcode: DecrJumpZero P1 P2 * * *
76263 ** Synopsis: if (--r[P1])==0 goto P2
76264 **
76265 ** Register P1 must hold an integer. Decrement the value in register P1
76266 ** then jump to P2 if the new value is exactly zero.
76267 */
76268 case OP_DecrJumpZero: { /* jump, in1 */
76269 pIn1 = &aMem[pOp->p1];
76270 assert( pIn1->flags&MEM_Int );
76271 pIn1->u.i--;
76272 VdbeBranchTaken(pIn1->u.i==0, 2);
76273 if( pIn1->u.i==0 ){
76274 pc = pOp->p2 - 1;
76275 }
76276 break;
76277 }
76278
76279
76280 /* Opcode: JumpZeroIncr P1 P2 * * *
76281 ** Synopsis: if (r[P1]++)==0 ) goto P2
76282 **
76283 ** The register P1 must contain an integer. If register P1 is initially
76284 ** zero, then jump to P2. Increment register P1 regardless of whether or
76285 ** not the jump is taken.
76286 */
76287 case OP_JumpZeroIncr: { /* jump, in1 */
76288 pIn1 = &aMem[pOp->p1];
76289 assert( pIn1->flags&MEM_Int );
76290 VdbeBranchTaken(pIn1->u.i==0, 2);
76291 if( (pIn1->u.i++)==0 ){
76292 pc = pOp->p2 - 1;
76293 }
76294 break;
76295 }
76296
76297 /* Opcode: AggStep * P2 P3 P4 P5
76298 ** Synopsis: accum=r[P3] step(r[P2@P5])
76299 **
76300 ** Execute the step function for an aggregate. The
76301 ** function has P5 arguments. P4 is a pointer to the FuncDef
@@ -76229,17 +76629,33 @@
76629 break;
76630 }
76631 #endif /* SQLITE_OMIT_VIRTUALTABLE */
76632
76633 #ifndef SQLITE_OMIT_VIRTUALTABLE
76634 /* Opcode: VCreate P1 P2 * * *
76635 **
76636 ** P2 is a register that holds the name of a virtual table in database
76637 ** P1. Call the xCreate method for that table.
76638 */
76639 case OP_VCreate: {
76640 Mem sMem; /* For storing the record being decoded */
76641 const char *zTab; /* Name of the virtual table */
76642
76643 memset(&sMem, 0, sizeof(sMem));
76644 sMem.db = db;
76645 /* Because P2 is always a static string, it is impossible for the
76646 ** sqlite3VdbeMemCopy() to fail */
76647 assert( (aMem[pOp->p2].flags & MEM_Str)!=0 );
76648 assert( (aMem[pOp->p2].flags & MEM_Static)!=0 );
76649 rc = sqlite3VdbeMemCopy(&sMem, &aMem[pOp->p2]);
76650 assert( rc==SQLITE_OK );
76651 zTab = (const char*)sqlite3_value_text(&sMem);
76652 assert( zTab || db->mallocFailed );
76653 if( zTab ){
76654 rc = sqlite3VtabCallCreate(db, pOp->p1, zTab, &p->zErrMsg);
76655 }
76656 sqlite3VdbeMemRelease(&sMem);
76657 break;
76658 }
76659 #endif /* SQLITE_OMIT_VIRTUALTABLE */
76660
76661 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -76247,13 +76663,13 @@
76663 **
76664 ** P4 is the name of a virtual table in database P1. Call the xDestroy method
76665 ** of that table.
76666 */
76667 case OP_VDestroy: {
76668 db->nVDestroy++;
76669 rc = sqlite3VtabCallDestroy(db, pOp->p1, pOp->p4.z);
76670 db->nVDestroy--;
76671 break;
76672 }
76673 #endif /* SQLITE_OMIT_VIRTUALTABLE */
76674
76675 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -76265,18 +76681,21 @@
76681 */
76682 case OP_VOpen: {
76683 VdbeCursor *pCur;
76684 sqlite3_vtab_cursor *pVtabCursor;
76685 sqlite3_vtab *pVtab;
76686 const sqlite3_module *pModule;
76687
76688 assert( p->bIsReader );
76689 pCur = 0;
76690 pVtabCursor = 0;
76691 pVtab = pOp->p4.pVtab->pVtab;
76692 if( pVtab==0 || NEVER(pVtab->pModule==0) ){
76693 rc = SQLITE_LOCKED;
76694 break;
76695 }
76696 pModule = pVtab->pModule;
76697 rc = pModule->xOpen(pVtab, &pVtabCursor);
76698 sqlite3VtabImportErrmsg(p, pVtab);
76699 if( SQLITE_OK==rc ){
76700 /* Initialize sqlite3_vtab_cursor base class */
76701 pVtabCursor->pVtab = pVtab;
@@ -76283,10 +76702,11 @@
76702
76703 /* Initialize vdbe cursor object */
76704 pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
76705 if( pCur ){
76706 pCur->pVtabCursor = pVtabCursor;
76707 pVtab->nRef++;
76708 }else{
76709 db->mallocFailed = 1;
76710 pModule->xClose(pVtabCursor);
76711 }
76712 }
@@ -76348,13 +76768,11 @@
76768 apArg = p->apArg;
76769 for(i = 0; i<nArg; i++){
76770 apArg[i] = &pArgc[i+1];
76771 }
76772
 
76773 rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg);
 
76774 sqlite3VtabImportErrmsg(p, pVtab);
76775 if( rc==SQLITE_OK ){
76776 res = pModule->xEof(pVtabCursor);
76777 }
76778 VdbeBranchTaken(res!=0,2);
@@ -76440,13 +76858,11 @@
76858 ** underlying implementation to return an error if one occurs during
76859 ** xNext(). Instead, if an error occurs, true is returned (indicating that
76860 ** data is available) and the error code returned when xColumn or
76861 ** some other method is next invoked on the save virtual table cursor.
76862 */
 
76863 rc = pModule->xNext(pCur->pVtabCursor);
 
76864 sqlite3VtabImportErrmsg(p, pVtab);
76865 if( rc==SQLITE_OK ){
76866 res = pModule->xEof(pCur->pVtabCursor);
76867 }
76868 VdbeBranchTaken(!res,2);
@@ -76517,11 +76933,11 @@
76933 ** P5 is the error actions (OE_Replace, OE_Fail, OE_Ignore, etc) to
76934 ** apply in the case of a constraint failure on an insert or update.
76935 */
76936 case OP_VUpdate: {
76937 sqlite3_vtab *pVtab;
76938 const sqlite3_module *pModule;
76939 int nArg;
76940 int i;
76941 sqlite_int64 rowid;
76942 Mem **apArg;
76943 Mem *pX;
@@ -76529,11 +76945,15 @@
76945 assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback
76946 || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace
76947 );
76948 assert( p->readOnly==0 );
76949 pVtab = pOp->p4.pVtab->pVtab;
76950 if( pVtab==0 || NEVER(pVtab->pModule==0) ){
76951 rc = SQLITE_LOCKED;
76952 break;
76953 }
76954 pModule = pVtab->pModule;
76955 nArg = pOp->p2;
76956 assert( pOp->p4type==P4_VTAB );
76957 if( ALWAYS(pModule->xUpdate) ){
76958 u8 vtabOnConflict = db->vtabOnConflict;
76959 apArg = p->apArg;
@@ -78399,10 +78819,11 @@
78819 sqlite3 *db, /* Database handle doing sort */
78820 i64 nExtend, /* Attempt to extend file to this size */
78821 sqlite3_file **ppFd
78822 ){
78823 int rc;
78824 if( sqlite3FaultSim(202) ) return SQLITE_IOERR_ACCESS;
78825 rc = sqlite3OsOpenMalloc(db->pVfs, 0, ppFd,
78826 SQLITE_OPEN_TEMP_JOURNAL |
78827 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE |
78828 SQLITE_OPEN_EXCLUSIVE | SQLITE_OPEN_DELETEONCLOSE, &rc
78829 );
@@ -81990,14 +82411,15 @@
82411 ** and the pExpr parameter is returned unchanged.
82412 */
82413 SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(
82414 Parse *pParse, /* Parsing context */
82415 Expr *pExpr, /* Add the "COLLATE" clause to this expression */
82416 const Token *pCollName, /* Name of collating sequence */
82417 int dequote /* True to dequote pCollName */
82418 ){
82419 if( pCollName->n>0 ){
82420 Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, dequote);
82421 if( pNew ){
82422 pNew->pLeft = pExpr;
82423 pNew->flags |= EP_Collate|EP_Skip;
82424 pExpr = pNew;
82425 }
@@ -82007,11 +82429,11 @@
82429 SQLITE_PRIVATE Expr *sqlite3ExprAddCollateString(Parse *pParse, Expr *pExpr, const char *zC){
82430 Token s;
82431 assert( zC!=0 );
82432 s.z = zC;
82433 s.n = sqlite3Strlen30(s.z);
82434 return sqlite3ExprAddCollateToken(pParse, pExpr, &s, 0);
82435 }
82436
82437 /*
82438 ** Skip over any TK_COLLATE or TK_AS operators and any unlikely()
82439 ** or likelihood() function at the root of an expression.
@@ -82317,10 +82739,11 @@
82739 **
82740 ** Also propagate all EP_Propagate flags from the Expr.x.pList into
82741 ** Expr.flags.
82742 */
82743 SQLITE_PRIVATE void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){
82744 if( pParse->nErr ) return;
82745 exprSetHeight(p);
82746 sqlite3ExprCheckHeight(pParse, p->nHeight);
82747 }
82748
82749 /*
@@ -87031,11 +87454,14 @@
87454 /* Ensure the default expression is something that sqlite3ValueFromExpr()
87455 ** can handle (i.e. not CURRENT_TIME etc.)
87456 */
87457 if( pDflt ){
87458 sqlite3_value *pVal = 0;
87459 int rc;
87460 rc = sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal);
87461 assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
87462 if( rc!=SQLITE_OK ){
87463 db->mallocFailed = 1;
87464 return;
87465 }
87466 if( !pVal ){
87467 sqlite3ErrorMsg(pParse, "Cannot add a column with non-constant default");
@@ -93094,10 +93520,11 @@
93520 }
93521 if( pIdx->onError==OE_Default ){
93522 pIdx->onError = pIndex->onError;
93523 }
93524 }
93525 pRet = pIdx;
93526 goto exit_create_index;
93527 }
93528 }
93529 }
93530
@@ -95553,11 +95980,13 @@
95980
95981 /*
95982 ** Return the collating function associated with a function.
95983 */
95984 static CollSeq *sqlite3GetFuncCollSeq(sqlite3_context *context){
95985 VdbeOp *pOp;
95986 assert( context->pVdbe!=0 );
95987 pOp = &context->pVdbe->aOp[context->iOp-1];
95988 assert( pOp->opcode==OP_CollSeq );
95989 assert( pOp->p4type==P4_COLLSEQ );
95990 return pOp->p4.pColl;
95991 }
95992
@@ -97181,10 +97610,15 @@
97610 ** pExpr points to an expression which implements a function. If
97611 ** it is appropriate to apply the LIKE optimization to that function
97612 ** then set aWc[0] through aWc[2] to the wildcard characters and
97613 ** return TRUE. If the function is not a LIKE-style function then
97614 ** return FALSE.
97615 **
97616 ** *pIsNocase is set to true if uppercase and lowercase are equivalent for
97617 ** the function (default for LIKE). If the function makes the distinction
97618 ** between uppercase and lowercase (as does GLOB) then *pIsNocase is set to
97619 ** false.
97620 */
97621 SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
97622 FuncDef *pDef;
97623 if( pExpr->op!=TK_FUNCTION
97624 || !pExpr->x.pList
@@ -102972,10 +103406,21 @@
103406 }
103407
103408 /* Send an SQLITE_FCNTL_PRAGMA file-control to the underlying VFS
103409 ** connection. If it returns SQLITE_OK, then assume that the VFS
103410 ** handled the pragma and generate a no-op prepared statement.
103411 **
103412 ** IMPLEMENTATION-OF: R-12238-55120 Whenever a PRAGMA statement is parsed,
103413 ** an SQLITE_FCNTL_PRAGMA file control is sent to the open sqlite3_file
103414 ** object corresponding to the database file to which the pragma
103415 ** statement refers.
103416 **
103417 ** IMPLEMENTATION-OF: R-29875-31678 The argument to the SQLITE_FCNTL_PRAGMA
103418 ** file control is an array of pointers to strings (char**) in which the
103419 ** second element of the array is the name of the pragma and the third
103420 ** element is the argument to the pragma or NULL if the pragma has no
103421 ** argument.
103422 */
103423 aFcntl[0] = 0;
103424 aFcntl[1] = zLeft;
103425 aFcntl[2] = zRight;
103426 aFcntl[3] = 0;
@@ -103732,34 +104177,46 @@
104177 Index *pIdx;
104178 Table *pTab;
104179 pIdx = sqlite3FindIndex(db, zRight, zDb);
104180 if( pIdx ){
104181 int i;
104182 int mx;
104183 if( pPragma->iArg ){
104184 /* PRAGMA index_xinfo (newer version with more rows and columns) */
104185 mx = pIdx->nColumn;
104186 pParse->nMem = 6;
104187 }else{
104188 /* PRAGMA index_info (legacy version) */
104189 mx = pIdx->nKeyCol;
104190 pParse->nMem = 3;
104191 }
104192 pTab = pIdx->pTable;
104193 sqlite3VdbeSetNumCols(v, pParse->nMem);
 
104194 sqlite3CodeVerifySchema(pParse, iDb);
104195 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", SQLITE_STATIC);
104196 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", SQLITE_STATIC);
104197 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", SQLITE_STATIC);
104198 if( pPragma->iArg ){
104199 sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "desc", SQLITE_STATIC);
104200 sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "coll", SQLITE_STATIC);
104201 sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "key", SQLITE_STATIC);
104202 }
104203 for(i=0; i<mx; i++){
104204 i16 cnum = pIdx->aiColumn[i];
104205 sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
104206 sqlite3VdbeAddOp2(v, OP_Integer, cnum, 2);
104207 if( cnum<0 ){
104208 sqlite3VdbeAddOp2(v, OP_Null, 0, 3);
104209 }else{
104210 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pTab->aCol[cnum].zName, 0);
104211 }
104212 if( pPragma->iArg ){
104213 sqlite3VdbeAddOp2(v, OP_Integer, pIdx->aSortOrder[i], 4);
104214 sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, pIdx->azColl[i], 0);
104215 sqlite3VdbeAddOp2(v, OP_Integer, i<pIdx->nKeyCol, 6);
104216 }
104217 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, pParse->nMem);
104218 }
104219 }
104220 }
104221 break;
104222
@@ -104457,12 +104914,13 @@
104914 #endif
104915
104916 /*
104917 ** PRAGMA shrink_memory
104918 **
104919 ** IMPLEMENTATION-OF: R-23445-46109 This pragma causes the database
104920 ** connection on which it is invoked to free up as much memory as it
104921 ** can, by calling sqlite3_db_release_memory().
104922 */
104923 case PragTyp_SHRINK_MEMORY: {
104924 sqlite3_db_release_memory(db);
104925 break;
104926 }
@@ -104487,12 +104945,16 @@
104945
104946 /*
104947 ** PRAGMA soft_heap_limit
104948 ** PRAGMA soft_heap_limit = N
104949 **
104950 ** IMPLEMENTATION-OF: R-26343-45930 This pragma invokes the
104951 ** sqlite3_soft_heap_limit64() interface with the argument N, if N is
104952 ** specified and is a non-negative integer.
104953 ** IMPLEMENTATION-OF: R-64451-07163 The soft_heap_limit pragma always
104954 ** returns the same integer that would be returned by the
104955 ** sqlite3_soft_heap_limit64(-1) C-language function.
104956 */
104957 case PragTyp_SOFT_HEAP_LIMIT: {
104958 sqlite3_int64 N;
104959 if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){
104960 sqlite3_soft_heap_limit64(N);
@@ -106065,24 +106527,21 @@
106527 }else{
106528 op = OP_IdxInsert;
106529 }
106530 sqlite3VdbeAddOp2(v, op, pSort->iECursor, regRecord);
106531 if( pSelect->iLimit ){
106532 int addr;
106533 int iLimit;
106534 if( pSelect->iOffset ){
106535 iLimit = pSelect->iOffset+1;
106536 }else{
106537 iLimit = pSelect->iLimit;
106538 }
106539 addr = sqlite3VdbeAddOp3(v, OP_IfNotZero, iLimit, 0, -1); VdbeCoverage(v);
 
 
 
106540 sqlite3VdbeAddOp1(v, OP_Last, pSort->iECursor);
106541 sqlite3VdbeAddOp1(v, OP_Delete, pSort->iECursor);
106542 sqlite3VdbeJumpHere(v, addr);
106543 }
106544 }
106545
106546 /*
106547 ** Add code to implement the OFFSET
@@ -106475,11 +106934,11 @@
106934 /* Jump to the end of the loop if the LIMIT is reached. Except, if
106935 ** there is a sorter, in which case the sorter has already limited
106936 ** the output for us.
106937 */
106938 if( pSort==0 && p->iLimit ){
106939 sqlite3VdbeAddOp2(v, OP_DecrJumpZero, p->iLimit, iBreak); VdbeCoverage(v);
106940 }
106941 }
106942
106943 /*
106944 ** Allocate a KeyInfo object sufficient for an index of N key columns and
@@ -107328,11 +107787,11 @@
107787 }
107788 }else{
107789 sqlite3ExprCode(pParse, p->pLimit, iLimit);
107790 sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit); VdbeCoverage(v);
107791 VdbeComment((v, "LIMIT counter"));
107792 sqlite3VdbeAddOp2(v, OP_IfNot, iLimit, iBreak); VdbeCoverage(v);
107793 }
107794 if( p->pOffset ){
107795 p->iOffset = iOffset = ++pParse->nMem;
107796 pParse->nMem++; /* Allocate an extra register for limit+offset */
107797 sqlite3ExprCode(pParse, p->pOffset, iOffset);
@@ -107547,11 +108006,11 @@
108006 addrCont = sqlite3VdbeMakeLabel(v);
108007 codeOffset(v, regOffset, addrCont);
108008 selectInnerLoop(pParse, p, p->pEList, iCurrent,
108009 0, 0, pDest, addrCont, addrBreak);
108010 if( regLimit ){
108011 sqlite3VdbeAddOp2(v, OP_DecrJumpZero, regLimit, addrBreak);
108012 VdbeCoverage(v);
108013 }
108014 sqlite3VdbeResolveLabel(v, addrCont);
108015
108016 /* Execute the recursive SELECT taking the single row in Current as
@@ -107772,11 +108231,11 @@
108231 }
108232 p->pPrior = 0;
108233 p->iLimit = pPrior->iLimit;
108234 p->iOffset = pPrior->iOffset;
108235 if( p->iLimit ){
108236 addr = sqlite3VdbeAddOp1(v, OP_IfNot, p->iLimit); VdbeCoverage(v);
108237 VdbeComment((v, "Jump ahead if LIMIT reached"));
108238 }
108239 explainSetInteger(iSub2, pParse->iNextSelectId);
108240 rc = sqlite3Select(pParse, p, &dest);
108241 testcase( rc!=SQLITE_OK );
@@ -108173,11 +108632,11 @@
108632 }
108633
108634 /* Jump to the end of the loop if the LIMIT is reached.
108635 */
108636 if( p->iLimit ){
108637 sqlite3VdbeAddOp2(v, OP_DecrJumpZero, p->iLimit, iBreak); VdbeCoverage(v);
108638 }
108639
108640 /* Generate the subroutine return
108641 */
108642 sqlite3VdbeResolveLabel(v, iContinue);
@@ -109540,11 +109999,11 @@
109999 sqlite3WalkSelect(pWalker, bMayRecursive ? pSel->pPrior : pSel);
110000
110001 for(pLeft=pSel; pLeft->pPrior; pLeft=pLeft->pPrior);
110002 pEList = pLeft->pEList;
110003 if( pCte->pCols ){
110004 if( pEList && pEList->nExpr!=pCte->pCols->nExpr ){
110005 sqlite3ErrorMsg(pParse, "table %s has %d values for %d columns",
110006 pCte->zName, pEList->nExpr, pCte->pCols->nExpr
110007 );
110008 pParse->pWith = pSavedWith;
110009 return SQLITE_ERROR;
@@ -113966,10 +114425,11 @@
114425 */
114426 if( !db->init.busy ){
114427 char *zStmt;
114428 char *zWhere;
114429 int iDb;
114430 int iReg;
114431 Vdbe *v;
114432
114433 /* Compute the complete text of the CREATE VIRTUAL TABLE statement */
114434 if( pEnd ){
114435 pParse->sNameToken.n = (int)(pEnd->z - pParse->sNameToken.z) + pEnd->n;
@@ -114000,12 +114460,14 @@
114460 sqlite3ChangeCookie(pParse, iDb);
114461
114462 sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
114463 zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
114464 sqlite3VdbeAddParseSchemaOp(v, iDb, zWhere);
114465
114466 iReg = ++pParse->nMem;
114467 sqlite3VdbeAddOp4(v, OP_String8, 0, iReg, 0, pTab->zName, 0);
114468 sqlite3VdbeAddOp2(v, OP_VCreate, iDb, iReg);
114469 }
114470
114471 /* If we are rereading the sqlite_master table create the in-memory
114472 ** record of the table. The xConnect() method is not called until
114473 ** the first time the virtual table is used in an SQL statement. This
@@ -114354,15 +114816,19 @@
114816 int rc = SQLITE_OK;
114817 Table *pTab;
114818
114819 pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName);
114820 if( ALWAYS(pTab!=0 && pTab->pVTable!=0) ){
114821 VTable *p;
114822 for(p=pTab->pVTable; p; p=p->pNext){
114823 assert( p->pVtab );
114824 if( p->pVtab->nRef>0 ){
114825 return SQLITE_LOCKED;
114826 }
114827 }
114828 p = vtabDisconnectAll(db, pTab);
114829 rc = p->pMod->pModule->xDestroy(p->pVtab);
 
114830 /* Remove the sqlite3_vtab* from the aVTrans[] array, if applicable */
114831 if( rc==SQLITE_OK ){
114832 assert( pTab->pVTable==p && p->pNext==0 );
114833 p->pVtab = 0;
114834 pTab->pVTable = 0;
@@ -114787,10 +115253,12 @@
115253 int addrNxt; /* Jump here to start the next IN combination */
115254 int addrSkip; /* Jump here for next iteration of skip-scan */
115255 int addrCont; /* Jump here to continue with the next loop cycle */
115256 int addrFirst; /* First instruction of interior of the loop */
115257 int addrBody; /* Beginning of the body of this loop */
115258 int iLikeRepCntr; /* LIKE range processing counter register */
115259 int addrLikeRep; /* LIKE range processing address */
115260 u8 iFrom; /* Which entry in the FROM clause */
115261 u8 op, p3, p5; /* Opcode, P3 & P5 of the opcode that ends the loop */
115262 int p1, p2; /* Operands of the opcode used to ends the loop */
115263 union { /* Information that depends on pWLoop->wsFlags */
115264 struct {
@@ -114971,11 +115439,11 @@
115439 WhereOrInfo *pOrInfo; /* Extra information if (eOperator & WO_OR)!=0 */
115440 WhereAndInfo *pAndInfo; /* Extra information if (eOperator& WO_AND)!=0 */
115441 } u;
115442 LogEst truthProb; /* Probability of truth for this expression */
115443 u16 eOperator; /* A WO_xx value describing <op> */
115444 u16 wtFlags; /* TERM_xxx bit flags. See below */
115445 u8 nChild; /* Number of children that must disable us */
115446 WhereClause *pWC; /* The clause this term is part of */
115447 Bitmask prereqRight; /* Bitmask of tables used by pExpr->pRight */
115448 Bitmask prereqAll; /* Bitmask of tables referenced by pExpr */
115449 };
@@ -114993,10 +115461,13 @@
115461 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
115462 # define TERM_VNULL 0x80 /* Manufactured x>NULL or x<=NULL term */
115463 #else
115464 # define TERM_VNULL 0x00 /* Disabled if not using stat3 */
115465 #endif
115466 #define TERM_LIKEOPT 0x100 /* Virtual terms from the LIKE optimization */
115467 #define TERM_LIKECOND 0x200 /* Conditionally this LIKE operator term */
115468 #define TERM_LIKE 0x400 /* The original LIKE operator */
115469
115470 /*
115471 ** An instance of the WhereScan object is used as an iterator for locating
115472 ** terms in the WHERE clause that are useful to the query planner.
115473 */
@@ -115368,11 +115839,11 @@
115839 ** WARNING: This routine might reallocate the space used to store
115840 ** WhereTerms. All pointers to WhereTerms should be invalidated after
115841 ** calling this routine. Such pointers may be reinitialized by referencing
115842 ** the pWC->a[] array.
115843 */
115844 static int whereClauseInsert(WhereClause *pWC, Expr *p, u16 wtFlags){
115845 WhereTerm *pTerm;
115846 int idx;
115847 testcase( wtFlags & TERM_VIRTUAL );
115848 if( pWC->nTerm>=pWC->nSlot ){
115849 WhereTerm *pOld = pWC->a;
@@ -115793,11 +116264,15 @@
116264 ** Check to see if the given expression is a LIKE or GLOB operator that
116265 ** can be optimized using inequality constraints. Return TRUE if it is
116266 ** so and false if not.
116267 **
116268 ** In order for the operator to be optimizible, the RHS must be a string
116269 ** literal that does not begin with a wildcard. The LHS must be a column
116270 ** that may only be NULL, a string, or a BLOB, never a number. (This means
116271 ** that virtual tables cannot participate in the LIKE optimization.) If the
116272 ** collating sequence for the column on the LHS must be appropriate for
116273 ** the operator.
116274 */
116275 static int isLikeOrGlob(
116276 Parse *pParse, /* Parsing and code generating context */
116277 Expr *pExpr, /* Test this expression */
116278 Expr **ppPrefix, /* Pointer to TK_STRING expression with pattern prefix */
@@ -115822,11 +116297,11 @@
116297 #endif
116298 pList = pExpr->x.pList;
116299 pLeft = pList->a[1].pExpr;
116300 if( pLeft->op!=TK_COLUMN
116301 || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT
116302 || IsVirtual(pLeft->pTab) /* Value might be numeric */
116303 ){
116304 /* IMP: R-02065-49465 The left-hand side of the LIKE or GLOB operator must
116305 ** be the name of an indexed column with TEXT affinity. */
116306 return 0;
116307 }
@@ -115931,10 +116406,83 @@
116406 static void markTermAsChild(WhereClause *pWC, int iChild, int iParent){
116407 pWC->a[iChild].iParent = iParent;
116408 pWC->a[iChild].truthProb = pWC->a[iParent].truthProb;
116409 pWC->a[iParent].nChild++;
116410 }
116411
116412 /*
116413 ** Return the N-th AND-connected subterm of pTerm. Or if pTerm is not
116414 ** a conjunction, then return just pTerm when N==0. If N is exceeds
116415 ** the number of available subterms, return NULL.
116416 */
116417 static WhereTerm *whereNthSubterm(WhereTerm *pTerm, int N){
116418 if( pTerm->eOperator!=WO_AND ){
116419 return N==0 ? pTerm : 0;
116420 }
116421 if( N<pTerm->u.pAndInfo->wc.nTerm ){
116422 return &pTerm->u.pAndInfo->wc.a[N];
116423 }
116424 return 0;
116425 }
116426
116427 /*
116428 ** Subterms pOne and pTwo are contained within WHERE clause pWC. The
116429 ** two subterms are in disjunction - they are OR-ed together.
116430 **
116431 ** If these two terms are both of the form: "A op B" with the same
116432 ** A and B values but different operators and if the operators are
116433 ** compatible (if one is = and the other is <, for example) then
116434 ** add a new virtual AND term to pWC that is the combination of the
116435 ** two.
116436 **
116437 ** Some examples:
116438 **
116439 ** x<y OR x=y --> x<=y
116440 ** x=y OR x=y --> x=y
116441 ** x<=y OR x<y --> x<=y
116442 **
116443 ** The following is NOT generated:
116444 **
116445 ** x<y OR x>y --> x!=y
116446 */
116447 static void whereCombineDisjuncts(
116448 SrcList *pSrc, /* the FROM clause */
116449 WhereClause *pWC, /* The complete WHERE clause */
116450 WhereTerm *pOne, /* First disjunct */
116451 WhereTerm *pTwo /* Second disjunct */
116452 ){
116453 u16 eOp = pOne->eOperator | pTwo->eOperator;
116454 sqlite3 *db; /* Database connection (for malloc) */
116455 Expr *pNew; /* New virtual expression */
116456 int op; /* Operator for the combined expression */
116457 int idxNew; /* Index in pWC of the next virtual term */
116458
116459 if( (pOne->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE))==0 ) return;
116460 if( (pTwo->eOperator & (WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE))==0 ) return;
116461 if( (eOp & (WO_EQ|WO_LT|WO_LE))!=eOp
116462 && (eOp & (WO_EQ|WO_GT|WO_GE))!=eOp ) return;
116463 assert( pOne->pExpr->pLeft!=0 && pOne->pExpr->pRight!=0 );
116464 assert( pTwo->pExpr->pLeft!=0 && pTwo->pExpr->pRight!=0 );
116465 if( sqlite3ExprCompare(pOne->pExpr->pLeft, pTwo->pExpr->pLeft, -1) ) return;
116466 if( sqlite3ExprCompare(pOne->pExpr->pRight, pTwo->pExpr->pRight, -1) )return;
116467 /* If we reach this point, it means the two subterms can be combined */
116468 if( (eOp & (eOp-1))!=0 ){
116469 if( eOp & (WO_LT|WO_LE) ){
116470 eOp = WO_LE;
116471 }else{
116472 assert( eOp & (WO_GT|WO_GE) );
116473 eOp = WO_GE;
116474 }
116475 }
116476 db = pWC->pWInfo->pParse->db;
116477 pNew = sqlite3ExprDup(db, pOne->pExpr, 0);
116478 if( pNew==0 ) return;
116479 for(op=TK_EQ; eOp!=(WO_EQ<<(op-TK_EQ)); op++){ assert( op<TK_GE ); }
116480 pNew->op = op;
116481 idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC);
116482 exprAnalyze(pSrc, pWC, idxNew);
116483 }
116484
116485 #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
116486 /*
116487 ** Analyze a term that consists of two or more OR-connected
116488 ** subterms. So in:
@@ -115956,10 +116504,11 @@
116504 ** (A) t1.x=t2.y OR t1.x=t2.z OR t1.y=15 OR t1.z=t3.a+5
116505 ** (B) x=expr1 OR expr2=x OR x=expr3
116506 ** (C) t1.x=t2.y OR (t1.x=t2.z AND t1.y=15)
116507 ** (D) x=expr1 OR (y>11 AND y<22 AND z LIKE '*hello*')
116508 ** (E) (p.a=1 AND q.b=2 AND r.c=3) OR (p.x=4 AND q.y=5 AND r.z=6)
116509 ** (F) x>A OR (x=A AND y>=B)
116510 **
116511 ** CASE 1:
116512 **
116513 ** If all subterms are of the form T.C=expr for some single column of C and
116514 ** a single table T (as shown in example B above) then create a new virtual
@@ -115971,10 +116520,20 @@
116520 ** then create a new virtual term like this:
116521 **
116522 ** x IN (expr1,expr2,expr3)
116523 **
116524 ** CASE 2:
116525 **
116526 ** If there are exactly two disjuncts one side has x>A and the other side
116527 ** has x=A (for the same x and A) then add a new virtual conjunct term to the
116528 ** WHERE clause of the form "x>=A". Example:
116529 **
116530 ** x>A OR (x=A AND y>B) adds: x>=A
116531 **
116532 ** The added conjunct can sometimes be helpful in query planning.
116533 **
116534 ** CASE 3:
116535 **
116536 ** If all subterms are indexable by a single table T, then set
116537 **
116538 ** WhereTerm.eOperator = WO_OR
116539 ** WhereTerm.u.pOrInfo->indexable |= the cursor number for table T
@@ -116098,15 +116657,29 @@
116657 }
116658 }
116659 }
116660
116661 /*
116662 ** Record the set of tables that satisfy case 3. The set might be
116663 ** empty.
116664 */
116665 pOrInfo->indexable = indexable;
116666 pTerm->eOperator = indexable==0 ? 0 : WO_OR;
116667
116668 /* For a two-way OR, attempt to implementation case 2.
116669 */
116670 if( indexable && pOrWc->nTerm==2 ){
116671 int iOne = 0;
116672 WhereTerm *pOne;
116673 while( (pOne = whereNthSubterm(&pOrWc->a[0],iOne++))!=0 ){
116674 int iTwo = 0;
116675 WhereTerm *pTwo;
116676 while( (pTwo = whereNthSubterm(&pOrWc->a[1],iTwo++))!=0 ){
116677 whereCombineDisjuncts(pSrc, pWC, pOne, pTwo);
116678 }
116679 }
116680 }
116681
116682 /*
116683 ** chngToIN holds a set of tables that *might* satisfy case 1. But
116684 ** we have to do some additional checking to see if case 1 really
116685 ** is satisfied.
@@ -116233,11 +116806,11 @@
116806 pTerm = &pWC->a[idxTerm];
116807 markTermAsChild(pWC, idxNew, idxTerm);
116808 }else{
116809 sqlite3ExprListDelete(db, pList);
116810 }
116811 pTerm->eOperator = WO_NOOP; /* case 1 trumps case 3 */
116812 }
116813 }
116814 }
116815 #endif /* !SQLITE_OMIT_OR_OPTIMIZATION && !SQLITE_OMIT_SUBQUERY */
116816
@@ -116271,11 +116844,11 @@
116844 Bitmask prereqLeft; /* Prerequesites of the pExpr->pLeft */
116845 Bitmask prereqAll; /* Prerequesites of pExpr */
116846 Bitmask extraRight = 0; /* Extra dependencies on LEFT JOIN */
116847 Expr *pStr1 = 0; /* RHS of LIKE/GLOB operator */
116848 int isComplete = 0; /* RHS of LIKE/GLOB ends with wildcard */
116849 int noCase = 0; /* uppercase equivalent to lowercase */
116850 int op; /* Top-level operator. pExpr->op */
116851 Parse *pParse = pWInfo->pParse; /* Parsing context */
116852 sqlite3 *db = pParse->db; /* Database connection */
116853
116854 if( db->mallocFailed ){
@@ -116409,16 +116982,19 @@
116982
116983 #ifndef SQLITE_OMIT_LIKE_OPTIMIZATION
116984 /* Add constraints to reduce the search space on a LIKE or GLOB
116985 ** operator.
116986 **
116987 ** A like pattern of the form "x LIKE 'aBc%'" is changed into constraints
116988 **
116989 ** x>='ABC' AND x<'abd' AND x LIKE 'aBc%'
116990 **
116991 ** The last character of the prefix "abc" is incremented to form the
116992 ** termination condition "abd". If case is not significant (the default
116993 ** for LIKE) then the lower-bound is made all uppercase and the upper-
116994 ** bound is made all lowercase so that the bounds also work when comparing
116995 ** BLOBs.
116996 */
116997 if( pWC->op==TK_AND
116998 && isLikeOrGlob(pParse, pExpr, &pStr1, &isComplete, &noCase)
116999 ){
117000 Expr *pLeft; /* LHS of LIKE/GLOB operator */
@@ -116425,14 +117001,30 @@
117001 Expr *pStr2; /* Copy of pStr1 - RHS of LIKE/GLOB operator */
117002 Expr *pNewExpr1;
117003 Expr *pNewExpr2;
117004 int idxNew1;
117005 int idxNew2;
117006 const char *zCollSeqName; /* Name of collating sequence */
117007 const u16 wtFlags = TERM_LIKEOPT | TERM_VIRTUAL | TERM_DYNAMIC;
117008
117009 pLeft = pExpr->x.pList->a[1].pExpr;
117010 pStr2 = sqlite3ExprDup(db, pStr1, 0);
117011
117012 /* Convert the lower bound to upper-case and the upper bound to
117013 ** lower-case (upper-case is less than lower-case in ASCII) so that
117014 ** the range constraints also work for BLOBs
117015 */
117016 if( noCase && !pParse->db->mallocFailed ){
117017 int i;
117018 char c;
117019 pTerm->wtFlags |= TERM_LIKE;
117020 for(i=0; (c = pStr1->u.zToken[i])!=0; i++){
117021 pStr1->u.zToken[i] = sqlite3Toupper(c);
117022 pStr2->u.zToken[i] = sqlite3Tolower(c);
117023 }
117024 }
117025
117026 if( !db->mallocFailed ){
117027 u8 c, *pC; /* Last character before the first wildcard */
117028 pC = (u8*)&pStr2->u.zToken[sqlite3Strlen30(pStr2->u.zToken)-1];
117029 c = *pC;
117030 if( noCase ){
@@ -116445,26 +117037,25 @@
117037 if( c=='A'-1 ) isComplete = 0;
117038 c = sqlite3UpperToLower[c];
117039 }
117040 *pC = c + 1;
117041 }
117042 zCollSeqName = noCase ? "NOCASE" : "BINARY";
 
117043 pNewExpr1 = sqlite3ExprDup(db, pLeft, 0);
117044 pNewExpr1 = sqlite3PExpr(pParse, TK_GE,
117045 sqlite3ExprAddCollateString(pParse,pNewExpr1,zCollSeqName),
117046 pStr1, 0);
117047 transferJoinMarkings(pNewExpr1, pExpr);
117048 idxNew1 = whereClauseInsert(pWC, pNewExpr1, wtFlags);
117049 testcase( idxNew1==0 );
117050 exprAnalyze(pSrc, pWC, idxNew1);
117051 pNewExpr2 = sqlite3ExprDup(db, pLeft, 0);
117052 pNewExpr2 = sqlite3PExpr(pParse, TK_LT,
117053 sqlite3ExprAddCollateString(pParse,pNewExpr2,zCollSeqName),
117054 pStr2, 0);
117055 transferJoinMarkings(pNewExpr2, pExpr);
117056 idxNew2 = whereClauseInsert(pWC, pNewExpr2, wtFlags);
117057 testcase( idxNew2==0 );
117058 exprAnalyze(pSrc, pWC, idxNew2);
117059 pTerm = &pWC->a[idxTerm];
117060 if( isComplete ){
117061 markTermAsChild(pWC, idxNew1, idxTerm);
@@ -117074,15 +117665,18 @@
117665 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
117666 /*
117667 ** Estimate the location of a particular key among all keys in an
117668 ** index. Store the results in aStat as follows:
117669 **
117670 ** aStat[0] Est. number of rows less than pRec
117671 ** aStat[1] Est. number of rows equal to pRec
117672 **
117673 ** Return the index of the sample that is the smallest sample that
117674 ** is greater than or equal to pRec. Note that this index is not an index
117675 ** into the aSample[] array - it is an index into a virtual set of samples
117676 ** based on the contents of aSample[] and the number of fields in record
117677 ** pRec.
117678 */
117679 static int whereKeyStats(
117680 Parse *pParse, /* Database connection */
117681 Index *pIdx, /* Index to consider domain of */
117682 UnpackedRecord *pRec, /* Vector of values to consider */
@@ -117089,71 +117683,162 @@
117683 int roundUp, /* Round up if true. Round down if false */
117684 tRowcnt *aStat /* OUT: stats written here */
117685 ){
117686 IndexSample *aSample = pIdx->aSample;
117687 int iCol; /* Index of required stats in anEq[] etc. */
117688 int i; /* Index of first sample >= pRec */
117689 int iSample; /* Smallest sample larger than or equal to pRec */
117690 int iMin = 0; /* Smallest sample not yet tested */
 
117691 int iTest; /* Next sample to test */
117692 int res; /* Result of comparison operation */
117693 int nField; /* Number of fields in pRec */
117694 tRowcnt iLower = 0; /* anLt[] + anEq[] of largest sample pRec is > */
117695
117696 #ifndef SQLITE_DEBUG
117697 UNUSED_PARAMETER( pParse );
117698 #endif
117699 assert( pRec!=0 );
 
117700 assert( pIdx->nSample>0 );
117701 assert( pRec->nField>0 && pRec->nField<=pIdx->nSampleCol );
117702
117703 /* Do a binary search to find the first sample greater than or equal
117704 ** to pRec. If pRec contains a single field, the set of samples to search
117705 ** is simply the aSample[] array. If the samples in aSample[] contain more
117706 ** than one fields, all fields following the first are ignored.
117707 **
117708 ** If pRec contains N fields, where N is more than one, then as well as the
117709 ** samples in aSample[] (truncated to N fields), the search also has to
117710 ** consider prefixes of those samples. For example, if the set of samples
117711 ** in aSample is:
117712 **
117713 ** aSample[0] = (a, 5)
117714 ** aSample[1] = (a, 10)
117715 ** aSample[2] = (b, 5)
117716 ** aSample[3] = (c, 100)
117717 ** aSample[4] = (c, 105)
117718 **
117719 ** Then the search space should ideally be the samples above and the
117720 ** unique prefixes [a], [b] and [c]. But since that is hard to organize,
117721 ** the code actually searches this set:
117722 **
117723 ** 0: (a)
117724 ** 1: (a, 5)
117725 ** 2: (a, 10)
117726 ** 3: (a, 10)
117727 ** 4: (b)
117728 ** 5: (b, 5)
117729 ** 6: (c)
117730 ** 7: (c, 100)
117731 ** 8: (c, 105)
117732 ** 9: (c, 105)
117733 **
117734 ** For each sample in the aSample[] array, N samples are present in the
117735 ** effective sample array. In the above, samples 0 and 1 are based on
117736 ** sample aSample[0]. Samples 2 and 3 on aSample[1] etc.
117737 **
117738 ** Often, sample i of each block of N effective samples has (i+1) fields.
117739 ** Except, each sample may be extended to ensure that it is greater than or
117740 ** equal to the previous sample in the array. For example, in the above,
117741 ** sample 2 is the first sample of a block of N samples, so at first it
117742 ** appears that it should be 1 field in size. However, that would make it
117743 ** smaller than sample 1, so the binary search would not work. As a result,
117744 ** it is extended to two fields. The duplicates that this creates do not
117745 ** cause any problems.
117746 */
117747 nField = pRec->nField;
117748 iCol = 0;
117749 iSample = pIdx->nSample * nField;
117750 do{
117751 int iSamp; /* Index in aSample[] of test sample */
117752 int n; /* Number of fields in test sample */
117753
117754 iTest = (iMin+iSample)/2;
117755 iSamp = iTest / nField;
117756 if( iSamp>0 ){
117757 /* The proposed effective sample is a prefix of sample aSample[iSamp].
117758 ** Specifically, the shortest prefix of at least (1 + iTest%nField)
117759 ** fields that is greater than the previous effective sample. */
117760 for(n=(iTest % nField) + 1; n<nField; n++){
117761 if( aSample[iSamp-1].anLt[n-1]!=aSample[iSamp].anLt[n-1] ) break;
117762 }
117763 }else{
117764 n = iTest + 1;
117765 }
117766
117767 pRec->nField = n;
117768 res = sqlite3VdbeRecordCompare(aSample[iSamp].n, aSample[iSamp].p, pRec);
117769 if( res<0 ){
117770 iLower = aSample[iSamp].anLt[n-1] + aSample[iSamp].anEq[n-1];
117771 iMin = iTest+1;
117772 }else if( res==0 && n<nField ){
117773 iLower = aSample[iSamp].anLt[n-1];
117774 iMin = iTest+1;
117775 res = -1;
117776 }else{
117777 iSample = iTest;
117778 iCol = n-1;
117779 }
117780 }while( res && iMin<iSample );
117781 i = iSample / nField;
117782
117783 #ifdef SQLITE_DEBUG
117784 /* The following assert statements check that the binary search code
117785 ** above found the right answer. This block serves no purpose other
117786 ** than to invoke the asserts. */
117787 if( pParse->db->mallocFailed==0 ){
117788 if( res==0 ){
117789 /* If (res==0) is true, then pRec must be equal to sample i. */
117790 assert( i<pIdx->nSample );
117791 assert( iCol==nField-1 );
117792 pRec->nField = nField;
117793 assert( 0==sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)
117794 || pParse->db->mallocFailed
117795 );
117796 }else{
117797 /* Unless i==pIdx->nSample, indicating that pRec is larger than
117798 ** all samples in the aSample[] array, pRec must be smaller than the
117799 ** (iCol+1) field prefix of sample i. */
117800 assert( i<=pIdx->nSample && i>=0 );
117801 pRec->nField = iCol+1;
117802 assert( i==pIdx->nSample
117803 || sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)>0
117804 || pParse->db->mallocFailed );
117805
117806 /* if i==0 and iCol==0, then record pRec is smaller than all samples
117807 ** in the aSample[] array. Otherwise, if (iCol>0) then pRec must
117808 ** be greater than or equal to the (iCol) field prefix of sample i.
117809 ** If (i>0), then pRec must also be greater than sample (i-1). */
117810 if( iCol>0 ){
117811 pRec->nField = iCol;
117812 assert( sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)<=0
117813 || pParse->db->mallocFailed );
117814 }
117815 if( i>0 ){
117816 pRec->nField = nField;
117817 assert( sqlite3VdbeRecordCompare(aSample[i-1].n, aSample[i-1].p, pRec)<0
117818 || pParse->db->mallocFailed );
117819 }
117820 }
117821 }
117822 #endif /* ifdef SQLITE_DEBUG */
117823
 
 
 
 
117824 if( res==0 ){
117825 /* Record pRec is equal to sample i */
117826 assert( iCol==nField-1 );
117827 aStat[0] = aSample[i].anLt[iCol];
117828 aStat[1] = aSample[i].anEq[iCol];
117829 }else{
117830 /* At this point, the (iCol+1) field prefix of aSample[i] is the first
117831 ** sample that is greater than pRec. Or, if i==pIdx->nSample then pRec
117832 ** is larger than all samples in the array. */
117833 tRowcnt iUpper, iGap;
117834 if( i>=pIdx->nSample ){
117835 iUpper = sqlite3LogEstToInt(pIdx->aiRowLogEst[0]);
117836 }else{
117837 iUpper = aSample[i].anLt[iCol];
 
 
117838 }
117839
117840 if( iLower>=iUpper ){
117841 iGap = 0;
117842 }else{
117843 iGap = iUpper - iLower;
117844 }
@@ -117161,11 +117846,15 @@
117846 iGap = (iGap*2)/3;
117847 }else{
117848 iGap = iGap/3;
117849 }
117850 aStat[0] = iLower + iGap;
117851 aStat[1] = pIdx->aAvgEq[iCol];
117852 }
117853
117854 /* Restore the pRec->nField value before returning. */
117855 pRec->nField = nField;
117856 return i;
117857 }
117858 #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
117859
117860 /*
@@ -117635,24 +118324,47 @@
118324 ** by indices, we disable them to prevent redundant tests in the inner
118325 ** loop. We would get the correct results if nothing were ever disabled,
118326 ** but joins might run a little slower. The trick is to disable as much
118327 ** as we can without disabling too much. If we disabled in (1), we'd get
118328 ** the wrong answer. See ticket #813.
118329 **
118330 ** If all the children of a term are disabled, then that term is also
118331 ** automatically disabled. In this way, terms get disabled if derived
118332 ** virtual terms are tested first. For example:
118333 **
118334 ** x GLOB 'abc*' AND x>='abc' AND x<'acd'
118335 ** \___________/ \______/ \_____/
118336 ** parent child1 child2
118337 **
118338 ** Only the parent term was in the original WHERE clause. The child1
118339 ** and child2 terms were added by the LIKE optimization. If both of
118340 ** the virtual child terms are valid, then testing of the parent can be
118341 ** skipped.
118342 **
118343 ** Usually the parent term is marked as TERM_CODED. But if the parent
118344 ** term was originally TERM_LIKE, then the parent gets TERM_LIKECOND instead.
118345 ** The TERM_LIKECOND marking indicates that the term should be coded inside
118346 ** a conditional such that is only evaluated on the second pass of a
118347 ** LIKE-optimization loop, when scanning BLOBs instead of strings.
118348 */
118349 static void disableTerm(WhereLevel *pLevel, WhereTerm *pTerm){
118350 int nLoop = 0;
118351 while( pTerm
118352 && (pTerm->wtFlags & TERM_CODED)==0
118353 && (pLevel->iLeftJoin==0 || ExprHasProperty(pTerm->pExpr, EP_FromJoin))
118354 && (pLevel->notReady & pTerm->prereqAll)==0
118355 ){
118356 if( nLoop && (pTerm->wtFlags & TERM_LIKE)!=0 ){
118357 pTerm->wtFlags |= TERM_LIKECOND;
118358 }else{
118359 pTerm->wtFlags |= TERM_CODED;
 
 
118360 }
118361 if( pTerm->iParent<0 ) break;
118362 pTerm = &pTerm->pWC->a[pTerm->iParent];
118363 pTerm->nChild--;
118364 if( pTerm->nChild!=0 ) break;
118365 nLoop++;
118366 }
118367 }
118368
118369 /*
118370 ** Code an OP_Affinity opcode to apply the column affinity string zAff
@@ -118132,11 +118844,38 @@
118844 }
118845 #else
118846 # define addScanStatus(a, b, c, d) ((void)d)
118847 #endif
118848
118849 /*
118850 ** If the most recently coded instruction is a constant range contraint
118851 ** that originated from the LIKE optimization, then change the P3 to be
118852 ** pLoop->iLikeRepCntr and set P5.
118853 **
118854 ** The LIKE optimization trys to evaluate "x LIKE 'abc%'" as a range
118855 ** expression: "x>='ABC' AND x<'abd'". But this requires that the range
118856 ** scan loop run twice, once for strings and a second time for BLOBs.
118857 ** The OP_String opcodes on the second pass convert the upper and lower
118858 ** bound string contants to blobs. This routine makes the necessary changes
118859 ** to the OP_String opcodes for that to happen.
118860 */
118861 static void whereLikeOptimizationStringFixup(
118862 Vdbe *v, /* prepared statement under construction */
118863 WhereLevel *pLevel, /* The loop that contains the LIKE operator */
118864 WhereTerm *pTerm /* The upper or lower bound just coded */
118865 ){
118866 if( pTerm->wtFlags & TERM_LIKEOPT ){
118867 VdbeOp *pOp;
118868 assert( pLevel->iLikeRepCntr>0 );
118869 pOp = sqlite3VdbeGetOp(v, -1);
118870 assert( pOp!=0 );
118871 assert( pOp->opcode==OP_String8
118872 || pTerm->pWC->pWInfo->pParse->db->mallocFailed );
118873 pOp->p3 = pLevel->iLikeRepCntr;
118874 pOp->p5 = 1;
118875 }
118876 }
118877
118878 /*
118879 ** Generate code for the start of the iLevel-th loop in the WHERE clause
118880 ** implementation described by pWInfo.
118881 */
@@ -118462,14 +119201,29 @@
119201 */
119202 j = nEq;
119203 if( pLoop->wsFlags & WHERE_BTM_LIMIT ){
119204 pRangeStart = pLoop->aLTerm[j++];
119205 nExtraReg = 1;
119206 /* Like optimization range constraints always occur in pairs */
119207 assert( (pRangeStart->wtFlags & TERM_LIKEOPT)==0 ||
119208 (pLoop->wsFlags & WHERE_TOP_LIMIT)!=0 );
119209 }
119210 if( pLoop->wsFlags & WHERE_TOP_LIMIT ){
119211 pRangeEnd = pLoop->aLTerm[j++];
119212 nExtraReg = 1;
119213 if( (pRangeEnd->wtFlags & TERM_LIKEOPT)!=0 ){
119214 assert( pRangeStart!=0 ); /* LIKE opt constraints */
119215 assert( pRangeStart->wtFlags & TERM_LIKEOPT ); /* occur in pairs */
119216 pLevel->iLikeRepCntr = ++pParse->nMem;
119217 testcase( bRev );
119218 testcase( pIdx->aSortOrder[nEq]==SQLITE_SO_DESC );
119219 sqlite3VdbeAddOp2(v, OP_Integer,
119220 bRev ^ (pIdx->aSortOrder[nEq]==SQLITE_SO_DESC),
119221 pLevel->iLikeRepCntr);
119222 VdbeComment((v, "LIKE loop counter"));
119223 pLevel->addrLikeRep = sqlite3VdbeCurrentAddr(v);
119224 }
119225 if( pRangeStart==0
119226 && (j = pIdx->aiColumn[nEq])>=0
119227 && pIdx->pTable->aCol[j].notNull==0
119228 ){
119229 bSeekPastNull = 1;
@@ -118508,10 +119262,11 @@
119262 /* Seek the index cursor to the start of the range. */
119263 nConstraint = nEq;
119264 if( pRangeStart ){
119265 Expr *pRight = pRangeStart->pExpr->pRight;
119266 sqlite3ExprCode(pParse, pRight, regBase+nEq);
119267 whereLikeOptimizationStringFixup(v, pLevel, pRangeStart);
119268 if( (pRangeStart->wtFlags & TERM_VNULL)==0
119269 && sqlite3ExprCanBeNull(pRight)
119270 ){
119271 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
119272 VdbeCoverage(v);
@@ -118553,10 +119308,11 @@
119308 nConstraint = nEq;
119309 if( pRangeEnd ){
119310 Expr *pRight = pRangeEnd->pExpr->pRight;
119311 sqlite3ExprCacheRemove(pParse, regBase+nEq, 1);
119312 sqlite3ExprCode(pParse, pRight, regBase+nEq);
119313 whereLikeOptimizationStringFixup(v, pLevel, pRangeEnd);
119314 if( (pRangeEnd->wtFlags & TERM_VNULL)==0
119315 && sqlite3ExprCanBeNull(pRight)
119316 ){
119317 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
119318 VdbeCoverage(v);
@@ -118780,11 +119536,12 @@
119536 ** eliminating duplicates from other WHERE clauses, the action for each
119537 ** sub-WHERE clause is to to invoke the main loop body as a subroutine.
119538 */
119539 wctrlFlags = WHERE_OMIT_OPEN_CLOSE
119540 | WHERE_FORCE_TABLE
119541 | WHERE_ONETABLE_ONLY
119542 | WHERE_NO_AUTOINDEX;
119543 for(ii=0; ii<pOrWc->nTerm; ii++){
119544 WhereTerm *pOrTerm = &pOrWc->a[ii];
119545 if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
119546 WhereInfo *pSubWInfo; /* Info for single OR-term scan */
119547 Expr *pOrExpr = pOrTerm->pExpr; /* Current OR clause term */
@@ -118942,10 +119699,11 @@
119699 /* Insert code to test every subexpression that can be completely
119700 ** computed using the current set of tables.
119701 */
119702 for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
119703 Expr *pE;
119704 int skipLikeAddr = 0;
119705 testcase( pTerm->wtFlags & TERM_VIRTUAL );
119706 testcase( pTerm->wtFlags & TERM_CODED );
119707 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
119708 if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
119709 testcase( pWInfo->untestedTerms==0
@@ -118955,12 +119713,18 @@
119713 }
119714 pE = pTerm->pExpr;
119715 assert( pE!=0 );
119716 if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
119717 continue;
119718 }
119719 if( pTerm->wtFlags & TERM_LIKECOND ){
119720 assert( pLevel->iLikeRepCntr>0 );
119721 skipLikeAddr = sqlite3VdbeAddOp1(v, OP_IfNot, pLevel->iLikeRepCntr);
119722 VdbeCoverage(v);
119723 }
119724 sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
119725 if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr);
119726 pTerm->wtFlags |= TERM_CODED;
119727 }
119728
119729 /* Insert code to test for implied constraints based on transitivity
119730 ** of the "==" operator.
@@ -119621,10 +120385,14 @@
120385 ){
120386 continue; /* ignore IS [NOT] NULL constraints on NOT NULL columns */
120387 }
120388 if( pTerm->prereqRight & pNew->maskSelf ) continue;
120389
120390 /* Do not allow the upper bound of a LIKE optimization range constraint
120391 ** to mix with a lower range bound from some other source */
120392 if( pTerm->wtFlags & TERM_LIKEOPT && pTerm->eOperator==WO_LT ) continue;
120393
120394 pNew->wsFlags = saved_wsFlags;
120395 pNew->u.btree.nEq = saved_nEq;
120396 pNew->nLTerm = saved_nLTerm;
120397 if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
120398 pNew->aLTerm[pNew->nLTerm++] = pTerm;
@@ -119664,10 +120432,21 @@
120432 testcase( eOp & WO_GT );
120433 testcase( eOp & WO_GE );
120434 pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_BTM_LIMIT;
120435 pBtm = pTerm;
120436 pTop = 0;
120437 if( pTerm->wtFlags & TERM_LIKEOPT ){
120438 /* Range contraints that come from the LIKE optimization are
120439 ** always used in pairs. */
120440 pTop = &pTerm[1];
120441 assert( (pTop-(pTerm->pWC->a))<pTerm->pWC->nTerm );
120442 assert( pTop->wtFlags & TERM_LIKEOPT );
120443 assert( pTop->eOperator==WO_LT );
120444 if( whereLoopResize(db, pNew, pNew->nLTerm+1) ) break; /* OOM */
120445 pNew->aLTerm[pNew->nLTerm++] = pTop;
120446 pNew->wsFlags |= WHERE_TOP_LIMIT;
120447 }
120448 }else{
120449 assert( eOp & (WO_LT|WO_LE) );
120450 testcase( eOp & WO_LT );
120451 testcase( eOp & WO_LE );
120452 pNew->wsFlags |= WHERE_COLUMN_RANGE|WHERE_TOP_LIMIT;
@@ -119974,10 +120753,11 @@
120753 rLogSize = estLog(rSize);
120754
120755 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
120756 /* Automatic indexes */
120757 if( !pBuilder->pOrSet
120758 && (pWInfo->wctrlFlags & WHERE_NO_AUTOINDEX)==0
120759 && (pWInfo->pParse->db->flags & SQLITE_AutoIndex)!=0
120760 && pSrc->pIndex==0
120761 && !pSrc->viaCoroutine
120762 && !pSrc->notIndexed
120763 && HasRowid(pTab)
@@ -120857,14 +121637,14 @@
121637 assert( aSortCost==0 || &pSpace[nSpace]==(char*)&aSortCost[nOrderBy] );
121638 assert( aSortCost!=0 || &pSpace[nSpace]==(char*)pX );
121639
121640 /* Seed the search with a single WherePath containing zero WhereLoops.
121641 **
121642 ** TUNING: Do not let the number of iterations go above 28. If the cost
121643 ** of computing an automatic index is not paid back within the first 28
121644 ** rows, then do not use the automatic index. */
121645 aFrom[0].nRow = MIN(pParse->nQueryLoop, 48); assert( 48==sqlite3LogEst(28) );
121646 nFrom = 1;
121647 assert( aFrom[0].isOrdered==0 );
121648 if( nOrderBy ){
121649 /* If nLoop is zero, then there are no FROM terms in the query. Since
121650 ** in this case the query may return a maximum of one row, the results
@@ -121658,10 +122438,16 @@
122438 assert( pIx->pSchema==pTab->pSchema );
122439 assert( iIndexCur>=0 );
122440 if( op ){
122441 sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
122442 sqlite3VdbeSetP4KeyInfo(pParse, pIx);
122443 if( (pLoop->wsFlags & WHERE_CONSTRAINT)!=0
122444 && (pLoop->wsFlags & (WHERE_COLUMN_RANGE|WHERE_SKIPSCAN))==0
122445 && (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0
122446 ){
122447 sqlite3VdbeChangeP5(v, OPFLAG_SEEKEQ); /* Hint to COMDB2 */
122448 }
122449 VdbeComment((v, "%s", pIx->zName));
122450 }
122451 }
122452 if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb);
122453 notReady &= ~getMask(&pWInfo->sMaskSet, pTabItem->iCursor);
@@ -121758,10 +122544,20 @@
122544 if( pLevel->addrSkip ){
122545 sqlite3VdbeAddOp2(v, OP_Goto, 0, pLevel->addrSkip);
122546 VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
122547 sqlite3VdbeJumpHere(v, pLevel->addrSkip);
122548 sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
122549 }
122550 if( pLevel->addrLikeRep ){
122551 int op;
122552 if( sqlite3VdbeGetOp(v, pLevel->addrLikeRep-1)->p1 ){
122553 op = OP_DecrJumpZero;
122554 }else{
122555 op = OP_JumpZeroIncr;
122556 }
122557 sqlite3VdbeAddOp2(v, op, pLevel->iLikeRepCntr, pLevel->addrLikeRep);
122558 VdbeCoverage(v);
122559 }
122560 if( pLevel->iLeftJoin ){
122561 addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v);
122562 assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
122563 || (pLoop->wsFlags & WHERE_INDEXED)!=0 );
@@ -124649,11 +125445,11 @@
125445 spanSet(&yygotominor.yy346, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
125446 }
125447 break;
125448 case 193: /* expr ::= expr COLLATE ID|STRING */
125449 {
125450 yygotominor.yy346.pExpr = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy346.pExpr, &yymsp[0].minor.yy0, 1);
125451 yygotominor.yy346.zStart = yymsp[-2].minor.yy346.zStart;
125452 yygotominor.yy346.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
125453 }
125454 break;
125455 case 194: /* expr ::= CAST LP expr AS typetoken RP */
@@ -124929,20 +125725,20 @@
125725 case 241: /* uniqueflag ::= */
125726 {yygotominor.yy328 = OE_None;}
125727 break;
125728 case 244: /* idxlist ::= idxlist COMMA nm collate sortorder */
125729 {
125730 Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0, 1);
125731 yygotominor.yy14 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy14, p);
125732 sqlite3ExprListSetName(pParse,yygotominor.yy14,&yymsp[-2].minor.yy0,1);
125733 sqlite3ExprListCheckLength(pParse, yygotominor.yy14, "index");
125734 if( yygotominor.yy14 ) yygotominor.yy14->a[yygotominor.yy14->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy328;
125735 }
125736 break;
125737 case 245: /* idxlist ::= nm collate sortorder */
125738 {
125739 Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &yymsp[-1].minor.yy0, 1);
125740 yygotominor.yy14 = sqlite3ExprListAppend(pParse,0, p);
125741 sqlite3ExprListSetName(pParse, yygotominor.yy14, &yymsp[-2].minor.yy0, 1);
125742 sqlite3ExprListCheckLength(pParse, yygotominor.yy14, "index");
125743 if( yygotominor.yy14 ) yygotominor.yy14->a[yygotominor.yy14->nExpr-1].sortOrder = (u8)yymsp[0].minor.yy328;
125744 }
@@ -126197,13 +126993,15 @@
126993 pParse->zTail = &zSql[i];
126994 }
126995 sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
126996 }
126997 #ifdef YYTRACKMAXSTACKDEPTH
126998 sqlite3_mutex_enter(sqlite3MallocMutex());
126999 sqlite3StatusSet(SQLITE_STATUS_PARSER_STACK,
127000 sqlite3ParserStackPeak(pEngine)
127001 );
127002 sqlite3_mutex_leave(sqlite3MallocMutex());
127003 #endif /* YYDEBUG */
127004 sqlite3ParserFree(pEngine, sqlite3_free);
127005 db->lookaside.bEnabled = enableLookaside;
127006 if( db->mallocFailed ){
127007 pParse->rc = SQLITE_NOMEM;
@@ -126769,10 +127567,15 @@
127567 rc = sqlite3_wsd_init(4096, 24);
127568 if( rc!=SQLITE_OK ){
127569 return rc;
127570 }
127571 #endif
127572
127573 /* If the following assert() fails on some obscure processor/compiler
127574 ** combination, the work-around is to set the correct pointer
127575 ** size at compile-time using -DSQLITE_PTRSIZE=n compile-time option */
127576 assert( SQLITE_PTRSIZE==sizeof(char*) );
127577
127578 /* If SQLite is already completely initialized, then this call
127579 ** to sqlite3_initialize() should be a no-op. But the initialization
127580 ** must be complete. So isInit must not be set until the very end
127581 ** of this routine.
@@ -126982,30 +127785,32 @@
127785 /* Mutex configuration options are only available in a threadsafe
127786 ** compile.
127787 */
127788 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-54466-46756 */
127789 case SQLITE_CONFIG_SINGLETHREAD: {
127790 /* EVIDENCE-OF: R-02748-19096 This option sets the threading mode to
127791 ** Single-thread. */
127792 sqlite3GlobalConfig.bCoreMutex = 0; /* Disable mutex on core */
127793 sqlite3GlobalConfig.bFullMutex = 0; /* Disable mutex on connections */
127794 break;
127795 }
127796 #endif
127797 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-20520-54086 */
127798 case SQLITE_CONFIG_MULTITHREAD: {
127799 /* EVIDENCE-OF: R-14374-42468 This option sets the threading mode to
127800 ** Multi-thread. */
127801 sqlite3GlobalConfig.bCoreMutex = 1; /* Enable mutex on core */
127802 sqlite3GlobalConfig.bFullMutex = 0; /* Disable mutex on connections */
127803 break;
127804 }
127805 #endif
127806 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-59593-21810 */
127807 case SQLITE_CONFIG_SERIALIZED: {
127808 /* EVIDENCE-OF: R-41220-51800 This option sets the threading mode to
127809 ** Serialized. */
127810 sqlite3GlobalConfig.bCoreMutex = 1; /* Enable mutex on core */
127811 sqlite3GlobalConfig.bFullMutex = 1; /* Enable mutex on connections */
127812 break;
127813 }
127814 #endif
127815 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-63666-48755 */
127816 case SQLITE_CONFIG_MUTEX: {
@@ -127113,11 +127918,12 @@
127918 ** SQLITE_ENABLE_MEMSYS5 and returns SQLITE_ERROR if invoked otherwise. */
127919 #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
127920 case SQLITE_CONFIG_HEAP: {
127921 /* EVIDENCE-OF: R-19854-42126 There are three arguments to
127922 ** SQLITE_CONFIG_HEAP: An 8-byte aligned pointer to the memory, the
127923 ** number of bytes in the memory buffer, and the minimum allocation size.
127924 */
127925 sqlite3GlobalConfig.pHeap = va_arg(ap, void*);
127926 sqlite3GlobalConfig.nHeap = va_arg(ap, int);
127927 sqlite3GlobalConfig.mnReq = va_arg(ap, int);
127928
127929 if( sqlite3GlobalConfig.mnReq<1 ){
@@ -127218,11 +128024,13 @@
128024 ** EVIDENCE-OF: R-34993-45031 The maximum allowed mmap size will be
128025 ** silently truncated if necessary so that it does not exceed the
128026 ** compile-time maximum mmap size set by the SQLITE_MAX_MMAP_SIZE
128027 ** compile-time option.
128028 */
128029 if( mxMmap<0 || mxMmap>SQLITE_MAX_MMAP_SIZE ){
128030 mxMmap = SQLITE_MAX_MMAP_SIZE;
128031 }
128032 if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE;
128033 if( szMmap>mxMmap) szMmap = mxMmap;
128034 sqlite3GlobalConfig.mxMmap = mxMmap;
128035 sqlite3GlobalConfig.szMmap = szMmap;
128036 break;
@@ -129062,11 +129870,23 @@
129870 for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
129871 zFile = sqlite3_malloc(nByte);
129872 if( !zFile ) return SQLITE_NOMEM;
129873
129874 iIn = 5;
129875 #ifdef SQLITE_ALLOW_URI_AUTHORITY
129876 if( strncmp(zUri+5, "///", 3)==0 ){
129877 iIn = 7;
129878 /* The following condition causes URIs with five leading / characters
129879 ** like file://///host/path to be converted into UNCs like //host/path.
129880 ** The correct URI for that UNC has only two or four leading / characters
129881 ** file://host/path or file:////host/path. But 5 leading slashes is a
129882 ** common error, we are told, so we handle it as a special case. */
129883 if( strncmp(zUri+7, "///", 3)==0 ){ iIn++; }
129884 }else if( strncmp(zUri+5, "//localhost/", 12)==0 ){
129885 iIn = 16;
129886 }
129887 #else
129888 /* Discard the scheme and authority segments of the URI. */
129889 if( zUri[5]=='/' && zUri[6]=='/' ){
129890 iIn = 7;
129891 while( zUri[iIn] && zUri[iIn]!='/' ) iIn++;
129892 if( iIn!=7 && (iIn!=16 || memcmp("localhost", &zUri[7], 9)) ){
@@ -129505,11 +130325,12 @@
130325 sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT);
130326
130327 opendb_out:
130328 sqlite3_free(zOpen);
130329 if( db ){
130330 assert( db->mutex!=0 || isThreadsafe==0
130331 || sqlite3GlobalConfig.bFullMutex==0 );
130332 sqlite3_mutex_leave(db->mutex);
130333 }
130334 rc = sqlite3_errcode(db);
130335 assert( db!=0 || rc==SQLITE_NOMEM );
130336 if( rc==SQLITE_NOMEM ){
@@ -130250,21 +131071,21 @@
131071 case SQLITE_TESTCTRL_ISINIT: {
131072 if( sqlite3GlobalConfig.isInit==0 ) rc = SQLITE_ERROR;
131073 break;
131074 }
131075
131076 /* sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, dbName, onOff, tnum);
131077 **
131078 ** This test control is used to create imposter tables. "db" is a pointer
131079 ** to the database connection. dbName is the database name (ex: "main" or
131080 ** "temp") which will receive the imposter. "onOff" turns imposter mode on
131081 ** or off. "tnum" is the root page of the b-tree to which the imposter
131082 ** table should connect.
131083 **
131084 ** Enable imposter mode only when the schema has already been parsed. Then
131085 ** run a single CREATE TABLE statement to construct the imposter table in
131086 ** the parsed schema. Then turn imposter mode back off again.
131087 **
131088 ** If onOff==0 and tnum>0 then reset the schema for all databases, causing
131089 ** the schema to be reparsed the next time it is needed. This has the
131090 ** effect of erasing all imposter tables.
131091 */
@@ -132506,15 +133327,20 @@
133327 ** the output value undefined. Otherwise SQLITE_OK is returned.
133328 **
133329 ** This function is used when parsing the "prefix=" FTS4 parameter.
133330 */
133331 static int fts3GobbleInt(const char **pp, int *pnOut){
133332 const int MAX_NPREFIX = 10000000;
133333 const char *p; /* Iterator pointer */
133334 int nInt = 0; /* Output value */
133335
133336 for(p=*pp; p[0]>='0' && p[0]<='9'; p++){
133337 nInt = nInt * 10 + (p[0] - '0');
133338 if( nInt>MAX_NPREFIX ){
133339 nInt = 0;
133340 break;
133341 }
133342 }
133343 if( p==*pp ) return SQLITE_ERROR;
133344 *pnOut = nInt;
133345 *pp = p;
133346 return SQLITE_OK;
@@ -132553,27 +133379,33 @@
133379 }
133380 }
133381
133382 aIndex = sqlite3_malloc(sizeof(struct Fts3Index) * nIndex);
133383 *apIndex = aIndex;
 
133384 if( !aIndex ){
133385 return SQLITE_NOMEM;
133386 }
133387
133388 memset(aIndex, 0, sizeof(struct Fts3Index) * nIndex);
133389 if( zParam ){
133390 const char *p = zParam;
133391 int i;
133392 for(i=1; i<nIndex; i++){
133393 int nPrefix = 0;
133394 if( fts3GobbleInt(&p, &nPrefix) ) return SQLITE_ERROR;
133395 assert( nPrefix>=0 );
133396 if( nPrefix==0 ){
133397 nIndex--;
133398 i--;
133399 }else{
133400 aIndex[i].nPrefix = nPrefix;
133401 }
133402 p++;
133403 }
133404 }
133405
133406 *pnIndex = nIndex;
133407 return SQLITE_OK;
133408 }
133409
133410 /*
133411 ** This function is called when initializing an FTS4 table that uses the
@@ -140349,11 +141181,11 @@
141181 nName = sqlite3_value_bytes(argv[0])+1;
141182
141183 if( argc==2 ){
141184 void *pOld;
141185 int n = sqlite3_value_bytes(argv[1]);
141186 if( zName==0 || n!=sizeof(pPtr) ){
141187 sqlite3_result_error(context, "argument type mismatch", -1);
141188 return;
141189 }
141190 pPtr = *(void **)sqlite3_value_blob(argv[1]);
141191 pOld = sqlite3Fts3HashInsert(pHash, (void *)zName, nName, pPtr);
@@ -140360,11 +141192,13 @@
141192 if( pOld==pPtr ){
141193 sqlite3_result_error(context, "out of memory", -1);
141194 return;
141195 }
141196 }else{
141197 if( zName ){
141198 pPtr = sqlite3Fts3HashFind(pHash, zName, nName);
141199 }
141200 if( !pPtr ){
141201 char *zErr = sqlite3_mprintf("unknown tokenizer: %s", zName);
141202 sqlite3_result_error(context, zErr, -1);
141203 sqlite3_free(zErr);
141204 return;
@@ -140441,10 +141275,14 @@
141275 zCopy = sqlite3_mprintf("%s", zArg);
141276 if( !zCopy ) return SQLITE_NOMEM;
141277 zEnd = &zCopy[strlen(zCopy)];
141278
141279 z = (char *)sqlite3Fts3NextToken(zCopy, &n);
141280 if( z==0 ){
141281 assert( n==0 );
141282 z = zCopy;
141283 }
141284 z[n] = '\0';
141285 sqlite3Fts3Dequote(z);
141286
141287 m = (sqlite3_tokenizer_module *)sqlite3Fts3HashFind(pHash,z,(int)strlen(z)+1);
141288 if( !m ){
@@ -143086,11 +143924,14 @@
143924 /*
143925 ** This is a comparison function used as a qsort() callback when sorting
143926 ** an array of pending terms by term. This occurs as part of flushing
143927 ** the contents of the pending-terms hash table to the database.
143928 */
143929 static int SQLITE_CDECL fts3CompareElemByTerm(
143930 const void *lhs,
143931 const void *rhs
143932 ){
143933 char *z1 = fts3HashKey(*(Fts3HashElem **)lhs);
143934 char *z2 = fts3HashKey(*(Fts3HashElem **)rhs);
143935 int n1 = fts3HashKeysize(*(Fts3HashElem **)lhs);
143936 int n2 = fts3HashKeysize(*(Fts3HashElem **)rhs);
143937
143938
+69 -48
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -52,10 +52,17 @@
5252
#ifndef SQLITE_API
5353
# define SQLITE_API
5454
#endif
5555
5656
57
+/*
58
+** Add the ability to override 'cdecl'
59
+*/
60
+#ifndef SQLITE_CDECL
61
+# define SQLITE_CDECL
62
+#endif
63
+
5764
/*
5865
** These no-op macros are used in front of interfaces to mark those
5966
** interfaces as either deprecated or experimental. New applications
6067
** should not use deprecated interfaces - they are supported for backwards
6168
** compatibility only. Application writers should be aware that
@@ -105,13 +112,13 @@
105112
**
106113
** See also: [sqlite3_libversion()],
107114
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108115
** [sqlite_version()] and [sqlite_source_id()].
109116
*/
110
-#define SQLITE_VERSION "3.8.8"
111
-#define SQLITE_VERSION_NUMBER 3008008
112
-#define SQLITE_SOURCE_ID "2015-02-25 14:25:31 6d132e7a224ee68b5cefe9222944aac5760ffc20"
117
+#define SQLITE_VERSION "3.8.9"
118
+#define SQLITE_VERSION_NUMBER 3008009
119
+#define SQLITE_SOURCE_ID "2015-03-24 18:19:39 436314b5728c9413f9ac2d837e1c19364f31be72"
113120
114121
/*
115122
** CAPI3REF: Run-Time Library Version Numbers
116123
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117124
**
@@ -754,18 +761,20 @@
754761
**
755762
** These integer constants are opcodes for the xFileControl method
756763
** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
757764
** interface.
758765
**
766
+** <ul>
767
+** <li>[[SQLITE_FCNTL_LOCKSTATE]]
759768
** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This
760769
** opcode causes the xFileControl method to write the current state of
761770
** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
762771
** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
763772
** into an integer that the pArg argument points to. This capability
764
-** is used during testing and only needs to be supported when SQLITE_TEST
765
-** is defined.
766
-** <ul>
773
+** is used during testing and is only available when the SQLITE_TEST
774
+** compile-time option is used.
775
+**
767776
** <li>[[SQLITE_FCNTL_SIZE_HINT]]
768777
** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
769778
** layer a hint of how large the database file will grow to be during the
770779
** current transaction. This hint is not guaranteed to be accurate but it
771780
** is often close. The underlying VFS might choose to preallocate database
@@ -886,11 +895,13 @@
886895
** the error message if the pragma fails. ^If the
887896
** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal
888897
** [PRAGMA] processing continues. ^If the [SQLITE_FCNTL_PRAGMA]
889898
** file control returns [SQLITE_OK], then the parser assumes that the
890899
** VFS has handled the PRAGMA itself and the parser generates a no-op
891
-** prepared statement. ^If the [SQLITE_FCNTL_PRAGMA] file control returns
900
+** prepared statement if result string is NULL, or that returns a copy
901
+** of the result string if the string is non-NULL.
902
+** ^If the [SQLITE_FCNTL_PRAGMA] file control returns
892903
** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means
893904
** that the VFS encountered an error while handling the [PRAGMA] and the
894905
** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA]
895906
** file control occurs at the beginning of pragma statement analysis and so
896907
** it is able to override built-in [PRAGMA] statements.
@@ -944,10 +955,17 @@
944955
** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This
945956
** opcode causes the xFileControl method to swap the file handle with the one
946957
** pointed to by the pArg argument. This capability is used during testing
947958
** and only needs to be supported when SQLITE_TEST is defined.
948959
**
960
+** <li>[[SQLITE_FCNTL_WAL_BLOCK]]
961
+** The [SQLITE_FCNTL_WAL_BLOCK] is a signal to the VFS layer that it might
962
+** be advantageous to block on the next WAL lock if the lock is not immediately
963
+** available. The WAL subsystem issues this signal during rare
964
+** circumstances in order to fix a problem with priority inversion.
965
+** Applications should <em>not</em> use this file-control.
966
+**
949967
** </ul>
950968
*/
951969
#define SQLITE_FCNTL_LOCKSTATE 1
952970
#define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
953971
#define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
@@ -968,10 +986,11 @@
968986
#define SQLITE_FCNTL_TRACE 19
969987
#define SQLITE_FCNTL_HAS_MOVED 20
970988
#define SQLITE_FCNTL_SYNC 21
971989
#define SQLITE_FCNTL_COMMIT_PHASETWO 22
972990
#define SQLITE_FCNTL_WIN32_SET_HANDLE 23
991
+#define SQLITE_FCNTL_WAL_BLOCK 24
973992
974993
/* deprecated names */
975994
#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
976995
#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
977996
#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -1534,11 +1553,11 @@
15341553
** disabled, the following SQLite interfaces become non-operational:
15351554
** <ul>
15361555
** <li> [sqlite3_memory_used()]
15371556
** <li> [sqlite3_memory_highwater()]
15381557
** <li> [sqlite3_soft_heap_limit64()]
1539
-** <li> [sqlite3_status()]
1558
+** <li> [sqlite3_status64()]
15401559
** </ul>)^
15411560
** ^Memory allocation statistics are enabled by default unless SQLite is
15421561
** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
15431562
** allocation statistics are disabled by default.
15441563
** </dd>
@@ -1745,11 +1764,10 @@
17451764
** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
17461765
** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is
17471766
** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro
17481767
** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
17491768
** that specifies the maximum size of the created heap.
1750
-** </dl>
17511769
**
17521770
** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
17531771
** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
17541772
** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
17551773
** is a pointer to an integer and writes into that integer the number of extra
@@ -2992,15 +3010,17 @@
29923010
29933011
29943012
/*
29953013
** CAPI3REF: Error Codes And Messages
29963014
**
2997
-** ^The sqlite3_errcode() interface returns the numeric [result code] or
2998
-** [extended result code] for the most recent failed sqlite3_* API call
2999
-** associated with a [database connection]. If a prior API call failed
3000
-** but the most recent API call succeeded, the return value from
3001
-** sqlite3_errcode() is undefined. ^The sqlite3_extended_errcode()
3015
+** ^If the most recent sqlite3_* API call associated with
3016
+** [database connection] D failed, then the sqlite3_errcode(D) interface
3017
+** returns the numeric [result code] or [extended result code] for that
3018
+** API call.
3019
+** If the most recent API call was successful,
3020
+** then the return value from sqlite3_errcode() is undefined.
3021
+** ^The sqlite3_extended_errcode()
30023022
** interface is the same except that it always returns the
30033023
** [extended result code] even when extended result codes are
30043024
** disabled.
30053025
**
30063026
** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
@@ -3185,20 +3205,18 @@
31853205
** The second argument, "zSql", is the statement to be compiled, encoded
31863206
** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2()
31873207
** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2()
31883208
** use UTF-16.
31893209
**
3190
-** ^If the nByte argument is less than zero, then zSql is read up to the
3191
-** first zero terminator. ^If nByte is non-negative, then it is the maximum
3192
-** number of bytes read from zSql. ^When nByte is non-negative, the
3193
-** zSql string ends at either the first '\000' or '\u0000' character or
3194
-** the nByte-th byte, whichever comes first. If the caller knows
3195
-** that the supplied string is nul-terminated, then there is a small
3196
-** performance advantage to be gained by passing an nByte parameter that
3197
-** is equal to the number of bytes in the input string <i>including</i>
3198
-** the nul-terminator bytes as this saves SQLite from having to
3199
-** make a copy of the input string.
3210
+** ^If the nByte argument is negative, then zSql is read up to the
3211
+** first zero terminator. ^If nByte is positive, then it is the
3212
+** number of bytes read from zSql. ^If nByte is zero, then no prepared
3213
+** statement is generated.
3214
+** If the caller knows that the supplied string is nul-terminated, then
3215
+** there is a small performance advantage to passing an nByte parameter that
3216
+** is the number of bytes in the input string <i>including</i>
3217
+** the nul-terminator.
32003218
**
32013219
** ^If pzTail is not NULL then *pzTail is made to point to the first byte
32023220
** past the end of the first SQL statement in zSql. These routines only
32033221
** compile the first statement in zSql, so *pzTail is left pointing to
32043222
** what remains uncompiled.
@@ -4223,12 +4241,12 @@
42234241
** DEPRECATED
42244242
**
42254243
** These functions are [deprecated]. In order to maintain
42264244
** backwards compatibility with older code, these functions continue
42274245
** to be supported. However, new applications should avoid
4228
-** the use of these functions. To help encourage people to avoid
4229
-** using these functions, we are not going to tell you what they do.
4246
+** the use of these functions. To encourage programmers to avoid
4247
+** these functions, we will not explain what they do.
42304248
*/
42314249
#ifndef SQLITE_OMIT_DEPRECATED
42324250
SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
42334251
SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
42344252
SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
@@ -5612,11 +5630,11 @@
56125630
** is delivered up to the client application, the string will be automatically
56135631
** freed by sqlite3_free() and the zErrMsg field will be zeroed.
56145632
*/
56155633
struct sqlite3_vtab {
56165634
const sqlite3_module *pModule; /* The module for this virtual table */
5617
- int nRef; /* NO LONGER USED */
5635
+ int nRef; /* Number of open cursors */
56185636
char *zErrMsg; /* Error message from sqlite3_mprintf() */
56195637
/* Virtual table implementations will typically add additional fields */
56205638
};
56215639
56225640
/*
@@ -6290,11 +6308,11 @@
62906308
#define SQLITE_TESTCTRL_LAST 25
62916309
62926310
/*
62936311
** CAPI3REF: SQLite Runtime Status
62946312
**
6295
-** ^This interface is used to retrieve runtime status information
6313
+** ^These interfaces are used to retrieve runtime status information
62966314
** about the performance of SQLite, and optionally to reset various
62976315
** highwater marks. ^The first argument is an integer code for
62986316
** the specific parameter to measure. ^(Recognized integer codes
62996317
** are of the form [status parameters | SQLITE_STATUS_...].)^
63006318
** ^The current value of the parameter is returned into *pCurrent.
@@ -6304,23 +6322,26 @@
63046322
** value. For those parameters
63056323
** nothing is written into *pHighwater and the resetFlag is ignored.)^
63066324
** ^(Other parameters record only the highwater mark and not the current
63076325
** value. For these latter parameters nothing is written into *pCurrent.)^
63086326
**
6309
-** ^The sqlite3_status() routine returns SQLITE_OK on success and a
6310
-** non-zero [error code] on failure.
6327
+** ^The sqlite3_status() and sqlite3_status64() routines return
6328
+** SQLITE_OK on success and a non-zero [error code] on failure.
63116329
**
6312
-** This routine is threadsafe but is not atomic. This routine can be
6313
-** called while other threads are running the same or different SQLite
6314
-** interfaces. However the values returned in *pCurrent and
6315
-** *pHighwater reflect the status of SQLite at different points in time
6316
-** and it is possible that another thread might change the parameter
6317
-** in between the times when *pCurrent and *pHighwater are written.
6330
+** If either the current value or the highwater mark is too large to
6331
+** be represented by a 32-bit integer, then the values returned by
6332
+** sqlite3_status() are undefined.
63186333
**
63196334
** See also: [sqlite3_db_status()]
63206335
*/
63216336
SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
6337
+SQLITE_API int sqlite3_status64(
6338
+ int op,
6339
+ sqlite3_int64 *pCurrent,
6340
+ sqlite3_int64 *pHighwater,
6341
+ int resetFlag
6342
+);
63226343
63236344
63246345
/*
63256346
** CAPI3REF: Status Parameters
63266347
** KEYWORDS: {status parameters}
@@ -6986,24 +7007,24 @@
69867007
**
69877008
** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
69887009
** is not a permanent error and does not affect the return value of
69897010
** sqlite3_backup_finish().
69907011
**
6991
-** [[sqlite3_backup__remaining()]] [[sqlite3_backup_pagecount()]]
7012
+** [[sqlite3_backup_remaining()]] [[sqlite3_backup_pagecount()]]
69927013
** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b>
69937014
**
6994
-** ^Each call to sqlite3_backup_step() sets two values inside
6995
-** the [sqlite3_backup] object: the number of pages still to be backed
6996
-** up and the total number of pages in the source database file.
6997
-** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces
6998
-** retrieve these two values, respectively.
6999
-**
7000
-** ^The values returned by these functions are only updated by
7001
-** sqlite3_backup_step(). ^If the source database is modified during a backup
7002
-** operation, then the values are not updated to account for any extra
7003
-** pages that need to be updated or the size of the source database file
7004
-** changing.
7015
+** ^The sqlite3_backup_remaining() routine returns the number of pages still
7016
+** to be backed up at the conclusion of the most recent sqlite3_backup_step().
7017
+** ^The sqlite3_backup_pagecount() routine returns the total number of pages
7018
+** in the source database at the conclusion of the most recent
7019
+** sqlite3_backup_step().
7020
+** ^(The values returned by these functions are only updated by
7021
+** sqlite3_backup_step(). If the source database is modified in a way that
7022
+** changes the size of the source database or the number of pages remaining,
7023
+** those changes are not reflected in the output of sqlite3_backup_pagecount()
7024
+** and sqlite3_backup_remaining() until after the next
7025
+** sqlite3_backup_step().)^
70057026
**
70067027
** <b>Concurrent Usage of Database Handles</b>
70077028
**
70087029
** ^The source [database connection] may be used by the application for other
70097030
** purposes while a backup operation is underway or being initialized.
70107031
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -52,10 +52,17 @@
52 #ifndef SQLITE_API
53 # define SQLITE_API
54 #endif
55
56
 
 
 
 
 
 
 
57 /*
58 ** These no-op macros are used in front of interfaces to mark those
59 ** interfaces as either deprecated or experimental. New applications
60 ** should not use deprecated interfaces - they are supported for backwards
61 ** compatibility only. Application writers should be aware that
@@ -105,13 +112,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.8"
111 #define SQLITE_VERSION_NUMBER 3008008
112 #define SQLITE_SOURCE_ID "2015-02-25 14:25:31 6d132e7a224ee68b5cefe9222944aac5760ffc20"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -754,18 +761,20 @@
754 **
755 ** These integer constants are opcodes for the xFileControl method
756 ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
757 ** interface.
758 **
 
 
759 ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This
760 ** opcode causes the xFileControl method to write the current state of
761 ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
762 ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
763 ** into an integer that the pArg argument points to. This capability
764 ** is used during testing and only needs to be supported when SQLITE_TEST
765 ** is defined.
766 ** <ul>
767 ** <li>[[SQLITE_FCNTL_SIZE_HINT]]
768 ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
769 ** layer a hint of how large the database file will grow to be during the
770 ** current transaction. This hint is not guaranteed to be accurate but it
771 ** is often close. The underlying VFS might choose to preallocate database
@@ -886,11 +895,13 @@
886 ** the error message if the pragma fails. ^If the
887 ** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal
888 ** [PRAGMA] processing continues. ^If the [SQLITE_FCNTL_PRAGMA]
889 ** file control returns [SQLITE_OK], then the parser assumes that the
890 ** VFS has handled the PRAGMA itself and the parser generates a no-op
891 ** prepared statement. ^If the [SQLITE_FCNTL_PRAGMA] file control returns
 
 
892 ** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means
893 ** that the VFS encountered an error while handling the [PRAGMA] and the
894 ** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA]
895 ** file control occurs at the beginning of pragma statement analysis and so
896 ** it is able to override built-in [PRAGMA] statements.
@@ -944,10 +955,17 @@
944 ** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This
945 ** opcode causes the xFileControl method to swap the file handle with the one
946 ** pointed to by the pArg argument. This capability is used during testing
947 ** and only needs to be supported when SQLITE_TEST is defined.
948 **
 
 
 
 
 
 
 
949 ** </ul>
950 */
951 #define SQLITE_FCNTL_LOCKSTATE 1
952 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
953 #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
@@ -968,10 +986,11 @@
968 #define SQLITE_FCNTL_TRACE 19
969 #define SQLITE_FCNTL_HAS_MOVED 20
970 #define SQLITE_FCNTL_SYNC 21
971 #define SQLITE_FCNTL_COMMIT_PHASETWO 22
972 #define SQLITE_FCNTL_WIN32_SET_HANDLE 23
 
973
974 /* deprecated names */
975 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
976 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
977 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -1534,11 +1553,11 @@
1534 ** disabled, the following SQLite interfaces become non-operational:
1535 ** <ul>
1536 ** <li> [sqlite3_memory_used()]
1537 ** <li> [sqlite3_memory_highwater()]
1538 ** <li> [sqlite3_soft_heap_limit64()]
1539 ** <li> [sqlite3_status()]
1540 ** </ul>)^
1541 ** ^Memory allocation statistics are enabled by default unless SQLite is
1542 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1543 ** allocation statistics are disabled by default.
1544 ** </dd>
@@ -1745,11 +1764,10 @@
1745 ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
1746 ** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is
1747 ** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro
1748 ** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
1749 ** that specifies the maximum size of the created heap.
1750 ** </dl>
1751 **
1752 ** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
1753 ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
1754 ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
1755 ** is a pointer to an integer and writes into that integer the number of extra
@@ -2992,15 +3010,17 @@
2992
2993
2994 /*
2995 ** CAPI3REF: Error Codes And Messages
2996 **
2997 ** ^The sqlite3_errcode() interface returns the numeric [result code] or
2998 ** [extended result code] for the most recent failed sqlite3_* API call
2999 ** associated with a [database connection]. If a prior API call failed
3000 ** but the most recent API call succeeded, the return value from
3001 ** sqlite3_errcode() is undefined. ^The sqlite3_extended_errcode()
 
 
3002 ** interface is the same except that it always returns the
3003 ** [extended result code] even when extended result codes are
3004 ** disabled.
3005 **
3006 ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
@@ -3185,20 +3205,18 @@
3185 ** The second argument, "zSql", is the statement to be compiled, encoded
3186 ** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2()
3187 ** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2()
3188 ** use UTF-16.
3189 **
3190 ** ^If the nByte argument is less than zero, then zSql is read up to the
3191 ** first zero terminator. ^If nByte is non-negative, then it is the maximum
3192 ** number of bytes read from zSql. ^When nByte is non-negative, the
3193 ** zSql string ends at either the first '\000' or '\u0000' character or
3194 ** the nByte-th byte, whichever comes first. If the caller knows
3195 ** that the supplied string is nul-terminated, then there is a small
3196 ** performance advantage to be gained by passing an nByte parameter that
3197 ** is equal to the number of bytes in the input string <i>including</i>
3198 ** the nul-terminator bytes as this saves SQLite from having to
3199 ** make a copy of the input string.
3200 **
3201 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
3202 ** past the end of the first SQL statement in zSql. These routines only
3203 ** compile the first statement in zSql, so *pzTail is left pointing to
3204 ** what remains uncompiled.
@@ -4223,12 +4241,12 @@
4223 ** DEPRECATED
4224 **
4225 ** These functions are [deprecated]. In order to maintain
4226 ** backwards compatibility with older code, these functions continue
4227 ** to be supported. However, new applications should avoid
4228 ** the use of these functions. To help encourage people to avoid
4229 ** using these functions, we are not going to tell you what they do.
4230 */
4231 #ifndef SQLITE_OMIT_DEPRECATED
4232 SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
4233 SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
4234 SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
@@ -5612,11 +5630,11 @@
5612 ** is delivered up to the client application, the string will be automatically
5613 ** freed by sqlite3_free() and the zErrMsg field will be zeroed.
5614 */
5615 struct sqlite3_vtab {
5616 const sqlite3_module *pModule; /* The module for this virtual table */
5617 int nRef; /* NO LONGER USED */
5618 char *zErrMsg; /* Error message from sqlite3_mprintf() */
5619 /* Virtual table implementations will typically add additional fields */
5620 };
5621
5622 /*
@@ -6290,11 +6308,11 @@
6290 #define SQLITE_TESTCTRL_LAST 25
6291
6292 /*
6293 ** CAPI3REF: SQLite Runtime Status
6294 **
6295 ** ^This interface is used to retrieve runtime status information
6296 ** about the performance of SQLite, and optionally to reset various
6297 ** highwater marks. ^The first argument is an integer code for
6298 ** the specific parameter to measure. ^(Recognized integer codes
6299 ** are of the form [status parameters | SQLITE_STATUS_...].)^
6300 ** ^The current value of the parameter is returned into *pCurrent.
@@ -6304,23 +6322,26 @@
6304 ** value. For those parameters
6305 ** nothing is written into *pHighwater and the resetFlag is ignored.)^
6306 ** ^(Other parameters record only the highwater mark and not the current
6307 ** value. For these latter parameters nothing is written into *pCurrent.)^
6308 **
6309 ** ^The sqlite3_status() routine returns SQLITE_OK on success and a
6310 ** non-zero [error code] on failure.
6311 **
6312 ** This routine is threadsafe but is not atomic. This routine can be
6313 ** called while other threads are running the same or different SQLite
6314 ** interfaces. However the values returned in *pCurrent and
6315 ** *pHighwater reflect the status of SQLite at different points in time
6316 ** and it is possible that another thread might change the parameter
6317 ** in between the times when *pCurrent and *pHighwater are written.
6318 **
6319 ** See also: [sqlite3_db_status()]
6320 */
6321 SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
 
 
 
 
 
 
6322
6323
6324 /*
6325 ** CAPI3REF: Status Parameters
6326 ** KEYWORDS: {status parameters}
@@ -6986,24 +7007,24 @@
6986 **
6987 ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
6988 ** is not a permanent error and does not affect the return value of
6989 ** sqlite3_backup_finish().
6990 **
6991 ** [[sqlite3_backup__remaining()]] [[sqlite3_backup_pagecount()]]
6992 ** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b>
6993 **
6994 ** ^Each call to sqlite3_backup_step() sets two values inside
6995 ** the [sqlite3_backup] object: the number of pages still to be backed
6996 ** up and the total number of pages in the source database file.
6997 ** The sqlite3_backup_remaining() and sqlite3_backup_pagecount() interfaces
6998 ** retrieve these two values, respectively.
6999 **
7000 ** ^The values returned by these functions are only updated by
7001 ** sqlite3_backup_step(). ^If the source database is modified during a backup
7002 ** operation, then the values are not updated to account for any extra
7003 ** pages that need to be updated or the size of the source database file
7004 ** changing.
7005 **
7006 ** <b>Concurrent Usage of Database Handles</b>
7007 **
7008 ** ^The source [database connection] may be used by the application for other
7009 ** purposes while a backup operation is underway or being initialized.
7010
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -52,10 +52,17 @@
52 #ifndef SQLITE_API
53 # define SQLITE_API
54 #endif
55
56
57 /*
58 ** Add the ability to override 'cdecl'
59 */
60 #ifndef SQLITE_CDECL
61 # define SQLITE_CDECL
62 #endif
63
64 /*
65 ** These no-op macros are used in front of interfaces to mark those
66 ** interfaces as either deprecated or experimental. New applications
67 ** should not use deprecated interfaces - they are supported for backwards
68 ** compatibility only. Application writers should be aware that
@@ -105,13 +112,13 @@
112 **
113 ** See also: [sqlite3_libversion()],
114 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
115 ** [sqlite_version()] and [sqlite_source_id()].
116 */
117 #define SQLITE_VERSION "3.8.9"
118 #define SQLITE_VERSION_NUMBER 3008009
119 #define SQLITE_SOURCE_ID "2015-03-24 18:19:39 436314b5728c9413f9ac2d837e1c19364f31be72"
120
121 /*
122 ** CAPI3REF: Run-Time Library Version Numbers
123 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
124 **
@@ -754,18 +761,20 @@
761 **
762 ** These integer constants are opcodes for the xFileControl method
763 ** of the [sqlite3_io_methods] object and for the [sqlite3_file_control()]
764 ** interface.
765 **
766 ** <ul>
767 ** <li>[[SQLITE_FCNTL_LOCKSTATE]]
768 ** The [SQLITE_FCNTL_LOCKSTATE] opcode is used for debugging. This
769 ** opcode causes the xFileControl method to write the current state of
770 ** the lock (one of [SQLITE_LOCK_NONE], [SQLITE_LOCK_SHARED],
771 ** [SQLITE_LOCK_RESERVED], [SQLITE_LOCK_PENDING], or [SQLITE_LOCK_EXCLUSIVE])
772 ** into an integer that the pArg argument points to. This capability
773 ** is used during testing and is only available when the SQLITE_TEST
774 ** compile-time option is used.
775 **
776 ** <li>[[SQLITE_FCNTL_SIZE_HINT]]
777 ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
778 ** layer a hint of how large the database file will grow to be during the
779 ** current transaction. This hint is not guaranteed to be accurate but it
780 ** is often close. The underlying VFS might choose to preallocate database
@@ -886,11 +895,13 @@
895 ** the error message if the pragma fails. ^If the
896 ** [SQLITE_FCNTL_PRAGMA] file control returns [SQLITE_NOTFOUND], then normal
897 ** [PRAGMA] processing continues. ^If the [SQLITE_FCNTL_PRAGMA]
898 ** file control returns [SQLITE_OK], then the parser assumes that the
899 ** VFS has handled the PRAGMA itself and the parser generates a no-op
900 ** prepared statement if result string is NULL, or that returns a copy
901 ** of the result string if the string is non-NULL.
902 ** ^If the [SQLITE_FCNTL_PRAGMA] file control returns
903 ** any result code other than [SQLITE_OK] or [SQLITE_NOTFOUND], that means
904 ** that the VFS encountered an error while handling the [PRAGMA] and the
905 ** compilation of the PRAGMA fails with an error. ^The [SQLITE_FCNTL_PRAGMA]
906 ** file control occurs at the beginning of pragma statement analysis and so
907 ** it is able to override built-in [PRAGMA] statements.
@@ -944,10 +955,17 @@
955 ** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This
956 ** opcode causes the xFileControl method to swap the file handle with the one
957 ** pointed to by the pArg argument. This capability is used during testing
958 ** and only needs to be supported when SQLITE_TEST is defined.
959 **
960 ** <li>[[SQLITE_FCNTL_WAL_BLOCK]]
961 ** The [SQLITE_FCNTL_WAL_BLOCK] is a signal to the VFS layer that it might
962 ** be advantageous to block on the next WAL lock if the lock is not immediately
963 ** available. The WAL subsystem issues this signal during rare
964 ** circumstances in order to fix a problem with priority inversion.
965 ** Applications should <em>not</em> use this file-control.
966 **
967 ** </ul>
968 */
969 #define SQLITE_FCNTL_LOCKSTATE 1
970 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
971 #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
@@ -968,10 +986,11 @@
986 #define SQLITE_FCNTL_TRACE 19
987 #define SQLITE_FCNTL_HAS_MOVED 20
988 #define SQLITE_FCNTL_SYNC 21
989 #define SQLITE_FCNTL_COMMIT_PHASETWO 22
990 #define SQLITE_FCNTL_WIN32_SET_HANDLE 23
991 #define SQLITE_FCNTL_WAL_BLOCK 24
992
993 /* deprecated names */
994 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
995 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
996 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -1534,11 +1553,11 @@
1553 ** disabled, the following SQLite interfaces become non-operational:
1554 ** <ul>
1555 ** <li> [sqlite3_memory_used()]
1556 ** <li> [sqlite3_memory_highwater()]
1557 ** <li> [sqlite3_soft_heap_limit64()]
1558 ** <li> [sqlite3_status64()]
1559 ** </ul>)^
1560 ** ^Memory allocation statistics are enabled by default unless SQLite is
1561 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1562 ** allocation statistics are disabled by default.
1563 ** </dd>
@@ -1745,11 +1764,10 @@
1764 ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
1765 ** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is
1766 ** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro
1767 ** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
1768 ** that specifies the maximum size of the created heap.
 
1769 **
1770 ** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
1771 ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
1772 ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
1773 ** is a pointer to an integer and writes into that integer the number of extra
@@ -2992,15 +3010,17 @@
3010
3011
3012 /*
3013 ** CAPI3REF: Error Codes And Messages
3014 **
3015 ** ^If the most recent sqlite3_* API call associated with
3016 ** [database connection] D failed, then the sqlite3_errcode(D) interface
3017 ** returns the numeric [result code] or [extended result code] for that
3018 ** API call.
3019 ** If the most recent API call was successful,
3020 ** then the return value from sqlite3_errcode() is undefined.
3021 ** ^The sqlite3_extended_errcode()
3022 ** interface is the same except that it always returns the
3023 ** [extended result code] even when extended result codes are
3024 ** disabled.
3025 **
3026 ** ^The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
@@ -3185,20 +3205,18 @@
3205 ** The second argument, "zSql", is the statement to be compiled, encoded
3206 ** as either UTF-8 or UTF-16. The sqlite3_prepare() and sqlite3_prepare_v2()
3207 ** interfaces use UTF-8, and sqlite3_prepare16() and sqlite3_prepare16_v2()
3208 ** use UTF-16.
3209 **
3210 ** ^If the nByte argument is negative, then zSql is read up to the
3211 ** first zero terminator. ^If nByte is positive, then it is the
3212 ** number of bytes read from zSql. ^If nByte is zero, then no prepared
3213 ** statement is generated.
3214 ** If the caller knows that the supplied string is nul-terminated, then
3215 ** there is a small performance advantage to passing an nByte parameter that
3216 ** is the number of bytes in the input string <i>including</i>
3217 ** the nul-terminator.
 
 
3218 **
3219 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
3220 ** past the end of the first SQL statement in zSql. These routines only
3221 ** compile the first statement in zSql, so *pzTail is left pointing to
3222 ** what remains uncompiled.
@@ -4223,12 +4241,12 @@
4241 ** DEPRECATED
4242 **
4243 ** These functions are [deprecated]. In order to maintain
4244 ** backwards compatibility with older code, these functions continue
4245 ** to be supported. However, new applications should avoid
4246 ** the use of these functions. To encourage programmers to avoid
4247 ** these functions, we will not explain what they do.
4248 */
4249 #ifndef SQLITE_OMIT_DEPRECATED
4250 SQLITE_API SQLITE_DEPRECATED int sqlite3_aggregate_count(sqlite3_context*);
4251 SQLITE_API SQLITE_DEPRECATED int sqlite3_expired(sqlite3_stmt*);
4252 SQLITE_API SQLITE_DEPRECATED int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
@@ -5612,11 +5630,11 @@
5630 ** is delivered up to the client application, the string will be automatically
5631 ** freed by sqlite3_free() and the zErrMsg field will be zeroed.
5632 */
5633 struct sqlite3_vtab {
5634 const sqlite3_module *pModule; /* The module for this virtual table */
5635 int nRef; /* Number of open cursors */
5636 char *zErrMsg; /* Error message from sqlite3_mprintf() */
5637 /* Virtual table implementations will typically add additional fields */
5638 };
5639
5640 /*
@@ -6290,11 +6308,11 @@
6308 #define SQLITE_TESTCTRL_LAST 25
6309
6310 /*
6311 ** CAPI3REF: SQLite Runtime Status
6312 **
6313 ** ^These interfaces are used to retrieve runtime status information
6314 ** about the performance of SQLite, and optionally to reset various
6315 ** highwater marks. ^The first argument is an integer code for
6316 ** the specific parameter to measure. ^(Recognized integer codes
6317 ** are of the form [status parameters | SQLITE_STATUS_...].)^
6318 ** ^The current value of the parameter is returned into *pCurrent.
@@ -6304,23 +6322,26 @@
6322 ** value. For those parameters
6323 ** nothing is written into *pHighwater and the resetFlag is ignored.)^
6324 ** ^(Other parameters record only the highwater mark and not the current
6325 ** value. For these latter parameters nothing is written into *pCurrent.)^
6326 **
6327 ** ^The sqlite3_status() and sqlite3_status64() routines return
6328 ** SQLITE_OK on success and a non-zero [error code] on failure.
6329 **
6330 ** If either the current value or the highwater mark is too large to
6331 ** be represented by a 32-bit integer, then the values returned by
6332 ** sqlite3_status() are undefined.
 
 
 
6333 **
6334 ** See also: [sqlite3_db_status()]
6335 */
6336 SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag);
6337 SQLITE_API int sqlite3_status64(
6338 int op,
6339 sqlite3_int64 *pCurrent,
6340 sqlite3_int64 *pHighwater,
6341 int resetFlag
6342 );
6343
6344
6345 /*
6346 ** CAPI3REF: Status Parameters
6347 ** KEYWORDS: {status parameters}
@@ -6986,24 +7007,24 @@
7007 **
7008 ** ^A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step()
7009 ** is not a permanent error and does not affect the return value of
7010 ** sqlite3_backup_finish().
7011 **
7012 ** [[sqlite3_backup_remaining()]] [[sqlite3_backup_pagecount()]]
7013 ** <b>sqlite3_backup_remaining() and sqlite3_backup_pagecount()</b>
7014 **
7015 ** ^The sqlite3_backup_remaining() routine returns the number of pages still
7016 ** to be backed up at the conclusion of the most recent sqlite3_backup_step().
7017 ** ^The sqlite3_backup_pagecount() routine returns the total number of pages
7018 ** in the source database at the conclusion of the most recent
7019 ** sqlite3_backup_step().
7020 ** ^(The values returned by these functions are only updated by
7021 ** sqlite3_backup_step(). If the source database is modified in a way that
7022 ** changes the size of the source database or the number of pages remaining,
7023 ** those changes are not reflected in the output of sqlite3_backup_pagecount()
7024 ** and sqlite3_backup_remaining() until after the next
7025 ** sqlite3_backup_step().)^
7026 **
7027 ** <b>Concurrent Usage of Database Handles</b>
7028 **
7029 ** ^The source [database connection] may be used by the application for other
7030 ** purposes while a backup operation is underway or being initialized.
7031
+28 -2
--- src/th_main.c
+++ src/th_main.c
@@ -1833,10 +1833,16 @@
18331833
** Make sure that the TH1 script error was not caused by a "missing"
18341834
** command hook handler as that is not actually an error condition.
18351835
*/
18361836
if( memcmp(zResult, NO_COMMAND_HOOK_ERROR, nResult)!=0 ){
18371837
sendError(zResult, nResult, 0);
1838
+ }else{
1839
+ /*
1840
+ ** There is no command hook handler "installed". This situation
1841
+ ** is NOT actually an error.
1842
+ */
1843
+ rc = TH_OK;
18381844
}
18391845
}
18401846
/*
18411847
** If the script returned TH_ERROR (e.g. the "command_hook" TH1 command does
18421848
** not exist because commands are not being hooked), return TH_OK because we
@@ -1853,11 +1859,11 @@
18531859
** clean it up now. This is very important because some commands do not
18541860
** expect the repository and/or the configuration ("user") database to be
18551861
** open prior to their own code doing so.
18561862
*/
18571863
if( TH_INIT_HOOK & TH_INIT_NEED_CONFIG ) Th_CloseConfig(1);
1858
- return (rc != TH_ERROR) ? rc : TH_OK;
1864
+ return rc;
18591865
}
18601866
18611867
/*
18621868
** This function is called by Fossil just after dispatching a command.
18631869
** Returning a value other than TH_OK from this function (i.e. via an
@@ -1914,10 +1920,16 @@
19141920
** Make sure that the TH1 script error was not caused by a "missing"
19151921
** webpage hook handler as that is not actually an error condition.
19161922
*/
19171923
if( memcmp(zResult, NO_WEBPAGE_HOOK_ERROR, nResult)!=0 ){
19181924
sendError(zResult, nResult, 1);
1925
+ }else{
1926
+ /*
1927
+ ** There is no webpage hook handler "installed". This situation
1928
+ ** is NOT actually an error.
1929
+ */
1930
+ rc = TH_OK;
19191931
}
19201932
}
19211933
/*
19221934
** If the script returned TH_ERROR (e.g. the "webpage_hook" TH1 command does
19231935
** not exist because commands are not being hooked), return TH_OK because we
@@ -1934,11 +1946,11 @@
19341946
** clean it up now. This is very important because some commands do not
19351947
** expect the repository and/or the configuration ("user") database to be
19361948
** open prior to their own code doing so.
19371949
*/
19381950
if( TH_INIT_HOOK & TH_INIT_NEED_CONFIG ) Th_CloseConfig(1);
1939
- return (rc != TH_ERROR) ? rc : TH_OK;
1951
+ return rc;
19401952
}
19411953
19421954
/*
19431955
** This function is called by Fossil just after processing a web page.
19441956
** Returning a value other than TH_OK from this function (i.e. via an
@@ -1969,10 +1981,24 @@
19691981
*/
19701982
if( TH_INIT_HOOK & TH_INIT_NEED_CONFIG ) Th_CloseConfig(1);
19711983
return rc;
19721984
}
19731985
#endif
1986
+
1987
+
1988
+#ifdef FOSSIL_ENABLE_TH1_DOCS
1989
+/*
1990
+** This function determines if TH1 docs are enabled for the repository.
1991
+*/
1992
+int Th_AreDocsEnabled(void){
1993
+ if( fossil_getenv("TH1_ENABLE_DOCS")!=0 ){
1994
+ return 1;
1995
+ }
1996
+ return db_get_boolean("th1-docs", 0);
1997
+}
1998
+#endif
1999
+
19742000
19752001
/*
19762002
** The z[] input contains text mixed with TH1 scripts.
19772003
** The TH1 scripts are contained within <th1>...</th1>.
19782004
** TH1 variables are $aaa or $<aaa>. The first form of
19792005
--- src/th_main.c
+++ src/th_main.c
@@ -1833,10 +1833,16 @@
1833 ** Make sure that the TH1 script error was not caused by a "missing"
1834 ** command hook handler as that is not actually an error condition.
1835 */
1836 if( memcmp(zResult, NO_COMMAND_HOOK_ERROR, nResult)!=0 ){
1837 sendError(zResult, nResult, 0);
 
 
 
 
 
 
1838 }
1839 }
1840 /*
1841 ** If the script returned TH_ERROR (e.g. the "command_hook" TH1 command does
1842 ** not exist because commands are not being hooked), return TH_OK because we
@@ -1853,11 +1859,11 @@
1853 ** clean it up now. This is very important because some commands do not
1854 ** expect the repository and/or the configuration ("user") database to be
1855 ** open prior to their own code doing so.
1856 */
1857 if( TH_INIT_HOOK & TH_INIT_NEED_CONFIG ) Th_CloseConfig(1);
1858 return (rc != TH_ERROR) ? rc : TH_OK;
1859 }
1860
1861 /*
1862 ** This function is called by Fossil just after dispatching a command.
1863 ** Returning a value other than TH_OK from this function (i.e. via an
@@ -1914,10 +1920,16 @@
1914 ** Make sure that the TH1 script error was not caused by a "missing"
1915 ** webpage hook handler as that is not actually an error condition.
1916 */
1917 if( memcmp(zResult, NO_WEBPAGE_HOOK_ERROR, nResult)!=0 ){
1918 sendError(zResult, nResult, 1);
 
 
 
 
 
 
1919 }
1920 }
1921 /*
1922 ** If the script returned TH_ERROR (e.g. the "webpage_hook" TH1 command does
1923 ** not exist because commands are not being hooked), return TH_OK because we
@@ -1934,11 +1946,11 @@
1934 ** clean it up now. This is very important because some commands do not
1935 ** expect the repository and/or the configuration ("user") database to be
1936 ** open prior to their own code doing so.
1937 */
1938 if( TH_INIT_HOOK & TH_INIT_NEED_CONFIG ) Th_CloseConfig(1);
1939 return (rc != TH_ERROR) ? rc : TH_OK;
1940 }
1941
1942 /*
1943 ** This function is called by Fossil just after processing a web page.
1944 ** Returning a value other than TH_OK from this function (i.e. via an
@@ -1969,10 +1981,24 @@
1969 */
1970 if( TH_INIT_HOOK & TH_INIT_NEED_CONFIG ) Th_CloseConfig(1);
1971 return rc;
1972 }
1973 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1974
1975 /*
1976 ** The z[] input contains text mixed with TH1 scripts.
1977 ** The TH1 scripts are contained within <th1>...</th1>.
1978 ** TH1 variables are $aaa or $<aaa>. The first form of
1979
--- src/th_main.c
+++ src/th_main.c
@@ -1833,10 +1833,16 @@
1833 ** Make sure that the TH1 script error was not caused by a "missing"
1834 ** command hook handler as that is not actually an error condition.
1835 */
1836 if( memcmp(zResult, NO_COMMAND_HOOK_ERROR, nResult)!=0 ){
1837 sendError(zResult, nResult, 0);
1838 }else{
1839 /*
1840 ** There is no command hook handler "installed". This situation
1841 ** is NOT actually an error.
1842 */
1843 rc = TH_OK;
1844 }
1845 }
1846 /*
1847 ** If the script returned TH_ERROR (e.g. the "command_hook" TH1 command does
1848 ** not exist because commands are not being hooked), return TH_OK because we
@@ -1853,11 +1859,11 @@
1859 ** clean it up now. This is very important because some commands do not
1860 ** expect the repository and/or the configuration ("user") database to be
1861 ** open prior to their own code doing so.
1862 */
1863 if( TH_INIT_HOOK & TH_INIT_NEED_CONFIG ) Th_CloseConfig(1);
1864 return rc;
1865 }
1866
1867 /*
1868 ** This function is called by Fossil just after dispatching a command.
1869 ** Returning a value other than TH_OK from this function (i.e. via an
@@ -1914,10 +1920,16 @@
1920 ** Make sure that the TH1 script error was not caused by a "missing"
1921 ** webpage hook handler as that is not actually an error condition.
1922 */
1923 if( memcmp(zResult, NO_WEBPAGE_HOOK_ERROR, nResult)!=0 ){
1924 sendError(zResult, nResult, 1);
1925 }else{
1926 /*
1927 ** There is no webpage hook handler "installed". This situation
1928 ** is NOT actually an error.
1929 */
1930 rc = TH_OK;
1931 }
1932 }
1933 /*
1934 ** If the script returned TH_ERROR (e.g. the "webpage_hook" TH1 command does
1935 ** not exist because commands are not being hooked), return TH_OK because we
@@ -1934,11 +1946,11 @@
1946 ** clean it up now. This is very important because some commands do not
1947 ** expect the repository and/or the configuration ("user") database to be
1948 ** open prior to their own code doing so.
1949 */
1950 if( TH_INIT_HOOK & TH_INIT_NEED_CONFIG ) Th_CloseConfig(1);
1951 return rc;
1952 }
1953
1954 /*
1955 ** This function is called by Fossil just after processing a web page.
1956 ** Returning a value other than TH_OK from this function (i.e. via an
@@ -1969,10 +1981,24 @@
1981 */
1982 if( TH_INIT_HOOK & TH_INIT_NEED_CONFIG ) Th_CloseConfig(1);
1983 return rc;
1984 }
1985 #endif
1986
1987
1988 #ifdef FOSSIL_ENABLE_TH1_DOCS
1989 /*
1990 ** This function determines if TH1 docs are enabled for the repository.
1991 */
1992 int Th_AreDocsEnabled(void){
1993 if( fossil_getenv("TH1_ENABLE_DOCS")!=0 ){
1994 return 1;
1995 }
1996 return db_get_boolean("th1-docs", 0);
1997 }
1998 #endif
1999
2000
2001 /*
2002 ** The z[] input contains text mixed with TH1 scripts.
2003 ** The TH1 scripts are contained within <th1>...</th1>.
2004 ** TH1 variables are $aaa or $<aaa>. The first form of
2005
+28 -10
--- src/timeline.c
+++ src/timeline.c
@@ -1458,11 +1458,11 @@
14581458
if( (tmFlags & TIMELINE_UNHIDE)==0 ){
14591459
timeline_submenu(&url, "Unhide", "unhide", "", 0);
14601460
}
14611461
}else{
14621462
/* Otherwise, a timeline based on a span of time */
1463
- int n;
1463
+ int n, nBefore, nAfter;
14641464
const char *zEType = "timeline item";
14651465
char *zDate;
14661466
if( zUses ){
14671467
blob_append_sql(&sql, " AND event.objid IN usesfile ");
14681468
}
@@ -1666,20 +1666,38 @@
16661666
}
16671667
if( zSearch ){
16681668
blob_appendf(&desc, " matching \"%h\"", zSearch);
16691669
}
16701670
if( g.perm.Hyperlink ){
1671
- if( zAfter || n==nEntry ){
1671
+ if( zCirca && rCirca ){
1672
+ nBefore = db_int(0,
1673
+ "SELECT count(*) FROM timeline WHERE etype!='div'"
1674
+ " AND sortby<=%f /*scan*/", rCirca);
1675
+ nAfter = db_int(0,
1676
+ "SELECT count(*) FROM timeline WHERE etype!='div'"
1677
+ " AND sortby>=%f /*scan*/", rCirca);
16721678
zDate = db_text(0, "SELECT min(timestamp) FROM timeline /*scan*/");
1673
- timeline_submenu(&url, "Older", "b", zDate, "a");
1674
- zOlderButton = fossil_strdup(url_render(&url, "b", zDate, "a", 0));
1675
- free(zDate);
1676
- }
1677
- if( zBefore || (zAfter && n==nEntry) ){
1678
- zDate = db_text(0, "SELECT max(timestamp) FROM timeline /*scan*/");
1679
- timeline_submenu(&url, "Newer", "a", zDate, "b");
1680
- free(zDate);
1679
+ if( nBefore>=nEntry ){
1680
+ timeline_submenu(&url, "Older", "b", zDate, "c");
1681
+ zOlderButton = fossil_strdup(url_render(&url, "b", zDate, "c", 0));
1682
+ }
1683
+ if( nAfter>=nEntry ){
1684
+ timeline_submenu(&url, "Newer", "a", zDate, "c");
1685
+ }
1686
+ free(zDate);
1687
+ }else{
1688
+ if( zAfter || n==nEntry ){
1689
+ zDate = db_text(0, "SELECT min(timestamp) FROM timeline /*scan*/");
1690
+ timeline_submenu(&url, "Older", "b", zDate, "a");
1691
+ zOlderButton = fossil_strdup(url_render(&url, "b", zDate, "a", 0));
1692
+ free(zDate);
1693
+ }
1694
+ if( zBefore || (zAfter && n==nEntry) ){
1695
+ zDate = db_text(0, "SELECT max(timestamp) FROM timeline /*scan*/");
1696
+ timeline_submenu(&url, "Newer", "a", zDate, "b");
1697
+ free(zDate);
1698
+ }
16811699
}
16821700
if( zType[0]=='a' || zType[0]=='c' ){
16831701
if( (tmFlags & TIMELINE_UNHIDE)==0 ){
16841702
timeline_submenu(&url, "Unhide", "unhide", "", 0);
16851703
}
16861704
--- src/timeline.c
+++ src/timeline.c
@@ -1458,11 +1458,11 @@
1458 if( (tmFlags & TIMELINE_UNHIDE)==0 ){
1459 timeline_submenu(&url, "Unhide", "unhide", "", 0);
1460 }
1461 }else{
1462 /* Otherwise, a timeline based on a span of time */
1463 int n;
1464 const char *zEType = "timeline item";
1465 char *zDate;
1466 if( zUses ){
1467 blob_append_sql(&sql, " AND event.objid IN usesfile ");
1468 }
@@ -1666,20 +1666,38 @@
1666 }
1667 if( zSearch ){
1668 blob_appendf(&desc, " matching \"%h\"", zSearch);
1669 }
1670 if( g.perm.Hyperlink ){
1671 if( zAfter || n==nEntry ){
 
 
 
 
 
 
1672 zDate = db_text(0, "SELECT min(timestamp) FROM timeline /*scan*/");
1673 timeline_submenu(&url, "Older", "b", zDate, "a");
1674 zOlderButton = fossil_strdup(url_render(&url, "b", zDate, "a", 0));
1675 free(zDate);
1676 }
1677 if( zBefore || (zAfter && n==nEntry) ){
1678 zDate = db_text(0, "SELECT max(timestamp) FROM timeline /*scan*/");
1679 timeline_submenu(&url, "Newer", "a", zDate, "b");
1680 free(zDate);
 
 
 
 
 
 
 
 
 
 
 
 
1681 }
1682 if( zType[0]=='a' || zType[0]=='c' ){
1683 if( (tmFlags & TIMELINE_UNHIDE)==0 ){
1684 timeline_submenu(&url, "Unhide", "unhide", "", 0);
1685 }
1686
--- src/timeline.c
+++ src/timeline.c
@@ -1458,11 +1458,11 @@
1458 if( (tmFlags & TIMELINE_UNHIDE)==0 ){
1459 timeline_submenu(&url, "Unhide", "unhide", "", 0);
1460 }
1461 }else{
1462 /* Otherwise, a timeline based on a span of time */
1463 int n, nBefore, nAfter;
1464 const char *zEType = "timeline item";
1465 char *zDate;
1466 if( zUses ){
1467 blob_append_sql(&sql, " AND event.objid IN usesfile ");
1468 }
@@ -1666,20 +1666,38 @@
1666 }
1667 if( zSearch ){
1668 blob_appendf(&desc, " matching \"%h\"", zSearch);
1669 }
1670 if( g.perm.Hyperlink ){
1671 if( zCirca && rCirca ){
1672 nBefore = db_int(0,
1673 "SELECT count(*) FROM timeline WHERE etype!='div'"
1674 " AND sortby<=%f /*scan*/", rCirca);
1675 nAfter = db_int(0,
1676 "SELECT count(*) FROM timeline WHERE etype!='div'"
1677 " AND sortby>=%f /*scan*/", rCirca);
1678 zDate = db_text(0, "SELECT min(timestamp) FROM timeline /*scan*/");
1679 if( nBefore>=nEntry ){
1680 timeline_submenu(&url, "Older", "b", zDate, "c");
1681 zOlderButton = fossil_strdup(url_render(&url, "b", zDate, "c", 0));
1682 }
1683 if( nAfter>=nEntry ){
1684 timeline_submenu(&url, "Newer", "a", zDate, "c");
1685 }
1686 free(zDate);
1687 }else{
1688 if( zAfter || n==nEntry ){
1689 zDate = db_text(0, "SELECT min(timestamp) FROM timeline /*scan*/");
1690 timeline_submenu(&url, "Older", "b", zDate, "a");
1691 zOlderButton = fossil_strdup(url_render(&url, "b", zDate, "a", 0));
1692 free(zDate);
1693 }
1694 if( zBefore || (zAfter && n==nEntry) ){
1695 zDate = db_text(0, "SELECT max(timestamp) FROM timeline /*scan*/");
1696 timeline_submenu(&url, "Newer", "a", zDate, "b");
1697 free(zDate);
1698 }
1699 }
1700 if( zType[0]=='a' || zType[0]=='c' ){
1701 if( (tmFlags & TIMELINE_UNHIDE)==0 ){
1702 timeline_submenu(&url, "Unhide", "unhide", "", 0);
1703 }
1704
+28 -10
--- src/timeline.c
+++ src/timeline.c
@@ -1458,11 +1458,11 @@
14581458
if( (tmFlags & TIMELINE_UNHIDE)==0 ){
14591459
timeline_submenu(&url, "Unhide", "unhide", "", 0);
14601460
}
14611461
}else{
14621462
/* Otherwise, a timeline based on a span of time */
1463
- int n;
1463
+ int n, nBefore, nAfter;
14641464
const char *zEType = "timeline item";
14651465
char *zDate;
14661466
if( zUses ){
14671467
blob_append_sql(&sql, " AND event.objid IN usesfile ");
14681468
}
@@ -1666,20 +1666,38 @@
16661666
}
16671667
if( zSearch ){
16681668
blob_appendf(&desc, " matching \"%h\"", zSearch);
16691669
}
16701670
if( g.perm.Hyperlink ){
1671
- if( zAfter || n==nEntry ){
1671
+ if( zCirca && rCirca ){
1672
+ nBefore = db_int(0,
1673
+ "SELECT count(*) FROM timeline WHERE etype!='div'"
1674
+ " AND sortby<=%f /*scan*/", rCirca);
1675
+ nAfter = db_int(0,
1676
+ "SELECT count(*) FROM timeline WHERE etype!='div'"
1677
+ " AND sortby>=%f /*scan*/", rCirca);
16721678
zDate = db_text(0, "SELECT min(timestamp) FROM timeline /*scan*/");
1673
- timeline_submenu(&url, "Older", "b", zDate, "a");
1674
- zOlderButton = fossil_strdup(url_render(&url, "b", zDate, "a", 0));
1675
- free(zDate);
1676
- }
1677
- if( zBefore || (zAfter && n==nEntry) ){
1678
- zDate = db_text(0, "SELECT max(timestamp) FROM timeline /*scan*/");
1679
- timeline_submenu(&url, "Newer", "a", zDate, "b");
1680
- free(zDate);
1679
+ if( nBefore>=nEntry ){
1680
+ timeline_submenu(&url, "Older", "b", zDate, "c");
1681
+ zOlderButton = fossil_strdup(url_render(&url, "b", zDate, "c", 0));
1682
+ }
1683
+ if( nAfter>=nEntry ){
1684
+ timeline_submenu(&url, "Newer", "a", zDate, "c");
1685
+ }
1686
+ free(zDate);
1687
+ }else{
1688
+ if( zAfter || n==nEntry ){
1689
+ zDate = db_text(0, "SELECT min(timestamp) FROM timeline /*scan*/");
1690
+ timeline_submenu(&url, "Older", "b", zDate, "a");
1691
+ zOlderButton = fossil_strdup(url_render(&url, "b", zDate, "a", 0));
1692
+ free(zDate);
1693
+ }
1694
+ if( zBefore || (zAfter && n==nEntry) ){
1695
+ zDate = db_text(0, "SELECT max(timestamp) FROM timeline /*scan*/");
1696
+ timeline_submenu(&url, "Newer", "a", zDate, "b");
1697
+ free(zDate);
1698
+ }
16811699
}
16821700
if( zType[0]=='a' || zType[0]=='c' ){
16831701
if( (tmFlags & TIMELINE_UNHIDE)==0 ){
16841702
timeline_submenu(&url, "Unhide", "unhide", "", 0);
16851703
}
16861704
--- src/timeline.c
+++ src/timeline.c
@@ -1458,11 +1458,11 @@
1458 if( (tmFlags & TIMELINE_UNHIDE)==0 ){
1459 timeline_submenu(&url, "Unhide", "unhide", "", 0);
1460 }
1461 }else{
1462 /* Otherwise, a timeline based on a span of time */
1463 int n;
1464 const char *zEType = "timeline item";
1465 char *zDate;
1466 if( zUses ){
1467 blob_append_sql(&sql, " AND event.objid IN usesfile ");
1468 }
@@ -1666,20 +1666,38 @@
1666 }
1667 if( zSearch ){
1668 blob_appendf(&desc, " matching \"%h\"", zSearch);
1669 }
1670 if( g.perm.Hyperlink ){
1671 if( zAfter || n==nEntry ){
 
 
 
 
 
 
1672 zDate = db_text(0, "SELECT min(timestamp) FROM timeline /*scan*/");
1673 timeline_submenu(&url, "Older", "b", zDate, "a");
1674 zOlderButton = fossil_strdup(url_render(&url, "b", zDate, "a", 0));
1675 free(zDate);
1676 }
1677 if( zBefore || (zAfter && n==nEntry) ){
1678 zDate = db_text(0, "SELECT max(timestamp) FROM timeline /*scan*/");
1679 timeline_submenu(&url, "Newer", "a", zDate, "b");
1680 free(zDate);
 
 
 
 
 
 
 
 
 
 
 
 
1681 }
1682 if( zType[0]=='a' || zType[0]=='c' ){
1683 if( (tmFlags & TIMELINE_UNHIDE)==0 ){
1684 timeline_submenu(&url, "Unhide", "unhide", "", 0);
1685 }
1686
--- src/timeline.c
+++ src/timeline.c
@@ -1458,11 +1458,11 @@
1458 if( (tmFlags & TIMELINE_UNHIDE)==0 ){
1459 timeline_submenu(&url, "Unhide", "unhide", "", 0);
1460 }
1461 }else{
1462 /* Otherwise, a timeline based on a span of time */
1463 int n, nBefore, nAfter;
1464 const char *zEType = "timeline item";
1465 char *zDate;
1466 if( zUses ){
1467 blob_append_sql(&sql, " AND event.objid IN usesfile ");
1468 }
@@ -1666,20 +1666,38 @@
1666 }
1667 if( zSearch ){
1668 blob_appendf(&desc, " matching \"%h\"", zSearch);
1669 }
1670 if( g.perm.Hyperlink ){
1671 if( zCirca && rCirca ){
1672 nBefore = db_int(0,
1673 "SELECT count(*) FROM timeline WHERE etype!='div'"
1674 " AND sortby<=%f /*scan*/", rCirca);
1675 nAfter = db_int(0,
1676 "SELECT count(*) FROM timeline WHERE etype!='div'"
1677 " AND sortby>=%f /*scan*/", rCirca);
1678 zDate = db_text(0, "SELECT min(timestamp) FROM timeline /*scan*/");
1679 if( nBefore>=nEntry ){
1680 timeline_submenu(&url, "Older", "b", zDate, "c");
1681 zOlderButton = fossil_strdup(url_render(&url, "b", zDate, "c", 0));
1682 }
1683 if( nAfter>=nEntry ){
1684 timeline_submenu(&url, "Newer", "a", zDate, "c");
1685 }
1686 free(zDate);
1687 }else{
1688 if( zAfter || n==nEntry ){
1689 zDate = db_text(0, "SELECT min(timestamp) FROM timeline /*scan*/");
1690 timeline_submenu(&url, "Older", "b", zDate, "a");
1691 zOlderButton = fossil_strdup(url_render(&url, "b", zDate, "a", 0));
1692 free(zDate);
1693 }
1694 if( zBefore || (zAfter && n==nEntry) ){
1695 zDate = db_text(0, "SELECT max(timestamp) FROM timeline /*scan*/");
1696 timeline_submenu(&url, "Newer", "a", zDate, "b");
1697 free(zDate);
1698 }
1699 }
1700 if( zType[0]=='a' || zType[0]=='c' ){
1701 if( (tmFlags & TIMELINE_UNHIDE)==0 ){
1702 timeline_submenu(&url, "Unhide", "unhide", "", 0);
1703 }
1704
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -1250,10 +1250,12 @@
12501250
zTerm = "]</span>";
12511251
}
12521252
}else if( g.perm.Hyperlink ){
12531253
blob_appendf(p->pOut, "%z[",href("%R/info/%s", zTarget));
12541254
zTerm = "]</a>";
1255
+ }else{
1256
+ zTerm = "";
12551257
}
12561258
}else if( strlen(zTarget)>=10 && fossil_isdigit(zTarget[0]) && zTarget[4]=='-'
12571259
&& db_int(0, "SELECT datetime(%Q) NOT NULL", zTarget) ){
12581260
blob_appendf(p->pOut, "<a href=\"%R/timeline?c=%T\">", zTarget);
12591261
}else if( (z = validWikiPageName(p, zTarget))!=0 ){
12601262
12611263
ADDED test/fileStat.th1
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -1250,10 +1250,12 @@
1250 zTerm = "]</span>";
1251 }
1252 }else if( g.perm.Hyperlink ){
1253 blob_appendf(p->pOut, "%z[",href("%R/info/%s", zTarget));
1254 zTerm = "]</a>";
 
 
1255 }
1256 }else if( strlen(zTarget)>=10 && fossil_isdigit(zTarget[0]) && zTarget[4]=='-'
1257 && db_int(0, "SELECT datetime(%Q) NOT NULL", zTarget) ){
1258 blob_appendf(p->pOut, "<a href=\"%R/timeline?c=%T\">", zTarget);
1259 }else if( (z = validWikiPageName(p, zTarget))!=0 ){
1260
1261 DDED test/fileStat.th1
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -1250,10 +1250,12 @@
1250 zTerm = "]</span>";
1251 }
1252 }else if( g.perm.Hyperlink ){
1253 blob_appendf(p->pOut, "%z[",href("%R/info/%s", zTarget));
1254 zTerm = "]</a>";
1255 }else{
1256 zTerm = "";
1257 }
1258 }else if( strlen(zTarget)>=10 && fossil_isdigit(zTarget[0]) && zTarget[4]=='-'
1259 && db_int(0, "SELECT datetime(%Q) NOT NULL", zTarget) ){
1260 blob_appendf(p->pOut, "<a href=\"%R/timeline?c=%T\">", zTarget);
1261 }else if( (z = validWikiPageName(p, zTarget))!=0 ){
1262
1263 DDED test/fileStat.th1
--- a/test/fileStat.th1
+++ b/test/fileStat.th1
@@ -0,0 +1,29 @@
1
+<th1>
2
+ proc doSomeTclSetup {} {
3
+ #
4
+ # NOTE: Copy repository file name to the Tcl interpreter. This is
5
+ # done first (once) because it will be necessary for almost
6
+ # everything else later on.
7
+ #
8
+ tclInvoke set repository [repository]
9
+
10
+ #
11
+ # NOTE: Create some procedures in the Tcl interpreter to perform
12
+ # useful operations. This could also do things like load
13
+ # packages, etc.
14
+ #
15
+ tclEval {
16
+ #
17
+ # NOTE: Returns an [exec] command for Fossil, using the provided
18
+ # sub-command and arguments, suitable for use with [eval]
19
+ # or [catch].
20
+ #
21
+ proc getFossilCommand { repository user args } {
22
+ global env
23
+
24
+ lappend result exec [info nameofexecutable]
25
+
26
+ if {[info exists env(GATEWAY_INTERFACE)]} then {
27
+ #
28
+ # NOTE: This option is required when calling
29
+ # out to
--- a/test/fileStat.th1
+++ b/test/fileStat.th1
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/test/fileStat.th1
+++ b/test/fileStat.th1
@@ -0,0 +1,29 @@
1 <th1>
2 proc doSomeTclSetup {} {
3 #
4 # NOTE: Copy repository file name to the Tcl interpreter. This is
5 # done first (once) because it will be necessary for almost
6 # everything else later on.
7 #
8 tclInvoke set repository [repository]
9
10 #
11 # NOTE: Create some procedures in the Tcl interpreter to perform
12 # useful operations. This could also do things like load
13 # packages, etc.
14 #
15 tclEval {
16 #
17 # NOTE: Returns an [exec] command for Fossil, using the provided
18 # sub-command and arguments, suitable for use with [eval]
19 # or [catch].
20 #
21 proc getFossilCommand { repository user args } {
22 global env
23
24 lappend result exec [info nameofexecutable]
25
26 if {[info exists env(GATEWAY_INTERFACE)]} then {
27 #
28 # NOTE: This option is required when calling
29 # out to
--- test/tester.tcl
+++ test/tester.tcl
@@ -328,10 +328,76 @@
328328
}
329329
append out \n$line
330330
}
331331
return [string range $out 1 end]
332332
}
333
+
334
+# Executes the "fossil http" command. The entire content of the HTTP request
335
+# is read from the data file name, with [subst] being performed on it prior to
336
+# submission. Temporary input and output files are created and deleted. The
337
+# result will be the contents of the temoprary output file.
338
+proc test_fossil_http { repository dataFileName url } {
339
+ set suffix [appendArgs [pid] - [getSeqNo] - [clock seconds] .txt]
340
+ set inFileName [file join $::tempPath [appendArgs test-http-in- $suffix]]
341
+ set outFileName [file join $::tempPath [appendArgs test-http-out- $suffix]]
342
+ set data [subst [read_file $dataFileName]]
343
+
344
+ write_file $inFileName $data
345
+ fossil http $inFileName $outFileName 127.0.0.1 $repository --localauth
346
+ set result [expr {[file exists $outFileName] ? [read_file $outFileName] : ""}]
347
+
348
+ if {1} then {
349
+ catch {file delete $inFileName}
350
+ catch {file delete $outFileName}
351
+ }
352
+
353
+ return $result
354
+}
355
+
356
+# obtains and increments a "sequence number" for this test run.
357
+proc getSeqNo {} {
358
+ upvar #0 seqNo seqNo
359
+ if {![info exists seqNo]} {
360
+ set seqNo 0
361
+ }
362
+ return [incr seqNo]
363
+}
364
+
365
+# fixup the whitespace in the result to make it easier to compare.
366
+proc normalize_result {} {
367
+ return [string map [list \r\n \n] [string trim $::RESULT]]
368
+}
369
+
370
+# returns the first line of the normalized result.
371
+proc first_data_line {} {
372
+ return [lindex [split [normalize_result] \n] 0]
373
+}
374
+
375
+# returns the second line of the normalized result.
376
+proc second_data_line {} {
377
+ return [lindex [split [normalize_result] \n] 1]
378
+}
379
+
380
+# returns the third line of the normalized result.
381
+proc third_data_line {} {
382
+ return [lindex [split [normalize_result] \n] 2]
383
+}
384
+
385
+# returns the last line of the normalized result.
386
+proc last_data_line {} {
387
+ return [lindex [split [normalize_result] \n] end]
388
+}
389
+
390
+# returns the second to last line of the normalized result.
391
+proc next_to_last_data_line {} {
392
+ return [lindex [split [normalize_result] \n] end-1]
393
+}
394
+
395
+# returns the third to last line of the normalized result.
396
+proc third_to_last_data_line {} {
397
+ return [lindex [split [normalize_result] \n] end-2]
398
+}
333399
334400
protInit $fossilexe
335401
foreach testfile $argv {
336402
set dir [file root [file tail $testfile]]
337403
file delete -force $dir
338404
339405
ADDED test/th1-docs-input.txt
340406
ADDED test/th1-docs.test
--- test/tester.tcl
+++ test/tester.tcl
@@ -328,10 +328,76 @@
328 }
329 append out \n$line
330 }
331 return [string range $out 1 end]
332 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
333
334 protInit $fossilexe
335 foreach testfile $argv {
336 set dir [file root [file tail $testfile]]
337 file delete -force $dir
338
339 DDED test/th1-docs-input.txt
340 DDED test/th1-docs.test
--- test/tester.tcl
+++ test/tester.tcl
@@ -328,10 +328,76 @@
328 }
329 append out \n$line
330 }
331 return [string range $out 1 end]
332 }
333
334 # Executes the "fossil http" command. The entire content of the HTTP request
335 # is read from the data file name, with [subst] being performed on it prior to
336 # submission. Temporary input and output files are created and deleted. The
337 # result will be the contents of the temoprary output file.
338 proc test_fossil_http { repository dataFileName url } {
339 set suffix [appendArgs [pid] - [getSeqNo] - [clock seconds] .txt]
340 set inFileName [file join $::tempPath [appendArgs test-http-in- $suffix]]
341 set outFileName [file join $::tempPath [appendArgs test-http-out- $suffix]]
342 set data [subst [read_file $dataFileName]]
343
344 write_file $inFileName $data
345 fossil http $inFileName $outFileName 127.0.0.1 $repository --localauth
346 set result [expr {[file exists $outFileName] ? [read_file $outFileName] : ""}]
347
348 if {1} then {
349 catch {file delete $inFileName}
350 catch {file delete $outFileName}
351 }
352
353 return $result
354 }
355
356 # obtains and increments a "sequence number" for this test run.
357 proc getSeqNo {} {
358 upvar #0 seqNo seqNo
359 if {![info exists seqNo]} {
360 set seqNo 0
361 }
362 return [incr seqNo]
363 }
364
365 # fixup the whitespace in the result to make it easier to compare.
366 proc normalize_result {} {
367 return [string map [list \r\n \n] [string trim $::RESULT]]
368 }
369
370 # returns the first line of the normalized result.
371 proc first_data_line {} {
372 return [lindex [split [normalize_result] \n] 0]
373 }
374
375 # returns the second line of the normalized result.
376 proc second_data_line {} {
377 return [lindex [split [normalize_result] \n] 1]
378 }
379
380 # returns the third line of the normalized result.
381 proc third_data_line {} {
382 return [lindex [split [normalize_result] \n] 2]
383 }
384
385 # returns the last line of the normalized result.
386 proc last_data_line {} {
387 return [lindex [split [normalize_result] \n] end]
388 }
389
390 # returns the second to last line of the normalized result.
391 proc next_to_last_data_line {} {
392 return [lindex [split [normalize_result] \n] end-1]
393 }
394
395 # returns the third to last line of the normalized result.
396 proc third_to_last_data_line {} {
397 return [lindex [split [normalize_result] \n] end-2]
398 }
399
400 protInit $fossilexe
401 foreach testfile $argv {
402 set dir [file root [file tail $testfile]]
403 file delete -force $dir
404
405 DDED test/th1-docs-input.txt
406 DDED test/th1-docs.test
--- a/test/th1-docs-input.txt
+++ b/test/th1-docs-input.txt
@@ -0,0 +1,4 @@
1
+GET ${url} HTTP/1.1
2
+Host: localhost
3
+User-Agent: Fossil
4
+
--- a/test/th1-docs-input.txt
+++ b/test/th1-docs-input.txt
@@ -0,0 +1,4 @@
 
 
 
 
--- a/test/th1-docs-input.txt
+++ b/test/th1-docs-input.txt
@@ -0,0 +1,4 @@
1 GET ${url} HTTP/1.1
2 Host: localhost
3 User-Agent: Fossil
4
--- a/test/th1-docs.test
+++ b/test/th1-docs.test
@@ -0,0 +1 @@
1
+thenthenthenset data [fossil info]
--- a/test/th1-docs.test
+++ b/test/th1-docs.test
@@ -0,0 +1 @@
 
--- a/test/th1-docs.test
+++ b/test/th1-docs.test
@@ -0,0 +1 @@
1 thenthenthenset data [fossil info]
--- test/th1-hooks.test
+++ test/th1-hooks.test
@@ -28,50 +28,10 @@
2828
2929
set env(TH1_ENABLE_HOOKS) 1; # TH1 hooks must be enabled for this test.
3030
3131
###############################################################################
3232
33
-proc fossil_th1_hook_http { repository url } {
34
- set suffix [appendArgs [pid] - [clock seconds] .txt]
35
- set inFileName [file join $::tempPath [appendArgs test-http-in- $suffix]]
36
- set outFileName [file join $::tempPath [appendArgs test-http-out- $suffix]]
37
- set data [subst [read_file [file join $::testdir th1-hooks-input.txt]]]
38
-
39
- write_file $inFileName $data
40
- fossil http $repository $inFileName $outFileName 127.0.0.1
41
- set result [expr {[file exists $outFileName] ? [read_file $outFileName] : ""}]
42
-
43
- if {1} then {
44
- catch {file delete $inFileName}
45
- catch {file delete $outFileName}
46
- }
47
-
48
- return $result
49
-}
50
-
51
-proc first_data_line {} {
52
- return [lindex [split [string trim $::RESULT] \r\n] 0]
53
-}
54
-
55
-proc second_data_line {} {
56
- return [lindex [split [string trim $::RESULT] \r\n] 1]
57
-}
58
-
59
-proc third_data_line {} {
60
- return [lindex [split [string trim $::RESULT] \r\n] 2]
61
-}
62
-
63
-proc last_data_line {} {
64
- return [lindex [split [string trim $::RESULT] \r\n] end]
65
-}
66
-
67
-proc next_to_last_data_line {} {
68
- return [lindex [split [string trim $::RESULT] \r\n] end-1]
69
-}
70
-
71
-###############################################################################
72
-
7333
set testTh1Setup {
7434
proc initialize_hook_log {} {
7535
if {![info exists ::hook_log]} {
7636
set ::hook_log ""
7737
}
@@ -103,13 +63,18 @@
10363
break "TH_BREAK return code"
10464
} elseif {$::cmd_name eq "test4"} {
10565
emit_hook_log
10666
return -code 2 "TH_RETURN return code"
10767
} elseif {$::cmd_name eq "timeline"} {
108
- if {$::cmd_args eq "custom"} {
68
+ set length [llength $::cmd_args]
69
+ set length [expr {$length - 1}]
70
+ if {[lindex $::cmd_args $length] eq "custom"} {
10971
emit_hook_log
11072
return "custom timeline"
73
+ } elseif {[lindex $::cmd_args $length] eq "now"} {
74
+ emit_hook_log
75
+ return "now timeline"
11176
} else {
11277
emit_hook_log
11378
error "unsupported timeline"
11479
}
11580
}
@@ -139,63 +104,89 @@
139104
regexp -line -- {^repository: (.*)$} $data dummy repository
140105
141106
if {[string length $repository] == 0 || ![file exists $repository]} then {
142107
error "unable to locate repository"
143108
}
109
+
110
+set dataFileName [file join $::testdir th1-hooks-input.txt]
144111
145112
###############################################################################
146113
147114
saveTh1SetupFile; writeTh1SetupFile $testTh1Setup
148115
149116
###############################################################################
150117
151118
fossil timeline custom; # NOTE: Bad "WHEN" argument.
152
-test th1-cmd-hooks-1a {[string map [list \r\n \n] [string trim $RESULT]] eq {<h1><b>command_hook timeline</b></h1>
153
-ERROR: unsupported timeline
119
+test th1-cmd-hooks-1a {[normalize_result] eq \
120
+{<h1><b>command_hook timeline</b></h1>
154121
+++ no more data (0) +++
155122
156123
<h1><b>command_hook timeline command_notify timeline</b></h1>}}
157124
158125
###############################################################################
159126
160127
fossil timeline
161
-test th1-cmd-hooks-2a {[first_data_line] eq {<h1><b>command_hook timeline</b></h1>}}
128
+test th1-cmd-hooks-2a {[first_data_line] eq \
129
+ {<h1><b>command_hook timeline</b></h1>}}
130
+
162131
test th1-cmd-hooks-2b {[second_data_line] eq {ERROR: unsupported timeline}}
163
-test th1-cmd-hooks-2c {[regexp -- {=== \d{4}-\d{2}-\d{2} ===} [third_data_line]]}
164
-test th1-cmd-hooks-2d {[last_data_line] eq {<h1><b>command_hook timeline command_notify timeline</b></h1>}}
132
+
133
+###############################################################################
134
+
135
+fossil timeline now
136
+test th1-cmd-hooks-3a {[first_data_line] eq \
137
+ {<h1><b>command_hook timeline</b></h1>}}
138
+
139
+test th1-cmd-hooks-3b \
140
+ {[regexp -- {=== \d{4}-\d{2}-\d{2} ===} [second_data_line]]}
141
+
142
+test th1-cmd-hooks-3c \
143
+ {[regexp -- {--- line limit \(\d+\) reached ---} [third_to_last_data_line]]}
144
+
145
+test th1-cmd-hooks-3d {[last_data_line] eq \
146
+ {<h1><b>command_hook timeline command_notify timeline</b></h1>}}
165147
166148
###############################################################################
167149
168150
fossil test1
169151
test th1-custom-cmd-1a {[next_to_last_data_line] eq $repository}
170
-test th1-custom-cmd-1b {[last_data_line] eq {<h1><b>command_hook test1 command_notify test1</b></h1>}}
152
+
153
+test th1-custom-cmd-1b {[last_data_line] eq \
154
+ {<h1><b>command_hook test1 command_notify test1</b></h1>}}
171155
172156
###############################################################################
173157
174158
fossil test2
175159
test th1-custom-cmd-2a {[first_data_line] eq {ERROR: unsupported command}}
176160
177161
###############################################################################
178162
179163
fossil test3
180
-test th1-custom-cmd-3a {[string trim $RESULT] eq {<h1><b>command_hook test3</b></h1>}}
164
+test th1-custom-cmd-3a {[string trim $RESULT] eq \
165
+ {<h1><b>command_hook test3</b></h1>}}
181166
182167
###############################################################################
183168
184169
fossil test4
185
-test th1-custom-cmd-4a {[string trim $RESULT] eq {<h1><b>command_hook test4</b></h1>}}
170
+test th1-custom-cmd-4a {[string trim $RESULT] eq \
171
+ {<h1><b>command_hook test4</b></h1>}}
186172
187173
###############################################################################
188174
189
-set RESULT [fossil_th1_hook_http $repository /timeline]
175
+set RESULT [test_fossil_http $repository $dataFileName /timeline]
190176
test th1-web-hooks-1a {[regexp {<title>Fossil: Timeline</title>} $RESULT]}
191
-test th1-web-hooks-1b {[regexp {<h1><b>command_hook http webpage_hook timeline webpage_notify timeline</b></h1>} $RESULT]}
177
+
178
+test th1-web-hooks-1b {[regexp [appendArgs \
179
+ {<h1><b>command_hook http webpage_hook timeline} " " \
180
+ {webpage_notify timeline</b></h1>}] $RESULT]}
192181
193182
###############################################################################
194183
195
-set RESULT [fossil_th1_hook_http $repository /test1]
184
+set RESULT [test_fossil_http $repository $dataFileName /test1]
196185
test th1-custom-web-1a {[next_to_last_data_line] eq $repository}
197
-test th1-custom-web-1b {[last_data_line] eq {<h1><b>command_hook http webpage_hook test1 webpage_notify test1</b></h1>}}
186
+
187
+test th1-custom-web-1b {[last_data_line] eq \
188
+ {<h1><b>command_hook http webpage_hook test1 webpage_notify test1</b></h1>}}
198189
199190
###############################################################################
200191
201192
restoreTh1SetupFile
202193
--- test/th1-hooks.test
+++ test/th1-hooks.test
@@ -28,50 +28,10 @@
28
29 set env(TH1_ENABLE_HOOKS) 1; # TH1 hooks must be enabled for this test.
30
31 ###############################################################################
32
33 proc fossil_th1_hook_http { repository url } {
34 set suffix [appendArgs [pid] - [clock seconds] .txt]
35 set inFileName [file join $::tempPath [appendArgs test-http-in- $suffix]]
36 set outFileName [file join $::tempPath [appendArgs test-http-out- $suffix]]
37 set data [subst [read_file [file join $::testdir th1-hooks-input.txt]]]
38
39 write_file $inFileName $data
40 fossil http $repository $inFileName $outFileName 127.0.0.1
41 set result [expr {[file exists $outFileName] ? [read_file $outFileName] : ""}]
42
43 if {1} then {
44 catch {file delete $inFileName}
45 catch {file delete $outFileName}
46 }
47
48 return $result
49 }
50
51 proc first_data_line {} {
52 return [lindex [split [string trim $::RESULT] \r\n] 0]
53 }
54
55 proc second_data_line {} {
56 return [lindex [split [string trim $::RESULT] \r\n] 1]
57 }
58
59 proc third_data_line {} {
60 return [lindex [split [string trim $::RESULT] \r\n] 2]
61 }
62
63 proc last_data_line {} {
64 return [lindex [split [string trim $::RESULT] \r\n] end]
65 }
66
67 proc next_to_last_data_line {} {
68 return [lindex [split [string trim $::RESULT] \r\n] end-1]
69 }
70
71 ###############################################################################
72
73 set testTh1Setup {
74 proc initialize_hook_log {} {
75 if {![info exists ::hook_log]} {
76 set ::hook_log ""
77 }
@@ -103,13 +63,18 @@
103 break "TH_BREAK return code"
104 } elseif {$::cmd_name eq "test4"} {
105 emit_hook_log
106 return -code 2 "TH_RETURN return code"
107 } elseif {$::cmd_name eq "timeline"} {
108 if {$::cmd_args eq "custom"} {
 
 
109 emit_hook_log
110 return "custom timeline"
 
 
 
111 } else {
112 emit_hook_log
113 error "unsupported timeline"
114 }
115 }
@@ -139,63 +104,89 @@
139 regexp -line -- {^repository: (.*)$} $data dummy repository
140
141 if {[string length $repository] == 0 || ![file exists $repository]} then {
142 error "unable to locate repository"
143 }
 
 
144
145 ###############################################################################
146
147 saveTh1SetupFile; writeTh1SetupFile $testTh1Setup
148
149 ###############################################################################
150
151 fossil timeline custom; # NOTE: Bad "WHEN" argument.
152 test th1-cmd-hooks-1a {[string map [list \r\n \n] [string trim $RESULT]] eq {<h1><b>command_hook timeline</b></h1>
153 ERROR: unsupported timeline
154 +++ no more data (0) +++
155
156 <h1><b>command_hook timeline command_notify timeline</b></h1>}}
157
158 ###############################################################################
159
160 fossil timeline
161 test th1-cmd-hooks-2a {[first_data_line] eq {<h1><b>command_hook timeline</b></h1>}}
 
 
162 test th1-cmd-hooks-2b {[second_data_line] eq {ERROR: unsupported timeline}}
163 test th1-cmd-hooks-2c {[regexp -- {=== \d{4}-\d{2}-\d{2} ===} [third_data_line]]}
164 test th1-cmd-hooks-2d {[last_data_line] eq {<h1><b>command_hook timeline command_notify timeline</b></h1>}}
 
 
 
 
 
 
 
 
 
 
 
 
 
165
166 ###############################################################################
167
168 fossil test1
169 test th1-custom-cmd-1a {[next_to_last_data_line] eq $repository}
170 test th1-custom-cmd-1b {[last_data_line] eq {<h1><b>command_hook test1 command_notify test1</b></h1>}}
 
 
171
172 ###############################################################################
173
174 fossil test2
175 test th1-custom-cmd-2a {[first_data_line] eq {ERROR: unsupported command}}
176
177 ###############################################################################
178
179 fossil test3
180 test th1-custom-cmd-3a {[string trim $RESULT] eq {<h1><b>command_hook test3</b></h1>}}
 
181
182 ###############################################################################
183
184 fossil test4
185 test th1-custom-cmd-4a {[string trim $RESULT] eq {<h1><b>command_hook test4</b></h1>}}
 
186
187 ###############################################################################
188
189 set RESULT [fossil_th1_hook_http $repository /timeline]
190 test th1-web-hooks-1a {[regexp {<title>Fossil: Timeline</title>} $RESULT]}
191 test th1-web-hooks-1b {[regexp {<h1><b>command_hook http webpage_hook timeline webpage_notify timeline</b></h1>} $RESULT]}
 
 
 
192
193 ###############################################################################
194
195 set RESULT [fossil_th1_hook_http $repository /test1]
196 test th1-custom-web-1a {[next_to_last_data_line] eq $repository}
197 test th1-custom-web-1b {[last_data_line] eq {<h1><b>command_hook http webpage_hook test1 webpage_notify test1</b></h1>}}
 
 
198
199 ###############################################################################
200
201 restoreTh1SetupFile
202
--- test/th1-hooks.test
+++ test/th1-hooks.test
@@ -28,50 +28,10 @@
28
29 set env(TH1_ENABLE_HOOKS) 1; # TH1 hooks must be enabled for this test.
30
31 ###############################################################################
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33 set testTh1Setup {
34 proc initialize_hook_log {} {
35 if {![info exists ::hook_log]} {
36 set ::hook_log ""
37 }
@@ -103,13 +63,18 @@
63 break "TH_BREAK return code"
64 } elseif {$::cmd_name eq "test4"} {
65 emit_hook_log
66 return -code 2 "TH_RETURN return code"
67 } elseif {$::cmd_name eq "timeline"} {
68 set length [llength $::cmd_args]
69 set length [expr {$length - 1}]
70 if {[lindex $::cmd_args $length] eq "custom"} {
71 emit_hook_log
72 return "custom timeline"
73 } elseif {[lindex $::cmd_args $length] eq "now"} {
74 emit_hook_log
75 return "now timeline"
76 } else {
77 emit_hook_log
78 error "unsupported timeline"
79 }
80 }
@@ -139,63 +104,89 @@
104 regexp -line -- {^repository: (.*)$} $data dummy repository
105
106 if {[string length $repository] == 0 || ![file exists $repository]} then {
107 error "unable to locate repository"
108 }
109
110 set dataFileName [file join $::testdir th1-hooks-input.txt]
111
112 ###############################################################################
113
114 saveTh1SetupFile; writeTh1SetupFile $testTh1Setup
115
116 ###############################################################################
117
118 fossil timeline custom; # NOTE: Bad "WHEN" argument.
119 test th1-cmd-hooks-1a {[normalize_result] eq \
120 {<h1><b>command_hook timeline</b></h1>
121 +++ no more data (0) +++
122
123 <h1><b>command_hook timeline command_notify timeline</b></h1>}}
124
125 ###############################################################################
126
127 fossil timeline
128 test th1-cmd-hooks-2a {[first_data_line] eq \
129 {<h1><b>command_hook timeline</b></h1>}}
130
131 test th1-cmd-hooks-2b {[second_data_line] eq {ERROR: unsupported timeline}}
132
133 ###############################################################################
134
135 fossil timeline now
136 test th1-cmd-hooks-3a {[first_data_line] eq \
137 {<h1><b>command_hook timeline</b></h1>}}
138
139 test th1-cmd-hooks-3b \
140 {[regexp -- {=== \d{4}-\d{2}-\d{2} ===} [second_data_line]]}
141
142 test th1-cmd-hooks-3c \
143 {[regexp -- {--- line limit \(\d+\) reached ---} [third_to_last_data_line]]}
144
145 test th1-cmd-hooks-3d {[last_data_line] eq \
146 {<h1><b>command_hook timeline command_notify timeline</b></h1>}}
147
148 ###############################################################################
149
150 fossil test1
151 test th1-custom-cmd-1a {[next_to_last_data_line] eq $repository}
152
153 test th1-custom-cmd-1b {[last_data_line] eq \
154 {<h1><b>command_hook test1 command_notify test1</b></h1>}}
155
156 ###############################################################################
157
158 fossil test2
159 test th1-custom-cmd-2a {[first_data_line] eq {ERROR: unsupported command}}
160
161 ###############################################################################
162
163 fossil test3
164 test th1-custom-cmd-3a {[string trim $RESULT] eq \
165 {<h1><b>command_hook test3</b></h1>}}
166
167 ###############################################################################
168
169 fossil test4
170 test th1-custom-cmd-4a {[string trim $RESULT] eq \
171 {<h1><b>command_hook test4</b></h1>}}
172
173 ###############################################################################
174
175 set RESULT [test_fossil_http $repository $dataFileName /timeline]
176 test th1-web-hooks-1a {[regexp {<title>Fossil: Timeline</title>} $RESULT]}
177
178 test th1-web-hooks-1b {[regexp [appendArgs \
179 {<h1><b>command_hook http webpage_hook timeline} " " \
180 {webpage_notify timeline</b></h1>}] $RESULT]}
181
182 ###############################################################################
183
184 set RESULT [test_fossil_http $repository $dataFileName /test1]
185 test th1-custom-web-1a {[next_to_last_data_line] eq $repository}
186
187 test th1-custom-web-1b {[last_data_line] eq \
188 {<h1><b>command_hook http webpage_hook test1 webpage_notify test1</b></h1>}}
189
190 ###############################################################################
191
192 restoreTh1SetupFile
193
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -146,11 +146,11 @@
146146
#### The directories where the OpenSSL include and library files are located.
147147
# The recommended usage here is to use the Sysinternals junction tool
148148
# to create a hard link between an "openssl-1.x" sub-directory of the
149149
# Fossil source code directory and the target OpenSSL source directory.
150150
#
151
-OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2
151
+OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2a
152152
OPENSSLINCDIR = $(OPENSSLDIR)/include
153153
OPENSSLLIBDIR = $(OPENSSLDIR)
154154
155155
#### Either the directory where the Tcl library is installed or the Tcl
156156
# source code directory resides (depending on the value of the macro
157157
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -146,11 +146,11 @@
146 #### The directories where the OpenSSL include and library files are located.
147 # The recommended usage here is to use the Sysinternals junction tool
148 # to create a hard link between an "openssl-1.x" sub-directory of the
149 # Fossil source code directory and the target OpenSSL source directory.
150 #
151 OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2
152 OPENSSLINCDIR = $(OPENSSLDIR)/include
153 OPENSSLLIBDIR = $(OPENSSLDIR)
154
155 #### Either the directory where the Tcl library is installed or the Tcl
156 # source code directory resides (depending on the value of the macro
157
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -146,11 +146,11 @@
146 #### The directories where the OpenSSL include and library files are located.
147 # The recommended usage here is to use the Sysinternals junction tool
148 # to create a hard link between an "openssl-1.x" sub-directory of the
149 # Fossil source code directory and the target OpenSSL source directory.
150 #
151 OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2a
152 OPENSSLINCDIR = $(OPENSSLDIR)/include
153 OPENSSLLIBDIR = $(OPENSSLDIR)
154
155 #### Either the directory where the Tcl library is installed or the Tcl
156 # source code directory resides (depending on the value of the macro
157
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -55,11 +55,11 @@
5555
#
5656
# FOSSIL_BUILD_SSL = 1
5757
5858
#### Enable TH1 scripts in embedded documentation files
5959
#
60
-# FOSSIL_ENABLE_TH1_DOCS = 1
60
+FOSSIL_ENABLE_TH1_DOCS = 1
6161
6262
#### Enable hooks for commands and web pages via TH1
6363
#
6464
FOSSIL_ENABLE_TH1_HOOKS = 1
6565
@@ -146,11 +146,11 @@
146146
#### The directories where the OpenSSL include and library files are located.
147147
# The recommended usage here is to use the Sysinternals junction tool
148148
# to create a hard link between an "openssl-1.x" sub-directory of the
149149
# Fossil source code directory and the target OpenSSL source directory.
150150
#
151
-OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2
151
+OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2a
152152
OPENSSLINCDIR = $(OPENSSLDIR)/include
153153
OPENSSLLIBDIR = $(OPENSSLDIR)
154154
155155
#### Either the directory where the Tcl library is installed or the Tcl
156156
# source code directory resides (depending on the value of the macro
157157
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -55,11 +55,11 @@
55 #
56 # FOSSIL_BUILD_SSL = 1
57
58 #### Enable TH1 scripts in embedded documentation files
59 #
60 # FOSSIL_ENABLE_TH1_DOCS = 1
61
62 #### Enable hooks for commands and web pages via TH1
63 #
64 FOSSIL_ENABLE_TH1_HOOKS = 1
65
@@ -146,11 +146,11 @@
146 #### The directories where the OpenSSL include and library files are located.
147 # The recommended usage here is to use the Sysinternals junction tool
148 # to create a hard link between an "openssl-1.x" sub-directory of the
149 # Fossil source code directory and the target OpenSSL source directory.
150 #
151 OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2
152 OPENSSLINCDIR = $(OPENSSLDIR)/include
153 OPENSSLLIBDIR = $(OPENSSLDIR)
154
155 #### Either the directory where the Tcl library is installed or the Tcl
156 # source code directory resides (depending on the value of the macro
157
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -55,11 +55,11 @@
55 #
56 # FOSSIL_BUILD_SSL = 1
57
58 #### Enable TH1 scripts in embedded documentation files
59 #
60 FOSSIL_ENABLE_TH1_DOCS = 1
61
62 #### Enable hooks for commands and web pages via TH1
63 #
64 FOSSIL_ENABLE_TH1_HOOKS = 1
65
@@ -146,11 +146,11 @@
146 #### The directories where the OpenSSL include and library files are located.
147 # The recommended usage here is to use the Sysinternals junction tool
148 # to create a hard link between an "openssl-1.x" sub-directory of the
149 # Fossil source code directory and the target OpenSSL source directory.
150 #
151 OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2a
152 OPENSSLINCDIR = $(OPENSSLDIR)/include
153 OPENSSLLIBDIR = $(OPENSSLDIR)
154
155 #### Either the directory where the Tcl library is installed or the Tcl
156 # source code directory resides (depending on the value of the macro
157
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -55,11 +55,11 @@
5555
5656
# Uncomment to enable Tcl support
5757
# FOSSIL_ENABLE_TCL = 1
5858
5959
!ifdef FOSSIL_ENABLE_SSL
60
-SSLDIR = $(B)\compat\openssl-1.0.2
60
+SSLDIR = $(B)\compat\openssl-1.0.2a
6161
SSLINCDIR = $(SSLDIR)\inc32
6262
SSLLIBDIR = $(SSLDIR)\out32
6363
SSLLFLAGS = /nologo /opt:ref /debug
6464
SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
6565
!if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
6666
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -55,11 +55,11 @@
55
56 # Uncomment to enable Tcl support
57 # FOSSIL_ENABLE_TCL = 1
58
59 !ifdef FOSSIL_ENABLE_SSL
60 SSLDIR = $(B)\compat\openssl-1.0.2
61 SSLINCDIR = $(SSLDIR)\inc32
62 SSLLIBDIR = $(SSLDIR)\out32
63 SSLLFLAGS = /nologo /opt:ref /debug
64 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
65 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
66
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -55,11 +55,11 @@
55
56 # Uncomment to enable Tcl support
57 # FOSSIL_ENABLE_TCL = 1
58
59 !ifdef FOSSIL_ENABLE_SSL
60 SSLDIR = $(B)\compat\openssl-1.0.2a
61 SSLINCDIR = $(SSLDIR)\inc32
62 SSLLIBDIR = $(SSLDIR)\out32
63 SSLLFLAGS = /nologo /opt:ref /debug
64 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
65 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
66
+1 -1
--- www/build.wiki
+++ www/build.wiki
@@ -125,11 +125,11 @@
125125
the optional <a href="https://www.openssl.org/">OpenSSL</a> support,
126126
first <a href="https://www.openssl.org/source/">download the official
127127
source code for OpenSSL</a> and extract it to an appropriately named
128128
"<b>openssl-X.Y.ZA</b>" subdirectory within the local
129129
[/tree?ci=trunk&name=compat | compat] directory (e.g.
130
-"<b>compat/openssl-1.0.2</b>"), then make sure that some recent
130
+"<b>compat/openssl-1.0.2a</b>"), then make sure that some recent
131131
<a href="http://www.perl.org/">Perl</a> binaries are installed locally,
132132
and finally run one of the following commands:
133133
<blockquote><pre>
134134
nmake /f Makefile.msc FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
135135
</pre></blockquote>
136136
--- www/build.wiki
+++ www/build.wiki
@@ -125,11 +125,11 @@
125 the optional <a href="https://www.openssl.org/">OpenSSL</a> support,
126 first <a href="https://www.openssl.org/source/">download the official
127 source code for OpenSSL</a> and extract it to an appropriately named
128 "<b>openssl-X.Y.ZA</b>" subdirectory within the local
129 [/tree?ci=trunk&name=compat | compat] directory (e.g.
130 "<b>compat/openssl-1.0.2</b>"), then make sure that some recent
131 <a href="http://www.perl.org/">Perl</a> binaries are installed locally,
132 and finally run one of the following commands:
133 <blockquote><pre>
134 nmake /f Makefile.msc FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
135 </pre></blockquote>
136
--- www/build.wiki
+++ www/build.wiki
@@ -125,11 +125,11 @@
125 the optional <a href="https://www.openssl.org/">OpenSSL</a> support,
126 first <a href="https://www.openssl.org/source/">download the official
127 source code for OpenSSL</a> and extract it to an appropriately named
128 "<b>openssl-X.Y.ZA</b>" subdirectory within the local
129 [/tree?ci=trunk&name=compat | compat] directory (e.g.
130 "<b>compat/openssl-1.0.2a</b>"), then make sure that some recent
131 <a href="http://www.perl.org/">Perl</a> binaries are installed locally,
132 and finally run one of the following commands:
133 <blockquote><pre>
134 nmake /f Makefile.msc FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
135 </pre></blockquote>
136
+4 -5
--- www/sync.wiki
+++ www/sync.wiki
@@ -247,13 +247,11 @@
247247
<b>push</b> <i>servercode projectcode</i><br>
248248
<b>pull</b> <i>servercode projectcode</i>
249249
</blockquote>
250250
251251
<p>The <i>servercode</i> argument is the repository ID for the
252
-client. The server will only allow the transaction to proceed
253
-if the servercode is different from its own servercode. This
254
-prevents a sync-loop. The <i>projectcode</i> is the identifier
252
+client. The <i>projectcode</i> is the identifier
255253
of the software project that the client repository contains.
256254
The projectcode for the client and server must match in order
257255
for the transaction to proceed.</p>
258256
259257
<p>The server will also send a push card back to the client
@@ -384,11 +382,11 @@
384382
385383
<blockquote>
386384
<b>reqconfig</b> <i>configuration-name</i>
387385
</blockquote>
388386
389
-<p>As of [/timeline?r=trunk&c=2015-01-24+00%3A17%3A55&n=20|2015-01-24], the configuration-name must be one of the
387
+<p>As of [/timeline?r=trunk&c=2015-03-19+03%3A57%3A46&n=20|2015-03-19], the configuration-name must be one of the
390388
following values:
391389
392390
<center><table border=0>
393391
<tr><td valign="top">
394392
<ul>
@@ -420,16 +418,17 @@
420418
<li> keep-glob
421419
<li> crnl-glob
422420
<li> encoding-glob
423421
<li> empty-dirs
424422
<li> allow-symlinks
423
+<li> dotfiles
425424
<li> ticket-table
426425
<li> ticket-common
427426
<li> ticket-change
428427
<li> ticket-newpage
429
-<li> ticket-viewpage
430428
<ul></td><td valign="top"><ul>
429
+<li> ticket-viewpage
431430
<li> ticket-editpage
432431
<li> ticket-reportlist
433432
<li> ticket-report-template
434433
<li> ticket-key-template
435434
<li> ticket-title-expr
436435
--- www/sync.wiki
+++ www/sync.wiki
@@ -247,13 +247,11 @@
247 <b>push</b> <i>servercode projectcode</i><br>
248 <b>pull</b> <i>servercode projectcode</i>
249 </blockquote>
250
251 <p>The <i>servercode</i> argument is the repository ID for the
252 client. The server will only allow the transaction to proceed
253 if the servercode is different from its own servercode. This
254 prevents a sync-loop. The <i>projectcode</i> is the identifier
255 of the software project that the client repository contains.
256 The projectcode for the client and server must match in order
257 for the transaction to proceed.</p>
258
259 <p>The server will also send a push card back to the client
@@ -384,11 +382,11 @@
384
385 <blockquote>
386 <b>reqconfig</b> <i>configuration-name</i>
387 </blockquote>
388
389 <p>As of [/timeline?r=trunk&c=2015-01-24+00%3A17%3A55&n=20|2015-01-24], the configuration-name must be one of the
390 following values:
391
392 <center><table border=0>
393 <tr><td valign="top">
394 <ul>
@@ -420,16 +418,17 @@
420 <li> keep-glob
421 <li> crnl-glob
422 <li> encoding-glob
423 <li> empty-dirs
424 <li> allow-symlinks
 
425 <li> ticket-table
426 <li> ticket-common
427 <li> ticket-change
428 <li> ticket-newpage
429 <li> ticket-viewpage
430 <ul></td><td valign="top"><ul>
 
431 <li> ticket-editpage
432 <li> ticket-reportlist
433 <li> ticket-report-template
434 <li> ticket-key-template
435 <li> ticket-title-expr
436
--- www/sync.wiki
+++ www/sync.wiki
@@ -247,13 +247,11 @@
247 <b>push</b> <i>servercode projectcode</i><br>
248 <b>pull</b> <i>servercode projectcode</i>
249 </blockquote>
250
251 <p>The <i>servercode</i> argument is the repository ID for the
252 client. The <i>projectcode</i> is the identifier
 
 
253 of the software project that the client repository contains.
254 The projectcode for the client and server must match in order
255 for the transaction to proceed.</p>
256
257 <p>The server will also send a push card back to the client
@@ -384,11 +382,11 @@
382
383 <blockquote>
384 <b>reqconfig</b> <i>configuration-name</i>
385 </blockquote>
386
387 <p>As of [/timeline?r=trunk&c=2015-03-19+03%3A57%3A46&n=20|2015-03-19], the configuration-name must be one of the
388 following values:
389
390 <center><table border=0>
391 <tr><td valign="top">
392 <ul>
@@ -420,16 +418,17 @@
418 <li> keep-glob
419 <li> crnl-glob
420 <li> encoding-glob
421 <li> empty-dirs
422 <li> allow-symlinks
423 <li> dotfiles
424 <li> ticket-table
425 <li> ticket-common
426 <li> ticket-change
427 <li> ticket-newpage
 
428 <ul></td><td valign="top"><ul>
429 <li> ticket-viewpage
430 <li> ticket-editpage
431 <li> ticket-reportlist
432 <li> ticket-report-template
433 <li> ticket-key-template
434 <li> ticket-title-expr
435

Keyboard Shortcuts

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